Skip to content

Commit a2e5c2d

Browse files
committed
merge with origin/master
2 parents ce35f96 + 4880e7e commit a2e5c2d

111 files changed

Lines changed: 3035 additions & 894 deletions

File tree

Some content is hidden

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

Gulpfile.ts

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

Jakefile.js

Lines changed: 65 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

@@ -979,16 +978,16 @@ task("tests-debug", ["setDebugMode", "tests"]);
979978
// Makes the test results the new baseline
980979
desc("Makes the most recent test results the new baseline, overwriting the old baseline");
981980
task("baseline-accept", function(hardOrSoft) {
982-
if (!hardOrSoft || hardOrSoft === "hard") {
983-
jake.rmRf(refBaseline);
984-
fs.renameSync(localBaseline, refBaseline);
985-
}
986-
else if (hardOrSoft === "soft") {
987-
var files = jake.readdirR(localBaseline);
988-
for (var i in files) {
981+
var files = jake.readdirR(localBaseline);
982+
var deleteEnding = '.delete';
983+
for (var i in files) {
984+
if (files[i].substr(files[i].length - deleteEnding.length) === deleteEnding) {
985+
var filename = path.basename(files[i]);
986+
filename = filename.substr(0, filename.length - deleteEnding.length);
987+
fs.unlink(path.join(refBaseline, filename));
988+
} else {
989989
jake.cpR(files[i], refBaseline);
990990
}
991-
jake.rmRf(path.join(refBaseline, "local"));
992991
}
993992
});
994993

@@ -1095,36 +1094,6 @@ task("build-rules-end", [] , function() {
10951094
if (fold.isTravis()) console.log(fold.end("build-rules"));
10961095
});
10971096

1098-
function getLinterOptions() {
1099-
return {
1100-
configuration: require("./tslint.json"),
1101-
formatter: "prose",
1102-
formattersDirectory: undefined,
1103-
rulesDirectory: "built/local/tslint"
1104-
};
1105-
}
1106-
1107-
function lintFileContents(options, path, contents) {
1108-
var ll = new Linter(path, contents, options);
1109-
console.log("Linting '" + path + "'.");
1110-
return ll.lint();
1111-
}
1112-
1113-
function lintFile(options, path) {
1114-
var contents = fs.readFileSync(path, "utf8");
1115-
return lintFileContents(options, path, contents);
1116-
}
1117-
1118-
function lintFileAsync(options, path, cb) {
1119-
fs.readFile(path, "utf8", function(err, contents) {
1120-
if (err) {
1121-
return cb(err);
1122-
}
1123-
var result = lintFileContents(options, path, contents);
1124-
cb(undefined, result);
1125-
});
1126-
}
1127-
11281097
var lintTargets = compilerSources
11291098
.concat(harnessSources)
11301099
// Other harness sources
@@ -1135,75 +1104,78 @@ var lintTargets = compilerSources
11351104
.concat(["Gulpfile.ts"])
11361105
.concat([nodeServerInFile, perftscPath, "tests/perfsys.ts", webhostPath]);
11371106

1107+
function sendNextFile(files, child, callback, failures) {
1108+
var file = files.pop();
1109+
if (file) {
1110+
console.log("Linting '" + file + "'.");
1111+
child.send({kind: "file", name: file});
1112+
}
1113+
else {
1114+
child.send({kind: "close"});
1115+
callback(failures);
1116+
}
1117+
}
1118+
1119+
function spawnLintWorker(files, callback) {
1120+
var child = child_process.fork("./scripts/parallel-lint");
1121+
var failures = 0;
1122+
child.on("message", function(data) {
1123+
switch (data.kind) {
1124+
case "result":
1125+
if (data.failures > 0) {
1126+
failures += data.failures;
1127+
console.log(data.output);
1128+
}
1129+
sendNextFile(files, child, callback, failures);
1130+
break;
1131+
case "error":
1132+
console.error(data.error);
1133+
failures++;
1134+
sendNextFile(files, child, callback, failures);
1135+
break;
1136+
}
1137+
});
1138+
sendNextFile(files, child, callback, failures);
1139+
}
11381140

11391141
desc("Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex");
11401142
task("lint", ["build-rules"], function() {
11411143
if (fold.isTravis()) console.log(fold.start("lint"));
11421144
var startTime = mark();
1143-
var lintOptions = getLinterOptions();
11441145
var failed = 0;
11451146
var fileMatcher = RegExp(process.env.f || process.env.file || process.env.files || "");
11461147
var done = {};
11471148
for (var i in lintTargets) {
11481149
var target = lintTargets[i];
11491150
if (!done[target] && fileMatcher.test(target)) {
1150-
var result = lintFile(lintOptions, target);
1151-
if (result.failureCount > 0) {
1152-
console.log(result.output);
1153-
failed += result.failureCount;
1154-
}
1155-
done[target] = true;
1151+
done[target] = fs.statSync(target).size;
11561152
}
11571153
}
1158-
measure(startTime);
1159-
if (fold.isTravis()) console.log(fold.end("lint"));
1160-
if (failed > 0) {
1161-
fail('Linter errors.', failed);
1162-
}
1163-
});
11641154

1165-
/**
1166-
* This is required because file watches on Windows get fires _twice_
1167-
* when a file changes on some node/windows version configuations
1168-
* (node v4 and win 10, for example). By not running a lint for a file
1169-
* which already has a pending lint, we avoid duplicating our work.
1170-
* (And avoid printing duplicate results!)
1171-
*/
1172-
var lintSemaphores = {};
1173-
1174-
function lintWatchFile(filename) {
1175-
fs.watch(filename, {persistent: true}, function(event) {
1176-
if (event !== "change") {
1177-
return;
1178-
}
1155+
var workerCount = (process.env.workerCount && +process.env.workerCount) || os.cpus().length;
11791156

1180-
if (!lintSemaphores[filename]) {
1181-
lintSemaphores[filename] = true;
1182-
lintFileAsync(getLinterOptions(), filename, function(err, result) {
1183-
delete lintSemaphores[filename];
1184-
if (err) {
1185-
console.log(err);
1186-
return;
1187-
}
1188-
if (result.failureCount > 0) {
1189-
console.log("***Lint failure***");
1190-
for (var i = 0; i < result.failures.length; i++) {
1191-
var failure = result.failures[i];
1192-
var start = failure.startPosition.lineAndCharacter;
1193-
var end = failure.endPosition.lineAndCharacter;
1194-
console.log("warning " + filename + " (" + (start.line + 1) + "," + (start.character + 1) + "," + (end.line + 1) + "," + (end.character + 1) + "): " + failure.failure);
1195-
}
1196-
console.log("*** Total " + result.failureCount + " failures.");
1197-
}
1198-
});
1199-
}
1157+
var names = Object.keys(done).sort(function(namea, nameb) {
1158+
return done[namea] - done[nameb];
12001159
});
1201-
}
12021160

1203-
desc("Watches files for changes to rerun a lint pass");
1204-
task("lint-server", ["build-rules"], function() {
1205-
console.log("Watching ./src for changes to linted files");
1206-
for (var i = 0; i < lintTargets.length; i++) {
1207-
lintWatchFile(lintTargets[i]);
1161+
for (var i = 0; i < workerCount; i++) {
1162+
spawnLintWorker(names, finished);
12081163
}
1209-
});
1164+
1165+
var completed = 0;
1166+
var failures = 0;
1167+
function finished(fails) {
1168+
completed++;
1169+
failures += fails;
1170+
if (completed === workerCount) {
1171+
measure(startTime);
1172+
if (fold.isTravis()) console.log(fold.end("lint"));
1173+
if (failures > 0) {
1174+
fail('Linter errors.', failed);
1175+
}
1176+
else {
1177+
complete();
1178+
}
1179+
}
1180+
}
1181+
}, {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/types/ambient.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare module "gulp-insert" {
1010
export function append(text: string | Buffer): NodeJS.ReadWriteStream;
1111
export function prepend(text: string | Buffer): NodeJS.ReadWriteStream;
1212
export function wrap(text: string | Buffer, tail: string | Buffer): NodeJS.ReadWriteStream;
13-
export function transform(cb: (contents: string, file: {path: string}) => string): NodeJS.ReadWriteStream; // file is a vinyl file
13+
export function transform(cb: (contents: string, file: {path: string, relative: string}) => string): NodeJS.ReadWriteStream; // file is a vinyl file
1414
}
1515

1616
declare module "into-stream" {

0 commit comments

Comments
 (0)