From 1de7083002e3f81e10477d6dd732f8f521032b94 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Tue, 6 Jun 2017 17:26:45 -0700 Subject: [PATCH 1/4] Fix: Don't do range collapsing when using a frozen lockfile --- __tests__/commands/install/lockfiles.js | 14 ++++++++++++++ .../package.json | 6 ++++++ .../yarn.lock | 17 +++++++++++++++++ .../-/node.date-time-1.2.2.tgz.bin | Bin 0 -> 3664 bytes src/cli/commands/import.js | 2 +- src/cli/commands/install.js | 10 ++++++++-- src/cli/commands/list.js | 2 +- src/cli/commands/upgrade.js | 3 +-- src/cli/commands/why.js | 2 +- src/package-request.js | 6 ++++-- src/package-resolver.js | 12 ++++++++++-- 11 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 __tests__/fixtures/install/install-should-not-write-lockfile-if-not-optimized-and-frozen/package.json create mode 100644 __tests__/fixtures/install/install-should-not-write-lockfile-if-not-optimized-and-frozen/yarn.lock create mode 100644 __tests__/fixtures/request-cache/GET/registry.yarnpkg.com/node.date-time/-/node.date-time-1.2.2.tgz.bin diff --git a/__tests__/commands/install/lockfiles.js b/__tests__/commands/install/lockfiles.js index c40c557d5e..46e68de761 100644 --- a/__tests__/commands/install/lockfiles.js +++ b/__tests__/commands/install/lockfiles.js @@ -71,6 +71,20 @@ test.concurrent("throws an error if existing lockfile isn't satisfied with --fro expect(thrown).toEqual(true); }); +test.concurrent( + "doesn't write new lockfile if existing one satisfied but not fully optimized with --frozen-lockfile", + (): Promise => { + return runInstall( + {frozenLockfile: true}, + 'install-should-not-write-lockfile-if-not-optimized-and-frozen', + async (config): Promise => { + const lockfile = await fs.readFile(path.join(config.cwd, 'yarn.lock')); + expect(lockfile.indexOf('left-pad@1.1.3:')).toBeGreaterThanOrEqual(0); + }, + ); + }, +); + test.concurrent('install transitive optional dependency from lockfile', (): Promise => { return runInstall({}, 'install-optional-dep-from-lockfile', (config, reporter, install) => { expect(install && install.resolver && install.resolver.patterns['fsevents@^1.0.0']).toBeTruthy(); diff --git a/__tests__/fixtures/install/install-should-not-write-lockfile-if-not-optimized-and-frozen/package.json b/__tests__/fixtures/install/install-should-not-write-lockfile-if-not-optimized-and-frozen/package.json new file mode 100644 index 0000000000..642df23cca --- /dev/null +++ b/__tests__/fixtures/install/install-should-not-write-lockfile-if-not-optimized-and-frozen/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "left-pad": "1.1.3", + "node.date-time": "1.2.2" + } +} diff --git a/__tests__/fixtures/install/install-should-not-write-lockfile-if-not-optimized-and-frozen/yarn.lock b/__tests__/fixtures/install/install-should-not-write-lockfile-if-not-optimized-and-frozen/yarn.lock new file mode 100644 index 0000000000..dd827d151b --- /dev/null +++ b/__tests__/fixtures/install/install-should-not-write-lockfile-if-not-optimized-and-frozen/yarn.lock @@ -0,0 +1,17 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +left-pad@1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a" + +left-pad@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.1.tgz#ca566bbdd84b90cc5969ac1726fda51f9d936a3c" + +node.date-time@1.2.2: + version "1.2.2" + resolved "https://registry.yarnpkg.com/node.date-time/-/node.date-time-1.2.2.tgz#2fc553b0520f1c75625b33fa5a1835c637ad9856" + dependencies: + left-pad "^1.1.0" diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/node.date-time/-/node.date-time-1.2.2.tgz.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/node.date-time/-/node.date-time-1.2.2.tgz.bin new file mode 100644 index 0000000000000000000000000000000000000000..f9b27c2fb104ce3857992e687504ec529db625be GIT binary patch literal 3664 zcmZuudpy(q-*)Q8GNBVW%}@?oHjHg7i8-cLL&#~iuNgDL3?=81W8F@Pa4(c<&LJv? za;iwA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_4vLR=sfpsX#Sg!a_ZeVmQYqj)`{s7%$)bloWx-%<_peI zf>~|YEzqN4ugBLcOmmQ^;?R8IQ$35MEMNAO7SybRmR1%RI9Rx^hj7OxbIwL+*<=Lu z?*5Z9@VULM#F_8!{>IJk`->PQd+v>|`lnrn;<>iSDj%!5=a1Fs)|h2(P5foS6?TZz zBx%1jy=CG1x$rI9jD?4hW}{XH&n%ejYMR1Z_o>5O0`(7gUy~ek8(=np@^jXtbj^jPuFH?7bf(xlI z8S-_lq?=x;<6Sj$*c^<%{>5DR9wphAeEiB4_NaP6Xe=D6t?2IXNE>JfAYQczuKW5l zev%^Q{k*o(MaN80L4cq^C8%?Svs?BY9ZIfdX!*L8$!1~1j)p~hs*Iz7{EL*_#FIN} zxSKZ(sO1l{FYn=Q$#Y-F24g!P)c^3;b!NPF&$;T<1?bpvg`zQlZ99l0j9Jjt+Y8toV%SUc9=in38iyt<6|YgE`Zt_if;Qdiv|E zd#7jE4F_v%TIDa!;ck|G`!Z5+r>Xe)RnIxw{YzaiVX?tw?m!zIkFopS+WalutsUOH ze^<%vuc~)%^t{Ym*yY5>Z=M;gGpSA6c*&oW$8S;%Tp3p zNMAek)x68D@^o8^6)4B)BfeTrn_As{V?NN@wKa8k0<`a#$iTBX+rTF>FeN{Tw8|#X z7W6r0)>eN>$~;1K-4W-kaq2WQcIW*x$YD}=cvBlp%X2MCjwyI40sdp;dRl_a-L;rj z#eG=Y<~ROUJ14fzw%s-?zWpK|zZ4wxq8fcmL=&3#a5(#tMe?WjX>|gvPfPIe>r!_% z6{pF!@y2|T>Ispf!LOhijrV%Sr#erU_WX7Zrbjl|Y|$!7U0aZC@?Ty;i%N#KZ# zM`K%{_lfc~b?fKPp6YdY^goH)@RA>#j>qH5YVyZ3-9*2>cg6 CaGh}g literal 0 HcmV?d00001 diff --git a/src/cli/commands/import.js b/src/cli/commands/import.js index 68761e5a47..9e3c4498ca 100644 --- a/src/cli/commands/import.js +++ b/src/cli/commands/import.js @@ -280,7 +280,7 @@ export class Import extends Install { if (manifest.name && this.resolver instanceof ImportPackageResolver) { this.resolver.rootName = manifest.name; } - await this.resolver.init(requests, this.flags.flat); + await this.resolver.init(requests, this.flags.flat, this.flags.frozenLockfile); const manifests: Array = await fetcher.fetch(this.resolver.getManifests(), this.config); this.resolver.updateManifests(manifests); await compatibility.check(this.resolver.getManifests(), this.config, this.flags.ignoreEngines); diff --git a/src/cli/commands/install.js b/src/cli/commands/install.js index 04b3233545..d6b1204739 100644 --- a/src/cli/commands/install.js +++ b/src/cli/commands/install.js @@ -55,6 +55,7 @@ type Flags = { flat: boolean, lockfile: boolean, pureLockfile: boolean, + frozenLockfile: boolean, skipIntegrityCheck: boolean, checkFiles: boolean, @@ -422,7 +423,12 @@ export class Install { steps.push(async (curr: number, total: number) => { this.reporter.step(curr, total, this.reporter.lang('resolvingPackages'), emoji.get('mag')); - await this.resolver.init(this.prepareRequests(depRequests), this.flags.flat, workspaceLayout); + await this.resolver.init( + this.prepareRequests(depRequests), + this.flags.flat, + this.flags.frozenLockfile, + workspaceLayout, + ); topLevelPatterns = this.preparePatterns(rawPatterns); flattenedTopLevelPatterns = await this.flatten(topLevelPatterns); return {bailout: await this.bailout(topLevelPatterns, workspaceLayout)}; @@ -693,7 +699,7 @@ export class Install { const request = await this.fetchRequestFromCwd([], ignoreUnusedPatterns); const {requests: depRequests, patterns: rawPatterns, ignorePatterns, workspaceLayout} = request; - await this.resolver.init(depRequests, this.flags.flat, workspaceLayout); + await this.resolver.init(depRequests, this.flags.flat, this.flags.frozenLockfile, workspaceLayout); await this.flatten(rawPatterns); this.markIgnored(ignorePatterns); diff --git a/src/cli/commands/list.js b/src/cli/commands/list.js index 89d204a2b3..0c1520fca0 100644 --- a/src/cli/commands/list.js +++ b/src/cli/commands/list.js @@ -175,7 +175,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg const lockfile = await Lockfile.fromDirectory(config.lockfileFolder, reporter); const install = new Install(flags, config, reporter, lockfile); const {requests: depRequests, patterns} = await install.fetchRequestFromCwd(); - await install.resolver.init(depRequests, install.flags.flat); + await install.resolver.init(depRequests, install.flags.flat, install.flags.frozenLockfile); const opts: ListOptions = { reqDepth: getReqDepth(flags.depth), diff --git a/src/cli/commands/upgrade.js b/src/cli/commands/upgrade.js index a4ee926df1..2e8f9c86c9 100644 --- a/src/cli/commands/upgrade.js +++ b/src/cli/commands/upgrade.js @@ -53,8 +53,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg throw new MessageError(reporter.lang('scopeNotValid')); } } else if (flags.latest && args.length === 0) { - addArgs = Object.keys(allDependencies) - .map(dependency => getDependency(allDependencies, dependency)); + addArgs = Object.keys(allDependencies).map(dependency => getDependency(allDependencies, dependency)); } else { addArgs = args.map(dependency => { return getDependency(allDependencies, dependency); diff --git a/src/cli/commands/why.js b/src/cli/commands/why.js index 79df3ca885..cec06dc582 100644 --- a/src/cli/commands/why.js +++ b/src/cli/commands/why.js @@ -131,7 +131,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg const lockfile = await Lockfile.fromDirectory(config.lockfileFolder, reporter); const install = new Install(flags, config, reporter, lockfile); const {requests: depRequests, patterns} = await install.fetchRequestFromCwd(); - await install.resolver.init(depRequests, install.flags.flat); + await install.resolver.init(depRequests, install.flags.flat, install.flags.frozenLockfile); const hoisted = await install.linker.getFlatHoistedTree(patterns); // finding diff --git a/src/package-request.js b/src/package-request.js index 3028b3f94a..97862c129a 100644 --- a/src/package-request.js +++ b/src/package-request.js @@ -254,7 +254,7 @@ export default class PackageRequest { /** * TODO description */ - async find(fresh: boolean): Promise { + async find(fresh: boolean, frozen: ?boolean): Promise { // find version info for this package pattern const info: ?Manifest = await this.findVersionInfo(); @@ -270,7 +270,9 @@ export default class PackageRequest { // check if while we were resolving this dep we've already resolved one that satisfies // the same range const {range, name} = PackageRequest.normalizePattern(this.pattern); - const resolved: ?Manifest = this.resolver.getHighestRangeVersionMatch(name, range); + const resolved: ?Manifest = frozen + ? this.resolver.getExactVersionMatch(name, range) + : this.resolver.getHighestRangeVersionMatch(name, range); if (resolved) { this.resolver.reportPackageWithExistingVersion(this, info); return; diff --git a/src/package-resolver.js b/src/package-resolver.js index 442ab42ae6..edc550c8cb 100644 --- a/src/package-resolver.js +++ b/src/package-resolver.js @@ -33,6 +33,8 @@ export default class PackageResolver { // whether the dependency graph will be flattened flat: boolean; + frozen: boolean; + workspaceLayout: ?WorkspaceLayout; // list of registries that have been used in this resolution @@ -448,15 +450,21 @@ export default class PackageResolver { } const request = new PackageRequest(req, this); - await request.find(fresh); + await request.find(fresh, this.frozen); } /** * TODO description */ - async init(deps: DependencyRequestPatterns, isFlat: boolean, workspaceLayout?: WorkspaceLayout): Promise { + async init( + deps: DependencyRequestPatterns, + isFlat: boolean, + isFrozen: boolean, + workspaceLayout?: WorkspaceLayout, + ): Promise { this.flat = isFlat; + this.frozen = isFrozen; this.workspaceLayout = workspaceLayout; const activity = (this.activity = this.reporter.activity()); await Promise.all(deps.map((req): Promise => this.find(req))); From 93b5c903a932cea8410b38460739f7cce3e8a534 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Thu, 8 Jun 2017 10:24:45 -0700 Subject: [PATCH 2/4] Don't use boolean arguments --- __tests__/commands/install/integration.js | 2 +- __tests__/package-resolver.js | 2 +- src/cli/commands/import.js | 9 ++++++--- src/cli/commands/install.js | 12 +++++++++--- src/cli/commands/list.js | 2 +- src/cli/commands/why.js | 2 +- src/package-request.js | 2 +- src/package-resolver.js | 7 +++---- 8 files changed, 23 insertions(+), 15 deletions(-) diff --git a/__tests__/commands/install/integration.js b/__tests__/commands/install/integration.js index e0d6b636f8..0c4d49b5c9 100644 --- a/__tests__/commands/install/integration.js +++ b/__tests__/commands/install/integration.js @@ -144,7 +144,7 @@ test('changes the cache directory when bumping the cache version', async () => { const lockfile = await Lockfile.fromDirectory(config.cwd); const resolver = new PackageResolver(config, lockfile); - await resolver.init([{pattern: 'is-array', registry: 'npm'}]); + await resolver.init([{pattern: 'is-array', registry: 'npm'}], {}); const ref = resolver.getManifests()[0]._reference; const cachePath = config.generateHardModulePath(ref, true); diff --git a/__tests__/package-resolver.js b/__tests__/package-resolver.js index 5742231f2e..f22802b287 100644 --- a/__tests__/package-resolver.js +++ b/__tests__/package-resolver.js @@ -42,7 +42,7 @@ function addTest(pattern, registry = 'npm', init: ?(cacheFolder: string) => Prom } const resolver = new PackageResolver(config, lockfile); - await resolver.init([{pattern, registry}]); + await resolver.init([{pattern, registry}], {}); const ref = resolver.getManifests()[0]._reference; const cachePath = config.generateHardModulePath(ref, true); diff --git a/src/cli/commands/import.js b/src/cli/commands/import.js index 9e3c4498ca..6073921ab5 100644 --- a/src/cli/commands/import.js +++ b/src/cli/commands/import.js @@ -227,7 +227,7 @@ class ImportPackageResolver extends PackageResolver { this.activity.tick(req.pattern); } const request = new ImportPackageRequest(req, this); - await request.find(false); + await request.find({fresh: false}); } async findAll(deps: DependencyRequestPatterns): Promise { @@ -254,7 +254,10 @@ class ImportPackageResolver extends PackageResolver { } } - async init(deps: DependencyRequestPatterns, isFlat: boolean): Promise { + async init( + deps: DependencyRequestPatterns, + {isFlat, isFrozen}: {isFlat: boolean, isFrozen?: boolean}, + ): Promise { this.flat = isFlat; const activity = (this.activity = this.reporter.activity()); await this.findAll(deps); @@ -280,7 +283,7 @@ export class Import extends Install { if (manifest.name && this.resolver instanceof ImportPackageResolver) { this.resolver.rootName = manifest.name; } - await this.resolver.init(requests, this.flags.flat, this.flags.frozenLockfile); + await this.resolver.init(requests, {isFlat: this.flags.flat, isFrozen: this.flags.frozenLockfile}); const manifests: Array = await fetcher.fetch(this.resolver.getManifests(), this.config); this.resolver.updateManifests(manifests); await compatibility.check(this.resolver.getManifests(), this.config, this.flags.ignoreEngines); diff --git a/src/cli/commands/install.js b/src/cli/commands/install.js index d6b1204739..276b572ccd 100644 --- a/src/cli/commands/install.js +++ b/src/cli/commands/install.js @@ -425,8 +425,10 @@ export class Install { this.reporter.step(curr, total, this.reporter.lang('resolvingPackages'), emoji.get('mag')); await this.resolver.init( this.prepareRequests(depRequests), - this.flags.flat, - this.flags.frozenLockfile, + { + isFlat: this.flags.flat, + isFrozen: this.flags.frozenLockfile, + }, workspaceLayout, ); topLevelPatterns = this.preparePatterns(rawPatterns); @@ -699,7 +701,11 @@ export class Install { const request = await this.fetchRequestFromCwd([], ignoreUnusedPatterns); const {requests: depRequests, patterns: rawPatterns, ignorePatterns, workspaceLayout} = request; - await this.resolver.init(depRequests, this.flags.flat, this.flags.frozenLockfile, workspaceLayout); + await this.resolver.init( + depRequests, + {isFlat: this.flags.flat, isFrozen: this.flags.frozenLockfile}, + workspaceLayout, + ); await this.flatten(rawPatterns); this.markIgnored(ignorePatterns); diff --git a/src/cli/commands/list.js b/src/cli/commands/list.js index 0c1520fca0..da224b996b 100644 --- a/src/cli/commands/list.js +++ b/src/cli/commands/list.js @@ -175,7 +175,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg const lockfile = await Lockfile.fromDirectory(config.lockfileFolder, reporter); const install = new Install(flags, config, reporter, lockfile); const {requests: depRequests, patterns} = await install.fetchRequestFromCwd(); - await install.resolver.init(depRequests, install.flags.flat, install.flags.frozenLockfile); + await install.resolver.init(depRequests, {isFlat: install.flags.flat, isFrozen: install.flags.frozenLockfile}); const opts: ListOptions = { reqDepth: getReqDepth(flags.depth), diff --git a/src/cli/commands/why.js b/src/cli/commands/why.js index cec06dc582..f086a3023b 100644 --- a/src/cli/commands/why.js +++ b/src/cli/commands/why.js @@ -131,7 +131,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg const lockfile = await Lockfile.fromDirectory(config.lockfileFolder, reporter); const install = new Install(flags, config, reporter, lockfile); const {requests: depRequests, patterns} = await install.fetchRequestFromCwd(); - await install.resolver.init(depRequests, install.flags.flat, install.flags.frozenLockfile); + await install.resolver.init(depRequests, {isFlat: install.flags.flat, isFrozen: install.flags.frozenLockfile}); const hoisted = await install.linker.getFlatHoistedTree(patterns); // finding diff --git a/src/package-request.js b/src/package-request.js index 97862c129a..b371c08e58 100644 --- a/src/package-request.js +++ b/src/package-request.js @@ -254,7 +254,7 @@ export default class PackageRequest { /** * TODO description */ - async find(fresh: boolean, frozen: ?boolean): Promise { + async find({fresh, frozen}: {fresh: boolean, frozen?: boolean}): Promise { // find version info for this package pattern const info: ?Manifest = await this.findVersionInfo(); diff --git a/src/package-resolver.js b/src/package-resolver.js index edc550c8cb..b77055a4d2 100644 --- a/src/package-resolver.js +++ b/src/package-resolver.js @@ -450,7 +450,7 @@ export default class PackageResolver { } const request = new PackageRequest(req, this); - await request.find(fresh, this.frozen); + await request.find({fresh, frozen: this.frozen}); } /** @@ -459,12 +459,11 @@ export default class PackageResolver { async init( deps: DependencyRequestPatterns, - isFlat: boolean, - isFrozen: boolean, + {isFlat, isFrozen}: {isFlat: boolean, isFrozen?: boolean}, workspaceLayout?: WorkspaceLayout, ): Promise { this.flat = isFlat; - this.frozen = isFrozen; + this.frozen = Boolean(isFrozen); this.workspaceLayout = workspaceLayout; const activity = (this.activity = this.reporter.activity()); await Promise.all(deps.map((req): Promise => this.find(req))); From a8299f7f31e37525029073bfa03b8a171cc20b47 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Thu, 8 Jun 2017 10:57:27 -0700 Subject: [PATCH 3/4] Better options, types, unicorns and everything --- src/cli/commands/import.js | 5 +++-- src/cli/commands/install.js | 19 ++++++++----------- src/package-resolver.js | 11 ++++++++--- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/cli/commands/import.js b/src/cli/commands/import.js index 6073921ab5..0904edefed 100644 --- a/src/cli/commands/import.js +++ b/src/cli/commands/import.js @@ -1,5 +1,6 @@ /* @flow */ +import type {ResolverOptions} from '../../package-resolver.js'; import type {Manifest, DependencyRequestPattern, DependencyRequestPatterns} from '../../types.js'; import type {Reporter} from '../../reporters/index.js'; import type Config from '../../config.js'; @@ -256,9 +257,9 @@ class ImportPackageResolver extends PackageResolver { async init( deps: DependencyRequestPatterns, - {isFlat, isFrozen}: {isFlat: boolean, isFrozen?: boolean}, + {isFlat, isFrozen, workspaceLayout}: ResolverOptions = {isFlat: false, isFrozen: false, workspaceLayout: undefined}, ): Promise { - this.flat = isFlat; + this.flat = Boolean(isFlat); const activity = (this.activity = this.reporter.activity()); await this.findAll(deps); this.resetOptional(); diff --git a/src/cli/commands/install.js b/src/cli/commands/install.js index 276b572ccd..e61db5838b 100644 --- a/src/cli/commands/install.js +++ b/src/cli/commands/install.js @@ -423,14 +423,11 @@ export class Install { steps.push(async (curr: number, total: number) => { this.reporter.step(curr, total, this.reporter.lang('resolvingPackages'), emoji.get('mag')); - await this.resolver.init( - this.prepareRequests(depRequests), - { - isFlat: this.flags.flat, - isFrozen: this.flags.frozenLockfile, - }, + await this.resolver.init(this.prepareRequests(depRequests), { + isFlat: this.flags.flat, + isFrozen: this.flags.frozenLockfile, workspaceLayout, - ); + }); topLevelPatterns = this.preparePatterns(rawPatterns); flattenedTopLevelPatterns = await this.flatten(topLevelPatterns); return {bailout: await this.bailout(topLevelPatterns, workspaceLayout)}; @@ -701,11 +698,11 @@ export class Install { const request = await this.fetchRequestFromCwd([], ignoreUnusedPatterns); const {requests: depRequests, patterns: rawPatterns, ignorePatterns, workspaceLayout} = request; - await this.resolver.init( - depRequests, - {isFlat: this.flags.flat, isFrozen: this.flags.frozenLockfile}, + await this.resolver.init(depRequests, { + isFlat: this.flags.flat, + isFrozen: this.flags.frozenLockfile, workspaceLayout, - ); + }); await this.flatten(rawPatterns); this.markIgnored(ignorePatterns); diff --git a/src/package-resolver.js b/src/package-resolver.js index b77055a4d2..25102daeda 100644 --- a/src/package-resolver.js +++ b/src/package-resolver.js @@ -15,6 +15,12 @@ import WorkspaceLayout from './workspace-layout.js'; const invariant = require('invariant'); const semver = require('semver'); +export type ResolverOptions = { + isFlat?: boolean, + isFrozen?: boolean, + workspaceLayout?: WorkspaceLayout, +}; + export default class PackageResolver { constructor(config: Config, lockfile: Lockfile) { this.patternsByPackage = map(); @@ -459,10 +465,9 @@ export default class PackageResolver { async init( deps: DependencyRequestPatterns, - {isFlat, isFrozen}: {isFlat: boolean, isFrozen?: boolean}, - workspaceLayout?: WorkspaceLayout, + {isFlat, isFrozen, workspaceLayout}: ResolverOptions = {isFlat: false, isFrozen: false, workspaceLayout: undefined}, ): Promise { - this.flat = isFlat; + this.flat = Boolean(isFlat); this.frozen = Boolean(isFrozen); this.workspaceLayout = workspaceLayout; const activity = (this.activity = this.reporter.activity()); From a0b3c74a945e90a2bee7a0733654a76277f2ecd8 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Thu, 8 Jun 2017 11:50:09 -0700 Subject: [PATCH 4/4] Exact types are the way --- src/package-resolver.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/package-resolver.js b/src/package-resolver.js index 25102daeda..47fb2ac23d 100644 --- a/src/package-resolver.js +++ b/src/package-resolver.js @@ -15,11 +15,11 @@ import WorkspaceLayout from './workspace-layout.js'; const invariant = require('invariant'); const semver = require('semver'); -export type ResolverOptions = { +export type ResolverOptions = {| isFlat?: boolean, isFrozen?: boolean, workspaceLayout?: WorkspaceLayout, -}; +|}; export default class PackageResolver { constructor(config: Config, lockfile: Lockfile) {