@@ -4,6 +4,9 @@ exports = module.exports = lifecycle
44exports . makeEnv = makeEnv
55exports . _incorrectWorkingDirectory = _incorrectWorkingDirectory
66
7+ // for testing
8+ const platform = process . env . __TESTING_FAKE_PLATFORM__ || process . platform
9+ const isWindows = platform === 'win32'
710const spawn = require ( './lib/spawn' )
811const path = require ( 'path' )
912const Stream = require ( 'stream' ) . Stream
@@ -20,8 +23,8 @@ const hookStatCache = new Map()
2023
2124let PATH = 'PATH'
2225
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 ) {
2528 PATH = 'Path'
2629 if ( ! process . env [ PATH ] ) {
2730 Object . keys ( process . env ) . forEach ( function ( e ) {
@@ -32,6 +35,8 @@ if (process.platform === 'win32') {
3235 }
3336}
3437
38+ exports . _pathEnvName = PATH
39+
3540function logid ( pkg , stage ) {
3641 return pkg . _id + '~' + stage + ':'
3742}
@@ -123,7 +128,7 @@ function lifecycle_ (pkg, stage, wd, opts, env, cb) {
123128 }
124129
125130 if ( env [ PATH ] ) pathArr . push ( env [ PATH ] )
126- env [ PATH ] = pathArr . join ( process . platform === 'win32' ? ';' : ':' )
131+ env [ PATH ] = pathArr . join ( isWindows ? ';' : ':' )
127132
128133 var packageLifecycle = pkg . scripts && pkg . scripts . hasOwnProperty ( stage )
129134
@@ -166,7 +171,6 @@ function shouldPrependCurrentNodeDirToPATH (opts) {
166171
167172 var isDifferentNodeInPath
168173
169- var isWindows = process . platform === 'win32'
170174 var foundExecPath
171175 try {
172176 foundExecPath = which . sync ( path . basename ( process . execPath ) , { pathExt : isWindows ? ';' : ':' } )
@@ -244,7 +248,7 @@ function runCmd (note, cmd, pkg, env, stage, wd, opts, cb) {
244248 }
245249 opts . log . verbose ( 'lifecycle' , logid ( pkg , stage ) , 'unsafe-perm in lifecycle' , unsafe )
246250
247- if ( process . platform === 'win32' ) {
251+ if ( isWindows ) {
248252 unsafe = true
249253 }
250254
@@ -282,7 +286,7 @@ function runCmd_ (cmd, pkg, env, wd, opts, stage, unsafe, uid, gid, cb_) {
282286
283287 if ( customShell ) {
284288 sh = customShell
285- } else if ( process . platform === 'win32' ) {
289+ } else if ( isWindows ) {
286290 sh = process . env . comspec || 'cmd'
287291 shFlag = '/d /s /c'
288292 conf . windowsVerbatimArguments = true
0 commit comments