Skip to content

Commit 2b1c289

Browse files
committed
Mark removed types as deprecated
1 parent a919c12 commit 2b1c289

File tree

9 files changed

+479
-9
lines changed

9 files changed

+479
-9
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ jobs:
5151
uses: ./.github/workflows/retag.yml
5252
with:
5353
dry: true
54+
deprecate-dry:
55+
needs: build_and_test
56+
uses: ./.github/workflows/deprecate.yml
57+
with:
58+
dry: true
5459
publish_alpha:
5560
name: publish alpha release
5661
runs-on: ubuntu-latest

.github/workflows/deprecate.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Mark removed types as deprecated
2+
on:
3+
workflow_call:
4+
inputs:
5+
dry:
6+
description: Dry run
7+
type: boolean
8+
workflow_dispatch:
9+
inputs:
10+
dry:
11+
description: Dry run
12+
type: boolean
13+
jobs:
14+
deprecate:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-node@v3
19+
with:
20+
cache: yarn
21+
- run: yarn install --frozen-lockfile
22+
- run: yarn build
23+
- name: Parse declarations
24+
run: yarn workspace @definitelytyped/publisher parse
25+
- name: Mark removed types as deprecated${{ (inputs || github.event.inputs).dry && ' dry run' }}
26+
run: node --require source-map-support/register packages/deprecate/${{ (inputs || github.event.inputs).dry && ' --dry' }}
27+
env:
28+
GH_API_TOKEN: ${{ secrets.GH_API_TOKEN }}
29+
NPM_TOKEN: ${{ secrets.NPM_RETAG_TOKEN }}
30+
- if: always()
31+
uses: actions/upload-artifact@v3
32+
with:
33+
name: ${{ github.job }}
34+
path: packages/definitions-parser/data/

.github/workflows/retag.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: Update npm tags
22
on:
3-
schedule:
4-
# https://crontab.guru/#0_0_*_*_0
5-
- cron: 0 0 * * 0
63
workflow_call:
74
inputs:
85
dry:

.github/workflows/weekly.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Weekly
2+
on:
3+
schedule:
4+
# https://crontab.guru/#0_0_*_*_0
5+
- cron: 0 0 * * 0
6+
workflow_dispatch:
7+
inputs:
8+
dry:
9+
description: Dry run
10+
type: boolean
11+
jobs:
12+
retag:
13+
uses: ./.github/workflows/retag.yml
14+
with:
15+
dry: ${{ github.event.inputs.dry == 'true' }}
16+
deprecate:
17+
uses: ./.github/workflows/deprecate.yml
18+
with:
19+
dry: ${{ github.event.inputs.dry == 'true' }}

packages/deprecate/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@definitelytyped/deprecate",
3+
"version": "1.0.0",
4+
"description": "Loop over npm @types packages and mark as deprecated any that no longer exist in the DT repo.",
5+
"license": "MIT",
6+
"main": "dist/index.js",
7+
"scripts": {
8+
"build": "tsc --build"
9+
},
10+
"dependencies": {
11+
"@definitelytyped/definitions-parser": "0.0.113-next.7",
12+
"@definitelytyped/utils": "0.0.113-next.7",
13+
"@octokit/graphql": "^4.8.0",
14+
"libnpmsearch": "^5.0.3",
15+
"yargs": "^17.4.1"
16+
},
17+
"devDependencies": {
18+
"@types/libnpmsearch": "^2.0.3"
19+
}
20+
}

packages/deprecate/src/index.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env node
2+
3+
import process from "process";
4+
import { AllPackages, getDefinitelyTyped } from "@definitelytyped/definitions-parser";
5+
import { loggerWithErrors, NpmPublishClient } from "@definitelytyped/utils";
6+
import { graphql } from "@octokit/graphql";
7+
import search from "libnpmsearch";
8+
import yargs from "yargs";
9+
10+
main();
11+
12+
async function main() {
13+
const { dry } = yargs.argv;
14+
const [log] = loggerWithErrors();
15+
const options = { definitelyTypedPath: undefined, progress: false, parseInParallel: false };
16+
const dt = await getDefinitelyTyped(options, log);
17+
const allPackages = await AllPackages.read(dt);
18+
const client = await NpmPublishClient.create(process.env.NPM_TOKEN!);
19+
// Loop over npm @types packages and mark as deprecated any that no longer exist in the DT repo.
20+
let from = 0;
21+
let results;
22+
do {
23+
const opts = { limit: 250, from };
24+
results = await search("@types", opts);
25+
for (const result of results) {
26+
const types = result.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+
// Reference the commit/PR that removed it.
30+
const msg = await fetchMsg(types);
31+
if (!msg) {
32+
log.info(`Could not find the commit that removed types/${types}/.`);
33+
continue
34+
}
35+
log.info(`Deprecating ${result.name}: ${msg}`);
36+
if (!dry) await client.deprecate(result.name, "*", msg);
37+
}
38+
from += results.length;
39+
} while (results.length >= 250 && from <= 5000);
40+
}
41+
42+
async function fetchMsg(types: string) {
43+
const {
44+
repository: {
45+
defaultBranchRef: {
46+
target: {
47+
history: {
48+
nodes: [commit],
49+
},
50+
},
51+
},
52+
},
53+
} = await graphql(
54+
`
55+
query ($path: String!) {
56+
repository(name: "DefinitelyTyped", owner: "DefinitelyTyped") {
57+
defaultBranchRef {
58+
target {
59+
... on Commit {
60+
history(first: 1, path: $path) {
61+
nodes {
62+
associatedPullRequests(first: 1) {
63+
nodes {
64+
url
65+
}
66+
}
67+
messageHeadline
68+
}
69+
}
70+
}
71+
}
72+
}
73+
}
74+
}
75+
`,
76+
{
77+
headers: { authorization: `token ${process.env.GH_API_TOKEN}` },
78+
path: `types/${types}/`,
79+
}
80+
);
81+
if (!commit) return;
82+
const {
83+
associatedPullRequests: {
84+
nodes: [pullRequest],
85+
},
86+
messageHeadline,
87+
} = commit;
88+
return pullRequest ? `${messageHeadline} ${pullRequest.url}` : messageHeadline;
89+
}

packages/deprecate/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "dist"
6+
},
7+
"references": [{ "path": "../definitions-parser/" }, { "path": "../utils/" }]
8+
}

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
"files": [],
44
"references": [
55
{ "path": "packages/definitions-parser" },
6+
{ "path": "packages/deprecate" },
67
{ "path": "packages/dts-critic" },
78
{ "path": "packages/dtslint" },
89
{ "path": "packages/dtslint-runner" },
910
{ "path": "packages/header-parser" },
1011
{ "path": "packages/perf" },
1112
{ "path": "packages/publisher" },
13+
{ "path": "packages/retag" },
1214
{ "path": "packages/typescript-versions" },
13-
{ "path": "packages/utils" },
14-
{ "path": "packages/retag" }
15+
{ "path": "packages/utils" }
1516
]
1617
}

0 commit comments

Comments
 (0)