UNPKG

everything-dev

Version:

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

1 lines • 13.1 kB
{"version":3,"file":"types-gen.mjs","names":[],"sources":["../../src/handlers/types-gen.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport process from \"node:process\";\nimport { Effect } from \"effect\";\nimport { generateUiManifest } from \"every-plugin/ui/manifest-generator\";\nimport { findConfigPath, MISSING_CONFIG_MESSAGE } from \"../config\";\nimport { generateCodeArtifacts } from \"../services/codegen/artifacts\";\nimport { checkFederationCompat, checkUiCompositionCompat } from \"../services/federation/service\";\nimport { readInstalledFrameworkVersion } from \"../services/framework-version\";\nimport {\n ManifestService,\n type PlatformCompatViolation,\n type ResolvedPlatformManifest,\n} from \"../services/platform/manifest\";\nimport { resolvePublishedConfig } from \"../services/registry/published\";\nimport { openResolution } from \"../services/resolution/session\";\nimport { selectWorkspaceTargets } from \"../services/workspace/build-train\";\nimport { readWorkspaceCatalog } from \"../services/workspace/catalog\";\nimport { findWorkspaceRoot } from \"../services/workspace/workspace\";\nimport type { BosConfig } from \"../types\";\nimport { colors } from \"../utils/theme\";\nimport type { BosBuilder } from \"./shared\";\n\nconst nodeEnvProduction = (): boolean => process.env.NODE_ENV === \"production\";\nconst envOf = (name: string): string | undefined => process.env[name];\n\nexport function registerTypesGen(builder: BosBuilder) {\n return {\n typesGen: builder.typesGen.effect(function* (_opts, input) {\n return yield* Effect.tryPromise({\n try: async () => {\n const configPath = findConfigPath();\n if (!configPath) {\n return {\n status: \"error\" as const,\n generated: [],\n fetched: [],\n skipped: [],\n failed: [],\n error: `${MISSING_CONFIG_MESSAGE} in current directory`,\n };\n }\n\n const projectDir = resolve(dirname(configPath));\n const env = input.env ?? (nodeEnvProduction() ? \"production\" : \"development\");\n\n const refreshed = await openResolution({\n cwd: projectDir,\n env,\n remotePlugins: input.remotePlugins,\n });\n if (!refreshed?.config || !refreshed.runtime) {\n return {\n status: \"error\" as const,\n generated: [],\n fetched: [],\n skipped: [],\n failed: [],\n error: \"Failed to load the authored config\",\n };\n }\n\n const runtime = refreshed.runtime;\n const resolvedConfig = refreshed.config;\n\n if (input.dryRun) {\n const pluginEntries = Object.entries(runtime.plugins ?? {});\n const fetched: string[] = [];\n const skipped: string[] = [];\n const hasLocalApiWorkspace = existsSync(join(projectDir, \"api\", \"src\"));\n\n if (runtime.api.source !== \"local\") {\n fetched.push(`api remote (${runtime.api.url})`);\n } else {\n const path = runtime.api.localPath\n ? ` (${relative(projectDir, runtime.api.localPath)})`\n : \"\";\n skipped.push(`api local${path}`);\n }\n\n if (runtime.auth) {\n if (runtime.auth.source !== \"local\") {\n fetched.push(`auth remote (${runtime.auth.url})`);\n } else {\n const path = runtime.auth.localPath\n ? ` (${relative(projectDir, runtime.auth.localPath)})`\n : \"\";\n skipped.push(`auth local${path}`);\n }\n }\n\n for (const [key, plugin] of pluginEntries) {\n if (plugin.url && plugin.source !== \"local\") {\n fetched.push(`${key} remote (${plugin.url})`);\n } else if (plugin.localPath) {\n skipped.push(`${key} local (${relative(projectDir, plugin.localPath)})`);\n } else {\n skipped.push(`${key} no URL resolved`);\n }\n }\n\n const generated = [\n \"ui/src/lib/api-types.gen.ts\",\n \"ui/src/lib/auth-types.gen.ts\",\n \".bos/bos.resolved-config.json\",\n ];\n if (hasLocalApiWorkspace) {\n generated.push(\"api/src/lib/plugins-types.gen.ts\", \"api/src/lib/auth-types.gen.ts\");\n }\n if (existsSync(join(projectDir, \"host\", \"src\"))) {\n generated.push(\"host/src/lib/auth-types.gen.ts\");\n }\n for (const [_key, plugin] of pluginEntries) {\n const localPath = plugin.localPath;\n if (!localPath) continue;\n const pluginSrc = join(localPath, \"src\", \"lib\", \"plugins-client.gen.ts\");\n if (existsSync(pluginSrc)) {\n generated.push(relative(projectDir, pluginSrc));\n }\n }\n if (runtime.auth?.localPath) {\n const authSrc = join(runtime.auth.localPath, \"src\", \"lib\", \"plugins-client.gen.ts\");\n if (existsSync(authSrc)) {\n generated.push(relative(projectDir, authSrc));\n }\n }\n\n return {\n status: \"success\" as const,\n generated,\n fetched,\n skipped,\n failed: [],\n };\n }\n\n const artifacts = await generateCodeArtifacts(projectDir, resolvedConfig, {\n env,\n extendsChain: [...refreshed.chain],\n runtimeConfig: runtime,\n forceRouteTree: true,\n // bos types gen is the strict runtime-map gate (#594): an\n // unresolvable remote manifest fails the run so typecheck\n // catches an upstream rename instead of shrinking the map\n runtimeMapStrict: true,\n });\n\n const hasLocalApiWorkspace = existsSync(join(projectDir, \"api\", \"src\"));\n const generated = [\"ui/src/lib/api-types.gen.ts\"];\n if (hasLocalApiWorkspace) {\n generated.push(\"api/src/lib/plugins-types.gen.ts\", \"api/src/lib/auth-types.gen.ts\");\n }\n if (runtime.auth && (runtime.auth.source !== \"local\" || runtime.auth.localPath)) {\n generated.push(\"ui/src/lib/auth-types.gen.ts\");\n }\n if (existsSync(join(projectDir, \"host\", \"src\"))) {\n generated.push(\"host/src/lib/auth-types.gen.ts\");\n }\n for (const [_key, plugin] of Object.entries(runtime.plugins ?? {})) {\n const localPath = plugin.localPath;\n if (!localPath) continue;\n const pluginSrc = join(localPath, \"src\", \"lib\", \"plugins-client.gen.ts\");\n if (existsSync(pluginSrc)) {\n generated.push(relative(projectDir, pluginSrc));\n }\n }\n if (runtime.auth?.localPath) {\n const authSrc = join(runtime.auth.localPath, \"src\", \"lib\", \"plugins-client.gen.ts\");\n if (existsSync(authSrc)) {\n generated.push(relative(projectDir, authSrc));\n }\n }\n\n const contractStatus = artifacts?.contractStatus ?? [];\n const fetched: string[] = [];\n const skipped: string[] = [];\n const failed: string[] = [];\n for (const entry of contractStatus) {\n if (entry.source === \"remote\") {\n fetched.push(entry.url ? `${entry.key} remote (${entry.url})` : entry.key);\n } else if (entry.source === \"local\") {\n const path = entry.localPath ? ` (${relative(projectDir, entry.localPath)})` : \"\";\n skipped.push(`${entry.key} local${path}`);\n } else if (entry.source === \"skipped\") {\n skipped.push(`${entry.key} no URL resolved`);\n } else if (entry.source === \"failed\") {\n const detail = entry.error ? `: ${entry.error}` : \"\";\n failed.push(`${entry.key}${detail}`);\n }\n }\n\n return {\n status: \"success\" as const,\n generated: [\n ...generated,\n \".bos/bos.resolved-config.json\",\n // the composition inventory (#594) — emitted when the map's\n // sources resolve (skipped with a note otherwise)\n ...(existsSync(join(projectDir, \".bos/generated/runtime-map.json\"))\n ? [\".bos/generated/runtime-map.json\"]\n : []),\n ...(runtime.ui?.source === \"local\" &&\n runtime.ui.localPath &&\n existsSync(join(runtime.ui.localPath, \"src/lib/runtime-map.gen.ts\"))\n ? [\"ui/src/lib/runtime-map.gen.ts\"]\n : []),\n ],\n fetched,\n skipped,\n failed,\n };\n },\n catch: (error) => ({\n status: \"error\" as const,\n generated: [],\n fetched: [],\n skipped: [],\n failed: [],\n error: error instanceof Error ? error.message : \"Unknown error\",\n }),\n });\n }),\n };\n}\n"],"mappings":";;;;;;;;;AAuBA,MAAM,0BAAmC,QAAQ,IAAI,aAAa;AAGlE,SAAgB,iBAAiB,SAAqB;CACpD,OAAO,EACL,UAAU,QAAQ,SAAS,OAAO,WAAW,OAAO,OAAO;EACzD,OAAO,OAAO,OAAO,WAAW;GAC9B,KAAK,YAAY;IACf,MAAM,aAAa,eAAe;IAClC,IAAI,CAAC,YACH,OAAO;KACL,QAAQ;KACR,WAAW,CAAC;KACZ,SAAS,CAAC;KACV,SAAS,CAAC;KACV,QAAQ,CAAC;KACT,OAAO,GAAG,uBAAuB;IACnC;IAGF,MAAM,aAAa,QAAQ,QAAQ,UAAU,CAAC;IAC9C,MAAM,MAAM,MAAM,QAAQ,kBAAkB,IAAI,eAAe;IAE/D,MAAM,YAAY,MAAM,eAAe;KACrC,KAAK;KACL;KACA,eAAe,MAAM;IACvB,CAAC;IACD,IAAI,CAAC,WAAW,UAAU,CAAC,UAAU,SACnC,OAAO;KACL,QAAQ;KACR,WAAW,CAAC;KACZ,SAAS,CAAC;KACV,SAAS,CAAC;KACV,QAAQ,CAAC;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