abortOnError/abortOnWarning/continueAfterFirstError #168

This commit is contained in:
Eugene Zolenko 2019-08-22 17:50:53 -06:00
parent b0a0ecb5ee
commit a4bb50b9b7
22 changed files with 169 additions and 126 deletions

4
dist/context.d.ts vendored
View File

@ -1,6 +1,6 @@
export interface IContext {
warn(message: string | (() => string)): void;
error(message: string | (() => string)): void;
warn(message: string | (() => string), lastMessage?: boolean): void;
error(message: string | (() => string), lastMessage?: boolean): void;
info(message: string | (() => string)): void;
debug(message: string | (() => string)): void;
}

View File

@ -1 +1 @@
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["src/context.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,QAAQ;IAExB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC;IAC7C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC;IAC9C,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC;IAC7C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC;CAC9C;AAED,oBAAY,cAAc;IAEzB,KAAK,IAAI;IACT,OAAO,IAAA;IACP,IAAI,IAAA;IACJ,KAAK,IAAA;CACL;AAED,qBAAa,cAAe,YAAW,QAAQ;IAElC,OAAO,CAAC,SAAS;IAAkB,OAAO,CAAC,MAAM;gBAAzC,SAAS,EAAE,cAAc,EAAU,MAAM,GAAE,MAAW;IAInE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;IAO5C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;IAO7C,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;IAO5C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;CAMpD"}
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["src/context.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,QAAQ;IAExB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACpE,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACrE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC;IAC7C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC;CAC9C;AAED,oBAAY,cAAc;IAEzB,KAAK,IAAI;IACT,OAAO,IAAA;IACP,IAAI,IAAA;IACJ,KAAK,IAAA;CACL;AAED,qBAAa,cAAe,YAAW,QAAQ;IAElC,OAAO,CAAC,SAAS;IAAkB,OAAO,CAAC,MAAM;gBAAzC,SAAS,EAAE,cAAc,EAAU,MAAM,GAAE,MAAW;IAInE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;IAO5C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;IAO7C,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;IAO5C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;CAMpD"}

2
dist/index.d.ts.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,OAAO,EAAE,UAAU,EAAgG,MAAM,QAAQ,CAAC;AAGlI,QAAA,MAAM,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAsW7C,CAAC;AAEF,eAAe,UAAU,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,OAAO,EAAE,UAAU,EAA8G,MAAM,QAAQ,CAAC;AAGhJ,QAAA,MAAM,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAyW7C,CAAC;AAEF,eAAe,UAAU,CAAC"}

2
dist/ioptions.d.ts vendored
View File

