everything-dev 1.3.2 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from \"node:fs\";\nimport { basename, join, resolve } from \"node:path\";\nimport { Effect } from \"effect\";\nimport { syncApiContractBridge } from \"./api-contract\";\nimport { buildRuntimeConfig, detectLocalPackages, prepareDevelopmentRuntimeConfig } from \"./app\";\nimport {\n copyFilteredFiles,\n personalizeConfig,\n readTemplatekeep,\n resolveSourceDir,\n runBunInstall,\n} from \"./cli/init\";\nimport { promptInitOptions } from \"./cli/prompts\";\nimport {\n buildRuntimePluginsForConfig,\n getHostDevelopmentPort,\n getProjectRoot,\n loadConfig,\n parsePort,\n resolveDevelopmentHostUrl,\n resolveLocalDevelopmentPath,\n} from \"./config\";\nimport {\n type BosConfigResult,\n type BuildOptions,\n bosContract,\n type DevOptions,\n type InitOptions,\n type KeyPublishOptions,\n type PluginAddOptions,\n type PluginListResult,\n type PluginPublishOptions,\n type PluginRemoveOptions,\n type PublishOptions,\n type StartOptions,\n} from \"./contract\";\nimport { type AppConfig, type AppOrchestrator, startApp } from \"./dev-session\";\nimport {\n buildRegistryConfigUrlForNetwork,\n fetchBosConfigFromFastKv,\n getRegistryNamespaceForAccount,\n getRegistryNamespaceForNetwork,\n} from \"./fastkv\";\nimport { addFunctionCallAccessKey, ensureNearCli, executeTransaction } from \"./near-cli\";\nimport { getNetworkIdForAccount } from \"./network\";\nimport { createPlugin, z } from \"./sdk\";\nimport { syncAndGenerateSharedUi } from \"./shared\";\nimport type { BosConfig, RuntimeConfig, SourceMode } from \"./types\";\nimport { run } from \"./utils/run\";\n\nconst DEFAULT_DEV_CONFIG: AppConfig = {\n host: \"local\",\n ui: \"local\",\n api: \"local\",\n ssr: false,\n};\n\nconst buildCommands: Record<string, { cmd: string; args: string[] }> = {\n host: { cmd: \"bun\", args: [\"run\", \"build\"] },\n ui: { cmd: \"bun\", args: [\"run\", \"build\"] },\n api: { cmd: \"bun\", args: [\"run\", \"build\"] },\n};\n\nconst PUBLISH_FUNCTION_NAMES = [\"__fastdata_kv\"];\n\ntype BosDeps = {\n bosConfig: BosConfig | null;\n runtimeConfig: RuntimeConfig | null;\n configDir: string;\n};\n\ntype PluginAttachmentConfig = NonNullable<BosConfig[\"plugins\"]>[string];\n\nfunction parseSourceMode(value: string | undefined, defaultValue: SourceMode): SourceMode {\n if (value === \"local\" || value === \"remote\") return value;\n return defaultValue;\n}\n\nfunction buildAppConfig(options: {\n host?: string;\n ui?: string;\n api?: string;\n proxy?: boolean;\n ssr?: boolean;\n}): AppConfig {\n return {\n host: parseSourceMode(options.host, DEFAULT_DEV_CONFIG.host),\n ui: parseSourceMode(options.ui, DEFAULT_DEV_CONFIG.ui),\n api: parseSourceMode(options.api, DEFAULT_DEV_CONFIG.api),\n proxy: options.proxy,\n ssr: options.ssr ?? DEFAULT_DEV_CONFIG.ssr,\n };\n}\n\nfunction buildDescription(config: AppConfig): string {\n if (config.host === \"local\" && config.ui === \"local\" && config.api === \"local\" && !config.proxy) {\n return \"Full Local Development\";\n }\n\n const parts: string[] = [];\n parts.push(config.host === \"remote\" ? \"Remote Host\" : \"Local Host\");\n if (config.ui === \"remote\") parts.push(\"Remote UI\");\n if (config.proxy) parts.push(\"Proxy API → Production\");\n else if (config.api === \"remote\") parts.push(\"Remote API\");\n return parts.join(\" + \");\n}\n\nfunction buildConfigResult(bosConfig: BosConfig | null): BosConfigResult {\n const packages = bosConfig ? Object.keys(bosConfig.app) : [];\n const remotes = packages.filter((name) => name !== \"host\");\n\n return {\n config: bosConfig,\n packages,\n remotes,\n };\n}\n\ntype WorkspaceTarget = {\n key: string;\n kind: \"app\" | \"plugin\";\n path: string;\n};\n\nfunction resolveWorkspaceTarget(\n key: string,\n bosConfig: BosConfig | null,\n runtimeConfig: RuntimeConfig | null,\n configDir: string,\n): WorkspaceTarget | null {\n if (bosConfig?.app && key in bosConfig.app) {\n return {\n key,\n kind: \"app\",\n path: `${configDir}/${key}`,\n };\n }\n\n const runtimePlugin = runtimeConfig?.plugins?.[key];\n const pluginPath =\n runtimePlugin?.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.plugins?.[key]?.development, configDir);\n if (pluginPath) {\n return {\n key,\n kind: \"plugin\",\n path: pluginPath,\n };\n }\n\n return null;\n}\n\nfunction determineProcesses(\n config: AppConfig,\n localPackages: string[],\n runtimeConfig?: RuntimeConfig | null,\n): string[] {\n const processes: string[] = [];\n if (config.ssr && config.ui === \"local\") processes.push(\"ui-ssr\");\n if (config.ui === \"local\") processes.push(\"ui\");\n if (config.api === \"local\" && !config.proxy) processes.push(\"api\");\n for (const pkg of localPackages) {\n if (pkg.startsWith(\"plugin:\")) {\n const pluginId = pkg.slice(\"plugin:\".length);\n if (runtimeConfig?.plugins?.[pluginId]?.source === \"local\") {\n processes.push(pkg);\n }\n }\n }\n processes.push(\"host\");\n return processes;\n}\n\nfunction isValidProxyUrl(url: string): boolean {\n try {\n const parsed = new URL(url);\n return parsed.protocol === \"http:\" || parsed.protocol === \"https:\";\n } catch {\n return false;\n }\n}\n\nfunction resolveProxyUrl(bosConfig: BosConfig | null): string | null {\n if (!bosConfig) return null;\n const apiConfig = bosConfig.app.api;\n if (!apiConfig) return null;\n if (apiConfig.proxy && isValidProxyUrl(apiConfig.proxy)) return apiConfig.proxy;\n if (apiConfig.production && isValidProxyUrl(apiConfig.production)) return apiConfig.production;\n return null;\n}\n\nfunction sanitizePluginKey(value: string): string {\n return value\n .replace(/[^A-Za-z0-9/_-]/g, \"-\")\n .replace(/\\/+/g, \"/\")\n .split(\"/\")\n .filter(Boolean)\n .map((segment) => segment.replace(/[^A-Za-z0-9_-]/g, \"-\"))\n .join(\"/\")\n .replace(/^\\/+|\\/+$/g, \"\");\n}\n\nfunction defaultPluginKey(source: string): string {\n const normalized = source.replace(/^local:/, \"\").replace(/\\/$/, \"\");\n if (source.startsWith(\"local:\")) {\n return sanitizePluginKey(basename(normalized)) || \"plugin\";\n }\n\n try {\n const url = new URL(source);\n return sanitizePluginKey(basename(url.pathname) || url.hostname) || \"plugin\";\n } catch {\n return sanitizePluginKey(source) || \"plugin\";\n }\n}\n\nfunction pluginLocalPath(configDir: string, attachment: PluginAttachmentConfig): string | null {\n const source = attachment.development ?? attachment.production;\n if (!source?.startsWith(\"local:\")) {\n return null;\n }\n\n return join(configDir, source.slice(\"local:\".length));\n}\n\nasync function saveBosConfig(configDir: string, config: BosConfig): Promise<void> {\n const filePath = join(configDir, \"bos.config.json\");\n const next = `${JSON.stringify(config, null, 2)}\\n`;\n try {\n if (readFileSync(filePath, \"utf8\") === next) return;\n } catch {\n // file does not exist yet\n }\n\n writeFileSync(filePath, next);\n}\n\nfunction listPluginAttachments(config: BosConfig | null) {\n return (Object.entries(config?.plugins ?? {}) as Array<[string, PluginAttachmentConfig]>)\n .map(([key, attachment]) => ({\n key,\n development: attachment.development,\n production: attachment.production,\n localPath: attachment.development?.startsWith(\"local:\")\n ? attachment.development.slice(\"local:\".length)\n : undefined,\n source: attachment.development?.startsWith(\"local:\")\n ? (\"local\" as const)\n : (\"remote\" as const),\n }))\n .sort((a, b) => a.key.localeCompare(b.key));\n}\n\nasync function refreshApiContractBridge(configDir: string): Promise<void> {\n const refreshed = await loadConfig({ cwd: configDir, env: \"development\" });\n if (!refreshed) return;\n\n await syncApiContractBridge({\n configDir,\n runtimeConfig: refreshed.runtime,\n apiBaseUrl: refreshed.runtime.api.url,\n });\n}\n\nfunction extractPublishedUrl(output: string): string | null {\n const match = output.match(/https?:\\/\\/[^\\s\"'<>]+/g);\n if (!match || match.length === 0) return null;\n return match[match.length - 1] ?? null;\n}\n\nasync function buildEnvVars(\n config: AppConfig,\n bosConfig?: BosConfig | null,\n): Promise<Record<string, string>> {\n const env: Record<string, string> = {\n HOST_SOURCE: config.host,\n UI_SOURCE: config.ui,\n API_SOURCE: config.api,\n };\n\n if (config.host === \"remote\") {\n const remoteUrl = bosConfig?.app.host.production;\n if (remoteUrl) env.HOST_REMOTE_URL = remoteUrl;\n }\n\n if (config.ui === \"remote\") {\n const remoteUrl = bosConfig?.app.ui.production;\n if (remoteUrl) env.UI_REMOTE_URL = remoteUrl;\n }\n\n if (config.api === \"remote\") {\n const remoteUrl = bosConfig?.app.api.production;\n if (remoteUrl) env.API_REMOTE_URL = remoteUrl;\n }\n\n if (config.proxy && bosConfig) {\n const proxyUrl = resolveProxyUrl(bosConfig);\n if (proxyUrl) env.API_PROXY = proxyUrl;\n }\n\n return env;\n}\n\nasync function buildEveryPluginQuietly(cwd: string) {\n const distPath = `${cwd}/packages/every-plugin/dist/build/rspack/plugin.mjs`;\n const distExists = await Bun.file(distPath).exists();\n\n if (distExists) {\n return;\n }\n\n const result = (await run(\"bun\", [\"run\", \"--cwd\", \"packages/every-plugin\", \"build\"], {\n cwd,\n capture: true,\n })) as { stdout: string; stderr: string; exitCode: number };\n\n if (result.exitCode === 0) {\n console.log(\"[build:ssr] build succeeded\");\n return;\n }\n\n if (result.stdout.trim()) {\n process.stdout.write(result.stdout);\n }\n\n if (result.stderr.trim()) {\n process.stderr.write(result.stderr);\n }\n\n throw new Error(\n `bun run --cwd packages/every-plugin build failed with exit code ${result.exitCode}`,\n );\n}\n\nasync function buildEverythingDevQuietly(cwd: string) {\n const distPath = `${cwd}/packages/everything-dev/dist/index.mjs`;\n const distExists = await Bun.file(distPath).exists();\n\n if (distExists) {\n return;\n }\n\n const result = (await run(\"bun\", [\"run\", \"--cwd\", \"packages/everything-dev\", \"build\"], {\n cwd,\n capture: true,\n })) as { stdout: string; stderr: string; exitCode: number };\n\n if (result.exitCode === 0) {\n console.log(\"[everything-dev] build succeeded\");\n return;\n }\n\n if (result.stdout.trim()) {\n process.stdout.write(result.stdout);\n }\n\n if (result.stderr.trim()) {\n process.stderr.write(result.stderr);\n }\n\n throw new Error(\n `bun run --cwd packages/everything-dev build failed with exit code ${result.exitCode}`,\n );\n}\n\nasync function fetchPublishedConfig(\n accountId: string,\n gatewayId: string,\n): Promise<BosConfig | null> {\n try {\n return await fetchBosConfigFromFastKv<BosConfig>(`bos://${accountId}/${gatewayId}`);\n } catch {\n return null;\n }\n}\n\nfunction selectWorkspaceTargets(packages: string, bosConfig: BosConfig | null): string[] {\n const allPackages = [\n ...Object.keys(bosConfig?.app ?? {}),\n ...Object.keys(bosConfig?.plugins ?? {}),\n ];\n if (packages === \"all\") {\n return allPackages;\n }\n\n return packages\n .split(\",\")\n .map((pkg) => pkg.trim())\n .filter((pkg) => allPackages.includes(pkg));\n}\n\nasync function buildWorkspaceTargets(opts: {\n configDir: string;\n bosConfig: BosConfig | null;\n runtimeConfig: RuntimeConfig | null;\n targets: string[];\n deploy: boolean;\n}): Promise<{ built: string[]; skipped: string[] }> {\n const existing: WorkspaceTarget[] = [];\n const skipped: string[] = [];\n\n for (const target of opts.targets) {\n const resolved = resolveWorkspaceTarget(\n target,\n opts.bosConfig,\n opts.runtimeConfig,\n opts.configDir,\n );\n if (!resolved) {\n skipped.push(target);\n continue;\n }\n\n const exists = await Bun.file(`${resolved.path}/package.json`).exists();\n if (exists) existing.push(resolved);\n else skipped.push(target);\n }\n\n if (existing.length === 0) {\n return { built: [], skipped };\n }\n\n const sharedSync = await syncAndGenerateSharedUi({\n configDir: opts.configDir,\n hostMode: \"local\",\n bosConfig: opts.bosConfig ?? undefined,\n });\n if (sharedSync.catalogChanged) {\n await run(\"bun\", [\"install\"], { cwd: opts.configDir });\n }\n\n if (existing.some((entry) => entry.key === \"api\")) {\n await buildEveryPluginQuietly(opts.configDir);\n }\n\n await buildEverythingDevQuietly(opts.configDir);\n\n const env: Record<string, string> = {\n ...process.env,\n NODE_ENV: opts.deploy ? \"production\" : \"development\",\n };\n if (opts.deploy) {\n env.DEPLOY = \"true\";\n } else {\n delete env.DEPLOY;\n }\n\n const orderedExisting = opts.deploy\n ? [\n ...existing.filter((entry) => entry.kind === \"app\" && entry.key !== \"host\"),\n ...existing.filter((entry) => entry.kind === \"plugin\"),\n ...existing.filter((entry) => entry.kind === \"app\" && entry.key === \"host\"),\n ]\n : existing;\n const built: string[] = [];\n\n for (const resolved of orderedExisting) {\n const pkgJson = JSON.parse(await Bun.file(`${resolved.path}/package.json`).text()) as {\n scripts?: Record<string, string>;\n };\n const shouldDeployScript = opts.deploy && pkgJson.scripts?.deploy;\n const buildConfig = shouldDeployScript\n ? { cmd: \"bun\", args: [\"run\", \"deploy\"] }\n : (buildCommands[resolved.key] ?? { cmd: \"bun\", args: [\"run\", \"build\"] });\n\n await run(buildConfig.cmd, buildConfig.args, {\n cwd: resolved.path,\n env,\n });\n built.push(resolved.key);\n }\n\n return { built, skipped };\n}\n\nexport default createPlugin({\n variables: z.object({\n configPath: z.string().optional(),\n }),\n secrets: z.object({}),\n contract: bosContract,\n initialize: (config: any) =>\n Effect.promise(async () => {\n const configResult = await loadConfig({ path: config.variables.configPath });\n return {\n bosConfig: configResult?.config ?? null,\n runtimeConfig: configResult?.runtime ?? null,\n configDir: getProjectRoot(),\n } satisfies BosDeps;\n }),\n shutdown: () => Effect.void,\n createRouter: (deps: BosDeps, builder: any) => ({\n config: builder.config.handler(async () => buildConfigResult(deps.bosConfig)),\n\n pluginAdd: builder.pluginAdd.handler(async ({ input }: { input: PluginAddOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n key: \"\",\n error: \"No bos.config.json found\",\n };\n }\n\n const key = sanitizePluginKey(input.as ?? defaultPluginKey(input.source));\n const existing = deps.bosConfig.plugins?.[key];\n const nextPlugins = { ...(deps.bosConfig.plugins ?? {}) };\n\n nextPlugins[key] = input.source.startsWith(\"local:\")\n ? {\n ...(existing ?? {}),\n development: input.source,\n production: input.production ?? existing?.production,\n }\n : {\n ...(existing ?? {}),\n production: input.production ?? input.source,\n };\n\n deps.bosConfig = {\n ...deps.bosConfig,\n plugins: nextPlugins,\n };\n\n await saveBosConfig(deps.configDir, deps.bosConfig);\n await refreshApiContractBridge(deps.configDir);\n\n return {\n status: \"added\" as const,\n key,\n development: deps.bosConfig.plugins?.[key]?.development,\n production: deps.bosConfig.plugins?.[key]?.production,\n };\n }),\n\n pluginRemove: builder.pluginRemove.handler(\n async ({ input }: { input: PluginRemoveOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: \"No bos.config.json found\",\n };\n }\n\n if (!deps.bosConfig.plugins?.[input.key]) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: `Plugin '${input.key}' is not configured`,\n };\n }\n\n const nextPlugins = { ...(deps.bosConfig.plugins ?? {}) };\n delete nextPlugins[input.key];\n deps.bosConfig = {\n ...deps.bosConfig,\n plugins: Object.keys(nextPlugins).length > 0 ? nextPlugins : undefined,\n };\n\n await saveBosConfig(deps.configDir, deps.bosConfig);\n await refreshApiContractBridge(deps.configDir);\n\n return {\n status: \"removed\" as const,\n key: input.key,\n };\n },\n ),\n\n pluginList: builder.pluginList.handler(async () => {\n const plugins: PluginListResult[\"plugins\"] = listPluginAttachments(deps.bosConfig);\n return {\n status: \"listed\" as const,\n plugins,\n };\n }),\n\n pluginPublish: builder.pluginPublish.handler(\n async ({ input }: { input: PluginPublishOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: \"No bos.config.json found\",\n };\n }\n\n const attachment = deps.bosConfig.plugins?.[input.key];\n if (!attachment) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: `Plugin '${input.key}' is not configured`,\n };\n }\n\n const localPath = pluginLocalPath(deps.configDir, attachment);\n if (!localPath) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: `Plugin '${input.key}' does not have a local development path`,\n };\n }\n\n const pkgPath = join(localPath, \"package.json\");\n if (!(await Bun.file(pkgPath).exists())) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: `Missing package.json at ${localPath}`,\n };\n }\n\n const pkgJson = (await Bun.file(pkgPath).json()) as { scripts?: Record<string, string> };\n const script = pkgJson.scripts?.deploy ? \"deploy\" : \"build\";\n\n const { stdout, stderr, exitCode } = (await run(\"bun\", [\"run\", script], {\n cwd: localPath,\n capture: true,\n })) as { stdout: string; stderr: string; exitCode: number };\n\n if (exitCode !== 0) {\n if (stdout.trim()) process.stdout.write(stdout);\n if (stderr.trim()) process.stderr.write(stderr);\n return {\n status: \"error\" as const,\n key: input.key,\n error: `Publish failed with exit code ${exitCode}`,\n };\n }\n\n if (stdout.trim()) process.stdout.write(stdout);\n if (stderr.trim()) process.stderr.write(stderr);\n\n const publishedUrl = extractPublishedUrl(`${stdout}\\n${stderr}`);\n if (publishedUrl) {\n deps.bosConfig = {\n ...deps.bosConfig,\n plugins: {\n ...(deps.bosConfig.plugins ?? {}),\n [input.key]: {\n ...(deps.bosConfig.plugins?.[input.key] ?? {}),\n production: publishedUrl,\n },\n },\n };\n await saveBosConfig(deps.configDir, deps.bosConfig);\n await refreshApiContractBridge(deps.configDir);\n }\n\n return {\n status: \"published\" as const,\n key: input.key,\n path: localPath,\n script,\n production: publishedUrl ?? attachment.production,\n };\n },\n ),\n\n dev: builder.dev.handler(async ({ input }: { input: DevOptions }) => {\n const localPackages = detectLocalPackages(\n deps.bosConfig ?? undefined,\n deps.runtimeConfig ?? undefined,\n );\n\n const appConfig = buildAppConfig({\n host: localPackages.includes(\"host\") ? (input.host as string) : \"remote\",\n ui: localPackages.includes(\"ui\") ? (input.ui as string) : \"remote\",\n api: localPackages.includes(\"api\") ? (input.api as string) : \"remote\",\n proxy: input.proxy,\n ssr: input.ssr,\n });\n\n const sharedSync = await syncAndGenerateSharedUi({\n configDir: deps.configDir,\n hostMode: appConfig.host,\n bosConfig: deps.bosConfig ?? undefined,\n });\n if (sharedSync.catalogChanged) {\n await run(\"bun\", [\"install\"], { cwd: deps.configDir });\n }\n if (\n (appConfig.api === \"local\" && !appConfig.proxy) ||\n localPackages.some((pkg) => pkg.startsWith(\"plugin:\"))\n ) {\n await buildEveryPluginQuietly(deps.configDir);\n }\n\n await buildEverythingDevQuietly(deps.configDir);\n\n const refreshed = await loadConfig({ cwd: deps.configDir });\n deps.bosConfig = refreshed?.config ?? deps.bosConfig;\n deps.runtimeConfig = refreshed?.runtime ?? deps.runtimeConfig;\n\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n description: \"No bos.config.json found\",\n processes: [],\n };\n }\n\n if (appConfig.proxy && !resolveProxyUrl(deps.bosConfig)) {\n return {\n status: \"error\" as const,\n description: \"No valid proxy URL configured in bos.config.json\",\n processes: [],\n };\n }\n\n const refreshedLocalPackages = detectLocalPackages(\n deps.bosConfig ?? undefined,\n deps.runtimeConfig ?? undefined,\n );\n const processes = determineProcesses(appConfig, refreshedLocalPackages, deps.runtimeConfig);\n const env = await buildEnvVars(appConfig, deps.bosConfig);\n const hostPort = input.port ?? getHostDevelopmentPort(deps.bosConfig.app.host.development);\n const developmentRuntime = buildRuntimeConfig(deps.bosConfig, {\n uiSource: appConfig.ui,\n apiSource: appConfig.api,\n hostUrl: `http://localhost:${hostPort}`,\n proxy: env.API_PROXY,\n env: \"development\",\n plugins: deps.runtimeConfig?.plugins,\n });\n const runtimeConfig = await prepareDevelopmentRuntimeConfig(developmentRuntime, {\n hostPort,\n ssr: appConfig.ssr,\n });\n\n await syncApiContractBridge({\n configDir: deps.configDir,\n runtimeConfig: runtimeConfig,\n apiBaseUrl: runtimeConfig.api.url,\n });\n\n const orchestrator: AppOrchestrator = {\n packages: processes,\n env,\n description: buildDescription(appConfig),\n appConfig,\n bosConfig: deps.bosConfig,\n runtimeConfig,\n port: parsePort(runtimeConfig.hostUrl),\n interactive: input.interactive,\n };\n\n startApp(orchestrator);\n\n return {\n status: \"started\" as const,\n description: orchestrator.description,\n processes,\n };\n }),\n\n start: builder.start.handler(async ({ input }: { input: StartOptions }) => {\n let remoteConfig: BosConfig | null = null;\n\n if (input.account && input.domain) {\n remoteConfig = await fetchPublishedConfig(input.account, input.domain);\n if (!remoteConfig) {\n return {\n status: \"error\" as const,\n url: \"\",\n };\n }\n }\n\n const config = remoteConfig || deps.bosConfig;\n if (!config) {\n return {\n status: \"error\" as const,\n url: \"\",\n };\n }\n\n const port = input.port ?? getHostDevelopmentPort(config.app.host.development);\n const appConfig: AppConfig = { host: \"remote\", ui: \"remote\", api: \"remote\" };\n const env = await buildEnvVars(appConfig, config);\n const isStaging = input.env === \"staging\";\n const runtimePlugins = remoteConfig\n ? await buildRuntimePluginsForConfig(config, deps.configDir, \"production\")\n : deps.runtimeConfig?.plugins;\n const runtimeConfig = buildRuntimeConfig(config, {\n uiSource: \"remote\",\n apiSource: \"remote\",\n hostUrl: `http://localhost:${port}`,\n env: \"production\",\n plugins: runtimePlugins,\n });\n\n await syncApiContractBridge({\n configDir: deps.configDir,\n runtimeConfig: runtimeConfig,\n apiBaseUrl: runtimeConfig.api.url,\n });\n\n const stagingEnvVars: Record<string, string> = isStaging\n ? { GATEWAY_DOMAIN: config.staging?.domain ?? config.domain ?? \"\" }\n : {};\n\n const orchestrator: AppOrchestrator = {\n packages: [\"host\"],\n env: {\n NODE_ENV: \"production\",\n ...env,\n ...stagingEnvVars,\n },\n description: `${isStaging ? \"Staging\" : \"Production\"} Mode (${config.account})`,\n appConfig,\n bosConfig: config,\n runtimeConfig,\n port,\n interactive: input.interactive,\n noLogs: true,\n };\n\n startApp(orchestrator);\n return {\n status: \"running\" as const,\n url: `http://localhost:${port}`,\n };\n }),\n\n build: builder.build.handler(async ({ input }: { input: BuildOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n built: [],\n skipped: [],\n };\n }\n\n const targets = selectWorkspaceTargets(input.packages, deps.bosConfig);\n if (targets.length === 0) {\n return {\n status: \"error\" as const,\n built: [],\n skipped: [],\n };\n }\n\n const runtimeConfig = buildRuntimeConfig(deps.bosConfig, {\n uiSource: deps.bosConfig.app.ui?.development ? \"local\" : \"remote\",\n apiSource: deps.bosConfig.app.api?.development ? \"local\" : \"remote\",\n hostUrl: resolveDevelopmentHostUrl(deps.bosConfig.app.host.development),\n env: \"development\",\n plugins: deps.runtimeConfig?.plugins,\n });\n\n await syncApiContractBridge({\n configDir: deps.configDir,\n runtimeConfig,\n apiBaseUrl: runtimeConfig.api.url,\n });\n\n const { built, skipped } = await buildWorkspaceTargets({\n configDir: deps.configDir,\n bosConfig: deps.bosConfig,\n runtimeConfig: runtimeConfig,\n targets,\n deploy: input.deploy,\n });\n\n if (built.length === 0) {\n return {\n status: \"error\" as const,\n built: [],\n skipped,\n };\n }\n\n return {\n status: \"success\" as const,\n built,\n skipped,\n deployed: input.deploy,\n };\n }),\n\n publish: builder.publish.handler(async ({ input }: { input: PublishOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n registryUrl: \"\",\n error: \"No bos.config.json found\",\n };\n }\n\n const account = deps.bosConfig.account;\n const gateway = deps.bosConfig.domain;\n if (!gateway) {\n return {\n status: \"error\" as const,\n registryUrl: \"\",\n error: \"bos.config.json must define domain to publish\",\n };\n }\n\n const network = input.network ?? getNetworkIdForAccount(account);\n const bosUrl = `bos://${account}/${gateway}`;\n const registryUrl = buildRegistryConfigUrlForNetwork(network, account, gateway);\n const targets = selectWorkspaceTargets(input.packages, deps.bosConfig);\n\n let publishConfig = deps.bosConfig;\n let built: string[] | undefined;\n let skipped: string[] | undefined;\n\n if (input.dryRun) {\n return {\n status: \"dry-run\" as const,\n registryUrl,\n built,\n skipped,\n };\n }\n\n if (input.deploy) {\n const result = await buildWorkspaceTargets({\n configDir: deps.configDir,\n bosConfig: deps.bosConfig,\n runtimeConfig: deps.runtimeConfig,\n targets,\n deploy: true,\n });\n built = result.built;\n skipped = result.skipped;\n\n const refreshed = await loadConfig({ cwd: deps.configDir });\n if (refreshed?.config) {\n deps.bosConfig = refreshed.config;\n deps.runtimeConfig = refreshed.runtime;\n publishConfig = refreshed.config;\n }\n }\n\n const payload = JSON.stringify({\n [`apps/${account}/${gateway}/bos.config.json`]: JSON.stringify(publishConfig),\n });\n const argsBase64 = Buffer.from(payload).toString(\"base64\");\n const privateKey =\n input.privateKey || process.env.NEAR_PRIVATE_KEY || process.env.BOS_NEAR_PRIVATE_KEY;\n\n try {\n await Effect.runPromise(ensureNearCli);\n let txHash: string | undefined;\n\n try {\n const tx = await Effect.runPromise(\n executeTransaction({\n account,\n contract: getRegistryNamespaceForNetwork(network),\n method: \"__fastdata_kv\",\n argsBase64,\n network,\n privateKey,\n gas: \"300Tgas\",\n deposit: \"0NEAR\",\n }),\n );\n txHash = tx.txHash;\n } catch (error) {\n txHash = extractTransactionHash(error);\n\n if (!txHash) {\n throw error;\n }\n\n const verifiedConfig = await fetchBosConfigFromFastKv<BosConfig>(bosUrl);\n if (JSON.stringify(verifiedConfig) !== JSON.stringify(publishConfig)) {\n throw error;\n }\n }\n\n return {\n status: \"published\" as const,\n registryUrl,\n txHash,\n built,\n skipped,\n };\n } catch (error) {\n return {\n status: \"error\" as const,\n registryUrl,\n error: error instanceof Error ? error.message : \"Unknown error\",\n built,\n skipped,\n };\n }\n }),\n\n keyPublish: builder.keyPublish.handler(async ({ input }: { input: KeyPublishOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n account: \"\",\n network: \"mainnet\" as const,\n contract: \"\",\n allowance: input.allowance,\n functionNames: PUBLISH_FUNCTION_NAMES,\n error: \"No bos.config.json found\",\n };\n }\n\n const account = deps.bosConfig.account;\n const network = getNetworkIdForAccount(account);\n const contract = getRegistryNamespaceForAccount(account);\n try {\n await Effect.runPromise(ensureNearCli);\n const keyPair = await addFunctionCallAccessKey({\n account,\n contract,\n allowance: input.allowance,\n functionNames: PUBLISH_FUNCTION_NAMES,\n network,\n });\n\n return {\n status: \"published\" as const,\n account,\n network,\n contract,\n allowance: input.allowance,\n functionNames: PUBLISH_FUNCTION_NAMES,\n publicKey: keyPair.publicKey,\n privateKey: keyPair.privateKey,\n };\n } catch (error) {\n return {\n status: \"error\" as const,\n account,\n network,\n contract,\n allowance: input.allowance,\n functionNames: PUBLISH_FUNCTION_NAMES,\n error: error instanceof Error ? error.message : \"Unknown error\",\n };\n }\n }),\n\n init: builder.init.handler(async ({ input }: { input: InitOptions }) => {\n try {\n let account = input.account;\n let gateway = input.gateway;\n let destination = input.destination;\n let name = input.name;\n let domain = input.domain;\n let withHost = input.withHost;\n\n if (!account || !gateway) {\n if (input.noInteractive) {\n return {\n status: \"error\" as const,\n destination: \"\",\n parentAccount: account ?? \"\",\n parentGateway: gateway ?? \"\",\n name: input.name,\n domain: input.domain,\n extends: account && gateway ? `bos://${account}/${gateway}` : \"\",\n filesCopied: 0,\n error:\n \"account and gateway are required (use --no-interactive to skip prompts and provide them as positional args)\",\n };\n }\n\n const prompted = await promptInitOptions({\n account,\n gateway,\n destination,\n name,\n domain,\n withHost,\n });\n account = prompted.account;\n gateway = prompted.gateway;\n destination = prompted.destination;\n name = prompted.name;\n domain = prompted.domain;\n withHost = prompted.withHost;\n }\n\n destination = destination || gateway;\n\n const { sourceDir, cleanup } = await resolveSourceDir({\n account,\n gateway,\n source: input.source,\n });\n\n try {\n const patterns = await readTemplatekeep(sourceDir);\n if (patterns.length === 0) {\n return {\n status: \"error\" as const,\n destination,\n parentAccount: account,\n parentGateway: gateway,\n name,\n domain,\n extends: `bos://${account}/${gateway}`,\n filesCopied: 0,\n error: \"No .templatekeep found in template source\",\n };\n }\n\n const filesCopied = await copyFilteredFiles(sourceDir, destination, patterns, {\n withHost,\n });\n\n await personalizeConfig(destination, {\n parentAccount: account,\n parentGateway: gateway,\n name: name || account,\n domain: domain || gateway,\n });\n\n if (!input.noInstall) {\n await runBunInstall(destination);\n }\n\n return {\n status: \"initialized\" as const,\n destination: resolve(destination),\n parentAccount: account,\n parentGateway: gateway,\n name,\n domain,\n extends: `bos://${account}/${gateway}`,\n filesCopied,\n };\n } finally {\n await cleanup();\n }\n } catch (error) {\n return {\n status: \"error\" as const,\n destination: input.destination ?? input.gateway ?? \"\",\n parentAccount: input.account ?? \"\",\n parentGateway: input.gateway ?? \"\",\n name: input.name,\n domain: input.domain,\n extends: input.account && input.gateway ? `bos://${input.account}/${input.gateway}` : \"\",\n filesCopied: 0,\n error: error instanceof Error ? error.message : \"Unknown error\",\n };\n }\n }),\n }),\n});\n\nfunction extractTransactionHash(error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n const match =\n message.match(/Transaction ID:\\s*([A-Za-z0-9]+)/i) ||\n message.match(/([A-HJ-NP-Za-km-z1-9]{43,44})/);\n\n return match?.[1];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkDA,MAAM,qBAAgC;CACpC,MAAM;CACN,IAAI;CACJ,KAAK;CACL,KAAK;CACN;AAED,MAAM,gBAAiE;CACrE,MAAM;EAAE,KAAK;EAAO,MAAM,CAAC,OAAO,QAAQ;EAAE;CAC5C,IAAI;EAAE,KAAK;EAAO,MAAM,CAAC,OAAO,QAAQ;EAAE;CAC1C,KAAK;EAAE,KAAK;EAAO,MAAM,CAAC,OAAO,QAAQ;EAAE;CAC5C;AAED,MAAM,yBAAyB,CAAC,gBAAgB;AAUhD,SAAS,gBAAgB,OAA2B,cAAsC;AACxF,KAAI,UAAU,WAAW,UAAU,SAAU,QAAO;AACpD,QAAO;;AAGT,SAAS,eAAe,SAMV;AACZ,QAAO;EACL,MAAM,gBAAgB,QAAQ,MAAM,mBAAmB,KAAK;EAC5D,IAAI,gBAAgB,QAAQ,IAAI,mBAAmB,GAAG;EACtD,KAAK,gBAAgB,QAAQ,KAAK,mBAAmB,IAAI;EACzD,OAAO,QAAQ;EACf,KAAK,QAAQ,OAAO,mBAAmB;EACxC;;AAGH,SAAS,iBAAiB,QAA2B;AACnD,KAAI,OAAO,SAAS,WAAW,OAAO,OAAO,WAAW,OAAO,QAAQ,WAAW,CAAC,OAAO,MACxF,QAAO;CAGT,MAAM,QAAkB,EAAE;AAC1B,OAAM,KAAK,OAAO,SAAS,WAAW,gBAAgB,aAAa;AACnE,KAAI,OAAO,OAAO,SAAU,OAAM,KAAK,YAAY;AACnD,KAAI,OAAO,MAAO,OAAM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MAAM,UAAU,SAAS,MAAM,QAAQ,GAAG,MAAM,YAAY;KACtF,aAAa;KACb,OAAO,iBAAiB,QAAQ,MAAM,UAAU;KACjD;;IAEH;EACH;CACF,CAAC;AAEF,SAAS,uBAAuB,OAAgB;CAC9C,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AAKtE,SAHE,QAAQ,MAAM,oCAAoC,IAClD,QAAQ,MAAM,gCAAgC,IAEjC"}
1
+ {"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from \"node:fs\";\nimport { basename, join, resolve } from \"node:path\";\nimport { Effect } from \"effect\";\nimport { syncApiContractBridge } from \"./api-contract\";\nimport { buildRuntimeConfig, detectLocalPackages, prepareDevelopmentRuntimeConfig } from \"./app\";\nimport {\n copyFilteredFiles,\n personalizeConfig,\n readTemplatekeep,\n resolveSourceDir,\n runBunInstall,\n} from \"./cli/init\";\nimport { promptInitOptions } from \"./cli/prompts\";\nimport {\n buildRuntimePluginsForConfig,\n getHostDevelopmentPort,\n getProjectRoot,\n loadConfig,\n parsePort,\n resolveDevelopmentHostUrl,\n resolveLocalDevelopmentPath,\n} from \"./config\";\nimport {\n type BosConfigResult,\n type BuildOptions,\n bosContract,\n type DevOptions,\n type InitOptions,\n type KeyPublishOptions,\n type PluginAddOptions,\n type PluginListResult,\n type PluginPublishOptions,\n type PluginRemoveOptions,\n type PublishOptions,\n type StartOptions,\n} from \"./contract\";\nimport { type AppConfig, type AppOrchestrator, startApp } from \"./dev-session\";\nimport {\n buildRegistryConfigUrlForNetwork,\n fetchBosConfigFromFastKv,\n getRegistryNamespaceForAccount,\n getRegistryNamespaceForNetwork,\n} from \"./fastkv\";\nimport { addFunctionCallAccessKey, ensureNearCli, executeTransaction } from \"./near-cli\";\nimport { getNetworkIdForAccount } from \"./network\";\nimport { createPlugin, z } from \"./sdk\";\nimport { syncAndGenerateSharedUi } from \"./shared\";\nimport type { BosConfig, RuntimeConfig, SourceMode } from \"./types\";\nimport { run } from \"./utils/run\";\n\nconst DEFAULT_DEV_CONFIG: AppConfig = {\n host: \"local\",\n ui: \"local\",\n api: \"local\",\n ssr: false,\n};\n\nconst buildCommands: Record<string, { cmd: string; args: string[] }> = {\n host: { cmd: \"bun\", args: [\"run\", \"build\"] },\n ui: { cmd: \"bun\", args: [\"run\", \"build\"] },\n api: { cmd: \"bun\", args: [\"run\", \"build\"] },\n};\n\nconst PUBLISH_FUNCTION_NAMES = [\"__fastdata_kv\"];\n\ntype BosDeps = {\n bosConfig: BosConfig | null;\n runtimeConfig: RuntimeConfig | null;\n configDir: string;\n};\n\ntype PluginAttachmentConfig = NonNullable<BosConfig[\"plugins\"]>[string];\n\nfunction parseSourceMode(value: string | undefined, defaultValue: SourceMode): SourceMode {\n if (value === \"local\" || value === \"remote\") return value;\n return defaultValue;\n}\n\nfunction buildAppConfig(options: {\n host?: string;\n ui?: string;\n api?: string;\n proxy?: boolean;\n ssr?: boolean;\n}): AppConfig {\n return {\n host: parseSourceMode(options.host, DEFAULT_DEV_CONFIG.host),\n ui: parseSourceMode(options.ui, DEFAULT_DEV_CONFIG.ui),\n api: parseSourceMode(options.api, DEFAULT_DEV_CONFIG.api),\n proxy: options.proxy,\n ssr: options.ssr ?? DEFAULT_DEV_CONFIG.ssr,\n };\n}\n\nfunction buildDescription(config: AppConfig): string {\n if (config.host === \"local\" && config.ui === \"local\" && config.api === \"local\" && !config.proxy) {\n return \"Full Local Development\";\n }\n\n const parts: string[] = [];\n parts.push(config.host === \"remote\" ? \"Remote Host\" : \"Local Host\");\n if (config.ui === \"remote\") parts.push(\"Remote UI\");\n if (config.proxy) parts.push(\"Proxy API → Production\");\n else if (config.api === \"remote\") parts.push(\"Remote API\");\n return parts.join(\" + \");\n}\n\nfunction buildConfigResult(bosConfig: BosConfig | null): BosConfigResult {\n const packages = bosConfig ? Object.keys(bosConfig.app) : [];\n const remotes = packages.filter((name) => name !== \"host\");\n\n return {\n config: bosConfig,\n packages,\n remotes,\n };\n}\n\ntype WorkspaceTarget = {\n key: string;\n kind: \"app\" | \"plugin\";\n path: string;\n};\n\nfunction resolveWorkspaceTarget(\n key: string,\n bosConfig: BosConfig | null,\n runtimeConfig: RuntimeConfig | null,\n configDir: string,\n): WorkspaceTarget | null {\n if (bosConfig?.app && key in bosConfig.app) {\n return {\n key,\n kind: \"app\",\n path: `${configDir}/${key}`,\n };\n }\n\n const runtimePlugin = runtimeConfig?.plugins?.[key];\n const pluginPath =\n runtimePlugin?.localPath ??\n resolveLocalDevelopmentPath(bosConfig?.plugins?.[key]?.development, configDir);\n if (pluginPath) {\n return {\n key,\n kind: \"plugin\",\n path: pluginPath,\n };\n }\n\n return null;\n}\n\nfunction determineProcesses(\n config: AppConfig,\n localPackages: string[],\n runtimeConfig?: RuntimeConfig | null,\n): string[] {\n const processes: string[] = [];\n if (config.ssr && config.ui === \"local\") processes.push(\"ui-ssr\");\n if (config.ui === \"local\") processes.push(\"ui\");\n if (config.api === \"local\" && !config.proxy) processes.push(\"api\");\n for (const pkg of localPackages) {\n if (pkg.startsWith(\"plugin:\")) {\n const pluginId = pkg.slice(\"plugin:\".length);\n if (runtimeConfig?.plugins?.[pluginId]?.source === \"local\") {\n processes.push(pkg);\n }\n }\n }\n processes.push(\"host\");\n return processes;\n}\n\nfunction isValidProxyUrl(url: string): boolean {\n try {\n const parsed = new URL(url);\n return parsed.protocol === \"http:\" || parsed.protocol === \"https:\";\n } catch {\n return false;\n }\n}\n\nfunction resolveProxyUrl(bosConfig: BosConfig | null): string | null {\n if (!bosConfig) return null;\n const apiConfig = bosConfig.app.api;\n if (!apiConfig) return null;\n if (apiConfig.proxy && isValidProxyUrl(apiConfig.proxy)) return apiConfig.proxy;\n if (apiConfig.production && isValidProxyUrl(apiConfig.production)) return apiConfig.production;\n return null;\n}\n\nfunction sanitizePluginKey(value: string): string {\n return value\n .replace(/[^A-Za-z0-9/_-]/g, \"-\")\n .replace(/\\/+/g, \"/\")\n .split(\"/\")\n .filter(Boolean)\n .map((segment) => segment.replace(/[^A-Za-z0-9_-]/g, \"-\"))\n .join(\"/\")\n .replace(/^\\/+|\\/+$/g, \"\");\n}\n\nfunction defaultPluginKey(source: string): string {\n const normalized = source.replace(/^local:/, \"\").replace(/\\/$/, \"\");\n if (source.startsWith(\"local:\")) {\n return sanitizePluginKey(basename(normalized)) || \"plugin\";\n }\n\n try {\n const url = new URL(source);\n return sanitizePluginKey(basename(url.pathname) || url.hostname) || \"plugin\";\n } catch {\n return sanitizePluginKey(source) || \"plugin\";\n }\n}\n\nfunction pluginLocalPath(configDir: string, attachment: PluginAttachmentConfig): string | null {\n const source = attachment.development ?? attachment.production;\n if (!source?.startsWith(\"local:\")) {\n return null;\n }\n\n return join(configDir, source.slice(\"local:\".length));\n}\n\nasync function saveBosConfig(configDir: string, config: BosConfig): Promise<void> {\n const filePath = join(configDir, \"bos.config.json\");\n const next = `${JSON.stringify(config, null, 2)}\\n`;\n try {\n if (readFileSync(filePath, \"utf8\") === next) return;\n } catch {\n // file does not exist yet\n }\n\n writeFileSync(filePath, next);\n}\n\nfunction listPluginAttachments(config: BosConfig | null) {\n return (Object.entries(config?.plugins ?? {}) as Array<[string, PluginAttachmentConfig]>)\n .map(([key, attachment]) => ({\n key,\n development: attachment.development,\n production: attachment.production,\n localPath: attachment.development?.startsWith(\"local:\")\n ? attachment.development.slice(\"local:\".length)\n : undefined,\n source: attachment.development?.startsWith(\"local:\")\n ? (\"local\" as const)\n : (\"remote\" as const),\n }))\n .sort((a, b) => a.key.localeCompare(b.key));\n}\n\nasync function refreshApiContractBridge(configDir: string): Promise<void> {\n const refreshed = await loadConfig({ cwd: configDir, env: \"development\" });\n if (!refreshed) return;\n\n await syncApiContractBridge({\n configDir,\n runtimeConfig: refreshed.runtime,\n apiBaseUrl: refreshed.runtime.api.url,\n });\n}\n\nfunction extractPublishedUrl(output: string): string | null {\n const match = output.match(/https?:\\/\\/[^\\s\"'<>]+/g);\n if (!match || match.length === 0) return null;\n return match[match.length - 1] ?? null;\n}\n\nasync function buildEnvVars(\n config: AppConfig,\n bosConfig?: BosConfig | null,\n): Promise<Record<string, string>> {\n const env: Record<string, string> = {\n HOST_SOURCE: config.host,\n UI_SOURCE: config.ui,\n API_SOURCE: config.api,\n };\n\n if (config.host === \"remote\") {\n const remoteUrl = bosConfig?.app.host.production;\n if (remoteUrl) env.HOST_REMOTE_URL = remoteUrl;\n }\n\n if (config.ui === \"remote\") {\n const remoteUrl = bosConfig?.app.ui.production;\n if (remoteUrl) env.UI_REMOTE_URL = remoteUrl;\n }\n\n if (config.api === \"remote\") {\n const remoteUrl = bosConfig?.app.api.production;\n if (remoteUrl) env.API_REMOTE_URL = remoteUrl;\n }\n\n if (config.proxy && bosConfig) {\n const proxyUrl = resolveProxyUrl(bosConfig);\n if (proxyUrl) env.API_PROXY = proxyUrl;\n }\n\n return env;\n}\n\nasync function buildEveryPluginQuietly(cwd: string) {\n const packageDir = `${cwd}/packages/every-plugin`;\n const packageExists = await Bun.file(`${packageDir}/package.json`).exists();\n if (!packageExists) {\n return;\n }\n\n const distPath = `${cwd}/packages/every-plugin/dist/build/rspack/plugin.mjs`;\n const distExists = await Bun.file(distPath).exists();\n\n if (distExists) {\n return;\n }\n\n const result = (await run(\"bun\", [\"run\", \"--cwd\", \"packages/every-plugin\", \"build\"], {\n cwd,\n capture: true,\n })) as { stdout: string; stderr: string; exitCode: number };\n\n if (result.exitCode === 0) {\n console.log(\"[build:ssr] build succeeded\");\n return;\n }\n\n if (result.stdout.trim()) {\n process.stdout.write(result.stdout);\n }\n\n if (result.stderr.trim()) {\n process.stderr.write(result.stderr);\n }\n\n throw new Error(\n `bun run --cwd packages/every-plugin build failed with exit code ${result.exitCode}`,\n );\n}\n\nasync function buildEverythingDevQuietly(cwd: string) {\n const packageDir = `${cwd}/packages/everything-dev`;\n const packageExists = await Bun.file(`${packageDir}/package.json`).exists();\n if (!packageExists) {\n return;\n }\n\n const distPath = `${cwd}/packages/everything-dev/dist/index.mjs`;\n const distExists = await Bun.file(distPath).exists();\n\n if (distExists) {\n return;\n }\n\n const result = (await run(\"bun\", [\"run\", \"--cwd\", \"packages/everything-dev\", \"build\"], {\n cwd,\n capture: true,\n })) as { stdout: string; stderr: string; exitCode: number };\n\n if (result.exitCode === 0) {\n console.log(\"[everything-dev] build succeeded\");\n return;\n }\n\n if (result.stdout.trim()) {\n process.stdout.write(result.stdout);\n }\n\n if (result.stderr.trim()) {\n process.stderr.write(result.stderr);\n }\n\n throw new Error(\n `bun run --cwd packages/everything-dev build failed with exit code ${result.exitCode}`,\n );\n}\n\nasync function fetchPublishedConfig(\n accountId: string,\n gatewayId: string,\n): Promise<BosConfig | null> {\n try {\n return await fetchBosConfigFromFastKv<BosConfig>(`bos://${accountId}/${gatewayId}`);\n } catch {\n return null;\n }\n}\n\nfunction selectWorkspaceTargets(packages: string, bosConfig: BosConfig | null): string[] {\n const allPackages = [\n ...Object.keys(bosConfig?.app ?? {}),\n ...Object.keys(bosConfig?.plugins ?? {}),\n ];\n if (packages === \"all\") {\n return allPackages;\n }\n\n return packages\n .split(\",\")\n .map((pkg) => pkg.trim())\n .filter((pkg) => allPackages.includes(pkg));\n}\n\nasync function buildWorkspaceTargets(opts: {\n configDir: string;\n bosConfig: BosConfig | null;\n runtimeConfig: RuntimeConfig | null;\n targets: string[];\n deploy: boolean;\n}): Promise<{ built: string[]; skipped: string[] }> {\n const existing: WorkspaceTarget[] = [];\n const skipped: string[] = [];\n\n for (const target of opts.targets) {\n const resolved = resolveWorkspaceTarget(\n target,\n opts.bosConfig,\n opts.runtimeConfig,\n opts.configDir,\n );\n if (!resolved) {\n skipped.push(target);\n continue;\n }\n\n const exists = await Bun.file(`${resolved.path}/package.json`).exists();\n if (exists) existing.push(resolved);\n else skipped.push(target);\n }\n\n if (existing.length === 0) {\n return { built: [], skipped };\n }\n\n const sharedSync = await syncAndGenerateSharedUi({\n configDir: opts.configDir,\n hostMode: \"local\",\n bosConfig: opts.bosConfig ?? undefined,\n });\n if (sharedSync.catalogChanged) {\n await run(\"bun\", [\"install\"], { cwd: opts.configDir });\n }\n\n if (existing.some((entry) => entry.key === \"api\")) {\n await buildEveryPluginQuietly(opts.configDir);\n }\n\n await buildEverythingDevQuietly(opts.configDir);\n\n const env: Record<string, string> = {\n ...process.env,\n NODE_ENV: opts.deploy ? \"production\" : \"development\",\n };\n if (opts.deploy) {\n env.DEPLOY = \"true\";\n } else {\n delete env.DEPLOY;\n }\n\n const orderedExisting = opts.deploy\n ? [\n ...existing.filter((entry) => entry.kind === \"app\" && entry.key !== \"host\"),\n ...existing.filter((entry) => entry.kind === \"plugin\"),\n ...existing.filter((entry) => entry.kind === \"app\" && entry.key === \"host\"),\n ]\n : existing;\n const built: string[] = [];\n\n for (const resolved of orderedExisting) {\n const pkgJson = JSON.parse(await Bun.file(`${resolved.path}/package.json`).text()) as {\n scripts?: Record<string, string>;\n };\n const shouldDeployScript = opts.deploy && pkgJson.scripts?.deploy;\n const buildConfig = shouldDeployScript\n ? { cmd: \"bun\", args: [\"run\", \"deploy\"] }\n : (buildCommands[resolved.key] ?? { cmd: \"bun\", args: [\"run\", \"build\"] });\n\n await run(buildConfig.cmd, buildConfig.args, {\n cwd: resolved.path,\n env,\n });\n built.push(resolved.key);\n }\n\n return { built, skipped };\n}\n\nexport default createPlugin({\n variables: z.object({\n configPath: z.string().optional(),\n }),\n secrets: z.object({}),\n contract: bosContract,\n initialize: (config: any) =>\n Effect.promise(async () => {\n const configResult = await loadConfig({ path: config.variables.configPath });\n return {\n bosConfig: configResult?.config ?? null,\n runtimeConfig: configResult?.runtime ?? null,\n configDir: getProjectRoot(),\n } satisfies BosDeps;\n }),\n shutdown: () => Effect.void,\n createRouter: (deps: BosDeps, builder: any) => ({\n config: builder.config.handler(async () => buildConfigResult(deps.bosConfig)),\n\n pluginAdd: builder.pluginAdd.handler(async ({ input }: { input: PluginAddOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n key: \"\",\n error: \"No bos.config.json found\",\n };\n }\n\n const key = sanitizePluginKey(input.as ?? defaultPluginKey(input.source));\n const existing = deps.bosConfig.plugins?.[key];\n const nextPlugins = { ...(deps.bosConfig.plugins ?? {}) };\n\n nextPlugins[key] = input.source.startsWith(\"local:\")\n ? {\n ...(existing ?? {}),\n development: input.source,\n production: input.production ?? existing?.production,\n }\n : {\n ...(existing ?? {}),\n production: input.production ?? input.source,\n };\n\n deps.bosConfig = {\n ...deps.bosConfig,\n plugins: nextPlugins,\n };\n\n await saveBosConfig(deps.configDir, deps.bosConfig);\n await refreshApiContractBridge(deps.configDir);\n\n return {\n status: \"added\" as const,\n key,\n development: deps.bosConfig.plugins?.[key]?.development,\n production: deps.bosConfig.plugins?.[key]?.production,\n };\n }),\n\n pluginRemove: builder.pluginRemove.handler(\n async ({ input }: { input: PluginRemoveOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: \"No bos.config.json found\",\n };\n }\n\n if (!deps.bosConfig.plugins?.[input.key]) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: `Plugin '${input.key}' is not configured`,\n };\n }\n\n const nextPlugins = { ...(deps.bosConfig.plugins ?? {}) };\n delete nextPlugins[input.key];\n deps.bosConfig = {\n ...deps.bosConfig,\n plugins: Object.keys(nextPlugins).length > 0 ? nextPlugins : undefined,\n };\n\n await saveBosConfig(deps.configDir, deps.bosConfig);\n await refreshApiContractBridge(deps.configDir);\n\n return {\n status: \"removed\" as const,\n key: input.key,\n };\n },\n ),\n\n pluginList: builder.pluginList.handler(async () => {\n const plugins: PluginListResult[\"plugins\"] = listPluginAttachments(deps.bosConfig);\n return {\n status: \"listed\" as const,\n plugins,\n };\n }),\n\n pluginPublish: builder.pluginPublish.handler(\n async ({ input }: { input: PluginPublishOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: \"No bos.config.json found\",\n };\n }\n\n const attachment = deps.bosConfig.plugins?.[input.key];\n if (!attachment) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: `Plugin '${input.key}' is not configured`,\n };\n }\n\n const localPath = pluginLocalPath(deps.configDir, attachment);\n if (!localPath) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: `Plugin '${input.key}' does not have a local development path`,\n };\n }\n\n const pkgPath = join(localPath, \"package.json\");\n if (!(await Bun.file(pkgPath).exists())) {\n return {\n status: \"error\" as const,\n key: input.key,\n error: `Missing package.json at ${localPath}`,\n };\n }\n\n const pkgJson = (await Bun.file(pkgPath).json()) as { scripts?: Record<string, string> };\n const script = pkgJson.scripts?.deploy ? \"deploy\" : \"build\";\n\n const { stdout, stderr, exitCode } = (await run(\"bun\", [\"run\", script], {\n cwd: localPath,\n capture: true,\n })) as { stdout: string; stderr: string; exitCode: number };\n\n if (exitCode !== 0) {\n if (stdout.trim()) process.stdout.write(stdout);\n if (stderr.trim()) process.stderr.write(stderr);\n return {\n status: \"error\" as const,\n key: input.key,\n error: `Publish failed with exit code ${exitCode}`,\n };\n }\n\n if (stdout.trim()) process.stdout.write(stdout);\n if (stderr.trim()) process.stderr.write(stderr);\n\n const publishedUrl = extractPublishedUrl(`${stdout}\\n${stderr}`);\n if (publishedUrl) {\n deps.bosConfig = {\n ...deps.bosConfig,\n plugins: {\n ...(deps.bosConfig.plugins ?? {}),\n [input.key]: {\n ...(deps.bosConfig.plugins?.[input.key] ?? {}),\n production: publishedUrl,\n },\n },\n };\n await saveBosConfig(deps.configDir, deps.bosConfig);\n await refreshApiContractBridge(deps.configDir);\n }\n\n return {\n status: \"published\" as const,\n key: input.key,\n path: localPath,\n script,\n production: publishedUrl ?? attachment.production,\n };\n },\n ),\n\n dev: builder.dev.handler(async ({ input }: { input: DevOptions }) => {\n const localPackages = detectLocalPackages(\n deps.bosConfig ?? undefined,\n deps.runtimeConfig ?? undefined,\n );\n\n const appConfig = buildAppConfig({\n host: localPackages.includes(\"host\") ? (input.host as string) : \"remote\",\n ui: localPackages.includes(\"ui\") ? (input.ui as string) : \"remote\",\n api: localPackages.includes(\"api\") ? (input.api as string) : \"remote\",\n proxy: input.proxy,\n ssr: input.ssr,\n });\n\n const sharedSync = await syncAndGenerateSharedUi({\n configDir: deps.configDir,\n hostMode: appConfig.host,\n bosConfig: deps.bosConfig ?? undefined,\n });\n if (sharedSync.catalogChanged) {\n await run(\"bun\", [\"install\"], { cwd: deps.configDir });\n }\n if (\n (appConfig.api === \"local\" && !appConfig.proxy) ||\n localPackages.some((pkg) => pkg.startsWith(\"plugin:\"))\n ) {\n await buildEveryPluginQuietly(deps.configDir);\n }\n\n await buildEverythingDevQuietly(deps.configDir);\n\n const refreshed = await loadConfig({ cwd: deps.configDir });\n deps.bosConfig = refreshed?.config ?? deps.bosConfig;\n deps.runtimeConfig = refreshed?.runtime ?? deps.runtimeConfig;\n\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n description: \"No bos.config.json found\",\n processes: [],\n };\n }\n\n if (appConfig.proxy && !resolveProxyUrl(deps.bosConfig)) {\n return {\n status: \"error\" as const,\n description: \"No valid proxy URL configured in bos.config.json\",\n processes: [],\n };\n }\n\n const refreshedLocalPackages = detectLocalPackages(\n deps.bosConfig ?? undefined,\n deps.runtimeConfig ?? undefined,\n );\n const processes = determineProcesses(appConfig, refreshedLocalPackages, deps.runtimeConfig);\n const env = await buildEnvVars(appConfig, deps.bosConfig);\n const hostPort = input.port ?? getHostDevelopmentPort(deps.bosConfig.app.host.development);\n const developmentRuntime = buildRuntimeConfig(deps.bosConfig, {\n uiSource: appConfig.ui,\n apiSource: appConfig.api,\n hostUrl: `http://localhost:${hostPort}`,\n proxy: env.API_PROXY,\n env: \"development\",\n plugins: deps.runtimeConfig?.plugins,\n });\n const runtimeConfig = await prepareDevelopmentRuntimeConfig(developmentRuntime, {\n hostPort,\n ssr: appConfig.ssr,\n });\n\n await syncApiContractBridge({\n configDir: deps.configDir,\n runtimeConfig: runtimeConfig,\n apiBaseUrl: runtimeConfig.api.url,\n });\n\n const orchestrator: AppOrchestrator = {\n packages: processes,\n env,\n description: buildDescription(appConfig),\n appConfig,\n bosConfig: deps.bosConfig,\n runtimeConfig,\n port: parsePort(runtimeConfig.hostUrl),\n interactive: input.interactive,\n };\n\n startApp(orchestrator);\n\n return {\n status: \"started\" as const,\n description: orchestrator.description,\n processes,\n };\n }),\n\n start: builder.start.handler(async ({ input }: { input: StartOptions }) => {\n let remoteConfig: BosConfig | null = null;\n\n if (input.account && input.domain) {\n remoteConfig = await fetchPublishedConfig(input.account, input.domain);\n if (!remoteConfig) {\n return {\n status: \"error\" as const,\n url: \"\",\n };\n }\n }\n\n const config = remoteConfig || deps.bosConfig;\n if (!config) {\n return {\n status: \"error\" as const,\n url: \"\",\n };\n }\n\n const port = input.port ?? getHostDevelopmentPort(config.app.host.development);\n const appConfig: AppConfig = { host: \"remote\", ui: \"remote\", api: \"remote\" };\n const env = await buildEnvVars(appConfig, config);\n const isStaging = input.env === \"staging\";\n const runtimePlugins = remoteConfig\n ? await buildRuntimePluginsForConfig(config, deps.configDir, \"production\")\n : deps.runtimeConfig?.plugins;\n const runtimeConfig = buildRuntimeConfig(config, {\n uiSource: \"remote\",\n apiSource: \"remote\",\n hostUrl: `http://localhost:${port}`,\n env: \"production\",\n plugins: runtimePlugins,\n });\n\n await syncApiContractBridge({\n configDir: deps.configDir,\n runtimeConfig: runtimeConfig,\n apiBaseUrl: runtimeConfig.api.url,\n });\n\n const stagingEnvVars: Record<string, string> = isStaging\n ? { GATEWAY_DOMAIN: config.staging?.domain ?? config.domain ?? \"\" }\n : {};\n\n const orchestrator: AppOrchestrator = {\n packages: [\"host\"],\n env: {\n NODE_ENV: \"production\",\n ...env,\n ...stagingEnvVars,\n },\n description: `${isStaging ? \"Staging\" : \"Production\"} Mode (${config.account})`,\n appConfig,\n bosConfig: config,\n runtimeConfig,\n port,\n interactive: input.interactive,\n noLogs: true,\n };\n\n startApp(orchestrator);\n return {\n status: \"running\" as const,\n url: `http://localhost:${port}`,\n };\n }),\n\n build: builder.build.handler(async ({ input }: { input: BuildOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n built: [],\n skipped: [],\n };\n }\n\n const targets = selectWorkspaceTargets(input.packages, deps.bosConfig);\n if (targets.length === 0) {\n return {\n status: \"error\" as const,\n built: [],\n skipped: [],\n };\n }\n\n const runtimeConfig = buildRuntimeConfig(deps.bosConfig, {\n uiSource: deps.bosConfig.app.ui?.development ? \"local\" : \"remote\",\n apiSource: deps.bosConfig.app.api?.development ? \"local\" : \"remote\",\n hostUrl: resolveDevelopmentHostUrl(deps.bosConfig.app.host.development),\n env: \"development\",\n plugins: deps.runtimeConfig?.plugins,\n });\n\n await syncApiContractBridge({\n configDir: deps.configDir,\n runtimeConfig,\n apiBaseUrl: runtimeConfig.api.url,\n });\n\n const { built, skipped } = await buildWorkspaceTargets({\n configDir: deps.configDir,\n bosConfig: deps.bosConfig,\n runtimeConfig: runtimeConfig,\n targets,\n deploy: input.deploy,\n });\n\n if (built.length === 0) {\n return {\n status: \"error\" as const,\n built: [],\n skipped,\n };\n }\n\n return {\n status: \"success\" as const,\n built,\n skipped,\n deployed: input.deploy,\n };\n }),\n\n publish: builder.publish.handler(async ({ input }: { input: PublishOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n registryUrl: \"\",\n error: \"No bos.config.json found\",\n };\n }\n\n const account = deps.bosConfig.account;\n const gateway = deps.bosConfig.domain;\n if (!gateway) {\n return {\n status: \"error\" as const,\n registryUrl: \"\",\n error: \"bos.config.json must define domain to publish\",\n };\n }\n\n const network = input.network ?? getNetworkIdForAccount(account);\n const bosUrl = `bos://${account}/${gateway}`;\n const registryUrl = buildRegistryConfigUrlForNetwork(network, account, gateway);\n const targets = selectWorkspaceTargets(input.packages, deps.bosConfig);\n\n let publishConfig = deps.bosConfig;\n let built: string[] | undefined;\n let skipped: string[] | undefined;\n\n if (input.dryRun) {\n return {\n status: \"dry-run\" as const,\n registryUrl,\n built,\n skipped,\n };\n }\n\n if (input.deploy) {\n const result = await buildWorkspaceTargets({\n configDir: deps.configDir,\n bosConfig: deps.bosConfig,\n runtimeConfig: deps.runtimeConfig,\n targets,\n deploy: true,\n });\n built = result.built;\n skipped = result.skipped;\n\n const refreshed = await loadConfig({ cwd: deps.configDir });\n if (refreshed?.config) {\n deps.bosConfig = refreshed.config;\n deps.runtimeConfig = refreshed.runtime;\n publishConfig = refreshed.config;\n }\n }\n\n const payload = JSON.stringify({\n [`apps/${account}/${gateway}/bos.config.json`]: JSON.stringify(publishConfig),\n });\n const argsBase64 = Buffer.from(payload).toString(\"base64\");\n const privateKey =\n input.privateKey || process.env.NEAR_PRIVATE_KEY || process.env.BOS_NEAR_PRIVATE_KEY;\n\n try {\n await Effect.runPromise(ensureNearCli);\n let txHash: string | undefined;\n\n try {\n const tx = await Effect.runPromise(\n executeTransaction({\n account,\n contract: getRegistryNamespaceForNetwork(network),\n method: \"__fastdata_kv\",\n argsBase64,\n network,\n privateKey,\n gas: \"300Tgas\",\n deposit: \"0NEAR\",\n }),\n );\n txHash = tx.txHash;\n } catch (error) {\n txHash = extractTransactionHash(error);\n\n if (!txHash) {\n throw error;\n }\n\n const verifiedConfig = await fetchBosConfigFromFastKv<BosConfig>(bosUrl);\n if (JSON.stringify(verifiedConfig) !== JSON.stringify(publishConfig)) {\n throw error;\n }\n }\n\n return {\n status: \"published\" as const,\n registryUrl,\n txHash,\n built,\n skipped,\n };\n } catch (error) {\n return {\n status: \"error\" as const,\n registryUrl,\n error: error instanceof Error ? error.message : \"Unknown error\",\n built,\n skipped,\n };\n }\n }),\n\n keyPublish: builder.keyPublish.handler(async ({ input }: { input: KeyPublishOptions }) => {\n if (!deps.bosConfig) {\n return {\n status: \"error\" as const,\n account: \"\",\n network: \"mainnet\" as const,\n contract: \"\",\n allowance: input.allowance,\n functionNames: PUBLISH_FUNCTION_NAMES,\n error: \"No bos.config.json found\",\n };\n }\n\n const account = deps.bosConfig.account;\n const network = getNetworkIdForAccount(account);\n const contract = getRegistryNamespaceForAccount(account);\n try {\n await Effect.runPromise(ensureNearCli);\n const keyPair = await addFunctionCallAccessKey({\n account,\n contract,\n allowance: input.allowance,\n functionNames: PUBLISH_FUNCTION_NAMES,\n network,\n });\n\n return {\n status: \"published\" as const,\n account,\n network,\n contract,\n allowance: input.allowance,\n functionNames: PUBLISH_FUNCTION_NAMES,\n publicKey: keyPair.publicKey,\n privateKey: keyPair.privateKey,\n };\n } catch (error) {\n return {\n status: \"error\" as const,\n account,\n network,\n contract,\n allowance: input.allowance,\n functionNames: PUBLISH_FUNCTION_NAMES,\n error: error instanceof Error ? error.message : \"Unknown error\",\n };\n }\n }),\n\n init: builder.init.handler(async ({ input }: { input: InitOptions }) => {\n try {\n let account = input.account;\n let gateway = input.gateway;\n let destination = input.destination;\n let name = input.name;\n let domain = input.domain;\n let withHost = input.withHost;\n\n if (!account || !gateway) {\n if (input.noInteractive) {\n return {\n status: \"error\" as const,\n destination: \"\",\n parentAccount: account ?? \"\",\n parentGateway: gateway ?? \"\",\n name: input.name,\n domain: input.domain,\n extends: account && gateway ? `bos://${account}/${gateway}` : \"\",\n filesCopied: 0,\n error:\n \"account and gateway are required (use --no-interactive to skip prompts and provide them as positional args)\",\n };\n }\n\n const prompted = await promptInitOptions({\n account,\n gateway,\n destination,\n name,\n domain,\n withHost,\n });\n account = prompted.account;\n gateway = prompted.gateway;\n destination = prompted.destination;\n name = prompted.name;\n domain = prompted.domain;\n withHost = prompted.withHost;\n }\n\n destination = destination || gateway;\n\n const { sourceDir, cleanup } = await resolveSourceDir({\n account,\n gateway,\n source: input.source,\n });\n\n try {\n const patterns = await readTemplatekeep(sourceDir);\n if (patterns.length === 0) {\n return {\n status: \"error\" as const,\n destination,\n parentAccount: account,\n parentGateway: gateway,\n name,\n domain,\n extends: `bos://${account}/${gateway}`,\n filesCopied: 0,\n error: \"No .templatekeep found in template source\",\n };\n }\n\n const filesCopied = await copyFilteredFiles(sourceDir, destination, patterns, {\n withHost,\n });\n\n await personalizeConfig(destination, {\n parentAccount: account,\n parentGateway: gateway,\n name: name || account,\n domain: domain || gateway,\n workspaceOpts: { sourceDir },\n });\n\n if (!input.noInstall) {\n await runBunInstall(destination);\n }\n\n return {\n status: \"initialized\" as const,\n destination: resolve(destination),\n parentAccount: account,\n parentGateway: gateway,\n name,\n domain,\n extends: `bos://${account}/${gateway}`,\n filesCopied,\n };\n } finally {\n await cleanup();\n }\n } catch (error) {\n return {\n status: \"error\" as const,\n destination: input.destination ?? input.gateway ?? \"\",\n parentAccount: input.account ?? \"\",\n parentGateway: input.gateway ?? \"\",\n name: input.name,\n domain: input.domain,\n extends: input.account && input.gateway ? `bos://${input.account}/${input.gateway}` : \"\",\n filesCopied: 0,\n error: error instanceof Error ? error.message : \"Unknown error\",\n };\n }\n }),\n }),\n});\n\nfunction extractTransactionHash(error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n const match =\n message.match(/Transaction ID:\\s*([A-Za-z0-9]+)/i) ||\n message.match(/([A-HJ-NP-Za-km-z1-9]{43,44})/);\n\n return match?.[1];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkDA,MAAM,qBAAgC;CACpC,MAAM;CACN,IAAI;CACJ,KAAK;CACL,KAAK;CACN;AAED,MAAM,gBAAiE;CACrE,MAAM;EAAE,KAAK;EAAO,MAAM,CAAC,OAAO,QAAQ;EAAE;CAC5C,IAAI;EAAE,KAAK;EAAO,MAAM,CAAC,OAAO,QAAQ;EAAE;CAC1C,KAAK;EAAE,KAAK;EAAO,MAAM,CAAC,OAAO,QAAQ;EAAE;CAC5C;AAED,MAAM,yBAAyB,CAAC,gBAAgB;AAUhD,SAAS,gBAAgB,OAA2B,cAAsC;AACxF,KAAI,UAAU,WAAW,UAAU,SAAU,QAAO;AACpD,QAAO;;AAGT,SAAS,eAAe,SAMV;AACZ,QAAO;EACL,MAAM,gBAAgB,QAAQ,MAAM,mBAAmB,KAAK;EAC5D,IAAI,gBAAgB,QAAQ,IAAI,mBAAmB,GAAG;EACtD,KAA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S,QAAQ,GAAG;MAC7B,aAAa;MACb,OAAO;MACR;KAGH,MAAM,cAAc,MAAM,kBAAkB,WAAW,aAAa,UAAU,EAC5E,UACD,CAAC;AAEF,WAAM,kBAAkB,aAAa;MACnC,eAAe;MACf,eAAe;MACf,MAAM,QAAQ;MACd,QAAQ,UAAU;MAClB,eAAe,EAAE,WAAW;MAC7B,CAAC;AAEF,SAAI,CAAC,MAAM,UACT,OAAM,cAAc,YAAY;AAGlC,YAAO;MACL,QAAQ;MACR,aAAa,QAAQ,YAAY;MACjC,eAAe;MACf,eAAe;MACf;MACA;MACA,SAAS,SAAS,QAAQ,GAAG;MAC7B;MACD;cACO;AACR,WAAM,SAAS;;YAEV,OAAO;AACd,WAAO;KACL,QAAQ;KACR,aAAa,MAAM,eAAe,MAAM,WAAW;KACnD,eAAe,MAAM,WAAW;KAChC,eAAe,MAAM,WAAW;KAChC,MAAM,MAAM;KACZ,QAAQ,MAAM;KACd,SAAS,MAAM,WAAW,MAAM,UAAU,SAAS,MAAM,QAAQ,GAAG,MAAM,YAAY;KACtF,aAAa;KACb,OAAO,iBAAiB,QAAQ,MAAM,UAAU;KACjD;;IAEH;EACH;CACF,CAAC;AAEF,SAAS,uBAAuB,OAAgB;CAC9C,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AAKtE,SAHE,QAAQ,MAAM,oCAAoC,IAClD,QAAQ,MAAM,gCAAgC,IAEjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "everything-dev",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -222,16 +222,16 @@
222
222
  },
