bun
bun copied to clipboard
Lifecycle scripts of root project should be run in foreground.
What version of Bun is running?
1.0.17+5e60861c3
What platform is your computer?
Linux 5.15.133.1-microsoft-standard-WSL2 x86_64 x86_64
What steps can reproduce the bug?
Put this in a package.json file and run bun install
:
{
"name": "testbunscripts",
"module": "index.ts",
"type": "module",
"devDependencies": {
"bun-types": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"scripts": {
"postinstall": "echo 'Postinstall script!'",
"preinstall": "echo 'Preinstall script!'"
}
}
What is the expected behavior?
Lifecycle scripts preinstall
and postinstall
should run, as they do in npm, and as is specified in the Bun docs.
This is the output of npm showing that they run:
$ npm install
> preinstall
> echo 'Preinstall script!'
Preinstall script!
> postinstall
> echo 'Postinstall script!'
Postinstall script!
changed 1 package, and audited 3 packages in 2s
found 0 vulnerabilities
What do you see instead?
Lifecycle scripts are ignored:
$ bun install
bun install v1.0.17 (5e60861c)
Checked 2 installs across 3 packages (no changes) [22.00ms]
Additional information
This was working in bun v1.0.15 and recently broke when I upgraded to v1.0.17. Presumably related to the changes to lifecycle scripts.
The reason I believe this is a bug and not intended, is that the docs state the following: https://bun.sh/docs/cli/install
Running bun install will: ...
- Run your project's {pre|post}install and {pre|post}prepare scripts at the appropriate time. ...
They are being run, but as of 1.0.17 the logs are not printed unless an error occurs. We should change this to print for the root.
I landed here wondering the same thing. I thought my postinstall script wasn't running because I didn't see any output. Would be great for bun to include full output from root lifecycle scripts. Maybe also output a concise list of package names for which a lifecycle method was run.
there is a function runPackageScriptForeground
(which before 1.0.17 was named runPackageScript
)
we should use this instead of the lifecycle script runner that buffers the output and prints on error. but only for the root package and maybe workspace ones.
Also, in case of error, it would be nice to see colored output of the error. In my case I need to pass --verbose
for colors to work. (I'm runnning bun test <my-test>
in preinstall
.)
fixed in #9724 , and is available in v1.1.8