mirror of
https://github.com/pnpm/pnpm.git
synced 2026-06-28 09:55:39 -04:00
## Summary - Match pacquet peer-resolution and lockfile output to pnpm for transitive optional peer variants. - Apply pnpm's Yarn compatibility package extensions in pacquet, with `ignoreCompatibilityDb` support. - Add regression coverage on both the pnpm resolver test and pacquet resolver/install paths. Fixes pnpm/pnpm#12330.
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import { expect, jest, test } from '@jest/globals'
|
|
import type { ReadPackageHook } from '@pnpm/types'
|
|
|
|
import { createReadPackageHook, getEffectivePackageExtensions } from '../lib/createReadPackageHook.js'
|
|
|
|
test('createReadPackageHook() is passing directory to all hooks', async () => {
|
|
const hook1 = jest.fn(((manifest) => manifest) as ReadPackageHook)
|
|
const hook2 = jest.fn(((manifest) => manifest) as ReadPackageHook)
|
|
const readPackageHook = createReadPackageHook({
|
|
ignoreCompatibilityDb: true,
|
|
lockfileDir: '/foo',
|
|
readPackageHook: [hook1, hook2],
|
|
})
|
|
const manifest = {}
|
|
const dir = '/bar'
|
|
await readPackageHook!(manifest, dir)
|
|
expect(hook1).toHaveBeenCalledWith(manifest, dir)
|
|
expect(hook2).toHaveBeenCalledWith(manifest, dir)
|
|
})
|
|
|
|
test('createReadPackageHook() runs the custom hook before the version overrider', async () => {
|
|
const hook = jest.fn(((manifest) => ({
|
|
...manifest,
|
|
dependencies: {
|
|
...manifest.dependencies,
|
|
react: '18',
|
|
},
|
|
})) as ReadPackageHook)
|
|
const readPackageHook = createReadPackageHook({
|
|
ignoreCompatibilityDb: true,
|
|
lockfileDir: '/foo',
|
|
readPackageHook: [hook],
|
|
overrides: [
|
|
{
|
|
targetPkg: {
|
|
name: 'react',
|
|
},
|
|
newBareSpecifier: '16',
|
|
},
|
|
],
|
|
})
|
|
const manifest = {}
|
|
const dir = '/bar'
|
|
const updatedManifest = await readPackageHook!(manifest, dir)
|
|
expect(hook).toHaveBeenCalledWith(manifest, dir)
|
|
expect(updatedManifest).toStrictEqual({
|
|
dependencies: {
|
|
react: '16',
|
|
},
|
|
})
|
|
})
|
|
|
|
test('getEffectivePackageExtensions() merges duplicate compatibility selectors', () => {
|
|
expect(getEffectivePackageExtensions({})?.['gatsby-core-utils@<2.14.0-next.1']).toStrictEqual({
|
|
dependencies: {
|
|
'@babel/runtime': '^7.14.8',
|
|
got: '8.3.2',
|
|
},
|
|
})
|
|
})
|