From 4d71984886212a3aab87fb6fae2b13a08ac5efe3 Mon Sep 17 00:00:00 2001 From: Konstantin Raev Date: Fri, 23 Jun 2017 17:32:07 -0700 Subject: [PATCH] added another test --- .../commands/install/integration-deduping.js | 21 ++++++++++++++++++- .../deps/a-1/package.json | 8 +++++++ .../deps/b-1/package.json | 7 +++++++ .../deps/b-2/package.json | 4 ++++ .../deps/c-1/package.json | 4 ++++ .../deps/c-2/package.json | 4 ++++ .../deps/c-3/package.json | 4 ++++ .../deps/d-1/package.json | 7 +++++++ .../install/hardlink-collision-2/package.json | 8 +++++++ src/util/fs.js | 1 - 10 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 __tests__/fixtures/install/hardlink-collision-2/deps/a-1/package.json create mode 100644 __tests__/fixtures/install/hardlink-collision-2/deps/b-1/package.json create mode 100644 __tests__/fixtures/install/hardlink-collision-2/deps/b-2/package.json create mode 100644 __tests__/fixtures/install/hardlink-collision-2/deps/c-1/package.json create mode 100644 __tests__/fixtures/install/hardlink-collision-2/deps/c-2/package.json create mode 100644 __tests__/fixtures/install/hardlink-collision-2/deps/c-3/package.json create mode 100644 __tests__/fixtures/install/hardlink-collision-2/deps/d-1/package.json create mode 100644 __tests__/fixtures/install/hardlink-collision-2/package.json diff --git a/__tests__/commands/install/integration-deduping.js b/__tests__/commands/install/integration-deduping.js index d08757fd20..8e099e0a37 100644 --- a/__tests__/commands/install/integration-deduping.js +++ b/__tests__/commands/install/integration-deduping.js @@ -226,7 +226,7 @@ test.concurrent('install should not copy node_modules when hardlinking', (): Pro // A@1 -> B@1 -> C@1 // -> C@2 // B@2 - // C@2 + // C@3 // D@1 -> B@1 (hardlink) -> C@1 (hardlink) // -> C@2 return runInstall({linkDuplicates: true}, 'hardlink-collision', async config => { @@ -238,3 +238,22 @@ test.concurrent('install should not copy node_modules when hardlinking', (): Pro expect(a_1.ino).toEqual(d_1.ino); }); }); + +test.concurrent('install should not hardlink full package structure', (): Promise => { + // https://github.com/yarnpkg/yarn/issues/2734 + // A@1 -> B@1 -> C@1 + // -> C@2 + // B@2 + // C@3 + // D@1 -> B@1 (hardlink) + // -> C@1 (hardlink) + return runInstall({linkDuplicates: true}, 'hardlink-collision-2', async config => { + let a_1 = await fs.stat(path.join(config.cwd, 'node_modules/a/node_modules/b/package.json')); + let d_1 = await fs.stat(path.join(config.cwd, 'node_modules/d/node_modules/b/package.json')); + expect(a_1.ino).toEqual(d_1.ino); + a_1 = await fs.stat(path.join(config.cwd, 'node_modules/a/node_modules/b/node_modules/c/package.json')); + d_1 = await fs.stat(path.join(config.cwd, 'node_modules/d/node_modules/c/package.json')); + expect(a_1.ino).toEqual(d_1.ino); + expect(await fs.exists(path.join(config.cwd, 'node_modules/d/node_modules/b/node_modules/c/package.json'))).toBe(false); + }); +}); diff --git a/__tests__/fixtures/install/hardlink-collision-2/deps/a-1/package.json b/__tests__/fixtures/install/hardlink-collision-2/deps/a-1/package.json new file mode 100644 index 0000000000..c2c8651d69 --- /dev/null +++ b/__tests__/fixtures/install/hardlink-collision-2/deps/a-1/package.json @@ -0,0 +1,8 @@ +{ + "name": "a", + "version": "1.0.0", + "dependencies": { + "b": "file:../b-1", + "c": "file:../c-2" + } +} diff --git a/__tests__/fixtures/install/hardlink-collision-2/deps/b-1/package.json b/__tests__/fixtures/install/hardlink-collision-2/deps/b-1/package.json new file mode 100644 index 0000000000..ad3074b214 --- /dev/null +++ b/__tests__/fixtures/install/hardlink-collision-2/deps/b-1/package.json @@ -0,0 +1,7 @@ +{ + "name": "b", + "version": "1.0.0", + "dependencies": { + "c": "file:../c-1" + } +} diff --git a/__tests__/fixtures/install/hardlink-collision-2/deps/b-2/package.json b/__tests__/fixtures/install/hardlink-collision-2/deps/b-2/package.json new file mode 100644 index 0000000000..57549744f3 --- /dev/null +++ b/__tests__/fixtures/install/hardlink-collision-2/deps/b-2/package.json @@ -0,0 +1,4 @@ +{ + "name": "b", + "version": "2.0.0" +} diff --git a/__tests__/fixtures/install/hardlink-collision-2/deps/c-1/package.json b/__tests__/fixtures/install/hardlink-collision-2/deps/c-1/package.json new file mode 100644 index 0000000000..abd3384930 --- /dev/null +++ b/__tests__/fixtures/install/hardlink-collision-2/deps/c-1/package.json @@ -0,0 +1,4 @@ +{ + "name": "c", + "version": "1.0.0" +} diff --git a/__tests__/fixtures/install/hardlink-collision-2/deps/c-2/package.json b/__tests__/fixtures/install/hardlink-collision-2/deps/c-2/package.json new file mode 100644 index 0000000000..eede1fcd97 --- /dev/null +++ b/__tests__/fixtures/install/hardlink-collision-2/deps/c-2/package.json @@ -0,0 +1,4 @@ +{ + "name": "c", + "version": "2.0.0" +} diff --git a/__tests__/fixtures/install/hardlink-collision-2/deps/c-3/package.json b/__tests__/fixtures/install/hardlink-collision-2/deps/c-3/package.json new file mode 100644 index 0000000000..6915ecb021 --- /dev/null +++ b/__tests__/fixtures/install/hardlink-collision-2/deps/c-3/package.json @@ -0,0 +1,4 @@ +{ + "name": "c", + "version": "3.0.0" +} diff --git a/__tests__/fixtures/install/hardlink-collision-2/deps/d-1/package.json b/__tests__/fixtures/install/hardlink-collision-2/deps/d-1/package.json new file mode 100644 index 0000000000..9728b0eba3 --- /dev/null +++ b/__tests__/fixtures/install/hardlink-collision-2/deps/d-1/package.json @@ -0,0 +1,7 @@ +{ + "name": "a", + "version": "2.0.0", + "dependencies": { + "b": "file:../b-1" + } +} diff --git a/__tests__/fixtures/install/hardlink-collision-2/package.json b/__tests__/fixtures/install/hardlink-collision-2/package.json new file mode 100644 index 0000000000..9b49885a10 --- /dev/null +++ b/__tests__/fixtures/install/hardlink-collision-2/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "a": "file:deps/a-1", + "b": "file:deps/b-2", + "c": "file:deps/c-3", + "d": "file:deps/d-1" + } +} diff --git a/src/util/fs.js b/src/util/fs.js index da9bc53320..f1123ec872 100644 --- a/src/util/fs.js +++ b/src/util/fs.js @@ -450,7 +450,6 @@ async function buildActionsForHardlink( // push all files to queue invariant(srcFiles, 'src files not initialised'); - // hardlinking is per package, not going into sub packages srcFiles = srcFiles.filter(f => f !== 'node_modules'); let remaining = srcFiles.length; if (!remaining) {