https://github.com/cinderblock/test-npm-yarn-lifecycle-scripts
Repo for exploring what happens with Yarn/Npm Lifecycle Scripts
https://github.com/cinderblock/test-npm-yarn-lifecycle-scripts
Last synced: 2 months ago
JSON representation
Repo for exploring what happens with Yarn/Npm Lifecycle Scripts
- Host: GitHub
- URL: https://github.com/cinderblock/test-npm-yarn-lifecycle-scripts
- Owner: cinderblock
- Created: 2022-12-22T00:33:18.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-23T00:48:28.000Z (over 3 years ago)
- Last Synced: 2025-01-28T02:16:05.212Z (over 1 year ago)
- Language: JavaScript
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Test Lifecycle Scripts with Npm, Yarn, et al.
Simple repo to test which lifecycle scripts are run when using `npm`, `yarn`, and `pnpm` to install/setup this package in various ways.
## Test method
1. Setup `package.json` with lifecycle scripts to be shared between package manager
- `prepare`
- `prepublish`
- `prepublishOnly`
- `prepack`
- `postpack`
- `dependencies`
- `postinstall`
1. Run [various standard package manager commands](.github/workflows/test.yml) via [GitHub Actions](https://github.com/cinderblock/test-npm-yarn-lifecycle-scripts/actions)
- `npm install`
- `npm install `
- `npm pack`
- `yarn install`
- `yarn add `
- `yarn pack`
- `pnpm install`
- `pnpm add `
- `pnpm pack`
1. Manually inspect logs to see which scripts were run and how
- Open `output.txt`, where possible, to see which lines were added to the file
- Open output of main command and see if "Ran script:" message appears
- Check `/node_modules/package-prepare` to see which files were included with package (did `.npmignore` work?)
1. Record results in table below
## Results
_Which lifecycle scripts were run? Which files were included in the package?_
| Package Manager | `.npmignore` | Add as Dependency | Initial Setup | Pack |
| --------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------ |
| npm | ✅ _(4)_ | ✖️postinstall
_⏭️(in `~/.npm/_cacache`)_
✖️prepublish
✖️prepare
✖️prepare
✖️postinstall
_⏭️(in `./node_modules`)_ | 👀postinstall
👀prepublish
👀prepare | 👀prepack
✖️prepare
👀postpack |
| pnpm | ❌ _(12)_ | ✖️postinstall
_⏭️(in `/tmp`)_
✖️prepublish
✖️prepare
👀postinstall
_⏭️(in `./node_modules`)_ | 👀postinstall
👀prepare | 👀prepublish
👀prepare
👀prepublishOnly
👀prepack
👀postpack |
| yarn | ✅ _(4)_ | 👀postinstall
_⏭️(in `~/.cache/yarn`)_
👀prepare
✖️postinstall
_⏭️(in `./node_modules`)_ | 👀postinstall
👀prepublish
👀prepare | 👀prepack
👀postpack |
| yarn PnP | ❓
_(`nodeLinker`)_ | _Inferred, no `output.txt`._
👀postinstall
👀prepare | _Not tested_ | _Not tested_ |
| yarn 2 | ✅
_(`nodeLinker`)_ | ✖️postinstall
_⏭️(in `/tmp`)_
👀prepack
👀postpack
✖️postinstall
_⏭️(in `./node_modules`)_ | _Not tested_ | _Not tested_ |
| yarn 3 | ✅
_(`nodeLinker`)_ | ✖️postinstall
_⏭️(in `/tmp`)_
👀prepack
👀postpack
✖️postinstall
_⏭️(in `./node_modules`)_ | _Not tested_ | _Not tested_ |
_👀/✖️ indicates associated logs were printed to terminal_
### Questions
1. Why does `npm install ` run the `prepare` script twice?
1. Why does `yarn install ` run the `postinstall` script twice but only outputs once?
1. Why does `npm pack` run both scripts, but the `prepare` script's output is never printed?
1. Why doesn't `pnpm` respect `.npmignore`&`package.json#files` field?
1. Why is `pnpm` a different order than `npm`?
1. How is a package installed with "PnP" supposed to modify its own files?
1. **Which script(s) should be set so that a package can be consistently installed and setup in all package managers?**