@@ -35,21 +35,22 @@ export const buildScripts = task({
35
35
run : ( ) => buildProject ( "scripts" )
36
36
} ) ;
37
37
38
+ const libsJson = "src/lib/libs.json" ;
39
+ const libsGenerated = "src/compiler/libs.generated.ts" ;
40
+
38
41
const libs = memoize ( ( ) => {
39
42
/** @type {{ libs: string[]; paths: Record<string, string | undefined>; } } */
40
- const libraries = readJson ( "./src/lib/libs.json" ) ;
43
+ const libraries = readJson ( libsJson ) ;
41
44
const libs = libraries . libs . map ( lib => {
42
45
const relativeSources = [ "header.d.ts" , lib + ".d.ts" ] ;
43
- const relativeTarget = libraries . paths && libraries . paths [ lib ] || ( "lib." + lib + ".d.ts" ) ;
46
+ const target = libraries . paths && libraries . paths [ lib ] || ( "lib." + lib + ".d.ts" ) ;
44
47
const sources = relativeSources . map ( s => path . posix . join ( "src/lib" , s ) ) ;
45
- const target = `built/local/${ relativeTarget } ` ;
46
48
return { target, sources } ;
47
49
} ) ;
48
50
return libs ;
49
51
} ) ;
50
52
51
-
52
- export const generateLibs = task ( {
53
+ export const lib = task ( {
53
54
name : "lib" ,
54
55
description : "Builds the library targets" ,
55
56
run : async ( ) => {
@@ -62,11 +63,41 @@ export const generateLibs = task({
62
63
output += "\n" + contents . replace ( / \r \n / g, "\n" ) ;
63
64
}
64
65
65
- await fs . promises . writeFile ( lib . target , output ) ;
66
+ await fs . promises . writeFile ( path . join ( "./built/local" , lib . target ) , output ) ;
67
+ }
68
+ } ,
69
+ } ) ;
70
+
71
+ export const generateLibs = task ( {
72
+ name : "generate-lib" ,
73
+ description : "Builds the library targets" ,
74
+ run : async ( ) => {
75
+ const libNames = libs ( ) . map ( lib => lib . target ) . sort ( ) ;
76
+ const result = [
77
+ "// <auto-generated />" ,
78
+ `// generated from '${ libsJson } '` ,
79
+ "" ,
80
+ "/** @internal */" ,
81
+ "export const allLibFiles: readonly string[] = [" ,
82
+ ] ;
83
+
84
+ for ( const name of libNames ) {
85
+ result . push ( ` ${ JSON . stringify ( name ) } ,` ) ;
66
86
}
87
+
88
+ result . push ( "];" ) ;
89
+
90
+ await fs . promises . writeFile ( libsGenerated , result . join ( "\r\n" ) ) ;
67
91
} ,
68
92
} ) ;
69
93
94
+ const cleanLib = task ( {
95
+ name : "clean-lib" ,
96
+ description : "Cleans generated lib files in src." ,
97
+ hiddenFromTaskList : true ,
98
+ run : ( ) => del ( [ libsGenerated ] ) ,
99
+ } ) ;
100
+
70
101
71
102
const diagnosticInformationMapTs = "src/compiler/diagnosticInformationMap.generated.ts" ;
72
103
const diagnosticMessagesJson = "src/compiler/diagnosticMessages.json" ;
@@ -82,11 +113,16 @@ export const generateDiagnostics = task({
82
113
83
114
const cleanDiagnostics = task ( {
84
115
name : "clean-diagnostics" ,
85
- description : "Generates a diagnostic file in TypeScript based on an input JSON file " ,
116
+ description : "Cleans generated diagnostic files in src. " ,
86
117
hiddenFromTaskList : true ,
87
118
run : ( ) => del ( [ diagnosticInformationMapTs , diagnosticMessagesGeneratedJson ] ) ,
88
119
} ) ;
89
120
121
+ export const generate = task ( {
122
+ name : "generate" ,
123
+ description : "Generate code for src." ,
124
+ dependencies : [ generateLibs , generateDiagnostics ] ,
125
+ } ) ;
90
126
91
127
// Localize diagnostics
92
128
/**
@@ -119,15 +155,15 @@ const localize = task({
119
155
export const buildSrc = task ( {
120
156
name : "build-src" ,
121
157
description : "Builds the src project (all code)" ,
122
- dependencies : [ generateDiagnostics ] ,
158
+ dependencies : [ generate ] ,
123
159
run : ( ) => buildProject ( "src" ) ,
124
160
} ) ;
125
161
126
162
export const watchSrc = task ( {
127
163
name : "watch-src" ,
128
164
description : "Watches the src project (all code)" ,
129
165
hiddenFromTaskList : true ,
130
- dependencies : [ generateDiagnostics ] ,
166
+ dependencies : [ generate ] ,
131
167
run : ( ) => watchProject ( "src" ) ,
132
168
} ) ;
133
169
@@ -341,25 +377,25 @@ function entrypointBuildTask(options) {
341
377
const { main : tsc , watch : watchTsc } = entrypointBuildTask ( {
342
378
name : "tsc" ,
343
379
description : "Builds the command-line compiler" ,
344
- buildDeps : [ generateDiagnostics ] ,
380
+ buildDeps : [ generate ] ,
345
381
project : "src/tsc" ,
346
382
srcEntrypoint : "./src/tsc/tsc.ts" ,
347
383
builtEntrypoint : "./built/local/tsc/tsc.js" ,
348
384
output : "./built/local/tsc.js" ,
349
- mainDeps : [ generateLibs ] ,
385
+ mainDeps : [ lib ] ,
350
386
} ) ;
351
387
export { tsc , watchTsc } ;
352
388
353
389
354
390
const { main : services , build : buildServices , watch : watchServices } = entrypointBuildTask ( {
355
391
name : "services" ,
356
392
description : "Builds the typescript.js library" ,
357
- buildDeps : [ generateDiagnostics ] ,
393
+ buildDeps : [ generate ] ,
358
394
project : "src/typescript" ,
359
395
srcEntrypoint : "./src/typescript/typescript.ts" ,
360
396
builtEntrypoint : "./built/local/typescript/typescript.js" ,
361
397
output : "./built/local/typescript.js" ,
362
- mainDeps : [ generateLibs ] ,
398
+ mainDeps : [ lib ] ,
363
399
bundlerOptions : { exportIsTsObject : true } ,
364
400
} ) ;
365
401
export { services , watchServices } ;
@@ -379,12 +415,12 @@ export const dtsServices = task({
379
415
const { main : tsserver , watch : watchTsserver } = entrypointBuildTask ( {
380
416
name : "tsserver" ,
381
417
description : "Builds the language server" ,
382
- buildDeps : [ generateDiagnostics ] ,
418
+ buildDeps : [ generate ] ,
383
419
project : "src/tsserver" ,
384
420
srcEntrypoint : "./src/tsserver/server.ts" ,
385
421
builtEntrypoint : "./built/local/tsserver/server.js" ,
386
422
output : "./built/local/tsserver.js" ,
387
- mainDeps : [ generateLibs ] ,
423
+ mainDeps : [ lib ] ,
388
424
} ) ;
389
425
export { tsserver , watchTsserver } ;
390
426
@@ -407,12 +443,12 @@ export const watchMin = task({
407
443
const { main : lssl , build : buildLssl , watch : watchLssl } = entrypointBuildTask ( {
408
444
name : "lssl" ,
409
445
description : "Builds language service server library" ,
410
- buildDeps : [ generateDiagnostics ] ,
446
+ buildDeps : [ generate ] ,
411
447
project : "src/tsserverlibrary" ,
412
448
srcEntrypoint : "./src/tsserverlibrary/tsserverlibrary.ts" ,
413
449
builtEntrypoint : "./built/local/tsserverlibrary/tsserverlibrary.js" ,
414
450
output : "./built/local/tsserverlibrary.js" ,
415
- mainDeps : [ generateLibs ] ,
451
+ mainDeps : [ lib ] ,
416
452
bundlerOptions : { exportIsTsObject : true } ,
417
453
} ) ;
418
454
export { lssl , watchLssl } ;
@@ -439,12 +475,12 @@ const watchTestsEmitter = new EventEmitter();
439
475
const { main : tests , watch : watchTests } = entrypointBuildTask ( {
440
476
name : "tests" ,
441
477
description : "Builds the test infrastructure" ,
442
- buildDeps : [ generateDiagnostics ] ,
478
+ buildDeps : [ generate ] ,
443
479
project : "src/testRunner" ,
444
480
srcEntrypoint : "./src/testRunner/_namespaces/Harness.ts" ,
445
481
builtEntrypoint : "./built/local/testRunner/runner.js" ,
446
482
output : testRunner ,
447
- mainDeps : [ generateLibs ] ,
483
+ mainDeps : [ lib ] ,
448
484
bundlerOptions : {
449
485
// Ensure we never drop any dead code, which might be helpful while debugging.
450
486
treeShaking : false ,
@@ -496,7 +532,7 @@ const { main: cancellationToken, watch: watchCancellationToken } = entrypointBui
496
532
497
533
const { main : typingsInstaller , watch : watchTypingsInstaller } = entrypointBuildTask ( {
498
534
name : "typings-installer" ,
499
- buildDeps : [ generateDiagnostics ] ,
535
+ buildDeps : [ generate ] ,
500
536
project : "src/typingsInstaller" ,
501
537
srcEntrypoint : "./src/typingsInstaller/nodeTypingsInstaller.ts" ,
502
538
builtEntrypoint : "./built/local/typingsInstaller/nodeTypingsInstaller.js" ,
@@ -530,7 +566,7 @@ export const generateTypesMap = task({
530
566
const builtLocalDiagnosticMessagesGeneratedJson = "built/local/diagnosticMessages.generated.json" ;
531
567
const copyBuiltLocalDiagnosticMessages = task ( {
532
568
name : "copy-built-local-diagnostic-messages" ,
533
- dependencies : [ generateDiagnostics ] ,
569
+ dependencies : [ generate ] ,
534
570
run : async ( ) => {
535
571
const contents = await fs . promises . readFile ( diagnosticMessagesGeneratedJson , "utf-8" ) ;
536
572
JSON . parse ( contents ) ; // Validates that the JSON parses.
@@ -566,7 +602,7 @@ export const watchLocal = task({
566
602
dependencies : [ localize , watchTsc , watchTsserver , watchServices , watchLssl , watchOtherOutputs , dts , watchSrc ] ,
567
603
} ) ;
568
604
569
- const runtestsDeps = [ tests , generateLibs ] . concat ( cmdLineOptions . typecheck ? [ dts ] : [ ] ) ;
605
+ const runtestsDeps = [ tests , lib ] . concat ( cmdLineOptions . typecheck ? [ dts ] : [ ] ) ;
570
606
571
607
export const runTests = task ( {
572
608
name : "runtests" ,
@@ -852,7 +888,7 @@ export const cleanBuilt = task({
852
888
export const clean = task ( {
853
889
name : "clean" ,
854
890
description : "Cleans build outputs" ,
855
- dependencies : [ cleanBuilt , cleanDiagnostics ] ,
891
+ dependencies : [ cleanBuilt , cleanDiagnostics , cleanLib ] ,
856
892
} ) ;
857
893
858
894
export const configureNightly = task ( {
0 commit comments