Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
feat(npm): embed npm binary
Browse files Browse the repository at this point in the history
BREAKING CHANGE: npx will no longer use the system npm -- it embeds its own
  • Loading branch information
zkat committed Jun 3, 2017
1 parent 34d71d3 commit a2cae9d
Show file tree
Hide file tree
Showing 3 changed files with 1,640 additions and 17 deletions.
30 changes: 14 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let rimraf
const updateNotifier = require('update-notifier')
const which = BB.promisify(require('which'))

const INSTALLER_PATH = path.resolve(__dirname, 'node_modules/.bin/npm')
const PATH_SEP = process.platform === 'win32' ? ';' : ':'

updateNotifier({pkg}).notify()
Expand Down Expand Up @@ -98,13 +99,12 @@ function getExistingPath (command, opts) {

module.exports._getNpmCache = getNpmCache
function getNpmCache (opts) {
return which('npm').then(npmPath => {
const args = ['config', 'get', 'cache']
if (opts.userconfig) {
args.push('--userconfig', opts.userconfig)
}
return child.exec(npmPath, ['config', 'get', 'cache'])
}).then(cache => cache.trim())
const args = ['config', 'get', 'cache']
if (opts.userconfig) {
args.push('--userconfig', opts.userconfig)
}
return child.exec(INSTALLER_PATH, ['config', 'get', 'cache'])
.then(cache => cache.trim())
}

module.exports._buildArgs = buildArgs
Expand All @@ -121,14 +121,12 @@ function buildArgs (specs, prefix, opts) {
module.exports._installPackages = installPackages
function installPackages (specs, prefix, npmOpts) {
const args = buildArgs(specs, prefix, npmOpts)
return which('npm').then(npmPath => {
return child.spawn(npmPath, args, {
stdio: [0, 'ignore', 2]
}).catch(err => {
if (err.exitCode) {
err.message = `Install for ${specs} failed with code ${err.exitCode}`
}
throw err
})
return child.spawn(INSTALLER_PATH, args, {
stdio: [0, 'ignore', 2]
}).catch(err => {
if (err.exitCode) {
err.message = `Install for ${specs} failed with code ${err.exitCode}`
}
throw err
})
}
Loading

0 comments on commit a2cae9d

Please sign in to comment.