Skip to content

Commit

Permalink
run-script: allow custom shell (#16687)
Browse files Browse the repository at this point in the history
Fixes: npm/npm#6543

PR-URL: npm/npm#16687
Credit: @mmkal
Reviewed-By: @zkat
Reviewed-By: @iarna
  • Loading branch information
mmkal authored and zkat committed Jul 5, 2017
1 parent 7d65004 commit a09c1a6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
7 changes: 7 additions & 0 deletions doc/misc/npm-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,13 @@ in to a private registry for the first time:
will cause `@organization` to be mapped to the registry for future installation
of packages specified according to the pattern `@organization/package`.

### script-shell

* Default: `null`
* Type: path

The shell to use for scripts run with the `npm run` command.

### scripts-prepend-node-path

* Default: "warn-only"
Expand Down
2 changes: 2 additions & 0 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ Object.defineProperty(exports, 'defaults', {get: function () {
'save-prefix': '^',
'save-prod': false,
scope: '',
'script-shell': null,
'scripts-prepend-node-path': 'warn-only',
searchopts: '',
searchexclude: null,
Expand Down Expand Up @@ -326,6 +327,7 @@ exports.types = {
'save-prefix': String,
'save-prod': Boolean,
scope: String,
'script-shell': [null, String],
'scripts-prepend-node-path': [false, true, 'auto', 'warn-only'],
searchopts: String,
searchexclude: [null, String],
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) {
var sh = 'sh'
var shFlag = '-c'

if (process.platform === 'win32') {
var customShell = npm.config.get('script-shell')

if (customShell) {
sh = customShell
} else if (process.platform === 'win32') {
sh = process.env.comspec || 'cmd'
shFlag = '/d /s /c'
conf.windowsVerbatimArguments = true
Expand Down
14 changes: 14 additions & 0 deletions test/tap/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ var exitCode = {
}
}

var shell = {
name: 'scripted',
version: '1.2.3',
scripts: {
'start': 'echo foo'
}
}

function testOutput (t, command, er, code, stdout, stderr) {
var lines

Expand Down Expand Up @@ -308,6 +316,12 @@ test('npm run-script no-params (direct only)', function (t) {
})
})

test('npm run-script script-shell config', function (t) {
writeMetadata(shell)

common.npm(['run-script', 'start', '--script-shell', 'echo'], opts, testOutput.bind(null, t, '-c echo foo'))
})

test('npm run-script no-params (direct only)', function (t) {
var expected = [
'Lifecycle scripts included in scripted:',
Expand Down

0 comments on commit a09c1a6

Please sign in to comment.