@@ -34,7 +34,7 @@ import through2 = require("through2");
3434import merge2 = require( "merge2" ) ;
3535import intoStream = require( "into-stream" ) ;
3636import * as os from "os" ;
37- import Linter = require( "tslint " ) ;
37+ import fold = require( "travis-fold " ) ;
3838const gulp = helpMaker ( originalGulp ) ;
3939const mochaParallel = require ( "./scripts/mocha-parallel.js" ) ;
4040const { runTestsInParallel} = mochaParallel ;
@@ -59,7 +59,6 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
5959 browser : process . env . browser || process . env . b || "IE" ,
6060 tests : process . env . test || process . env . tests || process . env . t ,
6161 light : process . env . light || false ,
62- port : process . env . port || process . env . p || "8888" ,
6362 reporter : process . env . reporter || process . env . r ,
6463 lint : process . env . lint || true ,
6564 files : process . env . f || process . env . file || process . env . files || "" ,
@@ -450,7 +449,7 @@ gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
450449} ) ;
451450
452451gulp . task ( "lssl" , "Builds language service server library" , [ tsserverLibraryFile ] ) ;
453- gulp . task ( "local" , "Builds the full compiler and services" , [ builtLocalCompiler , servicesFile , serverFile , builtGeneratedDiagnosticMessagesJSON ] ) ;
452+ gulp . task ( "local" , "Builds the full compiler and services" , [ builtLocalCompiler , servicesFile , serverFile , builtGeneratedDiagnosticMessagesJSON , tsserverLibraryFile ] ) ;
454453gulp . task ( "tsc" , "Builds only the compiler" , [ builtLocalCompiler ] ) ;
455454
456455
@@ -504,7 +503,7 @@ gulp.task("VerifyLKG", false, [], () => {
504503 return gulp . src ( expectedFiles ) . pipe ( gulp . dest ( LKGDirectory ) ) ;
505504} ) ;
506505
507- gulp . task ( "LKGInternal" , false , [ "lib" , "local" , "lssl" ] ) ;
506+ gulp . task ( "LKGInternal" , false , [ "lib" , "local" ] ) ;
508507
509508gulp . task ( "LKG" , "Makes a new LKG out of the built js files" , [ "clean" , "dontUseDebugMode" ] , ( ) => {
510509 return runSequence ( "LKGInternal" , "VerifyLKG" ) ;
@@ -766,7 +765,7 @@ function writeTestConfigFile(tests: string, light: boolean, taskConfigsFolder?:
766765}
767766
768767
769- gulp . task ( "runtests-browser" , "Runs the tests using the built run.js file like 'gulp runtests'. Syntax is gulp runtests-browser. Additional optional parameters --tests=[regex], --port=, -- browser=[chrome|IE]" , [ "browserify" , nodeServerOutFile ] , ( done ) => {
768+ gulp . task ( "runtests-browser" , "Runs the tests using the built run.js file like 'gulp runtests'. Syntax is gulp runtests-browser. Additional optional parameters --tests=[regex], --browser=[chrome|IE]" , [ "browserify" , nodeServerOutFile ] , ( done ) => {
770769 cleanTestDirs ( ( err ) => {
771770 if ( err ) { console . error ( err ) ; done ( err ) ; process . exit ( 1 ) ; }
772771 host = "node" ;
@@ -781,9 +780,6 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like '
781780 }
782781
783782 const args = [ nodeServerOutFile ] ;
784- if ( cmdLineOptions [ "port" ] ) {
785- args . push ( cmdLineOptions [ "port" ] ) ;
786- }
787783 if ( cmdLineOptions [ "browser" ] ) {
788784 args . push ( cmdLineOptions [ "browser" ] ) ;
789785 }
@@ -932,26 +928,6 @@ gulp.task("build-rules", "Compiles tslint rules to js", () => {
932928 . pipe ( gulp . dest ( dest ) ) ;
933929} ) ;
934930
935- function getLinterOptions ( ) {
936- return {
937- configuration : require ( "./tslint.json" ) ,
938- formatter : "prose" ,
939- formattersDirectory : undefined ,
940- rulesDirectory : "built/local/tslint"
941- } ;
942- }
943-
944- function lintFileContents ( options , path , contents ) {
945- const ll = new Linter ( path , contents , options ) ;
946- console . log ( "Linting '" + path + "'." ) ;
947- return ll . lint ( ) ;
948- }
949-
950- function lintFile ( options , path ) {
951- const contents = fs . readFileSync ( path , "utf8" ) ;
952- return lintFileContents ( options , path , contents ) ;
953- }
954-
955931const lintTargets = [
956932 "Gulpfile.ts" ,
957933 "src/compiler/**/*.ts" ,
@@ -960,29 +936,75 @@ const lintTargets = [
960936 "src/server/**/*.ts" ,
961937 "scripts/tslint/**/*.ts" ,
962938 "src/services/**/*.ts" ,
939+ "tests/*.ts" , "tests/webhost/*.ts" // Note: does *not* descend recursively
963940] ;
964941
942+ function sendNextFile ( files : { path : string } [ ] , child : cp . ChildProcess , callback : ( failures : number ) => void , failures : number ) {
943+ const file = files . pop ( ) ;
944+ if ( file ) {
945+ console . log ( `Linting '${ file . path } '.` ) ;
946+ child . send ( { kind : "file" , name : file . path } ) ;
947+ }
948+ else {
949+ child . send ( { kind : "close" } ) ;
950+ callback ( failures ) ;
951+ }
952+ }
953+
954+ function spawnLintWorker ( files : { path : string } [ ] , callback : ( failures : number ) => void ) {
955+ const child = cp . fork ( "./scripts/parallel-lint" ) ;
956+ let failures = 0 ;
957+ child . on ( "message" , function ( data ) {
958+ switch ( data . kind ) {
959+ case "result" :
960+ if ( data . failures > 0 ) {
961+ failures += data . failures ;
962+ console . log ( data . output ) ;
963+ }
964+ sendNextFile ( files , child , callback , failures ) ;
965+ break ;
966+ case "error" :
967+ console . error ( data . error ) ;
968+ failures ++ ;
969+ sendNextFile ( files , child , callback , failures ) ;
970+ break ;
971+ }
972+ } ) ;
973+ sendNextFile ( files , child , callback , failures ) ;
974+ }
965975
966976gulp . task ( "lint" , "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex" , [ "build-rules" ] , ( ) => {
967977 const fileMatcher = RegExp ( cmdLineOptions [ "files" ] ) ;
968- const lintOptions = getLinterOptions ( ) ;
969- let failed = 0 ;
970- return gulp . src ( lintTargets )
971- . pipe ( insert . transform ( ( contents , file ) => {
972- if ( ! fileMatcher . test ( file . path ) ) return contents ;
973- const result = lintFile ( lintOptions , file . path ) ;
974- if ( result . failureCount > 0 ) {
975- console . log ( result . output ) ;
976- failed += result . failureCount ;
978+ if ( fold . isTravis ( ) ) console . log ( fold . start ( "lint" ) ) ;
979+
980+ let files : { stat : fs . Stats , path : string } [ ] = [ ] ;
981+ return gulp . src ( lintTargets , { read : false } )
982+ . pipe ( through2 . obj ( ( chunk , enc , cb ) => {
983+ files . push ( chunk ) ;
984+ cb ( ) ;
985+ } , ( cb ) => {
986+ files = files . filter ( file => fileMatcher . test ( file . path ) ) . sort ( ( filea , fileb ) => filea . stat . size - fileb . stat . size ) ;
987+ const workerCount = ( process . env . workerCount && + process . env . workerCount ) || os . cpus ( ) . length ;
988+ for ( let i = 0 ; i < workerCount ; i ++ ) {
989+ spawnLintWorker ( files , finished ) ;
977990 }
978- return contents ; // TODO (weswig): Automatically apply fixes? :3
979- } ) )
980- . on ( "end" , ( ) => {
981- if ( failed > 0 ) {
982- console . error ( "Linter errors." ) ;
983- process . exit ( 1 ) ;
991+
992+ let completed = 0 ;
993+ let failures = 0 ;
994+ function finished ( fails ) {
995+ completed ++ ;
996+ failures += fails ;
997+ if ( completed === workerCount ) {
998+ if ( fold . isTravis ( ) ) console . log ( fold . end ( "lint" ) ) ;
999+ if ( failures > 0 ) {
1000+ throw new Error ( `Linter errors: ${ failures } ` ) ;
1001+ }
1002+ else {
1003+ cb ( ) ;
1004+ }
1005+ }
9841006 }
985- } ) ;
1007+ } ) ) ;
9861008} ) ;
9871009
9881010
0 commit comments