3
3
import console from "console" ;
4
4
import process from "process" ;
5
5
import { AllPackages , getDefinitelyTyped } from "@definitelytyped/definitions-parser" ;
6
- import { NpmPublishClient } from "@definitelytyped/utils" ;
6
+ import { NpmPublishClient , cacheDir } from "@definitelytyped/utils" ;
7
7
import { 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" ;
9
10
// @ts -expect-error
10
11
import { packages } from "typescript-dom-lib-generator/deploy/createTypesPackages.js" ;
11
12
import yargs from "yargs" ;
@@ -19,29 +20,29 @@ import yargs from "yargs";
19
20
const allPackages = await AllPackages . read ( dt ) ;
20
21
const client = await NpmPublishClient . create ( process . env . NPM_TOKEN ! ) ;
21
22
// 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 ;
41
42
}
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
+ }
45
46
} ) ( ) ;
46
47
47
48
/** Reference the commit/PR that removed the named types. */
0 commit comments