Skip to content

Commit 53cdb96

Browse files
rhendriciarna
authored andcommitted
update: don't attempt to update linked packages
Fixes: #11362 PR-URL: npm/npm#11584 Credit: @rhendric Reviewed-By: @iarna
1 parent f3c32bc commit 53cdb96

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

lib/outdated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function makePretty (p) {
139139
if (long) columns[5] = type
140140

141141
if (npm.color) {
142-
columns[0] = color[has === want ? 'yellow' : 'red'](columns[0]) // dep
142+
columns[0] = color[has === want || want === 'linked' ? 'yellow' : 'red'](columns[0]) // dep
143143
columns[2] = color.green(columns[2]) // want
144144
columns[3] = color.magenta(columns[3]) // latest
145145
columns[4] = color.brightBlack(columns[4]) // dir

lib/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function update (args, cb) {
3636
"because it's currently at the maximum version that matches its specified semver range"
3737
)
3838
}
39-
return ww.current !== ww.wanted
39+
return ww.current !== ww.wanted && ww.latest !== 'linked'
4040
})
4141
if (wanted.length === 0) return cb()
4242

test/tap/update-symlink.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
var fs = require('graceful-fs')
2+
var path = require('path')
3+
var osenv = require('osenv')
4+
var mkdirp = require('mkdirp')
5+
var mr = require('npm-registry-mock')
6+
var rimraf = require('rimraf')
7+
var test = require('tap').test
8+
9+
var common = require('../common-tap.js')
10+
11+
var pkg = path.resolve(__dirname, 'update-symlink')
12+
var originalLog
13+
14+
var fakeRoot = path.join(__dirname, 'fakeRoot')
15+
var OPTS = {
16+
env: {
17+
'npm_config_prefix': fakeRoot
18+
}
19+
}
20+
21+
var jsonLocal = {
22+
name: 'my-local-package',
23+
description: 'fixture',
24+
version: '1.0.0',
25+
dependencies: {
26+
'async': '*',
27+
'underscore': '*'
28+
}
29+
}
30+
31+
test('setup', function (t) {
32+
cleanup()
33+
originalLog = console.log
34+
mkdirp.sync(pkg)
35+
common.npm(['install', '-g', '[email protected]'], OPTS, function (err, c, out) {
36+
t.ifError(err, 'global install did not error')
37+
process.chdir(pkg)
38+
fs.writeFileSync(
39+
path.join(pkg, 'package.json'),
40+
JSON.stringify(jsonLocal, null, 2)
41+
)
42+
common.npm(['link', 'underscore'], OPTS, function (err, c, out) {
43+
t.ifError(err, 'link did not error')
44+
common.npm(['install', '[email protected]'], OPTS, function (err, c, out) {
45+
t.ifError(err, 'local install did not error')
46+
common.npm(['ls'], OPTS, function (err, c, out, stderr) {
47+
t.ifError(err)
48+
t.equal(c, 0)
49+
t.equal(stderr, '', 'got expected stderr')
50+
t.has(out, /async@0.2.9/, 'installed ok')
51+
t.has(out, /underscore@1.3.1/, 'creates local link ok')
52+
t.end()
53+
})
54+
})
55+
})
56+
})
57+
})
58+
59+
test('when update is called linked packages should be excluded', function (t) {
60+
console.log = function () {}
61+
mr({ port: common.port }, function (er, s) {
62+
common.npm(['update'], OPTS, function (err, c, out, stderr) {
63+
t.ifError(err)
64+
t.has(out, /async@1.5.2/, 'updated ok')
65+
t.doesNotHave(stderr, /ERR!/, 'no errors in stderr')
66+
s.close()
67+
t.end()
68+
})
69+
})
70+
})
71+
72+
test('cleanup', function (t) {
73+
common.npm(['rm', 'underscore', 'async'], OPTS, function (err, code) {
74+
t.ifError(err, 'npm removed the linked package without error')
75+
t.equal(code, 0, 'cleanup in local ok')
76+
process.chdir(osenv.tmpdir())
77+
common.npm(['rm', '-g', 'underscore'], OPTS, function (err, code) {
78+
t.ifError(err, 'npm removed the global package without error')
79+
t.equal(code, 0, 'cleanup in global ok')
80+
81+
console.log = originalLog
82+
cleanup()
83+
t.end()
84+
})
85+
})
86+
})
87+
88+
function cleanup () {
89+
rimraf.sync(pkg)
90+
rimraf.sync(fakeRoot)
91+
}

0 commit comments

Comments
 (0)