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

Commit 0f6f127

Browse files
committed
fix: run checher synchronously in some cases, also fixes #304, #308, #309
1 parent cb54045 commit 0f6f127

File tree

6 files changed

+390
-353
lines changed

6 files changed

+390
-353
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ So your webpack compilation will end earlier and you can explore compiled versio
3030
**webpack.config.js**
3131

3232
```javascript
33+
// `CheckerPlugin` is optional. Use it if you want async error reporting.
3334
// We need this plugin to detect a `--watch` mode. It may be removed later
3435
// after https://github.com/webpack/webpack/issues/3460 will be resolved.
3536
const { CheckerPlugin } = require('awesome-typescript-loader')

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "3.0.0-beta.13",
44
"description": "Awesome TS loader for webpack",
55
"main": "dist/entry.js",
6+
"typings": "./dist/index.d.ts",
67
"scripts": {
78
"prepublish": "npm run build",
89
"test": "mocha dist/test --harmony-async-await",

src/checker/checker.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,24 @@ export class Checker {
3838
compilerInfo: CompilerInfo,
3939
loaderConfig: LoaderConfig,
4040
compilerConfig: TsConfig,
41-
webpackOptions: any
41+
webpackOptions: any,
42+
fork: boolean = false
4243
) {
4344
const execArgv = getExecArgv();
44-
const checker: childProcess.ChildProcess
45-
= childProcess.fork(path.join(__dirname, 'runtime.js'), [], { execArgv });
45+
const checker: childProcess.ChildProcess = fork
46+
? childProcess.fork(path.join(__dirname, 'runtime.js'), [], { execArgv })
47+
: require('./runtime');
48+
49+
this.sender = fork
50+
? createQueuedSender(checker)
51+
: { send: checker.send };
4652

47-
this.sender = createQueuedSender(checker);
4853
this.checker = checker;
4954
this.compilerInfo = compilerInfo;
5055
this.loaderConfig = loaderConfig;
5156
this.compilerConfig = compilerConfig;
5257
this.webpackOptions = webpackOptions;
5358

54-
this.req({
55-
type: 'Init',
56-
payload: {
57-
compilerInfo: _.omit(compilerInfo, 'tsImpl'),
58-
loaderConfig,
59-
compilerConfig,
60-
webpackOptions
61-
}
62-
} as Init.Request);
63-
6459
checker.on('error', (e) => {
6560
console.error('Typescript checker error:', e);
6661
});
@@ -80,18 +75,29 @@ export class Checker {
8075
console.warn('Unknown message: ', payload);
8176
}
8277
});
78+
79+
this.req({
80+
type: 'Init',
81+
payload: {
82+
compilerInfo: _.omit(compilerInfo, 'tsImpl'),
83+
loaderConfig,
84+
compilerConfig,
85+
webpackOptions
86+
}
87+
} as Init.Request);
8388
}
8489

8590
req<T>(message: Req): Promise<T> {
8691
message.seq = ++this.seq;
87-
this.sender.send(message);
88-
return new Promise<T>((resolve, reject) => {
92+
const promise = new Promise<T>((resolve, reject) => {
8993
let resolver: Resolve = {
9094
resolve, reject
9195
};
9296

9397
this.pending.set(message.seq, resolver);
9498
});
99+
this.sender.send(message);
100+
return promise;
95101
}
96102

97103
emitFile(fileName: string, text: string): Promise<EmitFile.ResPayload> {

0 commit comments

Comments
 (0)