Skip to content

Commit

Permalink
bundle node-gyp and include it (shimmed) in the PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jan 28, 2020
1 parent 43366ab commit e4c7cb3
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 126 deletions.
2 changes: 2 additions & 0 deletions lib/make-spawn-args.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const isWindows = require('./is-windows.js')
const setPATH = require('./set-path.js')
const {resolve} = require('path')
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')

const makeSpawnArgs = options => {
const {
Expand All @@ -23,6 +24,7 @@ const makeSpawnArgs = options => {
npm_package_json: resolve(path, 'package.json'),
npm_lifecycle_event: event,
npm_lifecycle_script: cmd,
npm_config_node_gyp,
}),
stdio,
cwd: path,
Expand Down
2 changes: 2 additions & 0 deletions lib/node-gyp-bin/node-gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
node "$npm_config_node_gyp" "$@"
1 change: 1 addition & 0 deletions lib/node-gyp-bin/node-gyp.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@node "%npm_config_node_gyp%" %*
3 changes: 2 additions & 1 deletion lib/set-path.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {resolve, dirname} = require('path')
const isWindows = require('./is-windows.js')
const nodeGypPath = resolve(__dirname, 'node-gyp-bin')

// Windows typically calls its PATH environ 'Path', but this is not
// guaranteed, nor is it guaranteed to be the only one. Merge them
Expand All @@ -12,7 +13,7 @@ const setPATH = (projectPath, env) => {
.reduce((set, p) => set.concat(p.filter(p => !set.includes(p))), [])
.join(delimiter)

const pathArr = []
const pathArr = [nodeGypPath]
// unshift the ./node_modules/.bin from every folder
// walk up until dirname() does nothing, at the root
// XXX should we specify a cwd that we don't go above?
Expand Down
Loading

0 comments on commit e4c7cb3

Please sign in to comment.