diff --git a/common/changes/@microsoft/rush/fix-look-by-path_2023-04-25-09-41.json b/common/changes/@microsoft/rush/fix-look-by-path_2023-04-25-09-41.json new file mode 100644 index 00000000000..d5b4c94712a --- /dev/null +++ b/common/changes/@microsoft/rush/fix-look-by-path_2023-04-25-09-41.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Fix an issue where the last character in a project's path is ignored when determining which files contribute to the project's cache ID.", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/logic/LookupByPath.ts b/libraries/rush-lib/src/logic/LookupByPath.ts index a848949f216..ce209f909e4 100644 --- a/libraries/rush-lib/src/logic/LookupByPath.ts +++ b/libraries/rush-lib/src/logic/LookupByPath.ts @@ -111,7 +111,7 @@ export class LookupByPath { } // Last segment - if (previousIndex + 1 < input.length) { + if (previousIndex < input.length) { yield { prefix: input.slice(previousIndex, input.length), index: input.length diff --git a/libraries/rush-lib/src/logic/test/LookupByPath.test.ts b/libraries/rush-lib/src/logic/test/LookupByPath.test.ts index 5b4cbeed881..2d56d082d58 100644 --- a/libraries/rush-lib/src/logic/test/LookupByPath.test.ts +++ b/libraries/rush-lib/src/logic/test/LookupByPath.test.ts @@ -20,6 +20,10 @@ describe(LookupByPath.iteratePathSegments.name, () => { const result = [...LookupByPath.iteratePathSegments('foo/bar/baz')]; expect(result).toEqual(['foo', 'bar', 'baz']); }); + it('returns correct last single character segment', () => { + const result = [...LookupByPath.iteratePathSegments('foo/a')]; + expect(result).toEqual(['foo', 'a']); + }); }); describe(LookupByPath.prototype.findChildPath.name, () => {