Skip to content

Commit e135c2b

Browse files
larsgwzkat
authored andcommitted
update: re-enable updating local packages
PR #11584 removed the possibility of updating local packages (linked with symlinks) with `npm update`. Reason was that this functionality didn't work in v3.6.0. However, the system behind local dependencies has since changed, and I can't reproduce the original error anymore. Reverts 59e5056 Fixes: https://npm.community/t/1725?u=larsgw PR-URL: #73 Credit: @larsgw Reviewed-By: @iarna Reviewed-By: @zkat
1 parent 8047b19 commit e135c2b

File tree

4 files changed

+244
-2
lines changed

4 files changed

+244
-2
lines changed

Diff for: lib/outdated.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function makePretty (p, opts) {
157157
}
158158

159159
if (opts.color) {
160-
columns[0] = color[has === want || want === 'linked' ? 'yellow' : 'red'](columns[0]) // dep
160+
columns[0] = color[has === want ? 'yellow' : 'red'](columns[0]) // dep
161161
columns[2] = color.green(columns[2]) // want
162162
columns[3] = color.magenta(columns[3]) // latest
163163
}

Diff for: lib/update.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function update_ (args) {
4646
"because it's currently at the maximum version that matches its specified semver range"
4747
)
4848
}
49-
return ww.current !== ww.wanted && ww.latest !== 'linked'
49+
return ww.current !== ww.wanted
5050
})
5151
if (wanted.length === 0) return
5252

Diff for: test/tap/outdated-symlink.js

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
'use strict'
2+
const path = require('path')
3+
const test = require('tap').test
4+
const mr = require('npm-registry-mock')
5+
const Tacks = require('tacks')
6+
const File = Tacks.File
7+
const Symlink = Tacks.Symlink
8+
const Dir = Tacks.Dir
9+
const common = require('../common-tap.js')
10+
11+
const basedir = path.join(__dirname, path.basename(__filename, '.js'))
12+
const testdir = path.join(basedir, 'testdir')
13+
const cachedir = path.join(basedir, 'cache')
14+
const globaldir = path.join(basedir, 'global')
15+
const tmpdir = path.join(basedir, 'tmp')
16+
17+
const conf = {
18+
cwd: path.join(testdir, 'main'),
19+
env: Object.assign({}, process.env, {
20+
npm_config_cache: cachedir,
21+
npm_config_tmp: tmpdir,
22+
npm_config_prefix: globaldir,
23+
npm_config_registry: common.registry,
24+
npm_config_loglevel: 'warn'
25+
})
26+
}
27+
28+
let server
29+
const fixture = new Tacks(Dir({
30+
cache: Dir(),
31+
global: Dir(),
32+
tmp: Dir(),
33+
testdir: Dir({
34+
broken: Dir({
35+
'package.json': File({
36+
name: 'broken',
37+
version: '1.0.0'
38+
})
39+
}),
40+
main: Dir({
41+
node_modules: Dir({
42+
unbroken: Symlink('/testdir/unbroken')
43+
}),
44+
'package-lock.json': File({
45+
name: 'main',
46+
version: '1.0.0',
47+
lockfileVersion: 1,
48+
requires: true,
49+
dependencies: {
50+
broken: {
51+
version: 'file:../broken'
52+
},
53+
unbroken: {
54+
version: 'file:../unbroken'
55+
}
56+
}
57+
}),
58+
'package.json': File({
59+
name: 'main',
60+
version: '1.0.0',
61+
dependencies: {
62+
broken: 'file:../broken',
63+
unbroken: 'file:../unbroken'
64+
}
65+
})
66+
}),
67+
unbroken: Dir({
68+
'package.json': File({
69+
name: 'unbroken',
70+
version: '1.0.0'
71+
})
72+
})
73+
})
74+
}))
75+
76+
function setup () {
77+
cleanup()
78+
fixture.create(basedir)
79+
}
80+
81+
function cleanup () {
82+
fixture.remove(basedir)
83+
}
84+
85+
test('setup', function (t) {
86+
setup()
87+
mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
88+
if (err) throw err
89+
server = s
90+
t.done()
91+
})
92+
})
93+
94+
test('outdated sees broken links', function (t) {
95+
common.npm(['outdated', '--json'], conf, function (err, code, stdout, stderr) {
96+
if (err) throw err
97+
t.is(code, 1, 'command ran not ok')
98+
t.comment(stderr.trim())
99+
t.comment(stdout.trim())
100+
t.same(JSON.parse(stdout), {
101+
broken: {
102+
wanted: 'linked',
103+
latest: 'linked',
104+
location: ''
105+
}
106+
})
107+
t.done()
108+
})
109+
})
110+
111+
test('outdated with long output sees broken links', function (t) {
112+
common.npm(['outdated', '--long', '--json'], conf, function (err, code, stdout, stderr) {
113+
if (err) throw err
114+
t.is(code, 1, 'command ran not ok')
115+
t.comment(stderr.trim())
116+
t.comment(stdout.trim())
117+
t.same(JSON.parse(stdout), {
118+
broken: {
119+
wanted: 'linked',
120+
latest: 'linked',
121+
type: 'dependencies',
122+
location: ''
123+
}
124+
})
125+
t.done()
126+
})
127+
})
128+
129+
test('cleanup', function (t) {
130+
server.close()
131+
cleanup()
132+
t.done()
133+
})

