Skip to content

Commit 0610692

Browse files
committed
Update LKG
1 parent 6d620e0 commit 0610692

File tree

7 files changed

+114
-34
lines changed

7 files changed

+114
-34
lines changed

release/compiler.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
var ts = require('typescript');
22
var path = require('path');
33
var tsApi = require('./tsapi');
4-
var output = require('./output');
5-
var host = require('./host');
6-
var filter = require('./filter');
4+
var output_1 = require('./output');
5+
var host_1 = require('./host');
6+
var filter_1 = require('./filter');
7+
var reporter_1 = require('./reporter');
78
var utils = require('./utils');
89
/**
910
* Compiles a whole project, with full type checking
@@ -17,7 +18,7 @@ var ProjectCompiler = (function () {
1718
ProjectCompiler.prototype.inputFile = function (file) { };
1819
ProjectCompiler.prototype.inputDone = function () {
1920
if (!this.project.input.firstSourceFile) {
20-
this.project.output.finish();
21+
this.project.output.finish(reporter_1.emptyCompilationResult());
2122
return;
2223
}
2324
if (!this.project.input.isChanged(true)) {
@@ -30,22 +31,23 @@ var ProjectCompiler = (function () {
3031
for (var _b = 0, _c = Object.keys(old.files); _b < _c.length; _b++) {
3132
var fileName = _c[_b];
3233
var file = old.files[fileName];
33-
this.project.output.write(file.fileName + '.js', file.content[output.OutputFileKind.JavaScript]);
34-
this.project.output.write(file.fileName + '.js.map', file.content[output.OutputFileKind.SourceMap]);
35-
if (file.content[output.OutputFileKind.Definitions] !== undefined) {
36-
this.project.output.write(file.fileName + '.d.ts', file.content[output.OutputFileKind.Definitions]);
34+
this.project.output.write(file.fileName + '.js', file.content[output_1.OutputFileKind.JavaScript]);
35+
this.project.output.write(file.fileName + '.js.map', file.content[output_1.OutputFileKind.SourceMap]);
36+
if (file.content[output_1.OutputFileKind.Definitions] !== undefined) {
37+
this.project.output.write(file.fileName + '.d.ts', file.content[output_1.OutputFileKind.Definitions]);
3738
}
3839
}
40+
this.project.output.finish(old.results);
3941
return;
4042
}
4143
var root = this.project.input.commonBasePath;
4244
this.project.options.sourceRoot = root;
4345
this.project.options.rootDir = root; // rootDir was added in 1.5 & not available in 1.4
44-
this.host = new host.Host(this.project.typescript, this.project.currentDirectory, this.project.input, !this.project.noExternalResolve, this.project.options.target >= 2 /* ES6 */ ? 'lib.es6.d.ts' : 'lib.d.ts');
46+
this.host = new host_1.Host(this.project.typescript, this.project.currentDirectory, this.project.input, !this.project.noExternalResolve, this.project.options.target >= 2 /* ES6 */ ? 'lib.es6.d.ts' : 'lib.d.ts');
4547
var rootFilenames = this.project.input.getFileNames(true);
4648
if (this.project.filterSettings !== undefined) {
47-
var _filter = new filter.Filter(this.project, this.project.filterSettings);
48-
rootFilenames = rootFilenames.filter(function (fileName) { return _filter.match(fileName); });
49+
var filter = new filter_1.Filter(this.project, this.project.filterSettings);
50+
rootFilenames = rootFilenames.filter(function (fileName) { return filter.match(fileName); });
4951
}
5052
if (tsApi.isTS14(this.project.typescript) && !this.project.singleOutput) {
5153
// Add an empty file under the root, as the rootDir option is not supported in TS1.4.
@@ -55,7 +57,7 @@ var ProjectCompiler = (function () {
5557
}
5658
// Creating a program to compile the sources
5759
this.program = this.project.typescript.createProgram(rootFilenames, this.project.options, this.host);
58-
var errors = tsApi.getDiagnosticsAndEmit(this.program);
60+
var _d = tsApi.getDiagnosticsAndEmit(this.program), errors = _d[0], result = _d[1];
5961
for (var i = 0; i < errors.length; i++) {
6062
this.project.output.diagnostic(errors[i]);
6163
}
@@ -64,7 +66,7 @@ var ProjectCompiler = (function () {
6466
continue;
6567
this.project.output.write(fileName, this.host.output[fileName]);
6668
}
67-
this.project.output.finish();
69+
this.project.output.finish(result);
6870
};
6971
Object.defineProperty(ProjectCompiler.prototype, "commonBaseDiff", {
7072
/**

release/filter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ var tsApi = require('./tsapi');
22
var path = require('path');
33
var utils = require('./utils');
44
var Filter = (function () {
5-
function Filter(_project, filters) {
5+
function Filter(project, filters) {
66
var _this = this;
77
this.referencedFrom = undefined;
88
this.referencedFromAll = undefined;
9-
this.project = _project;
9+
this.project = project;
1010
if (filters.referencedFrom !== undefined) {
1111
this.referencedFrom = this.mapFilenamesToFiles(filters.referencedFrom);
1212
this.referencedFromAll = [];

release/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ var compile;
155155
if (fileNameOrSettings !== undefined) {
156156
if (typeof fileNameOrSettings === 'string') {
157157
tsConfigFileName = fileNameOrSettings;
158-
tsConfigContent = JSON.parse(fs.readFileSync(fileNameOrSettings).toString());
158+
// load file and strip BOM, since JSON.parse fails to parse if there's a BOM present
159+
var tsConfigText = fs.readFileSync(fileNameOrSettings).toString();
160+
tsConfigContent = JSON.parse(tsConfigText.replace(/^\uFEFF/, ''));
159161
var newSettings = {};
160162
if (tsConfigContent.compilerOptions) {
161163
for (var _i = 0, _a = Object.keys(tsConfigContent.compilerOptions); _i < _a.length; _i++) {

release/output.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ var Output = (function () {
161161
this.streamDts.push(fileDts);
162162
}
163163
};
164-
Output.prototype.finish = function () {
164+
Output.prototype.finish = function (results) {
165165
var _this = this;
166166
if (this.project.sortOutput) {
167167
var sortedEmit = function (fileName) {
@@ -179,6 +179,9 @@ var Output = (function () {
179179
sortedEmit(fileName);
180180
}
181181
}
182+
this.results = results;
183+
if (this.project.reporter.finish)
184+
this.project.reporter.finish(results);
182185
this.streamJs.push(null);
183186
this.streamDts.push(null);
184187
};

release/project.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
var ts = require('typescript');
33
var vfs = require('vinyl-fs');
44
var path = require('path');
5-
var input = require('./input');
6-
var output = require('./output');
5+
var through2 = require('through2');
6+
var utils = require('./utils');
7+
var input_1 = require('./input');
8+
var output_1 = require('./output');
79
var Project = (function () {
810
function Project(configFileName, config, options, noExternalResolve, sortOutput, typescript) {
911
if (typescript === void 0) { typescript = ts; }
@@ -14,7 +16,7 @@ var Project = (function () {
1416
this.noExternalResolve = noExternalResolve;
1517
this.sortOutput = sortOutput;
1618
this.singleOutput = options.out !== undefined;
17-
this.input = new input.FileCache(typescript, options);
19+
this.input = new input_1.FileCache(typescript, options);
1820
}
1921
/**
2022
* Resets the compiler.
@@ -23,17 +25,42 @@ var Project = (function () {
2325
Project.prototype.reset = function (outputJs, outputDts) {
2426
this.input.reset();
2527
this.previousOutput = this.output;
26-
this.output = new output.Output(this, outputJs, outputDts);
28+
this.output = new output_1.Output(this, outputJs, outputDts);
2729
};
2830
Project.prototype.src = function () {
31+
var _this = this;
2932
if (!this.config.files) {
3033
throw new Error('gulp-typescript: You can only use src() if the \'files\' property exists in your tsconfig.json. Use gulp.src(\'**/**.ts\') instead.');
3134
}
32-
var base = path.dirname(this.configFileName);
35+
var configPath = path.dirname(this.configFileName);
36+
var base;
3337
if (this.config.compilerOptions && this.config.compilerOptions.rootDir) {
34-
base = path.resolve(base, this.config.compilerOptions.rootDir);
38+
base = path.resolve(configPath, this.config.compilerOptions.rootDir);
3539
}
36-
return vfs.src(this.config.files.map(function (file) { return path.resolve(base, file); }), { base: base });
40+
else {
41+
base = configPath;
42+
}
43+
var resolvedFiles = [];
44+
var checkMissingFiles = through2.obj(function (file, enc, callback) {
45+
resolvedFiles.push(utils.normalizePath(file.path));
46+
callback();
47+
});
48+
checkMissingFiles.on('finish', function () {
49+
for (var _i = 0, _a = _this.config.files; _i < _a.length; _i++) {
50+
var fileName = _a[_i];
51+
var fullPaths = [
52+
utils.normalizePath(path.join(configPath, fileName)),
53+
utils.normalizePath(path.join(process.cwd(), configPath, fileName))
54+
];
55+
if (resolvedFiles.indexOf(fullPaths[0]) === -1 && resolvedFiles.indexOf(fullPaths[1]) === -1) {
56+
var error = new Error("error TS6053: File '" + fileName + "' not found.");
57+
console.error(error.message);
58+
checkMissingFiles.emit('error', error);
59+
}
60+
}
61+
});
62+
return vfs.src(this.config.files.map(function (file) { return path.resolve(base, file); }), { base: base })
63+
.pipe(checkMissingFiles);
3764
};
3865
return Project;
3966
})();

