From 27d6b1a29f3ec29817330e2ea83ada47fc660b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Tue, 20 Nov 2018 15:19:22 +0000 Subject: [PATCH] Implements the new peerDependenciesMeta field --- .../missing-opt-peer-dep/foo/package.json | 7 ++++++- src/package-linker.js | 10 ++++++++-- src/types.js | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/__tests__/fixtures/install/missing-opt-peer-dep/foo/package.json b/__tests__/fixtures/install/missing-opt-peer-dep/foo/package.json index 8c615a8b8e..5ef4d306d0 100644 --- a/__tests__/fixtures/install/missing-opt-peer-dep/foo/package.json +++ b/__tests__/fixtures/install/missing-opt-peer-dep/foo/package.json @@ -2,6 +2,11 @@ "name": "foo", "version": "1.0.0", "peerDependencies": { - "bar": "optional:*" + "bar": "*" + }, + "peerDependenciesMeta": { + "bar": { + "optional": true + } } } diff --git a/src/package-linker.js b/src/package-linker.js index 79020c3e87..7680f5cfd4 100644 --- a/src/package-linker.js +++ b/src/package-linker.js @@ -595,11 +595,15 @@ export default class PackageLinker { resolvePeerModules() { for (const pkg of this.resolver.getManifests()) { const peerDeps = pkg.peerDependencies; + const peerDepsMeta = pkg.peerDependenciesMeta; + if (!peerDeps) { continue; } + const ref = pkg._reference; invariant(ref, 'Package reference is missing'); + // TODO: We are taking the "shortest" ref tree but there may be multiple ref trees with the same length const refTree = ref.requests.map(req => req.parentNames).sort((arr1, arr2) => arr1.length - arr2.length)[0]; @@ -617,8 +621,10 @@ export default class PackageLinker { }; for (const peerDepName in peerDeps) { - const range = peerDeps[peerDepName].replace(/^optional:/, ''); - const isOptional = peerDeps[peerDepName].startsWith('optional:'); + const range = peerDeps[peerDepName]; + const meta = peerDepsMeta && peerDepsMeta[peerDepName]; + + const isOptional = meta && meta.optional ? true : false; const peerPkgs = this.resolver.getAllInfoForPackageName(peerDepName); diff --git a/src/types.js b/src/types.js index 092e9b20cd..d68bb262e7 100644 --- a/src/types.js +++ b/src/types.js @@ -13,6 +13,21 @@ export type CLIFunction = (config: Config, reporter: Reporter, flags: Object, ar type _CLIFunctionReturn = boolean; export type CLIFunctionReturn = ?_CLIFunctionReturn | Promise; +export type DependencyMeta = { +}; + +export type DependenciesMeta = { + [name: string]: DependencyMeta, +}; + +export type PeerDependencyMeta = { + optional?: boolean, +}; + +export type PeerDependenciesMeta = { + [name: string]: DependencyMeta, +}; + // dependency request pattern data structure that's used to request dependencies from a // PackageResolver export type DependencyRequestPattern = { @@ -132,6 +147,9 @@ export type Manifest = { peerDependencies?: Dependencies, optionalDependencies?: Dependencies, + dependenciesMeta?: DependenciesMeta, + peerDependenciesMeta?: PeerDependenciesMeta, + bundleDependencies?: Array, bundledDependencies?: Array,