@@ -354,7 +354,7 @@ async function getPackageInfosEtc(
354
354
return { pkgInfo : result , popularityLevel : downloadsToPopularityLevel ( maxDownloads ) } ;
355
355
}
356
356
357
- async function categorizeFile ( path : string , contents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
357
+ async function categorizeFile ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
358
358
// https://regex101.com/r/eFvtrz/1
359
359
const match = / ^ t y p e s \/ ( .* ?) \/ .* ?[ ^ \/ ] (?: \. ( d \. t s | t s x ? | m d ) ) ? $ / . exec ( path ) ;
360
360
if ( ! match ) return [ null , { path, kind : "infrastructure" } ] ;
@@ -364,26 +364,26 @@ async function categorizeFile(path: string, contents: (ref: string) => Promise<s
364
364
case "ts" : case "tsx" : return [ pkg , { path, kind : "test" } ] ;
365
365
case "md" : return [ pkg , { path, kind : "markdown" } ] ;
366
366
default :
367
- const suspect = await configSuspicious ( path , contents ) ;
367
+ const suspect = await configSuspicious ( path , getContents ) ;
368
368
return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , ...suspect } ] ;
369
369
}
370
370
}
371
371
372
372
interface ConfigSuspicious {
373
373
( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
374
- [ basename : string ] : ( text : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
374
+ [ basename : string ] : ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
375
375
} ;
376
376
const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
377
377
const basename = path . replace ( / .* \/ / , "" ) ;
378
- if ( ! ( basename in configSuspicious ) ) return { suspect : `edited` } ;
379
- const text = await getContents ( "head" ) ;
380
- if ( text === undefined ) return { suspect : `couldn't fetch contents` } ;
381
378
const tester = configSuspicious [ basename ] ;
382
- return tester ( text , getContents ) ;
379
+ if ( ! tester ) return { suspect : `edited` } ;
380
+ const newText = await getContents ( "head" ) ;
381
+ if ( newText === undefined ) return { suspect : `couldn't fetch contents` } ;
382
+ return tester ( newText , getContents ) ;
383
383
} ) ;
384
- configSuspicious [ "OTHER_FILES.txt" ] = async contents =>
384
+ configSuspicious [ "OTHER_FILES.txt" ] = async newText =>
385
385
// not empty
386
- ( contents . length === 0 ) ? { suspect : "empty" }
386
+ ( newText . length === 0 ) ? { suspect : "empty" }
387
387
: undefined ;
388
388
configSuspicious [ "package.json" ] = makeJsonCheckerFromCore (
389
389
{ private : true } ,
@@ -414,9 +414,9 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
414
414
// to it, ignoring some keys (JSON Patch paths). The ignored properties are in most cases checked
415
415
// elsewhere (dtslint), and in some cases they are irrelevant.
416
416
function makeJsonCheckerFromCore ( requiredForm : any , ignoredKeys : string [ ] ) {
417
- return async ( contents : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
417
+ return async ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
418
418
let suggestion : any ;
419
- try { suggestion = JSON . parse ( contents ) ; } catch ( e ) { return { suspect : "couldn't parse json" } ; }
419
+ try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { return { suspect : "couldn't parse json" } ; }
420
420
const newJson = jsonDiff . deepClone ( suggestion ) ;
421
421
jsonDiff . applyPatch ( newJson , ignoredKeys . map ( path => ( { op : "remove" , path } ) ) ) ;
422
422
const towardsIt = jsonDiff . deepClone ( requiredForm ) ;
@@ -459,7 +459,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[]) {
459
459
? prettier . format ( JSON . stringify ( suggestion ) , { tabWidth : 4 , filepath : ".json" } )
460
460
: JSON . stringify ( suggestion , undefined , 4 ) + "\n"
461
461
) . split ( / ^ / m) ;
462
- const lines = contents . split ( / ^ / m) ;
462
+ const lines = newText . split ( / ^ / m) ;
463
463
// When suggestionLines is empty, that suggests removing all
464
464
// of the different lines
465
465
let startLine = 1 ;
0 commit comments