@@ -24,13 +24,12 @@ import {
24
24
writeJson ,
25
25
writeFile ,
26
26
Logger ,
27
+ NpmInfoRaw ,
27
28
sleep ,
28
29
npmInstallFlags ,
29
30
readJson ,
30
31
UncachedNpmInfoClient ,
31
- withNpmCache ,
32
32
NpmPublishClient ,
33
- CachedNpmInfoClient ,
34
33
isObject ,
35
34
max ,
36
35
} from "@definitelytyped/utils" ;
@@ -69,11 +68,8 @@ export default async function publishRegistry(
69
68
assert . strictEqual ( npmVersion . minor , 1 ) ;
70
69
71
70
// Don't include not-needed packages in the registry.
72
- const registryJsonData = await withNpmCache (
73
- undefined ,
74
- ( offline ) => generateRegistry ( allPackages . allLatestTypings ( ) , offline ) ,
75
- cacheDirPath
76
- ) ;
71
+ const offline : Record < string , NpmInfoRaw > = await import ( `${ cacheDirPath } /npmInfo.json` ) ;
72
+ const registryJsonData = await generateRegistry ( allPackages . allLatestTypings ( ) , offline ) ;
77
73
const registry = JSON . stringify ( registryJsonData ) ;
78
74
const newContentHash = computeHash ( registry ) ;
79
75
const newVersion = semver . inc ( npmVersion , "patch" ) ! ;
@@ -251,30 +247,24 @@ interface Registry {
251
247
}
252
248
async function generateRegistry (
253
249
typings : readonly TypingsData [ ] ,
254
- offline : Omit < CachedNpmInfoClient , "fetchAndCacheNpmInfo" >
250
+ offline : Record < string , NpmInfoRaw >
255
251
) : Promise < Registry > {
256
252
const entries : { [ packageName : string ] : { [ distTags : string ] : string } } = { } ;
257
253
for ( const typing of typings ) {
258
254
// Unconditionally use cached info, this should have been set in calculate-versions so should be recent enough.
259
- const info = offline . getNpmInfoFromCache ( typing . fullNpmName ) ;
255
+ const info = offline [ typing . fullNpmName ] ;
260
256
if ( ! info ) {
261
- const missings = typings . filter ( ( t ) => ! offline . getNpmInfoFromCache ( t . fullNpmName ) ) . map ( ( t ) => t . fullNpmName ) ;
257
+ const missings = typings . filter ( ( t ) => ! ( t . fullNpmName in offline ) ) . map ( ( t ) => t . fullNpmName ) ;
262
258
throw new Error ( `${ missings . toString ( ) } not found in cached npm info.` ) ;
263
259
}
264
- entries [ typing . name ] = filterTags ( info . distTags ) ;
260
+ entries [ typing . name ] = filterTags ( info [ "dist-tags" ] ) ;
265
261
}
266
262
return { entries } ;
267
263
268
- function filterTags ( tags : Map < string , string > ) : { readonly [ tag : string ] : string } {
269
- const latestTag = "latest" ;
270
- const latestVersion = tags . get ( latestTag ) ;
271
- const out : { [ tag : string ] : string } = { } ;
272
- tags . forEach ( ( value , tag ) => {
273
- if ( tag === latestTag || value !== latestVersion ) {
274
- out [ tag ] = value ;
275
- }
276
- } ) ;
277
- return out ;
264
+ function filterTags ( tags : NpmInfoRaw [ "dist-tags" ] ) : { readonly [ tag : string ] : string } {
265
+ return Object . fromEntries (
266
+ Object . entries ( tags ) . filter ( ( [ tag , version ] ) => tag === "latest" || version !== tags . latest )
267
+ ) ;
278
268
}
279
269
}
280
270
0 commit comments