UNPKG

everything-dev

Version:

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

80 lines (78 loc) • 3.87 kB
const require_load = require('../resolution/load.cjs'); const require_bos_ref = require('../../utils/bos-ref.cjs'); const require_init_source = require('../resolution/init-source.cjs'); const require_manifest = require('../platform/manifest.cjs'); //#region src/services/scaffold/upgrade-source.ts async function readExtendedRootSource(projectDir, options = {}) { const localConfig = await require_load.readAuthoredConfigInput(projectDir); if (!localConfig) throw new Error("No authored config found in current directory"); if (!require_bos_ref.getExtendsRef(localConfig)?.startsWith("bos://")) throw new Error("No bos:// extends field found in the authored config — upgrade moves children that extend a deployed runtime"); const walk = await require_manifest.walkExtendsChain({ localConfig, localRepository: typeof localConfig.repository === "string" ? localConfig.repository : void 0, ...options.fetchParent ? { fetchParent: options.fetchParent } : {} }); const extendsChain = walk.chain.map((node) => `bos://${node.account}/${node.gateway}`); if (walk.circularAt) throw new Error(`Circular extends detected while resolving upgrade source: ${walk.circularAt}`); const platform = await require_manifest.resolvePlatformManifest({ configDir: projectDir, localConfig: { ...localConfig, platform: void 0 }, ...options.fetchManifest ? { fetchManifest: options.fetchManifest } : {}, ...options.fetchParent ? { fetchParent: options.fetchParent } : {}, ...options.cacheRead ? { cacheRead: options.cacheRead } : {}, ...options.cacheWrite ? { cacheWrite: options.cacheWrite } : {}, ...options.now ? { now: options.now } : {}, ...options.cacheTtlMs !== void 0 ? { cacheTtlMs: options.cacheTtlMs } : {} }); if (!platform) throw new Error(`No platform release manifest resolves in the extends chain (${extendsChain.join(" → ")}) — publish the platform manifest (bos publish on the parent) or run \`bos platform manifest --check\` to diagnose`); return { catalog: platform.manifest.catalog, repository: walk.repository, extendsChain, platform }; } async function loadParentPluginOptions(projectDir) { const localConfig = await require_load.readAuthoredConfigInput(projectDir); if (!localConfig) return null; const extendsRef = require_bos_ref.getExtendsRef(localConfig); if (!extendsRef?.startsWith("bos://")) return null; const parsed = require_bos_ref.parseBosRef(extendsRef); if (!parsed) return null; let parentConfig; try { parentConfig = await require_init_source.fetchParentConfig(parsed.account, parsed.gateway); } catch { return null; } const parentPlugins = parentConfig.plugins && typeof parentConfig.plugins === "object" ? parentConfig.plugins : {}; const localPlugins = localConfig.plugins && typeof localConfig.plugins === "object" ? localConfig.plugins : {}; return { localConfig, parentPlugins, newPluginKeys: Object.keys(parentPlugins).filter((key) => !(key in localPlugins)) }; } function extractSemver(value) { if (!value) return null; return value.match(/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?/)?.[0] ?? null; } function buildChangelogUrl(oldVersion, newVersion, repository) { const fromVersion = extractSemver(oldVersion); const toVersion = extractSemver(newVersion); if (!fromVersion || !toVersion || fromVersion === toVersion) return void 0; const repoUrl = repository; if (!repoUrl) return void 0; const githubMatch = repoUrl.match(/^https?:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?$/); if (!githubMatch) return void 0; const [, owner, repo] = githubMatch; return `https://github.com/${owner}/${repo}/compare/v${fromVersion}...v${toVersion}`; } //#endregion exports.buildChangelogUrl = buildChangelogUrl; exports.loadParentPluginOptions = loadParentPluginOptions; exports.readExtendedRootSource = readExtendedRootSource; //# sourceMappingURL=upgrade-source.cjs.map