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
1921const copyright = "CopyrightNotice.txt" ;
2022const cleanTasks = [ ] ;
@@ -23,9 +25,6 @@ const buildScripts = () => buildProject("scripts");
2325task ( "scripts" , buildScripts ) ;
2426task ( "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>; } } */
3029const libraries = readJson ( "./src/lib/libs.json" ) ;
3130const libs = libraries . libs . map ( lib => {
@@ -56,10 +55,10 @@ const diagnosticMessagesJson = "src/compiler/diagnosticMessages.json";
5655const diagnosticMessagesGeneratedJson = "src/compiler/diagnosticMessages.generated.json" ;
5756const 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 ) ;
6362task ( "generate-diagnostics" ) . description = "Generates a diagnostic file in TypeScript based on an input JSON file" ;
6463
6564const cleanDiagnostics = ( ) => del ( [ diagnosticInformationMapTs , diagnosticMessagesGeneratedJson ] ) ;
@@ -88,7 +87,7 @@ const localizationTargets = ["cs", "de", "es", "fr", "it", "ja", "ko", "pl", "pt
8887
8988const 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");
9796cleanTasks . 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
102101const buildTsc = ( ) => buildProject ( "src/tsc" ) ;
103102task ( "tsc" , series ( lkgPreBuild , buildTsc ) ) ;
@@ -113,7 +112,7 @@ task("watch-tsc", series(lkgPreBuild, parallel(watchLib, watchDiagnostics, watch
113112task ( "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.
119118const preBuild = cmdLineOptions . lkg ? lkgPreBuild : localPreBuild ;
@@ -335,17 +334,8 @@ task("clean-tests").description = "Cleans the outputs for the test infrastructur
335334
336335const 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 ) ;
349339task ( "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
466456task ( "diff" , ( ) => exec ( getDiffTool ( ) , [ refBaseline , localBaseline ] , { ignoreExitCode : true , waitForExit : false } ) ) ;
@@ -493,13 +483,9 @@ const updateSublime = () => src(["built/local/tsserver.js", "built/local/tsserve
493483task ( "update-sublime" , updateSublime ) ;
494484task ( "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 ) ;
503489task ( "importDefinitelyTypedTests" ) . description = "Runs the importDefinitelyTypedTests script to copy DT's tests to the TS-internal RWC tests" ;
504490
505491const 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} ;
544530task ( "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 ) ;
548534task ( "generate-spec" ) . description = "Generates a Markdown version of the Language Specification" ;
549535
550536task ( "clean" , series ( parallel ( cleanTasks ) , cleanBuilt ) ) ;
@@ -554,13 +540,13 @@ const configureNightly = () => exec(process.execPath, ["scripts/configurePrerele
554540task ( "configure-nightly" , series ( buildScripts , configureNightly ) ) ;
555541task ( "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
565551const publishNightly = ( ) => exec ( "npm" , [ "publish" , "--tag" , "next" ] ) ;
566552task ( "publish-nightly" , series ( task ( "clean" ) , task ( "LKG" ) , task ( "clean" ) , task ( "runtests-parallel" ) , publishNightly ) ) ;
0 commit comments