diff --git a/.changeset/curvy-tips-doubt.md b/.changeset/curvy-tips-doubt.md new file mode 100644 index 0000000000..38ec3d1b61 --- /dev/null +++ b/.changeset/curvy-tips-doubt.md @@ -0,0 +1,6 @@ +--- +"@pnpm/which-version-is-pinned": patch +"pnpm": patch +--- + +When updating dependencies, preserve the range prefix in aliased dependencies. So `npm:foo@1.0.0` becomes `npm:foo@1.1.0`. diff --git a/packages/which-version-is-pinned/src/index.ts b/packages/which-version-is-pinned/src/index.ts index 6ff6d964b3..9810225f9d 100644 --- a/packages/which-version-is-pinned/src/index.ts +++ b/packages/which-version-is-pinned/src/index.ts @@ -4,6 +4,10 @@ export function whichVersionIsPinned (spec: string) { const isWorkspaceProtocol = spec.startsWith('workspace:') if (isWorkspaceProtocol) spec = spec.slice('workspace:'.length) if (spec === '*') return isWorkspaceProtocol ? 'patch' : 'none' + if (spec.startsWith('npm:')) { + const index = spec.lastIndexOf('@') + spec = spec.slice(index + 1) + } const parsedRange = parseRange(spec) if (parsedRange.length !== 1) return undefined const versionObject = parsedRange[0] diff --git a/packages/which-version-is-pinned/test/index.ts b/packages/which-version-is-pinned/test/index.ts index cdb2f4cd9a..7e675567b5 100644 --- a/packages/which-version-is-pinned/test/index.ts +++ b/packages/which-version-is-pinned/test/index.ts @@ -6,6 +6,11 @@ test.each([ ['1.0.0', 'patch'], ['*', 'none'], ['workspace:^1.0.0', 'major'], + ['npm:foo@1.0.0', 'patch'], + ['npm:@foo/foo@1.0.0', 'patch'], + ['npm:foo@^1.0.0', 'major'], + ['npm:@foo/foo@^1.0.0', 'major'], + ['npm:@pnpm.e2e/qar@100.0.0', 'patch'], ])('whichVersionIsPinned()', (spec, expectedResult) => { expect(whichVersionIsPinned(spec)).toEqual(expectedResult) }) diff --git a/pnpm/test/update.ts b/pnpm/test/update.ts index c42d2c52fc..d1fe0194fb 100644 --- a/pnpm/test/update.ts +++ b/pnpm/test/update.ts @@ -399,7 +399,7 @@ test('recursive update --latest specific dependency on projects that do not shar const manifest1 = await readPackageJsonFromDir(path.resolve('project-1')) expect(manifest1.dependencies).toStrictEqual({ - alias: 'npm:@pnpm.e2e/qar@^100.1.0', // this might be not correct + alias: 'npm:@pnpm.e2e/qar@100.1.0', '@pnpm.e2e/dep-of-pkg-with-1-dep': '100.0.0', '@pnpm.e2e/foo': '^100.1.0', }) @@ -574,7 +574,7 @@ test('recursive update --latest specific dependency on projects with a shared a const manifest1 = await readPackageJsonFromDir(path.resolve('project-1')) expect(manifest1.dependencies).toStrictEqual({ - alias: 'npm:@pnpm.e2e/qar@^100.1.0', // this might be incorrect + alias: 'npm:@pnpm.e2e/qar@100.1.0', '@pnpm.e2e/dep-of-pkg-with-1-dep': '100.0.0', '@pnpm.e2e/foo': '100.1.0', })