Skip to content

Commit ad56b5c

Browse files
authored
Convert scripts/Gulpfile to checked mjs/cjs so they can run without compilation (microsoft#50988)
1 parent dbeae5d commit ad56b5c

File tree

72 files changed

+1083
-942
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1083
-942
lines changed

.dockerignore

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,8 @@ build.json
1717
*.config
1818
scripts/debug.bat
1919
scripts/run.bat
20-
scripts/word2md.js
21-
scripts/buildProtocol.js
22-
scripts/ior.js
23-
scripts/configurePrerelease.js
24-
scripts/open-user-pr.js
25-
scripts/open-cherry-pick-pr.js
26-
scripts/processDiagnosticMessages.d.ts
27-
scripts/processDiagnosticMessages.js
28-
scripts/produceLKG.js
29-
scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js
30-
scripts/generateLocalizedDiagnosticMessages.js
31-
scripts/configureLanguageServiceBuild.js
32-
scripts/*.js.map
33-
scripts/typings/
20+
scripts/**/*.js
21+
scripts/**/*.js.map
3422
coverage/
3523
internal/
3624
**/.DS_Store

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
/lib/**
55
/src/lib/*.generated.d.ts
66
# Ignore all compiled script outputs
7-
/scripts/*.js
7+
/scripts/**/*.js
8+
/scripts/**/*.d.*
89
# But, not the ones that are hand-written.
910
# TODO: remove once scripts are pure JS
1011
!/scripts/browserIntegrationTest.js

.eslintplugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require("fs");
22
const path = require("path");
33

44
const rulesDir = path.join(__dirname, "scripts", "eslint", "rules");
5-
const ext = ".js";
5+
const ext = ".cjs";
66
const ruleFiles = fs.readdirSync(rulesDir).filter((p) => p.endsWith(ext));
77

88
module.exports = {

.eslintrc.json

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@
1212
"plugins": [
1313
"@typescript-eslint", "jsdoc", "no-null", "import", "eslint-plugin-local"
1414
],
15-
"overrides": [
16-
// By default, the ESLint CLI only looks at .js files. But, it will also look at
17-
// any files which are referenced in an override config. Most users of typescript-eslint
18-
// get this behavior by default by extending a recommended typescript-eslint config, which
19-
// just so happens to override some core ESLint rules. We don't extend from any config, so
20-
// explicitly reference TS files here so the CLI picks them up.
21-
//
22-
// ESLint in VS Code will lint any opened file (so long as it's not eslintignore'd), so
23-
// that will work regardless of the below.
24-
{ "files": ["*.ts", "*.mts", "*.cts", "*.mjs", "*.cjs"] }
25-
],
2615
"rules": {
2716
"@typescript-eslint/adjacent-overload-signatures": "error",
2817
"@typescript-eslint/array-type": "error",
@@ -151,5 +140,31 @@
151140
"no-prototype-builtins": "error",
152141
"no-self-assign": "error",
153142
"no-dupe-else-if": "error"
154-
}
143+
},
144+
"overrides": [
145+
// By default, the ESLint CLI only looks at .js files. But, it will also look at
146+
// any files which are referenced in an override config. Most users of typescript-eslint
147+
// get this behavior by default by extending a recommended typescript-eslint config, which
148+
// just so happens to override some core ESLint rules. We don't extend from any config, so
149+
// explicitly reference TS files here so the CLI picks them up.
150+
//
151+
// ESLint in VS Code will lint any opened file (so long as it's not eslintignore'd), so
152+
// that will work regardless of the below.
153+
//
154+
// The same applies to mjs files; ESLint appears to not scan those either.
155+
{ "files": ["*.ts", "*.mts", "*.cts", "*.mjs", "*.cjs"] },
156+
{
157+
"files": ["*.mjs", "*.mts"],
158+
"rules": {
159+
// These globals don't exist outside of CJS files.
160+
"no-restricted-globals": ["error",
161+
{ "name": "__filename" },
162+
{ "name": "__dirname" },
163+
{ "name": "require" },
164+
{ "name": "module" },
165+
{ "name": "exports" }
166+
]
167+
}
168+
}
169+
]
155170
}

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,20 @@ jobs:
6767

6868
- name: Validate the browser can import TypeScript
6969
run: gulp test-browser-integration
70+
71+
misc:
72+
runs-on: ubuntu-latest
73+
74+
steps:
75+
- uses: actions/checkout@v3
76+
- uses: actions/setup-node@v3
77+
with:
78+
node-version: "*"
79+
check-latest: true
80+
- run: npm ci
81+
82+
- name: Build scripts
83+
run: gulp scripts
84+
85+
- name: ESLint tests
86+
run: gulp run-eslint-rules-tests

