Skip to content

Commit

Permalink
Implements the new peerDependenciesMeta field
Browse files Browse the repository at this point in the history
  • Loading branch information
Maël Nison committed Nov 20, 2018
1 parent bf63d74 commit 7d61b4f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Expand Up @@ -2,6 +2,11 @@
"name": "foo",
"version": "1.0.0",
"peerDependencies": {
"bar": "optional:*"
"bar": "*"
},
"peerDependenciesMeta": {
"bar": {
"optional": true
}
}
}
10 changes: 8 additions & 2 deletions src/package-linker.js
Expand Up @@ -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];

Expand All @@ -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);

Expand Down
18 changes: 18 additions & 0 deletions src/types.js
Expand Up @@ -13,6 +13,21 @@ export type CLIFunction = (config: Config, reporter: Reporter, flags: Object, ar
type _CLIFunctionReturn = boolean;
export type CLIFunctionReturn = ?_CLIFunctionReturn | Promise<?_CLIFunctionReturn>;

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 = {
Expand Down Expand Up @@ -132,6 +147,9 @@ export type Manifest = {
peerDependencies?: Dependencies,
optionalDependencies?: Dependencies,

dependenciesMeta?: DependenciesMeta,
peerDependenciesMeta?: PeerDependenciesMeta,

bundleDependencies?: Array<string>,
bundledDependencies?: Array<string>,

Expand Down

0 comments on commit 7d61b4f

Please sign in to comment.