From 95e8976eba87754a4db7422f5408d83004583566 Mon Sep 17 00:00:00 2001 From: Christian Moritz Date: Tue, 21 Nov 2017 22:46:10 +0100 Subject: [PATCH] fix(install): use node-gyp from homebrew npm **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. Homebrew installs a clean copy of npm inside a libexec folder 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 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 the 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. --- src/util/execute-lifecycle-script.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/execute-lifecycle-script.js b/src/util/execute-lifecycle-script.js index b89d002355..ae09f86dd5 100644 --- a/src/util/execute-lifecycle-script.js +++ b/src/util/execute-lifecycle-script.js @@ -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.