Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to alias ‘yarn rw’ so badly #328

Closed
thedavidprice opened this issue Mar 24, 2020 · 17 comments
Closed

I want to alias ‘yarn rw’ so badly #328

thedavidprice opened this issue Mar 24, 2020 · 17 comments

Comments

@thedavidprice
Copy link
Contributor

thedavidprice commented Mar 24, 2020

Hypothetically, if our installation script prompted users:
“Would you like to alias command line ‘yarn rw’ to ‘r’? y/n”

Would that really be so bad?

Talk me in/out of this ‘cause I’m feeling motivated.

😉

The Rules

  1. we only use yarn
  2. we only install package locally via package.json bin executable
  3. we do not make system settings changes without users' awareness and action (preferrably require a user to decide + act through simple, transparent step)
  4. our goal is DX; we want the effect to be a net positive happiness increase
@mojombo
Copy link
Contributor

mojombo commented Mar 24, 2020

Just r is pretty ambitious, but I could certainly be convinced that aliasing to rw would be suitable. Do you know of a reliable way to do this across shells and OSes?

@thedavidprice
Copy link
Contributor Author

thedavidprice commented Mar 24, 2020

I do not, but I'm willing to do some research! To that point might end up being too complicated to cover all cases. Maybe inspect for a limited number of shells/OS's and then gracefully decline if "not recognized".

We could recommend alias, e.g. "rw", but then let the user input their choice.

The easiest way forward --> within "Next Steps" message after successful CRA installation, make a suggestion for users to manually set up themselves.

@arjunv27
Copy link

yarn workspace commands should be aliased as well.

@weaversam8
Copy link

npm lets users install and invoke binaries supplied by local packages by name, by installing them in node_modules/.bin... does yarn not also do this?

If it does, we could just put a rw.sh and rw.bat or something in node_modules/.bin that simply invokes yarn rw.

@peterp
Copy link
Contributor

peterp commented Mar 24, 2020

@weaversam8 This is exactly what yarn does. They're talking about invoking the commands without having to prefix it with yarn: https://classic.yarnpkg.com/blog/2017/06/19/adding-command-line-aliases-for-yarn/

@weaversam8
Copy link

weaversam8 commented Mar 24, 2020

No sorry, I meant that NPM already has the ability to add commands without prefixing it with Yarn. When you install gatsby-cli with NPM globally, it'll enable the ability for you to run gatsby new instead of npm r gatsby new.

I'm pretty sure this should also work if you install gatsby-cli in a local project, you can execute gatsby new in that project folder.

This functionality is provided by the bin key in package.json, which is documented here.

Edit: looks like Yarn supports this key too.

@peterp
Copy link
Contributor

peterp commented Mar 24, 2020

Thanks for the clarification @weaversam8.

A bit more about how this works. Globally installed packages, that have "bin", are added to a place where they're available in your path:

echo $PATH
/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

which gatsby
/usr/local/bin/gatsby

We do this for our CLI over here:

"bin": {
"redwood": "./dist/index.js",
"rw": "./dist/index.js"
},

But, we prefer not to have people install our CLI globally since we update the CLI fairly frequently and would like to pin it to the redwood projects where you're invoking it from. We imagine you might have several Redwood projects with different versions.

For people that hate typing yarn rw we could suggest two things:

  1. Add an alias: alias rw="yarn rw"
  2. We could ask people to install a different package globally (@redwoodjs/cli-global-alias) that installed rw and would attempt to call yarn rw from the current working directory.

@weaversam8
Copy link

We could ask people to install a different package globally (@redwoodjs/cli-global-alias) that installed rw and would attempt to call yarn rw from the current working directory.

Is there any reason we couldn't roll this into the normal CLI package anyways? That way if someone installs it globally, it'll search first for a local version when executed?

@thedavidprice
Copy link
Contributor Author

thedavidprice commented Mar 24, 2020

Thanks for chiming in here with discussion and adding clarity + specifics.

I did edit the original comment by adding “The Rules” section. Please read 👀

there are important design choices that require the yarn rw … (which, imho, really isn’t that bad). This discussion isn’t about rolling back those decisions. It’s just about whether or not there’s value in giving the users an option to alias during the installation process (and/or just providing instructions about how to alias themselves as a next step).

@thedavidprice
Copy link
Contributor Author

@arjunv27 If I understand you correctly, I’m not sure this will be possible. Could you give me an example? That will help me make sure I understand and I could also better explain my thinking.

@arjunv27
Copy link

arjunv27 commented Mar 24, 2020

@thedavidprice
Sure:
yarn workspace add web netlify-identity-widget ->
rw add web netlify-identity-widget
don't think this will work w/ aliases however -- at least not in the current state; I'll take a look at the cli

@thedavidprice
Copy link
Contributor Author

@arjunv27 Ah, thanks for the example. I can see how/why people will alias for this case. But for me it’s not a commmon command I need so wasn’t thinking the same way. More importantly, from a Redwood installation perspective, we won’t address this because it’s specific to using yarn / yarn tooling.

But, again, not that it isn’t something you and many others many very well want to do!

@thedavidprice
Copy link
Contributor Author

To research:
https://github.com/magic/bash-alias

Wondering what they’re doing under the hood.

@pickleat
Copy link

pickleat commented Jun 7, 2020

Not sure if this will add much to the discussion, but alias rw="yarn rw" in zsh is working great so far here.

@thedavidprice
Copy link
Contributor Author

@pickleat Nice! I think the trick on this would be to figure out how to support the top 3-4 shells across Linux/Mac and Windows: bash, zsh, PowerShell, etc. During installation could check shell environment and, if support, prompt user if they want to make life much radder.

Totally doable. And I think totally worth it! (Just need 36 hours in a given day to get it done... )

Anyway, thanks for chiming in 😁

@peterp
Copy link
Contributor

peterp commented Jul 21, 2020

@thedavidprice Are we OK to close this one off now?

@thedavidprice
Copy link
Contributor Author

This can be accomplished via #3094

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

No branches or pull requests

7 participants