vite-plugin-stylelint
Version:
Stylelint plugin for Vite.
47 lines (45 loc) • 1.41 kB
JavaScript
import { PLUGIN_NAME, getFilePath, getFilter, initializeStylelint, lintFiles, shouldIgnoreModule } from "./utils-C5rXlwKu.js";
import { parentPort, workerData } from "node:worker_threads";
import debugWrap from "debug";
//#region src/worker.ts
const debug = debugWrap(`${PLUGIN_NAME}:worker`);
const options = workerData.options;
const filter = getFilter(options);
let stylelintInstance;
let formatter;
const initPromise = initializeStylelint(options).then((result) => {
stylelintInstance = result.stylelintInstance;
formatter = result.formatter;
return result;
});
(async () => {
debug("==== worker start ====");
debug("Initialize Stylelint");
const { stylelintInstance: stylelintInstance$1, formatter: formatter$1 } = await initPromise;
if (options.lintOnStart) {
debug("Lint on start");
lintFiles({
files: options.include,
stylelintInstance: stylelintInstance$1,
formatter: formatter$1,
options
});
}
})();
parentPort?.on("message", async (id) => {
if (!stylelintInstance) await initPromise;
debug("==== message event ====");
debug(`id: ${id}`);
const shouldIgnore = shouldIgnoreModule(id, filter);
debug(`should ignore: ${shouldIgnore}`);
if (shouldIgnore) return;
const filePath = getFilePath(id);
debug(`filePath: ${filePath}`);
lintFiles({
files: options.lintDirtyOnly ? filePath : options.include,
stylelintInstance,
formatter,
options
});
});
//#endregion