diff options
Diffstat (limited to 'deps/npm/lib/install/save.js')
-rw-r--r-- | deps/npm/lib/install/save.js | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/deps/npm/lib/install/save.js b/deps/npm/lib/install/save.js index 5d5f4e7f7a9..56a4a892ad4 100644 --- a/deps/npm/lib/install/save.js +++ b/deps/npm/lib/install/save.js @@ -19,9 +19,9 @@ const writeFileAtomic = require('write-file-atomic') // if the -S|--save option is specified, then write installed packages // as dependencies to a package.json file. -exports.saveRequested = function (args, tree, andReturn) { - validate('AOF', arguments) - savePackageJson(args, tree, andWarnErrors(andSaveShrinkwrap(tree, andReturn))) +exports.saveRequested = function (tree, andReturn) { + validate('OF', arguments) + savePackageJson(tree, andWarnErrors(andSaveShrinkwrap(tree, andReturn))) } function andSaveShrinkwrap (tree, andReturn) { @@ -43,13 +43,14 @@ function andWarnErrors (cb) { function saveShrinkwrap (tree, next) { validate('OF', arguments) + if (!npm.config.get('shrinkwrap') || !npm.config.get('package-lock')) { + next() + } createShrinkwrap(tree, {silent: false}, next) } -function savePackageJson (args, tree, next) { - validate('AOF', arguments) - if (!args || !args.length) { return next() } - +function savePackageJson (tree, next) { + validate('OF', arguments) var saveBundle = npm.config.get('save-bundle') // each item in the tree is a top-level thing that should be saved @@ -84,8 +85,23 @@ function savePackageJson (args, tree, next) { }) log.verbose('saving', toSave) + const types = ['dependencies', 'devDependencies', 'optionalDependencies'] toSave.forEach(function (pkg) { tree.package[pkg.save][pkg.name] = pkg.spec + const movedFrom = [] + for (let saveType of types) { + if ( + pkg.save !== saveType && + tree.package[saveType] && + tree.package[saveType][pkg.name] + ) { + movedFrom.push(saveType) + delete tree.package[saveType][pkg.name] + } + } + if (movedFrom.length) { + log.notice('save', `${pkg.name} is being moved from ${movedFrom.join(' and ')} to ${pkg.save}`) + } if (saveBundle) { var ii = bundle.indexOf(pkg.name) if (ii === -1) bundle.push(pkg.name) @@ -116,6 +132,7 @@ exports.getSaveType = function (tree, arg) { var globalInstall = npm.config.get('global') var noSaveFlags = !npm.config.get('save') && !npm.config.get('save-dev') && + !npm.config.get('save-prod') && !npm.config.get('save-optional') if (globalInstall || noSaveFlags) return null @@ -123,6 +140,8 @@ exports.getSaveType = function (tree, arg) { return 'optionalDependencies' } else if (npm.config.get('save-dev')) { return 'devDependencies' + } else if (npm.config.get('save-prod')) { + return 'dependencies' } else { if (arg) { var name = moduleName(arg) @@ -152,8 +171,8 @@ function getThingsToSave (tree) { function getThingsToRemove (tree) { validate('O', arguments) - if (!tree.removed) return [] - var toRemove = tree.removed.map(function (child) { + if (!tree.removedChildren) return [] + var toRemove = tree.removedChildren.map(function (child) { return { name: moduleName(child), save: child.save |