AndersDJohnson / use-yarn

Force users to use yarn instead of npm.
https://andersdjohnson.github.io/use-yarn/
ISC License
50 stars 12 forks source link

Discussion / Question: offer recommendation for usage in libraries or applications? #6

Open jimthedev opened 6 years ago

jimthedev commented 6 years ago

Hi @AndersDJohnson,

Great library, thanks for making it.

As I was using use-yarn for the first time I realized that it is ideal to use it in applications but probably not in widely distributed libraries since its functionality (when in preinstall) trickles into downstream dependencies. So if Library A implements use-yarn and Library B relies on it then now Library B is effectively also going to get use-yarn as a constraint. Now this might be intended for some people but not for others. I think the key is letting people that use use-yarn know that by using it they will be enforcing this constraint on their downstream dependencies.

So in the end it seems like use-yarn is probably mostly useful for

A) Applications or B) For libraries whose downstream dependents explicitly do not need to support npm (favoring yarn instead).

Does that sound right to you?

AndersDJohnson commented 6 years ago

@jimthedev You are right that this was incidentally designed for use in applications rather than libraries. Do you have any ideas how to solve the preinstall hook issue to allow it to be used in libraries as well? Maybe some NPM/yarn environment variable to indicate whether this is a dependency of the root package or of a (possibly transitive) dependency?

nevir commented 5 years ago

I would suggest using the prepare hook, rather than preinstall.

Unfortunately prepare happens after dependencies have been installed, though. Alternatively, you could parse the npm_config_argv environment variable to determine whether it's a directly npm install for the repo vs being installed as a dependency. However it gets really tricky because people like to alias npm i and whatnot

AndersDJohnson commented 5 years ago

@nevir Hi, thanks for participating the discussion. Can you explain the advantages of prepare over preinstall for this use case?