fix: path the project directory to the readPackage hook (#5475)

close #5443
This commit is contained in:
Zoltan Kochan
2022-10-10 18:54:23 +03:00
committed by GitHub
parent 96b507b73e
commit 8c3a0b2364
4 changed files with 27 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/hooks.read-package-hook": patch
---
The readPackageHooks should always get the project directory as the second argument.

View File

@@ -0,0 +1,5 @@
---
"pnpm": patch
---
It should be possible to override dependencies with local packages using overrides [#5443](https://github.com/pnpm/pnpm/issues/5443).

View File

@@ -61,6 +61,6 @@ export function createReadPackageHook (
}
const readPackageAndExtend = hooks.length === 1
? hooks[0]
: ((pkg: PackageManifest | ProjectManifest, dir: string) => pipeWith(async (f, res) => f(await res, dir), hooks as any)(pkg)) as ReadPackageHook // eslint-disable-line @typescript-eslint/no-explicit-any
: ((pkg: PackageManifest | ProjectManifest, dir: string) => pipeWith(async (f, res) => f(await res, dir), hooks as any)(pkg, dir)) as ReadPackageHook // eslint-disable-line @typescript-eslint/no-explicit-any
return readPackageAndExtend
}

View File

@@ -0,0 +1,16 @@
import { createReadPackageHook } from '../lib/createReadPackageHook'
test('createReadPackageHook() is passing directory to all hooks', async () => {
const hook1 = jest.fn((manifest) => manifest)
const hook2 = jest.fn((manifest) => manifest)
const readPackageHook = createReadPackageHook({
ignoreCompatibilityDb: true,
lockfileDir: '/foo',
readPackageHook: [hook1, hook2],
})
const manifest = {}
const dir = '/bar'
await readPackageHook!(manifest, dir)
expect(hook1).toBeCalledWith(manifest, dir)
expect(hook2).toBeCalledWith(manifest, dir)
})