From ecbe2ea9658d7730b80f3ef6774b2476ab60dba4 Mon Sep 17 00:00:00 2001 From: GwanSik Kim Date: Wed, 14 Aug 2024 07:17:24 +0900 Subject: [PATCH] fix(exportable-manifest): replace semver in peerDependency with workspace protocol (#8383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close: #8355 Co-authored-by: 장지훈 <32415680+WhiteKiwi@users.noreply.github.com> * Update smooth-ravens-wave.md --------- Co-authored-by: 장지훈 <32415680+WhiteKiwi@users.noreply.github.com> Co-authored-by: Zoltan Kochan --- .changeset/smooth-ravens-wave.md | 6 ++++++ pkg-manifest/exportable-manifest/src/index.ts | 17 +++++++++-------- .../exportable-manifest/test/index.test.ts | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 .changeset/smooth-ravens-wave.md diff --git a/.changeset/smooth-ravens-wave.md b/.changeset/smooth-ravens-wave.md new file mode 100644 index 0000000000..4e5f8cf323 --- /dev/null +++ b/.changeset/smooth-ravens-wave.md @@ -0,0 +1,6 @@ +--- +"@pnpm/exportable-manifest": patch +pnpm: patch +--- + +Replace semver in peerDependency with workspace protocol [#8355](https://github.com/pnpm/pnpm/issues/8355). diff --git a/pkg-manifest/exportable-manifest/src/index.ts b/pkg-manifest/exportable-manifest/src/index.ts index 9169071fa8..2702e013c1 100644 --- a/pkg-manifest/exportable-manifest/src/index.ts +++ b/pkg-manifest/exportable-manifest/src/index.ts @@ -159,22 +159,23 @@ async function replaceWorkspaceProtocolPeerDependency (depName: string, depSpec: return depSpec } - // Dependencies with bare "*", "^", "~",">=",">","<=",< versions - const workspaceSemverRegex = /workspace:([\^~*]|>=|>|<=|<)/ + // Dependencies with bare "*", "^", "~",">=",">","<=", "<", version + const workspaceSemverRegex = /workspace:([\^~*]|>=|>|<=|<)?((\d+|[xX]|\*)(\.(\d+|[xX]|\*)){0,2})?/ const versionAliasSpecParts = workspaceSemverRegex.exec(depSpec) if (versionAliasSpecParts != null) { + const [, semverRangGroup = '', version] = versionAliasSpecParts + + if (version) { + return depSpec.replace('workspace:', '') + } + modulesDir = modulesDir ?? path.join(dir, 'node_modules') const manifest = await resolveManifest(depName, modulesDir) - - const [,semverRangGroup] = versionAliasSpecParts - const semverRangeToken = semverRangGroup !== '*' ? semverRangGroup : '' return depSpec.replace(workspaceSemverRegex, `${semverRangeToken}${manifest.version}`) } - depSpec = depSpec.replace('workspace:', '') - - return depSpec + return depSpec.replace('workspace:', '') } diff --git a/pkg-manifest/exportable-manifest/test/index.test.ts b/pkg-manifest/exportable-manifest/test/index.test.ts index e47b4231ea..12b89a1917 100644 --- a/pkg-manifest/exportable-manifest/test/index.test.ts +++ b/pkg-manifest/exportable-manifest/test/index.test.ts @@ -95,10 +95,15 @@ test('workspace deps are replaced', async () => { bar: 'workspace:@foo/bar@*', baz: 'workspace:baz@^', foo: 'workspace:*', + qux: 'workspace:^', + waldo: 'workspace:^', }, peerDependencies: { foo: 'workspace:>= || ^3.9.0', baz: '^1.0.0 || workspace:>', + bar: 'workspace:^3.0.0', + qux: 'workspace:^', + waldo: 'workspace:^1.x', }, } @@ -116,6 +121,14 @@ test('workspace deps are replaced', async () => { name: 'foo', version: '4.5.6', }, + { + name: 'qux', + version: '1.0.0-alpha-a.b-c-something+build.1-aef.1-its-okay', + }, + { + name: 'waldo', + version: '1.9.0', + }, ]) writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] }) @@ -131,10 +144,15 @@ test('workspace deps are replaced', async () => { bar: 'npm:@foo/bar@3.2.1', baz: '^1.2.3', foo: '4.5.6', + qux: '^1.0.0-alpha-a.b-c-something+build.1-aef.1-its-okay', + waldo: '^1.9.0', }, peerDependencies: { baz: '^1.0.0 || >1.2.3', foo: '>=4.5.6 || ^3.9.0', + bar: '^3.0.0', + qux: '^1.0.0-alpha-a.b-c-something+build.1-aef.1-its-okay', + waldo: '^1.x', }, }) })