mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
- the only reason that `ConsoleContext` was still used was because the `options` hook doesn't support certain context functions like `this.error` / `this.warn` etc
- but `buildStart` does! so we can just move pretty much everything into `buildStart` instead
- didn't move setting `rollupOptions` because that value gets hashed and the value in `buildStart` is different, as it is after all plugins' `options` hooks have ran
- this way we don't need `ConsoleContext` what-so-ever and so can remove it entirely!
- as well as `IContext`, its tests, etc
- use `this.error` instead of `throw`ing errors in `parse-tsconfig` as it exists now
- couldn't in the `options` hook, can in `buildStart`
- this also ensure we don't have all the `rpt2: ` prefixes ever missing again
- c.f. ff8895103c8466694e7d8eeb734f51d2850670d8, 0628482ea26ddf56e6ef5521e4dcb85ef5b4beb6
- refactor `parse-tsconfig.spec` to account for this change
- c.f. Rollup hooks docs: https://rollupjs.org/guide/en/#options, https://rollupjs.org/guide/en/#buildstart
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import { PluginContext } from "rollup";
|
|
|
|
export enum VerbosityLevel
|
|
{
|
|
Error = 0,
|
|
Warning,
|
|
Info,
|
|
Debug,
|
|
}
|
|
|
|
function getText (message: string | (() => string)): string {
|
|
return typeof message === "string" ? message : message();
|
|
}
|
|
|
|
/** cannot be used in options hook (which does not have this.warn and this.error), but can be in other hooks */
|
|
export class RollupContext
|
|
{
|
|
constructor(private verbosity: VerbosityLevel, private bail: boolean, private context: PluginContext, private prefix: string = "")
|
|
{
|
|
}
|
|
|
|
public warn(message: string | (() => string)): void
|
|
{
|
|
if (this.verbosity < VerbosityLevel.Warning)
|
|
return;
|
|
this.context.warn(`${getText(message)}`);
|
|
}
|
|
|
|
public error(message: string | (() => string)): void | never
|
|
{
|
|
if (this.verbosity < VerbosityLevel.Error)
|
|
return;
|
|
|
|
if (this.bail)
|
|
this.context.error(`${getText(message)}`);
|
|
else
|
|
this.context.warn(`${getText(message)}`);
|
|
}
|
|
|
|
public info(message: string | (() => string)): void
|
|
{
|
|
if (this.verbosity < VerbosityLevel.Info)
|
|
return;
|
|
console.log(`${this.prefix}${getText(message)}`);
|
|
}
|
|
|
|
public debug(message: string | (() => string)): void
|
|
{
|
|
if (this.verbosity < VerbosityLevel.Debug)
|
|
return;
|
|
console.log(`${this.prefix}${getText(message)}`);
|
|
}
|
|
}
|