oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
72.83k stars 2.64k forks source link

`bun install` installs optional dependency with optional=false in bunfig.toml #7274

Open Osmose opened 9 months ago

Osmose commented 9 months ago

What version of Bun is running?

1.0.13+d8ca6ca69

What platform is your computer?

Darwin 22.5.0 x86_64 i386

What steps can reproduce the bug?

Create a directory with two files:

package.json

{
  "name": "test",
  "dependencies": {
    "chokidar": "^3.5.3"
  }
}

bunfig.toml

[install]
optional = false

Then run bun install and ls node_modules/fsevents to check if fsevents (which is an optional dependency for chokidar) was installed.

What is the expected behavior?

node_modules/fsevents wasn't installed and doesn't exist.

What do you see instead?

fsevents is installed under node_modules/fsevents.

Additional information

Ran into this while attempting to make a standalone binary with bun build that uses chokidar—#3903 prevents this from working since fsevents is a native module, so I'd like to avoid installing it since it's an optional dependency to chokidar, but bun seems to install it regardless of my bunfig.toml, --production flags, etc.

I also checked that it wasn't a cache issue by running rm -rf ~/.bun/install/cache, it still installs fsevents.

joakimbeng commented 6 months ago

Having the same issue with a dependency that has typescript as a peerOptional dependency, but it's installed no matter what I try.

infrahead commented 6 months ago

Same on Linux. Thought I was losing my mind. And this is not just optional dependences, but none of the dependency types documented under https://bun.sh/docs/runtime/bunfig#package-manager follow those settings. I've tried setting dev and peer to false and are always installed.

Also documented here: https://bun.sh/docs/cli/install#configuration

EDIT: unless I'm misunderstanding how this is expected to work. I can now see that the settings apply to my own project dependencies, but NOT to transitive dependencies (where optional still installed)

joakimbeng commented 6 months ago

For some reason it seems to skip the optional dependencies correctly when I install dependencies as part of a docker build when I have the dependency's optional dependency as a dev dependency and only install production dependencies though.

This is my Dockerfile:

FROM oven/bun:1.0.26-alpine
ENV CI true
ENV NODE_ENV production

COPY package.json package.json
COPY bun.lockb bun.lockb

RUN bun install --production --frozen-lockfile

When I run a container with that built image the optional dependency is not installed, which is correct. I don't know if it's the NODE_ENV or CI env variables that affect it in some way to make it behave correctly...

Alecyrus commented 4 months ago

I am seeing this issue in Bun v1.1.3. I set [install.optional] = false in bunfig.toml, but sharp, an optional dependency of astro, is still installed, which is not expected.

jbsiddall commented 3 months ago

👍

dszymon commented 1 month ago

present in 1.1.17