Skip to content

Commit a3bc14f

Browse files
author
Maël Nison
committed
Attaches the options to the plugin
1 parent cf71864 commit a3bc14f

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ especially if there are other loaders/plugins involved in the compilation. **req
155155
* **typescript** `string`:
156156
If supplied this is a custom path where `typescript` can be found. Defaults to `require.resolve('typescript')`.
157157

158+
* **resolveModuleName** `string`:
159+
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).
160+
161+
* **resolveTypeDirectiveReference** `string`:
162+
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).
163+
158164
### Pre-computed consts:
159165
* `ForkTsCheckerWebpackPlugin.ONE_CPU` - always use one CPU
160166
* `ForkTsCheckerWebpackPlugin.ALL_CPUS` - always use all CPUs (will increase build time)

src/ApiIncrementalChecker.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
makeGetLinterConfig
1313
} from './linterConfigHelpers';
1414
import { NormalizedMessage } from './NormalizedMessage';
15-
import { CompilerHost } from './CompilerHost';
15+
import {
16+
CompilerHost,
17+
ResolveModuleName,
18+
ResolveTypeReferenceDirective
19+
} from './CompilerHost';
1620
import { FsHelper } from './FsHelper';
1721

1822
export class ApiIncrementalChecker implements IncrementalCheckerInterface {
@@ -41,7 +45,9 @@ export class ApiIncrementalChecker implements IncrementalCheckerInterface {
4145
private context: string,
4246
private linterConfigFile: string | boolean,
4347
private linterAutoFix: boolean,
44-
checkSyntacticErrors: boolean
48+
checkSyntacticErrors: boolean,
49+
resolveModuleName: ResolveModuleName | undefined,
50+
resolveTypeReferenceDirective: ResolveTypeReferenceDirective | undefined
4551
) {
4652
this.hasFixedConfig = typeof this.linterConfigFile === 'string';
4753

@@ -51,7 +57,9 @@ export class ApiIncrementalChecker implements IncrementalCheckerInterface {
5157
typescript,
5258
programConfigFile,
5359
compilerOptions,
54-
checkSyntacticErrors
60+
checkSyntacticErrors,
61+
resolveModuleName,
62+
resolveTypeReferenceDirective
5563
);
5664
}
5765

src/CompilerHost.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ export class CompilerHost
9797
this.configFileName = this.tsHost.configFileName;
9898
this.optionsToExtend = this.tsHost.optionsToExtend || {};
9999

100-
// tslint:disable-next-line:no-shadowed-variable
101100
this.resolveModuleName =
102101
resolveModuleName ||
103102
((
103+
// tslint:disable-next-line:no-shadowed-variable
104104
typescript,
105105
moduleName,
106106
containingFile,
107+
// tslint:disable-next-line:no-shadowed-variable
107108
compilerOptions,
108109
moduleResolutionHost
109110
) => {
@@ -115,13 +116,14 @@ export class CompilerHost
115116
);
116117
});
117118

118-
// tslint:disable-next-line:no-shadowed-variable
119119
this.resolveTypeReferenceDirective =
120120
resolveTypeReferenceDirective ||
121121
((
122+
// tslint:disable-next-line:no-shadowed-variable
122123
typescript,
123124
typeDirectiveName,
124125
containingFile,
126+
// tslint:disable-next-line:no-shadowed-variable
125127
compilerOptions,
126128
moduleResolutionHost
127129
) => {

src/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ interface Options {
5353
vue: boolean;
5454
useTypescriptIncrementalApi: boolean;
5555
measureCompilationTime: boolean;
56+
resolveModuleNameModule: string;
57+
resolveTypeDirectiveReferenceModule: string;
5658
}
5759

5860
/**
@@ -99,6 +101,8 @@ class ForkTsCheckerWebpackPlugin {
99101
private colors: Chalk;
100102
private formatter: Formatter;
101103
private useTypescriptIncrementalApi: boolean;
104+
private resolveModuleNameModule: string | undefined;
105+
private resolveTypeDirectiveReferenceModule: string | undefined;
102106

103107
private tsconfigPath?: string;
104108
private tslintPath?: string;
@@ -155,6 +159,9 @@ class ForkTsCheckerWebpackPlugin {
155159
this.silent = options.silent === true; // default false
156160
this.async = options.async !== false; // default true
157161
this.checkSyntacticErrors = options.checkSyntacticErrors === true; // default false
162+
this.resolveModuleNameModule = options.resolveModuleNameModule;
163+
this.resolveTypeDirectiveReferenceModule =
164+
options.resolveTypeDirectiveReferenceModule;
158165
this.workersNumber = options.workers || ForkTsCheckerWebpackPlugin.ONE_CPU;
159166
this.memoryLimit =
160167
options.memoryLimit || ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT;
@@ -590,6 +597,9 @@ class ForkTsCheckerWebpackPlugin {
590597
MEMORY_LIMIT: this.memoryLimit,
591598
CHECK_SYNTACTIC_ERRORS: this.checkSyntacticErrors,
592599
USE_INCREMENTAL_API: this.useTypescriptIncrementalApi === true,
600+
RESOLVE_MODULE_NAME: this.resolveModuleNameModule,
601+
RESOLVE_TYPE_DIRECTIVE_REFERENCE: this
602+
.resolveTypeDirectiveReferenceModule,
593603
VUE: this.vue
594604
},
595605
stdio: ['inherit', 'inherit', 'inherit', 'ipc']

src/service.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ const checker: IncrementalCheckerInterface =
4242
process.env.CONTEXT!,
4343
process.env.TSLINT === 'true' ? true : process.env.TSLINT! || false,
4444
process.env.TSLINTAUTOFIX === 'true',
45-
process.env.CHECK_SYNTACTIC_ERRORS === 'true'
45+
process.env.CHECK_SYNTACTIC_ERRORS === 'true',
46+
process.env.RESOLVE_MODULE_NAME
47+
? require(process.env.RESOLVE_MODULE_NAME!).resolveModuleName
48+
: undefined,
49+
process.env.RESOLVE_TYPE_REFERENCE_DIRECTIVE
50+
? require(process.env.RESOLVE_TYPE_REFERENCE_DIRECTIVE!)
51+
.resolveTypeReferenceDirective
52+
: undefined
4653
)
4754
: new IncrementalChecker(
4855
typescript,

0 commit comments

Comments
 (0)