From 99f61c434522c6d01f7714c0da271317eba683c8 Mon Sep 17 00:00:00 2001 From: Konstantin Raev Date: Fri, 23 Jun 2017 11:20:28 -0700 Subject: [PATCH 1/4] fixes transtive file: dependencies --- __tests__/commands/install/integration.js | 6 ++++++ .../install/transitive-file/deps/a-1/package.json | 7 +++++++ .../install/transitive-file/deps/b-1/b-1.0.0.tgz | Bin 0 -> 438 bytes .../fixtures/install/transitive-file/package.json | 7 +++++++ src/resolvers/exotics/file-resolver.js | 2 +- 5 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 __tests__/fixtures/install/transitive-file/deps/a-1/package.json create mode 100644 __tests__/fixtures/install/transitive-file/deps/b-1/b-1.0.0.tgz create mode 100644 __tests__/fixtures/install/transitive-file/package.json diff --git a/__tests__/commands/install/integration.js b/__tests__/commands/install/integration.js index 463ccfae80..1ed2a12745 100644 --- a/__tests__/commands/install/integration.js +++ b/__tests__/commands/install/integration.js @@ -849,3 +849,9 @@ test.concurrent('package version resolve should be deterministic', (): Promise => { + return runInstall({}, 'transitive-file', async (config, reporter) => { + expect(await fs.exists(path.join(config.cwd, 'node_modules', 'b'))).toBe(true); + }); +}); diff --git a/__tests__/fixtures/install/transitive-file/deps/a-1/package.json b/__tests__/fixtures/install/transitive-file/deps/a-1/package.json new file mode 100644 index 0000000000..689146054d --- /dev/null +++ b/__tests__/fixtures/install/transitive-file/deps/a-1/package.json @@ -0,0 +1,7 @@ +{ + "name": "a", + "version": "1.0.0", + "dependencies": { + "b": "file:../b-1/b-1.0.0.tgz" + } +} diff --git a/__tests__/fixtures/install/transitive-file/deps/b-1/b-1.0.0.tgz b/__tests__/fixtures/install/transitive-file/deps/b-1/b-1.0.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..b9e2bcc285e4c89ea3e0882713ff8dcfc8e0678c GIT binary patch literal 438 zcmV;n0ZINJiwFP!000006YZ4CPTVjQhO_olSXsBh$CuctFUw11q_sy3zn#i!O;Tm~=K zHv%Mhckk=Bqt6G?$QJcP1EPE>o#bhn|JElatt?{kQg`DlFYR}i+A1PC%8J=S`I`rH zGe;bha)QxoF=Tj-FWMdh70hEjZh?J`Pe1mja zxl5}#Nn%84Tg+v-7K$?=1OmVh7DP$sU_P8yT6OPgYB#exl?I+D%E8z4bJjJ?)(v9K zFx+gAtG2GJCmT(#J*GV`#LK1ripTSx_z7Fjeu{}sYGY=SlXgu_Aj gq1is9X`{>oHAL5a0QB_q^t?0f0Zmu~WdIHU0APaFTmS$7 literal 0 HcmV?d00001 diff --git a/__tests__/fixtures/install/transitive-file/package.json b/__tests__/fixtures/install/transitive-file/package.json new file mode 100644 index 0000000000..8ab2fe880e --- /dev/null +++ b/__tests__/fixtures/install/transitive-file/package.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "a": "file:deps/a-1", + "b": "file:deps/b-2", + "d": "file:deps/d-1" + } +} diff --git a/src/resolvers/exotics/file-resolver.js b/src/resolvers/exotics/file-resolver.js index 08b4954218..34791cee8b 100644 --- a/src/resolvers/exotics/file-resolver.js +++ b/src/resolvers/exotics/file-resolver.js @@ -107,7 +107,7 @@ export default class FileResolver extends ExoticResolver { if (temp === section) { temp = Object.assign({}, section); } - temp[k] = `file:${path.relative(this.config.cwd, path.join(loc, util.removePrefix(v, 'file:')))}`; + temp[k] = `file:./${path.relative(this.config.cwd, path.join(loc, util.removePrefix(v, 'file:')))}`; } } From 362650434a78a239ec278258be38b7c543ab7b92 Mon Sep 17 00:00:00 2001 From: Konstantin Raev Date: Fri, 23 Jun 2017 11:49:33 -0700 Subject: [PATCH 2/4] fixed tests --- __tests__/commands/install/integration.js | 2 +- .../install/install-prod-deduped-direct-dev-dep/package.json | 4 ++-- __tests__/fixtures/install/transitive-file/package.json | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/__tests__/commands/install/integration.js b/__tests__/commands/install/integration.js index 1ed2a12745..d06d110295 100644 --- a/__tests__/commands/install/integration.js +++ b/__tests__/commands/install/integration.js @@ -850,7 +850,7 @@ test.concurrent('package version resolve should be deterministic', (): Promise => { +test.concurrent('transitive file: dependencies should work', (): Promise => { return runInstall({}, 'transitive-file', async (config, reporter) => { expect(await fs.exists(path.join(config.cwd, 'node_modules', 'b'))).toBe(true); }); diff --git a/__tests__/fixtures/install/install-prod-deduped-direct-dev-dep/package.json b/__tests__/fixtures/install/install-prod-deduped-direct-dev-dep/package.json index b08417d92b..4ae6a5df36 100644 --- a/__tests__/fixtures/install/install-prod-deduped-direct-dev-dep/package.json +++ b/__tests__/fixtures/install/install-prod-deduped-direct-dev-dep/package.json @@ -1,8 +1,8 @@ { "dependencies": { - "a": "file:a" + "a": "file:./a" }, "devDependencies": { - "b": "file:b" + "b": "file:./b" } } diff --git a/__tests__/fixtures/install/transitive-file/package.json b/__tests__/fixtures/install/transitive-file/package.json index 8ab2fe880e..bf8183b7b7 100644 --- a/__tests__/fixtures/install/transitive-file/package.json +++ b/__tests__/fixtures/install/transitive-file/package.json @@ -1,7 +1,5 @@ { "dependencies": { - "a": "file:deps/a-1", - "b": "file:deps/b-2", - "d": "file:deps/d-1" + "a": "file:deps/a-1" } } From 1bcd84cbb02f1d1de45291ba9f521b61f4fab712 Mon Sep 17 00:00:00 2001 From: Konstantin Raev Date: Fri, 23 Jun 2017 12:26:51 -0700 Subject: [PATCH 3/4] moved file: stripping to fetcher --- .../install-prod-deduped-direct-dev-dep/package.json | 4 ++-- src/fetchers/tarball-fetcher.js | 8 ++++++-- src/resolvers/exotics/file-resolver.js | 2 +- src/resolvers/exotics/tarball-resolver.js | 5 ++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/__tests__/fixtures/install/install-prod-deduped-direct-dev-dep/package.json b/__tests__/fixtures/install/install-prod-deduped-direct-dev-dep/package.json index 4ae6a5df36..b08417d92b 100644 --- a/__tests__/fixtures/install/install-prod-deduped-direct-dev-dep/package.json +++ b/__tests__/fixtures/install/install-prod-deduped-direct-dev-dep/package.json @@ -1,8 +1,8 @@ { "dependencies": { - "a": "file:./a" + "a": "file:a" }, "devDependencies": { - "b": "file:./b" + "b": "file:b" } } diff --git a/src/fetchers/tarball-fetcher.js b/src/fetchers/tarball-fetcher.js index 51d53029b5..cb1dfdf321 100644 --- a/src/fetchers/tarball-fetcher.js +++ b/src/fetchers/tarball-fetcher.js @@ -14,6 +14,7 @@ const url = require('url'); const fs = require('fs'); const stream = require('stream'); const gunzip = require('gunzip-maybe'); +import {removePrefix} from '../util/misc.js'; export default class TarballFetcher extends BaseFetcher { async setupMirrorFromCache(): Promise { @@ -174,13 +175,16 @@ export default class TarballFetcher extends BaseFetcher { } async _fetch(): Promise { + const isFilePath = this.reference.startsWith('file:'); + this.reference = removePrefix(this.reference, 'file:'); const urlParse = url.parse(this.reference); - const isFilePath = urlParse.protocol + // legacy support for local paths in yarn.lock entries + const isRelativePath = urlParse.protocol ? urlParse.protocol.match(/^[a-z]:$/i) : urlParse.pathname ? urlParse.pathname.match(/^(?:\.{1,2})?[\\\/]/) : false; - if (isFilePath) { + if (isFilePath || isRelativePath) { return this.fetchFromLocal(this.reference); } diff --git a/src/resolvers/exotics/file-resolver.js b/src/resolvers/exotics/file-resolver.js index 34791cee8b..08b4954218 100644 --- a/src/resolvers/exotics/file-resolver.js +++ b/src/resolvers/exotics/file-resolver.js @@ -107,7 +107,7 @@ export default class FileResolver extends ExoticResolver { if (temp === section) { temp = Object.assign({}, section); } - temp[k] = `file:./${path.relative(this.config.cwd, path.join(loc, util.removePrefix(v, 'file:')))}`; + temp[k] = `file:${path.relative(this.config.cwd, path.join(loc, util.removePrefix(v, 'file:')))}`; } } diff --git a/src/resolvers/exotics/tarball-resolver.js b/src/resolvers/exotics/tarball-resolver.js index b3eb45adeb..b1ae5bddb7 100644 --- a/src/resolvers/exotics/tarball-resolver.js +++ b/src/resolvers/exotics/tarball-resolver.js @@ -5,7 +5,6 @@ import type PackageRequest from '../../package-request.js'; import TarballFetcher from '../../fetchers/tarball-fetcher.js'; import ExoticResolver from './exotic-resolver.js'; import Git from './git-resolver.js'; -import {removePrefix} from '../../util/misc.js'; import guessName from '../../util/guess-name.js'; import * as versionUtil from '../../util/version.js'; import * as crypto from '../../util/crypto.js'; @@ -52,7 +51,7 @@ export default class TarballResolver extends ExoticResolver { return shrunk; } - const url = removePrefix(this.url, 'file:'); + const url = this.url; //removePrefix(this.url, 'file:'); let {hash, registry} = this; let pkgJson; @@ -71,7 +70,7 @@ export default class TarballResolver extends ExoticResolver { { type: 'tarball', reference: url, - registry, + registry, // TODO here? hash, }, this.config, From 4417bbfe77cc252a209df3bfa127d8e489e84551 Mon Sep 17 00:00:00 2001 From: Konstantin Raev Date: Fri, 23 Jun 2017 12:27:39 -0700 Subject: [PATCH 4/4] nits --- src/resolvers/exotics/tarball-resolver.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resolvers/exotics/tarball-resolver.js b/src/resolvers/exotics/tarball-resolver.js index b1ae5bddb7..12b40f0c18 100644 --- a/src/resolvers/exotics/tarball-resolver.js +++ b/src/resolvers/exotics/tarball-resolver.js @@ -51,7 +51,7 @@ export default class TarballResolver extends ExoticResolver { return shrunk; } - const url = this.url; //removePrefix(this.url, 'file:'); + const url = this.url; let {hash, registry} = this; let pkgJson; @@ -70,7 +70,7 @@ export default class TarballResolver extends ExoticResolver { { type: 'tarball', reference: url, - registry, // TODO here? + registry, hash, }, this.config,