Skip to content

Commit

Permalink
lifecycle: small tweaks to message
Browse files Browse the repository at this point in the history
PR-URL: npm/npm#14334
Credit: @zkat
Reviewed-By: @iarna
Reviewed-By: @addaleax
  • Loading branch information
zkat committed Oct 19, 2016
1 parent e16c14a commit 6a7d375
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 6 additions & 4 deletions lib/utils/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function shouldPrependCurrentNodeDirToPATH () {
var isDifferentNodeInPath

var isWindows = process.platform === 'win32'
var foundExecPath = '(none)'
var foundExecPath
try {
foundExecPath = which.sync(path.basename(process.execPath), {pathExt: isWindows ? ';' : ':'})
isDifferentNodeInPath = process.execPath.toUpperCase() !== foundExecPath.toUpperCase()
Expand All @@ -159,9 +159,11 @@ function shouldPrependCurrentNodeDirToPATH () {

if (cfgsetting === 'warn-only') {
if (isDifferentNodeInPath && !shouldPrependCurrentNodeDirToPATH.hasWarned) {
log.warn('lifecycle', 'The node binary used for scripts is', foundExecPath,
'but npm uses', process.execPath,
'itself. You may want to take a look at npm’s --scripts-prepend-node-path option.')
if (foundExecPath) {
log.warn('lifecycle', 'The node binary used for scripts is', foundExecPath, 'but npm is using', process.execPath, 'itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.')
} else {
log.warn('lifecycle', 'npm is using', process.execPath, 'but there is no node binary in the current PATH. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.')
}
shouldPrependCurrentNodeDirToPATH.hasWarned = true
}

Expand Down
7 changes: 2 additions & 5 deletions test/tap/lifecycle-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,8 @@ function checkPath (withDirOfCurrentNode, prependNodePathSetting, t) {

if (prependNodePathSetting === 'warn-only') {
if (withDirOfCurrentNode) {
t.match(stderr, new RegExp(
'npm WARN lifecycle The node binary used for scripts is \\(none\\) ' +
'but npm uses .*test.tap.lifecycle-path.node-bin.my_bundled_node(.exe)? ' +
'itself.'
))
t.match(stderr, /npm WARN lifecycle/, 'spit out a warning')
t.match(stderr, /npm is using .*test.tap.lifecycle-path.node-bin.my_bundled_node(.exe)?/, 'mention the path of the binary npm itself is using.')
} else {
t.same(stderr, '')
}
Expand Down

0 comments on commit 6a7d375

Please sign in to comment.