@@ -4,7 +4,6 @@ var fs = require("fs");
44var os = require ( "os" ) ;
55var path = require ( "path" ) ;
66var child_process = require ( "child_process" ) ;
7- var Linter = require ( "tslint" ) ;
87var fold = require ( "travis-fold" ) ;
98var runTestsInParallel = require ( "./scripts/mocha-parallel" ) . runTestsInParallel ;
109
@@ -181,7 +180,8 @@ var harnessSources = harnessCoreSources.concat([
181180 "convertCompilerOptionsFromJson.ts" ,
182181 "convertTypingOptionsFromJson.ts" ,
183182 "tsserverProjectSystem.ts" ,
184- "matchFiles.ts"
183+ "matchFiles.ts" ,
184+ "initializeTSConfig.ts" ,
185185] . map ( function ( f ) {
186186 return path . join ( unittestsDirectory , f ) ;
187187} ) ) . concat ( [
@@ -938,16 +938,16 @@ task("tests-debug", ["setDebugMode", "tests"]);
938938// Makes the test results the new baseline
939939desc ( "Makes the most recent test results the new baseline, overwriting the old baseline" ) ;
940940task ( "baseline-accept" , function ( hardOrSoft ) {
941- if ( ! hardOrSoft || hardOrSoft === "hard" ) {
942- jake . rmRf ( refBaseline ) ;
943- fs . renameSync ( localBaseline , refBaseline ) ;
944- }
945- else if ( hardOrSoft === "soft" ) {
946- var files = jake . readdirR ( localBaseline ) ;
947- for ( var i in files ) {
941+ var files = jake . readdirR ( localBaseline ) ;
942+ var deleteEnding = '.delete' ;
943+ for ( var i in files ) {
944+ if ( files [ i ] . substr ( files [ i ] . length - deleteEnding . length ) === deleteEnding ) {
945+ var filename = path . basename ( files [ i ] ) ;
946+ filename = filename . substr ( 0 , filename . length - deleteEnding . length ) ;
947+ fs . unlink ( path . join ( refBaseline , filename ) ) ;
948+ } else {
948949 jake . cpR ( files [ i ] , refBaseline ) ;
949950 }
950- jake . rmRf ( path . join ( refBaseline , "local" ) ) ;
951951 }
952952} ) ;
953953
@@ -1054,36 +1054,6 @@ task("build-rules-end", [] , function() {
10541054 if ( fold . isTravis ( ) ) console . log ( fold . end ( "build-rules" ) ) ;
10551055} ) ;
10561056
1057- function getLinterOptions ( ) {
1058- return {
1059- configuration : require ( "./tslint.json" ) ,
1060- formatter : "prose" ,
1061- formattersDirectory : undefined ,
1062- rulesDirectory : "built/local/tslint"
1063- } ;
1064- }
1065-
1066- function lintFileContents ( options , path , contents ) {
1067- var ll = new Linter ( path , contents , options ) ;
1068- console . log ( "Linting '" + path + "'." ) ;
1069- return ll . lint ( ) ;
1070- }
1071-
1072- function lintFile ( options , path ) {
1073- var contents = fs . readFileSync ( path , "utf8" ) ;
1074- return lintFileContents ( options , path , contents ) ;
1075- }
1076-
1077- function lintFileAsync ( options , path , cb ) {
1078- fs . readFile ( path , "utf8" , function ( err , contents ) {
1079- if ( err ) {
1080- return cb ( err ) ;
1081- }
1082- var result = lintFileContents ( options , path , contents ) ;
1083- cb ( undefined , result ) ;
1084- } ) ;
1085- }
1086-
10871057var lintTargets = compilerSources
10881058 . concat ( harnessSources )
10891059 // Other harness sources
@@ -1094,75 +1064,78 @@ var lintTargets = compilerSources
10941064 . concat ( [ "Gulpfile.ts" ] )
10951065 . concat ( [ nodeServerInFile , perftscPath , "tests/perfsys.ts" , webhostPath ] ) ;
10961066
1067+ function sendNextFile ( files , child , callback , failures ) {
1068+ var file = files . pop ( ) ;
1069+ if ( file ) {
1070+ console . log ( "Linting '" + file + "'." ) ;
1071+ child . send ( { kind : "file" , name : file } ) ;
1072+ }
1073+ else {
1074+ child . send ( { kind : "close" } ) ;
1075+ callback ( failures ) ;
1076+ }
1077+ }
1078+
1079+ function spawnLintWorker ( files , callback ) {
1080+ var child = child_process . fork ( "./scripts/parallel-lint" ) ;
1081+ var failures = 0 ;
1082+ child . on ( "message" , function ( data ) {
1083+ switch ( data . kind ) {
1084+ case "result" :
1085+ if ( data . failures > 0 ) {
1086+ failures += data . failures ;
1087+ console . log ( data . output ) ;
1088+ }
1089+ sendNextFile ( files , child , callback , failures ) ;
1090+ break ;
1091+ case "error" :
1092+ console . error ( data . error ) ;
1093+ failures ++ ;
1094+ sendNextFile ( files , child , callback , failures ) ;
1095+ break ;
1096+ }
1097+ } ) ;
1098+ sendNextFile ( files , child , callback , failures ) ;
1099+ }
10971100
10981101desc ( "Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex" ) ;
10991102task ( "lint" , [ "build-rules" ] , function ( ) {
11001103 if ( fold . isTravis ( ) ) console . log ( fold . start ( "lint" ) ) ;
11011104 var startTime = mark ( ) ;
1102- var lintOptions = getLinterOptions ( ) ;
11031105 var failed = 0 ;
11041106 var fileMatcher = RegExp ( process . env . f || process . env . file || process . env . files || "" ) ;
11051107 var done = { } ;
11061108 for ( var i in lintTargets ) {
11071109 var target = lintTargets [ i ] ;
11081110 if ( ! done [ target ] && fileMatcher . test ( target ) ) {
1109- var result = lintFile ( lintOptions , target ) ;
1110- if ( result . failureCount > 0 ) {
1111- console . log ( result . output ) ;
1112- failed += result . failureCount ;
1113- }
1114- done [ target ] = true ;
1111+ done [ target ] = fs . statSync ( target ) . size ;
11151112 }
11161113 }
1117- measure ( startTime ) ;
1118- if ( fold . isTravis ( ) ) console . log ( fold . end ( "lint" ) ) ;
1119- if ( failed > 0 ) {
1120- fail ( 'Linter errors.' , failed ) ;
1121- }
1122- } ) ;
11231114
1124- /**
1125- * This is required because file watches on Windows get fires _twice_
1126- * when a file changes on some node/windows version configuations
1127- * (node v4 and win 10, for example). By not running a lint for a file
1128- * which already has a pending lint, we avoid duplicating our work.
1129- * (And avoid printing duplicate results!)
1130- */
1131- var lintSemaphores = { } ;
1132-
1133- function lintWatchFile ( filename ) {
1134- fs . watch ( filename , { persistent : true } , function ( event ) {
1135- if ( event !== "change" ) {
1136- return ;
1137- }
1115+ var workerCount = ( process . env . workerCount && + process . env . workerCount ) || os . cpus ( ) . length ;
11381116
1139- if ( ! lintSemaphores [ filename ] ) {
1140- lintSemaphores [ filename ] = true ;
1141- lintFileAsync ( getLinterOptions ( ) , filename , function ( err , result ) {
1142- delete lintSemaphores [ filename ] ;
1143- if ( err ) {
1144- console . log ( err ) ;
1145- return ;
1146- }
1147- if ( result . failureCount > 0 ) {
1148- console . log ( "***Lint failure***" ) ;
1149- for ( var i = 0 ; i < result . failures . length ; i ++ ) {
1150- var failure = result . failures [ i ] ;
1151- var start = failure . startPosition . lineAndCharacter ;
1152- var end = failure . endPosition . lineAndCharacter ;
1153- console . log ( "warning " + filename + " (" + ( start . line + 1 ) + "," + ( start . character + 1 ) + "," + ( end . line + 1 ) + "," + ( end . character + 1 ) + "): " + failure . failure ) ;
1154- }
1155- console . log ( "*** Total " + result . failureCount + " failures." ) ;
1156- }
1157- } ) ;
1158- }
1117+ var names = Object . keys ( done ) . sort ( function ( namea , nameb ) {
1118+ return done [ namea ] - done [ nameb ] ;
11591119 } ) ;
1160- }
11611120
1162- desc ( "Watches files for changes to rerun a lint pass" ) ;
1163- task ( "lint-server" , [ "build-rules" ] , function ( ) {
1164- console . log ( "Watching ./src for changes to linted files" ) ;
1165- for ( var i = 0 ; i < lintTargets . length ; i ++ ) {
1166- lintWatchFile ( lintTargets [ i ] ) ;
1121+ for ( var i = 0 ; i < workerCount ; i ++ ) {
1122+ spawnLintWorker ( names , finished ) ;
11671123 }
1168- } ) ;
1124+
1125+ var completed = 0 ;
1126+ var failures = 0 ;
1127+ function finished ( fails ) {
1128+ completed ++ ;
1129+ failures += fails ;
1130+ if ( completed === workerCount ) {
1131+ measure ( startTime ) ;
1132+ if ( fold . isTravis ( ) ) console . log ( fold . end ( "lint" ) ) ;
1133+ if ( failures > 0 ) {
1134+ fail ( 'Linter errors.' , failed ) ;
1135+ }
1136+ else {
1137+ complete ( ) ;
1138+ }
1139+ }
1140+ }
1141+ } , { async : true } ) ;
0 commit comments