Skip to content

Commit

Permalink
fix: 修复 worker 模式下 eslintInstance 为undefind的问题
Browse files Browse the repository at this point in the history
修复在worker模式下因异步问题导致经常报错 Cannot read properties of undefined (reading 'lintFiles')
  • Loading branch information
fuxichen committed Sep 24, 2024
1 parent 31e4cdc commit a3f4f56
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/core/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ let outputFixes: ESLintOutputFixes;

// this file needs to be compiled into cjs, which doesn't support top-level await
// so we use iife here
(async () => {
let resolve: () => void;
const p = new Promise<void>((r) => {
resolve = r;
});
const init = async () => {
debug("Initialize ESLint");
const result = await initializeESLint(options);
eslintInstance = result.eslintInstance;
formatter = result.formatter;
outputFixes = result.outputFixes;
resolve();
if (options.lintOnStart) {
debug("Lint on start");
lintFiles({
Expand All @@ -40,9 +45,11 @@ let outputFixes: ESLintOutputFixes;
options,
}); // don't use context
}
})();
};
init();

parentPort?.on("message", async (files) => {
await p;
debug("==== message event ====");
debug(`message: ${files}`);
const shouldIgnore = await shouldIgnoreModule(files, filter, eslintInstance);
Expand Down

0 comments on commit a3f4f56

Please sign in to comment.