-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Use npm's node-gyp if available, otherwise automatically install node-gyp #3240
Conversation
Love the solution, thanks for considering so many edge cases |
Can this get a patch release asap zulu? 😄 EDIT: I realize that expression only works in my timezone, where zulu is one hour behind (CET)... Meh |
), | ||
); | ||
pathParts.unshift( | ||
path.join( |
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.
this stuff can use path.resolve
which gets rid of the ..
from the resulting string, and you can pass a single arg with /
. Yes, that works on windows.
$ node -pe "require('path').win32.resolve('/root', 'some/path/../slashes')"
\root\some\slashes
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.
so this can be path.resolve(path.dirname(process.execPath), '../lib/node_modules/npm/bin/node-gyp-bin')
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.
path.join
gets rid of the ..
too 😃
I used path.join
with all the pieces rather than hard-coding a string with /
since it seemed cleaner. I guess either way is fine.
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.
path.join
gets rid of the..
too
Didn't know! Nice
$ node -pe "require('path').win32.join('/root', 'cool', 'some/path/../slashes', '..')"
\root\cool\some
Would you look at that, it also fixes the slashes! You learn something every day
I think this might have complicated rebuilding native dependencies for electron: electron-userland/electron-builder#1542 Still trying to track down the source of the problem, but I can't rebuild sqlite3 for electron now when installing with 0.24.0 and greater. |
@bcomnes - I think there's some issue specific to |
@Daniel15 Do you think the fix should live there? I'm not terribly familiar with the internals of pre-gyp. |
@springmeyer do you have any idea why these changes might confuse or break the way node-pre-gyp works? |
@bcomnes the error you refer to in the electron ticket: |
I'll dig into it. From the sound of the changes in yarn, the only location of node-gyp would be in npm's node_modules. I don't have a global node-gyp install. Thank you for the hint! |
@bcomnes sounds good. A quick glance at this PR shows |
Sounds right. Want a PR? I might be able to get one out today or tomorrow. |
Another idea: maybe someone here would be interested in writing a separate module that:
|
Happy to review a PR over at node-pre-gyp. Thanks again for the ping here. |
The paths that Yarn uses to look for node-gyp are based on my experience with it:
Yarn adds these paths to the The only special case is when you do not have npm installed, in which case Yarn needs to install its own version of Looking at the code that @springmeyer linked to, it sounds like you could fix this by setting the |
I have to head home now and I haven't finished testing a fix yet. Perhaps tomorrow. If anyone else wants to land a fix first, don't let me stop you. |
I just tried searching the path for The next solution I will try is resolving the node-gyp path from npm in the exact same way as yarn, as @springmeyer originally suggested. I'm confident this will fix the current problem. But... This brings me to a question for @Daniel15: Can you help me understand what problem this change solves by not depending on
I'm cool either way, but those are just my thoughts now that I understand the situation a little deeper. |
I just PR'd a possible fix for node-pre-gyp: https://github.com/mapbox/node-pre-gyp/pull/292/files That should fix the issue, or if you like the argument I made above, reverting back to yarn shipping node-gyp would also put us back into a working state. |
The standalone .js build of Yarn nas never bundled node-gyp, due to the fact that it's a single file. This is the build of Yarn we use in some places at Facebook, and is also used in various other situations (for example, in cases where people want to commit all their build dependencies). This meant that node-gyp stuff never worked with it. The primary purpose of this pull request was to make node-gyp work the same way on all versions of Yarn - Both the bundled .js build as well as the tarball/installer version. Additionally, the Yarn tarball now contains the bundled .js file rather than all the raw Yarn JS + However, it means we can't easily bundle node-gyp. It would need to be a separate JS file in the bundle, including all its dependencies, defeating one of the main gains of the combined .js file. It's worth noting that Yarn will automatically install node-gyp if it's not available on your system. Essentially it runs
This is a fixable problem 😃 |
Thanks for the info, I think I understand now. Looks like there are more concerns at play than I had originally considered. |
This solves it: |
Summary
Some Node.js packages depend on
node-gyp
but do not declare the dependency in theirpackage.json
, instead relying on node-gyp to already be globally installed. For packages like this, we used to bundle node-gyp with Yarn itself. However, this does not work for the standalone JS build (which is used by the tarball now too)The ideal fix is for packages to explicitly specify that they require node-gyp, as relying on the global version is dangerous (eg. if there's breaking changes between releases).
The changes I've made are as follows:
yarn global add node-gyp
.Test plan
Tested manually on Windows and on Ubuntu 16.04 by using
yarn add nodetunes
I'm not sure how I could unit test this... I guess I could mock out the
fs
methods, but that might mess up other tests 😕Fixes #2266
Fixes #3114
cc @bestander