Skip to content

Commit a08d232

Browse files
committed
Require typescript from provided path
1 parent f35a31f commit a08d232

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/IncrementalChecker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class IncrementalChecker {
4545
vue: boolean;
4646

4747
constructor(
48+
typescriptPath: string,
4849
programConfigFile: string,
4950
compilerOptions: object,
5051
linterConfigFile: string | false,
@@ -54,7 +55,7 @@ export class IncrementalChecker {
5455
checkSyntacticErrors: boolean,
5556
vue: boolean
5657
) {
57-
// TODO: set `typescript`
58+
this.typescript = require(typescriptPath);
5859
this.programConfigFile = programConfigFile;
5960
this.compilerOptions = compilerOptions;
6061
this.linterConfigFile = linterConfigFile;

src/TypeScriptInstance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ export interface TypeScriptInstance {
2525
flattenDiagnosticMessageText: typeof ts.flattenDiagnosticMessageText;
2626
resolveModuleName: typeof ts.resolveModuleName;
2727
createSourceFile: typeof ts.createSourceFile;
28-
sys: ts.System;
28+
version: typeof ts.version;
29+
sys: typeof ts.sys;
2930
}

src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class ForkTsCheckerWebpackPlugin {
7272
static ONE_CPU_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 1);
7373
static TWO_CPUS_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 2);
7474

75+
typescriptPath: string;
7576
options: Partial<Options>;
7677
tsconfig: string;
7778
compilerOptions: object;
@@ -114,7 +115,7 @@ class ForkTsCheckerWebpackPlugin {
114115

115116
vue: boolean;
116117

117-
constructor(options?: Partial<Options>) {
118+
constructor(typescriptPath?: string | null, options?: Partial<Options>) {
118119
options = options || ({} as Options);
119120
this.options = Object.assign({}, options);
120121

@@ -169,9 +170,12 @@ class ForkTsCheckerWebpackPlugin {
169170
this.emitCallback = this.createNoopEmitCallback();
170171
this.doneCallback = this.createDoneCallback();
171172

172-
this.typescriptVersion = require('typescript').version;
173+
// tslint:disable-next-line:no-implicit-dependencies
174+
this.typescriptPath = typescriptPath || require.resolve('typescript');
175+
this.typescriptVersion = require(typescriptPath).version;
173176
this.tslintVersion = this.tslint
174-
? require('tslint').Linter.VERSION
177+
? // tslint:disable-next-line:no-implicit-dependencies
178+
require('tslint').Linter.VERSION
175179
: undefined;
176180

177181
this.vue = options.vue === true; // default false
@@ -563,6 +567,7 @@ class ForkTsCheckerWebpackPlugin {
563567
? []
564568
: ['--max-old-space-size=' + this.memoryLimit],
565569
env: Object.assign({}, process.env, {
570+
TYPESCRIPT_PATH: this.typescriptPath,
566571
TSCONFIG: this.tsconfigPath,
567572
COMPILER_OPTIONS: JSON.stringify(this.compilerOptions),
568573
TSLINT: this.tslintPath || '',

src/service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { NormalizedMessage } from './NormalizedMessage';
55
import { OperationCanceledException } from './OperationCanceledException';
66

77
const checker = new IncrementalChecker(
8+
process.env.TYPESCRIPT_PATH,
89
process.env.TSCONFIG,
910
JSON.parse(process.env.COMPILER_OPTIONS),
1011
process.env.TSLINT === '' ? false : process.env.TSLINT,

0 commit comments

Comments
 (0)