@@ -22,6 +22,7 @@ const through2 = require("through2");
22
22
const merge2 = require ( "merge2" ) ;
23
23
const os = require ( "os" ) ;
24
24
const fold = require ( "travis-fold" ) ;
25
+ const ts = require ( "./lib/typescript" ) ;
25
26
const gulp = helpMaker ( originalGulp ) ;
26
27
27
28
Error . stackTraceLimit = 1000 ;
@@ -66,10 +67,10 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
66
67
67
68
const noop = ( ) => { } ; // tslint:disable-line no-empty
68
69
/**
69
- * @param {string } cmd
70
- * @param {string[] } args
71
- * @param {() => void } complete
72
- * @param {(e: *, status: number) => void } error
70
+ * @param {string } cmd
71
+ * @param {string[] } args
72
+ * @param {() => void } complete
73
+ * @param {(e: *, status: number) => void } error
73
74
*/
74
75
function exec ( cmd , args , complete = noop , error = noop ) {
75
76
console . log ( `${ cmd } ${ args . join ( " " ) } ` ) ;
@@ -82,12 +83,42 @@ function exec(cmd, args, complete = noop, error = noop) {
82
83
}
83
84
84
85
/**
85
- * @param {string } cmd
86
+ * @param {string } cmd
86
87
*/
87
88
function possiblyQuote ( cmd ) {
88
89
return cmd . indexOf ( " " ) >= 0 ? `"${ cmd } "` : cmd ;
89
90
}
90
91
92
+ /**
93
+ * @param diagnostics {ts.Diagnostic[]}
94
+ * @param [pretty] {boolean}
95
+ */
96
+ function diagnosticsToString ( diagnostics , pretty ) {
97
+ const host = {
98
+ getCurrentDirectory ( ) { return process . cwd ( ) ; } ,
99
+ getCanonicalFileName ( fileName ) { return fileName ; } ,
100
+ getNewLine ( ) { return os . EOL ; }
101
+ } ;
102
+ return pretty ? ts . formatDiagnosticsWithColorAndContext ( diagnostics , host ) :
103
+ ts . formatDiagnostics ( diagnostics , host ) ;
104
+ }
105
+
106
+ /** @param diagnostics {ts.Diagnostic[]} */
107
+ function reportDiagnostics ( diagnostics ) {
108
+ console . log ( diagnosticsToString ( diagnostics , process . stdout . isTTY ) ) ;
109
+ }
110
+
111
+ /** @param jsonPath {string} */
112
+ function readJson ( jsonPath ) {
113
+ const jsonText = fs . readFileSync ( jsonPath , "utf8" ) ;
114
+ const result = ts . parseConfigFileTextToJson ( jsonPath , jsonText ) ;
115
+ if ( result . error ) {
116
+ reportDiagnostics ( [ result . error ] ) ;
117
+ throw new Error ( "An error occurred during parse." ) ;
118
+ }
119
+ return result . config ;
120
+ }
121
+
91
122
let useDebugMode = true ;
92
123
let host = cmdLineOptions . host ;
93
124
@@ -113,81 +144,8 @@ const nodeModulesPathPrefix = path.resolve("./node_modules/.bin/");
113
144
const isWin = / ^ w i n / . test ( process . platform ) ;
114
145
const mocha = path . join ( nodeModulesPathPrefix , "mocha" ) + ( isWin ? ".cmd" : "" ) ;
115
146
116
- const es2015LibrarySources = [
117
- "es2015.core.d.ts" ,
118
- "es2015.collection.d.ts" ,
119
- "es2015.generator.d.ts" ,
120
- "es2015.iterable.d.ts" ,
121
- "es2015.promise.d.ts" ,
122
- "es2015.proxy.d.ts" ,
123
- "es2015.reflect.d.ts" ,
124
- "es2015.symbol.d.ts" ,
125
- "es2015.symbol.wellknown.d.ts"
126
- ] ;
127
-
128
- const es2015LibrarySourceMap = es2015LibrarySources . map ( source =>
129
- ( { target : "lib." + source , sources : [ "header.d.ts" , source ] } ) ) ;
130
-
131
- const es2016LibrarySource = [ "es2016.array.include.d.ts" ] ;
132
-
133
- const es2016LibrarySourceMap = es2016LibrarySource . map ( source =>
134
- ( { target : "lib." + source , sources : [ "header.d.ts" , source ] } ) ) ;
135
-
136
- const es2017LibrarySource = [
137
- "es2017.object.d.ts" ,
138
- "es2017.sharedmemory.d.ts" ,
139
- "es2017.string.d.ts" ,
140
- "es2017.intl.d.ts" ,
141
- "es2017.typedarrays.d.ts" ,
142
- ] ;
143
-
144
- const es2017LibrarySourceMap = es2017LibrarySource . map ( source =>
145
- ( { target : "lib." + source , sources : [ "header.d.ts" , source ] } ) ) ;
146
-
147
- const es2018LibrarySource = [
148
- "es2018.regexp.d.ts" ,
149
- "es2018.promise.d.ts" ,
150
- "es2018.intl.d.ts"
151
- ] ;
152
- const es2018LibrarySourceMap = es2018LibrarySource . map ( source =>
153
- ( { target : "lib." + source , sources : [ "header.d.ts" , source ] } ) ) ;
154
-
155
- const esnextLibrarySource = [
156
- "esnext.asynciterable.d.ts" ,
157
- "esnext.array.d.ts"
158
- ] ;
159
-
160
- const esnextLibrarySourceMap = esnextLibrarySource . map ( source =>
161
- ( { target : "lib." + source , sources : [ "header.d.ts" , source ] } ) ) ;
162
-
163
- const hostsLibrarySources = [ "dom.generated.d.ts" , "webworker.importscripts.d.ts" , "scripthost.d.ts" ] ;
164
-
165
- const librarySourceMap = [
166
- // Host library
167
- { target : "lib.dom.d.ts" , sources : [ "header.d.ts" , "dom.generated.d.ts" ] } ,
168
- { target : "lib.dom.iterable.d.ts" , sources : [ "header.d.ts" , "dom.iterable.d.ts" ] } ,
169
- { target : "lib.webworker.d.ts" , sources : [ "header.d.ts" , "webworker.generated.d.ts" ] } ,
170
- { target : "lib.scripthost.d.ts" , sources : [ "header.d.ts" , "scripthost.d.ts" ] } ,
171
-
172
- // JavaScript library
173
- { target : "lib.es5.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] } ,
174
- { target : "lib.es2015.d.ts" , sources : [ "header.d.ts" , "es2015.d.ts" ] } ,
175
- { target : "lib.es2016.d.ts" , sources : [ "header.d.ts" , "es2016.d.ts" ] } ,
176
- { target : "lib.es2017.d.ts" , sources : [ "header.d.ts" , "es2017.d.ts" ] } ,
177
- { target : "lib.es2018.d.ts" , sources : [ "header.d.ts" , "es2018.d.ts" ] } ,
178
- { target : "lib.esnext.d.ts" , sources : [ "header.d.ts" , "esnext.d.ts" ] } ,
179
-
180
- // JavaScript + all host library
181
- { target : "lib.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] . concat ( hostsLibrarySources ) } ,
182
- { target : "lib.es6.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] . concat ( es2015LibrarySources , hostsLibrarySources , "dom.iterable.d.ts" ) } ,
183
- { target : "lib.es2016.full.d.ts" , sources : [ "header.d.ts" , "es2016.d.ts" ] . concat ( hostsLibrarySources , "dom.iterable.d.ts" ) } ,
184
- { target : "lib.es2017.full.d.ts" , sources : [ "header.d.ts" , "es2017.d.ts" ] . concat ( hostsLibrarySources , "dom.iterable.d.ts" ) } ,
185
- { target : "lib.es2018.full.d.ts" , sources : [ "header.d.ts" , "es2018.d.ts" ] . concat ( hostsLibrarySources , "dom.iterable.d.ts" ) } ,
186
- { target : "lib.esnext.full.d.ts" , sources : [ "header.d.ts" , "esnext.d.ts" ] . concat ( hostsLibrarySources , "dom.iterable.d.ts" ) } ,
187
- ] . concat ( es2015LibrarySourceMap , es2016LibrarySourceMap , es2017LibrarySourceMap , es2018LibrarySourceMap , esnextLibrarySourceMap ) ;
188
-
189
- const libraryTargets = librarySourceMap . map ( f =>
190
- path . join ( builtLocalDirectory , f . target ) ) ;
147
+ /** @type {{ libs: string[], paths?: Record<string, string>, sources?: Record<string, string[]> } } */
148
+ const libraries = readJson ( "./src/lib/libs.json" ) ;
191
149
192
150
/**
193
151
* .lcg file is what localization team uses to know what messages to localize.
@@ -206,25 +164,27 @@ const localizationTargets = ["cs", "de", "es", "fr", "it", "ja", "ko", "pl", "pt
206
164
. map ( f => path . join ( builtLocalDirectory , f , "diagnosticMessages.generated.json" ) )
207
165
. concat ( generatedLCGFile ) ;
208
166
209
- for ( const i in libraryTargets ) {
210
- const entry = librarySourceMap [ i ] ;
211
- const target = libraryTargets [ i ] ;
212
- const sources = [ copyright ] . concat ( entry . sources . map ( s => path . join ( libraryDirectory , s ) ) ) ;
167
+ const libraryTargets = libraries . libs . map ( lib => {
168
+ const relativeSources = [ "header.d.ts" ] . concat ( libraries . sources && libraries . sources [ lib ] || [ lib + ".d.ts" ] ) ;
169
+ const relativeTarget = libraries . paths && libraries . paths [ lib ] || ( "lib." + lib + ".d.ts" ) ;
170
+ const sources = [ copyright ] . concat ( relativeSources . map ( s => path . join ( libraryDirectory , s ) ) ) ;
171
+ const target = path . join ( builtLocalDirectory , relativeTarget ) ;
213
172
gulp . task ( target , /*help*/ false , [ ] , ( ) =>
214
173
gulp . src ( sources )
215
174
. pipe ( newer ( target ) )
216
175
. pipe ( concat ( target , { newLine : "\n\n" } ) )
217
176
. pipe ( gulp . dest ( "." ) ) ) ;
218
- }
177
+ return target ;
178
+ } ) ;
219
179
220
180
const configurePreleleaseJs = path . join ( scriptsDirectory , "configurePrerelease.js" ) ;
221
181
const configurePreleleaseTs = path . join ( scriptsDirectory , "configurePrerelease.ts" ) ;
222
182
const packageJson = "package.json" ;
223
183
const versionFile = path . join ( compilerDirectory , "core.ts" ) ;
224
184
225
185
/**
226
- * @param {string | string[] } source
227
- * @param {string | string[] } dest
186
+ * @param {string | string[] } source
187
+ * @param {string | string[] } dest
228
188
* @returns {boolean }
229
189
*/
230
190
function needsUpdate ( source , dest ) {
@@ -291,7 +251,7 @@ function needsUpdate(source, dest) {
291
251
}
292
252
293
253
/**
294
- * @param {tsc.Settings } base
254
+ * @param {tsc.Settings } base
295
255
* @param {boolean= } useBuiltCompiler
296
256
* @returns {tsc.Settings }
297
257
*/
@@ -443,7 +403,7 @@ const nodeStandaloneDefinitionsFile = path.join(builtLocalDirectory, "typescript
443
403
/** @type {string } */
444
404
let copyrightContent ;
445
405
/**
446
- * @param {boolean } outputCopyright
406
+ * @param {boolean } outputCopyright
447
407
*/
448
408
function prependCopyright ( outputCopyright = ! useDebugMode ) {
449
409
return insert . prepend ( outputCopyright ? ( copyrightContent || ( copyrightContent = fs . readFileSync ( copyright ) . toString ( ) ) ) : "" ) ;
@@ -667,9 +627,9 @@ function restoreSavedNodeEnv() {
667
627
}
668
628
669
629
/**
670
- * @param {string } defaultReporter
671
- * @param {boolean } runInParallel
672
- * @param {(e?: any) => void } done
630
+ * @param {string } defaultReporter
631
+ * @param {boolean } runInParallel
632
+ * @param {(e?: any) => void } done
673
633
*/
674
634
function runConsoleTests ( defaultReporter , runInParallel , done ) {
675
635
const lintFlag = cmdLineOptions . lint ;
@@ -747,8 +707,8 @@ function runConsoleTests(defaultReporter, runInParallel, done) {
747
707
} ) ;
748
708
749
709
/**
750
- * @param {any= } err
751
- * @param {number= } status
710
+ * @param {any= } err
711
+ * @param {number= } status
752
712
*/
753
713
function failWithStatus ( err , status ) {
754
714
if ( err || status ) {
@@ -767,8 +727,8 @@ function runConsoleTests(defaultReporter, runInParallel, done) {
767
727
}
768
728
769
729
/**
770
- * @param {any= } error
771
- * @param {number= } errorStatus
730
+ * @param {any= } error
731
+ * @param {number= } errorStatus
772
732
*/
773
733
function finish ( error , errorStatus ) {
774
734
restoreSavedNodeEnv ( ) ;
@@ -886,7 +846,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
886
846
} ) ;
887
847
888
848
/**
889
- * @param {(e?: any) => void } done
849
+ * @param {(e?: any) => void } done
890
850
*/
891
851
function cleanTestDirs ( done ) {
892
852
// Clean the local baselines & Rwc baselines directories
@@ -906,13 +866,13 @@ function cleanTestDirs(done) {
906
866
907
867
/**
908
868
* used to pass data from jake command line directly to run.js
909
- * @param {string } tests
910
- * @param {string } runners
911
- * @param {boolean } light
912
- * @param {string= } taskConfigsFolder
913
- * @param {number= } workerCount
914
- * @param {string= } stackTraceLimit
915
- * @param {number= } timeout
869
+ * @param {string } tests
870
+ * @param {string } runners
871
+ * @param {boolean } light
872
+ * @param {string= } taskConfigsFolder
873
+ * @param {number= } workerCount
874
+ * @param {string= } stackTraceLimit
875
+ * @param {number= } timeout
916
876
*/
917
877
function writeTestConfigFile ( tests , runners , light , taskConfigsFolder , workerCount , stackTraceLimit , timeout ) {
918
878
const testConfigContents = JSON . stringify ( {
0 commit comments