Diff for: test/tap/update-symlink.js

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
'use strict'
2+
const path = require('path')
3+
const test = require('tap').test
4+
const mr = require('npm-registry-mock')
5+
const Tacks = require('tacks')
6+
const File = Tacks.File
7+
const Symlink = Tacks.Symlink
8+
const Dir = Tacks.Dir
9+
const common = require('../common-tap.js')
10+
11+
const basedir = path.join(__dirname, path.basename(__filename, '.js'))
12+
const testdir = path.join(basedir, 'testdir')
13+
const cachedir = path.join(basedir, 'cache')
14+
const globaldir = path.join(basedir, 'global')
15+
const tmpdir = path.join(basedir, 'tmp')
16+
17+
const conf = {
18+
cwd: path.join(testdir, 'main'),
19+
env: Object.assign({}, process.env, {
20+
npm_config_cache: cachedir,
21+
npm_config_tmp: tmpdir,
22+
npm_config_prefix: globaldir,
23+
npm_config_registry: common.registry,
24+
npm_config_loglevel: 'warn'
25+
})
26+
}
27+
28+
let server
29+
const fixture = new Tacks(Dir({
30+
cache: Dir(),
31+
global: Dir(),
32+
tmp: Dir(),
33+
testdir: Dir({
34+
broken: Dir({
35+
'package.json': File({
36+
name: 'broken',
37+
version: '1.0.0'
38+
})
39+
}),
40+
main: Dir({
41+
node_modules: Dir({
42+
unbroken: Symlink('/testdir/unbroken')
43+
}),
44+
'package-lock.json': File({
45+
name: 'main',
46+
version: '1.0.0',
47+
lockfileVersion: 1,
48+
requires: true,
49+
dependencies: {
50+
broken: {
51+
version: 'file:../broken'
52+
},
53+
unbroken: {
54+
version: 'file:../unbroken'
55+
}
56+
}
57+
}),
58+
'package.json': File({
59+
name: 'main',
60+
version: '1.0.0',
61+
dependencies: {
62+
broken: 'file:../broken',
63+
unbroken: 'file:../unbroken'
64+
}
65+
})
66+
}),
67+
unbroken: Dir({
68+
'package.json': File({
69+
name: 'unbroken',
70+
version: '1.0.0'
71+
})
72+
})
73+
})
74+
}))
75+
76+
function setup () {
77+
cleanup()
78+
fixture.create(basedir)
79+
}
80+
81+
function cleanup () {
82+
fixture.remove(basedir)
83+
}
84+
85+
test('setup', function (t) {
86+
setup()
87+
mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
88+
if (err) throw err
89+
server = s
90+
t.done()
91+
})
92+
})
93+
94+
test('update fixes broken links', function (t) {
95+
common.npm(['update'], conf, function (err, code, stdout, stderr) {
96+
if (err) throw err
97+
t.is(code, 0, 'command ran ok')
98+
t.comment(stdout.trim())
99+
t.comment(stderr.trim())
100+
t.match(stdout, '+ [email protected]')
101+
t.done()
102+
})
103+
})
104+
105+
test('cleanup', function (t) {
106+
server.close()
107+
cleanup()
108+
t.done()
109+
})

0 commit comments

Comments
 (0)