-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(env): Do not clobber defined 'env' script
If an env script is already defined, run that instead of the default. PR-URL: #2655 Credit: @isaacs Close: #2655 Reviewed-by: @ljharb
- Loading branch information
Showing
4 changed files
with
66 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,12 +126,14 @@ t.test('default env, start, and restart scripts', async t => { | |
scriptShell: undefined, | ||
stdio: 'inherit', | ||
stdioString: true, | ||
pkg: { name: 'x', | ||
pkg: { | ||
name: 'x', | ||
version: '1.2.3', | ||
_id: '[email protected]', | ||
scripts: { | ||
env: 'env', | ||
} }, | ||
}, | ||
}, | ||
event: 'env', | ||
}, | ||
]) | ||
|
@@ -185,6 +187,67 @@ t.test('default env, start, and restart scripts', async t => { | |
RUN_SCRIPTS.length = 0 | ||
}) | ||
|
||
t.test('non-default env script', async t => { | ||
npm.localPrefix = t.testdir({ | ||
'package.json': JSON.stringify({ | ||
name: 'x', | ||
version: '1.2.3', | ||
scripts: { | ||
env: 'hello', | ||
}, | ||
}), | ||
}) | ||
|
||
await runScript(['env'], er => { | ||
if (er) | ||
throw er | ||
|
||
t.match(RUN_SCRIPTS, [ | ||
{ | ||
path: npm.localPrefix, | ||
args: [], | ||
scriptShell: undefined, | ||
stdio: 'inherit', | ||
stdioString: true, | ||
pkg: { | ||
name: 'x', | ||
version: '1.2.3', | ||
_id: '[email protected]', | ||
scripts: { | ||
env: 'hello', | ||
}, | ||
}, | ||
event: 'env', | ||
}, | ||
]) | ||
}) | ||
RUN_SCRIPTS.length = 0 | ||
|
||
await runScriptWin(['env'], er => { | ||
if (er) | ||
throw er | ||
|
||
t.match(RUN_SCRIPTS, [ | ||
{ | ||
path: npm.localPrefix, | ||
args: [], | ||
scriptShell: undefined, | ||
stdio: 'inherit', | ||
stdioString: true, | ||
pkg: { name: 'x', | ||
version: '1.2.3', | ||
_id: '[email protected]', | ||
scripts: { | ||
env: 'hello', | ||
}, | ||
}, | ||
event: 'env', | ||
}, | ||
]) | ||
}) | ||
RUN_SCRIPTS.length = 0 | ||
}) | ||
|
||
t.test('try to run missing script', t => { | ||
npm.localPrefix = t.testdir({ | ||
'package.json': JSON.stringify({ | ||
|