Skip to content

Commit

Permalink
Port from libnpmsearch -> all-the-package-names
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Jul 9, 2022
1 parent 3feccd1 commit e88c032
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
6 changes: 4 additions & 2 deletions packages/deprecate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
"@definitelytyped/definitions-parser": "^0.0.121",
"@definitelytyped/utils": "^0.0.121",
"@octokit/graphql": "^4.8.0",
"libnpmsearch": "^5.0.3",
"all-the-package-names": "^2.0.176",
"pacote": "^13.6.1",
"typescript-dom-lib-generator": "https://github.com/microsoft/TypeScript-DOM-lib-generator.git",
"yargs": "^17.5.1"
},
"devDependencies": {
"@types/libnpmsearch": "^2.0.3",
"@types/all-the-package-names": "^1.3744.0",
"@types/pacote": "^11.1.5",
"@types/yargs": "^17.0.10"
},
"private": true,
Expand Down
49 changes: 25 additions & 24 deletions packages/deprecate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import console from "console";
import process from "process";
import { AllPackages, getDefinitelyTyped } from "@definitelytyped/definitions-parser";
import { NpmPublishClient } from "@definitelytyped/utils";
import { NpmPublishClient, cacheDir } from "@definitelytyped/utils";
import { graphql } from "@octokit/graphql";
import search from "libnpmsearch";
import names from "all-the-package-names" assert { type: "json" };
import pacote from "pacote";
// @ts-expect-error
import { packages } from "typescript-dom-lib-generator/deploy/createTypesPackages.js";
import yargs from "yargs";
Expand All @@ -19,29 +20,29 @@ import yargs from "yargs";
const allPackages = await AllPackages.read(dt);
const client = await NpmPublishClient.create(process.env.NPM_TOKEN!);
// Loop over npm @types packages and mark as deprecated any that no longer exist in the DT repo.
let from = 0;
let results;
do {
const opts = { limit: 250, from };
// Won't return already-deprecated packages.
results = await search("@types", opts);
for (const result of results) {
// Skip @types/web, etc.
if (domLibs.has(result.name)) continue;
const types = result.name.slice("@types/".length);
// Skip ones that exist, either in the types/ directory or in notNeededPackages.json.
if (allPackages.tryGetLatestVersion(types) || allPackages.getNotNeededPackage(types)) continue;
const msg = await fetchMsg(types);
if (!msg) {
console.log(`Could not find the commit that removed types/${types}/.`);
continue;
}
console.log(`Deprecating ${result.name}: ${msg}`);
if (!dryRun) await client.deprecate(result.name, "*", msg);
for (const name of names) {
// Skip @types/web, etc.
if (!name.startsWith("@types/") || domLibs.has(name)) continue;
const types = name.slice("@types/".length);
// Skip ones that exist, either in the types/ directory or in notNeededPackages.json.
if (allPackages.tryGetLatestVersion(types) || allPackages.getNotNeededPackage(types)) continue;
// Skip already-deprecated packages.
// Cache package deprecation indefinitely.
const offline = await pacote.manifest(name, { cache: cacheDir, offline: true }).catch((reason) => {
if (reason.code !== "ENOTCACHED") throw reason;
return undefined;
});
if (offline?.deprecated) continue;
const online = await pacote.manifest(name, { cache: cacheDir, preferOnline: true });
if (online.deprecated) continue;
const msg = await fetchMsg(types);
if (!msg) {
console.log(`Could not find the commit that removed types/${types}/.`);
continue;
}
from += results.length;
// The registry API clamps limit at 250 and from at 5,000, so we can only loop over 5,250 packages, for now.
} while (results.length >= 250 && from <= 5000);
console.log(`Deprecating ${name}: ${msg}`);
if (!dryRun) await client.deprecate(name, "*", msg);
}
})();

/** Reference the commit/PR that removed the named types. */
Expand Down
2 changes: 1 addition & 1 deletion packages/deprecate/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "es6",
"module": "esnext",
"moduleResolution": "node",
"rootDir": "src/",
"outDir": "dist/"
Expand Down
27 changes: 11 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,11 @@
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf"
integrity sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==

"@types/all-the-package-names@^1.3744.0":
version "1.3744.0"
resolved "https://registry.yarnpkg.com/@types/all-the-package-names/-/all-the-package-names-1.3744.0.tgz#bf137bd79262dd24ed93ea80996f6a7bef74845e"
integrity sha512-pHfzXywUNwg0aKYXZqkl1H0dNOjJG8j5e1PqBrhQgF3vj+jcxZVKsaW+LFkc29R2PcIkIas8D6ocFIJqy0NFXg==

"@types/babel__core@^7.1.7":
version "7.1.7"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.7.tgz#1dacad8840364a57c98d0dd4855c6dd3752c6b89"
Expand Down Expand Up @@ -1909,14 +1914,6 @@
resolved "https://registry.yarnpkg.com/@types/json-stable-stringify/-/json-stable-stringify-1.0.33.tgz#099b0712d824d15e2660c20e1c16e6a8381f308c"
integrity sha512-qEWiQff6q2tA5gcJGWwzplQcXdJtm+0oy6IHGHzlOf3eFAkGE/FIPXZK9ofWgNSHVp8AFFI33PJJshS0ei3Gvw==

"@types/libnpmsearch@^2.0.3":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/libnpmsearch/-/libnpmsearch-2.0.3.tgz#6a7bba71e533d5344cd04ceac4fe81b6b1ab9ceb"
integrity sha512-f/tTUDiOaUNk+m1mfvXO4/7ZasYUaKdosLgvzMdrFHNFqJENqwT9kKE+Gd6N3nsoD5kCZ7q4Pw7ApPIjXQArbA==
dependencies:
"@types/node" "*"
"@types/npm-registry-fetch" "*"

"@types/minimatch@*", "@types/minimatch@^3.0.3":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
Expand Down Expand Up @@ -2402,6 +2399,11 @@ ajv@^8.0.1:
require-from-string "^2.0.2"
uri-js "^4.2.2"

all-the-package-names@^2.0.176:
version "2.0.176"
resolved "https://registry.yarnpkg.com/all-the-package-names/-/all-the-package-names-2.0.176.tgz#337bd76541e85985e09494d83b4734c8f02499a6"
integrity sha512-iDXRXto0tg4IiPHgZybugcpyusEZ8gor5ldS69OWCGIRDgEU7K+85G8iTG6IRCt+xbSj1Fz3zbwCvEJWJX7Akg==

ansi-colors@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"
Expand Down Expand Up @@ -6109,13 +6111,6 @@ libnpmpublish@^4.0.0:
semver "^7.1.3"
ssri "^8.0.1"

libnpmsearch@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/libnpmsearch/-/libnpmsearch-5.0.3.tgz#ed502a4c2c70ea36723180455fae1357546b2184"
integrity sha512-Ofq76qKAPhxbiyzPf/5LPjJln26VTKwU9hIU0ACxQ6tNtBJ1CHmI7iITrdp7vNezhZc0FlkXwrIpqXjhBJZgLQ==
dependencies:
npm-registry-fetch "^13.0.0"

lines-and-columns@^1.1.6:
version "1.1.6"
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00"
Expand Down Expand Up @@ -7008,7 +7003,7 @@ npm-registry-fetch@^11.0.0:
minizlib "^2.0.0"
npm-package-arg "^8.0.0"

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

0 comments on commit e88c032

Please sign in to comment.