@@ -4,6 +4,9 @@ exports = module.exports = lifecycle
4
4
exports . makeEnv = makeEnv
5
5
exports . _incorrectWorkingDirectory = _incorrectWorkingDirectory
6
6
7
+ // for testing
8
+ const platform = process . env . __TESTING_FAKE_PLATFORM__ || process . platform
9
+ const isWindows = platform === 'win32'
7
10
const spawn = require ( './lib/spawn' )
8
11
const path = require ( 'path' )
9
12
const Stream = require ( 'stream' ) . Stream
@@ -20,8 +23,8 @@ const hookStatCache = new Map()
20
23
21
24
let PATH = 'PATH'
22
25
23
- // windows calls it's path 'Path' usually, but this is not guaranteed.
24
- if ( process . platform === 'win32' ) {
26
+ // windows calls its path 'Path' usually, but this is not guaranteed.
27
+ if ( isWindows ) {
25
28
PATH = 'Path'
26
29
if ( ! process . env [ PATH ] ) {
27
30
Object . keys ( process . env ) . forEach ( function ( e ) {
@@ -32,6 +35,8 @@ if (process.platform === 'win32') {
32
35
}
33
36
}
34
37
38
+ exports . _pathEnvName = PATH
39
+
35
40
function logid ( pkg , stage ) {
36
41
return pkg . _id + '~' + stage + ':'
37
42
}
@@ -123,7 +128,7 @@ function lifecycle_ (pkg, stage, wd, opts, env, cb) {
123
128
}
124
129
125
130
if ( env [ PATH ] ) pathArr . push ( env [ PATH ] )
126
- env [ PATH ] = pathArr . join ( process . platform === 'win32' ? ';' : ':' )
131
+ env [ PATH ] = pathArr . join ( isWindows ? ';' : ':' )
127
132
128
133
var packageLifecycle = pkg . scripts && pkg . scripts . hasOwnProperty ( stage )
129
134
@@ -166,7 +171,6 @@ function shouldPrependCurrentNodeDirToPATH (opts) {
166
171
167
172
var isDifferentNodeInPath
168
173
169
- var isWindows = process . platform === 'win32'
170
174
var foundExecPath
171
175
try {
172
176
foundExecPath = which . sync ( path . basename ( process . execPath ) , { pathExt : isWindows ? ';' : ':' } )
@@ -244,7 +248,7 @@ function runCmd (note, cmd, pkg, env, stage, wd, opts, cb) {
244
248
}
245
249
opts . log . verbose ( 'lifecycle' , logid ( pkg , stage ) , 'unsafe-perm in lifecycle' , unsafe )
246
250
247
- if ( process . platform === 'win32' ) {
251
+ if ( isWindows ) {
248
252
unsafe = true
249
253
}
250
254
@@ -282,7 +286,7 @@ function runCmd_ (cmd, pkg, env, wd, opts, stage, unsafe, uid, gid, cb_) {
282
286
283
287
if ( customShell ) {
284
288
sh = customShell
285
- } else if ( process . platform === 'win32' ) {
289
+ } else if ( isWindows ) {
286
290
sh = process . env . comspec || 'cmd'
287
291
shFlag = '/d /s /c'
288
292
conf . windowsVerbatimArguments = true
0 commit comments