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

Commit

Permalink
feat(node-gyp): use own node-gyp
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zkochan authored and iarna committed Nov 17, 2017
1 parent 2eb7a38 commit ae94ed2
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 155 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const uidNumber = require('uid-number')
const umask = require('umask')
const which = require('which')
const byline = require('byline')
const resolveFrom = require('resolve-from')

const DEFAULT_NODE_GYP_PATH = resolveFrom(__dirname, 'node-gyp/bin/node-gyp')

let PATH = 'PATH'

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

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

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

if (shouldPrependCurrentNodeDirToPATH(opts)) {
// prefer current node interpreter in child scripts
Expand Down
6 changes: 6 additions & 0 deletions node-gyp-bin/node-gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
if [ "x$npm_config_node_gyp" = "x" ]; then
node "`dirname "$0"`/../../node_modules/node-gyp/bin/node-gyp.js" "$@"
else
"$npm_config_node_gyp" "$@"
fi
5 changes: 5 additions & 0 deletions node-gyp-bin/node-gyp.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if not defined npm_config_node_gyp (
node "%~dp0\..\..\node_modules\node-gyp\bin\node-gyp.js" %*
) else (
node "%npm_config_node_gyp%" %*
)
Loading

0 comments on commit ae94ed2

Please sign in to comment.