From 1d31cd3f4fb348e20ccff00662ff380adee9393e Mon Sep 17 00:00:00 2001 From: Azlam <43767972+azlam-abdulsalam@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:49:34 +1100 Subject: [PATCH] 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 --- .../core/src/package/diff/PackageDiffImpl.ts | 8 +++++++- .../core/tests/package/PackageDiffImpl.test.ts | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/core/src/package/diff/PackageDiffImpl.ts b/packages/core/src/package/diff/PackageDiffImpl.ts index 4584caf3e..356d9f3f8 100644 --- a/packages/core/src/package/diff/PackageDiffImpl.ts +++ b/packages/core/src/package/diff/PackageDiffImpl.ts @@ -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 }; } diff --git a/packages/core/tests/package/PackageDiffImpl.test.ts b/packages/core/tests/package/PackageDiffImpl.test.ts index 781487743..69a44d44a 100644 --- a/packages/core/tests/package/PackageDiffImpl.test.ts +++ b/packages/core/tests/package/PackageDiffImpl.test.ts @@ -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 () => { @@ -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",