Skip to content

Commit 1fafb51

Browse files
isaacsclaudiahdz
authored andcommitted
Revert "install: do not descend into directory deps' child modules"
This reverts commit 45772af Fix: https://npm.community/t/6-11-1-some-dependencies-are-no-longer-being-installed/9586/4 Also adds 2 tests to verify regression behavior. PR-URL: #242 Credit: @isaacs Close: #242 Reviewed-by: @claudiahdz
1 parent 235ed1d commit 1fafb51

5 files changed

+127
-146
lines changed

lib/install/inflate-shrinkwrap.js

+6-14
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,8 @@ function inflateShrinkwrap (topPath, tree, swdeps, opts) {
5050

5151
return BB.each(Object.keys(swdeps), (name) => {
5252
const sw = swdeps[name]
53+
const dependencies = sw.dependencies || {}
5354
const requested = realizeShrinkwrapSpecifier(name, sw, topPath)
54-
// We should not muck about in the node_modules folder of
55-
// symlinked packages. Treat its dependencies as if they
56-
// were empty, since it's none of our business.
57-
const dependencies = requested.type === 'directory' ? {}
58-
: sw.dependencies || {}
5955
return inflatableChild(
6056
onDisk[name], name, topPath, tree, sw, requested, opts
6157
).then((child) => {
@@ -145,10 +141,6 @@ function isGit (sw) {
145141
}
146142

147143
function makeFakeChild (name, topPath, tree, sw, requested) {
148-
// We should not muck about in the node_modules folder of
149-
// symlinked packages. Treat its dependencies as if they
150-
// were empty, since it's none of our business.
151-
const isDirectory = requested.type === 'directory'
152144
const from = sw.from || requested.raw
153145
const pkg = {
154146
name: name,
@@ -164,7 +156,7 @@ function makeFakeChild (name, topPath, tree, sw, requested) {
164156
_spec: requested.rawSpec,
165157
_where: topPath,
166158
_args: [[requested.toString(), topPath]],
167-
dependencies: isDirectory ? {} : sw.requires
159+
dependencies: sw.requires
168160
}
169161

170162
if (!sw.bundled) {
@@ -175,16 +167,16 @@ function makeFakeChild (name, topPath, tree, sw, requested) {
175167
}
176168
const child = createChild({
177169
package: pkg,
178-
loaded: isDirectory,
170+
loaded: true,
179171
parent: tree,
180172
children: [],
181173
fromShrinkwrap: requested,
182174
fakeChild: sw,
183175
fromBundle: sw.bundled ? tree.fromBundle || tree : null,
184176
path: childPath(tree.path, pkg),
185-
realpath: isDirectory ? requested.fetchSpec : childPath(tree.realpath, pkg),
177+
realpath: requested.type === 'directory' ? requested.fetchSpec : childPath(tree.realpath, pkg),
186178
location: (tree.location === '/' ? '' : tree.location + '/') + pkg.name,
187-
isLink: isDirectory,
179+
isLink: requested.type === 'directory',
188180
isInLink: tree.isLink || tree.isInLink,
189181
swRequires: sw.requires
190182
})
@@ -203,7 +195,7 @@ function fetchChild (topPath, tree, sw, requested) {
203195
var isLink = pkg._requested.type === 'directory'
204196
const child = createChild({
205197
package: pkg,
206-
loaded: isLink,
198+
loaded: false,
207199
parent: tree,
208200
fromShrinkwrap: requested,
209201
path: childPath(tree.path, pkg),

test/tap/install-from-local-multipath.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,9 @@ test('\'npm install\' should install local packages', function (t) {
167167
'install', '.'
168168
],
169169
EXEC_OPTS,
170-
function (err, code, stdout, stderr) {
170+
function (err, code) {
171171
t.ifError(err, 'error should not exist')
172172
t.notOk(code, 'npm install exited with code 0')
173-
// if the test fails, let's see why
174-
if (err || code) {
175-
console.error({code, stdout, stderr})
176-
}
177173
t.end()
178174
}
179175
)
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// XXX Remove in npm v7, when this is no longer how we do things
2+
const t = require('tap')
3+
const common = require('../common-tap.js')
4+
const pkg = common.pkg
5+
const mkdirp = require('mkdirp')
6+
const { writeFileSync, statSync } = require('fs')
7+
const { resolve } = require('path')
8+
const mr = require('npm-registry-mock')
9+
const rimraf = require('rimraf')
10+
11+
t.test('setup', t => {
12+
mkdirp.sync(resolve(pkg, 'node_modules'))
13+
mkdirp.sync(resolve(pkg, 'foo'))
14+
writeFileSync(resolve(pkg, 'foo', 'package.json'), JSON.stringify({
15+
name: 'foo',
16+
version: '1.2.3',
17+
dependencies: {
18+
underscore: '*'
19+
}
20+
}))
21+
22+
writeFileSync(resolve(pkg, 'package.json'), JSON.stringify({
23+
name: 'root',
24+
version: '1.2.3',
25+
dependencies: {
26+
foo: 'file:foo'
27+
}
28+
}))
29+
30+
mr({ port: common.port }, (er, s) => {
31+
if (er) {
32+
throw er
33+
}
34+
t.parent.teardown(() => s.close())
35+
t.end()
36+
})
37+
})
38+
39+
t.test('initial install to create package-lock',
40+
t => common.npm(['install', '--registry', common.registry], { cwd: pkg })
41+
.then(([code]) => t.equal(code, 0, 'command worked')))
42+
43+
t.test('remove node_modules', t =>
44+
rimraf(resolve(pkg, 'node_modules'), t.end))
45+
46+
t.test('install again from package-lock', t =>
47+
common.npm(['install', '--registry', common.registry], { cwd: pkg })
48+
.then(([code]) => {
49+
t.equal(code, 0, 'command worked')
50+
const underscore = resolve(pkg, 'node_modules', 'underscore')
51+
t.equal(statSync(underscore).isDirectory(), true, 'underscore installed')
52+
}))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const t = require('tap')
2+
const common = require('../common-tap.js')
3+
const mkdirp = require('mkdirp')
4+
const { writeFileSync, readFileSync } = require('fs')
5+
const { resolve } = require('path')
6+
const pkg = common.pkg
7+
const app = resolve(pkg, 'app')
8+
const lib = resolve(pkg, 'lib')
9+
const moda = resolve(lib, 'module-a')
10+
const modb = resolve(lib, 'module-b')
11+
12+
const rimraf = require('rimraf')
13+
14+
t.test('setup', t => {
15+
mkdirp.sync(app)
16+
mkdirp.sync(moda)
17+
mkdirp.sync(modb)
18+
19+
writeFileSync(resolve(app, 'package.json'), JSON.stringify({
20+
name: 'app',
21+
version: '1.2.3',
22+
dependencies: {
23+
moda: 'file:../lib/module-a'
24+
}
25+
}))
26+
27+
writeFileSync(resolve(moda, 'package.json'), JSON.stringify({
28+
name: 'moda',
29+
version: '1.2.3',
30+
dependencies: {
31+
modb: 'file:../module-b'
32+
}
33+
}))
34+
35+
writeFileSync(resolve(modb, 'package.json'), JSON.stringify({
36+
name: 'modb',
37+
version: '1.2.3'
38+
}))
39+
40+
t.end()
41+
})
42+
43+
t.test('initial install to create package-lock',
44+
t => common.npm(['install'], { cwd: app })
45+
.then(([code]) => t.equal(code, 0, 'command worked')))
46+
47+
t.test('remove node_modules', t =>
48+
rimraf(resolve(pkg, 'node_modules'), t.end))
49+
50+
t.test('install again from package-lock', t =>
51+
common.npm(['install'], { cwd: app })
52+
.then(([code]) => {
53+
t.equal(code, 0, 'command worked')
54+
// verify that module-b is linked under module-a
55+
const depPkg = resolve(
56+
app,
57+
'node_modules',
58+
'moda',
59+
'node_modules',
60+
'modb',
61+
'package.json'
62+
)
63+
const data = JSON.parse(readFileSync(depPkg, 'utf8'))
64+
t.strictSame(data, {
65+
name: 'modb',
66+
version: '1.2.3'
67+
})
68+
}))

test/tap/install-symlink-leave-children-alone.js

-127
This file was deleted.

0 commit comments

Comments
 (0)