From 14c6845a77a8a1cb58d5ae7377dea3bfa4dcf32e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Thu, 23 Sep 2021 21:07:05 +0200 Subject: [PATCH] Handle file system race conditions --- package.json | 5 +++-- worker.js | 51 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 7118225..fba6917 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nabla/vite-plugin-eslint", - "version": "1.3.1", + "version": "1.3.2", "license": "MIT", "description": "Plugs ESLint into Vite dev server", "homepage": "https://github.com/nabla/vite-plugin-eslint#readme", @@ -14,7 +14,8 @@ }, "keywords": [ "vite", - "eslint" + "eslint", + "vite-plugin" ], "main": "index.js", "dependencies": { diff --git a/worker.js b/worker.js index 094d51a..c260917 100644 --- a/worker.js +++ b/worker.js @@ -9,24 +9,39 @@ const formatterPromise = workerData.formatter : undefined; parentPort.on("message", (path) => { - eslint.isPathIgnored(path).then(async (ignored) => { - if (ignored) return; - const [report] = await eslint.lintFiles(path); - if (report.messages.length === 0) return; - if (formatterPromise) { - const formatter = await formatterPromise; - console.log(formatter.format([report])); - } else { - report.messages.forEach((m) => { - const prettyPath = path.slice(path.indexOf("/src/") + 1); - const location = `${prettyPath}(${m.line},${m.column})`; - const rule = m.ruleId ? ` ${m.ruleId}` : ""; + eslint + .isPathIgnored(path) + .then(async (ignored) => { + if (ignored) return; + const [report] = await eslint.lintFiles(path); + if (report.messages.length === 0) return; + if (formatterPromise) { + const formatter = await formatterPromise; + console.log(formatter.format([report])); + } else { + report.messages.forEach((m) => { + const prettyPath = path.slice(path.indexOf("/src/") + 1); + const location = `${prettyPath}(${m.line},${m.column})`; + const rule = m.ruleId ? ` ${m.ruleId}` : ""; + console.log( + `${location}: ${chalk[m.severity === 2 ? "red" : "yellow"]( + m.message + )}${rule}` + ); + }); + } + }) + .catch((e) => { + if (e.messageTemplate === "file-not-found" && e.messageData?.pattern) { + // Can happen when the file is deleted or moved console.log( - `${location}: ${chalk[m.severity === 2 ? "red" : "yellow"]( - `${m.message}` - )}${rule}` + `${chalk.yellow(`[eslint] File not found`)} ${chalk.dim( + e.messageData.pattern + )}` ); - }); - } - }); + } else { + // Otherwise log the full error + console.error(e); + } + }); });