File tree 3 files changed +50
-16
lines changed
3 files changed +50
-16
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint camelcase: "off" */
2
2
const setPATH = require ( './set-path.js' )
3
3
const { resolve } = require ( 'path' )
4
- const npm_config_node_gyp = require . resolve ( 'node-gyp/bin/node-gyp.js' )
4
+
5
+ let npm_config_node_gyp
5
6
6
7
const makeSpawnArgs = options => {
7
8
const {
9
+ args,
10
+ binPaths,
11
+ cmd,
12
+ env,
8
13
event,
14
+ nodeGyp,
9
15
path,
10
16
scriptShell = true ,
11
- binPaths,
12
- env,
13
17
stdio,
14
- cmd,
15
- args,
16
18
stdioString,
17
19
} = options
18
20
21
+ if ( nodeGyp ) {
22
+ // npm already pulled this from env and passes it in to options
23
+ npm_config_node_gyp = nodeGyp
24
+ } else if ( env . npm_config_node_gyp ) {
25
+ // legacy mode for standalone user
26
+ npm_config_node_gyp = env . npm_config_node_gyp
27
+ } else {
28
+ // default
29
+ npm_config_node_gyp = require . resolve ( 'node-gyp/bin/node-gyp.js' )
30
+ }
31
+
19
32
const spawnEnv = setPATH ( path , binPaths , {
20
33
// we need to at least save the PATH environment var
21
34
...process . env ,
Original file line number Diff line number Diff line change @@ -7,18 +7,19 @@ const isServerPackage = require('./is-server-package.js')
7
7
8
8
const runScriptPkg = async options => {
9
9
const {
10
- event,
11
- path,
12
- scriptShell,
10
+ args = [ ] ,
13
11
binPaths = false ,
14
12
env = { } ,
15
- stdio = 'pipe' ,
13
+ event,
14
+ nodeGyp,
15
+ path,
16
16
pkg,
17
- args = [ ] ,
18
- stdioString,
17
+ scriptShell,
19
18
// how long to wait for a process.kill signal
20
19
// only exposed here so that we can make the test go a bit faster.
21
20
signalTimeout = 500 ,
21
+ stdio = 'pipe' ,
22
+ stdioString,
22
23
} = options
23
24
24
25
const { scripts = { } , gypfile } = pkg
@@ -63,14 +64,15 @@ const runScriptPkg = async options => {
63
64
}
64
65
65
66
const [ spawnShell , spawnArgs , spawnOpts ] = makeSpawnArgs ( {
67
+ args,
68
+ binPaths,
69
+ cmd,
70
+ env : { ...env , ...packageEnvs ( pkg ) } ,
66
71
event,
72
+ nodeGyp,
67
73
path,
68
74
scriptShell,
69
- binPaths,
70
- env : { ...env , ...packageEnvs ( pkg ) } ,
71
75
stdio,
72
- cmd,
73
- args,
74
76
stdioString,
75
77
} )
76
78
Original file line number Diff line number Diff line change @@ -62,20 +62,39 @@ t.test('spawn args', async t => {
62
62
/ .* / ,
63
63
a => a . includes ( 'echo test' ) ,
64
64
e => {
65
- return e . env . test_fixture === 'a string'
65
+ return e . env . test_fixture === 'a string' &&
66
+ e . env . npm_config_node_gyp === '/test/path.js'
66
67
}
67
68
)
68
69
await t . resolves ( ( ) => runScript ( {
69
70
pkg,
70
71
path : testdir ,
71
72
env : {
73
+ npm_config_node_gyp : '/test/path.js' ,
72
74
test_fixture : 'a string' ,
73
75
} ,
74
76
event : 'test' ,
75
77
} ) )
76
78
t . ok ( spawk . done ( ) )
77
79
} )
78
80
81
+ await t . test ( 'provided options.nodeGyp' , async t => {
82
+ spawk . spawn (
83
+ / .* / ,
84
+ a => a . includes ( 'echo test' ) ,
85
+ e => {
86
+ return e . env . npm_config_node_gyp === '/test/path.js'
87
+ }
88
+ )
89
+ await t . resolves ( ( ) => runScript ( {
90
+ pkg,
91
+ path : testdir ,
92
+ nodeGyp : '/test/path.js' ,
93
+ event : 'test' ,
94
+ } ) )
95
+ t . ok ( spawk . done ( ) )
96
+ } )
97
+
79
98
await t . test ( 'provided args' , async t => {
80
99
spawk . spawn (
81
100
/ .* / ,
You can’t perform that action at this time.
0 commit comments