33import console from "console" ;
44import process from "process" ;
55import { AllPackages , getDefinitelyTyped } from "@definitelytyped/definitions-parser" ;
6- import { NpmPublishClient } from "@definitelytyped/utils" ;
6+ import { NpmPublishClient , cacheDir } from "@definitelytyped/utils" ;
77import { graphql } from "@octokit/graphql" ;
8- import search from "libnpmsearch" ;
8+ import names from "all-the-package-names" assert { type : "json " } ;
9+ import pacote from "pacote" ;
910// @ts -expect-error
1011import { packages } from "typescript-dom-lib-generator/deploy/createTypesPackages.js" ;
1112import yargs from "yargs" ;
@@ -19,29 +20,29 @@ import yargs from "yargs";
1920 const allPackages = await AllPackages . read ( dt ) ;
2021 const client = await NpmPublishClient . create ( process . env . NPM_TOKEN ! ) ;
2122 // Loop over npm @types packages and mark as deprecated any that no longer exist in the DT repo.
22- let from = 0 ;
23- let results ;
24- do {
25- const opts = { limit : 250 , from } ;
26- // Won't return already-deprecated packages .
27- results = await search ( "@ types" , opts ) ;
28- for ( const result of results ) {
29- // Skip @types /web, etc .
30- if ( domLibs . has ( result . name ) ) continue ;
31- const types = result . name . slice ( "@types/" . length ) ;
32- // Skip ones that exist, either in the types/ directory or in notNeededPackages.json.
33- if ( allPackages . tryGetLatestVersion ( types ) || allPackages . getNotNeededPackage ( types ) ) continue ;
34- const msg = await fetchMsg ( types ) ;
35- if ( ! msg ) {
36- console . log ( `Could not find the commit that removed types/ ${ types } /.` ) ;
37- continue ;
38- }
39- console . log ( `Deprecating ${ result . name } : ${ msg } ` ) ;
40- if ( ! dryRun ) await client . deprecate ( result . name , "*" , msg ) ;
23+ for ( const name of names ) {
24+ // Skip @types /web, etc.
25+ if ( ! name . startsWith ( "@types/" ) || domLibs . has ( name ) ) continue ;
26+ const types = name . slice ( "@types/" . length ) ;
27+ // Skip ones that exist, either in the types/ directory or in notNeededPackages.json .
28+ if ( allPackages . tryGetLatestVersion ( types ) || allPackages . getNotNeededPackage ( types ) ) continue ;
29+ // Skip already-deprecated packages.
30+ // Cache package deprecation indefinitely .
31+ const offline = await pacote . manifest ( name , { cache : cacheDir , offline : true } ) . catch ( ( reason ) => {
32+ if ( reason . code !== "ENOTCACHED" ) throw reason ;
33+ return undefined ;
34+ } ) ;
35+ if ( offline ?. deprecated ) continue ;
36+ const online = await pacote . manifest ( name , { cache : cacheDir , preferOnline : true } ) ;
37+ if ( online . deprecated ) continue ;
38+ const msg = await fetchMsg ( types ) ;
39+ if ( ! msg ) {
40+ console . log ( `Could not find the commit that removed types/ ${ types } /. ` ) ;
41+ continue ;
4142 }
42- from += results . length ;
43- // The registry API clamps limit at 250 and from at 5,000, so we can only loop over 5,250 packages, for now.
44- } while ( results . length >= 250 && from <= 5000 ) ;
43+ console . log ( `Deprecating ${ name } : ${ msg } ` ) ;
44+ if ( ! dryRun ) await client . deprecate ( name , "*" , msg ) ;
45+ }
4546} ) ( ) ;
4647
4748/** Reference the commit/PR that removed the named types. */
0 commit comments