Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
fix(packagediff): fix packages being built when the path to package s…
Browse files Browse the repository at this point in the history
…tart with same structure (#1423)

paths are matched with includes rather than checking the directory properly. This can result in
packages being built if the directory structure is similar

fixes #1396
  • Loading branch information
azlam-abdulsalam authored Oct 17, 2023
1 parent 7c5d9d4 commit 1d31cd3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/core/src/package/diff/PackageDiffImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ export default class PackageDiffImpl {

// Check whether the package has been modified
for (let filename of modified_files) {
if (filename.includes(path.normalize(pkgDescriptor.path))) {

let normalizedPkgPath = path.normalize(pkgDescriptor.path);
let normalizedFilename = path.normalize(filename);

let relativePath = path.relative(normalizedPkgPath, normalizedFilename);

if (!relativePath.startsWith('..')) {
SFPLogger.log(`Found change(s) in ${filename}`, LoggerLevel.TRACE, this.logger);
return { isToBeBuilt: true, reason: `Found change(s) in package`, tag: tag };
}
Expand Down
17 changes: 17 additions & 0 deletions packages/core/tests/package/PackageDiffImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ describe('Determines whether a given package has changed', () => {
let result = await packageDiffImpl.exec();
expect(result.isToBeBuilt).toEqual(true);
expect(result.reason).toEqual(`Found change(s) in package`);

packageDiffImpl = new PackageDiffImpl(new ConsoleLogger(), 'core-b', null);
result = await packageDiffImpl.exec();
expect(result.isToBeBuilt).toEqual(false);

});

it('should return true if package descriptor has changed', async () => {
Expand Down Expand Up @@ -187,6 +192,18 @@ const packageConfigJson: string = `
"PermSetC"
]
},
{
"path": "packages/domains/core-b",
"package": "core-b",
"default": false,
"versionName": "covax",
"versionNumber": "1.0.0.0",
"assignPermSetsPreDeployment": [
"PermSetA",
"PermSetB",
"PermSetC"
]
},
{
"path": "packages/frameworks/mass-dataload",
"package": "mass-dataload",
Expand Down

0 comments on commit 1d31cd3

Please sign in to comment.