diff --git a/__tests__/rollupcontext.spec.ts b/__tests__/rollupcontext.spec.ts index ee88b995..25925aa2 100644 --- a/__tests__/rollupcontext.spec.ts +++ b/__tests__/rollupcontext.spec.ts @@ -12,9 +12,7 @@ import { RollupContext } from "../src/rollupcontext"; test("RollupContext", () => { const data = {}; const stubbedContext = makeStubbedContext(data); - const context = new RollupContext(5, false, stubbedContext); - expect(Object.keys(context)).toEqual(["verbosity", "bail", "context", "prefix", "hasContext"]); context.warn("test"); expect((data as any).warn).toEqual("test"); @@ -27,23 +25,6 @@ test("RollupContext", () => { context.error(() => "test2!"); expect((data as any).warn).toEqual("test2!"); -}); - -test("RollupContext with no logger", () => { - const data = {}; - const stubbedContext = makeStubbedContext(data); - delete (stubbedContext as any).warn; - delete (stubbedContext as any).error; - delete (stubbedContext as any).info; - delete (stubbedContext as any).debug; - - const context = new RollupContext(5, false, stubbedContext); - - context.warn("test"); - expect(console.log).toHaveBeenLastCalledWith("test"); - - context.error("test2"); - expect(console.log).toHaveBeenLastCalledWith("test2"); context.info("test3"); expect(console.log).toHaveBeenLastCalledWith("test3"); diff --git a/src/index.ts b/src/index.ts index 30352ab7..bd7cf422 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,6 @@ import { relative, dirname, normalize as pathNormalize, resolve } from "path"; import * as tsTypes from "typescript"; import { PluginImpl, PluginContext, InputOptions, OutputOptions, TransformResult, SourceMap, Plugin } from "rollup"; import { normalizePath as normalize } from "@rollup/pluginutils"; -import * as _ from "lodash"; import { blue, red, yellow, green } from "colors/safe"; import findCacheDir from "find-cache-dir"; @@ -103,8 +102,7 @@ const typescript: PluginImpl = (options) => { context.info(`typescript version: ${tsModule.version}`); context.info(`tslib version: ${tslibVersion}`); - if (this.meta) - context.info(`rollup version: ${this.meta.rollupVersion}`); + context.info(`rollup version: ${this.meta.rollupVersion}`); context.info(`rollup-plugin-typescript2 version: $RPT2_VERSION`); context.debug(() => `plugin options:\n${JSON.stringify(pluginOptions, (key, value) => key === "typescript" ? `version ${(value as typeof tsModule).version}` : value, 4)}`); @@ -205,8 +203,7 @@ const typescript: PluginImpl = (options) => // since no output was generated, aborting compilation cache().done(); - if (_.isFunction(this.error)) - this.error(red(`failed to transpile '${id}'`)); + this.error(red(`failed to transpile '${id}'`)); } const references = getAllReferences(id, snapshot, parsedConfig.options); @@ -219,10 +216,11 @@ const typescript: PluginImpl = (options) => if (!result) return undefined; - if (watchMode && this.addWatchFile && result.references) + if (watchMode && result.references) { if (tsConfigPath) this.addWatchFile(tsConfigPath); + result.references.map(this.addWatchFile, this); context.debug(() => `${green(" watching")}: ${result.references!.join("\nrpt2: ")}`); } diff --git a/src/rollupcontext.ts b/src/rollupcontext.ts index 9ab52371..68c55dba 100644 --- a/src/rollupcontext.ts +++ b/src/rollupcontext.ts @@ -5,11 +5,8 @@ import { IContext, VerbosityLevel } from "./context"; export class RollupContext implements IContext { - private hasContext: boolean = true; - constructor(private verbosity: VerbosityLevel, private bail: boolean, private context: PluginContext, private prefix: string = "") { - this.hasContext = _.isFunction(this.context.warn) && _.isFunction(this.context.error); } public warn(message: string | (() => string)): void @@ -18,11 +15,7 @@ export class RollupContext implements IContext return; const text = _.isFunction(message) ? message() : message; - - if (this.hasContext) - this.context.warn(`${text}`); - else - console.log(`${this.prefix}${text}`); + this.context.warn(`${text}`); } public error(message: string | (() => string)): void @@ -32,15 +25,10 @@ export class RollupContext implements IContext const text = _.isFunction(message) ? message() : message; - if (this.hasContext) - { - if (this.bail) - this.context.error(`${text}`); - else - this.context.warn(`${text}`); - } + if (this.bail) + this.context.error(`${text}`); else - console.log(`${this.prefix}${text}`); + this.context.warn(`${text}`); } public info(message: string | (() => string)): void @@ -49,7 +37,6 @@ export class RollupContext implements IContext return; const text = _.isFunction(message) ? message() : message; - console.log(`${this.prefix}${text}`); } @@ -59,7 +46,6 @@ export class RollupContext implements IContext return; const text = _.isFunction(message) ? message() : message; - console.log(`${this.prefix}${text}`); } }