mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
- error output follows tsconfig pretty option #47
This commit is contained in:
parent
d3f340c87a
commit
e26cb55dd9
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,4 +4,5 @@
|
||||
/.rpt2_cache
|
||||
/.vscode
|
||||
/.idea
|
||||
/build-self
|
||||
/build-self
|
||||
/build
|
||||
7
dist/diagnostics-format-host.d.ts
vendored
Normal file
7
dist/diagnostics-format-host.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import * as tsTypes from "typescript";
|
||||
export declare class FormatHost implements tsTypes.FormatDiagnosticsHost {
|
||||
getCurrentDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
getNewLine(): string;
|
||||
}
|
||||
export declare const formatHost: FormatHost;
|
||||
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -9,6 +9,6 @@ export default function typescript(options?: Partial<IOptions>): {
|
||||
resolveId(importee: string, importer: string): string | null;
|
||||
load(id: string): string | undefined;
|
||||
transform(this: IRollupContext, code: string, id: string): ICode | undefined;
|
||||
ongenerate(bundleOptions: any): void;
|
||||
ongenerate(): void;
|
||||
onwrite({dest, file}: IRollupOptions): void;
|
||||
};
|
||||
|
||||
2
dist/print-diagnostics.d.ts
vendored
2
dist/print-diagnostics.d.ts
vendored
@ -1,3 +1,3 @@
|
||||
import { IContext } from "./context";
|
||||
import { IDiagnostics } from "./tscache";
|
||||
export declare function printDiagnostics(context: IContext, diagnostics: IDiagnostics[]): void;
|
||||
export declare function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty: boolean): void;
|
||||
|
||||
84
dist/rollup-plugin-typescript2.cjs.js
vendored
84
dist/rollup-plugin-typescript2.cjs.js
vendored
@ -6,8 +6,8 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
||||
var fs = require('fs');
|
||||
var crypto = _interopDefault(require('crypto'));
|
||||
var fsExtra = require('fs-extra');
|
||||
var resolve = require('resolve');
|
||||
var path = require('path');
|
||||
var resolve = require('resolve');
|
||||
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
@ -17239,7 +17239,7 @@ function setTypescriptModule(override) {
|
||||
tsModule = override;
|
||||
}
|
||||
|
||||
function normalize(fileName) {
|
||||
function normalize$1(fileName) {
|
||||
return fileName.split("\\").join("/");
|
||||
}
|
||||
|
||||
@ -17255,14 +17255,14 @@ var LanguageServiceHost = /** @class */ (function () {
|
||||
this.versions = {};
|
||||
};
|
||||
LanguageServiceHost.prototype.setSnapshot = function (fileName, data) {
|
||||
fileName = normalize(fileName);
|
||||
fileName = normalize$1(fileName);
|
||||
var snapshot = tsModule.ScriptSnapshot.fromString(data);
|
||||
this.snapshots[fileName] = snapshot;
|
||||
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
|
||||
return snapshot;
|
||||
};
|
||||
LanguageServiceHost.prototype.getScriptSnapshot = function (fileName) {
|
||||
fileName = normalize(fileName);
|
||||
fileName = normalize$1(fileName);
|
||||
if (lodash_8(this.snapshots, fileName))
|
||||
return this.snapshots[fileName];
|
||||
if (fs.existsSync(fileName)) {
|
||||
@ -17276,7 +17276,7 @@ var LanguageServiceHost = /** @class */ (function () {
|
||||
return this.cwd;
|
||||
};
|
||||
LanguageServiceHost.prototype.getScriptVersion = function (fileName) {
|
||||
fileName = normalize(fileName);
|
||||
fileName = normalize$1(fileName);
|
||||
return (this.versions[fileName] || 0).toString();
|
||||
};
|
||||
LanguageServiceHost.prototype.getScriptFileNames = function () {
|
||||
@ -19498,17 +19498,34 @@ var safe_3 = safe.red;
|
||||
var safe_4 = safe.yellow;
|
||||
var safe_5 = safe.blue;
|
||||
|
||||
var FormatHost = /** @class */ (function () {
|
||||
function FormatHost() {
|
||||
}
|
||||
FormatHost.prototype.getCurrentDirectory = function () {
|
||||
return tsModule.sys.getCurrentDirectory();
|
||||
};
|
||||
FormatHost.prototype.getCanonicalFileName = function (fileName) {
|
||||
return path.normalize(fileName);
|
||||
};
|
||||
FormatHost.prototype.getNewLine = function () {
|
||||
return tsModule.sys.newLine;
|
||||
};
|
||||
return FormatHost;
|
||||
}());
|
||||
var formatHost = new FormatHost();
|
||||
|
||||
function convertDiagnostic(type, data) {
|
||||
return lodash_7(data, function (diagnostic) {
|
||||
var entry = {
|
||||
flatMessage: tsModule.flattenDiagnosticMessageText(diagnostic.messageText, "\n"),
|
||||
formatted: tsModule.formatDiagnosticsWithColorAndContext(data, formatHost),
|
||||
category: diagnostic.category,
|
||||
code: diagnostic.code,
|
||||
type: type,
|
||||
};
|
||||
if (diagnostic.file && diagnostic.start !== undefined) {
|
||||
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character;
|
||||
entry.fileLine = diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + ")";
|
||||
entry.fileLine = diagnostic.file.fileName + "(" + (line + 1) + "," + (character + 1) + ")";
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
@ -19520,7 +19537,7 @@ var TsCache = /** @class */ (function () {
|
||||
this.options = options;
|
||||
this.rollupConfig = rollupConfig;
|
||||
this.context = context;
|
||||
this.cacheVersion = "6";
|
||||
this.cacheVersion = "7";
|
||||
this.ambientTypesDirty = false;
|
||||
this.cacheDir = cache + "/" + objectHash_2({
|
||||
version: this.cacheVersion,
|
||||
@ -19655,7 +19672,7 @@ var TsCache = /** @class */ (function () {
|
||||
return TsCache;
|
||||
}());
|
||||
|
||||
function printDiagnostics(context, diagnostics) {
|
||||
function printDiagnostics(context, diagnostics, pretty) {
|
||||
lodash_2(diagnostics, function (diagnostic) {
|
||||
var print;
|
||||
var color;
|
||||
@ -19679,10 +19696,14 @@ function printDiagnostics(context, diagnostics) {
|
||||
break;
|
||||
}
|
||||
var type = diagnostic.type + " ";
|
||||
if (diagnostic.fileLine)
|
||||
print.call(context, [diagnostic.fileLine + ": " + type + category + " TS" + diagnostic.code + " " + color(diagnostic.flatMessage)]);
|
||||
else
|
||||
print.call(context, ["" + type + category + " TS" + diagnostic.code + " " + color(diagnostic.flatMessage)]);
|
||||
if (pretty)
|
||||
print.call(context, ["" + diagnostic.formatted]);
|
||||
else {
|
||||
if (diagnostic.fileLine !== undefined)
|
||||
print.call(context, [diagnostic.fileLine + ": " + type + category + " TS" + diagnostic.code + " " + color(diagnostic.flatMessage)]);
|
||||
else
|
||||
print.call(context, ["" + type + category + " TS" + diagnostic.code + " " + color(diagnostic.flatMessage)]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -19700,7 +19721,7 @@ function parseTsConfig(tsconfig, context, pluginOptions) {
|
||||
var text = tsModule.sys.readFile(fileName);
|
||||
var result = tsModule.parseConfigFileTextToJson(fileName, text);
|
||||
if (result.error) {
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]));
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]), lodash_1(result.config, "pretty", false));
|
||||
throw new Error("failed to parse " + fileName);
|
||||
}
|
||||
lodash_14(result.config, pluginOptions.tsconfigOverride);
|
||||
@ -19729,8 +19750,7 @@ function typescript(options) {
|
||||
var createFilter = require("rollup-pluginutils").createFilter;
|
||||
// tslint:enable-next-line:no-var-requires
|
||||
var watchMode = false;
|
||||
var round = 0;
|
||||
var targetCount = 0;
|
||||
var generateRound = 0;
|
||||
var rollupOptions;
|
||||
var context;
|
||||
var filter;
|
||||
@ -19767,9 +19787,12 @@ function typescript(options) {
|
||||
rollupOptions = __assign({}, config);
|
||||
context = new ConsoleContext(pluginOptions.verbosity, "rpt2: ");
|
||||
context.info("typescript version: " + tsModule.version);
|
||||
context.info("rollup-plugin-typescript2 version: 0.8.4");
|
||||
context.info("rollup-plugin-typescript2 version: 0.9.0");
|
||||
context.debug(function () { return "plugin options:\n" + JSON.stringify(pluginOptions, function (key, value) { return key === "typescript" ? "version " + value.version : value; }, 4); });
|
||||
context.debug(function () { return "rollup config:\n" + JSON.stringify(rollupOptions, undefined, 4); });
|
||||
watchMode = process.env.ROLLUP_WATCH === "true";
|
||||
if (watchMode)
|
||||
context.info("running in watch mode");
|
||||
parsedConfig = parseTsConfig(pluginOptions.tsconfig, context, pluginOptions);
|
||||
if (parsedConfig.options.rootDirs) {
|
||||
var included_1 = lodash_16(parsedConfig.options.rootDirs)
|
||||
@ -19803,7 +19826,7 @@ function typescript(options) {
|
||||
service = tsModule.createLanguageService(servicesHost, tsModule.createDocumentRegistry());
|
||||
// printing compiler option errors
|
||||
if (pluginOptions.check)
|
||||
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()));
|
||||
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()), parsedConfig.options.pretty === true);
|
||||
if (pluginOptions.clean)
|
||||
cache().clean();
|
||||
},
|
||||
@ -19836,6 +19859,7 @@ function typescript(options) {
|
||||
},
|
||||
transform: function (code, id) {
|
||||
var _this = this;
|
||||
generateRound = 0; // in watch mode transform call resets generate count (used to avoid printing too many copies of the same error messages)
|
||||
if (!filter(id))
|
||||
return undefined;
|
||||
var contextWrapper = new RollupContext(pluginOptions.verbosity, pluginOptions.abortOnError, this, "rpt2: ");
|
||||
@ -19851,7 +19875,7 @@ function typescript(options) {
|
||||
}), cache().getSemanticDiagnostics(id, snapshot, function () {
|
||||
return service.getSemanticDiagnostics(id);
|
||||
}));
|
||||
printDiagnostics(contextWrapper, diagnostics);
|
||||
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
|
||||
// since no output was generated, aborting compilation
|
||||
cache().done();
|
||||
if (lodash_9(_this.error))
|
||||
@ -19874,42 +19898,36 @@ function typescript(options) {
|
||||
}));
|
||||
if (diagnostics.length > 0)
|
||||
noErrors = false;
|
||||
printDiagnostics(contextWrapper, diagnostics);
|
||||
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
|
||||
}
|
||||
if (result && result.dts) {
|
||||
var key_1 = normalize(id);
|
||||
var key_1 = normalize$1(id);
|
||||
declarations[key_1] = result.dts;
|
||||
context.debug(function () { return safe_5("generated declarations") + " for '" + key_1 + "'"; });
|
||||
result.dts = undefined;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
ongenerate: function (bundleOptions) {
|
||||
targetCount = lodash_1(bundleOptions, "targets.length", 1);
|
||||
if (round >= targetCount) {
|
||||
watchMode = true;
|
||||
round = 0;
|
||||
}
|
||||
context.debug(function () { return "generating target " + (round + 1) + " of " + targetCount; });
|
||||
if (watchMode && round === 0) {
|
||||
context.debug("running in watch mode");
|
||||
ongenerate: function () {
|
||||
context.debug(function () { return "generating target " + (generateRound + 1); });
|
||||
if (watchMode && generateRound === 0) {
|
||||
cache().walkTree(function (id) {
|
||||
if (!filter(id))
|
||||
return;
|
||||
var diagnostics = lodash_10(convertDiagnostic("syntax", service.getSyntacticDiagnostics(id)), convertDiagnostic("semantic", service.getSemanticDiagnostics(id)));
|
||||
printDiagnostics(context, diagnostics);
|
||||
printDiagnostics(context, diagnostics, parsedConfig.options.pretty === true);
|
||||
});
|
||||
}
|
||||
if (!watchMode && !noErrors)
|
||||
context.info(safe_4("there were errors or warnings above."));
|
||||
context.info(safe_4("there were errors or warnings."));
|
||||
cache().done();
|
||||
round++;
|
||||
generateRound++;
|
||||
},
|
||||
onwrite: function (_a) {
|
||||
var dest = _a.dest, file = _a.file;
|
||||
if (parsedConfig.options.declaration) {
|
||||
lodash_2(parsedConfig.fileNames, function (name) {
|
||||
var key = normalize(name);
|
||||
var key = normalize$1(name);
|
||||
if (lodash_8(declarations, key) || !filter(key))
|
||||
return;
|
||||
context.debug(function () { return "generating missed declarations for '" + key + "'"; });
|
||||
|
||||
2
dist/rollup-plugin-typescript2.cjs.js.map
vendored
2
dist/rollup-plugin-typescript2.cjs.js.map
vendored
File diff suppressed because one or more lines are too long
84
dist/rollup-plugin-typescript2.es.js
vendored
84
dist/rollup-plugin-typescript2.es.js
vendored
@ -2,8 +2,8 @@
|
||||
import { existsSync, readFileSync, readdirSync, renameSync } from 'fs';
|
||||
import crypto from 'crypto';
|
||||
import { emptyDirSync, ensureFileSync, readJsonSync, removeSync, writeJsonSync } from 'fs-extra';
|
||||
import { dirname, isAbsolute, join, normalize, relative } from 'path';
|
||||
import { sync } from 'resolve';
|
||||
import { dirname, isAbsolute, join, relative } from 'path';
|
||||
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
@ -17235,7 +17235,7 @@ function setTypescriptModule(override) {
|
||||
tsModule = override;
|
||||
}
|
||||
|
||||
function normalize(fileName) {
|
||||
function normalize$1(fileName) {
|
||||
return fileName.split("\\").join("/");
|
||||
}
|
||||
|
||||
@ -17251,14 +17251,14 @@ var LanguageServiceHost = /** @class */ (function () {
|
||||
this.versions = {};
|
||||
};
|
||||
LanguageServiceHost.prototype.setSnapshot = function (fileName, data) {
|
||||
fileName = normalize(fileName);
|
||||
fileName = normalize$1(fileName);
|
||||
var snapshot = tsModule.ScriptSnapshot.fromString(data);
|
||||
this.snapshots[fileName] = snapshot;
|
||||
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
|
||||
return snapshot;
|
||||
};
|
||||
LanguageServiceHost.prototype.getScriptSnapshot = function (fileName) {
|
||||
fileName = normalize(fileName);
|
||||
fileName = normalize$1(fileName);
|
||||
if (lodash_8(this.snapshots, fileName))
|
||||
return this.snapshots[fileName];
|
||||
if (existsSync(fileName)) {
|
||||
@ -17272,7 +17272,7 @@ var LanguageServiceHost = /** @class */ (function () {
|
||||
return this.cwd;
|
||||
};
|
||||
LanguageServiceHost.prototype.getScriptVersion = function (fileName) {
|
||||
fileName = normalize(fileName);
|
||||
fileName = normalize$1(fileName);
|
||||
return (this.versions[fileName] || 0).toString();
|
||||
};
|
||||
LanguageServiceHost.prototype.getScriptFileNames = function () {
|
||||
@ -19494,17 +19494,34 @@ var safe_3 = safe.red;
|
||||
var safe_4 = safe.yellow;
|
||||
var safe_5 = safe.blue;
|
||||
|
||||
var FormatHost = /** @class */ (function () {
|
||||
function FormatHost() {
|
||||
}
|
||||
FormatHost.prototype.getCurrentDirectory = function () {
|
||||
return tsModule.sys.getCurrentDirectory();
|
||||
};
|
||||
FormatHost.prototype.getCanonicalFileName = function (fileName) {
|
||||
return normalize(fileName);
|
||||
};
|
||||
FormatHost.prototype.getNewLine = function () {
|
||||
return tsModule.sys.newLine;
|
||||
};
|
||||
return FormatHost;
|
||||
}());
|
||||
var formatHost = new FormatHost();
|
||||
|
||||
function convertDiagnostic(type, data) {
|
||||
return lodash_7(data, function (diagnostic) {
|
||||
var entry = {
|
||||
flatMessage: tsModule.flattenDiagnosticMessageText(diagnostic.messageText, "\n"),
|
||||
formatted: tsModule.formatDiagnosticsWithColorAndContext(data, formatHost),
|
||||
category: diagnostic.category,
|
||||
code: diagnostic.code,
|
||||
type: type,
|
||||
};
|
||||
if (diagnostic.file && diagnostic.start !== undefined) {
|
||||
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character;
|
||||
entry.fileLine = diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + ")";
|
||||
entry.fileLine = diagnostic.file.fileName + "(" + (line + 1) + "," + (character + 1) + ")";
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
@ -19516,7 +19533,7 @@ var TsCache = /** @class */ (function () {
|
||||
this.options = options;
|
||||
this.rollupConfig = rollupConfig;
|
||||
this.context = context;
|
||||
this.cacheVersion = "6";
|
||||
this.cacheVersion = "7";
|
||||
this.ambientTypesDirty = false;
|
||||
this.cacheDir = cache + "/" + objectHash_2({
|
||||
version: this.cacheVersion,
|
||||
@ -19651,7 +19668,7 @@ var TsCache = /** @class */ (function () {
|
||||
return TsCache;
|
||||
}());
|
||||
|
||||
function printDiagnostics(context, diagnostics) {
|
||||
function printDiagnostics(context, diagnostics, pretty) {
|
||||
lodash_2(diagnostics, function (diagnostic) {
|
||||
var print;
|
||||
var color;
|
||||
@ -19675,10 +19692,14 @@ function printDiagnostics(context, diagnostics) {
|
||||
break;
|
||||
}
|
||||
var type = diagnostic.type + " ";
|
||||
if (diagnostic.fileLine)
|
||||
print.call(context, [diagnostic.fileLine + ": " + type + category + " TS" + diagnostic.code + " " + color(diagnostic.flatMessage)]);
|
||||
else
|
||||
print.call(context, ["" + type + category + " TS" + diagnostic.code + " " + color(diagnostic.flatMessage)]);
|
||||
if (pretty)
|
||||
print.call(context, ["" + diagnostic.formatted]);
|
||||
else {
|
||||
if (diagnostic.fileLine !== undefined)
|
||||
print.call(context, [diagnostic.fileLine + ": " + type + category + " TS" + diagnostic.code + " " + color(diagnostic.flatMessage)]);
|
||||
else
|
||||
print.call(context, ["" + type + category + " TS" + diagnostic.code + " " + color(diagnostic.flatMessage)]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -19696,7 +19717,7 @@ function parseTsConfig(tsconfig, context, pluginOptions) {
|
||||
var text = tsModule.sys.readFile(fileName);
|
||||
var result = tsModule.parseConfigFileTextToJson(fileName, text);
|
||||
if (result.error) {
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]));
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]), lodash_1(result.config, "pretty", false));
|
||||
throw new Error("failed to parse " + fileName);
|
||||
}
|
||||
lodash_14(result.config, pluginOptions.tsconfigOverride);
|
||||
@ -19725,8 +19746,7 @@ function typescript(options) {
|
||||
var createFilter = require("rollup-pluginutils").createFilter;
|
||||
// tslint:enable-next-line:no-var-requires
|
||||
var watchMode = false;
|
||||
var round = 0;
|
||||
var targetCount = 0;
|
||||
var generateRound = 0;
|
||||
var rollupOptions;
|
||||
var context;
|
||||
var filter;
|
||||
@ -19763,9 +19783,12 @@ function typescript(options) {
|
||||
rollupOptions = __assign({}, config);
|
||||
context = new ConsoleContext(pluginOptions.verbosity, "rpt2: ");
|
||||
context.info("typescript version: " + tsModule.version);
|
||||
context.info("rollup-plugin-typescript2 version: 0.8.4");
|
||||
context.info("rollup-plugin-typescript2 version: 0.9.0");
|
||||
context.debug(function () { return "plugin options:\n" + JSON.stringify(pluginOptions, function (key, value) { return key === "typescript" ? "version " + value.version : value; }, 4); });
|
||||
context.debug(function () { return "rollup config:\n" + JSON.stringify(rollupOptions, undefined, 4); });
|
||||
watchMode = process.env.ROLLUP_WATCH === "true";
|
||||
if (watchMode)
|
||||
context.info("running in watch mode");
|
||||
parsedConfig = parseTsConfig(pluginOptions.tsconfig, context, pluginOptions);
|
||||
if (parsedConfig.options.rootDirs) {
|
||||
var included_1 = lodash_16(parsedConfig.options.rootDirs)
|
||||
@ -19799,7 +19822,7 @@ function typescript(options) {
|
||||
service = tsModule.createLanguageService(servicesHost, tsModule.createDocumentRegistry());
|
||||
// printing compiler option errors
|
||||
if (pluginOptions.check)
|
||||
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()));
|
||||
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()), parsedConfig.options.pretty === true);
|
||||
if (pluginOptions.clean)
|
||||
cache().clean();
|
||||
},
|
||||
@ -19832,6 +19855,7 @@ function typescript(options) {
|
||||
},
|
||||
transform: function (code, id) {
|
||||
var _this = this;
|
||||
generateRound = 0; // in watch mode transform call resets generate count (used to avoid printing too many copies of the same error messages)
|
||||
if (!filter(id))
|
||||
return undefined;
|
||||
var contextWrapper = new RollupContext(pluginOptions.verbosity, pluginOptions.abortOnError, this, "rpt2: ");
|
||||
@ -19847,7 +19871,7 @@ function typescript(options) {
|
||||
}), cache().getSemanticDiagnostics(id, snapshot, function () {
|
||||
return service.getSemanticDiagnostics(id);
|
||||
}));
|
||||
printDiagnostics(contextWrapper, diagnostics);
|
||||
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
|
||||
// since no output was generated, aborting compilation
|
||||
cache().done();
|
||||
if (lodash_9(_this.error))
|
||||
@ -19870,42 +19894,36 @@ function typescript(options) {
|
||||
}));
|
||||
if (diagnostics.length > 0)
|
||||
noErrors = false;
|
||||
printDiagnostics(contextWrapper, diagnostics);
|
||||
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
|
||||
}
|
||||
if (result && result.dts) {
|
||||
var key_1 = normalize(id);
|
||||
var key_1 = normalize$1(id);
|
||||
declarations[key_1] = result.dts;
|
||||
context.debug(function () { return safe_5("generated declarations") + " for '" + key_1 + "'"; });
|
||||
result.dts = undefined;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
ongenerate: function (bundleOptions) {
|
||||
targetCount = lodash_1(bundleOptions, "targets.length", 1);
|
||||
if (round >= targetCount) {
|
||||
watchMode = true;
|
||||
round = 0;
|
||||
}
|
||||
context.debug(function () { return "generating target " + (round + 1) + " of " + targetCount; });
|
||||
if (watchMode && round === 0) {
|
||||
context.debug("running in watch mode");
|
||||
ongenerate: function () {
|
||||
context.debug(function () { return "generating target " + (generateRound + 1); });
|
||||
if (watchMode && generateRound === 0) {
|
||||
cache().walkTree(function (id) {
|
||||
if (!filter(id))
|
||||
return;
|
||||
var diagnostics = lodash_10(convertDiagnostic("syntax", service.getSyntacticDiagnostics(id)), convertDiagnostic("semantic", service.getSemanticDiagnostics(id)));
|
||||
printDiagnostics(context, diagnostics);
|
||||
printDiagnostics(context, diagnostics, parsedConfig.options.pretty === true);
|
||||
});
|
||||
}
|
||||
if (!watchMode && !noErrors)
|
||||
context.info(safe_4("there were errors or warnings above."));
|
||||
context.info(safe_4("there were errors or warnings."));
|
||||
cache().done();
|
||||
round++;
|
||||
generateRound++;
|
||||
},
|
||||
onwrite: function (_a) {
|
||||
var dest = _a.dest, file = _a.file;
|
||||
if (parsedConfig.options.declaration) {
|
||||
lodash_2(parsedConfig.fileNames, function (name) {
|
||||
var key = normalize(name);
|
||||
var key = normalize$1(name);
|
||||
if (lodash_8(declarations, key) || !filter(key))
|
||||
return;
|
||||
context.debug(function () { return "generating missed declarations for '" + key + "'"; });
|
||||
|
||||
2
dist/rollup-plugin-typescript2.es.js.map
vendored
2
dist/rollup-plugin-typescript2.es.js.map
vendored
File diff suppressed because one or more lines are too long
1
dist/tscache.d.ts
vendored
1
dist/tscache.d.ts
vendored
@ -7,6 +7,7 @@ export interface ICode {
|
||||
}
|
||||
export interface IDiagnostics {
|
||||
flatMessage: string;
|
||||
formatted: string;
|
||||
fileLine?: string;
|
||||
category: tsTypes.DiagnosticCategory;
|
||||
code: number;
|
||||
|
||||
16
package-lock.json
generated
16
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rollup-plugin-typescript2",
|
||||
"version": "0.8.4",
|
||||
"version": "0.9.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -12,7 +12,7 @@
|
||||
"@types/fs-extra": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-4.0.3.tgz",
|
||||
"integrity": "sha1-hzQ7GrmUFbYYF6yJTtYiNVoOv2c=",
|
||||
"integrity": "sha512-cUE7dc4RJsRPCk8mbrgMAaglugcJbf1Oxp7DYi/aOj4+ggCxzddDQFZwCKWnqrLv4LJ89apyNJ7Y3pN79tAPVg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "8.0.47"
|
||||
@ -26,13 +26,13 @@
|
||||
"@types/lodash": {
|
||||
"version": "4.14.80",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.80.tgz",
|
||||
"integrity": "sha1-pri3kA5qfcvC6Q2bbfvj9qf2mVE=",
|
||||
"integrity": "sha512-FumgRtCaxilKUcgMnZCzH6K3gntIwLiLLIaR+UBGNZpT/N3ne2dKrDSGoGIxSHYpAjnq6kIVV0r51U+kLXX59A==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "8.0.47",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.47.tgz",
|
||||
"integrity": "sha1-lo5Zb5Gs1ZBpBUVYoAcIxEXKMMI=",
|
||||
"integrity": "sha512-kOwL746WVvt/9Phf6/JgX/bsGQvbrK5iUgzyfwZNcKVFcjAUVSpF9HxevLTld2SG9aywYHOILj38arDdY1r/iQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/object-hash": {
|
||||
@ -673,9 +673,9 @@
|
||||
}
|
||||
},
|
||||
"rollup": {
|
||||
"version": "0.52.0",
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-0.52.0.tgz",
|
||||
"integrity": "sha512-IQ+t5uoeMSHpDyeJj4uFVWj+ocS8sUbFPNKCssyCac3GVgLs62nFH6UdU0nGLRIxjasPaN7wGHEioVXbxXRaYQ==",
|
||||
"version": "0.52.2",
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-0.52.2.tgz",
|
||||
"integrity": "sha512-1lSh5NghZu0H4QpA9wr4C1Y9lmgYK+p9MtVpriE6zpf5x3IXPbafc3k4Jfaw6upIT8eaVJLjDe4lcy7ByIYcOg==",
|
||||
"dev": true
|
||||
},
|
||||
"rollup-plugin-commonjs": {
|
||||
@ -730,7 +730,7 @@
|
||||
}
|
||||
},
|
||||
"rollup-plugin-typescript2": {
|
||||
"version": "github:ezolenko/rollup-plugin-typescript2#906db178ffb4311ae407227566cc09ffc55763a1",
|
||||
"version": "github:ezolenko/rollup-plugin-typescript2#d3f340c87a48c2f24bac0aa01a5a250373ca4c00",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fs-extra": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.2.tgz",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rollup-plugin-typescript2",
|
||||
"version": "0.8.5",
|
||||
"version": "0.9.0",
|
||||
"description": "Seamless integration between Rollup and TypeScript. Now with errors.",
|
||||
"main": "dist/rollup-plugin-typescript2.cjs.js",
|
||||
"module": "dist/rollup-plugin-typescript2.es.js",
|
||||
@ -53,7 +53,7 @@
|
||||
"@types/object-hash": "^1.1.0",
|
||||
"@types/resolve": "^0.0.4",
|
||||
"rimraf": "^2.6.2",
|
||||
"rollup": "^0.52.0",
|
||||
"rollup": "^0.52.2",
|
||||
"rollup-plugin-typescript2": "github:ezolenko/rollup-plugin-typescript2#master",
|
||||
"rollup-plugin-node-resolve": "^3.0.0",
|
||||
"rollup-plugin-commonjs": "^8.2.6",
|
||||
|
||||
23
src/diagnostics-format-host.ts
Normal file
23
src/diagnostics-format-host.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import * as path from "path";
|
||||
import * as tsTypes from "typescript";
|
||||
import { tsModule } from "./tsproxy";
|
||||
|
||||
export class FormatHost implements tsTypes.FormatDiagnosticsHost
|
||||
{
|
||||
public getCurrentDirectory(): string
|
||||
{
|
||||
return tsModule.sys.getCurrentDirectory();
|
||||
}
|
||||
|
||||
public getCanonicalFileName(fileName: string): string
|
||||
{
|
||||
return path.normalize(fileName);
|
||||
}
|
||||
|
||||
public getNewLine(): string
|
||||
{
|
||||
return tsModule.sys.newLine;
|
||||
}
|
||||
}
|
||||
|
||||
export const formatHost = new FormatHost();
|
||||
37
src/index.ts
37
src/index.ts
@ -22,8 +22,7 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
const createFilter = require("rollup-pluginutils").createFilter;
|
||||
// tslint:enable-next-line:no-var-requires
|
||||
let watchMode = false;
|
||||
let round = 0;
|
||||
let targetCount = 0;
|
||||
let generateRound = 0;
|
||||
let rollupOptions: IRollupOptions;
|
||||
let context: ConsoleContext;
|
||||
let filter: any;
|
||||
@ -75,6 +74,11 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
context.debug(() => `plugin options:\n${JSON.stringify(pluginOptions, (key, value) => key === "typescript" ? `version ${(value as typeof tsModule).version}` : value, 4)}`);
|
||||
context.debug(() => `rollup config:\n${JSON.stringify(rollupOptions, undefined, 4)}`);
|
||||
|
||||
watchMode = process.env.ROLLUP_WATCH === "true";
|
||||
|
||||
if (watchMode)
|
||||
context.info(`running in watch mode`);
|
||||
|
||||
parsedConfig = parseTsConfig(pluginOptions.tsconfig, context, pluginOptions);
|
||||
|
||||
if (parsedConfig.options.rootDirs)
|
||||
@ -120,7 +124,7 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
|
||||
// printing compiler option errors
|
||||
if (pluginOptions.check)
|
||||
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()));
|
||||
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()), parsedConfig.options.pretty === true);
|
||||
|
||||
if (pluginOptions.clean)
|
||||
cache().clean();
|
||||
@ -170,6 +174,8 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
|
||||
transform(this: IRollupContext, code: string, id: string): ICode | undefined
|
||||
{
|
||||
generateRound = 0; // in watch mode transform call resets generate count (used to avoid printing too many copies of the same error messages)
|
||||
|
||||
if (!filter(id))
|
||||
return undefined;
|
||||
|
||||
@ -197,7 +203,7 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
return service.getSemanticDiagnostics(id);
|
||||
}),
|
||||
);
|
||||
printDiagnostics(contextWrapper, diagnostics);
|
||||
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
|
||||
|
||||
// since no output was generated, aborting compilation
|
||||
cache().done();
|
||||
@ -232,7 +238,7 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
if (diagnostics.length > 0)
|
||||
noErrors = false;
|
||||
|
||||
printDiagnostics(contextWrapper, diagnostics);
|
||||
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
|
||||
}
|
||||
|
||||
if (result && result.dts)
|
||||
@ -246,21 +252,12 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
return result;
|
||||
},
|
||||
|
||||
ongenerate(bundleOptions: any): void
|
||||
ongenerate(): void
|
||||
{
|
||||
targetCount = _.get(bundleOptions, "targets.length", 1);
|
||||
context.debug(() => `generating target ${generateRound + 1}`);
|
||||
|
||||
if (round >= targetCount) // ongenerate() is called for each target
|
||||
if (watchMode && generateRound === 0)
|
||||
{
|
||||
watchMode = true;
|
||||
round = 0;
|
||||
}
|
||||
context.debug(() => `generating target ${round + 1} of ${targetCount}`);
|
||||
|
||||
if (watchMode && round === 0)
|
||||
{
|
||||
context.debug("running in watch mode");
|
||||
|
||||
cache().walkTree((id) =>
|
||||
{
|
||||
if (!filter(id))
|
||||
@ -271,16 +268,16 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
convertDiagnostic("semantic", service.getSemanticDiagnostics(id)),
|
||||
);
|
||||
|
||||
printDiagnostics(context, diagnostics);
|
||||
printDiagnostics(context, diagnostics, parsedConfig.options.pretty === true);
|
||||
});
|
||||
}
|
||||
|
||||
if (!watchMode && !noErrors)
|
||||
context.info(yellow("there were errors or warnings above."));
|
||||
context.info(yellow("there were errors or warnings."));
|
||||
|
||||
cache().done();
|
||||
|
||||
round++;
|
||||
generateRound++;
|
||||
},
|
||||
|
||||
onwrite({ dest, file }: IRollupOptions)
|
||||
|
||||
@ -20,7 +20,7 @@ export function parseTsConfig(tsconfig: string, context: IContext, pluginOptions
|
||||
|
||||
if (result.error)
|
||||
{
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]));
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]), _.get(result.config, "pretty", false));
|
||||
throw new Error(`failed to parse ${fileName}`);
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import { IContext } from "./context";
|
||||
import { IDiagnostics } from "./tscache";
|
||||
import * as _ from "lodash";
|
||||
|
||||
export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[]): void
|
||||
export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty: boolean): void
|
||||
{
|
||||
_.each(diagnostics, (diagnostic) =>
|
||||
{
|
||||
@ -33,9 +33,14 @@ export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[])
|
||||
|
||||
const type = diagnostic.type + " ";
|
||||
|
||||
if (diagnostic.fileLine)
|
||||
print.call(context, [`${diagnostic.fileLine}: ${type}${category} TS${diagnostic.code} ${color(diagnostic.flatMessage)}`]);
|
||||
if (pretty)
|
||||
print.call(context, [`${diagnostic.formatted}`]);
|
||||
else
|
||||
print.call(context, [`${type}${category} TS${diagnostic.code} ${color(diagnostic.flatMessage)}`]);
|
||||
{
|
||||
if (diagnostic.fileLine !== undefined)
|
||||
print.call(context, [`${diagnostic.fileLine}: ${type}${category} TS${diagnostic.code} ${color(diagnostic.flatMessage)}`]);
|
||||
else
|
||||
print.call(context, [`${type}${category} TS${diagnostic.code} ${color(diagnostic.flatMessage)}`]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import { tsModule } from "./tsproxy";
|
||||
import * as tsTypes from "typescript";
|
||||
import { blue, yellow, green } from "colors/safe";
|
||||
import { emptyDirSync } from "fs-extra";
|
||||
import { formatHost } from "./diagnostics-format-host";
|
||||
|
||||
export interface ICode
|
||||
{
|
||||
@ -24,6 +25,7 @@ interface INodeLabel
|
||||
export interface IDiagnostics
|
||||
{
|
||||
flatMessage: string;
|
||||
formatted: string;
|
||||
fileLine?: string;
|
||||
category: tsTypes.DiagnosticCategory;
|
||||
code: number;
|
||||
@ -43,6 +45,7 @@ export function convertDiagnostic(type: string, data: tsTypes.Diagnostic[]): IDi
|
||||
const entry: IDiagnostics =
|
||||
{
|
||||
flatMessage: tsModule.flattenDiagnosticMessageText(diagnostic.messageText, "\n"),
|
||||
formatted: tsModule.formatDiagnosticsWithColorAndContext(data, formatHost),
|
||||
category: diagnostic.category,
|
||||
code: diagnostic.code,
|
||||
type,
|
||||
@ -51,7 +54,7 @@ export function convertDiagnostic(type: string, data: tsTypes.Diagnostic[]): IDi
|
||||
if (diagnostic.file && diagnostic.start !== undefined)
|
||||
{
|
||||
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
||||
entry.fileLine = `${diagnostic.file.fileName} (${line + 1},${character + 1})`;
|
||||
entry.fileLine = `${diagnostic.file.fileName}(${line + 1},${character + 1})`;
|
||||
}
|
||||
|
||||
return entry;
|
||||
@ -60,7 +63,7 @@ export function convertDiagnostic(type: string, data: tsTypes.Diagnostic[]): IDi
|
||||
|
||||
export class TsCache
|
||||
{
|
||||
private cacheVersion = "6";
|
||||
private cacheVersion = "7";
|
||||
private dependencyTree: Graph;
|
||||
private ambientTypes: ITypeSnapshot[];
|
||||
private ambientTypesDirty = false;
|
||||
|
||||
@ -15,7 +15,8 @@
|
||||
"strictNullChecks": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noImplicitReturns": true,
|
||||
"declaration": true
|
||||
"declaration": true,
|
||||
"outDir": "./build"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user