From 68da583a6ef2b35ec3b13dbbb64678dfdb70934e Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Tue, 30 Jun 2015 23:26:22 -0400 Subject: link: fix `npm link package-name` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was broken two ways– it expected npm to accept a string for the list of packages to install. And it expected a install to return a list of packages added, not a tree. PR-URL: https://github.com/npm/npm/pull/8782 Fixes: #8766 --- lib/install.js | 12 +++++++++++- lib/link.js | 17 +++++++++++------ test/tap/peer-deps-invalid.js | 2 +- test/tap/peer-deps-without-package-json.js | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/install.js b/lib/install.js index 40344e90a..c29ec5e9a 100644 --- a/lib/install.js +++ b/lib/install.js @@ -257,7 +257,7 @@ Installer.prototype.run = function (cb) { log.warn('error', postInstallEr.message) log.verbose('error', postInstallEr.stack) } - cb(installEr || postInstallEr, self.idealTree) + cb(installEr || postInstallEr, self.getInstalledModules(), self.idealTree) }) }) } @@ -560,6 +560,16 @@ Installer.prototype.normalizeTree = function (log, cb) { })) } +Installer.prototype.getInstalledModules = function () { + return this.differences.filter(function (action) { + var mutation = action[0] + return (mutation === 'add' || mutation === 'update') + }).map(function (action) { + var child = action[1] + return [child.package._id, child.path] + }) +} + Installer.prototype.printInstalled = function (cb) { validate('F', arguments) log.silly('install', 'printInstalled') diff --git a/lib/link.js b/lib/link.js index b5d7f9d36..2e65b7fbd 100644 --- a/lib/link.js +++ b/lib/link.js @@ -59,11 +59,14 @@ function linkInstall (pkgs, cb) { function n (er, data) { if (er) return cb(er, data) - // install returns [ [folder, pkgId], ... ] - // but we definitely installed just one thing. - var d = data.filter(function (d) { return !d[3] }) - var what = npa(d[0][0]) - pp = d[0][1] + // we want the ONE thing that was installed into the global dir + var installed = data.filter(function (info) { + var folder = info[1] + return path.resolve(folder, '..') === npm.globalDir + }) + var id = installed[0][0] + pp = installed[0][1] + var what = npa(id) pkg = what.name target = path.resolve(npm.dir, pkg) next() @@ -85,7 +88,7 @@ function linkInstall (pkgs, cb) { fs.lstat(pp, function (er, st) { if (er) { rp = pp - return npm.commands.install(t, pkg, n) + return npm.commands.install(t, [pkg], n) } else if (!st.isSymbolicLink()) { rp = pp next() @@ -99,6 +102,7 @@ function linkInstall (pkgs, cb) { }) function next () { + if (npm.config.get('dry-run')) return resultPrinter(pkg, pp, target, rp, cb) chain( [ [npm.commands, 'unbuild', [target]], @@ -132,6 +136,7 @@ function linkPkg (folder, cb_) { er = new Error('Package must have a name field to be linked') return cb(er) } + if (npm.config.get('dry-run')) return resultPrinter(path.basename(me), me, target, cb) var target = path.resolve(npm.globalDir, d.name) symlink(me, target, false, true, function (er) { if (er) return cb(er) diff --git a/test/tap/peer-deps-invalid.js b/test/tap/peer-deps-invalid.js index 7c33e63ed..4ce2d6b26 100644 --- a/test/tap/peer-deps-invalid.js +++ b/test/tap/peer-deps-invalid.js @@ -77,7 +77,7 @@ test('installing dependencies that have conflicting peerDependencies', function registry: common.registry }, function () { - npm.commands.install([], function (err, tree) { + npm.commands.install([], function (err, additions, tree) { t.error(err) t.is(tree.warnings.length, 2) t.is(tree.warnings[0].code, 'EPEERINVALID') diff --git a/test/tap/peer-deps-without-package-json.js b/test/tap/peer-deps-without-package-json.js index 781686f62..bfb91162c 100644 --- a/test/tap/peer-deps-without-package-json.js +++ b/test/tap/peer-deps-without-package-json.js @@ -51,7 +51,7 @@ test('installing a peerDeps-using package without package.json', function (t) { registry: common.registry, cache: cache }, function () { - npm.install(common.registry + '/ok.js', function (err, result) { + npm.install(common.registry + '/ok.js', function (err, additions, result) { t.ifError(err, 'installed ok.js') t.ok( -- cgit v1.2.3