mirror of
https://github.com/pnpm/pnpm.git
synced 2026-06-28 01:45:30 -04:00
* fix: preserve user-defined npm_config_* env vars in lifecycle scripts * fix: use released `@pnpm/npm-lifecycle` and port npm_config_* filter to pacquet Pin the catalog to the released `@pnpm/npm-lifecycle` ^1100.0.0 instead of a mutable PR-head ref, regenerating the lockfile to the immutable registry tarball. Port the upstream env filter to pacquet's make_env so user-defined npm_config_* vars (e.g. npm_config_platform_arch) survive lifecycle scripts while (npm|pnpm)_config_* auth keys are still stripped, matching `@pnpm/npm-lifecycle` 9e2ac78148. Harden the new TS test to save/restore npm_config_platform_arch. * test(executor): restore env vars to pre-test value in lifecycle EnvGuard The guard removed the seeded var unconditionally on drop, which would discard any value the process env already had. Capture the original via var_os and restore it (or remove only when originally absent). --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
@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