mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
Apply prettier and fix all scripts (#57018)
This commit is contained in:
9
.gitignore
vendored
9
.gitignore
vendored
@@ -4,6 +4,7 @@
|
||||
*.pdb
|
||||
*.suo
|
||||
*.js
|
||||
*.cjs
|
||||
*.user
|
||||
*.cache
|
||||
*.cs
|
||||
@@ -32,10 +33,10 @@ _infrastructure/tests/build
|
||||
|
||||
*.js.map
|
||||
!*.js/
|
||||
!scripts/new-package.js
|
||||
!scripts/not-needed.js
|
||||
!scripts/lint.js
|
||||
!scripts/close-old-issues.js
|
||||
!scripts/not-needed.cjs
|
||||
!scripts/close-old-issues.cjs
|
||||
!scripts/remove-empty.cjs
|
||||
!scripts/update-codeowners.cjs
|
||||
|
||||
# npm
|
||||
node_modules
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
},
|
||||
"scripts": {
|
||||
"compile-scripts": "tsc -p scripts",
|
||||
"not-needed": "node scripts/not-needed.js",
|
||||
"update-codeowners": "node scripts/update-codeowners.js",
|
||||
"not-needed": "node scripts/not-needed.cjs",
|
||||
"update-codeowners": "node scripts/update-codeowners.cjs",
|
||||
"test-all": "node node_modules/@definitelytyped/dtslint-runner/dist/index.js --path .",
|
||||
"clean": "node scripts/remove-empty.js",
|
||||
"clean": "node scripts/remove-empty.cjs",
|
||||
"test": "dtslint types",
|
||||
"lint": "dtslint types",
|
||||
"prettier": "prettier"
|
||||
|
||||
@@ -7,32 +7,41 @@ const octokit = new CustomOctokit({ auth: process.env.GITHUB_API_TOKEN });
|
||||
const message = `
|
||||
Hi thread, we're moving DefinitelyTyped to use [GitHub Discussions](https://github.com/DefinitelyTyped/DefinitelyTyped/issues/53377) for conversations the \`@types\` modules in DefinitelyTyped.
|
||||
|
||||
To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the [TypeScript Community Discord](https://discord.gg/typescript) and mention the issue in the \`definitely-typed\` channel.`
|
||||
|
||||
To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the [TypeScript Community Discord](https://discord.gg/typescript) and mention the issue in the \`definitely-typed\` channel.`;
|
||||
|
||||
const go = async () => {
|
||||
const sixMonthsAgo = addMonths(new Date(), -6);
|
||||
const dateQuery = sixMonthsAgo.toISOString().split('T')[0];
|
||||
|
||||
|
||||
// For example:
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/search?q=updated%3A%3C%3D2021-02-01&state=open&type=issues
|
||||
|
||||
const parameters = {
|
||||
per_page: 100,
|
||||
q: `type:issue updated:<=${dateQuery} repo:DefinitelyTyped/DefinitelyTyped state:open`
|
||||
q: `type:issue updated:<=${dateQuery} repo:DefinitelyTyped/DefinitelyTyped state:open`,
|
||||
};
|
||||
|
||||
for await (const response of octokit.paginate.iterator('GET /search/issues', parameters)) {
|
||||
console.log("\n-")
|
||||
console.log('\n-');
|
||||
/** @type {Array<import("@octokit/types/src/generated/Endpoints").Endpoints["GET /issues"]["response"]["data"][number]>} */
|
||||
const items = response.data
|
||||
const items = response.data;
|
||||
for (const issue of items) {
|
||||
// Ignore issues with labels
|
||||
if (issue.labels.length) continue;
|
||||
|
||||
process.stdout.write("#" + issue.number + " ")
|
||||
await octokit.issues.update({ repo: "DefinitelyTyped", owner: "DefinitelyTyped", issue_number: issue.number, state: "closed" })
|
||||
await octokit.issues.createComment({ repo: "DefinitelyTyped", owner: "DefinitelyTyped", issue_number: issue.number, body: message })
|
||||
process.stdout.write('#' + issue.number + ' ');
|
||||
await octokit.issues.createComment({
|
||||
repo: 'DefinitelyTyped',
|
||||
owner: 'DefinitelyTyped',
|
||||
issue_number: issue.number,
|
||||
body: message,
|
||||
});
|
||||
await octokit.issues.update({
|
||||
repo: 'DefinitelyTyped',
|
||||
owner: 'DefinitelyTyped',
|
||||
issue_number: issue.number,
|
||||
state: 'closed',
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
const home = path.join(__dirname, "..", "types");
|
||||
const home = path.join('.', 'types');
|
||||
|
||||
for (const dirName of fs.readdirSync(home)) {
|
||||
if (dirName.startsWith(".") || dirName === "node_modules" || dirName === "scripts") {
|
||||
if (dirName.startsWith('.') || dirName === 'node_modules' || dirName === 'scripts') {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ function fixTsconfig(dir: string): void {
|
||||
const target = path.join(dir, 'tsconfig.json');
|
||||
let json = JSON.parse(fs.readFileSync(target, 'utf-8'));
|
||||
json = fix(json);
|
||||
fs.writeFileSync(target, JSON.stringify(json, undefined, 4), "utf-8");
|
||||
fs.writeFileSync(target, JSON.stringify(json, undefined, 4), 'utf-8');
|
||||
}
|
||||
|
||||
function fix(config: any): any {
|
||||
const out: any = {};
|
||||
for (const key in config) {
|
||||
let value = config[key];
|
||||
if (key === "compilerOptions") {
|
||||
if (key === 'compilerOptions') {
|
||||
value = fixCompilerOptions(value);
|
||||
}
|
||||
out[key] = value;
|
||||
|
||||
@@ -1,36 +1,34 @@
|
||||
/// <reference lib="esnext"/>
|
||||
// Script to remove a package from DefinitelyTyped and add it to notNeededPackages.json
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const typingsPackageName = process.argv[2];
|
||||
const asOfVersion = process.argv[3];
|
||||
const libraryName = process.argv[4] || typingsPackageName;
|
||||
|
||||
if (process.argv.length !== 4 && process.argv.length !== 5) {
|
||||
console.log("Usage: npm run not-needed -- typingsPackageName asOfVersion [libraryName]");
|
||||
process.exit(1);
|
||||
console.log('Usage: npm run not-needed -- typingsPackageName asOfVersion [libraryName]');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
rmdirRecursive(path.join("types", typingsPackageName));
|
||||
rmdirRecursive(path.join('types', typingsPackageName));
|
||||
|
||||
/** @type {{packages: Record<string, { libraryName: string; asOfVersion: string; }> }} */
|
||||
const notNeededPackages = JSON.parse(fs.readFileSync("notNeededPackages.json", "utf-8"));
|
||||
const notNeededPackages = JSON.parse(fs.readFileSync('notNeededPackages.json', 'utf-8'));
|
||||
notNeededPackages.packages[typingsPackageName] = { libraryName, asOfVersion };
|
||||
const sortedPackages = Object.entries(notNeededPackages.packages).sort((packageA, packageB) =>
|
||||
packageA[0].localeCompare(packageB[0]),
|
||||
);
|
||||
notNeededPackages.packages = Object.fromEntries(sortedPackages);
|
||||
fs.writeFileSync("notNeededPackages.json", JSON.stringify(notNeededPackages, undefined, 4) + "\n", "utf-8");
|
||||
fs.writeFileSync('notNeededPackages.json', JSON.stringify(notNeededPackages, undefined, 4) + '\n', 'utf-8');
|
||||
|
||||
function rmdirRecursive(dir) {
|
||||
for (let entry of fs.readdirSync(dir)) {
|
||||
entry = path.join(dir, entry)
|
||||
if (fs.statSync(entry).isDirectory())
|
||||
rmdirRecursive(entry);
|
||||
else
|
||||
fs.unlinkSync(entry);
|
||||
}
|
||||
fs.rmdirSync(dir);
|
||||
for (let entry of fs.readdirSync(dir)) {
|
||||
entry = path.join(dir, entry);
|
||||
if (fs.statSync(entry).isDirectory()) rmdirRecursive(entry);
|
||||
else fs.unlinkSync(entry);
|
||||
}
|
||||
fs.rmdirSync(dir);
|
||||
}
|
||||
10
scripts/remove-empty.cjs
Normal file
10
scripts/remove-empty.cjs
Normal file
@@ -0,0 +1,10 @@
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path');
|
||||
for (const d of fs.readdirSync('./types')) {
|
||||
const dir = path.join('./types', d);
|
||||
const files = fs.readdirSync(dir);
|
||||
if (files.length === 0 || files.length === 1) {
|
||||
console.log('Deleting unused directory', dir);
|
||||
fs.rmdirSync(dir, { recursive: true });
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
for (const d of fs.readdirSync("../types")) {
|
||||
const dir = path.join("../types", d)
|
||||
const files = fs.readdirSync(dir)
|
||||
if (files.length === 0 || files.length === 1) {
|
||||
console.log("Deleting unused directory", dir)
|
||||
fs.rmdirSync(dir, { recursive: true })
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
"exclude": ["fix-tslint.ts", "update-config"],
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "es2020",
|
||||
"strict": true,
|
||||
"baseUrl": "../types",
|
||||
"moduleResolution": "node",
|
||||
|
||||
@@ -1,53 +1,59 @@
|
||||
/// <reference lib="esnext.asynciterable" />
|
||||
// Must reference esnext.asynciterable lib, since octokit uses AsyncIterable internally
|
||||
const cp = require("child_process");
|
||||
const os = require("os");
|
||||
const { AllPackages, getDefinitelyTyped, parseDefinitions, clean } = require("@definitelytyped/definitions-parser");
|
||||
const { loggerWithErrors } = require("@definitelytyped/utils");
|
||||
const { writeFile } = require("fs-extra");
|
||||
const cp = require('node:child_process');
|
||||
const os = require('node:os');
|
||||
const { AllPackages, getDefinitelyTyped, parseDefinitions, clean } = require('@definitelytyped/definitions-parser');
|
||||
const { loggerWithErrors } = require('@definitelytyped/utils');
|
||||
const { writeFile } = require('fs-extra');
|
||||
|
||||
async function main() {
|
||||
const options = { definitelyTypedPath: ".", progress: false, parseInParallel: true };
|
||||
const options = { definitelyTypedPath: '.', progress: false, parseInParallel: true };
|
||||
const log = loggerWithErrors()[0];
|
||||
|
||||
clean();
|
||||
const dt = await getDefinitelyTyped(options, log);
|
||||
await parseDefinitions(dt, { nProcesses: os.cpus().length, definitelyTypedPath: "." }, log);
|
||||
await parseDefinitions(dt, { nProcesses: os.cpus().length, definitelyTypedPath: '.' }, log);
|
||||
const allPackages = await AllPackages.read(dt);
|
||||
const typings = allPackages.allTypings();
|
||||
const maxPathLen = Math.max(...typings.map(t => t.subDirectoryPath.length));
|
||||
const entries = mapDefined(typings, t => getEntry(t, maxPathLen));
|
||||
await writeFile([options.definitelyTypedPath, ".github", "CODEOWNERS"].join("/"), `${header}\n\n${entries.join("\n")}\n`, { encoding: "utf-8" });
|
||||
await writeFile(
|
||||
[options.definitelyTypedPath, '.github', 'CODEOWNERS'].join('/'),
|
||||
`${header}\n\n${entries.join('\n')}\n`,
|
||||
{ encoding: 'utf-8' },
|
||||
);
|
||||
}
|
||||
|
||||
runSequence([
|
||||
["git", ["checkout", "."]], // reset any changes
|
||||
['git', ['checkout', '.']], // reset any changes
|
||||
]);
|
||||
|
||||
main().then(() => {
|
||||
runSequence([
|
||||
["git", ["add", ".github/CODEOWNERS"]], // Add CODEOWNERS
|
||||
["git", ["commit", "-m", `"🤖 Update CODEOWNERS"`]], // Commit all changes
|
||||
["git", ["pull"]], // Ensure we're up-to-date
|
||||
["git", ["push"]] // push the branch
|
||||
]);
|
||||
console.log(`Pushed new commit.`);
|
||||
}).catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
main()
|
||||
.then(() => {
|
||||
runSequence([
|
||||
['git', ['add', '.github/CODEOWNERS']], // Add CODEOWNERS
|
||||
['git', ['pull']], // Ensure we're up-to-date
|
||||
['git', ['commit', '-m', `"🤖 Update CODEOWNERS"`]], // Commit all changes
|
||||
['git', ['push']], // push the branch
|
||||
]);
|
||||
console.log(`Pushed new commit.`);
|
||||
})
|
||||
.catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
/** @param {[string, string[]][]} tasks */
|
||||
function runSequence(tasks) {
|
||||
for (const task of tasks) {
|
||||
console.log(`${task[0]} ${task[1].join(" ")}`);
|
||||
const result = cp.spawnSync(task[0], task[1], { timeout: 100000, shell: true, stdio: "inherit" });
|
||||
if (result.status !== 0) throw new Error(`${task[0]} ${task[1].join(" ")} failed: ${result.stderr && result.stderr.toString()}`);
|
||||
console.log(`${task[0]} ${task[1].join(' ')}`);
|
||||
const result = cp.spawnSync(task[0], task[1], { timeout: 100000, shell: true, stdio: 'inherit' });
|
||||
if (result.status !== 0)
|
||||
throw new Error(`${task[0]} ${task[1].join(' ')} failed: ${result.stderr && result.stderr.toString()}`);
|
||||
}
|
||||
}
|
||||
|
||||
const header =
|
||||
`# This file is generated.
|
||||
const header = `# This file is generated.
|
||||
# Add yourself to the "Definitions by:" list instead.
|
||||
# See https://github.com/DefinitelyTyped/DefinitelyTyped#definition-owners`;
|
||||
|
||||
@@ -63,7 +69,7 @@ function getEntry(pkg, maxPathLen) {
|
||||
}
|
||||
|
||||
const path = `${pkg.subDirectoryPath}/`.padEnd(maxPathLen);
|
||||
return `/types/${path} ${users.map(u => `@${u}`).join(" ")}`;
|
||||
return `/types/${path} ${users.map(u => `@${u}`).join(' ')}`;
|
||||
}
|
||||
|
||||
/**
|
||||
Reference in New Issue
Block a user