11import assert = require( "assert" ) ;
22import process from "process" ;
33import { emptyDir } from "fs-extra" ;
4+ // @ts -expect-error
5+ import pickManifest from "npm-pick-manifest" ;
46import * as yargs from "yargs" ;
57
68import { defaultLocalOptions , defaultRemoteOptions } from "./lib/common" ;
@@ -230,10 +232,7 @@ async function generateRegistry(typings: readonly TypingsData[]): Promise<Regist
230232 return {
231233 entries : Object . fromEntries (
232234 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" ] ) ] )
237236 )
238237 ) ,
239238 } ;
@@ -245,6 +244,20 @@ async function generateRegistry(typings: readonly TypingsData[]): Promise<Regist
245244 }
246245}
247246
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" && reason . code !== "ETARGET" ) throw reason ;
253+ return undefined ;
254+ } ) ;
255+ return offline &&
256+ pickManifest ( offline , `~${ typing . major } .${ typing . minor } ` ) . typesPublisherContentHash === typing . contentHash
257+ ? offline
258+ : pacote . packument ( typing . fullNpmName , { cache : cacheDir , fullMetadata : true , preferOnline : true } ) ;
259+ }
260+
248261interface ProcessedNpmInfo {
249262 readonly latestVersion : string ;
250263 readonly maxVersion : string ;
0 commit comments