-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
135 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters