UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

245 lines (243 loc) • 9.22 kB
const require_runtime = require('./_virtual/_rolldown/runtime.cjs'); let node_fs = require("node:fs"); let node_path = require("node:path"); node_path = require_runtime.__toESM(node_path, 1); let effect = require("effect"); //#region src/service-descriptor.ts /** * True when a `plugins.<id>` entry is the runtime-config mirror of the * app-slot auth plugin (same backend target) — the `auth` service already * spawns that backend, so the mirror contributes only its `ui` surface. * The single implementation; consumed by the service descriptors, the DAG, * the infra planner, and the dev session. */ function isAuthMirrorPluginEntry(authEntry, pluginId, pluginConfig) { if (pluginId !== "auth" || !authEntry) return false; if (pluginConfig === authEntry) return true; if (pluginConfig.localPath && pluginConfig.localPath === authEntry.localPath) return true; if (!pluginConfig.localPath && pluginConfig.source === "remote" && pluginConfig.url && pluginConfig.url === authEntry.url) return true; return false; } var ServiceDescriptorMap = class extends effect.Context.Service()("ServiceDescriptorMap") {}; var DevRuntimeConfig = class extends effect.Context.Service()("DevRuntimeConfig") {}; var DevGeneratedEnv = class extends effect.Context.Service()("DevGeneratedEnv") {}; const DevGeneratedEnvLive = (env) => effect.Layer.succeed(DevGeneratedEnv, env); const PLUGIN_READY_PATTERNS = [ /ready in/i, /compiled.*successfully/i, /listening/i, /started/i ]; const PLUGIN_ERROR_PATTERNS = [ /\bERROR in\b/, /failed to compile/i, /Module not found/i, /Cannot find module/i ]; const SERVICE_CONFIGS = { host: { command: "pnpm", args: ["run", "dev"], env: { NODE_OPTIONS: "--conditions=development" }, readyPatterns: [/Host (dev|production) server running at/i, /Server running at/i], errorPatterns: [ /\berror\b(?!s)/i, /\bfailed to\b/i, /\bbuild failed\b/i, /exception/i ], defaultPort: 3e3, readinessPath: "/health" }, auth: { command: "pnpm", args: ["run", "dev"], readyPatterns: PLUGIN_READY_PATTERNS, errorPatterns: PLUGIN_ERROR_PATTERNS, defaultPort: 3002, readinessPath: "/remoteEntry.js" }, ui: { command: "pnpm", args: ["run", "dev"], readyPatterns: [ /\bready\s+built in\b/i, /\bLocal:\b/i, /\bcompiled\b.*successfully/i ], errorPatterns: [ /\berror\b(?!s)/i, /\bfailed to\b/i, /\bbuild failed\b/i ], defaultPort: 3003, readinessPath: "/remoteEntry.js" }, api: { command: "pnpm", args: ["run", "dev"], readyPatterns: PLUGIN_READY_PATTERNS, errorPatterns: PLUGIN_ERROR_PATTERNS, defaultPort: 3001, readinessPath: "/remoteEntry.js" } }; function buildServiceDescriptorMap(runtimeConfig, options) { const map = /* @__PURE__ */ new Map(); const ssr = options?.ssr ?? false; const hostIsRemote = runtimeConfig.host.source === "remote"; const hostProbeUrl = hostIsRemote ? runtimeConfig.host.remoteUrl ?? runtimeConfig.host.url : runtimeConfig.host.url; map.set("host", { key: "host", source: runtimeConfig.host.source, url: hostProbeUrl, remoteUrl: runtimeConfig.host.remoteUrl, entry: hostIsRemote ? hostProbeUrl ? `${hostProbeUrl}/mf-manifest.json` : "/mf-manifest.json" : runtimeConfig.host.entry, name: runtimeConfig.host.name, localPath: runtimeConfig.host.localPath, port: runtimeConfig.host.port, integrity: runtimeConfig.host.integrity, secrets: runtimeConfig.host.secrets, ...SERVICE_CONFIGS.host }); map.set("ui", { key: "ui", source: runtimeConfig.ui.source, url: runtimeConfig.ui.url, remoteUrl: runtimeConfig.ui.source === "remote" ? runtimeConfig.ui.url : void 0, entry: runtimeConfig.ui.entry, name: runtimeConfig.ui.name, localPath: runtimeConfig.ui.localPath, port: runtimeConfig.ui.port, integrity: runtimeConfig.ui.integrity, ssr, ...SERVICE_CONFIGS.ui, env: { BOS_DEV_SERVER: "1" }, args: process.env.BOS_NO_WATCH === "1" ? ["run", "dev:built"] : SERVICE_CONFIGS.ui.args }); map.set("api", { key: "api", source: runtimeConfig.api.source, url: runtimeConfig.api.url, remoteUrl: runtimeConfig.api.source === "remote" ? runtimeConfig.api.url : void 0, entry: runtimeConfig.api.entry, name: runtimeConfig.api.name, localPath: runtimeConfig.api.localPath, port: runtimeConfig.api.port, integrity: runtimeConfig.api.integrity, proxy: runtimeConfig.api.proxy, variables: runtimeConfig.api.variables, secrets: runtimeConfig.api.secrets, ...SERVICE_CONFIGS.api }); if (runtimeConfig.auth) map.set("auth", { key: "auth", source: runtimeConfig.auth.source, url: runtimeConfig.auth.url, remoteUrl: runtimeConfig.auth.source === "remote" ? runtimeConfig.auth.url : void 0, entry: runtimeConfig.auth.entry, name: runtimeConfig.auth.name, localPath: runtimeConfig.auth.localPath, port: runtimeConfig.auth.port, integrity: runtimeConfig.auth.integrity, proxy: runtimeConfig.auth.proxy, variables: runtimeConfig.auth.variables, secrets: runtimeConfig.auth.secrets, ...SERVICE_CONFIGS.auth }); if (runtimeConfig.plugins) { let pluginBasePort = 3010; for (const [pluginId, pluginConfig] of Object.entries(runtimeConfig.plugins)) { const isAuthMirror = isAuthMirrorPluginEntry(runtimeConfig.auth, pluginId, pluginConfig); const pluginKey = `plugin:${pluginId}`; const resolvedPort = pluginConfig.port ?? pluginBasePort; pluginBasePort = resolvedPort + 1; const uiLocalPath = pluginConfig.ui?.localPath; const isFolderFormUi = Boolean(uiLocalPath && pluginConfig.ui?.source === "local" && (0, node_fs.existsSync)(node_path.default.join(uiLocalPath, "src", "routes")) && !(0, node_fs.existsSync)(node_path.default.join(uiLocalPath, "package.json"))); const folderUiPort = pluginConfig.ui?.port ?? pluginBasePort; if (isFolderFormUi) pluginBasePort = folderUiPort + 1; if (!isAuthMirror) map.set(pluginKey, { key: pluginKey, source: pluginConfig.source, url: pluginConfig.url, remoteUrl: pluginConfig.source === "remote" ? pluginConfig.url : void 0, entry: pluginConfig.entry, name: pluginConfig.name, localPath: pluginConfig.localPath, port: resolvedPort, integrity: pluginConfig.integrity, proxy: pluginConfig.proxy, variables: pluginConfig.variables, secrets: pluginConfig.secrets, command: "pnpm", args: ["run", "dev"], env: isFolderFormUi ? { BOS_UI_PORT: String(folderUiPort) } : void 0, uiPort: isFolderFormUi ? folderUiPort : void 0, readyPatterns: PLUGIN_READY_PATTERNS, errorPatterns: PLUGIN_ERROR_PATTERNS, defaultPort: resolvedPort, readinessPath: "/remoteEntry.js" }); else if (isFolderFormUi) { const authDescriptor = map.get("auth"); if (authDescriptor) map.set("auth", { ...authDescriptor, env: { BOS_UI_PORT: String(folderUiPort) }, uiPort: folderUiPort }); } if (pluginConfig.ui?.localPath && pluginConfig.ui.source === "local" && !isFolderFormUi) { const uiKey = `plugin-ui:${pluginId}`; const uiPort = pluginConfig.ui.port ?? pluginBasePort; pluginBasePort = uiPort + 1; map.set(uiKey, { key: uiKey, source: pluginConfig.ui.source, url: pluginConfig.ui.url, entry: pluginConfig.ui.entry, name: pluginConfig.ui.name, localPath: pluginConfig.ui.localPath, port: uiPort, integrity: pluginConfig.ui.integrity, command: "pnpm", args: ["run", "dev"], readyPatterns: PLUGIN_READY_PATTERNS, errorPatterns: PLUGIN_ERROR_PATTERNS, defaultPort: uiPort, readinessPath: "/remoteEntry.js" }); } } } return map; } const ServiceDescriptorMapLive = (map) => effect.Layer.succeed(ServiceDescriptorMap, map); const DevRuntimeConfigLive = (config) => effect.Layer.succeed(DevRuntimeConfig, config); function buildServiceDescriptorMapFromPlan(plan, options) { return buildServiceDescriptorMap(plan.runtimeConfig, options); } function buildDescription(map) { const descriptors = [...map.values()].filter((d) => !d.key.startsWith("plugin:")); const allLocal = descriptors.every((d) => d.source === "local"); const hasProxy = [...map.values()].some((d) => d.proxy && d.source === "local"); if (allLocal && !hasProxy) return "Full Local Development"; const parts = []; for (const d of descriptors) if (d.source === "remote") { const label = d.key === "host" ? "Remote Host" : d.key === "ui" ? "Remote UI" : d.key === "api" ? hasProxy ? void 0 : "Remote API" : d.key === "auth" ? "Remote Auth" : void 0; if (label) parts.push(label); } if (hasProxy) parts.push("Proxy API → Production"); return parts.join(" + ") || "Remote Mode"; } //#endregion exports.DevGeneratedEnv = DevGeneratedEnv; exports.DevGeneratedEnvLive = DevGeneratedEnvLive; exports.DevRuntimeConfig = DevRuntimeConfig; exports.DevRuntimeConfigLive = DevRuntimeConfigLive; exports.ServiceDescriptorMap = ServiceDescriptorMap; exports.ServiceDescriptorMapLive = ServiceDescriptorMapLive; exports.buildDescription = buildDescription; exports.buildServiceDescriptorMap = buildServiceDescriptorMap; exports.buildServiceDescriptorMapFromPlan = buildServiceDescriptorMapFromPlan; exports.isAuthMirrorPluginEntry = isAuthMirrorPluginEntry; //# sourceMappingURL=service-descriptor.cjs.map