Yarn: Support -g / --global

Created on 19 Aug 2016  路  8Comments  路  Source: yarnpkg/yarn

cat-feature

Most helpful comment

Splitting it into a separate command would be a good idea since then we could have $ yarn global add <NAME> and then additional commands like $ yarn global ls.

All 8 comments

Are global modules actually a pattern we'd want to encourage?

refer to @wycats thinking here https://github.com/yarnpkg/yarn/issues/375

particularly this bit

That said, we definitely need to avoid losing users because basic workflows they've come to expect don't work anymore, but should avoid promising perfect compatibility.

-g is a super common pattern in npm land, regardless of if I would ever tell someone to do it, many many many people use it.

Fair enough - That seems reasonable!

@samccone totally agree.

I think a big part of what makes install -g "bad practice" is that it not only adds the package to your path, but also makes it available to require. I think we can almost certainly get away with making -g add the binaries to the path without making the package available to require.

Also, I think that -g is pretty analogous to --save, except that it's saying "save this package to the global node_modules", so I think it makes sense to make it yarn add --global in Yarn.

@wycats So IIUC you're teasing apart the good practice of installing global binaries as yarn install -g ember-cli and the more questionable (but surely widely used) practice of installing global libraries as yarn add -g lodash? I really like the idea both of separating the two (good practices shouldn't be coupled to bad) as well as the intuitions the separate verbs carry: installing binaries good, adding to a global node_modules not so good.

Would it make sense to also have a single verb alias for install -g since it's such common practice? Supporting install -g is important for workflow compat but it seems like it'd also be nice to be able to tell users of a cli tool to just type yarn use ember-cli as a more readable alias for yarn install -g ember-cli. (In a perfect world I might prefer something like build in place of install and install in place of install -g but that's too confusing of a workflow shift.)

@dherman I really like the idea of having a separate verb for installing a global "dependency". I'm not sure about use since it doesn't indicate that the action you're performing isn't on your local project.

Splitting it into a separate command would be a good idea since then we could have $ yarn global add <NAME> and then additional commands like $ yarn global ls.

you're teasing apart the good practice of installing global binaries as yarn install -g ember-cli

Calling that a "good practice" is a controversial opinion 馃槢 There's a lot of issues with it, such as the fact that updates are not performed when you update the rest of your system (any software installed via npm is a special snowflake compared to software installed via the native package management system, such as dpkg/apt-get on Debian and its derivatives), and the lack of signature verification.

In any case, it's not uncommon in the JavaScript community, so Yarn probably still needs it. In that case I think @kittens idea of splitting it into a separate command is a really good idea, such that global package installations aren't conflated with local package installations. In the end, they're two pretty different concepts.

Was this page helpful?
0 / 5 - 0 ratings