Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit b894413

Browse files
misterbyrneiarna
authored andcommitted
inflate-shrinkwrap: Inflate nested dependencies within a shrinkwrap
PR-URL: #12373 Fixes: #12372 Credit: @misterbyrne Reviewed-By: @iarna
1 parent b020127 commit b894413

2 files changed

Lines changed: 134 additions & 1 deletion

File tree

lib/install/inflate-shrinkwrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var inflateShrinkwrap = module.exports = function (tree, swdeps, finishInflating
3232
child.package.version === sw.version)) {
3333
if (!child.fromShrinkwrap) child.fromShrinkwrap = spec
3434
tree.children.push(child)
35-
return next()
35+
return inflateShrinkwrap(child, sw.dependencies || {}, next)
3636
}
3737
fetchPackageMetadata(spec, tree.path, iferr(next, function (pkg) {
3838
pkg._from = sw.from || spec

test/tap/shrinkwrap-nested.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
'use strict'
2+
var test = require('tap').test
3+
var Tacks = require('tacks')
4+
var File = Tacks.File
5+
var Dir = Tacks.Dir
6+
var fs = require('fs')
7+
var path = require('path')
8+
var common = require('../common-tap.js')
9+
10+
var testdir = path.resolve(__dirname, path.basename(__filename, '.js'))
11+
var modAdir = path.resolve(testdir, 'modA')
12+
var modB1dir = path.resolve(testdir, 'modB@1')
13+
var modB2dir = path.resolve(testdir, 'modB@2')
14+
var modCdir = path.resolve(testdir, 'modC')
15+
16+
var fixture = new Tacks(Dir({
17+
'package.json': File({
18+
dependencies: {
19+
modA: 'file://' + modAdir,
20+
modC: 'file://' + modCdir
21+
}
22+
}),
23+
'npm-shrinkwrap.json': File({
24+
dependencies: {
25+
modA: {
26+
version: '1.0.0',
27+
from: 'modA',
28+
resolved: 'file://' + modAdir
29+
},
30+
modB: {
31+
version: '1.0.0',
32+
from: 'modB@1',
33+
resolved: 'file://' + modB1dir
34+
}
35+
}
36+
}),
37+
'modA': Dir({
38+
'package.json': File({
39+
name: 'modA',
40+
version: '1.0.0',
41+
dependencies: {
42+
'modB': 'file://' + modB1dir
43+
}
44+
})
45+
}),
46+
'modB@1': Dir({
47+
'package.json': File({
48+
name: 'modB',
49+
version: '1.0.0'
50+
}),
51+
'B1': File('')
52+
}),
53+
'modB@2': Dir({
54+
'package.json': File({
55+
name: 'modB',
56+
version: '2.0.0'
57+
}),
58+
'B2': File('')
59+
}),
60+
'modC': Dir({
61+
'package.json': File({
62+
name: 'modC',
63+
version: '1.0.0',
64+
dependencies: {
65+
'modB': 'file://' + modB2dir
66+
}
67+
})
68+
})
69+
}))
70+
71+
var newShrinkwrap = new Tacks(Dir({
72+
'npm-shrinkwrap.json': File({
73+
dependencies: {
74+
modA: {
75+
version: '1.0.0',
76+
from: 'modA',
77+
resolved: 'file://' + modAdir
78+
},
79+
modB: {
80+
version: '1.0.0',
81+
from: 'modB@1',
82+
resolved: 'file://' + modB1dir
83+
},
84+
modC: {
85+
version: '1.0.0',
86+
from: 'modC',
87+
resolved: 'file://' + modCdir,
88+
dependencies: {
89+
modB: {
90+
version: '1.0.0',
91+
from: 'modB@1',
92+
resolved: 'file://' + modB1dir
93+
}
94+
}
95+
}
96+
}
97+
})
98+
}))
99+
100+
function setup () {
101+
fixture.create(testdir)
102+
}
103+
104+
function cleanup () {
105+
fixture.remove(testdir)
106+
}
107+
108+
test('setup', function (t) {
109+
cleanup()
110+
setup()
111+
common.npm(['install'], {cwd: testdir, stdio: [0, 2, 2]}, function (err, code) {
112+
if (err) throw err
113+
t.is(code, 0)
114+
t.end()
115+
})
116+
})
117+
118+
test('incremental install', function (t) {
119+
newShrinkwrap.create(testdir)
120+
common.npm(['install'], {cwd: testdir, stdio: [0, 2, 2]}, function (err, code) {
121+
if (err) throw err
122+
t.is(code, 0, 'npm itself completed ok')
123+
fs.stat(path.join(testdir, 'node_modules', 'modC', 'node_modules', 'modB', 'B1'), function (missing) {
124+
t.ok(!missing, 'modC got the updated version of modB')
125+
t.end()
126+
})
127+
})
128+
})
129+
130+
test('cleanup', function (t) {
131+
cleanup()
132+
t.end()
133+
})

0 commit comments

Comments
 (0)