everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
78 lines (76 loc) • 3.69 kB
JavaScript
import { readAuthoredConfigInput } from "../resolution/load.mjs";
import { getExtendsRef, parseBosRef } from "../../utils/bos-ref.mjs";
import { fetchParentConfig } from "../resolution/init-source.mjs";
import { resolvePlatformManifest, walkExtendsChain } from "../platform/manifest.mjs";
//#region src/services/scaffold/upgrade-source.ts
async function readExtendedRootSource(projectDir, options = {}) {
const localConfig = await readAuthoredConfigInput(projectDir);
if (!localConfig) throw new Error("No authored config found in current directory");
if (!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 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 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 readAuthoredConfigInput(projectDir);
if (!localConfig) return null;
const extendsRef = getExtendsRef(localConfig);
if (!extendsRef?.startsWith("bos://")) return null;
const parsed = parseBosRef(extendsRef);
if (!parsed) return null;
let parentConfig;
try {
parentConfig = await 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
export { buildChangelogUrl, loadParentPluginOptions, readExtendedRootSource };
//# sourceMappingURL=upgrade-source.mjs.map