diff options
Diffstat (limited to 'deps/npm/lib/install/action/finalize.js')
-rw-r--r-- | deps/npm/lib/install/action/finalize.js | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/deps/npm/lib/install/action/finalize.js b/deps/npm/lib/install/action/finalize.js index 62e21cc47d..08e9c149c4 100644 --- a/deps/npm/lib/install/action/finalize.js +++ b/deps/npm/lib/install/action/finalize.js @@ -4,7 +4,23 @@ var rimraf = require('rimraf') var fs = require('graceful-fs') var mkdirp = require('mkdirp') var asyncMap = require('slide').asyncMap -var andIgnoreErrors = require('../and-ignore-errors.js') +var iferr = require('iferr') + +function getTree (pkg) { + while (pkg.parent) pkg = pkg.parent + return pkg +} + +function warn (pkg, code, msg) { + var tree = getTree(pkg) + var err = new Error(msg) + err.code = code + tree.warnings.push(err) +} + +function pathToShortname (modpath) { + return modpath.replace(/node_modules[/]/g, '').replace(/[/]/g, ' > ') +} module.exports = function (top, buildpath, pkg, log, next) { log.silly('finalize', pkg.path) @@ -59,15 +75,26 @@ module.exports = function (top, buildpath, pkg, log, next) { function moveModules (mkdirEr, files) { if (mkdirEr) return next(mkdirEr) asyncMap(files, function (file, done) { + // `from` wins over `to`, because if `from` was there it's because the + // module installer wanted it to be there. By contrast, `to` is just + // whatever was bundled in this module. And the intentions of npm's + // installer should always beat out random module contents. var from = path.join(delpath, 'node_modules', file) var to = path.join(pkg.path, 'node_modules', file) - // we ignore errors here, because they can legitimately happen, for instance, - // bundled modules will be in both node_modules folders - fs.rename(from, to, andIgnoreErrors(done)) + fs.stat(to, function (er, info) { + if (er) return fs.rename(from, to, done) + + var shortname = pathToShortname(path.relative(getTree(pkg).path, to)) + warn(pkg, 'EBUNDLEOVERRIDE', 'Replacing bundled ' + shortname + ' with new installed version') + rimraf(to, iferr(done, function () { + fs.rename(from, to, done) + })) + }) }, cleanup) } - function cleanup () { + function cleanup (moveEr) { + if (moveEr) return next(moveEr) rimraf(delpath, afterCleanup) } |