@fulgurjs/federation 0.4.2 → 0.5.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.
- package/CHANGELOG.md +20 -7
- package/DESIGN.md +8 -8
- package/README.md +49 -49
- package/dist/cli.js +43 -43
- package/dist/config.cjs +13 -13
- package/dist/config.d.cts +20 -20
- package/dist/config.d.ts +20 -20
- package/dist/config.js +11 -11
- package/dist/index.cjs +139 -139
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +139 -139
- package/dist/pages.cjs +9 -9
- package/dist/pages.d.cts +7 -7
- package/dist/pages.d.ts +7 -7
- package/dist/pages.js +7 -7
- package/dist/runtime.js +2 -2
- package/docs/manual.html +23 -23
- package/docs/webpack-mf-/345/257/271/347/205/247/344/270/216/347/274/272/345/217/243.md +1 -1
- package/docs//346/262/231/347/256/261/350/276/271/347/225/214/345/256/241/350/256/241.md +1 -1
- package/docs//350/277/201/347/247/273/346/214/207/345/215/227.md +8 -8
- package/examples/fulgur.config.example.ts +4 -4
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -43,25 +43,25 @@ var import_node_fs = __toESM(require("fs"), 1);
|
|
|
43
43
|
var import_node_path = __toESM(require("path"), 1);
|
|
44
44
|
|
|
45
45
|
// src/version.ts
|
|
46
|
-
var RUNTIME_VERSION = "0.
|
|
46
|
+
var RUNTIME_VERSION = "0.5.0";
|
|
47
47
|
|
|
48
48
|
// src/options.ts
|
|
49
|
-
var DEFAULT_FILENAME = "
|
|
50
|
-
var RUNTIME_VIRTUAL_ID = "virtual:
|
|
51
|
-
var RUNTIME_PROXY_VIRTUAL_ID = "virtual:
|
|
52
|
-
var INIT_VIRTUAL_ID = "virtual:
|
|
53
|
-
var SHARED_FACADE_PREFIX = "virtual:
|
|
54
|
-
var SHARED_NS_FACADE_PREFIX = "virtual:
|
|
49
|
+
var DEFAULT_FILENAME = "fulgurjs-remoteEntry.js";
|
|
50
|
+
var RUNTIME_VIRTUAL_ID = "virtual:fulgurjs-runtime";
|
|
51
|
+
var RUNTIME_PROXY_VIRTUAL_ID = "virtual:fulgurjs-runtime-proxy";
|
|
52
|
+
var INIT_VIRTUAL_ID = "virtual:fulgurjs-init";
|
|
53
|
+
var SHARED_FACADE_PREFIX = "virtual:fulgurjs-shared:";
|
|
54
|
+
var SHARED_NS_FACADE_PREFIX = "virtual:fulgurjs-shared-ns:";
|
|
55
55
|
var RESOLVED = {
|
|
56
|
-
runtime: "virtual:
|
|
57
|
-
runtimeProxy: "virtual:
|
|
58
|
-
init: "virtual:
|
|
59
|
-
provides: "virtual:
|
|
60
|
-
remoteEntry: "virtual:
|
|
61
|
-
sharedFacade: (name) => `virtual:
|
|
62
|
-
sharedNsFacade: (name) => `virtual:
|
|
56
|
+
runtime: "virtual:fulgurjs-runtime",
|
|
57
|
+
runtimeProxy: "virtual:fulgurjs-runtime-proxy",
|
|
58
|
+
init: "virtual:fulgurjs-init",
|
|
59
|
+
provides: "virtual:fulgurjs-provides",
|
|
60
|
+
remoteEntry: "virtual:fulgurjs-remote-entry",
|
|
61
|
+
sharedFacade: (name) => `virtual:fulgurjs-shared:${name}`,
|
|
62
|
+
sharedNsFacade: (name) => `virtual:fulgurjs-shared-ns:${name}`,
|
|
63
63
|
/** CJS require(<shared>) 垫片:与 sharedNsFacade 同体,仅 id 形态不同(保持 require 调用语义) */
|
|
64
|
-
cjsNsFacade: (name) => `virtual:
|
|
64
|
+
cjsNsFacade: (name) => `virtual:fulgurjs-cjs-ns:${name}`
|
|
65
65
|
};
|
|
66
66
|
function joinUrl(base, file) {
|
|
67
67
|
const b = base.endsWith("/") ? base : `${base}/`;
|
|
@@ -99,7 +99,7 @@ function normalizeRemoteValue(key, value, filename, warnings) {
|
|
|
99
99
|
if (mode === "prod") return rawUrl;
|
|
100
100
|
return rawUrl;
|
|
101
101
|
}
|
|
102
|
-
return joinUrl(rawUrl, mode === "dev" ? "@
|
|
102
|
+
return joinUrl(rawUrl, mode === "dev" ? "@fulgurjs-entry.js" : filename);
|
|
103
103
|
};
|
|
104
104
|
const explicitDev = cfg.dev;
|
|
105
105
|
const explicitProd = cfg.prod;
|
|
@@ -230,7 +230,7 @@ function configError(what, got, expect, example) {
|
|
|
230
230
|
const gotText = typeof got === "string" ? `"${got}"` : JSON.stringify(got);
|
|
231
231
|
throw new Error(
|
|
232
232
|
[
|
|
233
|
-
`[
|
|
233
|
+
`[fulgurjs] Invalid federation() config \u2014 ${what}`,
|
|
234
234
|
` got: ${gotText}`,
|
|
235
235
|
` expected: ${expect}`,
|
|
236
236
|
` example: ${example}`
|
|
@@ -322,7 +322,7 @@ function validateOptions(options) {
|
|
|
322
322
|
function normalizeOptions(options, root, command) {
|
|
323
323
|
const warnings = [];
|
|
324
324
|
validateOptions(options);
|
|
325
|
-
if (!options.name) throw new Error("[
|
|
325
|
+
if (!options.name) throw new Error("[fulgurjs] option `name` is required.");
|
|
326
326
|
if (options.remoteType && options.remoteType !== "module") {
|
|
327
327
|
warnings.push(
|
|
328
328
|
`remoteType "${options.remoteType}" requires webpack-host interop (P3 milestone); falling back to "module".`
|
|
@@ -335,7 +335,7 @@ function normalizeOptions(options, root, command) {
|
|
|
335
335
|
}
|
|
336
336
|
if (options.automaticAsyncBoundary === false) {
|
|
337
337
|
warnings.push(
|
|
338
|
-
"automaticAsyncBoundary=false has no effect:
|
|
338
|
+
"automaticAsyncBoundary=false has no effect: fulgurjs uses TLA-based automatic async boundaries (better than webpack manual bootstrap)."
|
|
339
339
|
);
|
|
340
340
|
}
|
|
341
341
|
const exposes = [];
|
|
@@ -442,7 +442,7 @@ function serializeShareCallForFacade(item, fallbackUrl) {
|
|
|
442
442
|
const facadeUrl = fallbackUrl ?? SHARED_FACADE_PREFIX + item.shareKey;
|
|
443
443
|
opts.push(`fallback: () => import(${JSON.stringify(facadeUrl)})`);
|
|
444
444
|
}
|
|
445
|
-
return `
|
|
445
|
+
return `__fulgurjs_loadShare(${JSON.stringify(item.shareKey)}, { ${opts.join(", ")} })`;
|
|
446
446
|
}
|
|
447
447
|
function serializeShareCall(item, devUrls) {
|
|
448
448
|
const opts = [];
|
|
@@ -455,7 +455,7 @@ function serializeShareCall(item, devUrls) {
|
|
|
455
455
|
const facadeUrl = devUrls ? devUrls.namespaceFacade(item.shareKey) : SHARED_FACADE_PREFIX + item.shareKey;
|
|
456
456
|
opts.push(`fallback: () => import(${JSON.stringify(facadeUrl)})`);
|
|
457
457
|
}
|
|
458
|
-
return `
|
|
458
|
+
return `__fulgurjs_loadShare(${JSON.stringify(item.shareKey)}, { ${opts.join(", ")} })`;
|
|
459
459
|
}
|
|
460
460
|
function stripComments(s) {
|
|
461
461
|
return s.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
|
|
@@ -546,7 +546,7 @@ async function transformModule(code, id, ctx) {
|
|
|
546
546
|
for (const [alias, item] of sharedByAlias) {
|
|
547
547
|
const re = new RegExp(`require\\((["'])${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\1\\)`, "g");
|
|
548
548
|
if (!re.test(code)) continue;
|
|
549
|
-
code = code.replace(re, `require(${JSON.stringify(`virtual:
|
|
549
|
+
code = code.replace(re, `require(${JSON.stringify(`virtual:fulgurjs-cjs-ns:${item.shareKey}`)})`);
|
|
550
550
|
cjsEdited = true;
|
|
551
551
|
}
|
|
552
552
|
if (!cjsEdited) return null;
|
|
@@ -567,7 +567,7 @@ async function transformModule(code, id, ctx) {
|
|
|
567
567
|
let usesRuntimeHelpers = false;
|
|
568
568
|
const tlaLines = [];
|
|
569
569
|
let tempIdx = 0;
|
|
570
|
-
const genTemp = () => `
|
|
570
|
+
const genTemp = () => `__fulgurjs_m${tempIdx++}`;
|
|
571
571
|
const remap = (spec) => ctx.remapSpecifier?.(spec) ?? spec;
|
|
572
572
|
const remoteExposeName = (spec, remoteKey) => {
|
|
573
573
|
if (!spec.startsWith(`${remoteKey}/`)) return null;
|
|
@@ -581,7 +581,7 @@ async function transformModule(code, id, ctx) {
|
|
|
581
581
|
];
|
|
582
582
|
const genTlaOverwrite = (stmtStart, stmtEnd, shared, remoteName, exposeName, clauseRaw, clause) => {
|
|
583
583
|
usesRuntimeHelpers = true;
|
|
584
|
-
const call = shared ? serializeShareCall(shared, ctx?.devUrls) : `
|
|
584
|
+
const call = shared ? serializeShareCall(shared, ctx?.devUrls) : `__fulgurjs_loadRemote(${JSON.stringify(`${remoteName}/${exposeName}`)})`;
|
|
585
585
|
const nsAs = clauseRaw.match(/export\s+\*\s+as\s+(\w+)\s+from/);
|
|
586
586
|
if (nsAs) {
|
|
587
587
|
s.overwrite(stmtStart, stmtEnd, `const ${nsAs[1]} = await ${call};
|
|
@@ -595,14 +595,14 @@ export { ${nsAs[1]} };`);
|
|
|
595
595
|
const tmp = genTemp();
|
|
596
596
|
const parts = [`${tmp} = await ${call}`];
|
|
597
597
|
if (clause.ns) parts.push(`${clause.ns} = ${tmp}`);
|
|
598
|
-
if (clause.defaultLocal) parts.push(`${clause.defaultLocal} =
|
|
598
|
+
if (clause.defaultLocal) parts.push(`${clause.defaultLocal} = __fulgurjsU(${tmp})`);
|
|
599
599
|
const named = clause.bindings?.filter((b) => !b.isDefault) ?? [];
|
|
600
600
|
if (named.length) {
|
|
601
601
|
const destructure = named.map((b) => b.imported === b.local ? b.local : `${b.imported}: ${b.local}`);
|
|
602
602
|
parts.push(`{ ${destructure.join(", ")} } = ${tmp}`);
|
|
603
603
|
}
|
|
604
604
|
for (const b of clause.bindings?.filter((x) => x.isDefault) ?? []) {
|
|
605
|
-
parts.push(`${b.local} =
|
|
605
|
+
parts.push(`${b.local} = __fulgurjsU(${tmp})`);
|
|
606
606
|
}
|
|
607
607
|
s.overwrite(stmtStart, stmtEnd, `const ${parts.join(", ")}`);
|
|
608
608
|
};
|
|
@@ -634,7 +634,7 @@ export { ${nsAs[1]} };`);
|
|
|
634
634
|
const inner = clauseRaw.slice(clauseRaw.indexOf("{") + 1, clauseRaw.lastIndexOf("}"));
|
|
635
635
|
if (/export\s+\*/.test(clauseRaw) && !clauseRaw.includes("{")) {
|
|
636
636
|
throw new Error(
|
|
637
|
-
`[
|
|
637
|
+
`[fulgurjs] "export * from '${spec2}'" on a shared module is not supported (ESM cannot create dynamic export bindings). Use named re-exports: "export { a, b } from '${spec2}'".`
|
|
638
638
|
);
|
|
639
639
|
}
|
|
640
640
|
const bindings = parseBindings(inner).map((b) => b.imported === "default" ? "default" : b.imported);
|
|
@@ -665,15 +665,15 @@ export { ${nsAs[1]} };`);
|
|
|
665
665
|
s.overwrite(
|
|
666
666
|
callStart,
|
|
667
667
|
closeParen + 1,
|
|
668
|
-
`
|
|
668
|
+
`__fulgurjs_loadRemote(${JSON.stringify(`${remote.name}/${exposeName}`)})`
|
|
669
669
|
);
|
|
670
670
|
}
|
|
671
671
|
}
|
|
672
672
|
if (!edited) return null;
|
|
673
673
|
if (usesRuntimeHelpers) {
|
|
674
|
-
const runtimeSpec = JSON.stringify(ctx.devUrls?.runtime ?? "virtual:
|
|
674
|
+
const runtimeSpec = JSON.stringify(ctx.devUrls?.runtime ?? "virtual:fulgurjs-runtime");
|
|
675
675
|
s.prepend(
|
|
676
|
-
`import { loadShare as
|
|
676
|
+
`import { loadShare as __fulgurjs_loadShare, loadRemote as __fulgurjs_loadRemote, unwrapDefault as __fulgurjsU } from ${runtimeSpec};
|
|
677
677
|
`
|
|
678
678
|
);
|
|
679
679
|
}
|
|
@@ -690,39 +690,39 @@ function genSharedFacade(specifier, exportNames) {
|
|
|
690
690
|
);
|
|
691
691
|
if (names.length === 0) {
|
|
692
692
|
return [
|
|
693
|
-
`import * as
|
|
693
|
+
`import * as __fulgurjs_facade from ${JSON.stringify(specifier)};`,
|
|
694
694
|
`export * from ${JSON.stringify(specifier)};`,
|
|
695
|
-
`export default
|
|
695
|
+
`export default __fulgurjs_facade.default ?? __fulgurjs_facade;`,
|
|
696
696
|
""
|
|
697
697
|
].join("\n");
|
|
698
698
|
}
|
|
699
699
|
return [
|
|
700
|
-
`import * as
|
|
701
|
-
...names.map((n) => `export const ${n} =
|
|
702
|
-
`export default
|
|
700
|
+
`import * as __fulgurjs_facade from ${JSON.stringify(specifier)};`,
|
|
701
|
+
...names.map((n) => `export const ${n} = __fulgurjs_facade[${JSON.stringify(n)}];`),
|
|
702
|
+
`export default __fulgurjs_facade.default ?? __fulgurjs_facade;`,
|
|
703
703
|
""
|
|
704
704
|
].join("\n");
|
|
705
705
|
}
|
|
706
706
|
function genSharedNsFacade(item, loadShareCall, exportNames) {
|
|
707
707
|
const lines = [
|
|
708
|
-
`import { loadShare as
|
|
709
|
-
`const
|
|
710
|
-
`const
|
|
711
|
-
`export default
|
|
708
|
+
`import { loadShare as __fulgurjs_loadShare, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
709
|
+
`const __fulgurjs_m = await ${loadShareCall};`,
|
|
710
|
+
`const __fulgurjs_d = __fulgurjsU(__fulgurjs_m);`,
|
|
711
|
+
`export default __fulgurjs_d;`
|
|
712
712
|
];
|
|
713
713
|
const seen = /* @__PURE__ */ new Set(["default"]);
|
|
714
714
|
for (const name of exportNames) {
|
|
715
715
|
if (seen.has(name) || !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name)) continue;
|
|
716
716
|
seen.add(name);
|
|
717
|
-
lines.push(`export const ${name} =
|
|
717
|
+
lines.push(`export const ${name} = __fulgurjs_d[${JSON.stringify(name)}];`);
|
|
718
718
|
}
|
|
719
719
|
lines.push("");
|
|
720
720
|
return lines.join("\n");
|
|
721
721
|
}
|
|
722
722
|
function genBindingFacade(item, bindings, loadShareCall) {
|
|
723
723
|
const lines = [
|
|
724
|
-
`import { loadShare as
|
|
725
|
-
`const
|
|
724
|
+
`import { loadShare as __fulgurjs_loadShare, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
725
|
+
`const __fulgurjs_m = await ${loadShareCall};`
|
|
726
726
|
];
|
|
727
727
|
const seen = /* @__PURE__ */ new Set();
|
|
728
728
|
for (const bRaw of bindings) {
|
|
@@ -731,16 +731,16 @@ function genBindingFacade(item, bindings, loadShareCall) {
|
|
|
731
731
|
const imported = (asMatch ? asMatch[1] : bRaw).trim();
|
|
732
732
|
if (seen.has(imported)) continue;
|
|
733
733
|
seen.add(imported);
|
|
734
|
-
lines.push(`export const ${imported} =
|
|
734
|
+
lines.push(`export const ${imported} = __fulgurjs_m.${imported};`);
|
|
735
735
|
}
|
|
736
|
-
lines.push(`export default
|
|
736
|
+
lines.push(`export default __fulgurjsU(__fulgurjs_m);`);
|
|
737
737
|
lines.push("");
|
|
738
738
|
return lines.join("\n");
|
|
739
739
|
}
|
|
740
740
|
function genRemoteBindingFacade(remoteSpec, bindings) {
|
|
741
741
|
const lines = [
|
|
742
|
-
`import { loadRemote as
|
|
743
|
-
`const
|
|
742
|
+
`import { loadRemote as __fulgurjs_loadRemote, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
743
|
+
`const __fulgurjs_m = await __fulgurjs_loadRemote(${JSON.stringify(remoteSpec)});`
|
|
744
744
|
];
|
|
745
745
|
const seen = /* @__PURE__ */ new Set();
|
|
746
746
|
for (const bRaw of bindings) {
|
|
@@ -749,9 +749,9 @@ function genRemoteBindingFacade(remoteSpec, bindings) {
|
|
|
749
749
|
const imported = (asMatch ? asMatch[1] : bRaw).trim();
|
|
750
750
|
if (seen.has(imported)) continue;
|
|
751
751
|
seen.add(imported);
|
|
752
|
-
lines.push(`export const ${imported} =
|
|
752
|
+
lines.push(`export const ${imported} = __fulgurjs_m.${imported};`);
|
|
753
753
|
}
|
|
754
|
-
lines.push(`export default
|
|
754
|
+
lines.push(`export default __fulgurjsU(__fulgurjs_m);`);
|
|
755
755
|
lines.push("");
|
|
756
756
|
return lines.join("\n");
|
|
757
757
|
}
|
|
@@ -766,21 +766,21 @@ function providesRecords(options) {
|
|
|
766
766
|
}
|
|
767
767
|
function genInitModule(options, command) {
|
|
768
768
|
const lines = [];
|
|
769
|
-
lines.push(`import { initSharing, registerShare, registerRemotes, registerPlugins } from "virtual:
|
|
769
|
+
lines.push(`import { initSharing, registerShare, registerRemotes, registerPlugins } from "virtual:fulgurjs-runtime";`);
|
|
770
770
|
const provides = providesRecords(options);
|
|
771
771
|
const eagerShared = options.shared.filter((s) => s.eager && s.import !== false);
|
|
772
772
|
eagerShared.forEach((s, i) => {
|
|
773
|
-
lines.push(`import * as
|
|
773
|
+
lines.push(`import * as __fulgurjs_eager_${i} from "virtual:fulgurjs-shared:${s.shareKey}";`);
|
|
774
774
|
});
|
|
775
775
|
const isDevHost = command === "serve" && options.remotes.length > 0;
|
|
776
776
|
const loadedFlag = isDevHost ? "true" : "false";
|
|
777
777
|
lines.push(`initSharing(${JSON.stringify(options.shareScope)});`);
|
|
778
778
|
if (options.runtimePlugins.length > 0) {
|
|
779
779
|
options.runtimePlugins.forEach((p, i) => {
|
|
780
|
-
lines.push(`import * as
|
|
780
|
+
lines.push(`import * as __fulgurjs_rp_${i} from ${JSON.stringify(p)};`);
|
|
781
781
|
});
|
|
782
782
|
lines.push(
|
|
783
|
-
`registerPlugins([${options.runtimePlugins.map((_, i) => `(
|
|
783
|
+
`registerPlugins([${options.runtimePlugins.map((_, i) => `(__fulgurjs_rp_${i}.default ?? __fulgurjs_rp_${i})`).join(", ")}]);`
|
|
784
784
|
);
|
|
785
785
|
}
|
|
786
786
|
if (options.remotes.length > 0) {
|
|
@@ -790,11 +790,11 @@ function genInitModule(options, command) {
|
|
|
790
790
|
const eagerIdx = eagerShared.findIndex((s) => s.shareKey === p.name && s.shareScope === p.shareScope);
|
|
791
791
|
if (p.eager && eagerIdx !== -1) {
|
|
792
792
|
lines.push(
|
|
793
|
-
`registerShare(${JSON.stringify(p.shareScope)}, ${JSON.stringify(p.name)}, ${JSON.stringify(p.version)}, () => Promise.resolve(
|
|
793
|
+
`registerShare(${JSON.stringify(p.shareScope)}, ${JSON.stringify(p.name)}, ${JSON.stringify(p.version)}, () => Promise.resolve(__fulgurjs_eager_${eagerIdx}), { from: ${JSON.stringify(p.from)}, eager: true, loaded: ${loadedFlag} });`
|
|
794
794
|
);
|
|
795
795
|
} else {
|
|
796
796
|
lines.push(
|
|
797
|
-
`registerShare(${JSON.stringify(p.shareScope)}, ${JSON.stringify(p.name)}, ${JSON.stringify(p.version)}, () => import("virtual:
|
|
797
|
+
`registerShare(${JSON.stringify(p.shareScope)}, ${JSON.stringify(p.name)}, ${JSON.stringify(p.version)}, () => import("virtual:fulgurjs-shared:${p.name}"), { from: ${JSON.stringify(p.from)}, eager: false, loaded: ${loadedFlag} });`
|
|
798
798
|
);
|
|
799
799
|
}
|
|
800
800
|
});
|
|
@@ -806,10 +806,10 @@ function manifestUrlFor(r, command) {
|
|
|
806
806
|
if (!entry) return null;
|
|
807
807
|
try {
|
|
808
808
|
const u = new URL(entry);
|
|
809
|
-
if (u.pathname.includes("@
|
|
810
|
-
u.pathname = u.pathname.replace("@
|
|
809
|
+
if (u.pathname.includes("@fulgurjs-entry.js")) {
|
|
810
|
+
u.pathname = u.pathname.replace("@fulgurjs-entry.js", "@fulgurjs-manifest.json");
|
|
811
811
|
} else {
|
|
812
|
-
u.pathname = u.pathname.replace(/[^/]*$/, "") + "
|
|
812
|
+
u.pathname = u.pathname.replace(/[^/]*$/, "") + "fulgurjs-manifest.json";
|
|
813
813
|
}
|
|
814
814
|
return u.href;
|
|
815
815
|
} catch {
|
|
@@ -847,24 +847,24 @@ function genRuntimeProxyModule() {
|
|
|
847
847
|
"parseSpec"
|
|
848
848
|
];
|
|
849
849
|
const lines = [
|
|
850
|
-
`let
|
|
851
|
-
`const
|
|
852
|
-
`
|
|
853
|
-
` return await
|
|
850
|
+
`let __fulgurjs_mod_p;`,
|
|
851
|
+
`const __fulgurjs_rt = async () => {`,
|
|
852
|
+
` __fulgurjs_mod_p ??= import('virtual:fulgurjs-runtime');`,
|
|
853
|
+
` return await __fulgurjs_mod_p;`,
|
|
854
854
|
`};`,
|
|
855
|
-
...promiseApis.map((m) => `export const ${m} = (...a) =>
|
|
856
|
-
`export const getRuntime = () => (globalThis).
|
|
857
|
-
`export const
|
|
858
|
-
` (globalThis).
|
|
859
|
-
`export const
|
|
855
|
+
...promiseApis.map((m) => `export const ${m} = (...a) => __fulgurjs_rt().then((m2) => m2.${m}(...a));`),
|
|
856
|
+
`export const getRuntime = () => (globalThis).__FULGURJS_RUNTIME__;`,
|
|
857
|
+
`export const getFulgurjsAppConfig = () =>`,
|
|
858
|
+
` (globalThis).__FULGURJS_RUNTIME__?.getFulgurjsAppConfig?.() ?? (globalThis).__FULGURJS_APP_CONFIG__ ?? {};`,
|
|
859
|
+
`export const provideFulgurjsAppConfig = (c) => {`,
|
|
860
860
|
` const g = (globalThis);`,
|
|
861
|
-
` g.
|
|
862
|
-
` g.
|
|
861
|
+
` g.__FULGURJS_APP_CONFIG__ = { ...(g.__FULGURJS_APP_CONFIG__ ?? {}), ...c };`,
|
|
862
|
+
` g.__FULGURJS_RUNTIME__?.provideFulgurjsAppConfig?.(c);`,
|
|
863
863
|
`};`,
|
|
864
864
|
`export const unwrapDefault = (ns) =>`,
|
|
865
865
|
` ns && typeof ns === 'object' && 'default' in ns ? (ns.default !== undefined ? ns.default : ns) : ns;`,
|
|
866
|
-
`export const version = (globalThis).
|
|
867
|
-
`export default { get runtime() { return (globalThis).
|
|
866
|
+
`export const version = (globalThis).__FULGURJS_RUNTIME__?.version;`,
|
|
867
|
+
`export default { get runtime() { return (globalThis).__FULGURJS_RUNTIME__; } };`,
|
|
868
868
|
``
|
|
869
869
|
];
|
|
870
870
|
return lines.join("\n");
|
|
@@ -873,11 +873,11 @@ function genDevRemoteEntry(options, base) {
|
|
|
873
873
|
const b = base.endsWith("/") ? base : `${base}/`;
|
|
874
874
|
const remoteLines = registerRemotesLines(options, "serve");
|
|
875
875
|
return `import ${JSON.stringify(`${b}@vite/client`)};
|
|
876
|
-
import { name as
|
|
877
|
-
${remoteLines.length > 0 ? `import { registerRemotes } from ${JSON.stringify(`${b}@id/virtual:
|
|
876
|
+
import { name as _fulgurjs_name, exposes, provides } from ${JSON.stringify(`${b}@id/__x00__virtual:fulgurjs-provides`)};
|
|
877
|
+
${remoteLines.length > 0 ? `import { registerRemotes } from ${JSON.stringify(`${b}@id/virtual:fulgurjs-runtime`)};
|
|
878
878
|
${remoteLines.join("\n")}` : ""}
|
|
879
879
|
|
|
880
|
-
export const name =
|
|
880
|
+
export const name = _fulgurjs_name;
|
|
881
881
|
|
|
882
882
|
export async function init(shareScopeMap) {
|
|
883
883
|
for (const p of provides) {
|
|
@@ -908,7 +908,7 @@ function genDevProvides(options) {
|
|
|
908
908
|
);
|
|
909
909
|
}
|
|
910
910
|
const provides = providesRecords(options).map(
|
|
911
|
-
(p) => ` { shareScope: ${JSON.stringify(p.shareScope)}, name: ${JSON.stringify(p.name)}, version: ${JSON.stringify(p.version)}, eager: ${p.eager}, get: () => import("virtual:
|
|
911
|
+
(p) => ` { shareScope: ${JSON.stringify(p.shareScope)}, name: ${JSON.stringify(p.name)}, version: ${JSON.stringify(p.version)}, eager: ${p.eager}, get: () => import("virtual:fulgurjs-shared:${p.name}") },`
|
|
912
912
|
);
|
|
913
913
|
return [
|
|
914
914
|
`export const name = ${JSON.stringify(options.name)};`,
|
|
@@ -929,11 +929,11 @@ function genBuildRemoteEntry(options, exposeAbsPaths) {
|
|
|
929
929
|
exposes.push(` ${JSON.stringify(e.name)}: () => import(${JSON.stringify(abs)}),`);
|
|
930
930
|
}
|
|
931
931
|
const provides = providesRecords(options).map(
|
|
932
|
-
(p) => ` { shareScope: ${JSON.stringify(p.shareScope)}, name: ${JSON.stringify(p.name)}, version: ${JSON.stringify(p.version)}, eager: ${p.eager}, get: () => import("virtual:
|
|
932
|
+
(p) => ` { shareScope: ${JSON.stringify(p.shareScope)}, name: ${JSON.stringify(p.name)}, version: ${JSON.stringify(p.version)}, eager: ${p.eager}, get: () => import("virtual:fulgurjs-shared:${p.name}") },`
|
|
933
933
|
);
|
|
934
934
|
const remoteLines = registerRemotesLines(options, "build");
|
|
935
935
|
return [
|
|
936
|
-
...remoteLines.length > 0 ? [`import { registerRemotes } from "virtual:
|
|
936
|
+
...remoteLines.length > 0 ? [`import { registerRemotes } from "virtual:fulgurjs-runtime";`, ...remoteLines] : [],
|
|
937
937
|
`const exposes = {`,
|
|
938
938
|
...exposes,
|
|
939
939
|
`};`,
|
|
@@ -968,16 +968,16 @@ function genDevManifest(options, base) {
|
|
|
968
968
|
return {
|
|
969
969
|
id: options.name,
|
|
970
970
|
name: options.name,
|
|
971
|
-
version: options.pkgDependencies?.["
|
|
971
|
+
version: options.pkgDependencies?.["fulgurjs"] ?? "0.0.0",
|
|
972
972
|
devServer: true,
|
|
973
973
|
base: b,
|
|
974
|
-
entry: `${b}@
|
|
974
|
+
entry: `${b}@fulgurjs-entry.js`,
|
|
975
975
|
/** 本地联调时供宿主端 dts 类型直连(见 dts.ts);远程不在本机时宿主回退 any 桩 */
|
|
976
976
|
fsRoot: options.root,
|
|
977
977
|
exposes: options.exposes.map((e) => ({
|
|
978
978
|
name: e.name,
|
|
979
979
|
src: e.import,
|
|
980
|
-
file: `${b}@
|
|
980
|
+
file: `${b}@fulgurjs-src/${e.import.replace(/^\.?\//, "")}`
|
|
981
981
|
})),
|
|
982
982
|
shared: options.shared.map((s) => ({
|
|
983
983
|
name: s.shareKey,
|
|
@@ -1004,7 +1004,7 @@ function genProdManifest(options, exposeFiles, entryFile) {
|
|
|
1004
1004
|
eager: s.eager
|
|
1005
1005
|
})),
|
|
1006
1006
|
buildInfo: {
|
|
1007
|
-
builtBy: "
|
|
1007
|
+
builtBy: "fulgurjs-federation",
|
|
1008
1008
|
timestamp: Date.now()
|
|
1009
1009
|
}
|
|
1010
1010
|
};
|
|
@@ -1017,7 +1017,7 @@ async function fetchManifest(devEntry, attempts = 30, delayMs = 2e3) {
|
|
|
1017
1017
|
let manifestUrl;
|
|
1018
1018
|
try {
|
|
1019
1019
|
const u = new URL(devEntry);
|
|
1020
|
-
u.pathname = u.pathname.replace("@
|
|
1020
|
+
u.pathname = u.pathname.replace("@fulgurjs-entry.js", "@fulgurjs-manifest.json");
|
|
1021
1021
|
manifestUrl = u;
|
|
1022
1022
|
} catch {
|
|
1023
1023
|
return null;
|
|
@@ -1043,7 +1043,7 @@ function sourceHasDefaultExport(file) {
|
|
|
1043
1043
|
async function generateDevTypes(options, _server) {
|
|
1044
1044
|
const dtsOpt = options.dts === void 0 ? true : options.dts;
|
|
1045
1045
|
if (dtsOpt === false) return;
|
|
1046
|
-
const defaultDir = import_node_fs2.default.existsSync(import_node_path3.default.join(options.root, "src")) ? "src/
|
|
1046
|
+
const defaultDir = import_node_fs2.default.existsSync(import_node_path3.default.join(options.root, "src")) ? "src/fulgurjs-types" : "fulgurjs-types";
|
|
1047
1047
|
const dir = typeof dtsOpt === "object" ? dtsOpt.dir ?? defaultDir : defaultDir;
|
|
1048
1048
|
const outDir = import_node_path3.default.join(options.root, dir);
|
|
1049
1049
|
import_node_fs2.default.mkdirSync(outDir, { recursive: true });
|
|
@@ -1051,18 +1051,18 @@ async function generateDevTypes(options, _server) {
|
|
|
1051
1051
|
if (!remote.devEntry || remote.promise) continue;
|
|
1052
1052
|
const manifest = await fetchManifest(remote.devEntry);
|
|
1053
1053
|
if (!manifest || !manifest.exposes) {
|
|
1054
|
-
console.warn(`[
|
|
1054
|
+
console.warn(`[fulgurjs] dts: remote "${remote.key}" dev manifest unavailable; type mapping skipped.`);
|
|
1055
1055
|
continue;
|
|
1056
1056
|
}
|
|
1057
1057
|
const remoteRoot = manifest.fsRoot;
|
|
1058
1058
|
if (!remoteRoot || !import_node_fs2.default.existsSync(remoteRoot)) {
|
|
1059
1059
|
console.warn(
|
|
1060
|
-
`[
|
|
1060
|
+
`[fulgurjs] dts: remote "${remote.key}" is not on this machine; type mapping skipped (module types fall back to any).`
|
|
1061
1061
|
);
|
|
1062
1062
|
continue;
|
|
1063
1063
|
}
|
|
1064
1064
|
const lines = [
|
|
1065
|
-
`// \u81EA\u52A8\u751F\u6210\
|
|
1065
|
+
`// \u81EA\u52A8\u751F\u6210\uFF1Afulgurjs-federation dev \u7C7B\u578B\u76F4\u8FDE\uFF08remote: ${remote.name}\uFF09`,
|
|
1066
1066
|
`// \u91CD\u65B0\u751F\u6210\uFF1A\u91CD\u542F host dev server`
|
|
1067
1067
|
];
|
|
1068
1068
|
for (const expose of manifest.exposes ?? []) {
|
|
@@ -1089,16 +1089,16 @@ async function generateDevTypes(options, _server) {
|
|
|
1089
1089
|
import_node_fs2.default.writeFileSync(import_node_path3.default.join(outDir, `${remote.key}.d.ts`), `${lines.join("\n")}
|
|
1090
1090
|
`);
|
|
1091
1091
|
console.log(
|
|
1092
|
-
`[
|
|
1092
|
+
`[fulgurjs] dts: generated ${dir}/${remote.key}.d.ts (${manifest.exposes?.length ?? 0} exposes). \u786E\u4FDD tsconfig include \u5305\u542B "${dir}" \u4EE5\u83B7\u5F97\u6E90\u7801\u7EA7\u7C7B\u578B\u8865\u5168\u3002`
|
|
1093
1093
|
);
|
|
1094
1094
|
}
|
|
1095
1095
|
}
|
|
1096
1096
|
|
|
1097
1097
|
// src/diagnostics.ts
|
|
1098
|
-
function
|
|
1098
|
+
function formatFulgurjsDiagnostic(input) {
|
|
1099
1099
|
const ctx = input.details ? `
|
|
1100
1100
|
\u4E0A\u4E0B\u6587\uFF1A${JSON.stringify(input.details)}` : "";
|
|
1101
|
-
return `[
|
|
1101
|
+
return `[fulgurjs:${input.code}] ${input.symptom}
|
|
1102
1102
|
\u6839\u56E0\uFF1A${input.cause}
|
|
1103
1103
|
\u4FEE\u6CD5\uFF1A${input.fix}` + ctx;
|
|
1104
1104
|
}
|
|
@@ -1122,7 +1122,7 @@ async function isPortReachable(host, port, timeoutMs = 800) {
|
|
|
1122
1122
|
function manifestUrlOf(devEntry) {
|
|
1123
1123
|
try {
|
|
1124
1124
|
const u = new URL(devEntry);
|
|
1125
|
-
u.pathname = u.pathname.replace("@
|
|
1125
|
+
u.pathname = u.pathname.replace("@fulgurjs-entry.js", "@fulgurjs-manifest.json");
|
|
1126
1126
|
return u;
|
|
1127
1127
|
} catch {
|
|
1128
1128
|
return null;
|
|
@@ -1148,7 +1148,7 @@ async function probeRemotesAndBuildSchema(options) {
|
|
|
1148
1148
|
schema[remote.key] = { exposes, exists: true };
|
|
1149
1149
|
if (exposes.length === 0) {
|
|
1150
1150
|
console.warn(
|
|
1151
|
-
|
|
1151
|
+
formatFulgurjsDiagnostic({
|
|
1152
1152
|
code: "DEV-002",
|
|
1153
1153
|
symptom: `remote "${remote.key}" \u7684 dev manifest \u53EF\u8FBE\u4F46 exposes \u4E3A\u7A7A\uFF08${u.href}\uFF09`,
|
|
1154
1154
|
cause: "remote \u4FA7 federation({ exposes }) \u4E3A\u7A7A\uFF0C\u6216\u5176\u63D2\u4EF6\u7248\u672C\u8FC7\u65E7\u5BFC\u81F4 manifest \u7F3A\u5B57\u6BB5",
|
|
@@ -1160,7 +1160,7 @@ async function probeRemotesAndBuildSchema(options) {
|
|
|
1160
1160
|
const remoteVersion = manifest?.buildInfo?.version;
|
|
1161
1161
|
if (remoteVersion && remoteVersion !== options.pluginVersion) {
|
|
1162
1162
|
console.warn(
|
|
1163
|
-
|
|
1163
|
+
formatFulgurjsDiagnostic({
|
|
1164
1164
|
code: "DEV-006",
|
|
1165
1165
|
symptom: `\u5BBF\u4E3B\u4E0E remote "${remote.key}" \u7684 @fulgurjs/federation \u7248\u672C\u4E0D\u4E00\u81F4`,
|
|
1166
1166
|
cause: `\u5BBF\u4E3B ${options.pluginVersion} vs \u8FDC\u7A0B ${remoteVersion}\uFF08pnpm tarball \u65AD\u94FE/\u6F0F\u5347\u7EA7\u5E38\u89C1\uFF09`,
|
|
@@ -1174,7 +1174,7 @@ async function probeRemotesAndBuildSchema(options) {
|
|
|
1174
1174
|
const port = u.port ? Number(u.port) : u.protocol === "https:" ? 443 : 80;
|
|
1175
1175
|
const portOpen = await isPortReachable(u.hostname, port);
|
|
1176
1176
|
console.warn(
|
|
1177
|
-
|
|
1177
|
+
formatFulgurjsDiagnostic({
|
|
1178
1178
|
code: "DEV-001",
|
|
1179
1179
|
symptom: `remote "${remote.key}" \u7684 dev manifest \u4E0D\u53EF\u8FBE\uFF08${u.href}\uFF09\u2014\u2014\u8BE5 remote \u7684\u8DEF\u7531\u5B58\u5728\u6027\u6821\u9A8C\u5C06\u8DF3\u8FC7`,
|
|
1180
1180
|
cause: portOpen ? "\u7AEF\u53E3\u6709\u8FDB\u7A0B\u76D1\u542C\u4F46 manifest \u7AEF\u70B9\u5F02\u5E38\uFF1Aremote dev server \u53EF\u80FD\u4EE5\u975E\u8054\u90A6\u914D\u7F6E\u542F\u52A8\uFF0C\u6216 base/\u8DEF\u5F84\u4E0E remotes[].dev \u4E0D\u4E00\u81F4" : "\u7AEF\u53E3\u65E0\u8FDB\u7A0B\u76D1\u542C\uFF1Aremote dev server \u672A\u542F\u52A8\uFF0C\u6216 remotes[].dev \u7AEF\u53E3\u5199\u9519\uFF08server.origin \u9519\u4F4D\u540C\u6B3E\uFF09",
|
|
@@ -1187,7 +1187,7 @@ async function probeRemotesAndBuildSchema(options) {
|
|
|
1187
1187
|
return schema;
|
|
1188
1188
|
}
|
|
1189
1189
|
function genEmptyRemoteSchemaModule() {
|
|
1190
|
-
console.info("[
|
|
1190
|
+
console.info("[fulgurjs] build \u671F\u8DF3\u8FC7\u8DEF\u7531 spec \u5B58\u5728\u6027\u6821\u9A8C\uFF08\u8FDC\u7A0B manifest \u4E0D\u5728\u6784\u5EFA\u673A\u672C\u5730\uFF1Bdev \u4E0B\u81EA\u52A8\u542F\u7528\uFF09");
|
|
1191
1191
|
return "export default {}";
|
|
1192
1192
|
}
|
|
1193
1193
|
|
|
@@ -1196,27 +1196,27 @@ var import_node_fs3 = __toESM(require("fs"), 1);
|
|
|
1196
1196
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
1197
1197
|
function syncViteCacheMarker(root, pluginVersion, log) {
|
|
1198
1198
|
const viteDir = import_node_path4.default.join(root, "node_modules", ".vite");
|
|
1199
|
-
const marker = import_node_path4.default.join(viteDir, "
|
|
1199
|
+
const marker = import_node_path4.default.join(viteDir, "fulgurjs-version.txt");
|
|
1200
1200
|
try {
|
|
1201
1201
|
if (import_node_fs3.default.existsSync(viteDir)) {
|
|
1202
1202
|
const prev = import_node_fs3.default.existsSync(marker) ? import_node_fs3.default.readFileSync(marker, "utf8").trim() : "";
|
|
1203
1203
|
if (prev === pluginVersion) return;
|
|
1204
1204
|
import_node_fs3.default.rmSync(viteDir, { recursive: true, force: true });
|
|
1205
1205
|
log(
|
|
1206
|
-
`[
|
|
1206
|
+
`[fulgurjs] \u63D2\u4EF6\u7248\u672C\u53D8\u5316\uFF08${prev || "\u65E0\u8BB0\u5F55"} \u2192 ${pluginVersion}\uFF09\uFF0C\u5DF2\u81EA\u52A8\u6E05\u9664 ${import_node_path4.default.relative(root, viteDir)} \u9884\u6784\u5EFA\u7F13\u5B58\uFF08\u907F\u514D\u65E7\u95E8\u9762\u7B7E\u540D 404 / DEV-009\uFF09\u3002\u672C\u6B21\u542F\u52A8\u5C06\u91CD\u65B0\u9884\u6784\u5EFA\uFF0C\u9996\u8F6E 30~60s \u5C5E\u6682\u6001\uFF08DEV-010\uFF09\u3002`
|
|
1207
1207
|
);
|
|
1208
1208
|
}
|
|
1209
1209
|
import_node_fs3.default.mkdirSync(viteDir, { recursive: true });
|
|
1210
1210
|
import_node_fs3.default.writeFileSync(marker, pluginVersion);
|
|
1211
1211
|
} catch (e) {
|
|
1212
1212
|
log(
|
|
1213
|
-
`[
|
|
1213
|
+
`[fulgurjs] \u81EA\u52A8\u6E05\u7406 .vite \u7F13\u5B58\u5931\u8D25\uFF08\u4E0D\u5F71\u54CD\u542F\u52A8\uFF1B\u5982\u9047\u8054\u90A6\u6A21\u5757 404 \u8BF7\u624B\u5DE5\u6267\u884C rm -rf ${viteDir}\uFF09\uFF1A${String(e.message ?? e)}`
|
|
1214
1214
|
);
|
|
1215
1215
|
}
|
|
1216
1216
|
}
|
|
1217
1217
|
|
|
1218
1218
|
// src/runtime-code.gen.ts
|
|
1219
|
-
var runtime_code_gen_default = 'var Q=/^v?(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?(?:-((?:[0-9A-Za-z-]+)(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z.-]+)?$/;function k(t){let n=Q.exec(String(t).trim());return n?{major:Number(n[1]),minor:Number(n[2]??0),patch:Number(n[3]??0),pre:n[4]?n[4].split("."):[]}:null}function ee(t,n){if(t.length===0&&n.length===0)return 0;if(t.length===0)return 1;if(n.length===0)return-1;let o=Math.max(t.length,n.length);for(let r=0;r<o;r++){let l=t[r],m=n[r];if(l===void 0)return-1;if(m===void 0)return 1;let y=/^\\d+$/.test(l),w=/^\\d+$/.test(m);if(y&&w){let M=Number(l)-Number(m);if(M!==0)return M}else{if(y!==w)return y?-1:1;if(l!==m)return l<m?-1:1}}return 0}function T(t,n){let o=k(t),r=k(n);return!o||!r?t<n?-1:t>n?1:0:o.major!==r.major?o.major-r.major:o.minor!==r.minor?o.minor-r.minor:o.patch!==r.patch?o.patch-r.patch:ee(o.pre,r.pre)}var re=/^[a-z]+[+:-]/i;function N(t,n){if(n===!1||n==null||n==="")return!0;let o=String(n).trim();return!o||o==="*"||o==="latest"||re.test(o)?!0:o.split("||").some(r=>te(t,r.trim()))}function te(t,n){if(!n||n==="*")return!k(t)?.pre.length;let o=n.split(/\\s+-\\s+/);if(o.length===2){let m=o[0].trim(),y=o[1].trim();return!(!N(t,`>=${m}`)||!N(t,`<=${y}`))}let r=k(t);if(!r)return!1;let l=ne(n);if(l===null)return!0;for(let m of l)if(!ue(r,t,m))return!1;return!(r.pre.length>0&&!l.some(m=>m.ver.pre.length>0)&&!l.some(y=>y.ver.major===r.major&&y.ver.minor===r.minor&&y.ver.patch===r.patch))}function ne(t){let n=[],o=t.trim().split(/\\s+/).filter(Boolean);if(o.length===0)return null;for(let r of o){let l=/^(>=|<=|>|<|=|\\^|~)?(.*)$/.exec(r);if(!l)return null;let m=l[1],y=l[2],w=oe(m,y);if(w===null)return null;n.push(...w)}return n}function oe(t,n){let o=ae(n);if(!o)return null;let{ver:r,partial:l}=o;switch(t){case"^":{let m=ie(r);return m?[{op:">=",ver:r},{op:"<",ver:m}]:null}case"~":{let m=l>=2?{major:r.major,minor:r.minor+1,patch:0,pre:[]}:{major:r.major+1,minor:0,patch:0,pre:[]};return[{op:">=",ver:r},{op:"<",ver:m}]}case">=":return[{op:">=",ver:r}];case">":return l===1?[{op:">=",ver:{major:r.major+1,minor:0,patch:0,pre:[]}}]:l===2?[{op:">=",ver:{major:r.major,minor:r.minor+1,patch:0,pre:[]}}]:[{op:">",ver:r}];case"<":return l===1?[{op:"<",ver:{major:r.major,minor:0,patch:0,pre:[]}}]:l===2?[{op:"<",ver:{major:r.major,minor:r.minor,patch:0,pre:[]}}]:[{op:"<",ver:r}];case"<=":return[{op:"<=",ver:r}];case"=":case void 0:return l===1?[{op:">=",ver:r},{op:"<",ver:{major:r.major+1,minor:0,patch:0,pre:[]}}]:l===2?[{op:">=",ver:r},{op:"<",ver:{major:r.major,minor:r.minor+1,patch:0,pre:[]}}]:[{op:"=",ver:r}];default:return null}}function ie(t){return t.major>0?{major:t.major+1,minor:0,patch:0,pre:[]}:t.minor>0?{major:0,minor:t.minor+1,patch:0,pre:[]}:{major:0,minor:0,patch:t.patch+1,pre:[]}}function ae(t){let n=t.replace(/^v/,"").trim();if(!n||n==="*"||n==="x"||n==="X")return{ver:{major:0,minor:0,patch:0,pre:[]},partial:0};let o=n.split("."),r=[],l=0;for(let w of o.slice(0,3))if(/^\\d+$/.test(w))r.push(Number(w)),l++;else{if(w==="x"||w==="X"||w==="*")break;break}let m=n.split("-"),y=m.length>1?m.slice(1).join("-").split("+")[0].split("."):[];return l===0&&y.length===0?{ver:{major:0,minor:0,patch:0,pre:[]},partial:0}:{ver:{major:r[0]??0,minor:r[1]??0,patch:r[2]??0,pre:y},partial:l}}function se(t,n){switch(n){case">=":return t>=0;case">":return t>0;case"<":return t<0;case"<=":return t<=0;case"=":return t===0}}function ue(t,n,o){let r=`${t.major}.${t.minor}.${t.patch}`+(t.pre.length?`-${t.pre.join(".")}`:"");if(o.upper)return!(!(T(r,`${o.ver.major}.${o.ver.minor}.${o.ver.patch}`+(o.ver.pre.length?`-${o.ver.pre.join(".")}`:""))>=0)||!(T(r,`${o.upper.major}.${o.upper.minor}.${o.upper.patch}`)<0));let l=T(r,`${o.ver.major}.${o.ver.minor}.${o.ver.patch}`+(o.ver.pre.length?`-${o.ver.pre.join(".")}`:"")),m=se(l,o.op);return o.ver.pre.length>0&&t.pre.length===0&&(o.op===">"||o.op==="<")?!1:m}var g=class extends Error{code;details;constructor(n,o,r){super(`[fulgur:${n}] ${o}`),this.name="FulgurError",this.code=n,this.details=r}},R={REMOTE_LOAD_FAILED:"MFU-001",REMOTE_NAME_MISMATCH:"MFU-002",SHARE_STRICT_VERSION:"MFU-003",SHARE_NOT_AVAILABLE:"MFU-004",CONTAINER_REINIT_CONFLICT:"MFU-005",MODULE_NOT_EXPOSED:"MFU-006",PRELOAD_FAILED:"MFU-007",REMOTE_UNKNOWN:"MFU-008",EMPTY_EXPORTS:"MFU-009",SINGLETON_SKEW:"MFU-010"};var F="0.4.2";var U=15e3,P=2,ce=5,le=3e4;function fe(){let t={},n=new Map,o=[],r=new Map,l=new WeakMap,m={};function y(e){m={...m,...e},typeof globalThis<"u"&&(globalThis.__FULGUR_APP_CONFIG__=m)}function w(){return m}let M={},D=()=>{for(let e of o)try{e.init?.(M)}catch(i){console.warn("[fulgur] runtimePlugin init failed:",e.name,i)}},I=e=>t[e]??={};function $(e){try{M.onRemoteError?.(e)}catch{}typeof window<"u"&&window.dispatchEvent(new CustomEvent("fulgur:error",{detail:e}))}function H(e="default"){return I(e),t}function K(e,i,a,u,E={}){let s=I(e||"default"),c=s[i]??={};c[a]||(c[a]={version:a,get:u,from:E.from??"unknown",eager:!!E.eager,loaded:!!E.loaded})}function x(e){for(let i of e){let a=n.get(i.name);n.set(i.name,{timeout:U,retries:P,...a,...i,state:a?.state??"idle",breakerState:a?.breakerState??{fails:0,openUntil:0},debug:a?.debug??{entry:i.entry,status:"idle"}})}}function q(e){x([e])}function G(e){o.push(...e),D()}async function z(e,i={}){let a=i.shareScope||"default",u=i.shareKey||e,s=I(a)[u]||{},c=Object.keys(s),d=i.requiredVersion,f=c.filter(p=>d===void 0||d===!1||N(p,d)),b;if(i.singleton&&c.length>0){let p=c.filter(h=>s[h].loaded);if(b=[...p.length?p:c].sort(T).pop(),c.length>1||!f.includes(b)){let h=s[b],O=`singleton skew "${u}": req "${d??"any"}" use ${b} from ${h.from}`;if(i.strictVersion){let v=new g(R.SHARE_STRICT_VERSION,O,{shareKey:u,requiredVersion:d});throw $({remote:h.from,error:v}),v}console.warn(`[fulgur:MFU-010] ${O}`)}}else if(b=[...f].sort(T).pop(),!b){if(i.strictVersion){let h=new g(R.SHARE_STRICT_VERSION,`no satisfying version for "${u}" (required "${d}") in share scope "${a}"`);throw $({remote:u,error:h}),h}if(i.fallback)return i.fallback();let p=new g(R.SHARE_NOT_AVAILABLE,`shared "${u}" (${d??"any"}) unavailable in scope "${a}" (no local fallback)`,{shareKey:u,requiredVersion:d});throw $({remote:u,error:p}),p}let _=s[b];if(M.resolveShare){let p=await M.resolveShare({shareKey:u,shareScope:a,requiredVersion:d,picked:_,available:Object.values(s)});p&&(_=p)}return _.loaded=!0,_.get()}function W(e,i,a){return new Promise((u,E)=>{let s=setTimeout(()=>E(new Error(`timeout after ${i}ms: ${a}`)),i);e.then(c=>{clearTimeout(s),u(c)},c=>{clearTimeout(s),E(c)})})}let B=e=>new Promise(i=>setTimeout(i,e));function j(e,i){if(!e||typeof e.get!="function")throw new Error(`remoteEntry of "${i.name}" does not export a container interface (get/init)`);if(e.name&&i.name&&e.name!==i.name){let a=`remoteEntry self-reported name "${e.name}" mismatches configured name "${i.name}"`;if(i.promise)console.warn(`[fulgur] ${a} (promise-based remote, continuing)`);else throw Object.assign(new Error(a),{code:R.REMOTE_NAME_MISMATCH})}}async function L(e,i){return W(import(e),i.timeout??U,`load remoteEntry ${e}`)}async function C(e,i){let a=e.shareScope||"default";if(e.container){let s=l.get(e.container);if(s&&s!==a)throw new g(R.CONTAINER_REINIT_CONFLICT,`container "${e.name}" already initialized with share scope "${s}", cannot re-init with "${a}"`);return e.container}if(e.containerPromise)return e.containerPromise;let u=e.breakerState;if(u.openUntil>Date.now()){let s=new g(R.REMOTE_LOAD_FAILED,`circuit breaker open for remote "${e.name}" until ${new Date(u.openUntil).toISOString()}`,{remote:e.name});throw $({remote:e.name,error:s}),s}e.state="loading",e.debug.status="loading";let E=(async()=>{let s=[];if(e.promise)s.push(async()=>{let p=await e.promise(),h=typeof p=="string"?await L(p,e):p;return j(h,e),h});else for(let p of[e.entry,...e.fallback??[]])s.push(async()=>{let h=await L(p,e);return j(h,e),h});let c,d,f=!1,b=i?.retries??e.retries??P;for(let p of s){for(let h=0;h<=b;h++){let O=performance.now();try{c=await p(),e.lastLoadMs=Math.round(performance.now()-O),e.debug.lastLoadMs=e.lastLoadMs,f=!0;break}catch(v){if(d=v,v?.code)throw v;h<b&&await B(200*2**h)}}if(f)break}if(!f||!c){let p=[];throw/^https?:\\/\\//.test(e.entry)&&typeof location<"u"?(p.push(`1. is the remote dev server running? try opening ${e.entry} in the browser \\u2014 it must return JS, not HTML/an error`),p.push("2. is the URL correct in federation({ remotes })? dev and prod entries can differ"),p.push("3. CORS: the remote dev server must allow cross-origin requests (fulgur-federation enables server.cors automatically; a custom server config may have disabled it)")):(p.push(`1. is the remote deployed and reachable? try opening ${e.entry} in the browser \\u2014 it must return JS`),p.push("2. NGINX/CDN routing: the entry path must serve the remoteEntry JS file (check try_files / fallback rules)")),new g(R.REMOTE_LOAD_FAILED,`failed to load remote "${e.name}" from ${e.entry}: ${String(d?.message??d)}\n`+p.join(`\n`),{remote:e.name})}j(c,e);let _=l.get(c);if(_&&_!==a)throw new g(R.CONTAINER_REINIT_CONFLICT,`container "${e.name}" already initialized with share scope "${_}", cannot re-init with "${a}"`);return typeof c.init=="function"&&await c.init(t),l.set(c,a),e.container=c,e.state="loaded",e.debug.status="loaded",u.fails=0,c})();e.containerPromise=E;try{return await E}catch(s){if(e.containerPromise=void 0,e.state="failed",e.debug.status="failed",e.debug.error=String(s?.message??s),u.fails+=1,u.fails>=ce&&(u.openUntil=Date.now()+le,u.fails=0),s instanceof g)throw $({remote:e.name,error:s}),s;if(s?.code)throw $({remote:e.name,error:s}),s;let c=new g(R.REMOTE_LOAD_FAILED,String(s?.message??s),{remote:e.name});throw $({remote:e.name,error:c}),c}}function A(e){let i=e.indexOf("/");return i===-1?{remote:e,module:""}:{remote:e.slice(0,i),module:X(e.slice(i+1))}}function X(e){return e?e.startsWith(".")?e:`./${e}`:""}async function J(e,i){let{remote:a,module:u}=A(e);M.beforeLoadRemote?.({remote:a,module:u});let E=n.get(a);if(!E)throw new g(R.REMOTE_UNKNOWN,`unknown remote "${a}". Register it via federation({ remotes }) or registerRemote().`,{remote:a});let s;try{s=await C(E,{retries:i?.retries})}catch(f){if(i?.fallbackModule)return console.error(`[fulgur] loadRemote("${e}") failed; returning fallbackModule (\\u663E\\u5F0F\\u964D\\u7EA7\\uFF0C\\u9519\\u8BEF\\u5DF2\\u900F\\u51FA)`,f),$({remote:a,error:f}),await i.fallbackModule();throw f}if(!u)return s;let c=`${a}@${E.shareScope||"default"}#${u}`;r.has(c)||r.set(c,s.get(u).catch(f=>{throw r.delete(c),f instanceof g||f?.code?f:new g(R.REMOTE_LOAD_FAILED,`failed to load module "${u}" from remote "${a}": ${String(f?.message??f)}`,{remote:a,module:u})}));let d;try{d=await r.get(c)}catch(f){if(i?.fallbackModule)return console.error(`[fulgur] loadRemote("${e}") failed; returning fallbackModule (\\u663E\\u5F0F\\u964D\\u7EA7\\uFF0C\\u9519\\u8BEF\\u5DF2\\u900F\\u51FA)`,f),$({remote:a,error:f}),await i.fallbackModule();throw f}if(M.afterLoadRemote?.({remote:a,module:u,module_ns:d}),d&&typeof d=="object"&&Object.keys(d).length===0){let f=new g(R.EMPTY_EXPORTS,`no exports: ${u} @ ${a}`,{remote:a,module:u});$({remote:a,error:f}),console.error(`[fulgur:MFU-009] ${f.message}`)}return d}function Y(e){let i=n.get(e);if(!i)throw new g(R.REMOTE_UNKNOWN,`unknown remote "${e}"`,{remote:e});return C(i)}async function Z(e,i={}){let{remote:a}=A(e),u=n.get(a);if(!u)throw new g(R.REMOTE_UNKNOWN,`unknown remote "${a}"`,{remote:a});let E=i.mode??"preload",s=(c,d)=>{if(typeof document>"u"||document.querySelector(`link[href="${c}"]`))return;let f=document.createElement("link");f.rel=d==="style"?"stylesheet":"modulepreload",f.href=c,E==="prefetch"&&(f.fetchPriority="low"),document.head.appendChild(f)};try{if(u.manifestUrl){let c=await fetch(u.manifestUrl,{cache:"no-cache"});if(c.ok){let d=await c.json();s(u.entry,"modulepreload");let f=d.exposes??{};for(let b of Object.keys(f)){let _=f[b];_?.file&&s(new URL(_.file,u.entry).href,"modulepreload");for(let p of _?.css??[])s(new URL(p,u.entry).href,"style")}return}}s(u.entry,"modulepreload")}catch(c){$({remote:a,error:new g(R.PRELOAD_FAILED,String(c?.message??c),{remote:a})})}}return typeof window>"u"||(window.__FULGUR_SCOPE__=t,window.__FULGUR_INFO__={get remotes(){let e={};for(let[i,a]of n)e[i]={...a.debug,entry:a.entry};return e},errors:[]}),{shareScopeMap:t,initSharing:H,registerShare:K,registerRemotes:x,registerRemote:q,registerPlugins:G,loadShare:z,loadRemote:J,getContainer:Y,preloadRemote:Z,parseSpec:A,provideFulgurAppConfig:y,getFulgurAppConfig:w}}var V=globalThis,S=V.__FULGUR_RUNTIME__??fe();V.__FULGUR_RUNTIME__=S;try{Object.freeze(S)}catch{}var Re=F;function Se(){return S}var we=S.initSharing,be=S.registerShare,_e=S.registerRemotes,$e=S.registerRemote,Me=S.registerPlugins,ve=S.loadShare,Te=S.loadRemote,Oe=S.getContainer,ke=S.preloadRemote,Ne=S.shareScopeMap,Ie=S.provideFulgurAppConfig,je=S.getFulgurAppConfig;function Ae(t){if(t&&typeof t=="object"&&"default"in t){let n=t.default;return n!==void 0?n:t}return t}var xe=S;export{xe as default,Oe as getContainer,je as getFulgurAppConfig,Se as getRuntime,we as initSharing,Te as loadRemote,ve as loadShare,ke as preloadRemote,Ie as provideFulgurAppConfig,Me as registerPlugins,$e as registerRemote,_e as registerRemotes,be as registerShare,S as runtime,Ne as shareScopeMap,Ae as unwrapDefault,Re as version};\n';
|
|
1219
|
+
var runtime_code_gen_default = 'var Q=/^v?(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?(?:-((?:[0-9A-Za-z-]+)(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z.-]+)?$/;function O(t){let n=Q.exec(String(t).trim());return n?{major:Number(n[1]),minor:Number(n[2]??0),patch:Number(n[3]??0),pre:n[4]?n[4].split("."):[]}:null}function ee(t,n){if(t.length===0&&n.length===0)return 0;if(t.length===0)return 1;if(n.length===0)return-1;let o=Math.max(t.length,n.length);for(let r=0;r<o;r++){let l=t[r],m=n[r];if(l===void 0)return-1;if(m===void 0)return 1;let y=/^\\d+$/.test(l),w=/^\\d+$/.test(m);if(y&&w){let $=Number(l)-Number(m);if($!==0)return $}else{if(y!==w)return y?-1:1;if(l!==m)return l<m?-1:1}}return 0}function v(t,n){let o=O(t),r=O(n);return!o||!r?t<n?-1:t>n?1:0:o.major!==r.major?o.major-r.major:o.minor!==r.minor?o.minor-r.minor:o.patch!==r.patch?o.patch-r.patch:ee(o.pre,r.pre)}var re=/^[a-z]+[+:-]/i;function k(t,n){if(n===!1||n==null||n==="")return!0;let o=String(n).trim();return!o||o==="*"||o==="latest"||re.test(o)?!0:o.split("||").some(r=>te(t,r.trim()))}function te(t,n){if(!n||n==="*")return!O(t)?.pre.length;let o=n.split(/\\s+-\\s+/);if(o.length===2){let m=o[0].trim(),y=o[1].trim();return!(!k(t,`>=${m}`)||!k(t,`<=${y}`))}let r=O(t);if(!r)return!1;let l=ne(n);if(l===null)return!0;for(let m of l)if(!ue(r,t,m))return!1;return!(r.pre.length>0&&!l.some(m=>m.ver.pre.length>0)&&!l.some(y=>y.ver.major===r.major&&y.ver.minor===r.minor&&y.ver.patch===r.patch))}function ne(t){let n=[],o=t.trim().split(/\\s+/).filter(Boolean);if(o.length===0)return null;for(let r of o){let l=/^(>=|<=|>|<|=|\\^|~)?(.*)$/.exec(r);if(!l)return null;let m=l[1],y=l[2],w=oe(m,y);if(w===null)return null;n.push(...w)}return n}function oe(t,n){let o=ae(n);if(!o)return null;let{ver:r,partial:l}=o;switch(t){case"^":{let m=ie(r);return m?[{op:">=",ver:r},{op:"<",ver:m}]:null}case"~":{let m=l>=2?{major:r.major,minor:r.minor+1,patch:0,pre:[]}:{major:r.major+1,minor:0,patch:0,pre:[]};return[{op:">=",ver:r},{op:"<",ver:m}]}case">=":return[{op:">=",ver:r}];case">":return l===1?[{op:">=",ver:{major:r.major+1,minor:0,patch:0,pre:[]}}]:l===2?[{op:">=",ver:{major:r.major,minor:r.minor+1,patch:0,pre:[]}}]:[{op:">",ver:r}];case"<":return l===1?[{op:"<",ver:{major:r.major,minor:0,patch:0,pre:[]}}]:l===2?[{op:"<",ver:{major:r.major,minor:r.minor,patch:0,pre:[]}}]:[{op:"<",ver:r}];case"<=":return[{op:"<=",ver:r}];case"=":case void 0:return l===1?[{op:">=",ver:r},{op:"<",ver:{major:r.major+1,minor:0,patch:0,pre:[]}}]:l===2?[{op:">=",ver:r},{op:"<",ver:{major:r.major,minor:r.minor+1,patch:0,pre:[]}}]:[{op:"=",ver:r}];default:return null}}function ie(t){return t.major>0?{major:t.major+1,minor:0,patch:0,pre:[]}:t.minor>0?{major:0,minor:t.minor+1,patch:0,pre:[]}:{major:0,minor:0,patch:t.patch+1,pre:[]}}function ae(t){let n=t.replace(/^v/,"").trim();if(!n||n==="*"||n==="x"||n==="X")return{ver:{major:0,minor:0,patch:0,pre:[]},partial:0};let o=n.split("."),r=[],l=0;for(let w of o.slice(0,3))if(/^\\d+$/.test(w))r.push(Number(w)),l++;else{if(w==="x"||w==="X"||w==="*")break;break}let m=n.split("-"),y=m.length>1?m.slice(1).join("-").split("+")[0].split("."):[];return l===0&&y.length===0?{ver:{major:0,minor:0,patch:0,pre:[]},partial:0}:{ver:{major:r[0]??0,minor:r[1]??0,patch:r[2]??0,pre:y},partial:l}}function se(t,n){switch(n){case">=":return t>=0;case">":return t>0;case"<":return t<0;case"<=":return t<=0;case"=":return t===0}}function ue(t,n,o){let r=`${t.major}.${t.minor}.${t.patch}`+(t.pre.length?`-${t.pre.join(".")}`:"");if(o.upper)return!(!(v(r,`${o.ver.major}.${o.ver.minor}.${o.ver.patch}`+(o.ver.pre.length?`-${o.ver.pre.join(".")}`:""))>=0)||!(v(r,`${o.upper.major}.${o.upper.minor}.${o.upper.patch}`)<0));let l=v(r,`${o.ver.major}.${o.ver.minor}.${o.ver.patch}`+(o.ver.pre.length?`-${o.ver.pre.join(".")}`:"")),m=se(l,o.op);return o.ver.pre.length>0&&t.pre.length===0&&(o.op===">"||o.op==="<")?!1:m}var g=class extends Error{code;details;constructor(n,o,r){super(`[fulgurjs:${n}] ${o}`),this.name="FulgurjsError",this.code=n,this.details=r}},R={REMOTE_LOAD_FAILED:"MFU-001",REMOTE_NAME_MISMATCH:"MFU-002",SHARE_STRICT_VERSION:"MFU-003",SHARE_NOT_AVAILABLE:"MFU-004",CONTAINER_REINIT_CONFLICT:"MFU-005",MODULE_NOT_EXPOSED:"MFU-006",PRELOAD_FAILED:"MFU-007",REMOTE_UNKNOWN:"MFU-008",EMPTY_EXPORTS:"MFU-009",SINGLETON_SKEW:"MFU-010"};var F="0.5.0";var U=15e3,P=2,ce=5,le=3e4;function fe(){let t={},n=new Map,o=[],r=new Map,l=new WeakMap,m={};function y(e){m={...m,...e},typeof globalThis<"u"&&(globalThis.__FULGURJS_APP_CONFIG__=m)}function w(){return m}let $={},D=()=>{for(let e of o)try{e.init?.($)}catch(i){console.warn("[fulgurjs] runtimePlugin init failed:",e.name,i)}},N=e=>t[e]??={};function j(e){try{$.onRemoteError?.(e)}catch{}typeof window<"u"&&window.dispatchEvent(new CustomEvent("fulgurjs:error",{detail:e}))}function H(e="default"){return N(e),t}function K(e,i,a,u,E={}){let s=N(e||"default"),c=s[i]??={};c[a]||(c[a]={version:a,get:u,from:E.from??"unknown",eager:!!E.eager,loaded:!!E.loaded})}function x(e){for(let i of e){let a=n.get(i.name);n.set(i.name,{timeout:U,retries:P,...a,...i,state:a?.state??"idle",breakerState:a?.breakerState??{fails:0,openUntil:0},debug:a?.debug??{entry:i.entry,status:"idle"}})}}function q(e){x([e])}function G(e){o.push(...e),D()}async function z(e,i={}){let a=i.shareScope||"default",u=i.shareKey||e,s=N(a)[u]||{},c=Object.keys(s),d=i.requiredVersion,f=c.filter(p=>d===void 0||d===!1||k(p,d)),b;if(i.singleton&&c.length>0){let p=c.filter(h=>s[h].loaded);if(b=[...p.length?p:c].sort(v).pop(),c.length>1||!f.includes(b)){let h=s[b],T=`singleton skew "${u}": req "${d??"any"}" use ${b} from ${h.from}`;if(i.strictVersion){let M=new g(R.SHARE_STRICT_VERSION,T,{shareKey:u,requiredVersion:d});throw j({remote:h.from,error:M}),M}console.warn(`[fulgurjs:MFU-010] ${T}`)}}else if(b=[...f].sort(v).pop(),!b){if(i.strictVersion){let h=new g(R.SHARE_STRICT_VERSION,`no satisfying version for "${u}" (required "${d}") in share scope "${a}"`);throw j({remote:u,error:h}),h}if(i.fallback)return i.fallback();let p=new g(R.SHARE_NOT_AVAILABLE,`shared "${u}" (${d??"any"}) unavailable in scope "${a}" (no local fallback)`,{shareKey:u,requiredVersion:d});throw j({remote:u,error:p}),p}let _=s[b];if($.resolveShare){let p=await $.resolveShare({shareKey:u,shareScope:a,requiredVersion:d,picked:_,available:Object.values(s)});p&&(_=p)}return _.loaded=!0,_.get()}function J(e,i,a){return new Promise((u,E)=>{let s=setTimeout(()=>E(new Error(`timeout after ${i}ms: ${a}`)),i);e.then(c=>{clearTimeout(s),u(c)},c=>{clearTimeout(s),E(c)})})}let W=e=>new Promise(i=>setTimeout(i,e));function I(e,i){if(!e||typeof e.get!="function")throw new Error(`remoteEntry of "${i.name}" does not export a container interface (get/init)`);if(e.name&&i.name&&e.name!==i.name){let a=`remoteEntry self-reported name "${e.name}" mismatches configured name "${i.name}"`;if(i.promise)console.warn(`[fulgurjs] ${a} (promise-based remote, continuing)`);else throw Object.assign(new Error(a),{code:R.REMOTE_NAME_MISMATCH})}}async function L(e,i){return J(import(e),i.timeout??U,`load remoteEntry ${e}`)}async function C(e,i){let a=e.shareScope||"default";if(e.container){let s=l.get(e.container);if(s&&s!==a)throw new g(R.CONTAINER_REINIT_CONFLICT,`container "${e.name}" already initialized with share scope "${s}", cannot re-init with "${a}"`);return e.container}if(e.containerPromise)return e.containerPromise;let u=e.breakerState;if(u.openUntil>Date.now()){let s=new g(R.REMOTE_LOAD_FAILED,`circuit breaker open for remote "${e.name}" until ${new Date(u.openUntil).toISOString()}`,{remote:e.name});throw j({remote:e.name,error:s}),s}e.state="loading",e.debug.status="loading";let E=(async()=>{let s=[];if(e.promise)s.push(async()=>{let p=await e.promise(),h=typeof p=="string"?await L(p,e):p;return I(h,e),h});else for(let p of[e.entry,...e.fallback??[]])s.push(async()=>{let h=await L(p,e);return I(h,e),h});let c,d,f=!1,b=i?.retries??e.retries??P;for(let p of s){for(let h=0;h<=b;h++){let T=performance.now();try{c=await p(),e.lastLoadMs=Math.round(performance.now()-T),e.debug.lastLoadMs=e.lastLoadMs,f=!0;break}catch(M){if(d=M,M?.code)throw M;h<b&&await W(200*2**h)}}if(f)break}if(!f||!c){let p=[];throw/^https?:\\/\\//.test(e.entry)&&typeof location<"u"?(p.push(`1. is the remote dev server running? try opening ${e.entry} in the browser \\u2014 it must return JS, not HTML/an error`),p.push("2. is the URL correct in federation({ remotes })? dev and prod entries can differ"),p.push("3. CORS: the remote dev server must allow cross-origin requests (fulgurjs-federation enables server.cors automatically; a custom server config may have disabled it)")):(p.push(`1. is the remote deployed and reachable? try opening ${e.entry} in the browser \\u2014 it must return JS`),p.push("2. NGINX/CDN routing: the entry path must serve the remoteEntry JS file (check try_files / fallback rules)")),new g(R.REMOTE_LOAD_FAILED,`failed to load remote "${e.name}" from ${e.entry}: ${String(d?.message??d)}\n`+p.join(`\n`),{remote:e.name})}I(c,e);let _=l.get(c);if(_&&_!==a)throw new g(R.CONTAINER_REINIT_CONFLICT,`container "${e.name}" already initialized with share scope "${_}", cannot re-init with "${a}"`);return typeof c.init=="function"&&await c.init(t),l.set(c,a),e.container=c,e.state="loaded",e.debug.status="loaded",u.fails=0,c})();e.containerPromise=E;try{return await E}catch(s){if(e.containerPromise=void 0,e.state="failed",e.debug.status="failed",e.debug.error=String(s?.message??s),u.fails+=1,u.fails>=ce&&(u.openUntil=Date.now()+le,u.fails=0),s instanceof g)throw j({remote:e.name,error:s}),s;if(s?.code)throw j({remote:e.name,error:s}),s;let c=new g(R.REMOTE_LOAD_FAILED,String(s?.message??s),{remote:e.name});throw j({remote:e.name,error:c}),c}}function A(e){let i=e.indexOf("/");return i===-1?{remote:e,module:""}:{remote:e.slice(0,i),module:B(e.slice(i+1))}}function B(e){return e?e.startsWith(".")?e:`./${e}`:""}async function X(e,i){let{remote:a,module:u}=A(e);$.beforeLoadRemote?.({remote:a,module:u});let E=n.get(a);if(!E)throw new g(R.REMOTE_UNKNOWN,`unknown remote "${a}". Register it via federation({ remotes }) or registerRemote().`,{remote:a});let s;try{s=await C(E,{retries:i?.retries})}catch(f){if(i?.fallbackModule)return console.error(`[fulgurjs] loadRemote("${e}") failed; returning fallbackModule (\\u663E\\u5F0F\\u964D\\u7EA7\\uFF0C\\u9519\\u8BEF\\u5DF2\\u900F\\u51FA)`,f),j({remote:a,error:f}),await i.fallbackModule();throw f}if(!u)return s;let c=`${a}@${E.shareScope||"default"}#${u}`;r.has(c)||r.set(c,s.get(u).catch(f=>{throw r.delete(c),f instanceof g||f?.code?f:new g(R.REMOTE_LOAD_FAILED,`failed to load module "${u}" from remote "${a}": ${String(f?.message??f)}`,{remote:a,module:u})}));let d;try{d=await r.get(c)}catch(f){if(i?.fallbackModule)return console.error(`[fulgurjs] loadRemote("${e}") failed; returning fallbackModule (\\u663E\\u5F0F\\u964D\\u7EA7\\uFF0C\\u9519\\u8BEF\\u5DF2\\u900F\\u51FA)`,f),j({remote:a,error:f}),await i.fallbackModule();throw f}if($.afterLoadRemote?.({remote:a,module:u,module_ns:d}),d&&typeof d=="object"&&Object.keys(d).length===0){let f=new g(R.EMPTY_EXPORTS,`no exports: ${u} @ ${a}`,{remote:a,module:u});j({remote:a,error:f}),console.error(`[fulgurjs:MFU-009] ${f.message}`)}return d}function Y(e){let i=n.get(e);if(!i)throw new g(R.REMOTE_UNKNOWN,`unknown remote "${e}"`,{remote:e});return C(i)}async function Z(e,i={}){let{remote:a}=A(e),u=n.get(a);if(!u)throw new g(R.REMOTE_UNKNOWN,`unknown remote "${a}"`,{remote:a});let E=i.mode??"preload",s=(c,d)=>{if(typeof document>"u"||document.querySelector(`link[href="${c}"]`))return;let f=document.createElement("link");f.rel=d==="style"?"stylesheet":"modulepreload",f.href=c,E==="prefetch"&&(f.fetchPriority="low"),document.head.appendChild(f)};try{if(u.manifestUrl){let c=await fetch(u.manifestUrl,{cache:"no-cache"});if(c.ok){let d=await c.json();s(u.entry,"modulepreload");let f=d.exposes??{};for(let b of Object.keys(f)){let _=f[b];_?.file&&s(new URL(_.file,u.entry).href,"modulepreload");for(let p of _?.css??[])s(new URL(p,u.entry).href,"style")}return}}s(u.entry,"modulepreload")}catch(c){j({remote:a,error:new g(R.PRELOAD_FAILED,String(c?.message??c),{remote:a})})}}return typeof window>"u"||(window.__FULGURJS_SCOPE__=t,window.__FULGURJS_INFO__={get remotes(){let e={};for(let[i,a]of n)e[i]={...a.debug,entry:a.entry};return e},errors:[]}),{shareScopeMap:t,initSharing:H,registerShare:K,registerRemotes:x,registerRemote:q,registerPlugins:G,loadShare:z,loadRemote:X,getContainer:Y,preloadRemote:Z,parseSpec:A,provideFulgurjsAppConfig:y,getFulgurjsAppConfig:w}}var V=globalThis,S=V.__FULGURJS_RUNTIME__??fe();V.__FULGURJS_RUNTIME__=S;try{Object.freeze(S)}catch{}var Re=F;function Se(){return S}var we=S.initSharing,be=S.registerShare,_e=S.registerRemotes,je=S.registerRemote,$e=S.registerPlugins,Me=S.loadShare,ve=S.loadRemote,Te=S.getContainer,Oe=S.preloadRemote,ke=S.shareScopeMap,Ne=S.provideFulgurjsAppConfig,Ie=S.getFulgurjsAppConfig;function Ae(t){if(t&&typeof t=="object"&&"default"in t){let n=t.default;return n!==void 0?n:t}return t}var xe=S;export{xe as default,Te as getContainer,Ie as getFulgurjsAppConfig,Se as getRuntime,we as initSharing,ve as loadRemote,Me as loadShare,Oe as preloadRemote,Ne as provideFulgurjsAppConfig,$e as registerPlugins,je as registerRemote,_e as registerRemotes,be as registerShare,S as runtime,ke as shareScopeMap,Ae as unwrapDefault,Re as version};\n';
|
|
1220
1220
|
|
|
1221
1221
|
// src/index.ts
|
|
1222
1222
|
function readRuntimeCode() {
|
|
@@ -1226,7 +1226,7 @@ function normalizeBase(base) {
|
|
|
1226
1226
|
if (!base || base === "/") return "/";
|
|
1227
1227
|
return base.endsWith("/") ? base : `${base}/`;
|
|
1228
1228
|
}
|
|
1229
|
-
var
|
|
1229
|
+
var FULGURJS_STUB_NAMESPACE = "fulgurjs-opt-stub";
|
|
1230
1230
|
var nsExportCache = /* @__PURE__ */ new Map();
|
|
1231
1231
|
function enumerateCjsExports(packageName, appRoot) {
|
|
1232
1232
|
const cached = nsExportCache.get(packageName);
|
|
@@ -1238,7 +1238,7 @@ function enumerateCjsExports(packageName, appRoot) {
|
|
|
1238
1238
|
names = Object.keys(mod);
|
|
1239
1239
|
} catch {
|
|
1240
1240
|
console.warn(
|
|
1241
|
-
`[
|
|
1241
|
+
`[fulgurjs] cannot enumerate CJS exports of shared package "${packageName}" for the optimize-deps facade; the facade will export default only. If consumers destructure named exports from it, add this package to optimizeDeps.exclude to serve it through the transform pipeline instead.`
|
|
1242
1242
|
);
|
|
1243
1243
|
}
|
|
1244
1244
|
nsExportCache.set(packageName, names);
|
|
@@ -1270,7 +1270,7 @@ function federation(options) {
|
|
|
1270
1270
|
entryInitInjected: /* @__PURE__ */ new Set()
|
|
1271
1271
|
};
|
|
1272
1272
|
const pre = {
|
|
1273
|
-
name: "
|
|
1273
|
+
name: "fulgurjs:core",
|
|
1274
1274
|
enforce: "pre",
|
|
1275
1275
|
async config(userConfig, env) {
|
|
1276
1276
|
state.command = env.command;
|
|
@@ -1289,19 +1289,19 @@ function federation(options) {
|
|
|
1289
1289
|
const filter = new RegExp(`^(${[...aliasToShare.keys()].map(escapeRe).join("|")})$`);
|
|
1290
1290
|
const devBase = normalizeBase(userConfig.base ?? "/");
|
|
1291
1291
|
const sharedExternal = {
|
|
1292
|
-
name: "
|
|
1292
|
+
name: "fulgurjs:optimize-shared-external",
|
|
1293
1293
|
setup(build) {
|
|
1294
|
-
const facadeUrlFor = (shareKey) => `${devBase}@id/__x00__virtual:
|
|
1294
|
+
const facadeUrlFor = (shareKey) => `${devBase}@id/__x00__virtual:fulgurjs-shared-ns:${shareKey}?import`;
|
|
1295
1295
|
const b = build;
|
|
1296
|
-
b.onResolve({ filter: /
|
|
1296
|
+
b.onResolve({ filter: /fulgurjs-shared-ns:/ }, (args) => ({ path: args.path, external: true }));
|
|
1297
1297
|
b.onResolve({ filter }, (args) => {
|
|
1298
1298
|
if (args.kind === "entry-point" || args.kind === "entry-point-render") return null;
|
|
1299
1299
|
const s = aliasToShare.get(args.path);
|
|
1300
1300
|
if (!s) return null;
|
|
1301
|
-
return { path: `
|
|
1301
|
+
return { path: `fulgurjs-stub:${s.shareKey}`, namespace: FULGURJS_STUB_NAMESPACE };
|
|
1302
1302
|
});
|
|
1303
|
-
b.onLoad({ filter: /^
|
|
1304
|
-
const shareKey = args.path.slice("
|
|
1303
|
+
b.onLoad({ filter: /^fulgurjs-stub:/, namespace: FULGURJS_STUB_NAMESPACE }, (args) => {
|
|
1304
|
+
const shareKey = args.path.slice("fulgurjs-stub:".length);
|
|
1305
1305
|
const url = facadeUrlFor(shareKey);
|
|
1306
1306
|
return {
|
|
1307
1307
|
contents: `export * from ${JSON.stringify(url)};
|
|
@@ -1328,7 +1328,7 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1328
1328
|
if (userTarget) {
|
|
1329
1329
|
if (/es20(0\d|1\d|20|21)/.test(String(userTarget))) {
|
|
1330
1330
|
normalized.warnings.push(
|
|
1331
|
-
`build.target="${String(userTarget)}" does not support top-level await;
|
|
1331
|
+
`build.target="${String(userTarget)}" does not support top-level await; fulgurjs requires es2022 or higher.`
|
|
1332
1332
|
);
|
|
1333
1333
|
}
|
|
1334
1334
|
} else {
|
|
@@ -1336,13 +1336,13 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1336
1336
|
extra.build = { target: "es2022" };
|
|
1337
1337
|
}
|
|
1338
1338
|
}
|
|
1339
|
-
for (const w of normalized.warnings) console.warn(`[
|
|
1339
|
+
for (const w of normalized.warnings) console.warn(`[fulgurjs] ${w}`);
|
|
1340
1340
|
return extra;
|
|
1341
1341
|
},
|
|
1342
1342
|
configResolved(resolved) {
|
|
1343
1343
|
state.base = normalizeBase(resolved.base);
|
|
1344
1344
|
if (resolved.build?.ssr) {
|
|
1345
|
-
console.warn("[
|
|
1345
|
+
console.warn("[fulgurjs] SSR builds are not supported in this version; plugin hooks disabled.");
|
|
1346
1346
|
}
|
|
1347
1347
|
const n0 = state.normalized;
|
|
1348
1348
|
const optimize = resolved.optimizeDeps;
|
|
@@ -1355,7 +1355,7 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1355
1355
|
for (const pkg of KNOWN_UMD) {
|
|
1356
1356
|
if (n0.pkgDependencies[pkg] && !incl(pkg) && !excl(pkg)) {
|
|
1357
1357
|
console.warn(
|
|
1358
|
-
|
|
1358
|
+
formatFulgurjsDiagnostic({
|
|
1359
1359
|
code: "DEV-004",
|
|
1360
1360
|
symptom: `UMD-only \u4F9D\u8D56 "${pkg}" \u4E0D\u5728 optimizeDeps.include`,
|
|
1361
1361
|
cause: "UMD \u5305\u53EA\u80FD\u7ECF\u9884\u6784\u5EFA\u6D88\u8D39\uFF1B\u4E0D\u58F0\u660E\u4F1A\u88AB\u88F8 CJS \u670D\u52A1\u6216\u5185\u8054\u672C\u5730 vue\uFF08\u9875\u9762\u7A7A\u767D/\u53CC\u5B9E\u4F8B\uFF09",
|
|
@@ -1384,7 +1384,7 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1384
1384
|
if (!known && !warnedUnknownPrefixes.has(prefix)) {
|
|
1385
1385
|
warnedUnknownPrefixes.add(prefix);
|
|
1386
1386
|
console.warn(
|
|
1387
|
-
`[
|
|
1387
|
+
`[fulgurjs] "${source}" uses prefix "${prefix}/", which is not in federation({ remotes }) or shared. If "${prefix}" is a federated remote, add it: remotes: { '${prefix}': '<url>' }. (Ignore this if it is a plain npm package.)`
|
|
1388
1388
|
);
|
|
1389
1389
|
}
|
|
1390
1390
|
}
|
|
@@ -1392,17 +1392,17 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1392
1392
|
if (bareClean === RUNTIME_VIRTUAL_ID) return RESOLVED.runtime;
|
|
1393
1393
|
if (bareClean === RUNTIME_PROXY_VIRTUAL_ID) return RESOLVED.runtimeProxy;
|
|
1394
1394
|
if (bareClean === INIT_VIRTUAL_ID) return RESOLVED.init;
|
|
1395
|
-
if (bareClean === "virtual:
|
|
1396
|
-
if (bareClean === "virtual:
|
|
1397
|
-
if (bareClean === "virtual:
|
|
1395
|
+
if (bareClean === "virtual:fulgurjs-remote-schema") return bareClean;
|
|
1396
|
+
if (bareClean === "virtual:fulgurjs-provides") return RESOLVED.provides;
|
|
1397
|
+
if (bareClean === "virtual:fulgurjs-remote-entry") return RESOLVED.remoteEntry;
|
|
1398
1398
|
if (bareClean.startsWith(SHARED_NS_FACADE_PREFIX)) {
|
|
1399
1399
|
return RESOLVED.sharedNsFacade(bareClean.slice(SHARED_NS_FACADE_PREFIX.length)) + query;
|
|
1400
1400
|
}
|
|
1401
|
-
if (bareClean.startsWith("virtual:
|
|
1402
|
-
return RESOLVED.sharedNsFacade(bareClean.slice("virtual:
|
|
1401
|
+
if (bareClean.startsWith("virtual:fulgurjs-cjs-ns:")) {
|
|
1402
|
+
return RESOLVED.sharedNsFacade(bareClean.slice("virtual:fulgurjs-cjs-ns:".length)) + query;
|
|
1403
1403
|
}
|
|
1404
|
-
if (bareClean.startsWith("virtual:
|
|
1405
|
-
const body = bareClean.slice("virtual:
|
|
1404
|
+
if (bareClean.startsWith("virtual:fulgurjs-shared:")) {
|
|
1405
|
+
const body = bareClean.slice("virtual:fulgurjs-shared:".length);
|
|
1406
1406
|
return RESOLVED.sharedFacade(body) + query;
|
|
1407
1407
|
}
|
|
1408
1408
|
return null;
|
|
@@ -1411,22 +1411,22 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1411
1411
|
const raw = id.startsWith("\0") ? id.slice(1) : id;
|
|
1412
1412
|
const q = raw.indexOf("?");
|
|
1413
1413
|
const clean = q === -1 ? raw : raw.slice(0, q);
|
|
1414
|
-
if (clean === "virtual:
|
|
1414
|
+
if (clean === "virtual:fulgurjs-runtime") return readRuntimeCode();
|
|
1415
1415
|
if (clean === RESOLVED.runtimeProxy || clean === RUNTIME_PROXY_VIRTUAL_ID) return genRuntimeProxyModule();
|
|
1416
|
-
if (clean === "virtual:
|
|
1416
|
+
if (clean === "virtual:fulgurjs-init" && state.normalized) {
|
|
1417
1417
|
return genInitModule(state.normalized, state.command);
|
|
1418
1418
|
}
|
|
1419
|
-
if (clean === "virtual:
|
|
1419
|
+
if (clean === "virtual:fulgurjs-provides" && state.normalized) {
|
|
1420
1420
|
return genDevProvides(state.normalized);
|
|
1421
1421
|
}
|
|
1422
|
-
if (clean === "virtual:
|
|
1422
|
+
if (clean === "virtual:fulgurjs-remote-schema" && state.normalized) {
|
|
1423
1423
|
if (state.command === "build") return genEmptyRemoteSchemaModule();
|
|
1424
1424
|
remoteSchemaPromise ??= probeRemotesAndBuildSchema(state.normalized).then(
|
|
1425
1425
|
(schema) => `export default ${JSON.stringify(schema)}`
|
|
1426
1426
|
);
|
|
1427
1427
|
return remoteSchemaPromise;
|
|
1428
1428
|
}
|
|
1429
|
-
if (clean === "virtual:
|
|
1429
|
+
if (clean === "virtual:fulgurjs-remote-entry" && state.normalized) {
|
|
1430
1430
|
return genBuildRemoteEntry(state.normalized, state.exposeAbsPaths);
|
|
1431
1431
|
}
|
|
1432
1432
|
if (clean.startsWith(SHARED_NS_FACADE_PREFIX) && state.normalized) {
|
|
@@ -1441,8 +1441,8 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1441
1441
|
}
|
|
1442
1442
|
return genSharedNsFacade(item, serializeShareCallForFacade(item), names);
|
|
1443
1443
|
}
|
|
1444
|
-
if (clean.startsWith("virtual:
|
|
1445
|
-
const body = clean.slice("virtual:
|
|
1444
|
+
if (clean.startsWith("virtual:fulgurjs-shared:") && state.normalized) {
|
|
1445
|
+
const body = clean.slice("virtual:fulgurjs-shared:".length);
|
|
1446
1446
|
const f = raw.indexOf("?f=");
|
|
1447
1447
|
if (f === -1) {
|
|
1448
1448
|
const item2 = state.normalized.shared.find((x) => x.shareKey === body);
|
|
@@ -1467,7 +1467,7 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1467
1467
|
...item.strictVersion ? ["strictVersion: true"] : [],
|
|
1468
1468
|
"fallback: () => import(" + JSON.stringify(item.import) + ")"
|
|
1469
1469
|
];
|
|
1470
|
-
const call = "
|
|
1470
|
+
const call = "__fulgurjs_loadShare(" + JSON.stringify(item.shareKey) + ", { " + opts.join(", ") + " })";
|
|
1471
1471
|
return genBindingFacade(item, entry.bindings, call);
|
|
1472
1472
|
}
|
|
1473
1473
|
return null;
|
|
@@ -1532,12 +1532,12 @@ ${code}`, map: null };
|
|
|
1532
1532
|
if (resolved) {
|
|
1533
1533
|
state.exposeAbsPaths[e.import] = resolved.id.split("?")[0];
|
|
1534
1534
|
} else {
|
|
1535
|
-
this.error(`[
|
|
1535
|
+
this.error(`[fulgurjs] expose "${e.import}" could not be resolved from ${n.root}`);
|
|
1536
1536
|
}
|
|
1537
1537
|
}
|
|
1538
1538
|
this.emitFile({
|
|
1539
1539
|
type: "chunk",
|
|
1540
|
-
id: "virtual:
|
|
1540
|
+
id: "virtual:fulgurjs-remote-entry",
|
|
1541
1541
|
fileName: n.filename.replace(/^\//, ""),
|
|
1542
1542
|
preserveSignature: "allow-extension"
|
|
1543
1543
|
});
|
|
@@ -1567,7 +1567,7 @@ ${code}`, map: null };
|
|
|
1567
1567
|
const manifest = genProdManifest(n, state.exposeFiles, entryChunkName ?? n.filename);
|
|
1568
1568
|
this.emitFile({
|
|
1569
1569
|
type: "asset",
|
|
1570
|
-
fileName: "
|
|
1570
|
+
fileName: "fulgurjs-manifest.json",
|
|
1571
1571
|
source: JSON.stringify(manifest, null, 2)
|
|
1572
1572
|
});
|
|
1573
1573
|
},
|
|
@@ -1577,10 +1577,10 @@ ${code}`, map: null };
|
|
|
1577
1577
|
warmResolvedSharedPaths(server);
|
|
1578
1578
|
if (n.exposes.length > 0 || n.remotes.length > 0) {
|
|
1579
1579
|
console.warn(
|
|
1580
|
-
|
|
1580
|
+
formatFulgurjsDiagnostic({
|
|
1581
1581
|
code: "DEV-010",
|
|
1582
1582
|
symptom: 'dev \u51B7\u542F\u52A8\u9884\u6784\u5EFA\u7A97\u53E3\uFF1A\u9996\u6B21\u542F\u52A8\u6216\u6E05 node_modules/.vite \u540E\u9996\u8F6E 30~60s \u5185\uFF0C\u8054\u90A6\u6A21\u5757\u8BF7\u6C42\u53EF\u80FD\u51FA\u73B0\u77AC\u65F6 504 / "ce" / Outdated Optimize Dep',
|
|
1583
|
-
cause: "vite \u4F9D\u8D56\u9884\u6784\u5EFA\uFF08\u542B
|
|
1583
|
+
cause: "vite \u4F9D\u8D56\u9884\u6784\u5EFA\uFF08\u542B fulgurjs \u5916\u90E8\u5316\u6869\uFF09\u5C1A\u672A\u5C31\u7EEA\uFF0C\u5C5E\u9884\u6784\u5EFA\u6682\u6001\u800C\u975E\u56DE\u5F52\uFF1B\u9996\u8F6E\u7ED3\u675F\u540E\u81EA\u884C\u6062\u590D",
|
|
1584
1584
|
fix: "\u5148\u771F\u5B9E\u6253\u5F00\u4E00\u6B21\u9875\u9762\u9884\u70ED\uFF08\u7B49\u5230\u7F51\u7EDC\u7A7A\u95F2\uFF09\uFF0C\u518D\u505A\u9A8C\u6536\u65AD\u8A00\u6216\u4EBA\u5DE5\u5224\u65AD\uFF1B\u91CD\u590D\u51FA\u73B0\u624D\u6309 DEV-009 \u6E05\u7F13\u5B58\u6392\u67E5"
|
|
1585
1585
|
})
|
|
1586
1586
|
);
|
|
@@ -1590,7 +1590,7 @@ ${code}`, map: null };
|
|
|
1590
1590
|
server.middlewares.use((req, res, next) => {
|
|
1591
1591
|
const raw = (req.url ?? "").split("?")[0];
|
|
1592
1592
|
const stripped = raw.startsWith(baseNorm) ? `/${raw.slice(baseNorm.length)}` : raw;
|
|
1593
|
-
if (stripped === "/@
|
|
1593
|
+
if (stripped === "/@fulgurjs-entry.js" || stripped === "/@fulgurjs-manifest.json") {
|
|
1594
1594
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
1595
1595
|
res.setHeader("Access-Control-Allow-Methods", "GET,OPTIONS");
|
|
1596
1596
|
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
@@ -1599,7 +1599,7 @@ ${code}`, map: null };
|
|
|
1599
1599
|
res.end();
|
|
1600
1600
|
return;
|
|
1601
1601
|
}
|
|
1602
|
-
if (stripped === "/@
|
|
1602
|
+
if (stripped === "/@fulgurjs-entry.js") {
|
|
1603
1603
|
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
1604
1604
|
res.setHeader("Cache-Control", "no-cache");
|
|
1605
1605
|
res.end(genDevRemoteEntry(n, baseNorm));
|
|
@@ -1629,10 +1629,10 @@ ${code}`, map: null };
|
|
|
1629
1629
|
return () => {
|
|
1630
1630
|
server.middlewares.use((req, res, next) => {
|
|
1631
1631
|
const url = req.url ?? "";
|
|
1632
|
-
if (req.method === "GET" && url.includes("
|
|
1632
|
+
if (req.method === "GET" && url.includes("fulgurjs")) {
|
|
1633
1633
|
res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
|
|
1634
1634
|
res.end(
|
|
1635
|
-
|
|
1635
|
+
formatFulgurjsDiagnostic({
|
|
1636
1636
|
code: "DEV-009",
|
|
1637
1637
|
symptom: `\u8054\u90A6\u6A21\u5757\u8BF7\u6C42 404\uFF1A${url.slice(0, 120)}`,
|
|
1638
1638
|
cause: "node_modules/.vite \u9884\u6784\u5EFA\u7F13\u5B58\u4E0E\u5F53\u524D\u63D2\u4EF6\u4EA7\u7269\u4E0D\u4E00\u81F4\uFF08immutable \u7F13\u5B58\u6309 ?f= \u7B7E\u540D\u957F\u671F\u6301\u6709\uFF0C\u63D2\u4EF6 dist \u66F4\u65B0\u540E\u65E7\u7B7E\u540D\u5FC5 404\uFF09",
|
|
@@ -1647,15 +1647,15 @@ ${code}`, map: null };
|
|
|
1647
1647
|
}
|
|
1648
1648
|
};
|
|
1649
1649
|
const post = {
|
|
1650
|
-
name: "
|
|
1650
|
+
name: "fulgurjs:vue-post",
|
|
1651
1651
|
enforce: "post",
|
|
1652
1652
|
async transform(code, id) {
|
|
1653
1653
|
if (!state.normalized) return null;
|
|
1654
1654
|
const clean = id.split("?")[0];
|
|
1655
|
-
if (state.command === "serve" && code.includes("virtual:
|
|
1656
|
-
return { code: code.split("virtual:
|
|
1655
|
+
if (state.command === "serve" && code.includes("virtual:fulgurjs-runtime") && !code.includes("virtual:fulgurjs-runtime-proxy") && isExposeTargetFile(clean, state.normalized.root, state.normalized.exposes)) {
|
|
1656
|
+
return { code: code.split("virtual:fulgurjs-runtime").join("virtual:fulgurjs-runtime-proxy"), map: null };
|
|
1657
1657
|
}
|
|
1658
|
-
if (code.includes("virtual:
|
|
1658
|
+
if (code.includes("virtual:fulgurjs-runtime")) return null;
|
|
1659
1659
|
if (state.command === "build" && !/\.vue(\?|$)/.test(id)) return null;
|
|
1660
1660
|
if (/type=(style|template)/.test(id)) return null;
|
|
1661
1661
|
const isJsLike = /\.(m|c)?[jt]sx?$/.test(clean) || clean.endsWith(".vue");
|