Skip to content

Commit 181f4e4

Browse files
committed
Require typescript from provided path
1 parent 5d9e204 commit 181f4e4

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
@@ -44,6 +44,7 @@ export class IncrementalChecker {
4444
vue: boolean;
4545

4646
constructor(
47+
typescriptPath: string,
4748
programConfigFile: string,
4849
linterConfigFile: string | false,
4950
watchPaths: string[],
@@ -52,7 +53,7 @@ export class IncrementalChecker {
5253
checkSyntacticErrors: boolean,
5354
vue: boolean
5455
) {
55-
// TODO: set `typescript`
56+
this.typescript = require(typescriptPath);
5657
this.programConfigFile = programConfigFile;
5758
this.linterConfigFile = linterConfigFile;
5859
this.watchPaths = watchPaths;

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
@@ -69,6 +69,7 @@ class ForkTsCheckerWebpackPlugin {
6969
static ONE_CPU_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 1);
7070
static TWO_CPUS_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 2);
7171

72+
typescriptPath: string;
7273
options: Partial<Options>;
7374
tsconfig: string;
7475
tslint: string | true;
@@ -109,7 +110,7 @@ class ForkTsCheckerWebpackPlugin {
109110

110111
vue: boolean;
111112

112-
constructor(options?: Partial<Options>) {
113+
constructor(typescriptPath?: string | null, options?: Partial<Options>) {
113114
options = options || ({} as Options);
114115
this.options = Object.assign({}, options);
115116

@@ -159,9 +160,12 @@ class ForkTsCheckerWebpackPlugin {
159160
this.emitCallback = this.createNoopEmitCallback();
160161
this.doneCallback = this.createDoneCallback();
161162

162-
this.typescriptVersion = require('typescript').version;
163+
// tslint:disable-next-line:no-implicit-dependencies
164+
this.typescriptPath = typescriptPath || require.resolve('typescript');
165+
this.typescriptVersion = require(typescriptPath).version;
163166
this.tslintVersion = this.tslint
164-
? require('tslint').Linter.VERSION
167+
? // tslint:disable-next-line:no-implicit-dependencies
168+
require('tslint').Linter.VERSION
165169
: undefined;
166170

167171
this.vue = options.vue === true; // default false
@@ -553,6 +557,7 @@ class ForkTsCheckerWebpackPlugin {
553557
? []
554558
: ['--max-old-space-size=' + this.memoryLimit],
555559
env: Object.assign({}, process.env, {
560+
TYPESCRIPT_PATH: this.typescriptPath,
556561
TSCONFIG: this.tsconfigPath,
557562
TSLINT: this.tslintPath || '',
558563
WATCH: this.isWatching ? this.watchPaths.join('|') : '',

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
process.env.TSLINT === '' ? false : process.env.TSLINT,
1011
process.env.WATCH === '' ? [] : process.env.WATCH.split('|'),

0 commit comments

Comments
 (0)