mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-21 13:12:46 -04:00
Two follow-ups from the upstream CI run on canora.11: 1. `mirrorFilesIntoTarget` only mkdir'd intermediate sub-directories (collected via `path.dirname(relPath)`), so any workspace package with only top-level files (e.g. `main.js`) ended up calling unlinkSync against a path whose parent target dir didn't exist yet — failing three pre-existing `inject local packages and relink them after build` tests on Linux. Pre-create the target dir itself before the sub-dir loop so top-level relPaths are covered. 2. The catch around unlinkSync used `err instanceof Error` to narrow before reading `.code`. That check is unreliable across bundler / realm boundaries (the bundled pnpm CLI is one artifact running under Node's experimental-vm-modules in tests, where Error identity can diverge). Match the pattern used elsewhere in the pnpm tree (bins.linker, modules-yaml, bins.resolver) and cast directly to `NodeJS.ErrnoException`, which is what those call sites do. Also corrects the bin-having-dep regression test to use `prepare` (which pnpm runs during install) instead of `prepublishOnly` (only fires during publish). The original test name is unchanged — the test still asserts the same behaviour, just with a lifecycle script that actually runs in the install path being tested.
@pnpm/exec.lifecycle
Package lifecycle hook runner
Installation
pnpm add @pnpm/logger @pnpm/exec.lifecycle
Usage
import runLifecycleHook, {runPostinstallHooks} from '@pnpm/exec.lifecycle'
const targetPkgRoot = path.resolve('node_modules/target-pkg')
const pkg = require(path.join(targetPkgRoot, 'package.json'))
// Run a specific hook
await runLifecycleHook('preinstall', pkg, {
pkgId: 'target-pkg/1.0.0',
pkgRoot: targetPkgRoot,
rawConfig: {},
rootModulesDir: path.resolve('node_modules'),
unsafePerm: true,
})
// Run all install hooks
await runPostinstallHooks({
pkgId: 'target-pkg/1.0.0',
pkgRoot: targetPkgRoot,
rawConfig: {},
rootModulesDir: path.resolve('node_modules'),
unsafePerm: true,
})
API
runLifecycleHook(stage, packageManifest, opts): Promise<void>
runPostinstallHooks(opts): Promise<void>
License
MIT