Skip to content
This repository has been archived by the owner on Dec 1, 2019. It is now read-only.

Fix custom transformers when using fork checker #531

Merged
merged 1 commit into from
Feb 24, 2018
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
23 changes: 21 additions & 2 deletions src/checker/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,28 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re

class Host implements ts.LanguageServiceHost {
filesRegex: RegExp;
getCustomTransformers = loaderConfig.getCustomTransformers;
getCustomTransformers?: () => ts.CustomTransformers | undefined;

constructor(filesRegex: RegExp) {
this.filesRegex = filesRegex;

let {getCustomTransformers} = loaderConfig;

if (typeof getCustomTransformers === "function") {
this.getCustomTransformers = getCustomTransformers;
} else if (typeof getCustomTransformers === "string") {
try {
getCustomTransformers = require(getCustomTransformers);
} catch (err) {
throw new Error(`Failed to load customTransformers from "${loaderConfig.getCustomTransformers}": ${err.message}`)
};

if (typeof getCustomTransformers !== "function") {
throw new Error(`Custom transformers in "${loaderConfig.getCustomTransformers}" should export a function, got ${typeof getCustomTransformers}`)
};

this.getCustomTransformers = getCustomTransformers;
};
}

getProjectVersion() { return projectVersion.toString(); }
Expand Down Expand Up @@ -400,7 +418,8 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
const trans = compiler.transpileModule(files.get(fileName).text, {
compilerOptions: compilerOptions,
fileName,
reportDiagnostics: false
reportDiagnostics: false,
transformers: host.getCustomTransformers ? host.getCustomTransformers() : undefined,
});

return {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface LoaderConfig {
debug?: boolean;
reportFiles?: string[];
context?: string;
getCustomTransformers?(): ts.CustomTransformers | undefined;
getCustomTransformers?: string | (() => ts.CustomTransformers | undefined);
}

export interface OutputFile {
Expand Down