Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6588a8

Browse files
feelepxyzMichael Perrotte
authored andcommitted
Fix regression in lockfile repair for sub-deps
This fixes a regression where lockfiles with missing sub-dependencies are no longer repaired. The regression was introduced in this commit: 1fafb51 which in turn was bringing back the change from this commit 24acc9f. PR-URL: #265 Credit: @feelepxyz Close: #265 Reviewed-by: @mikemimik
1 parent 6508e83 commit b6588a8

File tree

2 files changed

+122
-3
lines changed

2 files changed

+122
-3
lines changed

lib/install/inflate-shrinkwrap.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ function isGit (sw) {
141141
}
142142

143143
function makeFakeChild (name, topPath, tree, sw, requested) {
144+
const isDirectory = requested.type === 'directory'
144145
const from = sw.from || requested.raw
145146
const pkg = {
146147
name: name,
@@ -167,16 +168,16 @@ function makeFakeChild (name, topPath, tree, sw, requested) {
167168
}
168169
const child = createChild({
169170
package: pkg,
170-
loaded: true,
171+
loaded: isDirectory,
171172
parent: tree,
172173
children: [],
173174
fromShrinkwrap: requested,
174175
fakeChild: sw,
175176
fromBundle: sw.bundled ? tree.fromBundle || tree : null,
176177
path: childPath(tree.path, pkg),
177-
realpath: requested.type === 'directory' ? requested.fetchSpec : childPath(tree.realpath, pkg),
178+
realpath: isDirectory ? requested.fetchSpec : childPath(tree.realpath, pkg),
178179
location: (tree.location === '/' ? '' : tree.location + '/') + pkg.name,
179-
isLink: requested.type === 'directory',
180+
isLink: isDirectory,
180181
isInLink: tree.isLink || tree.isInLink,
181182
swRequires: sw.requires
182183
})
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
var fs = require('graceful-fs')
2+
var path = require('path')
3+
4+
var mkdirp = require('mkdirp')
5+
var osenv = require('osenv')
6+
var rimraf = require('rimraf')
7+
var test = require('tap').test
8+
9+
var common = require('../common-tap.js')
10+
11+
var pkg = common.pkg
12+
13+
var EXEC_OPTS = { cwd: pkg }
14+
15+
var json = {
16+
name: 'install-test-cli-with-broken-package-lock',
17+
description: 'fixture',
18+
version: '0.0.0',
19+
dependencies: {
20+
optimist: '0.6.0'
21+
}
22+
}
23+
24+
var brokenLockfile = {
25+
name: 'install-test-cli-with-broken-package-lock',
26+
version: '0.0.0',
27+
lockfileVersion: 1,
28+
requires: true,
29+
dependencies: {
30+
optimist: {
31+
version: '0.6.0',
32+
resolved: 'https://registry.npmjs.org/optimist/-/optimist-0.6.0.tgz',
33+
integrity: 'sha1-aUJIJvNAX3nxQub8PZrljU27kgA=',
34+
requires: {
35+
minimist: '~0.0.1',
36+
wordwrap: '~0.0.2'
37+
}
38+
},
39+
wordwrap: {
40+
version: '0.0.3',
41+
resolved: 'https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz',
42+
integrity: 'sha1-o9XabNXAvAAI03I0u68b7WMFkQc='
43+
}
44+
}
45+
}
46+
47+
var expected = {
48+
name: 'install-test-cli-with-broken-package-lock',
49+
version: '0.0.0',
50+
lockfileVersion: 1,
51+
requires: true,
52+
dependencies: {
53+
minimist: {
54+
version: '0.0.10',
55+
resolved: 'https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz',
56+
integrity: 'sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8='
57+
},
58+
optimist: {
59+
version: '0.6.0',
60+
resolved: 'https://registry.npmjs.org/optimist/-/optimist-0.6.0.tgz',
61+
integrity: 'sha1-aUJIJvNAX3nxQub8PZrljU27kgA=',
62+
requires: {
63+
minimist: '~0.0.1',
64+
wordwrap: '~0.0.2'
65+
}
66+
},
67+
wordwrap: {
68+
version: '0.0.3',
69+
resolved: 'https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz',
70+
integrity: 'sha1-o9XabNXAvAAI03I0u68b7WMFkQc='
71+
}
72+
}
73+
}
74+
75+
test('setup', function (t) {
76+
setup()
77+
t.end()
78+
})
79+
80+
test('\'npm install-test\' should repair package-lock.json', function (t) {
81+
common.npm(['install-test'], EXEC_OPTS, function (err, code, stderr, stdout) {
82+
if (err) throw err
83+
t.comment(stdout.trim())
84+
t.comment(stderr.trim())
85+
t.is(code, 0, 'npm install did not raise error code')
86+
var lockfile = JSON.parse(fs.readFileSync(path.join(pkg, 'package-lock.json')))
87+
t.same(
88+
lockfile,
89+
expected,
90+
'package-lock.json should be repaired'
91+
)
92+
t.end()
93+
})
94+
})
95+
96+
test('cleanup', function (t) {
97+
cleanup()
98+
t.end()
99+
})
100+
101+
function setup () {
102+
cleanup()
103+
mkdirp.sync(pkg)
104+
fs.writeFileSync(
105+
path.join(pkg, 'package.json'),
106+
JSON.stringify(json, null, 2)
107+
)
108+
fs.writeFileSync(
109+
path.join(pkg, 'package-lock.json'),
110+
JSON.stringify(brokenLockfile, null, 2)
111+
)
112+
process.chdir(pkg)
113+
}
114+
115+
function cleanup () {
116+
process.chdir(osenv.tmpdir())
117+
rimraf.sync(pkg)
118+
}

0 commit comments

Comments
 (0)