UNPKG

everything-dev

Version:

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

446 lines (444 loc) • 15.8 kB
const require_runtime = require("../_virtual/_rolldown/runtime.cjs"); const require_load = require("../services/resolution/load.cjs"); const require_theme = require("../utils/theme.cjs"); const require_catalog = require("../services/workspace/catalog.cjs"); const require_manifest = require("../services/platform/manifest.cjs"); const require_services_resolution_session = require("../services/resolution/session.cjs"); const require_services_federation_service = require("../services/federation/service.cjs"); const require_artifacts = require("../services/codegen/artifacts.cjs"); const require_workspace = require("../services/workspace/workspace.cjs"); const require_framework_version = require("../services/framework-version.cjs"); const require_build_train = require("../services/workspace/build-train.cjs"); const require_published = require("../services/registry/published.cjs"); const require_upgrade = require("../services/scaffold/upgrade.cjs"); const require_upgrade_plan = require("../cli/upgrade-plan.cjs"); const require_domain = require("../services/scaffold/upgrade-audit/domain.cjs"); const require_index = require("../services/scaffold/upgrade-audit/index.cjs"); let node_fs = require("node:fs"); let node_path = require("node:path"); let effect = require("effect"); let node_process = require("node:process"); node_process = require_runtime.__toESM(node_process, 1); let node_child_process = require("node:child_process"); let every_plugin_ui_manifest_generator = require("every-plugin/ui/manifest-generator"); //#region src/handlers/upgrade.ts const nodeEnvProduction = () => node_process.default.env.NODE_ENV === "production"; const envOf = (name) => node_process.default.env[name]; const stageLog = (message) => { console.log(message); }; function registerUpgrade(builder) { return { upgrade: builder.upgrade.effect(function* (_opts, input) { return yield* effect.Effect.tryPromise({ try: async () => { const configPath = require_load.findConfigPath(); if (!configPath) return { status: "error", packages: [], error: `${require_load.MISSING_CONFIG_MESSAGE} in current directory` }; const projectDir = (0, node_path.resolve)((0, node_path.dirname)(configPath)); if (input.from === "v1") { if (input.maintain && input.maintain.length > 0) { const migrated = []; const notes = []; for (const step of input.maintain) try { const result = await require_index.maintainV1Tree(projectDir, step, input.dryRun); for (const path of result.writes) migrated.push(`${step}: wrote ${path}`); for (const path of result.deletes) migrated.push(`${step}: deleted ${path}`); for (const note of result.notes) notes.push(`${step}: ${note}`); } catch (error) { if (!(error instanceof require_domain.GateBlocked)) throw error; return { status: "gate-blocked", packages: [], blockers: error.findings.map(require_index.toPlainFinding) }; } return { status: input.dryRun ? "dry-run" : "upgraded", packages: [], migrated, notes }; } if (require_index.isV2Tree(projectDir)) return { status: "already-upgraded", packages: [], notes: ["bos.app.ts present — this tree is already on the v2 train; nothing to audit or apply"] }; if (input.audit) { const outcome = await require_index.auditV1Tree(projectDir); const auditResult = { tier: outcome.tier, findings: outcome.findings, manifest: outcome.manifest }; return outcome.gateBlocked ? { status: "gate-blocked", packages: [], audit: auditResult, blockers: outcome.findings.filter((f) => f.severity === "blocker") } : { status: "audit", packages: [], audit: auditResult }; } const outcome = await require_index.applyV1Tree(projectDir, input.dryRun); if (!outcome.ok) return { status: "gate-blocked", packages: [], blockers: outcome.blockers }; return { status: input.dryRun ? "dry-run" : "upgraded", packages: [], migrated: outcome.outcome.migrated, notes: outcome.outcome.notes }; } const decision = await require_upgrade_plan.planUpgradeInteraction(projectDir, input); if (decision === null) return { status: "cancelled", packages: [] }; return await require_upgrade.upgradeTemplate(projectDir, { ...input, ...decision }); }, catch: (error) => ({ status: "error", packages: [], error: error instanceof Error ? error.message : "Unknown error" }) }); }), typecheck: builder.typecheck.effect(function* (_opts, input) { return yield* effect.Effect.tryPromise({ try: async () => { const configPath = require_load.findConfigPath(); if (!configPath) return { status: "error", checked: [], skipped: [], results: [], error: `${require_load.MISSING_CONFIG_MESSAGE} in current directory` }; const projectDir = (0, node_path.resolve)((0, node_path.dirname)(configPath)); const refreshed = await require_services_resolution_session.openResolution({ cwd: projectDir }); if (!refreshed?.config || !refreshed.runtime) return { status: "error", checked: [], skipped: [], results: [], error: "Failed to load the authored config" }; const runtime = refreshed.runtime; const resolvedConfig = refreshed.config; await require_artifacts.generateCodeArtifacts(projectDir, resolvedConfig, { env: nodeEnvProduction() ? "production" : "development", extendsChain: [...refreshed.chain], runtimeConfig: runtime }); const workspaceEntries = []; const skipped = []; const appTargets = [ { key: "host", label: "host", target: runtime.host }, { key: "ui", label: "ui", target: runtime.ui }, { key: "api", label: "api", target: runtime.api } ]; if (runtime.auth) appTargets.push({ key: "auth", label: "auth", target: runtime.auth }); for (const entry of appTargets) if (entry.target?.source === "local" && entry.target.localPath && (0, node_fs.existsSync)((0, node_path.join)(entry.target.localPath, "tsconfig.json"))) workspaceEntries.push({ key: entry.key, label: entry.label, dir: entry.target.localPath }); else skipped.push({ key: entry.key, label: entry.label }); for (const [key, plugin] of Object.entries(runtime.plugins ?? {})) { const label = `plugins/${key}`; const localPath = plugin.source === "local" ? plugin.localPath : void 0; if (localPath && (0, node_fs.existsSync)((0, node_path.join)(localPath, "tsconfig.json"))) workspaceEntries.push({ key, label, dir: localPath }); else skipped.push({ key, label }); if (localPath && (0, node_fs.existsSync)((0, node_path.join)(localPath, "ui", "tsconfig.json"))) workspaceEntries.push({ key, label: `${label}/ui`, dir: localPath, ui: true }); } const selected = require_build_train.selectWorkspaceTargets(input.packages, resolvedConfig); const targets = input.packages === "all" ? workspaceEntries : workspaceEntries.filter((entry) => selected.includes(entry.key)); const skippedEntries = input.packages === "all" ? skipped : skipped.filter((entry) => selected.includes(entry.key)); const checked = []; const results = []; for (const entry of targets) { if (entry.ui && !(0, node_fs.existsSync)((0, node_path.join)(entry.dir, "ui", "src", "routeTree.gen.ts"))) try { await (0, every_plugin_ui_manifest_generator.generateUiManifest)({ workspaceRoot: (0, node_path.join)(entry.dir, "ui"), pluginName: entry.key, emitRouteTree: true }); } catch (error) { checked.push(entry.label); results.push({ workspace: entry.label, passed: false, error: `routeTree materialization failed: ${error instanceof Error ? error.message : String(error)}` }); continue; } const packageJsonPath = (0, node_path.join)(entry.dir, "package.json"); let args = entry.ui ? [ "exec", "tsc", "--noEmit", "-p", "ui/tsconfig.json" ] : [ "exec", "tsc", "--noEmit" ]; if ((0, node_fs.existsSync)(packageJsonPath)) try { const pkg = JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf-8")); const scriptName = entry.ui ? "typecheck:ui" : "typecheck"; if (pkg.scripts?.[scriptName]) args = ["run", scriptName]; } catch {} stageLog(`\n ${require_theme.colors.dim("Checking")} ${require_theme.colors.cyan(entry.label)}`); const child = (0, node_child_process.spawnSync)("pnpm", args, { cwd: entry.dir, stdio: "inherit" }); const passed = child.status === 0; checked.push(entry.label); results.push({ workspace: entry.label, passed, error: passed ? void 0 : `typecheck failed (exit code ${child.status ?? "n/a"})` }); } return { status: "success", checked, skipped: skippedEntries.map((entry) => entry.label), results }; }, catch: (error) => ({ status: "error", checked: [], skipped: [], results: [], error: error instanceof Error ? error.message : "Unknown error" }) }); }), mfCheck: builder.mfCheck.effect(function* (_opts, input) { const manifestService = yield* require_manifest.ManifestService; return yield* effect.Effect.promise(async () => { let authored = null; try { authored = await require_load.readAuthoredConfigInput(); } catch (e) { return { status: "fail", hostVersion: null, hostReachable: false, hostReason: e instanceof Error ? e.message : String(e), remotes: [] }; } if (!authored) { const account = envOf("BOS_ACCOUNT"); const gateway = envOf("BOS_GATEWAY"); if (!account || !gateway) return { status: "fail", hostVersion: null, hostReachable: false, hostReason: require_load.MISSING_CONFIG_MESSAGE, remotes: [] }; try { authored = await require_published.resolvePublishedConfig(account, gateway); } catch (e) { return { status: "fail", hostVersion: null, hostReachable: false, hostReason: e instanceof Error ? e.message : String(e), remotes: [] }; } if (!authored) return { status: "fail", hostVersion: null, hostReachable: false, hostReason: `No config found at bos://${account}/${gateway} — verify BOS_ACCOUNT/BOS_GATEWAY and that the config has been published.`, remotes: [] }; } const report = await require_services_federation_service.checkFederationCompat(authored, { timeoutMs: input.timeoutMs }); const ui = await require_services_federation_service.checkUiCompositionCompat(authored, { timeoutMs: input.timeoutMs }); let manifest; try { const configPath = require_load.findConfigPath(); if (configPath) { const projectDir = (0, node_path.resolve)((0, node_path.dirname)(configPath)); const resolved = await manifestService.resolvePlatformManifest({ configDir: projectDir, localConfig: authored }); if (resolved) { const root = require_workspace.findWorkspaceRoot(projectDir)?.dir ?? projectDir; const violations = manifestService.checkPlatformCompat(resolved.manifest, { platformVersion: require_framework_version.readInstalledFrameworkVersion(projectDir, "everything-dev"), catalog: require_catalog.readWorkspaceCatalog(root) }); manifest = { ok: violations.length === 0, violations }; } } } catch (e) { manifest = { ok: false, violations: [{ kind: "minChild", message: `release manifest resolution failed: ${e instanceof Error ? e.message : String(e)}` }] }; } return { status: report.ok && (manifest?.ok ?? true) ? "ok" : "fail", hostVersion: report.hostVersion, hostReachable: report.hostReachable, hostReason: report.hostReason, remotes: report.remotes, ...ui.remotes.length > 0 ? { ui: { ok: ui.ok, remotes: ui.remotes } } : {}, ...manifest ? { manifest } : {} }; }); }), manifest: builder.manifest.effect(function* (_opts, input) { const manifestService = yield* require_manifest.ManifestService; return yield* effect.Effect.promise(async () => { const inImage = manifestService.readInImagePlatformManifest(); if (inImage) return { status: "ok", version: inImage.frameworkVersion, source: "in-image", ...input.check ? { compat: { ok: true, violations: [] } } : {} }; const configPath = require_load.findConfigPath(); if (!configPath) return { status: "absent", version: null, error: `${require_load.MISSING_CONFIG_MESSAGE} — and the in-image platform manifest is absent (non-framework image)` }; const projectDir = (0, node_path.resolve)((0, node_path.dirname)(configPath)); try { const authoredConfig = await require_load.readAuthoredConfigInput() ?? {}; let resolved; let drift; try { resolved = await manifestService.resolvePlatformManifest({ configDir: projectDir, localConfig: authoredConfig }); } catch (pinError) { const latest = await manifestService.resolvePlatformManifest({ configDir: projectDir, localConfig: { ...authoredConfig, release: void 0 } }); if (!latest) throw pinError; resolved = latest; const authored = typeof authoredConfig.release === "string" ? authoredConfig.release : void 0; drift = authored ? { pinned: authored, published: latest.manifest.frameworkVersion } : void 0; } if (!resolved) return { status: "absent", version: null }; if (drift) return { status: "fail", version: drift.published, source: `bos://${resolved.source.account}/${resolved.source.gateway}`, drift, error: `parent release is ${drift.published} (published at bos://${resolved.source.account}/${resolved.source.gateway}), you target ${drift.pinned} — run \`bos upgrade\` to realign` }; const base = { status: "ok", version: resolved.manifest.frameworkVersion, source: `bos://${resolved.source.account}/${resolved.source.gateway}`, fromCache: resolved.fromCache, provenance: resolved.provenance }; if (!input.check) return base; const root = require_workspace.findWorkspaceRoot(projectDir)?.dir ?? projectDir; const violations = manifestService.checkPlatformCompat(resolved.manifest, { platformVersion: require_framework_version.readInstalledFrameworkVersion(projectDir, "everything-dev"), catalog: require_catalog.readWorkspaceCatalog(root) }); return { ...base, compat: { ok: violations.length === 0, violations } }; } catch (e) { return { status: "fail", version: null, error: e instanceof Error ? e.message : String(e) }; } }); }) }; } //#endregion exports.registerUpgrade = registerUpgrade; //# sourceMappingURL=upgrade.cjs.map