@markless/bundler 0.1.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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/preload.d.ts +79 -0
- package/dist/preload.js +75 -0
- package/dist/rolldown-Czh1duwk.js +1802 -0
- package/dist/rolldown.d.ts +79 -0
- package/dist/rolldown.js +3 -0
- package/dist/source-module-BRb5P7wL.d.ts +6 -0
- package/dist/source-module-CSRzW4Ny.js +876 -0
- package/dist/types-D6KerlYq.d.ts +107 -0
- package/dist/vite.d.ts +12 -0
- package/dist/vite.js +387 -0
- package/package.json +55 -0
|
@@ -0,0 +1,1802 @@
|
|
|
1
|
+
import { S as planModulePreloads, _ as requalifyExecutionLogModuleHook, a as resumeVirtualModuleId, b as outputDefaults, c as symbolVirtualModuleId, d as MARKLESS_EXECUTION_SIZES, f as createExecutionSizesAsset, g as normalizeExecutionLogMode, h as injectExecutionLogModuleHook, i as payloadModule, l as symbolVirtualModuleSourceFile, m as executionLogVirtualModuleSource, n as emitResumeModule, o as rewriteSymbolModuleExport, p as executionLogActivationInjection, r as emitSourceModule, s as scopedSymbolExportName, t as MARKLESS_VIRTUAL_PREFIX, u as MARKLESS_EXECUTION_LOG_MODULE_ID, v as MARKLESS_BUILD_PREFIX, y as MARKLESS_BUNDLE_GRAPH } from "./source-module-CSRzW4Ny.js";
|
|
2
|
+
import { joinURL, parsePath, withLeadingSlash, withQuery, withoutLeadingSlash } from "ufo";
|
|
3
|
+
import { dirname, isAbsolute, join, normalize, relative, resolve } from "pathe";
|
|
4
|
+
import { defDGraph } from "@thi.ng/dgraph";
|
|
5
|
+
import { compileTsrxModule, emitSymbolResolverModule, parseJavaScriptModule } from "@markless/compiler";
|
|
6
|
+
//#region src/build/bundle-graph.ts
|
|
7
|
+
const SLOW_BUNDLE_TOTAL = 300 * 1024 / 8 * .5;
|
|
8
|
+
const SMALL_BUNDLE_TOTAL = 1e3;
|
|
9
|
+
function convertManifestToBundleGraph(manifest, bundleGraphAdders) {
|
|
10
|
+
const graph = bundleGraphRecords(manifest, bundleGraphAdders);
|
|
11
|
+
const dag = defDGraph(bundleGraphEdges(graph));
|
|
12
|
+
const reduced = dag.copy();
|
|
13
|
+
for (const name of dag.nodes()) for (const dep of dag.immediateDependencies(name)) for (const transitive of dag.transitiveDependencies(dep)) reduced.removeEdge(name, transitive);
|
|
14
|
+
const nodes = Object.keys(graph).sort().map((name) => {
|
|
15
|
+
const bundle = graph[name];
|
|
16
|
+
const dynamicImports = (bundle?.dynamicImports ?? []).map((dep) => [dep, dynamicImportMarker(bundle, graph[dep])]).sort((a, b) => a[1] - b[1] || a[0].localeCompare(b[0]));
|
|
17
|
+
const deps = [...reduced.immediateDependencies(name)].sort();
|
|
18
|
+
let lastMarker;
|
|
19
|
+
for (const [dep, marker] of dynamicImports) {
|
|
20
|
+
if (marker !== lastMarker) {
|
|
21
|
+
deps.push(marker);
|
|
22
|
+
lastMarker = marker;
|
|
23
|
+
}
|
|
24
|
+
deps.push(dep);
|
|
25
|
+
}
|
|
26
|
+
return [name, deps];
|
|
27
|
+
});
|
|
28
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
29
|
+
let index = 0;
|
|
30
|
+
for (const [name, deps] of nodes) {
|
|
31
|
+
indexes.set(name, index);
|
|
32
|
+
index += 1 + deps.length;
|
|
33
|
+
}
|
|
34
|
+
return nodes.flatMap(([name, deps]) => [name, ...deps.map((dep) => {
|
|
35
|
+
if (typeof dep === "number") return dep;
|
|
36
|
+
return indexes.get(dep);
|
|
37
|
+
})]);
|
|
38
|
+
}
|
|
39
|
+
function createPreloadGraphAdder(addEntries) {
|
|
40
|
+
return (manifest) => addEntries({
|
|
41
|
+
manifest,
|
|
42
|
+
hasBundle: (bundleName) => !!manifest.bundles[bundleName],
|
|
43
|
+
bundlesForOrigins: (origins) => bundlesForOrigins(manifest, origins)
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function bundlesForOrigins(manifest, origins) {
|
|
47
|
+
const normalizedOrigins = new Set(origins.map(normalizeManifestOrigin));
|
|
48
|
+
const bundles = [];
|
|
49
|
+
for (const [bundleName, bundle] of Object.entries(manifest.bundles)) if (bundle.origins?.some((origin) => normalizedOrigins.has(normalizeManifestOrigin(origin)))) bundles.push(bundleName);
|
|
50
|
+
return bundles.sort();
|
|
51
|
+
}
|
|
52
|
+
function bundleGraphRecords(manifest, bundleGraphAdders) {
|
|
53
|
+
const graph = { ...manifest.bundles };
|
|
54
|
+
const runtimeBundles = runtimeBundleNamesByModuleId(manifest);
|
|
55
|
+
for (const module of manifest.modules) {
|
|
56
|
+
const runtimeModuleIdsBySymbolId = new Map((module.runtimeDemandMap?.symbols ?? []).map((symbol) => [symbol.symbolId, symbol.runtimeModuleIds]));
|
|
57
|
+
for (const symbol of module.symbols) {
|
|
58
|
+
if (!symbol.fileName) continue;
|
|
59
|
+
const imports = [...manifest.bundles[symbol.fileName]?.imports ?? [], ...module.resolver.fileName ? [module.resolver.fileName] : []];
|
|
60
|
+
const runtimeDemandBundles = (runtimeModuleIdsBySymbolId.get(symbol.symbolId) ?? []).flatMap((id) => runtimeBundles.get(id) ?? []);
|
|
61
|
+
const symbolBundle = {
|
|
62
|
+
size: 0,
|
|
63
|
+
total: 0,
|
|
64
|
+
dynamicImports: [...new Set([symbol.fileName, ...runtimeDemandBundles])]
|
|
65
|
+
};
|
|
66
|
+
if (imports.length > 0) symbolBundle.imports = imports;
|
|
67
|
+
graph[symbol.symbolId] = symbolBundle;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (const [bundleName, bundle] of Object.entries(graph)) for (const symbolId of bundle.symbols ?? []) {
|
|
71
|
+
if (symbolId === bundleName) continue;
|
|
72
|
+
graph[symbolId] = appendDynamicImport(graph[symbolId] ?? {
|
|
73
|
+
size: 0,
|
|
74
|
+
total: 0
|
|
75
|
+
}, bundleName);
|
|
76
|
+
}
|
|
77
|
+
if (bundleGraphAdders) {
|
|
78
|
+
const combined = {
|
|
79
|
+
...manifest,
|
|
80
|
+
bundles: graph
|
|
81
|
+
};
|
|
82
|
+
for (const add of bundleGraphAdders) Object.assign(graph, add(combined));
|
|
83
|
+
}
|
|
84
|
+
for (const bundleName of Object.keys(graph)) {
|
|
85
|
+
const bundle = graph[bundleName];
|
|
86
|
+
if (!bundle) continue;
|
|
87
|
+
graph[bundleName] = {
|
|
88
|
+
...bundle,
|
|
89
|
+
imports: bundle.imports?.filter((dep) => graph[dep]) ?? [],
|
|
90
|
+
dynamicImports: bundle.dynamicImports?.filter((dep) => graph[dep]) ?? []
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const used = /* @__PURE__ */ new Set();
|
|
94
|
+
for (const bundle of Object.values(graph)) {
|
|
95
|
+
for (const dep of bundle.imports ?? []) used.add(dep);
|
|
96
|
+
for (const dep of bundle.dynamicImports ?? []) used.add(dep);
|
|
97
|
+
}
|
|
98
|
+
for (const [bundleName, bundle] of Object.entries(graph)) if (!used.has(bundleName) && !bundle.imports?.length && !bundle.dynamicImports?.length) delete graph[bundleName];
|
|
99
|
+
return graph;
|
|
100
|
+
}
|
|
101
|
+
function appendDynamicImport(bundle, dependency) {
|
|
102
|
+
if (bundle.dynamicImports?.includes(dependency)) return bundle;
|
|
103
|
+
return {
|
|
104
|
+
...bundle,
|
|
105
|
+
dynamicImports: [...bundle.dynamicImports ?? [], dependency]
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function runtimeBundleNamesByModuleId(manifest) {
|
|
109
|
+
const entries = /* @__PURE__ */ new Map();
|
|
110
|
+
for (const [bundleName, bundle] of Object.entries(manifest.bundles)) for (const origin of bundle.origins ?? []) {
|
|
111
|
+
const runtimeModuleId = runtimeModuleIdFromOrigin(origin);
|
|
112
|
+
if (!runtimeModuleId) continue;
|
|
113
|
+
entries.set(runtimeModuleId, [...entries.get(runtimeModuleId) ?? [], bundleName]);
|
|
114
|
+
}
|
|
115
|
+
for (const [id, names] of entries) entries.set(id, names.sort());
|
|
116
|
+
return entries;
|
|
117
|
+
}
|
|
118
|
+
function runtimeModuleIdFromOrigin(origin) {
|
|
119
|
+
const normalized = normalizeManifestOrigin(origin);
|
|
120
|
+
for (const [prefix, marker] of [["web", "packages/web/src/"], ["core", "packages/core/src/"]]) {
|
|
121
|
+
const index = normalized.lastIndexOf(marker);
|
|
122
|
+
if (index === -1 || !normalized.endsWith(".ts")) continue;
|
|
123
|
+
return `${prefix}/${normalized.slice(index + marker.length, -3)}`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function dynamicImportMarker(bundle, dependency) {
|
|
127
|
+
let probability = .5;
|
|
128
|
+
if (hasRelatedOrigin(bundle, dependency)) probability += .25;
|
|
129
|
+
if ((dependency?.total ?? 0) > SLOW_BUNDLE_TOTAL) if (probability > .5) probability += .02;
|
|
130
|
+
else probability -= .02;
|
|
131
|
+
if ((dependency?.total ?? 0) < SMALL_BUNDLE_TOTAL) probability += .15;
|
|
132
|
+
probability = Math.min(probability, .99);
|
|
133
|
+
return -Math.round(probability * 10);
|
|
134
|
+
}
|
|
135
|
+
function hasRelatedOrigin(bundle, dependency) {
|
|
136
|
+
return !!bundle?.origins?.some((origin) => dependency?.origins?.some((depOrigin) => depOrigin.startsWith(origin)));
|
|
137
|
+
}
|
|
138
|
+
function* bundleGraphEdges(graph) {
|
|
139
|
+
for (const [bundleName, bundle] of Object.entries(graph)) {
|
|
140
|
+
yield [bundleName, null];
|
|
141
|
+
for (const dep of bundle.imports ?? []) yield [bundleName, dep];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function normalizeManifestOrigin(origin) {
|
|
145
|
+
return withoutLeadingSlash(normalize(origin));
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/build/dynamic-import-scan.ts
|
|
149
|
+
function scanEmittedDynamicImports(code, chunkFileName) {
|
|
150
|
+
if (!code.includes("import(")) return [];
|
|
151
|
+
let ast;
|
|
152
|
+
try {
|
|
153
|
+
ast = parseJavaScriptModule(code);
|
|
154
|
+
} catch {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
const specifiers = /* @__PURE__ */ new Set();
|
|
158
|
+
const visit = (node) => {
|
|
159
|
+
if (!node || typeof node !== "object") return;
|
|
160
|
+
if (node.type === "ImportExpression") {
|
|
161
|
+
const specifier = staticSpecifier(node.source ?? node.arguments);
|
|
162
|
+
if (specifier?.startsWith(".")) specifiers.add(join(dirname(chunkFileName), specifier));
|
|
163
|
+
}
|
|
164
|
+
for (const child of childNodes$1(node)) visit(child);
|
|
165
|
+
};
|
|
166
|
+
visit(ast);
|
|
167
|
+
return [...specifiers];
|
|
168
|
+
}
|
|
169
|
+
function staticSpecifier(source) {
|
|
170
|
+
const node = Array.isArray(source) ? source[0] : source;
|
|
171
|
+
if (!node || typeof node !== "object") return void 0;
|
|
172
|
+
const astNode = node;
|
|
173
|
+
if (astNode.type === "Literal" || astNode.type === "StringLiteral") return typeof astNode.value === "string" ? astNode.value : void 0;
|
|
174
|
+
if (astNode.type === "TemplateLiteral" && (astNode.expressions ?? []).length === 0) {
|
|
175
|
+
const quasi = astNode.quasis?.[0];
|
|
176
|
+
return quasi?.value?.cooked ?? quasi?.cooked;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function childNodes$1(node) {
|
|
180
|
+
const children = [];
|
|
181
|
+
for (const [key, value] of Object.entries(node)) {
|
|
182
|
+
if (key === "loc" || key === "span" || key === "range") continue;
|
|
183
|
+
if (Array.isArray(value)) {
|
|
184
|
+
for (const item of value) if (isAstNode$1(item)) children.push(item);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (isAstNode$1(value)) children.push(value);
|
|
188
|
+
}
|
|
189
|
+
return children;
|
|
190
|
+
}
|
|
191
|
+
function isAstNode$1(value) {
|
|
192
|
+
return !!value && typeof value === "object" && "type" in value;
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/build/head-links.ts
|
|
196
|
+
const STYLESHEET_ASSET_RE = /\.css$/;
|
|
197
|
+
function collectHeadLinkInjections(bundle, options = {}) {
|
|
198
|
+
const publicPath = options.publicPath ?? ((fileName) => fileName);
|
|
199
|
+
const stylesheetFiles = stylesheetFilesFromViteMetadata(bundle);
|
|
200
|
+
if (stylesheetFiles.size === 0) {
|
|
201
|
+
for (const item of Object.values(bundle)) if (item.type === "asset" && STYLESHEET_ASSET_RE.test(item.fileName)) stylesheetFiles.add(item.fileName);
|
|
202
|
+
}
|
|
203
|
+
return [...stylesheetFiles].sort().map((fileName) => stylesheetInjection(publicPath(fileName)));
|
|
204
|
+
}
|
|
205
|
+
function stylesheetFilesFromViteMetadata(bundle) {
|
|
206
|
+
const stylesheetFiles = /* @__PURE__ */ new Set();
|
|
207
|
+
for (const item of Object.values(bundle)) {
|
|
208
|
+
if (item.type !== "chunk") continue;
|
|
209
|
+
for (const fileName of item.viteMetadata?.importedCss ?? []) stylesheetFiles.add(fileName);
|
|
210
|
+
}
|
|
211
|
+
return stylesheetFiles;
|
|
212
|
+
}
|
|
213
|
+
function collectModulePreloadInjections(preloadSource, options = {}) {
|
|
214
|
+
const buildMetadata = isBuildMetadata(preloadSource) ? preloadSource : void 0;
|
|
215
|
+
const bundleGraph = buildMetadata ? buildMetadata.bundleGraph : preloadSource;
|
|
216
|
+
const roots = [...buildMetadata ? symbolRootsFromBuildMetadata(buildMetadata) : (bundleGraph ?? []).filter((name) => typeof name === "string" && name.startsWith("symbol:")).map((name) => ({
|
|
217
|
+
name,
|
|
218
|
+
priority: "high"
|
|
219
|
+
})), ...(options.entryChunks ?? []).map((name) => ({
|
|
220
|
+
name,
|
|
221
|
+
priority: "auto",
|
|
222
|
+
edges: "dynamic-only"
|
|
223
|
+
}))];
|
|
224
|
+
return planModulePreloads({
|
|
225
|
+
base: options.publicPath ? options.publicPath(MARKLESS_BUILD_PREFIX) : joinURL("/", MARKLESS_BUILD_PREFIX),
|
|
226
|
+
bundleGraph,
|
|
227
|
+
roots
|
|
228
|
+
}).map(modulePreloadInjection);
|
|
229
|
+
}
|
|
230
|
+
function symbolRootsFromBuildMetadata(metadata) {
|
|
231
|
+
const roots = [];
|
|
232
|
+
const seen = /* @__PURE__ */ new Set();
|
|
233
|
+
for (const module of metadata.modules) for (const symbol of module.symbols) {
|
|
234
|
+
if (!symbol.fileName || seen.has(symbol.symbolId)) continue;
|
|
235
|
+
seen.add(symbol.symbolId);
|
|
236
|
+
roots.push({
|
|
237
|
+
name: symbol.symbolId,
|
|
238
|
+
priority: "high"
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return roots;
|
|
242
|
+
}
|
|
243
|
+
function isBuildMetadata(value) {
|
|
244
|
+
return !!value && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.modules);
|
|
245
|
+
}
|
|
246
|
+
function injectHeadLinks(bundle, injections) {
|
|
247
|
+
if (injections.length === 0) return;
|
|
248
|
+
const links = injections.map(headLinkTag).join("");
|
|
249
|
+
for (const output of Object.values(bundle)) {
|
|
250
|
+
if (!isHtmlAssetWithSource(output)) continue;
|
|
251
|
+
output.source = output.source.includes("</head>") ? output.source.replace("</head>", `${links}</head>`) : `${links}${output.source}`;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function headLinkTag(injection) {
|
|
255
|
+
const attributes = Object.entries(injection.attributes ?? {}).map(([name, value]) => `${name}="${value.replaceAll("\"", """)}"`);
|
|
256
|
+
const open = attributes.length > 0 ? `<${injection.tag} ${attributes.join(" ")}>` : `<${injection.tag}>`;
|
|
257
|
+
return injection.children === void 0 ? open : `${open}${injection.children}</${injection.tag}>`;
|
|
258
|
+
}
|
|
259
|
+
function isHtmlAssetWithSource(output) {
|
|
260
|
+
if (!output || typeof output !== "object") return false;
|
|
261
|
+
const asset = output;
|
|
262
|
+
return asset.type === "asset" && typeof asset.fileName === "string" && asset.fileName.endsWith(".html") && typeof asset.source === "string";
|
|
263
|
+
}
|
|
264
|
+
function modulePreloadInjection(preload) {
|
|
265
|
+
const attributes = {
|
|
266
|
+
rel: "modulepreload",
|
|
267
|
+
href: preload.href,
|
|
268
|
+
crossorigin: "anonymous"
|
|
269
|
+
};
|
|
270
|
+
if (preload.fetchPriority && preload.fetchPriority !== "auto") attributes.fetchpriority = preload.fetchPriority;
|
|
271
|
+
return {
|
|
272
|
+
tag: "link",
|
|
273
|
+
location: "head",
|
|
274
|
+
attributes
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function stylesheetInjection(href) {
|
|
278
|
+
return {
|
|
279
|
+
tag: "link",
|
|
280
|
+
location: "head",
|
|
281
|
+
attributes: {
|
|
282
|
+
rel: "stylesheet",
|
|
283
|
+
href
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/build/build-metadata.ts
|
|
289
|
+
function createBuildMetadata(bundle, transformManifests, root, options = {}) {
|
|
290
|
+
const canonPath = options.canonPath ?? ((fileName) => fileName);
|
|
291
|
+
const publicPath = options.publicPath ?? ((fileName) => fileName);
|
|
292
|
+
const modules = [...transformManifests].map(cloneTransformManifest);
|
|
293
|
+
const metadata = {
|
|
294
|
+
version: 1,
|
|
295
|
+
modules,
|
|
296
|
+
bundles: {},
|
|
297
|
+
assets: {},
|
|
298
|
+
injections: [...options.injections ?? [], ...collectHeadLinkInjections(bundle, { publicPath })]
|
|
299
|
+
};
|
|
300
|
+
for (const item of Object.values(bundle)) {
|
|
301
|
+
if (item.type === "asset") {
|
|
302
|
+
if (item.fileName.endsWith(".js.map")) continue;
|
|
303
|
+
metadata.assets[item.fileName] = assetInfo(item);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
const bundleFileName = canonPath(item.fileName);
|
|
307
|
+
const origins = getOrigins(item, root);
|
|
308
|
+
const asyncBundle = {
|
|
309
|
+
size: item.code.length,
|
|
310
|
+
total: item.code.length
|
|
311
|
+
};
|
|
312
|
+
const imports = mapBundleNames(bundle, item.imports, canonPath);
|
|
313
|
+
if (imports.length > 0) asyncBundle.imports = imports;
|
|
314
|
+
const dynamicImports = [...new Set([...mapBundleNames(bundle, item.dynamicImports, canonPath), ...mapBundleNames(bundle, scanEmittedDynamicImports(item.code, item.fileName), canonPath)])];
|
|
315
|
+
if (dynamicImports.length > 0) asyncBundle.dynamicImports = dynamicImports;
|
|
316
|
+
if (origins.length > 0) asyncBundle.origins = origins;
|
|
317
|
+
finalizeVirtualModuleReferences(modules, item, bundleFileName);
|
|
318
|
+
const symbols = modules.flatMap((module) => module.symbols.filter((symbol) => symbol.fileName === bundleFileName).map((symbol) => symbol.symbolId));
|
|
319
|
+
if (symbols.length > 0) asyncBundle.symbols = symbols;
|
|
320
|
+
metadata.bundles[bundleFileName] = asyncBundle;
|
|
321
|
+
}
|
|
322
|
+
computeTotals(metadata.bundles);
|
|
323
|
+
sortBuildMetadata(metadata);
|
|
324
|
+
if (options.bundleGraphAsset) {
|
|
325
|
+
metadata.bundleGraph = convertManifestToBundleGraph(metadata, options.bundleGraphAdders);
|
|
326
|
+
metadata.bundleGraphAsset = options.bundleGraphAsset;
|
|
327
|
+
metadata.assets[options.bundleGraphAsset] = {
|
|
328
|
+
name: "bundle-graph.json",
|
|
329
|
+
size: JSON.stringify(metadata.bundleGraph).length
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
return metadata;
|
|
333
|
+
}
|
|
334
|
+
function cloneTransformManifest(manifest) {
|
|
335
|
+
return {
|
|
336
|
+
source: manifest.source,
|
|
337
|
+
payload: { ...manifest.payload },
|
|
338
|
+
resolver: { ...manifest.resolver },
|
|
339
|
+
symbols: manifest.symbols.map((symbol) => ({ ...symbol })),
|
|
340
|
+
runtimeDemandMap: manifest.runtimeDemandMap
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function finalizeVirtualModuleReferences(modules, item, bundleFileName) {
|
|
344
|
+
const ids = new Set([item.facadeModuleId ?? void 0, ...item.moduleIds].filter((id) => !!id).map(normalizeVirtualModuleId));
|
|
345
|
+
for (const module of modules) {
|
|
346
|
+
for (const reference of [module.payload, module.resolver]) if (ids.has(normalizeVirtualModuleId(reference.virtualModuleId))) reference.fileName = bundleFileName;
|
|
347
|
+
for (const symbol of module.symbols) if (ids.has(normalizeVirtualModuleId(symbol.virtualModuleId))) symbol.fileName = bundleFileName;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function normalizeVirtualModuleId(id) {
|
|
351
|
+
if (id.startsWith("\0")) return id.slice(1);
|
|
352
|
+
return id;
|
|
353
|
+
}
|
|
354
|
+
function assetInfo(item) {
|
|
355
|
+
return {
|
|
356
|
+
name: item.names?.[0] ?? item.name,
|
|
357
|
+
size: item.source.length
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function mapBundleNames(bundle, names, canonPath) {
|
|
361
|
+
return names.flatMap((name) => {
|
|
362
|
+
const item = bundle[name];
|
|
363
|
+
if (item) return [canonPath(item.fileName)];
|
|
364
|
+
return [canonPath(name)];
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
function getOrigins(item, root) {
|
|
368
|
+
return item.moduleIds.filter((id) => !id.startsWith("\0")).map((id) => {
|
|
369
|
+
if (root) return relative(root, id);
|
|
370
|
+
return id;
|
|
371
|
+
}).sort();
|
|
372
|
+
}
|
|
373
|
+
function computeTotals(bundles) {
|
|
374
|
+
const collect = (name, seen) => {
|
|
375
|
+
const bundle = bundles[name];
|
|
376
|
+
if (!bundle || seen.has(name)) return;
|
|
377
|
+
seen.add(name);
|
|
378
|
+
for (const dep of bundle.imports ?? []) collect(dep, seen);
|
|
379
|
+
};
|
|
380
|
+
for (const name of Object.keys(bundles)) {
|
|
381
|
+
const seen = /* @__PURE__ */ new Set();
|
|
382
|
+
collect(name, seen);
|
|
383
|
+
bundles[name].total = [...seen].reduce((sum, dep) => sum + (bundles[dep]?.size ?? 0), 0);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function sortBuildMetadata(metadata) {
|
|
387
|
+
metadata.modules = metadata.modules.sort((a, b) => a.source.localeCompare(b.source));
|
|
388
|
+
metadata.bundles = sortRecord(metadata.bundles);
|
|
389
|
+
metadata.assets = sortRecord(metadata.assets ?? {});
|
|
390
|
+
metadata.injections?.sort((a, b) => injectionKey(a).localeCompare(injectionKey(b)));
|
|
391
|
+
for (const bundle of Object.values(metadata.bundles)) {
|
|
392
|
+
bundle.imports?.sort();
|
|
393
|
+
bundle.dynamicImports?.sort();
|
|
394
|
+
bundle.origins?.sort();
|
|
395
|
+
bundle.symbols?.sort();
|
|
396
|
+
}
|
|
397
|
+
for (const module of metadata.modules) module.symbols.sort((a, b) => a.symbolId.localeCompare(b.symbolId));
|
|
398
|
+
}
|
|
399
|
+
function sortRecord(record) {
|
|
400
|
+
const next = {};
|
|
401
|
+
for (const key of Object.keys(record).sort()) {
|
|
402
|
+
const value = record[key];
|
|
403
|
+
if (value !== void 0) next[key] = value;
|
|
404
|
+
}
|
|
405
|
+
return next;
|
|
406
|
+
}
|
|
407
|
+
function injectionKey(injection) {
|
|
408
|
+
return `${injection.location}:${injection.tag}:${injection.attributes?.href ?? ""}`;
|
|
409
|
+
}
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/build/preload-cleanup.ts
|
|
412
|
+
function stripEmptyVitePreloadWrappers(code) {
|
|
413
|
+
return stripImportedVitePreloadHelper(stripUnusedVitePreloadHelper(stripAsyncEmptyPreloadWrappers(stripDirectEmptyPreloadWrappers(code))));
|
|
414
|
+
}
|
|
415
|
+
const IMPORT_DECLARATION_CANDIDATE_RE = /\bimport\s*\{[\s\S]*?\}\s*from\s*["'][^"']+["'];?/g;
|
|
416
|
+
function stripDirectEmptyPreloadWrappers(code) {
|
|
417
|
+
let next = "";
|
|
418
|
+
let cursor = 0;
|
|
419
|
+
let changed = false;
|
|
420
|
+
const wrapperRE = /\b[$A-Z_a-z][$\w]*\(\(\)\s*=>\s*/g;
|
|
421
|
+
for (let match = wrapperRE.exec(code); match; match = wrapperRE.exec(code)) {
|
|
422
|
+
const callStart = match.index;
|
|
423
|
+
const bodyStart = match.index + match[0].length;
|
|
424
|
+
if (!code.startsWith("import(", bodyStart)) continue;
|
|
425
|
+
const wrapper = findEmptyPreloadWrapper(code, callStart, bodyStart);
|
|
426
|
+
if (!wrapper) continue;
|
|
427
|
+
next += code.slice(cursor, callStart);
|
|
428
|
+
next += code.slice(bodyStart, wrapper.firstArgumentEnd);
|
|
429
|
+
cursor = wrapper.callEnd + 1;
|
|
430
|
+
wrapperRE.lastIndex = cursor;
|
|
431
|
+
changed = true;
|
|
432
|
+
}
|
|
433
|
+
if (!changed) return code;
|
|
434
|
+
return next + code.slice(cursor);
|
|
435
|
+
}
|
|
436
|
+
function stripAsyncEmptyPreloadWrappers(code) {
|
|
437
|
+
let next = "";
|
|
438
|
+
let cursor = 0;
|
|
439
|
+
let changed = false;
|
|
440
|
+
const wrapperRE = /\b[$A-Z_a-z][$\w]*\(\s*async\s*\(\)\s*=>\s*\{/g;
|
|
441
|
+
for (let match = wrapperRE.exec(code); match; match = wrapperRE.exec(code)) {
|
|
442
|
+
const callStart = match.index;
|
|
443
|
+
const callOpen = code.indexOf("(", callStart);
|
|
444
|
+
if (callOpen < 0) continue;
|
|
445
|
+
const firstArgumentEnd = findTopLevelComma(code, callOpen + 1);
|
|
446
|
+
if (firstArgumentEnd < 0) continue;
|
|
447
|
+
const wrapper = findEmptyPreloadWrapper(code, callStart, callOpen + 1);
|
|
448
|
+
if (!wrapper) continue;
|
|
449
|
+
const loader = code.slice(callOpen + 1, firstArgumentEnd);
|
|
450
|
+
next += code.slice(cursor, callStart);
|
|
451
|
+
next += `(${loader})()`;
|
|
452
|
+
cursor = wrapper.callEnd + 1;
|
|
453
|
+
wrapperRE.lastIndex = cursor;
|
|
454
|
+
changed = true;
|
|
455
|
+
}
|
|
456
|
+
if (!changed) return code;
|
|
457
|
+
return next + code.slice(cursor);
|
|
458
|
+
}
|
|
459
|
+
function findEmptyPreloadWrapper(code, callStart, bodyStart) {
|
|
460
|
+
const callOpen = code.indexOf("(", callStart);
|
|
461
|
+
if (callOpen < 0 || callOpen >= bodyStart) return void 0;
|
|
462
|
+
const firstArgumentEnd = findTopLevelComma(code, callOpen + 1);
|
|
463
|
+
if (firstArgumentEnd < 0) return void 0;
|
|
464
|
+
let cursor = skipSpaces(code, firstArgumentEnd + 1);
|
|
465
|
+
if (code[cursor] !== "[" || code[cursor + 1] !== "]") return void 0;
|
|
466
|
+
cursor = skipSpaces(code, cursor + 2);
|
|
467
|
+
if (code[cursor] === ")") return {
|
|
468
|
+
firstArgumentEnd,
|
|
469
|
+
callEnd: cursor
|
|
470
|
+
};
|
|
471
|
+
if (code[cursor] !== ",") return void 0;
|
|
472
|
+
cursor = skipSpaces(code, cursor + 1);
|
|
473
|
+
if (!code.startsWith("import.meta.url", cursor)) return void 0;
|
|
474
|
+
cursor = skipSpaces(code, cursor + 15);
|
|
475
|
+
if (code[cursor] !== ")") return void 0;
|
|
476
|
+
return {
|
|
477
|
+
firstArgumentEnd,
|
|
478
|
+
callEnd: cursor
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
function findTopLevelComma(code, start) {
|
|
482
|
+
let depth = 1;
|
|
483
|
+
let quote = null;
|
|
484
|
+
let escaped = false;
|
|
485
|
+
for (let index = start; index < code.length; index++) {
|
|
486
|
+
const char = code[index];
|
|
487
|
+
if (quote) {
|
|
488
|
+
if (escaped) {
|
|
489
|
+
escaped = false;
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
if (char === "\\") {
|
|
493
|
+
escaped = true;
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
if (char === quote) quote = null;
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
if (char === "\"" || char === "'" || char === "`") {
|
|
500
|
+
quote = char;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (char === "(" || char === "[" || char === "{") {
|
|
504
|
+
depth++;
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
if (char === ")" || char === "]" || char === "}") {
|
|
508
|
+
depth--;
|
|
509
|
+
if (depth === 0) return -1;
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
if (char === "," && depth === 1) return index;
|
|
513
|
+
}
|
|
514
|
+
return -1;
|
|
515
|
+
}
|
|
516
|
+
function skipSpaces(code, start) {
|
|
517
|
+
let cursor = start;
|
|
518
|
+
while (/\s/.test(code[cursor] ?? "")) cursor++;
|
|
519
|
+
return cursor;
|
|
520
|
+
}
|
|
521
|
+
function stripImportedVitePreloadHelper(code) {
|
|
522
|
+
const helper = findImportedVitePreloadHelper(code);
|
|
523
|
+
if (!helper) return code;
|
|
524
|
+
const withoutImport = code.slice(0, helper.importStart) + code.slice(helper.importEnd);
|
|
525
|
+
if (hasCallableReference(withoutImport, helper.preloadFunction)) return code;
|
|
526
|
+
const initCall = `${escapeRegExp$1(helper.initFunction)}\\(\\)`;
|
|
527
|
+
return withoutImport.replace(new RegExp(String.raw`,${initCall},`, "g"), ",").replace(new RegExp(String.raw`\{${initCall},`, "g"), "{").replace(new RegExp(String.raw`,${initCall},`, "g"), ",").replace(new RegExp(String.raw`,${initCall}\}`, "g"), "}").replace(new RegExp(String.raw`\{${initCall}\}`, "g"), "{}");
|
|
528
|
+
}
|
|
529
|
+
function findImportedVitePreloadHelper(code) {
|
|
530
|
+
for (const match of code.matchAll(IMPORT_DECLARATION_CANDIDATE_RE)) {
|
|
531
|
+
const importStart = match.index ?? -1;
|
|
532
|
+
if (importStart < 0) continue;
|
|
533
|
+
const statement = match[0];
|
|
534
|
+
const declaration = asNodes(tryParseJavaScriptModule(statement)?.body).find((node) => node.type === "ImportDeclaration");
|
|
535
|
+
if (!declaration) continue;
|
|
536
|
+
let preloadFunction;
|
|
537
|
+
let initFunction;
|
|
538
|
+
for (const specifier of asNodes(declaration.specifiers)) {
|
|
539
|
+
if (specifier.type !== "ImportSpecifier") continue;
|
|
540
|
+
const imported = identifierName(specifier.imported);
|
|
541
|
+
const local = identifierName(specifier.local);
|
|
542
|
+
if (!imported || !local) continue;
|
|
543
|
+
if (imported === "__vitePreload") preloadFunction = local;
|
|
544
|
+
if (imported === "init_preload_helper") initFunction = local;
|
|
545
|
+
}
|
|
546
|
+
if (preloadFunction && initFunction) return {
|
|
547
|
+
importStart,
|
|
548
|
+
importEnd: importStart + statement.length,
|
|
549
|
+
preloadFunction,
|
|
550
|
+
initFunction
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function stripUnusedVitePreloadHelper(code) {
|
|
555
|
+
const marker = code.indexOf("vite:preloadError");
|
|
556
|
+
if (marker < 0) return code;
|
|
557
|
+
const helper = findVitePreloadHelperModule(code, marker);
|
|
558
|
+
if (!helper) return code;
|
|
559
|
+
const statementEnd = code[helper.removeStart] === "," && code[helper.removeEnd - 1] === ";" ? ";" : "";
|
|
560
|
+
const outsideHelper = code.slice(0, helper.removeStart) + statementEnd + code.slice(helper.removeEnd);
|
|
561
|
+
if (hasCallableReference(outsideHelper, helper.preloadFunction)) return code;
|
|
562
|
+
let withoutHelper = outsideHelper;
|
|
563
|
+
const chain = findVitePreloadHelperInitChain(withoutHelper, helper.moduleVariable);
|
|
564
|
+
if (chain) withoutHelper = removeInitCall(withoutHelper.slice(0, chain.removeStart) + withoutHelper.slice(chain.removeEnd), chain.entryVariable);
|
|
565
|
+
return removeInitCall(withoutHelper, helper.moduleVariable);
|
|
566
|
+
}
|
|
567
|
+
function findVitePreloadHelperModule(code, marker) {
|
|
568
|
+
const initStart = code.lastIndexOf("=e((()=>{", marker);
|
|
569
|
+
if (initStart < 0) return void 0;
|
|
570
|
+
const moduleVariable = readIdentifierBefore(code, initStart);
|
|
571
|
+
if (!moduleVariable) return void 0;
|
|
572
|
+
const bodyStart = initStart + 9;
|
|
573
|
+
const bodyEnd = findModuleInitEnd(code, initStart);
|
|
574
|
+
if (bodyEnd < 0) return void 0;
|
|
575
|
+
const helperBody = code.slice(bodyStart, bodyEnd);
|
|
576
|
+
const preloadFunction = helperBody.match(/,([$A-Z_a-z][$\w]*)=function\([^)]*\)\{let\s+[$A-Z_a-z][$\w]*=Promise\.resolve\(\)/)?.[1];
|
|
577
|
+
if (!preloadFunction) return void 0;
|
|
578
|
+
const firstHelperVariable = helperBody.match(/^([$A-Z_a-z][$\w]*)=/)?.[1];
|
|
579
|
+
if (!firstHelperVariable) return void 0;
|
|
580
|
+
const removeStart = findHelperDeclarationStart(code, initStart, firstHelperVariable);
|
|
581
|
+
if (removeStart < 0) return void 0;
|
|
582
|
+
return {
|
|
583
|
+
moduleVariable,
|
|
584
|
+
preloadFunction,
|
|
585
|
+
removeStart,
|
|
586
|
+
removeEnd: bodyEnd + 4
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function findVitePreloadHelperInitChain(code, moduleVariable) {
|
|
590
|
+
const match = new RegExp(`var\\s+([$A-Z_a-z][$\\w]*)=e\\(\\(\\(\\)=>\\{${escapeRegExp$1(moduleVariable)}\\(\\)\\}\\)\\),([$A-Z_a-z][$\\w]*)=e\\(\\(\\(\\)=>\\{\\1\\(\\)\\}\\)\\);`).exec(code);
|
|
591
|
+
if (!match) return void 0;
|
|
592
|
+
return {
|
|
593
|
+
entryVariable: match[2],
|
|
594
|
+
removeStart: match.index,
|
|
595
|
+
removeEnd: match.index + match[0].length
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
function removeInitCall(code, entryVariable) {
|
|
599
|
+
return code.replace(new RegExp(`,${escapeRegExp$1(entryVariable)}\\(\\)`), "").replace(new RegExp(`${escapeRegExp$1(entryVariable)}\\(\\),`), "").replace(new RegExp(`\\{${escapeRegExp$1(entryVariable)}\\(\\)\\}`), "{}");
|
|
600
|
+
}
|
|
601
|
+
function readIdentifierBefore(code, index) {
|
|
602
|
+
let end = index;
|
|
603
|
+
while (/\s/.test(code[end - 1] ?? "")) end--;
|
|
604
|
+
let start = end;
|
|
605
|
+
while (/[$\w]/.test(code[start - 1] ?? "")) start--;
|
|
606
|
+
const value = code.slice(start, end);
|
|
607
|
+
return /^[$A-Z_a-z][$\w]*$/.test(value) ? value : void 0;
|
|
608
|
+
}
|
|
609
|
+
function findModuleInitEnd(code, initStart) {
|
|
610
|
+
return code.indexOf("}));", initStart);
|
|
611
|
+
}
|
|
612
|
+
function findHelperDeclarationStart(code, initStart, firstHelperVariable) {
|
|
613
|
+
const commaStart = code.lastIndexOf(`,${firstHelperVariable},`, initStart);
|
|
614
|
+
if (commaStart >= 0) return commaStart;
|
|
615
|
+
const varStart = code.lastIndexOf(`var ${firstHelperVariable},`, initStart);
|
|
616
|
+
if (varStart >= 0) return varStart;
|
|
617
|
+
return -1;
|
|
618
|
+
}
|
|
619
|
+
function escapeRegExp$1(value) {
|
|
620
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
621
|
+
}
|
|
622
|
+
function hasCallableReference(code, name) {
|
|
623
|
+
const ast = tryParseJavaScriptModule(code);
|
|
624
|
+
if (!ast) return true;
|
|
625
|
+
let found = false;
|
|
626
|
+
walkReferenceScopes(ast, [], (node, scopes) => {
|
|
627
|
+
if (node.type !== "CallExpression") return;
|
|
628
|
+
const callee = node.callee;
|
|
629
|
+
if (identifierName(callee) !== name) return;
|
|
630
|
+
if (isDeclaredInScope(name, scopes)) return;
|
|
631
|
+
found = true;
|
|
632
|
+
});
|
|
633
|
+
return found;
|
|
634
|
+
}
|
|
635
|
+
function walkReferenceScopes(node, scopes, visit) {
|
|
636
|
+
if (!node || typeof node !== "object") return;
|
|
637
|
+
if (node.type === "Program") {
|
|
638
|
+
const scope = collectScopeDeclarations(asNodes(node.body));
|
|
639
|
+
visit(node, [scope]);
|
|
640
|
+
for (const child of asNodes(node.body)) walkReferenceScopes(child, [scope], visit);
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
if (isFunctionNode(node)) {
|
|
644
|
+
const scope = /* @__PURE__ */ new Set();
|
|
645
|
+
collectBindingNames(node.id, scope);
|
|
646
|
+
for (const parameter of asNodes(node.params)) collectBindingNames(parameter, scope);
|
|
647
|
+
const nextScopes = [...scopes, scope];
|
|
648
|
+
visit(node, nextScopes);
|
|
649
|
+
walkReferenceScopes(node.body, nextScopes, visit);
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
if (node.type === "BlockStatement") {
|
|
653
|
+
const scope = collectScopeDeclarations(asNodes(node.body));
|
|
654
|
+
const nextScopes = [...scopes, scope];
|
|
655
|
+
visit(node, nextScopes);
|
|
656
|
+
for (const child of asNodes(node.body)) walkReferenceScopes(child, nextScopes, visit);
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
visit(node, scopes);
|
|
660
|
+
for (const child of childNodes(node)) walkReferenceScopes(child, scopes, visit);
|
|
661
|
+
}
|
|
662
|
+
function collectScopeDeclarations(nodes) {
|
|
663
|
+
const declarations = /* @__PURE__ */ new Set();
|
|
664
|
+
for (const node of nodes) {
|
|
665
|
+
if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") {
|
|
666
|
+
collectBindingNames(node.id, declarations);
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
if (node.type === "ImportDeclaration") {
|
|
670
|
+
for (const specifier of asNodes(node.specifiers)) collectBindingNames(specifier.local, declarations);
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
if (node.type === "VariableDeclaration") for (const declaration of asNodes(node.declarations)) collectBindingNames(declaration.id, declarations);
|
|
674
|
+
}
|
|
675
|
+
return declarations;
|
|
676
|
+
}
|
|
677
|
+
function collectBindingNames(node, names) {
|
|
678
|
+
if (!node) return;
|
|
679
|
+
const name = identifierName(node);
|
|
680
|
+
if (name) {
|
|
681
|
+
names.add(name);
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
for (const child of childNodes(node)) collectBindingNames(child, names);
|
|
685
|
+
}
|
|
686
|
+
function isDeclaredInScope(name, scopes) {
|
|
687
|
+
return scopes.some((scope) => scope.has(name));
|
|
688
|
+
}
|
|
689
|
+
function isFunctionNode(node) {
|
|
690
|
+
return node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
|
|
691
|
+
}
|
|
692
|
+
function tryParseJavaScriptModule(code) {
|
|
693
|
+
try {
|
|
694
|
+
return parseJavaScriptModule(code);
|
|
695
|
+
} catch {
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
function childNodes(node) {
|
|
700
|
+
const children = [];
|
|
701
|
+
for (const [key, value] of Object.entries(node)) {
|
|
702
|
+
if (ignoredAstKeys.has(key)) continue;
|
|
703
|
+
if (Array.isArray(value)) {
|
|
704
|
+
for (const item of value) if (isAstNode(item)) children.push(item);
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
if (isAstNode(value)) children.push(value);
|
|
708
|
+
}
|
|
709
|
+
return children;
|
|
710
|
+
}
|
|
711
|
+
function asNodes(value) {
|
|
712
|
+
return Array.isArray(value) ? value.filter(isAstNode) : [];
|
|
713
|
+
}
|
|
714
|
+
function isAstNode(value) {
|
|
715
|
+
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
716
|
+
}
|
|
717
|
+
function identifierName(node) {
|
|
718
|
+
return node?.type === "Identifier" && typeof node.name === "string" ? node.name : void 0;
|
|
719
|
+
}
|
|
720
|
+
const ignoredAstKeys = new Set([
|
|
721
|
+
"closingElement",
|
|
722
|
+
"id",
|
|
723
|
+
"leadingComments",
|
|
724
|
+
"loc",
|
|
725
|
+
"metadata",
|
|
726
|
+
"openingElement",
|
|
727
|
+
"parent",
|
|
728
|
+
"range",
|
|
729
|
+
"trailingComments"
|
|
730
|
+
]);
|
|
731
|
+
//#endregion
|
|
732
|
+
//#region src/build/symbol-facade-cleanup.ts
|
|
733
|
+
const TSRX_SOURCE_FILE$1 = /\.tsrx(?:[?#].*)?$/;
|
|
734
|
+
const SYMBOL_INIT_EXPORT_PREFIX = "init__virtual_markless_symbol";
|
|
735
|
+
const STRING_LITERAL_SOURCE = String.raw`(?:"[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|` + "`[^`\\\\]*(?:\\\\.[^`\\\\]*)*`)";
|
|
736
|
+
const FUNCTION_DECLARATION_RE = /\bfunction\s+([$A-Z_a-z][$\w]*)\s*\(\s*([$A-Z_a-z][$\w]*)\s*\)\s*\{/g;
|
|
737
|
+
const LOCAL_DYNAMIC_IMPORT_HELPER_RE = /import\(\s*(["'`])([^"'`]+)\1\s*\)\.then\(\s*\(?\s*([$A-Z_a-z][$\w]*)\s*\)?\s*=>\s*([$A-Z_a-z][$\w]*)\(\s*\3\s*,\s*(["'`])([^"'`]*)\5\s*\)\s*\)/g;
|
|
738
|
+
const LOCAL_DYNAMIC_IMPORT_RE = /import\(\s*(["'`])([^"'`]+)\1\s*\)(?:\.then\(\s*\(?\s*([$A-Z_a-z][$\w]*)\s*\)?\s*=>\s*\3\.([$A-Z_a-z][$\w]*)\s*\))?/g;
|
|
739
|
+
function rewriteGeneratedSymbolFacadeImports(bundle) {
|
|
740
|
+
const chunks = collectChunks$1(bundle);
|
|
741
|
+
const rewrites = findSymbolFacadeRewrites(chunks);
|
|
742
|
+
const removedFacades = /* @__PURE__ */ new Set();
|
|
743
|
+
if (rewrites.size === 0) return removedFacades;
|
|
744
|
+
for (const chunk of chunks.values()) {
|
|
745
|
+
if (!isGeneratedAsyncChunk(chunk)) continue;
|
|
746
|
+
const result = rewriteDynamicImportSpecifiers(chunk, rewrites);
|
|
747
|
+
chunk.code = result.code;
|
|
748
|
+
chunk.dynamicImports = unique(chunk.dynamicImports.map((fileName) => result.rewrittenFacades.has(fileName) ? rewrites.get(fileName)?.target.fileName ?? fileName : fileName));
|
|
749
|
+
}
|
|
750
|
+
for (const rewrite of rewrites.values()) {
|
|
751
|
+
const facadeId = rewrite.facade.facadeModuleId;
|
|
752
|
+
if (facadeId && !rewrite.target.moduleIds.includes(facadeId)) rewrite.target.moduleIds = [...rewrite.target.moduleIds, facadeId];
|
|
753
|
+
}
|
|
754
|
+
for (const rewrite of rewrites.values()) {
|
|
755
|
+
deleteBundleChunk(bundle, rewrite.facade.fileName);
|
|
756
|
+
chunks.delete(rewrite.facade.fileName);
|
|
757
|
+
removedFacades.add(rewrite.facade.fileName);
|
|
758
|
+
}
|
|
759
|
+
return removedFacades;
|
|
760
|
+
}
|
|
761
|
+
function rewriteGeneratedSymbolInitExports(bundle) {
|
|
762
|
+
const chunks = collectChunks$1(bundle);
|
|
763
|
+
const rewrites = findSymbolInitExportRewrites(chunks);
|
|
764
|
+
if (rewrites.length === 0) return { renamed: 0 };
|
|
765
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
766
|
+
for (const rewrite of rewrites) {
|
|
767
|
+
rewrite.chunk.exports = rewrite.collapsed ? [...rewrite.collapsed.exports] : rewrite.chunk.exports.map((name) => rewrite.names.get(name) ?? name);
|
|
768
|
+
if (rewrite.collapsed) rewrite.chunk.code = rewrite.collapsed.code;
|
|
769
|
+
for (const [from, to] of rewrite.names) replacements.set(from, to);
|
|
770
|
+
}
|
|
771
|
+
for (const chunk of chunks.values()) {
|
|
772
|
+
if (!isGeneratedAsyncChunk(chunk)) continue;
|
|
773
|
+
chunk.code = replaceIdentifierNames(chunk.code, replacements);
|
|
774
|
+
}
|
|
775
|
+
return { renamed: replacements.size };
|
|
776
|
+
}
|
|
777
|
+
function compactGeneratedDirectSymbolLoaders(bundle) {
|
|
778
|
+
let compacted = 0;
|
|
779
|
+
for (const chunk of collectChunks$1(bundle).values()) {
|
|
780
|
+
if (!isGeneratedAsyncChunk(chunk)) continue;
|
|
781
|
+
if (!chunk.code.includes("?import(")) continue;
|
|
782
|
+
const result = compactDirectSymbolLoadersInCode(chunk.code);
|
|
783
|
+
if (result.compacted === 0) continue;
|
|
784
|
+
chunk.code = result.code;
|
|
785
|
+
compacted += result.compacted;
|
|
786
|
+
}
|
|
787
|
+
return { compacted };
|
|
788
|
+
}
|
|
789
|
+
function collectChunks$1(bundle) {
|
|
790
|
+
const chunks = /* @__PURE__ */ new Map();
|
|
791
|
+
for (const output of Object.values(bundle)) if (isGeneratedChunk$1(output)) chunks.set(output.fileName, output);
|
|
792
|
+
return chunks;
|
|
793
|
+
}
|
|
794
|
+
function findSymbolFacadeRewrites(chunks) {
|
|
795
|
+
const rewrites = /* @__PURE__ */ new Map();
|
|
796
|
+
for (const chunk of chunks.values()) {
|
|
797
|
+
const rewrite = findSymbolFacadeRewrite(chunk, chunks);
|
|
798
|
+
if (rewrite) rewrites.set(chunk.fileName, rewrite);
|
|
799
|
+
}
|
|
800
|
+
return rewrites;
|
|
801
|
+
}
|
|
802
|
+
function findSymbolInitExportRewrites(chunks) {
|
|
803
|
+
const rewrites = [];
|
|
804
|
+
for (const chunk of chunks.values()) {
|
|
805
|
+
const rewrite = findSymbolInitExportRewrite(chunk);
|
|
806
|
+
if (rewrite) rewrites.push(rewrite);
|
|
807
|
+
}
|
|
808
|
+
return rewrites;
|
|
809
|
+
}
|
|
810
|
+
function findSymbolInitExportRewrite(chunk) {
|
|
811
|
+
if (!isGeneratedAsyncChunk(chunk)) return void 0;
|
|
812
|
+
const initExports = chunk.exports.filter(isGeneratedSymbolInitExport);
|
|
813
|
+
if (initExports.length === 0) return void 0;
|
|
814
|
+
const names = /* @__PURE__ */ new Map();
|
|
815
|
+
const used = new Set(chunk.exports.filter((name) => !isGeneratedSymbolInitExport(name)));
|
|
816
|
+
const collapsed = collapseGeneratedSymbolInitExports(chunk.code, initExports);
|
|
817
|
+
if (collapsed) {
|
|
818
|
+
for (const name of initExports) if (name !== SYMBOL_INIT_EXPORT_PREFIX) names.set(name, SYMBOL_INIT_EXPORT_PREFIX);
|
|
819
|
+
return {
|
|
820
|
+
chunk,
|
|
821
|
+
names,
|
|
822
|
+
collapsed
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
for (const name of initExports) {
|
|
826
|
+
const next = compactSymbolInitExportName(name, used);
|
|
827
|
+
used.add(next);
|
|
828
|
+
if (next !== name) names.set(name, next);
|
|
829
|
+
}
|
|
830
|
+
return names.size > 0 ? {
|
|
831
|
+
chunk,
|
|
832
|
+
names
|
|
833
|
+
} : void 0;
|
|
834
|
+
}
|
|
835
|
+
function findSymbolFacadeRewrite(chunk, chunks) {
|
|
836
|
+
if (!isGeneratedSymbolFacade(chunk)) return void 0;
|
|
837
|
+
if (chunk.imports.length !== 1 || chunk.dynamicImports.length > 0) return void 0;
|
|
838
|
+
const parsed = parseSymbolFacade(chunk.code);
|
|
839
|
+
if (!parsed) return void 0;
|
|
840
|
+
const target = chunks.get(chunk.imports[0]);
|
|
841
|
+
if (!target) return void 0;
|
|
842
|
+
const targetExports = new Set(target.exports);
|
|
843
|
+
if (!chunk.exports.every((name) => targetExports.has(name))) return void 0;
|
|
844
|
+
if (!parsed.initExports.every((name) => targetExports.has(name))) return void 0;
|
|
845
|
+
return {
|
|
846
|
+
facade: chunk,
|
|
847
|
+
target,
|
|
848
|
+
initExports: parsed.initExports
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
function isGeneratedSymbolFacade(chunk) {
|
|
852
|
+
return (chunk.facadeModuleId ? normalizeVirtualId$2(chunk.facadeModuleId) : "").startsWith(`${MARKLESS_VIRTUAL_PREFIX}symbol:`);
|
|
853
|
+
}
|
|
854
|
+
function isGeneratedSymbolInitExport(name) {
|
|
855
|
+
return name === SYMBOL_INIT_EXPORT_PREFIX || name.startsWith(`${SYMBOL_INIT_EXPORT_PREFIX}_`) || /^\$\d+$/.test(name.slice(29));
|
|
856
|
+
}
|
|
857
|
+
function compactSymbolInitExportName(name, used) {
|
|
858
|
+
const suffix = name.match(/\$(\d+)$/)?.[1];
|
|
859
|
+
let candidate = suffix ? `${SYMBOL_INIT_EXPORT_PREFIX}$${suffix}` : SYMBOL_INIT_EXPORT_PREFIX;
|
|
860
|
+
let nextSuffix = suffix ? Number(suffix) : 0;
|
|
861
|
+
while (used.has(candidate)) {
|
|
862
|
+
nextSuffix++;
|
|
863
|
+
candidate = `${SYMBOL_INIT_EXPORT_PREFIX}$${nextSuffix}`;
|
|
864
|
+
}
|
|
865
|
+
return candidate;
|
|
866
|
+
}
|
|
867
|
+
function collapseGeneratedSymbolInitExports(code, initExports) {
|
|
868
|
+
if (initExports.length < 2) return void 0;
|
|
869
|
+
const match = code.match(/export\s*\{\s*([^}]*)\s*\}\s*;?\s*$/);
|
|
870
|
+
if (!match || match.index === void 0) return void 0;
|
|
871
|
+
const specifiers = parseExportSpecifiers(match[1]);
|
|
872
|
+
if (!specifiers) return void 0;
|
|
873
|
+
if (specifiers.some((specifier) => !isIdentifier(specifier.local))) return void 0;
|
|
874
|
+
const initExportSet = new Set(initExports);
|
|
875
|
+
const initLocals = unique(specifiers.filter((specifier) => initExportSet.has(specifier.exported)).map((specifier) => specifier.local));
|
|
876
|
+
if (initLocals.length < 2) return void 0;
|
|
877
|
+
const nonInitSpecifiers = specifiers.filter((specifier) => !initExportSet.has(specifier.exported));
|
|
878
|
+
if (nonInitSpecifiers.some((specifier) => specifier.exported === SYMBOL_INIT_EXPORT_PREFIX)) return;
|
|
879
|
+
const initLocal = uniqueIdentifier("$i", code);
|
|
880
|
+
return {
|
|
881
|
+
code: `${code.slice(0, match.index)}function ${initLocal}(){${initLocals.map((local) => `${local}()`).join(";")}}export{${[`${initLocal} as ${SYMBOL_INIT_EXPORT_PREFIX}`, ...nonInitSpecifiers.map(formatExportSpecifier)].join(",")}};`,
|
|
882
|
+
exports: [SYMBOL_INIT_EXPORT_PREFIX, ...nonInitSpecifiers.map((specifier) => specifier.exported)]
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
function rewriteDynamicImportSpecifiers(chunk, rewrites) {
|
|
886
|
+
const rewrittenFacades = /* @__PURE__ */ new Set();
|
|
887
|
+
return {
|
|
888
|
+
code: chunk.code.replace(LOCAL_DYNAMIC_IMPORT_HELPER_RE, (match, quote, specifier, parameter, helperName, exportQuote, exportName) => {
|
|
889
|
+
if (!isLocalSpecifier(specifier)) return match;
|
|
890
|
+
const importedFileName = resolveChunkSpecifier(chunk.fileName, specifier);
|
|
891
|
+
const rewrite = rewrites.get(importedFileName);
|
|
892
|
+
if (!rewrite) return match;
|
|
893
|
+
if (!rewrite.target.exports.includes(exportName)) return match;
|
|
894
|
+
const nextSpecifier = relativeChunkSpecifier$1(chunk.fileName, rewrite.target.fileName);
|
|
895
|
+
rewrittenFacades.add(importedFileName);
|
|
896
|
+
return `import(${quote}${nextSpecifier}${quote}).then(${parameter}=>${helperName}(${parameter},${exportQuote}${exportName}${exportQuote}))`;
|
|
897
|
+
}).replace(LOCAL_DYNAMIC_IMPORT_RE, (match, quote, specifier, parameter, exportName) => {
|
|
898
|
+
if (!isLocalSpecifier(specifier)) return match;
|
|
899
|
+
const importedFileName = resolveChunkSpecifier(chunk.fileName, specifier);
|
|
900
|
+
const rewrite = rewrites.get(importedFileName);
|
|
901
|
+
if (!rewrite) return match;
|
|
902
|
+
if (rewrite.initExports.length > 0 && (!parameter || !exportName)) return match;
|
|
903
|
+
const nextSpecifier = relativeChunkSpecifier$1(chunk.fileName, rewrite.target.fileName);
|
|
904
|
+
rewrittenFacades.add(importedFileName);
|
|
905
|
+
const nextImport = `import(${quote}${nextSpecifier}${quote})`;
|
|
906
|
+
if (!parameter || !exportName || rewrite.initExports.length === 0) return nextImport;
|
|
907
|
+
return `${nextImport}.then(${parameter}=>(${[...rewrite.initExports.map((name) => `${parameter}.${name}()`), `${parameter}.${exportName}`].join(",")}))`;
|
|
908
|
+
}),
|
|
909
|
+
rewrittenFacades
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
function compactDirectSymbolLoadersInCode(code) {
|
|
913
|
+
let next = "";
|
|
914
|
+
let cursor = 0;
|
|
915
|
+
let compacted = 0;
|
|
916
|
+
for (let match = FUNCTION_DECLARATION_RE.exec(code); match; match = FUNCTION_DECLARATION_RE.exec(code)) {
|
|
917
|
+
const functionStart = match.index;
|
|
918
|
+
const bodyStart = FUNCTION_DECLARATION_RE.lastIndex;
|
|
919
|
+
const bodyEnd = findBlockEnd(code, bodyStart - 1);
|
|
920
|
+
if (bodyEnd < 0) continue;
|
|
921
|
+
const body = code.slice(bodyStart, bodyEnd);
|
|
922
|
+
const mapName = uniqueIdentifier("$s", `${code}${next}`);
|
|
923
|
+
const moduleCacheName = uniqueIdentifier("$m", `${code}${next}${mapName}`);
|
|
924
|
+
const replacement = compactDirectSymbolLoaderFunction({
|
|
925
|
+
functionName: match[1],
|
|
926
|
+
parameterName: match[2],
|
|
927
|
+
body,
|
|
928
|
+
mapName,
|
|
929
|
+
moduleCacheName
|
|
930
|
+
});
|
|
931
|
+
if (!replacement) {
|
|
932
|
+
FUNCTION_DECLARATION_RE.lastIndex = bodyEnd + 1;
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
next += code.slice(cursor, functionStart);
|
|
936
|
+
next += replacement;
|
|
937
|
+
cursor = bodyEnd + 1;
|
|
938
|
+
compacted++;
|
|
939
|
+
FUNCTION_DECLARATION_RE.lastIndex = cursor;
|
|
940
|
+
}
|
|
941
|
+
if (compacted === 0) return {
|
|
942
|
+
code,
|
|
943
|
+
compacted
|
|
944
|
+
};
|
|
945
|
+
return {
|
|
946
|
+
code: next + code.slice(cursor),
|
|
947
|
+
compacted
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
function compactDirectSymbolLoaderFunction(input) {
|
|
951
|
+
const returnSource = input.body.trim();
|
|
952
|
+
if (!returnSource.startsWith("return ")) return void 0;
|
|
953
|
+
const parsed = parseDirectSymbolLoaderBranches(returnSource.slice(7), input.parameterName);
|
|
954
|
+
if (!parsed) return void 0;
|
|
955
|
+
const first = parsed.branches[0];
|
|
956
|
+
if (parsed.branches.some((branch) => branch.importSpecifier !== first.importSpecifier || branch.helperName !== first.helperName)) return;
|
|
957
|
+
const generatedCount = generatedSymbolRangeCount(parsed.branches);
|
|
958
|
+
if (generatedCount !== void 0) return [
|
|
959
|
+
`let ${input.moduleCacheName};`,
|
|
960
|
+
`function ${input.functionName}(${input.parameterName}){`,
|
|
961
|
+
`let t=+${input.parameterName}.slice(7);`,
|
|
962
|
+
`if(${input.parameterName}===\`symbol:\${t}\`&&t>=0&&t<${generatedCount}){`,
|
|
963
|
+
`if(${input.moduleCacheName})return ${first.helperName}(${input.moduleCacheName},\`symbol_\${t}\`);`,
|
|
964
|
+
`return import(${JSON.stringify(first.importSpecifier)})`,
|
|
965
|
+
`.then(${first.moduleParameter}=>(${input.moduleCacheName}=${first.moduleParameter},${first.helperName}(${first.moduleParameter},\`symbol_\${t}\`)))`,
|
|
966
|
+
`}`,
|
|
967
|
+
`return ${parsed.fallback}`,
|
|
968
|
+
"}"
|
|
969
|
+
].join("");
|
|
970
|
+
const exportVariable = input.parameterName === "t" ? "n" : "t";
|
|
971
|
+
const mapEntries = parsed.branches.map((branch) => `${JSON.stringify(branch.symbolId)}:${JSON.stringify(branch.exportName)}`).join(",");
|
|
972
|
+
return [
|
|
973
|
+
`const ${input.mapName}={${mapEntries}};`,
|
|
974
|
+
`let ${input.moduleCacheName};`,
|
|
975
|
+
`function ${input.functionName}(${input.parameterName}){`,
|
|
976
|
+
`let ${exportVariable}=${input.mapName}[${input.parameterName}];`,
|
|
977
|
+
`if(${exportVariable}){`,
|
|
978
|
+
`if(${input.moduleCacheName})return ${first.helperName}(${input.moduleCacheName},${exportVariable});`,
|
|
979
|
+
`return import(${JSON.stringify(first.importSpecifier)})`,
|
|
980
|
+
`.then(${first.moduleParameter}=>(${input.moduleCacheName}=${first.moduleParameter},${first.helperName}(${first.moduleParameter},${exportVariable})))`,
|
|
981
|
+
`}`,
|
|
982
|
+
`return ${parsed.fallback}`,
|
|
983
|
+
"}"
|
|
984
|
+
].join("");
|
|
985
|
+
}
|
|
986
|
+
function parseDirectSymbolLoaderBranches(source, parameterName) {
|
|
987
|
+
const branches = [];
|
|
988
|
+
const branchRE = directSymbolLoaderBranchRE(parameterName);
|
|
989
|
+
let cursor = 0;
|
|
990
|
+
while (cursor < source.length) {
|
|
991
|
+
const match = source.slice(cursor).match(branchRE);
|
|
992
|
+
if (!match) break;
|
|
993
|
+
const symbolId = simpleStringLiteralValue(match[1]);
|
|
994
|
+
const importSpecifier = simpleStringLiteralValue(match[2]);
|
|
995
|
+
const moduleParameter = match[3];
|
|
996
|
+
const helperName = match[4];
|
|
997
|
+
const helperArgument = match[5];
|
|
998
|
+
const exportName = simpleStringLiteralValue(match[6]);
|
|
999
|
+
if (symbolId === void 0 || importSpecifier === void 0 || exportName === void 0 || moduleParameter !== helperArgument) return;
|
|
1000
|
+
branches.push({
|
|
1001
|
+
symbolId,
|
|
1002
|
+
importSpecifier,
|
|
1003
|
+
moduleParameter,
|
|
1004
|
+
helperName,
|
|
1005
|
+
exportName
|
|
1006
|
+
});
|
|
1007
|
+
cursor += match[0].length;
|
|
1008
|
+
}
|
|
1009
|
+
const fallback = source.slice(cursor);
|
|
1010
|
+
if (branches.length < 2 || !fallback.startsWith("Promise.reject(")) return void 0;
|
|
1011
|
+
return {
|
|
1012
|
+
branches,
|
|
1013
|
+
fallback
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
function generatedSymbolRangeCount(branches) {
|
|
1017
|
+
for (const [index, branch] of branches.entries()) if (branch.symbolId !== `symbol:${index}` || branch.exportName !== `symbol_${index}`) return;
|
|
1018
|
+
return branches.length;
|
|
1019
|
+
}
|
|
1020
|
+
function directSymbolLoaderBranchRE(parameterName) {
|
|
1021
|
+
return new RegExp(`^${escapeRegExp(parameterName)}\\s*===\\s*(${STRING_LITERAL_SOURCE})\\s*\\?\\s*import\\(\\s*(${STRING_LITERAL_SOURCE})\\s*\\)\\.then\\(\\s*\\(?\\s*([$A-Z_a-z][$\\w]*)\\s*\\)?\\s*=>\\s*([$A-Z_a-z][$\\w]*)\\(\\s*([$A-Z_a-z][$\\w]*)\\s*,\\s*(${STRING_LITERAL_SOURCE})\\s*\\)\\s*\\)\\s*:`);
|
|
1022
|
+
}
|
|
1023
|
+
function simpleStringLiteralValue(source) {
|
|
1024
|
+
const quote = source[0];
|
|
1025
|
+
if (quote !== "\"" && quote !== "'" && quote !== "`" || source[source.length - 1] !== quote) return;
|
|
1026
|
+
return source.slice(1, -1);
|
|
1027
|
+
}
|
|
1028
|
+
function findBlockEnd(code, open) {
|
|
1029
|
+
let depth = 0;
|
|
1030
|
+
let quote = null;
|
|
1031
|
+
let escaped = false;
|
|
1032
|
+
for (let index = open; index < code.length; index++) {
|
|
1033
|
+
const char = code[index];
|
|
1034
|
+
if (quote) {
|
|
1035
|
+
if (escaped) {
|
|
1036
|
+
escaped = false;
|
|
1037
|
+
continue;
|
|
1038
|
+
}
|
|
1039
|
+
if (char === "\\") {
|
|
1040
|
+
escaped = true;
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
if (char === quote) quote = null;
|
|
1044
|
+
continue;
|
|
1045
|
+
}
|
|
1046
|
+
if (char === "\"" || char === "'" || char === "`") {
|
|
1047
|
+
quote = char;
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
if (char === "{") {
|
|
1051
|
+
depth++;
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
if (char === "}") {
|
|
1055
|
+
depth--;
|
|
1056
|
+
if (depth === 0) return index;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
return -1;
|
|
1060
|
+
}
|
|
1061
|
+
function resolveChunkSpecifier(importerFileName, specifier) {
|
|
1062
|
+
return normalize(join(dirname(importerFileName), specifier));
|
|
1063
|
+
}
|
|
1064
|
+
function relativeChunkSpecifier$1(importerFileName, targetFileName) {
|
|
1065
|
+
const value = relative(dirname(importerFileName), targetFileName).replaceAll("\\", "/");
|
|
1066
|
+
return value.startsWith(".") ? value : `./${value}`;
|
|
1067
|
+
}
|
|
1068
|
+
function isGeneratedAsyncChunk(chunk) {
|
|
1069
|
+
return chunk.moduleIds.some((id) => {
|
|
1070
|
+
return normalizeVirtualId$2(id).startsWith("virtual:markless:") || TSRX_SOURCE_FILE$1.test(id);
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
function deleteBundleChunk(bundle, fileName) {
|
|
1074
|
+
for (const [key, output] of Object.entries(bundle)) if (isGeneratedChunk$1(output) && output.fileName === fileName) delete bundle[key];
|
|
1075
|
+
}
|
|
1076
|
+
function isGeneratedChunk$1(value) {
|
|
1077
|
+
if (!value || typeof value !== "object") return false;
|
|
1078
|
+
const chunk = value;
|
|
1079
|
+
return chunk.type === "chunk" && typeof chunk.fileName === "string" && typeof chunk.code === "string" && Array.isArray(chunk.exports) && Array.isArray(chunk.imports) && Array.isArray(chunk.dynamicImports) && Array.isArray(chunk.moduleIds);
|
|
1080
|
+
}
|
|
1081
|
+
function unique(values) {
|
|
1082
|
+
return [...new Set(values)];
|
|
1083
|
+
}
|
|
1084
|
+
function replaceIdentifierNames(code, replacements) {
|
|
1085
|
+
const names = [...replacements.keys()].sort((a, b) => b.length - a.length);
|
|
1086
|
+
let next = code;
|
|
1087
|
+
for (const name of names) next = next.replace(identifierNameRE(name), replacements.get(name));
|
|
1088
|
+
return next;
|
|
1089
|
+
}
|
|
1090
|
+
function identifierNameRE(name) {
|
|
1091
|
+
return new RegExp(`(?<![$\\w])${escapeRegExp(name)}(?![$\\w])`, "g");
|
|
1092
|
+
}
|
|
1093
|
+
function escapeRegExp(value) {
|
|
1094
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1095
|
+
}
|
|
1096
|
+
function isLocalSpecifier(specifier) {
|
|
1097
|
+
return specifier.startsWith("./") || specifier.startsWith("../");
|
|
1098
|
+
}
|
|
1099
|
+
function parseSymbolFacade(code) {
|
|
1100
|
+
const match = code.trim().match(/^import\s*\{\s*([^}]*)\s*\}\s*from\s*(["'`])([^"'`]+)\2\s*;\s*([\s\S]*?)\s*export\s*\{\s*([^}]*)\s*\}\s*;?\s*$/);
|
|
1101
|
+
if (!match) return void 0;
|
|
1102
|
+
const imports = parseImportSpecifiers(match[1]);
|
|
1103
|
+
const exportLocals = parseExportLocalNames(match[5]);
|
|
1104
|
+
if (!imports || !exportLocals) return void 0;
|
|
1105
|
+
const body = match[4].trim();
|
|
1106
|
+
const initLocals = body ? body.split(";").map((statement) => statement.trim()).filter(Boolean).map((statement) => statement.match(/^([$A-Z_a-z][$\w]*)\(\)$/)?.[1]) : [];
|
|
1107
|
+
if (initLocals.some((name) => !name)) return void 0;
|
|
1108
|
+
for (const local of exportLocals) if (!imports.has(local)) return void 0;
|
|
1109
|
+
return { initExports: unique(initLocals.filter((local) => !!local).map((local) => imports.get(local)).filter((name) => !!name)) };
|
|
1110
|
+
}
|
|
1111
|
+
function parseImportSpecifiers(value) {
|
|
1112
|
+
const imports = /* @__PURE__ */ new Map();
|
|
1113
|
+
for (const part of value.split(",")) {
|
|
1114
|
+
const specifier = part.trim();
|
|
1115
|
+
if (!specifier) continue;
|
|
1116
|
+
const aliased = specifier.match(/^(.+?)\s+as\s+(.+)$/);
|
|
1117
|
+
const imported = (aliased?.[1] ?? specifier).trim();
|
|
1118
|
+
const local = (aliased?.[2] ?? specifier).trim();
|
|
1119
|
+
if (!isIdentifier(imported) || !isIdentifier(local)) return void 0;
|
|
1120
|
+
imports.set(local, imported);
|
|
1121
|
+
}
|
|
1122
|
+
return imports;
|
|
1123
|
+
}
|
|
1124
|
+
function parseExportLocalNames(value) {
|
|
1125
|
+
const locals = [];
|
|
1126
|
+
for (const part of value.split(",")) {
|
|
1127
|
+
const specifier = part.trim();
|
|
1128
|
+
if (!specifier) continue;
|
|
1129
|
+
const aliased = specifier.match(/^(.+?)\s+as\s+(.+)$/);
|
|
1130
|
+
const local = (aliased?.[1] ?? specifier).trim();
|
|
1131
|
+
const exported = (aliased?.[2] ?? specifier).trim();
|
|
1132
|
+
if (!isIdentifier(local) || !isIdentifier(exported)) return void 0;
|
|
1133
|
+
locals.push(local);
|
|
1134
|
+
}
|
|
1135
|
+
return locals;
|
|
1136
|
+
}
|
|
1137
|
+
function parseExportSpecifiers(value) {
|
|
1138
|
+
const specifiers = [];
|
|
1139
|
+
for (const part of value.split(",")) {
|
|
1140
|
+
const specifier = part.trim();
|
|
1141
|
+
if (!specifier) continue;
|
|
1142
|
+
const aliased = specifier.match(/^(.+?)\s+as\s+(.+)$/);
|
|
1143
|
+
const local = (aliased?.[1] ?? specifier).trim();
|
|
1144
|
+
const exported = (aliased?.[2] ?? specifier).trim();
|
|
1145
|
+
if (!isIdentifier(local) || !isIdentifier(exported)) return void 0;
|
|
1146
|
+
specifiers.push({
|
|
1147
|
+
local,
|
|
1148
|
+
exported
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
return specifiers;
|
|
1152
|
+
}
|
|
1153
|
+
function formatExportSpecifier(specifier) {
|
|
1154
|
+
return specifier.local === specifier.exported ? specifier.local : `${specifier.local} as ${specifier.exported}`;
|
|
1155
|
+
}
|
|
1156
|
+
function uniqueIdentifier(base, code) {
|
|
1157
|
+
let candidate = base;
|
|
1158
|
+
let index = 0;
|
|
1159
|
+
while (identifierNameRE(candidate).test(code)) {
|
|
1160
|
+
index++;
|
|
1161
|
+
candidate = `${base}${index}`;
|
|
1162
|
+
}
|
|
1163
|
+
return candidate;
|
|
1164
|
+
}
|
|
1165
|
+
function isIdentifier(value) {
|
|
1166
|
+
return /^[$A-Z_a-z][$\w]*$/.test(value);
|
|
1167
|
+
}
|
|
1168
|
+
function normalizeVirtualId$2(id) {
|
|
1169
|
+
return id.startsWith("\0") ? id.slice(1) : id;
|
|
1170
|
+
}
|
|
1171
|
+
//#endregion
|
|
1172
|
+
//#region src/transform.ts
|
|
1173
|
+
let oxcTransformSyncPromise;
|
|
1174
|
+
function loadOxcTransformSync() {
|
|
1175
|
+
oxcTransformSyncPromise ??= import("rolldown/experimental").then((mod) => mod.transformSync, () => void 0);
|
|
1176
|
+
return oxcTransformSyncPromise;
|
|
1177
|
+
}
|
|
1178
|
+
async function stripEmittedTypes(code) {
|
|
1179
|
+
const oxcTransformSync = await loadOxcTransformSync();
|
|
1180
|
+
if (!oxcTransformSync) return code;
|
|
1181
|
+
try {
|
|
1182
|
+
const out = oxcTransformSync("markless-emitted.ts", code);
|
|
1183
|
+
if (!out.code || (out.errors?.length ?? 0) > 0) return code;
|
|
1184
|
+
return out.code;
|
|
1185
|
+
} catch {
|
|
1186
|
+
return code;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
async function transformTsrxModule(input) {
|
|
1190
|
+
const encodedFilename = encodeURIComponent(input.filename);
|
|
1191
|
+
const payloadId = `${MARKLESS_VIRTUAL_PREFIX}payload:${encodedFilename}`;
|
|
1192
|
+
const resolverId = `${MARKLESS_VIRTUAL_PREFIX}resolver:${encodedFilename}`;
|
|
1193
|
+
const resumeId = resumeVirtualModuleId(input.filename);
|
|
1194
|
+
const compiled = await compileTsrxModule({
|
|
1195
|
+
filename: input.filename,
|
|
1196
|
+
source: input.source,
|
|
1197
|
+
buildId: input.buildId,
|
|
1198
|
+
resolverId,
|
|
1199
|
+
symbols: []
|
|
1200
|
+
});
|
|
1201
|
+
const symbolRows = compiled.symbolModules.modules.map((module) => ({
|
|
1202
|
+
id: module.symbolId,
|
|
1203
|
+
chunk: symbolVirtualModuleId(input.filename, module.symbolId),
|
|
1204
|
+
exportName: scopedSymbolExportName(input.filename, module.exportName)
|
|
1205
|
+
}));
|
|
1206
|
+
const resolverSource = emitSymbolResolverModule({
|
|
1207
|
+
buildId: input.buildId,
|
|
1208
|
+
symbols: symbolRows
|
|
1209
|
+
});
|
|
1210
|
+
const symbolRoutes = compiled.semanticGraph.componentEdges.flatMap((edge, index) => edge.importSource ? [{
|
|
1211
|
+
prefix: `c${index}:`,
|
|
1212
|
+
importSource: edge.importSource
|
|
1213
|
+
}] : []);
|
|
1214
|
+
const executionLogModuleHookMode = input.executionLogModuleHooks === false ? "never" : input.executionLog;
|
|
1215
|
+
const manifest = {
|
|
1216
|
+
source: input.filename,
|
|
1217
|
+
payload: { virtualModuleId: payloadId },
|
|
1218
|
+
resolver: { virtualModuleId: resolverId },
|
|
1219
|
+
symbols: compiled.symbolModules.modules.map((module, index) => ({
|
|
1220
|
+
symbolId: module.symbolId,
|
|
1221
|
+
kind: module.kind,
|
|
1222
|
+
exportName: symbolRows[index].exportName,
|
|
1223
|
+
virtualModuleId: symbolVirtualModuleId(input.filename, module.symbolId)
|
|
1224
|
+
})),
|
|
1225
|
+
runtimeDemandMap: compiled.runtimeDemandMap
|
|
1226
|
+
};
|
|
1227
|
+
const styleScope = compiled.publicRenderPlan.styleScopes[0];
|
|
1228
|
+
const styleId = styleScope ? `${MARKLESS_VIRTUAL_PREFIX}style:${encodedFilename}.css` : null;
|
|
1229
|
+
const virtualModules = [
|
|
1230
|
+
...styleScope && styleId ? [{
|
|
1231
|
+
id: styleId,
|
|
1232
|
+
type: "style",
|
|
1233
|
+
source: styleScope.cssText
|
|
1234
|
+
}] : [],
|
|
1235
|
+
{
|
|
1236
|
+
id: payloadId,
|
|
1237
|
+
type: "payload",
|
|
1238
|
+
source: payloadModule({
|
|
1239
|
+
...compiled.payloadScripts,
|
|
1240
|
+
runtimeDemandMap: compiled.runtimeDemandMap
|
|
1241
|
+
})
|
|
1242
|
+
},
|
|
1243
|
+
{
|
|
1244
|
+
id: resolverId,
|
|
1245
|
+
type: "resolver",
|
|
1246
|
+
source: resolverSource
|
|
1247
|
+
},
|
|
1248
|
+
{
|
|
1249
|
+
id: resumeId,
|
|
1250
|
+
type: "resume",
|
|
1251
|
+
source: emitResumeModule({
|
|
1252
|
+
payloadId,
|
|
1253
|
+
resolverId,
|
|
1254
|
+
payloadState: compiled.payloadScripts.state,
|
|
1255
|
+
payloadView: containerScopedResumeView(compiled.payloadScripts.view),
|
|
1256
|
+
runtimeDemandMap: compiled.runtimeDemandMap,
|
|
1257
|
+
executionLog: input.executionLog,
|
|
1258
|
+
needsFullResume: needsFullResume(compiled.protocolView, compiled.runtimeDemandMap),
|
|
1259
|
+
symbols: symbolRows,
|
|
1260
|
+
symbolRoutes
|
|
1261
|
+
})
|
|
1262
|
+
},
|
|
1263
|
+
...await Promise.all(compiled.symbolModules.modules.map(async (module, index) => ({
|
|
1264
|
+
id: symbolVirtualModuleId(input.filename, module.symbolId),
|
|
1265
|
+
type: "symbol",
|
|
1266
|
+
symbolId: module.symbolId,
|
|
1267
|
+
exportName: symbolRows[index].exportName,
|
|
1268
|
+
source: injectExecutionLogModuleHook(await stripEmittedTypes(rewriteSymbolModuleExport(module.source, module.exportName, symbolRows[index].exportName)), `symbol:${module.symbolId}`, executionLogModuleHookMode)
|
|
1269
|
+
})))
|
|
1270
|
+
];
|
|
1271
|
+
return {
|
|
1272
|
+
code: (styleId ? `import ${JSON.stringify(styleId)};\n` : "") + await stripEmittedTypes(emitSourceModule({
|
|
1273
|
+
filename: input.filename,
|
|
1274
|
+
payloadId,
|
|
1275
|
+
resolverId,
|
|
1276
|
+
environment: input.environment ?? "lib",
|
|
1277
|
+
clientOutput: input.clientOutput ?? "full",
|
|
1278
|
+
executionLog: input.executionLog,
|
|
1279
|
+
headInjections: input.headInjections,
|
|
1280
|
+
devResumeReexport: input.devResumeReexport === true,
|
|
1281
|
+
needsFullResume: needsFullResume(compiled.protocolView, compiled.runtimeDemandMap),
|
|
1282
|
+
resumeModuleUrl: input.resumeModuleUrl,
|
|
1283
|
+
publicRenderModuleSource: compiled.publicRenderModule.moduleSource,
|
|
1284
|
+
publicRenderRootExportName: compiled.publicRenderModule.rootExportName,
|
|
1285
|
+
publicCsrModuleSource: compiled.publicRenderModule.csrModuleSource,
|
|
1286
|
+
publicRenderCsrExportName: compiled.publicRenderModule.csrExportName,
|
|
1287
|
+
publicSsrModuleSource: compiled.publicRenderModule.ssrModuleSource,
|
|
1288
|
+
publicRenderSsrExportName: compiled.publicRenderModule.ssrExportName,
|
|
1289
|
+
symbols: symbolRows,
|
|
1290
|
+
symbolRoutes
|
|
1291
|
+
})),
|
|
1292
|
+
map: null,
|
|
1293
|
+
virtualModules,
|
|
1294
|
+
manifest
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
function containerScopedResumeView(view) {
|
|
1298
|
+
return {
|
|
1299
|
+
...view,
|
|
1300
|
+
locators: (view.locators ?? []).map((locator) => ({
|
|
1301
|
+
...locator,
|
|
1302
|
+
index: locator.index + 1
|
|
1303
|
+
}))
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
function needsFullResume(view, runtimeDemandMap) {
|
|
1307
|
+
if ((view.branches?.length ?? 0) > 0) return true;
|
|
1308
|
+
if ((view.elementHandles?.length ?? 0) > 0) return true;
|
|
1309
|
+
if ((view.asyncBoundaries?.length ?? 0) > 0) return true;
|
|
1310
|
+
if ((view.keyedRepeats?.length ?? 0) === 0) return false;
|
|
1311
|
+
return !recordKindReplaced(runtimeDemandMap, "keyed-repeat");
|
|
1312
|
+
}
|
|
1313
|
+
function recordKindReplaced(runtimeDemandMap, kind) {
|
|
1314
|
+
return runtimeDemandMap.recordKinds.some((record) => record.kind === kind && record.replaced === true);
|
|
1315
|
+
}
|
|
1316
|
+
//#endregion
|
|
1317
|
+
//#region src/build/symbol-table.ts
|
|
1318
|
+
const SYMBOL_VIRTUAL_PREFIX = `${MARKLESS_VIRTUAL_PREFIX}symbol:`;
|
|
1319
|
+
const SYMBOL_VIRTUAL_STRING_RE$1 = /(["'`])((?:virtual:markless:symbol:)[^"'`]+)\1/g;
|
|
1320
|
+
const SYMBOL_MANIFEST_TUPLE_RE = /(\[1,(?:null|["'`][^"'`]*["'`]),(?:null|["'`][^"'`]*["'`]),)(\[[^\]]*\]),(\[[^\]]*\]),(\{[^}]*\})(\])/g;
|
|
1321
|
+
const STRING_LITERAL_RE = /(["'`])([^"'`]*)\1/g;
|
|
1322
|
+
const SYMBOL_ROW_RE = /((?:["'`][^"'`]*["'`])\s*:\s*\[)(\d+)(,\s*\d+\])/g;
|
|
1323
|
+
function rewriteGeneratedSymbolTableUrls(bundle) {
|
|
1324
|
+
const chunks = collectChunks(bundle);
|
|
1325
|
+
const symbolFiles = collectGeneratedSymbolFiles(chunks);
|
|
1326
|
+
let rewritten = 0;
|
|
1327
|
+
const unresolved = /* @__PURE__ */ new Set();
|
|
1328
|
+
for (const chunk of chunks.values()) {
|
|
1329
|
+
if (!chunk.code.includes(SYMBOL_VIRTUAL_PREFIX)) continue;
|
|
1330
|
+
const result = rewriteSymbolVirtualStrings(chunk, symbolFiles);
|
|
1331
|
+
chunk.code = result.code;
|
|
1332
|
+
rewritten += result.rewritten;
|
|
1333
|
+
for (const id of result.unresolved) unresolved.add(id);
|
|
1334
|
+
}
|
|
1335
|
+
return {
|
|
1336
|
+
rewritten,
|
|
1337
|
+
unresolved: [...unresolved].sort()
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
function collectChunks(bundle) {
|
|
1341
|
+
const chunks = /* @__PURE__ */ new Map();
|
|
1342
|
+
for (const output of Object.values(bundle)) if (isGeneratedChunk(output)) chunks.set(output.fileName, output);
|
|
1343
|
+
return chunks;
|
|
1344
|
+
}
|
|
1345
|
+
function collectGeneratedSymbolFiles(chunks) {
|
|
1346
|
+
const symbolFiles = /* @__PURE__ */ new Map();
|
|
1347
|
+
for (const chunk of chunks.values()) for (const id of virtualIds(chunk)) if (id.startsWith(SYMBOL_VIRTUAL_PREFIX)) symbolFiles.set(id, chunk.fileName);
|
|
1348
|
+
return symbolFiles;
|
|
1349
|
+
}
|
|
1350
|
+
function virtualIds(chunk) {
|
|
1351
|
+
return [chunk.facadeModuleId ?? void 0, ...chunk.moduleIds].filter((id) => !!id).map(normalizeVirtualId$1);
|
|
1352
|
+
}
|
|
1353
|
+
function rewriteSymbolVirtualStrings(chunk, symbolFiles) {
|
|
1354
|
+
let rewritten = 0;
|
|
1355
|
+
const unresolved = /* @__PURE__ */ new Set();
|
|
1356
|
+
return {
|
|
1357
|
+
code: compactSymbolManifestTables(chunk.code.replace(SYMBOL_VIRTUAL_STRING_RE$1, (match, _quote, virtualId) => {
|
|
1358
|
+
const fileName = symbolFiles.get(virtualId);
|
|
1359
|
+
if (!fileName) {
|
|
1360
|
+
unresolved.add(virtualId);
|
|
1361
|
+
return match;
|
|
1362
|
+
}
|
|
1363
|
+
rewritten++;
|
|
1364
|
+
return JSON.stringify(relativeChunkSpecifier(chunk.fileName, fileName));
|
|
1365
|
+
})),
|
|
1366
|
+
rewritten,
|
|
1367
|
+
unresolved: [...unresolved]
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
function compactSymbolManifestTables(code) {
|
|
1371
|
+
return code.replace(SYMBOL_MANIFEST_TUPLE_RE, (match, prefix, moduleUrlsSource, exportNamesSource, symbolRowsSource, suffix) => {
|
|
1372
|
+
const moduleUrls = parseStringArray(moduleUrlsSource);
|
|
1373
|
+
if (!moduleUrls) return match;
|
|
1374
|
+
const nextModuleUrls = [];
|
|
1375
|
+
const moduleIndexMap = /* @__PURE__ */ new Map();
|
|
1376
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1377
|
+
for (const [index, moduleUrl] of moduleUrls.entries()) {
|
|
1378
|
+
let nextIndex = seen.get(moduleUrl);
|
|
1379
|
+
if (nextIndex === void 0) {
|
|
1380
|
+
nextIndex = nextModuleUrls.length;
|
|
1381
|
+
seen.set(moduleUrl, nextIndex);
|
|
1382
|
+
nextModuleUrls.push(moduleUrl);
|
|
1383
|
+
}
|
|
1384
|
+
moduleIndexMap.set(index, nextIndex);
|
|
1385
|
+
}
|
|
1386
|
+
if (nextModuleUrls.length === moduleUrls.length) return match;
|
|
1387
|
+
const nextSymbolRows = symbolRowsSource.replace(SYMBOL_ROW_RE, (rowMatch, rowPrefix, moduleIndexSource, rowSuffix) => {
|
|
1388
|
+
const moduleIndex = Number(moduleIndexSource);
|
|
1389
|
+
const nextModuleIndex = moduleIndexMap.get(moduleIndex);
|
|
1390
|
+
if (nextModuleIndex === void 0) return rowMatch;
|
|
1391
|
+
return `${rowPrefix}${nextModuleIndex}${rowSuffix}`;
|
|
1392
|
+
});
|
|
1393
|
+
return `${prefix}${JSON.stringify(nextModuleUrls)},${exportNamesSource},${nextSymbolRows}${suffix}`;
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
function parseStringArray(source) {
|
|
1397
|
+
const values = [];
|
|
1398
|
+
let end = 1;
|
|
1399
|
+
for (const match of source.matchAll(STRING_LITERAL_RE)) {
|
|
1400
|
+
values.push(match[2]);
|
|
1401
|
+
end = (match.index ?? 0) + match[0].length;
|
|
1402
|
+
}
|
|
1403
|
+
if (source.slice(end).trim() !== "]") return void 0;
|
|
1404
|
+
return values;
|
|
1405
|
+
}
|
|
1406
|
+
function relativeChunkSpecifier(importerFileName, targetFileName) {
|
|
1407
|
+
const value = relative(dirname(importerFileName), targetFileName).replaceAll("\\", "/");
|
|
1408
|
+
return value.startsWith(".") ? value : `./${value}`;
|
|
1409
|
+
}
|
|
1410
|
+
function isGeneratedChunk(value) {
|
|
1411
|
+
if (!value || typeof value !== "object") return false;
|
|
1412
|
+
const chunk = value;
|
|
1413
|
+
return chunk.type === "chunk" && typeof chunk.fileName === "string" && typeof chunk.code === "string" && Array.isArray(chunk.moduleIds);
|
|
1414
|
+
}
|
|
1415
|
+
function normalizeVirtualId$1(id) {
|
|
1416
|
+
return id.startsWith("\0") ? id.slice(1) : id;
|
|
1417
|
+
}
|
|
1418
|
+
//#endregion
|
|
1419
|
+
//#region src/dev.ts
|
|
1420
|
+
function createMarklessDevGraph() {
|
|
1421
|
+
const parentModules = /* @__PURE__ */ new Map();
|
|
1422
|
+
return {
|
|
1423
|
+
record(parent, ids, environment) {
|
|
1424
|
+
const entries = [...ids];
|
|
1425
|
+
for (const path of parentKeys(parent)) {
|
|
1426
|
+
const key = parentKey(environment, path);
|
|
1427
|
+
const existing = parentModules.get(key) ?? /* @__PURE__ */ new Set();
|
|
1428
|
+
for (const id of entries) existing.add(id);
|
|
1429
|
+
parentModules.set(key, existing);
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1432
|
+
clear(parent, environment) {
|
|
1433
|
+
const deleted = [];
|
|
1434
|
+
for (const currentEnvironment of targetEnvironments(environment)) for (const path of parentKeys(parent)) {
|
|
1435
|
+
const key = parentKey(currentEnvironment, path);
|
|
1436
|
+
const ids = parentModules.get(key);
|
|
1437
|
+
if (!ids) continue;
|
|
1438
|
+
deleted.push(...ids);
|
|
1439
|
+
parentModules.delete(key);
|
|
1440
|
+
}
|
|
1441
|
+
return [...new Set(deleted)];
|
|
1442
|
+
},
|
|
1443
|
+
reset() {
|
|
1444
|
+
parentModules.clear();
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
function targetEnvironments(environment) {
|
|
1449
|
+
if (environment) return [environment];
|
|
1450
|
+
return allEnvironments;
|
|
1451
|
+
}
|
|
1452
|
+
const allEnvironments = [
|
|
1453
|
+
"client",
|
|
1454
|
+
"server",
|
|
1455
|
+
"lib"
|
|
1456
|
+
];
|
|
1457
|
+
function parentKeys(parent) {
|
|
1458
|
+
const path = pathname$1(parent);
|
|
1459
|
+
const normalized = normalize(path);
|
|
1460
|
+
const leadingPath = withLeadingSlash(normalized);
|
|
1461
|
+
const barePath = leadingPath.slice(1);
|
|
1462
|
+
return new Set([
|
|
1463
|
+
path,
|
|
1464
|
+
normalized,
|
|
1465
|
+
leadingPath,
|
|
1466
|
+
barePath
|
|
1467
|
+
]);
|
|
1468
|
+
}
|
|
1469
|
+
function parentKey(environment, parent) {
|
|
1470
|
+
return `${environment}:${parent}`;
|
|
1471
|
+
}
|
|
1472
|
+
function pathname$1(id) {
|
|
1473
|
+
return parsePath(id).pathname;
|
|
1474
|
+
}
|
|
1475
|
+
//#endregion
|
|
1476
|
+
//#region src/rolldown.ts
|
|
1477
|
+
const TSRX_SOURCE_FILE = /\.tsrx(?:[?#].*)?$/;
|
|
1478
|
+
const MARKLESS_SYMBOL_SOURCE_QUERY_RE = /[?&]markless-symbols(?:[&#]|$)/;
|
|
1479
|
+
const MARKLESS_RESUME_SOURCE_QUERY_RE = /[?&]markless-resume(?:[&#]|$)/;
|
|
1480
|
+
const RESUME_VIRTUAL_ID_RE = /^virtual:markless:resume:([^:]+)$/;
|
|
1481
|
+
const SYMBOL_VIRTUAL_STRING_RE = /(["'`])((?:virtual:markless:symbol:)[^"'`]+)\1/g;
|
|
1482
|
+
const marklessClient = (options = {}) => createMarklessRolldownPlugin({
|
|
1483
|
+
environment: "client",
|
|
1484
|
+
options
|
|
1485
|
+
});
|
|
1486
|
+
const marklessServer = (options = {}) => createMarklessRolldownPlugin({
|
|
1487
|
+
environment: "server",
|
|
1488
|
+
options
|
|
1489
|
+
});
|
|
1490
|
+
const marklessLib = (options = {}) => createMarklessRolldownPlugin({
|
|
1491
|
+
environment: "lib",
|
|
1492
|
+
options
|
|
1493
|
+
});
|
|
1494
|
+
function createMarklessRolldownPlugin(input) {
|
|
1495
|
+
const environment = input.environment;
|
|
1496
|
+
const internalOptions = input.options ?? {};
|
|
1497
|
+
const virtualModules = /* @__PURE__ */ new Map();
|
|
1498
|
+
const transformManifests = /* @__PURE__ */ new Map();
|
|
1499
|
+
const sourceVirtualModules = /* @__PURE__ */ new Map();
|
|
1500
|
+
const clientSymbolEntrySources = /* @__PURE__ */ new Set();
|
|
1501
|
+
const executionLogEstimatedSizes = /* @__PURE__ */ new Map();
|
|
1502
|
+
const dev = createMarklessDevGraph();
|
|
1503
|
+
let root = internalOptions.rootDir;
|
|
1504
|
+
const name = pluginName(environment);
|
|
1505
|
+
function getEnvironment(context) {
|
|
1506
|
+
if (typeof environment === "function") return environment(context);
|
|
1507
|
+
return environment;
|
|
1508
|
+
}
|
|
1509
|
+
function getRoot() {
|
|
1510
|
+
return root ?? internalOptions.rootDir;
|
|
1511
|
+
}
|
|
1512
|
+
return {
|
|
1513
|
+
api: { invalidateGeneratedModules(parent, currentEnvironment) {
|
|
1514
|
+
const ids = dev.clear(parent, currentEnvironment);
|
|
1515
|
+
for (const id of ids) virtualModules.delete(id);
|
|
1516
|
+
return ids.map(resolveVirtualId);
|
|
1517
|
+
} },
|
|
1518
|
+
name,
|
|
1519
|
+
options(input) {
|
|
1520
|
+
if (getEnvironment(this) !== "client") return input;
|
|
1521
|
+
return {
|
|
1522
|
+
...input,
|
|
1523
|
+
preserveEntrySignatures: input.preserveEntrySignatures ?? "allow-extension"
|
|
1524
|
+
};
|
|
1525
|
+
},
|
|
1526
|
+
async buildStart(input) {
|
|
1527
|
+
if (!root) root = internalOptions.rootDir ?? input.cwd;
|
|
1528
|
+
clientSymbolEntrySources.clear();
|
|
1529
|
+
virtualModules.clear();
|
|
1530
|
+
transformManifests.clear();
|
|
1531
|
+
sourceVirtualModules.clear();
|
|
1532
|
+
executionLogEstimatedSizes.clear();
|
|
1533
|
+
dev.reset();
|
|
1534
|
+
const currentRoot = getRoot();
|
|
1535
|
+
if (getEnvironment(this) === "client") for (const source of clientSymbolEntries(input.input, currentRoot)) clientSymbolEntrySources.add(source);
|
|
1536
|
+
},
|
|
1537
|
+
outputOptions(output) {
|
|
1538
|
+
return outputDefaults(output, getEnvironment(this));
|
|
1539
|
+
},
|
|
1540
|
+
async resolveId(source, importer) {
|
|
1541
|
+
if (source.startsWith("@markless/web/fns/")) {
|
|
1542
|
+
const resolved = import.meta.resolve(source);
|
|
1543
|
+
if (resolved?.startsWith("file://")) return { id: decodeURIComponent(resolved.slice(7)) };
|
|
1544
|
+
}
|
|
1545
|
+
if (source.startsWith("@markless/web/inline/")) {
|
|
1546
|
+
const resolvedRoot = import.meta.resolve("@markless/web");
|
|
1547
|
+
if (resolvedRoot?.startsWith("file://") && resolvedRoot.endsWith("/index.ts")) {
|
|
1548
|
+
const helperPath = source.slice(14);
|
|
1549
|
+
return { id: decodeURIComponent(resolvedRoot.slice(7, -8) + `${helperPath}.ts`) };
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
const normalized = normalizeVirtualId(source);
|
|
1553
|
+
if (normalized === "virtual:markless:dev-log") return {
|
|
1554
|
+
id: resolveVirtualId(MARKLESS_EXECUTION_LOG_MODULE_ID),
|
|
1555
|
+
moduleSideEffects: true
|
|
1556
|
+
};
|
|
1557
|
+
if (virtualModules.has(normalized)) return {
|
|
1558
|
+
id: resolveVirtualId(normalized),
|
|
1559
|
+
moduleSideEffects: true
|
|
1560
|
+
};
|
|
1561
|
+
const symbolSource = sourceForSymbolVirtualImporter(importer);
|
|
1562
|
+
if (symbolSource && isRelativeImport(source)) return await this.resolve(source, symbolSource, { skipSelf: true });
|
|
1563
|
+
const resumeSource = sourceForResumeVirtualImporter(importer);
|
|
1564
|
+
if (resumeSource && isRelativeImport(source)) return await this.resolve(source, resumeSource, { skipSelf: true });
|
|
1565
|
+
return null;
|
|
1566
|
+
},
|
|
1567
|
+
load(id) {
|
|
1568
|
+
if (normalizeVirtualId(id) === "virtual:markless:dev-log") return executionLogVirtualModuleSource({
|
|
1569
|
+
moduleSizes: internalOptions.dev === true && getEnvironment(this) === "client" ? executionLogEstimatedSizes : void 0,
|
|
1570
|
+
sizesUrl: internalOptions.dev === true ? void 0 : internalOptions.publicPath?.(MARKLESS_EXECUTION_SIZES) ?? `/${MARKLESS_EXECUTION_SIZES}`
|
|
1571
|
+
});
|
|
1572
|
+
const module = virtualModules.get(normalizeVirtualId(id));
|
|
1573
|
+
if (module) return virtualModuleSourceForLoad(module, {
|
|
1574
|
+
dev: internalOptions.dev === true && getEnvironment(this) === "client",
|
|
1575
|
+
publicPath: internalOptions.publicPath
|
|
1576
|
+
});
|
|
1577
|
+
return null;
|
|
1578
|
+
},
|
|
1579
|
+
async transform(code, id) {
|
|
1580
|
+
const currentEnvironment = getEnvironment(this);
|
|
1581
|
+
const virtualId = normalizeVirtualId(id);
|
|
1582
|
+
if (!TSRX_SOURCE_FILE.test(id)) {
|
|
1583
|
+
if (currentEnvironment === "client" && internalOptions.dev === true && normalizeExecutionLogMode(internalOptions.executionLog) !== "never" && isMarklessRuntimeModule(id)) {
|
|
1584
|
+
executionLogEstimatedSizes.set(executionLogRuntimeModuleId(id), code.length);
|
|
1585
|
+
return {
|
|
1586
|
+
code: injectExecutionLogModuleHook(code, executionLogRuntimeModuleId(id), internalOptions.executionLog),
|
|
1587
|
+
map: null
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
return null;
|
|
1591
|
+
}
|
|
1592
|
+
if (virtualId.startsWith("virtual:markless:")) return null;
|
|
1593
|
+
const source = pathname(id);
|
|
1594
|
+
clearSourceVirtualModules(source, virtualModules, sourceVirtualModules);
|
|
1595
|
+
const transformed = await transformTsrxModule({
|
|
1596
|
+
filename: source,
|
|
1597
|
+
source: code,
|
|
1598
|
+
buildId: internalOptions.buildId,
|
|
1599
|
+
executionLog: normalizeExecutionLogMode(internalOptions.executionLog),
|
|
1600
|
+
executionLogModuleHooks: internalOptions.dev === true && currentEnvironment === "client",
|
|
1601
|
+
environment: currentEnvironment,
|
|
1602
|
+
clientOutput: currentEnvironment === "client" && (clientSymbolEntrySources.has(source) || isSymbolOnlySourceRequest(id)) ? "symbols-only" : void 0,
|
|
1603
|
+
resumeModuleUrl: internalOptions.dev === true && currentEnvironment === "server" ? devBrowserSourceModuleUrl(source, getRoot(), internalOptions.publicPath) : void 0,
|
|
1604
|
+
headInjections: internalOptions.dev === true && currentEnvironment === "server" ? internalOptions.devInjections : void 0,
|
|
1605
|
+
devResumeReexport: internalOptions.dev === true && currentEnvironment === "client"
|
|
1606
|
+
});
|
|
1607
|
+
registerTransformArtifacts({
|
|
1608
|
+
source,
|
|
1609
|
+
result: transformed,
|
|
1610
|
+
virtualModules,
|
|
1611
|
+
transformManifests,
|
|
1612
|
+
sourceVirtualModules,
|
|
1613
|
+
executionLogEstimatedSizes,
|
|
1614
|
+
dev,
|
|
1615
|
+
environment: currentEnvironment
|
|
1616
|
+
});
|
|
1617
|
+
if (currentEnvironment === "client" && isResumeSourceRequest(id)) {
|
|
1618
|
+
const resumeModule = transformed.virtualModules.find((module) => module.type === "resume");
|
|
1619
|
+
if (resumeModule) return {
|
|
1620
|
+
code: resumeModule.source,
|
|
1621
|
+
map: null
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
if (currentEnvironment === "client" && !internalOptions.dev) for (const module of transformed.virtualModules.filter((item) => item.type === "symbol" || item.type === "resume" && internalOptions.emitResumeModules === true && clientSymbolEntrySources.has(source))) this.emitFile({
|
|
1625
|
+
type: "chunk",
|
|
1626
|
+
id: module.id,
|
|
1627
|
+
preserveSignature: "strict"
|
|
1628
|
+
});
|
|
1629
|
+
return transformed;
|
|
1630
|
+
},
|
|
1631
|
+
generateBundle: {
|
|
1632
|
+
order: "post",
|
|
1633
|
+
async handler(_, bundle) {
|
|
1634
|
+
if (getEnvironment(this) !== "client") return;
|
|
1635
|
+
stripEmptyPreloadWrappersFromChunks(bundle);
|
|
1636
|
+
const removedSymbolFacades = rewriteGeneratedSymbolFacadeImports(bundle);
|
|
1637
|
+
rewriteGeneratedSymbolInitExports(bundle);
|
|
1638
|
+
compactGeneratedDirectSymbolLoaders(bundle);
|
|
1639
|
+
const manifestBundle = bundleWithoutRemovedChunks(bundle, removedSymbolFacades);
|
|
1640
|
+
const tableRewrite = rewriteGeneratedSymbolTableUrls(manifestBundle);
|
|
1641
|
+
if (tableRewrite.unresolved.length > 0) this.error(`Markless symbol resolver table contains unresolved generated symbol chunks: ${tableRewrite.unresolved.join(", ")}`);
|
|
1642
|
+
const clientManifest = createBuildMetadata(manifestBundle, transformManifests.values(), getRoot(), {
|
|
1643
|
+
bundleGraphAsset: MARKLESS_BUNDLE_GRAPH,
|
|
1644
|
+
bundleGraphAdders: internalOptions.bundleGraphAdders,
|
|
1645
|
+
canonPath: stripBuildPrefix,
|
|
1646
|
+
publicPath: internalOptions.publicPath,
|
|
1647
|
+
injections: internalOptions.devInjections
|
|
1648
|
+
});
|
|
1649
|
+
const executionLogInjection = executionLogActivationInjection(internalOptions.executionLog);
|
|
1650
|
+
if (executionLogInjection) injectHeadLinks(bundle, [executionLogInjection]);
|
|
1651
|
+
injectHeadLinks(bundle, collectModulePreloadInjections(clientManifest, {
|
|
1652
|
+
publicPath: internalOptions.publicPath,
|
|
1653
|
+
entryChunks: Object.values(bundle).filter((output) => !!output && typeof output === "object" && output.type === "chunk" && output.isEntry === true).map((chunk) => stripBuildPrefix(chunk.fileName))
|
|
1654
|
+
}));
|
|
1655
|
+
this.emitFile({
|
|
1656
|
+
type: "asset",
|
|
1657
|
+
fileName: MARKLESS_BUNDLE_GRAPH,
|
|
1658
|
+
source: JSON.stringify(clientManifest.bundleGraph)
|
|
1659
|
+
});
|
|
1660
|
+
this.emitFile(await createExecutionSizesAsset(manifestBundle, clientManifest, stripBuildPrefix));
|
|
1661
|
+
this.emitFile({
|
|
1662
|
+
type: "asset",
|
|
1663
|
+
fileName: `${MARKLESS_BUILD_PREFIX}execution-demand.json`,
|
|
1664
|
+
source: JSON.stringify(Object.fromEntries(clientManifest.modules.filter((module) => module.runtimeDemandMap).map((module) => [module.source, module.runtimeDemandMap])))
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1670
|
+
function bundleWithoutRemovedChunks(bundle, removedFileNames) {
|
|
1671
|
+
if (removedFileNames.size === 0) return bundle;
|
|
1672
|
+
const next = {};
|
|
1673
|
+
for (const [key, output] of Object.entries(bundle)) {
|
|
1674
|
+
if (isChunkFile(output) && removedFileNames.has(output.fileName)) continue;
|
|
1675
|
+
next[key] = output;
|
|
1676
|
+
}
|
|
1677
|
+
return next;
|
|
1678
|
+
}
|
|
1679
|
+
function stripEmptyPreloadWrappersFromChunks(bundle) {
|
|
1680
|
+
for (const output of Object.values(bundle)) {
|
|
1681
|
+
if (!isChunkWithCode(output)) continue;
|
|
1682
|
+
const nextCode = stripEmptyVitePreloadWrappers(output.code);
|
|
1683
|
+
if (nextCode !== output.code) output.code = nextCode;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
function isChunkFile(output) {
|
|
1687
|
+
if (!output || typeof output !== "object") return false;
|
|
1688
|
+
const chunk = output;
|
|
1689
|
+
return chunk.type === "chunk" && typeof chunk.fileName === "string";
|
|
1690
|
+
}
|
|
1691
|
+
function isChunkWithCode(output) {
|
|
1692
|
+
if (!output || typeof output !== "object") return false;
|
|
1693
|
+
const chunk = output;
|
|
1694
|
+
return chunk.type === "chunk" && typeof chunk.code === "string";
|
|
1695
|
+
}
|
|
1696
|
+
function pluginName(environment) {
|
|
1697
|
+
if (typeof environment === "function") return "markless:rolldown";
|
|
1698
|
+
return `markless:rolldown:${environment}`;
|
|
1699
|
+
}
|
|
1700
|
+
function registerTransformArtifacts(input) {
|
|
1701
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1702
|
+
for (const module of input.result.virtualModules) {
|
|
1703
|
+
const isClientSymbol = input.environment === "client" && module.type === "symbol";
|
|
1704
|
+
const stored = isClientSymbol ? {
|
|
1705
|
+
...module,
|
|
1706
|
+
source: requalifyExecutionLogModuleHook(module.source, module.id)
|
|
1707
|
+
} : module;
|
|
1708
|
+
input.virtualModules.set(module.id, stored);
|
|
1709
|
+
ids.add(module.id);
|
|
1710
|
+
if (isClientSymbol) input.executionLogEstimatedSizes.set(module.id, stored.source.length);
|
|
1711
|
+
}
|
|
1712
|
+
input.transformManifests.set(input.source, input.result.manifest);
|
|
1713
|
+
input.sourceVirtualModules.set(input.source, ids);
|
|
1714
|
+
input.dev.record(input.source, ids, input.environment);
|
|
1715
|
+
}
|
|
1716
|
+
function clearSourceVirtualModules(source, virtualModules, sourceVirtualModules) {
|
|
1717
|
+
const stale = sourceVirtualModules.get(source);
|
|
1718
|
+
if (!stale) return;
|
|
1719
|
+
for (const id of stale) virtualModules.delete(id);
|
|
1720
|
+
sourceVirtualModules.delete(source);
|
|
1721
|
+
}
|
|
1722
|
+
function stripBuildPrefix(fileName) {
|
|
1723
|
+
return fileName.startsWith(MARKLESS_BUILD_PREFIX) ? fileName.slice(MARKLESS_BUILD_PREFIX.length) : fileName;
|
|
1724
|
+
}
|
|
1725
|
+
function virtualModuleSourceForLoad(module, options) {
|
|
1726
|
+
if (!options.dev || module.type !== "resolver") return module.source;
|
|
1727
|
+
if (!module.source.includes("moduleUrls[row[0]]")) return module.source;
|
|
1728
|
+
return module.source.replace(SYMBOL_VIRTUAL_STRING_RE, (_match, _quote, virtualId) => JSON.stringify(devBrowserVirtualModuleUrl(virtualId, options.publicPath)));
|
|
1729
|
+
}
|
|
1730
|
+
function devBrowserSourceModuleUrl(source, _root, publicPath) {
|
|
1731
|
+
const path = withQuery(joinURL("@fs", withoutLeadingSlash(source)), { import: null });
|
|
1732
|
+
return publicPath ? publicPath(path) : joinURL("/", path);
|
|
1733
|
+
}
|
|
1734
|
+
function devBrowserVirtualModuleUrl(virtualId, publicPath) {
|
|
1735
|
+
const path = joinURL("@id", resolveVirtualId(virtualId).replace("\0", "__x00__"));
|
|
1736
|
+
return publicPath ? publicPath(path) : joinURL("/", path);
|
|
1737
|
+
}
|
|
1738
|
+
function clientSymbolEntries(input, root) {
|
|
1739
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return [];
|
|
1740
|
+
const sources = [];
|
|
1741
|
+
for (const [name, value] of Object.entries(input)) {
|
|
1742
|
+
if (!/symbol/i.test(name)) continue;
|
|
1743
|
+
for (const entry of inputEntryValues(value)) if (typeof entry === "string" && TSRX_SOURCE_FILE.test(entry)) sources.push(normalizeInputSource(entry, root));
|
|
1744
|
+
}
|
|
1745
|
+
return sources;
|
|
1746
|
+
}
|
|
1747
|
+
function inputEntryValues(value) {
|
|
1748
|
+
return Array.isArray(value) ? value.flatMap(inputEntryValues) : [value];
|
|
1749
|
+
}
|
|
1750
|
+
function normalizeInputSource(source, root) {
|
|
1751
|
+
const path = pathname(source);
|
|
1752
|
+
if (isAbsolute(path)) return path;
|
|
1753
|
+
return pathname(resolve(root ?? "", path));
|
|
1754
|
+
}
|
|
1755
|
+
function isSymbolOnlySourceRequest(id) {
|
|
1756
|
+
return MARKLESS_SYMBOL_SOURCE_QUERY_RE.test(id);
|
|
1757
|
+
}
|
|
1758
|
+
function isResumeSourceRequest(id) {
|
|
1759
|
+
return MARKLESS_RESUME_SOURCE_QUERY_RE.test(id);
|
|
1760
|
+
}
|
|
1761
|
+
function sourceForSymbolVirtualImporter(importer) {
|
|
1762
|
+
if (!importer) return null;
|
|
1763
|
+
return symbolVirtualModuleSourceFile(normalizeVirtualId(importer));
|
|
1764
|
+
}
|
|
1765
|
+
function sourceForResumeVirtualImporter(importer) {
|
|
1766
|
+
if (!importer) return null;
|
|
1767
|
+
const match = normalizeVirtualId(importer).match(RESUME_VIRTUAL_ID_RE);
|
|
1768
|
+
return match?.[1] ? decodeURIComponent(match[1]) : null;
|
|
1769
|
+
}
|
|
1770
|
+
function isRelativeImport(source) {
|
|
1771
|
+
return source.startsWith("./") || source.startsWith("../");
|
|
1772
|
+
}
|
|
1773
|
+
function isMarklessRuntimeModule(id) {
|
|
1774
|
+
const path = pathname(id);
|
|
1775
|
+
return /[/\\](?:web|runtime|serializer)[/\\]src[/\\].+\.ts$/.test(path);
|
|
1776
|
+
}
|
|
1777
|
+
function executionLogRuntimeModuleId(id) {
|
|
1778
|
+
const path = pathname(id);
|
|
1779
|
+
const match = path.match(/[/\\](web|runtime|serializer)[/\\]src[/\\]([^?#]+)\.ts$/);
|
|
1780
|
+
return match ? `${match[1]}:${match[2].replace(/[/\\]/g, "/")}` : path;
|
|
1781
|
+
}
|
|
1782
|
+
function normalizeVirtualId(id) {
|
|
1783
|
+
const bare = id.startsWith("\0") ? id.slice(1) : id;
|
|
1784
|
+
if (!bare.startsWith("virtual:markless:")) return bare;
|
|
1785
|
+
const queryIndex = bare.indexOf("?");
|
|
1786
|
+
return `${MARKLESS_VIRTUAL_PREFIX}${(queryIndex === -1 ? bare : bare.slice(0, queryIndex)).slice(MARKLESS_VIRTUAL_PREFIX.length).split(":").map((segment) => {
|
|
1787
|
+
try {
|
|
1788
|
+
return encodeURIComponent(decodeURIComponent(segment));
|
|
1789
|
+
} catch {
|
|
1790
|
+
return segment;
|
|
1791
|
+
}
|
|
1792
|
+
}).join(":")}`;
|
|
1793
|
+
}
|
|
1794
|
+
function resolveVirtualId(id) {
|
|
1795
|
+
if (id.startsWith("\0")) return id;
|
|
1796
|
+
return `\0${id}`;
|
|
1797
|
+
}
|
|
1798
|
+
function pathname(id) {
|
|
1799
|
+
return parsePath(id).pathname;
|
|
1800
|
+
}
|
|
1801
|
+
//#endregion
|
|
1802
|
+
export { transformTsrxModule as a, convertManifestToBundleGraph as c, marklessServer as i, createPreloadGraphAdder as l, marklessClient as n, createBuildMetadata as o, marklessLib as r, collectHeadLinkInjections as s, createMarklessRolldownPlugin as t };
|