@@ -31,11 +31,17 @@ import merge2 = require("merge2");
3131import * as os from "os" ;
3232import fold = require( "travis-fold" ) ;
3333const gulp = helpMaker ( originalGulp ) ;
34- const mochaParallel = require ( "./scripts/mocha-parallel.js" ) ;
35- const { runTestsInParallel} = mochaParallel ;
3634
3735Error . stackTraceLimit = 1000 ;
3836
37+ /**
38+ * This regexp exists to capture our const enums and replace them with normal enums in our public API
39+ * - this is fine since we compile with preserveConstEnums, and ensures our consumers are not locked
40+ * to the TS version they compile with.
41+ */
42+ const constEnumCaptureRegexp = / ^ ( \s * ) ( e x p o r t ) ? c o n s t e n u m ( \S + ) { ( \s * ) $ / gm;
43+ const constEnumReplacement = "$1$2enum $3 {$4" ;
44+
3945const cmdLineOptions = minimist ( process . argv . slice ( 2 ) , {
4046 boolean : [ "debug" , "inspect" , "light" , "colors" , "lint" , "soft" ] ,
4147 string : [ "browser" , "tests" , "host" , "reporter" , "stackTraceLimit" , "timeout" ] ,
@@ -89,6 +95,7 @@ const harnessDirectory = "src/harness/";
8995const libraryDirectory = "src/lib/" ;
9096const scriptsDirectory = "scripts/" ;
9197const docDirectory = "doc/" ;
98+ const lclDirectory = "src/loc/lcl" ;
9299
93100const builtDirectory = "built/" ;
94101const builtLocalDirectory = "built/local/" ;
@@ -262,8 +269,8 @@ function getCompilerSettings(base: tsc.Settings, useBuiltCompiler?: boolean): ts
262269 }
263270 if ( ! useDebugMode ) {
264271 if ( copy . removeComments === undefined ) copy . removeComments = true ;
265- copy . newLine = "lf" ;
266272 }
273+ copy . newLine = "lf" ;
267274 if ( useBuiltCompiler === true ) {
268275 copy . typescript = require ( "./built/local/typescript.js" ) ;
269276 }
@@ -369,6 +376,36 @@ gulp.task(builtGeneratedDiagnosticMessagesJSON, [diagnosticInfoMapTs], (done) =>
369376
370377gulp . task ( "generate-diagnostics" , "Generates a diagnostic file in TypeScript based on an input JSON file" , [ diagnosticInfoMapTs ] ) ;
371378
379+ // Localize diagnostics script
380+ const generateLocalizedDiagnosticMessagesJs = path . join ( scriptsDirectory , "generateLocalizedDiagnosticMessages.js" ) ;
381+ const generateLocalizedDiagnosticMessagesTs = path . join ( scriptsDirectory , "generateLocalizedDiagnosticMessages.ts" ) ;
382+
383+ gulp . task ( generateLocalizedDiagnosticMessagesJs , /*help*/ false , [ ] , ( ) => {
384+ const settings : tsc . Settings = getCompilerSettings ( {
385+ target : "es5" ,
386+ declaration : false ,
387+ removeComments : true ,
388+ noResolve : false ,
389+ stripInternal : false ,
390+ types : [ "node" , "xml2js" ]
391+ } , /*useBuiltCompiler*/ false ) ;
392+ return gulp . src ( generateLocalizedDiagnosticMessagesTs )
393+ . pipe ( newer ( generateLocalizedDiagnosticMessagesJs ) )
394+ . pipe ( sourcemaps . init ( ) )
395+ . pipe ( tsc ( settings ) )
396+ . pipe ( sourcemaps . write ( "." ) )
397+ . pipe ( gulp . dest ( scriptsDirectory ) ) ;
398+ } ) ;
399+
400+ // Localize diagnostics
401+ const generatedLCGFile = path . join ( builtLocalDirectory , "enu" , "diagnosticMessages.generated.json.lcg" ) ;
402+ gulp . task ( generatedLCGFile , [ generateLocalizedDiagnosticMessagesJs , diagnosticInfoMapTs ] , ( done ) => {
403+ if ( fs . existsSync ( builtLocalDirectory ) && needsUpdate ( generatedDiagnosticMessagesJSON , generatedLCGFile ) ) {
404+ exec ( host , [ generateLocalizedDiagnosticMessagesJs , lclDirectory , builtLocalDirectory , generatedDiagnosticMessagesJSON ] , done , done ) ;
405+ }
406+ } ) ;
407+
408+ gulp . task ( "localize" , [ generatedLCGFile ] ) ;
372409
373410const servicesFile = path . join ( builtLocalDirectory , "typescriptServices.js" ) ;
374411const standaloneDefinitionsFile = path . join ( builtLocalDirectory , "typescriptServices.d.ts" ) ;
@@ -403,7 +440,7 @@ gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
403440 const completedDts = dts . pipe ( prependCopyright ( /*outputCopyright*/ true ) )
404441 . pipe ( insert . transform ( ( contents , file ) => {
405442 file . path = standaloneDefinitionsFile ;
406- return contents . replace ( / ^ ( \s * ) ( e x p o r t ) ? c o n s t e n u m ( \S + ) { ( \s * ) $ / gm , "$1$2enum $3 {$4" ) ;
443+ return contents . replace ( constEnumCaptureRegexp , constEnumReplacement ) ;
407444 } ) ) ;
408445 return merge2 ( [
409446 completedJs ,
@@ -413,7 +450,7 @@ gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
413450 completedDts . pipe ( clone ( ) )
414451 . pipe ( insert . transform ( ( content , file ) => {
415452 file . path = nodeDefinitionsFile ;
416- return content + "\r\ nexport = ts;" ;
453+ return content + "\nexport = ts;" ;
417454 } ) )
418455 . pipe ( gulp . dest ( "src/services" ) ) ,
419456 completedDts . pipe ( clone ( ) )
@@ -468,7 +505,7 @@ const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js")
468505const tsserverLibraryDefinitionFile = path . join ( builtLocalDirectory , "tsserverlibrary.d.ts" ) ;
469506
470507gulp . task ( tsserverLibraryFile , /*help*/ false , [ servicesFile , typesMapJson ] , ( done ) => {
471- const serverLibraryProject = tsc . createProject ( "src/server/tsconfig.library.json" , getCompilerSettings ( { } , /*useBuiltCompiler*/ true ) ) ;
508+ const serverLibraryProject = tsc . createProject ( "src/server/tsconfig.library.json" , getCompilerSettings ( { removeComments : false } , /*useBuiltCompiler*/ true ) ) ;
472509 const { js, dts} : { js : NodeJS . ReadableStream , dts : NodeJS . ReadableStream } = serverLibraryProject . src ( )
473510 . pipe ( sourcemaps . init ( ) )
474511 . pipe ( newer ( tsserverLibraryFile ) )
@@ -480,7 +517,7 @@ gulp.task(tsserverLibraryFile, /*help*/ false, [servicesFile, typesMapJson], (do
480517 . pipe ( gulp . dest ( "src/server" ) ) ,
481518 dts . pipe ( prependCopyright ( /*outputCopyright*/ true ) )
482519 . pipe ( insert . transform ( ( content ) => {
483- return content + "\r\ nexport = ts;\r \nexport as namespace ts;" ;
520+ return content . replace ( constEnumCaptureRegexp , constEnumReplacement ) + "\nexport = ts;\nexport as namespace ts;" ;
484521 } ) )
485522 . pipe ( gulp . dest ( "src/server" ) )
486523 ] ) ;
@@ -496,7 +533,7 @@ gulp.task(typesMapJson, /*help*/ false, [], () => {
496533} ) ;
497534
498535gulp . task ( "lssl" , "Builds language service server library" , [ tsserverLibraryFile ] ) ;
499- gulp . task ( "local" , "Builds the full compiler and services" , [ builtLocalCompiler , servicesFile , serverFile , builtGeneratedDiagnosticMessagesJSON , tsserverLibraryFile ] ) ;
536+ gulp . task ( "local" , "Builds the full compiler and services" , [ builtLocalCompiler , servicesFile , serverFile , builtGeneratedDiagnosticMessagesJSON , tsserverLibraryFile , "localize" ] ) ;
500537gulp . task ( "tsc" , "Builds only the compiler" , [ builtLocalCompiler ] ) ;
501538
502539// Generate Markdown spec
@@ -538,15 +575,16 @@ gulp.task("dontUseDebugMode", /*help*/ false, [], (done) => { useDebugMode = fal
538575
539576gulp . task ( "VerifyLKG" , /*help*/ false , [ ] , ( ) => {
540577 const expectedFiles = [ builtLocalCompiler , servicesFile , serverFile , nodePackageFile , nodeDefinitionsFile , standaloneDefinitionsFile , tsserverLibraryFile , tsserverLibraryDefinitionFile , typingsInstallerJs , cancellationTokenJs ] . concat ( libraryTargets ) ;
541- const missingFiles = expectedFiles . filter ( function ( f ) {
542- return ! fs . existsSync ( f ) ;
543- } ) ;
578+ const missingFiles = expectedFiles .
579+ concat ( fs . readdirSync ( lclDirectory ) . map ( function ( d ) { return path . join ( builtLocalDirectory , d , "diagnosticMessages.generated.json" ) ; } ) ) .
580+ concat ( generatedLCGFile ) .
581+ filter ( f => ! fs . existsSync ( f ) ) ;
544582 if ( missingFiles . length > 0 ) {
545583 throw new Error ( "Cannot replace the LKG unless all built targets are present in directory " + builtLocalDirectory +
546584 ". The following files are missing:\n" + missingFiles . join ( "\n" ) ) ;
547585 }
548586 // Copy all the targets into the LKG directory
549- return gulp . src ( expectedFiles ) . pipe ( gulp . dest ( LKGDirectory ) ) ;
587+ return gulp . src ( [ ... expectedFiles , path . join ( builtLocalDirectory , "**" ) , `! ${ path . join ( builtLocalDirectory , "tslint" ) } ` , `! ${ path . join ( builtLocalDirectory , "*.*" ) } ` ] ) . pipe ( gulp . dest ( LKGDirectory ) ) ;
550588} ) ;
551589
552590gulp . task ( "LKGInternal" , /*help*/ false , [ "lib" , "local" ] ) ;
@@ -558,7 +596,7 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
558596
559597// Task to build the tests infrastructure using the built compiler
560598const run = path . join ( builtLocalDirectory , "run.js" ) ;
561- gulp . task ( run , /*help*/ false , [ servicesFile ] , ( ) => {
599+ gulp . task ( run , /*help*/ false , [ servicesFile , tsserverLibraryFile ] , ( ) => {
562600 const testProject = tsc . createProject ( "src/harness/tsconfig.json" , getCompilerSettings ( { } , /*useBuiltCompiler*/ true ) ) ;
563601 return testProject . src ( )
564602 . pipe ( newer ( run ) )
@@ -668,36 +706,18 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
668706 }
669707 else {
670708 // run task to load all tests and partition them between workers
671- const args = [ ] ;
672- args . push ( "-R" , "min" ) ;
673- if ( colors ) {
674- args . push ( "--colors" ) ;
675- }
676- else {
677- args . push ( "--no-colors" ) ;
678- }
679- args . push ( run ) ;
680709 setNodeEnvToDevelopment ( ) ;
681- runTestsInParallel ( taskConfigsFolder , run , { testTimeout, noColors : colors === " --no-colors " } , function ( err ) {
682- // last worker clean everything and runs linter in case if there were no errors
683- del ( taskConfigsFolder ) . then ( ( ) => {
684- if ( ! err ) {
685- lintThenFinish ( ) ;
686- }
687- else {
688- finish ( err ) ;
689- }
690- } ) ;
710+ exec ( host , [ run ] , lintThenFinish , function ( e , status ) {
711+ finish ( e , status ) ;
691712 } ) ;
692713 }
693714 } ) ;
694715
695716 function failWithStatus ( err ?: any , status ?: number ) {
696- if ( err ) {
697- console . log ( err ) ;
717+ if ( err || status ) {
718+ process . exit ( typeof status === "number" ? status : 2 ) ;
698719 }
699- done ( err || status ) ;
700- process . exit ( status ) ;
720+ done ( ) ;
701721 }
702722
703723 function lintThenFinish ( ) {
@@ -711,7 +731,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
711731
712732 function finish ( error ?: any , errorStatus ?: number ) {
713733 restoreSavedNodeEnv ( ) ;
714- deleteTemporaryProjectOutput ( ) . then ( ( ) => {
734+ deleteTestConfig ( ) . then ( deleteTemporaryProjectOutput ) . then ( ( ) => {
715735 if ( error !== undefined || errorStatus !== undefined ) {
716736 failWithStatus ( error , errorStatus ) ;
717737 }
@@ -720,6 +740,10 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
720740 }
721741 } ) ;
722742 }
743+
744+ function deleteTestConfig ( ) {
745+ return del ( "test.config" ) ;
746+ }
723747}
724748
725749gulp . task ( "runtests-parallel" , "Runs all the tests in parallel using the built run.js file. Optional arguments are: --t[ests]=category1|category2|... --d[ebug]=true." , [ "build-rules" , "tests" ] , ( done ) => {
@@ -836,7 +860,7 @@ function cleanTestDirs(done: (e?: any) => void) {
836860
837861// used to pass data from jake command line directly to run.js
838862function writeTestConfigFile ( tests : string , light : boolean , taskConfigsFolder ?: string , workerCount ?: number , stackTraceLimit ?: string ) {
839- const testConfigContents = JSON . stringify ( { test : tests ? [ tests ] : undefined , light, workerCount, stackTraceLimit, taskConfigsFolder } ) ;
863+ const testConfigContents = JSON . stringify ( { test : tests ? [ tests ] : undefined , light, workerCount, stackTraceLimit, taskConfigsFolder, noColor : ! cmdLineOptions [ "colors" ] } ) ;
840864 console . log ( "Running tests with config: " + testConfigContents ) ;
841865 fs . writeFileSync ( "test.config" , testConfigContents ) ;
842866}
@@ -994,8 +1018,9 @@ gulp.task(instrumenterJsPath, /*help*/ false, [servicesFile], () => {
9941018 . pipe ( gulp . dest ( builtLocalDirectory ) ) ;
9951019} ) ;
9961020
997- gulp . task ( "tsc-instrumented" , "Builds an instrumented tsc.js" , [ "local" , loggedIOJsPath , instrumenterJsPath , servicesFile ] , ( done ) => {
998- exec ( host , [ instrumenterJsPath , "record" , "iocapture" , builtLocalCompiler ] , done , done ) ;
1021+ gulp . task ( "tsc-instrumented" , "Builds an instrumented tsc.js - run with --test=[testname]" , [ "local" , loggedIOJsPath , instrumenterJsPath , servicesFile ] , ( done ) => {
1022+ const test = cmdLineOptions [ "tests" ] || "iocapture" ;
1023+ exec ( host , [ instrumenterJsPath , "record" , test , builtLocalCompiler ] , done , done ) ;
9991024} ) ;
10001025
10011026gulp . task ( "update-sublime" , "Updates the sublime plugin's tsserver" , [ "local" , serverFile ] , ( ) => {
@@ -1066,10 +1091,11 @@ gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are:
10661091 const fileMatcher = cmdLineOptions [ "files" ] ;
10671092 const files = fileMatcher
10681093 ? `src/**/${ fileMatcher } `
1069- : "Gulpfile.ts 'scripts/tslint/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'" ;
1070- const cmd = `node node_modules/tslint/bin/tslint ${ files } --format stylish ` ;
1094+ : "Gulpfile.ts 'scripts/generateLocalizedDiagnosticMessages.ts' 'scripts/ tslint/** /*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'" ;
1095+ const cmd = `node node_modules/tslint/bin/tslint ${ files } --formatters-dir ./built/local/tslint/formatters -- format autolinkableStylish ` ;
10711096 console . log ( "Linting: " + cmd ) ;
10721097 child_process . execSync ( cmd , { stdio : [ 0 , 1 , 2 ] } ) ;
1098+ if ( fold . isTravis ( ) ) console . log ( fold . end ( "lint" ) ) ;
10731099} ) ;
10741100
10751101gulp . task ( "default" , "Runs 'local'" , [ "local" ] ) ;
0 commit comments