import { import_binding } from "../shared/parse-ast-index-CVCVLNV5.mjs";
import { PluginContextData, bindingifyPlugin } from "../shared/src-BUnkpoo3.mjs";
import { parentPort, workerData } from "node:worker_threads";

//#region src/parallel-plugin-worker.ts
const { registryId, pluginInfos, threadNumber } = workerData;
(async () => {
	try {
		const plugins = await Promise.all(pluginInfos.map(async (pluginInfo) => {
			const pluginModule = await import(pluginInfo.fileUrl);
			const definePluginImpl = pluginModule.default;
			const plugin = await definePluginImpl(pluginInfo.options, { threadNumber });
			return {
				index: pluginInfo.index,
				plugin: bindingifyPlugin(
					plugin,
					{},
					{},
					// TODO need to find a way to share pluginContextData
					new PluginContextData(),
					[],
					() => {},
					"info"
)
			};
		}));
		(0, import_binding.registerPlugins)(registryId, plugins);
		parentPort.postMessage({ type: "success" });
	} catch (error) {
		parentPort.postMessage({
			type: "error",
			error
		});
	} finally {
		parentPort.unref();
	}
})();

//#endregion