Skip to content

Commit

Permalink
Attaches the options to the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Maël Nison committed Apr 18, 2019
1 parent cf71864 commit a3bc14f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions src/ApiIncrementalChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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';

Expand All @@ -51,7 +57,9 @@ export class ApiIncrementalChecker implements IncrementalCheckerInterface {
typescript,
programConfigFile,
compilerOptions,
checkSyntacticErrors
checkSyntacticErrors,
resolveModuleName,
resolveTypeReferenceDirective
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/CompilerHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
) => {
Expand All @@ -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
) => {
Expand Down
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ interface Options {
vue: boolean;
useTypescriptIncrementalApi: boolean;
measureCompilationTime: boolean;
resolveModuleNameModule: string;
resolveTypeDirectiveReferenceModule: string;
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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']
Expand Down
9 changes: 8 additions & 1 deletion src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a3bc14f

Please sign in to comment.