Change installCmd()'s function signature

This commit is contained in:
Rico Sta. Cruz
2016-02-02 01:09:13 +08:00
parent 0456ef7745
commit c27cefcc73
3 changed files with 32 additions and 30 deletions

View File

@@ -51,7 +51,7 @@ function run (argv) {
}
})
return installCmd(cli).catch(require('../lib/err'))
return installCmd(cli.input, cli.flags).catch(require('../lib/err'))
}
module.exports = run

View File

@@ -11,10 +11,12 @@ var save = require('../save')
var linkPeers = require('../install/link_peers')
/*
* Perform
* Perform installation.
*
* installCmd([ 'lodash', 'foo' ], { quiet: true })
*/
function run (cli) {
function installCmd (input, flags) {
var ctx = {}
var pkg
var packagesToInstall
@@ -28,10 +30,10 @@ function run (cli) {
.then(_ => linkPeers(pkg, ctx.store, ctx.installs))
function install () {
installType = cli.input && cli.input.length ? 'named' : 'general'
installType = input && input.length ? 'named' : 'general'
if (installType === 'named') {
packagesToInstall = cli.input
packagesToInstall = input
} else {
packagesToInstall = assign({}, pkg.pkg.dependencies || {})
if (!isProductionInstall) assign(packagesToInstall, pkg.pkg.devDependencies || {})
@@ -40,7 +42,7 @@ function run (cli) {
return installMultiple(ctx,
packagesToInstall,
join(ctx.root, 'node_modules'),
cli.flags)
flags)
.then(savePkgs)
}
@@ -48,16 +50,16 @@ function run (cli) {
var root = packageJson ? dirname(packageJson) : process.cwd()
ctx.root = root
ctx.store = join(root, config.store_path)
if (!cli.flags.quiet) ctx.log = logger()
if (!flags.quiet) ctx.log = logger()
else ctx.log = function () { return function () {} }
}
function savePkgs (packages) {
var saveType = getSaveType(cli.flags)
var saveType = getSaveType(flags)
if (saveType && installType === 'named') {
var inputNames = cli.input.map(pkgName => npa(pkgName).name)
var inputNames = input.map(pkgName => npa(pkgName).name)
var savedPackages = packages.filter(pkg => inputNames.indexOf(pkg.name) > -1)
return save(pkg, savedPackages, saveType, cli.flags.saveExact)
return save(pkg, savedPackages, saveType, flags.saveExact)
}
}
}
@@ -68,4 +70,4 @@ function getSaveType (flags) {
if (flags.saveOptional) return 'optionalDependencies'
}
module.exports = run
module.exports = installCmd

View File

@@ -12,7 +12,7 @@ test('eslint', require('tape-eslint')())
test('small with dependencies (rimraf)', function (t) {
prepare()
install({ input: ['rimraf@2.5.1'], flags: { quiet: true } })
install(['rimraf@2.5.1'], { quiet: true })
.then(function () {
var rimraf = require(join(process.cwd(), 'node_modules', 'rimraf'))
t.ok(typeof rimraf === 'function', 'rimraf() is available')
@@ -30,7 +30,7 @@ test('small with dependencies (rimraf)', function (t) {
test('no dependencies (lodash)', function (t) {
prepare()
install({ input: ['lodash@4.0.0'], flags: { quiet: true } })
install(['lodash@4.0.0'], { quiet: true })
.then(function () {
_ = require(join(process.cwd(), 'node_modules', 'lodash'))
t.ok(typeof _ === 'function', '_ is available')
@@ -41,7 +41,7 @@ test('no dependencies (lodash)', function (t) {
test('scoped modules without version spec (@rstacruz/tap-spec)', function (t) {
prepare()
install({ input: ['@rstacruz/tap-spec'], flags: { quiet: true } })
install(['@rstacruz/tap-spec'], { quiet: true })
.then(function () {
_ = require(join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
t.ok(typeof _ === 'function', 'tap-spec is available')
@@ -51,7 +51,7 @@ test('scoped modules without version spec (@rstacruz/tap-spec)', function (t) {
test('scoped modules with versions (@rstacruz/tap-spec@4.1.1)', function (t) {
prepare()
install({ input: ['@rstacruz/tap-spec@4.1.1'], flags: { quiet: true } })
install(['@rstacruz/tap-spec@4.1.1'], { quiet: true })
.then(function () {
_ = require(join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
t.ok(typeof _ === 'function', 'tap-spec is available')
@@ -61,7 +61,7 @@ test('scoped modules with versions (@rstacruz/tap-spec@4.1.1)', function (t) {
test('scoped modules (@rstacruz/tap-spec@*)', function (t) {
prepare()
install({ input: ['@rstacruz/tap-spec@*'], flags: { quiet: true } })
install(['@rstacruz/tap-spec@*'], { quiet: true })
.then(function () {
_ = require(join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
t.ok(typeof _ === 'function', 'tap-spec is available')
@@ -71,7 +71,7 @@ test('scoped modules (@rstacruz/tap-spec@*)', function (t) {
test('multiple scoped modules (@rstacruz/...)', function (t) {
prepare()
install({ input: ['@rstacruz/tap-spec@*', '@rstacruz/travis-encrypt@*'], flags: { quiet: true } })
install(['@rstacruz/tap-spec@*', '@rstacruz/travis-encrypt@*'], { quiet: true })
.then(function () {
_ = require(join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
t.ok(typeof _ === 'function', 'tap-spec is available')
@@ -83,8 +83,8 @@ test('multiple scoped modules (@rstacruz/...)', function (t) {
test('idempotency (rimraf)', function (t) {
prepare()
install({ input: ['rimraf@2.5.1'], flags: { quiet: true } })
.then(function () { return install({ input: [ 'rimraf@2.5.1' ], flags: { quiet: true } }) })
install(['rimraf@2.5.1'], { quiet: true })
.then(function () { return install([ 'rimraf@2.5.1' ], { quiet: true }) })
.then(function () {
var rimraf = require(join(process.cwd(), 'node_modules', 'rimraf'))
t.ok(typeof rimraf === 'function', 'rimraf is available')
@@ -94,7 +94,7 @@ test('idempotency (rimraf)', function (t) {
test('big with dependencies and circular deps (babel-preset-2015)', function (t) {
prepare()
install({ input: ['babel-preset-es2015@6.3.13'], flags: { quiet: true } })
install(['babel-preset-es2015@6.3.13'], { quiet: true })
.then(function () {
var b = require(join(process.cwd(), 'node_modules', 'babel-preset-es2015'))
t.ok(typeof b === 'object', 'babel-preset-es2015 is available')
@@ -104,7 +104,7 @@ test('big with dependencies and circular deps (babel-preset-2015)', function (t)
test('bundleDependencies (fsevents@1.0.6)', function (t) {
prepare()
install({ input: ['fsevents@1.0.6'], flags: { quiet: true } })
install(['fsevents@1.0.6'], { quiet: true })
.then(function () {
stat = fs.lstatSync(
join(process.cwd(), 'node_modules', 'fsevents', 'node_modules', '.bin', 'mkdirp'))
@@ -124,7 +124,7 @@ test('compiled modules (ursa@0.9.1)', function (t) {
}
prepare()
install({ input: ['ursa@0.9.1'], flags: { quiet: false } })
install(['ursa@0.9.1'], { quiet: false })
.then(function () {
var ursa = require(join(process.cwd(), 'node_modules', 'ursa'))
t.ok(typeof ursa === 'object', 'ursa() is available')
@@ -134,7 +134,7 @@ test('compiled modules (ursa@0.9.1)', function (t) {
test('tarballs (is-array-1.0.1.tgz)', function (t) {
prepare()
install({ input: ['http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz'], flags: { quiet: true } })
install(['http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz'], { quiet: true })
.then(function () {
var isArray = require(
join(process.cwd(), 'node_modules', 'is-array'))
@@ -155,7 +155,7 @@ test('shrinkwrap compatibility', function (t) {
JSON.stringify({ dependencies: { rimraf: '*' } }),
'utf-8')
install({ input: ['rimraf@2.5.1'], flags: { quiet: true } })
install(['rimraf@2.5.1'], { quiet: true })
.then(function () {
var npm = JSON.stringify(require.resolve('npm/bin/npm-cli.js'))
require('child_process').execSync('node ' + npm + ' shrinkwrap')
@@ -168,7 +168,7 @@ test('shrinkwrap compatibility', function (t) {
test('save to package.json (rimraf@2.5.1)', function (t) {
prepare()
install({ input: ['rimraf@2.5.1'], flags: { quiet: true, save: true } })
install(['rimraf@2.5.1'], { quiet: true, save: true })
.then(function () {
var rimraf = require(join(process.cwd(), 'node_modules', 'rimraf'))
t.ok(typeof rimraf === 'function', 'rimraf() is available')
@@ -183,7 +183,7 @@ test('save to package.json (rimraf@2.5.1)', function (t) {
test('saveDev scoped module to package.json (@rstacruz/tap-spec)', function (t) {
prepare()
install({ input: ['@rstacruz/tap-spec'], flags: { quiet: true, saveDev: true } })
install(['@rstacruz/tap-spec'], { quiet: true, saveDev: true })
.then(function () {
var tapSpec = require(join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
t.ok(typeof tapSpec === 'function', 'tapSpec() is available')
@@ -198,7 +198,7 @@ test('saveDev scoped module to package.json (@rstacruz/tap-spec)', function (t)
test('multiple save to package.json with `exact` versions (@rstacruz/tap-spec & rimraf@2.5.1)', function (t) {
prepare()
install({ input: ['@rstacruz/tap-spec@latest', 'rimraf@2.5.1'], flags: { quiet: true, save: true, saveExact: true } })
install(['@rstacruz/tap-spec@latest', 'rimraf@2.5.1'], { quiet: true, save: true, saveExact: true })
.then(function () {
var tapSpec = require(join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'))
t.ok(typeof tapSpec === 'function', 'tapSpec() is available')
@@ -220,7 +220,7 @@ test('multiple save to package.json with `exact` versions (@rstacruz/tap-spec &
test('flattening symlinks (minimatch@3.0.0)', function (t) {
prepare()
install({ input: ['minimatch@3.0.0'], flags: { quiet: true } })
install(['minimatch@3.0.0'], { quiet: true })
.then(function () {
stat = fs.lstatSync(join(process.cwd(), 'node_modules', '.store', 'node_modules', 'balanced-match'))
t.ok(stat.isSymbolicLink(), 'balanced-match is linked into store node_modules')
@@ -233,8 +233,8 @@ test('flattening symlinks (minimatch@3.0.0)', function (t) {
test('flattening symlinks (minimatch + balanced-match)', function (t) {
prepare()
install({ input: ['minimatch@3.0.0'], flags: { quiet: true } })
.then(_ => install({ input: ['balanced-match@^0.3.0'], flags: { quiet: true } }))
install(['minimatch@3.0.0'], { quiet: true })
.then(_ => install(['balanced-match@^0.3.0'], { quiet: true }))
.then(function () {
_ = exists(join(process.cwd(), 'node_modules', '.store', 'node_modules', 'balanced-match'))
t.ok(!_, 'balanced-match is removed from store node_modules')