Skip to content

Commit 297cb50

Browse files
author
Andy Hanson
committed
Merge branch 'master' into no_ts_extension
2 parents 8fc17af + a621c09 commit 297cb50

File tree

126 files changed

+3425
-955
lines changed

Some content is hidden

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

126 files changed

+3425
-955
lines changed

Gulpfile.ts

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

Jakefile.js

Lines changed: 67 additions & 94 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

@@ -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
939939
desc("Makes the most recent test results the new baseline, overwriting the old baseline");
940940
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 {
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-
10871057
var 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

10981101
desc("Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex");
10991102
task("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});

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/ior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../src/harness/external/node.d.ts" />
1+
/// <reference types="node"/>
22

33
import fs = require('fs');
44
import path = require('path');

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)