Skip to content

Commit 8162cb1

Browse files
authored
Merge pull request #1198 from typed-ember/test-race-condition
fix(typecheck-worker): avoid false-positive `willTypecheck`s on Linux
2 parents 1077e51 + b7f2f92 commit 8162cb1

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

ts/lib/typechecking/worker/index.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export default class TypecheckWorker {
138138
private patchCompilerHostMethods(
139139
host: WatchCompilerHostOfConfigFile<SemanticDiagnosticsBuilderProgram>
140140
) {
141-
let { watchFile, watchDirectory, createProgram, afterProgramCreate = () => {} } = host;
141+
let { watchFile, watchDirectory, afterProgramCreate = () => {} } = host;
142142

143143
// Intercept tsc's `watchFile` to also invoke `mayTypecheck()` when a watched file changes
144144
host.watchFile = (path, callback, pollingInterval?) => {
@@ -167,14 +167,11 @@ export default class TypecheckWorker {
167167
);
168168
};
169169

170-
// Intercept `createProgram` to invoke `willTypecheck` beforehand, as we know at this
171-
// point that a new check is definitively happening.
172-
host.createProgram = (...params) => {
170+
// Intercept `afterProgramCreate` to confirm when a suspected typecheck is happening
171+
// and schedule the new diagnostics to be emitted.
172+
host.afterProgramCreate = (program) => {
173173
this.willTypecheck();
174-
return createProgram.apply(host, params);
175-
};
176174

177-
host.afterProgramCreate = (program) => {
178175
// The `afterProgramCreate` callback will be invoked synchronously when we first call
179176
// `createWatchProgram`, meaning we can enter `didTypecheck` before we're fully set up
180177
// (e.g. before `compilerOptions` has been set). We use `nextTick` to ensure that

ts/tests/helpers/skeleton-app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const getEmberPort = (() => {
1616
export default class SkeletonApp {
1717
port = getEmberPort();
1818
watched: WatchedBuild | null = null;
19-
cleanupTempDir = () => rimraf(this.root, (error) => console.error(error));
19+
cleanupTempDir = () => rimraf(this.root, (error) => error && console.error(error));
2020
root = path.join(process.cwd(), `test-skeleton-app-${Math.random().toString(36).slice(2)}`);
2121

2222
constructor() {

0 commit comments

Comments
 (0)