Skip to content

Commit

Permalink
Don't initialize worker for builds
Browse files Browse the repository at this point in the history
This was preventing the build from properly exiting
  • Loading branch information
ArnaudBarre committed Jul 5, 2021
1 parent 175be32 commit 2766795
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require("path");
const { resolve } = require("path");
const { Worker } = require("worker_threads");
const { normalizePath } = require("vite");

Expand All @@ -9,15 +9,18 @@ module.exports = function eslintPlugin(options = {}) {
formatter,
} = options;

const worker = new Worker(path.resolve(__dirname, "./worker.js"), {
workerData: { options: { cache: true, ...eslintOptions }, formatter },
});
let worker; // Don't initialize worker for builds

return {
name: "eslint",
apply: "serve",
transform(_code, id) {
const path = normalizePath(id);
if (!worker) {
worker = new Worker(resolve(__dirname, "./worker.js"), {
workerData: { options: { cache: true, ...eslintOptions }, formatter },
});
}
if (shouldLint(path)) worker.postMessage(path);
return null;
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nabla/vite-plugin-eslint",
"version": "1.3.0",
"version": "1.3.1",
"license": "MIT",
"description": "Plugs ESLint into Vite dev server",
"homepage": "https://github.com/nabla/vite-plugin-eslint#readme",
Expand Down

0 comments on commit 2766795

Please sign in to comment.