Skip to content

Commit d68210f

Browse files
authored
Merge pull request #64 from bestander/issue-62-react-native
Fixed flattening algorithm
2 parents 1e7a181 + 2a3afd4 commit d68210f

13 files changed

Lines changed: 68 additions & 7 deletions

File tree

src/package-linker.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,16 @@ export default class PackageLinker {
169169

170170
//
171171
let tickCopyModule = this.reporter.progress(flatTree.length);
172-
await promise.queue(flatTree, async function ([dest, { loc: src, pkg }]) {
172+
await promise.queue(flatTree, async function ([dest, { pkg }]) {
173173
pkg.reference.setLocation(dest);
174-
175174
await fs.mkdirp(dest);
176-
await fs.copy(src, dest);
175+
}, 4);
177176

177+
// TODO concurrent copies can interfere when copying master and a sub dependency in parallel
178+
await promise.queue(flatTree, async function ([dest, { loc: src }]) {
179+
await fs.copy(src, dest);
178180
tickCopyModule(dest);
179-
}, 4);
181+
}, 1);
180182

181183
//
182184
let tickBin = this.reporter.progress(flatTree.length);
@@ -257,7 +259,6 @@ export default class PackageLinker {
257259

258260
//
259261
let src = this.config.generateHardModulePath(ref);
260-
261262
// link bins
262263
if (!_.isEmpty(resolved.bin)) {
263264
let binLoc = path.join(this.config.cwd, await ref.getFolder(), ".bin");

test/commands/install.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ test("install with --save and offline mirror", () => {
100100

101101
let rawLockfile = await fs.readFile(path.join(cwd, constants.LOCKFILE_FILENAME));
102102
let lockfile = parse(rawLockfile);
103-
assert(lockfile["is-array@1.0.1"]["resolved"] ===
103+
assert.equal(lockfile["is-array@1.0.1"]["resolved"],
104104
"is-array-1.0.1.tgz#e9850cc2cc860c3bc0977e84ccf0dd464584279a");
105105

106106
await fs.unlink(path.join(cwd, mirrorPath));
@@ -121,7 +121,7 @@ test("install with --save and without offline mirror", () => {
121121

122122
let rawLockfile = await fs.readFile(path.join(cwd, constants.LOCKFILE_FILENAME));
123123
let lockfile = parse(rawLockfile);
124-
assert(lockfile["is-array@1.0.1"]["resolved"] ===
124+
assert.equal(lockfile["is-array@1.0.1"]["resolved"],
125125
"https://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz#e9850cc2cc860c3bc0977e84ccf0dd464584279a");
126126

127127
await fs.unlink(path.join(cwd, mirrorPath));
@@ -142,3 +142,26 @@ test("install from offline mirror", () => {
142142
return allFiles;
143143
});
144144
});
145+
146+
test("install should not flatten dependencies if there are collisions", () => {
147+
// A@2.0.1 -> B@2.0.0
148+
// B@1.0.0
149+
// should result in B@2.0.0 not flattened
150+
return run({}, [], "install-dont-flatten-when-conflict", async (cwd) => {
151+
let rawDepBPackage = await fs.readFile(path.join(cwd, "node_modules/dep-b/package.json"));
152+
assert.equal(JSON.parse(rawDepBPackage).version, "1.0.0");
153+
rawDepBPackage = await fs.readFile(path.join(cwd, "node_modules/dep-a/node_modules/dep-b/package.json"));
154+
assert.equal(JSON.parse(rawDepBPackage).version, "2.0.0");
155+
});
156+
});
157+
158+
test("install should flatten dependencies at the most top level without collisions", () => {
159+
// A@2.0.1 -> B@2.0.0
160+
// should result in B@2.0.0 flattened
161+
return run({}, [], "install-flatten-when-no-conflict", async (cwd) => {
162+
let rawDepBPackage = await fs.readFile(path.join(cwd, "node_modules/dep-b/package.json"));
163+
assert.equal(JSON.parse(rawDepBPackage).version, "2.0.0");
164+
rawDepBPackage = await fs.readFile(path.join(cwd, "node_modules/dep-a/package.json"));
165+
assert.equal(JSON.parse(rawDepBPackage).version, "2.0.1");
166+
});
167+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kpm-offline-mirror=./mirror-for-offline
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
dep-a@2.0.1:
2+
name dep-a
3+
version "2.0.1"
4+
resolved dep-a-2.0.1.tgz#9651b29dbff798e65ddd0f9941eefcd139466e2e
5+
dependencies:
6+
dep-b "2.0.0"
7+
dep-b@1.0.0:
8+
name dep-b
9+
version "1.0.0"
10+
resolved dep-b-1.0.0.tgz#20e1c32691d41bf8a8a02550bbf41faa7c3db5b7
11+
dep-b@^2.0.0:
12+
name dep-b
13+
version "2.0.0"
14+
resolved dep-b-2.0.0.tgz#70d81646e122375676f615834e73cd9737341844
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"dep-a": "2.0.1",
4+
"dep-b": "1.0.0"
5+
}
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kpm-offline-mirror=./mirror-for-offline
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
dep-a@2.0.1:
2+
name dep-a
3+
version "2.0.1"
4+
resolved dep-a-2.0.1.tgz#9651b29dbff798e65ddd0f9941eefcd139466e2e
5+
dependencies:
6+
dep-b "2.0.0"
7+
dep-b@^2.0.0:
8+
name dep-b
9+
version "2.0.0"
10+
resolved dep-b-2.0.0.tgz#70d81646e122375676f615834e73cd9737341844

0 commit comments

Comments
 (0)