Skip to content

fix: prefer local node_modules/.bin executables to globally installed ones#87

Merged
43081j merged 2 commits intotinylibs:mainfrom
iiroj:prefer-local-node-modules
Mar 4, 2026
Merged

fix: prefer local node_modules/.bin executables to globally installed ones#87
43081j merged 2 commits intotinylibs:mainfrom
iiroj:prefer-local-node-modules

Conversation

@iiroj
Copy link
Contributor

@iiroj iiroj commented Mar 3, 2026

Previously the local node_modules/.bin paths, resolved from the current working directory all the way to the root directory, were added to the end of the PATH variable when spawning a binary. This meant that if a binary was installed both to a default global path like /usr/local/bin as well as a local directory like ~/node_modules/.bin, the globally installed binary was spawned instead of the local one.

Now the the node_modules/.bin paths are prefixed to the start of PATH instead, so that locally-installed binaries are preferred to global ones. This mirrors the behavior of npm/npx path resolution when running scripts.

@iiroj iiroj force-pushed the prefer-local-node-modules branch 2 times, most recently from fa2c80d to ff4ab6e Compare March 3, 2026 14:17
@iiroj
Copy link
Contributor Author

iiroj commented Mar 3, 2026

Changing this behavior might be seen as a breaking change, so it could be released with a new option like preferLocal: true.

…ed ones

Previously the local `node_modules/.bin` paths, resolved from the current working
directory all the way to the root directory, were added to the end of the `PATH`
variable when spawning a binary. This meant that if a binary was installed both
to a default global path like `/usr/local/bin` as well as a local directory
like `~/node_modules/.bin`, the globally installed binary was spawned instead
of the local one.

Now the the `node_modules/.bin` paths are prefixed to the **start of `PATH`**
instead, so that locally-installed binaries are preferred to global ones. This
mirrors the behavior of `npm`/`npx` path resolution when running scripts.
@iiroj iiroj force-pushed the prefer-local-node-modules branch from ff4ab6e to 25b52a6 Compare March 3, 2026 14:34
@43081j
Copy link
Member

43081j commented Mar 4, 2026

im not sure about the semver yet. this is a bug really rather than a breaking change, but i understand it could break things...

ill have a think 🤔

@43081j 43081j merged commit 32b9015 into tinylibs:main Mar 4, 2026
7 checks passed
@iiroj
Copy link
Contributor Author

iiroj commented Mar 4, 2026

My personal opinion would be to treat it as a bugfix and refer to how npm handles it, and if someone absolutely requires it maybe an option that restores the previous behavior. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants