"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { default: () => src_default, unplugin: () => unplugin, unpluginFactory: () => unpluginFactory }); module.exports = __toCommonJS(src_exports); var import_config2 = require("@pact-toolbox/config"); var import_unplugin = require("unplugin"); // src/core/index.ts var import_config = require("@pact-toolbox/config"); var import_network = require("@pact-toolbox/network"); var import_runtime = require("@pact-toolbox/runtime"); var import_utils = require("@pact-toolbox/utils"); async function startToolboxNetwork({ isServe, isTest }, toolboxConfig, { startNetwork = true, onReady } = {}) { const network = (0, import_config.getNetworkConfig)(toolboxConfig); const client = new import_runtime.PactToolboxClient(toolboxConfig); if (isServe && !isTest && (0, import_config.isLocalNetwork)(network) && startNetwork) { import_utils.logger.info("Starting local network"); await (0, import_network.startLocalNetwork)(toolboxConfig, { client, isStateless: false, logAccounts: true }); } if (isServe && !isTest && onReady) { await onReady(client); } } var PLUGIN_NAME = "pact-toolbox"; // src/index.ts var unpluginFactory = (options) => { const toolboxConfig = (0, import_config2.resolveConfig)(); let isTest = process.env.NODE_ENV === "test"; let isServe = false; return { name: PLUGIN_NAME, enforce: "post", vite: { async configureServer() { await startToolboxNetwork({ isServe, isTest }, await toolboxConfig, options); }, async configResolved(config) { isTest = config.command === "test" || isTest; isServe = config.command === "serve"; if (!isTest) { const networkConfig = (0, import_config2.getSerializableNetworkConfig)(await toolboxConfig); config.define = config.define || {}; config.define["globalThis.__PACT_TOOLBOX_NETWORK_CONFIG__"] = JSON.stringify(networkConfig); } } }, esbuild: { async setup(build) { const options2 = build.initialOptions; const networkConfig = (0, import_config2.getSerializableNetworkConfig)(await toolboxConfig); options2.define = options2.define || {}; options2.define["globalThis.__PACT_TOOLBOX_NETWORK_CONFIG__"] = JSON.stringify(networkConfig); } }, async rspack(compiler) { const DefinePlugin = (await import("@rspack/core")).DefinePlugin; const networkConfig = (0, import_config2.getSerializableNetworkConfig)(await toolboxConfig); const define = new DefinePlugin({ "globalThis.__PACT_TOOLBOX_NETWORK_CONFIG__": JSON.stringify(networkConfig) }); define.apply(compiler); if (compiler.options.mode === "development") { await startToolboxNetwork({ isServe: true, isTest: false }, await toolboxConfig, options); } } }; }; var unplugin = /* @__PURE__ */ (0, import_unplugin.createUnplugin)(unpluginFactory); var src_default = unplugin; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { unplugin, unpluginFactory }); //# sourceMappingURL=index.cjs.mapexports.default = module.exports;