Skip to content

clean: remove backward-compat checks for old Rollup versions #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions __tests__/rollupcontext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -103,8 +102,7 @@ const typescript: PluginImpl<RPT2Options> = (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)}`);
Expand Down Expand Up @@ -205,8 +203,7 @@ const typescript: PluginImpl<RPT2Options> = (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);
Expand All @@ -219,10 +216,11 @@ const typescript: PluginImpl<RPT2Options> = (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: ")}`);
}
Expand Down
22 changes: 4 additions & 18 deletions src/rollupcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -49,7 +37,6 @@ export class RollupContext implements IContext
return;

const text = _.isFunction(message) ? message() : message;

console.log(`${this.prefix}${text}`);
}

Expand All @@ -59,7 +46,6 @@ export class RollupContext implements IContext
return;

const text = _.isFunction(message) ? message() : message;

console.log(`${this.prefix}${text}`);
}
}