Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: eslintInstance may not be initialized when calling lintFiles in the worker #40

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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