Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Oct 27, 2020
1 parent b5e7c98 commit a14ab1a
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 88 deletions.
21 changes: 21 additions & 0 deletions packages/deprecate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@definitelytyped/deprecate",
"version": "1.0.0",
"description": "Loop over the @types packages in npm and mark any that no longer exist in HEAD as deprecated.",
"main": "dist/index.js",
"license": "MIT",
"bin": "dist/index.js",
"scripts": {
"build": "tsc --build"
},
"dependencies": {
"@definitelytyped/definitions-parser": "^0.0.58-next.6",
"@definitelytyped/publisher": "^0.0.58-next.6",
"@definitelytyped/utils": "^0.0.58-next.3",
"@octokit/graphql": "^4.5.6",
"yargs": "^16.1.0"
},
"devDependencies": {
"@types/libnpmsearch": "^2.0.1"
}
}
104 changes: 104 additions & 0 deletions packages/deprecate/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env node

import { graphql } from "@octokit/graphql";
import search = require("libnpmsearch");
import * as yargs from "yargs";

import { AllPackages, getDefinitelyTyped } from "@definitelytyped/definitions-parser";
import { getSecret, Secret } from "@definitelytyped/publisher/dist/lib/secrets";
import { loggerWithErrors, NpmPublishClient } from "@definitelytyped/utils";

async function main() {
const [log] = loggerWithErrors();

const options = {
definitelyTypedPath: `${__dirname}/../../../../DefinitelyTyped`,
progress: true,
parseInParallel: true
};
const dt = await getDefinitelyTyped(options, log);
const allPackages = await AllPackages.read(dt);

const { dry } = yargs.argv;
const client = dry || (await NpmPublishClient.create(await getSecret(Secret.NPM_TOKEN)));

// 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("@types", opts);
for (const { name: fullNpmName } of objects) {
const name = fullNpmName.slice("@types/".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.info(`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 ${process.env.GH_API_TOKEN}` },
path: `types/${name}`
}
);
let deprecatedMessage;
if (commit) {
const {
associatedPullRequests: {
nodes: [pullRequest]
},
messageHeadline
} = commit;
deprecatedMessage = messageHeadline;
if (pullRequest) {
deprecatedMessage += ` (${pullRequest.url})`;
}
}
if (dry) {
log.info(`(dry) Skip deprecate removed package ${fullNpmName}`);
} else {
log.info(`Deprecating ${fullNpmName} with message: ${deprecatedMessage}`);
await (client as NpmPublishClient).deprecate(fullNpmName, "", deprecatedMessage);
}
}
}
from += objects.length;
} while (objects.length >= 250 && from <= 5000);
}
main();
8 changes: 8 additions & 0 deletions packages/deprecate/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"references": [{ "path": "../definitions-parser" }, { "path": "../publisher" }, { "path": "../utils" }]
}
2 changes: 0 additions & 2 deletions packages/publisher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"@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 @@ -28,7 +27,6 @@
},
"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(allPackages, changedPackages, dry, githubAccessToken, fetcher);
await publishPackages(changedPackages, dry, githubAccessToken, fetcher);
await publishRegistry(dt, allPackages, dry, infoClient);
await validate(dt);
}
86 changes: 1 addition & 85 deletions packages/publisher/src/publish-packages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import applicationinsights = require("applicationinsights");
import search = require("libnpmsearch");
import { graphql } from "@octokit/graphql";
import * as yargs from "yargs";

import { defaultLocalOptions } from "./lib/common";
Expand Down Expand Up @@ -54,10 +52,8 @@ if (!module.parent) {
log
);
} else {
const allPackages = await AllPackages.read(dt);
await publishPackages(
allPackages,
await readChangedPackages(allPackages),
await readChangedPackages(await AllPackages.read(dt)),
dry,
process.env.GH_API_TOKEN || "",
new Fetcher()
Expand All @@ -67,7 +63,6 @@ if (!module.parent) {
}

export default async function publishPackages(
allPackages: AllPackages,
changedPackages: ChangedPackages,
dry: boolean,
githubAccessToken: string,
Expand Down Expand Up @@ -192,85 +187,6 @@ 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("@types", opts);
for (const { name: fullNpmName } of objects) {
const name = fullNpmName.slice("@types/".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: `types/${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 a14ab1a

Please sign in to comment.