Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2015-07-01 06:26:22 +0300
committerRebecca Turner <me@re-becca.org>2015-07-01 14:22:58 +0300
commit68da583a6ef2b35ec3b13dbbb64678dfdb70934e (patch)
tree15f7e885645dac8de0f3d1c2b0523a1add6278f6
parent3cb6ad2a86a8d228fb10c389b3219855efd564b3 (diff)
link: fix `npm link package-name`
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
-rw-r--r--lib/install.js12
-rw-r--r--lib/link.js17
-rw-r--r--test/tap/peer-deps-invalid.js2
-rw-r--r--test/tap/peer-deps-without-package-json.js2
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(