Package Exports
- yarn-plugin-lifecycle-hooks
- yarn-plugin-lifecycle-hooks/index.cjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (yarn-plugin-lifecycle-hooks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
yarn-plugin-lifecycle-hooks
Yarn Berry plugin that restores npm-style pre<script> and post<script> lifecycle hooks.
Yarn Berry (v2+) intentionally dropped automatic execution of pre/post scripts. This plugin brings them back.
Install
From GitHub (recommended)
yarn plugin import https://raw.githubusercontent.com/RoiDayan1/yarn-plugin-lifecycle-hooks/main/index.cjsThis downloads the plugin into .yarn/plugins/ and updates .yarnrc.yml automatically.
From a local file
yarn plugin import ./index.cjsUsage
Once installed, define pre<script> and post<script> entries in your package.json and they will run automatically:
{
"scripts": {
"prebuild": "echo 'before build'",
"build": "tsc",
"postbuild": "echo 'after build'",
"pretest": "echo 'before test'",
"test": "jest",
"posttest": "echo 'after test'"
}
}yarn build
# Runs: prebuild → build → postbuild
yarn test
# Runs: pretest → test → posttestHow it works
- Before the main script runs, if
pre<scriptName>exists inpackage.json, it is executed. - After the main script succeeds, if
post<scriptName>exists, it is executed. - CLI arguments are forwarded only to the main script — pre/post hooks receive no arguments.
- If a pre-script or the main script fails (non-zero exit), execution stops and the exit code is propagated.
- Built-in lifecycle scripts that Yarn already handles (
preinstall,postinstall,prepublish, etc.) are skipped to avoid double-firing. - Works with colon-separated script names too (e.g.
premy:task/postmy:task).
Uninstall
Remove the plugin entry from .yarnrc.yml and delete the file from .yarn/plugins/.
License
MIT