Files
pnpm/config/reader/test/deprecatedVersionReferences.test.ts
Zoltan Kochan 894ea6af2c feat: deprecate $ version references in overrides (#12262)
Using the "$" syntax in overrides (e.g. "react": "$react") now emits a
deprecation warning. The syntax still resolves as before. Catalogs are the
recommended replacement: reference a catalog entry with the "catalog:"
protocol.

Refs pnpm/pnpm#12160
2026-06-08 14:00:05 +02:00

45 lines
1.2 KiB
TypeScript

import { beforeEach, expect, jest, test } from '@jest/globals'
jest.unstable_mockModule('@pnpm/logger', () => ({
globalWarn: jest.fn(),
}))
const { globalWarn } = await import('@pnpm/logger')
const { getOptionsFromPnpmSettings } = await import('../lib/getOptionsFromRootManifest.js')
beforeEach(() => {
jest.mocked(globalWarn).mockClear()
})
test('getOptionsFromPnpmSettings() warns about deprecated "$" version references and still resolves them', () => {
const options = getOptionsFromPnpmSettings(process.cwd(), {
overrides: {
foo: '$foo',
},
}, {
dependencies: {
foo: '^1.0.0',
},
})
expect(options.overrides).toStrictEqual({ foo: '^1.0.0' })
expect(globalWarn).toHaveBeenCalledTimes(1)
const warning = jest.mocked(globalWarn).mock.calls[0][0]
expect(warning).toContain('deprecated')
expect(warning).toContain('foo')
expect(warning).toContain('catalog:')
})
test('getOptionsFromPnpmSettings() does not warn when no "$" version references are used', () => {
getOptionsFromPnpmSettings(process.cwd(), {
overrides: {
foo: '^1.0.0',
bar: 'catalog:',
},
}, {
dependencies: {
foo: '^1.0.0',
},
})
expect(globalWarn).not.toHaveBeenCalled()
})