.gitignore

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,8 @@ tests/cases/**/*.js.map
4040
scripts/eslint/built/
4141
scripts/debug.bat
4242
scripts/run.bat
43-
scripts/word2md.js
44-
scripts/buildProtocol.js
45-
scripts/ior.js
46-
scripts/configurePrerelease.js
47-
scripts/configureLanguageServiceBuild.js
48-
scripts/open-user-pr.js
49-
scripts/open-cherry-pick-pr.js
50-
scripts/processDiagnosticMessages.d.ts
51-
scripts/processDiagnosticMessages.js
52-
scripts/produceLKG.js
53-
scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js
54-
scripts/generateLocalizedDiagnosticMessages.js
55-
scripts/request-pr-review.js
56-
scripts/errorCheck.js
57-
scripts/*.js.map
58-
scripts/typings/
43+
scripts/**/*.js
44+
scripts/**/*.js.map
5945
coverage/
6046
internal/
6147
**/.DS_Store

Gulpfile.js renamed to Gulpfile.mjs

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
// @ts-check
2-
const path = require("path");
3-
const fs = require("fs");
4-
const log = require("fancy-log");
5-
const newer = require("gulp-newer");
6-
const sourcemaps = require("gulp-sourcemaps");
7-
const del = require("del");
8-
const rename = require("gulp-rename");
9-
const concat = require("gulp-concat");
10-
const merge2 = require("merge2");
11-
const { src, dest, task, parallel, series, watch } = require("gulp");
12-
const { append, transform } = require("gulp-insert");
13-
const { prependFile } = require("./scripts/build/prepend");
14-
const { exec, readJson, needsUpdate, getDiffTool, getDirSize, rm } = require("./scripts/build/utils");
15-
const { runConsoleTests, refBaseline, localBaseline, refRwcBaseline, localRwcBaseline } = require("./scripts/build/tests");
16-
const { buildProject, cleanProject, watchProject } = require("./scripts/build/projects");
17-
const cmdLineOptions = require("./scripts/build/options");
2+
import path from "path";
3+
import fs from "fs";
4+
import log from "fancy-log";
5+
import newer from "gulp-newer";
6+
import sourcemaps from "gulp-sourcemaps";
7+
import del from "del";
8+
import rename from "gulp-rename";
9+
import concat from "gulp-concat";
10+
import merge2 from "merge2";
11+
import gulp from "gulp";
12+
import { append, transform } from "gulp-insert";
13+
import { prependFile } from "./scripts/build/prepend.mjs";
14+
import { exec, readJson, needsUpdate, getDiffTool, getDirSize, rm } from "./scripts/build/utils.mjs";
15+
import { runConsoleTests, refBaseline, localBaseline, refRwcBaseline, localRwcBaseline } from "./scripts/build/tests.mjs";
16+
import { buildProject, cleanProject, watchProject } from "./scripts/build/projects.mjs";
17+
import cmdLineOptions from "./scripts/build/options.mjs";
18+
19+
const { src, dest, task, parallel, series, watch } = gulp;
1820

1921
const copyright = "CopyrightNotice.txt";
2022
const cleanTasks = [];
@@ -23,9 +25,6 @@ const buildScripts = () => buildProject("scripts");
2325
task("scripts", buildScripts);
2426
task("scripts").description = "Builds files in the 'scripts' folder.";
2527

