@markless/bundler 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-worker.d.ts +1 -0
- package/dist/build-worker.js +59 -0
- package/dist/chunk-ast-C8zKZiam.js +1 -0
- package/dist/chunk-ast-pN_P5wIo.js +204 -0
- package/dist/chunk-tasks-BexSGNjx.js +1 -0
- package/dist/compile-store-DxF9Vj4_.js +187 -0
- package/dist/{execution-log-6xkAwVG_.d.ts → execution-log-7HH5XDfA.d.ts} +2 -2
- package/dist/lazy-module-facades-qZajWDD8.js +2691 -0
- package/dist/planned-landing-BHy22Yf5.js +2291 -0
- package/dist/preload.d.ts +2 -2
- package/dist/preload.js +2 -2
- package/dist/{rolldown-Bh_TCkt_.js → rolldown-DS8OY1i9.js} +482 -3836
- package/dist/rolldown.d.ts +3 -3
- package/dist/rolldown.js +3 -2
- package/dist/{route-pack-groups-0vHmSVdv.js → route-pack-groups-ByQmKKom.js} +363 -1033
- package/dist/{types-5srcMsXU.d.ts → types-B8YqEscg.d.ts} +45 -2
- package/dist/vite.d.ts +6 -1
- package/dist/vite.js +791 -25
- package/package.json +6 -5
- package/dist/optimized-deps-BfzxSm6C.js +0 -89
|
@@ -1,140 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, join, normalize, relative, resolve } from "pathe";
|
|
3
|
+
import { withQuery } from "ufo";
|
|
2
4
|
import { INLINE_RESUMER_PAGE_TOKEN, PRERENDER_INLINE_EVENT_NAMES_TOKEN, createInlineResumerDebugRegistrationSource, createInlineResumerSelfWakeSource, createInlineResumerSource, createPrerenderInlineResumerSource, createPrerenderSettleInlineResumerSource } from "@markless/web/inline/resumer";
|
|
5
|
+
import { minifySync, transformSync } from "rolldown/experimental";
|
|
3
6
|
import { MARKLESS_COMPONENT_PART_BRAND } from "@markless/web/render-to-string";
|
|
4
|
-
import { ASYNC_PROTOCOL_VERSION,
|
|
5
|
-
import { isAbsolute, resolve } from "pathe";
|
|
6
|
-
import { emitSymbolResolverModule } from "@markless/compiler";
|
|
7
|
-
//#region src/build/preload-plan.ts
|
|
8
|
-
const DEFAULT_MIN_PROBABILITY = 0;
|
|
9
|
-
const JAVASCRIPT_MODULE_RE = /\.(?:mjs|js)(?:[?#].*)?$/;
|
|
10
|
-
const PRIORITY_RANK = {
|
|
11
|
-
high: 2,
|
|
12
|
-
auto: 1,
|
|
13
|
-
low: 0
|
|
14
|
-
};
|
|
15
|
-
function planModulePreloadUrls(input) {
|
|
16
|
-
return planModulePreloads(input).map((preload) => preload.href);
|
|
17
|
-
}
|
|
18
|
-
function planModulePreloads(input) {
|
|
19
|
-
const minProbability = input.minProbability ?? DEFAULT_MIN_PROBABILITY;
|
|
20
|
-
const maxPreloads = input.maxPreloads ?? Number.POSITIVE_INFINITY;
|
|
21
|
-
const graph = parseBundleGraph(input.bundleGraph);
|
|
22
|
-
const planned = /* @__PURE__ */ new Map();
|
|
23
|
-
const bestVisitByNode = /* @__PURE__ */ new Map();
|
|
24
|
-
let order = 0;
|
|
25
|
-
const addModule = (name, probability, priority, fetchPriority) => {
|
|
26
|
-
if (!isPreloadableModuleName(name)) return;
|
|
27
|
-
const href = preloadHref(input.base, name);
|
|
28
|
-
const existing = planned.get(href);
|
|
29
|
-
const nextRank = PRIORITY_RANK[priority];
|
|
30
|
-
const existingRank = existing ? PRIORITY_RANK[existing.priority] : -1;
|
|
31
|
-
if (existing && (existingRank > nextRank || existingRank === nextRank && existing.probability >= probability)) return;
|
|
32
|
-
planned.set(href, {
|
|
33
|
-
fetchPriority,
|
|
34
|
-
href,
|
|
35
|
-
name,
|
|
36
|
-
order: existing?.order ?? order++,
|
|
37
|
-
priority,
|
|
38
|
-
probability
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
const visit = (name, probability, priority, fetchPriority, seen, suppressed = false, suppressRootOnly = false) => {
|
|
42
|
-
if (probability < minProbability || planned.size >= maxPreloads) return;
|
|
43
|
-
if (!suppressed) {
|
|
44
|
-
const priorityRank = PRIORITY_RANK[priority];
|
|
45
|
-
const previousBest = bestVisitByNode.get(name);
|
|
46
|
-
if (previousBest && (previousBest.priorityRank > priorityRank || previousBest.priorityRank === priorityRank && previousBest.probability >= probability)) return;
|
|
47
|
-
bestVisitByNode.set(name, {
|
|
48
|
-
priorityRank,
|
|
49
|
-
probability
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
if (seen.has(name)) return;
|
|
53
|
-
const nextSeen = new Set(seen);
|
|
54
|
-
nextSeen.add(name);
|
|
55
|
-
const record = graph.get(name);
|
|
56
|
-
if (!record) {
|
|
57
|
-
if (!suppressed) addModule(name, probability, priority, fetchPriority);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
for (const dep of record.deps.filter((item) => item.kind === "static")) visit(dep.name, probability * dep.probability, priority, fetchPriority, nextSeen, suppressed && !suppressRootOnly);
|
|
61
|
-
if (!suppressed) addModule(name, probability, priority, fetchPriority);
|
|
62
|
-
for (const dep of record.deps.filter((item) => item.kind === "dynamic")) {
|
|
63
|
-
if (input.lazyChunks?.has(dep.name)) continue;
|
|
64
|
-
const edgeProbability = JAVASCRIPT_MODULE_RE.test(name) ? dep.probability : 1;
|
|
65
|
-
visit(dep.name, probability * edgeProbability, priority, fetchPriority, nextSeen, false);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
for (const root of input.roots) {
|
|
69
|
-
const normalized = normalizeRoot(root);
|
|
70
|
-
visit(normalized.name, 1, normalized.priority, normalized.fetchPriority, /* @__PURE__ */ new Set(), normalized.edges === "dynamic-only" || normalized.edges === "dependencies-only", normalized.edges === "dependencies-only");
|
|
71
|
-
}
|
|
72
|
-
return [...planned.values()].sort((left, right) => {
|
|
73
|
-
const priority = PRIORITY_RANK[right.priority] - PRIORITY_RANK[left.priority];
|
|
74
|
-
if (priority !== 0) return priority;
|
|
75
|
-
return left.order - right.order;
|
|
76
|
-
}).slice(0, maxPreloads).map(({ order: _order, ...preload }) => preload);
|
|
77
|
-
}
|
|
78
|
-
function parseBundleGraph(graph) {
|
|
79
|
-
const records = /* @__PURE__ */ new Map();
|
|
80
|
-
if (!graph) return records;
|
|
81
|
-
let index = 0;
|
|
82
|
-
while (index < graph.length) {
|
|
83
|
-
const name = graph[index++];
|
|
84
|
-
if (typeof name !== "string") continue;
|
|
85
|
-
const deps = [];
|
|
86
|
-
let probability = 1;
|
|
87
|
-
let kind = "static";
|
|
88
|
-
while (typeof graph[index] === "number") {
|
|
89
|
-
const marker = graph[index++];
|
|
90
|
-
if (marker < 0) {
|
|
91
|
-
probability = -marker / 10;
|
|
92
|
-
kind = "dynamic";
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
const dep = graph[marker];
|
|
96
|
-
if (typeof dep === "string") deps.push({
|
|
97
|
-
name: dep,
|
|
98
|
-
kind,
|
|
99
|
-
probability
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
records.set(name, {
|
|
103
|
-
name,
|
|
104
|
-
deps
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
return records;
|
|
108
|
-
}
|
|
109
|
-
function preloadHref(base, name) {
|
|
110
|
-
if (!base || /^(?:[a-z]+:)?\/\//i.test(name)) return name;
|
|
111
|
-
return joinURL(base, name);
|
|
112
|
-
}
|
|
113
|
-
function isPreloadableModuleName(name) {
|
|
114
|
-
return JAVASCRIPT_MODULE_RE.test(name) || isViteDevModuleUrl(name);
|
|
115
|
-
}
|
|
116
|
-
function isViteDevModuleUrl(name) {
|
|
117
|
-
return (name.startsWith("/") || name.startsWith("@id/")) && /(?:^|[?&])import(?:[&#]|$)/.test(name);
|
|
118
|
-
}
|
|
119
|
-
function normalizeRoot(root) {
|
|
120
|
-
if (typeof root === "string") return {
|
|
121
|
-
name: root,
|
|
122
|
-
priority: "auto",
|
|
123
|
-
fetchPriority: "auto"
|
|
124
|
-
};
|
|
125
|
-
const priority = root.priority ?? "auto";
|
|
126
|
-
return {
|
|
127
|
-
name: root.name,
|
|
128
|
-
priority,
|
|
129
|
-
edges: root.edges,
|
|
130
|
-
fetchPriority: root.fetchPriority ?? priorityToFetchPriority(priority)
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function priorityToFetchPriority(priority) {
|
|
134
|
-
if (priority === "auto") return "auto";
|
|
135
|
-
return priority;
|
|
136
|
-
}
|
|
137
|
-
//#endregion
|
|
7
|
+
import { ASYNC_PROTOCOL_VERSION, protocolBoundSymbolPrefix } from "@markless/serializer";
|
|
138
8
|
//#region src/execution-log.ts
|
|
139
9
|
const MARKLESS_EXECUTION_LOG_MODULE_ID = "virtual:markless:dev-log";
|
|
140
10
|
const MARKLESS_EXECUTION_LOG_GLOBAL = "__mxLog";
|
|
@@ -662,6 +532,10 @@ const PROTOCOL_EVENT_HOST_ATTRIBUTE = "m:on";
|
|
|
662
532
|
//#region ../serializer/src/protocol-page-markers.ts
|
|
663
533
|
const PROTOCOL_CONTAINER_START_COMMENT = "markless:page-start";
|
|
664
534
|
const PROTOCOL_CONTAINER_END_COMMENT = "markless:page-end";
|
|
535
|
+
const PROTOCOL_BLOCK_START_COMMENT = /^markless:(?:branch|arm-branch|async):/;
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region ../serializer/src/protocol-stream-open.ts
|
|
538
|
+
const PROTOCOL_STREAM_OPEN_PROPERTY = "__mStreamOpen";
|
|
665
539
|
//#endregion
|
|
666
540
|
//#region ../web/src/inline/defer.ts
|
|
667
541
|
const PROTOCOL_EVENT_HOST_SELECTOR = PROTOCOL_EVENT_HOST_ATTRIBUTE.replace(":", "\\:");
|
|
@@ -673,7 +547,7 @@ const PROTOCOL_EVENT_HOST_SELECTOR = PROTOCOL_EVENT_HOST_ATTRIBUTE.replace(":",
|
|
|
673
547
|
* `ownsRoot` adds the container itself, which hands records the runtime owns
|
|
674
548
|
* (arms, rows) to the runtime.
|
|
675
549
|
*/
|
|
676
|
-
function createMarklessDefer(loadModule, pageStart, pageEnd, pathsAttribute, hostSelector) {
|
|
550
|
+
function createMarklessDefer(loadModule, pageStart, pageEnd, pathsAttribute, hostSelector, streamOpenProperty) {
|
|
677
551
|
const scope = globalThis;
|
|
678
552
|
const clockOf = (root) => root.__mClock || {
|
|
679
553
|
frame: (run) => requestAnimationFrame(run),
|
|
@@ -699,18 +573,21 @@ function createMarklessDefer(loadModule, pageStart, pageEnd, pathsAttribute, hos
|
|
|
699
573
|
const clock = clockOf(root);
|
|
700
574
|
const next = () => clock.idle(() => root.__marklessArmRegistering?.size ? next() : run());
|
|
701
575
|
const loaded = () => clock.frame(() => scope.__mArm?.idle ? scope.__mArm.idle(next) : next());
|
|
702
|
-
|
|
576
|
+
const open = Reflect.get(document, streamOpenProperty);
|
|
577
|
+
if (open) open.then(loaded);
|
|
578
|
+
else if (document.readyState === "complete") loaded();
|
|
703
579
|
else addEventListener("load", loaded, { once: true });
|
|
704
580
|
};
|
|
705
581
|
const trigger = (target, lane, ownsRoot, eventName) => {
|
|
706
582
|
const root = target;
|
|
707
583
|
const url = document.currentScript?.getAttribute("data-markless-resume-module");
|
|
708
584
|
if (!root || !url) return;
|
|
585
|
+
const life = root.__mL ||= {};
|
|
709
586
|
const fired = root.__mFired ||= /* @__PURE__ */ new WeakSet();
|
|
710
587
|
const claimed = /* @__PURE__ */ new WeakSet();
|
|
711
588
|
let pending = 0;
|
|
712
589
|
const claim = (host) => {
|
|
713
|
-
if (fired.has(host) || claimed.has(host)) return;
|
|
590
|
+
if (fired.has(host) || claimed.has(host) || root.__mL !== life) return;
|
|
714
591
|
const input = {
|
|
715
592
|
root,
|
|
716
593
|
event: {
|
|
@@ -727,7 +604,7 @@ function createMarklessDefer(loadModule, pageStart, pageEnd, pathsAttribute, hos
|
|
|
727
604
|
root.__marklessCensus ||= census(root);
|
|
728
605
|
root.__marklessDelegatedDispatch ||= eventName;
|
|
729
606
|
pending++;
|
|
730
|
-
(queue ? Promise.resolve(queue(input)) : (root.__mResume ||= loadModule(url)).then((module) => module.resumeContainerEvent(input))).then(() => {
|
|
607
|
+
(queue ? Promise.resolve(queue(input)) : (root.__mResume ||= loadModule(url)).then((module) => root.__mL === life && module.resumeContainerEvent(input))).then(() => {
|
|
731
608
|
if (root.__asyncResumeRuntimeStarted) return;
|
|
732
609
|
fired.add(host);
|
|
733
610
|
if (!--pending && root.__marklessDelegatedDispatch === eventName) root.__marklessDelegatedDispatch = void 0;
|
|
@@ -737,6 +614,7 @@ function createMarklessDefer(loadModule, pageStart, pageEnd, pathsAttribute, hos
|
|
|
737
614
|
hosts.push(...root.querySelectorAll(`[${hostSelector}^="${eventName}:"],[${hostSelector}*=";${eventName}:"]`));
|
|
738
615
|
if (lane === "idle") return idle(root, () => hosts.forEach(claim));
|
|
739
616
|
const observer = new IntersectionObserver((entries) => {
|
|
617
|
+
if (root.__mL !== life) return observer.disconnect();
|
|
740
618
|
for (const entry of entries) if (entry.isIntersecting) {
|
|
741
619
|
observer.unobserve(entry.target);
|
|
742
620
|
claim(entry.target);
|
|
@@ -749,7 +627,7 @@ function createMarklessDefer(loadModule, pageStart, pageEnd, pathsAttribute, hos
|
|
|
749
627
|
const INLINE_DEFER_LOADER_SOURCE = "(url) => import(/* @vite-ignore */ url)";
|
|
750
628
|
/** An expression that installs the helper once per document and evaluates to it; a build passes the factory minified. */
|
|
751
629
|
function inlineDeferSource(factory = createMarklessDefer.toString()) {
|
|
752
|
-
return `(globalThis.__mDefer||=(${factory})(${INLINE_DEFER_LOADER_SOURCE},${JSON.stringify(PROTOCOL_CONTAINER_START_COMMENT)},${JSON.stringify(PROTOCOL_CONTAINER_END_COMMENT)},${JSON.stringify(PROTOCOL_LOCATOR_PATHS_ATTRIBUTE)},${JSON.stringify(PROTOCOL_EVENT_HOST_SELECTOR)}))`;
|
|
630
|
+
return `(globalThis.__mDefer||=(${factory})(${INLINE_DEFER_LOADER_SOURCE},${JSON.stringify(PROTOCOL_CONTAINER_START_COMMENT)},${JSON.stringify(PROTOCOL_CONTAINER_END_COMMENT)},${JSON.stringify(PROTOCOL_LOCATOR_PATHS_ATTRIBUTE)},${JSON.stringify(PROTOCOL_EVENT_HOST_SELECTOR)},${JSON.stringify(PROTOCOL_STREAM_OPEN_PROPERTY)}))`;
|
|
753
631
|
}
|
|
754
632
|
/** One lane's registration, appended only to a served page whose records name that lane's event. */
|
|
755
633
|
function createInlineDeferTriggerSource(lane, ownsRoot) {
|
|
@@ -758,15 +636,7 @@ function createInlineDeferTriggerSource(lane, ownsRoot) {
|
|
|
758
636
|
}
|
|
759
637
|
//#endregion
|
|
760
638
|
//#region src/inline-resumer.ts
|
|
761
|
-
let oxcToolsPromise;
|
|
762
639
|
const compiledSources = /* @__PURE__ */ new Map();
|
|
763
|
-
function loadOxcTools() {
|
|
764
|
-
oxcToolsPromise ??= import("rolldown/experimental").then(({ minifySync, transformSync }) => ({
|
|
765
|
-
minifySync,
|
|
766
|
-
transformSync
|
|
767
|
-
}));
|
|
768
|
-
return oxcToolsPromise;
|
|
769
|
-
}
|
|
770
640
|
function compileInlineResumerSources(options) {
|
|
771
641
|
const cacheKey = `${options.debug ? "debug" : "production"}:${options.executionLog}`;
|
|
772
642
|
let compiled = compiledSources.get(cacheKey);
|
|
@@ -819,7 +689,6 @@ async function compileInlineResumerSourceVariants(options) {
|
|
|
819
689
|
}
|
|
820
690
|
async function compileDeferFactorySource() {
|
|
821
691
|
const binding = "var __marklessDeferFactory=";
|
|
822
|
-
const { minifySync, transformSync } = await loadOxcTools();
|
|
823
692
|
const transformed = transformSync("markless-defer.js", `${binding}${createMarklessDefer.toString()};`, {
|
|
824
693
|
lang: "js",
|
|
825
694
|
sourceType: "script",
|
|
@@ -844,7 +713,6 @@ async function compileInlineResumerSource(options) {
|
|
|
844
713
|
debugRegistrationSource: createInlineResumerDebugRegistrationSource()
|
|
845
714
|
} : {}
|
|
846
715
|
});
|
|
847
|
-
const { minifySync, transformSync } = await loadOxcTools();
|
|
848
716
|
const transformed = transformSync("markless-inline-resumer.js", source, {
|
|
849
717
|
lang: "js",
|
|
850
718
|
sourceType: "script",
|
|
@@ -888,7 +756,6 @@ async function compilePrerenderVariants() {
|
|
|
888
756
|
}
|
|
889
757
|
async function compilePrerenderInlineResumerSource(selfWake) {
|
|
890
758
|
const source = parameterizedPrerenderInlineResumerSource(selfWake);
|
|
891
|
-
const { minifySync, transformSync } = await loadOxcTools();
|
|
892
759
|
const transformed = transformSync("markless-prerender-inline-resumer.js", source, {
|
|
893
760
|
lang: "js",
|
|
894
761
|
sourceType: "script",
|
|
@@ -1012,9 +879,9 @@ function emitSymbolRouteTable(input) {
|
|
|
1012
879
|
function boundEntry(boundSymbols, keyLists) {
|
|
1013
880
|
const entries = Object.entries(boundSymbols);
|
|
1014
881
|
const [firstKey, firstId] = entries[0];
|
|
1015
|
-
const head =
|
|
882
|
+
const head = `${protocolBoundSymbolPrefix(firstKey)}:`;
|
|
1016
883
|
const suffix = firstId.startsWith(head) ? firstId.slice(head.length) : void 0;
|
|
1017
|
-
if (suffix === void 0 || entries.some(([key, id]) =>
|
|
884
|
+
if (suffix === void 0 || entries.some(([key, id]) => protocolBoundSymbolPrefix(key) !== `bound:${encodeURIComponent(key)}` || id !== `${protocolBoundSymbolPrefix(key)}:${suffix}`)) return JSON.stringify(boundSymbols);
|
|
1018
885
|
const keys = JSON.stringify(entries.map(([key]) => key));
|
|
1019
886
|
let index = keyLists.indexOf(keys);
|
|
1020
887
|
if (index < 0) index = keyLists.push(keys) - 1;
|
|
@@ -1033,9 +900,6 @@ const SYMBOL_VIRTUAL_PREFIX = `${MARKLESS_VIRTUAL_PREFIX}symbol:`;
|
|
|
1033
900
|
function symbolVirtualModuleId(filename, symbolId) {
|
|
1034
901
|
return `${SYMBOL_VIRTUAL_PREFIX}${encodeURIComponent(filename)}:${encodeURIComponent(symbolId)}`;
|
|
1035
902
|
}
|
|
1036
|
-
function symbolEntryVirtualModuleId(filename, symbolId) {
|
|
1037
|
-
return `${symbolVirtualModuleId(filename, symbolId)}:entry`;
|
|
1038
|
-
}
|
|
1039
903
|
function encodedSymbolSource(filename) {
|
|
1040
904
|
return encodeURIComponent(filename);
|
|
1041
905
|
}
|
|
@@ -1155,7 +1019,7 @@ function emitSourceModule(input) {
|
|
|
1155
1019
|
const emitsSsrBody = !!input.publicSsrModuleSource && !(input.environment === "client" && (symbolsOnly || !input.prerenderRecords && !input.dev));
|
|
1156
1020
|
const csrRootName = input.environment !== "server" && !symbolsOnly && !input.prerenderRecords && input.publicRenderRootExportName ? csrRootLocalName(input.publicRenderRootExportName) : null;
|
|
1157
1021
|
return [
|
|
1158
|
-
!input.publicSsrModuleSource && !input.publicRenderModuleSource || symbolsOnly || !input.renderDataId || input.environment === "client" && !input.publicRenderModuleSource && !input.prerenderRecords && !input.dev && !canonicalRenderData ? "" : canonicalRenderData ? emitsSsrBody ? `import { marklessPrerenderData, marklessRenderData } from ${singleQuoted(input.renderDataId)};` : `import { marklessPrerenderData } from ${singleQuoted(input.renderDataId)};` : `import { marklessRenderData } from ${singleQuoted(input.renderDataId)};`,
|
|
1022
|
+
!input.publicSsrModuleSource && !input.publicRenderModuleSource || symbolsOnly || !input.renderDataId || input.environment === "client" && !input.publicRenderModuleSource && !input.prerenderRecords && !input.dev && !canonicalRenderData ? "" : canonicalRenderData ? emitsSsrBody ? `import { marklessPrerenderData, marklessRenderData } from ${singleQuoted(input.renderDataId)};` : input.lazyFullRenderDataId ? "" : `import { marklessPrerenderData } from ${singleQuoted(input.renderDataId)};` : `import { marklessRenderData } from ${singleQuoted(input.renderDataId)};`,
|
|
1159
1023
|
symbolsOnly ? "" : `import { state as payloadState, view as payloadView, runtimeDemandMap as payloadRuntimeDemandMap } from ${singleQuoted(input.payloadId)};`,
|
|
1160
1024
|
sharedInlineSources(input) ? `import { ${SHARED_INLINE_RESUMER_SOURCES} as marklessInlineResumerSources, ${SHARED_PRERENDER_BOOT} as marklessPrerenderBoot } from ${singleQuoted(input.sharedInlineSourcesModuleId)};` : null,
|
|
1161
1025
|
input.environment === "client" && input.directCsr === true && input.hasComputedState === true ? ["import { installMarklessDerivedReconcile } from '@markless/web/fns/reconcile-plane';", "installMarklessDerivedReconcile();"].join("\n") : null,
|
|
@@ -1202,6 +1066,7 @@ function emitSourceModule(input) {
|
|
|
1202
1066
|
ssrExportName: input.publicRenderSsrExportName,
|
|
1203
1067
|
ssrComponents: input.publicRenderSsrComponentExports ?? [],
|
|
1204
1068
|
canonicalRenderData,
|
|
1069
|
+
...canonicalRenderData && !emitsSsrBody && input.lazyFullRenderDataId ? { lazyFullRenderDataId: input.lazyFullRenderDataId } : {},
|
|
1205
1070
|
prerenderRecords: input.prerenderRecords,
|
|
1206
1071
|
dev: input.dev
|
|
1207
1072
|
}),
|
|
@@ -1328,10 +1193,16 @@ function componentRowLoader(input) {
|
|
|
1328
1193
|
if (input.linkedRowComponents || demandsKeyedRepeatModule(input.runtimeDemandMap, ROW_COMPONENT_MINT_RUNTIME_MODULE_ID)) return emitRowComponentMintLoaderInstall();
|
|
1329
1194
|
return input.linkedRowSlotReaders || demandsKeyedRepeatModule(input.runtimeDemandMap, ROW_SLOT_MINT_RUNTIME_MODULE_ID) ? emitRowSlotMintLoaderInstall() : void 0;
|
|
1330
1195
|
}
|
|
1196
|
+
function rowBranchesLoader(runtimeDemandMap, linked = false) {
|
|
1197
|
+
return linked || demandsKeyedRepeatModule(runtimeDemandMap, ROW_BRANCH_MINT_RUNTIME_MODULE_ID) ? "globalThis.__marklessRowBranches ??= () => import('@markless/web/fns/row-branch-mint').then((branches) => branches.marklessRowBranches());" : null;
|
|
1198
|
+
}
|
|
1331
1199
|
function clientRowMintLoader(input) {
|
|
1332
|
-
const
|
|
1333
|
-
|
|
1334
|
-
|
|
1200
|
+
const lines = [
|
|
1201
|
+
demandsRowComponentMint(input.runtimeDemandMap) ? emitRowComponentMintLoaderInstall() : componentRowLoader(input) ?? (input.linkedRowTemplates || demandsRowMint(input.runtimeDemandMap) ? emitRowMintLoaderInstall() : null),
|
|
1202
|
+
nestedRepeatsLoader(input.runtimeDemandMap, input.linkedNestedRepeats),
|
|
1203
|
+
rowBranchesLoader(input.runtimeDemandMap, input.linkedRowBranches)
|
|
1204
|
+
].filter((line) => line !== null);
|
|
1205
|
+
return lines.length > 0 ? lines.join("\n") : null;
|
|
1335
1206
|
}
|
|
1336
1207
|
function emitRowSlotMintLoaderInstall() {
|
|
1337
1208
|
return ["if (!globalThis.__marklessRowMint?.components) globalThis.__marklessRowMint = (...input) =>", " import('@markless/web/fns/row-slot-mint').then((mint) => mint.marklessRowSlotMint(...input));"].join("\n");
|
|
@@ -1351,6 +1222,7 @@ const ROW_MINT_RUNTIME_MODULE_ID = "web/fns/row-mint";
|
|
|
1351
1222
|
const NESTED_REPEATS_RUNTIME_MODULE_ID = "web/fns/nested-repeats";
|
|
1352
1223
|
const ROW_COMPONENT_MINT_RUNTIME_MODULE_ID = "web/fns/row-component-mint";
|
|
1353
1224
|
const ROW_SLOT_MINT_RUNTIME_MODULE_ID = "web/fns/row-slot-mint";
|
|
1225
|
+
const ROW_BRANCH_MINT_RUNTIME_MODULE_ID = "web/fns/row-branch-mint";
|
|
1354
1226
|
/** True when the compiler recorded an `overlay` mark for this module. */
|
|
1355
1227
|
function demandsOverlay(runtimeDemandMap) {
|
|
1356
1228
|
const records = runtimeDemandMap?.payloadRecords;
|
|
@@ -1365,7 +1237,7 @@ function emitResumeModule(input) {
|
|
|
1365
1237
|
runtimeDemandMap: input.servedScalarPlans
|
|
1366
1238
|
} : input);
|
|
1367
1239
|
const stagedPrerender = (input.prerenderTriggerGroups?.length ?? 0) > 0;
|
|
1368
|
-
const resumeContainerEvent = emitQueuedResumeContainerEvent(emitResumeContainerEvent(resumeSymbolLoader, input.needsFullResume ?? false, input.storageCells !== true && input.payloadState?.version === ASYNC_PROTOCOL_VERSION, servedPlansOnly ? "scalar" : composedLeanMode(input.symbolRoutes.length > 0, leanResumeMode(input.runtimeDemandMap)), scalarSpecializations, input.runtimeDemandMap, input.executionLog !== "never", input.prerenderDataId, stagedPrerender, componentRowLoader(input) ? input.lazyRenderDataId ?? input.renderDataId : void 0, input.symbolRoutes.length > 0 || servedPlansOnly, (input.closurePlanRoutes ?? []).some((route) => "importSource" in route) && scalarSpecializations.length > 0 && !input.prerenderDataId, input.streamsArms === true));
|
|
1240
|
+
const resumeContainerEvent = emitQueuedResumeContainerEvent(emitResumeContainerEvent(resumeSymbolLoader, input.needsFullResume ?? false, input.storageCells !== true && input.payloadState?.version === ASYNC_PROTOCOL_VERSION, servedPlansOnly ? "scalar" : composedLeanMode(input.symbolRoutes.length > 0, leanResumeMode(input.runtimeDemandMap)), scalarSpecializations, input.runtimeDemandMap, input.executionLog !== "never", input.prerenderDataId, stagedPrerender, componentRowLoader(input) ? input.servedRenderDataId ?? input.lazyRenderDataId ?? input.renderDataId : void 0, input.symbolRoutes.length > 0 || servedPlansOnly, (input.closurePlanRoutes ?? []).some((route) => "importSource" in route) && scalarSpecializations.length > 0 && !input.prerenderDataId, input.streamsArms === true));
|
|
1369
1241
|
const closureImports = [
|
|
1370
1242
|
"marklessClosureRouted",
|
|
1371
1243
|
"marklessPrimeClosure",
|
|
@@ -1387,6 +1259,7 @@ function emitResumeModule(input) {
|
|
|
1387
1259
|
input.hasIdleEvents ? emitIdleTriggerInstall() : null,
|
|
1388
1260
|
componentRowLoader(input) ?? (input.linkedRowTemplates || demandsRowMint(input.runtimeDemandMap) ? emitRowMintLoaderInstall() : null),
|
|
1389
1261
|
nestedRepeatsLoader(input.runtimeDemandMap, input.linkedNestedRepeats),
|
|
1262
|
+
rowBranchesLoader(input.runtimeDemandMap, input.linkedRowBranches),
|
|
1390
1263
|
scalarSpecializations.length > 0 ? [
|
|
1391
1264
|
"import { marklessDecodeScalarCell, marklessReadScalarCell, marklessScalarSpecializedError } from '@markless/web/fns/scalar-specialized';",
|
|
1392
1265
|
resumeContainerEvent.includes("marklessScalarServedOwner") ? `import { marklessScalarLocate, marklessScalarServedOwner, marklessScalarServedPrime${resumeContainerEvent.includes("marklessScalarServedRecord") ? ", marklessScalarServedRecord" : ""} } from '@markless/web/fns/scalar-served';` : "",
|
|
@@ -1395,6 +1268,7 @@ function emitResumeModule(input) {
|
|
|
1395
1268
|
"import { marklessUpdateText } from '@markless/web/fns/update-text';"
|
|
1396
1269
|
].join("\n") : "",
|
|
1397
1270
|
scalarSpecializations.length > 0 || stagedPrerender ? "import { marklessFindElementAtDomOrderIndex } from '@markless/web/fns/dom-order';" : "",
|
|
1271
|
+
input.prerenderTriggerGroups?.some((group) => group.hostPath) ? "import { marklessElementAt } from '@markless/web/fns/element-address';" : null,
|
|
1398
1272
|
"",
|
|
1399
1273
|
input.executionLog === "never" ? "" : emitExecutionLogLoader(),
|
|
1400
1274
|
input.installResumeSummary && input.executionLog !== "never" ? "if (globalThis.__mxLog) globalThis.__mxLoadLog().then(log => log.installMarklessExecutionLog());" : null,
|
|
@@ -1423,21 +1297,21 @@ function emitQueuedResumeContainerEvent(source, { censusRepair = true } = {}) {
|
|
|
1423
1297
|
" if (input.eventIndex >= 0) input = { ...input, eventRecord: (root.__mE ||= JSON.parse(root.querySelector('script[type=\"markless/view\"]').textContent).events)[input.eventIndex] };",
|
|
1424
1298
|
censusRepair ? " if (root.__marklessShifted) return import('@markless/web/fns/served-census-repair').then((census) => (census.marklessRepairCensus(root), resumeContainerEvent(input)));" : "",
|
|
1425
1299
|
" if (!root.__marklessDispatch) {",
|
|
1426
|
-
" let handler = marklessResumeContainerEvent, tail = Promise.resolve(), done = tail, lastEvent = null, lastEventTime = undefined, seen = new WeakMap();",
|
|
1300
|
+
" let handler = marklessResumeContainerEvent, tail = Promise.resolve(), done = tail, lastEvent = null, lastEventTime = undefined, seen = new WeakMap(), life = root.__mL;",
|
|
1427
1301
|
" root.__marklessRegisterDispatch = next => {",
|
|
1428
1302
|
" const fallback = handler;",
|
|
1429
1303
|
" handler = input => next(input, fallback);",
|
|
1430
1304
|
" };",
|
|
1431
1305
|
" root.__marklessDispatch = next => {",
|
|
1432
1306
|
" const event = next.event, eventTime = event?.timeStamp;",
|
|
1433
|
-
" if (event && next.eventRecord && next.element) event.
|
|
1307
|
+
" if (event && next.eventRecord && next.element) event.__marklessPressPath ??= [next.element];",
|
|
1434
1308
|
" if ((event === lastEvent && eventTime === lastEventTime) || (seen.has(event) && seen.get(event) === eventTime)) return done;",
|
|
1435
1309
|
" if (Object(event) === event) seen.set(event, eventTime);",
|
|
1436
1310
|
" lastEvent = event;",
|
|
1437
1311
|
" lastEventTime = eventTime;",
|
|
1438
1312
|
" let release;",
|
|
1439
1313
|
" const started = new Promise(resolve => release = resolve);",
|
|
1440
|
-
" const run = () => (root.__marklessReleaseDispatch = release, handler(next));",
|
|
1314
|
+
" const run = () => root.__mL === life ? (root.__marklessReleaseDispatch = release, handler(next)) : release();",
|
|
1441
1315
|
" done = tail.then(run, run);",
|
|
1442
1316
|
" done.then(release, release);",
|
|
1443
1317
|
" tail = started;",
|
|
@@ -1456,7 +1330,7 @@ function emitLazySymbolRouteFunction(routes, functionName, fallbackName = "loadS
|
|
|
1456
1330
|
return emitSymbolRouteTable({
|
|
1457
1331
|
routes: [...routes].sort((left, right) => right.prefix.length - left.prefix.length).map((route) => "importSource" in route ? {
|
|
1458
1332
|
...route,
|
|
1459
|
-
importSource: symbolRouteImportSource
|
|
1333
|
+
importSource: symbolRouteImportSource(route.importSource, includeScalarActionPlans)
|
|
1460
1334
|
} : route),
|
|
1461
1335
|
functionName,
|
|
1462
1336
|
fallbackName,
|
|
@@ -1490,14 +1364,14 @@ function emitClosurePlanRoute(routes, functionName, actions) {
|
|
|
1490
1364
|
`function ${functionName}(symbolId) {`,
|
|
1491
1365
|
...ordered.flatMap((route) => [
|
|
1492
1366
|
` if (symbolId.startsWith(${JSON.stringify(route.prefix)})) {`,
|
|
1493
|
-
"importSource" in route ? ` return import(${JSON.stringify(symbolRouteImportSource
|
|
1367
|
+
"importSource" in route ? ` return import(${JSON.stringify(symbolRouteImportSource(route.importSource))}).then((mod) => mod.loadClosureActionPlan?.(symbolId.slice(${route.prefix.length})));` : route.prefix.length > 0 ? ` return ${functionName}(symbolId.slice(${route.prefix.length}));` : ` return ${localLookup};`,
|
|
1494
1368
|
" }"
|
|
1495
1369
|
]),
|
|
1496
1370
|
` return ${localLookup};`,
|
|
1497
1371
|
"}"
|
|
1498
1372
|
].filter(Boolean).join("\n");
|
|
1499
1373
|
}
|
|
1500
|
-
function symbolRouteImportSource
|
|
1374
|
+
function symbolRouteImportSource(importSource, includeScalarActionPlans = false) {
|
|
1501
1375
|
if (includeScalarActionPlans) return scalarPlanSourceReference(importSource);
|
|
1502
1376
|
return importSource.includes("?") ? `${importSource}&markless-symbols` : `${importSource}?markless-symbols`;
|
|
1503
1377
|
}
|
|
@@ -1512,7 +1386,7 @@ function sharedPrerenderBootSource(boot) {
|
|
|
1512
1386
|
function emitCompiledAppDefault(input) {
|
|
1513
1387
|
const renderCsrEntry = input.csrRootName ? [` renderCsr: ${input.csrRootName},`] : [];
|
|
1514
1388
|
const symbolLoaderEntry = input.environment !== "server" && input.rootExportName === null ? [`\tloadSymbol: ${input.symbolLoaderName},`] : input.prerenderRecords === true ? [`\tloadSymbol: ${input.symbolLoaderName},`] : [];
|
|
1515
|
-
const renderDataEntry = input.canonicalRenderData ? [" renderData: marklessPrerenderData,"]
|
|
1389
|
+
const renderDataEntry = !input.canonicalRenderData ? [] : input.lazyFullRenderDataId ? [`\trenderData: () => import(${singleQuoted(input.lazyFullRenderDataId)}).then((data) => data.marklessPrerenderData),`] : [" renderData: marklessPrerenderData,"];
|
|
1516
1390
|
const servesSsr = !!input.ssrExportName && (input.environment !== "client" || input.prerenderRecords || input.dev);
|
|
1517
1391
|
const renderSsrEntry = servesSsr ? [
|
|
1518
1392
|
" renderSsr(props, marklessRenderContext) {",
|
|
@@ -1602,21 +1476,32 @@ function emitComponentExports(input) {
|
|
|
1602
1476
|
});
|
|
1603
1477
|
}
|
|
1604
1478
|
function emitResumeContainerEvent(loadSymbolName, needsFullResume, storageFreePayload, leanMode, scalarSpecializations, runtimeDemandMap, executionLogEnabled, prerenderDataId, stagedPrerender = false, componentRowRenderDataId, servedOnly = false, routedClosures = false, streamsArms = false) {
|
|
1605
|
-
const
|
|
1479
|
+
const lifeOpen = (indent) => `${indent}const marklessLife = handoff.root.__mL;`;
|
|
1480
|
+
const lifeCheck = (indent) => `${indent}if (handoff.root.__mL !== marklessLife) return;`;
|
|
1481
|
+
const armsOpen = (indent) => streamsArms ? [
|
|
1482
|
+
`${indent}const marklessArmsModule = await import('@markless/web/fns/streamed-arms');`,
|
|
1483
|
+
lifeCheck(indent),
|
|
1484
|
+
`${indent}const marklessArms = marklessArmsModule.marklessStreamedArms(handoff.root, ${loadSymbolName});`
|
|
1485
|
+
] : [];
|
|
1606
1486
|
const armsStarted = (indent) => streamsArms ? [`${indent}marklessArms.started();`] : [];
|
|
1607
1487
|
const wakeLoadSymbol = streamsArms ? "marklessArms.loadSymbol" : loadSymbolName;
|
|
1608
1488
|
const resumeEntry = storageFreePayload ? STORAGE_FREE_RESUME_ENTRY_SPECIFIER : RESUME_ENTRY_SPECIFIER;
|
|
1609
1489
|
const renderDataEntry = (indent, expression) => componentRowRenderDataId ? [`${indent}renderData: () => ${expression},`] : [];
|
|
1610
1490
|
const fullResumeHandoff = stagedPrerender && prerenderDataId ? [
|
|
1611
1491
|
"async function marklessFullResumeHandoff(handoff) {",
|
|
1492
|
+
lifeOpen(" "),
|
|
1612
1493
|
" handoff.root.__asyncResumeRuntimeStarted = true;",
|
|
1613
1494
|
" const group = await marklessLoadPrerenderTriggerGroup(handoff);",
|
|
1614
1495
|
" const { mergePrerenderPayloadRecords, resumePrerenderTriggerGroup } = await import('@markless/web/fns/prerender-trigger-resume');",
|
|
1496
|
+
lifeCheck(" "),
|
|
1615
1497
|
" if (!group) {",
|
|
1616
1498
|
" const { derivePrerenderResumeRecords, renderPrerenderBoundary, resumeFromPrerenderRecords } = await import('@markless/web/fns/prerender-resume');",
|
|
1499
|
+
lifeCheck(" "),
|
|
1617
1500
|
" handoff.root.__marklessFullResumeRuntime ??= (async () => {",
|
|
1618
1501
|
" const marklessPrerenderData = await marklessLoadPrerenderData();",
|
|
1619
|
-
`\t\t\tconst
|
|
1502
|
+
`\t\t\tconst derivedRecords = await derivePrerenderResumeRecords(marklessPrerenderData, ${loadSymbolName});`,
|
|
1503
|
+
lifeCheck(" "),
|
|
1504
|
+
" const fallbackRecords = mergePrerenderPayloadRecords(derivedRecords, handoff.root);",
|
|
1620
1505
|
" return (await resumeFromPrerenderRecords({",
|
|
1621
1506
|
" ...fallbackRecords,",
|
|
1622
1507
|
" root: handoff.root,",
|
|
@@ -1626,6 +1511,7 @@ function emitResumeContainerEvent(loadSymbolName, needsFullResume, storageFreePa
|
|
|
1626
1511
|
" })).runtime;",
|
|
1627
1512
|
" })();",
|
|
1628
1513
|
" const marklessFullRuntime = await handoff.root.__marklessFullResumeRuntime;",
|
|
1514
|
+
" if (!marklessFullRuntime) return;",
|
|
1629
1515
|
" await marklessFullRuntime.dispatch(handoff.event, { syncPolicyAlreadyApplied: handoff.syncPolicyAlreadyApplied === true, ignoreUnmatched: true });",
|
|
1630
1516
|
" return;",
|
|
1631
1517
|
" }",
|
|
@@ -1638,11 +1524,13 @@ function emitResumeContainerEvent(loadSymbolName, needsFullResume, storageFreePa
|
|
|
1638
1524
|
"}"
|
|
1639
1525
|
].join("\n") : prerenderDataId ? [
|
|
1640
1526
|
"async function marklessFullResumeHandoff(handoff) {",
|
|
1527
|
+
lifeOpen(" "),
|
|
1641
1528
|
" handoff.root.__marklessLinkedRenderDataBoot = true;",
|
|
1642
1529
|
" handoff.root.__asyncResumeRuntimeStarted = true;",
|
|
1643
1530
|
" const runtime = await (handoff.root.__marklessFullResumeRuntime ??= (async () => {",
|
|
1644
1531
|
" const { derivePrerenderResumeRecords, mergePrerenderPayloadRecords, renderPrerenderBoundary, resumeFromPrerenderRecords } = await import('@markless/web/fns/prerender-resume');",
|
|
1645
1532
|
`\t\tconst records = await derivePrerenderResumeRecords(marklessPrerenderData, ${loadSymbolName});`,
|
|
1533
|
+
lifeCheck(" "),
|
|
1646
1534
|
" const mergedRecords = mergePrerenderPayloadRecords(records, handoff.root);",
|
|
1647
1535
|
...armsOpen(" "),
|
|
1648
1536
|
streamsArms ? " const resumed = await resumeFromPrerenderRecords({" : " return (await resumeFromPrerenderRecords({",
|
|
@@ -1657,13 +1545,16 @@ function emitResumeContainerEvent(loadSymbolName, needsFullResume, storageFreePa
|
|
|
1657
1545
|
" return resumed.runtime;"
|
|
1658
1546
|
] : [" })).runtime;"],
|
|
1659
1547
|
" })());",
|
|
1548
|
+
" if (!runtime) return;",
|
|
1660
1549
|
" await runtime.dispatch(handoff.event, { syncPolicyAlreadyApplied: handoff.syncPolicyAlreadyApplied === true, ignoreUnmatched: true });",
|
|
1661
1550
|
"}"
|
|
1662
1551
|
].join("\n") : [
|
|
1663
1552
|
"async function marklessFullResumeHandoff(handoff) {",
|
|
1553
|
+
lifeOpen(" "),
|
|
1664
1554
|
" handoff.root.__asyncResumeRuntimeStarted = true;",
|
|
1665
1555
|
...armsOpen(" "),
|
|
1666
1556
|
` const { resumeFromPayloadDocument } = await import(${singleQuoted(resumeEntry)});`,
|
|
1557
|
+
lifeCheck(" "),
|
|
1667
1558
|
" const { runtime } = await resumeFromPayloadDocument({",
|
|
1668
1559
|
" document: handoff.document,",
|
|
1669
1560
|
" root: handoff.root,",
|
|
@@ -1685,7 +1576,9 @@ function emitResumeContainerEvent(loadSymbolName, needsFullResume, storageFreePa
|
|
|
1685
1576
|
].join("\n");
|
|
1686
1577
|
if (leanMode !== "none") {
|
|
1687
1578
|
const row = [
|
|
1579
|
+
" const marklessLife = input.root.__mL;",
|
|
1688
1580
|
" const { resumeScalarRowEventFromPayloadDocument } = await import('@markless/web/event-only-lean/row');",
|
|
1581
|
+
" if (input.root.__mL !== marklessLife) return;",
|
|
1689
1582
|
" await resumeScalarRowEventFromPayloadDocument({",
|
|
1690
1583
|
...[
|
|
1691
1584
|
" document: input.root,",
|
|
@@ -1750,10 +1643,9 @@ function emitPrerenderTriggerGroupLoader(groups) {
|
|
|
1750
1643
|
" let within = false, done = false;",
|
|
1751
1644
|
" const between = node => { for (const child of node.childNodes ?? []) { if (child === start) { within = true; continue; } if (child === end) { done = true; return; } if (within) armNodes.push(child); else between(child); if (done) return; } };",
|
|
1752
1645
|
" between(input.root);",
|
|
1753
|
-
"
|
|
1754
|
-
" for (let index = 1; host && index < hostPath.length; index++) host = host.childNodes?.[hostPath[index]];",
|
|
1646
|
+
" const host = marklessElementAt({ childNodes: armNodes }, hostPath);",
|
|
1755
1647
|
" const target = input.event?.target;",
|
|
1756
|
-
" return host
|
|
1648
|
+
" return !!host && (host === target || (!!target?.nodeType && typeof host.contains === \"function\" && host.contains(target)));",
|
|
1757
1649
|
"}",
|
|
1758
1650
|
"function marklessLoadPrerenderTriggerGroup(input) {",
|
|
1759
1651
|
...groups.map((group) => {
|
|
@@ -1969,7 +1861,7 @@ function emitScalarAction(action, loadSymbolName, resolution) {
|
|
|
1969
1861
|
] : [],
|
|
1970
1862
|
...emitScalarWrite(action),
|
|
1971
1863
|
` const symbol = await Promise.resolve(${loadSymbolName}(${JSON.stringify(action.symbolId)}));`,
|
|
1972
|
-
" await Promise.resolve(symbol({ graph: { ...graph, write()
|
|
1864
|
+
" await Promise.resolve(symbol({ graph: { ...graph, write: (write) => write.value, update(update) { const value = graph.read(update.graphNodeId, update.path ?? []); return update.returnValue === \"previous\" || update.returnValue === \"next\" ? value : undefined; } }, event: input.event, element: host, getElementHandle: () => undefined }));",
|
|
1973
1865
|
" if (state.dirty) {",
|
|
1974
1866
|
" state.dirty = false;",
|
|
1975
1867
|
...action.textUpdates.map((update, index) => ` textTarget${index}.textContent = marklessUpdateText({ domUpdate: { hostNodeId: ${JSON.stringify(update.hostNodeId)} }, value: ${JSON.stringify(update.prefix ?? "")} + (state.value == null ? '' : String(state.value))${update.suffix ? ` + ${JSON.stringify(update.suffix)}` : ""} }, ${JSON.stringify(update.hostNodeId)}).value;`),
|
|
@@ -2044,7 +1936,7 @@ function emitLoadSymbol(input, sourceReaderName) {
|
|
|
2044
1936
|
function emitDirectSourceSymbolLoader(symbols, readerName = "readMarklessSourceSymbol") {
|
|
2045
1937
|
return [
|
|
2046
1938
|
"function loadSymbol(symbolId) {",
|
|
2047
|
-
...symbols.flatMap((symbol) => [` if (symbolId === ${JSON.stringify(symbol.id)}) return import(${singleQuoted(symbol.
|
|
1939
|
+
...symbols.flatMap((symbol) => [` if (symbolId === ${JSON.stringify(symbol.id)}) return import(${singleQuoted(symbol.chunk)})`, ` .then((mod) => ${readerName}(mod, ${JSON.stringify(symbol.exportName)}));`]),
|
|
2048
1940
|
" return Promise.reject(new Error(`Unknown async symbol ${symbolId}`));",
|
|
2049
1941
|
"}",
|
|
2050
1942
|
emitSourceSymbolExportReader(readerName)
|
|
@@ -2069,885 +1961,194 @@ function stringHash(value) {
|
|
|
2069
1961
|
function singleQuoted(value) {
|
|
2070
1962
|
return `'${String(value).replace(/[\\']/g, "\\$&").replace(/\n/g, "\\n").replace(/\r/g, "\\r")}'`;
|
|
2071
1963
|
}
|
|
2072
|
-
const MARKLESS_BUILD_PREFIX = `build/`;
|
|
2073
|
-
const MARKLESS_BUNDLE_GRAPH = `${MARKLESS_BUILD_PREFIX}bundle-graph.json`;
|
|
2074
|
-
const MARKLESS_EXECUTION_SIZES = `${MARKLESS_BUILD_PREFIX}execution-sizes.json`;
|
|
2075
|
-
const MARKLESS_EXECUTION_DEMAND = `${MARKLESS_BUILD_PREFIX}execution-demand.json`;
|
|
2076
|
-
const MARKLESS_INTERACTION_CLOSURES = `${MARKLESS_BUILD_PREFIX}interaction-closures.json`;
|
|
2077
|
-
const MARKLESS_BYTE_ATTRIBUTION = `${MARKLESS_BUILD_PREFIX}byte-attribution.json`;
|
|
2078
|
-
const MARKLESS_SERVER_CHUNK_MAX_BYTES = 4194304;
|
|
2079
|
-
const MARKLESS_BUILD_METADATA_FILES = [
|
|
2080
|
-
MARKLESS_BUNDLE_GRAPH,
|
|
2081
|
-
MARKLESS_EXECUTION_SIZES,
|
|
2082
|
-
MARKLESS_EXECUTION_DEMAND,
|
|
2083
|
-
MARKLESS_INTERACTION_CLOSURES,
|
|
2084
|
-
MARKLESS_BYTE_ATTRIBUTION
|
|
2085
|
-
];
|
|
2086
|
-
const MARKLESS_PUBLIC_BUILD_METADATA_FILES = [MARKLESS_EXECUTION_SIZES];
|
|
2087
|
-
const WEB_RUNTIME_CAPABILITY_GROUPS = [
|
|
2088
|
-
{
|
|
2089
|
-
name: "markless-direct-renderer",
|
|
2090
|
-
test: fileBasenamePattern("direct")
|
|
2091
|
-
},
|
|
2092
|
-
{
|
|
2093
|
-
name: "markless-resume-branches",
|
|
2094
|
-
test: fileBasenamePattern("resume-branches", "resume-arm-records-lazy")
|
|
2095
|
-
},
|
|
2096
|
-
{
|
|
2097
|
-
name: "markless-resume-behaviors",
|
|
2098
|
-
test: fileBasenamePattern("resume-behaviors")
|
|
2099
|
-
},
|
|
2100
|
-
{
|
|
2101
|
-
name: "markless-resume-repeats",
|
|
2102
|
-
test: fileBasenamePattern("resume-keyed-repeats", "resume-keyed-repeats-lazy", "repeat-runtime")
|
|
2103
|
-
},
|
|
2104
|
-
{
|
|
2105
|
-
name: "markless-resume-async",
|
|
2106
|
-
test: fileBasenamePattern("resume-async-boundaries", "resume-async-wiring")
|
|
2107
|
-
},
|
|
2108
|
-
{
|
|
2109
|
-
name: "markless-resume-shared-patch",
|
|
2110
|
-
test: fileBasenamePattern("resume-shared-patch")
|
|
2111
|
-
},
|
|
2112
|
-
{
|
|
2113
|
-
name: "markless-resume-runtime",
|
|
2114
|
-
test: fileBasenamePattern("resume-runtime")
|
|
2115
|
-
},
|
|
2116
|
-
{
|
|
2117
|
-
name: "markless-resume-runtime-start",
|
|
2118
|
-
test: fileBasenamePattern("resume-runtime-start")
|
|
2119
|
-
},
|
|
2120
|
-
{
|
|
2121
|
-
name: "markless-resume-runtime-shared",
|
|
2122
|
-
test: fileBasenamePattern("resume-runtime-shared")
|
|
2123
|
-
},
|
|
2124
|
-
{
|
|
2125
|
-
name: "markless-resume-events",
|
|
2126
|
-
test: fileBasenamePattern("resume-events")
|
|
2127
|
-
},
|
|
2128
|
-
{
|
|
2129
|
-
name: "markless-resume-handoff",
|
|
2130
|
-
test: fileBasenamePattern("resume-handoff")
|
|
2131
|
-
},
|
|
2132
|
-
{
|
|
2133
|
-
name: "markless-resume-locators",
|
|
2134
|
-
test: fileBasenamePattern("resume-locators", "resume-census")
|
|
2135
|
-
},
|
|
2136
|
-
{
|
|
2137
|
-
name: "markless-resume-errors",
|
|
2138
|
-
test: fileBasenamePattern("resume-errors")
|
|
2139
|
-
},
|
|
2140
|
-
{
|
|
2141
|
-
name: "markless-resume-sync-computed",
|
|
2142
|
-
test: fileBasenamePattern("resume-sync-computed")
|
|
2143
|
-
},
|
|
2144
|
-
{
|
|
2145
|
-
name: "markless-resume-sync-demand",
|
|
2146
|
-
test: fileBasenamePattern("resume-sync-demand")
|
|
2147
|
-
},
|
|
2148
|
-
{
|
|
2149
|
-
name: "markless-payload-full",
|
|
2150
|
-
test: fileBasenamePattern("payload-full", "payload-full-storage-free")
|
|
2151
|
-
},
|
|
2152
|
-
{
|
|
2153
|
-
name: "markless-payload-resume",
|
|
2154
|
-
test: fileBasenamePattern("payload-resume", "payload-resume-lazy")
|
|
2155
|
-
},
|
|
2156
|
-
{
|
|
2157
|
-
name: "markless-inline-payload-document",
|
|
2158
|
-
test: /[/\\]web[/\\]src[/\\]inline[/\\]payload-document\.ts(?:[?#].*)?$/
|
|
2159
|
-
},
|
|
2160
|
-
{
|
|
2161
|
-
name: "markless-payload-document",
|
|
2162
|
-
test: fileBasenamePattern("payload-document", "payload-document-common", "payload-resume-registry")
|
|
2163
|
-
},
|
|
2164
|
-
{
|
|
2165
|
-
name: "markless-payload-graph-construct",
|
|
2166
|
-
test: fileBasenamePattern("payload-graph-construct")
|
|
2167
|
-
},
|
|
2168
|
-
{
|
|
2169
|
-
name: "markless-dom-journal",
|
|
2170
|
-
test: fileBasenamePattern("dom-journal")
|
|
2171
|
-
},
|
|
2172
|
-
{
|
|
2173
|
-
name: "markless-protocol-decode",
|
|
2174
|
-
test: fileBasenamePattern("protocol-client", "protocol-client-storage", "protocol-state", "storage-record-client")
|
|
2175
|
-
},
|
|
2176
|
-
{
|
|
2177
|
-
name: "markless-value-decode",
|
|
2178
|
-
test: fileBasenamePattern("value-decode-client", "value-decode-client-lazy", "value-decode-extensions")
|
|
2179
|
-
},
|
|
2180
|
-
{
|
|
2181
|
-
name: "markless-payload-leaves",
|
|
2182
|
-
test: fileBasenamePattern("payload", "payload-document")
|
|
2183
|
-
},
|
|
2184
|
-
{
|
|
2185
|
-
name: "markless-dev-log",
|
|
2186
|
-
test: EXECUTION_LOG_CHUNK_MODULE_PATTERN
|
|
2187
|
-
},
|
|
2188
|
-
{
|
|
2189
|
-
name: "markless-resume-core",
|
|
2190
|
-
test: fileBasenamePattern("resume")
|
|
2191
|
-
},
|
|
2192
|
-
{
|
|
2193
|
-
name: "markless-runtime-graph-core",
|
|
2194
|
-
test: fileBasenamePattern("graph-core")
|
|
2195
|
-
},
|
|
2196
|
-
{
|
|
2197
|
-
name: "markless-runtime-graph-collections",
|
|
2198
|
-
test: fileBasenamePattern("graph-collections")
|
|
2199
|
-
},
|
|
2200
|
-
{
|
|
2201
|
-
name: "markless-runtime-graph-computed",
|
|
2202
|
-
test: fileBasenamePattern("graph-computed")
|
|
2203
|
-
},
|
|
2204
|
-
{
|
|
2205
|
-
name: "markless-runtime-graph-async",
|
|
2206
|
-
test: fileBasenamePattern("graph-async")
|
|
2207
|
-
},
|
|
2208
|
-
{
|
|
2209
|
-
name: "markless-runtime-graph-scheduler",
|
|
2210
|
-
test: fileBasenamePattern("graph-scheduler")
|
|
2211
|
-
},
|
|
2212
|
-
{
|
|
2213
|
-
name: "markless-runtime-graph-shared",
|
|
2214
|
-
test: fileBasenamePattern("graph-shared")
|
|
2215
|
-
},
|
|
2216
|
-
{
|
|
2217
|
-
name: "markless-graph",
|
|
2218
|
-
test: /[/\\](?:runtime[/\\]src[/\\](?!graph-(?:core|collections|computed|async|scheduler|shared)\.ts)|core[/\\]src[/\\]runtime)[/\\]?/
|
|
2219
|
-
},
|
|
2220
|
-
{
|
|
2221
|
-
name: "markless-serializer",
|
|
2222
|
-
test: /[/\\]serializer[/\\]src[/\\](?!protocol-validation)/
|
|
2223
|
-
}
|
|
2224
|
-
];
|
|
2225
|
-
function fileBasenamePattern(...names) {
|
|
2226
|
-
return new RegExp(`[/\\\\](?:${names.join("|")})\\.ts(?:[?#].*)?$`);
|
|
2227
|
-
}
|
|
2228
|
-
const MARKLESS_RUNTIME_GROUPS = [...WEB_RUNTIME_CAPABILITY_GROUPS, {
|
|
2229
|
-
name: "markless-runtime",
|
|
2230
|
-
test: /[/\\]@markless[/\\]runtime[/\\]/
|
|
2231
|
-
}];
|
|
2232
|
-
const MARKLESS_SERVER_COMPILED_GROUP = {
|
|
2233
|
-
name: "markless-server",
|
|
2234
|
-
minShareCount: 2,
|
|
2235
|
-
test: /\.tsrx(?:[?#]|$)|^\0?virtual:markless:/,
|
|
2236
|
-
entriesAware: true,
|
|
2237
|
-
maxSize: MARKLESS_SERVER_CHUNK_MAX_BYTES
|
|
2238
|
-
};
|
|
2239
|
-
function outputDefaults(output, environment) {
|
|
2240
|
-
if (environment === "lib") return output;
|
|
2241
|
-
const next = {
|
|
2242
|
-
...output,
|
|
2243
|
-
hoistTransitiveImports: false
|
|
2244
|
-
};
|
|
2245
|
-
if (environment === "server") {
|
|
2246
|
-
next.entryFileNames ??= "[name].js";
|
|
2247
|
-
next.chunkFileNames ??= "chunk-[hash].js";
|
|
2248
|
-
const splitting = marklessCodeSplitting(next.codeSplitting);
|
|
2249
|
-
next.codeSplitting = {
|
|
2250
|
-
...splitting,
|
|
2251
|
-
groups: [...splitting.groups, MARKLESS_SERVER_COMPILED_GROUP]
|
|
2252
|
-
};
|
|
2253
|
-
return next;
|
|
2254
|
-
}
|
|
2255
|
-
next.entryFileNames ??= `${MARKLESS_BUILD_PREFIX}chunk-[hash].js`;
|
|
2256
|
-
next.chunkFileNames ??= `${MARKLESS_BUILD_PREFIX}chunk-[hash].js`;
|
|
2257
|
-
next.minifyInternalExports = true;
|
|
2258
|
-
next.strictExecutionOrder = true;
|
|
2259
|
-
next.codeSplitting = marklessCodeSplitting(next.codeSplitting);
|
|
2260
|
-
return next;
|
|
2261
|
-
}
|
|
2262
|
-
function marklessCodeSplitting(codeSplitting) {
|
|
2263
|
-
if (typeof codeSplitting === "boolean") throw new Error("@markless/bundler requires output.codeSplitting to be an object so runtime chunks can be grouped.");
|
|
2264
|
-
return {
|
|
2265
|
-
...codeSplitting,
|
|
2266
|
-
groups: [...MARKLESS_RUNTIME_GROUPS, ...codeSplitting?.groups ?? []]
|
|
2267
|
-
};
|
|
2268
|
-
}
|
|
2269
|
-
//#endregion
|
|
2270
|
-
//#region src/bound-resolver.ts
|
|
2271
|
-
function adaptImportedCaptureResolver(source, hasImportedRows) {
|
|
2272
|
-
if (!hasImportedRows) return source;
|
|
2273
|
-
const original = " return (context) => base({ ...context, capture: createCaptureContext(context, bound) });";
|
|
2274
|
-
const replacement = [
|
|
2275
|
-
" return async (context) => {",
|
|
2276
|
-
" const pendingCallbacks = [];",
|
|
2277
|
-
" const capture = createCaptureContext(context, bound);",
|
|
2278
|
-
" const result = await base({ ...context, graph: createBoundGraph(context, bound, capture, pendingCallbacks), capture });",
|
|
2279
|
-
" await Promise.all(pendingCallbacks);",
|
|
2280
|
-
" return result;",
|
|
2281
|
-
" };"
|
|
2282
|
-
].join("\n");
|
|
2283
|
-
const helper = [
|
|
2284
|
-
"function createBoundGraph(context, bound, capture, pendingCallbacks) {",
|
|
2285
|
-
" const legacySlots = new Map(bound.captureSlots.flatMap((slot) => slot.legacyGraphRead ? [[JSON.stringify([slot.legacyGraphRead.graphNodeId, slot.legacyGraphRead.path ?? []]), slot]] : []));",
|
|
2286
|
-
" let lastCallback = Promise.resolve();",
|
|
2287
|
-
" return {",
|
|
2288
|
-
" ...context.graph,",
|
|
2289
|
-
" read(graphNodeId, path = []) {",
|
|
2290
|
-
" const slot = legacySlots.get(JSON.stringify([graphNodeId, path]));",
|
|
2291
|
-
" if (!slot) return context.graph.read(graphNodeId, path);",
|
|
2292
|
-
" if (slot.route.kind === callbackRoute) return (...args) => {",
|
|
2293
|
-
" const pending = lastCallback.then(() => capture.invoke(slot.slotId, args));",
|
|
2294
|
-
" lastCallback = pending.catch(() => {});",
|
|
2295
|
-
" pendingCallbacks.push(pending);",
|
|
2296
|
-
" return pending;",
|
|
2297
|
-
" };",
|
|
2298
|
-
" return capture.read(slot.slotId);",
|
|
2299
|
-
" },",
|
|
2300
|
-
" };",
|
|
2301
|
-
"}",
|
|
2302
|
-
""
|
|
2303
|
-
].join("\n");
|
|
2304
|
-
return source.replace(original, replacement).replace("function createCaptureContext(context, bound) {", `${helper}function createCaptureContext(context, bound) {`);
|
|
2305
|
-
}
|
|
2306
1964
|
//#endregion
|
|
2307
|
-
//#region src/
|
|
2308
|
-
const
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
try {
|
|
2320
|
-
return decodeURIComponent(match[1]);
|
|
2321
|
-
} catch {
|
|
2322
|
-
return null;
|
|
1965
|
+
//#region src/build/machine-paths.ts
|
|
1966
|
+
const rootsByBuildRoot = /* @__PURE__ */ new Map();
|
|
1967
|
+
function machinePathRoots(root) {
|
|
1968
|
+
const cached = rootsByBuildRoot.get(root);
|
|
1969
|
+
if (cached) return cached;
|
|
1970
|
+
const roots = /* @__PURE__ */ new Set();
|
|
1971
|
+
for (const start of [normalize(root), realpathOrSelf(root)]) {
|
|
1972
|
+
roots.add(start);
|
|
1973
|
+
for (let directory = start; dirname(directory) !== directory; directory = dirname(directory)) if (existsSync(join(directory, "pnpm-workspace.yaml")) || existsSync(join(directory, ".git"))) {
|
|
1974
|
+
roots.add(directory);
|
|
1975
|
+
break;
|
|
1976
|
+
}
|
|
2323
1977
|
}
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
routes: routes.map((route) => "importSource" in route ? {
|
|
2343
|
-
...route,
|
|
2344
|
-
importSource: symbolRouteImportSource(route.importSource)
|
|
2345
|
-
} : route),
|
|
2346
|
-
functionName: "loadSymbol",
|
|
2347
|
-
fallbackName: "marklessLoadLocalSymbol",
|
|
2348
|
-
reboundName: "marklessLoadSymbolRebound",
|
|
2349
|
-
exported: true
|
|
2350
|
-
});
|
|
1978
|
+
const found = [...roots].filter((path) => path !== "/");
|
|
1979
|
+
rootsByBuildRoot.set(root, found);
|
|
1980
|
+
return found;
|
|
1981
|
+
}
|
|
1982
|
+
/** `text` with every checkout path removed, as spelled raw, URI-encoded, or as a bundler-minted identifier. */
|
|
1983
|
+
function withoutMachinePaths(text, root) {
|
|
1984
|
+
if (!root) return text;
|
|
1985
|
+
const asIdentifier = (value) => value.replace(/[^\w$]/g, "_");
|
|
1986
|
+
let stripped = text;
|
|
1987
|
+
for (const suffix of ["/", ""]) for (const path of machinePathRoots(root)) {
|
|
1988
|
+
const encoded = encodeURIComponent(`${path}${suffix}`);
|
|
1989
|
+
for (const spelling of [
|
|
1990
|
+
`${path}${suffix}`,
|
|
1991
|
+
encoded,
|
|
1992
|
+
encoded.replaceAll("%", "_"),
|
|
1993
|
+
asIdentifier(encoded),
|
|
1994
|
+
asIdentifier(`${path}${suffix}`)
|
|
1995
|
+
]) stripped = stripped.split(spelling).join("");
|
|
2351
1996
|
}
|
|
2352
|
-
return
|
|
2353
|
-
armRendererModuleId ? [
|
|
2354
|
-
`import { prepareBoundaryArm as marklessPrepareBoundaryArm, renderBoundaryArm as marklessRenderBoundaryArm } from ${JSON.stringify(armRendererModuleId)};`,
|
|
2355
|
-
"export function prepareBoundaryArm(boundaryId, status, graph) {",
|
|
2356
|
-
" return marklessPrepareBoundaryArm(boundaryId, status, graph, loadSymbol);",
|
|
2357
|
-
"}",
|
|
2358
|
-
"export function renderBoundaryArm(boundaryId, status, graph) {",
|
|
2359
|
-
" return marklessRenderBoundaryArm(boundaryId, status, graph, loadSymbol);",
|
|
2360
|
-
"}"
|
|
2361
|
-
].join("\n") : "",
|
|
2362
|
-
adaptImportedCaptureResolver(source, boundRows.some((row) => row.loaderSymbolId !== void 0)),
|
|
2363
|
-
`export const groupId=${JSON.stringify(input.group.id)};`,
|
|
2364
|
-
`export const state=${JSON.stringify(input.group.state)};`,
|
|
2365
|
-
`export const view=${JSON.stringify(input.group.view)};`,
|
|
2366
|
-
`export const graphNodeIds=${JSON.stringify(input.group.graphNodeIds)};`
|
|
2367
|
-
].join("\n");
|
|
1997
|
+
return stripped;
|
|
2368
1998
|
}
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
" const key = `${boundaryId}:${status}`;",
|
|
2381
|
-
" const prepared = marklessPreparedBoundaryArms.get(graph);",
|
|
2382
|
-
" const rendered = prepared?.get(key);",
|
|
2383
|
-
" if (!rendered) throw new Error(`Markless prerender arm ${key} was not prepared.`);",
|
|
2384
|
-
" prepared.delete(key);",
|
|
2385
|
-
" return rendered;",
|
|
2386
|
-
"}"
|
|
2387
|
-
].join("\n");
|
|
2388
|
-
}
|
|
2389
|
-
function symbolRouteImportSource(importSource) {
|
|
2390
|
-
return importSource.includes("?") ? `${importSource}&markless-symbols` : `${importSource}?markless-symbols`;
|
|
2391
|
-
}
|
|
2392
|
-
function planPrerenderTriggerGroups(input) {
|
|
2393
|
-
const symbols = new Map(input.symbolResolver.symbols.map((symbol) => [symbol.id, symbol]));
|
|
2394
|
-
const bounds = new Map(input.boundRows.map((row) => [row.id, row]));
|
|
2395
|
-
const completeView = input.completeView ?? input.view;
|
|
2396
|
-
const completeBoundaries = new Map(completeView.asyncBoundaries.map((boundary) => [boundary.id, boundary]));
|
|
2397
|
-
const selfWakeBoundaries = unsettledAsyncBoundaryIndexes(input.state, input.view);
|
|
2398
|
-
const groups = [
|
|
2399
|
-
...selfWakeBoundaries.length > 0 ? [{
|
|
2400
|
-
event: {
|
|
2401
|
-
hostNodeId: "self-wake",
|
|
2402
|
-
eventName: "self-wake",
|
|
2403
|
-
symbolIds: []
|
|
2404
|
-
},
|
|
2405
|
-
selfWakeBoundaries
|
|
2406
|
-
}] : [],
|
|
2407
|
-
...input.view.events.filter((event) => EVENT_STAGES_BROWSER_TRIGGER[protocolEventActionKind(event)]).map((event) => ({ event })),
|
|
2408
|
-
...(input.view.branches ?? []).flatMap((branch, branchIndex) => {
|
|
2409
|
-
const events = /* @__PURE__ */ new Map();
|
|
2410
|
-
for (const arm of branch.armRecords ?? []) for (const event of arm.events) {
|
|
2411
|
-
const key = `${event.eventName}:${event.hostPath.join(".")}`;
|
|
2412
|
-
const route = events.get(key) ?? {
|
|
2413
|
-
eventName: event.eventName,
|
|
2414
|
-
hostPath: event.hostPath,
|
|
2415
|
-
symbolIds: /* @__PURE__ */ new Set()
|
|
2416
|
-
};
|
|
2417
|
-
for (const symbolId of event.symbolIds ?? []) route.symbolIds.add(symbolId);
|
|
2418
|
-
events.set(key, route);
|
|
2419
|
-
}
|
|
2420
|
-
return [...events.values()].map((route) => ({
|
|
2421
|
-
event: {
|
|
2422
|
-
hostNodeId: `branch:${branch.id}:${route.hostPath.join(".")}`,
|
|
2423
|
-
eventName: route.eventName,
|
|
2424
|
-
symbolIds: [...route.symbolIds]
|
|
2425
|
-
},
|
|
2426
|
-
branch,
|
|
2427
|
-
branchIndex,
|
|
2428
|
-
hostPath: route.hostPath
|
|
2429
|
-
}));
|
|
2430
|
-
})
|
|
2431
|
-
].flatMap(({ event, branch, branchIndex, hostPath, selfWakeBoundaries }) => {
|
|
2432
|
-
const closureView = selfWakeBoundaries ? completeView : input.view;
|
|
2433
|
-
const host = branch ? void 0 : input.view.locators.find((locator) => locator.hostNodeId === event.hostNodeId);
|
|
2434
|
-
if (!host && !branch && !selfWakeBoundaries) return [];
|
|
2435
|
-
const compilerGroup = input.triggerGroups.groups.find((group) => group.hostNodeId === event.hostNodeId && group.eventName === event.eventName);
|
|
2436
|
-
const graphNodeIds = /* @__PURE__ */ new Set();
|
|
2437
|
-
const symbolIds = new Set(event.symbolIds ?? []);
|
|
2438
|
-
const selected = {
|
|
2439
|
-
domUpdates: /* @__PURE__ */ new Set(),
|
|
2440
|
-
behaviors: /* @__PURE__ */ new Set(),
|
|
2441
|
-
branches: /* @__PURE__ */ new Set(),
|
|
2442
|
-
boundaries: /* @__PURE__ */ new Set(),
|
|
2443
|
-
repeats: /* @__PURE__ */ new Set(),
|
|
2444
|
-
elementHandles: /* @__PURE__ */ new Set()
|
|
2445
|
-
};
|
|
2446
|
-
if (branch && branchIndex !== void 0) {
|
|
2447
|
-
selected.branches.add(branchIndex);
|
|
2448
|
-
if (branch.symbolId) symbolIds.add(branch.symbolId);
|
|
2449
|
-
for (const read of branch.testReads ?? []) graphNodeIds.add(read.graphNodeId);
|
|
2450
|
-
for (const arm of branch.armRecords ?? []) collectCompleteArmRecordClosure(arm, graphNodeIds, symbolIds);
|
|
2451
|
-
}
|
|
2452
|
-
const adoptedBoundaryIds = /* @__PURE__ */ new Set();
|
|
2453
|
-
const escalatedHostNodeIds = /* @__PURE__ */ new Set();
|
|
2454
|
-
for (const boundaryIndex of selfWakeBoundaries ?? []) {
|
|
2455
|
-
const servedBoundary = input.view.asyncBoundaries[boundaryIndex];
|
|
2456
|
-
selected.boundaries.add(boundaryIndex);
|
|
2457
|
-
collectSettledBoundaryClosure(input, completeBoundaries.get(servedBoundary.id) ?? servedBoundary, graphNodeIds, symbolIds);
|
|
2458
|
-
}
|
|
2459
|
-
closureView.behaviors.forEach((behavior, index) => {
|
|
2460
|
-
if (selfWakeBoundaries) return;
|
|
2461
|
-
const recordId = `behavior:${behavior.hostNodeId}:${behavior.symbolId ?? ""}`;
|
|
2462
|
-
if ((behavior.inputGraphReads?.length ?? 0) > 0 && !compilerGroup?.payloadRecordIds.includes(recordId)) return;
|
|
2463
|
-
selected.behaviors.add(index);
|
|
2464
|
-
if (behavior.symbolId) symbolIds.add(behavior.symbolId);
|
|
2465
|
-
});
|
|
2466
|
-
let changed = true;
|
|
2467
|
-
while (changed) {
|
|
2468
|
-
const before = closureSize(graphNodeIds, symbolIds, selected);
|
|
2469
|
-
const currentSymbolIds = Array.from(symbolIds);
|
|
2470
|
-
for (const symbolId of currentSymbolIds) {
|
|
2471
|
-
const bound = bounds.get(symbolId);
|
|
2472
|
-
if (bound) {
|
|
2473
|
-
symbolIds.add(bound.loaderSymbolId ?? bound.baseSymbolId);
|
|
2474
|
-
for (const slot of bound.captureSlots) {
|
|
2475
|
-
if (slot.route.kind === "graph-reference") graphNodeIds.add(slot.route.graphNodeId);
|
|
2476
|
-
if (slot.route.kind === "callback-route") symbolIds.add(slot.route.callbackSymbolId);
|
|
2477
|
-
}
|
|
2478
|
-
}
|
|
2479
|
-
const symbol = symbols.get(symbolId);
|
|
2480
|
-
if (!symbol) continue;
|
|
2481
|
-
if ("reads" in symbol) for (const read of symbol.reads ?? []) graphNodeIds.add(read.graphNodeId);
|
|
2482
|
-
if ("writes" in symbol) for (const write of symbol.writes ?? []) graphNodeIds.add(write.graphNodeId);
|
|
2483
|
-
if (symbol.kind === "async-computed-runner" || symbol.kind === "sync-computed-derive") {
|
|
2484
|
-
graphNodeIds.add(symbol.graphNodeId);
|
|
2485
|
-
for (const dependency of symbol.dependencies ?? []) graphNodeIds.add(dependency.graphNodeId);
|
|
2486
|
-
}
|
|
2487
|
-
if ("elementHandleCalls" in symbol) for (const call of symbol.elementHandleCalls ?? []) closureView.elementHandles.forEach((handle, index) => {
|
|
2488
|
-
if (handle.name === call.handleName) selected.elementHandles.add(index);
|
|
2489
|
-
});
|
|
2490
|
-
if ("elementHandleReads" in symbol) for (const read of symbol.elementHandleReads ?? []) closureView.elementHandles.forEach((handle, index) => {
|
|
2491
|
-
if (handle.handleId === read.handleId || handle.name === read.handleName) selected.elementHandles.add(index);
|
|
2492
|
-
});
|
|
2493
|
-
}
|
|
2494
|
-
closeComputedGraph(graphNodeIds, input.state);
|
|
2495
|
-
for (const computed of input.state.computed) if (computed.deriveSymbolId && graphNodeIds.has(computed.graphNodeId)) symbolIds.add(computed.deriveSymbolId);
|
|
2496
|
-
for (const graphNodeId of graphNodeIds) {
|
|
2497
|
-
const runnerSymbolId = closureView.asyncRunners?.[graphNodeId];
|
|
2498
|
-
if (runnerSymbolId) symbolIds.add(runnerSymbolId);
|
|
2499
|
-
}
|
|
2500
|
-
selectViewSubscribers(closureView, graphNodeIds, symbolIds, selected);
|
|
2501
|
-
const escalatedBranchIds = /* @__PURE__ */ new Set();
|
|
2502
|
-
for (const index of selected.branches) {
|
|
2503
|
-
const record = closureView.branches?.[index];
|
|
2504
|
-
if (record?.escalates) escalatedBranchIds.add(record.id);
|
|
2505
|
-
}
|
|
2506
|
-
for (const index of selected.boundaries) {
|
|
2507
|
-
const served = closureView.asyncBoundaries[index];
|
|
2508
|
-
for (const arm of boundaryArmRecordSets(completeBoundaries.get(served.id) ?? served)) collectEscalatedArmBranchIds(arm, escalatedBranchIds);
|
|
2509
|
-
}
|
|
2510
|
-
for (const branchId of escalatedBranchIds) collectEscalatedBranchClosure(input, branchId, graphNodeIds, symbolIds, escalatedHostNodeIds);
|
|
2511
|
-
if (!selfWakeBoundaries) input.view.asyncBoundaries.forEach((servedBoundary, index) => {
|
|
2512
|
-
if (adoptedBoundaryIds.has(servedBoundary.id)) return;
|
|
2513
|
-
const boundary = completeBoundaries.get(servedBoundary.id) ?? servedBoundary;
|
|
2514
|
-
if (!settledArmReadGraphNodeIds(input, boundary).some((graphNodeId) => graphNodeIds.has(graphNodeId))) return;
|
|
2515
|
-
adoptedBoundaryIds.add(servedBoundary.id);
|
|
2516
|
-
selected.boundaries.add(index);
|
|
2517
|
-
collectSettledBoundaryClosure(input, boundary, graphNodeIds, symbolIds);
|
|
2518
|
-
collectSettledArmHostRecordClosure(completeView, boundary, graphNodeIds, symbolIds);
|
|
2519
|
-
});
|
|
2520
|
-
if (selfWakeBoundaries || adoptedBoundaryIds.size > 0) {
|
|
2521
|
-
for (const symbol of symbols.values()) if (symbol.kind === "state-initializer" && graphNodeIds.has(symbol.graphNodeId)) symbolIds.add(symbol.id);
|
|
2522
|
-
}
|
|
2523
|
-
changed = closureSize(graphNodeIds, symbolIds, selected) !== before;
|
|
2524
|
-
}
|
|
2525
|
-
dropEscalatedHostRecords(closureView, selected, escalatedHostNodeIds);
|
|
2526
|
-
const neededHosts = new Set(branch ? [] : [event.hostNodeId]);
|
|
2527
|
-
for (const index of selected.domUpdates) neededHosts.add(closureView.domUpdates[index].hostNodeId);
|
|
2528
|
-
for (const index of selected.behaviors) neededHosts.add(closureView.behaviors[index].hostNodeId);
|
|
2529
|
-
for (const index of selected.repeats) neededHosts.add(closureView.keyedRepeats[index].parentHostNodeId);
|
|
2530
|
-
for (const index of selected.elementHandles) neededHosts.add(closureView.elementHandles[index].hostNodeId);
|
|
2531
|
-
const selectedBoundaryIds = new Set([...selected.boundaries].map((index) => closureView.asyncBoundaries[index].id));
|
|
2532
|
-
const view = {
|
|
2533
|
-
...input.view,
|
|
2534
|
-
locators: closureView.locators.filter((locator) => neededHosts.has(locator.hostNodeId)),
|
|
2535
|
-
events: branch || selfWakeBoundaries ? [] : [event],
|
|
2536
|
-
domUpdates: closureView.domUpdates.filter((_, index) => selected.domUpdates.has(index)),
|
|
2537
|
-
behaviors: closureView.behaviors.filter((_, index) => selected.behaviors.has(index)),
|
|
2538
|
-
elementHandles: closureView.elementHandles.filter((_, index) => selected.elementHandles.has(index)),
|
|
2539
|
-
keyedRepeats: closureView.keyedRepeats?.filter((_, index) => selected.repeats.has(index)),
|
|
2540
|
-
branches: closureView.branches?.filter((_, index) => selected.branches.has(index)),
|
|
2541
|
-
asyncBoundaries: closureView.asyncBoundaries.filter((boundary) => selectedBoundaryIds.has(boundary.id)).map((boundary) => adoptedBoundaryIds.has(boundary.id) ? completeBoundaries.get(boundary.id) ?? boundary : boundary),
|
|
2542
|
-
...closureView.asyncRunners ? { asyncRunners: Object.fromEntries(Object.entries(closureView.asyncRunners).filter(([graphNodeId]) => graphNodeIds.has(graphNodeId))) } : {}
|
|
2543
|
-
};
|
|
2544
|
-
const graphIds = [...graphNodeIds].sort();
|
|
2545
|
-
return [{
|
|
2546
|
-
id: selfWakeBoundaries ? "self-wake" : branch ? `branch:${branch.id}:${event.eventName}:${hostPath.join(".")}` : `${event.hostNodeId}:${event.eventName}`,
|
|
2547
|
-
hostNodeId: event.hostNodeId,
|
|
2548
|
-
eventName: event.eventName,
|
|
2549
|
-
hostIndex: host?.index ?? -1,
|
|
2550
|
-
hostTagName: host?.tagName ?? "*",
|
|
2551
|
-
...branch ? {
|
|
2552
|
-
branchStartIndex: branch.startAnchor.index,
|
|
2553
|
-
branchEndIndex: branch.endAnchor.index,
|
|
2554
|
-
hostPath
|
|
2555
|
-
} : {},
|
|
2556
|
-
graphNodeIds: graphIds,
|
|
2557
|
-
symbolIds: [...symbolIds].sort(),
|
|
2558
|
-
state: filterState(input.state, new Set(graphIds)),
|
|
2559
|
-
view,
|
|
2560
|
-
...adoptedBoundaryIds.size > 0 ? { adoptsSettledArm: true } : {}
|
|
2561
|
-
}];
|
|
1999
|
+
/** Emitted files whose contents spell a machine path, raw, URI-encoded, or inside a bundler-minted identifier. */
|
|
2000
|
+
function machinePathLeaks(bundle, roots) {
|
|
2001
|
+
const asIdentifier = (value) => value.replace(/[^\w$]/g, "_");
|
|
2002
|
+
const needles = roots.flatMap((path) => {
|
|
2003
|
+
const encoded = encodeURIComponent(`${path}/`);
|
|
2004
|
+
return [
|
|
2005
|
+
`${path}/`,
|
|
2006
|
+
encoded,
|
|
2007
|
+
asIdentifier(encoded),
|
|
2008
|
+
asIdentifier(`${path}/`)
|
|
2009
|
+
];
|
|
2562
2010
|
});
|
|
2563
|
-
const
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
}
|
|
2569
|
-
function settledArmReadGraphNodeIds(input, boundary) {
|
|
2570
|
-
const graphNodeIds = /* @__PURE__ */ new Set();
|
|
2571
|
-
for (const arm of boundaryArmRecordSets(boundary)) collectCompleteArmRecordClosure(arm, graphNodeIds, /* @__PURE__ */ new Set());
|
|
2572
|
-
for (const edge of input.componentEdges ?? []) if (edge.asyncBoundaryId === boundary.id) {
|
|
2573
|
-
for (const prop of edge.props) if (prop.kind === "graph-reference") graphNodeIds.add(prop.graphNodeId);
|
|
2011
|
+
const leaks = [];
|
|
2012
|
+
for (const [fileName, output] of Object.entries(bundle)) {
|
|
2013
|
+
const item = output;
|
|
2014
|
+
const contents = item.type === "chunk" ? item.code : typeof item.source === "string" ? item.source : item.source instanceof Uint8Array ? new TextDecoder().decode(item.source) : void 0;
|
|
2015
|
+
if (contents && needles.some((needle) => contents.includes(needle))) leaks.push(fileName);
|
|
2574
2016
|
}
|
|
2575
|
-
return
|
|
2017
|
+
return leaks.sort();
|
|
2576
2018
|
}
|
|
2577
|
-
function
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
}
|
|
2583
|
-
for (const arm of boundaryArmRecordSets(boundary)) collectCompleteArmRecordClosure(arm, graphNodeIds, symbolIds);
|
|
2584
|
-
const settledEdgeIds = /* @__PURE__ */ new Set();
|
|
2585
|
-
for (const edge of input.componentEdges ?? []) {
|
|
2586
|
-
if (edge.asyncBoundaryId !== boundary.id) continue;
|
|
2587
|
-
settledEdgeIds.add(edge.id);
|
|
2588
|
-
for (const prop of edge.props) if (prop.kind === "graph-reference") graphNodeIds.add(prop.graphNodeId);
|
|
2589
|
-
}
|
|
2590
|
-
for (const row of input.boundRows) if (row.componentEdgePath.some((edgeId) => settledEdgeIds.has(edgeId))) symbolIds.add(row.id);
|
|
2591
|
-
}
|
|
2592
|
-
function collectSettledArmHostRecordClosure(completeView, boundary, graphNodeIds, symbolIds) {
|
|
2593
|
-
const armHosts = /* @__PURE__ */ new Set();
|
|
2594
|
-
for (const arm of boundaryArmRecordSets(boundary)) for (const locator of arm.locators ?? []) armHosts.add(locator.hostNodeId);
|
|
2595
|
-
if (armHosts.size === 0) return;
|
|
2596
|
-
for (const record of completeView.events) if (armHosts.has(record.hostNodeId)) for (const symbolId of record.symbolIds ?? []) symbolIds.add(symbolId);
|
|
2597
|
-
for (const record of completeView.domUpdates) if (armHosts.has(record.hostNodeId)) {
|
|
2598
|
-
graphNodeIds.add(record.graphNodeId);
|
|
2599
|
-
if (record.symbolId) symbolIds.add(record.symbolId);
|
|
2600
|
-
}
|
|
2601
|
-
for (const record of completeView.behaviors) if (armHosts.has(record.hostNodeId)) {
|
|
2602
|
-
for (const read of record.inputGraphReads ?? []) graphNodeIds.add(read.graphNodeId);
|
|
2603
|
-
if (record.symbolId) symbolIds.add(record.symbolId);
|
|
2604
|
-
}
|
|
2605
|
-
for (const record of completeView.keyedRepeats ?? []) if (armHosts.has(record.parentHostNodeId)) {
|
|
2606
|
-
if (record.collectionGraphNodeId) graphNodeIds.add(record.collectionGraphNodeId);
|
|
2607
|
-
for (const rowEvent of record.rowEvents) for (const symbolId of rowEvent.symbolIds ?? []) symbolIds.add(symbolId);
|
|
2019
|
+
function realpathOrSelf(path) {
|
|
2020
|
+
try {
|
|
2021
|
+
return normalize(realpathSync(path));
|
|
2022
|
+
} catch {
|
|
2023
|
+
return normalize(path);
|
|
2608
2024
|
}
|
|
2609
2025
|
}
|
|
2610
|
-
function
|
|
2611
|
-
if (
|
|
2612
|
-
const
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
drop(selected.behaviors, (index) => view.behaviors[index]?.hostNodeId);
|
|
2617
|
-
drop(selected.elementHandles, (index) => view.elementHandles[index]?.hostNodeId);
|
|
2618
|
-
drop(selected.repeats, (index) => view.keyedRepeats?.[index]?.parentHostNodeId);
|
|
2619
|
-
}
|
|
2620
|
-
function collectEscalatedArmBranchIds(arm, branchIds) {
|
|
2621
|
-
for (const branch of arm.branches ?? []) {
|
|
2622
|
-
if (!branch.symbolId && (branch.testReads?.length ?? 0) > 0) branchIds.add(branch.id);
|
|
2623
|
-
for (const nested of branch.armRecords ?? []) collectEscalatedArmBranchIds(nested, branchIds);
|
|
2026
|
+
function rootRelativeRegionComments(bundle, root) {
|
|
2027
|
+
if (!root) return;
|
|
2028
|
+
for (const output of Object.values(bundle)) {
|
|
2029
|
+
const chunk = output;
|
|
2030
|
+
if (chunk.type !== "chunk" || !chunk.code?.includes("//#region ")) continue;
|
|
2031
|
+
chunk.code = chunk.code.replace(/^(\/\/#region (?:\\0)?)(.+)$/gm, (_, prefix, id) => `${prefix}${rootRelativeId(id, root)}`);
|
|
2624
2032
|
}
|
|
2625
2033
|
}
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
const
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
const
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
for (const slot of chunk.slots) if (slot.kind === "child-component") {
|
|
2640
|
-
edgeIds.add(slot.componentEdgeId);
|
|
2641
|
-
walk(slot.childTemplateId);
|
|
2642
|
-
walk(slot.projectionChunkId);
|
|
2643
|
-
} else if (slot.kind === "branch") for (const armId of slot.armTemplateIds) walk(armId);
|
|
2644
|
-
else if (slot.kind === "repeat") {
|
|
2645
|
-
walk(slot.rowTemplateId);
|
|
2646
|
-
walk(slot.emptyTemplateId);
|
|
2647
|
-
} else if (slot.kind === "async") {
|
|
2648
|
-
walk(slot.armTemplateIds.try);
|
|
2649
|
-
walk(slot.armTemplateIds.pending);
|
|
2650
|
-
walk(slot.armTemplateIds.catch);
|
|
2651
|
-
} else if (slot.kind === "dynamic-host") walk(slot.childChunkId);
|
|
2652
|
-
else if ("residue" in slot && slot.residue.kind === "graph-read") graphNodeIds.add(slot.residue.graphNodeId);
|
|
2653
|
-
};
|
|
2654
|
-
for (const armId of branch.armChunkIds) walk(armId);
|
|
2655
|
-
for (const symbol of input.symbolResolver.symbols) if (symbol.kind === "dom-update" && hostNodeIds.has(symbol.hostNodeId)) graphNodeIds.add(symbol.graphNodeId);
|
|
2656
|
-
for (const symbol of input.symbolResolver.symbols) if ("hostNodeId" in symbol && hostNodeIds.has(symbol.hostNodeId) || symbol.kind === "callback-prop" && edgeIds.has(symbol.componentEdgeId) || (symbol.kind === "state-initializer" || symbol.kind === "sync-computed-derive" || symbol.kind === "async-computed-runner") && graphNodeIds.has(symbol.graphNodeId)) symbolIds.add(symbol.id);
|
|
2657
|
-
for (const row of input.boundRows) if (row.componentEdgePath.some((edgeId) => edgeIds.has(edgeId))) symbolIds.add(row.id);
|
|
2658
|
-
}
|
|
2659
|
-
function boundaryArmRecordSets(boundary) {
|
|
2660
|
-
return Array.isArray(boundary.armRecords) ? boundary.armRecords : boundary.armRecords ? [boundary.armRecords] : [];
|
|
2661
|
-
}
|
|
2662
|
-
function unsettledAsyncBoundaryIndexes(state, view) {
|
|
2663
|
-
const computed = new Map(state.computed.map((record) => [record.graphNodeId, record]));
|
|
2664
|
-
const runners = { ...view.asyncRunners };
|
|
2665
|
-
for (const boundary of view.asyncBoundaries) for (const read of boundary.asyncReads) if (read.runnerSymbolId) runners[read.graphNodeId] ??= read.runnerSymbolId;
|
|
2666
|
-
return view.asyncBoundaries.flatMap((boundary, index) => {
|
|
2667
|
-
const reachable = new Set(boundary.asyncReads.map((read) => read.graphNodeId));
|
|
2668
|
-
for (const graphNodeId of reachable) {
|
|
2669
|
-
const record = computed.get(graphNodeId);
|
|
2670
|
-
if (!record) continue;
|
|
2671
|
-
if (runners[graphNodeId] && record.snapshot?.status !== "fulfilled" && record.snapshot?.status !== "rejected") return [index];
|
|
2672
|
-
for (const dependency of record.dependencies ?? []) reachable.add(dependency.graphNodeId);
|
|
2673
|
-
}
|
|
2674
|
-
return [];
|
|
2675
|
-
});
|
|
2676
|
-
}
|
|
2677
|
-
function selectViewSubscribers(view, graphNodeIds, symbolIds, selected) {
|
|
2678
|
-
view.domUpdates.forEach((record, index) => {
|
|
2679
|
-
if (!graphNodeIds.has(record.graphNodeId)) return;
|
|
2680
|
-
selected.domUpdates.add(index);
|
|
2681
|
-
if (record.symbolId) symbolIds.add(record.symbolId);
|
|
2682
|
-
});
|
|
2683
|
-
view.behaviors.forEach((record, index) => {
|
|
2684
|
-
if (!(record.inputGraphReads ?? []).some((read) => graphNodeIds.has(read.graphNodeId))) return;
|
|
2685
|
-
selected.behaviors.add(index);
|
|
2686
|
-
if (record.symbolId) symbolIds.add(record.symbolId);
|
|
2687
|
-
});
|
|
2688
|
-
(view.branches ?? []).forEach((record, index) => {
|
|
2689
|
-
if (!(record.testReads ?? []).some((read) => graphNodeIds.has(read.graphNodeId))) return;
|
|
2690
|
-
selected.branches.add(index);
|
|
2691
|
-
if (record.symbolId) symbolIds.add(record.symbolId);
|
|
2692
|
-
for (const arm of record.armRecords ?? []) collectCompleteArmRecordClosure(arm, graphNodeIds, symbolIds);
|
|
2693
|
-
});
|
|
2694
|
-
view.asyncBoundaries.forEach((record, index) => {
|
|
2695
|
-
if (!record.asyncReads.some((read) => graphNodeIds.has(read.graphNodeId))) return;
|
|
2696
|
-
selected.boundaries.add(index);
|
|
2697
|
-
if (record.updateSymbolId) symbolIds.add(record.updateSymbolId);
|
|
2698
|
-
for (const read of record.asyncReads) if (read.runnerSymbolId) symbolIds.add(read.runnerSymbolId);
|
|
2699
|
-
const arms = Array.isArray(record.armRecords) ? record.armRecords : record.armRecords ? [record.armRecords] : [];
|
|
2700
|
-
for (const arm of arms) collectCompleteArmRecordClosure(arm, graphNodeIds, symbolIds);
|
|
2701
|
-
});
|
|
2702
|
-
(view.keyedRepeats ?? []).forEach((record, index) => {
|
|
2703
|
-
if (!record.collectionGraphNodeId || !graphNodeIds.has(record.collectionGraphNodeId)) return;
|
|
2704
|
-
selected.repeats.add(index);
|
|
2705
|
-
for (const rowEvent of record.rowEvents) for (const symbolId of rowEvent.symbolIds ?? []) symbolIds.add(symbolId);
|
|
2706
|
-
});
|
|
2707
|
-
}
|
|
2708
|
-
function collectCompleteArmRecordClosure(arm, graphNodeIds, symbolIds) {
|
|
2709
|
-
for (const event of arm.events ?? []) for (const symbolId of event.symbolIds ?? []) symbolIds.add(symbolId);
|
|
2710
|
-
for (const update of arm.domUpdates ?? []) {
|
|
2711
|
-
if (typeof update.graphNodeId === "string") graphNodeIds.add(update.graphNodeId);
|
|
2712
|
-
if (typeof update.symbolId === "string") symbolIds.add(update.symbolId);
|
|
2713
|
-
}
|
|
2714
|
-
for (const behavior of arm.behaviors ?? []) {
|
|
2715
|
-
for (const read of behavior.inputGraphReads ?? []) if (typeof read.graphNodeId === "string") graphNodeIds.add(read.graphNodeId);
|
|
2716
|
-
if (typeof behavior.symbolId === "string") symbolIds.add(behavior.symbolId);
|
|
2717
|
-
}
|
|
2718
|
-
for (const repeat of arm.keyedRepeats ?? []) {
|
|
2719
|
-
if (repeat.collectionGraphNodeId) graphNodeIds.add(repeat.collectionGraphNodeId);
|
|
2720
|
-
for (const event of repeat.rowEvents) for (const symbolId of event.symbolIds ?? []) symbolIds.add(symbolId);
|
|
2034
|
+
//#endregion
|
|
2035
|
+
//#region src/module-id.ts
|
|
2036
|
+
const linkedPackagesByRoot = /* @__PURE__ */ new Map();
|
|
2037
|
+
const mintedSources = /* @__PURE__ */ new Map();
|
|
2038
|
+
const mintedIds = /* @__PURE__ */ new Map();
|
|
2039
|
+
function moduleIdFor(filename, root) {
|
|
2040
|
+
if (!root || !isAbsolute(filename)) return filename;
|
|
2041
|
+
const key = `${root}\0${filename}`;
|
|
2042
|
+
let id = mintedIds.get(key);
|
|
2043
|
+
if (id === void 0) {
|
|
2044
|
+
const relativeId = relative(root, filename);
|
|
2045
|
+
id = !relativeId.startsWith("..") && !relativeId.includes("node_modules/") ? relativeId : packageRootedModuleId(filename, root) ?? (outsideCheckout(filename, root) ? namedPackageModuleId(filename) : null) ?? relativeId;
|
|
2046
|
+
mintedIds.set(key, id);
|
|
2721
2047
|
}
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2048
|
+
mintedSources.set(`${root}\0${id}`, filename);
|
|
2049
|
+
return id;
|
|
2050
|
+
}
|
|
2051
|
+
/** The file a module id names, spelled the way the bundler resolved it. */
|
|
2052
|
+
function sourceForModuleId(moduleId, root) {
|
|
2053
|
+
if (!root || isAbsolute(moduleId)) return moduleId;
|
|
2054
|
+
return mintedSources.get(`${root}\0${moduleId}`) ?? realpathOf(resolve(root, moduleId));
|
|
2055
|
+
}
|
|
2056
|
+
function packageRootedModuleId(filename, root) {
|
|
2057
|
+
const real = realpathOf(filename);
|
|
2058
|
+
for (const linked of linkedPackages(root)) {
|
|
2059
|
+
if (real === linked.real) return linked.id;
|
|
2060
|
+
if (real.startsWith(`${linked.real}/`)) return `${linked.id}${real.slice(linked.real.length)}`;
|
|
2726
2061
|
}
|
|
2062
|
+
return null;
|
|
2727
2063
|
}
|
|
2728
|
-
function
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
graphNodeIds.add(dependency.graphNodeId);
|
|
2741
|
-
changed = true;
|
|
2742
|
-
}
|
|
2064
|
+
function outsideCheckout(filename, root) {
|
|
2065
|
+
const real = realpathOf(filename);
|
|
2066
|
+
return !machinePathRoots(root).some((checkout) => filename.startsWith(`${checkout}/`) || real.startsWith(`${checkout}/`));
|
|
2067
|
+
}
|
|
2068
|
+
function namedPackageModuleId(filename) {
|
|
2069
|
+
const real = realpathOf(filename);
|
|
2070
|
+
for (let directory = dirname(real); dirname(directory) !== directory; directory = dirname(directory)) {
|
|
2071
|
+
let name;
|
|
2072
|
+
try {
|
|
2073
|
+
name = JSON.parse(readFileSync(join(directory, "package.json"), "utf8")).name;
|
|
2074
|
+
} catch {
|
|
2075
|
+
continue;
|
|
2743
2076
|
}
|
|
2077
|
+
if (typeof name === "string" && name) return `node_modules/${name}${real.slice(directory.length)}`;
|
|
2744
2078
|
}
|
|
2079
|
+
return null;
|
|
2080
|
+
}
|
|
2081
|
+
function linkedPackages(root) {
|
|
2082
|
+
const cached = linkedPackagesByRoot.get(root);
|
|
2083
|
+
if (cached) return cached;
|
|
2084
|
+
const directory = join(root, "node_modules");
|
|
2085
|
+
const packages = [];
|
|
2086
|
+
for (const name of packageNames(directory)) try {
|
|
2087
|
+
packages.push({
|
|
2088
|
+
id: `node_modules/${name}`,
|
|
2089
|
+
real: realpathOf(join(directory, name))
|
|
2090
|
+
});
|
|
2091
|
+
} catch {}
|
|
2092
|
+
packages.sort((a, b) => b.real.length - a.real.length);
|
|
2093
|
+
linkedPackagesByRoot.set(root, packages);
|
|
2094
|
+
return packages;
|
|
2745
2095
|
}
|
|
2746
|
-
function
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
sharedDefinitions: state.sharedDefinitions?.filter((definition) => definition.graphNodeIds.some((graphNodeId) => graphNodeIds.has(graphNodeId)))
|
|
2753
|
-
};
|
|
2754
|
-
}
|
|
2755
|
-
function closureSize(graphNodeIds, symbolIds, selected) {
|
|
2756
|
-
return graphNodeIds.size + symbolIds.size + Object.values(selected).reduce((total, records) => total + records.size, 0);
|
|
2757
|
-
}
|
|
2758
|
-
//#endregion
|
|
2759
|
-
//#region src/virtual-ids.ts
|
|
2760
|
-
const TSRX_SOURCE_FILE = /\.tsrx(?:[?#].*)?$/;
|
|
2761
|
-
const MARKLESS_SYMBOL_SOURCE_QUERY_RE = /[?&]markless-symbols(?:[&#]|$)/;
|
|
2762
|
-
const MARKLESS_RESUME_SOURCE_QUERY_RE = /[?&]markless-resume(?:[&#]|$)/;
|
|
2763
|
-
const MARKLESS_RENDER_DATA_SOURCE_QUERY_RE = /[?&]markless-render-data(?:[&#]|$)/;
|
|
2764
|
-
const MARKLESS_REACHED_FROM_SOURCE_QUERY = "markless-reached-from";
|
|
2765
|
-
const MARKLESS_REACHED_FROM_ROUTE = "route";
|
|
2766
|
-
const MARKLESS_PRERENDER_WAKE_SOURCE_QUERY_RE = /[?&]markless-prerender-wake(?:[&#]|$)/;
|
|
2767
|
-
const MARKLESS_ROUTE_SOURCE_QUERY_RE = /[?&]markless-route(?:[&#]|$)/;
|
|
2768
|
-
const RESUME_VIRTUAL_ID_RE = /^virtual:markless:resume:([^:]+)$/;
|
|
2769
|
-
const PRERENDER_WAKE_VIRTUAL_ID_RE = /^virtual:markless:prerender-wake:([^:]+)$/;
|
|
2770
|
-
const SETTLE_VIRTUAL_ID_RE = /^virtual:markless:settle:([^:]+)$/;
|
|
2771
|
-
const SYMBOL_VIRTUAL_STRING_RE = /(["'`])((?:virtual:markless:symbol:)[^"'`]+)\1/g;
|
|
2772
|
-
function stripBuildPrefix(fileName) {
|
|
2773
|
-
return fileName.startsWith("build/") ? fileName.slice(MARKLESS_BUILD_PREFIX.length) : fileName;
|
|
2774
|
-
}
|
|
2775
|
-
function virtualModuleSourceForLoad(module, options) {
|
|
2776
|
-
if (!options.dev || module.type !== "resolver") return module.source;
|
|
2777
|
-
if (!module.source.includes("moduleUrls[row[0]]")) return module.source;
|
|
2778
|
-
return module.source.replace(SYMBOL_VIRTUAL_STRING_RE, (_match, _quote, virtualId) => JSON.stringify(devBrowserVirtualModuleUrl(virtualId, options.publicPath)));
|
|
2779
|
-
}
|
|
2780
|
-
function devBrowserSourceModuleUrl(source, _root, publicPath) {
|
|
2781
|
-
const path = withQuery(joinURL("@fs", withoutLeadingSlash(source)), { import: null });
|
|
2782
|
-
return publicPath ? publicPath(path) : joinURL("/", path);
|
|
2783
|
-
}
|
|
2784
|
-
function devBrowserVirtualModuleUrl(virtualId, publicPath) {
|
|
2785
|
-
const path = joinURL("@id", resolveVirtualId(virtualId).replace("\0", "__x00__"));
|
|
2786
|
-
return publicPath ? publicPath(path) : joinURL("/", path);
|
|
2787
|
-
}
|
|
2788
|
-
function clientSymbolEntries(input, root) {
|
|
2789
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) return [];
|
|
2790
|
-
const sources = [];
|
|
2791
|
-
for (const [name, value] of Object.entries(input)) {
|
|
2792
|
-
if (!/symbol/i.test(name)) continue;
|
|
2793
|
-
for (const entry of inputEntryValues(value)) if (typeof entry === "string" && TSRX_SOURCE_FILE.test(entry)) sources.push(normalizeInputSource(entry, root));
|
|
2096
|
+
function packageNames(directory) {
|
|
2097
|
+
let entries;
|
|
2098
|
+
try {
|
|
2099
|
+
entries = readdirSync(directory);
|
|
2100
|
+
} catch {
|
|
2101
|
+
return [];
|
|
2794
2102
|
}
|
|
2795
|
-
return
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
return Array.isArray(value) ? value.flatMap(inputEntryValues) : [value];
|
|
2799
|
-
}
|
|
2800
|
-
function normalizeInputSource(source, root) {
|
|
2801
|
-
const path = pathname(source);
|
|
2802
|
-
if (isAbsolute(path)) return path;
|
|
2803
|
-
return pathname(resolve(root ?? "", path));
|
|
2804
|
-
}
|
|
2805
|
-
function isSymbolOnlySourceRequest(id) {
|
|
2806
|
-
return MARKLESS_SYMBOL_SOURCE_QUERY_RE.test(id);
|
|
2807
|
-
}
|
|
2808
|
-
function isScalarPlanSourceRequest(id) {
|
|
2809
|
-
return isSymbolOnlySourceRequest(id) && new URLSearchParams(parsePath(id).search).has("markless-scalar-plans");
|
|
2810
|
-
}
|
|
2811
|
-
function isResumeSourceRequest(id) {
|
|
2812
|
-
return MARKLESS_RESUME_SOURCE_QUERY_RE.test(id);
|
|
2813
|
-
}
|
|
2814
|
-
function isRenderDataSourceRequest(id) {
|
|
2815
|
-
return MARKLESS_RENDER_DATA_SOURCE_QUERY_RE.test(id);
|
|
2816
|
-
}
|
|
2817
|
-
function renderDataReachedFromQuery(id) {
|
|
2818
|
-
return new URLSearchParams(parsePath(id).search).get(MARKLESS_REACHED_FROM_SOURCE_QUERY) ?? void 0;
|
|
2819
|
-
}
|
|
2820
|
-
function isRouteNavigationSourceRequest(id) {
|
|
2821
|
-
return MARKLESS_ROUTE_SOURCE_QUERY_RE.test(id) || isRenderDataSourceRequest(id) && renderDataReachedFromQuery(id) === void 0;
|
|
2822
|
-
}
|
|
2823
|
-
function materializedReachedRenderDataSource(source) {
|
|
2824
|
-
return withQuery(source, {
|
|
2825
|
-
"markless-render-data": null,
|
|
2826
|
-
[MARKLESS_REACHED_FROM_SOURCE_QUERY]: MARKLESS_REACHED_FROM_ROUTE
|
|
2827
|
-
});
|
|
2828
|
-
}
|
|
2829
|
-
function sharedReachedRenderDataRequest(id) {
|
|
2830
|
-
if (!isRenderDataSourceRequest(id)) return void 0;
|
|
2831
|
-
const reachedFrom = renderDataReachedFromQuery(id);
|
|
2832
|
-
return reachedFrom === void 0 || reachedFrom === MARKLESS_REACHED_FROM_ROUTE ? void 0 : withQuery(id, { [MARKLESS_REACHED_FROM_SOURCE_QUERY]: MARKLESS_REACHED_FROM_ROUTE });
|
|
2833
|
-
}
|
|
2834
|
-
function isPrerenderWakeSourceRequest(id) {
|
|
2835
|
-
return MARKLESS_PRERENDER_WAKE_SOURCE_QUERY_RE.test(id);
|
|
2836
|
-
}
|
|
2837
|
-
function isClientPrimarySourceRequest(id) {
|
|
2838
|
-
return !(MARKLESS_SYMBOL_SOURCE_QUERY_RE.test(id) || MARKLESS_RESUME_SOURCE_QUERY_RE.test(id) || MARKLESS_RENDER_DATA_SOURCE_QUERY_RE.test(id) || MARKLESS_PRERENDER_WAKE_SOURCE_QUERY_RE.test(id) || MARKLESS_ROUTE_SOURCE_QUERY_RE.test(id));
|
|
2839
|
-
}
|
|
2840
|
-
function clientRouteArtifactReference(source) {
|
|
2841
|
-
const symbolSource = source.includes("?") ? `${source}&markless-symbols` : `${source}?markless-symbols`;
|
|
2842
|
-
const renderDataSource = source.includes("?") ? `${source}&markless-render-data` : `${source}?markless-render-data`;
|
|
2843
|
-
return [
|
|
2844
|
-
`const [symbolModule, renderDataModule] = await Promise.all([import(${JSON.stringify(symbolSource)}), import(${JSON.stringify(renderDataSource)})]);`,
|
|
2845
|
-
"const marklessRouteArtifact = {",
|
|
2846
|
-
" renderData: renderDataModule.marklessPrerenderData,",
|
|
2847
|
-
" loadSymbol: symbolModule.loadSymbol,",
|
|
2848
|
-
"};",
|
|
2849
|
-
"export default marklessRouteArtifact;"
|
|
2850
|
-
].join("\n");
|
|
2851
|
-
}
|
|
2852
|
-
function sourceForSymbolVirtualImporter(importer) {
|
|
2853
|
-
if (!importer) return null;
|
|
2854
|
-
return symbolVirtualModuleSourceFile(normalizeVirtualId(importer));
|
|
2855
|
-
}
|
|
2856
|
-
function sourceForResumeVirtualImporter(importer) {
|
|
2857
|
-
if (!importer) return null;
|
|
2858
|
-
const match = normalizeVirtualId(importer).match(RESUME_VIRTUAL_ID_RE);
|
|
2859
|
-
return match?.[1] ? decodeURIComponent(match[1]) : null;
|
|
2860
|
-
}
|
|
2861
|
-
function resolverVirtualModuleSourceFile(id) {
|
|
2862
|
-
const prefix = `${MARKLESS_VIRTUAL_PREFIX}resolver:`;
|
|
2863
|
-
return id.startsWith(prefix) ? decodeURIComponent(id.slice(prefix.length)) : null;
|
|
2864
|
-
}
|
|
2865
|
-
function sourceForTriggerGroupVirtualImporter(importer) {
|
|
2866
|
-
if (!importer) return null;
|
|
2867
|
-
return triggerGroupVirtualModuleSourceFile(normalizeVirtualId(importer));
|
|
2868
|
-
}
|
|
2869
|
-
function sourceForPrerenderWakeVirtualImporter(importer) {
|
|
2870
|
-
if (!importer) return null;
|
|
2871
|
-
const match = normalizeVirtualId(importer).match(PRERENDER_WAKE_VIRTUAL_ID_RE);
|
|
2872
|
-
return match?.[1] ? decodeURIComponent(match[1]) : null;
|
|
2873
|
-
}
|
|
2874
|
-
function sourceForSettleVirtualImporter(importer) {
|
|
2875
|
-
if (!importer) return null;
|
|
2876
|
-
const match = normalizeVirtualId(importer).match(SETTLE_VIRTUAL_ID_RE);
|
|
2877
|
-
return match?.[1] ? decodeURIComponent(match[1]) : null;
|
|
2878
|
-
}
|
|
2879
|
-
function isRelativeImport(source) {
|
|
2880
|
-
return source.startsWith("./") || source.startsWith("../");
|
|
2881
|
-
}
|
|
2882
|
-
function isCompilerStatefulModuleId(id) {
|
|
2883
|
-
const bare = id.startsWith("\0") ? id.slice(1) : id;
|
|
2884
|
-
return TSRX_SOURCE_FILE.test(bare) || bare.startsWith("virtual:markless:") || /[?&]markless-[a-z-]+(?:[=&#]|$)/.test(bare);
|
|
2885
|
-
}
|
|
2886
|
-
function isMarklessRuntimeModule(id) {
|
|
2887
|
-
const path = pathname(id);
|
|
2888
|
-
return /[/\\](?:web|runtime|serializer)[/\\]src[/\\].+\.ts$/.test(path);
|
|
2889
|
-
}
|
|
2890
|
-
function executionLogRuntimeModuleId(id) {
|
|
2891
|
-
const path = pathname(id);
|
|
2892
|
-
const match = path.match(/[/\\](web|runtime|serializer)[/\\]src[/\\]([^?#]+)\.ts$/);
|
|
2893
|
-
return match ? `${match[1]}:${match[2].replace(/[/\\]/g, "/")}` : path;
|
|
2894
|
-
}
|
|
2895
|
-
function normalizeVirtualId(id) {
|
|
2896
|
-
const bare = id.startsWith("\0") ? id.slice(1) : id;
|
|
2897
|
-
if (!bare.startsWith("virtual:markless:")) return bare;
|
|
2898
|
-
const queryIndex = bare.indexOf("?");
|
|
2899
|
-
const segments = (queryIndex === -1 ? bare : bare.slice(0, queryIndex)).slice(17).split(":").map((segment) => {
|
|
2103
|
+
return entries.flatMap((entry) => {
|
|
2104
|
+
if (entry.startsWith(".")) return [];
|
|
2105
|
+
if (!entry.startsWith("@")) return [entry];
|
|
2900
2106
|
try {
|
|
2901
|
-
return
|
|
2107
|
+
return readdirSync(join(directory, entry)).map((scoped) => `${entry}/${scoped}`);
|
|
2902
2108
|
} catch {
|
|
2903
|
-
return
|
|
2109
|
+
return [];
|
|
2904
2110
|
}
|
|
2905
2111
|
});
|
|
2906
|
-
return `${MARKLESS_VIRTUAL_PREFIX}${segments.join(":")}`;
|
|
2907
2112
|
}
|
|
2908
|
-
function
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
if (chunk.type !== "chunk") continue;
|
|
2914
|
-
if (typeof chunk.facadeModuleId === "string") ids.add(normalizeVirtualId(chunk.facadeModuleId));
|
|
2915
|
-
if (Array.isArray(chunk.moduleIds)) {
|
|
2916
|
-
for (const id of chunk.moduleIds) if (typeof id === "string") ids.add(normalizeVirtualId(id));
|
|
2917
|
-
}
|
|
2113
|
+
function realpathOf(path) {
|
|
2114
|
+
try {
|
|
2115
|
+
return normalize(realpathSync(path));
|
|
2116
|
+
} catch {
|
|
2117
|
+
return normalize(path);
|
|
2918
2118
|
}
|
|
2919
|
-
return ids;
|
|
2920
|
-
}
|
|
2921
|
-
function resolveVirtualId(id) {
|
|
2922
|
-
if (id.startsWith("\0")) return id;
|
|
2923
|
-
return `\0${id}`;
|
|
2924
2119
|
}
|
|
2925
|
-
|
|
2926
|
-
|
|
2120
|
+
/** A symbol module's execution-log identity: its virtual id with the source spelled root-relative. */
|
|
2121
|
+
function symbolExecutionLogId(virtualModuleId, root) {
|
|
2122
|
+
const bare = virtualModuleId.startsWith("\0") ? virtualModuleId.slice(1) : virtualModuleId;
|
|
2123
|
+
const source = symbolVirtualModuleSourceFile(bare);
|
|
2124
|
+
if (source === null) return bare;
|
|
2125
|
+
const encodedSymbolId = bare.slice(bare.lastIndexOf(":") + 1);
|
|
2126
|
+
return symbolVirtualModuleId(moduleIdFor(source, root), decodeURIComponent(encodedSymbolId));
|
|
2927
2127
|
}
|
|
2928
|
-
const
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
function
|
|
2935
|
-
if (
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2128
|
+
const EMBEDDED_SOURCE_RE = new RegExp(`^(${String.fromCharCode(0)}?(?:virtual:markless:[a-z-]+:|imported:))([^:?]*)(.*)$`, "s");
|
|
2129
|
+
/**
|
|
2130
|
+
* Any id a build writes into output, with the file it names spelled by `moduleIdFor`:
|
|
2131
|
+
* a bare path, `virtual:markless:<kind>:<source>...` or `imported:<source>:...`,
|
|
2132
|
+
* the source raw or URI-encoded. Other ids pass through unchanged.
|
|
2133
|
+
*/
|
|
2134
|
+
function rootRelativeId(id, root) {
|
|
2135
|
+
if (!root) return id;
|
|
2136
|
+
if (isAbsolute(id)) {
|
|
2137
|
+
const query = id.search(/[?#]/);
|
|
2138
|
+
return query < 0 ? moduleIdFor(id, root) : `${moduleIdFor(id.slice(0, query), root)}${id.slice(query)}`;
|
|
2139
|
+
}
|
|
2140
|
+
const match = EMBEDDED_SOURCE_RE.exec(id);
|
|
2141
|
+
if (!match) return id;
|
|
2142
|
+
const [, prefix, spelled, rest] = match;
|
|
2143
|
+
let source;
|
|
2144
|
+
try {
|
|
2145
|
+
source = decodeURIComponent(spelled);
|
|
2146
|
+
} catch {
|
|
2147
|
+
return id;
|
|
2148
|
+
}
|
|
2149
|
+
if (!isAbsolute(source)) return id;
|
|
2150
|
+
const moduleId = moduleIdFor(source, root);
|
|
2151
|
+
return `${prefix}${spelled === source ? moduleId : encodeURIComponent(moduleId)}${rest}`;
|
|
2951
2152
|
}
|
|
2952
2153
|
//#endregion
|
|
2953
2154
|
//#region src/build/warm-packs.ts
|
|
@@ -2973,7 +2174,8 @@ const PACK_COST_MODEL = {
|
|
|
2973
2174
|
fileOverheadGzipKb: .5,
|
|
2974
2175
|
lazySiblingOverheadGzipKb: 1,
|
|
2975
2176
|
minDeferredGzipKb: 1,
|
|
2976
|
-
sourceGzipRatio: .25
|
|
2177
|
+
sourceGzipRatio: .25,
|
|
2178
|
+
packedModuleWrapperBytes: 64
|
|
2977
2179
|
};
|
|
2978
2180
|
function estimatedGzipKb(sourceLength, model = PACK_COST_MODEL) {
|
|
2979
2181
|
return sourceLength * model.sourceGzipRatio / 1024;
|
|
@@ -3178,7 +2380,77 @@ function planRoutePackGroups(input) {
|
|
|
3178
2380
|
}
|
|
3179
2381
|
}
|
|
3180
2382
|
}
|
|
3181
|
-
|
|
2383
|
+
for (const [id, pack] of alternativeDeferredPacks(input.modules, groups)) groups.set(id, pack);
|
|
2384
|
+
return splitOversizedLazyPacks(input.pagesLoadOneRoute ? splitOversizedStartupPacks(splitFrameworkFromApp(splitStartupPacksByStaticReach(groups, roots, sources, owners, input), input), input) : groups, input);
|
|
2385
|
+
}
|
|
2386
|
+
function splitOversizedStartupPacks(groups, input) {
|
|
2387
|
+
const cap = input.maxPackBytes;
|
|
2388
|
+
if (!cap) return groups;
|
|
2389
|
+
const packs = /* @__PURE__ */ new Map();
|
|
2390
|
+
for (const [id, group] of groups) if (isStartupPack(group)) push(packs, group, id);
|
|
2391
|
+
const sizeOf = (id) => (input.modules.get(id)?.size ?? 0) + PACK_COST_MODEL.packedModuleWrapperBytes;
|
|
2392
|
+
const routeRoots = [...input.routes.values()].flat();
|
|
2393
|
+
for (const [group, ids] of packs) {
|
|
2394
|
+
if (ids.reduce((sum, id) => sum + sizeOf(id), 0) <= cap) continue;
|
|
2395
|
+
const members = new Set(ids);
|
|
2396
|
+
const order = [];
|
|
2397
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2398
|
+
const visit = (start) => {
|
|
2399
|
+
const stack = [[start, 0]];
|
|
2400
|
+
seen.add(start);
|
|
2401
|
+
while (stack.length) {
|
|
2402
|
+
const top = stack[stack.length - 1];
|
|
2403
|
+
const dependencies = input.modules.get(top[0])?.dependencies ?? [];
|
|
2404
|
+
const next = dependencies.slice(top[1]).findIndex((dependency) => members.has(dependency) && !seen.has(dependency));
|
|
2405
|
+
if (next < 0) {
|
|
2406
|
+
order.push(top[0]);
|
|
2407
|
+
stack.pop();
|
|
2408
|
+
continue;
|
|
2409
|
+
}
|
|
2410
|
+
const dependency = dependencies[top[1] + next];
|
|
2411
|
+
top[1] += next + 1;
|
|
2412
|
+
seen.add(dependency);
|
|
2413
|
+
stack.push([dependency, 0]);
|
|
2414
|
+
}
|
|
2415
|
+
};
|
|
2416
|
+
for (const id of [...routeRoots.filter((id) => members.has(id)), ...[...ids].sort()]) if (!seen.has(id)) visit(id);
|
|
2417
|
+
let piece = 1;
|
|
2418
|
+
let filled = 0;
|
|
2419
|
+
for (const id of order) {
|
|
2420
|
+
const size = sizeOf(id);
|
|
2421
|
+
if (filled > 0 && filled + size > cap) {
|
|
2422
|
+
piece++;
|
|
2423
|
+
filled = 0;
|
|
2424
|
+
}
|
|
2425
|
+
filled += size;
|
|
2426
|
+
if (piece > 1) groups.set(id, `${group}~${piece}`);
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
return groups;
|
|
2430
|
+
}
|
|
2431
|
+
function splitOversizedLazyPacks(groups, input) {
|
|
2432
|
+
const cap = input.maxPackBytes;
|
|
2433
|
+
if (!cap) return groups;
|
|
2434
|
+
const packs = /* @__PURE__ */ new Map();
|
|
2435
|
+
for (const [id, group] of groups) if (!isStartupPack(group)) push(packs, group, id);
|
|
2436
|
+
const sizeOf = (id) => (input.modules.get(id)?.size ?? 0) + PACK_COST_MODEL.packedModuleWrapperBytes;
|
|
2437
|
+
for (const [group, ids] of packs) {
|
|
2438
|
+
if (ids.reduce((sum, id) => sum + sizeOf(id), 0) <= cap) continue;
|
|
2439
|
+
const bySource = /* @__PURE__ */ new Map();
|
|
2440
|
+
for (const id of ids) push(bySource, input.modules.get(id)?.source ?? id, id);
|
|
2441
|
+
let part = 0;
|
|
2442
|
+
let filled = Infinity;
|
|
2443
|
+
for (const [, members] of [...bySource].sort(([left], [right]) => left.localeCompare(right))) {
|
|
2444
|
+
const size = members.reduce((sum, id) => sum + sizeOf(id), 0);
|
|
2445
|
+
if (filled + size > cap) {
|
|
2446
|
+
part++;
|
|
2447
|
+
filled = 0;
|
|
2448
|
+
}
|
|
2449
|
+
filled += size;
|
|
2450
|
+
for (const id of members) groups.set(id, part === 1 ? group : `${group}${PACK_PART_MARK}${part}`);
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
return groups;
|
|
3182
2454
|
}
|
|
3183
2455
|
function splitFrameworkFromApp(groups, input) {
|
|
3184
2456
|
const halves = /* @__PURE__ */ new Map();
|
|
@@ -3209,6 +2481,15 @@ function splitStartupPacksByStaticReach(groups, roots, sources, owners, input) {
|
|
|
3209
2481
|
return !!module && !module.navigationOnly && (!flagged || !!module.firstEvent);
|
|
3210
2482
|
};
|
|
3211
2483
|
const handler = (id) => !!input.modules.get(id)?.handler;
|
|
2484
|
+
const seedSiblings = /* @__PURE__ */ new Map();
|
|
2485
|
+
const seedSiblingsOf = (source) => {
|
|
2486
|
+
let list = seedSiblings.get(source);
|
|
2487
|
+
if (!list) seedSiblings.set(source, list = (sources.get(source) ?? []).filter(seed).map((id) => ({
|
|
2488
|
+
id,
|
|
2489
|
+
handler: handler(id)
|
|
2490
|
+
})));
|
|
2491
|
+
return list;
|
|
2492
|
+
};
|
|
3212
2493
|
const closure = (route, start, path) => {
|
|
3213
2494
|
const reached = /* @__PURE__ */ new Set();
|
|
3214
2495
|
const handlers = /* @__PURE__ */ new Set();
|
|
@@ -3220,8 +2501,9 @@ function splitStartupPacksByStaticReach(groups, roots, sources, owners, input) {
|
|
|
3220
2501
|
if (!module) continue;
|
|
3221
2502
|
reached.add(id);
|
|
3222
2503
|
pending.push(...module.dependencies);
|
|
3223
|
-
|
|
3224
|
-
|
|
2504
|
+
if (!module.source) continue;
|
|
2505
|
+
for (const sibling of seedSiblingsOf(module.source)) if (sibling.id !== id) if (sibling.handler) handlers.add(sibling.id);
|
|
2506
|
+
else pending.push(sibling.id);
|
|
3225
2507
|
}
|
|
3226
2508
|
return {
|
|
3227
2509
|
reached,
|
|
@@ -3281,6 +2563,14 @@ function startupPackOfLazy(name) {
|
|
|
3281
2563
|
return name.replace(new RegExp(`^(route|shared)${LAZY_PACK_MARK}`), "$1");
|
|
3282
2564
|
}
|
|
3283
2565
|
const LAZY_PACK_MARK = "-lazy";
|
|
2566
|
+
const PACK_PART_MARK = "-part";
|
|
2567
|
+
function packOfPiece(name) {
|
|
2568
|
+
return name.replace(PACK_PIECES, "");
|
|
2569
|
+
}
|
|
2570
|
+
const PACK_PIECES = /(?:~\d+)+$/;
|
|
2571
|
+
function packOfPart(name) {
|
|
2572
|
+
return name.replace(new RegExp(`${PACK_PART_MARK}\\d+$`), "");
|
|
2573
|
+
}
|
|
3284
2574
|
const FRAMEWORK_PIECE = "~1";
|
|
3285
2575
|
const ROUTE_KEY_SEPARATOR = "\n";
|
|
3286
2576
|
const SHARED_MARK = " ";
|
|
@@ -3305,5 +2595,45 @@ function push(map, key, value) {
|
|
|
3305
2595
|
if (values) values.push(value);
|
|
3306
2596
|
else map.set(key, [value]);
|
|
3307
2597
|
}
|
|
2598
|
+
/**
|
|
2599
|
+
* An app module that imports several deferred targets picks one per run (a table of loaders), so
|
|
2600
|
+
* each target, with the code only it reaches, gets a deferred pack of its own instead of the one
|
|
2601
|
+
* every deferred module shares: choosing one never downloads the others.
|
|
2602
|
+
*/
|
|
2603
|
+
function alternativeDeferredPacks(modules, groups) {
|
|
2604
|
+
const deferred = (id) => groups.get(id) === MARKLESS_DEFERRED_PACK;
|
|
2605
|
+
const alternatives = /* @__PURE__ */ new Set();
|
|
2606
|
+
const entries = /* @__PURE__ */ new Set();
|
|
2607
|
+
for (const [id, module] of modules) {
|
|
2608
|
+
const targets = (module.dynamicDependencies ?? []).filter(deferred);
|
|
2609
|
+
for (const target of targets) if (!deferred(id)) entries.add(target);
|
|
2610
|
+
if (!module.app || targets.length < 2) continue;
|
|
2611
|
+
for (const target of targets) if (modules.get(target)?.app) alternatives.add(target);
|
|
2612
|
+
}
|
|
2613
|
+
const packs = /* @__PURE__ */ new Map();
|
|
2614
|
+
if (alternatives.size === 0) return packs;
|
|
2615
|
+
const closure = (from, stop) => {
|
|
2616
|
+
const reached = /* @__PURE__ */ new Set();
|
|
2617
|
+
const pending = [from];
|
|
2618
|
+
for (let id = pending.pop(); id !== void 0; id = pending.pop()) {
|
|
2619
|
+
if (reached.has(id) || !deferred(id) || id !== from && stop(id)) continue;
|
|
2620
|
+
reached.add(id);
|
|
2621
|
+
const module = modules.get(id);
|
|
2622
|
+
pending.push(...module?.dependencies ?? [], ...module?.dynamicDependencies ?? []);
|
|
2623
|
+
}
|
|
2624
|
+
return reached;
|
|
2625
|
+
};
|
|
2626
|
+
const shared = /* @__PURE__ */ new Set();
|
|
2627
|
+
for (const entry of entries) if (!alternatives.has(entry)) for (const id of closure(entry, (id) => alternatives.has(id))) shared.add(id);
|
|
2628
|
+
const owner = /* @__PURE__ */ new Map();
|
|
2629
|
+
for (const root of alternatives) for (const id of closure(root, (id) => alternatives.has(id))) owner.set(id, owner.has(id) && owner.get(id) !== root ? null : root);
|
|
2630
|
+
const labels = /* @__PURE__ */ new Map();
|
|
2631
|
+
for (const [id, root] of owner) {
|
|
2632
|
+
if (root === null || shared.has(id) || !modules.get(id)?.app) continue;
|
|
2633
|
+
if (!labels.has(root)) labels.set(root, `${MARKLESS_DEFERRED_PACK}-alt${labels.size}`);
|
|
2634
|
+
packs.set(id, labels.get(root));
|
|
2635
|
+
}
|
|
2636
|
+
return packs;
|
|
2637
|
+
}
|
|
3308
2638
|
//#endregion
|
|
3309
|
-
export {
|
|
2639
|
+
export { EXECUTION_LOG_CHUNK_MODULE_PATTERN as $, emitSourceModule as A, symbolVirtualModuleSourceFile as B, MARKLESS_VIRTUAL_PREFIX as C, emitOverlayLoaderInstall as D, demandsOverlay as E, resumeVirtualModuleId as F, sharedInlineSourcesModuleId as G, emitSymbolRouteTable as H, rewriteSymbolModuleExport as I, compilePrerenderInlineResumerSources as J, sharedInlineSourcesModuleSource as K, scopedSymbolExportName as L, payloadModule as M, prerenderWakeVirtualModuleId as N, emitResumeModule as O, prerenderWakeVirtualModuleSourceFile as P, PROTOCOL_BLOCK_START_COMMENT as Q, settleVirtualModuleId as R, withoutMachinePaths as S, STORAGE_FREE_RESUME_ENTRY_SPECIFIER as T, MARKLESS_SCALAR_PLAN_SOURCE_QUERY as U, withoutFirstUse as V, isSharedInlineSourcesModuleId as W, createInlineDeferTriggerSource as X, INLINE_DEFER_LOADER_SOURCE as Y, inlineDeferSource as Z, sourceForModuleId as _, isStartupPack as a, hasExecutionLogModuleHook as at, machinePathRoots as b, packOfPart as c, normalizeExecutionLogMode as ct, startupPackOfLazy as d, EXECUTION_LOG_DISPATCH_MODULE_IDS as et, PACK_COST_MODEL as f, rootRelativeId as g, moduleIdFor as h, isMarklessNavigationPack as i, executionLogVirtualModuleSource as it, encodedSymbolSource as j, emitSettleModule as k, packOfPiece as l, requalifyExecutionLogModuleHook as lt, warmPacksSuffix as m, MARKLESS_NAVIGATION_PACK_PREFIX as n, MARKLESS_EXECUTION_LOG_MODULE_ID as nt, lazyStartupPackName as o, injectExecutionLogModuleHook as ot, warmEvaluatedImports as p, compileInlineResumerSources as q, isMarklessDeferredPack as r, executionLogActivationInjection as rt, marklessDeferredChunkFileNames as s, isExecutionLogChunk as st, MARKLESS_DEFERRED_PACK as t, MARKLESS_EXECUTION_LOG_GLOBAL as tt, planRoutePackGroups as u, symbolExecutionLogId as v, RESUME_ENTRY_SPECIFIER as w, rootRelativeRegionComments as x, machinePathLeaks as y, symbolVirtualModuleId as z };
|