@@ -34,7 +34,7 @@ import through2 = require("through2");
34
34
import merge2 = require( "merge2" ) ;
35
35
import intoStream = require( "into-stream" ) ;
36
36
import * as os from "os" ;
37
- import Linter = require( "tslint " ) ;
37
+ import fold = require( "travis-fold " ) ;
38
38
const gulp = helpMaker ( originalGulp ) ;
39
39
const mochaParallel = require ( "./scripts/mocha-parallel.js" ) ;
40
40
const { runTestsInParallel} = mochaParallel ;
@@ -449,7 +449,7 @@ gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
449
449
} ) ;
450
450
451
451
gulp . task ( "lssl" , "Builds language service server library" , [ tsserverLibraryFile ] ) ;
452
- 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 ] ) ;
453
453
gulp . task ( "tsc" , "Builds only the compiler" , [ builtLocalCompiler ] ) ;
454
454
455
455
@@ -503,7 +503,7 @@ gulp.task("VerifyLKG", false, [], () => {
503
503
return gulp . src ( expectedFiles ) . pipe ( gulp . dest ( LKGDirectory ) ) ;
504
504
} ) ;
505
505
506
- gulp . task ( "LKGInternal" , false , [ "lib" , "local" , "lssl" ] ) ;
506
+ gulp . task ( "LKGInternal" , false , [ "lib" , "local" ] ) ;
507
507
508
508
gulp . task ( "LKG" , "Makes a new LKG out of the built js files" , [ "clean" , "dontUseDebugMode" ] , ( ) => {
509
509
return runSequence ( "LKGInternal" , "VerifyLKG" ) ;
@@ -928,26 +928,6 @@ gulp.task("build-rules", "Compiles tslint rules to js", () => {
928
928
. pipe ( gulp . dest ( dest ) ) ;
929
929
} ) ;
930
930
931
- function getLinterOptions ( ) {
932
- return {
933
- configuration : require ( "./tslint.json" ) ,
934
- formatter : "prose" ,
935
- formattersDirectory : undefined ,
936
- rulesDirectory : "built/local/tslint"
937
- } ;
938
- }
939
-
940
- function lintFileContents ( options , path , contents ) {
941
- const ll = new Linter ( path , contents , options ) ;
942
- console . log ( "Linting '" + path + "'." ) ;
943
- return ll . lint ( ) ;
944
- }
945
-
946
- function lintFile ( options , path ) {
947
- const contents = fs . readFileSync ( path , "utf8" ) ;
948
- return lintFileContents ( options , path , contents ) ;
949
- }
950
-
951
931
const lintTargets = [
952
932
"Gulpfile.ts" ,
953
933
"src/compiler/**/*.ts" ,
@@ -959,27 +939,72 @@ const lintTargets = [
959
939
"tests/*.ts" , "tests/webhost/*.ts" // Note: does *not* descend recursively
960
940
] ;
961
941
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
+ }
962
975
963
976
gulp . task ( "lint" , "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex" , [ "build-rules" ] , ( ) => {
964
977
const fileMatcher = RegExp ( cmdLineOptions [ "files" ] ) ;
965
- const lintOptions = getLinterOptions ( ) ;
966
- let failed = 0 ;
967
- return gulp . src ( lintTargets )
968
- . pipe ( insert . transform ( ( contents , file ) => {
969
- if ( ! fileMatcher . test ( file . path ) ) return contents ;
970
- const result = lintFile ( lintOptions , file . path ) ;
971
- if ( result . failureCount > 0 ) {
972
- console . log ( result . output ) ;
973
- 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 ) ;
974
990
}
975
- return contents ; // TODO (weswig): Automatically apply fixes? :3
976
- } ) )
977
- . on ( "end" , ( ) => {
978
- if ( failed > 0 ) {
979
- console . error ( "Linter errors." ) ;
980
- 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
+ }
981
1006
}
982
- } ) ;
1007
+ } ) ) ;
983
1008
} ) ;
984
1009
985
1010
0 commit comments