Skip to content

Commit 6fba113

Browse files
committed
Apply suggestions from code review
1 parent b5e7c98 commit 6fba113

File tree

6 files changed

+133
-88
lines changed

6 files changed

+133
-88
lines changed

packages/deprecate/package.json

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

packages/deprecate/src/index.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env node
2+
3+
import { graphql } from "@octokit/graphql";
4+
import search = require("libnpmsearch");
5+
import * as yargs from "yargs";
6+
7+
import { AllPackages, getDefinitelyTyped } from "@definitelytyped/definitions-parser";
8+
import { getSecret, Secret } from "@definitelytyped/publisher/dist/lib/secrets";
9+
import { loggerWithErrors, NpmPublishClient } from "@definitelytyped/utils";
10+
11+
// Loop over the @types packages in npm and mark any that no longer
12+
// exist in HEAD as deprecated.
13+
async function main() {
14+
const [log] = loggerWithErrors();
15+
16+
const options = {
17+
definitelyTypedPath: `${__dirname}/../../../../DefinitelyTyped`,
18+
progress: true,
19+
parseInParallel: true
20+
};
21+
const dt = await getDefinitelyTyped(options, log);
22+
const allPackages = await AllPackages.read(dt);
23+
const client = yargs.argv.dry || (await NpmPublishClient.create(await getSecret(Secret.NPM_TOKEN)));
24+
25+
let from = 0;
26+
let objects;
27+
do {
28+
const opts = {
29+
limit: 250,
30+
from
31+
};
32+
objects = await search("@types", opts);
33+
for (const { name: fullNpmName } of objects) {
34+
const name = fullNpmName.slice("@types/".length);
35+
// If they don't exist in the types directory or in
36+
// notNeededPackages.json then mark them deprecated. Reference the
37+
// commit/pull request that removed them.
38+
if (!allPackages.tryGetLatestVersion(name) && !allPackages.getNotNeededPackage(name)) {
39+
log.info(`Deprecating ${name}`);
40+
const {
41+
repository: {
42+
ref: {
43+
target: {
44+
history: {
45+
nodes: [commit]
46+
}
47+
}
48+
}
49+
}
50+
} = await graphql(
51+
`
52+
query($path: String!) {
53+
repository(name: "DefinitelyTyped", owner: "DefinitelyTyped") {
54+
ref(qualifiedName: "master") {
55+
target {
56+
... on Commit {
57+
history(first: 1, path: $path) {
58+
nodes {
59+
associatedPullRequests(first: 1) {
60+
nodes {
61+
url
62+
}
63+
}
64+
messageHeadline
65+
}
66+
}
67+
}
68+
}
69+
}
70+
}
71+
}
72+
`,
73+
{
74+
headers: { authorization: `token ${process.env.GH_API_TOKEN}` },
75+
path: `types/${name}`
76+
}
77+
);
78+
let deprecatedMessage;
79+
if (commit) {
80+
const {
81+
associatedPullRequests: {
82+
nodes: [pullRequest]
83+
},
84+
messageHeadline
85+
} = commit;
86+
deprecatedMessage = messageHeadline;
87+
if (pullRequest) {
88+
deprecatedMessage += ` (${pullRequest.url})`;
89+
}
90+
}
91+
if (yargs.argv.dry) {
92+
log.info(`(dry) Skip deprecate removed package ${fullNpmName}`);
93+
} else {
94+
log.info(`Deprecating ${fullNpmName} with message: ${deprecatedMessage}`);
95+
await (client as NpmPublishClient).deprecate(fullNpmName, "", deprecatedMessage);
96+
}
97+
}
98+
}
99+
from += objects.length;
100+
} while (objects.length >= 250 && from <= 5000);
101+
}
102+
main();

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+
"outDir": "dist",
5+
"rootDir": "src"
6+
},
7+
"references": [{ "path": "../definitions-parser" }, { "path": "../publisher" }, { "path": "../utils" }]
8+
}

