From e33e7f0f09b61eba0a0d686c62004658d2a01380 Mon Sep 17 00:00:00 2001 From: Rui Wu Date: Mon, 30 Sep 2024 19:16:39 +0800 Subject: [PATCH] feat!: remove chokidar option --- packages/core/src/constants.ts | 2 -- packages/core/src/index.ts | 42 +--------------------------------- packages/core/src/types.ts | 14 ------------ packages/core/src/utils.ts | 3 --- 4 files changed, 1 insertion(+), 60 deletions(-) diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index be298cd..4f095fb 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -6,8 +6,6 @@ export const ESLINT_SEVERITY = { WARNING: 1, } as const; -export const CWD = process.cwd(); - export const PLUGIN_NAME = "vite:eslint2"; export const COLOR_MAPPING: Record< diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index c48b415..4666e95 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,11 +1,9 @@ import { dirname, extname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { Worker } from "node:worker_threads"; -import type { FSWatcher } from "chokidar"; -import chokidar from "chokidar"; import debugWrap from "debug"; import type * as Vite from "vite"; -import { CWD, PLUGIN_NAME } from "./constants"; +import { PLUGIN_NAME } from "./constants"; import type { ESLintFormatter, ESLintInstance, @@ -32,7 +30,6 @@ export default function ESLintPlugin( const options = getOptions(userOptions); let worker: Worker; - let watcher: FSWatcher; const filter = getFilter(options); let eslintInstance: ESLintInstance; @@ -84,39 +81,6 @@ export default function ESLintPlugin( }, async transform(_, id) { debug("==== transform hook ===="); - // initialize watcher - if (options.chokidar) { - if (watcher) return; - debug("Initialize watcher"); - watcher = chokidar - .watch(options.include, { ignored: options.exclude }) - .on("change", async (path) => { - debug("==== change event ===="); - const fullPath = resolve(CWD, path); - // worker + watcher - if (worker) return worker.postMessage(fullPath); - // watcher only - const shouldIgnore = await shouldIgnoreModule( - fullPath, - filter, - eslintInstance, - ); - debug(`should ignore: ${shouldIgnore}`); - if (shouldIgnore) return; - return await lintFiles( - { - files: options.lintDirtyOnly ? fullPath : options.include, - eslintInstance, - formatter, - outputFixes, - options, - }, - // this, // TODO: use transform hook context will breaks build - ); - }); - return; - } - // no watcher debug(`id: ${id}`); const filePath = getFilePath(id); debug(`filePath: ${filePath}`); @@ -137,10 +101,6 @@ export default function ESLintPlugin( this, // use transform hook context ); }, - async buildEnd() { - debug("==== buildEnd ===="); - if (watcher?.close) await watcher.close(); - }, }; } diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index d316c1c..928269b 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -190,20 +190,6 @@ export interface ESLintPluginOptions extends ESLint.ESLint.Options { * @default true */ lintDirtyOnly: boolean; - /** - * Run ESLint in Chokidar `change` event instead of `transform` hook. This is disabled by default. - * - * Recommend to enable `lintOnStart` if you enable this one. - * - * 在 Chokidar `change` 事件中而不是在 `transform` 生命周期中运行 ESLint。默认禁用。 - * - * 如果你启用这个选项,建议也启用 `lintOnStart`。 - * - * @default false - * - * @deprecated - */ - chokidar: boolean; /** * Emit found errors. This is enabled by default. * diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index b50e331..2908c3b 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -31,7 +31,6 @@ export const getOptions = ({ lintInWorker, lintOnStart, lintDirtyOnly, - chokidar, emitError, emitErrorAsWarning, emitWarning, @@ -50,7 +49,6 @@ export const getOptions = ({ lintInWorker: lintInWorker ?? false, lintOnStart: lintOnStart ?? false, lintDirtyOnly: lintDirtyOnly ?? true, - chokidar: chokidar ?? false, emitError: emitError ?? true, emitErrorAsWarning: emitErrorAsWarning ?? false, emitWarning: emitWarning ?? true, @@ -78,7 +76,6 @@ export const getESLintConstructorOptions = ( "lintInWorker", "lintOnStart", "lintDirtyOnly", - "chokidar", "emitError", "emitErrorAsWarning", "emitWarning",