@fulgurjs/federation 0.4.2 → 0.5.1
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 +30 -7
- package/DESIGN.md +8 -8
- package/README.md +55 -55
- 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 +524 -518
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +524 -518
- 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.1";
|
|
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 = [];
|
|
@@ -397,126 +397,462 @@ function normalizeOptions(options, root, command) {
|
|
|
397
397
|
var import_es_module_lexer = require("es-module-lexer");
|
|
398
398
|
var import_magic_string = __toESM(require("magic-string"), 1);
|
|
399
399
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return
|
|
404
|
-
}
|
|
405
|
-
function isExposeTargetFile(cleanPath, root, exposes) {
|
|
406
|
-
for (const e of exposes) {
|
|
407
|
-
const abs = import_node_path2.default.resolve(root, e.import.replace(/^\.\//, ""));
|
|
408
|
-
if (cleanPath === abs) return true;
|
|
409
|
-
for (const ext of [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".vue"]) {
|
|
410
|
-
if (cleanPath === abs + ext) return true;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return false;
|
|
400
|
+
|
|
401
|
+
// src/virtual.ts
|
|
402
|
+
function jsonReplacer(_k, v) {
|
|
403
|
+
return v;
|
|
414
404
|
}
|
|
415
|
-
function
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
405
|
+
function genSharedFacade(specifier, exportNames) {
|
|
406
|
+
const names = (exportNames ?? []).filter(
|
|
407
|
+
(n) => n !== "default" && /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n)
|
|
408
|
+
);
|
|
409
|
+
if (names.length === 0) {
|
|
410
|
+
return [
|
|
411
|
+
`import * as __fulgurjs_facade from ${JSON.stringify(specifier)};`,
|
|
412
|
+
`export * from ${JSON.stringify(specifier)};`,
|
|
413
|
+
`export default __fulgurjs_facade.default ?? __fulgurjs_facade;`,
|
|
414
|
+
""
|
|
415
|
+
].join("\n");
|
|
423
416
|
}
|
|
424
|
-
return
|
|
417
|
+
return [
|
|
418
|
+
`import * as __fulgurjs_facade from ${JSON.stringify(specifier)};`,
|
|
419
|
+
...names.map((n) => `export const ${n} = __fulgurjs_facade[${JSON.stringify(n)}];`),
|
|
420
|
+
`export default __fulgurjs_facade.default ?? __fulgurjs_facade;`,
|
|
421
|
+
""
|
|
422
|
+
].join("\n");
|
|
425
423
|
}
|
|
426
|
-
function
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
424
|
+
function genSharedNsFacade(item, loadShareCall, exportNames) {
|
|
425
|
+
const lines = [
|
|
426
|
+
`import { loadShare as __fulgurjs_loadShare, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
427
|
+
`const __fulgurjs_m = await ${loadShareCall};`,
|
|
428
|
+
`const __fulgurjs_d = __fulgurjsU(__fulgurjs_m);`,
|
|
429
|
+
`export default __fulgurjs_d;`
|
|
430
|
+
];
|
|
431
|
+
const seen = /* @__PURE__ */ new Set(["default"]);
|
|
432
|
+
for (const name of exportNames) {
|
|
433
|
+
if (seen.has(name) || !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name)) continue;
|
|
434
|
+
seen.add(name);
|
|
435
|
+
lines.push(`export const ${name} = __fulgurjs_d[${JSON.stringify(name)}];`);
|
|
431
436
|
}
|
|
432
|
-
|
|
437
|
+
lines.push("");
|
|
438
|
+
return lines.join("\n");
|
|
433
439
|
}
|
|
434
|
-
function
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const
|
|
443
|
-
|
|
440
|
+
function genBindingFacade(item, bindings, loadShareCall) {
|
|
441
|
+
const lines = [
|
|
442
|
+
`import { loadShare as __fulgurjs_loadShare, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
443
|
+
`const __fulgurjs_m = await ${loadShareCall};`
|
|
444
|
+
];
|
|
445
|
+
const seen = /* @__PURE__ */ new Set();
|
|
446
|
+
for (const bRaw of bindings) {
|
|
447
|
+
if (bRaw === "default") continue;
|
|
448
|
+
const asMatch = bRaw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
449
|
+
const imported = (asMatch ? asMatch[1] : bRaw).trim();
|
|
450
|
+
if (seen.has(imported)) continue;
|
|
451
|
+
seen.add(imported);
|
|
452
|
+
lines.push(`export const ${imported} = __fulgurjs_m.${imported};`);
|
|
444
453
|
}
|
|
445
|
-
|
|
454
|
+
lines.push(`export default __fulgurjsU(__fulgurjs_m);`);
|
|
455
|
+
lines.push("");
|
|
456
|
+
return lines.join("\n");
|
|
446
457
|
}
|
|
447
|
-
function
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
|
|
458
|
+
function genRemoteBindingFacade(remoteSpec, bindings) {
|
|
459
|
+
const lines = [
|
|
460
|
+
`import { loadRemote as __fulgurjs_loadRemote, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
461
|
+
`const __fulgurjs_m = await __fulgurjs_loadRemote(${JSON.stringify(remoteSpec)});`
|
|
462
|
+
];
|
|
463
|
+
const seen = /* @__PURE__ */ new Set();
|
|
464
|
+
for (const bRaw of bindings) {
|
|
465
|
+
if (bRaw === "default") continue;
|
|
466
|
+
const asMatch = bRaw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
467
|
+
const imported = (asMatch ? asMatch[1] : bRaw).trim();
|
|
468
|
+
if (seen.has(imported)) continue;
|
|
469
|
+
seen.add(imported);
|
|
470
|
+
lines.push(`export const ${imported} = __fulgurjs_m.${imported};`);
|
|
457
471
|
}
|
|
458
|
-
|
|
472
|
+
lines.push(`export default __fulgurjsU(__fulgurjs_m);`);
|
|
473
|
+
lines.push("");
|
|
474
|
+
return lines.join("\n");
|
|
459
475
|
}
|
|
460
|
-
function
|
|
461
|
-
return
|
|
476
|
+
function providesRecords(options) {
|
|
477
|
+
return options.shared.filter((s) => s.import !== false).map((s) => ({
|
|
478
|
+
shareScope: s.shareScope,
|
|
479
|
+
name: s.shareKey,
|
|
480
|
+
version: s.version,
|
|
481
|
+
eager: s.eager,
|
|
482
|
+
from: options.name
|
|
483
|
+
}));
|
|
462
484
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
485
|
+
var INIT_MODULE_MARKER = "/* fulgurjs:init */";
|
|
486
|
+
function genInitModule(options, command) {
|
|
487
|
+
const lines = [INIT_MODULE_MARKER];
|
|
488
|
+
lines.push(`import { initSharing, registerShare, registerRemotes, registerPlugins } from "virtual:fulgurjs-runtime";`);
|
|
489
|
+
const provides = providesRecords(options);
|
|
490
|
+
const eagerShared = options.shared.filter((s) => s.eager && s.import !== false);
|
|
491
|
+
eagerShared.forEach((s, i) => {
|
|
492
|
+
lines.push(`import * as __fulgurjs_eager_${i} from "virtual:fulgurjs-shared:${s.shareKey}";`);
|
|
493
|
+
});
|
|
494
|
+
const isDevHost = command === "serve" && options.remotes.length > 0;
|
|
495
|
+
const loadedFlag = isDevHost ? "true" : "false";
|
|
496
|
+
lines.push(`initSharing(${JSON.stringify(options.shareScope)});`);
|
|
497
|
+
if (options.runtimePlugins.length > 0) {
|
|
498
|
+
options.runtimePlugins.forEach((p, i) => {
|
|
499
|
+
lines.push(`import * as __fulgurjs_rp_${i} from ${JSON.stringify(p)};`);
|
|
500
|
+
});
|
|
501
|
+
lines.push(
|
|
502
|
+
`registerPlugins([${options.runtimePlugins.map((_, i) => `(__fulgurjs_rp_${i}.default ?? __fulgurjs_rp_${i})`).join(", ")}]);`
|
|
503
|
+
);
|
|
473
504
|
}
|
|
474
|
-
|
|
505
|
+
if (options.remotes.length > 0) {
|
|
506
|
+
lines.push(...registerRemotesLines(options, command));
|
|
507
|
+
}
|
|
508
|
+
provides.forEach((p) => {
|
|
509
|
+
const eagerIdx = eagerShared.findIndex((s) => s.shareKey === p.name && s.shareScope === p.shareScope);
|
|
510
|
+
if (p.eager && eagerIdx !== -1) {
|
|
511
|
+
lines.push(
|
|
512
|
+
`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} });`
|
|
513
|
+
);
|
|
514
|
+
} else {
|
|
515
|
+
lines.push(
|
|
516
|
+
`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} });`
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
return `${lines.join("\n")}
|
|
521
|
+
`;
|
|
475
522
|
}
|
|
476
|
-
function
|
|
477
|
-
const
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
523
|
+
function manifestUrlFor(r, command) {
|
|
524
|
+
const entry = command === "serve" ? r.devEntry : r.prodEntry;
|
|
525
|
+
if (!entry) return null;
|
|
526
|
+
try {
|
|
527
|
+
const u = new URL(entry);
|
|
528
|
+
if (u.pathname.includes("@fulgurjs-entry.js")) {
|
|
529
|
+
u.pathname = u.pathname.replace("@fulgurjs-entry.js", "@fulgurjs-manifest.json");
|
|
530
|
+
} else {
|
|
531
|
+
u.pathname = u.pathname.replace(/[^/]*$/, "") + "fulgurjs-manifest.json";
|
|
532
|
+
}
|
|
533
|
+
return u.href;
|
|
534
|
+
} catch {
|
|
535
|
+
return null;
|
|
536
|
+
}
|
|
485
537
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
538
|
+
function registerRemotesLines(options, command) {
|
|
539
|
+
if (options.remotes.length === 0) return [];
|
|
540
|
+
const remotesJson = options.remotes.filter((r) => !r.promise).map((r) => ({
|
|
541
|
+
name: r.name,
|
|
542
|
+
entry: command === "serve" ? r.devEntry : r.prodEntry,
|
|
543
|
+
shareScope: r.shareScope,
|
|
544
|
+
timeout: r.timeout,
|
|
545
|
+
retries: r.retries,
|
|
546
|
+
fallback: r.fallback,
|
|
547
|
+
breaker: r.breaker,
|
|
548
|
+
manifestUrl: manifestUrlFor(r, command)
|
|
549
|
+
}));
|
|
550
|
+
if (remotesJson.length === 0) return [];
|
|
551
|
+
return [
|
|
552
|
+
`registerRemotes(${JSON.stringify(remotesJson, jsonReplacer).replace(/"manifestUrl":null,?/g, "")});`
|
|
553
|
+
];
|
|
492
554
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
555
|
+
function genRuntimeProxyModule() {
|
|
556
|
+
const promiseApis = [
|
|
557
|
+
"loadRemote",
|
|
558
|
+
"loadShare",
|
|
559
|
+
"preloadRemote",
|
|
560
|
+
"getContainer",
|
|
561
|
+
"registerRemote",
|
|
562
|
+
"registerRemotes",
|
|
563
|
+
"registerShare",
|
|
564
|
+
"initSharing",
|
|
565
|
+
"registerPlugins",
|
|
566
|
+
"parseSpec"
|
|
567
|
+
];
|
|
568
|
+
const lines = [
|
|
569
|
+
`let __fulgurjs_mod_p;`,
|
|
570
|
+
`const __fulgurjs_rt = async () => {`,
|
|
571
|
+
` __fulgurjs_mod_p ??= import('virtual:fulgurjs-runtime');`,
|
|
572
|
+
` return await __fulgurjs_mod_p;`,
|
|
573
|
+
`};`,
|
|
574
|
+
...promiseApis.map((m) => `export const ${m} = (...a) => __fulgurjs_rt().then((m2) => m2.${m}(...a));`),
|
|
575
|
+
`export const getRuntime = () => (globalThis).__FULGURJS_RUNTIME__;`,
|
|
576
|
+
`export const getFulgurjsAppConfig = () =>`,
|
|
577
|
+
` (globalThis).__FULGURJS_RUNTIME__?.getFulgurjsAppConfig?.() ?? (globalThis).__FULGURJS_APP_CONFIG__ ?? {};`,
|
|
578
|
+
`export const provideFulgurjsAppConfig = (c) => {`,
|
|
579
|
+
` const g = (globalThis);`,
|
|
580
|
+
` g.__FULGURJS_APP_CONFIG__ = { ...(g.__FULGURJS_APP_CONFIG__ ?? {}), ...c };`,
|
|
581
|
+
` g.__FULGURJS_RUNTIME__?.provideFulgurjsAppConfig?.(c);`,
|
|
582
|
+
`};`,
|
|
583
|
+
`export const unwrapDefault = (ns) =>`,
|
|
584
|
+
` ns && typeof ns === 'object' && 'default' in ns ? (ns.default !== undefined ? ns.default : ns) : ns;`,
|
|
585
|
+
`export const version = (globalThis).__FULGURJS_RUNTIME__?.version;`,
|
|
586
|
+
`export default { get runtime() { return (globalThis).__FULGURJS_RUNTIME__; } };`,
|
|
587
|
+
``
|
|
588
|
+
];
|
|
589
|
+
return lines.join("\n");
|
|
501
590
|
}
|
|
502
|
-
function
|
|
503
|
-
|
|
591
|
+
function genDevRemoteEntry(options, base) {
|
|
592
|
+
const b = base.endsWith("/") ? base : `${base}/`;
|
|
593
|
+
const remoteLines = registerRemotesLines(options, "serve");
|
|
594
|
+
return `import ${JSON.stringify(`${b}@vite/client`)};
|
|
595
|
+
import { name as _fulgurjs_name, exposes, provides } from ${JSON.stringify(`${b}@id/__x00__virtual:fulgurjs-provides`)};
|
|
596
|
+
${remoteLines.length > 0 ? `import { registerRemotes } from ${JSON.stringify(`${b}@id/virtual:fulgurjs-runtime`)};
|
|
597
|
+
${remoteLines.join("\n")}` : ""}
|
|
598
|
+
|
|
599
|
+
export const name = _fulgurjs_name;
|
|
600
|
+
|
|
601
|
+
export async function init(shareScopeMap) {
|
|
602
|
+
for (const p of provides) {
|
|
603
|
+
const scope = shareScopeMap[p.shareScope] || (shareScopeMap[p.shareScope] = {});
|
|
604
|
+
const byName = scope[p.name] || (scope[p.name] = {});
|
|
605
|
+
if (byName[p.version]) continue; // \u5DF2\u6CE8\u518C\u7248\u672C\u6C38\u4E0D\u66FF\u6362
|
|
606
|
+
byName[p.version] = { version: p.version, get: p.get, from: name, eager: p.eager, loaded: false };
|
|
607
|
+
}
|
|
504
608
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
const
|
|
510
|
-
|
|
609
|
+
|
|
610
|
+
export async function get(moduleName) {
|
|
611
|
+
const loader = exposes[moduleName];
|
|
612
|
+
if (!loader) {
|
|
613
|
+
const err = new Error('MFU-006: module "' + moduleName + '" is not exposed by remote "' + name + '"');
|
|
614
|
+
err.code = 'MFU-006';
|
|
615
|
+
throw err;
|
|
511
616
|
}
|
|
512
|
-
return
|
|
617
|
+
return loader();
|
|
513
618
|
}
|
|
514
|
-
|
|
515
|
-
const canonical = canonicalBindings(bindings);
|
|
516
|
-
const sig = canonical.length ? `?f=${shortSig("shared", item.shareKey, canonical)}` : "";
|
|
517
|
-
return `${SHARED_FACADE_PREFIX}${item.shareKey}${sig}`;
|
|
619
|
+
`;
|
|
518
620
|
}
|
|
519
|
-
function
|
|
621
|
+
function genDevProvides(options) {
|
|
622
|
+
const exposes = [];
|
|
623
|
+
for (const e of options.exposes) {
|
|
624
|
+
const devUrl = `/${e.import.replace(/^\.?\//, "")}`;
|
|
625
|
+
exposes.push(
|
|
626
|
+
` ${JSON.stringify(e.name)}: () => import(${JSON.stringify(devUrl)}),`
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
const provides = providesRecords(options).map(
|
|
630
|
+
(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}") },`
|
|
631
|
+
);
|
|
632
|
+
return [
|
|
633
|
+
`export const name = ${JSON.stringify(options.name)};`,
|
|
634
|
+
`export const exposes = {`,
|
|
635
|
+
...exposes,
|
|
636
|
+
`};`,
|
|
637
|
+
`export const provides = [`,
|
|
638
|
+
...provides,
|
|
639
|
+
`];`,
|
|
640
|
+
""
|
|
641
|
+
].join("\n");
|
|
642
|
+
}
|
|
643
|
+
function genBuildRemoteEntry(options, exposeAbsPaths) {
|
|
644
|
+
const exposes = [];
|
|
645
|
+
for (const e of options.exposes) {
|
|
646
|
+
const abs = exposeAbsPaths[e.import];
|
|
647
|
+
if (!abs) continue;
|
|
648
|
+
exposes.push(` ${JSON.stringify(e.name)}: () => import(${JSON.stringify(abs)}),`);
|
|
649
|
+
}
|
|
650
|
+
const provides = providesRecords(options).map(
|
|
651
|
+
(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}") },`
|
|
652
|
+
);
|
|
653
|
+
const remoteLines = registerRemotesLines(options, "build");
|
|
654
|
+
return [
|
|
655
|
+
...remoteLines.length > 0 ? [`import { registerRemotes } from "virtual:fulgurjs-runtime";`, ...remoteLines] : [],
|
|
656
|
+
`const exposes = {`,
|
|
657
|
+
...exposes,
|
|
658
|
+
`};`,
|
|
659
|
+
`const provides = [`,
|
|
660
|
+
...provides,
|
|
661
|
+
`];`,
|
|
662
|
+
`export const name = ${JSON.stringify(options.name)};`,
|
|
663
|
+
``,
|
|
664
|
+
`export async function init(shareScopeMap) {`,
|
|
665
|
+
` for (const p of provides) {`,
|
|
666
|
+
` const scope = shareScopeMap[p.shareScope] || (shareScopeMap[p.shareScope] = {});`,
|
|
667
|
+
` const byName = scope[p.name] || (scope[p.name] = {});`,
|
|
668
|
+
` if (byName[p.version]) continue; // \u5DF2\u6CE8\u518C\u7248\u672C\u6C38\u4E0D\u66FF\u6362`,
|
|
669
|
+
` byName[p.version] = { version: p.version, get: p.get, from: name, eager: p.eager, loaded: false };`,
|
|
670
|
+
` }`,
|
|
671
|
+
`}`,
|
|
672
|
+
``,
|
|
673
|
+
`export async function get(moduleName) {`,
|
|
674
|
+
` const loader = exposes[moduleName];`,
|
|
675
|
+
` if (!loader) {`,
|
|
676
|
+
` const err = new Error('MFU-006: module "' + moduleName + '" is not exposed by remote "' + name + '"');`,
|
|
677
|
+
` err.code = 'MFU-006';`,
|
|
678
|
+
` throw err;`,
|
|
679
|
+
` }`,
|
|
680
|
+
` return loader();`,
|
|
681
|
+
`}`,
|
|
682
|
+
""
|
|
683
|
+
].join("\n");
|
|
684
|
+
}
|
|
685
|
+
function genDevManifest(options, base) {
|
|
686
|
+
const b = base.endsWith("/") ? base : `${base}/`;
|
|
687
|
+
return {
|
|
688
|
+
id: options.name,
|
|
689
|
+
name: options.name,
|
|
690
|
+
version: options.pkgDependencies?.["fulgurjs"] ?? "0.0.0",
|
|
691
|
+
devServer: true,
|
|
692
|
+
base: b,
|
|
693
|
+
entry: `${b}@fulgurjs-entry.js`,
|
|
694
|
+
/** 本地联调时供宿主端 dts 类型直连(见 dts.ts);远程不在本机时宿主回退 any 桩 */
|
|
695
|
+
fsRoot: options.root,
|
|
696
|
+
exposes: options.exposes.map((e) => ({
|
|
697
|
+
name: e.name,
|
|
698
|
+
src: e.import,
|
|
699
|
+
file: `${b}@fulgurjs-src/${e.import.replace(/^\.?\//, "")}`
|
|
700
|
+
})),
|
|
701
|
+
shared: options.shared.map((s) => ({
|
|
702
|
+
name: s.shareKey,
|
|
703
|
+
version: s.version,
|
|
704
|
+
singleton: s.singleton,
|
|
705
|
+
requiredVersion: s.requiredVersion,
|
|
706
|
+
shareScope: s.shareScope,
|
|
707
|
+
eager: s.eager
|
|
708
|
+
}))
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
function genProdManifest(options, exposeFiles, entryFile) {
|
|
712
|
+
return {
|
|
713
|
+
id: options.name,
|
|
714
|
+
name: options.name,
|
|
715
|
+
entry: entryFile,
|
|
716
|
+
exposes: exposeFiles,
|
|
717
|
+
shared: options.shared.map((s) => ({
|
|
718
|
+
name: s.shareKey,
|
|
719
|
+
version: s.version,
|
|
720
|
+
singleton: s.singleton,
|
|
721
|
+
requiredVersion: s.requiredVersion,
|
|
722
|
+
shareScope: s.shareScope,
|
|
723
|
+
eager: s.eager
|
|
724
|
+
})),
|
|
725
|
+
buildInfo: {
|
|
726
|
+
builtBy: "fulgurjs-federation",
|
|
727
|
+
timestamp: Date.now()
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// src/transform.ts
|
|
733
|
+
var lexerReady = null;
|
|
734
|
+
function ensureLexer() {
|
|
735
|
+
lexerReady ??= import_es_module_lexer.init;
|
|
736
|
+
return lexerReady;
|
|
737
|
+
}
|
|
738
|
+
function isExposeTargetFile(cleanPath, root, exposes) {
|
|
739
|
+
for (const e of exposes) {
|
|
740
|
+
const abs = import_node_path2.default.resolve(root, e.import.replace(/^\.\//, ""));
|
|
741
|
+
if (cleanPath === abs) return true;
|
|
742
|
+
for (const ext of [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".vue"]) {
|
|
743
|
+
if (cleanPath === abs + ext) return true;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
function buildSharedMatcher(shared) {
|
|
749
|
+
const exact = /* @__PURE__ */ new Map();
|
|
750
|
+
const prefixes = [];
|
|
751
|
+
for (const s of shared) {
|
|
752
|
+
for (const alias of s.aliases) {
|
|
753
|
+
if (!exact.has(alias)) exact.set(alias, s);
|
|
754
|
+
}
|
|
755
|
+
if (s.configKey.endsWith("/")) prefixes.push({ prefix: s.configKey, item: s });
|
|
756
|
+
}
|
|
757
|
+
return { exact, prefixes };
|
|
758
|
+
}
|
|
759
|
+
function matchShared(spec, matcher) {
|
|
760
|
+
const exact = matcher.exact.get(spec);
|
|
761
|
+
if (exact) return exact;
|
|
762
|
+
for (const p of matcher.prefixes) {
|
|
763
|
+
if (spec.startsWith(p.prefix)) return p.item;
|
|
764
|
+
}
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
function serializeShareCallForFacade(item, fallbackUrl) {
|
|
768
|
+
const opts = [];
|
|
769
|
+
opts.push(`shareScope: ${JSON.stringify(item.shareScope)}`);
|
|
770
|
+
opts.push(`shareKey: ${JSON.stringify(item.shareKey)}`);
|
|
771
|
+
if (item.requiredVersion !== false) opts.push(`requiredVersion: ${JSON.stringify(item.requiredVersion)}`);
|
|
772
|
+
if (item.singleton) opts.push("singleton: true");
|
|
773
|
+
if (item.strictVersion) opts.push("strictVersion: true");
|
|
774
|
+
if (item.import !== false) {
|
|
775
|
+
const facadeUrl = fallbackUrl ?? SHARED_FACADE_PREFIX + item.shareKey;
|
|
776
|
+
opts.push(`fallback: () => import(${JSON.stringify(facadeUrl)})`);
|
|
777
|
+
}
|
|
778
|
+
return `__fulgurjs_loadShare(${JSON.stringify(item.shareKey)}, { ${opts.join(", ")} })`;
|
|
779
|
+
}
|
|
780
|
+
function serializeShareCall(item, devUrls) {
|
|
781
|
+
const opts = [];
|
|
782
|
+
opts.push(`shareScope: ${JSON.stringify(item.shareScope)}`);
|
|
783
|
+
opts.push(`shareKey: ${JSON.stringify(item.shareKey)}`);
|
|
784
|
+
if (item.requiredVersion !== false) opts.push(`requiredVersion: ${JSON.stringify(item.requiredVersion)}`);
|
|
785
|
+
if (item.singleton) opts.push("singleton: true");
|
|
786
|
+
if (item.strictVersion) opts.push("strictVersion: true");
|
|
787
|
+
if (item.import !== false) {
|
|
788
|
+
const facadeUrl = devUrls ? devUrls.namespaceFacade(item.shareKey) : SHARED_FACADE_PREFIX + item.shareKey;
|
|
789
|
+
opts.push(`fallback: () => import(${JSON.stringify(facadeUrl)})`);
|
|
790
|
+
}
|
|
791
|
+
return `__fulgurjs_loadShare(${JSON.stringify(item.shareKey)}, { ${opts.join(", ")} })`;
|
|
792
|
+
}
|
|
793
|
+
function stripComments(s) {
|
|
794
|
+
return s.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
|
|
795
|
+
}
|
|
796
|
+
function parseBindings(inner) {
|
|
797
|
+
const out = [];
|
|
798
|
+
for (const piece of stripComments(inner).split(",")) {
|
|
799
|
+
const raw = piece.trim();
|
|
800
|
+
if (!raw) continue;
|
|
801
|
+
if (/^type\s/.test(raw)) continue;
|
|
802
|
+
const asMatch = raw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
803
|
+
const imported = asMatch ? asMatch[1].trim() : raw;
|
|
804
|
+
const local = asMatch ? asMatch[2].trim() : raw;
|
|
805
|
+
out.push({ imported, local, isDefault: imported === "default" });
|
|
806
|
+
}
|
|
807
|
+
return out;
|
|
808
|
+
}
|
|
809
|
+
function parseImportClause(clause) {
|
|
810
|
+
const nsMatch = clause.match(/\*\s+as\s+(\w+)/);
|
|
811
|
+
const braceStart = clause.indexOf("{");
|
|
812
|
+
const bindings = braceStart !== -1 ? parseBindings(clause.slice(braceStart + 1, clause.lastIndexOf("}"))) : null;
|
|
813
|
+
let head = clause.replace(/^\s*import\s*/, "");
|
|
814
|
+
if (braceStart !== -1) head = head.slice(0, head.indexOf("{"));
|
|
815
|
+
if (nsMatch) head = head.slice(0, head.indexOf("*"));
|
|
816
|
+
const defaultLocal = head.replace(/,\s*$/, "").trim() || null;
|
|
817
|
+
return { ns: nsMatch?.[1] ?? null, bindings, defaultLocal };
|
|
818
|
+
}
|
|
819
|
+
var JS_EXT_RE = /\.(m|c)?[jt]sx?$/;
|
|
820
|
+
function isTransformableId(id, allowNodeModules = false) {
|
|
821
|
+
const clean = id.split("?")[0];
|
|
822
|
+
if (!JS_EXT_RE.test(clean) && !clean.endsWith(".vue")) return false;
|
|
823
|
+
if (clean.includes("node_modules") && !allowNodeModules) return false;
|
|
824
|
+
return true;
|
|
825
|
+
}
|
|
826
|
+
function isPluginProcessedModule(code) {
|
|
827
|
+
return code.includes("virtual:fulgurjs-runtime-proxy") || code.includes("__fulgurjs_loadRemote") || code.includes("__fulgurjs_loadShare") || code.includes(INIT_MODULE_MARKER);
|
|
828
|
+
}
|
|
829
|
+
var facadeRegistry = /* @__PURE__ */ new Map();
|
|
830
|
+
function shortSig(kind, key, bindings) {
|
|
831
|
+
const full = kind + "|" + key + "|" + bindings.join("|");
|
|
832
|
+
let h = 5381;
|
|
833
|
+
for (let i = 0; i < full.length; i++) h = (h << 5) + h + full.charCodeAt(i) | 0;
|
|
834
|
+
const id = (h >>> 0).toString(36) + bindings.length.toString(36);
|
|
835
|
+
facadeRegistry.set(id, kind === "shared" ? { bindings, shareKey: key } : { bindings, remoteName: key });
|
|
836
|
+
return id;
|
|
837
|
+
}
|
|
838
|
+
function getFacadeEntry(id) {
|
|
839
|
+
return facadeRegistry.get(id);
|
|
840
|
+
}
|
|
841
|
+
function canonicalBindings(bindings) {
|
|
842
|
+
const names = /* @__PURE__ */ new Set();
|
|
843
|
+
for (const bRaw of bindings) {
|
|
844
|
+
if (bRaw === "default") continue;
|
|
845
|
+
const asMatch = bRaw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
846
|
+
names.add((asMatch ? asMatch[1] : bRaw).trim());
|
|
847
|
+
}
|
|
848
|
+
return [...names].sort();
|
|
849
|
+
}
|
|
850
|
+
function bindingFacadeId(item, bindings) {
|
|
851
|
+
const canonical = canonicalBindings(bindings);
|
|
852
|
+
const sig = canonical.length ? `?f=${shortSig("shared", item.shareKey, canonical)}` : "";
|
|
853
|
+
return `${SHARED_FACADE_PREFIX}${item.shareKey}${sig}`;
|
|
854
|
+
}
|
|
855
|
+
function facadeSpecFor(ctx, item, bindings) {
|
|
520
856
|
const id = bindingFacadeId(item, bindings);
|
|
521
857
|
return ctx.devUrls ? ctx.devUrls.bindingFacade(id) : id;
|
|
522
858
|
}
|
|
@@ -546,7 +882,7 @@ async function transformModule(code, id, ctx) {
|
|
|
546
882
|
for (const [alias, item] of sharedByAlias) {
|
|
547
883
|
const re = new RegExp(`require\\((["'])${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\1\\)`, "g");
|
|
548
884
|
if (!re.test(code)) continue;
|
|
549
|
-
code = code.replace(re, `require(${JSON.stringify(`virtual:
|
|
885
|
+
code = code.replace(re, `require(${JSON.stringify(`virtual:fulgurjs-cjs-ns:${item.shareKey}`)})`);
|
|
550
886
|
cjsEdited = true;
|
|
551
887
|
}
|
|
552
888
|
if (!cjsEdited) return null;
|
|
@@ -567,7 +903,7 @@ async function transformModule(code, id, ctx) {
|
|
|
567
903
|
let usesRuntimeHelpers = false;
|
|
568
904
|
const tlaLines = [];
|
|
569
905
|
let tempIdx = 0;
|
|
570
|
-
const genTemp = () => `
|
|
906
|
+
const genTemp = () => `__fulgurjs_m${tempIdx++}`;
|
|
571
907
|
const remap = (spec) => ctx.remapSpecifier?.(spec) ?? spec;
|
|
572
908
|
const remoteExposeName = (spec, remoteKey) => {
|
|
573
909
|
if (!spec.startsWith(`${remoteKey}/`)) return null;
|
|
@@ -581,7 +917,7 @@ async function transformModule(code, id, ctx) {
|
|
|
581
917
|
];
|
|
582
918
|
const genTlaOverwrite = (stmtStart, stmtEnd, shared, remoteName, exposeName, clauseRaw, clause) => {
|
|
583
919
|
usesRuntimeHelpers = true;
|
|
584
|
-
const call = shared ? serializeShareCall(shared, ctx?.devUrls) : `
|
|
920
|
+
const call = shared ? serializeShareCall(shared, ctx?.devUrls) : `__fulgurjs_loadRemote(${JSON.stringify(`${remoteName}/${exposeName}`)})`;
|
|
585
921
|
const nsAs = clauseRaw.match(/export\s+\*\s+as\s+(\w+)\s+from/);
|
|
586
922
|
if (nsAs) {
|
|
587
923
|
s.overwrite(stmtStart, stmtEnd, `const ${nsAs[1]} = await ${call};
|
|
@@ -595,14 +931,14 @@ export { ${nsAs[1]} };`);
|
|
|
595
931
|
const tmp = genTemp();
|
|
596
932
|
const parts = [`${tmp} = await ${call}`];
|
|
597
933
|
if (clause.ns) parts.push(`${clause.ns} = ${tmp}`);
|
|
598
|
-
if (clause.defaultLocal) parts.push(`${clause.defaultLocal} =
|
|
934
|
+
if (clause.defaultLocal) parts.push(`${clause.defaultLocal} = __fulgurjsU(${tmp})`);
|
|
599
935
|
const named = clause.bindings?.filter((b) => !b.isDefault) ?? [];
|
|
600
936
|
if (named.length) {
|
|
601
937
|
const destructure = named.map((b) => b.imported === b.local ? b.local : `${b.imported}: ${b.local}`);
|
|
602
938
|
parts.push(`{ ${destructure.join(", ")} } = ${tmp}`);
|
|
603
939
|
}
|
|
604
940
|
for (const b of clause.bindings?.filter((x) => x.isDefault) ?? []) {
|
|
605
|
-
parts.push(`${b.local} =
|
|
941
|
+
parts.push(`${b.local} = __fulgurjsU(${tmp})`);
|
|
606
942
|
}
|
|
607
943
|
s.overwrite(stmtStart, stmtEnd, `const ${parts.join(", ")}`);
|
|
608
944
|
};
|
|
@@ -634,7 +970,7 @@ export { ${nsAs[1]} };`);
|
|
|
634
970
|
const inner = clauseRaw.slice(clauseRaw.indexOf("{") + 1, clauseRaw.lastIndexOf("}"));
|
|
635
971
|
if (/export\s+\*/.test(clauseRaw) && !clauseRaw.includes("{")) {
|
|
636
972
|
throw new Error(
|
|
637
|
-
`[
|
|
973
|
+
`[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
974
|
);
|
|
639
975
|
}
|
|
640
976
|
const bindings = parseBindings(inner).map((b) => b.imported === "default" ? "default" : b.imported);
|
|
@@ -665,351 +1001,21 @@ export { ${nsAs[1]} };`);
|
|
|
665
1001
|
s.overwrite(
|
|
666
1002
|
callStart,
|
|
667
1003
|
closeParen + 1,
|
|
668
|
-
`
|
|
1004
|
+
`__fulgurjs_loadRemote(${JSON.stringify(`${remote.name}/${exposeName}`)})`
|
|
669
1005
|
);
|
|
670
1006
|
}
|
|
671
1007
|
}
|
|
672
1008
|
if (!edited) return null;
|
|
673
1009
|
if (usesRuntimeHelpers) {
|
|
674
|
-
const runtimeSpec = JSON.stringify(ctx.devUrls?.runtime ?? "virtual:
|
|
1010
|
+
const runtimeSpec = JSON.stringify(ctx.devUrls?.runtime ?? "virtual:fulgurjs-runtime");
|
|
675
1011
|
s.prepend(
|
|
676
|
-
`import { loadShare as
|
|
1012
|
+
`import { loadShare as __fulgurjs_loadShare, loadRemote as __fulgurjs_loadRemote, unwrapDefault as __fulgurjsU } from ${runtimeSpec};
|
|
677
1013
|
`
|
|
678
1014
|
);
|
|
679
1015
|
}
|
|
680
1016
|
return { code: s.toString(), map: null };
|
|
681
1017
|
}
|
|
682
1018
|
|
|
683
|
-
// src/virtual.ts
|
|
684
|
-
function jsonReplacer(_k, v) {
|
|
685
|
-
return v;
|
|
686
|
-
}
|
|
687
|
-
function genSharedFacade(specifier, exportNames) {
|
|
688
|
-
const names = (exportNames ?? []).filter(
|
|
689
|
-
(n) => n !== "default" && /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n)
|
|
690
|
-
);
|
|
691
|
-
if (names.length === 0) {
|
|
692
|
-
return [
|
|
693
|
-
`import * as __fulgur_facade from ${JSON.stringify(specifier)};`,
|
|
694
|
-
`export * from ${JSON.stringify(specifier)};`,
|
|
695
|
-
`export default __fulgur_facade.default ?? __fulgur_facade;`,
|
|
696
|
-
""
|
|
697
|
-
].join("\n");
|
|
698
|
-
}
|
|
699
|
-
return [
|
|
700
|
-
`import * as __fulgur_facade from ${JSON.stringify(specifier)};`,
|
|
701
|
-
...names.map((n) => `export const ${n} = __fulgur_facade[${JSON.stringify(n)}];`),
|
|
702
|
-
`export default __fulgur_facade.default ?? __fulgur_facade;`,
|
|
703
|
-
""
|
|
704
|
-
].join("\n");
|
|
705
|
-
}
|
|
706
|
-
function genSharedNsFacade(item, loadShareCall, exportNames) {
|
|
707
|
-
const lines = [
|
|
708
|
-
`import { loadShare as __fulgur_loadShare, unwrapDefault as __fulgurU } from "virtual:fulgur-runtime";`,
|
|
709
|
-
`const __fulgur_m = await ${loadShareCall};`,
|
|
710
|
-
`const __fulgur_d = __fulgurU(__fulgur_m);`,
|
|
711
|
-
`export default __fulgur_d;`
|
|
712
|
-
];
|
|
713
|
-
const seen = /* @__PURE__ */ new Set(["default"]);
|
|
714
|
-
for (const name of exportNames) {
|
|
715
|
-
if (seen.has(name) || !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name)) continue;
|
|
716
|
-
seen.add(name);
|
|
717
|
-
lines.push(`export const ${name} = __fulgur_d[${JSON.stringify(name)}];`);
|
|
718
|
-
}
|
|
719
|
-
lines.push("");
|
|
720
|
-
return lines.join("\n");
|
|
721
|
-
}
|
|
722
|
-
function genBindingFacade(item, bindings, loadShareCall) {
|
|
723
|
-
const lines = [
|
|
724
|
-
`import { loadShare as __fulgur_loadShare, unwrapDefault as __fulgurU } from "virtual:fulgur-runtime";`,
|
|
725
|
-
`const __fulgur_m = await ${loadShareCall};`
|
|
726
|
-
];
|
|
727
|
-
const seen = /* @__PURE__ */ new Set();
|
|
728
|
-
for (const bRaw of bindings) {
|
|
729
|
-
if (bRaw === "default") continue;
|
|
730
|
-
const asMatch = bRaw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
731
|
-
const imported = (asMatch ? asMatch[1] : bRaw).trim();
|
|
732
|
-
if (seen.has(imported)) continue;
|
|
733
|
-
seen.add(imported);
|
|
734
|
-
lines.push(`export const ${imported} = __fulgur_m.${imported};`);
|
|
735
|
-
}
|
|
736
|
-
lines.push(`export default __fulgurU(__fulgur_m);`);
|
|
737
|
-
lines.push("");
|
|
738
|
-
return lines.join("\n");
|
|
739
|
-
}
|
|
740
|
-
function genRemoteBindingFacade(remoteSpec, bindings) {
|
|
741
|
-
const lines = [
|
|
742
|
-
`import { loadRemote as __fulgur_loadRemote, unwrapDefault as __fulgurU } from "virtual:fulgur-runtime";`,
|
|
743
|
-
`const __fulgur_m = await __fulgur_loadRemote(${JSON.stringify(remoteSpec)});`
|
|
744
|
-
];
|
|
745
|
-
const seen = /* @__PURE__ */ new Set();
|
|
746
|
-
for (const bRaw of bindings) {
|
|
747
|
-
if (bRaw === "default") continue;
|
|
748
|
-
const asMatch = bRaw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
749
|
-
const imported = (asMatch ? asMatch[1] : bRaw).trim();
|
|
750
|
-
if (seen.has(imported)) continue;
|
|
751
|
-
seen.add(imported);
|
|
752
|
-
lines.push(`export const ${imported} = __fulgur_m.${imported};`);
|
|
753
|
-
}
|
|
754
|
-
lines.push(`export default __fulgurU(__fulgur_m);`);
|
|
755
|
-
lines.push("");
|
|
756
|
-
return lines.join("\n");
|
|
757
|
-
}
|
|
758
|
-
function providesRecords(options) {
|
|
759
|
-
return options.shared.filter((s) => s.import !== false).map((s) => ({
|
|
760
|
-
shareScope: s.shareScope,
|
|
761
|
-
name: s.shareKey,
|
|
762
|
-
version: s.version,
|
|
763
|
-
eager: s.eager,
|
|
764
|
-
from: options.name
|
|
765
|
-
}));
|
|
766
|
-
}
|
|
767
|
-
function genInitModule(options, command) {
|
|
768
|
-
const lines = [];
|
|
769
|
-
lines.push(`import { initSharing, registerShare, registerRemotes, registerPlugins } from "virtual:fulgur-runtime";`);
|
|
770
|
-
const provides = providesRecords(options);
|
|
771
|
-
const eagerShared = options.shared.filter((s) => s.eager && s.import !== false);
|
|
772
|
-
eagerShared.forEach((s, i) => {
|
|
773
|
-
lines.push(`import * as __fulgur_eager_${i} from "virtual:fulgur-shared:${s.shareKey}";`);
|
|
774
|
-
});
|
|
775
|
-
const isDevHost = command === "serve" && options.remotes.length > 0;
|
|
776
|
-
const loadedFlag = isDevHost ? "true" : "false";
|
|
777
|
-
lines.push(`initSharing(${JSON.stringify(options.shareScope)});`);
|
|
778
|
-
if (options.runtimePlugins.length > 0) {
|
|
779
|
-
options.runtimePlugins.forEach((p, i) => {
|
|
780
|
-
lines.push(`import * as __fulgur_rp_${i} from ${JSON.stringify(p)};`);
|
|
781
|
-
});
|
|
782
|
-
lines.push(
|
|
783
|
-
`registerPlugins([${options.runtimePlugins.map((_, i) => `(__fulgur_rp_${i}.default ?? __fulgur_rp_${i})`).join(", ")}]);`
|
|
784
|
-
);
|
|
785
|
-
}
|
|
786
|
-
if (options.remotes.length > 0) {
|
|
787
|
-
lines.push(...registerRemotesLines(options, command));
|
|
788
|
-
}
|
|
789
|
-
provides.forEach((p) => {
|
|
790
|
-
const eagerIdx = eagerShared.findIndex((s) => s.shareKey === p.name && s.shareScope === p.shareScope);
|
|
791
|
-
if (p.eager && eagerIdx !== -1) {
|
|
792
|
-
lines.push(
|
|
793
|
-
`registerShare(${JSON.stringify(p.shareScope)}, ${JSON.stringify(p.name)}, ${JSON.stringify(p.version)}, () => Promise.resolve(__fulgur_eager_${eagerIdx}), { from: ${JSON.stringify(p.from)}, eager: true, loaded: ${loadedFlag} });`
|
|
794
|
-
);
|
|
795
|
-
} else {
|
|
796
|
-
lines.push(
|
|
797
|
-
`registerShare(${JSON.stringify(p.shareScope)}, ${JSON.stringify(p.name)}, ${JSON.stringify(p.version)}, () => import("virtual:fulgur-shared:${p.name}"), { from: ${JSON.stringify(p.from)}, eager: false, loaded: ${loadedFlag} });`
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
});
|
|
801
|
-
return `${lines.join("\n")}
|
|
802
|
-
`;
|
|
803
|
-
}
|
|
804
|
-
function manifestUrlFor(r, command) {
|
|
805
|
-
const entry = command === "serve" ? r.devEntry : r.prodEntry;
|
|
806
|
-
if (!entry) return null;
|
|
807
|
-
try {
|
|
808
|
-
const u = new URL(entry);
|
|
809
|
-
if (u.pathname.includes("@fulgur-entry.js")) {
|
|
810
|
-
u.pathname = u.pathname.replace("@fulgur-entry.js", "@fulgur-manifest.json");
|
|
811
|
-
} else {
|
|
812
|
-
u.pathname = u.pathname.replace(/[^/]*$/, "") + "fulgur-manifest.json";
|
|
813
|
-
}
|
|
814
|
-
return u.href;
|
|
815
|
-
} catch {
|
|
816
|
-
return null;
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
function registerRemotesLines(options, command) {
|
|
820
|
-
if (options.remotes.length === 0) return [];
|
|
821
|
-
const remotesJson = options.remotes.filter((r) => !r.promise).map((r) => ({
|
|
822
|
-
name: r.name,
|
|
823
|
-
entry: command === "serve" ? r.devEntry : r.prodEntry,
|
|
824
|
-
shareScope: r.shareScope,
|
|
825
|
-
timeout: r.timeout,
|
|
826
|
-
retries: r.retries,
|
|
827
|
-
fallback: r.fallback,
|
|
828
|
-
breaker: r.breaker,
|
|
829
|
-
manifestUrl: manifestUrlFor(r, command)
|
|
830
|
-
}));
|
|
831
|
-
if (remotesJson.length === 0) return [];
|
|
832
|
-
return [
|
|
833
|
-
`registerRemotes(${JSON.stringify(remotesJson, jsonReplacer).replace(/"manifestUrl":null,?/g, "")});`
|
|
834
|
-
];
|
|
835
|
-
}
|
|
836
|
-
function genRuntimeProxyModule() {
|
|
837
|
-
const promiseApis = [
|
|
838
|
-
"loadRemote",
|
|
839
|
-
"loadShare",
|
|
840
|
-
"preloadRemote",
|
|
841
|
-
"getContainer",
|
|
842
|
-
"registerRemote",
|
|
843
|
-
"registerRemotes",
|
|
844
|
-
"registerShare",
|
|
845
|
-
"initSharing",
|
|
846
|
-
"registerPlugins",
|
|
847
|
-
"parseSpec"
|
|
848
|
-
];
|
|
849
|
-
const lines = [
|
|
850
|
-
`let __fulgur_mod_p;`,
|
|
851
|
-
`const __fulgur_rt = async () => {`,
|
|
852
|
-
` __fulgur_mod_p ??= import('virtual:fulgur-runtime');`,
|
|
853
|
-
` return await __fulgur_mod_p;`,
|
|
854
|
-
`};`,
|
|
855
|
-
...promiseApis.map((m) => `export const ${m} = (...a) => __fulgur_rt().then((m2) => m2.${m}(...a));`),
|
|
856
|
-
`export const getRuntime = () => (globalThis).__FULGUR_RUNTIME__;`,
|
|
857
|
-
`export const getFulgurAppConfig = () =>`,
|
|
858
|
-
` (globalThis).__FULGUR_RUNTIME__?.getFulgurAppConfig?.() ?? (globalThis).__FULGUR_APP_CONFIG__ ?? {};`,
|
|
859
|
-
`export const provideFulgurAppConfig = (c) => {`,
|
|
860
|
-
` const g = (globalThis);`,
|
|
861
|
-
` g.__FULGUR_APP_CONFIG__ = { ...(g.__FULGUR_APP_CONFIG__ ?? {}), ...c };`,
|
|
862
|
-
` g.__FULGUR_RUNTIME__?.provideFulgurAppConfig?.(c);`,
|
|
863
|
-
`};`,
|
|
864
|
-
`export const unwrapDefault = (ns) =>`,
|
|
865
|
-
` ns && typeof ns === 'object' && 'default' in ns ? (ns.default !== undefined ? ns.default : ns) : ns;`,
|
|
866
|
-
`export const version = (globalThis).__FULGUR_RUNTIME__?.version;`,
|
|
867
|
-
`export default { get runtime() { return (globalThis).__FULGUR_RUNTIME__; } };`,
|
|
868
|
-
``
|
|
869
|
-
];
|
|
870
|
-
return lines.join("\n");
|
|
871
|
-
}
|
|
872
|
-
function genDevRemoteEntry(options, base) {
|
|
873
|
-
const b = base.endsWith("/") ? base : `${base}/`;
|
|
874
|
-
const remoteLines = registerRemotesLines(options, "serve");
|
|
875
|
-
return `import ${JSON.stringify(`${b}@vite/client`)};
|
|
876
|
-
import { name as _fulgur_name, exposes, provides } from ${JSON.stringify(`${b}@id/__x00__virtual:fulgur-provides`)};
|
|
877
|
-
${remoteLines.length > 0 ? `import { registerRemotes } from ${JSON.stringify(`${b}@id/virtual:fulgur-runtime`)};
|
|
878
|
-
${remoteLines.join("\n")}` : ""}
|
|
879
|
-
|
|
880
|
-
export const name = _fulgur_name;
|
|
881
|
-
|
|
882
|
-
export async function init(shareScopeMap) {
|
|
883
|
-
for (const p of provides) {
|
|
884
|
-
const scope = shareScopeMap[p.shareScope] || (shareScopeMap[p.shareScope] = {});
|
|
885
|
-
const byName = scope[p.name] || (scope[p.name] = {});
|
|
886
|
-
if (byName[p.version]) continue; // \u5DF2\u6CE8\u518C\u7248\u672C\u6C38\u4E0D\u66FF\u6362
|
|
887
|
-
byName[p.version] = { version: p.version, get: p.get, from: name, eager: p.eager, loaded: false };
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
export async function get(moduleName) {
|
|
892
|
-
const loader = exposes[moduleName];
|
|
893
|
-
if (!loader) {
|
|
894
|
-
const err = new Error('MFU-006: module "' + moduleName + '" is not exposed by remote "' + name + '"');
|
|
895
|
-
err.code = 'MFU-006';
|
|
896
|
-
throw err;
|
|
897
|
-
}
|
|
898
|
-
return loader();
|
|
899
|
-
}
|
|
900
|
-
`;
|
|
901
|
-
}
|
|
902
|
-
function genDevProvides(options) {
|
|
903
|
-
const exposes = [];
|
|
904
|
-
for (const e of options.exposes) {
|
|
905
|
-
const devUrl = `/${e.import.replace(/^\.?\//, "")}`;
|
|
906
|
-
exposes.push(
|
|
907
|
-
` ${JSON.stringify(e.name)}: () => import(${JSON.stringify(devUrl)}),`
|
|
908
|
-
);
|
|
909
|
-
}
|
|
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:fulgur-shared:${p.name}") },`
|
|
912
|
-
);
|
|
913
|
-
return [
|
|
914
|
-
`export const name = ${JSON.stringify(options.name)};`,
|
|
915
|
-
`export const exposes = {`,
|
|
916
|
-
...exposes,
|
|
917
|
-
`};`,
|
|
918
|
-
`export const provides = [`,
|
|
919
|
-
...provides,
|
|
920
|
-
`];`,
|
|
921
|
-
""
|
|
922
|
-
].join("\n");
|
|
923
|
-
}
|
|
924
|
-
function genBuildRemoteEntry(options, exposeAbsPaths) {
|
|
925
|
-
const exposes = [];
|
|
926
|
-
for (const e of options.exposes) {
|
|
927
|
-
const abs = exposeAbsPaths[e.import];
|
|
928
|
-
if (!abs) continue;
|
|
929
|
-
exposes.push(` ${JSON.stringify(e.name)}: () => import(${JSON.stringify(abs)}),`);
|
|
930
|
-
}
|
|
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:fulgur-shared:${p.name}") },`
|
|
933
|
-
);
|
|
934
|
-
const remoteLines = registerRemotesLines(options, "build");
|
|
935
|
-
return [
|
|
936
|
-
...remoteLines.length > 0 ? [`import { registerRemotes } from "virtual:fulgur-runtime";`, ...remoteLines] : [],
|
|
937
|
-
`const exposes = {`,
|
|
938
|
-
...exposes,
|
|
939
|
-
`};`,
|
|
940
|
-
`const provides = [`,
|
|
941
|
-
...provides,
|
|
942
|
-
`];`,
|
|
943
|
-
`export const name = ${JSON.stringify(options.name)};`,
|
|
944
|
-
``,
|
|
945
|
-
`export async function init(shareScopeMap) {`,
|
|
946
|
-
` for (const p of provides) {`,
|
|
947
|
-
` const scope = shareScopeMap[p.shareScope] || (shareScopeMap[p.shareScope] = {});`,
|
|
948
|
-
` const byName = scope[p.name] || (scope[p.name] = {});`,
|
|
949
|
-
` if (byName[p.version]) continue; // \u5DF2\u6CE8\u518C\u7248\u672C\u6C38\u4E0D\u66FF\u6362`,
|
|
950
|
-
` byName[p.version] = { version: p.version, get: p.get, from: name, eager: p.eager, loaded: false };`,
|
|
951
|
-
` }`,
|
|
952
|
-
`}`,
|
|
953
|
-
``,
|
|
954
|
-
`export async function get(moduleName) {`,
|
|
955
|
-
` const loader = exposes[moduleName];`,
|
|
956
|
-
` if (!loader) {`,
|
|
957
|
-
` const err = new Error('MFU-006: module "' + moduleName + '" is not exposed by remote "' + name + '"');`,
|
|
958
|
-
` err.code = 'MFU-006';`,
|
|
959
|
-
` throw err;`,
|
|
960
|
-
` }`,
|
|
961
|
-
` return loader();`,
|
|
962
|
-
`}`,
|
|
963
|
-
""
|
|
964
|
-
].join("\n");
|
|
965
|
-
}
|
|
966
|
-
function genDevManifest(options, base) {
|
|
967
|
-
const b = base.endsWith("/") ? base : `${base}/`;
|
|
968
|
-
return {
|
|
969
|
-
id: options.name,
|
|
970
|
-
name: options.name,
|
|
971
|
-
version: options.pkgDependencies?.["fulgur"] ?? "0.0.0",
|
|
972
|
-
devServer: true,
|
|
973
|
-
base: b,
|
|
974
|
-
entry: `${b}@fulgur-entry.js`,
|
|
975
|
-
/** 本地联调时供宿主端 dts 类型直连(见 dts.ts);远程不在本机时宿主回退 any 桩 */
|
|
976
|
-
fsRoot: options.root,
|
|
977
|
-
exposes: options.exposes.map((e) => ({
|
|
978
|
-
name: e.name,
|
|
979
|
-
src: e.import,
|
|
980
|
-
file: `${b}@fulgur-src/${e.import.replace(/^\.?\//, "")}`
|
|
981
|
-
})),
|
|
982
|
-
shared: options.shared.map((s) => ({
|
|
983
|
-
name: s.shareKey,
|
|
984
|
-
version: s.version,
|
|
985
|
-
singleton: s.singleton,
|
|
986
|
-
requiredVersion: s.requiredVersion,
|
|
987
|
-
shareScope: s.shareScope,
|
|
988
|
-
eager: s.eager
|
|
989
|
-
}))
|
|
990
|
-
};
|
|
991
|
-
}
|
|
992
|
-
function genProdManifest(options, exposeFiles, entryFile) {
|
|
993
|
-
return {
|
|
994
|
-
id: options.name,
|
|
995
|
-
name: options.name,
|
|
996
|
-
entry: entryFile,
|
|
997
|
-
exposes: exposeFiles,
|
|
998
|
-
shared: options.shared.map((s) => ({
|
|
999
|
-
name: s.shareKey,
|
|
1000
|
-
version: s.version,
|
|
1001
|
-
singleton: s.singleton,
|
|
1002
|
-
requiredVersion: s.requiredVersion,
|
|
1003
|
-
shareScope: s.shareScope,
|
|
1004
|
-
eager: s.eager
|
|
1005
|
-
})),
|
|
1006
|
-
buildInfo: {
|
|
1007
|
-
builtBy: "fulgur-federation",
|
|
1008
|
-
timestamp: Date.now()
|
|
1009
|
-
}
|
|
1010
|
-
};
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
1019
|
// src/dts.ts
|
|
1014
1020
|
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
1015
1021
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
@@ -1017,7 +1023,7 @@ async function fetchManifest(devEntry, attempts = 30, delayMs = 2e3) {
|
|
|
1017
1023
|
let manifestUrl;
|
|
1018
1024
|
try {
|
|
1019
1025
|
const u = new URL(devEntry);
|
|
1020
|
-
u.pathname = u.pathname.replace("@
|
|
1026
|
+
u.pathname = u.pathname.replace("@fulgurjs-entry.js", "@fulgurjs-manifest.json");
|
|
1021
1027
|
manifestUrl = u;
|
|
1022
1028
|
} catch {
|
|
1023
1029
|
return null;
|
|
@@ -1043,7 +1049,7 @@ function sourceHasDefaultExport(file) {
|
|
|
1043
1049
|
async function generateDevTypes(options, _server) {
|
|
1044
1050
|
const dtsOpt = options.dts === void 0 ? true : options.dts;
|
|
1045
1051
|
if (dtsOpt === false) return;
|
|
1046
|
-
const defaultDir = import_node_fs2.default.existsSync(import_node_path3.default.join(options.root, "src")) ? "src/
|
|
1052
|
+
const defaultDir = import_node_fs2.default.existsSync(import_node_path3.default.join(options.root, "src")) ? "src/fulgurjs-types" : "fulgurjs-types";
|
|
1047
1053
|
const dir = typeof dtsOpt === "object" ? dtsOpt.dir ?? defaultDir : defaultDir;
|
|
1048
1054
|
const outDir = import_node_path3.default.join(options.root, dir);
|
|
1049
1055
|
import_node_fs2.default.mkdirSync(outDir, { recursive: true });
|
|
@@ -1051,18 +1057,18 @@ async function generateDevTypes(options, _server) {
|
|
|
1051
1057
|
if (!remote.devEntry || remote.promise) continue;
|
|
1052
1058
|
const manifest = await fetchManifest(remote.devEntry);
|
|
1053
1059
|
if (!manifest || !manifest.exposes) {
|
|
1054
|
-
console.warn(`[
|
|
1060
|
+
console.warn(`[fulgurjs] dts: remote "${remote.key}" dev manifest unavailable; type mapping skipped.`);
|
|
1055
1061
|
continue;
|
|
1056
1062
|
}
|
|
1057
1063
|
const remoteRoot = manifest.fsRoot;
|
|
1058
1064
|
if (!remoteRoot || !import_node_fs2.default.existsSync(remoteRoot)) {
|
|
1059
1065
|
console.warn(
|
|
1060
|
-
`[
|
|
1066
|
+
`[fulgurjs] dts: remote "${remote.key}" is not on this machine; type mapping skipped (module types fall back to any).`
|
|
1061
1067
|
);
|
|
1062
1068
|
continue;
|
|
1063
1069
|
}
|
|
1064
1070
|
const lines = [
|
|
1065
|
-
`// \u81EA\u52A8\u751F\u6210\
|
|
1071
|
+
`// \u81EA\u52A8\u751F\u6210\uFF1Afulgurjs-federation dev \u7C7B\u578B\u76F4\u8FDE\uFF08remote: ${remote.name}\uFF09`,
|
|
1066
1072
|
`// \u91CD\u65B0\u751F\u6210\uFF1A\u91CD\u542F host dev server`
|
|
1067
1073
|
];
|
|
1068
1074
|
for (const expose of manifest.exposes ?? []) {
|
|
@@ -1089,16 +1095,16 @@ async function generateDevTypes(options, _server) {
|
|
|
1089
1095
|
import_node_fs2.default.writeFileSync(import_node_path3.default.join(outDir, `${remote.key}.d.ts`), `${lines.join("\n")}
|
|
1090
1096
|
`);
|
|
1091
1097
|
console.log(
|
|
1092
|
-
`[
|
|
1098
|
+
`[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
1099
|
);
|
|
1094
1100
|
}
|
|
1095
1101
|
}
|
|
1096
1102
|
|
|
1097
1103
|
// src/diagnostics.ts
|
|
1098
|
-
function
|
|
1104
|
+
function formatFulgurjsDiagnostic(input) {
|
|
1099
1105
|
const ctx = input.details ? `
|
|
1100
1106
|
\u4E0A\u4E0B\u6587\uFF1A${JSON.stringify(input.details)}` : "";
|
|
1101
|
-
return `[
|
|
1107
|
+
return `[fulgurjs:${input.code}] ${input.symptom}
|
|
1102
1108
|
\u6839\u56E0\uFF1A${input.cause}
|
|
1103
1109
|
\u4FEE\u6CD5\uFF1A${input.fix}` + ctx;
|
|
1104
1110
|
}
|
|
@@ -1122,7 +1128,7 @@ async function isPortReachable(host, port, timeoutMs = 800) {
|
|
|
1122
1128
|
function manifestUrlOf(devEntry) {
|
|
1123
1129
|
try {
|
|
1124
1130
|
const u = new URL(devEntry);
|
|
1125
|
-
u.pathname = u.pathname.replace("@
|
|
1131
|
+
u.pathname = u.pathname.replace("@fulgurjs-entry.js", "@fulgurjs-manifest.json");
|
|
1126
1132
|
return u;
|
|
1127
1133
|
} catch {
|
|
1128
1134
|
return null;
|
|
@@ -1148,7 +1154,7 @@ async function probeRemotesAndBuildSchema(options) {
|
|
|
1148
1154
|
schema[remote.key] = { exposes, exists: true };
|
|
1149
1155
|
if (exposes.length === 0) {
|
|
1150
1156
|
console.warn(
|
|
1151
|
-
|
|
1157
|
+
formatFulgurjsDiagnostic({
|
|
1152
1158
|
code: "DEV-002",
|
|
1153
1159
|
symptom: `remote "${remote.key}" \u7684 dev manifest \u53EF\u8FBE\u4F46 exposes \u4E3A\u7A7A\uFF08${u.href}\uFF09`,
|
|
1154
1160
|
cause: "remote \u4FA7 federation({ exposes }) \u4E3A\u7A7A\uFF0C\u6216\u5176\u63D2\u4EF6\u7248\u672C\u8FC7\u65E7\u5BFC\u81F4 manifest \u7F3A\u5B57\u6BB5",
|
|
@@ -1160,7 +1166,7 @@ async function probeRemotesAndBuildSchema(options) {
|
|
|
1160
1166
|
const remoteVersion = manifest?.buildInfo?.version;
|
|
1161
1167
|
if (remoteVersion && remoteVersion !== options.pluginVersion) {
|
|
1162
1168
|
console.warn(
|
|
1163
|
-
|
|
1169
|
+
formatFulgurjsDiagnostic({
|
|
1164
1170
|
code: "DEV-006",
|
|
1165
1171
|
symptom: `\u5BBF\u4E3B\u4E0E remote "${remote.key}" \u7684 @fulgurjs/federation \u7248\u672C\u4E0D\u4E00\u81F4`,
|
|
1166
1172
|
cause: `\u5BBF\u4E3B ${options.pluginVersion} vs \u8FDC\u7A0B ${remoteVersion}\uFF08pnpm tarball \u65AD\u94FE/\u6F0F\u5347\u7EA7\u5E38\u89C1\uFF09`,
|
|
@@ -1174,7 +1180,7 @@ async function probeRemotesAndBuildSchema(options) {
|
|
|
1174
1180
|
const port = u.port ? Number(u.port) : u.protocol === "https:" ? 443 : 80;
|
|
1175
1181
|
const portOpen = await isPortReachable(u.hostname, port);
|
|
1176
1182
|
console.warn(
|
|
1177
|
-
|
|
1183
|
+
formatFulgurjsDiagnostic({
|
|
1178
1184
|
code: "DEV-001",
|
|
1179
1185
|
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
1186
|
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 +1193,7 @@ async function probeRemotesAndBuildSchema(options) {
|
|
|
1187
1193
|
return schema;
|
|
1188
1194
|
}
|
|
1189
1195
|
function genEmptyRemoteSchemaModule() {
|
|
1190
|
-
console.info("[
|
|
1196
|
+
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
1197
|
return "export default {}";
|
|
1192
1198
|
}
|
|
1193
1199
|
|
|
@@ -1196,27 +1202,27 @@ var import_node_fs3 = __toESM(require("fs"), 1);
|
|
|
1196
1202
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
1197
1203
|
function syncViteCacheMarker(root, pluginVersion, log) {
|
|
1198
1204
|
const viteDir = import_node_path4.default.join(root, "node_modules", ".vite");
|
|
1199
|
-
const marker = import_node_path4.default.join(viteDir, "
|
|
1205
|
+
const marker = import_node_path4.default.join(viteDir, "fulgurjs-version.txt");
|
|
1200
1206
|
try {
|
|
1201
1207
|
if (import_node_fs3.default.existsSync(viteDir)) {
|
|
1202
1208
|
const prev = import_node_fs3.default.existsSync(marker) ? import_node_fs3.default.readFileSync(marker, "utf8").trim() : "";
|
|
1203
1209
|
if (prev === pluginVersion) return;
|
|
1204
1210
|
import_node_fs3.default.rmSync(viteDir, { recursive: true, force: true });
|
|
1205
1211
|
log(
|
|
1206
|
-
`[
|
|
1212
|
+
`[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
1213
|
);
|
|
1208
1214
|
}
|
|
1209
1215
|
import_node_fs3.default.mkdirSync(viteDir, { recursive: true });
|
|
1210
1216
|
import_node_fs3.default.writeFileSync(marker, pluginVersion);
|
|
1211
1217
|
} catch (e) {
|
|
1212
1218
|
log(
|
|
1213
|
-
`[
|
|
1219
|
+
`[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
1220
|
);
|
|
1215
1221
|
}
|
|
1216
1222
|
}
|
|
1217
1223
|
|
|
1218
1224
|
// 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';
|
|
1225
|
+
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.1";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
1226
|
|
|
1221
1227
|
// src/index.ts
|
|
1222
1228
|
function readRuntimeCode() {
|
|
@@ -1226,7 +1232,7 @@ function normalizeBase(base) {
|
|
|
1226
1232
|
if (!base || base === "/") return "/";
|
|
1227
1233
|
return base.endsWith("/") ? base : `${base}/`;
|
|
1228
1234
|
}
|
|
1229
|
-
var
|
|
1235
|
+
var FULGURJS_STUB_NAMESPACE = "fulgurjs-opt-stub";
|
|
1230
1236
|
var nsExportCache = /* @__PURE__ */ new Map();
|
|
1231
1237
|
function enumerateCjsExports(packageName, appRoot) {
|
|
1232
1238
|
const cached = nsExportCache.get(packageName);
|
|
@@ -1238,7 +1244,7 @@ function enumerateCjsExports(packageName, appRoot) {
|
|
|
1238
1244
|
names = Object.keys(mod);
|
|
1239
1245
|
} catch {
|
|
1240
1246
|
console.warn(
|
|
1241
|
-
`[
|
|
1247
|
+
`[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
1248
|
);
|
|
1243
1249
|
}
|
|
1244
1250
|
nsExportCache.set(packageName, names);
|
|
@@ -1270,7 +1276,7 @@ function federation(options) {
|
|
|
1270
1276
|
entryInitInjected: /* @__PURE__ */ new Set()
|
|
1271
1277
|
};
|
|
1272
1278
|
const pre = {
|
|
1273
|
-
name: "
|
|
1279
|
+
name: "fulgurjs:core",
|
|
1274
1280
|
enforce: "pre",
|
|
1275
1281
|
async config(userConfig, env) {
|
|
1276
1282
|
state.command = env.command;
|
|
@@ -1289,19 +1295,19 @@ function federation(options) {
|
|
|
1289
1295
|
const filter = new RegExp(`^(${[...aliasToShare.keys()].map(escapeRe).join("|")})$`);
|
|
1290
1296
|
const devBase = normalizeBase(userConfig.base ?? "/");
|
|
1291
1297
|
const sharedExternal = {
|
|
1292
|
-
name: "
|
|
1298
|
+
name: "fulgurjs:optimize-shared-external",
|
|
1293
1299
|
setup(build) {
|
|
1294
|
-
const facadeUrlFor = (shareKey) => `${devBase}@id/__x00__virtual:
|
|
1300
|
+
const facadeUrlFor = (shareKey) => `${devBase}@id/__x00__virtual:fulgurjs-shared-ns:${shareKey}?import`;
|
|
1295
1301
|
const b = build;
|
|
1296
|
-
b.onResolve({ filter: /
|
|
1302
|
+
b.onResolve({ filter: /fulgurjs-shared-ns:/ }, (args) => ({ path: args.path, external: true }));
|
|
1297
1303
|
b.onResolve({ filter }, (args) => {
|
|
1298
1304
|
if (args.kind === "entry-point" || args.kind === "entry-point-render") return null;
|
|
1299
1305
|
const s = aliasToShare.get(args.path);
|
|
1300
1306
|
if (!s) return null;
|
|
1301
|
-
return { path: `
|
|
1307
|
+
return { path: `fulgurjs-stub:${s.shareKey}`, namespace: FULGURJS_STUB_NAMESPACE };
|
|
1302
1308
|
});
|
|
1303
|
-
b.onLoad({ filter: /^
|
|
1304
|
-
const shareKey = args.path.slice("
|
|
1309
|
+
b.onLoad({ filter: /^fulgurjs-stub:/, namespace: FULGURJS_STUB_NAMESPACE }, (args) => {
|
|
1310
|
+
const shareKey = args.path.slice("fulgurjs-stub:".length);
|
|
1305
1311
|
const url = facadeUrlFor(shareKey);
|
|
1306
1312
|
return {
|
|
1307
1313
|
contents: `export * from ${JSON.stringify(url)};
|
|
@@ -1328,7 +1334,7 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1328
1334
|
if (userTarget) {
|
|
1329
1335
|
if (/es20(0\d|1\d|20|21)/.test(String(userTarget))) {
|
|
1330
1336
|
normalized.warnings.push(
|
|
1331
|
-
`build.target="${String(userTarget)}" does not support top-level await;
|
|
1337
|
+
`build.target="${String(userTarget)}" does not support top-level await; fulgurjs requires es2022 or higher.`
|
|
1332
1338
|
);
|
|
1333
1339
|
}
|
|
1334
1340
|
} else {
|
|
@@ -1336,13 +1342,13 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1336
1342
|
extra.build = { target: "es2022" };
|
|
1337
1343
|
}
|
|
1338
1344
|
}
|
|
1339
|
-
for (const w of normalized.warnings) console.warn(`[
|
|
1345
|
+
for (const w of normalized.warnings) console.warn(`[fulgurjs] ${w}`);
|
|
1340
1346
|
return extra;
|
|
1341
1347
|
},
|
|
1342
1348
|
configResolved(resolved) {
|
|
1343
1349
|
state.base = normalizeBase(resolved.base);
|
|
1344
1350
|
if (resolved.build?.ssr) {
|
|
1345
|
-
console.warn("[
|
|
1351
|
+
console.warn("[fulgurjs] SSR builds are not supported in this version; plugin hooks disabled.");
|
|
1346
1352
|
}
|
|
1347
1353
|
const n0 = state.normalized;
|
|
1348
1354
|
const optimize = resolved.optimizeDeps;
|
|
@@ -1355,7 +1361,7 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1355
1361
|
for (const pkg of KNOWN_UMD) {
|
|
1356
1362
|
if (n0.pkgDependencies[pkg] && !incl(pkg) && !excl(pkg)) {
|
|
1357
1363
|
console.warn(
|
|
1358
|
-
|
|
1364
|
+
formatFulgurjsDiagnostic({
|
|
1359
1365
|
code: "DEV-004",
|
|
1360
1366
|
symptom: `UMD-only \u4F9D\u8D56 "${pkg}" \u4E0D\u5728 optimizeDeps.include`,
|
|
1361
1367
|
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 +1390,7 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1384
1390
|
if (!known && !warnedUnknownPrefixes.has(prefix)) {
|
|
1385
1391
|
warnedUnknownPrefixes.add(prefix);
|
|
1386
1392
|
console.warn(
|
|
1387
|
-
`[
|
|
1393
|
+
`[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
1394
|
);
|
|
1389
1395
|
}
|
|
1390
1396
|
}
|
|
@@ -1392,17 +1398,17 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1392
1398
|
if (bareClean === RUNTIME_VIRTUAL_ID) return RESOLVED.runtime;
|
|
1393
1399
|
if (bareClean === RUNTIME_PROXY_VIRTUAL_ID) return RESOLVED.runtimeProxy;
|
|
1394
1400
|
if (bareClean === INIT_VIRTUAL_ID) return RESOLVED.init;
|
|
1395
|
-
if (bareClean === "virtual:
|
|
1396
|
-
if (bareClean === "virtual:
|
|
1397
|
-
if (bareClean === "virtual:
|
|
1401
|
+
if (bareClean === "virtual:fulgurjs-remote-schema") return bareClean;
|
|
1402
|
+
if (bareClean === "virtual:fulgurjs-provides") return RESOLVED.provides;
|
|
1403
|
+
if (bareClean === "virtual:fulgurjs-remote-entry") return RESOLVED.remoteEntry;
|
|
1398
1404
|
if (bareClean.startsWith(SHARED_NS_FACADE_PREFIX)) {
|
|
1399
1405
|
return RESOLVED.sharedNsFacade(bareClean.slice(SHARED_NS_FACADE_PREFIX.length)) + query;
|
|
1400
1406
|
}
|
|
1401
|
-
if (bareClean.startsWith("virtual:
|
|
1402
|
-
return RESOLVED.sharedNsFacade(bareClean.slice("virtual:
|
|
1407
|
+
if (bareClean.startsWith("virtual:fulgurjs-cjs-ns:")) {
|
|
1408
|
+
return RESOLVED.sharedNsFacade(bareClean.slice("virtual:fulgurjs-cjs-ns:".length)) + query;
|
|
1403
1409
|
}
|
|
1404
|
-
if (bareClean.startsWith("virtual:
|
|
1405
|
-
const body = bareClean.slice("virtual:
|
|
1410
|
+
if (bareClean.startsWith("virtual:fulgurjs-shared:")) {
|
|
1411
|
+
const body = bareClean.slice("virtual:fulgurjs-shared:".length);
|
|
1406
1412
|
return RESOLVED.sharedFacade(body) + query;
|
|
1407
1413
|
}
|
|
1408
1414
|
return null;
|
|
@@ -1411,22 +1417,22 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1411
1417
|
const raw = id.startsWith("\0") ? id.slice(1) : id;
|
|
1412
1418
|
const q = raw.indexOf("?");
|
|
1413
1419
|
const clean = q === -1 ? raw : raw.slice(0, q);
|
|
1414
|
-
if (clean === "virtual:
|
|
1420
|
+
if (clean === "virtual:fulgurjs-runtime") return readRuntimeCode();
|
|
1415
1421
|
if (clean === RESOLVED.runtimeProxy || clean === RUNTIME_PROXY_VIRTUAL_ID) return genRuntimeProxyModule();
|
|
1416
|
-
if (clean === "virtual:
|
|
1422
|
+
if (clean === "virtual:fulgurjs-init" && state.normalized) {
|
|
1417
1423
|
return genInitModule(state.normalized, state.command);
|
|
1418
1424
|
}
|
|
1419
|
-
if (clean === "virtual:
|
|
1425
|
+
if (clean === "virtual:fulgurjs-provides" && state.normalized) {
|
|
1420
1426
|
return genDevProvides(state.normalized);
|
|
1421
1427
|
}
|
|
1422
|
-
if (clean === "virtual:
|
|
1428
|
+
if (clean === "virtual:fulgurjs-remote-schema" && state.normalized) {
|
|
1423
1429
|
if (state.command === "build") return genEmptyRemoteSchemaModule();
|
|
1424
1430
|
remoteSchemaPromise ??= probeRemotesAndBuildSchema(state.normalized).then(
|
|
1425
1431
|
(schema) => `export default ${JSON.stringify(schema)}`
|
|
1426
1432
|
);
|
|
1427
1433
|
return remoteSchemaPromise;
|
|
1428
1434
|
}
|
|
1429
|
-
if (clean === "virtual:
|
|
1435
|
+
if (clean === "virtual:fulgurjs-remote-entry" && state.normalized) {
|
|
1430
1436
|
return genBuildRemoteEntry(state.normalized, state.exposeAbsPaths);
|
|
1431
1437
|
}
|
|
1432
1438
|
if (clean.startsWith(SHARED_NS_FACADE_PREFIX) && state.normalized) {
|
|
@@ -1441,8 +1447,8 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1441
1447
|
}
|
|
1442
1448
|
return genSharedNsFacade(item, serializeShareCallForFacade(item), names);
|
|
1443
1449
|
}
|
|
1444
|
-
if (clean.startsWith("virtual:
|
|
1445
|
-
const body = clean.slice("virtual:
|
|
1450
|
+
if (clean.startsWith("virtual:fulgurjs-shared:") && state.normalized) {
|
|
1451
|
+
const body = clean.slice("virtual:fulgurjs-shared:".length);
|
|
1446
1452
|
const f = raw.indexOf("?f=");
|
|
1447
1453
|
if (f === -1) {
|
|
1448
1454
|
const item2 = state.normalized.shared.find((x) => x.shareKey === body);
|
|
@@ -1467,7 +1473,7 @@ export { default } from ${JSON.stringify(url)};
|
|
|
1467
1473
|
...item.strictVersion ? ["strictVersion: true"] : [],
|
|
1468
1474
|
"fallback: () => import(" + JSON.stringify(item.import) + ")"
|
|
1469
1475
|
];
|
|
1470
|
-
const call = "
|
|
1476
|
+
const call = "__fulgurjs_loadShare(" + JSON.stringify(item.shareKey) + ", { " + opts.join(", ") + " })";
|
|
1471
1477
|
return genBindingFacade(item, entry.bindings, call);
|
|
1472
1478
|
}
|
|
1473
1479
|
return null;
|
|
@@ -1532,12 +1538,12 @@ ${code}`, map: null };
|
|
|
1532
1538
|
if (resolved) {
|
|
1533
1539
|
state.exposeAbsPaths[e.import] = resolved.id.split("?")[0];
|
|
1534
1540
|
} else {
|
|
1535
|
-
this.error(`[
|
|
1541
|
+
this.error(`[fulgurjs] expose "${e.import}" could not be resolved from ${n.root}`);
|
|
1536
1542
|
}
|
|
1537
1543
|
}
|
|
1538
1544
|
this.emitFile({
|
|
1539
1545
|
type: "chunk",
|
|
1540
|
-
id: "virtual:
|
|
1546
|
+
id: "virtual:fulgurjs-remote-entry",
|
|
1541
1547
|
fileName: n.filename.replace(/^\//, ""),
|
|
1542
1548
|
preserveSignature: "allow-extension"
|
|
1543
1549
|
});
|
|
@@ -1567,7 +1573,7 @@ ${code}`, map: null };
|
|
|
1567
1573
|
const manifest = genProdManifest(n, state.exposeFiles, entryChunkName ?? n.filename);
|
|
1568
1574
|
this.emitFile({
|
|
1569
1575
|
type: "asset",
|
|
1570
|
-
fileName: "
|
|
1576
|
+
fileName: "fulgurjs-manifest.json",
|
|
1571
1577
|
source: JSON.stringify(manifest, null, 2)
|
|
1572
1578
|
});
|
|
1573
1579
|
},
|
|
@@ -1577,10 +1583,10 @@ ${code}`, map: null };
|
|
|
1577
1583
|
warmResolvedSharedPaths(server);
|
|
1578
1584
|
if (n.exposes.length > 0 || n.remotes.length > 0) {
|
|
1579
1585
|
console.warn(
|
|
1580
|
-
|
|
1586
|
+
formatFulgurjsDiagnostic({
|
|
1581
1587
|
code: "DEV-010",
|
|
1582
1588
|
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
|
|
1589
|
+
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
1590
|
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
1591
|
})
|
|
1586
1592
|
);
|
|
@@ -1590,7 +1596,7 @@ ${code}`, map: null };
|
|
|
1590
1596
|
server.middlewares.use((req, res, next) => {
|
|
1591
1597
|
const raw = (req.url ?? "").split("?")[0];
|
|
1592
1598
|
const stripped = raw.startsWith(baseNorm) ? `/${raw.slice(baseNorm.length)}` : raw;
|
|
1593
|
-
if (stripped === "/@
|
|
1599
|
+
if (stripped === "/@fulgurjs-entry.js" || stripped === "/@fulgurjs-manifest.json") {
|
|
1594
1600
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
1595
1601
|
res.setHeader("Access-Control-Allow-Methods", "GET,OPTIONS");
|
|
1596
1602
|
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
@@ -1599,7 +1605,7 @@ ${code}`, map: null };
|
|
|
1599
1605
|
res.end();
|
|
1600
1606
|
return;
|
|
1601
1607
|
}
|
|
1602
|
-
if (stripped === "/@
|
|
1608
|
+
if (stripped === "/@fulgurjs-entry.js") {
|
|
1603
1609
|
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
1604
1610
|
res.setHeader("Cache-Control", "no-cache");
|
|
1605
1611
|
res.end(genDevRemoteEntry(n, baseNorm));
|
|
@@ -1629,10 +1635,10 @@ ${code}`, map: null };
|
|
|
1629
1635
|
return () => {
|
|
1630
1636
|
server.middlewares.use((req, res, next) => {
|
|
1631
1637
|
const url = req.url ?? "";
|
|
1632
|
-
if (req.method === "GET" && url.includes("
|
|
1638
|
+
if (req.method === "GET" && url.includes("fulgurjs")) {
|
|
1633
1639
|
res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
|
|
1634
1640
|
res.end(
|
|
1635
|
-
|
|
1641
|
+
formatFulgurjsDiagnostic({
|
|
1636
1642
|
code: "DEV-009",
|
|
1637
1643
|
symptom: `\u8054\u90A6\u6A21\u5757\u8BF7\u6C42 404\uFF1A${url.slice(0, 120)}`,
|
|
1638
1644
|
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 +1653,15 @@ ${code}`, map: null };
|
|
|
1647
1653
|
}
|
|
1648
1654
|
};
|
|
1649
1655
|
const post = {
|
|
1650
|
-
name: "
|
|
1656
|
+
name: "fulgurjs:vue-post",
|
|
1651
1657
|
enforce: "post",
|
|
1652
1658
|
async transform(code, id) {
|
|
1653
1659
|
if (!state.normalized) return null;
|
|
1654
1660
|
const clean = id.split("?")[0];
|
|
1655
|
-
if (state.command === "serve" && code.includes("virtual:
|
|
1656
|
-
return { code: code.split("virtual:
|
|
1661
|
+
if (state.command === "serve" && code.includes("virtual:fulgurjs-runtime") && !code.includes("virtual:fulgurjs-runtime-proxy") && isExposeTargetFile(clean, state.normalized.root, state.normalized.exposes)) {
|
|
1662
|
+
return { code: code.split("virtual:fulgurjs-runtime").join("virtual:fulgurjs-runtime-proxy"), map: null };
|
|
1657
1663
|
}
|
|
1658
|
-
if (code
|
|
1664
|
+
if (isPluginProcessedModule(code)) return null;
|
|
1659
1665
|
if (state.command === "build" && !/\.vue(\?|$)/.test(id)) return null;
|
|
1660
1666
|
if (/type=(style|template)/.test(id)) return null;
|
|
1661
1667
|
const isJsLike = /\.(m|c)?[jt]sx?$/.test(clean) || clean.endsWith(".vue");
|