npm-cli-path
Advanced tools
Comparing version 3.1.1 to 3.1.2
35
index.js
@@ -15,7 +15,9 @@ 'use strict'; | ||
const getNpmCliPath = (async () => promisify(realpath)(await promisify(which)('npm')))(); | ||
const promisifiedRealpath = promisify(realpath); | ||
const promisifiedWhich = promisify(which); | ||
const getNpmCliPath = async () => promisifiedRealpath(await promisifiedWhich('npm')); | ||
if (process.platform !== 'win32') { | ||
module.exports = async function npmCliPath() { | ||
return getNpmCliPath; | ||
return getNpmCliPath(); | ||
}; | ||
@@ -27,19 +29,18 @@ } else { | ||
const getPreinstalledNpmCliPath = (async () => join(dirname(await getNpmCliPath), 'node_modules\\npm\\bin\\npm-cli.js'))(); | ||
const getUserInstalledCliPath = (async () => { | ||
try { | ||
return await winUserInstalledNpmCliPath(); | ||
} catch (err) { | ||
if (/lstat .*\\node_modules\\npm\\bin\\npm-cli\.js/u.test(err.message)) { | ||
return null; | ||
} | ||
throw err; | ||
} | ||
})(); | ||
module.exports = async function npmCliPath() { | ||
const [preinstalledCliPath, userInstalledCliPath] = await Promise.all([ | ||
getPreinstalledNpmCliPath, | ||
getUserInstalledCliPath | ||
(async function getPreinstalledNpmCliPath() { | ||
return join(dirname(await getNpmCliPath()), 'node_modules\\npm\\bin\\npm-cli.js'); | ||
})(), | ||
(async function getUserInstalledCliPath() { | ||
try { | ||
return await winUserInstalledNpmCliPath(); | ||
} catch (err) { | ||
if (/lstat .*\\node_modules\\npm\\bin\\npm-cli\.js/u.test(err.message)) { | ||
return null; | ||
} | ||
throw err; | ||
} | ||
})() | ||
]); | ||
@@ -46,0 +47,0 @@ |
{ | ||
"name": "npm-cli-path", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "Resolve the path of `npm-cli.js` included in the globally installed npm CLI", | ||
@@ -42,3 +42,3 @@ "repository": "shinnn/npm-cli-path", | ||
"@shinnn/eslint-config-node": "^6.0.0", | ||
"eslint": "^5.3.0", | ||
"eslint": "^5.4.0", | ||
"nyc": "^13.0.1", | ||
@@ -45,0 +45,0 @@ "pretend-platform": "^2.0.0", |
4664
40