From 66d8b959412d48e4ae827429cbcc5f1b8ec52027 Mon Sep 17 00:00:00 2001
From: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Date: Wed, 17 Aug 2022 16:42:50 -0700
Subject: [PATCH] Ensure all scripts are checked, fix errors (#50326)
---
.gitignore | 1 +
package-lock.json | 13 +++++++++++++
package.json | 1 +
scripts/authors.ts | 10 +++++-----
scripts/configureLanguageServiceBuild.ts | 8 ++++----
scripts/configurePrerelease.ts | 2 +-
scripts/errorCheck.ts | 10 +++++-----
scripts/failed-tests.d.ts | 2 +-
.../importDefinitelyTypedTests.ts | 4 ++--
scripts/open-cherry-pick-pr.ts | 6 +++---
scripts/open-user-pr.ts | 4 ++--
scripts/processDiagnosticMessages.ts | 4 ++--
scripts/produceLKG.ts | 8 ++++----
scripts/request-pr-review.ts | 7 +++----
scripts/run-sequence.d.ts | 3 +++
scripts/tsconfig.json | 10 +---------
16 files changed, 51 insertions(+), 42 deletions(-)
create mode 100644 scripts/run-sequence.d.ts
diff --git a/.gitignore b/.gitignore
index f63a2aeea02..33df5bf877d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -54,6 +54,7 @@ scripts/produceLKG.js
scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js
scripts/generateLocalizedDiagnosticMessages.js
scripts/request-pr-review.js
+scripts/errorCheck.js
scripts/*.js.map
scripts/typings/
coverage/
diff --git a/package-lock.json b/package-lock.json
index 22947e82483..62bca118b3c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -14,6 +14,7 @@
},
"devDependencies": {
"@octokit/rest": "latest",
+ "@types/async": "latest",
"@types/chai": "latest",
"@types/convert-source-map": "latest",
"@types/fs-extra": "^9.0.13",
@@ -435,6 +436,12 @@
"@octokit/openapi-types": "^13.1.0"
}
},
+ "node_modules/@types/async": {
+ "version": "3.2.15",
+ "resolved": "https://registry.npmjs.org/@types/async/-/async-3.2.15.tgz",
+ "integrity": "sha512-PAmPfzvFA31mRoqZyTVsgJMsvbynR429UTTxhmfsUCrWGh3/fxOrzqBtaTPJsn4UtzTv4Vb0+/O7CARWb69N4g==",
+ "dev": true
+ },
"node_modules/@types/chai": {
"version": "4.3.3",
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.3.tgz",
@@ -8884,6 +8891,12 @@
"@octokit/openapi-types": "^13.1.0"
}
},
+ "@types/async": {
+ "version": "3.2.15",
+ "resolved": "https://registry.npmjs.org/@types/async/-/async-3.2.15.tgz",
+ "integrity": "sha512-PAmPfzvFA31mRoqZyTVsgJMsvbynR429UTTxhmfsUCrWGh3/fxOrzqBtaTPJsn4UtzTv4Vb0+/O7CARWb69N4g==",
+ "dev": true
+ },
"@types/chai": {
"version": "4.3.3",
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.3.tgz",
diff --git a/package.json b/package.json
index 1a4d0f4ab67..5d04854f854 100644
--- a/package.json
+++ b/package.json
@@ -30,6 +30,7 @@
},
"devDependencies": {
"@octokit/rest": "latest",
+ "@types/async": "latest",
"@types/chai": "latest",
"@types/convert-source-map": "latest",
"@types/fs-extra": "^9.0.13",
diff --git a/scripts/authors.ts b/scripts/authors.ts
index a619d3022d6..3c7fe985dff 100644
--- a/scripts/authors.ts
+++ b/scripts/authors.ts
@@ -1,6 +1,6 @@
-import fs = require("fs");
-import path = require("path");
-import childProcess = require("child_process");
+import * as fs from "fs";
+import * as path from "path";
+import * as childProcess from "child_process";
interface Author {
displayNames: string[];
@@ -120,10 +120,10 @@ namespace Commands {
const authors: { name: string, email: string, knownAuthor?: Author }[] = [];
const {output: [error, stdout, stderr]} = childProcess.spawnSync(`git`, ["shortlog", "-se", ...specs], { cwd: path.resolve(__dirname, "../") });
if (error) {
- console.log(stderr.toString());
+ console.log(stderr!.toString());
}
else {
- const output = stdout.toString();
+ const output = stdout!.toString();
const lines = output.split("\n");
lines.forEach(line => {
if (line) {
diff --git a/scripts/configureLanguageServiceBuild.ts b/scripts/configureLanguageServiceBuild.ts
index d61aeaeec35..41d189f5b85 100644
--- a/scripts/configureLanguageServiceBuild.ts
+++ b/scripts/configureLanguageServiceBuild.ts
@@ -1,7 +1,7 @@
///
import { normalize, dirname, join } from "path";
import { readFileSync, writeFileSync, unlinkSync, existsSync } from "fs";
-import assert = require("assert");
+import * as assert from "assert";
import { execSync } from "child_process";
const args = process.argv.slice(2);
@@ -10,11 +10,11 @@ const args = process.argv.slice(2);
*/
interface PackageJson {
name: string;
- bin: {};
+ bin?: {};
main: string;
scripts: {
- prepare: string
- postpublish: string
+ prepare?: string
+ postpublish?: string
}
}
diff --git a/scripts/configurePrerelease.ts b/scripts/configurePrerelease.ts
index 141f1d5cba8..17d8bb3a920 100644
--- a/scripts/configurePrerelease.ts
+++ b/scripts/configurePrerelease.ts
@@ -1,6 +1,6 @@
///
import { normalize, relative } from "path";
-import assert = require("assert");
+import * as assert from "assert";
import { readFileSync, writeFileSync } from "fs";
/**
diff --git a/scripts/errorCheck.ts b/scripts/errorCheck.ts
index dfd78724115..711d5474aac 100644
--- a/scripts/errorCheck.ts
+++ b/scripts/errorCheck.ts
@@ -1,6 +1,6 @@
-const fs = require("fs");
-const async = require("async");
-const glob = require("glob");
+import * as fs from "fs";
+import * as async from "async";
+import * as glob from "glob";
fs.readFile("src/compiler/diagnosticMessages.json", "utf-8", (err, data) => {
if (err) {
@@ -25,7 +25,7 @@ fs.readFile("src/compiler/diagnosticMessages.json", "utf-8", (err, data) => {
fs.readFile(baseDir + f, "utf-8", (err, baseline) => {
if (err) throw err;
- let g: string[];
+ let g: RegExpExecArray | null;
while (g = errRegex.exec(baseline)) {
const errCode = +g[1];
const msg = keys.filter(k => messages[k].code === errCode)[0];
@@ -53,7 +53,7 @@ fs.readFile("src/compiler/diagnosticMessages.json", "utf-8", (err, data) => {
fs.readFile("src/compiler/diagnosticInformationMap.generated.ts", "utf-8", (err, data) => {
const errorRegexp = /\s(\w+): \{ code/g;
const errorNames: string[] = [];
- let errMatch: string[];
+ let errMatch: RegExpExecArray | null;
while (errMatch = errorRegexp.exec(data)) {
errorNames.push(errMatch[1]);
}
diff --git a/scripts/failed-tests.d.ts b/scripts/failed-tests.d.ts
index 5218a75910e..866ed8f6bfe 100644
--- a/scripts/failed-tests.d.ts
+++ b/scripts/failed-tests.d.ts
@@ -1,4 +1,4 @@
-import Mocha = require("mocha");
+import * as Mocha from "mocha";
export = FailedTestsReporter;
diff --git a/scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.ts b/scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.ts
index 8dbc6a5c668..bfe4886361b 100644
--- a/scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.ts
+++ b/scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.ts
@@ -46,7 +46,7 @@ function copyFileSync(source: string, destination: string) {
fs.writeFileSync(destination, text);
}
-function importDefinitelyTypedTest(tscPath: string, rwcTestPath: string, testCaseName: string, testFiles: string[], responseFile: string) {
+function importDefinitelyTypedTest(tscPath: string, rwcTestPath: string, testCaseName: string, testFiles: string[], responseFile: string | undefined) {
let cmd = "node " + tscPath + " --module commonjs " + testFiles.join(" ");
if (responseFile) {
cmd += " @" + responseFile;
@@ -122,7 +122,7 @@ function importDefinitelyTypedTests(tscPath: string, rwcTestPath: string, defini
const tsFiles: string[] = [];
const testFiles: string[] = [];
- let paramFile: string;
+ let paramFile: string | undefined;
for (const filePath of files.map(f => path.join(directoryPath, f))) {
if (filePathEndsWith(filePath, ".ts")) {
diff --git a/scripts/open-cherry-pick-pr.ts b/scripts/open-cherry-pick-pr.ts
index 07e61b8e3bf..8bce97f4e06 100644
--- a/scripts/open-cherry-pick-pr.ts
+++ b/scripts/open-cherry-pick-pr.ts
@@ -3,9 +3,9 @@
///
import { Octokit } from "@octokit/rest";
-const {runSequence} = require("./run-sequence");
-import fs = require("fs");
-import path = require("path");
+import { runSequence } from "./run-sequence";
+import * as fs from "fs";
+import * as path from "path";
const userName = process.env.GH_USERNAME;
const reviewers = process.env.REQUESTING_USER ? [process.env.REQUESTING_USER] : ["weswigham", "RyanCavanaugh"];
diff --git a/scripts/open-user-pr.ts b/scripts/open-user-pr.ts
index 7d77da9dea8..314cd737771 100644
--- a/scripts/open-user-pr.ts
+++ b/scripts/open-user-pr.ts
@@ -2,7 +2,7 @@
///
// Must reference esnext.asynciterable lib, since octokit uses AsyncIterable internally
import { Octokit } from "@octokit/rest";
-const {runSequence} = require("./run-sequence");
+import { runSequence } from "./run-sequence";
const userName = process.env.GH_USERNAME || "typescript-bot";
const reviewers = process.env.REQUESTING_USER ? [process.env.REQUESTING_USER] : ["weswigham", "sandersn", "RyanCavanaugh"];
@@ -22,7 +22,7 @@ runSequence([
["node", ["./node_modules/gulp/bin/gulp.js", "baseline-accept"]], // accept baselines
["git", ["checkout", "-b", branchName]], // create a branch
["git", ["add", "."]], // Add all changes
- ["git", ["commit", "-m", `"Update user baselines${+process.env.SOURCE_ISSUE === 33716 ? " +cc @sandersn" : ""}"`]], // Commit all changes (ping nathan if we would post to CI thread)
+ ["git", ["commit", "-m", `"Update user baselines${+process.env.SOURCE_ISSUE! === 33716 ? " +cc @sandersn" : ""}"`]], // Commit all changes (ping nathan if we would post to CI thread)
["git", ["push", "--set-upstream", "fork", branchName, "-f"]] // push the branch
]);
diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts
index fd5f825b848..0ddc27b06f1 100644
--- a/scripts/processDiagnosticMessages.ts
+++ b/scripts/processDiagnosticMessages.ts
@@ -1,5 +1,5 @@
-import path = require("path");
-import fs = require("fs");
+import * as path from "path";
+import * as fs from "fs";
interface DiagnosticDetails {
category: string;
diff --git a/scripts/produceLKG.ts b/scripts/produceLKG.ts
index 08cabcfe619..e4e37df028e 100644
--- a/scripts/produceLKG.ts
+++ b/scripts/produceLKG.ts
@@ -1,9 +1,9 @@
///
-import childProcess = require("child_process");
-import fs = require("fs-extra");
-import path = require("path");
-import glob = require("glob");
+import * as childProcess from "child_process";
+import * as fs from "fs-extra";
+import * as path from "path";
+import * as glob from "glob";
const root = path.join(__dirname, "..");
const source = path.join(root, "built/local");
diff --git a/scripts/request-pr-review.ts b/scripts/request-pr-review.ts
index fd9cf016e6e..f8c993f19e7 100644
--- a/scripts/request-pr-review.ts
+++ b/scripts/request-pr-review.ts
@@ -1,8 +1,7 @@
///
///
-import octokit = require("@octokit/rest");
-import Octokit = octokit.Octokit;
-import minimist = require("minimist");
+import { Octokit } from "@octokit/rest";
+import * as minimist from "minimist";
const options = minimist(process.argv.slice(2), {
boolean: ["help"],
@@ -70,4 +69,4 @@ options:
-h --help Prints this help message.
`);
return process.exit(exitCode);
-}
\ No newline at end of file
+}
diff --git a/scripts/run-sequence.d.ts b/scripts/run-sequence.d.ts
new file mode 100644
index 00000000000..fde899dde0d
--- /dev/null
+++ b/scripts/run-sequence.d.ts
@@ -0,0 +1,3 @@
+import { SpawnSyncOptions } from "child_process";
+
+export function runSequence(tasks: [string, string[]][], opts?: SpawnSyncOptions): string;
diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json
index eeb14ab3781..54d4a435014 100644
--- a/scripts/tsconfig.json
+++ b/scripts/tsconfig.json
@@ -11,13 +11,5 @@
"lib": ["es6", "scripthost"],
},
- "include": [
- "generateLocalizedDiagnosticMessages.ts",
- "processDiagnosticMessages.ts",
- "configurePrerelease.ts",
- "buildProtocol.ts",
- "produceLKG.ts",
- "word2md.ts",
- "request-pr-review.ts"
- ]
+ "include": ["*.ts"]
}