Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit e9cab7a

Browse files
committed
fix(index): normalize watch resolver
1 parent 2faf8ac commit e9cab7a

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
node_modules
33
dist
44
tscommand
5+
npm-debug.log

src/index.ts

+16-14
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ import { loadLib } from './helpers';
1313

1414
var loaderUtils = require('loader-utils');
1515

16-
interface WebPack {
17-
_compiler: {
18-
inputFileSystem: typeof fs;
19-
_tsInstances: {[key:string]: CompilerInstance};
20-
options: {
21-
externals: {
22-
[ key: string ]: string
23-
}
16+
interface ICompiler {
17+
inputFileSystem: typeof fs;
18+
_tsInstances: {[key:string]: CompilerInstance};
19+
options: {
20+
externals: {
21+
[ key: string ]: string
2422
}
25-
};
23+
}
24+
}
25+
26+
interface WebPack {
27+
_compiler: ICompiler;
2628
cacheable: () => void;
2729
query: string;
2830
async: () => (err: Error, source?: string, map?: string) => void;
@@ -68,9 +70,9 @@ function resolveInstance(compiler, instanceName) {
6870
return getInstanceStore(compiler)[instanceName];
6971
}
7072

71-
function createResolver(webpack: WebPack): Resolver {
72-
let externals = webpack._compiler.options.externals;
73-
let resolver = <Resolver>Promise.promisify(webpack.resolve);
73+
function createResolver(compiler: ICompiler, webpackResolver: any): Resolver {
74+
let externals = compiler.options.externals;
75+
let resolver = <Resolver>Promise.promisify(webpackResolver);
7476

7577
function resolve(base: string, dep: string): Promise<string> {
7678
if (externals && externals.hasOwnProperty(dep)) {
@@ -159,7 +161,7 @@ function ensureInstance(webpack: WebPack, options: CompilerOptions, instanceName
159161
var compiler = (<any>webpack._compiler);
160162

161163
compiler.plugin('watch-run', (watching, callback) => {
162-
var resolver = <Resolver>Promise.promisify(watching.compiler.resolvers.normal.resolve);
164+
var resolver = createResolver(watching.compiler, watching.compiler.resolvers.normal.resolve);
163165
var instance: CompilerInstance = resolveInstance(watching.compiler, instanceName);
164166
var state = instance.tsState;
165167
var mtimes = watching.compiler.watchFileSystem.watcher.mtimes;
@@ -235,7 +237,7 @@ function compiler(webpack: WebPack, text: string): void {
235237
var callback = webpack.async();
236238
var fileName = webpack.resourcePath;
237239

238-
var resolver = createResolver(webpack);
240+
var resolver = createResolver(webpack._compiler, webpack.resolve);
239241

240242
var depsInjector = {
241243
add: (depFileName) => {webpack.addDependency(depFileName)},

0 commit comments

Comments
 (0)