@@ -22,6 +22,7 @@ const through2 = require("through2");
2222const merge2 = require ( "merge2" ) ;
2323const os = require ( "os" ) ;
2424const fold = require ( "travis-fold" ) ;
25+ const ts = require ( "./lib/typescript" ) ;
2526const gulp = helpMaker ( originalGulp ) ;
2627
2728Error . stackTraceLimit = 1000 ;
@@ -66,10 +67,10 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
6667
6768const noop = ( ) => { } ; // tslint:disable-line no-empty
6869/**
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
7374 */
7475function exec ( cmd , args , complete = noop , error = noop ) {
7576 console . log ( `${ cmd } ${ args . join ( " " ) } ` ) ;
@@ -82,12 +83,42 @@ function exec(cmd, args, complete = noop, error = noop) {
8283}
8384
8485/**
85- * @param {string } cmd
86+ * @param {string } cmd
8687 */
8788function possiblyQuote ( cmd ) {
8889 return cmd . indexOf ( " " ) >= 0 ? `"${ cmd } "` : cmd ;
8990}
9091
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+
91122let useDebugMode = true ;
92123let host = cmdLineOptions . host ;
93124
@@ -113,81 +144,8 @@ const nodeModulesPathPrefix = path.resolve("./node_modules/.bin/");
113144const isWin = / ^ w i n / . test ( process . platform ) ;
114145const mocha = path . join ( nodeModulesPathPrefix , "mocha" ) + ( isWin ? ".cmd" : "" ) ;
115146
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" ) ;
191149
192150/**
193151 * .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
206164 . map ( f => path . join ( builtLocalDirectory , f , "diagnosticMessages.generated.json" ) )
207165 . concat ( generatedLCGFile ) ;
208166
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 ) ;
213172 gulp . task ( target , /*help*/ false , [ ] , ( ) =>
214173 gulp . src ( sources )
215174 . pipe ( newer ( target ) )
216175 . pipe ( concat ( target , { newLine : "\n\n" } ) )
217176 . pipe ( gulp . dest ( "." ) ) ) ;
218- }
177+ return target ;
178+ } ) ;
219179
220180const configurePreleleaseJs = path . join ( scriptsDirectory , "configurePrerelease.js" ) ;
221181const configurePreleleaseTs = path . join ( scriptsDirectory , "configurePrerelease.ts" ) ;
222182const packageJson = "package.json" ;
223183const versionFile = path . join ( compilerDirectory , "core.ts" ) ;
224184
225185/**
226- * @param {string | string[] } source
227- * @param {string | string[] } dest
186+ * @param {string | string[] } source
187+ * @param {string | string[] } dest
228188 * @returns {boolean }
229189 */
230190function needsUpdate ( source , dest ) {
@@ -291,7 +251,7 @@ function needsUpdate(source, dest) {
291251}
292252
293253/**
294- * @param {tsc.Settings } base
254+ * @param {tsc.Settings } base
295255 * @param {boolean= } useBuiltCompiler
296256 * @returns {tsc.Settings }
297257 */
@@ -443,7 +403,7 @@ const nodeStandaloneDefinitionsFile = path.join(builtLocalDirectory, "typescript
443403/** @type {string } */
444404let copyrightContent ;
445405/**
446- * @param {boolean } outputCopyright
406+ * @param {boolean } outputCopyright
447407 */
448408function prependCopyright ( outputCopyright = ! useDebugMode ) {
449409 return insert . prepend ( outputCopyright ? ( copyrightContent || ( copyrightContent = fs . readFileSync ( copyright ) . toString ( ) ) ) : "" ) ;
@@ -667,9 +627,9 @@ function restoreSavedNodeEnv() {
667627}
668628
669629/**
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
673633 */
674634function runConsoleTests ( defaultReporter , runInParallel , done ) {
675635 const lintFlag = cmdLineOptions . lint ;
@@ -747,8 +707,8 @@ function runConsoleTests(defaultReporter, runInParallel, done) {
747707 } ) ;
748708
749709 /**
750- * @param {any= } err
751- * @param {number= } status
710+ * @param {any= } err
711+ * @param {number= } status
752712 */
753713 function failWithStatus ( err , status ) {
754714 if ( err || status ) {
@@ -767,8 +727,8 @@ function runConsoleTests(defaultReporter, runInParallel, done) {
767727 }
768728
769729 /**
770- * @param {any= } error
771- * @param {number= } errorStatus
730+ * @param {any= } error
731+ * @param {number= } errorStatus
772732 */
773733 function finish ( error , errorStatus ) {
774734 restoreSavedNodeEnv ( ) ;
@@ -886,7 +846,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
886846} ) ;
887847
888848/**
889- * @param {(e?: any) => void } done
849+ * @param {(e?: any) => void } done
890850 */
891851function cleanTestDirs ( done ) {
892852 // Clean the local baselines & Rwc baselines directories
@@ -906,13 +866,13 @@ function cleanTestDirs(done) {
906866
907867/**
908868 * 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
916876 */
917877function writeTestConfigFile ( tests , runners , light , taskConfigsFolder , workerCount , stackTraceLimit , timeout ) {
918878 const testConfigContents = JSON . stringify ( {
0 commit comments