223
223
  "dependencies": {
224
224
  "@hono/node-server": "^1.14.4",
225
- "@module-federation/enhanced": "catalog:",
226
- "@module-federation/node": "catalog:",
227
- "@module-federation/runtime-core": "catalog:",
225
+ "@module-federation/enhanced": "^2.3.2",
226
+ "@module-federation/node": "^2.7.40",
227
+ "@module-federation/runtime-core": "^2.3.2",
228
228
  "@orpc/contract": "^1.13.4",
229
229
  "@orpc/server": "^1.13.4",
230
230
  "@orpc/openapi": "^1.13.4",
231
231
  "@orpc/zod": "^1.13.4",
232
232
  "chalk": "^5.6.2",
233
233
  "effect": "^3.21.0",
234
- "every-plugin": "workspace:*",
234
+ "every-plugin": "^2.2.4",
235
235
  "glob": "^11.0.0",
236
236
  "gradient-string": "^3.0.0",
237
237
  "hono": "^4.7.11",
@@ -256,12 +256,12 @@
256
256
  }
257
257
  },
258
258
  "devDependencies": {
259
- "@tanstack/react-query": "catalog:",
260
- "@tanstack/react-router": "catalog:",
259
+ "@tanstack/react-query": "5.90.20",
260
+ "@tanstack/react-router": "1.157.16",
261
261
  "@types/gradient-string": "^1.1.6",
262
262
  "@types/node": "^22.10.2",
263
- "@types/react": "catalog:",
264
- "@types/react-dom": "catalog:",
263
+ "@types/react": "^19.2.7",
264
+ "@types/react-dom": "^19.2.3",
265
265
  "@types/tar": "^7.0.0",
266
266
  "tsdown": "^0.21.7",
267
267
  "typescript": "^5.7.2",
package/src/cli/init.ts CHANGED
@@ -14,6 +14,10 @@ import { dirname, join, resolve } from "node:path";
14
14
  import { pipeline } from "node:stream/promises";
15
15
  import { glob } from "glob";
16
16
  import { fetchBosConfigFromFastKv } from "../fastkv";
17
+ import {
18
+ loadManifestNormalizationSpec,
19
+ normalizePackageManifestsInTree,
20
+ } from "../internal/manifest-normalizer";
17
21
  import type { BosConfig } from "../types";
18
22
 
19
23
  const require = createRequire(import.meta.url);
@@ -278,8 +282,12 @@ export async function personalizeConfig(
278
282
 
279
283
  if (!pkg.dependencies) pkg.dependencies = {};
280
284
  const deps = pkg.dependencies as Record<string, string>;
281
- if (!deps["everything-dev"]) deps["everything-dev"] = "^1.1.0";
282
- if (!deps["every-plugin"]) deps["every-plugin"] = "^2.0.0";
285
+ const spec = opts.workspaceOpts?.sourceDir
286
+ ? loadManifestNormalizationSpec(opts.workspaceOpts.sourceDir)
287
+ : null;
288
+ if (!deps["everything-dev"] && spec)
289
+ deps["everything-dev"] = spec.rootCatalog["everything-dev"];
290
+ if (!deps["every-plugin"] && spec) deps["every-plugin"] = spec.rootCatalog["every-plugin"];
283
291
 
284
292
  writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
285
293
  }
@@ -291,11 +299,6 @@ export async function runBunInstall(destination: string): Promise<void> {
291
299
  await execCommand("bun", ["install"], destination);
292
300
  }
293
301
 
294
- const WORKSPACE_VERSION_MAP: Record<string, string> = {
295
- "everything-dev": "^1.1.0",
296
- "every-plugin": "^2.0.0",
297
- };
298
-
299
302
  const WORKSPACE_LOCAL_PATHS: Record<string, string> = {
300
303
  "everything-dev": "packages/everything-dev",
301
304
  "every-plugin": "packages/every-plugin",
@@ -305,45 +308,13 @@ async function resolveWorkspaceRefs(
305
308
  destination: string,
306
309
  options?: { localOverrides?: boolean; sourceDir?: string },
307
310
  ): Promise<void> {
308
- const files = await glob("**/package.json", {
309
- cwd: destination,
310
- nodir: true,
311
- dot: false,
312
- absolute: false,
313
- ignore: ["**/node_modules/**"],
311
+ await normalizePackageManifestsInTree({
312
+ sourceRootDir: options?.sourceDir ?? destination,
313
+ targetDir: destination,
314
+ resolveCatalogRefs: false,
315
+ removeWorkspaceDeps: ["host"],
314
316
  });
315
317
 
316
- for (const file of files) {
317
- const filePath = join(destination, file);
318
- const content = readFileSync(filePath, "utf-8");
319
- if (!content.includes("workspace:")) continue;
320
-
321
- const pkg = JSON.parse(content) as Record<string, unknown>;
322
- let modified = false;
323
-
324
- for (const depField of ["dependencies", "devDependencies", "peerDependencies"]) {
325
- const deps = pkg[depField];
326
- if (!deps || typeof deps !== "object") continue;
327
- const map = deps as Record<string, string>;
328
- for (const [name, version] of Object.entries(map)) {
329
- if (version === "workspace:*") {
330
- const resolved = WORKSPACE_VERSION_MAP[name];
331
- if (resolved) {
332
- map[name] = resolved;
333
- modified = true;
334
- } else if (name === "host") {
335
- delete map[name];
336
- modified = true;
337
- }
338
- }
339
- }
340
- }
341
-
342
- if (modified) {
343
- writeFileSync(filePath, `${JSON.stringify(pkg, null, 2)}\n`);
344
- }
345
- }
346
-
347
318
  if (options?.localOverrides && options.sourceDir) {
348
319
  const rootPkgPath = join(destination, "package.json");
349
320
  if (existsSync(rootPkgPath)) {
@@ -0,0 +1,251 @@
1
+ import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { dirname, join, relative, sep } from "node:path";
3
+ import { glob } from "glob";
4
+
5
+ const FRAMEWORK_PACKAGES = ["every-plugin", "everything-dev"] as const;
6
+
7
+ type PackageJson = Record<string, unknown>;
8
+
9
+ type NormalizationSpec = {
10
+ rootCatalog: Record<string, string>;
11
+ frameworkVersions: Record<string, string>;
12
+ };
13
+
14
+ type NormalizeManifestOptions = {
15
+ resolveCatalogRefs: boolean;
16
+ excludeFrameworkWorkspaces?: boolean;
17
+ removeWorkspaceDeps?: string[];
18
+ removeWorkspaces?: boolean;
19
+ removePublishScripts?: boolean;
20
+ };
21
+
22
+ export type NormalizeTreeOptions = NormalizeManifestOptions & {
23
+ sourceRootDir: string;
24
+ targetDir: string;
25
+ };
26
+
27
+ function readJson<T>(filePath: string): T {
28
+ return JSON.parse(readFileSync(filePath, "utf-8")) as T;
29
+ }
30
+
31
+ function extractExactVersion(input: string | undefined): string | null {
32
+ if (!input) return null;
33
+ const match = input.match(/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?/);
34
+ return match ? match[0] : null;
35
+ }
36
+
37
+ function writeJson(filePath: string, value: PackageJson) {
38
+ writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
39
+ }
40
+
41
+ export function loadManifestNormalizationSpec(sourceRootDir: string): NormalizationSpec {
42
+ const rootPackage = readJson<PackageJson>(join(sourceRootDir, "package.json"));
43
+ const rootCatalog = {
44
+ ...(((rootPackage.workspaces as { catalog?: Record<string, string> } | undefined)?.catalog ??
45
+ {}) as Record<string, string>),
46
+ };
47
+ const frameworkVersions: Record<string, string> = {};
48
+
49
+ for (const packageName of FRAMEWORK_PACKAGES) {
50
+ const sourcePackagePath = join(sourceRootDir, "packages", packageName, "package.json");
51
+ const localPackagePath = join(import.meta.dirname, "..", "..", packageName, "package.json");
52
+ const packageVersion = existsSync(sourcePackagePath)
53
+ ? readJson<{ version: string }>(sourcePackagePath).version
54
+ : existsSync(localPackagePath)
55
+ ? readJson<{ version: string }>(localPackagePath).version
56
+ : extractExactVersion(rootCatalog[packageName]);
57
+
58
+ if (!packageVersion) {
59
+ throw new Error(`Could not resolve version for ${packageName}`);
60
+ }
61
+
62
+ frameworkVersions[packageName] = packageVersion;
63
+ rootCatalog[packageName] = `^${packageVersion}`;
64
+ }
65
+
66
+ return { rootCatalog, frameworkVersions };
67
+ }
68
+
69
+ function normalizeDependencyMap(
70
+ map: Record<string, string>,
71
+ spec: NormalizationSpec,
72
+ options: NormalizeManifestOptions,
73
+ ) {
74
+ let modified = false;
75
+
76
+ for (const [name, version] of Object.entries(map)) {
77
+ if (version === "workspace:*") {
78
+ const frameworkVersion = spec.frameworkVersions[name];
79
+ if (frameworkVersion) {
80
+ map[name] = `^${frameworkVersion}`;
81
+ modified = true;
82
+ continue;
83
+ }
84
+
85
+ if (options.removeWorkspaceDeps?.includes(name)) {
86
+ delete map[name];
87
+ modified = true;
88
+ }
89
+ continue;
90
+ }
91
+
92
+ if (options.resolveCatalogRefs && version.startsWith("catalog:")) {
93
+ const resolved = spec.rootCatalog[name];
94
+ if (resolved) {
95
+ map[name] = resolved;
96
+ modified = true;
97
+ }
98
+ }
99
+ }
100
+
101
+ return modified;
102
+ }
103
+
104
+ export function normalizePackageManifest(
105
+ pkg: PackageJson,
106
+ spec: NormalizationSpec,
107
+ options: NormalizeManifestOptions,
108
+ ) {
109
+ let modified = false;
110
+
111
+ for (const depField of ["dependencies", "devDependencies", "peerDependencies"]) {
112
+ const deps = pkg[depField];
113
+ if (!deps || typeof deps !== "object") continue;
114
+ if (normalizeDependencyMap(deps as Record<string, string>, spec, options)) {
115
+ modified = true;
116
+ }
117
+ }
118
+
119
+ if (pkg.workspaces && typeof pkg.workspaces === "object") {
120
+ const workspaces = pkg.workspaces as {
121
+ packages?: string[];
122
+ catalog?: Record<string, string>;
123
+ };
124
+
125
+ if (options.excludeFrameworkWorkspaces && Array.isArray(workspaces.packages)) {
126
+ const nextPackages = workspaces.packages.filter(
127
+ (entry) => !FRAMEWORK_PACKAGES.some((name) => entry === `packages/${name}`),
128
+ );
129
+ if (nextPackages.length !== workspaces.packages.length) {
130
+ workspaces.packages = nextPackages;
131
+ modified = true;
132
+ }
133
+ }
134
+
135
+ if (workspaces.catalog && typeof workspaces.catalog === "object") {
136
+ for (const [name, version] of Object.entries(workspaces.catalog)) {
137
+ const resolved = spec.rootCatalog[name];
138
+ if (resolved && resolved !== version) {
139
+ workspaces.catalog[name] = resolved;
140
+ modified = true;
141
+ continue;
142
+ }
143
+
144
+ if (version === "workspace:*" && spec.frameworkVersions[name]) {
145
+ workspaces.catalog[name] = `^${spec.frameworkVersions[name]}`;
146
+ modified = true;
147
+ }
148
+ }
149
+ }
150
+ }
151
+
152
+ if (options.removeWorkspaces && "workspaces" in pkg) {
153
+ delete pkg.workspaces;
154
+ modified = true;
155
+ }
156
+
157
+ if (options.removePublishScripts && pkg.scripts && typeof pkg.scripts === "object") {
158
+ const scripts = pkg.scripts as Record<string, string>;
159
+ let scriptsModified = false;
160
+ for (const key of ["prepublishOnly", "prepack", "prepare", "postpack"]) {
161
+ if (key in scripts) {
162
+ delete scripts[key];
163
+ scriptsModified = true;
164
+ }
165
+ }
166
+ if (scriptsModified) {
167
+ modified = true;
168
+ if (Object.keys(scripts).length === 0) {
169
+ delete pkg.scripts;
170
+ }
171
+ }
172
+ }
173
+
174
+ return modified;
175
+ }
176
+
177
+ export async function normalizePackageManifestsInTree(opts: NormalizeTreeOptions) {
178
+ const spec = loadManifestNormalizationSpec(opts.sourceRootDir);
179
+ const files = await glob("**/package.json", {
180
+ cwd: opts.targetDir,
181
+ nodir: true,
182
+ dot: false,
183
+ absolute: true,
184
+ ignore: ["**/node_modules/**"],
185
+ });
186
+
187
+ const updatedFiles: string[] = [];
188
+
189
+ for (const filePath of files) {
190
+ const pkg = readJson<PackageJson>(filePath);
191
+ if (normalizePackageManifest(pkg, spec, opts)) {
192
+ writeJson(filePath, pkg);
193
+ updatedFiles.push(filePath);
194
+ }
195
+ }
196
+
197
+ return updatedFiles;
198
+ }
199
+
200
+ function shouldCopyPackageFile(sourceDir: string, filePath: string) {
201
+ const relPath = relative(sourceDir, filePath);
202
+ if (!relPath) return true;
203
+ const segments = relPath.split(sep);
204
+ return !segments.includes("node_modules") && !segments.includes("tests");
205
+ }
206
+
207
+ export function stageReleasePackage(opts: {
208
+ repoRoot: string;
209
+ packageName: string;
210
+ outDir: string;
211
+ }) {
212
+ const sourceDir = join(opts.repoRoot, "packages", opts.packageName);
213
+
214
+ rmSync(opts.outDir, { recursive: true, force: true });
215
+ mkdirSync(dirname(opts.outDir), { recursive: true });
216
+ cpSync(sourceDir, opts.outDir, {
217
+ recursive: true,
218
+ filter: (filePath) => shouldCopyPackageFile(sourceDir, filePath),
219
+ });
220
+ rmSync(join(opts.outDir, "tests"), { recursive: true, force: true });
221
+
222
+ const packageJsonPath = join(opts.outDir, "package.json");
223
+ const spec = loadManifestNormalizationSpec(opts.repoRoot);
224
+ const pkg = readJson<PackageJson>(packageJsonPath);
225
+
226
+ normalizePackageManifest(pkg, spec, {
227
+ resolveCatalogRefs: true,
228
+ removeWorkspaces: true,
229
+ removePublishScripts: true,
230
+ });
231
+
232
+ writeJson(packageJsonPath, pkg);
233
+ }
234
+
235
+ export function stageReleasePackages(opts: {
236
+ repoRoot: string;
237
+ outDir: string;
238
+ packageNames?: string[];
239
+ }) {
240
+ const packageNames = opts.packageNames ?? [...FRAMEWORK_PACKAGES];
241
+ rmSync(opts.outDir, { recursive: true, force: true });
242
+ mkdirSync(opts.outDir, { recursive: true });
243
+
244
+ for (const packageName of packageNames) {
245
+ stageReleasePackage({
246
+ repoRoot: opts.repoRoot,
247
+ packageName,
248
+ outDir: join(opts.outDir, packageName),
249
+ });
250
+ }
251
+ }