1
1
import assert = require( "assert" ) ;
2
2
import process from "process" ;
3
3
import { emptyDir } from "fs-extra" ;
4
+ // @ts -expect-error
5
+ import pickManifest from "npm-pick-manifest" ;
4
6
import * as yargs from "yargs" ;
5
7
6
8
import { defaultLocalOptions , defaultRemoteOptions } from "./lib/common" ;
@@ -230,10 +232,7 @@ async function generateRegistry(typings: readonly TypingsData[]): Promise<Regist
230
232
return {
231
233
entries : Object . fromEntries (
232
234
await Promise . all (
233
- typings . map ( async ( typing ) => [
234
- typing . name ,
235
- filterTags ( ( await pacote . packument ( typing . fullNpmName , { cache : cacheDir } ) ) [ "dist-tags" ] ) ,
236
- ] )
235
+ typings . map ( async ( typing ) => [ typing . name , filterTags ( ( await revalidate ( typing ) ) [ "dist-tags" ] ) ] )
237
236
)
238
237
) ,
239
238
} ;
@@ -245,6 +244,27 @@ async function generateRegistry(typings: readonly TypingsData[]): Promise<Regist
245
244
}
246
245
}
247
246
247
+ /** Fetch packument from the cache or the network, depending on whether the types have changed or not. */
248
+ async function revalidate ( typing : TypingsData ) {
249
+ const offline = await pacote
250
+ . packument ( typing . fullNpmName , { cache : cacheDir , fullMetadata : true , offline : true } )
251
+ . catch ( ( reason ) => {
252
+ if ( reason . code !== "ENOTCACHED" ) throw reason ;
253
+ return undefined ;
254
+ } ) ;
255
+ try {
256
+ if (
257
+ offline &&
258
+ pickManifest ( offline , `~${ typing . major } .${ typing . minor } ` ) . typesPublisherContentHash === typing . contentHash
259
+ )
260
+ return offline ;
261
+ // @ts -expect-error
262
+ } catch ( reason : { } ) {
263
+ if ( reason . code !== "ETARGET" ) throw reason ;
264
+ }
265
+ return pacote . packument ( typing . fullNpmName , { cache : cacheDir , fullMetadata : true , preferOnline : true } ) ;
266
+ }
267
+
248
268
interface ProcessedNpmInfo {
249
269
readonly latestVersion : string ;
250
270
readonly maxVersion : string ;
0 commit comments