Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit ae94ed2

Browse files
zkochaniarna
authored andcommitted
feat(node-gyp): use own node-gyp
BREAKING CHANGE: Previously you had to bring your own node-gyp AND you had to provide access the way npm does, by having a `bin` dir with a `node-gyp-bin` in it. Fixes: #4
1 parent 2eb7a38 commit ae94ed2

File tree

5 files changed

+226
-155
lines changed

5 files changed

+226
-155
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const uidNumber = require('uid-number')
1313
const umask = require('umask')
1414
const which = require('which')
1515
const byline = require('byline')
16+
const resolveFrom = require('resolve-from')
17+
18+
const DEFAULT_NODE_GYP_PATH = resolveFrom(__dirname, 'node-gyp/bin/node-gyp')
1619

1720
let PATH = 'PATH'
1821

@@ -62,6 +65,7 @@ function lifecycle (pkg, stage, wd, opts) {
6265
env.npm_node_execpath = env.NODE = env.NODE || process.execPath
6366
env.npm_execpath = require.main.filename
6467
env.INIT_CWD = process.cwd()
68+
env.npm_config_node_gyp = env.npm_config_node_gyp || DEFAULT_NODE_GYP_PATH
6569

6670
// 'nobody' typically doesn't have permission to write to /tmp
6771
// even if it's never used, sh freaks out.
@@ -92,7 +96,7 @@ function lifecycle_ (pkg, stage, wd, opts, env, cb) {
9296

9397
// we also unshift the bundled node-gyp-bin folder so that
9498
// the bundled one will be used for installing things.
95-
pathArr.unshift(path.join(__dirname, '..', '..', 'bin', 'node-gyp-bin'))
99+
pathArr.unshift(path.join(__dirname, 'node-gyp-bin'))
96100

97101
if (shouldPrependCurrentNodeDirToPATH(opts)) {
98102
// prefer current node interpreter in child scripts

node-gyp-bin/node-gyp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
if [ "x$npm_config_node_gyp" = "x" ]; then
3+
node "`dirname "$0"`/../../node_modules/node-gyp/bin/node-gyp.js" "$@"
4+
else
5+
"$npm_config_node_gyp" "$@"
6+
fi

node-gyp-bin/node-gyp.cmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if not defined npm_config_node_gyp (
2+
node "%~dp0\..\..\node_modules\node-gyp\bin\node-gyp.js" %*
3+
) else (
4+
node "%npm_config_node_gyp%" %*
5+
)

0 commit comments

Comments
 (0)