release/reporter.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
///<reference path='../typings/tsd.d.ts'/>
22
var gutil = require('gulp-util');
3+
function emptyCompilationResult() {
4+
return {
5+
syntaxErrors: 0,
6+
globalErrors: 0,
7+
semanticErrors: 0,
8+
emitErrors: 0,
9+
emitSkipped: false
10+
};
11+
}
12+
exports.emptyCompilationResult = emptyCompilationResult;
13+
function defaultFinishHandler(results) {
14+
var hasError = false;
15+
var showErrorCount = function (count, type) {
16+
if (count === 0)
17+
return;
18+
gutil.log('TypeScript:', gutil.colors.magenta(count.toString()), type + ' ' + (count === 1 ? 'error' : 'errors'));
19+
hasError = true;
20+
};
21+
showErrorCount(results.syntaxErrors, 'syntax');
22+
showErrorCount(results.globalErrors, 'global');
23+
showErrorCount(results.semanticErrors, 'semantic');
24+
showErrorCount(results.emitErrors, 'emit');
25+
if (results.emitSkipped) {
26+
gutil.log('TypeScript: emit', gutil.colors.red('failed'));
27+
}
28+
else if (hasError) {
29+
gutil.log('TypeScript: emit', gutil.colors.cyan('succeeded'), '(with errors)');
30+
}
31+
}
332
function nullReporter() {
433
return {};
534
}
@@ -8,7 +37,8 @@ function defaultReporter() {
837
return {
938
error: function (error) {
1039
console.error(error.message);
11-
}
40+
},
41+
finish: defaultFinishHandler
1242
};
1343
}
1444
exports.defaultReporter = defaultReporter;
@@ -40,7 +70,8 @@ function longReporter() {
4070
else {
4171
console.error(error.message);
4272
}
43-
}
73+
},
74+
finish: defaultFinishHandler
4475
};
4576
}
4677
exports.longReporter = longReporter;
@@ -67,7 +98,8 @@ function fullReporter(fullFilename) {
6798
logLine(i, i === error.startPosition.line ? error.startPosition.character - 1 : 0, i === error.endPosition.line ? error.endPosition.character - 1 : undefined);
6899
}
69100
}
70-
}
101+
},
102+
finish: defaultFinishHandler
71103
};
72104
}
73105
exports.fullReporter = fullReporter;

