Skip to content

Commit

Permalink
Mark removed types as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Oct 19, 2020
1 parent 9cf6081 commit ed1fb04
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/publisher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@definitelytyped/retag": "^0.0.58-next.6",
"@definitelytyped/typescript-versions": "^0.0.57",
"@definitelytyped/utils": "^0.0.58-next.3",
"@octokit/graphql": "^4.5.6",
"@octokit/rest": "^16.1.0",
"adal-node": "^0.1.22",
"applicationinsights": "^1.0.7",
Expand All @@ -27,6 +28,7 @@
},
"devDependencies": {
"@types/fs-extra": "4.0.0",
"@types/libnpmsearch": "^2.0.1",
"@types/mz": "^0.0.31",
"@types/node": "^12.12.29",
"@types/oboe": "^2.0.28",
Expand Down
2 changes: 1 addition & 1 deletion packages/publisher/src/full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default async function full(
const changedPackages = await calculateVersions(dt, infoClient, log);
await generatePackages(dt, allPackages, changedPackages);
await createSearchIndex(allPackages, infoClient);
await publishPackages(changedPackages, dry, githubAccessToken, fetcher);
await publishPackages(allPackages, changedPackages, dry, githubAccessToken, fetcher);
await publishRegistry(dt, allPackages, dry, infoClient);
await validate(dt);
}
87 changes: 86 additions & 1 deletion packages/publisher/src/publish-packages.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import applicationinsights = require("applicationinsights");
import search = require("libnpmsearch");
import { graphql } from "@octokit/graphql";
import * as yargs from "yargs";

import { defaultLocalOptions } from "./lib/common";
import { deprecateNotNeededPackage, publishNotNeededPackage, publishTypingsPackage } from "./lib/package-publisher";
import { getDefinitelyTyped, AllPackages } from "@definitelytyped/definitions-parser";
import { scopeName, typesDirectoryName } from "@definitelytyped/definitions-parser/dist/lib/settings";
import {
loggerWithErrors,
logUncaughtErrors,
Expand Down Expand Up @@ -52,8 +55,10 @@ if (!module.parent) {
log
);
} else {
const allPackages = await AllPackages.read(dt);
await publishPackages(
await readChangedPackages(await AllPackages.read(dt)),
allPackages,
await readChangedPackages(allPackages),
dry,
process.env.GH_API_TOKEN || "",
new Fetcher()
Expand All @@ -63,6 +68,7 @@ if (!module.parent) {
}

export default async function publishPackages(
allPackages: AllPackages,
changedPackages: ChangedPackages,
dry: boolean,
githubAccessToken: string,
Expand Down Expand Up @@ -187,6 +193,85 @@ export default async function publishPackages(
cacheDirPath
);

// Loop over the @types packages in npm and mark any that no longer
// exist in HEAD as deprecated.
let from = 0;
let objects;
do {
const opts = {
limit: 250,
from
};
objects = await search(`@${scopeName}`, opts);
for (const { name: fullNpmName } of objects) {
const name = fullNpmName.slice(`@${scopeName}/`.length);
// If they don't exist in the types directory or in
// notNeededPackages.json then mark them deprecated. Reference the
// commit/pull request that removed them.
if (!allPackages.tryGetLatestVersion(name) && !allPackages.getNotNeededPackage(name)) {
log(`Deprecating ${name}`);
const {
repository: {
ref: {
target: {
history: {
nodes: [commit]
}
}
}
}
} = await graphql(
`
query($path: String!) {
repository(name: "DefinitelyTyped", owner: "DefinitelyTyped") {
ref(qualifiedName: "master") {
target {
... on Commit {
history(first: 1, path: $path) {
nodes {
associatedPullRequests(first: 1) {
nodes {
url
}
}
messageHeadline
}
}
}
}
}
}
}
`,
{
headers: { authorization: `token ${githubAccessToken}` },
path: `${typesDirectoryName}/${name}`
}
);
let deprecatedMessage;
if (commit) {
const {
associatedPullRequests: {
nodes: [pullRequest]
},
messageHeadline
} = commit;
deprecatedMessage = messageHeadline;
if (pullRequest) {
deprecatedMessage += ` (${pullRequest.url})`;
}
}
if (dry) {
log(`(dry) Skip deprecate removed package ${fullNpmName}`);
} else {
log(`Deprecating ${fullNpmName} with message: ${deprecatedMessage}`);
await client.deprecate(fullNpmName, "", deprecatedMessage);
}
}
}
from += objects.length;
} while (objects.length >= 250 && from <= 5000);

await writeLog("publishing.md", logResult());
console.log("Done!");
}
Expand Down

0 comments on commit ed1fb04

Please sign in to comment.