mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-27 10:30:58 -04:00
fix: hooks (#5534)
This commit is contained in:
5
.changeset/sixty-laws-relate.md
Normal file
5
.changeset/sixty-laws-relate.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/hooks.read-package-hook": patch
|
||||
---
|
||||
|
||||
The custom hooks should be executed after the peer dependency patcher hook.
|
||||
@@ -40,6 +40,11 @@ export function createReadPackageHook (
|
||||
if (!isEmpty(packageExtensions ?? {})) {
|
||||
hooks.push(createPackageExtender(packageExtensions!))
|
||||
}
|
||||
if (Array.isArray(readPackageHook)) {
|
||||
hooks.push(...readPackageHook)
|
||||
} else if (readPackageHook) {
|
||||
hooks.push(readPackageHook)
|
||||
}
|
||||
if (
|
||||
peerDependencyRules != null &&
|
||||
(
|
||||
@@ -50,11 +55,6 @@ export function createReadPackageHook (
|
||||
) {
|
||||
hooks.push(createPeerDependencyPatcher(peerDependencyRules))
|
||||
}
|
||||
if (Array.isArray(readPackageHook)) {
|
||||
hooks.push(...readPackageHook)
|
||||
} else if (readPackageHook) {
|
||||
hooks.push(readPackageHook)
|
||||
}
|
||||
|
||||
if (hooks.length === 0) {
|
||||
return undefined
|
||||
|
||||
@@ -14,3 +14,34 @@ test('createReadPackageHook() is passing directory to all hooks', async () => {
|
||||
expect(hook1).toBeCalledWith(manifest, dir)
|
||||
expect(hook2).toBeCalledWith(manifest, dir)
|
||||
})
|
||||
|
||||
test('createReadPackageHook() runs the custom hook before the peer rules hook', async () => {
|
||||
const hook = jest.fn((manifest) => ({
|
||||
...manifest,
|
||||
dependencies: { ...manifest.peerDependencies },
|
||||
}))
|
||||
const readPackageHook = createReadPackageHook({
|
||||
ignoreCompatibilityDb: true,
|
||||
lockfileDir: '/foo',
|
||||
readPackageHook: [hook],
|
||||
peerDependencyRules: {
|
||||
allowAny: ['*'],
|
||||
},
|
||||
})
|
||||
const manifest = {
|
||||
peerDependencies: {
|
||||
react: '16',
|
||||
},
|
||||
}
|
||||
const dir = '/bar'
|
||||
const updatedManifest = await readPackageHook!(manifest, dir)
|
||||
expect(hook).toBeCalledWith(manifest, dir)
|
||||
expect(updatedManifest).toStrictEqual({
|
||||
dependencies: {
|
||||
react: '16',
|
||||
},
|
||||
peerDependencies: {
|
||||
react: '*',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user