Skip to content

Ensure all scripts are checked, fix errors #50326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions scripts/authors.ts
Original file line number Diff line number Diff line change
@@ -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[];
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions scripts/configureLanguageServiceBuild.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="node"/>
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);

Expand All @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/configurePrerelease.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="node"/>
import { normalize, relative } from "path";
import assert = require("assert");
import * as assert from "assert";
import { readFileSync, writeFileSync } from "fs";

/**
Expand Down
10 changes: 5 additions & 5 deletions scripts/errorCheck.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const async = require("async");
const glob = require("glob");
Comment on lines -1 to -3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are arguably more correct though, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the old requires, or the new imports? (Some of the scripts already used imports; I have these changes also on my module transform branch too.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(The output code is the same; with the imports, we generate const fs = require("fs") exactly)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the old requires since those correspond to these being true CommonJS require calls anyway. It probably doesn't matter, so long as glob doesn't get called.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, are you suggesting import glob from "glob"? I can do that, so long as we enable esModuleInterop. I opted to not change the tsconfig settings since import * seem to work.

Copy link
Member

@DanielRosenwasser DanielRosenwasser Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right so that's the thing - import/require allows us to not worry about interop at all because we get to just say "yeah, the thing Node actually does with CJS.

The alternative is to swap to ESM scripts which I am actually open to as well for dog-fooding purposes. But maybe do that as a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is actually the next step I wanted to take, but I wanted to get them to type check first.

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) {
Expand All @@ -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];
Expand Down Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/failed-tests.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Mocha = require("mocha");
import * as Mocha from "mocha";

export = FailedTestsReporter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")) {
Expand Down
6 changes: 3 additions & 3 deletions scripts/open-cherry-pick-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
/// <reference types="node" />

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"];
Expand Down
4 changes: 2 additions & 2 deletions scripts/open-user-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// <reference lib="es2015.promise" />
// 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"];
Expand All @@ -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
]);

Expand Down
4 changes: 2 additions & 2 deletions scripts/processDiagnosticMessages.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 4 additions & 4 deletions scripts/produceLKG.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// <reference types="node" />

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");
Expand Down
7 changes: 3 additions & 4 deletions scripts/request-pr-review.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/// <reference lib="esnext.asynciterable" />
/// <reference lib="es2015.promise" />
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"],
Expand Down Expand Up @@ -70,4 +69,4 @@ options:
-h --help Prints this help message.
`);
return process.exit(exitCode);
}
}
3 changes: 3 additions & 0 deletions scripts/run-sequence.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { SpawnSyncOptions } from "child_process";

export function runSequence(tasks: [string, string[]][], opts?: SpawnSyncOptions): string;
10 changes: 1 addition & 9 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}