packages/publisher/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"@definitelytyped/retag": "^0.0.58-next.6",
1212
"@definitelytyped/typescript-versions": "^0.0.57",
1313
"@definitelytyped/utils": "^0.0.58-next.3",
14-
"@octokit/graphql": "^4.5.6",
1514
"@octokit/rest": "^16.1.0",
1615
"adal-node": "^0.1.22",
1716
"applicationinsights": "^1.0.7",
@@ -28,7 +27,6 @@
2827
},
2928
"devDependencies": {
3029
"@types/fs-extra": "4.0.0",
31-
"@types/libnpmsearch": "^2.0.1",
3230
"@types/mz": "^0.0.31",
3331
"@types/node": "^12.12.29",
3432
"@types/oboe": "^2.0.28",

packages/publisher/src/full.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default async function full(
5151
const changedPackages = await calculateVersions(dt, infoClient, log);
5252
await generatePackages(dt, allPackages, changedPackages);
5353
await createSearchIndex(allPackages, infoClient);
54-
await publishPackages(allPackages, changedPackages, dry, githubAccessToken, fetcher);
54+
await publishPackages(changedPackages, dry, githubAccessToken, fetcher);
5555
await publishRegistry(dt, allPackages, dry, infoClient);
5656
await validate(dt);
5757
}

packages/publisher/src/publish-packages.ts

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import applicationinsights = require("applicationinsights");
2-
import search = require("libnpmsearch");
3-
import { graphql } from "@octokit/graphql";
42
import * as yargs from "yargs";
53

64
import { defaultLocalOptions } from "./lib/common";
@@ -54,10 +52,8 @@ if (!module.parent) {
5452
log
5553
);
5654
} else {
57-
const allPackages = await AllPackages.read(dt);
5855
await publishPackages(
59-
allPackages,
60-
await readChangedPackages(allPackages),
56+
await readChangedPackages(await AllPackages.read(dt)),
6157
dry,
6258
process.env.GH_API_TOKEN || "",
6359
new Fetcher()
@@ -67,7 +63,6 @@ if (!module.parent) {
6763
}
6864

6965
export default async function publishPackages(
70-
allPackages: AllPackages,
7166
changedPackages: ChangedPackages,
7267
dry: boolean,
7368
githubAccessToken: string,
@@ -192,85 +187,6 @@ export default async function publishPackages(
192187
cacheDirPath
193188
);
194189

195-
// Loop over the @types packages in npm and mark any that no longer
196-
// exist in HEAD as deprecated.
197-
let from = 0;
198-
let objects;
199-
do {
200-
const opts = {
201-
limit: 250,
202-
from
203-
};
204-
objects = await search("@types", opts);
205-
for (const { name: fullNpmName } of objects) {
206-
const name = fullNpmName.slice("@types/".length);
207-
// If they don't exist in the types directory or in
208-
// notNeededPackages.json then mark them deprecated. Reference the
209-
// commit/pull request that removed them.
210-
if (!allPackages.tryGetLatestVersion(name) && !allPackages.getNotNeededPackage(name)) {
211-
log(`Deprecating ${name}`);
212-
const {
213-
repository: {
214-
ref: {
215-
target: {
216-
history: {
217-
nodes: [commit]
218-
}
219-
}
220-
}
221-
}
222-
} = await graphql(
223-
`
224-
query($path: String!) {
225-
repository(name: "DefinitelyTyped", owner: "DefinitelyTyped") {
226-
ref(qualifiedName: "master") {
227-
target {
228-
... on Commit {
229-
history(first: 1, path: $path) {
230-
nodes {
231-
associatedPullRequests(first: 1) {
232-
nodes {
233-
url
234-
}
235-
}
236-
messageHeadline
237-
}
238-
}
239-
}
240-
}
241-
}
242-
}
243-
}
244-
`,
245-
{
246-
headers: { authorization: `token ${githubAccessToken}` },
247-
path: `types/${name}`
248-
}
249-
);
250-
let deprecatedMessage;
251-
if (commit) {
252-
const {
253-
associatedPullRequests: {
254-
nodes: [pullRequest]
255-
},
256-
messageHeadline
257-
} = commit;
258-
deprecatedMessage = messageHeadline;
259-
if (pullRequest) {
260-
deprecatedMessage += ` (${pullRequest.url})`;
261-
}
262-
}
263-
if (dry) {
264-
log(`(dry) Skip deprecate removed package ${fullNpmName}`);
265-
} else {
266-
log(`Deprecating ${fullNpmName} with message: ${deprecatedMessage}`);
267-
await client.deprecate(fullNpmName, "", deprecatedMessage);
268-
}
269-
}
270-
}
271-
from += objects.length;
272-
} while (objects.length >= 250 && from <= 5000);
273-
274190
await writeLog("publishing.md", logResult());
275191
console.log("Done!");
276192
}

0 commit comments

Comments
 (0)