Skip to content

docs: list supported lifecycle scripts, note that npm's dependencies script is not implemented - #30249

Closed
robobun wants to merge 1 commit into
mainfrom
farm/084c10c9/docs-lifecycle-supported-scripts
Closed

robobun wants to merge 1 commit into
mainfrom
farm/084c10c9/docs-lifecycle-supported-scripts

Conversation

@robobun

@robobun robobun commented May 4, 2026 •

Copy link
Copy Markdown
Collaborator

What

Rewrite the top of docs/pm/lifecycle.mdx to list exactly which lifecycle scripts Bun runs, grouped by command, and to explicitly note that npm's dependencies script (and a few other npm hooks) are not invoked by Bun.

Why

The docs today linked out to npm's scripts page with "there are many others." A reader could reasonably read that and assume npm's dependencies script — which runs after node_modules changes — would run after bun add/bun remove. It does not.

The old "most common" bullet list also presented preuninstall and prepublishOnly as lifecycle scripts without qualifying which commands actually invoke them, which was misleading.

What now

The page now lists, by command, the exact set Bun supports:

  • bun install / add / remove / update: preinstall, install, postinstall, plus preprepare/prepare/postprepare for root, git:, github:, and (for prepare) workspace packages only (source: src/install/lockfile.zig:58, src/install/lockfile/Package/Scripts.zig:159)
  • bun publish / bun pm pack: prepublishOnly, prepack, prepare, postpack, publish, postpublish (source: src/cli/pack_command.zig:1259)
  • bun pm version: preversion, version, postversion (source: src/cli/pm_version_command.zig:74)

