Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const node_fs = require('node:fs'); const node_path = require('node:path'); const wrangler = require('wrangler'); const bindings = require('./bindings.js'); function resolveWranglerConfig(root, explicitPath) { const configPath = explicitPath ? node_path.resolve(root, explicitPath) : ["wrangler.json", "wrangler.jsonc", "wrangler.toml"].map((name) => node_path.resolve(root, name)).find(node_fs.existsSync); if (!configPath || !node_fs.existsSync(configPath)) { return void 0; } let raw; try { raw = wrangler.unstable_readConfig({ config: configPath }, { hideWarnings: true }); } catch { return void 0; } return { config: { main: raw.main, durableObjects: collectClassBindings(raw.durable_objects?.bindings), workflows: collectClassBindings(raw.workflows), workerEntrypoints: collectSelfBoundEntrypoints(raw), sameWorkerBindings: collectSameWorkerBindings(raw) }, configDir: node_path.dirname(raw.configPath ?? configPath) }; } function collectSelfBoundEntrypoints(raw) { if (!raw.name) { return []; } const entrypoints = /* @__PURE__ */ new Set(); for (const binding of raw.services ?? []) { if (binding?.service === raw.name && typeof binding.entrypoint === "string") { entrypoints.add(binding.entrypoint); } } return [...entrypoints]; } function collectSameWorkerBindings(raw) { const bindings$1 = []; for (const binding of raw.durable_objects?.bindings ?? []) { if (typeof binding?.name === "string" && typeof binding.class_name === "string" && !binding.script_name) { bindings$1.push({ bindingName: binding.name, className: binding.class_name }); } } for (const binding of raw.services ?? []) { if (raw.name && binding?.service === raw.name && typeof binding.binding === "string") { bindings$1.push({ bindingName: binding.binding, className: typeof binding.entrypoint === "string" ? binding.entrypoint : bindings.DEFAULT_EXPORT }); } } return bindings$1; } function collectClassBindings(bindings) { const result = []; const seenClassNames = /* @__PURE__ */ new Set(); for (const binding of bindings ?? []) { if (typeof binding?.class_name !== "string" || binding.script_name || seenClassNames.has(binding.class_name)) { continue; } seenClassNames.add(binding.class_name); result.push({ name: binding.name, className: binding.class_name }); } return result; } exports.DEFAULT_EXPORT = bindings.DEFAULT_EXPORT; exports.resolveWranglerConfig = resolveWranglerConfig; //# sourceMappingURL=wranglerConfig.js.map