Skip to content

Commit dc9524e

Browse files
committed
Port from libnpmsearch -> all-the-package-names
1 parent 7b22394 commit dc9524e

File tree

4 files changed

+41
-43
lines changed

4 files changed

+41
-43
lines changed

packages/deprecate/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
"@definitelytyped/definitions-parser": "^0.0.121",
1212
"@definitelytyped/utils": "^0.0.121",
1313
"@octokit/graphql": "^4.8.0",
14-
"libnpmsearch": "^5.0.3",
14+
"all-the-package-names": "^2.0.176",
15+
"pacote": "^13.6.1",
1516
"typescript-dom-lib-generator": "https://github.com/microsoft/TypeScript-DOM-lib-generator.git",
1617
"yargs": "^17.5.1"
1718
},
1819
"devDependencies": {
19-
"@types/libnpmsearch": "^2.0.3",
20+
"@types/all-the-package-names": "^1.3744.0",
21+
"@types/pacote": "^11.1.5",
2022
"@types/yargs": "^17.0.10"
2123
},
2224
"private": true,

packages/deprecate/src/index.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import console from "console";
44
import process from "process";
55
import { AllPackages, getDefinitelyTyped } from "@definitelytyped/definitions-parser";
6-
import { NpmPublishClient } from "@definitelytyped/utils";
6+
import { NpmPublishClient, cacheDir } from "@definitelytyped/utils";
77
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";
910
// @ts-expect-error
1011
import { packages } from "typescript-dom-lib-generator/deploy/createTypesPackages.js";
1112
import 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. */

packages/deprecate/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
4-
"module": "es6",
4+
"module": "esnext",
55
"moduleResolution": "node",
66
"rootDir": "src/",
77
"outDir": "dist/"

yarn.lock

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,11 @@
17621762
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf"
17631763
integrity sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==
17641764

1765+
"@types/all-the-package-names@^1.3744.0":
1766+
version "1.3744.0"
1767+
resolved "https://registry.yarnpkg.com/@types/all-the-package-names/-/all-the-package-names-1.3744.0.tgz#bf137bd79262dd24ed93ea80996f6a7bef74845e"
1768+
integrity sha512-pHfzXywUNwg0aKYXZqkl1H0dNOjJG8j5e1PqBrhQgF3vj+jcxZVKsaW+LFkc29R2PcIkIas8D6ocFIJqy0NFXg==
1769+
17651770
"@types/babel__core@^7.1.7":
17661771
version "7.1.7"
17671772
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.7.tgz#1dacad8840364a57c98d0dd4855c6dd3752c6b89"
@@ -1909,14 +1914,6 @@
19091914
resolved "https://registry.yarnpkg.com/@types/json-stable-stringify/-/json-stable-stringify-1.0.33.tgz#099b0712d824d15e2660c20e1c16e6a8381f308c"
19101915
integrity sha512-qEWiQff6q2tA5gcJGWwzplQcXdJtm+0oy6IHGHzlOf3eFAkGE/FIPXZK9ofWgNSHVp8AFFI33PJJshS0ei3Gvw==
19111916

1912-
"@types/libnpmsearch@^2.0.3":
1913-
version "2.0.3"
1914-
resolved "https://registry.yarnpkg.com/@types/libnpmsearch/-/libnpmsearch-2.0.3.tgz#6a7bba71e533d5344cd04ceac4fe81b6b1ab9ceb"
1915-
integrity sha512-f/tTUDiOaUNk+m1mfvXO4/7ZasYUaKdosLgvzMdrFHNFqJENqwT9kKE+Gd6N3nsoD5kCZ7q4Pw7ApPIjXQArbA==
1916-
dependencies:
1917-
"@types/node" "*"
1918-
"@types/npm-registry-fetch" "*"
1919-
19201917
"@types/minimatch@*", "@types/minimatch@^3.0.3":
19211918
version "3.0.5"
19221919
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
@@ -2402,6 +2399,11 @@ ajv@^8.0.1:
24022399
require-from-string "^2.0.2"
24032400
uri-js "^4.2.2"
24042401

2402+
all-the-package-names@^2.0.176:
2403+
version "2.0.176"
2404+
resolved "https://registry.yarnpkg.com/all-the-package-names/-/all-the-package-names-2.0.176.tgz#337bd76541e85985e09494d83b4734c8f02499a6"
2405+
integrity sha512-iDXRXto0tg4IiPHgZybugcpyusEZ8gor5ldS69OWCGIRDgEU7K+85G8iTG6IRCt+xbSj1Fz3zbwCvEJWJX7Akg==
2406+
24052407
ansi-colors@^4.1.1:
24062408
version "4.1.1"
24072409
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"
@@ -6109,13 +6111,6 @@ libnpmpublish@^4.0.0:
61096111
semver "^7.1.3"
61106112
ssri "^8.0.1"
61116113

6112-
libnpmsearch@^5.0.3:
6113-
version "5.0.3"
6114-
resolved "https://registry.yarnpkg.com/libnpmsearch/-/libnpmsearch-5.0.3.tgz#ed502a4c2c70ea36723180455fae1357546b2184"
6115-
integrity sha512-Ofq76qKAPhxbiyzPf/5LPjJln26VTKwU9hIU0ACxQ6tNtBJ1CHmI7iITrdp7vNezhZc0FlkXwrIpqXjhBJZgLQ==
6116-
dependencies:
6117-
npm-registry-fetch "^13.0.0"
6118-
61196114
lines-and-columns@^1.1.6:
61206115
version "1.1.6"
61216116
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00"
@@ -7008,7 +7003,7 @@ npm-registry-fetch@^11.0.0:
70087003
minizlib "^2.0.0"
70097004
npm-package-arg "^8.0.0"
70107005

7011-
npm-registry-fetch@^13.0.0, npm-registry-fetch@^13.0.1:
7006+
npm-registry-fetch@^13.0.1:
70127007
version "13.1.1"
70137008
resolved "https://registry.yarnpkg.com/npm-registry-fetch/-/npm-registry-fetch-13.1.1.tgz#26dc4b26d0a545886e807748032ba2aefaaae96b"
70147009
integrity sha512-5p8rwe6wQPLJ8dMqeTnA57Dp9Ox6GH9H60xkyJup07FmVlu3Mk7pf/kIIpl9gaN5bM8NM+UUx3emUWvDNTt39w==

0 commit comments

Comments
 (0)