@@ -19,7 +19,8 @@ const copyright = "CopyrightNotice.txt";
1919const cleanTasks = [ ] ;
2020
2121
22- // TODO(jakebailey): This is really gross. Waiting on: https://github.com/microsoft/TypeScript/issues/25613
22+ // TODO(jakebailey): This is really gross. Waiting on https://github.com/microsoft/TypeScript/issues/25613,
23+ // or at least control over noEmit / emitDeclarationOnly in build mode.
2324let currentlyBuilding = 0 ;
2425let oldTsconfigBase ;
2526
@@ -123,8 +124,7 @@ const localize = async () => {
123124const preSrc = parallel ( generateLibs , series ( buildScripts , generateDiagnostics , localize ) ) ;
124125const buildSrc = ( ) => buildProject ( "src" ) ;
125126
126- // TODO(jakebailey): when should we run this? it's nice to have tests run quickly, but we also want to know if the code is broken.
127- // But, if we are bundling, we are running only d.ts emit, so maybe this is fast?
127+ // TODO(jakebailey): add a variant of this that runs on ./built/local/tsc, with noEmit, for post-test verification.
128128task ( "build-src" , series ( preSrc , buildSrc ) ) ;
129129
130130/**
@@ -168,18 +168,16 @@ function esbuildTask(entrypoint, outfile, exportIsTsObject = false, performanceM
168168 bundle : true ,
169169 outfile : performanceMatters ? preBabel : outfile ,
170170 platform : "node" ,
171- // TODO: also specify minimal browser targets
172- target : "node10" , // Node 10 is the oldest benchmarker.
171+ target : "es2018" , // This covers Node 10.
173172 format : "cjs" ,
174173 sourcemap : true ,
175- external : [ "./node_modules/*" ] , // TODO(jakebailey): does the test runner import relatively from scripts?
174+ external : [ "./node_modules/*" ] ,
176175 conditions : [ "require" ] ,
177176 supported : {
178- // "const-and-let": false, // Unfortunately, no: https://github.com/evanw/esbuild/issues/297
179- "object-rest-spread" : false , // See : https://github.com/evanw/esbuild/releases/tag/v0.14.46
177+ // "const-and-let": false, // https://github.com/evanw/esbuild/issues/297
178+ "object-rest-spread" : false , // Performance enhancement, see : https://github.com/evanw/esbuild/releases/tag/v0.14.46
180179 } ,
181- // legalComments: "none", // TODO(jakebailey): enable once we add copyright headers to our source files.
182- // logLevel: "info",
180+ // legalComments: "none", // If we add copyright headers to the source files, uncomment.
183181 } ;
184182
185183 if ( exportIsTsObject ) {
@@ -239,11 +237,12 @@ const lkgPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnost
239237
240238
241239const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
240+ const writeTscCJSShim = ( ) => writeCJSReexport ( "./built/local/tsc/tsc.js" , "./built/local/tsc.js" ) ;
242241
243242
244243const buildTsc = ( ) => {
245244 if ( cmdLineOptions . bundle ) return esbuildTsc . build ( ) ;
246- writeCJSReexport ( "./built/local/tsc/tsc.js" , "./built/local/tsc.js" ) ;
245+ writeTscCJSShim ( ) ;
247246 return buildProject ( "src/tsc" ) ;
248247} ;
249248task ( "tsc" , series ( lkgPreBuild , buildTsc ) ) ;
@@ -254,8 +253,11 @@ cleanTasks.push(cleanTsc);
254253task ( "clean-tsc" , cleanTsc ) ;
255254task ( "clean-tsc" ) . description = "Cleans outputs for the command-line compiler" ;
256255
257- // TODO(jakebailey): watch mode doesn't mix with --bundle=false.
258- const watchTsc = ( ) => cmdLineOptions . bundle ? esbuildTsc . watch ( ) : watchProject ( "src/tsc" ) ;
256+ const watchTsc = ( ) => {
257+ if ( cmdLineOptions . bundle ) return esbuildTsc . watch ( ) ;
258+ writeTscCJSShim ( ) ;
259+ return watchProject ( "src/tsc" ) ;
260+ } ;
259261task ( "watch-tsc" , series ( lkgPreBuild , parallel ( watchLib , watchDiagnostics , watchTsc ) ) ) ;
260262task ( "watch-tsc" ) . description = "Watch for changes and rebuild the command-line compiler only." ;
261263
@@ -265,15 +267,15 @@ const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagno
265267// Pre-build steps to use based on supplied options.
266268const preBuild = cmdLineOptions . lkg ? lkgPreBuild : localPreBuild ;
267269
268- const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
269-
270270// TODO(jakebailey): rename this; no longer "services".
271271
272+ const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
273+ const writeServicesCJSShim = ( ) => writeCJSReexport ( "./built/local/typescript/typescript.js" , "./built/local/typescript.js" ) ;
272274const buildServicesProject = ( ) => buildProject ( "src/typescript" ) ;
273275
274276const buildServices = ( ) => {
275277 if ( cmdLineOptions . bundle ) return esbuildServices . build ( ) ;
276- writeCJSReexport ( "./built/local/typescript/typescript.js" , "./built/local/typescript.js" ) ;
278+ writeServicesCJSShim ( ) ;
277279 return buildServicesProject ( ) ;
278280} ;
279281
@@ -289,8 +291,11 @@ cleanTasks.push(cleanServices);
289291task ( "clean-services" , cleanServices ) ;
290292task ( "clean-services" ) . description = "Cleans outputs for the language service" ;
291293
292- // TODO(jakebailey): watch mode doesn't mix with --bundle=false.
293- const watchServices = ( ) => cmdLineOptions . bundle ? esbuildServices . watch ( ) : watchProject ( "src/typescript" ) ;
294+ const watchServices = ( ) => {
295+ if ( cmdLineOptions . bundle ) return esbuildServices . watch ( ) ;
296+ writeServicesCJSShim ( ) ;
297+ return watchProject ( "src/typescript" ) ;
298+ } ;
294299task ( "watch-services" , series ( preBuild , parallel ( watchLib , watchDiagnostics , watchServices ) ) ) ;
295300task ( "watch-services" ) . description = "Watches for changes and rebuild language service only" ;
296301task ( "watch-services" ) . flags = {
@@ -302,10 +307,11 @@ task("dts-services", series(preBuild, buildServicesProject, dtsServices));
302307task ( "dts-services" ) . description = "Builds typescript.d.ts" ;
303308
304309const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
310+ const writeServerCJSShim = ( ) => writeCJSReexport ( "./built/local/tsserver/server.js" , "./built/local/tsserver.js" ) ;
305311
306312const buildServer = ( ) => {
307313 if ( cmdLineOptions . bundle ) return esbuildServer . build ( ) ;
308- writeCJSReexport ( "./built/local/tsserver/server.js" , "./built/local/tsserver.js" ) ;
314+ writeServerCJSShim ( ) ;
309315 return buildProject ( "src/tsserver" ) ;
310316} ;
311317buildServer . displayName = "buildServer" ;
@@ -321,8 +327,11 @@ cleanTasks.push(cleanServer);
321327task ( "clean-tsserver" , cleanServer ) ;
322328task ( "clean-tsserver" ) . description = "Cleans outputs for the language server" ;
323329
324- // TODO(jakebailey): watch mode doesn't mix with --bundle=false.
325- const watchServer = ( ) => cmdLineOptions . bundle ? esbuildServer . watch ( ) : watchProject ( "src/tsserver" ) ;
330+ const watchServer = ( ) => {
331+ if ( cmdLineOptions . bundle ) return esbuildServer . watch ( ) ;
332+ writeServerCJSShim ( ) ;
333+ return watchProject ( "src/tsserver" ) ;
334+ } ;
326335task ( "watch-tsserver" , series ( preBuild , parallel ( watchLib , watchDiagnostics , watchServer ) ) ) ;
327336task ( "watch-tsserver" ) . description = "Watch for changes and rebuild the language server only" ;
328337task ( "watch-tsserver" ) . flags = {
@@ -345,11 +354,12 @@ task("watch-min").flags = {
345354} ;
346355
347356const esbuildLssl = esbuildTask ( "./src/tsserverlibrary/tsserverlibrary.ts" , "./built/local/tsserverlibrary.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
357+ const writeLsslCJSShim = ( ) => writeCJSReexport ( "./built/local/tsserverlibrary/tsserverlibrary.js" , "./built/local/tsserverlibrary.js" ) ;
348358
349359const buildLsslProject = ( ) => buildProject ( "src/tsserverlibrary" ) ;
350360const buildLssl = ( ) => {
351361 if ( cmdLineOptions . bundle ) return esbuildLssl . build ( ) ;
352- writeCJSReexport ( "./built/local/tsserverlibrary/tsserverlibrary.js" , "./built/local/tsserverlibrary.js" ) ;
362+ writeLsslCJSShim ( ) ;
353363 return buildLsslProject ( ) ;
354364} ;
355365task ( "lssl" , series ( preBuild , buildLssl ) ) ;
@@ -363,9 +373,11 @@ cleanTasks.push(cleanLssl);
363373task ( "clean-lssl" , cleanLssl ) ;
364374task ( "clean-lssl" ) . description = "Clean outputs for the language service server library" ;
365375
366- // TODO(jakebailey): watch mode doesn't mix with --bundle=false.
367- const watchLssl = ( ) => cmdLineOptions . bundle ? esbuildLssl . watch ( ) : watchProject ( "src/tsserverlibrary" ) ;
368-
376+ const watchLssl = ( ) => {
377+ if ( cmdLineOptions . bundle ) return esbuildLssl . watch ( ) ;
378+ writeLsslCJSShim ( ) ;
379+ return watchProject ( "src/tsserverlibrary" ) ;
380+ } ;
369381task ( "watch-lssl" , series ( preBuild , parallel ( watchLib , watchDiagnostics , watchLssl ) ) ) ;
370382task ( "watch-lssl" ) . description = "Watch for changes and rebuild tsserverlibrary only" ;
371383task ( "watch-lssl" ) . flags = {
@@ -382,10 +394,11 @@ task("dts", dts);
382394
383395const testRunner = "./built/local/run.js" ;
384396const esbuildTests = esbuildTask ( "./src/testRunner/_namespaces/Harness.ts" , testRunner ) ;
397+ const writeTestsCJSShim = ( ) => writeCJSReexport ( "./built/local/testRunner/runner.js" , testRunner ) ;
385398
386399const buildTests = ( ) => {
387400 if ( cmdLineOptions . bundle ) return esbuildTests . build ( ) ;
388- writeCJSReexport ( "./built/local/testRunner/runner.js" , testRunner ) ;
401+ writeTestsCJSShim ( ) ;
389402 return buildProject ( "src/testRunner" ) ;
390403} ;
391404task ( "tests" , series ( preBuild , parallel ( buildLssl , buildTests ) ) ) ;
@@ -399,8 +412,11 @@ cleanTasks.push(cleanTests);
399412task ( "clean-tests" , cleanTests ) ;
400413task ( "clean-tests" ) . description = "Cleans the outputs for the test infrastructure" ;
401414
402- // TODO(jakebailey): watch mode doesn't mix with --bundle=false.
403- const watchTests = ( ) => cmdLineOptions . bundle ? esbuildTests . watch ( ) : watchProject ( "src/testRunner" ) ;
415+ const watchTests = ( ) => {
416+ if ( cmdLineOptions . bundle ) return esbuildTests . watch ( ) ;
417+ writeTestsCJSShim ( ) ;
418+ return watchProject ( "src/testRunner" ) ;
419+ } ;
404420
405421const buildEslintRules = ( ) => buildProject ( "scripts/eslint" ) ;
406422task ( "build-eslint-rules" , buildEslintRules ) ;
@@ -452,7 +468,6 @@ const esbuildTypingsInstaller = esbuildTask("./src/typingsInstaller/nodeTypingsI
452468
453469const buildTypingsInstaller = ( ) => {
454470 if ( cmdLineOptions . bundle ) return esbuildTypingsInstaller . build ( ) ;
455- // TODO(jakebailey): In --bundle=false, can we emit to this directly?
456471 writeCJSReexport ( "./built/typingsInstaller/nodeTypingsInstaller.js" , "./built/local/typingsInstaller.js" ) ;
457472 return buildProject ( "src/typingsInstaller" ) ;
458473} ;
@@ -586,16 +601,19 @@ task("importDefinitelyTypedTests").description = "Runs the importDefinitelyTyped
586601const cleanBuilt = ( ) => del ( "built" ) ;
587602
588603const produceLKG = async ( ) => {
589- // TODO(jakebailey): there are probably more files here that are needed.
604+ if ( ! cmdLineOptions . bundle ) {
605+ throw new Error ( "LKG cannot be created when --bundle=false" ) ;
606+ }
607+
590608 const expectedFiles = [
609+ "built/local/cancellationToken.js" ,
591610 "built/local/tsc.js" ,
592611 "built/local/tsserver.js" ,
593- "built/local/typescript.js" ,
594- "built/local/typescript.d.ts" ,
595612 "built/local/tsserverlibrary.js" ,
596613 "built/local/tsserverlibrary.d.ts" ,
614+ "built/local/typescript.js" ,
615+ "built/local/typescript.d.ts" ,
597616 "built/local/typingsInstaller.js" ,
598- "built/local/cancellationToken.js" ,
599617 "built/local/watchGuard.js" ,
600618 ] . concat ( libs . map ( lib => lib . target ) ) ;
601619 const missingFiles = expectedFiles
@@ -626,8 +644,6 @@ task("generate-spec").description = "Generates a Markdown version of the Languag
626644task ( "clean" , series ( parallel ( cleanTasks ) , cleanBuilt ) ) ;
627645task ( "clean" ) . description = "Cleans build outputs" ;
628646
629- // TODO(jakebailey): Figure out what needs to change below.
630-
631647const configureNightly = ( ) => exec ( process . execPath , [ "scripts/configurePrerelease.js" , "dev" , "package.json" , "src/compiler/corePublic.ts" ] ) ;
632648task ( "configure-nightly" , series ( buildScripts , configureNightly ) ) ;
633649task ( "configure-nightly" ) . description = "Runs scripts/configurePrerelease.ts to prepare a build for nightly publishing" ;
0 commit comments