UNPKG

eslint-svelte3-preprocess

Version:
32 lines (31 loc) 1.24 kB
import debug from "debug"; import { createRequire } from "module"; import { isMainThread, parentPort, workerData } from "worker_threads"; import { preprocess } from "./preprocess"; const loadFile = createRequire(__dirname); const debugWorker = debug("eslint:svelte-preprocess:worker"); if (!isMainThread) { parentPort?.on("message", async ({ src, filename }) => { const { isDoneView, dataView, dataLengthView, svelteConfigPath, } = workerData; const svelteConfig = loadFile(svelteConfigPath); debugWorker(`Preprocessing ${filename}`); let result = null; try { result = await preprocess(src, filename, svelteConfig.preprocess); debugWorker(`Preprocessed ${filename}`); } catch (error) { debugWorker("Failed to preprocess:", error); } const textEncoder = new TextEncoder(); const encodedResult = textEncoder.encode(result ? JSON.stringify(result) : ''); // prettier-ignore dataView.set(encodedResult, 0); dataLengthView[0] = encodedResult.length; Atomics.store(isDoneView, 0, 1); Atomics.notify(isDoneView, 0, Infinity); }); } const path = __filename; export default { path, };