@fulgurjs/federation 0.5.0 → 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 +10 -0
- package/README.md +8 -8
- package/dist/index.cjs +507 -501
- package/dist/index.js +507 -501
- package/dist/runtime.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -43,7 +43,7 @@ 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.5.
|
|
46
|
+
var RUNTIME_VERSION = "0.5.1";
|
|
47
47
|
|
|
48
48
|
// src/options.ts
|
|
49
49
|
var DEFAULT_FILENAME = "fulgurjs-remoteEntry.js";
|
|
@@ -397,527 +397,246 @@ 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;
|
|
414
|
-
}
|
|
415
|
-
function buildSharedMatcher(shared) {
|
|
416
|
-
const exact = /* @__PURE__ */ new Map();
|
|
417
|
-
const prefixes = [];
|
|
418
|
-
for (const s of shared) {
|
|
419
|
-
for (const alias of s.aliases) {
|
|
420
|
-
if (!exact.has(alias)) exact.set(alias, s);
|
|
421
|
-
}
|
|
422
|
-
if (s.configKey.endsWith("/")) prefixes.push({ prefix: s.configKey, item: s });
|
|
423
|
-
}
|
|
424
|
-
return { exact, prefixes };
|
|
425
|
-
}
|
|
426
|
-
function matchShared(spec, matcher) {
|
|
427
|
-
const exact = matcher.exact.get(spec);
|
|
428
|
-
if (exact) return exact;
|
|
429
|
-
for (const p of matcher.prefixes) {
|
|
430
|
-
if (spec.startsWith(p.prefix)) return p.item;
|
|
431
|
-
}
|
|
432
|
-
return null;
|
|
400
|
+
|
|
401
|
+
// src/virtual.ts
|
|
402
|
+
function jsonReplacer(_k, v) {
|
|
403
|
+
return v;
|
|
433
404
|
}
|
|
434
|
-
function
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
if (
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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");
|
|
444
416
|
}
|
|
445
|
-
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");
|
|
446
423
|
}
|
|
447
|
-
function
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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)}];`);
|
|
457
436
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
function stripComments(s) {
|
|
461
|
-
return s.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
|
|
437
|
+
lines.push("");
|
|
438
|
+
return lines.join("\n");
|
|
462
439
|
}
|
|
463
|
-
function
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
const
|
|
472
|
-
|
|
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};`);
|
|
473
453
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
const nsMatch = clause.match(/\*\s+as\s+(\w+)/);
|
|
478
|
-
const braceStart = clause.indexOf("{");
|
|
479
|
-
const bindings = braceStart !== -1 ? parseBindings(clause.slice(braceStart + 1, clause.lastIndexOf("}"))) : null;
|
|
480
|
-
let head = clause.replace(/^\s*import\s*/, "");
|
|
481
|
-
if (braceStart !== -1) head = head.slice(0, head.indexOf("{"));
|
|
482
|
-
if (nsMatch) head = head.slice(0, head.indexOf("*"));
|
|
483
|
-
const defaultLocal = head.replace(/,\s*$/, "").trim() || null;
|
|
484
|
-
return { ns: nsMatch?.[1] ?? null, bindings, defaultLocal };
|
|
485
|
-
}
|
|
486
|
-
var JS_EXT_RE = /\.(m|c)?[jt]sx?$/;
|
|
487
|
-
function isTransformableId(id, allowNodeModules = false) {
|
|
488
|
-
const clean = id.split("?")[0];
|
|
489
|
-
if (!JS_EXT_RE.test(clean) && !clean.endsWith(".vue")) return false;
|
|
490
|
-
if (clean.includes("node_modules") && !allowNodeModules) return false;
|
|
491
|
-
return true;
|
|
492
|
-
}
|
|
493
|
-
var facadeRegistry = /* @__PURE__ */ new Map();
|
|
494
|
-
function shortSig(kind, key, bindings) {
|
|
495
|
-
const full = kind + "|" + key + "|" + bindings.join("|");
|
|
496
|
-
let h = 5381;
|
|
497
|
-
for (let i = 0; i < full.length; i++) h = (h << 5) + h + full.charCodeAt(i) | 0;
|
|
498
|
-
const id = (h >>> 0).toString(36) + bindings.length.toString(36);
|
|
499
|
-
facadeRegistry.set(id, kind === "shared" ? { bindings, shareKey: key } : { bindings, remoteName: key });
|
|
500
|
-
return id;
|
|
501
|
-
}
|
|
502
|
-
function getFacadeEntry(id) {
|
|
503
|
-
return facadeRegistry.get(id);
|
|
454
|
+
lines.push(`export default __fulgurjsU(__fulgurjs_m);`);
|
|
455
|
+
lines.push("");
|
|
456
|
+
return lines.join("\n");
|
|
504
457
|
}
|
|
505
|
-
function
|
|
506
|
-
const
|
|
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();
|
|
507
464
|
for (const bRaw of bindings) {
|
|
508
465
|
if (bRaw === "default") continue;
|
|
509
466
|
const asMatch = bRaw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
510
|
-
|
|
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};`);
|
|
511
471
|
}
|
|
512
|
-
|
|
472
|
+
lines.push(`export default __fulgurjsU(__fulgurjs_m);`);
|
|
473
|
+
lines.push("");
|
|
474
|
+
return lines.join("\n");
|
|
513
475
|
}
|
|
514
|
-
function
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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
|
+
}));
|
|
518
484
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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
|
+
);
|
|
504
|
+
}
|
|
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
|
+
`;
|
|
522
522
|
}
|
|
523
|
-
function
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
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
|
+
}
|
|
527
537
|
}
|
|
528
|
-
function
|
|
529
|
-
|
|
530
|
-
|
|
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
|
+
];
|
|
531
554
|
}
|
|
532
|
-
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
let cjsEdited = false;
|
|
546
|
-
for (const [alias, item] of sharedByAlias) {
|
|
547
|
-
const re = new RegExp(`require\\((["'])${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\1\\)`, "g");
|
|
548
|
-
if (!re.test(code)) continue;
|
|
549
|
-
code = code.replace(re, `require(${JSON.stringify(`virtual:fulgurjs-cjs-ns:${item.shareKey}`)})`);
|
|
550
|
-
cjsEdited = true;
|
|
551
|
-
}
|
|
552
|
-
if (!cjsEdited) return null;
|
|
553
|
-
return { code, map: null };
|
|
554
|
-
}
|
|
555
|
-
await ensureLexer();
|
|
556
|
-
let imports;
|
|
557
|
-
try {
|
|
558
|
-
;
|
|
559
|
-
[imports] = (0, import_es_module_lexer.parse)(code);
|
|
560
|
-
} catch {
|
|
561
|
-
return null;
|
|
562
|
-
}
|
|
563
|
-
const matcher = ctx.rewriteShared ? buildSharedMatcher(options.shared) : null;
|
|
564
|
-
const remotesByKey = new Map(options.remotes.map((r) => [r.key, r]));
|
|
565
|
-
const s = new import_magic_string.default(code);
|
|
566
|
-
let edited = false;
|
|
567
|
-
let usesRuntimeHelpers = false;
|
|
568
|
-
const tlaLines = [];
|
|
569
|
-
let tempIdx = 0;
|
|
570
|
-
const genTemp = () => `__fulgurjs_m${tempIdx++}`;
|
|
571
|
-
const remap = (spec) => ctx.remapSpecifier?.(spec) ?? spec;
|
|
572
|
-
const remoteExposeName = (spec, remoteKey) => {
|
|
573
|
-
if (!spec.startsWith(`${remoteKey}/`)) return null;
|
|
574
|
-
const exposeRaw = spec.slice(remoteKey.length + 1);
|
|
575
|
-
if (!exposeRaw) return null;
|
|
576
|
-
return exposeRaw.startsWith(".") ? exposeRaw : `./${exposeRaw}`;
|
|
577
|
-
};
|
|
578
|
-
const bindingsOf = (clause) => [
|
|
579
|
-
...clause.defaultLocal ? ["default"] : [],
|
|
580
|
-
...(clause.bindings ?? []).map((b) => b.imported === b.local ? b.imported : `${b.imported} as ${b.local}`)
|
|
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"
|
|
581
567
|
];
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
const
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
export
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
};
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
const firstSeg2 = spec2.split("/")[0];
|
|
622
|
-
const remote2 = remotesByKey.get(firstSeg2);
|
|
623
|
-
const exposeName2 = remote2 ? remoteExposeName(spec2, remote2.key) : null;
|
|
624
|
-
if (!shared2 && !(remote2 && exposeName2)) continue;
|
|
625
|
-
edited = true;
|
|
626
|
-
const clauseRaw = code.slice(stmtStart, imp.s).replace(/['"]\s*$/, "");
|
|
627
|
-
const isImport = clauseRaw.trimStart().startsWith("import");
|
|
628
|
-
const clause = parseImportClause(clauseRaw.replace(/\bfrom\s*$/, ""));
|
|
629
|
-
if (clause.ns || /export\s+\*\s+as\s+\w+\s+from/.test(clauseRaw)) {
|
|
630
|
-
genTlaOverwrite(stmtStart, stmtEnd, shared2, remote2?.name ?? null, exposeName2, clauseRaw, clause);
|
|
631
|
-
continue;
|
|
632
|
-
}
|
|
633
|
-
if (!isImport) {
|
|
634
|
-
const inner = clauseRaw.slice(clauseRaw.indexOf("{") + 1, clauseRaw.lastIndexOf("}"));
|
|
635
|
-
if (/export\s+\*/.test(clauseRaw) && !clauseRaw.includes("{")) {
|
|
636
|
-
throw new Error(
|
|
637
|
-
`[fulgurjs] "export * from '${spec2}'" on a shared module is not supported (ESM cannot create dynamic export bindings). Use named re-exports: "export { a, b } from '${spec2}'".`
|
|
638
|
-
);
|
|
639
|
-
}
|
|
640
|
-
const bindings = parseBindings(inner).map((b) => b.imported === "default" ? "default" : b.imported);
|
|
641
|
-
const facadeSpec2 = shared2 ? facadeSpecFor(ctx, shared2, bindings) : remoteFacadeSpecFor(ctx, remote2.name, exposeName2, bindings);
|
|
642
|
-
s.overwrite(imp.s, imp.e, facadeSpec2);
|
|
643
|
-
continue;
|
|
644
|
-
}
|
|
645
|
-
const facadeSpec = shared2 ? facadeSpecFor(ctx, shared2, bindingsOf(clause)) : remoteFacadeSpecFor(ctx, remote2.name, exposeName2, bindingsOf(clause));
|
|
646
|
-
s.overwrite(imp.s, imp.e, facadeSpec);
|
|
647
|
-
continue;
|
|
648
|
-
}
|
|
649
|
-
const specExpr = code.slice(imp.s, imp.e).trim();
|
|
650
|
-
const literal = specExpr.match(/^['"](.*)['"]$/s);
|
|
651
|
-
if (!literal) continue;
|
|
652
|
-
const spec = remap(literal[1]);
|
|
653
|
-
const shared = matcher ? matchShared(spec, matcher) : null;
|
|
654
|
-
const firstSeg = spec.split("/")[0];
|
|
655
|
-
const remote = remotesByKey.get(firstSeg);
|
|
656
|
-
const exposeName = remote ? remoteExposeName(spec, remote.key) : null;
|
|
657
|
-
if (!shared && !(remote && exposeName)) continue;
|
|
658
|
-
edited = true;
|
|
659
|
-
usesRuntimeHelpers = true;
|
|
660
|
-
const callStart = code.lastIndexOf("import", d);
|
|
661
|
-
const closeParen = code.indexOf(")", imp.e);
|
|
662
|
-
if (shared) {
|
|
663
|
-
s.overwrite(callStart, closeParen + 1, serializeShareCall(shared, ctx?.devUrls));
|
|
664
|
-
} else if (remote && exposeName) {
|
|
665
|
-
s.overwrite(
|
|
666
|
-
callStart,
|
|
667
|
-
closeParen + 1,
|
|
668
|
-
`__fulgurjs_loadRemote(${JSON.stringify(`${remote.name}/${exposeName}`)})`
|
|
669
|
-
);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
if (!edited) return null;
|
|
673
|
-
if (usesRuntimeHelpers) {
|
|
674
|
-
const runtimeSpec = JSON.stringify(ctx.devUrls?.runtime ?? "virtual:fulgurjs-runtime");
|
|
675
|
-
s.prepend(
|
|
676
|
-
`import { loadShare as __fulgurjs_loadShare, loadRemote as __fulgurjs_loadRemote, unwrapDefault as __fulgurjsU } from ${runtimeSpec};
|
|
677
|
-
`
|
|
678
|
-
);
|
|
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");
|
|
590
|
+
}
|
|
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 };
|
|
679
607
|
}
|
|
680
|
-
return { code: s.toString(), map: null };
|
|
681
608
|
}
|
|
682
609
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
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;
|
|
616
|
+
}
|
|
617
|
+
return loader();
|
|
686
618
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
`
|
|
695
|
-
|
|
696
|
-
""
|
|
697
|
-
].join("\n");
|
|
619
|
+
`;
|
|
620
|
+
}
|
|
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
|
+
);
|
|
698
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
|
+
);
|
|
699
632
|
return [
|
|
700
|
-
`
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
const lines = [
|
|
708
|
-
`import { loadShare as __fulgurjs_loadShare, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
709
|
-
`const __fulgurjs_m = await ${loadShareCall};`,
|
|
710
|
-
`const __fulgurjs_d = __fulgurjsU(__fulgurjs_m);`,
|
|
711
|
-
`export default __fulgurjs_d;`
|
|
712
|
-
];
|
|
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} = __fulgurjs_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 __fulgurjs_loadShare, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
725
|
-
`const __fulgurjs_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} = __fulgurjs_m.${imported};`);
|
|
735
|
-
}
|
|
736
|
-
lines.push(`export default __fulgurjsU(__fulgurjs_m);`);
|
|
737
|
-
lines.push("");
|
|
738
|
-
return lines.join("\n");
|
|
739
|
-
}
|
|
740
|
-
function genRemoteBindingFacade(remoteSpec, bindings) {
|
|
741
|
-
const lines = [
|
|
742
|
-
`import { loadRemote as __fulgurjs_loadRemote, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
743
|
-
`const __fulgurjs_m = await __fulgurjs_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} = __fulgurjs_m.${imported};`);
|
|
753
|
-
}
|
|
754
|
-
lines.push(`export default __fulgurjsU(__fulgurjs_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:fulgurjs-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 __fulgurjs_eager_${i} from "virtual:fulgurjs-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 __fulgurjs_rp_${i} from ${JSON.stringify(p)};`);
|
|
781
|
-
});
|
|
782
|
-
lines.push(
|
|
783
|
-
`registerPlugins([${options.runtimePlugins.map((_, i) => `(__fulgurjs_rp_${i}.default ?? __fulgurjs_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(__fulgurjs_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:fulgurjs-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("@fulgurjs-entry.js")) {
|
|
810
|
-
u.pathname = u.pathname.replace("@fulgurjs-entry.js", "@fulgurjs-manifest.json");
|
|
811
|
-
} else {
|
|
812
|
-
u.pathname = u.pathname.replace(/[^/]*$/, "") + "fulgurjs-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 __fulgurjs_mod_p;`,
|
|
851
|
-
`const __fulgurjs_rt = async () => {`,
|
|
852
|
-
` __fulgurjs_mod_p ??= import('virtual:fulgurjs-runtime');`,
|
|
853
|
-
` return await __fulgurjs_mod_p;`,
|
|
854
|
-
`};`,
|
|
855
|
-
...promiseApis.map((m) => `export const ${m} = (...a) => __fulgurjs_rt().then((m2) => m2.${m}(...a));`),
|
|
856
|
-
`export const getRuntime = () => (globalThis).__FULGURJS_RUNTIME__;`,
|
|
857
|
-
`export const getFulgurjsAppConfig = () =>`,
|
|
858
|
-
` (globalThis).__FULGURJS_RUNTIME__?.getFulgurjsAppConfig?.() ?? (globalThis).__FULGURJS_APP_CONFIG__ ?? {};`,
|
|
859
|
-
`export const provideFulgurjsAppConfig = (c) => {`,
|
|
860
|
-
` const g = (globalThis);`,
|
|
861
|
-
` g.__FULGURJS_APP_CONFIG__ = { ...(g.__FULGURJS_APP_CONFIG__ ?? {}), ...c };`,
|
|
862
|
-
` g.__FULGURJS_RUNTIME__?.provideFulgurjsAppConfig?.(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).__FULGURJS_RUNTIME__?.version;`,
|
|
867
|
-
`export default { get runtime() { return (globalThis).__FULGURJS_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 _fulgurjs_name, exposes, provides } from ${JSON.stringify(`${b}@id/__x00__virtual:fulgurjs-provides`)};
|
|
877
|
-
${remoteLines.length > 0 ? `import { registerRemotes } from ${JSON.stringify(`${b}@id/virtual:fulgurjs-runtime`)};
|
|
878
|
-
${remoteLines.join("\n")}` : ""}
|
|
879
|
-
|
|
880
|
-
export const name = _fulgurjs_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:fulgurjs-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
|
-
`];`,
|
|
633
|
+
`export const name = ${JSON.stringify(options.name)};`,
|
|
634
|
+
`export const exposes = {`,
|
|
635
|
+
...exposes,
|
|
636
|
+
`};`,
|
|
637
|
+
`export const provides = [`,
|
|
638
|
+
...provides,
|
|
639
|
+
`];`,
|
|
921
640
|
""
|
|
922
641
|
].join("\n");
|
|
923
642
|
}
|
|
@@ -1010,6 +729,293 @@ function genProdManifest(options, exposeFiles, entryFile) {
|
|
|
1010
729
|
};
|
|
1011
730
|
}
|
|
1012
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) {
|
|
856
|
+
const id = bindingFacadeId(item, bindings);
|
|
857
|
+
return ctx.devUrls ? ctx.devUrls.bindingFacade(id) : id;
|
|
858
|
+
}
|
|
859
|
+
function remoteBindingFacadeId(remoteName, exposeName, bindings) {
|
|
860
|
+
const canonical = canonicalBindings(bindings);
|
|
861
|
+
const sig = canonical.length ? `?f=${shortSig("remote", `${remoteName}/${exposeName}`, canonical)}` : "";
|
|
862
|
+
return `${SHARED_FACADE_PREFIX}__remote__${remoteName}/${exposeName}${sig}`;
|
|
863
|
+
}
|
|
864
|
+
function remoteFacadeSpecFor(ctx, remoteName, exposeName, bindings) {
|
|
865
|
+
const id = remoteBindingFacadeId(remoteName, exposeName, bindings);
|
|
866
|
+
return ctx.devUrls ? ctx.devUrls.bindingFacade(id) : id;
|
|
867
|
+
}
|
|
868
|
+
async function transformModule(code, id, ctx) {
|
|
869
|
+
const { options } = ctx;
|
|
870
|
+
if (options.shared.length === 0 && options.remotes.length === 0) return null;
|
|
871
|
+
const candidates = [];
|
|
872
|
+
for (const s2 of options.shared) candidates.push(s2.configKey.replace(/\/$/, ""));
|
|
873
|
+
for (const r of options.remotes) candidates.push(r.key);
|
|
874
|
+
if (!candidates.some((c) => code.includes(c))) return null;
|
|
875
|
+
if (ctx.cjsRequireRewrite && /require\s*\(\s*["']/.test(code)) {
|
|
876
|
+
const sharedByAlias = /* @__PURE__ */ new Map();
|
|
877
|
+
for (const s2 of options.shared) {
|
|
878
|
+
if (s2.import === false) continue;
|
|
879
|
+
for (const a of s2.aliases) if (!a.includes("/")) sharedByAlias.set(a, s2);
|
|
880
|
+
}
|
|
881
|
+
let cjsEdited = false;
|
|
882
|
+
for (const [alias, item] of sharedByAlias) {
|
|
883
|
+
const re = new RegExp(`require\\((["'])${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\1\\)`, "g");
|
|
884
|
+
if (!re.test(code)) continue;
|
|
885
|
+
code = code.replace(re, `require(${JSON.stringify(`virtual:fulgurjs-cjs-ns:${item.shareKey}`)})`);
|
|
886
|
+
cjsEdited = true;
|
|
887
|
+
}
|
|
888
|
+
if (!cjsEdited) return null;
|
|
889
|
+
return { code, map: null };
|
|
890
|
+
}
|
|
891
|
+
await ensureLexer();
|
|
892
|
+
let imports;
|
|
893
|
+
try {
|
|
894
|
+
;
|
|
895
|
+
[imports] = (0, import_es_module_lexer.parse)(code);
|
|
896
|
+
} catch {
|
|
897
|
+
return null;
|
|
898
|
+
}
|
|
899
|
+
const matcher = ctx.rewriteShared ? buildSharedMatcher(options.shared) : null;
|
|
900
|
+
const remotesByKey = new Map(options.remotes.map((r) => [r.key, r]));
|
|
901
|
+
const s = new import_magic_string.default(code);
|
|
902
|
+
let edited = false;
|
|
903
|
+
let usesRuntimeHelpers = false;
|
|
904
|
+
const tlaLines = [];
|
|
905
|
+
let tempIdx = 0;
|
|
906
|
+
const genTemp = () => `__fulgurjs_m${tempIdx++}`;
|
|
907
|
+
const remap = (spec) => ctx.remapSpecifier?.(spec) ?? spec;
|
|
908
|
+
const remoteExposeName = (spec, remoteKey) => {
|
|
909
|
+
if (!spec.startsWith(`${remoteKey}/`)) return null;
|
|
910
|
+
const exposeRaw = spec.slice(remoteKey.length + 1);
|
|
911
|
+
if (!exposeRaw) return null;
|
|
912
|
+
return exposeRaw.startsWith(".") ? exposeRaw : `./${exposeRaw}`;
|
|
913
|
+
};
|
|
914
|
+
const bindingsOf = (clause) => [
|
|
915
|
+
...clause.defaultLocal ? ["default"] : [],
|
|
916
|
+
...(clause.bindings ?? []).map((b) => b.imported === b.local ? b.imported : `${b.imported} as ${b.local}`)
|
|
917
|
+
];
|
|
918
|
+
const genTlaOverwrite = (stmtStart, stmtEnd, shared, remoteName, exposeName, clauseRaw, clause) => {
|
|
919
|
+
usesRuntimeHelpers = true;
|
|
920
|
+
const call = shared ? serializeShareCall(shared, ctx?.devUrls) : `__fulgurjs_loadRemote(${JSON.stringify(`${remoteName}/${exposeName}`)})`;
|
|
921
|
+
const nsAs = clauseRaw.match(/export\s+\*\s+as\s+(\w+)\s+from/);
|
|
922
|
+
if (nsAs) {
|
|
923
|
+
s.overwrite(stmtStart, stmtEnd, `const ${nsAs[1]} = await ${call};
|
|
924
|
+
export { ${nsAs[1]} };`);
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
if (!clause.ns && !clause.bindings && !clause.defaultLocal) {
|
|
928
|
+
s.overwrite(stmtStart, stmtEnd, `await ${call};`);
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
const tmp = genTemp();
|
|
932
|
+
const parts = [`${tmp} = await ${call}`];
|
|
933
|
+
if (clause.ns) parts.push(`${clause.ns} = ${tmp}`);
|
|
934
|
+
if (clause.defaultLocal) parts.push(`${clause.defaultLocal} = __fulgurjsU(${tmp})`);
|
|
935
|
+
const named = clause.bindings?.filter((b) => !b.isDefault) ?? [];
|
|
936
|
+
if (named.length) {
|
|
937
|
+
const destructure = named.map((b) => b.imported === b.local ? b.local : `${b.imported}: ${b.local}`);
|
|
938
|
+
parts.push(`{ ${destructure.join(", ")} } = ${tmp}`);
|
|
939
|
+
}
|
|
940
|
+
for (const b of clause.bindings?.filter((x) => x.isDefault) ?? []) {
|
|
941
|
+
parts.push(`${b.local} = __fulgurjsU(${tmp})`);
|
|
942
|
+
}
|
|
943
|
+
s.overwrite(stmtStart, stmtEnd, `const ${parts.join(", ")}`);
|
|
944
|
+
};
|
|
945
|
+
for (const imp of imports) {
|
|
946
|
+
const { d } = imp;
|
|
947
|
+
if (d === -2) continue;
|
|
948
|
+
if (d === -1) {
|
|
949
|
+
const rawSpec = code.slice(imp.s, imp.e).replace(/['"]/g, "");
|
|
950
|
+
const spec2 = remap(rawSpec);
|
|
951
|
+
const stmtStart = imp.ss;
|
|
952
|
+
let stmtEnd = imp.se;
|
|
953
|
+
while (code[stmtEnd] === ";") stmtEnd++;
|
|
954
|
+
const head = code.slice(stmtStart, stmtStart + 24);
|
|
955
|
+
if (/^\s*(import|export)\s+type[\s{]/.test(head)) continue;
|
|
956
|
+
const shared2 = matcher ? matchShared(spec2, matcher) : null;
|
|
957
|
+
const firstSeg2 = spec2.split("/")[0];
|
|
958
|
+
const remote2 = remotesByKey.get(firstSeg2);
|
|
959
|
+
const exposeName2 = remote2 ? remoteExposeName(spec2, remote2.key) : null;
|
|
960
|
+
if (!shared2 && !(remote2 && exposeName2)) continue;
|
|
961
|
+
edited = true;
|
|
962
|
+
const clauseRaw = code.slice(stmtStart, imp.s).replace(/['"]\s*$/, "");
|
|
963
|
+
const isImport = clauseRaw.trimStart().startsWith("import");
|
|
964
|
+
const clause = parseImportClause(clauseRaw.replace(/\bfrom\s*$/, ""));
|
|
965
|
+
if (clause.ns || /export\s+\*\s+as\s+\w+\s+from/.test(clauseRaw)) {
|
|
966
|
+
genTlaOverwrite(stmtStart, stmtEnd, shared2, remote2?.name ?? null, exposeName2, clauseRaw, clause);
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
969
|
+
if (!isImport) {
|
|
970
|
+
const inner = clauseRaw.slice(clauseRaw.indexOf("{") + 1, clauseRaw.lastIndexOf("}"));
|
|
971
|
+
if (/export\s+\*/.test(clauseRaw) && !clauseRaw.includes("{")) {
|
|
972
|
+
throw new Error(
|
|
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}'".`
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
const bindings = parseBindings(inner).map((b) => b.imported === "default" ? "default" : b.imported);
|
|
977
|
+
const facadeSpec2 = shared2 ? facadeSpecFor(ctx, shared2, bindings) : remoteFacadeSpecFor(ctx, remote2.name, exposeName2, bindings);
|
|
978
|
+
s.overwrite(imp.s, imp.e, facadeSpec2);
|
|
979
|
+
continue;
|
|
980
|
+
}
|
|
981
|
+
const facadeSpec = shared2 ? facadeSpecFor(ctx, shared2, bindingsOf(clause)) : remoteFacadeSpecFor(ctx, remote2.name, exposeName2, bindingsOf(clause));
|
|
982
|
+
s.overwrite(imp.s, imp.e, facadeSpec);
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
const specExpr = code.slice(imp.s, imp.e).trim();
|
|
986
|
+
const literal = specExpr.match(/^['"](.*)['"]$/s);
|
|
987
|
+
if (!literal) continue;
|
|
988
|
+
const spec = remap(literal[1]);
|
|
989
|
+
const shared = matcher ? matchShared(spec, matcher) : null;
|
|
990
|
+
const firstSeg = spec.split("/")[0];
|
|
991
|
+
const remote = remotesByKey.get(firstSeg);
|
|
992
|
+
const exposeName = remote ? remoteExposeName(spec, remote.key) : null;
|
|
993
|
+
if (!shared && !(remote && exposeName)) continue;
|
|
994
|
+
edited = true;
|
|
995
|
+
usesRuntimeHelpers = true;
|
|
996
|
+
const callStart = code.lastIndexOf("import", d);
|
|
997
|
+
const closeParen = code.indexOf(")", imp.e);
|
|
998
|
+
if (shared) {
|
|
999
|
+
s.overwrite(callStart, closeParen + 1, serializeShareCall(shared, ctx?.devUrls));
|
|
1000
|
+
} else if (remote && exposeName) {
|
|
1001
|
+
s.overwrite(
|
|
1002
|
+
callStart,
|
|
1003
|
+
closeParen + 1,
|
|
1004
|
+
`__fulgurjs_loadRemote(${JSON.stringify(`${remote.name}/${exposeName}`)})`
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
if (!edited) return null;
|
|
1009
|
+
if (usesRuntimeHelpers) {
|
|
1010
|
+
const runtimeSpec = JSON.stringify(ctx.devUrls?.runtime ?? "virtual:fulgurjs-runtime");
|
|
1011
|
+
s.prepend(
|
|
1012
|
+
`import { loadShare as __fulgurjs_loadShare, loadRemote as __fulgurjs_loadRemote, unwrapDefault as __fulgurjsU } from ${runtimeSpec};
|
|
1013
|
+
`
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
return { code: s.toString(), map: null };
|
|
1017
|
+
}
|
|
1018
|
+
|
|
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);
|
|
@@ -1216,7 +1222,7 @@ function syncViteCacheMarker(root, pluginVersion, log) {
|
|
|
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 O(t){let n=Q.exec(String(t).trim());return n?{major:Number(n[1]),minor:Number(n[2]??0),patch:Number(n[3]??0),pre:n[4]?n[4].split("."):[]}:null}function ee(t,n){if(t.length===0&&n.length===0)return 0;if(t.length===0)return 1;if(n.length===0)return-1;let o=Math.max(t.length,n.length);for(let r=0;r<o;r++){let l=t[r],m=n[r];if(l===void 0)return-1;if(m===void 0)return 1;let y=/^\\d+$/.test(l),w=/^\\d+$/.test(m);if(y&&w){let $=Number(l)-Number(m);if($!==0)return $}else{if(y!==w)return y?-1:1;if(l!==m)return l<m?-1:1}}return 0}function v(t,n){let o=O(t),r=O(n);return!o||!r?t<n?-1:t>n?1:0:o.major!==r.major?o.major-r.major:o.minor!==r.minor?o.minor-r.minor:o.patch!==r.patch?o.patch-r.patch:ee(o.pre,r.pre)}var re=/^[a-z]+[+:-]/i;function k(t,n){if(n===!1||n==null||n==="")return!0;let o=String(n).trim();return!o||o==="*"||o==="latest"||re.test(o)?!0:o.split("||").some(r=>te(t,r.trim()))}function te(t,n){if(!n||n==="*")return!O(t)?.pre.length;let o=n.split(/\\s+-\\s+/);if(o.length===2){let m=o[0].trim(),y=o[1].trim();return!(!k(t,`>=${m}`)||!k(t,`<=${y}`))}let r=O(t);if(!r)return!1;let l=ne(n);if(l===null)return!0;for(let m of l)if(!ue(r,t,m))return!1;return!(r.pre.length>0&&!l.some(m=>m.ver.pre.length>0)&&!l.some(y=>y.ver.major===r.major&&y.ver.minor===r.minor&&y.ver.patch===r.patch))}function ne(t){let n=[],o=t.trim().split(/\\s+/).filter(Boolean);if(o.length===0)return null;for(let r of o){let l=/^(>=|<=|>|<|=|\\^|~)?(.*)$/.exec(r);if(!l)return null;let m=l[1],y=l[2],w=oe(m,y);if(w===null)return null;n.push(...w)}return n}function oe(t,n){let o=ae(n);if(!o)return null;let{ver:r,partial:l}=o;switch(t){case"^":{let m=ie(r);return m?[{op:">=",ver:r},{op:"<",ver:m}]:null}case"~":{let m=l>=2?{major:r.major,minor:r.minor+1,patch:0,pre:[]}:{major:r.major+1,minor:0,patch:0,pre:[]};return[{op:">=",ver:r},{op:"<",ver:m}]}case">=":return[{op:">=",ver:r}];case">":return l===1?[{op:">=",ver:{major:r.major+1,minor:0,patch:0,pre:[]}}]:l===2?[{op:">=",ver:{major:r.major,minor:r.minor+1,patch:0,pre:[]}}]:[{op:">",ver:r}];case"<":return l===1?[{op:"<",ver:{major:r.major,minor:0,patch:0,pre:[]}}]:l===2?[{op:"<",ver:{major:r.major,minor:r.minor,patch:0,pre:[]}}]:[{op:"<",ver:r}];case"<=":return[{op:"<=",ver:r}];case"=":case void 0:return l===1?[{op:">=",ver:r},{op:"<",ver:{major:r.major+1,minor:0,patch:0,pre:[]}}]:l===2?[{op:">=",ver:r},{op:"<",ver:{major:r.major,minor:r.minor+1,patch:0,pre:[]}}]:[{op:"=",ver:r}];default:return null}}function ie(t){return t.major>0?{major:t.major+1,minor:0,patch:0,pre:[]}:t.minor>0?{major:0,minor:t.minor+1,patch:0,pre:[]}:{major:0,minor:0,patch:t.patch+1,pre:[]}}function ae(t){let n=t.replace(/^v/,"").trim();if(!n||n==="*"||n==="x"||n==="X")return{ver:{major:0,minor:0,patch:0,pre:[]},partial:0};let o=n.split("."),r=[],l=0;for(let w of o.slice(0,3))if(/^\\d+$/.test(w))r.push(Number(w)),l++;else{if(w==="x"||w==="X"||w==="*")break;break}let m=n.split("-"),y=m.length>1?m.slice(1).join("-").split("+")[0].split("."):[];return l===0&&y.length===0?{ver:{major:0,minor:0,patch:0,pre:[]},partial:0}:{ver:{major:r[0]??0,minor:r[1]??0,patch:r[2]??0,pre:y},partial:l}}function se(t,n){switch(n){case">=":return t>=0;case">":return t>0;case"<":return t<0;case"<=":return t<=0;case"=":return t===0}}function ue(t,n,o){let r=`${t.major}.${t.minor}.${t.patch}`+(t.pre.length?`-${t.pre.join(".")}`:"");if(o.upper)return!(!(v(r,`${o.ver.major}.${o.ver.minor}.${o.ver.patch}`+(o.ver.pre.length?`-${o.ver.pre.join(".")}`:""))>=0)||!(v(r,`${o.upper.major}.${o.upper.minor}.${o.upper.patch}`)<0));let l=v(r,`${o.ver.major}.${o.ver.minor}.${o.ver.patch}`+(o.ver.pre.length?`-${o.ver.pre.join(".")}`:"")),m=se(l,o.op);return o.ver.pre.length>0&&t.pre.length===0&&(o.op===">"||o.op==="<")?!1:m}var g=class extends Error{code;details;constructor(n,o,r){super(`[fulgurjs:${n}] ${o}`),this.name="FulgurjsError",this.code=n,this.details=r}},R={REMOTE_LOAD_FAILED:"MFU-001",REMOTE_NAME_MISMATCH:"MFU-002",SHARE_STRICT_VERSION:"MFU-003",SHARE_NOT_AVAILABLE:"MFU-004",CONTAINER_REINIT_CONFLICT:"MFU-005",MODULE_NOT_EXPOSED:"MFU-006",PRELOAD_FAILED:"MFU-007",REMOTE_UNKNOWN:"MFU-008",EMPTY_EXPORTS:"MFU-009",SINGLETON_SKEW:"MFU-010"};var F="0.5.0";var U=15e3,P=2,ce=5,le=3e4;function fe(){let t={},n=new Map,o=[],r=new Map,l=new WeakMap,m={};function y(e){m={...m,...e},typeof globalThis<"u"&&(globalThis.__FULGURJS_APP_CONFIG__=m)}function w(){return m}let $={},D=()=>{for(let e of o)try{e.init?.($)}catch(i){console.warn("[fulgurjs] runtimePlugin init failed:",e.name,i)}},N=e=>t[e]??={};function j(e){try{$.onRemoteError?.(e)}catch{}typeof window<"u"&&window.dispatchEvent(new CustomEvent("fulgurjs:error",{detail:e}))}function H(e="default"){return N(e),t}function K(e,i,a,u,E={}){let s=N(e||"default"),c=s[i]??={};c[a]||(c[a]={version:a,get:u,from:E.from??"unknown",eager:!!E.eager,loaded:!!E.loaded})}function x(e){for(let i of e){let a=n.get(i.name);n.set(i.name,{timeout:U,retries:P,...a,...i,state:a?.state??"idle",breakerState:a?.breakerState??{fails:0,openUntil:0},debug:a?.debug??{entry:i.entry,status:"idle"}})}}function q(e){x([e])}function G(e){o.push(...e),D()}async function z(e,i={}){let a=i.shareScope||"default",u=i.shareKey||e,s=N(a)[u]||{},c=Object.keys(s),d=i.requiredVersion,f=c.filter(p=>d===void 0||d===!1||k(p,d)),b;if(i.singleton&&c.length>0){let p=c.filter(h=>s[h].loaded);if(b=[...p.length?p:c].sort(v).pop(),c.length>1||!f.includes(b)){let h=s[b],T=`singleton skew "${u}": req "${d??"any"}" use ${b} from ${h.from}`;if(i.strictVersion){let M=new g(R.SHARE_STRICT_VERSION,T,{shareKey:u,requiredVersion:d});throw j({remote:h.from,error:M}),M}console.warn(`[fulgurjs:MFU-010] ${T}`)}}else if(b=[...f].sort(v).pop(),!b){if(i.strictVersion){let h=new g(R.SHARE_STRICT_VERSION,`no satisfying version for "${u}" (required "${d}") in share scope "${a}"`);throw j({remote:u,error:h}),h}if(i.fallback)return i.fallback();let p=new g(R.SHARE_NOT_AVAILABLE,`shared "${u}" (${d??"any"}) unavailable in scope "${a}" (no local fallback)`,{shareKey:u,requiredVersion:d});throw j({remote:u,error:p}),p}let _=s[b];if($.resolveShare){let p=await $.resolveShare({shareKey:u,shareScope:a,requiredVersion:d,picked:_,available:Object.values(s)});p&&(_=p)}return _.loaded=!0,_.get()}function J(e,i,a){return new Promise((u,E)=>{let s=setTimeout(()=>E(new Error(`timeout after ${i}ms: ${a}`)),i);e.then(c=>{clearTimeout(s),u(c)},c=>{clearTimeout(s),E(c)})})}let W=e=>new Promise(i=>setTimeout(i,e));function I(e,i){if(!e||typeof e.get!="function")throw new Error(`remoteEntry of "${i.name}" does not export a container interface (get/init)`);if(e.name&&i.name&&e.name!==i.name){let a=`remoteEntry self-reported name "${e.name}" mismatches configured name "${i.name}"`;if(i.promise)console.warn(`[fulgurjs] ${a} (promise-based remote, continuing)`);else throw Object.assign(new Error(a),{code:R.REMOTE_NAME_MISMATCH})}}async function L(e,i){return J(import(e),i.timeout??U,`load remoteEntry ${e}`)}async function C(e,i){let a=e.shareScope||"default";if(e.container){let s=l.get(e.container);if(s&&s!==a)throw new g(R.CONTAINER_REINIT_CONFLICT,`container "${e.name}" already initialized with share scope "${s}", cannot re-init with "${a}"`);return e.container}if(e.containerPromise)return e.containerPromise;let u=e.breakerState;if(u.openUntil>Date.now()){let s=new g(R.REMOTE_LOAD_FAILED,`circuit breaker open for remote "${e.name}" until ${new Date(u.openUntil).toISOString()}`,{remote:e.name});throw j({remote:e.name,error:s}),s}e.state="loading",e.debug.status="loading";let E=(async()=>{let s=[];if(e.promise)s.push(async()=>{let p=await e.promise(),h=typeof p=="string"?await L(p,e):p;return I(h,e),h});else for(let p of[e.entry,...e.fallback??[]])s.push(async()=>{let h=await L(p,e);return I(h,e),h});let c,d,f=!1,b=i?.retries??e.retries??P;for(let p of s){for(let h=0;h<=b;h++){let T=performance.now();try{c=await p(),e.lastLoadMs=Math.round(performance.now()-T),e.debug.lastLoadMs=e.lastLoadMs,f=!0;break}catch(M){if(d=M,M?.code)throw M;h<b&&await W(200*2**h)}}if(f)break}if(!f||!c){let p=[];throw/^https?:\\/\\//.test(e.entry)&&typeof location<"u"?(p.push(`1. is the remote dev server running? try opening ${e.entry} in the browser \\u2014 it must return JS, not HTML/an error`),p.push("2. is the URL correct in federation({ remotes })? dev and prod entries can differ"),p.push("3. CORS: the remote dev server must allow cross-origin requests (fulgurjs-federation enables server.cors automatically; a custom server config may have disabled it)")):(p.push(`1. is the remote deployed and reachable? try opening ${e.entry} in the browser \\u2014 it must return JS`),p.push("2. NGINX/CDN routing: the entry path must serve the remoteEntry JS file (check try_files / fallback rules)")),new g(R.REMOTE_LOAD_FAILED,`failed to load remote "${e.name}" from ${e.entry}: ${String(d?.message??d)}\n`+p.join(`\n`),{remote:e.name})}I(c,e);let _=l.get(c);if(_&&_!==a)throw new g(R.CONTAINER_REINIT_CONFLICT,`container "${e.name}" already initialized with share scope "${_}", cannot re-init with "${a}"`);return typeof c.init=="function"&&await c.init(t),l.set(c,a),e.container=c,e.state="loaded",e.debug.status="loaded",u.fails=0,c})();e.containerPromise=E;try{return await E}catch(s){if(e.containerPromise=void 0,e.state="failed",e.debug.status="failed",e.debug.error=String(s?.message??s),u.fails+=1,u.fails>=ce&&(u.openUntil=Date.now()+le,u.fails=0),s instanceof g)throw j({remote:e.name,error:s}),s;if(s?.code)throw j({remote:e.name,error:s}),s;let c=new g(R.REMOTE_LOAD_FAILED,String(s?.message??s),{remote:e.name});throw j({remote:e.name,error:c}),c}}function A(e){let i=e.indexOf("/");return i===-1?{remote:e,module:""}:{remote:e.slice(0,i),module:B(e.slice(i+1))}}function B(e){return e?e.startsWith(".")?e:`./${e}`:""}async function X(e,i){let{remote:a,module:u}=A(e);$.beforeLoadRemote?.({remote:a,module:u});let E=n.get(a);if(!E)throw new g(R.REMOTE_UNKNOWN,`unknown remote "${a}". Register it via federation({ remotes }) or registerRemote().`,{remote:a});let s;try{s=await C(E,{retries:i?.retries})}catch(f){if(i?.fallbackModule)return console.error(`[fulgurjs] loadRemote("${e}") failed; returning fallbackModule (\\u663E\\u5F0F\\u964D\\u7EA7\\uFF0C\\u9519\\u8BEF\\u5DF2\\u900F\\u51FA)`,f),j({remote:a,error:f}),await i.fallbackModule();throw f}if(!u)return s;let c=`${a}@${E.shareScope||"default"}#${u}`;r.has(c)||r.set(c,s.get(u).catch(f=>{throw r.delete(c),f instanceof g||f?.code?f:new g(R.REMOTE_LOAD_FAILED,`failed to load module "${u}" from remote "${a}": ${String(f?.message??f)}`,{remote:a,module:u})}));let d;try{d=await r.get(c)}catch(f){if(i?.fallbackModule)return console.error(`[fulgurjs] loadRemote("${e}") failed; returning fallbackModule (\\u663E\\u5F0F\\u964D\\u7EA7\\uFF0C\\u9519\\u8BEF\\u5DF2\\u900F\\u51FA)`,f),j({remote:a,error:f}),await i.fallbackModule();throw f}if($.afterLoadRemote?.({remote:a,module:u,module_ns:d}),d&&typeof d=="object"&&Object.keys(d).length===0){let f=new g(R.EMPTY_EXPORTS,`no exports: ${u} @ ${a}`,{remote:a,module:u});j({remote:a,error:f}),console.error(`[fulgurjs:MFU-009] ${f.message}`)}return d}function Y(e){let i=n.get(e);if(!i)throw new g(R.REMOTE_UNKNOWN,`unknown remote "${e}"`,{remote:e});return C(i)}async function Z(e,i={}){let{remote:a}=A(e),u=n.get(a);if(!u)throw new g(R.REMOTE_UNKNOWN,`unknown remote "${a}"`,{remote:a});let E=i.mode??"preload",s=(c,d)=>{if(typeof document>"u"||document.querySelector(`link[href="${c}"]`))return;let f=document.createElement("link");f.rel=d==="style"?"stylesheet":"modulepreload",f.href=c,E==="prefetch"&&(f.fetchPriority="low"),document.head.appendChild(f)};try{if(u.manifestUrl){let c=await fetch(u.manifestUrl,{cache:"no-cache"});if(c.ok){let d=await c.json();s(u.entry,"modulepreload");let f=d.exposes??{};for(let b of Object.keys(f)){let _=f[b];_?.file&&s(new URL(_.file,u.entry).href,"modulepreload");for(let p of _?.css??[])s(new URL(p,u.entry).href,"style")}return}}s(u.entry,"modulepreload")}catch(c){j({remote:a,error:new g(R.PRELOAD_FAILED,String(c?.message??c),{remote:a})})}}return typeof window>"u"||(window.__FULGURJS_SCOPE__=t,window.__FULGURJS_INFO__={get remotes(){let e={};for(let[i,a]of n)e[i]={...a.debug,entry:a.entry};return e},errors:[]}),{shareScopeMap:t,initSharing:H,registerShare:K,registerRemotes:x,registerRemote:q,registerPlugins:G,loadShare:z,loadRemote:X,getContainer:Y,preloadRemote:Z,parseSpec:A,provideFulgurjsAppConfig:y,getFulgurjsAppConfig:w}}var V=globalThis,S=V.__FULGURJS_RUNTIME__??fe();V.__FULGURJS_RUNTIME__=S;try{Object.freeze(S)}catch{}var Re=F;function Se(){return S}var we=S.initSharing,be=S.registerShare,_e=S.registerRemotes,je=S.registerRemote,$e=S.registerPlugins,Me=S.loadShare,ve=S.loadRemote,Te=S.getContainer,Oe=S.preloadRemote,ke=S.shareScopeMap,Ne=S.provideFulgurjsAppConfig,Ie=S.getFulgurjsAppConfig;function Ae(t){if(t&&typeof t=="object"&&"default"in t){let n=t.default;return n!==void 0?n:t}return t}var xe=S;export{xe as default,Te as getContainer,Ie as getFulgurjsAppConfig,Se as getRuntime,we as initSharing,ve as loadRemote,Me as loadShare,Oe as preloadRemote,Ne as provideFulgurjsAppConfig,$e as registerPlugins,je as registerRemote,_e as registerRemotes,be as registerShare,S as runtime,ke as shareScopeMap,Ae as unwrapDefault,Re as version};\n';
|
|
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() {
|
|
@@ -1655,7 +1661,7 @@ ${code}`, map: null };
|
|
|
1655
1661
|
if (state.command === "serve" && code.includes("virtual:fulgurjs-runtime") && !code.includes("virtual:fulgurjs-runtime-proxy") && isExposeTargetFile(clean, state.normalized.root, state.normalized.exposes)) {
|
|
1656
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");
|