Skip to content

Commit

Permalink
fix: path the project directory to the readPackage hook (#5475)
Browse files Browse the repository at this point in the history
close #5443
  • Loading branch information
zkochan committed Oct 10, 2022
1 parent 96b507b commit 8c3a0b2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/great-dolls-collect.md
@@ -0,0 +1,5 @@
---
"@pnpm/hooks.read-package-hook": patch
---

The readPackageHooks should always get the project directory as the second argument.
5 changes: 5 additions & 0 deletions .changeset/kind-bottles-knock.md
@@ -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).
Expand Up @@ -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
}
16 changes: 16 additions & 0 deletions packages/hooks.read-package-hook/test/createReadPackageHook.ts
@@ -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)
})

0 comments on commit 8c3a0b2

Please sign in to comment.