@@ -16,11 +16,15 @@ export type Resolution = {
16
16
} ;
17
17
18
18
export type ResolutionMap = {
19
- [ string ] : Array < Resolution > ,
19
+ [ packageName : string ] : Array < Resolution > ,
20
20
} ;
21
21
22
22
export type ResolvedPatternsMap = {
23
- [ string ] : string ,
23
+ [ reqPattern : string ] : string ,
24
+ } ;
25
+
26
+ export type ResolutionEntry = {
27
+ [ packageName : string ] : string ,
24
28
} ;
25
29
26
30
export default class Resolutions {
@@ -32,13 +36,13 @@ export default class Resolutions {
32
36
this . reporter = config . reporter ;
33
37
}
34
38
35
- _resolutions : { [ packageName : string ] : string } ;
39
+ _resolutions : ResolutionEntry ;
36
40
resolutionsByPackage : ResolutionMap ;
37
41
resolvedPatterns : ResolvedPatternsMap ;
38
42
config : Config ;
39
43
reporter : Reporter ;
40
44
41
- init ( resolutions ) {
45
+ init ( resolutions : ResolutionEntry ) {
42
46
this . _resolutions = { ...this . _resolutions , ...resolutions } ;
43
47
this . resolvedPatterns = map ( ) ;
44
48
@@ -73,23 +77,24 @@ export default class Resolutions {
73
77
}
74
78
75
79
find ( reqPattern : string , parentNames : Array < string > ) : ?string {
76
- const { name, version } = PackageRequest . normalizePattern ( reqPattern ) ;
80
+ const { name, range } = PackageRequest . normalizePattern ( reqPattern ) ;
77
81
const resolutions = this . resolutionsByPackage [ name ] ;
82
+ let resolvedPattern = null ;
78
83
79
84
if ( ! resolutions ) {
80
- return null ;
85
+ return resolvedPattern ;
81
86
}
82
87
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 } ` ;
86
92
87
- if ( resolvedPattern ) {
88
- if ( ! semver . valid ( resolvedPattern ) ) {
93
+ if ( ! semver . valid ( version ) ) {
89
94
this . reporter . warn ( this . reporter . lang ( 'invalidResolutionVersion' , resolvedPattern ) ) ;
90
95
}
91
96
92
- if ( ! semver . satisfies ( resolution . version , version ) ) {
97
+ if ( ! semver . satisfies ( version , range ) ) {
93
98
this . reporter . warn ( this . reporter . lang ( 'incompatibleResolutionVersion' , resolvedPattern , reqPattern ) ) ;
94
99
}
95
100
0 commit comments