Skip to content

Commit

Permalink
fix: build list of excluded pkg dirs even if scopeProfiles is set
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Oct 17, 2023
1 parent c88bf17 commit 58a3fde
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/package/packageProfileApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class PackageProfileApi extends AsyncCreatable<ProfileApiOptions> {
.filter(({ hasContent, profileName, removedSettings, profilePath, xmlFileLocation, adjustedProfile }) => {
if (!hasContent) {
logger.warn(
`Profile ${profileName} has no content after filtering. It will still be part of the package but you can remove if it it's not needed.`
`Profile ${profileName} has no content after filtering. It will still be part of the package but you can remove it if it's not needed.`
);
return true;
} else {
Expand Down
40 changes: 25 additions & 15 deletions src/package/packageVersionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,23 @@ export class PackageVersionCreate {
);
}

let profileExcludeDirs: string[] = [];
if (this.packageObject.scopeProfiles) {
this.logger.debug(
`packageDirectory: ${this.packageObject.name} has 'scopeProfiles' set, so only including profiles from within this directory`
);
// exclude all package dirs except the one being packaged
profileExcludeDirs = this.project
.getPackageDirectories()
.map((packageDir) => {
if (packageDir.path !== this.packageObject.path) {
return packageDir.path;
}
})
.filter((packageDirPath) => packageDirPath) as string[];
} else {
// don't package the profiles from any un-packagedMetadata dir in the project
const profileExcludeDirs = this.project
profileExcludeDirs = this.project
.getPackageDirectories()
.map((packageDir) => (packageDir as PackageDescriptorJson).unpackagedMetadata?.path)
.filter((packageDirPath) => packageDirPath) as string[];
Expand All @@ -520,23 +530,23 @@ export class PackageVersionCreate {
debugMsg += ` excluding these unpackagedMetadata dirs: ${profileExcludeDirs.toString()}`;
}
this.logger.debug(debugMsg);
}

const typesArr =
this.options?.profileApi?.filterAndGenerateProfilesForManifest(packageXmlAsJson.types, profileExcludeDirs) ??
packageXmlAsJson.types;
const typesArr =
this.options?.profileApi?.filterAndGenerateProfilesForManifest(packageXmlAsJson.types, profileExcludeDirs) ??
packageXmlAsJson.types;

// Next generate profiles and retrieve any profiles that were excluded because they had no matching nodes.
const excludedProfiles = this.options?.profileApi?.generateProfiles(
packageVersProfileFolder,
typesArr,
profileExcludeDirs
);
// Next generate profiles and retrieve any profiles that were excluded because they had no matching nodes.
const excludedProfiles = this.options?.profileApi?.generateProfiles(
packageVersProfileFolder,
typesArr,
profileExcludeDirs
);

packageXmlAsJson.types = typesArr.map((type) => {
if (type.name !== 'Profile') return type;
return { ...type, members: type.members.filter((m) => !excludedProfiles?.includes(m)) };
});
}
packageXmlAsJson.types = typesArr.map((type) => {
if (type.name !== 'Profile') return type;
return { ...type, members: type.members.filter((m) => !excludedProfiles?.includes(m)) };
});

const xml = packageXmlJsonToXmlString(packageXmlAsJson);
await fs.promises.writeFile(path.join(packageVersMetadataFolder, 'package.xml'), xml, 'utf-8');
Expand Down
6 changes: 4 additions & 2 deletions test/package/packageVersionCreate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,10 @@ describe('Package Version Create', () => {
const logMsg =
"packageDirectory: force-app has 'scopeProfiles' set, so only including profiles from within this directory";
expect(loggerSpy.calledWith(logMsg)).to.be.true;
expect(profileSpyGenerate.called).to.be.false;
expect(profileSpyFilter.called).to.be.false;
expect(profileSpyGenerate.called).to.be.true;
expect(profileSpyGenerate.firstCall.args[2]).to.deep.equal(['pkg', 'unpackaged-pkg', 'unpackaged-force-app']);
expect(profileSpyFilter.called).to.be.true;
expect(profileSpyFilter.firstCall.args[1]).to.deep.equal(['pkg', 'unpackaged-pkg', 'unpackaged-force-app']);
});

it('should not package profiles from outside of project package directories', async () => {
Expand Down

0 comments on commit 58a3fde

Please sign in to comment.