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

Commit 1d31cd3

Browse files
fix(packagediff): fix packages being built when the path to package start 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
1 parent 7c5d9d4 commit 1d31cd3

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

packages/core/src/package/diff/PackageDiffImpl.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ export default class PackageDiffImpl {
7373

7474
// Check whether the package has been modified
7575
for (let filename of modified_files) {
76-
if (filename.includes(path.normalize(pkgDescriptor.path))) {
76+
77+
let normalizedPkgPath = path.normalize(pkgDescriptor.path);
78+
let normalizedFilename = path.normalize(filename);
79+
80+
let relativePath = path.relative(normalizedPkgPath, normalizedFilename);
81+
82+
if (!relativePath.startsWith('..')) {
7783
SFPLogger.log(`Found change(s) in ${filename}`, LoggerLevel.TRACE, this.logger);
7884
return { isToBeBuilt: true, reason: `Found change(s) in package`, tag: tag };
7985
}

packages/core/tests/package/PackageDiffImpl.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ describe('Determines whether a given package has changed', () => {
7474
let result = await packageDiffImpl.exec();
7575
expect(result.isToBeBuilt).toEqual(true);
7676
expect(result.reason).toEqual(`Found change(s) in package`);
77+
78+
packageDiffImpl = new PackageDiffImpl(new ConsoleLogger(), 'core-b', null);
79+
result = await packageDiffImpl.exec();
80+
expect(result.isToBeBuilt).toEqual(false);
81+
7782
});
7883

7984
it('should return true if package descriptor has changed', async () => {
@@ -187,6 +192,18 @@ const packageConfigJson: string = `
187192
"PermSetC"
188193
]
189194
},
195+
{
196+
"path": "packages/domains/core-b",
197+
"package": "core-b",
198+
"default": false,
199+
"versionName": "covax",
200+
"versionNumber": "1.0.0.0",
201+
"assignPermSetsPreDeployment": [
202+
"PermSetA",
203+
"PermSetB",
204+
"PermSetC"
205+
]
206+
},
190207
{
191208
"path": "packages/frameworks/mass-dataload",
192209
"package": "mass-dataload",

0 commit comments

Comments
 (0)