Files
pnpm/hooks/read-package-hook/test/createReadPackageHook.ts
Zoltan Kochan 4819fb4e66 fix(pacquet): match pnpm lockfile resolution (#12372)
## 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.
2026-06-13 15:07:59 +02:00

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',
},
})
})