26-
const cleanScripts = () => cleanProject("scripts");
27-
cleanTasks.push(cleanScripts);
28-
2928
/** @type {{ libs: string[]; paths: Record<string, string | undefined>; }} */
3029
const libraries = readJson("./src/lib/libs.json");
3130
const libs = libraries.libs.map(lib => {
@@ -56,10 +55,10 @@ const diagnosticMessagesJson = "src/compiler/diagnosticMessages.json";
5655
const diagnosticMessagesGeneratedJson = "src/compiler/diagnosticMessages.generated.json";
5756
const generateDiagnostics = async () => {
5857
if (needsUpdate(diagnosticMessagesJson, [diagnosticMessagesGeneratedJson, diagnosticInformationMapTs])) {
59-
await exec(process.execPath, ["scripts/processDiagnosticMessages.js", diagnosticMessagesJson]);
58+
await exec(process.execPath, ["scripts/processDiagnosticMessages.mjs", diagnosticMessagesJson]);
6059
}
6160
};
62-
task("generate-diagnostics", series(buildScripts, generateDiagnostics));
61+
task("generate-diagnostics", generateDiagnostics);
6362
task("generate-diagnostics").description = "Generates a diagnostic file in TypeScript based on an input JSON file";
6463

6564
const cleanDiagnostics = () => del([diagnosticInformationMapTs, diagnosticMessagesGeneratedJson]);
@@ -88,7 +87,7 @@ const localizationTargets = ["cs", "de", "es", "fr", "it", "ja", "ko", "pl", "pt
8887

8988
const localize = async () => {
9089
if (needsUpdate(diagnosticMessagesGeneratedJson, generatedLCGFile)) {
91-
return exec(process.execPath, ["scripts/generateLocalizedDiagnosticMessages.js", "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true });
90+
return exec(process.execPath, ["scripts/generateLocalizedDiagnosticMessages.mjs", "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true });
9291
}
9392
};
9493

@@ -97,7 +96,7 @@ const cleanDebugTools = () => cleanProject("src/debug");
9796
cleanTasks.push(cleanDebugTools);
9897

9998
// Pre-build steps when targeting the LKG compiler
100-
const lkgPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnostics, buildDebugTools));
99+
const lkgPreBuild = parallel(generateLibs, series(generateDiagnostics, buildDebugTools));
101100

102101
const buildTsc = () => buildProject("src/tsc");
103102
task("tsc", series(lkgPreBuild, buildTsc));
@@ -113,7 +112,7 @@ task("watch-tsc", series(lkgPreBuild, parallel(watchLib, watchDiagnostics, watch
113112
task("watch-tsc").description = "Watch for changes and rebuild the command-line compiler only.";
114113

115114
// Pre-build steps when targeting the built/local compiler.
116-
const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnostics, buildDebugTools, buildTsc));
115+
const localPreBuild = parallel(generateLibs, series(generateDiagnostics, buildDebugTools, buildTsc));
117116

118117
// Pre-build steps to use based on supplied options.
119118
const preBuild = cmdLineOptions.lkg ? lkgPreBuild : localPreBuild;
@@ -335,17 +334,8 @@ task("clean-tests").description = "Cleans the outputs for the test infrastructur
335334

336335
const watchTests = () => watchProject("src/testRunner", cmdLineOptions);
337336

338-
const buildEslintRules = () => buildProject("scripts/eslint");
339-
task("build-eslint-rules", buildEslintRules);
340-
task("build-eslint-rules").description = "Compiles eslint rules to js";
341-
342-
const cleanEslintRules = () => cleanProject("scripts/eslint");
343-
cleanTasks.push(cleanEslintRules);
344-
task("clean-eslint-rules", cleanEslintRules);
345-
task("clean-eslint-rules").description = "Cleans the outputs for the eslint rules";
346-
347-
const runEslintRulesTests = () => runConsoleTests("scripts/eslint/built/tests", "mocha-fivemat-progress-reporter", /*runInParallel*/ false, /*watchMode*/ false);
348-
task("run-eslint-rules-tests", series(buildEslintRules, runEslintRulesTests));
337+
const runEslintRulesTests = () => runConsoleTests("scripts/eslint/tests", "mocha-fivemat-progress-reporter", /*runInParallel*/ false, /*watchMode*/ false);
338+
task("run-eslint-rules-tests", runEslintRulesTests);
349339
task("run-eslint-rules-tests").description = "Runs the eslint rule tests";
350340

351341
/** @type { (folder: string) => { (): Promise<any>; displayName?: string } } */
@@ -459,8 +449,8 @@ task("runtests-parallel").flags = {
459449
};
460450

461451

462-
task("test-browser-integration", () => exec(process.execPath, ["scripts/browserIntegrationTest.js"]));
463-
task("test-browser-integration").description = "Runs scripts/browserIntegrationTest.ts which tests that typescript.js loads in a browser";
452+
task("test-browser-integration", () => exec(process.execPath, ["scripts/browserIntegrationTest.mjs"]));
453+
task("test-browser-integration").description = "Runs scripts/browserIntegrationTest.mjs which tests that typescript.js loads in a browser";
464454

465455

466456
task("diff", () => exec(getDiffTool(), [refBaseline, localBaseline], { ignoreExitCode: true, waitForExit: false }));
@@ -493,13 +483,9 @@ const updateSublime = () => src(["built/local/tsserver.js", "built/local/tsserve
493483
task("update-sublime", updateSublime);
494484
task("update-sublime").description = "Updates the sublime plugin's tsserver";
495485

496-
const buildImportDefinitelyTypedTests = () => buildProject("scripts/importDefinitelyTypedTests");
497-
const cleanImportDefinitelyTypedTests = () => cleanProject("scripts/importDefinitelyTypedTests");
498-
cleanTasks.push(cleanImportDefinitelyTypedTests);
499-
500486
// TODO(rbuckton): Should the path to DefinitelyTyped be configurable via an environment variable?
501-
const importDefinitelyTypedTests = () => exec(process.execPath, ["scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js", "./", "../DefinitelyTyped"]);
502-
task("importDefinitelyTypedTests", series(buildImportDefinitelyTypedTests, importDefinitelyTypedTests));
487+
const importDefinitelyTypedTests = () => exec(process.execPath, ["scripts/importDefinitelyTypedTests.mjs", "./", "../DefinitelyTyped"]);
488+
task("importDefinitelyTypedTests", importDefinitelyTypedTests);
503489
task("importDefinitelyTypedTests").description = "Runs the importDefinitelyTypedTests script to copy DT's tests to the TS-internal RWC tests";
504490

505491
const buildReleaseTsc = () => buildProject("src/tsc/tsconfig.release.json");
@@ -529,7 +515,7 @@ const produceLKG = async () => {
529515
throw new Error("Cannot replace the LKG unless all built targets are present in directory 'built/local/'. The following files are missing:\n" + missingFiles.join("\n"));
530516
}
531517
const sizeBefore = getDirSize("lib");
532-
await exec(process.execPath, ["scripts/produceLKG.js"]);
518+
await exec(process.execPath, ["scripts/produceLKG.mjs"]);
533519
const sizeAfter = getDirSize("lib");
534520
if (sizeAfter > (sizeBefore * 1.10)) {
535521
throw new Error("The lib folder increased by 10% or more. This likely indicates a bug.");
@@ -543,8 +529,8 @@ task("LKG").flags = {
543529
};
544530
task("lkg", series("LKG"));
545531

546-
const generateSpec = () => exec("cscript", ["//nologo", "scripts/word2md.js", path.resolve("doc/TypeScript Language Specification - ARCHIVED.docx"), path.resolve("doc/spec-ARCHIVED.md")]);
547-
task("generate-spec", series(buildScripts, generateSpec));
532+
const generateSpec = () => exec("cscript", ["//nologo", "scripts/word2md.mjs", path.resolve("doc/TypeScript Language Specification - ARCHIVED.docx"), path.resolve("doc/spec-ARCHIVED.md")]);
533+
task("generate-spec", generateSpec);
548534
task("generate-spec").description = "Generates a Markdown version of the Language Specification";
549535

550536
task("clean", series(parallel(cleanTasks), cleanBuilt));
@@ -554,13 +540,13 @@ const configureNightly = () => exec(process.execPath, ["scripts/configurePrerele
554540
task("configure-nightly", series(buildScripts, configureNightly));
555541
task("configure-nightly").description = "Runs scripts/configurePrerelease.ts to prepare a build for nightly publishing";
556542

557-
const configureInsiders = () => exec(process.execPath, ["scripts/configurePrerelease.js", "insiders", "package.json", "src/compiler/corePublic.ts"]);
558-
task("configure-insiders", series(buildScripts, configureInsiders));
559-
task("configure-insiders").description = "Runs scripts/configurePrerelease.ts to prepare a build for insiders publishing";
543+
const configureInsiders = () => exec(process.execPath, ["scripts/configurePrerelease.mjs", "insiders", "package.json", "src/compiler/corePublic.ts"]);
544+
task("configure-insiders", configureInsiders);
545+
task("configure-insiders").description = "Runs scripts/configurePrerelease.mjs to prepare a build for insiders publishing";
560546

561-
const configureExperimental = () => exec(process.execPath, ["scripts/configurePrerelease.js", "experimental", "package.json", "src/compiler/corePublic.ts"]);
562-
task("configure-experimental", series(buildScripts, configureExperimental));
563-
task("configure-experimental").description = "Runs scripts/configurePrerelease.ts to prepare a build for experimental publishing";
547+
const configureExperimental = () => exec(process.execPath, ["scripts/configurePrerelease.mjs", "experimental", "package.json", "src/compiler/corePublic.ts"]);
548+
task("configure-experimental", configureExperimental);
549+
task("configure-experimental").description = "Runs scripts/configurePrerelease.mjs to prepare a build for experimental publishing";
564550

565551
const publishNightly = () => exec("npm", ["publish", "--tag", "next"]);
566552
task("publish-nightly", series(task("clean"), task("LKG"), task("clean"), task("runtests-parallel"), publishNightly));

0 commit comments

Comments
 (0)