From a3bc14facc3c7d63e4a0b8f41e31a0c2694aaea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Thu, 18 Apr 2019 21:16:04 +0100 Subject: [PATCH] Attaches the options to the plugin --- README.md | 6 ++++++ src/ApiIncrementalChecker.ts | 14 +++++++++++--- src/CompilerHost.ts | 6 ++++-- src/index.ts | 10 ++++++++++ src/service.ts | 9 ++++++++- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dd57ec4c..19cd9066 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,12 @@ especially if there are other loaders/plugins involved in the compilation. **req * **typescript** `string`: If supplied this is a custom path where `typescript` can be found. Defaults to `require.resolve('typescript')`. +* **resolveModuleName** `string`: +If supplied this is a path of a file where the worker can find a working implementation of `resolveModuleName` to use with TypeScript (exported through the `resolveModuleName` symbol). + +* **resolveTypeDirectiveReference** `string`: +If supplied this is a path of a file where the worker can find a working implementation of `resolveTypeDirectiveReference` to use with TypeScript (exported through the `resolveTypeDirectiveReference` symbol). + ### Pre-computed consts: * `ForkTsCheckerWebpackPlugin.ONE_CPU` - always use one CPU * `ForkTsCheckerWebpackPlugin.ALL_CPUS` - always use all CPUs (will increase build time) diff --git a/src/ApiIncrementalChecker.ts b/src/ApiIncrementalChecker.ts index 2945accd..472ecbd3 100644 --- a/src/ApiIncrementalChecker.ts +++ b/src/ApiIncrementalChecker.ts @@ -12,7 +12,11 @@ import { makeGetLinterConfig } from './linterConfigHelpers'; import { NormalizedMessage } from './NormalizedMessage'; -import { CompilerHost } from './CompilerHost'; +import { + CompilerHost, + ResolveModuleName, + ResolveTypeReferenceDirective +} from './CompilerHost'; import { FsHelper } from './FsHelper'; export class ApiIncrementalChecker implements IncrementalCheckerInterface { @@ -41,7 +45,9 @@ export class ApiIncrementalChecker implements IncrementalCheckerInterface { private context: string, private linterConfigFile: string | boolean, private linterAutoFix: boolean, - checkSyntacticErrors: boolean + checkSyntacticErrors: boolean, + resolveModuleName: ResolveModuleName | undefined, + resolveTypeReferenceDirective: ResolveTypeReferenceDirective | undefined ) { this.hasFixedConfig = typeof this.linterConfigFile === 'string'; @@ -51,7 +57,9 @@ export class ApiIncrementalChecker implements IncrementalCheckerInterface { typescript, programConfigFile, compilerOptions, - checkSyntacticErrors + checkSyntacticErrors, + resolveModuleName, + resolveTypeReferenceDirective ); } diff --git a/src/CompilerHost.ts b/src/CompilerHost.ts index 56e15bfd..e11c8106 100644 --- a/src/CompilerHost.ts +++ b/src/CompilerHost.ts @@ -97,13 +97,14 @@ export class CompilerHost this.configFileName = this.tsHost.configFileName; this.optionsToExtend = this.tsHost.optionsToExtend || {}; - // tslint:disable-next-line:no-shadowed-variable this.resolveModuleName = resolveModuleName || (( + // tslint:disable-next-line:no-shadowed-variable typescript, moduleName, containingFile, + // tslint:disable-next-line:no-shadowed-variable compilerOptions, moduleResolutionHost ) => { @@ -115,13 +116,14 @@ export class CompilerHost ); }); - // tslint:disable-next-line:no-shadowed-variable this.resolveTypeReferenceDirective = resolveTypeReferenceDirective || (( + // tslint:disable-next-line:no-shadowed-variable typescript, typeDirectiveName, containingFile, + // tslint:disable-next-line:no-shadowed-variable compilerOptions, moduleResolutionHost ) => { diff --git a/src/index.ts b/src/index.ts index 3d0774ea..2540ff6a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,6 +53,8 @@ interface Options { vue: boolean; useTypescriptIncrementalApi: boolean; measureCompilationTime: boolean; + resolveModuleNameModule: string; + resolveTypeDirectiveReferenceModule: string; } /** @@ -99,6 +101,8 @@ class ForkTsCheckerWebpackPlugin { private colors: Chalk; private formatter: Formatter; private useTypescriptIncrementalApi: boolean; + private resolveModuleNameModule: string | undefined; + private resolveTypeDirectiveReferenceModule: string | undefined; private tsconfigPath?: string; private tslintPath?: string; @@ -155,6 +159,9 @@ class ForkTsCheckerWebpackPlugin { this.silent = options.silent === true; // default false this.async = options.async !== false; // default true this.checkSyntacticErrors = options.checkSyntacticErrors === true; // default false + this.resolveModuleNameModule = options.resolveModuleNameModule; + this.resolveTypeDirectiveReferenceModule = + options.resolveTypeDirectiveReferenceModule; this.workersNumber = options.workers || ForkTsCheckerWebpackPlugin.ONE_CPU; this.memoryLimit = options.memoryLimit || ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT; @@ -590,6 +597,9 @@ class ForkTsCheckerWebpackPlugin { MEMORY_LIMIT: this.memoryLimit, CHECK_SYNTACTIC_ERRORS: this.checkSyntacticErrors, USE_INCREMENTAL_API: this.useTypescriptIncrementalApi === true, + RESOLVE_MODULE_NAME: this.resolveModuleNameModule, + RESOLVE_TYPE_DIRECTIVE_REFERENCE: this + .resolveTypeDirectiveReferenceModule, VUE: this.vue }, stdio: ['inherit', 'inherit', 'inherit', 'ipc'] diff --git a/src/service.ts b/src/service.ts index 90c47306..307aab25 100644 --- a/src/service.ts +++ b/src/service.ts @@ -42,7 +42,14 @@ const checker: IncrementalCheckerInterface = process.env.CONTEXT!, process.env.TSLINT === 'true' ? true : process.env.TSLINT! || false, process.env.TSLINTAUTOFIX === 'true', - process.env.CHECK_SYNTACTIC_ERRORS === 'true' + process.env.CHECK_SYNTACTIC_ERRORS === 'true', + process.env.RESOLVE_MODULE_NAME + ? require(process.env.RESOLVE_MODULE_NAME!).resolveModuleName + : undefined, + process.env.RESOLVE_TYPE_REFERENCE_DIRECTIVE + ? require(process.env.RESOLVE_TYPE_REFERENCE_DIRECTIVE!) + .resolveTypeReferenceDirective + : undefined ) : new IncrementalChecker( typescript,