Coder Social home page Coder Social logo

Prefer local node_modules/.bin? about nodenv HOT 4 CLOSED

nodenv avatar nodenv commented on July 2, 2024
Prefer local node_modules/.bin?

from nodenv.

Comments (4)

jasonkarns avatar jasonkarns commented on July 2, 2024 1

nodenv alters PATH when the output of nodenv init is sourced (or evaled depending on your setup)

So you just need to prepend ./node_modules/.bin to PATH after you've invoked nodenv-init

from nodenv.

jasonkarns avatar jasonkarns commented on July 2, 2024

I have an idea for a plugin to make this possible, but at present it is not. It's not related to nodenv in any way. Local node_modules bins simply aren't on the path, and a non-nodenv installation isn't any different. There are alternatives, however.

  1. Add ./node_modules/.bin to your PATH. Though there are security reasons to avoid this.

  2. $(npm bin)/coffee will run the local coffee. And npm-bin works anywhere in the project (not just at root).

  3. Use npm run-scripts. When an npm script is invoked via npm run foo, npm prepends $(npm-bin) to your PATH. So scripts can invoke any locally installed bin without the need to prefix it.

    "scripts": {
      "compile": "coffee"
    }

    Now npm run compile will use your local coffee.

The complication for making a plugin for this is finding a way to make nodenv aware of all your local node_modules. It can't shim what it doesn't know about. Best I can think of so far, is that the plugin prepends $(npm bin) to the PATH during the exec hook. But this would only work for modules that have been installed globally and are thus shimmed. So for any locally-installed bin, one would need to install it globally as well. Then the global shim would trigger nodenv, and the exec hook could prepend local bin path.

from nodenv.

hurrymaplelad avatar hurrymaplelad commented on July 2, 2024

Thanks for all the thoughts!

I'm in bucket #1. I've already added ./node_modules/.bin to my path, but I can't give them precedence over globally installed modules which nodenv pretends to my path.

Any thoughts on configuring where in the path the shims are added?

On Feb 11, 2016, at 5:22 AM, Jason Karns [email protected] wrote:

I have an idea for a plugin to make this possible, but at present it is not. It's not related to nodenv in any way. Local node_modules bins simply aren't on the path, and a non-nodenv installation isn't any different. There are alternatives, however.

Add ./node_modules/.bin to your PATH. Though there are security reasons to avoid this.
$(npm bin)/coffee will run the local coffee. And npm-bin works anywhere in the project (not just at root).
Use npm run-scripts. When an npm script is invoked via npm run foo, npm prepends $(npm-bin) to your PATH. So scripts can invoke any locally installed bin without the need to prefix it.

"scripts": {
"compile": "coffee"
}
Now npm run compile will use your local coffee.

The complication for making a plugin for this is finding a way to make nodenv aware of all your local node_modules. It can't shim what it doesn't know about. Best I can think of so far, is that the plugin prepends $(npm bin) to the PATH during the exec hook. But this would only work for modules that have been installed globally and are thus shimmed. So for any locally-installed bin, one would need to install it globally as well. Then the global shim would trigger nodenv, and the exec hook could prepend local bin path.


Reply to this email directly or view it on GitHub.

from nodenv.

jasonkarns avatar jasonkarns commented on July 2, 2024

Closing since there's a workaround:

from nodenv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.