Files
pnpm/pnpm11/installing/deps-resolver/test/replaceVersionInPref.test.ts
Zoltan Kochan bb09b5084b feat: support selecting and refreshing registry revisions (#14175)
Implement explicit registry revision selection and revision-only updates from the current revisions RFC.

Parse exact +rN selectors across npm, JSR, aliases, and named registries. Validate historical artifacts against strict integrity-addressed metadata, overlay only immutable manifest fields, and avoid metadata requests during frozen installs unless an active policy requires them.

Add update --patches to refresh artifacts at the currently locked package versions while preserving explicit revision pins and manifest ranges. Mirror the behavior in the Rust CLI, force reimport when the artifact changes under the same package identity, and make pnpr expose only safe rewritten revision histories.

Follow-up to https://github.com/pnpm/pnpm/pull/13475.
Related to https://github.com/pnpm/rfcs/pull/19.
2026-08-26 01:58:44 +02:00

42 lines
2.8 KiB
TypeScript

import { expect, test } from '@jest/globals'
import { replaceVersionInBareSpecifier } from '../lib/replaceVersionInBareSpecifier.js'
test('replaceVersionInBareSpecifier()', () => {
expect(replaceVersionInBareSpecifier('^1.0.0', '1.1.0')).toBe('1.1.0')
expect(replaceVersionInBareSpecifier('npm:foo@^1.0.0', '1.1.0')).toBe('npm:foo@1.1.0')
expect(replaceVersionInBareSpecifier('npm:@foo/bar@^1.0.0', '1.1.0')).toBe('npm:@foo/bar@1.1.0')
expect(replaceVersionInBareSpecifier('npm:foo', '1.1.0')).toBe('npm:foo@1.1.0')
expect(replaceVersionInBareSpecifier('npm:@foo/bar', '1.1.0')).toBe('npm:@foo/bar@1.1.0')
expect(replaceVersionInBareSpecifier('jsr:^1.0.0', '1.1.0')).toBe('jsr:1.1.0')
expect(replaceVersionInBareSpecifier('jsr:@foo/bar@^1.0.0', '1.1.0')).toBe('jsr:@foo/bar@1.1.0')
expect(replaceVersionInBareSpecifier('jsr:@foo/bar', '1.1.0')).toBe('jsr:@foo/bar@1.1.0')
})
test('replaceVersionInBareSpecifier() applies the fast path to configured named-registry prefixes', () => {
// The caller (deps-resolver) supplies the merged set of named-registry
// prefixes — built-in `gh:` and any user-defined aliases — so the locked
// version can be pasted in without re-fetching metadata.
const prefixes = ['gh:', 'work:']
expect(replaceVersionInBareSpecifier('gh:^1.0.0', '1.1.0', prefixes)).toBe('gh:1.1.0')
expect(replaceVersionInBareSpecifier('gh:@acme/foo@^1.0.0', '1.1.0', prefixes)).toBe('gh:@acme/foo@1.1.0')
expect(replaceVersionInBareSpecifier('gh:foo', '1.1.0', prefixes)).toBe('gh:foo@1.1.0')
expect(replaceVersionInBareSpecifier('gh:@acme/foo', '1.1.0', prefixes)).toBe('gh:@acme/foo@1.1.0')
expect(replaceVersionInBareSpecifier('work:@corp/lib@^2.0.0', '2.1.0', prefixes)).toBe('work:@corp/lib@2.1.0')
})
test('replaceVersionInBareSpecifier() leaves unrecognized prefixes untouched', () => {
// Other resolvers (workspace, file/link, catalog, git, tarball) own these
// schemes; the npm-style version replacer must not rewrite them. An alias
// that isn't in the supplied named-registry set also falls through.
expect(replaceVersionInBareSpecifier('workspace:^1.0.0', '1.1.0')).toBe('workspace:^1.0.0')
expect(replaceVersionInBareSpecifier('workspace:./pkg', '1.1.0')).toBe('workspace:./pkg')
expect(replaceVersionInBareSpecifier('file:./pkg', '1.1.0')).toBe('file:./pkg')
expect(replaceVersionInBareSpecifier('link:../pkg', '1.1.0')).toBe('link:../pkg')
expect(replaceVersionInBareSpecifier('catalog:', '1.1.0')).toBe('catalog:')
expect(replaceVersionInBareSpecifier('github:owner/repo', '1.1.0')).toBe('github:owner/repo')
expect(replaceVersionInBareSpecifier('https://example.com/tarball.tgz', '1.1.0')).toBe('https://example.com/tarball.tgz')
expect(replaceVersionInBareSpecifier('gh:^1.0.0', '1.1.0', [])).toBe('gh:^1.0.0')
expect(replaceVersionInBareSpecifier('work:^1.0.0', '1.1.0', ['gh:'])).toBe('work:^1.0.0')
})