@@ -140,14 +140,17 @@ function getCopyrightHeader() {
140
140
* @param {string } entrypoint
141
141
* @param {string } outfile
142
142
* @param {boolean } exportIsTsObject True if this file exports the TS object and should have relevant code injected.
143
+ * @param {boolean } performanceMatters True if this is a bundle where performance matters, so should be optimized at the cost of build time.
143
144
*/
144
- function esbuildTask ( entrypoint , outfile , exportIsTsObject = false ) {
145
+ function esbuildTask ( entrypoint , outfile , exportIsTsObject = false , performanceMatters = false ) {
146
+ const preBabel = `${ outfile } .tmp.js` ;
147
+
145
148
/** @type {esbuild.BuildOptions } */
146
149
const options = {
147
150
entryPoints : [ entrypoint ] ,
148
151
banner : { js : getCopyrightHeader ( ) } ,
149
152
bundle : true ,
150
- outfile,
153
+ outfile : performanceMatters ? preBabel : outfile ,
151
154
platform : "node" ,
152
155
// TODO: also specify minimal browser targets
153
156
target : "node10" , // Node 10 is the oldest benchmarker.
@@ -183,7 +186,15 @@ function esbuildTask(entrypoint, outfile, exportIsTsObject = false) {
183
186
}
184
187
185
188
return {
186
- build : ( ) => esbuild . build ( options ) ,
189
+ build : async ( ) => {
190
+ await esbuild . build ( options ) ;
191
+ if ( performanceMatters ) {
192
+ // TODO(jakebailey): we could use ts.transpileModule for this, but running babel is faster to get this singular transform.
193
+ // If we did use ts.transpileModule, we'd need ts.ScriptTarget.ES5, which also will downlevel arrow functions, for-of, spread, etc.
194
+ await exec ( process . execPath , [ "./node_modules/@babel/cli/bin/babel.js" , preBabel , "--out-file" , outfile , "--plugins" , "@babel/plugin-transform-block-scoping" , "--compact" , "false" , "--source-maps" ] ) ;
195
+ await del ( [ preBabel , `${ preBabel } .map` ] ) ;
196
+ }
197
+ } ,
187
198
clean : ( ) => del ( [ outfile , `${ outfile } .map` ] ) ,
188
199
watch : ( ) => esbuild . build ( { ...options , watch : true } ) ,
189
200
} ;
@@ -211,7 +222,7 @@ cleanTasks.push(cleanDebugTools);
211
222
const lkgPreBuild = parallel ( generateLibs , series ( buildScripts , generateDiagnostics , buildDebugTools ) ) ;
212
223
213
224
214
- const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true ) ;
225
+ const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
215
226
216
227
217
228
const buildTsc = ( ) => {
@@ -238,7 +249,7 @@ const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagno
238
249
// Pre-build steps to use based on supplied options.
239
250
const preBuild = cmdLineOptions . lkg ? lkgPreBuild : localPreBuild ;
240
251
241
- const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true ) ;
252
+ const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
242
253
243
254
// TODO(jakebailey): rename this; no longer "services".
244
255
const buildServices = ( ) => {
@@ -268,7 +279,7 @@ task("watch-services").flags = {
268
279
} ;
269
280
270
281
271
- const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true ) ;
282
+ const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
272
283
273
284
const buildServer = ( ) => {
274
285
if ( cmdLineOptions . bundle ) return esbuildServer . build ( ) ;
@@ -311,12 +322,7 @@ task("watch-min").flags = {
311
322
" --built" : "Compile using the built version of the compiler."
312
323
} ;
313
324
314
- const buildLssl = ( ( ) => {
315
- // TODO(jakebailey): fix this for modules
316
- return cb => {
317
- console . log ( "!!!TODO!!! buildLssl" ) ;
318
- cb ( ) ;
319
- } ;
325
+ const esbuildLssl = esbuildTask ( "./src/tsserverlibrary/tsserverlibrary.ts" , "./built/local/tsserverlibrary.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
320
326
321
327
const buildLssl = ( ) => {
322
328
if ( cmdLineOptions . bundle ) return esbuildLssl . build ( ) ;
0 commit comments