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
checks if babel is installed globally and displays correct cli message #5258
Conversation
@xtina-starr, thanks for your PR! By analyzing the history of the files in this pull request, we identified @loganfsmyth and @hzoo to be potential reviewers. |
Hey @xtina-starr! It looks like one or more of your builds have failed. I've copied the relevant info below to save you some time. |
Interesting. We don't generally recommend people install the CLI globally. Perhaps we could only include the Edit: Swapped locally/globally :( |
Codecov Report
@@ Coverage Diff @@
## master #5258 +/- ##
========================================
Coverage ? 89.2%
========================================
Files ? 204
Lines ? 9890
Branches ? 2665
========================================
Hits ? 8822
Misses ? 1068
Partials ? 0
Continue to review full report at Codecov.
|
@loganfsmyth thanks for the feedback. My latest commit edits the install command and fixes the lint errors. |
There is #5091 though @loganfsmyth? (invoke local command from global). But yeah in the end |
@hzoo I totally missed that the command contained |
packages/babel/cli.js
Outdated
|
||
console.error("You have mistakenly installed the `babel` package, which is a no-op in Babel 6.\n" + | ||
"Babel's CLI commands have been moved from the `babel` package to the `babel-cli` package.\n" + | ||
"\n" + | ||
" npm uninstall babel\n" + | ||
" npm install babel-cli\n" + | ||
" npm uninstall" + globalMessage + " babel-cli\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there was a miscommunication, having this be babel
and not babel-cli
is on purpose, because babel
is the package that contains the script that prints this warning, and we want to tell people to remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Other than changing babel-cli
back to babel
is there any other feedback for this PR? Also is it okay just to add another commit to make this change or do you prefer I rebase to keep the commit history clean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For PRs with a few work-in-progress commits like this, we'll probably github's squash-and-merge behavior, so you are free to push another commit and it'll all get squashed in the end.
I don't have any other comments, looks solid :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, thx!
Sooo, I got curious, and I'm not sure
then running |
Yikes, you are right! I refactored to use |
Getting an accurate true/false out of this is more of a pain than I expected! I think we should avoid using |
I'm not super familiar with the process obj, but it looks like In the global babel module
The above outputs:
In the local babel module
outputs:
|
Thanks for the super thorough reply, I really appreciate the back and forth! I know it's making more work for you. There are a few other concerns here
How about, as a rough guess at global, we check to see that the Babel executable is in the same folder as the Node command? It won't be perfect, but it would falling back to non-global when it's not extremely obvious that it is run globally. Say we did
This will work in a standard Node environment on OSX and Linux as far as I know, though it'll fail on Windows. And if it guesses wrong, it'll just default to |
No worries about the back and forth. I'm learning in this process. I'm not sure I fully understand the second concern, but I'm wondering if something like below would solve the windows concern?
|
Yup! For
to build a path that adds the separators based on the current OS. However, there are there is another different that makes things on Windows more complicated. I'll elaborate on my point in 2, since I didn't make it clear, and I think I had an error in it anyway. This will hopefully also help with the Windows vs Unix comparison. When you install a module locally you get
and when you use Similarly, when installing globally, If we only had to worry about Unix-like systems, your solution would be totally fine. Unfortunately there are two pieces that will fail on Windows I believe:
So currently I think 1. will cause your current PR to throw an exception due to it being My proposal of
would detect when the script that was executed is in the same directory as I think this is a good compromise for now so that the detection works on Unix, and will default to non-global on Windows. |
This makes a lot sense and does seem like a reasonable compromise. Thanks for thoroughly walking through your explanation. I've just made the discussed changes. |
Great, thanks for doing this. I pushed one extra commit into this PR because I realized there was an issue with the location of the file that was going to make things break on older Node versions. Nothing for you to do, but if you're curious, essentially during our build process, we only compile files inside |
Nice work @xtina-starr! |
Ah, good to know for the future! and thanks @existentialism 😃 |
Great read, this back and forth, and congrats for landing this patch @xtina-starr 👏 |
#5258) * checks if babel is installed globally and displays correct cli message - fixes #5228 * recommend local installation and fix lint errors * uses babel-cli vs babel * switch back to babel * use process.cwd() to determine if globally executed * checks for /node_module/.bin/babel * compare execPath and module execution path to determine global or local installation * Move the babel/cli.js into a 'src' so the 'const's are compiled Node < 6.
i have get a program when start Project 。npm -start
See http://babeljs.io/docs/usage/cli/ for setup instructions. so how can fix them |
I've added the is-global dependency to ensure this also works on windows. I check against isGlobal to determine if the process is executed globally or from the node module.
This was difficult to reproduce locally. I tried using
npm link
to test but that undermines the local check.