@fulgurjs/federation 0.5.0 → 0.5.2
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 +16 -0
- package/README.md +8 -8
- package/dist/index.cjs +512 -502
- package/dist/index.js +512 -502
- package/dist/runtime.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import fs from "fs";
|
|
|
8
8
|
import path from "path";
|
|
9
9
|
|
|
10
10
|
// src/version.ts
|
|
11
|
-
var RUNTIME_VERSION = "0.5.
|
|
11
|
+
var RUNTIME_VERSION = "0.5.2";
|
|
12
12
|
|
|
13
13
|
// src/options.ts
|
|
14
14
|
var DEFAULT_FILENAME = "fulgurjs-remoteEntry.js";
|
|
@@ -362,527 +362,246 @@ function normalizeOptions(options, root, command) {
|
|
|
362
362
|
import { init as initLexer, parse } from "es-module-lexer";
|
|
363
363
|
import MagicString from "magic-string";
|
|
364
364
|
import path2 from "path";
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return
|
|
369
|
-
}
|
|
370
|
-
function isExposeTargetFile(cleanPath, root, exposes) {
|
|
371
|
-
for (const e of exposes) {
|
|
372
|
-
const abs = path2.resolve(root, e.import.replace(/^\.\//, ""));
|
|
373
|
-
if (cleanPath === abs) return true;
|
|
374
|
-
for (const ext of [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".vue"]) {
|
|
375
|
-
if (cleanPath === abs + ext) return true;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
function buildSharedMatcher(shared) {
|
|
381
|
-
const exact = /* @__PURE__ */ new Map();
|
|
382
|
-
const prefixes = [];
|
|
383
|
-
for (const s of shared) {
|
|
384
|
-
for (const alias of s.aliases) {
|
|
385
|
-
if (!exact.has(alias)) exact.set(alias, s);
|
|
386
|
-
}
|
|
387
|
-
if (s.configKey.endsWith("/")) prefixes.push({ prefix: s.configKey, item: s });
|
|
388
|
-
}
|
|
389
|
-
return { exact, prefixes };
|
|
390
|
-
}
|
|
391
|
-
function matchShared(spec, matcher) {
|
|
392
|
-
const exact = matcher.exact.get(spec);
|
|
393
|
-
if (exact) return exact;
|
|
394
|
-
for (const p of matcher.prefixes) {
|
|
395
|
-
if (spec.startsWith(p.prefix)) return p.item;
|
|
396
|
-
}
|
|
397
|
-
return null;
|
|
365
|
+
|
|
366
|
+
// src/virtual.ts
|
|
367
|
+
function jsonReplacer(_k, v) {
|
|
368
|
+
return v;
|
|
398
369
|
}
|
|
399
|
-
function
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
370
|
+
function genSharedFacade(specifier, exportNames) {
|
|
371
|
+
const names = (exportNames ?? []).filter(
|
|
372
|
+
(n) => n !== "default" && /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n)
|
|
373
|
+
);
|
|
374
|
+
if (names.length === 0) {
|
|
375
|
+
return [
|
|
376
|
+
`import * as __fulgurjs_facade from ${JSON.stringify(specifier)};`,
|
|
377
|
+
`export * from ${JSON.stringify(specifier)};`,
|
|
378
|
+
`export default __fulgurjs_facade.default ?? __fulgurjs_facade;`,
|
|
379
|
+
""
|
|
380
|
+
].join("\n");
|
|
409
381
|
}
|
|
410
|
-
return
|
|
382
|
+
return [
|
|
383
|
+
`import * as __fulgurjs_facade from ${JSON.stringify(specifier)};`,
|
|
384
|
+
...names.map((n) => `export const ${n} = __fulgurjs_facade[${JSON.stringify(n)}];`),
|
|
385
|
+
`export default __fulgurjs_facade.default ?? __fulgurjs_facade;`,
|
|
386
|
+
""
|
|
387
|
+
].join("\n");
|
|
411
388
|
}
|
|
412
|
-
function
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
389
|
+
function genSharedNsFacade(item, loadShareCall, exportNames) {
|
|
390
|
+
const lines = [
|
|
391
|
+
`import { loadShare as __fulgurjs_loadShare, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
392
|
+
`const __fulgurjs_m = await ${loadShareCall};`,
|
|
393
|
+
`const __fulgurjs_d = __fulgurjsU(__fulgurjs_m);`,
|
|
394
|
+
`export default __fulgurjs_d;`
|
|
395
|
+
];
|
|
396
|
+
const seen = /* @__PURE__ */ new Set(["default"]);
|
|
397
|
+
for (const name of exportNames) {
|
|
398
|
+
if (seen.has(name) || !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name)) continue;
|
|
399
|
+
seen.add(name);
|
|
400
|
+
lines.push(`export const ${name} = __fulgurjs_d[${JSON.stringify(name)}];`);
|
|
422
401
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
function stripComments(s) {
|
|
426
|
-
return s.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
|
|
402
|
+
lines.push("");
|
|
403
|
+
return lines.join("\n");
|
|
427
404
|
}
|
|
428
|
-
function
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
|
|
405
|
+
function genBindingFacade(item, bindings, loadShareCall) {
|
|
406
|
+
const lines = [
|
|
407
|
+
`import { loadShare as __fulgurjs_loadShare, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
408
|
+
`const __fulgurjs_m = await ${loadShareCall};`
|
|
409
|
+
];
|
|
410
|
+
const seen = /* @__PURE__ */ new Set();
|
|
411
|
+
for (const bRaw of bindings) {
|
|
412
|
+
if (bRaw === "default") continue;
|
|
413
|
+
const asMatch = bRaw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
414
|
+
const imported = (asMatch ? asMatch[1] : bRaw).trim();
|
|
415
|
+
if (seen.has(imported)) continue;
|
|
416
|
+
seen.add(imported);
|
|
417
|
+
lines.push(`export const ${imported} = __fulgurjs_m.${imported};`);
|
|
438
418
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const nsMatch = clause.match(/\*\s+as\s+(\w+)/);
|
|
443
|
-
const braceStart = clause.indexOf("{");
|
|
444
|
-
const bindings = braceStart !== -1 ? parseBindings(clause.slice(braceStart + 1, clause.lastIndexOf("}"))) : null;
|
|
445
|
-
let head = clause.replace(/^\s*import\s*/, "");
|
|
446
|
-
if (braceStart !== -1) head = head.slice(0, head.indexOf("{"));
|
|
447
|
-
if (nsMatch) head = head.slice(0, head.indexOf("*"));
|
|
448
|
-
const defaultLocal = head.replace(/,\s*$/, "").trim() || null;
|
|
449
|
-
return { ns: nsMatch?.[1] ?? null, bindings, defaultLocal };
|
|
450
|
-
}
|
|
451
|
-
var JS_EXT_RE = /\.(m|c)?[jt]sx?$/;
|
|
452
|
-
function isTransformableId(id, allowNodeModules = false) {
|
|
453
|
-
const clean = id.split("?")[0];
|
|
454
|
-
if (!JS_EXT_RE.test(clean) && !clean.endsWith(".vue")) return false;
|
|
455
|
-
if (clean.includes("node_modules") && !allowNodeModules) return false;
|
|
456
|
-
return true;
|
|
457
|
-
}
|
|
458
|
-
var facadeRegistry = /* @__PURE__ */ new Map();
|
|
459
|
-
function shortSig(kind, key, bindings) {
|
|
460
|
-
const full = kind + "|" + key + "|" + bindings.join("|");
|
|
461
|
-
let h = 5381;
|
|
462
|
-
for (let i = 0; i < full.length; i++) h = (h << 5) + h + full.charCodeAt(i) | 0;
|
|
463
|
-
const id = (h >>> 0).toString(36) + bindings.length.toString(36);
|
|
464
|
-
facadeRegistry.set(id, kind === "shared" ? { bindings, shareKey: key } : { bindings, remoteName: key });
|
|
465
|
-
return id;
|
|
466
|
-
}
|
|
467
|
-
function getFacadeEntry(id) {
|
|
468
|
-
return facadeRegistry.get(id);
|
|
419
|
+
lines.push(`export default __fulgurjsU(__fulgurjs_m);`);
|
|
420
|
+
lines.push("");
|
|
421
|
+
return lines.join("\n");
|
|
469
422
|
}
|
|
470
|
-
function
|
|
471
|
-
const
|
|
423
|
+
function genRemoteBindingFacade(remoteSpec, bindings) {
|
|
424
|
+
const lines = [
|
|
425
|
+
`import { loadRemote as __fulgurjs_loadRemote, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
426
|
+
`const __fulgurjs_m = await __fulgurjs_loadRemote(${JSON.stringify(remoteSpec)});`
|
|
427
|
+
];
|
|
428
|
+
const seen = /* @__PURE__ */ new Set();
|
|
472
429
|
for (const bRaw of bindings) {
|
|
473
430
|
if (bRaw === "default") continue;
|
|
474
431
|
const asMatch = bRaw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
475
|
-
|
|
432
|
+
const imported = (asMatch ? asMatch[1] : bRaw).trim();
|
|
433
|
+
if (seen.has(imported)) continue;
|
|
434
|
+
seen.add(imported);
|
|
435
|
+
lines.push(`export const ${imported} = __fulgurjs_m.${imported};`);
|
|
476
436
|
}
|
|
477
|
-
|
|
437
|
+
lines.push(`export default __fulgurjsU(__fulgurjs_m);`);
|
|
438
|
+
lines.push("");
|
|
439
|
+
return lines.join("\n");
|
|
478
440
|
}
|
|
479
|
-
function
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
441
|
+
function providesRecords(options) {
|
|
442
|
+
return options.shared.filter((s) => s.import !== false).map((s) => ({
|
|
443
|
+
shareScope: s.shareScope,
|
|
444
|
+
name: s.shareKey,
|
|
445
|
+
version: s.version,
|
|
446
|
+
eager: s.eager,
|
|
447
|
+
from: options.name
|
|
448
|
+
}));
|
|
483
449
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
450
|
+
var INIT_MODULE_MARKER = "/* fulgurjs:init */";
|
|
451
|
+
function genInitModule(options, command) {
|
|
452
|
+
const lines = [INIT_MODULE_MARKER];
|
|
453
|
+
lines.push(`import { initSharing, registerShare, registerRemotes, registerPlugins } from "virtual:fulgurjs-runtime";`);
|
|
454
|
+
const provides = providesRecords(options);
|
|
455
|
+
const eagerShared = options.shared.filter((s) => s.eager && s.import !== false);
|
|
456
|
+
eagerShared.forEach((s, i) => {
|
|
457
|
+
lines.push(`import * as __fulgurjs_eager_${i} from "virtual:fulgurjs-shared:${s.shareKey}";`);
|
|
458
|
+
});
|
|
459
|
+
const isDevHost = command === "serve" && options.remotes.length > 0;
|
|
460
|
+
const loadedFlag = isDevHost ? "true" : "false";
|
|
461
|
+
lines.push(`initSharing(${JSON.stringify(options.shareScope)});`);
|
|
462
|
+
if (options.runtimePlugins.length > 0) {
|
|
463
|
+
options.runtimePlugins.forEach((p, i) => {
|
|
464
|
+
lines.push(`import * as __fulgurjs_rp_${i} from ${JSON.stringify(p)};`);
|
|
465
|
+
});
|
|
466
|
+
lines.push(
|
|
467
|
+
`registerPlugins([${options.runtimePlugins.map((_, i) => `(__fulgurjs_rp_${i}.default ?? __fulgurjs_rp_${i})`).join(", ")}]);`
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
if (options.remotes.length > 0) {
|
|
471
|
+
lines.push(...registerRemotesLines(options, command));
|
|
472
|
+
}
|
|
473
|
+
provides.forEach((p) => {
|
|
474
|
+
const eagerIdx = eagerShared.findIndex((s) => s.shareKey === p.name && s.shareScope === p.shareScope);
|
|
475
|
+
if (p.eager && eagerIdx !== -1) {
|
|
476
|
+
lines.push(
|
|
477
|
+
`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} });`
|
|
478
|
+
);
|
|
479
|
+
} else {
|
|
480
|
+
lines.push(
|
|
481
|
+
`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} });`
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
return `${lines.join("\n")}
|
|
486
|
+
`;
|
|
487
487
|
}
|
|
488
|
-
function
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
488
|
+
function manifestUrlFor(r, command) {
|
|
489
|
+
const entry = command === "serve" ? r.devEntry : r.prodEntry;
|
|
490
|
+
if (!entry) return null;
|
|
491
|
+
try {
|
|
492
|
+
const u = new URL(entry);
|
|
493
|
+
if (u.pathname.includes("@fulgurjs-entry.js")) {
|
|
494
|
+
u.pathname = u.pathname.replace("@fulgurjs-entry.js", "@fulgurjs-manifest.json");
|
|
495
|
+
} else {
|
|
496
|
+
u.pathname = u.pathname.replace(/[^/]*$/, "") + "fulgurjs-manifest.json";
|
|
497
|
+
}
|
|
498
|
+
return u.href;
|
|
499
|
+
} catch {
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
492
502
|
}
|
|
493
|
-
function
|
|
494
|
-
|
|
495
|
-
|
|
503
|
+
function registerRemotesLines(options, command) {
|
|
504
|
+
if (options.remotes.length === 0) return [];
|
|
505
|
+
const remotesJson = options.remotes.filter((r) => !r.promise).map((r) => ({
|
|
506
|
+
name: r.name,
|
|
507
|
+
entry: command === "serve" ? r.devEntry : r.prodEntry,
|
|
508
|
+
shareScope: r.shareScope,
|
|
509
|
+
timeout: r.timeout,
|
|
510
|
+
retries: r.retries,
|
|
511
|
+
fallback: r.fallback,
|
|
512
|
+
breaker: r.breaker,
|
|
513
|
+
manifestUrl: manifestUrlFor(r, command)
|
|
514
|
+
}));
|
|
515
|
+
if (remotesJson.length === 0) return [];
|
|
516
|
+
return [
|
|
517
|
+
`registerRemotes(${JSON.stringify(remotesJson, jsonReplacer).replace(/"manifestUrl":null,?/g, "")});`
|
|
518
|
+
];
|
|
496
519
|
}
|
|
497
|
-
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
}
|
|
510
|
-
let cjsEdited = false;
|
|
511
|
-
for (const [alias, item] of sharedByAlias) {
|
|
512
|
-
const re = new RegExp(`require\\((["'])${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\1\\)`, "g");
|
|
513
|
-
if (!re.test(code)) continue;
|
|
514
|
-
code = code.replace(re, `require(${JSON.stringify(`virtual:fulgurjs-cjs-ns:${item.shareKey}`)})`);
|
|
515
|
-
cjsEdited = true;
|
|
516
|
-
}
|
|
517
|
-
if (!cjsEdited) return null;
|
|
518
|
-
return { code, map: null };
|
|
519
|
-
}
|
|
520
|
-
await ensureLexer();
|
|
521
|
-
let imports;
|
|
522
|
-
try {
|
|
523
|
-
;
|
|
524
|
-
[imports] = parse(code);
|
|
525
|
-
} catch {
|
|
526
|
-
return null;
|
|
527
|
-
}
|
|
528
|
-
const matcher = ctx.rewriteShared ? buildSharedMatcher(options.shared) : null;
|
|
529
|
-
const remotesByKey = new Map(options.remotes.map((r) => [r.key, r]));
|
|
530
|
-
const s = new MagicString(code);
|
|
531
|
-
let edited = false;
|
|
532
|
-
let usesRuntimeHelpers = false;
|
|
533
|
-
const tlaLines = [];
|
|
534
|
-
let tempIdx = 0;
|
|
535
|
-
const genTemp = () => `__fulgurjs_m${tempIdx++}`;
|
|
536
|
-
const remap = (spec) => ctx.remapSpecifier?.(spec) ?? spec;
|
|
537
|
-
const remoteExposeName = (spec, remoteKey) => {
|
|
538
|
-
if (!spec.startsWith(`${remoteKey}/`)) return null;
|
|
539
|
-
const exposeRaw = spec.slice(remoteKey.length + 1);
|
|
540
|
-
if (!exposeRaw) return null;
|
|
541
|
-
return exposeRaw.startsWith(".") ? exposeRaw : `./${exposeRaw}`;
|
|
542
|
-
};
|
|
543
|
-
const bindingsOf = (clause) => [
|
|
544
|
-
...clause.defaultLocal ? ["default"] : [],
|
|
545
|
-
...(clause.bindings ?? []).map((b) => b.imported === b.local ? b.imported : `${b.imported} as ${b.local}`)
|
|
520
|
+
function genRuntimeProxyModule() {
|
|
521
|
+
const promiseApis = [
|
|
522
|
+
"loadRemote",
|
|
523
|
+
"loadShare",
|
|
524
|
+
"preloadRemote",
|
|
525
|
+
"getContainer",
|
|
526
|
+
"registerRemote",
|
|
527
|
+
"registerRemotes",
|
|
528
|
+
"registerShare",
|
|
529
|
+
"initSharing",
|
|
530
|
+
"registerPlugins",
|
|
531
|
+
"parseSpec"
|
|
546
532
|
];
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
export
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
const firstSeg2 = spec2.split("/")[0];
|
|
587
|
-
const remote2 = remotesByKey.get(firstSeg2);
|
|
588
|
-
const exposeName2 = remote2 ? remoteExposeName(spec2, remote2.key) : null;
|
|
589
|
-
if (!shared2 && !(remote2 && exposeName2)) continue;
|
|
590
|
-
edited = true;
|
|
591
|
-
const clauseRaw = code.slice(stmtStart, imp.s).replace(/['"]\s*$/, "");
|
|
592
|
-
const isImport = clauseRaw.trimStart().startsWith("import");
|
|
593
|
-
const clause = parseImportClause(clauseRaw.replace(/\bfrom\s*$/, ""));
|
|
594
|
-
if (clause.ns || /export\s+\*\s+as\s+\w+\s+from/.test(clauseRaw)) {
|
|
595
|
-
genTlaOverwrite(stmtStart, stmtEnd, shared2, remote2?.name ?? null, exposeName2, clauseRaw, clause);
|
|
596
|
-
continue;
|
|
597
|
-
}
|
|
598
|
-
if (!isImport) {
|
|
599
|
-
const inner = clauseRaw.slice(clauseRaw.indexOf("{") + 1, clauseRaw.lastIndexOf("}"));
|
|
600
|
-
if (/export\s+\*/.test(clauseRaw) && !clauseRaw.includes("{")) {
|
|
601
|
-
throw new Error(
|
|
602
|
-
`[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}'".`
|
|
603
|
-
);
|
|
604
|
-
}
|
|
605
|
-
const bindings = parseBindings(inner).map((b) => b.imported === "default" ? "default" : b.imported);
|
|
606
|
-
const facadeSpec2 = shared2 ? facadeSpecFor(ctx, shared2, bindings) : remoteFacadeSpecFor(ctx, remote2.name, exposeName2, bindings);
|
|
607
|
-
s.overwrite(imp.s, imp.e, facadeSpec2);
|
|
608
|
-
continue;
|
|
609
|
-
}
|
|
610
|
-
const facadeSpec = shared2 ? facadeSpecFor(ctx, shared2, bindingsOf(clause)) : remoteFacadeSpecFor(ctx, remote2.name, exposeName2, bindingsOf(clause));
|
|
611
|
-
s.overwrite(imp.s, imp.e, facadeSpec);
|
|
612
|
-
continue;
|
|
613
|
-
}
|
|
614
|
-
const specExpr = code.slice(imp.s, imp.e).trim();
|
|
615
|
-
const literal = specExpr.match(/^['"](.*)['"]$/s);
|
|
616
|
-
if (!literal) continue;
|
|
617
|
-
const spec = remap(literal[1]);
|
|
618
|
-
const shared = matcher ? matchShared(spec, matcher) : null;
|
|
619
|
-
const firstSeg = spec.split("/")[0];
|
|
620
|
-
const remote = remotesByKey.get(firstSeg);
|
|
621
|
-
const exposeName = remote ? remoteExposeName(spec, remote.key) : null;
|
|
622
|
-
if (!shared && !(remote && exposeName)) continue;
|
|
623
|
-
edited = true;
|
|
624
|
-
usesRuntimeHelpers = true;
|
|
625
|
-
const callStart = code.lastIndexOf("import", d);
|
|
626
|
-
const closeParen = code.indexOf(")", imp.e);
|
|
627
|
-
if (shared) {
|
|
628
|
-
s.overwrite(callStart, closeParen + 1, serializeShareCall(shared, ctx?.devUrls));
|
|
629
|
-
} else if (remote && exposeName) {
|
|
630
|
-
s.overwrite(
|
|
631
|
-
callStart,
|
|
632
|
-
closeParen + 1,
|
|
633
|
-
`__fulgurjs_loadRemote(${JSON.stringify(`${remote.name}/${exposeName}`)})`
|
|
634
|
-
);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
if (!edited) return null;
|
|
638
|
-
if (usesRuntimeHelpers) {
|
|
639
|
-
const runtimeSpec = JSON.stringify(ctx.devUrls?.runtime ?? "virtual:fulgurjs-runtime");
|
|
640
|
-
s.prepend(
|
|
641
|
-
`import { loadShare as __fulgurjs_loadShare, loadRemote as __fulgurjs_loadRemote, unwrapDefault as __fulgurjsU } from ${runtimeSpec};
|
|
642
|
-
`
|
|
643
|
-
);
|
|
533
|
+
const lines = [
|
|
534
|
+
`let __fulgurjs_mod_p;`,
|
|
535
|
+
`const __fulgurjs_rt = async () => {`,
|
|
536
|
+
` __fulgurjs_mod_p ??= import('virtual:fulgurjs-runtime');`,
|
|
537
|
+
` return await __fulgurjs_mod_p;`,
|
|
538
|
+
`};`,
|
|
539
|
+
...promiseApis.map((m) => `export const ${m} = (...a) => __fulgurjs_rt().then((m2) => m2.${m}(...a));`),
|
|
540
|
+
`export const getRuntime = () => (globalThis).__FULGURJS_RUNTIME__;`,
|
|
541
|
+
`export const getFulgurjsAppConfig = () =>`,
|
|
542
|
+
` (globalThis).__FULGURJS_RUNTIME__?.getFulgurjsAppConfig?.() ?? (globalThis).__FULGURJS_APP_CONFIG__ ?? {};`,
|
|
543
|
+
`export const provideFulgurjsAppConfig = (c) => {`,
|
|
544
|
+
` const g = (globalThis);`,
|
|
545
|
+
` g.__FULGURJS_APP_CONFIG__ = { ...(g.__FULGURJS_APP_CONFIG__ ?? {}), ...c };`,
|
|
546
|
+
` g.__FULGURJS_RUNTIME__?.provideFulgurjsAppConfig?.(c);`,
|
|
547
|
+
`};`,
|
|
548
|
+
`export const unwrapDefault = (ns) =>`,
|
|
549
|
+
` ns && typeof ns === 'object' && 'default' in ns ? (ns.default !== undefined ? ns.default : ns) : ns;`,
|
|
550
|
+
`export const version = (globalThis).__FULGURJS_RUNTIME__?.version;`,
|
|
551
|
+
`export default { get runtime() { return (globalThis).__FULGURJS_RUNTIME__; } };`,
|
|
552
|
+
``
|
|
553
|
+
];
|
|
554
|
+
return lines.join("\n");
|
|
555
|
+
}
|
|
556
|
+
function genDevRemoteEntry(options, base) {
|
|
557
|
+
const b = base.endsWith("/") ? base : `${base}/`;
|
|
558
|
+
const remoteLines = registerRemotesLines(options, "serve");
|
|
559
|
+
return `import ${JSON.stringify(`${b}@vite/client`)};
|
|
560
|
+
import { name as _fulgurjs_name, exposes, provides } from ${JSON.stringify(`${b}@id/__x00__virtual:fulgurjs-provides`)};
|
|
561
|
+
${remoteLines.length > 0 ? `import { registerRemotes } from ${JSON.stringify(`${b}@id/virtual:fulgurjs-runtime`)};
|
|
562
|
+
${remoteLines.join("\n")}` : ""}
|
|
563
|
+
|
|
564
|
+
export const name = _fulgurjs_name;
|
|
565
|
+
|
|
566
|
+
export async function init(shareScopeMap) {
|
|
567
|
+
for (const p of provides) {
|
|
568
|
+
const scope = shareScopeMap[p.shareScope] || (shareScopeMap[p.shareScope] = {});
|
|
569
|
+
const byName = scope[p.name] || (scope[p.name] = {});
|
|
570
|
+
if (byName[p.version]) continue; // \u5DF2\u6CE8\u518C\u7248\u672C\u6C38\u4E0D\u66FF\u6362
|
|
571
|
+
byName[p.version] = { version: p.version, get: p.get, from: name, eager: p.eager, loaded: false };
|
|
644
572
|
}
|
|
645
|
-
return { code: s.toString(), map: null };
|
|
646
573
|
}
|
|
647
574
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
575
|
+
export async function get(moduleName) {
|
|
576
|
+
const loader = exposes[moduleName];
|
|
577
|
+
if (!loader) {
|
|
578
|
+
const err = new Error('MFU-006: module "' + moduleName + '" is not exposed by remote "' + name + '"');
|
|
579
|
+
err.code = 'MFU-006';
|
|
580
|
+
throw err;
|
|
581
|
+
}
|
|
582
|
+
return loader();
|
|
651
583
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
`
|
|
660
|
-
|
|
661
|
-
""
|
|
662
|
-
].join("\n");
|
|
584
|
+
`;
|
|
585
|
+
}
|
|
586
|
+
function genDevProvides(options) {
|
|
587
|
+
const exposes = [];
|
|
588
|
+
for (const e of options.exposes) {
|
|
589
|
+
const devUrl = `/${e.import.replace(/^\.?\//, "")}`;
|
|
590
|
+
exposes.push(
|
|
591
|
+
` ${JSON.stringify(e.name)}: () => import(${JSON.stringify(devUrl)}),`
|
|
592
|
+
);
|
|
663
593
|
}
|
|
594
|
+
const provides = providesRecords(options).map(
|
|
595
|
+
(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}") },`
|
|
596
|
+
);
|
|
664
597
|
return [
|
|
665
|
-
`
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
const lines = [
|
|
673
|
-
`import { loadShare as __fulgurjs_loadShare, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
674
|
-
`const __fulgurjs_m = await ${loadShareCall};`,
|
|
675
|
-
`const __fulgurjs_d = __fulgurjsU(__fulgurjs_m);`,
|
|
676
|
-
`export default __fulgurjs_d;`
|
|
677
|
-
];
|
|
678
|
-
const seen = /* @__PURE__ */ new Set(["default"]);
|
|
679
|
-
for (const name of exportNames) {
|
|
680
|
-
if (seen.has(name) || !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name)) continue;
|
|
681
|
-
seen.add(name);
|
|
682
|
-
lines.push(`export const ${name} = __fulgurjs_d[${JSON.stringify(name)}];`);
|
|
683
|
-
}
|
|
684
|
-
lines.push("");
|
|
685
|
-
return lines.join("\n");
|
|
686
|
-
}
|
|
687
|
-
function genBindingFacade(item, bindings, loadShareCall) {
|
|
688
|
-
const lines = [
|
|
689
|
-
`import { loadShare as __fulgurjs_loadShare, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
690
|
-
`const __fulgurjs_m = await ${loadShareCall};`
|
|
691
|
-
];
|
|
692
|
-
const seen = /* @__PURE__ */ new Set();
|
|
693
|
-
for (const bRaw of bindings) {
|
|
694
|
-
if (bRaw === "default") continue;
|
|
695
|
-
const asMatch = bRaw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
696
|
-
const imported = (asMatch ? asMatch[1] : bRaw).trim();
|
|
697
|
-
if (seen.has(imported)) continue;
|
|
698
|
-
seen.add(imported);
|
|
699
|
-
lines.push(`export const ${imported} = __fulgurjs_m.${imported};`);
|
|
700
|
-
}
|
|
701
|
-
lines.push(`export default __fulgurjsU(__fulgurjs_m);`);
|
|
702
|
-
lines.push("");
|
|
703
|
-
return lines.join("\n");
|
|
704
|
-
}
|
|
705
|
-
function genRemoteBindingFacade(remoteSpec, bindings) {
|
|
706
|
-
const lines = [
|
|
707
|
-
`import { loadRemote as __fulgurjs_loadRemote, unwrapDefault as __fulgurjsU } from "virtual:fulgurjs-runtime";`,
|
|
708
|
-
`const __fulgurjs_m = await __fulgurjs_loadRemote(${JSON.stringify(remoteSpec)});`
|
|
709
|
-
];
|
|
710
|
-
const seen = /* @__PURE__ */ new Set();
|
|
711
|
-
for (const bRaw of bindings) {
|
|
712
|
-
if (bRaw === "default") continue;
|
|
713
|
-
const asMatch = bRaw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
714
|
-
const imported = (asMatch ? asMatch[1] : bRaw).trim();
|
|
715
|
-
if (seen.has(imported)) continue;
|
|
716
|
-
seen.add(imported);
|
|
717
|
-
lines.push(`export const ${imported} = __fulgurjs_m.${imported};`);
|
|
718
|
-
}
|
|
719
|
-
lines.push(`export default __fulgurjsU(__fulgurjs_m);`);
|
|
720
|
-
lines.push("");
|
|
721
|
-
return lines.join("\n");
|
|
722
|
-
}
|
|
723
|
-
function providesRecords(options) {
|
|
724
|
-
return options.shared.filter((s) => s.import !== false).map((s) => ({
|
|
725
|
-
shareScope: s.shareScope,
|
|
726
|
-
name: s.shareKey,
|
|
727
|
-
version: s.version,
|
|
728
|
-
eager: s.eager,
|
|
729
|
-
from: options.name
|
|
730
|
-
}));
|
|
731
|
-
}
|
|
732
|
-
function genInitModule(options, command) {
|
|
733
|
-
const lines = [];
|
|
734
|
-
lines.push(`import { initSharing, registerShare, registerRemotes, registerPlugins } from "virtual:fulgurjs-runtime";`);
|
|
735
|
-
const provides = providesRecords(options);
|
|
736
|
-
const eagerShared = options.shared.filter((s) => s.eager && s.import !== false);
|
|
737
|
-
eagerShared.forEach((s, i) => {
|
|
738
|
-
lines.push(`import * as __fulgurjs_eager_${i} from "virtual:fulgurjs-shared:${s.shareKey}";`);
|
|
739
|
-
});
|
|
740
|
-
const isDevHost = command === "serve" && options.remotes.length > 0;
|
|
741
|
-
const loadedFlag = isDevHost ? "true" : "false";
|
|
742
|
-
lines.push(`initSharing(${JSON.stringify(options.shareScope)});`);
|
|
743
|
-
if (options.runtimePlugins.length > 0) {
|
|
744
|
-
options.runtimePlugins.forEach((p, i) => {
|
|
745
|
-
lines.push(`import * as __fulgurjs_rp_${i} from ${JSON.stringify(p)};`);
|
|
746
|
-
});
|
|
747
|
-
lines.push(
|
|
748
|
-
`registerPlugins([${options.runtimePlugins.map((_, i) => `(__fulgurjs_rp_${i}.default ?? __fulgurjs_rp_${i})`).join(", ")}]);`
|
|
749
|
-
);
|
|
750
|
-
}
|
|
751
|
-
if (options.remotes.length > 0) {
|
|
752
|
-
lines.push(...registerRemotesLines(options, command));
|
|
753
|
-
}
|
|
754
|
-
provides.forEach((p) => {
|
|
755
|
-
const eagerIdx = eagerShared.findIndex((s) => s.shareKey === p.name && s.shareScope === p.shareScope);
|
|
756
|
-
if (p.eager && eagerIdx !== -1) {
|
|
757
|
-
lines.push(
|
|
758
|
-
`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} });`
|
|
759
|
-
);
|
|
760
|
-
} else {
|
|
761
|
-
lines.push(
|
|
762
|
-
`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} });`
|
|
763
|
-
);
|
|
764
|
-
}
|
|
765
|
-
});
|
|
766
|
-
return `${lines.join("\n")}
|
|
767
|
-
`;
|
|
768
|
-
}
|
|
769
|
-
function manifestUrlFor(r, command) {
|
|
770
|
-
const entry = command === "serve" ? r.devEntry : r.prodEntry;
|
|
771
|
-
if (!entry) return null;
|
|
772
|
-
try {
|
|
773
|
-
const u = new URL(entry);
|
|
774
|
-
if (u.pathname.includes("@fulgurjs-entry.js")) {
|
|
775
|
-
u.pathname = u.pathname.replace("@fulgurjs-entry.js", "@fulgurjs-manifest.json");
|
|
776
|
-
} else {
|
|
777
|
-
u.pathname = u.pathname.replace(/[^/]*$/, "") + "fulgurjs-manifest.json";
|
|
778
|
-
}
|
|
779
|
-
return u.href;
|
|
780
|
-
} catch {
|
|
781
|
-
return null;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
function registerRemotesLines(options, command) {
|
|
785
|
-
if (options.remotes.length === 0) return [];
|
|
786
|
-
const remotesJson = options.remotes.filter((r) => !r.promise).map((r) => ({
|
|
787
|
-
name: r.name,
|
|
788
|
-
entry: command === "serve" ? r.devEntry : r.prodEntry,
|
|
789
|
-
shareScope: r.shareScope,
|
|
790
|
-
timeout: r.timeout,
|
|
791
|
-
retries: r.retries,
|
|
792
|
-
fallback: r.fallback,
|
|
793
|
-
breaker: r.breaker,
|
|
794
|
-
manifestUrl: manifestUrlFor(r, command)
|
|
795
|
-
}));
|
|
796
|
-
if (remotesJson.length === 0) return [];
|
|
797
|
-
return [
|
|
798
|
-
`registerRemotes(${JSON.stringify(remotesJson, jsonReplacer).replace(/"manifestUrl":null,?/g, "")});`
|
|
799
|
-
];
|
|
800
|
-
}
|
|
801
|
-
function genRuntimeProxyModule() {
|
|
802
|
-
const promiseApis = [
|
|
803
|
-
"loadRemote",
|
|
804
|
-
"loadShare",
|
|
805
|
-
"preloadRemote",
|
|
806
|
-
"getContainer",
|
|
807
|
-
"registerRemote",
|
|
808
|
-
"registerRemotes",
|
|
809
|
-
"registerShare",
|
|
810
|
-
"initSharing",
|
|
811
|
-
"registerPlugins",
|
|
812
|
-
"parseSpec"
|
|
813
|
-
];
|
|
814
|
-
const lines = [
|
|
815
|
-
`let __fulgurjs_mod_p;`,
|
|
816
|
-
`const __fulgurjs_rt = async () => {`,
|
|
817
|
-
` __fulgurjs_mod_p ??= import('virtual:fulgurjs-runtime');`,
|
|
818
|
-
` return await __fulgurjs_mod_p;`,
|
|
819
|
-
`};`,
|
|
820
|
-
...promiseApis.map((m) => `export const ${m} = (...a) => __fulgurjs_rt().then((m2) => m2.${m}(...a));`),
|
|
821
|
-
`export const getRuntime = () => (globalThis).__FULGURJS_RUNTIME__;`,
|
|
822
|
-
`export const getFulgurjsAppConfig = () =>`,
|
|
823
|
-
` (globalThis).__FULGURJS_RUNTIME__?.getFulgurjsAppConfig?.() ?? (globalThis).__FULGURJS_APP_CONFIG__ ?? {};`,
|
|
824
|
-
`export const provideFulgurjsAppConfig = (c) => {`,
|
|
825
|
-
` const g = (globalThis);`,
|
|
826
|
-
` g.__FULGURJS_APP_CONFIG__ = { ...(g.__FULGURJS_APP_CONFIG__ ?? {}), ...c };`,
|
|
827
|
-
` g.__FULGURJS_RUNTIME__?.provideFulgurjsAppConfig?.(c);`,
|
|
828
|
-
`};`,
|
|
829
|
-
`export const unwrapDefault = (ns) =>`,
|
|
830
|
-
` ns && typeof ns === 'object' && 'default' in ns ? (ns.default !== undefined ? ns.default : ns) : ns;`,
|
|
831
|
-
`export const version = (globalThis).__FULGURJS_RUNTIME__?.version;`,
|
|
832
|
-
`export default { get runtime() { return (globalThis).__FULGURJS_RUNTIME__; } };`,
|
|
833
|
-
``
|
|
834
|
-
];
|
|
835
|
-
return lines.join("\n");
|
|
836
|
-
}
|
|
837
|
-
function genDevRemoteEntry(options, base) {
|
|
838
|
-
const b = base.endsWith("/") ? base : `${base}/`;
|
|
839
|
-
const remoteLines = registerRemotesLines(options, "serve");
|
|
840
|
-
return `import ${JSON.stringify(`${b}@vite/client`)};
|
|
841
|
-
import { name as _fulgurjs_name, exposes, provides } from ${JSON.stringify(`${b}@id/__x00__virtual:fulgurjs-provides`)};
|
|
842
|
-
${remoteLines.length > 0 ? `import { registerRemotes } from ${JSON.stringify(`${b}@id/virtual:fulgurjs-runtime`)};
|
|
843
|
-
${remoteLines.join("\n")}` : ""}
|
|
844
|
-
|
|
845
|
-
export const name = _fulgurjs_name;
|
|
846
|
-
|
|
847
|
-
export async function init(shareScopeMap) {
|
|
848
|
-
for (const p of provides) {
|
|
849
|
-
const scope = shareScopeMap[p.shareScope] || (shareScopeMap[p.shareScope] = {});
|
|
850
|
-
const byName = scope[p.name] || (scope[p.name] = {});
|
|
851
|
-
if (byName[p.version]) continue; // \u5DF2\u6CE8\u518C\u7248\u672C\u6C38\u4E0D\u66FF\u6362
|
|
852
|
-
byName[p.version] = { version: p.version, get: p.get, from: name, eager: p.eager, loaded: false };
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
export async function get(moduleName) {
|
|
857
|
-
const loader = exposes[moduleName];
|
|
858
|
-
if (!loader) {
|
|
859
|
-
const err = new Error('MFU-006: module "' + moduleName + '" is not exposed by remote "' + name + '"');
|
|
860
|
-
err.code = 'MFU-006';
|
|
861
|
-
throw err;
|
|
862
|
-
}
|
|
863
|
-
return loader();
|
|
864
|
-
}
|
|
865
|
-
`;
|
|
866
|
-
}
|
|
867
|
-
function genDevProvides(options) {
|
|
868
|
-
const exposes = [];
|
|
869
|
-
for (const e of options.exposes) {
|
|
870
|
-
const devUrl = `/${e.import.replace(/^\.?\//, "")}`;
|
|
871
|
-
exposes.push(
|
|
872
|
-
` ${JSON.stringify(e.name)}: () => import(${JSON.stringify(devUrl)}),`
|
|
873
|
-
);
|
|
874
|
-
}
|
|
875
|
-
const provides = providesRecords(options).map(
|
|
876
|
-
(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}") },`
|
|
877
|
-
);
|
|
878
|
-
return [
|
|
879
|
-
`export const name = ${JSON.stringify(options.name)};`,
|
|
880
|
-
`export const exposes = {`,
|
|
881
|
-
...exposes,
|
|
882
|
-
`};`,
|
|
883
|
-
`export const provides = [`,
|
|
884
|
-
...provides,
|
|
885
|
-
`];`,
|
|
598
|
+
`export const name = ${JSON.stringify(options.name)};`,
|
|
599
|
+
`export const exposes = {`,
|
|
600
|
+
...exposes,
|
|
601
|
+
`};`,
|
|
602
|
+
`export const provides = [`,
|
|
603
|
+
...provides,
|
|
604
|
+
`];`,
|
|
886
605
|
""
|
|
887
606
|
].join("\n");
|
|
888
607
|
}
|
|
@@ -942,7 +661,11 @@ function genDevManifest(options, base) {
|
|
|
942
661
|
exposes: options.exposes.map((e) => ({
|
|
943
662
|
name: e.name,
|
|
944
663
|
src: e.import,
|
|
945
|
-
|
|
664
|
+
// 真实可请求的模块 URL(dev 容器 get 的 import 同款裸 URL,base 前缀补齐)——
|
|
665
|
+
// preloadRemote 会把该字段注入 <link rel=modulepreload>,必须是浏览器可 200 的地址。
|
|
666
|
+
// 回归:曾写 dts 虚拟路径 /@fulgurjs-src/...(dts 实际只用 fsRoot+src,不用 file),
|
|
667
|
+
// dev 下 preload 全部 404。
|
|
668
|
+
file: `${b}${e.import.replace(/^\.?\//, "")}`
|
|
946
669
|
})),
|
|
947
670
|
shared: options.shared.map((s) => ({
|
|
948
671
|
name: s.shareKey,
|
|
@@ -975,6 +698,293 @@ function genProdManifest(options, exposeFiles, entryFile) {
|
|
|
975
698
|
};
|
|
976
699
|
}
|
|
977
700
|
|
|
701
|
+
// src/transform.ts
|
|
702
|
+
var lexerReady = null;
|
|
703
|
+
function ensureLexer() {
|
|
704
|
+
lexerReady ??= initLexer;
|
|
705
|
+
return lexerReady;
|
|
706
|
+
}
|
|
707
|
+
function isExposeTargetFile(cleanPath, root, exposes) {
|
|
708
|
+
for (const e of exposes) {
|
|
709
|
+
const abs = path2.resolve(root, e.import.replace(/^\.\//, ""));
|
|
710
|
+
if (cleanPath === abs) return true;
|
|
711
|
+
for (const ext of [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".vue"]) {
|
|
712
|
+
if (cleanPath === abs + ext) return true;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
function buildSharedMatcher(shared) {
|
|
718
|
+
const exact = /* @__PURE__ */ new Map();
|
|
719
|
+
const prefixes = [];
|
|
720
|
+
for (const s of shared) {
|
|
721
|
+
for (const alias of s.aliases) {
|
|
722
|
+
if (!exact.has(alias)) exact.set(alias, s);
|
|
723
|
+
}
|
|
724
|
+
if (s.configKey.endsWith("/")) prefixes.push({ prefix: s.configKey, item: s });
|
|
725
|
+
}
|
|
726
|
+
return { exact, prefixes };
|
|
727
|
+
}
|
|
728
|
+
function matchShared(spec, matcher) {
|
|
729
|
+
const exact = matcher.exact.get(spec);
|
|
730
|
+
if (exact) return exact;
|
|
731
|
+
for (const p of matcher.prefixes) {
|
|
732
|
+
if (spec.startsWith(p.prefix)) return p.item;
|
|
733
|
+
}
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
function serializeShareCallForFacade(item, fallbackUrl) {
|
|
737
|
+
const opts = [];
|
|
738
|
+
opts.push(`shareScope: ${JSON.stringify(item.shareScope)}`);
|
|
739
|
+
opts.push(`shareKey: ${JSON.stringify(item.shareKey)}`);
|
|
740
|
+
if (item.requiredVersion !== false) opts.push(`requiredVersion: ${JSON.stringify(item.requiredVersion)}`);
|
|
741
|
+
if (item.singleton) opts.push("singleton: true");
|
|
742
|
+
if (item.strictVersion) opts.push("strictVersion: true");
|
|
743
|
+
if (item.import !== false) {
|
|
744
|
+
const facadeUrl = fallbackUrl ?? SHARED_FACADE_PREFIX + item.shareKey;
|
|
745
|
+
opts.push(`fallback: () => import(${JSON.stringify(facadeUrl)})`);
|
|
746
|
+
}
|
|
747
|
+
return `__fulgurjs_loadShare(${JSON.stringify(item.shareKey)}, { ${opts.join(", ")} })`;
|
|
748
|
+
}
|
|
749
|
+
function serializeShareCall(item, devUrls) {
|
|
750
|
+
const opts = [];
|
|
751
|
+
opts.push(`shareScope: ${JSON.stringify(item.shareScope)}`);
|
|
752
|
+
opts.push(`shareKey: ${JSON.stringify(item.shareKey)}`);
|
|
753
|
+
if (item.requiredVersion !== false) opts.push(`requiredVersion: ${JSON.stringify(item.requiredVersion)}`);
|
|
754
|
+
if (item.singleton) opts.push("singleton: true");
|
|
755
|
+
if (item.strictVersion) opts.push("strictVersion: true");
|
|
756
|
+
if (item.import !== false) {
|
|
757
|
+
const facadeUrl = devUrls ? devUrls.namespaceFacade(item.shareKey) : SHARED_FACADE_PREFIX + item.shareKey;
|
|
758
|
+
opts.push(`fallback: () => import(${JSON.stringify(facadeUrl)})`);
|
|
759
|
+
}
|
|
760
|
+
return `__fulgurjs_loadShare(${JSON.stringify(item.shareKey)}, { ${opts.join(", ")} })`;
|
|
761
|
+
}
|
|
762
|
+
function stripComments(s) {
|
|
763
|
+
return s.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
|
|
764
|
+
}
|
|
765
|
+
function parseBindings(inner) {
|
|
766
|
+
const out = [];
|
|
767
|
+
for (const piece of stripComments(inner).split(",")) {
|
|
768
|
+
const raw = piece.trim();
|
|
769
|
+
if (!raw) continue;
|
|
770
|
+
if (/^type\s/.test(raw)) continue;
|
|
771
|
+
const asMatch = raw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
772
|
+
const imported = asMatch ? asMatch[1].trim() : raw;
|
|
773
|
+
const local = asMatch ? asMatch[2].trim() : raw;
|
|
774
|
+
out.push({ imported, local, isDefault: imported === "default" });
|
|
775
|
+
}
|
|
776
|
+
return out;
|
|
777
|
+
}
|
|
778
|
+
function parseImportClause(clause) {
|
|
779
|
+
const nsMatch = clause.match(/\*\s+as\s+(\w+)/);
|
|
780
|
+
const braceStart = clause.indexOf("{");
|
|
781
|
+
const bindings = braceStart !== -1 ? parseBindings(clause.slice(braceStart + 1, clause.lastIndexOf("}"))) : null;
|
|
782
|
+
let head = clause.replace(/^\s*import\s*/, "");
|
|
783
|
+
if (braceStart !== -1) head = head.slice(0, head.indexOf("{"));
|
|
784
|
+
if (nsMatch) head = head.slice(0, head.indexOf("*"));
|
|
785
|
+
const defaultLocal = head.replace(/,\s*$/, "").trim() || null;
|
|
786
|
+
return { ns: nsMatch?.[1] ?? null, bindings, defaultLocal };
|
|
787
|
+
}
|
|
788
|
+
var JS_EXT_RE = /\.(m|c)?[jt]sx?$/;
|
|
789
|
+
function isTransformableId(id, allowNodeModules = false) {
|
|
790
|
+
const clean = id.split("?")[0];
|
|
791
|
+
if (!JS_EXT_RE.test(clean) && !clean.endsWith(".vue")) return false;
|
|
792
|
+
if (clean.includes("node_modules") && !allowNodeModules) return false;
|
|
793
|
+
return true;
|
|
794
|
+
}
|
|
795
|
+
function isPluginProcessedModule(code) {
|
|
796
|
+
return code.includes("virtual:fulgurjs-runtime-proxy") || code.includes("__fulgurjs_loadRemote") || code.includes("__fulgurjs_loadShare") || code.includes(INIT_MODULE_MARKER);
|
|
797
|
+
}
|
|
798
|
+
var facadeRegistry = /* @__PURE__ */ new Map();
|
|
799
|
+
function shortSig(kind, key, bindings) {
|
|
800
|
+
const full = kind + "|" + key + "|" + bindings.join("|");
|
|
801
|
+
let h = 5381;
|
|
802
|
+
for (let i = 0; i < full.length; i++) h = (h << 5) + h + full.charCodeAt(i) | 0;
|
|
803
|
+
const id = (h >>> 0).toString(36) + bindings.length.toString(36);
|
|
804
|
+
facadeRegistry.set(id, kind === "shared" ? { bindings, shareKey: key } : { bindings, remoteName: key });
|
|
805
|
+
return id;
|
|
806
|
+
}
|
|
807
|
+
function getFacadeEntry(id) {
|
|
808
|
+
return facadeRegistry.get(id);
|
|
809
|
+
}
|
|
810
|
+
function canonicalBindings(bindings) {
|
|
811
|
+
const names = /* @__PURE__ */ new Set();
|
|
812
|
+
for (const bRaw of bindings) {
|
|
813
|
+
if (bRaw === "default") continue;
|
|
814
|
+
const asMatch = bRaw.match(/^(.*?)\s+as\s+(.+)$/);
|
|
815
|
+
names.add((asMatch ? asMatch[1] : bRaw).trim());
|
|
816
|
+
}
|
|
817
|
+
return [...names].sort();
|
|
818
|
+
}
|
|
819
|
+
function bindingFacadeId(item, bindings) {
|
|
820
|
+
const canonical = canonicalBindings(bindings);
|
|
821
|
+
const sig = canonical.length ? `?f=${shortSig("shared", item.shareKey, canonical)}` : "";
|
|
822
|
+
return `${SHARED_FACADE_PREFIX}${item.shareKey}${sig}`;
|
|
823
|
+
}
|
|
824
|
+
function facadeSpecFor(ctx, item, bindings) {
|
|
825
|
+
const id = bindingFacadeId(item, bindings);
|
|
826
|
+
return ctx.devUrls ? ctx.devUrls.bindingFacade(id) : id;
|
|
827
|
+
}
|
|
828
|
+
function remoteBindingFacadeId(remoteName, exposeName, bindings) {
|
|
829
|
+
const canonical = canonicalBindings(bindings);
|
|
830
|
+
const sig = canonical.length ? `?f=${shortSig("remote", `${remoteName}/${exposeName}`, canonical)}` : "";
|
|
831
|
+
return `${SHARED_FACADE_PREFIX}__remote__${remoteName}/${exposeName}${sig}`;
|
|
832
|
+
}
|
|
833
|
+
function remoteFacadeSpecFor(ctx, remoteName, exposeName, bindings) {
|
|
834
|
+
const id = remoteBindingFacadeId(remoteName, exposeName, bindings);
|
|
835
|
+
return ctx.devUrls ? ctx.devUrls.bindingFacade(id) : id;
|
|
836
|
+
}
|
|
837
|
+
async function transformModule(code, id, ctx) {
|
|
838
|
+
const { options } = ctx;
|
|
839
|
+
if (options.shared.length === 0 && options.remotes.length === 0) return null;
|
|
840
|
+
const candidates = [];
|
|
841
|
+
for (const s2 of options.shared) candidates.push(s2.configKey.replace(/\/$/, ""));
|
|
842
|
+
for (const r of options.remotes) candidates.push(r.key);
|
|
843
|
+
if (!candidates.some((c) => code.includes(c))) return null;
|
|
844
|
+
if (ctx.cjsRequireRewrite && /require\s*\(\s*["']/.test(code)) {
|
|
845
|
+
const sharedByAlias = /* @__PURE__ */ new Map();
|
|
846
|
+
for (const s2 of options.shared) {
|
|
847
|
+
if (s2.import === false) continue;
|
|
848
|
+
for (const a of s2.aliases) if (!a.includes("/")) sharedByAlias.set(a, s2);
|
|
849
|
+
}
|
|
850
|
+
let cjsEdited = false;
|
|
851
|
+
for (const [alias, item] of sharedByAlias) {
|
|
852
|
+
const re = new RegExp(`require\\((["'])${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\1\\)`, "g");
|
|
853
|
+
if (!re.test(code)) continue;
|
|
854
|
+
code = code.replace(re, `require(${JSON.stringify(`virtual:fulgurjs-cjs-ns:${item.shareKey}`)})`);
|
|
855
|
+
cjsEdited = true;
|
|
856
|
+
}
|
|
857
|
+
if (!cjsEdited) return null;
|
|
858
|
+
return { code, map: null };
|
|
859
|
+
}
|
|
860
|
+
await ensureLexer();
|
|
861
|
+
let imports;
|
|
862
|
+
try {
|
|
863
|
+
;
|
|
864
|
+
[imports] = parse(code);
|
|
865
|
+
} catch {
|
|
866
|
+
return null;
|
|
867
|
+
}
|
|
868
|
+
const matcher = ctx.rewriteShared ? buildSharedMatcher(options.shared) : null;
|
|
869
|
+
const remotesByKey = new Map(options.remotes.map((r) => [r.key, r]));
|
|
870
|
+
const s = new MagicString(code);
|
|
871
|
+
let edited = false;
|
|
872
|
+
let usesRuntimeHelpers = false;
|
|
873
|
+
const tlaLines = [];
|
|
874
|
+
let tempIdx = 0;
|
|
875
|
+
const genTemp = () => `__fulgurjs_m${tempIdx++}`;
|
|
876
|
+
const remap = (spec) => ctx.remapSpecifier?.(spec) ?? spec;
|
|
877
|
+
const remoteExposeName = (spec, remoteKey) => {
|
|
878
|
+
if (!spec.startsWith(`${remoteKey}/`)) return null;
|
|
879
|
+
const exposeRaw = spec.slice(remoteKey.length + 1);
|
|
880
|
+
if (!exposeRaw) return null;
|
|
881
|
+
return exposeRaw.startsWith(".") ? exposeRaw : `./${exposeRaw}`;
|
|
882
|
+
};
|
|
883
|
+
const bindingsOf = (clause) => [
|
|
884
|
+
...clause.defaultLocal ? ["default"] : [],
|
|
885
|
+
...(clause.bindings ?? []).map((b) => b.imported === b.local ? b.imported : `${b.imported} as ${b.local}`)
|
|
886
|
+
];
|
|
887
|
+
const genTlaOverwrite = (stmtStart, stmtEnd, shared, remoteName, exposeName, clauseRaw, clause) => {
|
|
888
|
+
usesRuntimeHelpers = true;
|
|
889
|
+
const call = shared ? serializeShareCall(shared, ctx?.devUrls) : `__fulgurjs_loadRemote(${JSON.stringify(`${remoteName}/${exposeName}`)})`;
|
|
890
|
+
const nsAs = clauseRaw.match(/export\s+\*\s+as\s+(\w+)\s+from/);
|
|
891
|
+
if (nsAs) {
|
|
892
|
+
s.overwrite(stmtStart, stmtEnd, `const ${nsAs[1]} = await ${call};
|
|
893
|
+
export { ${nsAs[1]} };`);
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
if (!clause.ns && !clause.bindings && !clause.defaultLocal) {
|
|
897
|
+
s.overwrite(stmtStart, stmtEnd, `await ${call};`);
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
const tmp = genTemp();
|
|
901
|
+
const parts = [`${tmp} = await ${call}`];
|
|
902
|
+
if (clause.ns) parts.push(`${clause.ns} = ${tmp}`);
|
|
903
|
+
if (clause.defaultLocal) parts.push(`${clause.defaultLocal} = __fulgurjsU(${tmp})`);
|
|
904
|
+
const named = clause.bindings?.filter((b) => !b.isDefault) ?? [];
|
|
905
|
+
if (named.length) {
|
|
906
|
+
const destructure = named.map((b) => b.imported === b.local ? b.local : `${b.imported}: ${b.local}`);
|
|
907
|
+
parts.push(`{ ${destructure.join(", ")} } = ${tmp}`);
|
|
908
|
+
}
|
|
909
|
+
for (const b of clause.bindings?.filter((x) => x.isDefault) ?? []) {
|
|
910
|
+
parts.push(`${b.local} = __fulgurjsU(${tmp})`);
|
|
911
|
+
}
|
|
912
|
+
s.overwrite(stmtStart, stmtEnd, `const ${parts.join(", ")}`);
|
|
913
|
+
};
|
|
914
|
+
for (const imp of imports) {
|
|
915
|
+
const { d } = imp;
|
|
916
|
+
if (d === -2) continue;
|
|
917
|
+
if (d === -1) {
|
|
918
|
+
const rawSpec = code.slice(imp.s, imp.e).replace(/['"]/g, "");
|
|
919
|
+
const spec2 = remap(rawSpec);
|
|
920
|
+
const stmtStart = imp.ss;
|
|
921
|
+
let stmtEnd = imp.se;
|
|
922
|
+
while (code[stmtEnd] === ";") stmtEnd++;
|
|
923
|
+
const head = code.slice(stmtStart, stmtStart + 24);
|
|
924
|
+
if (/^\s*(import|export)\s+type[\s{]/.test(head)) continue;
|
|
925
|
+
const shared2 = matcher ? matchShared(spec2, matcher) : null;
|
|
926
|
+
const firstSeg2 = spec2.split("/")[0];
|
|
927
|
+
const remote2 = remotesByKey.get(firstSeg2);
|
|
928
|
+
const exposeName2 = remote2 ? remoteExposeName(spec2, remote2.key) : null;
|
|
929
|
+
if (!shared2 && !(remote2 && exposeName2)) continue;
|
|
930
|
+
edited = true;
|
|
931
|
+
const clauseRaw = code.slice(stmtStart, imp.s).replace(/['"]\s*$/, "");
|
|
932
|
+
const isImport = clauseRaw.trimStart().startsWith("import");
|
|
933
|
+
const clause = parseImportClause(clauseRaw.replace(/\bfrom\s*$/, ""));
|
|
934
|
+
if (clause.ns || /export\s+\*\s+as\s+\w+\s+from/.test(clauseRaw)) {
|
|
935
|
+
genTlaOverwrite(stmtStart, stmtEnd, shared2, remote2?.name ?? null, exposeName2, clauseRaw, clause);
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
if (!isImport) {
|
|
939
|
+
const inner = clauseRaw.slice(clauseRaw.indexOf("{") + 1, clauseRaw.lastIndexOf("}"));
|
|
940
|
+
if (/export\s+\*/.test(clauseRaw) && !clauseRaw.includes("{")) {
|
|
941
|
+
throw new Error(
|
|
942
|
+
`[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}'".`
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
const bindings = parseBindings(inner).map((b) => b.imported === "default" ? "default" : b.imported);
|
|
946
|
+
const facadeSpec2 = shared2 ? facadeSpecFor(ctx, shared2, bindings) : remoteFacadeSpecFor(ctx, remote2.name, exposeName2, bindings);
|
|
947
|
+
s.overwrite(imp.s, imp.e, facadeSpec2);
|
|
948
|
+
continue;
|
|
949
|
+
}
|
|
950
|
+
const facadeSpec = shared2 ? facadeSpecFor(ctx, shared2, bindingsOf(clause)) : remoteFacadeSpecFor(ctx, remote2.name, exposeName2, bindingsOf(clause));
|
|
951
|
+
s.overwrite(imp.s, imp.e, facadeSpec);
|
|
952
|
+
continue;
|
|
953
|
+
}
|
|
954
|
+
const specExpr = code.slice(imp.s, imp.e).trim();
|
|
955
|
+
const literal = specExpr.match(/^['"](.*)['"]$/s);
|
|
956
|
+
if (!literal) continue;
|
|
957
|
+
const spec = remap(literal[1]);
|
|
958
|
+
const shared = matcher ? matchShared(spec, matcher) : null;
|
|
959
|
+
const firstSeg = spec.split("/")[0];
|
|
960
|
+
const remote = remotesByKey.get(firstSeg);
|
|
961
|
+
const exposeName = remote ? remoteExposeName(spec, remote.key) : null;
|
|
962
|
+
if (!shared && !(remote && exposeName)) continue;
|
|
963
|
+
edited = true;
|
|
964
|
+
usesRuntimeHelpers = true;
|
|
965
|
+
const callStart = code.lastIndexOf("import", d);
|
|
966
|
+
const closeParen = code.indexOf(")", imp.e);
|
|
967
|
+
if (shared) {
|
|
968
|
+
s.overwrite(callStart, closeParen + 1, serializeShareCall(shared, ctx?.devUrls));
|
|
969
|
+
} else if (remote && exposeName) {
|
|
970
|
+
s.overwrite(
|
|
971
|
+
callStart,
|
|
972
|
+
closeParen + 1,
|
|
973
|
+
`__fulgurjs_loadRemote(${JSON.stringify(`${remote.name}/${exposeName}`)})`
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
if (!edited) return null;
|
|
978
|
+
if (usesRuntimeHelpers) {
|
|
979
|
+
const runtimeSpec = JSON.stringify(ctx.devUrls?.runtime ?? "virtual:fulgurjs-runtime");
|
|
980
|
+
s.prepend(
|
|
981
|
+
`import { loadShare as __fulgurjs_loadShare, loadRemote as __fulgurjs_loadRemote, unwrapDefault as __fulgurjsU } from ${runtimeSpec};
|
|
982
|
+
`
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
return { code: s.toString(), map: null };
|
|
986
|
+
}
|
|
987
|
+
|
|
978
988
|
// src/dts.ts
|
|
979
989
|
import fs2 from "fs";
|
|
980
990
|
import path3 from "path";
|
|
@@ -1181,7 +1191,7 @@ function syncViteCacheMarker(root, pluginVersion, log) {
|
|
|
1181
1191
|
}
|
|
1182
1192
|
|
|
1183
1193
|
// src/runtime-code.gen.ts
|
|
1184
|
-
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';
|
|
1194
|
+
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.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.__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';
|
|
1185
1195
|
|
|
1186
1196
|
// src/index.ts
|
|
1187
1197
|
function readRuntimeCode() {
|
|
@@ -1620,7 +1630,7 @@ ${code}`, map: null };
|
|
|
1620
1630
|
if (state.command === "serve" && code.includes("virtual:fulgurjs-runtime") && !code.includes("virtual:fulgurjs-runtime-proxy") && isExposeTargetFile(clean, state.normalized.root, state.normalized.exposes)) {
|
|
1621
1631
|
return { code: code.split("virtual:fulgurjs-runtime").join("virtual:fulgurjs-runtime-proxy"), map: null };
|
|
1622
1632
|
}
|
|
1623
|
-
if (code
|
|
1633
|
+
if (isPluginProcessedModule(code)) return null;
|
|
1624
1634
|
if (state.command === "build" && !/\.vue(\?|$)/.test(id)) return null;
|
|
1625
1635
|
if (/type=(style|template)/.test(id)) return null;
|
|
1626
1636
|
const isJsLike = /\.(m|c)?[jt]sx?$/.test(clean) || clean.endsWith(".vue");
|