@@ -4,7 +4,6 @@ var fs = require("fs");
4
4
var os = require ( "os" ) ;
5
5
var path = require ( "path" ) ;
6
6
var child_process = require ( "child_process" ) ;
7
- var Linter = require ( "tslint" ) ;
8
7
var fold = require ( "travis-fold" ) ;
9
8
var runTestsInParallel = require ( "./scripts/mocha-parallel" ) . runTestsInParallel ;
10
9
@@ -181,7 +180,8 @@ var harnessSources = harnessCoreSources.concat([
181
180
"convertCompilerOptionsFromJson.ts" ,
182
181
"convertTypingOptionsFromJson.ts" ,
183
182
"tsserverProjectSystem.ts" ,
184
- "matchFiles.ts"
183
+ "matchFiles.ts" ,
184
+ "initializeTSConfig.ts" ,
185
185
] . map ( function ( f ) {
186
186
return path . join ( unittestsDirectory , f ) ;
187
187
} ) ) . concat ( [
@@ -938,16 +938,16 @@ task("tests-debug", ["setDebugMode", "tests"]);
938
938
// Makes the test results the new baseline
939
939
desc ( "Makes the most recent test results the new baseline, overwriting the old baseline" ) ;
940
940
task ( "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 {
948
949
jake . cpR ( files [ i ] , refBaseline ) ;
949
950
}
950
- jake . rmRf ( path . join ( refBaseline , "local" ) ) ;
951
951
}
952
952
} ) ;
953
953
@@ -1054,36 +1054,6 @@ task("build-rules-end", [] , function() {
1054
1054
if ( fold . isTravis ( ) ) console . log ( fold . end ( "build-rules" ) ) ;
1055
1055
} ) ;
1056
1056
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
-
1087
1057
var lintTargets = compilerSources
1088
1058
. concat ( harnessSources )
1089
1059
// Other harness sources
@@ -1094,75 +1064,78 @@ var lintTargets = compilerSources
1094
1064
. concat ( [ "Gulpfile.ts" ] )
1095
1065
. concat ( [ nodeServerInFile , perftscPath , "tests/perfsys.ts" , webhostPath ] ) ;
1096
1066
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
+ }
1097
1100
1098
1101
desc ( "Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex" ) ;
1099
1102
task ( "lint" , [ "build-rules" ] , function ( ) {
1100
1103
if ( fold . isTravis ( ) ) console . log ( fold . start ( "lint" ) ) ;
1101
1104
var startTime = mark ( ) ;
1102
- var lintOptions = getLinterOptions ( ) ;
1103
1105
var failed = 0 ;
1104
1106
var fileMatcher = RegExp ( process . env . f || process . env . file || process . env . files || "" ) ;
1105
1107
var done = { } ;
1106
1108
for ( var i in lintTargets ) {
1107
1109
var target = lintTargets [ i ] ;
1108
1110
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 ;
1115
1112
}
1116
1113
}
1117
- measure ( startTime ) ;
1118
- if ( fold . isTravis ( ) ) console . log ( fold . end ( "lint" ) ) ;
1119
- if ( failed > 0 ) {
1120
- fail ( 'Linter errors.' , failed ) ;
1121
- }
1122
- } ) ;
1123
1114
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 ;
1138
1116
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 ] ;
1159
1119
} ) ;
1160
- }
1161
1120
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 ) ;
1167
1123
}
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