@@ -373,7 +373,7 @@ async function getPackageInfosEtc(
373373 return { pkgInfo : result , popularityLevel : downloadsToPopularityLevel ( maxDownloads ) } ;
374374}
375375
376- async function categorizeFile ( path : string , contents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
376+ async function categorizeFile ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
377377 // https://regex101.com/r/eFvtrz/1
378378 const match = / ^ t y p e s \/ ( .* ?) \/ .* ?[ ^ \/ ] (?: \. ( d \. t s | t s x ? | m d ) ) ? $ / . exec ( path ) ;
379379 if ( ! match ) return [ null , { path, kind : "infrastructure" } ] ;
@@ -383,26 +383,26 @@ async function categorizeFile(path: string, contents: (ref: string) => Promise<s
383383 case "ts" : case "tsx" : return [ pkg , { path, kind : "test" } ] ;
384384 case "md" : return [ pkg , { path, kind : "markdown" } ] ;
385385 default :
386- const suspect = await configSuspicious ( path , contents ) ;
386+ const suspect = await configSuspicious ( path , getContents ) ;
387387 return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , ...suspect } ] ;
388388 }
389389}
390390
391391interface ConfigSuspicious {
392392 ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
393- [ basename : string ] : ( text : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
393+ [ basename : string ] : ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
394394}
395395const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
396396 const basename = path . replace ( / .* \/ / , "" ) ;
397- if ( ! ( basename in configSuspicious ) ) return { suspect : `edited` } ;
398- const text = await getContents ( "head" ) ;
399- if ( text === undefined ) return { suspect : `couldn't fetch contents` } ;
400397 const tester = configSuspicious [ basename ] ;
401- return tester ( text , getContents ) ;
398+ if ( ! tester ) return { suspect : `edited` } ;
399+ const newText = await getContents ( "head" ) ;
400+ if ( newText === undefined ) return { suspect : `couldn't fetch contents` } ;
401+ return tester ( newText , getContents ) ;
402402} ) ;
403- configSuspicious [ "OTHER_FILES.txt" ] = async contents =>
403+ configSuspicious [ "OTHER_FILES.txt" ] = async newText =>
404404 // not empty
405- ( contents . length === 0 ) ? { suspect : "empty" }
405+ ( newText . length === 0 ) ? { suspect : "empty" }
406406 : undefined ;
407407configSuspicious [ "package.json" ] = makeJsonCheckerFromCore (
408408 { private : true } ,
@@ -434,9 +434,9 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
434434// to it, ignoring some keys (JSON Patch paths). The ignored properties are in most cases checked
435435// elsewhere (dtslint), and in some cases they are irrelevant.
436436function makeJsonCheckerFromCore ( requiredForm : any , ignoredKeys : string [ ] , requiredFormUrl ?: string ) {
437- return async ( contents : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
437+ return async ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
438438 let suggestion : any ;
439- try { suggestion = JSON . parse ( contents ) ; } catch ( e ) { return { suspect : "couldn't parse json" } ; }
439+ try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { return { suspect : "couldn't parse json" } ; }
440440 const newJson = jsonDiff . deepClone ( suggestion ) ;
441441 jsonDiff . applyPatch ( newJson , ignoredKeys . map ( path => ( { op : "remove" , path } ) ) ) ;
442442 const towardsIt = jsonDiff . deepClone ( requiredForm ) ;
@@ -482,7 +482,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[], requi
482482 ? prettier . format ( JSON . stringify ( suggestion ) , { tabWidth : 4 , filepath : ".json" } )
483483 : JSON . stringify ( suggestion , undefined , 4 ) + "\n"
484484 ) . split ( / ^ / m) ;
485- const lines = contents . split ( / ^ / m) ;
485+ const lines = newText . split ( / ^ / m) ;
486486 // When suggestionLines is empty, that suggests removing all
487487 // of the different lines
488488 let startLine = 1 ;
0 commit comments