@ -13,6 +13,8 @@ export interface IOptions {
clean: boolean;
cacheRoot: string;
abortOnError: boolean;
abortOnWarning: boolean;
continueAfterFirstError: boolean;
rollupCommonJSResolveHack: boolean;
tsconfig?: string;
useTsconfigDeclarationDir: boolean;

View File

@ -1 +1 @@
{"version":3,"file":"ioptions.d.ts","sourceRoot":"","sources":["src/ioptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAEtC,MAAM,WAAW,kBAAkB;IAElC,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACxD,KAAK,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;CACvD;AAED,oBAAY,yBAAyB,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,eAAe,KAAK,OAAO,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;AAEzH,MAAM,WAAW,QAAQ;IAExB,OAAO,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC;IACzB,OAAO,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,yBAAyB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yBAAyB,EAAE,OAAO,CAAC;IACnC,UAAU,EAAE,OAAO,QAAQ,CAAC;IAC5B,gBAAgB,EAAE,GAAG,CAAC;IACtB,YAAY,EAAE,yBAAyB,EAAE,CAAC;IAC1C,gBAAgB,EAAE,GAAG,CAAC;IACtB,iBAAiB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,2BAA2B,EAAE,OAAO,CAAC;CACrC"}
{"version":3,"file":"ioptions.d.ts","sourceRoot":"","sources":["src/ioptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAEtC,MAAM,WAAW,kBAAkB;IAElC,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACxD,KAAK,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;CACvD;AAED,oBAAY,yBAAyB,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,eAAe,KAAK,OAAO,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;AAEzH,MAAM,WAAW,QAAQ;IAExB,OAAO,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC;IACzB,OAAO,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,uBAAuB,EAAE,OAAO,CAAC;IACjC,yBAAyB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yBAAyB,EAAE,OAAO,CAAC;IACnC,UAAU,EAAE,OAAO,QAAQ,CAAC;IAC5B,gBAAgB,EAAE,GAAG,CAAC;IACtB,YAAY,EAAE,yBAAyB,EAAE,CAAC;IAC1C,gBAAgB,EAAE,GAAG,CAAC;IACtB,iBAAiB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,2BAA2B,EAAE,OAAO,CAAC;CACrC"}

View File

@ -1,6 +1,9 @@
import { IContext } from "./context";
import { IOptions } from "./ioptions";
export declare function parseTsConfig(context: IContext, pluginOptions: IOptions): {
export declare function parseTsConfig(context: IContext, pluginOptions: IOptions, buildStatus: {
error: boolean;
warning: boolean;
}): {
parsedTsConfig: import("typescript").ParsedCommandLine;
fileName: string | undefined;
};

View File

@ -1 +1 @@
{"version":3,"file":"parse-tsconfig.d.ts","sourceRoot":"","sources":["src/parse-tsconfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAKrC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,wBAAgB,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ;;;EA8CvE"}
{"version":3,"file":"parse-tsconfig.d.ts","sourceRoot":"","sources":["src/parse-tsconfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAKrC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,wBAAgB,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE;;;EA+C1H"}

View File

@ -1,4 +1,7 @@
import { IContext } from "./context";
import { IDiagnostics } from "./tscache";
export declare function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty: boolean): void;
export declare function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty: boolean, buildStatus: {
error: boolean;
warning: boolean;
}): void;
//# sourceMappingURL=print-diagnostics.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"print-diagnostics.d.ts","sourceRoot":"","sources":["src/print-diagnostics.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAuCtG"}
{"version":3,"file":"print-diagnostics.d.ts","sourceRoot":"","sources":["src/print-diagnostics.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAyCzJ"}

View File

@ -17166,29 +17166,32 @@ class ConsoleContext {
}
class RollupContext {
constructor(verbosity, bail, context, prefix = "") {
this.verbosity = verbosity;
this.bail = bail;
constructor(options, context, prefix = "") {
this.options = options;
this.context = context;
this.prefix = prefix;
this.hasContext = true;
this.hasContext = lodash_10(this.context.warn) && lodash_10(this.context.error);
}
warn(message) {
if (this.verbosity < VerbosityLevel.Warning)
return;
const text = lodash_10(message) ? message() : message;
if (this.hasContext)
this.context.warn(`${text}`);
else
console.log(`${this.prefix}${text}`);
}
error(message) {
if (this.verbosity < VerbosityLevel.Error)
warn(message, lastMessage) {
if (this.options.verbosity < VerbosityLevel.Warning)
return;
const text = lodash_10(message) ? message() : message;
if (this.hasContext) {
if (this.bail)
if (this.options.abortOnWarning && (!this.options.continueAfterFirstError || lastMessage))
this.context.error(`${text}`);
else
this.context.warn(`${text}`);
}
else
console.log(`${this.prefix}${text}`);
}
error(message, lastMessage) {
if (this.options.verbosity < VerbosityLevel.Error)
return;
const text = lodash_10(message) ? message() : message;
if (this.hasContext) {
if (this.options.abortOnError && (!this.options.continueAfterFirstError || lastMessage))
this.context.error(`${text}`);
else
this.context.warn(`${text}`);
@ -17197,13 +17200,13 @@ class RollupContext {
console.log(`${this.prefix}${text}`);
}
info(message) {
if (this.verbosity < VerbosityLevel.Info)
if (this.options.verbosity < VerbosityLevel.Info)
return;
const text = lodash_10(message) ? message() : message;
console.log(`${this.prefix}${text}`);
}
debug(message) {
if (this.verbosity < VerbosityLevel.Debug)
if (this.options.verbosity < VerbosityLevel.Debug)
return;
const text = lodash_10(message) ? message() : message;
console.log(`${this.prefix}${text}`);
@ -24922,7 +24925,7 @@ class TsCache {
}
}
function printDiagnostics(context, diagnostics, pretty) {
function printDiagnostics(context, diagnostics, pretty, buildStatus) {
lodash_3(diagnostics, (diagnostic) => {
let print;
let color;
@ -24937,12 +24940,14 @@ function printDiagnostics(context, diagnostics, pretty) {
print = context.error;
color = safe_3;
category = "error";
buildStatus.error = true;
break;
case tsModule.DiagnosticCategory.Warning:
default:
print = context.warn;
color = safe_4;
category = "warning";
buildStatus.warning = true;
break;
}
const type = diagnostic.type + " ";
@ -25018,7 +25023,7 @@ function checkTsConfig(parsedConfig) {
throw new Error(`Incompatible tsconfig option. Module resolves to '${tsModule.ModuleKind[module]}'. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.`);
}
function parseTsConfig(context, pluginOptions) {
function parseTsConfig(context, pluginOptions, buildStatus) {
const fileName = tsModule.findConfigFile(process.cwd(), tsModule.sys.fileExists, pluginOptions.tsconfig);
// if the value was provided, but no file, fail hard
if (pluginOptions.tsconfig !== undefined && !fileName)
@ -25034,7 +25039,7 @@ function parseTsConfig(context, pluginOptions) {
const result = tsModule.parseConfigFileTextToJson(fileName, text);
pretty = lodash_2(result.config, "pretty", pretty);
if (result.error !== undefined) {
printDiagnostics(context, convertDiagnostic("config", [result.error]), pretty);
printDiagnostics(context, convertDiagnostic("config", [result.error]), pretty, buildStatus);
throw new Error(`failed to parse '${fileName}'`);
}
loadedConfig = result.config;
@ -25047,7 +25052,7 @@ function parseTsConfig(context, pluginOptions) {
const compilerOptionsOverride = getOptionsOverrides(pluginOptions, preParsedTsConfig);
const parsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, compilerOptionsOverride, configFileName);
checkTsConfig(parsedTsConfig);
printDiagnostics(context, convertDiagnostic("config", parsedTsConfig.errors), pretty);
printDiagnostics(context, convertDiagnostic("config", parsedTsConfig.errors), pretty, buildStatus);
context.debug(`built-in options overrides: ${JSON.stringify(compilerOptionsOverride, undefined, 4)}`);
context.debug(`parsed tsconfig: ${JSON.stringify(parsedTsConfig, undefined, 4)}`);
return { parsedTsConfig, fileName };
@ -26712,7 +26717,7 @@ const typescript = (options) => {
let tsConfigPath;
let servicesHost;
let service;
let noErrors = true;
const buildStatus = { error: false, warning: false };
const declarations = {};
const allImportedFiles = new Set();
let _cache;
@ -26730,6 +26735,8 @@ const typescript = (options) => {
include: ["*.ts+(|x)", "**/*.ts+(|x)"],
exclude: ["*.d.ts", "**/*.d.ts"],
abortOnError: true,
abortOnWarning: true,
continueAfterFirstError: false,
rollupCommonJSResolveHack: false,
tsconfig: undefined,
useTsconfigDeclarationDir: false,
@ -26748,7 +26755,7 @@ const typescript = (options) => {
rollupOptions = Object.assign({}, config);
context = new ConsoleContext(pluginOptions.verbosity, "rpt2: ");
watchMode = process.env.ROLLUP_WATCH === "true";
({ parsedTsConfig: parsedConfig, fileName: tsConfigPath } = parseTsConfig(context, pluginOptions));
({ parsedTsConfig: parsedConfig, fileName: tsConfigPath } = parseTsConfig(context, pluginOptions, buildStatus));
if (generateRound === 0) {
context.info(`typescript version: ${tsModule.version}`);
context.info(`tslib version: ${tslibVersion}`);
@ -26769,7 +26776,7 @@ const typescript = (options) => {
servicesHost.setLanguageService(service);
// printing compiler option errors
if (pluginOptions.check)
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()), parsedConfig.options.pretty === true);
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()), parsedConfig.options.pretty === true, buildStatus);
if (pluginOptions.clean)
cache().clean();
return config;
@ -26813,20 +26820,19 @@ const typescript = (options) => {
if (!filter(id))
return undefined;
allImportedFiles.add(normalize(id));
const contextWrapper = new RollupContext(pluginOptions.verbosity, pluginOptions.abortOnError, this, "rpt2: ");
const contextWrapper = new RollupContext(pluginOptions, this, "rpt2: ");
const snapshot = servicesHost.setSnapshot(id, code);
// getting compiled file from cache or from ts
const result = cache().getCompiled(id, snapshot, () => {
const output = service.getEmitOutput(id);
if (output.emitSkipped) {
noErrors = false;
// always checking on fatal errors, even if options.check is set to false
const diagnostics = lodash_11(cache().getSyntacticDiagnostics(id, snapshot, () => {
return service.getSyntacticDiagnostics(id);
}), cache().getSemanticDiagnostics(id, snapshot, () => {
return service.getSemanticDiagnostics(id);
}));
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true, buildStatus);
// since no output was generated, aborting compilation
cache().done();
if (lodash_10(this.error))
@ -26841,9 +26847,7 @@ const typescript = (options) => {
}), cache().getSemanticDiagnostics(id, snapshot, () => {
return service.getSemanticDiagnostics(id);
}));
if (diagnostics.length > 0)
noErrors = false;
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true, buildStatus);
}
if (result) {
if (result.references)
@ -26889,11 +26893,9 @@ const typescript = (options) => {
}), cache().getSemanticDiagnostics(id, snapshot, () => {
return service.getSemanticDiagnostics(id);
}));
printDiagnostics(context, diagnostics, parsedConfig.options.pretty === true);
printDiagnostics(context, diagnostics, parsedConfig.options.pretty === true, buildStatus);
});
}
if (!watchMode && !noErrors)
context.info(safe_4("there were errors or warnings."));
cache().done();
generateRound++;
},
@ -26942,6 +26944,13 @@ const typescript = (options) => {
writeDeclaration(key, ".d.ts.map", map);
});
},
buildEnd(_err) {
const contextWrapper = new RollupContext(pluginOptions, this, "rpt2: ");
if (buildStatus.error)
contextWrapper.error(safe_3("there were errors in typescript build."), true);
else if (buildStatus.warning)
contextWrapper.warn(safe_4("there were warnings in typescript build."), true);
},
};
return self;
};

File diff suppressed because one or more lines are too long

View File

@ -17162,29 +17162,32 @@ class ConsoleContext {
}
class RollupContext {
constructor(verbosity, bail, context, prefix = "") {
this.verbosity = verbosity;
this.bail = bail;
constructor(options, context, prefix = "") {
this.options = options;
this.context = context;
this.prefix = prefix;
this.hasContext = true;
this.hasContext = lodash_10(this.context.warn) && lodash_10(this.context.error);
}
warn(message) {
if (this.verbosity < VerbosityLevel.Warning)
return;
const text = lodash_10(message) ? message() : message;
if (this.hasContext)
this.context.warn(`${text}`);
else
console.log(`${this.prefix}${text}`);
}
error(message) {
if (this.verbosity < VerbosityLevel.Error)
warn(message, lastMessage) {
if (this.options.verbosity < VerbosityLevel.Warning)
return;
const text = lodash_10(message) ? message() : message;
if (this.hasContext) {
if (this.bail)
if (this.options.abortOnWarning && (!this.options.continueAfterFirstError || lastMessage))
this.context.error(`${text}`);
else
this.context.warn(`${text}`);
}
else
console.log(`${this.prefix}${text}`);
}
error(message, lastMessage) {
if (this.options.verbosity < VerbosityLevel.Error)
return;
const text = lodash_10(message) ? message() : message;
if (this.hasContext) {
if (this.options.abortOnError && (!this.options.continueAfterFirstError || lastMessage))
this.context.error(`${text}`);
else
this.context.warn(`${text}`);
@ -17193,13 +17196,13 @@ class RollupContext {
console.log(`${this.prefix}${text}`);
}
info(message) {
if (this.verbosity < VerbosityLevel.Info)
if (this.options.verbosity < VerbosityLevel.Info)
return;
const text = lodash_10(message) ? message() : message;
console.log(`${this.prefix}${text}`);
}
debug(message) {
if (this.verbosity < VerbosityLevel.Debug)
if (this.options.verbosity < VerbosityLevel.Debug)
return;
const text = lodash_10(message) ? message() : message;
console.log(`${this.prefix}${text}`);
@ -24918,7 +24921,7 @@ class TsCache {
}
}
function printDiagnostics(context, diagnostics, pretty) {
function printDiagnostics(context, diagnostics, pretty, buildStatus) {
lodash_3(diagnostics, (diagnostic) => {
let print;
let color;
@ -24933,12 +24936,14 @@ function printDiagnostics(context, diagnostics, pretty) {
print = context.error;
color = safe_3;
category = "error";
buildStatus.error = true;
break;
case tsModule.DiagnosticCategory.Warning:
default:
print = context.warn;
color = safe_4;
category = "warning";
buildStatus.warning = true;
break;
}
const type = diagnostic.type + " ";
@ -25014,7 +25019,7 @@ function checkTsConfig(parsedConfig) {
throw new Error(`Incompatible tsconfig option. Module resolves to '${tsModule.ModuleKind[module]}'. This is incompatible with rollup, please use 'module: "ES2015"' or 'module: "ESNext"'.`);
}
function parseTsConfig(context, pluginOptions) {
function parseTsConfig(context, pluginOptions, buildStatus) {
const fileName = tsModule.findConfigFile(process.cwd(), tsModule.sys.fileExists, pluginOptions.tsconfig);
// if the value was provided, but no file, fail hard
if (pluginOptions.tsconfig !== undefined && !fileName)
@ -25030,7 +25035,7 @@ function parseTsConfig(context, pluginOptions) {
const result = tsModule.parseConfigFileTextToJson(fileName, text);
pretty = lodash_2(result.config, "pretty", pretty);
if (result.error !== undefined) {
printDiagnostics(context, convertDiagnostic("config", [result.error]), pretty);
printDiagnostics(context, convertDiagnostic("config", [result.error]), pretty, buildStatus);
throw new Error(`failed to parse '${fileName}'`);
}
loadedConfig = result.config;
@ -25043,7 +25048,7 @@ function parseTsConfig(context, pluginOptions) {
const compilerOptionsOverride = getOptionsOverrides(pluginOptions, preParsedTsConfig);
const parsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, compilerOptionsOverride, configFileName);
checkTsConfig(parsedTsConfig);
printDiagnostics(context, convertDiagnostic("config", parsedTsConfig.errors), pretty);
printDiagnostics(context, convertDiagnostic("config", parsedTsConfig.errors), pretty, buildStatus);
context.debug(`built-in options overrides: ${JSON.stringify(compilerOptionsOverride, undefined, 4)}`);
context.debug(`parsed tsconfig: ${JSON.stringify(parsedTsConfig, undefined, 4)}`);
return { parsedTsConfig, fileName };
@ -26708,7 +26713,7 @@ const typescript = (options) => {
let tsConfigPath;
let servicesHost;
let service;
let noErrors = true;
const buildStatus = { error: false, warning: false };
const declarations = {};
const allImportedFiles = new Set();
let _cache;
@ -26726,6 +26731,8 @@ const typescript = (options) => {
include: ["*.ts+(|x)", "**/*.ts+(|x)"],
exclude: ["*.d.ts", "**/*.d.ts"],
abortOnError: true,
abortOnWarning: true,
continueAfterFirstError: false,
rollupCommonJSResolveHack: false,
tsconfig: undefined,
useTsconfigDeclarationDir: false,
@ -26744,7 +26751,7 @@ const typescript = (options) => {
rollupOptions = Object.assign({}, config);
context = new ConsoleContext(pluginOptions.verbosity, "rpt2: ");
watchMode = process.env.ROLLUP_WATCH === "true";
({ parsedTsConfig: parsedConfig, fileName: tsConfigPath } = parseTsConfig(context, pluginOptions));
({ parsedTsConfig: parsedConfig, fileName: tsConfigPath } = parseTsConfig(context, pluginOptions, buildStatus));
if (generateRound === 0) {
context.info(`typescript version: ${tsModule.version}`);
context.info(`tslib version: ${tslibVersion}`);
@ -26765,7 +26772,7 @@ const typescript = (options) => {
servicesHost.setLanguageService(service);
// printing compiler option errors
if (pluginOptions.check)
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()), parsedConfig.options.pretty === true);
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()), parsedConfig.options.pretty === true, buildStatus);
if (pluginOptions.clean)
cache().clean();
return config;
@ -26809,20 +26816,19 @@ const typescript = (options) => {
if (!filter(id))
return undefined;
allImportedFiles.add(normalize(id));
const contextWrapper = new RollupContext(pluginOptions.verbosity, pluginOptions.abortOnError, this, "rpt2: ");
const contextWrapper = new RollupContext(pluginOptions, this, "rpt2: ");
const snapshot = servicesHost.setSnapshot(id, code);
// getting compiled file from cache or from ts
const result = cache().getCompiled(id, snapshot, () => {
const output = service.getEmitOutput(id);
if (output.emitSkipped) {
noErrors = false;
// always checking on fatal errors, even if options.check is set to false
const diagnostics = lodash_11(cache().getSyntacticDiagnostics(id, snapshot, () => {
return service.getSyntacticDiagnostics(id);
}), cache().getSemanticDiagnostics(id, snapshot, () => {
return service.getSemanticDiagnostics(id);
}));
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true, buildStatus);
// since no output was generated, aborting compilation
cache().done();
if (lodash_10(this.error))
@ -26837,9 +26843,7 @@ const typescript = (options) => {
}), cache().getSemanticDiagnostics(id, snapshot, () => {
return service.getSemanticDiagnostics(id);
}));
if (diagnostics.length > 0)
noErrors = false;
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true, buildStatus);
}
if (result) {
if (result.references)
@ -26885,11 +26889,9 @@ const typescript = (options) => {
}), cache().getSemanticDiagnostics(id, snapshot, () => {
return service.getSemanticDiagnostics(id);
}));
printDiagnostics(context, diagnostics, parsedConfig.options.pretty === true);
printDiagnostics(context, diagnostics, parsedConfig.options.pretty === true, buildStatus);
});
}
if (!watchMode && !noErrors)
context.info(safe_4("there were errors or warnings."));
cache().done();
generateRound++;
},
@ -26938,6 +26940,13 @@ const typescript = (options) => {
writeDeclaration(key, ".d.ts.map", map);
});
},
buildEnd(_err) {
const contextWrapper = new RollupContext(pluginOptions, this, "rpt2: ");
if (buildStatus.error)
contextWrapper.error(safe_3("there were errors in typescript build."), true);
else if (buildStatus.warning)
contextWrapper.warn(safe_4("there were warnings in typescript build."), true);
},
};
return self;
};

File diff suppressed because one or more lines are too long

View File

@ -1,14 +1,18 @@
import { IContext, VerbosityLevel } from "./context";
import { PluginContext } from "rollup";
export declare class RollupContext implements IContext {
private verbosity;
private bail;
private options;
private context;
private prefix;
private hasContext;
constructor(verbosity: VerbosityLevel, bail: boolean, context: PluginContext, prefix?: string);
warn(message: string | (() => string)): void;
error(message: string | (() => string)): void;
constructor(options: {
verbosity: VerbosityLevel;
abortOnError: boolean;
abortOnWarning: boolean;
continueAfterFirstError: boolean;
}, context: PluginContext, prefix?: string);
warn(message: string | (() => string), lastMessage?: boolean): void;
error(message: string | (() => string), lastMessage?: boolean): void;
info(message: string | (() => string)): void;
debug(message: string | (() => string)): void;
}

View File

@ -1 +1 @@
{"version":3,"file":"rollupcontext.d.ts","sourceRoot":"","sources":["src/rollupcontext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,qBAAa,aAAc,YAAW,QAAQ;IAIjC,OAAO,CAAC,SAAS;IAAkB,OAAO,CAAC,IAAI;IAAW,OAAO,CAAC,OAAO;IAAiB,OAAO,CAAC,MAAM;IAFpH,OAAO,CAAC,UAAU,CAAiB;gBAEf,SAAS,EAAE,cAAc,EAAU,IAAI,EAAE,OAAO,EAAU,OAAO,EAAE,aAAa,EAAU,MAAM,GAAE,MAAW;IAK1H,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;IAa5C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;IAkB7C,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;IAU5C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;CASpD"}
{"version":3,"file":"rollupcontext.d.ts","sourceRoot":"","sources":["src/rollupcontext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,qBAAa,aAAc,YAAW,QAAQ;IAIjC,OAAO,CAAC,OAAO;IAAkH,OAAO,CAAC,OAAO;IAAiB,OAAO,CAAC,MAAM;IAF3L,OAAO,CAAC,UAAU,CAAiB;gBAEf,OAAO,EAAE;QAAE,SAAS,EAAE,cAAc,CAAC;QAAC,YAAY,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAC;QAAC,uBAAuB,EAAE,OAAO,CAAA;KAAC,EAAU,OAAO,EAAE,aAAa,EAAU,MAAM,GAAE,MAAW;IAKjM,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI;IAkBnE,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI;IAkBpE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;IAU5C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,IAAI;CASpD"}

View File

@ -2,6 +2,6 @@ import ts from "./build-self/dist/rollup-plugin-typescript2.es";
import config from "./rollup.config.base";
config.plugins.push(ts({ verbosity: 2, abortOnError: false, clean: false }));
config.plugins.push(ts({ verbosity: 2, abortOnError: true, continueAfterFirstError: true, clean: false }));
export default config;

View File

@ -3,8 +3,8 @@ import * as _ from "lodash";
export interface IContext
{
warn(message: string | (() => string)): void;
error(message: string | (() => string)): void;
warn(message: string | (() => string), lastMessage?: boolean): void;
error(message: string | (() => string), lastMessage?: boolean): void;
info(message: string | (() => string)): void;
debug(message: string | (() => string)): void;
}

View File

@ -16,7 +16,7 @@ import { dirname, isAbsolute, join, relative } from "path";
import { normalize } from "./normalize";
import { satisfies } from "semver";
import { PluginImpl, PluginContext, InputOptions, OutputOptions, TransformSourceDescription, MinimalPluginContext } from "rollup";
import { PluginImpl, PluginContext, InputOptions, OutputOptions, TransformSourceDescription, MinimalPluginContext, OutputBundle } from "rollup";
import { createFilter } from "./get-options-overrides";
const typescript: PluginImpl<Partial<IOptions>> = (options) =>
@ -30,7 +30,7 @@ const typescript: PluginImpl<Partial<IOptions>> = (options) =>
let tsConfigPath: string | undefined;
let servicesHost: LanguageServiceHost;
let service: tsTypes.LanguageService;
let noErrors = true;
const buildStatus = { error: false, warning: false };
const declarations: { [name: string]: { type: tsTypes.OutputFile; map?: tsTypes.OutputFile } } = {};
const allImportedFiles = new Set();
@ -53,6 +53,8 @@ const typescript: PluginImpl<Partial<IOptions>> = (options) =>
include: ["*.ts+(|x)", "**/*.ts+(|x)"],
exclude: ["*.d.ts", "**/*.d.ts"],
abortOnError: true,
abortOnWarning: true,
continueAfterFirstError: false,
rollupCommonJSResolveHack: false,
tsconfig: undefined,
useTsconfigDeclarationDir: false,
@ -78,7 +80,7 @@ const typescript: PluginImpl<Partial<IOptions>> = (options) =>
context = new ConsoleContext(pluginOptions.verbosity, "rpt2: ");
watchMode = process.env.ROLLUP_WATCH === "true";
({ parsedTsConfig: parsedConfig, fileName: tsConfigPath } = parseTsConfig(context, pluginOptions));
({ parsedTsConfig: parsedConfig, fileName: tsConfigPath } = parseTsConfig(context, pluginOptions, buildStatus));
if (generateRound === 0)
{
@ -108,7 +110,7 @@ const typescript: PluginImpl<Partial<IOptions>> = (options) =>
// printing compiler option errors
if (pluginOptions.check)
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()), parsedConfig.options.pretty === true);
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()), parsedConfig.options.pretty === true, buildStatus);
if (pluginOptions.clean)
cache().clean();
@ -177,7 +179,7 @@ const typescript: PluginImpl<Partial<IOptions>> = (options) =>
allImportedFiles.add(normalize(id));
const contextWrapper = new RollupContext(pluginOptions.verbosity, pluginOptions.abortOnError, this, "rpt2: ");
const contextWrapper = new RollupContext(pluginOptions, this, "rpt2: ");
const snapshot = servicesHost.setSnapshot(id, code);
@ -188,8 +190,6 @@ const typescript: PluginImpl<Partial<IOptions>> = (options) =>
if (output.emitSkipped)
{
noErrors = false;
// always checking on fatal errors, even if options.check is set to false
const diagnostics = _.concat(
cache().getSyntacticDiagnostics(id, snapshot, () =>
@ -201,7 +201,7 @@ const typescript: PluginImpl<Partial<IOptions>> = (options) =>
return service.getSemanticDiagnostics(id);
}),
);
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true, buildStatus);
// since no output was generated, aborting compilation
cache().done();
@ -226,10 +226,7 @@ const typescript: PluginImpl<Partial<IOptions>> = (options) =>
}),
);
if (diagnostics.length > 0)
noErrors = false;
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true);
printDiagnostics(contextWrapper, diagnostics, parsedConfig.options.pretty === true, buildStatus);
}
if (result)
@ -267,7 +264,7 @@ const typescript: PluginImpl<Partial<IOptions>> = (options) =>
return undefined;
},
generateBundle(bundleOptions: OutputOptions, _bundle: any, isWrite: boolean): void
generateBundle(bundleOptions: OutputOptions, _bundle: OutputBundle, isWrite: boolean): void
{
self._ongenerate();
if (isWrite)
@ -302,13 +299,10 @@ const typescript: PluginImpl<Partial<IOptions>> = (options) =>
}),
);
printDiagnostics(context, diagnostics, parsedConfig.options.pretty === true);
printDiagnostics(context, diagnostics, parsedConfig.options.pretty === true, buildStatus);
});
}
if (!watchMode && !noErrors)
context.info(yellow("there were errors or warnings."));
cache().done();
generateRound++;
@ -374,6 +368,15 @@ const typescript: PluginImpl<Partial<IOptions>> = (options) =>
writeDeclaration(key, ".d.ts.map", map);
});
},
buildEnd(this: PluginContext, _err?: Error): void
{
const contextWrapper = new RollupContext(pluginOptions, this, "rpt2: ");
if (buildStatus.error)
contextWrapper.error(red("there were errors in typescript build."), true);
else if (buildStatus.warning)
contextWrapper.warn(yellow("there were warnings in typescript build."), true);
},
};
return self;

