Skip to content

Commit

Permalink
Merge pull request #4281 from iclanton/pnpm8-non-workspace-alias
Browse files Browse the repository at this point in the history
[rush] Fix an issue where a pnpm-lock file would fail to parse if a project used a package alias in a repo using pnpm 8.
  • Loading branch information
dmichon-msft committed Aug 15, 2023
2 parents 10db039 + 83f9af2 commit 2e5c69f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix an issue where a pnpm-lock file would fail to parse if a project used a package alias in a repo using pnpm 8.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
6 changes: 4 additions & 2 deletions libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,14 @@ export function parsePnpmDependencyKey(
// Example: "path.pkgs.visualstudio.com/@scope/depame/1.4.0" --> 0="@scope/depame" 1="1.4.0"
// Example: "/isarray/2.0.1" --> 0="isarray" 1="2.0.1"
// Example: "/sinon-chai/2.8.0/chai@3.5.0+sinon@1.17.7" --> 0="sinon-chai" 1="2.8.0/chai@3.5.0+sinon@1.17.7"
// Example: "/typescript@5.1.6" --> 0=typescript 1="5.1.6"
// Example: 1.2.3_peer-dependency@.4.5.6 --> no match
// Example: 1.2.3_@scope+peer-dependency@.4.5.6 --> no match
// Example: 1.2.3(peer-dependency@.4.5.6) --> no match
// Example: 1.2.3(@scope/peer-dependency@.4.5.6) --> no match
const packageNameMatch: RegExpMatchArray | null =
/^[^\/]*(?<!\([^\(]*)\/((?:@[^\/]+\/)?[^\/]+)\/(.*)$/.exec(dependencyKey);
const packageNameMatch: RegExpMatchArray | null = /^[^\/(]*\/((?:@[^\/(]+\/)?[^\/(]+)[\/@](.*)$/.exec(
dependencyKey
);
if (packageNameMatch) {
parsedPackageName = packageNameMatch[1];
parsedInstallPath = packageNameMatch[2];
Expand Down
15 changes: 13 additions & 2 deletions libraries/rush-lib/src/logic/pnpm/test/PnpmShrinkwrapFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,26 @@ describe(PnpmShrinkwrapFile.name, () => {
);
});

it('Supports aliased package specifiers', () => {
it('Supports aliased package specifiers (v5)', () => {
const parsedSpecifier: DependencySpecifier | undefined = parsePnpmDependencyKey(
SCOPED_DEPENDENCY_NAME,
`/${DEPENDENCY_NAME}/${VERSION}`
);
expect(parsedSpecifier).toBeDefined();
expect(parsedSpecifier!.specifierType).toBe(DependencySpecifierType.Alias);
expect(parsedSpecifier!.packageName).toBe(SCOPED_DEPENDENCY_NAME);
expect(parsedSpecifier!.versionSpecifier).toMatchInlineSnapshot(`"npm:dependency_name@1.4.0"`);
expect(parsedSpecifier!.versionSpecifier).toMatchInlineSnapshot(`"npm:${DEPENDENCY_NAME}@${VERSION}"`);
});

it('Supports aliased package specifiers (v6)', () => {
const parsedSpecifier: DependencySpecifier | undefined = parsePnpmDependencyKey(
SCOPED_DEPENDENCY_NAME,
`/${DEPENDENCY_NAME}@${VERSION}`
);
expect(parsedSpecifier).toBeDefined();
expect(parsedSpecifier!.specifierType).toBe(DependencySpecifierType.Alias);
expect(parsedSpecifier!.packageName).toBe(SCOPED_DEPENDENCY_NAME);
expect(parsedSpecifier!.versionSpecifier).toMatchInlineSnapshot(`"npm:${DEPENDENCY_NAME}@${VERSION}"`);
});

it('Supports URL package specifiers', () => {
Expand Down

0 comments on commit 2e5c69f

Please sign in to comment.