It explicitly calls out that npm package-manager hooks dependencies, preuninstall, and postuninstall are not invoked, and notes two Bun-specific behaviors surfaced in review:

  • Root install-time scripts run as a single batch after node_modules is populated (a divergence from npm's preinstall timing; source: src/install/PackageManager/install_with_manager.zig:935).
  • Generic pre<name> / post<name> wrappers still fire via bun run <name> (source: src/cli/run_command.zig:1763), so e.g. prerestart is reachable and is not listed as "not invoked."

Fixes #30247

Rebase note

Rebased onto current main, which had meanwhile restructured this file (editorial pass #33112 and the new "Behavior of the trustedDependencies fieldsection from #31027). Resolved by keeping all of main's content intact (thepostinstall, trustedDependencies+ behavior-table, and--ignore-scriptssections) and replacing only main's misleading intro bullet list with the new "Supported lifecycle scripts" section. The trust-summary sentence now links to main'strustedDependencies` section rather than restating the allow-list rules, so the two don't drift.

@coderabbitai

coderabbitai Bot commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Documentation now enumerates the exact npm lifecycle hooks Bun supports for install/add/remove/update, publish/pack, and version commands; states which npm hooks Bun does not invoke; clarifies prepare-hook scope and root script ordering; and limits dependency lifecycle execution to trusted or workspace packages.

Changes

Lifecycle Scripts Documentation

Layer / File(s) Summary
Content restructure
docs/pm/lifecycle.mdx
Replaces the previous generic "common scripts" list with a focused "Supported lifecycle scripts" section and link to the npm scripts reference.
Command-specific lists
docs/pm/lifecycle.mdx
Adds ordered, command-specific sequences for bun install/add/remove/update, for bun publish/bun pm pack, and for bun pm version (including preprepare/prepare/postprepare framing).
Prepare & root ordering
docs/pm/lifecycle.mdx
Clarifies that prepare-family hooks run for root/git/GitHub packages only and that root install-time scripts execute as a single batch after node_modules is populated and dependency scripts complete.
Trust constraint
docs/pm/lifecycle.mdx
Specifies that dependency lifecycle scripts run only for packages on Bun’s default trusted list or listed in trustedDependencies (workspace packages are always trusted).
Non-invoked scripts
docs/pm/lifecycle.mdx
Explicitly documents that other npm lifecycle hooks (e.g., dependencies, preuninstall, postuninstall, and various service hooks) are not invoked by Bun.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: documenting supported lifecycle scripts and explicitly noting that npm's dependencies script is not implemented.
Linked Issues check ✅ Passed The PR directly addresses all requirements from issue #30247: it enumerates exactly which lifecycle scripts Bun supports by command and explicitly lists unsupported hooks including dependencies.
Out of Scope Changes check ✅ Passed All changes are directly scoped to addressing issue #30247; only the documentation file is modified with no extraneous alterations.
Description check ✅ Passed The description clearly explains the change, motivation, and implementation details, though it omits the template's verification section.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/pm/lifecycle.mdx (1)

63-63: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Replace the stale placeholder package name.

my-trusted-package doesn't match the node-sass example above, so this reads like copied placeholder text instead of a concrete instruction.

✏️ Suggested text cleanup
-Once added to trustedDependencies, install/re-install the package. Bun will read this field and run lifecycle scripts for `my-trusted-package`.
+Once added to `trustedDependencies`, reinstall the package. Bun will then run lifecycle scripts for that package.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/pm/lifecycle.mdx` at line 63, The sentence uses a stale placeholder
`my-trusted-package`; update it to match the earlier example package
(`node-sass`) or whichever concrete package was used above so the instruction
reads consistently (e.g., change "lifecycle scripts for `my-trusted-package`" to
"lifecycle scripts for `node-sass`"); locate the occurrence near the
`trustedDependencies` explanation and replace the placeholder package name
accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/pm/lifecycle.mdx`:
- Line 31: Update the sentence "Lifecycle scripts of installed dependencies only
run for packages listed in `trustedDependencies`" to clarify that scripts run
for packages that are either listed in `trustedDependencies` or included in
Bun's built-in npm package allowlist; mention both the explicit
trustedDependencies setting and Bun's internal allowlist so readers understand
both paths that permit dependency lifecycle scripts to run.

---

Outside diff comments:
In `@docs/pm/lifecycle.mdx`:
- Line 63: The sentence uses a stale placeholder `my-trusted-package`; update it
to match the earlier example package (`node-sass`) or whichever concrete package
was used above so the instruction reads consistently (e.g., change "lifecycle
scripts for `my-trusted-package`" to "lifecycle scripts for `node-sass`");
locate the occurrence near the `trustedDependencies` explanation and replace the
placeholder package name accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 48baed5b-d63c-467a-9c40-61b456d98784

📥 Commits

Reviewing files that changed from the base of the PR and between 0a7bed5 and 71dc593.

📒 Files selected for processing (1)
  • docs/pm/lifecycle.mdx

Comment thread docs/pm/lifecycle.mdx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/pm/lifecycle.mdx`:
- Line 31: Update the sentence "Lifecycle scripts of installed dependencies only
run for packages on Bun's default trusted list or in your project's
`trustedDependencies`" to also mention workspace/monorepo packages: clarify that
lifecycle scripts run for packages on Bun's default trusted list, packages
listed in `trustedDependencies`, and packages that are part of the current
workspace/monorepo (i.e., local workspace packages resolved by the installer).
Keep the mention concise and add an inline pointer to the workspace exception so
readers know workspace packages are allowed by the install logic.
- Around line 12-19: The current text implies preprepare/prepare/postprepare
always run during bun install/add/remove/update; update the wording so it
clarifies these hooks are conditional — only queued/executed for packages with
resolution types "git", "github", or "root" (i.e., non-registry resolutions) and
are not run for normal registry installs; locate the section listing the hooks
(references: preprepare, prepare, postprepare) and add a short qualifying
sentence noting the resolution-type condition and when those hooks are skipped.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: cc9d2c66-09ce-4c1a-8f75-231f3b66758b

📥 Commits

Reviewing files that changed from the base of the PR and between 71dc593 and d35dd37.

📒 Files selected for processing (1)
  • docs/pm/lifecycle.mdx

Comment thread docs/pm/lifecycle.mdx Outdated
Comment thread docs/pm/lifecycle.mdx Outdated
Comment thread docs/pm/lifecycle.mdx Outdated
Comment thread docs/pm/lifecycle.mdx Outdated
Comment thread docs/pm/lifecycle.mdx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/pm/lifecycle.mdx`:
- Line 42: Update the sentence that begins "Lifecycle scripts of installed
dependencies..." to explicitly mention the `from_git` trust path so readers know
git- and github-sourced packages can also be trusted: change the wording to
state that lifecycle scripts run for packages on Bun's default trusted list,
packages declared in `trustedDependencies`, workspace packages, and packages
installed via the `from_git`/`git:`/`github:` install path; reference the
`from_git` token in the sentence so the doc matches the install logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 31b0022e-88a9-45a7-a12f-0c31a16872c2

📥 Commits

Reviewing files that changed from the base of the PR and between d35dd37 and 634a6f1.

📒 Files selected for processing (1)
  • docs/pm/lifecycle.mdx

Comment thread docs/pm/lifecycle.mdx Outdated
@robobun

robobun commented May 4, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 9:32 AM PT - Jun 30th, 2026

✅ @robobun, your commit 2014cc0b7047c3d666e0802bca9d730e94079e59 passed in Build #67261! 🎉


🧪   To try this PR locally:

bunx bun-pr 30249

That installs a local version of the PR into your bun-30249 executable, so you can run:

bun-30249 --bun

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — all prior feedback addressed; the remaining coderabbit note about a from_git trust path is a false positive (no such bypass exists in hasTrustedDependency / PackageInstaller.zig:1171), so line 42 is accurate as written.

Extended reasoning...

Overview

Docs-only change to docs/pm/lifecycle.mdx that replaces a vague "common scripts" list with a precise, source-verified enumeration of which lifecycle hooks Bun runs per command (install/add/remove/update, publish/pack, pm version), which resolution types get the prepare-family hooks, the root-script timing divergence from npm, and which npm hooks Bun never invokes. No code, config, or build changes.

Security risks

None. Pure documentation; does not alter trust gating, script execution, or any runtime behavior.

Level of scrutiny

Low-to-moderate — docs accuracy matters here since the page describes security-relevant behavior (when arbitrary scripts run), but every claim has been cross-checked against source by the author with file:line citations, and I independently re-verified the install-time script ordering (install_with_manager.zig), prepare-hook gating (Scripts.zig:159), workspace trust short-circuit (PackageInstaller.zig:1171), and hasTrustedDependency (lockfile.zig:2126-2134).

Other factors

  • All three of my earlier inline comments (root preinstall timing, default trusted list wording, prerestart/prestop examples) were addressed in d35dd37 / 334e260 / 634a6f1 and are resolved.
  • The one unresolved coderabbit comment claims git/github deps have a separate from_git trust path. I grepped src/install and read hasTrustedDependency: there is no such path — git/github deps go through the same is_trusted gate and are excluded from the default list (which is npm-only). The existing <Note> further down the page already documents this correctly. The sentence at line 42 is accurate and should not be changed per that suggestion.
  • The inline 🔵 pre-existing note about the postinstall→preinstall copy/paste typo in Scripts.zig:137 is a real code bug but is unrelated to this docs PR and explicitly flagged as not blocking.
  • docs/pm/ has no CODEOWNERS entry.

Comment thread docs/pm/lifecycle.mdx
…ies` script is not implemented

Users following the link out to npm's scripts docs could see npm's
`dependencies` hook (which runs after node_modules changes) and
reasonably assume Bun runs it too. It doesn't, and neither do
`preuninstall`, `postuninstall`, etc.

Replace the misleading "most common" bullet list with a precise
"Supported lifecycle scripts" section grouped by command:

- install/add/remove/update: preinstall, install, postinstall, and
  preprepare/prepare/postprepare (the prepare family only runs for
  root, git:, github:, and workspace packages, not npm tarballs)
- publish/pack: prepublishOnly, prepack, prepare, postpack, publish,
  postpublish
- pm version: preversion, version, postversion

Also note that root install-time scripts run as a single batch after
node_modules is populated (a divergence from npm's preinstall timing),
that generic pre<name>/post<name> wrappers still fire via bun run, and
that workspace packages are always trusted.

Fixes #30247
@robobun
robobun force-pushed the farm/084c10c9/docs-lifecycle-supported-scripts branch from 634a6f1 to 2014cc0 Compare June 30, 2026 16:31
@mintlify

mintlify Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
bun 🟢 Ready View Preview Jun 30, 2026, 4:34 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — docs-only change, all prior feedback addressed and source-verified.

Extended reasoning...

Overview

This PR rewrites the intro of docs/pm/lifecycle.mdx to enumerate exactly which npm lifecycle scripts Bun invokes, grouped by command (install/add/remove/update, publish/pm pack, pm version), and explicitly calls out hooks Bun does not run (dependencies, preuninstall, postuninstall). It also adds a callout documenting Bun's divergence from npm on root preinstall timing. Single file touched, ~40 lines of prose changed; the rest of the page (trustedDependencies, --ignore-scripts) is preserved from main after a clean rebase.

Security risks

None. This is documentation only — no code, config, build, or test changes. The content describes existing behavior; it does not alter what scripts Bun runs or how trust is evaluated.

Level of scrutiny

Low. Docs-only, and the factual claims have been cross-checked against source (lockfile.zig, Scripts.zig, install_with_manager.zig, pack_command.zig, pm_version_command.zig, run_command.zig) during the review threads on this PR. The rebase note explains conflict resolution and the final file content correctly retains main's trustedDependencies behavior table and --ignore-scripts sections.

Other factors

Every inline thread (CodeRabbit's and my own from earlier runs) is resolved: the prepare-family resolution-type gating, workspace trust exception, default-trusted-list wording, root preinstall timing, and the prerestart/prestop examples were all corrected in follow-up commits. The one remaining flagged item (a pre-existing copy/paste bug in Scripts.zig:137) is explicitly out of scope for a docs PR and is being tracked separately. CI passed on the latest commit. No outstanding human reviewer comments. Approving.

@robobun

robobun commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

I am closing this PR in favor of #41350. That PR fixes #30247 with a smaller change.

One claim in this PR is wrong. The Note says: "Unlike npm, Bun runs the root project's install-time scripts as a single batch after node_modules is populated". npm 7 and later do the same. npm install runs the root preinstall, install, and postinstall scripts only after arb.reify() returns (see lib/commands/install.js). So the .npmrc example in the Note fails under npm too.

I tested this with npm 11.16.0 and a local tarball dependency. The root preinstall ran after the dependency's postinstall, and node_modules/dep was already on disk. Bun 1.4.1 gives the same order.

The claims about Bun itself match main. The hook list matches Scripts::NAMES, and the prepare hooks follow the resolution check in Scripts.rs. To add the list of supported scripts later, reopen this PR and remove the comparison with npm from the Note.

@robobun robobun closed this Sep 4, 2026

This branch was successfully deployed

1 active deployment
staging - docs — 2014cc0b Deployed Jun 30, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation does not mention that the "dependencies" package.json script is not implemented

1 participant