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 ;
@@ -309,17 +308,8 @@ task("clean-tests").description = "Cleans the outputs for the test infrastructur
309308
310309const watchTests = ( ) => watchProject ( "src/testRunner" , cmdLineOptions ) ;
311310
312- const buildEslintRules = ( ) => buildProject ( "scripts/eslint" ) ;
313- task ( "build-eslint-rules" , buildEslintRules ) ;
314- task ( "build-eslint-rules" ) . description = "Compiles eslint rules to js" ;
315-
316- const cleanEslintRules = ( ) => cleanProject ( "scripts/eslint" ) ;
317- cleanTasks . push ( cleanEslintRules ) ;
318- task ( "clean-eslint-rules" , cleanEslintRules ) ;
319- task ( "clean-eslint-rules" ) . description = "Cleans the outputs for the eslint rules" ;
320-
321- const runEslintRulesTests = ( ) => runConsoleTests ( "scripts/eslint/built/tests" , "mocha-fivemat-progress-reporter" , /*runInParallel*/ false , /*watchMode*/ false ) ;
322- task ( "run-eslint-rules-tests" , series ( buildEslintRules , runEslintRulesTests ) ) ;
311+ const runEslintRulesTests = ( ) => runConsoleTests ( "scripts/eslint/tests" , "mocha-fivemat-progress-reporter" , /*runInParallel*/ false , /*watchMode*/ false ) ;
312+ task ( "run-eslint-rules-tests" , runEslintRulesTests ) ;
323313task ( "run-eslint-rules-tests" ) . description = "Runs the eslint rule tests" ;
324314
325315/** @type { (folder: string) => { (): Promise<any>; displayName?: string } } */
@@ -433,8 +423,8 @@ task("runtests-parallel").flags = {
433423} ;
434424
435425
436- task ( "test-browser-integration" , ( ) => exec ( process . execPath , [ "scripts/browserIntegrationTest.js " ] ) ) ;
437- task ( "test-browser-integration" ) . description = "Runs scripts/browserIntegrationTest.ts which tests that typescript.js loads in a browser" ;
426+ task ( "test-browser-integration" , ( ) => exec ( process . execPath , [ "scripts/browserIntegrationTest.mjs " ] ) ) ;
427+ task ( "test-browser-integration" ) . description = "Runs scripts/browserIntegrationTest.mjs which tests that typescript.js loads in a browser" ;
438428
439429
440430task ( "diff" , ( ) => exec ( getDiffTool ( ) , [ refBaseline , localBaseline ] , { ignoreExitCode : true , waitForExit : false } ) ) ;
@@ -467,13 +457,9 @@ const updateSublime = () => src(["built/local/tsserver.js", "built/local/tsserve
467457task ( "update-sublime" , updateSublime ) ;
468458task ( "update-sublime" ) . description = "Updates the sublime plugin's tsserver" ;
469459
470- const buildImportDefinitelyTypedTests = ( ) => buildProject ( "scripts/importDefinitelyTypedTests" ) ;
471- const cleanImportDefinitelyTypedTests = ( ) => cleanProject ( "scripts/importDefinitelyTypedTests" ) ;
472- cleanTasks . push ( cleanImportDefinitelyTypedTests ) ;
473-
474460// TODO(rbuckton): Should the path to DefinitelyTyped be configurable via an environment variable?
475- const importDefinitelyTypedTests = ( ) => exec ( process . execPath , [ "scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js " , "./" , "../DefinitelyTyped" ] ) ;
476- task ( "importDefinitelyTypedTests" , series ( buildImportDefinitelyTypedTests , importDefinitelyTypedTests ) ) ;
461+ const importDefinitelyTypedTests = ( ) => exec ( process . execPath , [ "scripts/importDefinitelyTypedTests.mjs " , "./" , "../DefinitelyTyped" ] ) ;
462+ task ( "importDefinitelyTypedTests" , importDefinitelyTypedTests ) ;
477463task ( "importDefinitelyTypedTests" ) . description = "Runs the importDefinitelyTypedTests script to copy DT's tests to the TS-internal RWC tests" ;
478464
479465const buildReleaseTsc = ( ) => buildProject ( "src/tsc/tsconfig.release.json" ) ;
@@ -501,7 +487,7 @@ const produceLKG = async () => {
501487 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" ) ) ;
502488 }
503489 const sizeBefore = getDirSize ( "lib" ) ;
504- await exec ( process . execPath , [ "scripts/produceLKG.js " ] ) ;
490+ await exec ( process . execPath , [ "scripts/produceLKG.mjs " ] ) ;
505491 const sizeAfter = getDirSize ( "lib" ) ;
506492 if ( sizeAfter > ( sizeBefore * 1.10 ) ) {
507493 throw new Error ( "The lib folder increased by 10% or more. This likely indicates a bug." ) ;
@@ -515,24 +501,24 @@ task("LKG").flags = {
515501} ;
516502task ( "lkg" , series ( "LKG" ) ) ;
517503
518- const generateSpec = ( ) => exec ( "cscript" , [ "//nologo" , "scripts/word2md.js " , path . resolve ( "doc/TypeScript Language Specification - ARCHIVED.docx" ) , path . resolve ( "doc/spec-ARCHIVED.md" ) ] ) ;
519- task ( "generate-spec" , series ( buildScripts , generateSpec ) ) ;
504+ const generateSpec = ( ) => exec ( "cscript" , [ "//nologo" , "scripts/word2md.mjs " , path . resolve ( "doc/TypeScript Language Specification - ARCHIVED.docx" ) , path . resolve ( "doc/spec-ARCHIVED.md" ) ] ) ;
505+ task ( "generate-spec" , generateSpec ) ;
520506task ( "generate-spec" ) . description = "Generates a Markdown version of the Language Specification" ;
521507
522508task ( "clean" , series ( parallel ( cleanTasks ) , cleanBuilt ) ) ;
523509task ( "clean" ) . description = "Cleans build outputs" ;
524510
525- const configureNightly = ( ) => exec ( process . execPath , [ "scripts/configurePrerelease.js " , "dev" , "package.json" , "src/compiler/corePublic.ts" ] ) ;
511+ const configureNightly = ( ) => exec ( process . execPath , [ "scripts/configurePrerelease.mjs " , "dev" , "package.json" , "src/compiler/corePublic.ts" ] ) ;
526512task ( "configure-nightly" , series ( buildScripts , configureNightly ) ) ;
527513task ( "configure-nightly" ) . description = "Runs scripts/configurePrerelease.ts to prepare a build for nightly publishing" ;
528514
529- const configureInsiders = ( ) => exec ( process . execPath , [ "scripts/configurePrerelease.js " , "insiders" , "package.json" , "src/compiler/corePublic.ts" ] ) ;
530- task ( "configure-insiders" , series ( buildScripts , configureInsiders ) ) ;
531- task ( "configure-insiders" ) . description = "Runs scripts/configurePrerelease.ts to prepare a build for insiders publishing" ;
515+ const configureInsiders = ( ) => exec ( process . execPath , [ "scripts/configurePrerelease.mjs " , "insiders" , "package.json" , "src/compiler/corePublic.ts" ] ) ;
516+ task ( "configure-insiders" , configureInsiders ) ;
517+ task ( "configure-insiders" ) . description = "Runs scripts/configurePrerelease.mjs to prepare a build for insiders publishing" ;
532518
533- const configureExperimental = ( ) => exec ( process . execPath , [ "scripts/configurePrerelease.js " , "experimental" , "package.json" , "src/compiler/corePublic.ts" ] ) ;
534- task ( "configure-experimental" , series ( buildScripts , configureExperimental ) ) ;
535- task ( "configure-experimental" ) . description = "Runs scripts/configurePrerelease.ts to prepare a build for experimental publishing" ;
519+ const configureExperimental = ( ) => exec ( process . execPath , [ "scripts/configurePrerelease.mjs " , "experimental" , "package.json" , "src/compiler/corePublic.ts" ] ) ;
520+ task ( "configure-experimental" , configureExperimental ) ;
521+ task ( "configure-experimental" ) . description = "Runs scripts/configurePrerelease.mjs to prepare a build for experimental publishing" ;
536522
537523const publishNightly = ( ) => exec ( "npm" , [ "publish" , "--tag" , "next" ] ) ;
538524task ( "publish-nightly" , series ( task ( "clean" ) , task ( "LKG" ) , task ( "clean" ) , task ( "runtests-parallel" ) , publishNightly ) ) ;
0 commit comments