Skip to content

Commit 5d86888

Browse files
author
Kanchalai Tanglertsampan
committed
Merge branch 'master' into fix10193
2 parents 3479f4b + ef2d6ab commit 5d86888

File tree

118 files changed

+3634
-1337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3634
-1337
lines changed

Gulpfile.ts

Lines changed: 119 additions & 95 deletions
Large diffs are not rendered by default.

Jakefile.js

Lines changed: 96 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var fs = require("fs");
44
var os = require("os");
55
var path = require("path");
66
var child_process = require("child_process");
7-
var Linter = require("tslint");
87
var fold = require("travis-fold");
98
var runTestsInParallel = require("./scripts/mocha-parallel").runTestsInParallel;
109

@@ -33,6 +32,28 @@ if (process.env.path !== undefined) {
3332
process.env.PATH = nodeModulesPathPrefix + process.env.PATH;
3433
}
3534

35+
function toNs(diff) {
36+
return diff[0] * 1e9 + diff[1];
37+
}
38+
39+
function mark() {
40+
if (!fold.isTravis()) return;
41+
var stamp = process.hrtime();
42+
var id = Math.floor(Math.random() * 0xFFFFFFFF).toString(16);
43+
console.log("travis_time:start:" + id + "\r");
44+
return {
45+
stamp: stamp,
46+
id: id
47+
};
48+
}
49+
50+
function measure(marker) {
51+
if (!fold.isTravis()) return;
52+
var diff = process.hrtime(marker.stamp);
53+
var total = [marker.stamp[0] + diff[0], marker.stamp[1] + diff[1]];
54+
console.log("travis_time:end:" + marker.id + ":start=" + toNs(marker.stamp) + ",finish=" + toNs(total) + ",duration=" + toNs(diff) + "\r");
55+
}
56+
3657
var compilerSources = [
3758
"core.ts",
3859
"performance.ts",
@@ -286,6 +307,7 @@ var builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename);
286307
*/
287308
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts, callback) {
288309
file(outFile, prereqs, function() {
310+
var startCompileTime = mark();
289311
opts = opts || {};
290312
var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler;
291313
var options = "--noImplicitAny --noImplicitThis --noEmitOnError --types "
@@ -362,11 +384,13 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
362384
callback();
363385
}
364386

387+
measure(startCompileTime);
365388
complete();
366389
});
367390
ex.addListener("error", function() {
368391
fs.unlinkSync(outFile);
369392
fail("Compilation of " + outFile + " unsuccessful");
393+
measure(startCompileTime);
370394
});
371395
ex.run();
372396
}, {async: true});
@@ -769,6 +793,7 @@ function runConsoleTests(defaultReporter, runInParallel) {
769793
// timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally
770794
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
771795
if(!runInParallel) {
796+
var startTime = mark();
772797
tests = tests ? ' -g "' + tests + '"' : '';
773798
var cmd = "mocha" + (debug ? " --debug-brk" : "") + " -R " + reporter + tests + colors + bail + ' -t ' + testTimeout + ' ' + run;
774799
console.log(cmd);
@@ -777,20 +802,23 @@ function runConsoleTests(defaultReporter, runInParallel) {
777802
process.env.NODE_ENV = "development";
778803
exec(cmd, function () {
779804
process.env.NODE_ENV = savedNodeEnv;
805+
measure(startTime);
780806
runLinter();
781807
finish();
782808
}, function(e, status) {
783809
process.env.NODE_ENV = savedNodeEnv;
810+
measure(startTime);
784811
finish(status);
785812
});
786813

787814
}
788815
else {
789816
var savedNodeEnv = process.env.NODE_ENV;
790817
process.env.NODE_ENV = "development";
818+
var startTime = mark();
791819
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: colors === " --no-colors " }, function (err) {
792820
process.env.NODE_ENV = savedNodeEnv;
793-
821+
measure(startTime);
794822
// last worker clean everything and runs linter in case if there were no errors
795823
deleteTemporaryProjectOutput();
796824
jake.rmRf(taskConfigsFolder);
@@ -909,16 +937,16 @@ task("tests-debug", ["setDebugMode", "tests"]);
909937
// Makes the test results the new baseline
910938
desc("Makes the most recent test results the new baseline, overwriting the old baseline");
911939
task("baseline-accept", function(hardOrSoft) {
912-
if (!hardOrSoft || hardOrSoft === "hard") {
913-
jake.rmRf(refBaseline);
914-
fs.renameSync(localBaseline, refBaseline);
915-
}
916-
else if (hardOrSoft === "soft") {
917-
var files = jake.readdirR(localBaseline);
918-
for (var i in files) {
940+
var files = jake.readdirR(localBaseline);
941+
var deleteEnding = '.delete';
942+
for (var i in files) {
943+
if (files[i].substr(files[i].length - deleteEnding.length) === deleteEnding) {
944+
var filename = path.basename(files[i]);
945+
filename = filename.substr(0, filename.length - deleteEnding.length);
946+
fs.unlink(path.join(refBaseline, filename));
947+
} else {
919948
jake.cpR(files[i], refBaseline);
920949
}
921-
jake.rmRf(path.join(refBaseline, "local"));
922950
}
923951
});
924952

@@ -1025,36 +1053,6 @@ task("build-rules-end", [] , function() {
10251053
if (fold.isTravis()) console.log(fold.end("build-rules"));
10261054
});
10271055

1028-
function getLinterOptions() {
1029-
return {
1030-
configuration: require("./tslint.json"),
1031-
formatter: "prose",
1032-
formattersDirectory: undefined,
1033-
rulesDirectory: "built/local/tslint"
1034-
};
1035-
}
1036-
1037-
function lintFileContents(options, path, contents) {
1038-
var ll = new Linter(path, contents, options);
1039-
console.log("Linting '" + path + "'.");
1040-
return ll.lint();
1041-
}
1042-
1043-
function lintFile(options, path) {
1044-
var contents = fs.readFileSync(path, "utf8");
1045-
return lintFileContents(options, path, contents);
1046-
}
1047-
1048-
function lintFileAsync(options, path, cb) {
1049-
fs.readFile(path, "utf8", function(err, contents) {
1050-
if (err) {
1051-
return cb(err);
1052-
}
1053-
var result = lintFileContents(options, path, contents);
1054-
cb(undefined, result);
1055-
});
1056-
}
1057-
10581056
var lintTargets = compilerSources
10591057
.concat(harnessSources)
10601058
// Other harness sources
@@ -1065,73 +1063,78 @@ var lintTargets = compilerSources
10651063
.concat(["Gulpfile.ts"])
10661064
.concat([nodeServerInFile, perftscPath, "tests/perfsys.ts", webhostPath]);
10671065

1066+
function sendNextFile(files, child, callback, failures) {
1067+
var file = files.pop();
1068+
if (file) {
1069+
console.log("Linting '" + file + "'.");
1070+
child.send({kind: "file", name: file});
1071+
}
1072+
else {
1073+
child.send({kind: "close"});
1074+
callback(failures);
1075+
}
1076+
}
1077+
1078+
function spawnLintWorker(files, callback) {
1079+
var child = child_process.fork("./scripts/parallel-lint");
1080+
var failures = 0;
1081+
child.on("message", function(data) {
1082+
switch (data.kind) {
1083+
case "result":
1084+
if (data.failures > 0) {
1085+
failures += data.failures;
1086+
console.log(data.output);
1087+
}
1088+
sendNextFile(files, child, callback, failures);
1089+
break;
1090+
case "error":
1091+
console.error(data.error);
1092+
failures++;
1093+
sendNextFile(files, child, callback, failures);
1094+
break;
1095+
}
1096+
});
1097+
sendNextFile(files, child, callback, failures);
1098+
}
10681099

10691100
desc("Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex");
10701101
task("lint", ["build-rules"], function() {
10711102
if (fold.isTravis()) console.log(fold.start("lint"));
1072-
var lintOptions = getLinterOptions();
1103+
var startTime = mark();
10731104
var failed = 0;
10741105
var fileMatcher = RegExp(process.env.f || process.env.file || process.env.files || "");
10751106
var done = {};
10761107
for (var i in lintTargets) {
10771108
var target = lintTargets[i];
10781109
if (!done[target] && fileMatcher.test(target)) {
1079-
var result = lintFile(lintOptions, target);
1080-
if (result.failureCount > 0) {
1081-
console.log(result.output);
1082-
failed += result.failureCount;
1083-
}
1084-
done[target] = true;
1110+
done[target] = fs.statSync(target).size;
10851111
}
10861112
}
1087-
if (fold.isTravis()) console.log(fold.end("lint"));
1088-
if (failed > 0) {
1089-
fail('Linter errors.', failed);
1090-
}
1091-
});
10921113

1093-
/**
1094-
* This is required because file watches on Windows get fires _twice_
1095-
* when a file changes on some node/windows version configuations
1096-
* (node v4 and win 10, for example). By not running a lint for a file
1097-
* which already has a pending lint, we avoid duplicating our work.
1098-
* (And avoid printing duplicate results!)
1099-
*/
1100-
var lintSemaphores = {};
1101-
1102-
function lintWatchFile(filename) {
1103-
fs.watch(filename, {persistent: true}, function(event) {
1104-
if (event !== "change") {
1105-
return;
1106-
}
1114+
var workerCount = (process.env.workerCount && +process.env.workerCount) || os.cpus().length;
11071115

1108-
if (!lintSemaphores[filename]) {
1109-
lintSemaphores[filename] = true;
1110-
lintFileAsync(getLinterOptions(), filename, function(err, result) {
1111-
delete lintSemaphores[filename];
1112-
if (err) {
1113-
console.log(err);
1114-
return;
1115-
}
1116-
if (result.failureCount > 0) {
1117-
console.log("***Lint failure***");
1118-
for (var i = 0; i < result.failures.length; i++) {
1119-
var failure = result.failures[i];
1120-
var start = failure.startPosition.lineAndCharacter;
1121-
var end = failure.endPosition.lineAndCharacter;
1122-
console.log("warning " + filename + " (" + (start.line + 1) + "," + (start.character + 1) + "," + (end.line + 1) + "," + (end.character + 1) + "): " + failure.failure);
1123-
}
1124-
console.log("*** Total " + result.failureCount + " failures.");
1125-
}
1126-
});
1127-
}
1116+
var names = Object.keys(done).sort(function(namea, nameb) {
1117+
return done[namea] - done[nameb];
11281118
});
1129-
}
11301119

1131-
desc("Watches files for changes to rerun a lint pass");
1132-
task("lint-server", ["build-rules"], function() {
1133-
console.log("Watching ./src for changes to linted files");
1134-
for (var i = 0; i < lintTargets.length; i++) {
1135-
lintWatchFile(lintTargets[i]);
1120+
for (var i = 0; i < workerCount; i++) {
1121+
spawnLintWorker(names, finished);
11361122
}
1137-
});
1123+
1124+
var completed = 0;
1125+
var failures = 0;
1126+
function finished(fails) {
1127+
completed++;
1128+
failures += fails;
1129+
if (completed === workerCount) {
1130+
measure(startTime);
1131+
if (fold.isTravis()) console.log(fold.end("lint"));
1132+
if (failures > 0) {
1133+
fail('Linter errors.', failed);
1134+
}
1135+
else {
1136+
complete();
1137+
}
1138+
}
1139+
}
1140+
}, {async: true});

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[![Join the chat at https://gitter.im/Microsoft/TypeScript](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Microsoft/TypeScript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
88

9-
[TypeScript](http://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](http://www.typescriptlang.org/Playground), and stay up to date via [our blog](http://blogs.msdn.com/typescript) and [Twitter account](https://twitter.com/typescriptlang).
9+
[TypeScript](http://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](http://www.typescriptlang.org/Playground), and stay up to date via [our blog](https://blogs.msdn.microsoft.com/typescript) and [Twitter account](https://twitter.com/typescriptlang).
1010

1111
## Installing
1212

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"mkdirp": "latest",
7070
"mocha": "latest",
7171
"mocha-fivemat-progress-reporter": "latest",
72+
"q": "latest",
7273
"run-sequence": "latest",
7374
"sorcery": "latest",
7475
"through2": "latest",

scripts/parallel-lint.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var Linter = require("tslint");
2+
var fs = require("fs");
3+
4+
function getLinterOptions() {
5+
return {
6+
configuration: require("../tslint.json"),
7+
formatter: "prose",
8+
formattersDirectory: undefined,
9+
rulesDirectory: "built/local/tslint"
10+
};
11+
}
12+
13+
function lintFileContents(options, path, contents) {
14+
var ll = new Linter(path, contents, options);
15+
return ll.lint();
16+
}
17+
18+
function lintFileAsync(options, path, cb) {
19+
fs.readFile(path, "utf8", function (err, contents) {
20+
if (err) {
21+
return cb(err);
22+
}
23+
var result = lintFileContents(options, path, contents);
24+
cb(undefined, result);
25+
});
26+
}
27+
28+
process.on("message", function (data) {
29+
switch (data.kind) {
30+
case "file":
31+
var target = data.name;
32+
var lintOptions = getLinterOptions();
33+
lintFileAsync(lintOptions, target, function (err, result) {
34+
if (err) {
35+
process.send({ kind: "error", error: err.toString() });
36+
return;
37+
}
38+
process.send({ kind: "result", failures: result.failureCount, output: result.output });
39+
});
40+
break;
41+
case "close":
42+
process.exit(0);
43+
break;
44+
}
45+
});

scripts/processDiagnosticMessages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function checkForUniqueCodes(messages: string[], diagnosticTable: InputDiagnosti
6969
}
7070

7171
function buildUniqueNameMap(names: string[]): ts.Map<string> {
72-
var nameMap: ts.Map<string> = {};
72+
var nameMap = ts.createMap<string>();
7373

7474
var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined);
7575

0 commit comments

Comments
 (0)