@@ -15,6 +15,8 @@ const VERSIONS = Object.assign({}, process.versions, {
1515 yarn : yarnVersion ,
1616} ) ;
1717
18+ type PartialManifest = $Shape < Manifest > ;
19+
1820function isValid ( items : Array < string > , actual : string ) : boolean {
1921 let isNotWhitelist = true ;
2022 let isBlacklist = false ;
@@ -127,19 +129,19 @@ export function checkOne(info: Manifest, config: Config, ignoreEngines: boolean)
127129 } ;
128130
129131 const invalidPlatform =
130- ! config . ignorePlatform && Array . isArray ( info . os ) && info . os . length > 0 && ! isValidPlatform ( info . os ) ;
132+ shouldCheckPlatform ( info , config . ignorePlatform ) && info . os != null && ! isValidPlatform ( info . os ) ;
131133
132134 if ( invalidPlatform ) {
133135 pushError ( reporter . lang ( 'incompatibleOS' , process . platform ) ) ;
134136 }
135137
136- const invalidCpu = ! config . ignorePlatform && Array . isArray ( info . cpu ) && info . cpu . length > 0 && ! isValidArch ( info . cpu ) ;
138+ const invalidCpu = shouldCheckCpu ( info , config . ignorePlatform ) && info . cpu != null && ! isValidArch ( info . cpu ) ;
137139
138140 if ( invalidCpu ) {
139141 pushError ( reporter . lang ( 'incompatibleCPU' , process . arch ) ) ;
140142 }
141143
142- if ( ! ignoreEngines && typeof info . engines === 'object' ) {
144+ if ( shouldCheckEngines ( info , ignoreEngines ) ) {
143145 for ( const entry of entries ( info . engines ) ) {
144146 let name = entry [ 0 ] ;
145147 const range = entry [ 1 ] ;
@@ -168,3 +170,26 @@ export function check(infos: Array<Manifest>, config: Config, ignoreEngines: boo
168170 checkOne ( info , config , ignoreEngines ) ;
169171 }
170172}
173+
174+ function shouldCheckCpu ( manifest : PartialManifest , ignorePlatform : boolean ) : boolean {
175+ return ! ignorePlatform && Array . isArray ( manifest . cpu ) && manifest . cpu . length > 0 ;
176+ }
177+
178+ function shouldCheckPlatform ( manifest : PartialManifest , ignorePlatform : boolean ) : boolean {
179+ return ! ignorePlatform && Array . isArray ( manifest . os ) && manifest . os . length > 0 ;
180+ }
181+
182+ function shouldCheckEngines ( manifest : PartialManifest , ignoreEngines : boolean ) : boolean {
183+ return ! ignoreEngines && typeof manifest . engines === 'object' ;
184+ }
185+
186+ export function shouldCheck (
187+ manifest : PartialManifest ,
188+ options : { ignoreEngines : boolean , ignorePlatform : boolean } ,
189+ ) : boolean {
190+ return (
191+ shouldCheckCpu ( manifest , options . ignorePlatform ) ||
192+ shouldCheckPlatform ( manifest , options . ignorePlatform ) ||
193+ shouldCheckEngines ( manifest , options . ignoreEngines )
194+ ) ;
195+ }
0 commit comments