mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-01 03:28:14 -05:00
51 lines
1.0 KiB
Markdown
51 lines
1.0 KiB
Markdown
# @pnpm/lifecycle
|
|
|
|
> Package lifecycle hook runner
|
|
|
|
<!--@shields('npm')-->
|
|
[](https://www.npmjs.com/package/@pnpm/lifecycle)
|
|
<!--/@-->
|
|
|
|
## Installation
|
|
|
|
```sh
|
|
pnpm add @pnpm/logger @pnpm/lifecycle
|
|
```
|
|
|
|
## Usage
|
|
|
|
```ts
|
|
import runLifecycleHook, {runPostinstallHooks} from '@pnpm/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
|