View File

@ -18,6 +18,8 @@ export interface IOptions
clean: boolean;
cacheRoot: string;
abortOnError: boolean;
abortOnWarning: boolean;
continueAfterFirstError: boolean;
rollupCommonJSResolveHack: boolean;
tsconfig?: string;
useTsconfigDeclarationDir: boolean;

View File

@ -8,7 +8,7 @@ import { IOptions } from "./ioptions";
import * as _ from "lodash";
import { checkTsConfig } from "./check-tsconfig";
export function parseTsConfig(context: IContext, pluginOptions: IOptions)
export function parseTsConfig(context: IContext, pluginOptions: IOptions, buildStatus: { error: boolean, warning: boolean })
{
const fileName = tsModule.findConfigFile(process.cwd(), tsModule.sys.fileExists, pluginOptions.tsconfig);
@ -20,6 +20,7 @@ export function parseTsConfig(context: IContext, pluginOptions: IOptions)
let baseDir = process.cwd();
let configFileName;
let pretty = false;
if (fileName)
{
const text = tsModule.sys.readFile(fileName);
@ -31,7 +32,7 @@ export function parseTsConfig(context: IContext, pluginOptions: IOptions)
if (result.error !== undefined)
{
printDiagnostics(context, convertDiagnostic("config", [result.error]), pretty);
printDiagnostics(context, convertDiagnostic("config", [result.error]), pretty, buildStatus);
throw new Error(`failed to parse '${fileName}'`);
}
@ -48,7 +49,7 @@ export function parseTsConfig(context: IContext, pluginOptions: IOptions)
const parsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, compilerOptionsOverride, configFileName);
checkTsConfig(parsedTsConfig);
printDiagnostics(context, convertDiagnostic("config", parsedTsConfig.errors), pretty);
printDiagnostics(context, convertDiagnostic("config", parsedTsConfig.errors), pretty, buildStatus);
context.debug(`built-in options overrides: ${JSON.stringify(compilerOptionsOverride, undefined, 4)}`);
context.debug(`parsed tsconfig: ${JSON.stringify(parsedTsConfig, undefined, 4)}`);

View File

@ -4,7 +4,7 @@ import { IContext } from "./context";
import { IDiagnostics } from "./tscache";
import * as _ from "lodash";
export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty: boolean): void
export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty: boolean, buildStatus: { error: boolean, warning: boolean }): void
{
_.each(diagnostics, (diagnostic) =>
{
@ -22,12 +22,14 @@ export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[],
print = context.error;
color = red;
category = "error";
buildStatus.error = true;
break;
case tsModule.DiagnosticCategory.Warning:
default:
print = context.warn;
color = yellow;
category = "warning";
buildStatus.warning = true;
break;
}

View File

@ -6,34 +6,39 @@ export class RollupContext implements IContext
{
private hasContext: boolean = true;
constructor(private verbosity: VerbosityLevel, private bail: boolean, private context: PluginContext, private prefix: string = "")
constructor(private options: { verbosity: VerbosityLevel, abortOnError: boolean, abortOnWarning: boolean, continueAfterFirstError: boolean}, private context: PluginContext, private prefix: string = "")
{
this.hasContext = _.isFunction(this.context.warn) && _.isFunction(this.context.error);
}
public warn(message: string | (() => string)): void
public warn(message: string | (() => string), lastMessage?: boolean): void
{
if (this.verbosity < VerbosityLevel.Warning)
return;
const text = _.isFunction(message) ? message() : message;
if (this.hasContext)
this.context.warn(`${text}`);
else
console.log(`${this.prefix}${text}`);
}
public error(message: string | (() => string)): void
{
if (this.verbosity < VerbosityLevel.Error)
if (this.options.verbosity < VerbosityLevel.Warning)
return;
const text = _.isFunction(message) ? message() : message;
if (this.hasContext)
{
if (this.bail)
if (this.options.abortOnWarning && (!this.options.continueAfterFirstError || lastMessage))
this.context.error(`${text}`);
else
this.context.warn(`${text}`);
}
else
console.log(`${this.prefix}${text}`);
}
public error(message: string | (() => string), lastMessage?: boolean): void
{
if (this.options.verbosity < VerbosityLevel.Error)
return;
const text = _.isFunction(message) ? message() : message;
if (this.hasContext)
{
if (this.options.abortOnError && (!this.options.continueAfterFirstError || lastMessage))
this.context.error(`${text}`);
else
this.context.warn(`${text}`);
@ -44,7 +49,7 @@ export class RollupContext implements IContext
public info(message: string | (() => string)): void
{
if (this.verbosity < VerbosityLevel.Info)
if (this.options.verbosity < VerbosityLevel.Info)
return;
const text = _.isFunction(message) ? message() : message;
@ -54,7 +59,7 @@ export class RollupContext implements IContext
public debug(message: string | (() => string)): void
{
if (this.verbosity < VerbosityLevel.Debug)
if (this.options.verbosity < VerbosityLevel.Debug)
return;
const text = _.isFunction(message) ? message() : message;