Skip to content

Commit 89ccd75

Browse files
committed
Update release
1 parent bc59775 commit 89ccd75

File tree

3 files changed

+63
-54
lines changed

3 files changed

+63
-54
lines changed

release/main.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,18 @@ var CompileStream = (function (_super) {
1717
__extends(CompileStream, _super);
1818
function CompileStream(proj, theReporter) {
1919
if (theReporter === void 0) { theReporter = _reporter.defaultReporter(); }
20-
_super.call(this, {
21-
objectMode: true
22-
});
20+
_super.call(this, { objectMode: true });
2321
this._hasSources = false;
2422
this.dts = new CompileOutputStream();
2523
this._project = proj;
2624
this.reporter = theReporter;
2725
// Backwards compatibility
2826
this.js = this;
2927
// Prevent "Unhandled stream error in pipe" when compilation error occurs.
30-
this.on('error', function () {
31-
});
28+
this.on('error', function () { });
3229
}
3330
CompileStream.prototype._write = function (file, encoding, cb) {
34-
if (cb === void 0) { cb = function (err) {
35-
}; }
31+
if (cb === void 0) { cb = function (err) { }; }
3632
if (!file)
3733
return cb();
3834
if (file.isNull()) {
@@ -81,9 +77,7 @@ var CompileStream = (function (_super) {
8177
var CompileOutputStream = (function (_super) {
8278
__extends(CompileOutputStream, _super);
8379
function CompileOutputStream() {
84-
_super.call(this, {
85-
objectMode: true
86-
});
80+
_super.call(this, { objectMode: true });
8781
}
8882
CompileOutputStream.prototype._read = function () {
8983
};
@@ -117,7 +111,14 @@ function getCompilerOptions(settings) {
117111
for (var key in settings) {
118112
if (!Object.hasOwnProperty.call(settings, key))
119113
continue;
120-
if (key === 'outDir' || key === 'noExternalResolve' || key === 'declarationFiles' || key === 'sortOutput' || key === 'typescript' || key === 'target' || key === 'module' || key === 'sourceRoot')
114+
if (key === 'outDir' ||
115+
key === 'noExternalResolve' ||
116+
key === 'declarationFiles' ||
117+
key === 'sortOutput' ||
118+
key === 'typescript' ||
119+
key === 'target' ||
120+
key === 'module' ||
121+
key === 'sourceRoot')
121122
continue;
122123
tsSettings[key] = settings[key];
123124
}

release/project.js

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,16 @@ var Project = (function () {
128128
line: endPos.line,
129129
character: endPos.character
130130
};
131-
err.message = gutil.colors.red(filename + '(' + startPos.line + ',' + startPos.character + '): ') + info.code + ' ' + tsApi.flattenDiagnosticMessageText(this.typescript, info.messageText);
131+
err.message = gutil.colors.red(filename + '(' + startPos.line + ',' + startPos.character + '): ')
132+
+ info.code + ' '
133+
+ tsApi.flattenDiagnosticMessageText(this.typescript, info.messageText);
132134
return err;
133135
};
134136
Project.prototype.lazyCompile = function (jsStream, declStream) {
135-
if (this.isFileChanged === false && Object.keys(this.currentFiles).length === Object.keys(this.previousFiles).length && this.previousOutputJS !== undefined && this.previousOutputDts !== undefined) {
137+
if (this.isFileChanged === false
138+
&& Object.keys(this.currentFiles).length === Object.keys(this.previousFiles).length
139+
&& this.previousOutputJS !== undefined
140+
&& this.previousOutputDts !== undefined) {
136141
// Emit files from previous build, since they are the same.
137142
// JavaScript files
138143
for (var i = 0; i < this.previousOutputJS.length; i++) {
@@ -170,35 +175,7 @@ var Project = (function () {
170175
};
171176
Project.prototype.resolve = function (session, file) {
172177
var _this = this;
173-
var references = file.ts.referencedFiles.map(function (item) {
174-
return path.join(path.dirname(tsApi.getFileName(file.ts)), tsApi.getFileName(item));
175-
});
176-
this.typescript.forEachChild(file.ts, function (node) {
177-
if (node.kind === _this.typescript.SyntaxKind.ImportDeclaration) {
178-
var importNode = node;
179-
if (importNode.moduleReference === undefined || importNode.moduleReference.kind !== _this.typescript.SyntaxKind.ExternalModuleReference) {
180-
return;
181-
}
182-
var reference = importNode.moduleReference;
183-
if (reference.expression === undefined || reference.expression.kind !== _this.typescript.SyntaxKind.StringLiteral) {
184-
return;
185-
}
186-
if (typeof reference.text !== 'string') {
187-
return;
188-
}
189-
var ref = path.join(path.dirname(tsApi.getFileName(file.ts)), reference.text);
190-
// Don't know if this name is defined with `declare module 'foo'`, but let's load it to be sure.
191-
// We guess what file the user wants. This will be right in most cases.
192-
// The advantage of guessing is that we can now use fs.readFile (async) instead of fs.readFileSync.
193-
// If we guessed wrong, the file will be loaded with fs.readFileSync in Host#getSourceFile (host.ts)
194-
if (ref.substr(-3).toLowerCase() === '.ts') {
195-
references.push(ref);
196-
}
197-
else {
198-
references.push(ref + '.ts');
199-
}
200-
}
201-
});
178+
var references = file.ts.referencedFiles.map(function (item) { return path.join(path.dirname(tsApi.getFileName(file.ts)), tsApi.getFileName(item)); });
202179
for (var i = 0; i < references.length; ++i) {
203180
(function (i) {
204181
var ref = references[i];
@@ -347,9 +324,7 @@ var Project = (function () {
347324
oldFiles = Object.keys(_this.currentFiles);
348325
}
349326
else {
350-
oldFiles = [
351-
originalName
352-
];
327+
oldFiles = [originalName];
353328
}
354329
var generator = sourceMap.SourceMapGenerator.fromSourceMap(new sourceMap.SourceMapConsumer(parsedMap));
355330
for (var i = 0; i < oldFiles.length; i++) {
@@ -380,9 +355,7 @@ var Project = (function () {
380355
done[originalName] = true;
381356
var inputFile = _this.currentFiles[originalName];
382357
var tsFile = _this.program.getSourceFile(originalName);
383-
var references = tsFile.referencedFiles.map(function (file) {
384-
return tsApi.getFileName(file);
385-
});
358+
var references = tsFile.referencedFiles.map(function (file) { return tsApi.getFileName(file); });
386359
for (var j = 0; j < outputJS.length; ++j) {
387360
var other = outputJS[j];
388361
var otherName = _this.getOriginalName(other.path);

release/reporter.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
///<reference path='../definitions/ref.d.ts'/>
2-
var ts = require('typescript');
3-
var tsApi = require('./tsapi');
42
var gutil = require('gulp-util');
53
function nullReporter() {
64
return {};
@@ -14,22 +12,59 @@ function defaultReporter() {
1412
};
1513
}
1614
exports.defaultReporter = defaultReporter;
15+
function flattenDiagnosticsVerbose(message, index) {
16+
if (index === void 0) { index = 0; }
17+
if (typeof message === 'undefined') {
18+
return '';
19+
}
20+
else if (typeof message === 'string') {
21+
return message;
22+
}
23+
else {
24+
var result;
25+
if (index === 0) {
26+
result = message.messageText;
27+
}
28+
else {
29+
result = '\n> TS' + message.code + ' ' + message.messageText;
30+
}
31+
return result + flattenDiagnosticsVerbose(message.next, index + 1);
32+
}
33+
}
34+
function longReporter() {
35+
return {
36+
error: function (error) {
37+
if (error.tsFile) {
38+
console.error('[' + gutil.colors.gray('gulp-typescript') + '] ' + gutil.colors.red(error.fullFilename + '(' + error.startPosition.line + ',' + error.startPosition.character + '): ') + 'error TS' + error.diagnostic.code + ' ' + flattenDiagnosticsVerbose(error.diagnostic.messageText));
39+
}
40+
else {
41+
console.error(error.message);
42+
}
43+
}
44+
};
45+
}
46+
exports.longReporter = longReporter;
1747
function fullReporter(fullFilename) {
1848
if (fullFilename === void 0) { fullFilename = false; }
1949
return {
2050
error: function (error, typescript) {
21-
console.error('[' + gutil.colors.gray('gulp-typescript') + '] ' + gutil.colors.bgRed(error.diagnostic.code + '') + ' ' + gutil.colors.red(tsApi.flattenDiagnosticMessageText(ts, error.diagnostic.messageText)));
51+
console.error('[' + gutil.colors.gray('gulp-typescript') + '] '
52+
+ gutil.colors.bgRed(error.diagnostic.code + '')
53+
+ ' ' + gutil.colors.red(flattenDiagnosticsVerbose(error.diagnostic.messageText)));
2254
if (error.tsFile) {
2355
console.error('> ' + gutil.colors.gray('file: ') + (fullFilename ? error.fullFilename : error.relativeFilename) + gutil.colors.gray(':'));
2456
var lines = error.tsFile.text.split(/(\r\n|\r|\n)/);
2557
var logLine = function (lineIndex, errorStart, errorEnd) {
26-
var line = lines[lineIndex - 1];
58+
var line = lines[lineIndex];
2759
if (errorEnd === undefined)
2860
errorEnd = line.length;
29-
console.error('> ' + gutil.colors.gray('[' + lineIndex + '] ') + line.substring(0, errorStart - 1) + gutil.colors.red(line.substring(errorStart - 1, errorEnd)) + line.substring(errorEnd));
61+
console.error('> ' + gutil.colors.gray('[' + lineIndex + '] ')
62+
+ line.substring(0, errorStart)
63+
+ gutil.colors.red(line.substring(errorStart, errorEnd))
64+
+ line.substring(errorEnd));
3065
};
3166
for (var i = error.startPosition.line; i <= error.endPosition.line; i++) {
32-
logLine(i, i === error.startPosition.line ? error.startPosition.character : 0, i === error.endPosition.line ? error.endPosition.character : undefined);
67+
logLine(i, i === error.startPosition.line ? error.startPosition.character - 1 : 0, i === error.endPosition.line ? error.endPosition.character - 1 : undefined);
3368
}
3469
}
3570
}

0 commit comments

Comments
 (0)