release/tsapi.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var reporter_1 = require('./reporter');
12
function isTS14(typescript) {
23
return !('findConfigFile' in typescript);
34
}
@@ -9,28 +10,41 @@ function getFileName(thing) {
910
}
1011
exports.getFileName = getFileName;
1112
function getDiagnosticsAndEmit(program) {
13+
var result = reporter_1.emptyCompilationResult();
1214
if (program.getDiagnostics) {
1315
var errors = program.getDiagnostics();
16+
result.syntaxErrors = errors.length;
1417
if (!errors.length) {
1518
// If there are no syntax errors, check types
1619
var checker = program.getTypeChecker(true);
1720
var semanticErrors = checker.getDiagnostics();
1821
var emitErrors = checker.emitFiles().diagnostics;
1922
errors = semanticErrors.concat(emitErrors);
23+
result.semanticErrors = errors.length;
2024
}
21-
return errors;
25+
else {
26+
result.emitSkipped = true;
27+
}
28+
return [errors, result];
2229
}
2330
else {
2431
var errors = program.getSyntacticDiagnostics();
25-
if (errors.length === 0)
32+
result.syntaxErrors = errors.length;
33+
if (errors.length === 0) {
2634
errors = program.getGlobalDiagnostics();
27-
// Remove error: "File '...' is not under 'rootDir' '...'. 'rootDir' is expected to contain all source files."
28-
// This is handled by ICompiler#correctSourceMap, so this error can be muted.
29-
errors = errors.filter(function (item) { return item.code !== 6059; });
30-
if (errors.length === 0)
35+
// Remove error: "File '...' is not under 'rootDir' '...'. 'rootDir' is expected to contain all source files."
36+
// This is handled by ICompiler#correctSourceMap, so this error can be muted.
37+
errors = errors.filter(function (item) { return item.code !== 6059; });
38+
result.globalErrors = errors.length;
39+
}
40+
if (errors.length === 0) {
3141
errors = program.getSemanticDiagnostics();
42+
result.semanticErrors = errors.length;
43+
}
3244
var emitOutput = program.emit();
33-
return errors.concat(emitOutput.diagnostics);
45+
result.emitErrors = emitOutput.diagnostics.length;
46+
result.emitSkipped = emitOutput.emitSkipped;
47+
return [errors.concat(emitOutput.diagnostics), result];
3448
}
3549
}
3650
exports.getDiagnosticsAndEmit = getDiagnosticsAndEmit;

0 commit comments

Comments
 (0)