Skip to content

Commit dc0cfe6

Browse files
author
Kaylie Kwon
committed
flow
1 parent f68bd31 commit dc0cfe6

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/package-resolver.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type ResolverOptions = {|
2424
|};
2525

2626
export default class PackageResolver {
27-
constructor(config: Config, lockfile: Lockfile, resolutions: Resolutions) {
27+
constructor(config: Config, lockfile: Lockfile, resolutions: ?Resolutions) {
2828
this.patternsByPackage = map();
2929
this.fetchingPatterns = map();
3030
this.fetchingQueue = new BlockingQueue('resolver fetching');
@@ -540,7 +540,7 @@ export default class PackageResolver {
540540
}
541541
}
542542

543-
resolveToResolution(req: DependencyRequestPattern): ?string {
543+
resolveToResolution(req: DependencyRequestPattern): DependencyRequestPattern {
544544
const {parentNames, pattern} = req;
545545

546546
if (!parentNames) {

src/resolutions.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ export type Resolution = {
1616
};
1717

1818
export type ResolutionMap = {
19-
[string]: Array<Resolution>,
19+
[packageName: string]: Array<Resolution>,
2020
};
2121

2222
export type ResolvedPatternsMap = {
23-
[string]: string,
23+
[reqPattern: string]: string,
24+
};
25+
26+
export type ResolutionEntry = {
27+
[packageName: string]: string,
2428
};
2529

2630
export default class Resolutions {
@@ -32,13 +36,13 @@ export default class Resolutions {
3236
this.reporter = config.reporter;
3337
}
3438

35-
_resolutions: {[packageName: string]: string};
39+
_resolutions: ResolutionEntry;
3640
resolutionsByPackage: ResolutionMap;
3741
resolvedPatterns: ResolvedPatternsMap;
3842
config: Config;
3943
reporter: Reporter;
4044

41-
init(resolutions) {
45+
init(resolutions: ResolutionEntry) {
4246
this._resolutions = {...this._resolutions, ...resolutions};
4347
this.resolvedPatterns = map();
4448

@@ -73,23 +77,24 @@ export default class Resolutions {
7377
}
7478

7579
find(reqPattern: string, parentNames: Array<string>): ?string {
76-
const {name, version} = PackageRequest.normalizePattern(reqPattern);
80+
const {name, range} = PackageRequest.normalizePattern(reqPattern);
7781
const resolutions = this.resolutionsByPackage[name];
82+
let resolvedPattern = null;
7883

7984
if (!resolutions) {
80-
return null;
85+
return resolvedPattern;
8186
}
8287

83-
const resolvedPath = path.join(...parentNames, name);
84-
const resolution = resolutions.find(({pattern}) => minimatch(resolvedPath, pattern));
85-
const resolvedPattern = resolution && `${name}@${resolution.version}`;
88+
const {version} = resolutions.find(({pattern}) => minimatch(path.join(...parentNames, name), pattern)) || {};
89+
90+
if (version) {
91+
resolvedPattern = `${name}@${version}`;
8692

87-
if (resolvedPattern) {
88-
if (!semver.valid(resolvedPattern)) {
93+
if (!semver.valid(version)) {
8994
this.reporter.warn(this.reporter.lang('invalidResolutionVersion', resolvedPattern));
9095
}
9196

92-
if (!semver.satisfies(resolution.version, version)) {
97+
if (!semver.satisfies(version, range)) {
9398
this.reporter.warn(this.reporter.lang('incompatibleResolutionVersion', resolvedPattern, reqPattern));
9499
}
95100

0 commit comments

Comments
 (0)