Skip to content

Commit

Permalink
fix(install): use node-gyp from homebrew npm
Browse files Browse the repository at this point in the history
**Summary**

With this yarn will be able to discover and use the node-gyp from the
homebrew installed npm on macOS instead of falling back to globally
installing node-gyp every time a native addon needs to be compiled from
source.

Homebrew installs a clean copy of npm inside a libexec folder together
with node.
Previously yarn didn't look there when trying to locate node-gyp and the
globally install node-gyp fallback would be used every time when
building native addons with a yarn version from homebrew.
This PR adds the libexec path of node-gyp from homebrew to the node-gyp
search paths of yarn, making it possible to compile native addons using
the homebrew npm provided node-gyp with yarn without relying on this
fallback.

**Test plan**

This can't be tested outside a homebrew environment.

A way to manually test this on macOS, by installing a test build of this
PR with homebrew and trying to install a native addon with it, is
provided in the PR description.
  • Loading branch information
chrmoritz committed Dec 3, 2017
1 parent f69cdda commit 79b41b0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/util/execute-lifecycle-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ export async function makeEnv(
pathParts.unshift(
path.join(path.dirname(process.execPath), '..', 'lib', 'node_modules', 'npm', 'bin', 'node-gyp-bin'),
);
// Include node-gyp version from homebrew managed npm, if available.
pathParts.unshift(
path.join(path.dirname(process.execPath), '..', 'libexec', 'lib', 'node_modules', 'npm', 'bin', 'node-gyp-bin'),
);

// Add global bin folder if it is not present already, as some packages depend
// on a globally-installed version of node-gyp.
Expand Down

0 comments on commit 79b41b0

Please sign in to comment.