Skip to content

Commit

Permalink
fix: 调整实现方案
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxichen committed Sep 25, 2024
1 parent a3f4f56 commit ecf971b
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions packages/core/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ let eslintInstance: ESLintInstance;
let formatter: ESLintFormatter;
let outputFixes: ESLintOutputFixes;

// this file needs to be compiled into cjs, which doesn't support top-level await
// so we use iife here
let resolve: () => void;
const p = new Promise<void>((r) => {
resolve = r;
});
const init = async () => {
debug("Initialize ESLint");
const result = await initializeESLint(options);
const initPromise = initializeESLint(options).then((result) => {
eslintInstance = result.eslintInstance;
formatter = result.formatter;
outputFixes = result.outputFixes;
resolve();
return result;
});

// this file needs to be compiled into cjs, which doesn't support top-level await
// so we use iife here
(async () => {
debug("Initialize ESLint");
const { eslintInstance, formatter, outputFixes } = await initPromise;
if (options.lintOnStart) {
debug("Lint on start");
lintFiles({
Expand All @@ -45,11 +44,10 @@ const init = async () => {
options,
}); // don't use context
}
};
init();
})();

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

0 comments on commit ecf971b

Please sign in to comment.