Skip to content

Fix postinstall and finish trustedDependencies #4959

@Electroid

Description

@Electroid
Contributor

🔍 Summary

Bun introduces the concept of trustedDependencies, which allows you to specify an allow-list of packages that are allowed to run lifecycle scripts, such as postinstall. This is because dependencies can run arbitrary shell scripts when installed, and that's generally not great.

package.json:

{
  "dependencies": {
    "utf-8-validate": "^6.0.3"
  },
  "trustedDependencies": [
    "utf-8-validate"
  ]
}

However, there are dependencies that you need to trust to run scripts, because otherwise they do not work. To do this, you can add the package name to the trustedDependencies list in your package.json.

But doing this for every package would be annoying, so Bun would also have a default allow-list of the most popular packages on npm that need to run scripts, like utf-8-validate or esbuild. #4263

We planned to include these changes in 1.0, but ran out of time. Once Bun supports these changes, you wouldn't need to use trustedDependencies for 99% of the time, except for more obscure dependencies. Also, when running bun add or bun install, there would be a prompt to indicate that the dependency is using scripts.

🚧 Workaround

  1. Add package to trustedDependencies in your package.json.
{
  "trustedDependencies": ["utf-8-validate"]
}
  1. Run bun remove, then bun add, to ensure script is re-run.
bun remove utf-8-validate
bun add utf-8-validate

Activity

added
bugSomething isn't working
bun installSomething that relates to the npm-compatible client
on Sep 11, 2023
birkskyum

birkskyum commented on Sep 12, 2023

@birkskyum
Collaborator

Also, it would be great to expand the test suite here beyond a clean install, because it appear to behave incorrectly. I've made a PR here that does test more scenarios:

Scenarios that aren't covered in that PR yet is if a lockfile i.e. already exist, and then the library is added to the trustedDependencies array, followed by bun install, or the other way around, but it's a good starting point.

intrnl

intrnl commented on Sep 19, 2023

@intrnl

Are the defaults for trustedDependencies overrideable?

53 remaining items

brianmhunt

brianmhunt commented on Nov 22, 2023

@brianmhunt

If the perf branch is taking a long time, is it worth breaking the flag into a separate story? The analysis is very different from the performance issue, namely:

Perspective --trust-all-dependencies Flag Parallelized install
Complexity of fix Trivial Complex
Impact on affected packages Silent failure to install Slower installation
First user experience Inexplicable deviation from expectation and unusable installation Performance at-worst equivalent to npm/etc
Required user remediation Time consuming investigation [1] N/A

[1] The investigation entails:

  1. discovering why bun i failed (i.e. google + repo search, some knowledge of postinstall, etc.)
  2. finding out what postinstall/etc didn't run
  3. editing package.json files to add trustedDependencies

There's low hanging fruit in the flag (and perhaps logging) to fix a very negative experience, and I fear it being conflated with a performance impression may be lowering the apparent significance of this issue.

cc @Jarred-Sumner @Electroid @dylan-conway

strokirk

strokirk commented on Nov 23, 2023

@strokirk

I would like to second the suggestion to print a list of ignored post-install scripts. Currently there isn't much guidance about this issue on the internet, so while trying to install vue-demi today it took quite a bit of digging to realize that bun doesn't run postinstall scripts, and even after adding the script to trustedDependencies, bun i didn't run the script.

uncenter

uncenter commented on Dec 8, 2023

@uncenter

#7132 fixes the big issue here but leaves out some ideas that have been thrown around:

  • Prompt users to accept/deny execution of each post-install script OR just print a list of ignored post-install scripts (no prompts)
  • --trust-all-dependencies or glob-based --trust-dependencies='*' CLI flag
  • Configuration of the above two behaviors via bunfig.toml

Should these be split into additional issues?

Jarred-Sumner

Jarred-Sumner commented on Dec 12, 2023

@Jarred-Sumner
Collaborator
Jarred-Sumner

Jarred-Sumner commented on Dec 12, 2023

@Jarred-Sumner
Collaborator

We will ship a follow-up that warns on skipped postinstall scripts in a future release

brianmhunt

brianmhunt commented on Jan 27, 2024

@brianmhunt

@Jarred-Sumner just a ping re your comment above:

... We will add a flag to allow all as well. We are aiming to ship it by Monday.

Not to pester, just making sure it didn't get lost in the shuffle. Thank you!

balloman

balloman commented on Apr 15, 2024

@balloman

Asking if we ever got the flag for the post install script? I don't see it in the documentation anywhere. Is there an issue tracking it somewhere?

It seems that --trust would be an option, but that doesn't actually do anything, you still need to manually trust the packages afterwards. (And in fact, using --trust doesn't even give you the warning, so you would have no idea)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbun installSomething that relates to the npm-compatible client

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @brianmhunt@fdaciuk@Jarred-Sumner@elmpp@strokirk

      Issue actions