From 27667956292ab4ec717017e4becf0b9bcf5d1659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Mon, 5 Jul 2021 11:38:43 +0200 Subject: [PATCH] Don't initialize worker for builds This was preventing the build from properly exiting --- index.js | 11 +++++++---- package.json | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index b55ea44..e87e10a 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const path = require("path"); +const { resolve } = require("path"); const { Worker } = require("worker_threads"); const { normalizePath } = require("vite"); @@ -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; }, diff --git a/package.json b/package.json index 63575c8..7118225 100644 --- a/package.json +++ b/package.json @@ -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",