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

Commit 7b1a3a7

Browse files
committed
fix(*): remove common instance lock, fixes #103
1 parent dd4697f commit 7b1a3a7

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/index.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ async function loader(text) {
2727
}
2828
}
2929

30-
let externalsInvocation: Promise<void>;
31-
3230
async function compiler(webpack: IWebPack, text: string): Promise<void> {
3331
if (webpack.cacheable) {
3432
webpack.cacheable();
@@ -65,16 +63,19 @@ async function compiler(webpack: IWebPack, text: string): Promise<void> {
6563
});
6664

6765
if (instance.options.externals && !instance.externalsInvoked) {
68-
if (externalsInvocation) {
69-
await externalsInvocation;
66+
if (instance.externalsInvocation) {
67+
await instance.externalsInvocation;
7068
} else {
71-
externalsInvocation = instance.options.externals.map(async (external) => {
69+
let promises = instance.options.externals.map(async (external) => {
7270
await state.fileAnalyzer.checkDependencies(resolver, external);
7371
});
7472

75-
await Promise.all(externalsInvocation as any);
73+
instance.externalsInvocation = Promise.all(promises).then(() => {
74+
instance.externalsInvoked = true;
75+
});
76+
77+
await instance.externalsInvocation;
7678
}
77-
instance.externalsInvoked = true;
7879
}
7980

8081
instance.compiledFiles[fileName] = true;

src/instance.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface LoaderPluginDef {
2323
}
2424

2525
export interface ICompilerInstance {
26+
id: number;
2627
tsFlow: Promise<any>;
2728
tsState: State;
2829
babelImpl?: any;
@@ -33,6 +34,7 @@ export interface ICompilerInstance {
3334
cacheIdentifier: any;
3435
plugins: LoaderPluginDef[];
3536
initedPlugins: LoaderPlugin[];
37+
externalsInvocation: Promise<any>;
3638
}
3739

3840
interface ICompiler {
@@ -101,6 +103,7 @@ const BABEL_ERROR = colors.red(`\n\nBabel compiler cannot be found, please add i
101103
/**
102104
* Creates compiler instance
103105
*/
106+
let id = 0;
104107
export function ensureInstance(webpack: IWebPack, options: ICompilerOptions, instanceName: string): ICompilerInstance {
105108
ensureInstanceStore(webpack._compiler);
106109

@@ -251,6 +254,7 @@ export function ensureInstance(webpack: IWebPack, options: ICompilerOptions, ins
251254
}
252255

253256
return getInstanceStore(webpack._compiler)[instanceName] = {
257+
id: ++id,
254258
tsFlow,
255259
tsState,
256260
babelImpl,
@@ -262,7 +266,8 @@ export function ensureInstance(webpack: IWebPack, options: ICompilerOptions, ins
262266
: null,
263267
cacheIdentifier,
264268
plugins,
265-
initedPlugins
269+
initedPlugins,
270+
externalsInvocation: null
266271
};
267272
}
268273

0 commit comments

Comments
 (0)