@fulgurjs/federation 4.3.1 → 5.0.0

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,141 +0,0 @@
1
- import {
2
- definePages
3
- } from "./chunk-TSXZ7TWA.js";
4
-
5
- // src/vue-adapter.ts
6
- import { defineAsyncComponent, defineComponent, h } from "vue";
7
- var ERROR_STYLE = {
8
- padding: "16px",
9
- border: "1px solid #fde2e2",
10
- borderRadius: "4px",
11
- background: "#fef0f0",
12
- color: "#c45656",
13
- fontSize: "13px",
14
- lineHeight: "1.6"
15
- };
16
- var RemoteErrorPlaceholder = defineComponent({
17
- name: "FulgurjsRemoteError",
18
- props: { error: { type: Object, default: void 0 } },
19
- setup(props) {
20
- return () => {
21
- const err = props.error;
22
- const code = err?.code ?? "UNKNOWN";
23
- const message = err?.message ?? String(props.error ?? "unknown error");
24
- return h("div", { style: ERROR_STYLE }, [
25
- h("p", { style: "margin:0 0 4px;font-weight:600" }, `\u8FDC\u7A0B\u7EC4\u4EF6\u52A0\u8F7D\u5931\u8D25\uFF08\u9519\u8BEF\u7801 ${code}\uFF09`),
26
- h("p", { style: "margin:0 0 8px;word-break:break-all" }, message),
27
- h("p", { style: "margin:0" }, "\u4FEE\u6CD5\uFF1A\u2460 \u6838\u5BF9 spec \u7684\u300C\u8FDC\u7A0B\u540D/expose \u540D\u300D\u4E0E\u8FDC\u7A0B\u5E94\u7528 exposes \u662F\u5426\u4E00\u81F4\uFF08MFU-006/008\uFF09\uFF1B\u2461 \u6838\u5BF9 remotes \u5730\u5740\u7AEF\u53E3\u4E0E\u8FDC\u7A0B\u670D\u52A1\u53EF\u8FBE\u6027\u3001remoteEntry \u662F\u5426\u53EF\u8BBF\u95EE\uFF08MFU-001\uFF09\uFF1B\u2462 \u67E5\u770B window \u7684 fulgurjs:error \u4E8B\u4EF6\u4E0E console \u540C\u6E90\u9519\u8BEF\u5B9A\u4F4D\u6839\u56E0\u3002")
28
- ]);
29
- };
30
- }
31
- });
32
- function createRemoteComponent(loadRemote) {
33
- return function remoteComponent(spec, opts = {}) {
34
- return defineAsyncComponent({
35
- loader: () => loadRemote(spec, { retries: opts.retries }).then((m) => m.default ?? m),
36
- loadingComponent: opts.loadingComponent,
37
- errorComponent: opts.errorComponent ?? RemoteErrorPlaceholder,
38
- delay: opts.delay,
39
- timeout: opts.timeout
40
- });
41
- };
42
- }
43
- var cleanCompName = (spec) => "Fulgurjs_" + spec.replace(/[^A-Za-z0-9_-]/g, "_");
44
- function defaultDeriveSpec(route) {
45
- return route.split("/").filter(Boolean).slice(1).filter((seg) => !seg.startsWith(":")).join("/");
46
- }
47
- function createHostPages(options, load) {
48
- const { pages, remotePrefixes, deriveSpec, schema, strict, base, beforeLoad, loadingComponent, errorComponent, delay } = options;
49
- definePages(pages, { deriveSpec, remotes: remotePrefixes, schema, strict });
50
- const prefixes = Object.entries(remotePrefixes).map(([p, name]) => [p.endsWith("/") ? p : `${p}/`, name]).sort((a, b) => b[0].length - a[0].length);
51
- const remoteOf = (route) => {
52
- for (const [prefix, name] of prefixes) {
53
- if (route.startsWith(prefix) || `${route}/` === prefix) return name;
54
- }
55
- throw new Error(
56
- `[fulgurjs] \u9875\u9762\u8DEF\u7531 "${route}" \u672A\u5339\u914D\u4EFB\u4F55 remotePrefixes\uFF1A{ ${Object.entries(remotePrefixes).map(([k, v]) => `'${k}': '${v}'`).join(", ")} }
57
- \u6839\u56E0: \u9875\u9762\u8868\u6761\u76EE\u7684\u8DEF\u7531\u4E0D\u5728\u4EFB\u4F55\u5DF2\u58F0\u660E\u7684\u8FDC\u7A0B\u524D\u7F00\u4E0B\u3002
58
- \u4FEE\u6CD5: \u5728 remotePrefixes \u8865\u5145\u8BE5\u8DEF\u7531\u524D\u7F00 \u2192 \u8FDC\u7A0B\u540D\u7684\u6620\u5C04\uFF0C\u6216\u4FEE\u6B63\u9875\u9762\u8868 route\u3002`
59
- );
60
- };
61
- for (const page of pages) remoteOf(page.route);
62
- const specOf = (page) => {
63
- const s = page.spec ?? (deriveSpec ? deriveSpec(page.route) : defaultDeriveSpec(page.route));
64
- return `${remoteOf(page.route)}/${String(s).replace(/^[./]+/, "")}`;
65
- };
66
- const baseNorm = base && base !== "/" ? base.endsWith("/") ? base : `${base}/` : "";
67
- const matchSegments = (pattern, path) => {
68
- const patSegs = pattern.split("/").filter(Boolean);
69
- const pathSegs = path.split("/").filter(Boolean);
70
- if (patSegs.length !== pathSegs.length) return null;
71
- const params = {};
72
- for (let i = 0; i < patSegs.length; i++) {
73
- const seg = patSegs[i];
74
- if (seg.startsWith(":")) {
75
- try {
76
- params[seg.slice(1)] = decodeURIComponent(pathSegs[i]);
77
- } catch {
78
- return null;
79
- }
80
- } else if (seg !== pathSegs[i]) {
81
- return null;
82
- }
83
- }
84
- return params;
85
- };
86
- let cacheSession;
87
- const compCache = /* @__PURE__ */ new Map();
88
- const resolve = (rawPath) => {
89
- let clean = String(rawPath ?? "");
90
- if (baseNorm) {
91
- if (clean === baseNorm.replace(/\/$/, "")) clean = "/";
92
- else if (clean.startsWith(baseNorm)) clean = `/${clean.slice(baseNorm.length)}`;
93
- }
94
- clean = (clean.replace(/\/+$/, "") || "/").split("?")[0].split("#")[0];
95
- for (const page of pages) {
96
- const params = matchSegments(page.route, clean);
97
- if (params) return { page, remote: remoteOf(page.route), spec: specOf(page), params };
98
- }
99
- return null;
100
- };
101
- const component = (spec) => {
102
- const sk = (globalThis.__FULGURJS_APP_CONFIG__ ?? {}).sessionKey;
103
- const sessionKey = typeof sk === "string" && sk !== "" ? sk : void 0;
104
- if (sessionKey !== void 0 && sessionKey !== cacheSession) {
105
- compCache.clear();
106
- cacheSession = sessionKey;
107
- }
108
- let comp = compCache.get(spec);
109
- if (!comp) {
110
- const name = cleanCompName(spec);
111
- const asyncComp = defineAsyncComponent({
112
- loader: async () => {
113
- await beforeLoad?.();
114
- const mod = await load(spec);
115
- const inner = mod?.default ?? mod;
116
- if (!inner) {
117
- throw new Error(
118
- `[fulgurjs] \u8FDC\u7A0B\u6A21\u5757 "${spec}" \u6CA1\u6709\u5BFC\u51FA\u53EF\u6E32\u67D3\u7EC4\u4EF6\uFF1B\u5F53\u524D\u503C\u7C7B\u578B\u4E3A ${inner === null ? "null" : typeof inner}\u3002
119
- \u4FEE\u6CD5: \u6838\u5BF9\u8FDC\u7A0B exposes \u952E\u540D\u4E0E\u9875\u9762\u8868 spec \u662F\u5426\u4E00\u81F4\uFF08MFU-006 \u8BED\u4E49\uFF09`
120
- );
121
- }
122
- return inner;
123
- },
124
- loadingComponent,
125
- errorComponent: errorComponent ?? RemoteErrorPlaceholder,
126
- delay
127
- });
128
- asyncComp.name = name;
129
- comp = asyncComp;
130
- compCache.set(spec, comp);
131
- }
132
- return comp;
133
- };
134
- const keepAliveNames = pages.filter((p) => p.keepAlive).map((p) => cleanCompName(specOf(p)));
135
- return { pages, resolve, component, keepAliveNames };
136
- }
137
-
138
- export {
139
- createRemoteComponent,
140
- createHostPages
141
- };
@@ -1,46 +0,0 @@
1
- // src/runtime/errors.ts
2
- var FgError = class extends Error {
3
- code;
4
- details;
5
- constructor(code, message, details) {
6
- super(`[fulgurjs:${code}] ${message}`);
7
- this.name = "FgError";
8
- this.code = code;
9
- this.details = details;
10
- }
11
- };
12
- var ErrorCodes = {
13
- /** 远程容器加载失败(网络/超时/重试耗尽/熔断) */
14
- REMOTE_LOAD_FAILED: "MFU-001",
15
- /** remoteEntry 自报名与 remotes 配置的名称不匹配 */
16
- REMOTE_NAME_MISMATCH: "MFU-002",
17
- /** strictVersion 开启且共享版本不满足 */
18
- SHARE_STRICT_VERSION: "MFU-003",
19
- /** 共享模块缺失且无本地 fallback(import: false) */
20
- SHARE_NOT_AVAILABLE: "MFU-004",
21
- /** 同一容器用不同 share scope 重复 init */
22
- CONTAINER_REINIT_CONFLICT: "MFU-005",
23
- /** 请求的模块未被该远程 exposes */
24
- MODULE_NOT_EXPOSED: "MFU-006",
25
- /** 预加载失败 */
26
- PRELOAD_FAILED: "MFU-007",
27
- /** 未知远程 */
28
- REMOTE_UNKNOWN: "MFU-008",
29
- /** 加载到的模块没有任何导出(常见:exposes 指向了不导出内容的文件) */
30
- EMPTY_EXPORTS: "MFU-009",
31
- /** singleton 共享协商版本与消费方 requiredVersion 不一致(使用作用域版本,仅告警) */
32
- SINGLETON_SKEW: "MFU-010",
33
- /** setup 生命周期入口导出形态非法(默认导出不是函数,或具名 onSession 不是函数) */
34
- SETUP_INVALID_EXPORT: "MFU-011",
35
- /** setup/onSession 执行抛错(该次 loadRemote 拒绝;仅清失败阶段缓存,允许重试) */
36
- SETUP_RUN_FAILED: "MFU-012",
37
- /** 远程声明了 onSession 但宿主 AppContext 未提供 sessionKey(登录代次) */
38
- SETUP_SESSION_KEY_MISSING: "MFU-013",
39
- /** setup/onSession 执行的同步段内递归 loadRemote 同一远程 */
40
- SETUP_RECURSION: "MFU-014"
41
- };
42
-
43
- export {
44
- FgError,
45
- ErrorCodes
46
- };
package/dist/config.cjs DELETED
@@ -1,174 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/config.ts
31
- var config_exports = {};
32
- __export(config_exports, {
33
- defineRepoConfig: () => defineRepoConfig,
34
- federationOptionsForApp: () => federationOptionsForApp,
35
- loadRepoConfig: () => loadRepoConfig
36
- });
37
- module.exports = __toCommonJS(config_exports);
38
- var import_meta = {};
39
- function defineRepoConfig(config) {
40
- return config;
41
- }
42
- async function loadRepoConfig(configPath) {
43
- const { pathToFileURL, fileURLToPath } = await import("url");
44
- const { createRequire } = await import("module");
45
- const fs = await import("fs");
46
- const os = await import("os");
47
- const path = await import("path");
48
- const selfDir = await (async () => {
49
- try {
50
- return path.dirname(fileURLToPath(import_meta.url));
51
- } catch {
52
- }
53
- try {
54
- return __dirname;
55
- } catch {
56
- }
57
- return "";
58
- })();
59
- const selfConfigJs = selfDir ? path.join(selfDir, "config.js") : "";
60
- const SELF_SPEC = selfConfigJs && fs.existsSync(selfConfigJs) ? pathToFileURL(selfConfigJs).href : "@fulgurjs-federation-config-unavailable";
61
- const rewriteSelfImports = (source) => source.replace(/(['"])@fulgurjs\/federation\/config\1/g, (_m, q) => `${q}${SELF_SPEC}${q}`);
62
- let cacheBust = 0;
63
- const importConfigs = async (cacheKey) => {
64
- return await import(`${cacheKey}?t=${Date.now()}-${++cacheBust}`);
65
- };
66
- let mod;
67
- if (configPath.endsWith(".json")) {
68
- mod = { default: JSON.parse(fs.readFileSync(configPath, "utf8")) };
69
- } else {
70
- const source = rewriteSelfImports(fs.readFileSync(configPath, "utf8"));
71
- const tmpBase = path.join(os.tmpdir(), `fulgurjs-config-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`);
72
- if (/\.(ts|mts|cts)$/.test(configPath)) {
73
- try {
74
- const tmpTs = `${tmpBase}.ts`;
75
- fs.writeFileSync(tmpTs, source);
76
- mod = await importConfigs(pathToFileURL(tmpTs).href);
77
- } catch (e) {
78
- if (!/Unexpected|SyntaxError|ERR_UNSUPPORTED_NODE_MODULES|ERR_UNKNOWN_FILE_EXTENSION|ERR_IMPORT_ATTRIBUTE/.test(String(e)) && process.version.startsWith("v2")) {
79
- throw e;
80
- }
81
- const requireFromConfig = createRequire(configPath);
82
- let esbuild;
83
- try {
84
- esbuild = requireFromConfig("esbuild");
85
- } catch {
86
- const requireFromSelf = createRequire(import_meta.url);
87
- esbuild = requireFromSelf("esbuild");
88
- }
89
- const out = esbuild.buildSync({ entryPoints: [configPath], bundle: false, write: false, format: "esm", target: "node18" });
90
- const jsFile = `${tmpBase}.mjs`;
91
- fs.writeFileSync(jsFile, rewriteSelfImports(out.outputFiles[0].text));
92
- mod = await importConfigs(pathToFileURL(jsFile).href);
93
- }
94
- } else {
95
- const jsFile = `${tmpBase}.mjs`;
96
- fs.writeFileSync(jsFile, source);
97
- mod = await importConfigs(pathToFileURL(jsFile).href);
98
- }
99
- }
100
- const cfg = mod.default;
101
- if (!cfg?.root) {
102
- throw new Error(
103
- `[fulgurjs:init] \u914D\u7F6E\u7F3A\u5C11 root\uFF08\u5DE5\u7A0B\u6839\u76EE\u5F55\u7EDD\u5BF9\u8DEF\u5F84\uFF09
104
- \u6839\u56E0\uFF1ACLI \u9700\u8981\u77E5\u9053\u5728\u54EA\u4E2A\u5DE5\u7A0B\u4E0A\u505A\u96C6\u6210
105
- \u4FEE\u6CD5\uFF1Afulgurjs.config.ts \u9876\u5C42\u8865 root: '/abs/path/to/repo'\uFF08\u8D77\u6B65\u6A21\u677F\uFF1Afulgurjs init\uFF09`
106
- );
107
- }
108
- if (!Array.isArray(cfg.apps) || cfg.apps.length === 0) {
109
- throw new Error("[fulgurjs:init] \u914D\u7F6E\u7F3A\u5C11 apps\uFF08\u81F3\u5C11\u4E00\u4E2A\u5BBF\u4E3B\u6216\u8FDC\u7A0B\u5E94\u7528\uFF09");
110
- }
111
- for (const app of cfg.apps) {
112
- if (!app.host && !app.remote) {
113
- throw new Error(
114
- `[fulgurjs:init] \u5E94\u7528 "${app.path}" \u65E2\u65E0 host \u4E5F\u65E0 remote \u89D2\u8272
115
- \u6839\u56E0\uFF1A\u5E94\u7528\u5FC5\u987B\u81F3\u5C11\u58F0\u660E\u4E00\u4E2A\u89D2\u8272
116
- \u4FEE\u6CD5\uFF1A\u5BBF\u4E3B\u8865 host: { remotePrefixes, remotes }\uFF08pages \u53EF\u9009\uFF09\uFF0C\u8FDC\u7A0B\u8865 remote: { exposes }`
117
- );
118
- }
119
- }
120
- return cfg;
121
- }
122
- function federationOptionsForApp(config, appPathOrName) {
123
- const app = config.apps.find(
124
- (a) => a.path === appPathOrName || a.name === appPathOrName
125
- );
126
- if (!app) {
127
- throw new Error(
128
- `[fulgurjs] \u5E94\u7528 "${appPathOrName}" \u4E0D\u5728\u4ED3\u5E93\u914D\u7F6E\u4E2D
129
- \u53EF\u7528\u5E94\u7528: ${config.apps.map((a) => `${a.path}(${a.name})`).join("\u3001")}
130
- \u4FEE\u6CD5: \u4FEE\u6B63\u5E94\u7528\u76EE\u5F55\u540D\u6216\u5BB9\u5668\u540D\uFF08fulgurjs.config.ts apps \u6570\u7EC4\u5185\u4E8C\u9009\u4E00\u5339\u914D\uFF09`
131
- );
132
- }
133
- if (!app.host && !app.remote) {
134
- throw new Error(
135
- `[fulgurjs] \u5E94\u7528 "${app.path}" \u65E2\u65E0 host \u4E5F\u65E0 remote \u89D2\u8272
136
- \u4FEE\u6CD5: \u5BBF\u4E3B\u8865 host: { remotePrefixes, remotes }\uFF0C\u8FDC\u7A0B\u8865 remote: { exposes }`
137
- );
138
- }
139
- const remotes = {};
140
- const remoteSource = /* @__PURE__ */ new Map();
141
- const mergeRemotes = (from, role) => {
142
- for (const [key, addr] of Object.entries(from ?? {})) {
143
- const prev = remotes[key];
144
- if (prev && (prev.dev !== addr.dev || prev.prod !== addr.prod)) {
145
- throw new Error(
146
- `[fulgurjs] \u5E94\u7528 "${app.path}" \u7684\u8FDC\u7A0B "${key}" \u5728 ${role} \u4E0E ${remoteSource.get(key)} \u4E24\u5904\u5730\u5740\u4E0D\u4E00\u81F4
147
- ${remoteSource.get(key)}: dev=${prev.dev} prod=${prev.prod}
148
- ${role}: dev=${addr.dev} prod=${addr.prod}
149
- \u4FEE\u6CD5: \u4FEE\u6B63 fulgurjs.config.ts \u4F7F\u4E24\u5904\u4E00\u81F4\uFF08\u540C\u4E00\u8FDC\u7A0B\u5728\u4E00\u4E2A\u5E94\u7528\u5185\u53EA\u80FD\u6709\u4E00\u4E2A\u5730\u5740\uFF09`
150
- );
151
- }
152
- remotes[key] = addr;
153
- remoteSource.set(key, role);
154
- }
155
- };
156
- mergeRemotes(app.host?.remotes, "host.remotes");
157
- mergeRemotes(app.remote?.remotes, "remote.remotes");
158
- const hasExposes = !!app.remote && Object.keys(app.remote.exposes).length > 0;
159
- const hasRemotes = Object.keys(remotes).length > 0;
160
- return {
161
- name: app.name,
162
- ...hasRemotes ? { remotes } : {},
163
- ...hasExposes ? { exposes: app.remote.exposes } : {},
164
- ...app.remote?.setup ? { setup: app.remote.setup } : {},
165
- ...app.shared ? { shared: app.shared } : {},
166
- devSharedSelf: app.devSharedSelf ?? (hasExposes || !!app.remote?.setup)
167
- };
168
- }
169
- // Annotate the CommonJS export names for ESM import in node:
170
- 0 && (module.exports = {
171
- defineRepoConfig,
172
- federationOptionsForApp,
173
- loadRepoConfig
174
- });
package/dist/config.d.cts DELETED
@@ -1,106 +0,0 @@
1
- import { F as FederationOptions } from './options-CRGpSmVj.cjs';
2
-
3
- /**
4
- * W1 fulgurjs.config.ts:单配置文件驱动的 schema + 加载器(项目无关,决策见排期文档 §4:
5
- * 主包内置 bin + 单配置文件驱动,可入库可复跑)。
6
- * init 只消费该配置生成通用样板(见 init.ts);插件运行时(federation())不读取本文件。
7
- */
8
- interface PageEntry {
9
- /** 宿主路由路径(参数段用 :xx) */
10
- route: string;
11
- /** 路由 name(命名跳转依赖) */
12
- name?: string;
13
- /** 远程 exposes 键(显式覆盖默认推导 pages/<去前缀去参数段>) */
14
- spec?: string;
15
- /** 页签标题 */
16
- title?: string;
17
- /** 页面保活开关(按页显式开启;默认关闭) */
18
- keepAlive?: boolean;
19
- }
20
- interface RemoteAddress {
21
- dev: string;
22
- prod: string;
23
- }
24
- interface HostConfig {
25
- /**
26
- * 页面路由表(可选):应用代码的页面表是运行时页面真源(供宿主路由与
27
- * createHostPages 共用),仓库配置中的副本仅供 init/explain 摘要与核对。
28
- * 不再强制——缺省时 CLI 摘要按实际提供数量报告。
29
- */
30
- pages?: PageEntry[];
31
- /** 页面 spec 推导规则(与宿主 createHostPages 的 deriveSpec 保持一致;缺省 = 去首段 + 剥 :参 段) */
32
- deriveSpec?: (route: string) => string;
33
- /** 路由前缀 → 远程名 */
34
- remotePrefixes: Record<string, string>;
35
- /** 消费的远程地址(键 = import 前缀;裸 URL,对象形式不支持 name@ 前缀) */
36
- remotes: Record<string, RemoteAddress>;
37
- }
38
- interface RemoteConfig {
39
- /** exposes:./键 → 源文件(独立页) */
40
- exposes: Record<string, string>;
41
- /** 远程初始化入口(默认导出 setup(context),可选具名导出 onSession(context)) */
42
- setup?: string;
43
- /** 反向消费的远程(双向联邦时) */
44
- remotes?: Record<string, RemoteAddress>;
45
- }
46
- interface AppConfig {
47
- /** 相对 root 的应用目录 */
48
- path: string;
49
- /** 联邦容器名 */
50
- name: string;
51
- /** dev 端口 */
52
- port: number;
53
- /** 部署/dev 的 URL 前缀,如 /main */
54
- base: string;
55
- /** 部署目录名(缺省取 base 去斜杠) */
56
- deployDir?: string;
57
- /** 宿主角色 */
58
- host?: HostConfig;
59
- /** 远程角色 */
60
- remote?: RemoteConfig;
61
- /** 该应用的 shared 表(缺省建议 vue/vue-router/pinia singleton,见 init 输出的样板) */
62
- shared?: Record<string, {
63
- singleton?: boolean;
64
- requiredVersion?: string;
65
- }>;
66
- /** 显式覆盖 dev 下自身源码参与 shared 协商改写;缺省按角色推断(见 federationOptionsForApp) */
67
- devSharedSelf?: boolean;
68
- }
69
- interface DeployConfig {
70
- /** NGINX 站点根(样板输出用,可选) */
71
- webRoot?: string;
72
- /** 监听端口(样板输出用,可选) */
73
- listen?: number;
74
- }
75
- interface RepoConfig {
76
- /** 工程根(monorepo 根或单应用仓库根) */
77
- root: string;
78
- apps: AppConfig[];
79
- deploy?: DeployConfig;
80
- }
81
- type UserConfig = Partial<RepoConfig>;
82
- /** 用户配置文件入口:仅做类型收窄(identity),不引入运行时逻辑 */
83
- declare function defineRepoConfig(config: UserConfig): UserConfig;
84
- /**
85
- * 加载 fulgurjs.config.ts(或 .js/.json)。
86
- * - 配置内的 `@fulgurjs/federation/config` 导入被重写为本包 dist/config.js 绝对路径——
87
- * init 之前工程依赖尚未安装(鸡生蛋),重写后零依赖可加载;
88
- * - TS 走 Node 原生类型剥离(Node ≥23.6 默认开启;配置文件须用可擦除语法——纯对象无 enum/namespace);
89
- * 老版本 Node 回退 esbuild 转译(先试配置工程,再试 CLI 自带依赖树)。
90
- */
91
- declare function loadRepoConfig(configPath: string): Promise<RepoConfig>;
92
- /**
93
- * 仓库配置 → 某应用的 federation() Vite 插件选项(§3.4 单配置驱动)。
94
- *
95
- * 转换范围:name、宿主/反向 remotes(两处同键冲突即报错,带两边值)、exposes、
96
- * 可选 setup、shared、devSharedSelf。build.target/base/端口/代理/插件顺序等仍归各应用
97
- * vite.config.ts 管理——本函数只生成 federation({...}) 的入参。
98
- *
99
- * devSharedSelf 来源(优先级):app.devSharedSelf 显式值 > 角色推断。
100
- * 推断规则:提供 exposes(含仅 setup)的应用为 true(其源码被宿主消费,需协商到宿主
101
- * 实例);纯宿主(只消费)为 false。双向联邦漏配该项曾是已知错误配置(§12.4),
102
- * 推断后不再依赖背诵。
103
- */
104
- declare function federationOptionsForApp(config: RepoConfig, appPathOrName: string): FederationOptions;
105
-
106
- export { type AppConfig, type DeployConfig, type HostConfig, type PageEntry, type RemoteAddress, type RemoteConfig, type RepoConfig, type UserConfig, defineRepoConfig, federationOptionsForApp, loadRepoConfig };
package/dist/config.d.ts DELETED
@@ -1,106 +0,0 @@
1
- import { F as FederationOptions } from './options-CRGpSmVj.js';
2
-
3
- /**
4
- * W1 fulgurjs.config.ts:单配置文件驱动的 schema + 加载器(项目无关,决策见排期文档 §4:
5
- * 主包内置 bin + 单配置文件驱动,可入库可复跑)。
6
- * init 只消费该配置生成通用样板(见 init.ts);插件运行时(federation())不读取本文件。
7
- */
8
- interface PageEntry {
9
- /** 宿主路由路径(参数段用 :xx) */
10
- route: string;
11
- /** 路由 name(命名跳转依赖) */
12
- name?: string;
13
- /** 远程 exposes 键(显式覆盖默认推导 pages/<去前缀去参数段>) */
14
- spec?: string;
15
- /** 页签标题 */
16
- title?: string;
17
- /** 页面保活开关(按页显式开启;默认关闭) */
18
- keepAlive?: boolean;
19
- }
20
- interface RemoteAddress {
21
- dev: string;
22
- prod: string;
23
- }
24
- interface HostConfig {
25
- /**
26
- * 页面路由表(可选):应用代码的页面表是运行时页面真源(供宿主路由与
27
- * createHostPages 共用),仓库配置中的副本仅供 init/explain 摘要与核对。
28
- * 不再强制——缺省时 CLI 摘要按实际提供数量报告。
29
- */
30
- pages?: PageEntry[];
31
- /** 页面 spec 推导规则(与宿主 createHostPages 的 deriveSpec 保持一致;缺省 = 去首段 + 剥 :参 段) */
32
- deriveSpec?: (route: string) => string;
33
- /** 路由前缀 → 远程名 */
34
- remotePrefixes: Record<string, string>;
35
- /** 消费的远程地址(键 = import 前缀;裸 URL,对象形式不支持 name@ 前缀) */
36
- remotes: Record<string, RemoteAddress>;
37
- }
38
- interface RemoteConfig {
39
- /** exposes:./键 → 源文件(独立页) */
40
- exposes: Record<string, string>;
41
- /** 远程初始化入口(默认导出 setup(context),可选具名导出 onSession(context)) */
42
- setup?: string;
43
- /** 反向消费的远程(双向联邦时) */
44
- remotes?: Record<string, RemoteAddress>;
45
- }
46
- interface AppConfig {
47
- /** 相对 root 的应用目录 */
48
- path: string;
49
- /** 联邦容器名 */
50
- name: string;
51
- /** dev 端口 */
52
- port: number;
53
- /** 部署/dev 的 URL 前缀,如 /main */
54
- base: string;
55
- /** 部署目录名(缺省取 base 去斜杠) */
56
- deployDir?: string;
57
- /** 宿主角色 */
58
- host?: HostConfig;
59
- /** 远程角色 */
60
- remote?: RemoteConfig;
61
- /** 该应用的 shared 表(缺省建议 vue/vue-router/pinia singleton,见 init 输出的样板) */
62
- shared?: Record<string, {
63
- singleton?: boolean;
64
- requiredVersion?: string;
65
- }>;
66
- /** 显式覆盖 dev 下自身源码参与 shared 协商改写;缺省按角色推断(见 federationOptionsForApp) */
67
- devSharedSelf?: boolean;
68
- }
69
- interface DeployConfig {
70
- /** NGINX 站点根(样板输出用,可选) */
71
- webRoot?: string;
72
- /** 监听端口(样板输出用,可选) */
73
- listen?: number;
74
- }
75
- interface RepoConfig {
76
- /** 工程根(monorepo 根或单应用仓库根) */
77
- root: string;
78
- apps: AppConfig[];
79
- deploy?: DeployConfig;
80
- }
81
- type UserConfig = Partial<RepoConfig>;
82
- /** 用户配置文件入口:仅做类型收窄(identity),不引入运行时逻辑 */
83
- declare function defineRepoConfig(config: UserConfig): UserConfig;
84
- /**
85
- * 加载 fulgurjs.config.ts(或 .js/.json)。
86
- * - 配置内的 `@fulgurjs/federation/config` 导入被重写为本包 dist/config.js 绝对路径——
87
- * init 之前工程依赖尚未安装(鸡生蛋),重写后零依赖可加载;
88
- * - TS 走 Node 原生类型剥离(Node ≥23.6 默认开启;配置文件须用可擦除语法——纯对象无 enum/namespace);
89
- * 老版本 Node 回退 esbuild 转译(先试配置工程,再试 CLI 自带依赖树)。
90
- */
91
- declare function loadRepoConfig(configPath: string): Promise<RepoConfig>;
92
- /**
93
- * 仓库配置 → 某应用的 federation() Vite 插件选项(§3.4 单配置驱动)。
94
- *
95
- * 转换范围:name、宿主/反向 remotes(两处同键冲突即报错,带两边值)、exposes、
96
- * 可选 setup、shared、devSharedSelf。build.target/base/端口/代理/插件顺序等仍归各应用
97
- * vite.config.ts 管理——本函数只生成 federation({...}) 的入参。
98
- *
99
- * devSharedSelf 来源(优先级):app.devSharedSelf 显式值 > 角色推断。
100
- * 推断规则:提供 exposes(含仅 setup)的应用为 true(其源码被宿主消费,需协商到宿主
101
- * 实例);纯宿主(只消费)为 false。双向联邦漏配该项曾是已知错误配置(§12.4),
102
- * 推断后不再依赖背诵。
103
- */
104
- declare function federationOptionsForApp(config: RepoConfig, appPathOrName: string): FederationOptions;
105
-
106
- export { type AppConfig, type DeployConfig, type HostConfig, type PageEntry, type RemoteAddress, type RemoteConfig, type RepoConfig, type UserConfig, defineRepoConfig, federationOptionsForApp, loadRepoConfig };