blob: d4af5fed46509ec5a3757b199e43e9a2e56f0f41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
var re = /^\s*("*)([^"]*?\b(?:node|iojs)(?:\.exe)?)("*)( |$)/
var npmre = /^\s*("*)([^"]*?\b(?:npm))("*)( |$)/
var path_ = require('path')
if (path_.win32) path_ = path_.win32
module.exports = function (path, rebase, whichOrUndefined) {
var m = path.match(re)
if (!m) {
m = path.match(npmre)
if (!m) return path
var npmPath = whichOrUndefined('npm') || 'npm'
npmPath = path_.dirname(npmPath) + '\\node_modules\\npm\\bin\\npm-cli.js'
return path.replace(npmre, m[1] + rebase + ' "' + npmPath + '"' + m[3] + m[4])
}
// preserve the quotes
var replace = m[1] + rebase + m[3] + m[4]
return path.replace(re, replace)
}
|