@vite-hub/bundle 0.0.0 → 0.3.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 +201 -0
- package/README.md +92 -0
- package/dist/cli-DdzHN8li.js +334 -0
- package/dist/cli-ubYJpAL_.d.ts +163 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.js +3 -0
- package/dist/compare-B-xpyN4Y.js +1796 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +16 -0
- package/dist/types-DBa_sXqC.d.ts +239 -0
- package/dist/vite.d.ts +84 -0
- package/dist/vite.js +294 -0
- package/package.json +78 -1
|
@@ -0,0 +1,1796 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, posix, relative, resolve } from "node:path";
|
|
3
|
+
import { createConsoleReporter, defineDiagnostics } from "nostics";
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/files.ts
|
|
6
|
+
/** Folder of the environment reports, relative to the project root. */
|
|
7
|
+
const bundleReportDir = ".vitehub/bundle";
|
|
8
|
+
const bundleReportRootFile = ".vitehub/bundle-root.json";
|
|
9
|
+
/** Finds the last build's report root without loading its configuration. */
|
|
10
|
+
function readBundleReportRoot(root) {
|
|
11
|
+
try {
|
|
12
|
+
const value = JSON.parse(readFileSync(join(root, bundleReportRootFile), "utf8"));
|
|
13
|
+
return typeof value === "string" && value ? resolve(root, value) : void 0;
|
|
14
|
+
} catch {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Relative paths keep the build reports usable when a checkout moves. */
|
|
19
|
+
function writeBundleReportRoot(root, reportRoot) {
|
|
20
|
+
const file = join(root, bundleReportRootFile);
|
|
21
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
22
|
+
writeFileSync(file, `${JSON.stringify(relative(root, reportRoot) || ".")}\n`);
|
|
23
|
+
}
|
|
24
|
+
function isReport(value) {
|
|
25
|
+
return typeof value === "object" && value !== null && Reflect.get(value, "schemaVersion") === 1 && typeof Reflect.get(value, "build") === "string" && typeof Reflect.get(value, "environment") === "string" && Array.isArray(Reflect.get(value, "chunks"));
|
|
26
|
+
}
|
|
27
|
+
/** Reads every environment report in `.vitehub/bundle/`. A file that is not a report is skipped. */
|
|
28
|
+
function readEnvironmentReports(root) {
|
|
29
|
+
return readEnvironmentReportFolder(join(root, bundleReportDir));
|
|
30
|
+
}
|
|
31
|
+
/** Reads every environment report in `dir`, such as a copy of `.vitehub/bundle/`. */
|
|
32
|
+
function readEnvironmentReportFolder(dir) {
|
|
33
|
+
let files;
|
|
34
|
+
try {
|
|
35
|
+
files = readdirSync(dir).filter((file) => file.endsWith(".json"));
|
|
36
|
+
} catch {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
return files.flatMap((file) => {
|
|
40
|
+
try {
|
|
41
|
+
const value = JSON.parse(readFileSync(join(dir, file), "utf8"));
|
|
42
|
+
return isReport(value) ? [value] : [];
|
|
43
|
+
} catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** Writes the report of one environment and removes the reports of older builds. */
|
|
49
|
+
function writeEnvironmentReport(root, report) {
|
|
50
|
+
const dir = join(root, bundleReportDir);
|
|
51
|
+
mkdirSync(dir, { recursive: true });
|
|
52
|
+
for (const old of readEnvironmentReports(root)) if (old.build !== report.build) rmSync(join(dir, `${old.environment}.json`), { force: true });
|
|
53
|
+
writeFileSync(join(dir, `${report.environment}.json`), `${JSON.stringify(report)}\n`);
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/bytes.ts
|
|
57
|
+
/** Splits file bytes proportionally, carrying rounding between shares so their sum stays exact. */
|
|
58
|
+
function allocateBytes(weights, bytes) {
|
|
59
|
+
const total = weights.reduce((sum, weight) => sum + weight, 0);
|
|
60
|
+
let weightSoFar = 0;
|
|
61
|
+
let allocated = 0;
|
|
62
|
+
return weights.map((weight) => {
|
|
63
|
+
weightSoFar += weight;
|
|
64
|
+
const next = total === 0 ? 0 : Math.round(weightSoFar * bytes / total);
|
|
65
|
+
const share = next - allocated;
|
|
66
|
+
allocated = next;
|
|
67
|
+
return share;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** `1234567` becomes `1.23 MB`, like Vite's build output. */
|
|
71
|
+
function formatBytes(bytes) {
|
|
72
|
+
if (bytes >= 1e6) return `${(bytes / 1e6).toFixed(2)} MB`;
|
|
73
|
+
if (bytes >= 1e3) return `${(bytes / 1e3).toFixed(1)} kB`;
|
|
74
|
+
return `${bytes} B`;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/diagnostics.ts
|
|
78
|
+
/** The largest Worker that Cloudflare accepts, before compression. */
|
|
79
|
+
const cloudflareWorkerSizeLimit = 67108864;
|
|
80
|
+
const bundleDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
81
|
+
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
82
|
+
codes: {
|
|
83
|
+
BUNDLE_STARTUP_UNUSED: {
|
|
84
|
+
why: ({ packages, reason }) => `${packages.map((item) => `\`${item.name}\` (${formatBytes(item.bytes)})`).join(", ")} ${packages.length === 1 ? "loads" : "load"} at server startup. ${reason}`,
|
|
85
|
+
fix: ({ fix, target }) => `${fix} Run \`vitehub bundle why ${target}\` for the import chain.`
|
|
86
|
+
},
|
|
87
|
+
BUNDLE_HOST_SIZE_LIMIT: {
|
|
88
|
+
why: ({ bytes, limit }) => `The server JavaScript is ${formatBytes(bytes)} before compression. Cloudflare rejects a Worker over ${formatBytes(limit)} (64 MiB), and the deployment also counts files other than JavaScript.`,
|
|
89
|
+
fix: "Keep large data and binary files in KV, R2, D1, or static assets, not in server code. Import large packages with `import()` in the routes that use them. `vitehub bundle` lists the largest groups."
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/groups.ts
|
|
95
|
+
const frameworkPackages = /* @__PURE__ */ new Set([
|
|
96
|
+
"@unhead/vue",
|
|
97
|
+
"nuxt-nightly",
|
|
98
|
+
"@vue/reactivity",
|
|
99
|
+
"@vue/runtime-core",
|
|
100
|
+
"@vue/runtime-dom",
|
|
101
|
+
"@vue/server-renderer",
|
|
102
|
+
"@vue/shared",
|
|
103
|
+
"crossws",
|
|
104
|
+
"h3",
|
|
105
|
+
"nitro",
|
|
106
|
+
"nuxt",
|
|
107
|
+
"ocache",
|
|
108
|
+
"rou3",
|
|
109
|
+
"srvx",
|
|
110
|
+
"unhead",
|
|
111
|
+
"vue",
|
|
112
|
+
"vue-router"
|
|
113
|
+
]);
|
|
114
|
+
/** The root-relative id of a module. Dependencies become `node_modules/<package>/<file>`, wherever pnpm stores them. */
|
|
115
|
+
function moduleId(id, root, packages = /* @__PURE__ */ new Map()) {
|
|
116
|
+
const clean = id.replace(/\\/g, "/").replace(/\?.*$/, "").replace(/^\0/, "");
|
|
117
|
+
const rootPath = root.replace(/\\/g, "/").replace(/\/$/, "");
|
|
118
|
+
const nuxtTemplate = clean.match(/^virtual:nuxt:(.+)$/);
|
|
119
|
+
if (nuxtTemplate) return moduleId(decodeURIComponent(nuxtTemplate[1]), rootPath, packages);
|
|
120
|
+
const windows = /^[a-z]:\//i.test(clean);
|
|
121
|
+
if (!clean.startsWith("/") && !windows) return clean;
|
|
122
|
+
const nodeModules = clean.lastIndexOf("/node_modules/");
|
|
123
|
+
if (nodeModules >= 0) {
|
|
124
|
+
const rest = clean.slice(nodeModules + 14);
|
|
125
|
+
if (!rest.startsWith(".")) return `node_modules/${rest}`;
|
|
126
|
+
}
|
|
127
|
+
const withinRoot = windows ? clean.toLowerCase().startsWith(`${rootPath.toLowerCase()}/`) : clean.startsWith(`${rootPath}/`);
|
|
128
|
+
if (!withinRoot) {
|
|
129
|
+
let dir = posix.dirname(clean);
|
|
130
|
+
while (dir !== ".") {
|
|
131
|
+
if (!packages.has(dir)) {
|
|
132
|
+
let name;
|
|
133
|
+
try {
|
|
134
|
+
const manifest = JSON.parse(readFileSync(`${dir}/package.json`, "utf8"));
|
|
135
|
+
if (manifest && typeof manifest === "object" && typeof Reflect.get(manifest, "name") === "string") name = Reflect.get(manifest, "name");
|
|
136
|
+
} catch {}
|
|
137
|
+
packages.set(dir, name);
|
|
138
|
+
}
|
|
139
|
+
const name = packages.get(dir);
|
|
140
|
+
if (name) return `node_modules/${name}/${posix.relative(dir, clean)}`;
|
|
141
|
+
const parent = posix.dirname(dir);
|
|
142
|
+
if (parent === dir) break;
|
|
143
|
+
dir = parent;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return withinRoot ? clean.slice(rootPath.length + 1) : clean;
|
|
147
|
+
}
|
|
148
|
+
function packageName(path) {
|
|
149
|
+
const parts = path.split("/");
|
|
150
|
+
return parts[0].startsWith("@") ? `${parts[0]}/${parts[1]}` : parts[0];
|
|
151
|
+
}
|
|
152
|
+
/** Names the group of a root-relative module id. */
|
|
153
|
+
function moduleGroup(id) {
|
|
154
|
+
if (id.startsWith("node_modules/")) {
|
|
155
|
+
const rest = id.slice(13);
|
|
156
|
+
if (rest.startsWith(".")) return {
|
|
157
|
+
name: rest.includes("/.nuxt/") ? ".nuxt" : `node_modules/${packageName(rest)}`,
|
|
158
|
+
kind: "generated"
|
|
159
|
+
};
|
|
160
|
+
const name = packageName(rest);
|
|
161
|
+
if (name === "vite-hub") {
|
|
162
|
+
const feature = rest.split("/")[2]?.replace(/\.js$/, "").replace(/-[\w-]{8}$/, "");
|
|
163
|
+
return {
|
|
164
|
+
name: feature && feature !== "index" ? `vite-hub/${feature}` : "vite-hub",
|
|
165
|
+
kind: "vitehub"
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
if (name.startsWith("@vite-hub/")) return {
|
|
169
|
+
name,
|
|
170
|
+
kind: "vitehub"
|
|
171
|
+
};
|
|
172
|
+
if (frameworkPackages.has(name) || name.startsWith("@nuxt/") || name.startsWith("@unhead/")) return {
|
|
173
|
+
name,
|
|
174
|
+
kind: "framework"
|
|
175
|
+
};
|
|
176
|
+
return {
|
|
177
|
+
name,
|
|
178
|
+
kind: "dependency"
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (id.startsWith("#")) return {
|
|
182
|
+
name: id.split("/").slice(0, 2).join("/"),
|
|
183
|
+
kind: "generated"
|
|
184
|
+
};
|
|
185
|
+
if (id.startsWith("/") || /^[a-z]:\//i.test(id)) return {
|
|
186
|
+
name: "outside the project",
|
|
187
|
+
kind: "dependency"
|
|
188
|
+
};
|
|
189
|
+
if (/^[\w-]+:/.test(id)) return {
|
|
190
|
+
name: id.split("/")[0],
|
|
191
|
+
kind: "generated"
|
|
192
|
+
};
|
|
193
|
+
if (!id.includes("/") && !id.includes(".")) return {
|
|
194
|
+
name: "virtual",
|
|
195
|
+
kind: "generated"
|
|
196
|
+
};
|
|
197
|
+
const top = id.split("/")[0];
|
|
198
|
+
if (top === ".vitehub" || top === ".nuxt" || top === ".nitro" || top === ".output") return {
|
|
199
|
+
name: top,
|
|
200
|
+
kind: "generated"
|
|
201
|
+
};
|
|
202
|
+
const parts = id.split("/");
|
|
203
|
+
return {
|
|
204
|
+
name: parts.length > 2 ? parts.slice(0, 2).join("/") : parts[0],
|
|
205
|
+
kind: "app"
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/checks.ts
|
|
210
|
+
function finding(code, diagnostic, rest) {
|
|
211
|
+
return {
|
|
212
|
+
code,
|
|
213
|
+
severity: rest.severity,
|
|
214
|
+
side: rest.side,
|
|
215
|
+
why: diagnostic.why,
|
|
216
|
+
fix: diagnostic.fix ?? "",
|
|
217
|
+
docs: diagnostic.docs ?? "",
|
|
218
|
+
bytes: rest.bytes,
|
|
219
|
+
chain: rest.chain
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function serverChain(explain, target) {
|
|
223
|
+
return explain(target).find((explanation) => explanation.side === "server")?.chain ?? [];
|
|
224
|
+
}
|
|
225
|
+
/** Each rule once, also when several server environments carry it. */
|
|
226
|
+
function uniqueRules(reports) {
|
|
227
|
+
const rules = /* @__PURE__ */ new Map();
|
|
228
|
+
for (const report of reports) for (const rule of report.side === "server" ? report.rules ?? [] : []) rules.set(JSON.stringify(rule), rule);
|
|
229
|
+
return [...rules.values()];
|
|
230
|
+
}
|
|
231
|
+
/** A feature's configuration says nothing about independent consumers of the same packages. */
|
|
232
|
+
function exclusivelyOwned(reports, rule) {
|
|
233
|
+
let ownedImport = false;
|
|
234
|
+
for (const report of reports) {
|
|
235
|
+
if (report.side !== "server") continue;
|
|
236
|
+
for (const chunk of report.chunks) for (const module of chunk.modules) {
|
|
237
|
+
const group = moduleGroup(module.id).name;
|
|
238
|
+
if (module.entry && rule.packages.includes(group)) return false;
|
|
239
|
+
for (const target of [...module.imports, ...module.dynamicImports]) {
|
|
240
|
+
if (!rule.packages.includes(moduleGroup(target).name)) continue;
|
|
241
|
+
if (group === rule.owner) ownedImport = true;
|
|
242
|
+
else if (!rule.packages.includes(group)) return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return ownedImport;
|
|
247
|
+
}
|
|
248
|
+
/** A package that a feature declared as not needed at startup, and that loads at startup. */
|
|
249
|
+
function startupUnused(server, rules, explain) {
|
|
250
|
+
return rules.flatMap((rule) => {
|
|
251
|
+
const packages = server.groups.filter((group) => rule.packages.includes(group.name) && group.startupBytes > 0).map((group) => ({
|
|
252
|
+
name: group.name,
|
|
253
|
+
bytes: group.startupBytes
|
|
254
|
+
})).sort((left, right) => right.bytes - left.bytes);
|
|
255
|
+
if (!packages.length) return [];
|
|
256
|
+
const target = rule.packages.find((name) => packages.some((item) => item.name === name));
|
|
257
|
+
return [finding("BUNDLE_STARTUP_UNUSED", bundleDiagnostics.BUNDLE_STARTUP_UNUSED({
|
|
258
|
+
packages,
|
|
259
|
+
reason: rule.why,
|
|
260
|
+
fix: rule.fix,
|
|
261
|
+
target
|
|
262
|
+
}), {
|
|
263
|
+
severity: "warning",
|
|
264
|
+
side: "server",
|
|
265
|
+
bytes: packages.reduce((sum, item) => sum + item.bytes, 0),
|
|
266
|
+
chain: serverChain(explain, target)
|
|
267
|
+
})];
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/** Server output over the size that the host accepts. */
|
|
271
|
+
function hostSizeLimit(server, host, explain) {
|
|
272
|
+
if (!host?.startsWith("cloudflare") || server.bytes <= 67108864) return [];
|
|
273
|
+
const largest = server.groups[0];
|
|
274
|
+
return [finding("BUNDLE_HOST_SIZE_LIMIT", bundleDiagnostics.BUNDLE_HOST_SIZE_LIMIT({
|
|
275
|
+
bytes: server.bytes,
|
|
276
|
+
limit: cloudflareWorkerSizeLimit
|
|
277
|
+
}), {
|
|
278
|
+
severity: "error",
|
|
279
|
+
side: "server",
|
|
280
|
+
bytes: server.bytes,
|
|
281
|
+
chain: largest ? serverChain(explain, largest.name) : []
|
|
282
|
+
})];
|
|
283
|
+
}
|
|
284
|
+
/** The checks that the report of one build proves. Only certain problems, no guesses. */
|
|
285
|
+
function checkBundle(reports, server, host, explain) {
|
|
286
|
+
if (!server) return [];
|
|
287
|
+
return [...hostSizeLimit(server, host, explain), ...startupUnused(server, uniqueRules(reports).filter((rule) => exclusivelyOwned(reports, rule)), explain)];
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @vue/shared v3.5.44
|
|
291
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
292
|
+
* @license MIT
|
|
293
|
+
**/
|
|
294
|
+
/**
|
|
295
|
+
* @vue/shared v3.5.44
|
|
296
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
297
|
+
* @license MIT
|
|
298
|
+
**/
|
|
299
|
+
/**
|
|
300
|
+
* @vue/compiler-core v3.5.44
|
|
301
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
302
|
+
* @license MIT
|
|
303
|
+
**/
|
|
304
|
+
/**
|
|
305
|
+
* @vue/compiler-core v3.5.44
|
|
306
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
307
|
+
* @license MIT
|
|
308
|
+
**/
|
|
309
|
+
/**
|
|
310
|
+
* @vue/compiler-dom v3.5.44
|
|
311
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
312
|
+
* @license MIT
|
|
313
|
+
**/
|
|
314
|
+
/**
|
|
315
|
+
* @vue/compiler-dom v3.5.44
|
|
316
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
317
|
+
* @license MIT
|
|
318
|
+
**/
|
|
319
|
+
/**
|
|
320
|
+
* @vue/reactivity v3.5.44
|
|
321
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
322
|
+
* @license MIT
|
|
323
|
+
**/
|
|
324
|
+
/**
|
|
325
|
+
* @vue/reactivity v3.5.44
|
|
326
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
327
|
+
* @license MIT
|
|
328
|
+
**/
|
|
329
|
+
/**
|
|
330
|
+
* @vue/runtime-core v3.5.44
|
|
331
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
332
|
+
* @license MIT
|
|
333
|
+
**/
|
|
334
|
+
/**
|
|
335
|
+
* @vue/runtime-core v3.5.44
|
|
336
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
337
|
+
* @license MIT
|
|
338
|
+
**/
|
|
339
|
+
/**
|
|
340
|
+
* @vue/runtime-dom v3.5.44
|
|
341
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
342
|
+
* @license MIT
|
|
343
|
+
**/
|
|
344
|
+
/**
|
|
345
|
+
* @vue/runtime-dom v3.5.44
|
|
346
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
347
|
+
* @license MIT
|
|
348
|
+
**/
|
|
349
|
+
/**
|
|
350
|
+
* vue v3.5.44
|
|
351
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
352
|
+
* @license MIT
|
|
353
|
+
**/
|
|
354
|
+
/**
|
|
355
|
+
* vue v3.5.44
|
|
356
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
357
|
+
* @license MIT
|
|
358
|
+
**/
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region ../../node_modules/.pnpm/vue-router@5.4.0_@voidzero-dev+vite-plus-core@0.3.3_@types+node@24.19.1_esbuild@0.28.2__771eab81e2fd06a479763e79bcb19884/node_modules/vue-router/dist/useApi-CUWMwLLw.js
|
|
361
|
+
/*!
|
|
362
|
+
* vue-router v5.4.0
|
|
363
|
+
* (c) 2026 Eduardo San Martin Morote
|
|
364
|
+
* @license MIT
|
|
365
|
+
*/
|
|
366
|
+
/**
|
|
367
|
+
* Checks if a path is absolute, meaning it starts with a `/`.
|
|
368
|
+
*
|
|
369
|
+
* @param path - path to check
|
|
370
|
+
*
|
|
371
|
+
* @internal
|
|
372
|
+
*/
|
|
373
|
+
const isAbsolutePath = (path) => path.startsWith("/");
|
|
374
|
+
const assign = Object.assign;
|
|
375
|
+
const noop = () => {};
|
|
376
|
+
/**
|
|
377
|
+
* Typesafe alternative to Array.isArray
|
|
378
|
+
* https://github.com/microsoft/TypeScript/pull/48228
|
|
379
|
+
*
|
|
380
|
+
* @internal
|
|
381
|
+
*/
|
|
382
|
+
const isArray = Array.isArray;
|
|
383
|
+
function mergeOptions(defaults, partialOptions) {
|
|
384
|
+
const options = {};
|
|
385
|
+
for (const key in defaults) options[key] = key in partialOptions ? partialOptions[key] : defaults[key];
|
|
386
|
+
return options;
|
|
387
|
+
}
|
|
388
|
+
const NavigationFailureSymbol = Symbol(process.env.NODE_ENV !== "production" ? "navigation failure" : "");
|
|
389
|
+
const ErrorTypeMessages = {
|
|
390
|
+
[1]({ location, currentLocation }) {
|
|
391
|
+
return `No match for\n ${JSON.stringify(location)}${currentLocation ? "\nwhile being at\n" + JSON.stringify(currentLocation) : ""}`;
|
|
392
|
+
},
|
|
393
|
+
[2]({ from, to }) {
|
|
394
|
+
return `Redirected from "${from.fullPath}" to "${stringifyRoute(to)}" via a navigation guard.`;
|
|
395
|
+
},
|
|
396
|
+
[4]({ from, to }) {
|
|
397
|
+
return `Navigation aborted from "${from.fullPath}" to "${to.fullPath}" via a navigation guard.`;
|
|
398
|
+
},
|
|
399
|
+
[8]({ from, to }) {
|
|
400
|
+
return `Navigation cancelled from "${from.fullPath}" to "${to.fullPath}" with a new navigation.`;
|
|
401
|
+
},
|
|
402
|
+
[16]({ from, to: _to }) {
|
|
403
|
+
return `Avoided redundant navigation to current location: "${from.fullPath}".`;
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* Creates a typed NavigationFailure object.
|
|
408
|
+
* @internal
|
|
409
|
+
* @param type - NavigationFailureType
|
|
410
|
+
* @param params - { from, to }
|
|
411
|
+
*/
|
|
412
|
+
function createRouterError(type, params) {
|
|
413
|
+
if (process.env.NODE_ENV !== "production" || false) return assign(new Error(ErrorTypeMessages[type](params)), {
|
|
414
|
+
type,
|
|
415
|
+
[NavigationFailureSymbol]: true
|
|
416
|
+
}, params);
|
|
417
|
+
else return assign(/* @__PURE__ */ new Error(), {
|
|
418
|
+
type,
|
|
419
|
+
[NavigationFailureSymbol]: true
|
|
420
|
+
}, params);
|
|
421
|
+
}
|
|
422
|
+
const propertiesToLog = [
|
|
423
|
+
"params",
|
|
424
|
+
"query",
|
|
425
|
+
"hash"
|
|
426
|
+
];
|
|
427
|
+
/**
|
|
428
|
+
* Stringifies a raw location for display in dev warnings.
|
|
429
|
+
*
|
|
430
|
+
* @internal
|
|
431
|
+
*/
|
|
432
|
+
function stringifyRoute(to) {
|
|
433
|
+
if (!to || typeof to === "string") return to;
|
|
434
|
+
if (to.path != null) return to.path;
|
|
435
|
+
const location = {};
|
|
436
|
+
for (const key of propertiesToLog) if (key in to) location[key] = to[key];
|
|
437
|
+
return JSON.stringify(location, null, 2);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Runtime diagnostics catalog for Vue Router.
|
|
441
|
+
*
|
|
442
|
+
* Every entry has a stable `VUE_ROUTER_X####` code, a `why` that states the problem
|
|
443
|
+
* (the diagnosis only, never the remedy) and a `fix` that states the remedy
|
|
444
|
+
* (only, never the diagnosis). They are complementary: the reporter prints
|
|
445
|
+
* both, so neither repeats the other. The diagnosis substrings asserted by the
|
|
446
|
+
* warning tests stay in `why`. All call sites stay behind the existing `__DEV__` (or
|
|
447
|
+
* `process.env.NODE_ENV !== 'production'`) guards and remain bare expression
|
|
448
|
+
* statements so they tree-shake out of production builds.
|
|
449
|
+
*
|
|
450
|
+
* Codes are permanent: never rename or reuse one.
|
|
451
|
+
* - `VUE_ROUTER_R0###` core runtime warnings
|
|
452
|
+
* - `VUE_ROUTER_R1###` experimental data-loaders
|
|
453
|
+
* - `VUE_ROUTER_D0###` deprecations
|
|
454
|
+
*/
|
|
455
|
+
const diagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
456
|
+
reporters: [/*#__PURE__*/ createConsoleReporter()],
|
|
457
|
+
codes: {
|
|
458
|
+
VUE_ROUTER_R0122: {
|
|
459
|
+
why: (p) => `The optional path param "${p.param}" is being removed with ${p.value}.`,
|
|
460
|
+
fix: "Use null to remove an optional path param."
|
|
461
|
+
},
|
|
462
|
+
VUE_ROUTER_D0001: {
|
|
463
|
+
why: (p) => `Route "${p.name}" uses beforeEnter, which is deprecated in the experimental router.`,
|
|
464
|
+
fix: "Move the condition to the route meta field and check to.meta in router.beforeEach()."
|
|
465
|
+
},
|
|
466
|
+
VUE_ROUTER_D0002: {
|
|
467
|
+
why: (p) => `The query value of "${p.key}" is not an array (${p.value}). Non array query values are deprecated in the experimental router.`,
|
|
468
|
+
fix: (p) => `Wrap the value in an array: \`{ ${JSON.stringify(p.key)}: [${p.value}] }\`. Use undefined to remove the key.`
|
|
469
|
+
},
|
|
470
|
+
VUE_ROUTER_R0001: {
|
|
471
|
+
why: (p) => `Parent route "${p.name}" not found when adding child route`,
|
|
472
|
+
fix: "Add the parent route before its children, or check the parent name for typos.",
|
|
473
|
+
docs: "https://router.vuejs.org/guide/advanced/dynamic-routing.html#Adding-nested-routes"
|
|
474
|
+
},
|
|
475
|
+
VUE_ROUTER_R0002: {
|
|
476
|
+
why: (p) => `Cannot remove non-existent route "${p.name}"`,
|
|
477
|
+
fix: "Check the route name; it may already have been removed or was never added.",
|
|
478
|
+
docs: "https://router.vuejs.org/guide/advanced/dynamic-routing.html#Removing-routes"
|
|
479
|
+
},
|
|
480
|
+
VUE_ROUTER_R0003: {
|
|
481
|
+
why: (p) => `Location "${stringifyRoute(p.location)}" resolved to "${p.href}". A resolved location cannot start with multiple slashes.`,
|
|
482
|
+
fix: "Remove the leading slashes from the location or fix the route configuration."
|
|
483
|
+
},
|
|
484
|
+
VUE_ROUTER_R0004: {
|
|
485
|
+
why: (p) => `No match found for location with path "${stringifyRoute(p.path)}"`,
|
|
486
|
+
fix: "Add a route matching this path or check for typos in the location.",
|
|
487
|
+
docs: "https://router.vuejs.org/guide/essentials/dynamic-matching.html#Catch-all-404-Not-found-Route"
|
|
488
|
+
},
|
|
489
|
+
VUE_ROUTER_R0005: {
|
|
490
|
+
why: (p) => `router.resolve() was passed an invalid location. This will fail in production.\nLocation: ${stringifyRoute(p.rawLocation)}`,
|
|
491
|
+
fix: "Pass a valid route location: a string path or an object with `path` or `name`."
|
|
492
|
+
},
|
|
493
|
+
VUE_ROUTER_R0006: {
|
|
494
|
+
why: (p) => `Path "${p.path}" was passed with params but they will be ignored because a "path" was passed.`,
|
|
495
|
+
fix: "Use a named route `{ name, params }` instead of `{ path, params }`.",
|
|
496
|
+
docs: "https://router.vuejs.org/guide/essentials/navigation.html#Navigate-to-a-different-location"
|
|
497
|
+
},
|
|
498
|
+
VUE_ROUTER_R0007: {
|
|
499
|
+
why: (p) => `A \`hash\` should always start with the character "#" but received "${p.hash}".`,
|
|
500
|
+
fix: (p) => `Prepend "#" to the hash in your route location: use "#${p.hash}".`
|
|
501
|
+
},
|
|
502
|
+
VUE_ROUTER_R0008: {
|
|
503
|
+
why: (p) => `Invalid redirect found:\n${p.target}\n when navigating to "${p.to}".\nThis will break in production.`,
|
|
504
|
+
fix: "A redirect must resolve to a location with a `name` or `path`; return one of those (or a string path) from `redirect`.",
|
|
505
|
+
docs: "https://router.vuejs.org/guide/essentials/redirect-and-alias.html#Redirect"
|
|
506
|
+
},
|
|
507
|
+
VUE_ROUTER_R0009: {
|
|
508
|
+
why: (p) => `Detected a possibly infinite redirection in a navigation guard when going from "${p.from}" to "${p.to}". Aborting to avoid a Stack Overflow. This might break in production if not fixed.`,
|
|
509
|
+
fix: "A guard is returning a new location on every call; make that return conditional so it only redirects when actually needed.",
|
|
510
|
+
docs: "https://router.vuejs.org/guide/advanced/navigation-guards.html#Global-Before-Guards"
|
|
511
|
+
},
|
|
512
|
+
VUE_ROUTER_R0010: {
|
|
513
|
+
why: "Uncaught error during route navigation",
|
|
514
|
+
fix: "Register an error handler with `router.onError()` to handle navigation errors."
|
|
515
|
+
},
|
|
516
|
+
VUE_ROUTER_R0011: {
|
|
517
|
+
why: "Unexpected error when starting the router:",
|
|
518
|
+
fix: "Inspect the actual cause; a navigation guard or async component likely threw during the initial navigation."
|
|
519
|
+
},
|
|
520
|
+
VUE_ROUTER_R0020: {
|
|
521
|
+
why: (p) => `No active route record was found when calling \`${p.fn}()\`. Maybe you called it inside of App.vue?`,
|
|
522
|
+
fix: "Call it from a component rendered inside <router-view> (a page component or one of its children), not from App.vue.",
|
|
523
|
+
docs: "https://router.vuejs.org/guide/advanced/composition-api.html#Navigation-Guards"
|
|
524
|
+
},
|
|
525
|
+
VUE_ROUTER_R0021: {
|
|
526
|
+
why: "No active route record was found when reactivating component with navigation guard. This is likely a bug in vue-router.",
|
|
527
|
+
fix: "Report with a minimal reproduction at https://github.com/vuejs/router/issues/new/choose."
|
|
528
|
+
},
|
|
529
|
+
VUE_ROUTER_R0022: {
|
|
530
|
+
why: (p) => `${p.fn}() was called outside of component setup but it must be called at the top of a setup function`,
|
|
531
|
+
fix: "Call it synchronously at the top of `setup()`, before any `await`.",
|
|
532
|
+
docs: "https://router.vuejs.org/guide/advanced/composition-api.html#Navigation-Guards"
|
|
533
|
+
},
|
|
534
|
+
VUE_ROUTER_R0023: {
|
|
535
|
+
why: (p) => `The "next" callback was never called inside of ${p.name ? `"${p.name}"` : ""}:\n${p.guard}`,
|
|
536
|
+
fix: "Make sure `next()` runs on every branch, including early returns and async paths, or drop the `next` parameter and return the value instead.",
|
|
537
|
+
docs: "https://router.vuejs.org/guide/advanced/navigation-guards.html#Optional-third-argument-next"
|
|
538
|
+
},
|
|
539
|
+
VUE_ROUTER_R0024: {
|
|
540
|
+
why: (p) => `The "next" callback was called more than once in one navigation guard when going from "${p.from}" to "${p.to}". This will fail in production.`,
|
|
541
|
+
fix: "Call `next()` exactly once per guard: remove the extra call, or migrate to returning the value you passed to `next()`.",
|
|
542
|
+
docs: "https://router.vuejs.org/guide/advanced/navigation-guards.html#Optional-third-argument-next"
|
|
543
|
+
},
|
|
544
|
+
VUE_ROUTER_R0025: {
|
|
545
|
+
why: "The `next()` callback in navigation guards is deprecated.",
|
|
546
|
+
fix: "Return the value instead: `next()` becomes `return`, `next(false)` becomes `return false`, `next(\"/path\")` becomes `return \"/path\"`.",
|
|
547
|
+
docs: "https://router.vuejs.org/guide/advanced/navigation-guards.html#Optional-third-argument-next"
|
|
548
|
+
},
|
|
549
|
+
VUE_ROUTER_R0026: {
|
|
550
|
+
why: (p) => `Record with path "${p.path}" is either missing a "component(s)" or "children" property.`,
|
|
551
|
+
fix: "Add a `component`, `components`, or `children` to the route record.",
|
|
552
|
+
docs: "https://router.vuejs.org/guide/essentials/nested-routes.html"
|
|
553
|
+
},
|
|
554
|
+
VUE_ROUTER_R0027: {
|
|
555
|
+
why: (p) => `Component "${p.name}" in record with path "${p.path}" is not a valid component. Received "${p.received}".`,
|
|
556
|
+
fix: "Pass a component or a function returning a Promise that resolves to one."
|
|
557
|
+
},
|
|
558
|
+
VUE_ROUTER_R0028: {
|
|
559
|
+
why: (p) => `Component "${p.name}" in record with path "${p.path}" is a Promise instead of a function that returns a Promise. This will break in production if not fixed.`,
|
|
560
|
+
fix: `Defer the import in an arrow function so it loads lazily: write "() => import('./MyPage.vue')", not "import('./MyPage.vue')".`,
|
|
561
|
+
docs: "https://router.vuejs.org/guide/advanced/lazy-loading.html"
|
|
562
|
+
},
|
|
563
|
+
VUE_ROUTER_R0029: {
|
|
564
|
+
why: (p) => `Component "${p.name}" in record with path "${p.path}" is defined using "defineAsyncComponent()".`,
|
|
565
|
+
fix: `Drop the wrapper and pass "() => import('./MyPage.vue')" directly; the router handles lazy components itself.`,
|
|
566
|
+
docs: "https://router.vuejs.org/guide/advanced/lazy-loading.html#Relationship-to-async-components"
|
|
567
|
+
},
|
|
568
|
+
VUE_ROUTER_R0030: {
|
|
569
|
+
why: (p) => `Component "${p.name}" in record with path "${p.path}" is a function that does not return a Promise. This will break in production if not fixed.`,
|
|
570
|
+
fix: "Return a dynamic import (`() => import(\"./MyPage.vue\")`) from the function, or add a `displayName` if it is a functional component.",
|
|
571
|
+
docs: "https://router.vuejs.org/guide/advanced/lazy-loading.html"
|
|
572
|
+
},
|
|
573
|
+
VUE_ROUTER_R0040: {
|
|
574
|
+
why: (p) => `Because "${p.el}" starts with "#", scrollBehavior resolves it as an element id via document.getElementById("${p.el.slice(1)}"), not as a CSS selector. No element has that id, but "${p.el}" does match an element with document.querySelector().`,
|
|
575
|
+
fix: (p) => `Resolve the element yourself and return the node: el: document.querySelector('${p.el}').`,
|
|
576
|
+
docs: "https://router.vuejs.org/guide/advanced/scroll-behavior.html"
|
|
577
|
+
},
|
|
578
|
+
VUE_ROUTER_R0041: {
|
|
579
|
+
why: (p) => `The selector "${p.el}" is invalid. See https://mathiasbynens.be/notes/css-escapes or CSS.escape (https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape) for the escaping rules.`,
|
|
580
|
+
fix: "Build an id selector as `#${CSS.escape(id)}` so special characters in the id are escaped.",
|
|
581
|
+
docs: "https://router.vuejs.org/guide/advanced/scroll-behavior.html"
|
|
582
|
+
},
|
|
583
|
+
VUE_ROUTER_R0042: {
|
|
584
|
+
why: (p) => `Couldn't find element using selector "${p.el}" returned by scrollBehavior.`,
|
|
585
|
+
fix: "Return a selector that matches an existing element, or guard against missing elements.",
|
|
586
|
+
docs: "https://router.vuejs.org/guide/advanced/scroll-behavior.html"
|
|
587
|
+
},
|
|
588
|
+
VUE_ROUTER_R0043: {
|
|
589
|
+
why: (p) => `Several active useScrollRestoration() calls use the key "${p.key}" with different "capture" or "restore" options. They overwrite each other's saved entry.`,
|
|
590
|
+
fix: "Give each call a different \"key\", or combine them if they are in the same component."
|
|
591
|
+
},
|
|
592
|
+
VUE_ROUTER_R0044: {
|
|
593
|
+
why: "No ScrollRestoration plugin is available to useScrollRestoration().",
|
|
594
|
+
fix: "Install ScrollRestoration on the app before calling useScrollRestoration()."
|
|
595
|
+
},
|
|
596
|
+
VUE_ROUTER_R0050: {
|
|
597
|
+
why: (p) => {
|
|
598
|
+
let to;
|
|
599
|
+
try {
|
|
600
|
+
to = p.to === void 0 ? "undefined" : JSON.stringify(p.to);
|
|
601
|
+
} catch {
|
|
602
|
+
to = String(p.to);
|
|
603
|
+
}
|
|
604
|
+
return `Invalid value for prop "to" in useLink()\n- to: ${to}`;
|
|
605
|
+
},
|
|
606
|
+
fix: "Pass a valid route location (a string path or an object) to the \"to\" prop."
|
|
607
|
+
},
|
|
608
|
+
VUE_ROUTER_R0060: {
|
|
609
|
+
why: (p) => `<router-view> can no longer be used directly inside <${p.comp}>.`,
|
|
610
|
+
fix: (p) => `Wrap the slot's resolved component with <${p.comp}> instead of nesting <router-view> in it:\n\n<router-view v-slot="{ Component }">\n <${p.comp}>\n <component :is="Component" />\n </${p.comp}>\n</router-view>`,
|
|
611
|
+
docs: "https://router.vuejs.org/guide/advanced/router-view-slot.html#KeepAlive-Transition"
|
|
612
|
+
},
|
|
613
|
+
VUE_ROUTER_R0070: {
|
|
614
|
+
why: (p) => `Cannot resolve a relative location without an absolute path. Trying to resolve "${p.to}" from "${p.from}".`,
|
|
615
|
+
fix: (p) => `Resolve from an absolute \`from\` path that starts with "/", e.g. "/${p.from}".`
|
|
616
|
+
},
|
|
617
|
+
VUE_ROUTER_R0080: {
|
|
618
|
+
why: (p) => `Error decoding "${p.text}". Using original value`,
|
|
619
|
+
fix: "Ensure the value is correctly percent-encoded."
|
|
620
|
+
},
|
|
621
|
+
VUE_ROUTER_R0090: {
|
|
622
|
+
why: (p) => `Found duplicated params with name "${p.name}" for path "${p.path}". Only the last one will be available on "$route.params".`,
|
|
623
|
+
fix: "Give each param a unique name within the path.",
|
|
624
|
+
docs: "https://router.vuejs.org/guide/essentials/route-matching-syntax.html"
|
|
625
|
+
},
|
|
626
|
+
VUE_ROUTER_R0100: {
|
|
627
|
+
why: (p) => `Discarded invalid param(s) "${p.params}" when navigating.` + p.inherited + ` See https://github.com/vuejs/router/commit/e887570 for more details.`,
|
|
628
|
+
fix: "Only pass params that exist on the target route."
|
|
629
|
+
},
|
|
630
|
+
VUE_ROUTER_R0101: {
|
|
631
|
+
why: (p) => `The Matcher cannot resolve relative paths but received "${p.path}". Unless you directly called \`matcher.resolve("${p.path}")\`, this is probably a bug in vue-router. Please open an issue at https://github.com/vuejs/router/issues/new/choose.`,
|
|
632
|
+
fix: "Pass an absolute path (starting with \"/\") to the matcher."
|
|
633
|
+
},
|
|
634
|
+
VUE_ROUTER_R0102: {
|
|
635
|
+
why: (p) => `Alias "${p.alias}" and the original record: "${p.original}" must have the exact same param named "${p.name}"`,
|
|
636
|
+
fix: "Use the same param names in the alias as in the original route.",
|
|
637
|
+
docs: "https://router.vuejs.org/guide/essentials/redirect-and-alias.html#Alias"
|
|
638
|
+
},
|
|
639
|
+
VUE_ROUTER_R0103: {
|
|
640
|
+
why: (p) => `The route named "${p.name}" has a child without a name, an empty path, and no children. Using that name won't render the empty path child, so this is probably a mistake.`,
|
|
641
|
+
fix: "Move the `name` onto the empty-path child; or, if intentional, give the child its own name to silence this.",
|
|
642
|
+
docs: "https://router.vuejs.org/guide/essentials/nested-routes.html#Nested-Named-Routes"
|
|
643
|
+
},
|
|
644
|
+
VUE_ROUTER_R0104: {
|
|
645
|
+
why: (p) => `Absolute path "${p.path}" must have the exact same param named "${p.name}" as its parent "${p.parent}".`,
|
|
646
|
+
fix: "Include the parent route params in the absolute child path.",
|
|
647
|
+
docs: "https://router.vuejs.org/guide/essentials/nested-routes.html"
|
|
648
|
+
},
|
|
649
|
+
VUE_ROUTER_R0105: {
|
|
650
|
+
why: (p) => `Finding ancestor route "${p.ancestor}" failed for "${p.record}"`,
|
|
651
|
+
fix: "Report a reproduction at https://github.com/vuejs/router/issues/new/choose."
|
|
652
|
+
},
|
|
653
|
+
VUE_ROUTER_R0110: {
|
|
654
|
+
why: `A hash base must end with a "#"`,
|
|
655
|
+
fix: (p) => `Append "#" to the "base" argument passed to "createWebHashHistory()": "${p.base}" should be "${p.suggestion}".`
|
|
656
|
+
},
|
|
657
|
+
VUE_ROUTER_R0120: {
|
|
658
|
+
why: "Error with push/replace State",
|
|
659
|
+
fix: "The browser rejected the history API call; check for cross-origin or rate-limit issues."
|
|
660
|
+
},
|
|
661
|
+
VUE_ROUTER_R0121: {
|
|
662
|
+
why: "history.state seems to have been manually replaced without preserving the necessary values.\nYou can find more information at https://router.vuejs.org/guide/migration/#Usage-of-history-state",
|
|
663
|
+
fix: "Merge the router's state into your own when calling it manually: `history.replaceState({ ...history.state, ...yourState }, '', url)`.",
|
|
664
|
+
docs: "https://router.vuejs.org/guide/migration.html#Usage-of-history-state"
|
|
665
|
+
},
|
|
666
|
+
VUE_ROUTER_R1001: {
|
|
667
|
+
why: (p) => `Data loader "${String(p.key)}" has a different parent than the current context. This shouldn't be happening.`,
|
|
668
|
+
fix: "Report a bug with a minimal reproduction at https://github.com/vuejs/router/."
|
|
669
|
+
},
|
|
670
|
+
VUE_ROUTER_R1002: {
|
|
671
|
+
why: "Returning a NavigationResult is deprecated.",
|
|
672
|
+
fix: "Replace `return new NavigationResult(to)` with `reroute(to)`, which throws internally to reroute.",
|
|
673
|
+
docs: "https://router.vuejs.org/data-loaders/navigation-aware.html#Controlling-the-navigation-with-reroute-"
|
|
674
|
+
},
|
|
675
|
+
VUE_ROUTER_R1003: {
|
|
676
|
+
why: (p) => `Loader "${p.key}"'s "commit()" was called but there is no staged data.`,
|
|
677
|
+
fix: "Ensure the loader resolved before calling `commit()`.",
|
|
678
|
+
docs: "https://router.vuejs.org/data-loaders/defining-loaders.html#Delaying-data-updates-with-commit"
|
|
679
|
+
},
|
|
680
|
+
VUE_ROUTER_R1004: {
|
|
681
|
+
why: (p) => "A loader returned a NavigationResult but is not registered on the route." + p.key,
|
|
682
|
+
fix: "Export the loader from the page component so it gets registered, e.g. `export const useUserData = defineLoader(...)`.",
|
|
683
|
+
docs: "https://router.vuejs.org/data-loaders/organization.html"
|
|
684
|
+
},
|
|
685
|
+
VUE_ROUTER_R1005: {
|
|
686
|
+
why: (p) => `Data loader "${p.key}" has itself as parent. This shouldn't be happening.`,
|
|
687
|
+
fix: "Report a bug with a minimal reproduction at https://github.com/vuejs/router/."
|
|
688
|
+
},
|
|
689
|
+
VUE_ROUTER_R1006: {
|
|
690
|
+
why: (p) => `A query was defined with the same key as the loader "[${p.key}]".\nSee https://pinia-colada.esm.dev/#TODO`,
|
|
691
|
+
fix: "If the key is meant to match, use the data loader directly; otherwise rename the `useQuery()` key so it no longer collides.",
|
|
692
|
+
docs: "https://router.vuejs.org/data-loaders/colada.html"
|
|
693
|
+
},
|
|
694
|
+
VUE_ROUTER_R1007: {
|
|
695
|
+
why: "Data Loader was setup twice.",
|
|
696
|
+
fix: "Register `DataLoaderPlugin` a single time via `app.use()`.",
|
|
697
|
+
docs: "https://router.vuejs.org/data-loaders.html#Installation"
|
|
698
|
+
},
|
|
699
|
+
VUE_ROUTER_R1008: {
|
|
700
|
+
why: "Data Loader is experimental and subject to breaking changes in the future.",
|
|
701
|
+
docs: "https://router.vuejs.org/data-loaders.html"
|
|
702
|
+
},
|
|
703
|
+
VUE_ROUTER_R1009: {
|
|
704
|
+
why: "Returning a NavigationResult from a loader is deprecated.",
|
|
705
|
+
fix: "Call `reroute(to)` inside the loader instead of returning `new NavigationResult(to)`; it throws internally to reroute.",
|
|
706
|
+
docs: "https://router.vuejs.org/data-loaders/navigation-aware.html#Controlling-the-navigation-with-reroute-"
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
Symbol(process.env.NODE_ENV !== "production" ? "router view location matched" : "");
|
|
711
|
+
Symbol(process.env.NODE_ENV !== "production" ? "router view depth" : "");
|
|
712
|
+
Symbol(process.env.NODE_ENV !== "production" ? "router" : "");
|
|
713
|
+
Symbol(process.env.NODE_ENV !== "production" ? "route location" : "");
|
|
714
|
+
Symbol(process.env.NODE_ENV !== "production" ? "router view location" : "");
|
|
715
|
+
Symbol(process.env.NODE_ENV !== "production" ? "router view on route rendered" : "");
|
|
716
|
+
//#endregion
|
|
717
|
+
//#region ../../node_modules/.pnpm/vue-router@5.4.0_@voidzero-dev+vite-plus-core@0.3.3_@types+node@24.19.1_esbuild@0.28.2__771eab81e2fd06a479763e79bcb19884/node_modules/vue-router/dist/devtools-CxgSYwGp.js
|
|
718
|
+
/*!
|
|
719
|
+
* vue-router v5.4.0
|
|
720
|
+
* (c) 2026 Eduardo San Martin Morote
|
|
721
|
+
* @license MIT
|
|
722
|
+
*/
|
|
723
|
+
function isRouteName(name) {
|
|
724
|
+
return typeof name === "string" || typeof name === "symbol";
|
|
725
|
+
}
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region ../../node_modules/.pnpm/vue-router@5.4.0_@voidzero-dev+vite-plus-core@0.3.3_@types+node@24.19.1_esbuild@0.28.2__771eab81e2fd06a479763e79bcb19884/node_modules/vue-router/dist/vue-router.js
|
|
728
|
+
/*!
|
|
729
|
+
* vue-router v5.4.0
|
|
730
|
+
* (c) 2026 Eduardo San Martin Morote
|
|
731
|
+
* @license MIT
|
|
732
|
+
*/
|
|
733
|
+
const ROOT_TOKEN = {
|
|
734
|
+
type: 0,
|
|
735
|
+
value: ""
|
|
736
|
+
};
|
|
737
|
+
const VALID_PARAM_RE = /[a-zA-Z0-9_]/;
|
|
738
|
+
function tokenizePath(path) {
|
|
739
|
+
if (!path) return [[]];
|
|
740
|
+
if (path === "/") return [[ROOT_TOKEN]];
|
|
741
|
+
if (!isAbsolutePath(path)) throw new Error(process.env.NODE_ENV !== "production" ? `Route paths should start with a "/": "${path}" should be "/${path}".` : `Invalid path "${path}"`);
|
|
742
|
+
function crash(message) {
|
|
743
|
+
throw new Error(`ERR (${state})/"${buffer}": ${message}`);
|
|
744
|
+
}
|
|
745
|
+
let state = 0;
|
|
746
|
+
let previousState = state;
|
|
747
|
+
const tokens = [];
|
|
748
|
+
let segment;
|
|
749
|
+
function finalizeSegment() {
|
|
750
|
+
if (segment) tokens.push(segment);
|
|
751
|
+
segment = [];
|
|
752
|
+
}
|
|
753
|
+
let i = 0;
|
|
754
|
+
let char;
|
|
755
|
+
let buffer = "";
|
|
756
|
+
let customRe = "";
|
|
757
|
+
function consumeBuffer() {
|
|
758
|
+
if (!buffer) return;
|
|
759
|
+
if (state === 0) segment.push({
|
|
760
|
+
type: 0,
|
|
761
|
+
value: buffer
|
|
762
|
+
});
|
|
763
|
+
else if (state === 1 || state === 2 || state === 3) {
|
|
764
|
+
if (segment.length > 1 && (char === "*" || char === "+")) crash(`A repeatable param (${buffer}) must be alone in its segment. eg: '/:ids+.`);
|
|
765
|
+
segment.push({
|
|
766
|
+
type: 1,
|
|
767
|
+
value: buffer,
|
|
768
|
+
regexp: customRe,
|
|
769
|
+
repeatable: char === "*" || char === "+",
|
|
770
|
+
optional: char === "*" || char === "?"
|
|
771
|
+
});
|
|
772
|
+
} else crash("Invalid state to consume buffer");
|
|
773
|
+
buffer = "";
|
|
774
|
+
}
|
|
775
|
+
function addCharToBuffer() {
|
|
776
|
+
buffer += char;
|
|
777
|
+
}
|
|
778
|
+
while (i < path.length) {
|
|
779
|
+
char = path[i++];
|
|
780
|
+
switch (state) {
|
|
781
|
+
case 0:
|
|
782
|
+
if (char === "\\") {
|
|
783
|
+
previousState = state;
|
|
784
|
+
state = 4;
|
|
785
|
+
} else if (char === "/") {
|
|
786
|
+
if (buffer) consumeBuffer();
|
|
787
|
+
finalizeSegment();
|
|
788
|
+
} else if (char === ":") {
|
|
789
|
+
consumeBuffer();
|
|
790
|
+
state = 1;
|
|
791
|
+
} else addCharToBuffer();
|
|
792
|
+
break;
|
|
793
|
+
case 4:
|
|
794
|
+
addCharToBuffer();
|
|
795
|
+
state = previousState;
|
|
796
|
+
break;
|
|
797
|
+
case 1:
|
|
798
|
+
if (char === "(") state = 2;
|
|
799
|
+
else if (VALID_PARAM_RE.test(char)) addCharToBuffer();
|
|
800
|
+
else {
|
|
801
|
+
consumeBuffer();
|
|
802
|
+
state = 0;
|
|
803
|
+
if (char !== "*" && char !== "?" && char !== "+") i--;
|
|
804
|
+
}
|
|
805
|
+
break;
|
|
806
|
+
case 2:
|
|
807
|
+
if (char === ")") {
|
|
808
|
+
if (customRe[customRe.length - 1] == "\\") customRe = customRe.slice(0, -1) + char;
|
|
809
|
+
else state = 3;
|
|
810
|
+
} else customRe += char;
|
|
811
|
+
break;
|
|
812
|
+
case 3:
|
|
813
|
+
consumeBuffer();
|
|
814
|
+
state = 0;
|
|
815
|
+
if (char !== "*" && char !== "?" && char !== "+") i--;
|
|
816
|
+
customRe = "";
|
|
817
|
+
break;
|
|
818
|
+
default: crash("Unknown state");
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
if (state === 2) crash(`Unfinished custom RegExp for param "${buffer}"`);
|
|
822
|
+
consumeBuffer();
|
|
823
|
+
finalizeSegment();
|
|
824
|
+
return tokens;
|
|
825
|
+
}
|
|
826
|
+
const BASE_PARAM_PATTERN = "[^/]+?";
|
|
827
|
+
const BASE_PATH_PARSER_OPTIONS = {
|
|
828
|
+
sensitive: false,
|
|
829
|
+
strict: false,
|
|
830
|
+
start: true,
|
|
831
|
+
end: true
|
|
832
|
+
};
|
|
833
|
+
const REGEX_CHARS_RE = /[.+*?^${}()[\]/\\]/g;
|
|
834
|
+
/**
|
|
835
|
+
* Creates a path parser from an array of Segments (a segment is an array of Tokens)
|
|
836
|
+
*
|
|
837
|
+
* @param segments - array of segments returned by tokenizePath
|
|
838
|
+
* @param extraOptions - optional options for the regexp
|
|
839
|
+
* @returns a PathParser
|
|
840
|
+
*/
|
|
841
|
+
function tokensToParser(segments, extraOptions) {
|
|
842
|
+
const options = assign({}, BASE_PATH_PARSER_OPTIONS, extraOptions);
|
|
843
|
+
const score = [];
|
|
844
|
+
let pattern = options.start ? "^" : "";
|
|
845
|
+
const keys = [];
|
|
846
|
+
for (const segment of segments) {
|
|
847
|
+
const segmentScores = segment.length ? [] : [90];
|
|
848
|
+
if (options.strict && !segment.length) pattern += "/";
|
|
849
|
+
for (let tokenIndex = 0; tokenIndex < segment.length; tokenIndex++) {
|
|
850
|
+
const token = segment[tokenIndex];
|
|
851
|
+
let subSegmentScore = 40 + (options.sensitive ? .25 : 0);
|
|
852
|
+
if (token.type === 0) {
|
|
853
|
+
if (!tokenIndex) pattern += "/";
|
|
854
|
+
pattern += token.value.replace(REGEX_CHARS_RE, "\\$&");
|
|
855
|
+
subSegmentScore += 40;
|
|
856
|
+
} else if (token.type === 1) {
|
|
857
|
+
const { value, repeatable, optional, regexp } = token;
|
|
858
|
+
keys.push({
|
|
859
|
+
name: value,
|
|
860
|
+
repeatable,
|
|
861
|
+
optional
|
|
862
|
+
});
|
|
863
|
+
const re = regexp ? regexp : BASE_PARAM_PATTERN;
|
|
864
|
+
if (re !== BASE_PARAM_PATTERN) {
|
|
865
|
+
subSegmentScore += 10;
|
|
866
|
+
try {
|
|
867
|
+
new RegExp(`(${re})`);
|
|
868
|
+
} catch (err) {
|
|
869
|
+
throw new Error(`Invalid custom RegExp for param "${value}" (${re}): ` + err.message);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
let subPattern = repeatable ? `((?:${re})(?:/(?:${re}))*)` : `(${re})`;
|
|
873
|
+
if (!tokenIndex) subPattern = optional && segment.length < 2 ? `(?:/${subPattern})` : "/" + subPattern;
|
|
874
|
+
if (optional) subPattern += "?";
|
|
875
|
+
pattern += subPattern;
|
|
876
|
+
subSegmentScore += 20;
|
|
877
|
+
if (optional) subSegmentScore += -8;
|
|
878
|
+
if (repeatable) subSegmentScore += -20;
|
|
879
|
+
if (re === ".*") subSegmentScore += -50;
|
|
880
|
+
}
|
|
881
|
+
segmentScores.push(subSegmentScore);
|
|
882
|
+
}
|
|
883
|
+
score.push(segmentScores);
|
|
884
|
+
}
|
|
885
|
+
if (options.strict && options.end) {
|
|
886
|
+
const i = score.length - 1;
|
|
887
|
+
score[i][score[i].length - 1] += .7000000000000001;
|
|
888
|
+
}
|
|
889
|
+
if (!options.strict) pattern += "/?";
|
|
890
|
+
if (options.end) pattern += "$";
|
|
891
|
+
else if (options.strict && !pattern.endsWith("/")) pattern += "(?:/|$)";
|
|
892
|
+
const re = new RegExp(pattern, options.sensitive ? "" : "i");
|
|
893
|
+
function parse(path) {
|
|
894
|
+
const match = path.match(re);
|
|
895
|
+
const params = {};
|
|
896
|
+
if (!match) return null;
|
|
897
|
+
for (let i = 1; i < match.length; i++) {
|
|
898
|
+
const value = match[i] || "";
|
|
899
|
+
const key = keys[i - 1];
|
|
900
|
+
params[key.name] = value && key.repeatable ? value.split("/") : value;
|
|
901
|
+
}
|
|
902
|
+
return params;
|
|
903
|
+
}
|
|
904
|
+
function stringify(params) {
|
|
905
|
+
let path = "";
|
|
906
|
+
let avoidDuplicatedSlash = false;
|
|
907
|
+
for (const segment of segments) {
|
|
908
|
+
if (!avoidDuplicatedSlash || !path.endsWith("/")) path += "/";
|
|
909
|
+
avoidDuplicatedSlash = false;
|
|
910
|
+
for (const token of segment) if (token.type === 0) path += token.value;
|
|
911
|
+
else if (token.type === 1) {
|
|
912
|
+
const { value, repeatable, optional } = token;
|
|
913
|
+
const param = value in params ? params[value] : "";
|
|
914
|
+
if (isArray(param) && !repeatable) throw new Error(`Provided param "${value}" is an array but it is not repeatable (* or + modifiers)`);
|
|
915
|
+
const text = isArray(param) ? param.join("/") : param;
|
|
916
|
+
if (!text) {
|
|
917
|
+
if (optional) {
|
|
918
|
+
if (segment.length < 2) {
|
|
919
|
+
if (path.endsWith("/")) path = path.slice(0, -1);
|
|
920
|
+
else avoidDuplicatedSlash = true;
|
|
921
|
+
}
|
|
922
|
+
} else throw new Error(`Missing required param "${value}"`);
|
|
923
|
+
}
|
|
924
|
+
path += text;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
return path || "/";
|
|
928
|
+
}
|
|
929
|
+
return {
|
|
930
|
+
re,
|
|
931
|
+
score,
|
|
932
|
+
keys,
|
|
933
|
+
parse,
|
|
934
|
+
stringify
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Compares an array of numbers as used in PathParser.score and returns a
|
|
939
|
+
* number. This function can be used to `sort` an array
|
|
940
|
+
*
|
|
941
|
+
* @param a - first array of numbers
|
|
942
|
+
* @param b - second array of numbers
|
|
943
|
+
* @returns 0 if both are equal, < 0 if a should be sorted first, > 0 if b
|
|
944
|
+
* should be sorted first
|
|
945
|
+
*/
|
|
946
|
+
function compareScoreArray(a, b) {
|
|
947
|
+
let i = 0;
|
|
948
|
+
while (i < a.length && i < b.length) {
|
|
949
|
+
const diff = b[i] - a[i];
|
|
950
|
+
if (diff) return diff;
|
|
951
|
+
i++;
|
|
952
|
+
}
|
|
953
|
+
if (a.length < b.length) return a.length === 1 && a[0] === 80 ? -1 : 1;
|
|
954
|
+
else if (a.length > b.length) return b.length === 1 && b[0] === 80 ? 1 : -1;
|
|
955
|
+
return 0;
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Compare function that can be used with `sort` to sort an array of PathParser
|
|
959
|
+
*
|
|
960
|
+
* @param a - first PathParser
|
|
961
|
+
* @param b - second PathParser
|
|
962
|
+
* @returns 0 if both are equal, < 0 if a should be sorted first, > 0 if b
|
|
963
|
+
*/
|
|
964
|
+
function comparePathParserScore(a, b) {
|
|
965
|
+
let i = 0;
|
|
966
|
+
const aScore = a.score;
|
|
967
|
+
const bScore = b.score;
|
|
968
|
+
while (i < aScore.length && i < bScore.length) {
|
|
969
|
+
const comp = compareScoreArray(aScore[i], bScore[i]);
|
|
970
|
+
if (comp) return comp;
|
|
971
|
+
i++;
|
|
972
|
+
}
|
|
973
|
+
if (Math.abs(bScore.length - aScore.length) === 1) {
|
|
974
|
+
if (isLastScoreNegative(aScore)) return 1;
|
|
975
|
+
if (isLastScoreNegative(bScore)) return -1;
|
|
976
|
+
}
|
|
977
|
+
return bScore.length - aScore.length;
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* This allows detecting splats at the end of a path: /home/:id(.*)*
|
|
981
|
+
*
|
|
982
|
+
* @param score - score to check
|
|
983
|
+
* @returns true if the last entry is negative
|
|
984
|
+
*/
|
|
985
|
+
function isLastScoreNegative(score) {
|
|
986
|
+
const last = score[score.length - 1];
|
|
987
|
+
return score.length > 0 && last[last.length - 1] < 0;
|
|
988
|
+
}
|
|
989
|
+
const PATH_PARSER_OPTIONS_DEFAULTS = {
|
|
990
|
+
strict: false,
|
|
991
|
+
end: true,
|
|
992
|
+
sensitive: false
|
|
993
|
+
};
|
|
994
|
+
function createRouteRecordMatcher(record, parent, options) {
|
|
995
|
+
const parser = tokensToParser(tokenizePath(record.path), options);
|
|
996
|
+
if (process.env.NODE_ENV !== "production") {
|
|
997
|
+
const existingKeys = /* @__PURE__ */ new Set();
|
|
998
|
+
for (const key of parser.keys) {
|
|
999
|
+
if (existingKeys.has(key.name)) diagnostics.VUE_ROUTER_R0090({
|
|
1000
|
+
name: key.name,
|
|
1001
|
+
path: record.path
|
|
1002
|
+
});
|
|
1003
|
+
existingKeys.add(key.name);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
const matcher = assign(parser, {
|
|
1007
|
+
record,
|
|
1008
|
+
parent,
|
|
1009
|
+
children: [],
|
|
1010
|
+
alias: []
|
|
1011
|
+
});
|
|
1012
|
+
if (parent) {
|
|
1013
|
+
if (!matcher.record.aliasOf === !parent.record.aliasOf) parent.children.push(matcher);
|
|
1014
|
+
}
|
|
1015
|
+
return matcher;
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Creates a Router Matcher.
|
|
1019
|
+
*
|
|
1020
|
+
* @internal
|
|
1021
|
+
* @param routes - array of initial routes
|
|
1022
|
+
* @param globalOptions - global route options
|
|
1023
|
+
*/
|
|
1024
|
+
function createRouterMatcher(routes, globalOptions) {
|
|
1025
|
+
const matchers = [];
|
|
1026
|
+
const matcherMap = /* @__PURE__ */ new Map();
|
|
1027
|
+
globalOptions = mergeOptions(PATH_PARSER_OPTIONS_DEFAULTS, globalOptions);
|
|
1028
|
+
function getRecordMatcher(name) {
|
|
1029
|
+
return matcherMap.get(name);
|
|
1030
|
+
}
|
|
1031
|
+
function addRoute(record, parent, originalRecord) {
|
|
1032
|
+
const isRootAdd = !originalRecord;
|
|
1033
|
+
const mainNormalizedRecord = normalizeRouteRecord(record);
|
|
1034
|
+
if (process.env.NODE_ENV !== "production") checkChildMissingNameWithEmptyPath(mainNormalizedRecord, parent);
|
|
1035
|
+
mainNormalizedRecord.aliasOf = originalRecord && originalRecord.record;
|
|
1036
|
+
const options = mergeOptions(globalOptions, record);
|
|
1037
|
+
const normalizedRecords = [mainNormalizedRecord];
|
|
1038
|
+
if ("alias" in record) {
|
|
1039
|
+
const aliases = typeof record.alias === "string" ? [record.alias] : record.alias;
|
|
1040
|
+
for (const alias of aliases) normalizedRecords.push(normalizeRouteRecord(assign({}, mainNormalizedRecord, {
|
|
1041
|
+
components: originalRecord ? originalRecord.record.components : mainNormalizedRecord.components,
|
|
1042
|
+
path: alias,
|
|
1043
|
+
aliasOf: originalRecord ? originalRecord.record : mainNormalizedRecord
|
|
1044
|
+
})));
|
|
1045
|
+
}
|
|
1046
|
+
let matcher;
|
|
1047
|
+
let originalMatcher;
|
|
1048
|
+
for (const normalizedRecord of normalizedRecords) {
|
|
1049
|
+
const { path } = normalizedRecord;
|
|
1050
|
+
if (parent && !isAbsolutePath(path)) {
|
|
1051
|
+
const parentPath = parent.record.path;
|
|
1052
|
+
const connectingSlash = parentPath[parentPath.length - 1] === "/" ? "" : "/";
|
|
1053
|
+
normalizedRecord.path = parent.record.path + (path && connectingSlash + path);
|
|
1054
|
+
}
|
|
1055
|
+
if (process.env.NODE_ENV !== "production" && normalizedRecord.path === "*") throw new Error("Catch all routes (\"*\") must now be defined using a param with a custom regexp.\nSee more at https://router.vuejs.org/guide/migration/#Removed-star-or-catch-all-routes.");
|
|
1056
|
+
matcher = createRouteRecordMatcher(normalizedRecord, parent, options);
|
|
1057
|
+
if (process.env.NODE_ENV !== "production" && parent && isAbsolutePath(path)) checkMissingParamsInAbsolutePath(matcher, parent);
|
|
1058
|
+
if (originalRecord) {
|
|
1059
|
+
originalRecord.alias.push(matcher);
|
|
1060
|
+
if (process.env.NODE_ENV !== "production") checkSameParams(originalRecord, matcher);
|
|
1061
|
+
} else {
|
|
1062
|
+
originalMatcher = originalMatcher || matcher;
|
|
1063
|
+
if (originalMatcher !== matcher) originalMatcher.alias.push(matcher);
|
|
1064
|
+
if (isRootAdd && record.name && !isAliasRecord(matcher)) {
|
|
1065
|
+
if (process.env.NODE_ENV !== "production") checkSameNameAsAncestor(record, parent);
|
|
1066
|
+
removeRoute(record.name);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
if (isMatchable(matcher)) insertMatcher(matcher);
|
|
1070
|
+
if (mainNormalizedRecord.children) {
|
|
1071
|
+
const children = mainNormalizedRecord.children;
|
|
1072
|
+
for (let i = 0; i < children.length; i++) addRoute(children[i], matcher, originalRecord && originalRecord.children[i]);
|
|
1073
|
+
}
|
|
1074
|
+
originalRecord = originalRecord || matcher;
|
|
1075
|
+
}
|
|
1076
|
+
return originalMatcher ? () => {
|
|
1077
|
+
removeRoute(originalMatcher);
|
|
1078
|
+
} : noop;
|
|
1079
|
+
}
|
|
1080
|
+
function removeRoute(matcherRef) {
|
|
1081
|
+
if (isRouteName(matcherRef)) {
|
|
1082
|
+
const matcher = matcherMap.get(matcherRef);
|
|
1083
|
+
if (matcher) {
|
|
1084
|
+
matcherMap.delete(matcherRef);
|
|
1085
|
+
matchers.splice(matchers.indexOf(matcher), 1);
|
|
1086
|
+
matcher.children.forEach(removeRoute);
|
|
1087
|
+
matcher.alias.forEach(removeRoute);
|
|
1088
|
+
}
|
|
1089
|
+
} else {
|
|
1090
|
+
const index = matchers.indexOf(matcherRef);
|
|
1091
|
+
if (index > -1) {
|
|
1092
|
+
matchers.splice(index, 1);
|
|
1093
|
+
if (matcherRef.record.name) matcherMap.delete(matcherRef.record.name);
|
|
1094
|
+
matcherRef.children.forEach(removeRoute);
|
|
1095
|
+
matcherRef.alias.forEach(removeRoute);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
function getRoutes() {
|
|
1100
|
+
return matchers;
|
|
1101
|
+
}
|
|
1102
|
+
function insertMatcher(matcher) {
|
|
1103
|
+
const index = findInsertionIndex(matcher, matchers);
|
|
1104
|
+
matchers.splice(index, 0, matcher);
|
|
1105
|
+
if (matcher.record.name && !isAliasRecord(matcher)) matcherMap.set(matcher.record.name, matcher);
|
|
1106
|
+
}
|
|
1107
|
+
function resolve(location, currentLocation) {
|
|
1108
|
+
let matcher;
|
|
1109
|
+
let params = {};
|
|
1110
|
+
let path;
|
|
1111
|
+
let name;
|
|
1112
|
+
if ("name" in location && location.name) {
|
|
1113
|
+
matcher = matcherMap.get(location.name);
|
|
1114
|
+
if (!matcher) throw createRouterError(1, { location });
|
|
1115
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1116
|
+
const invalidParams = Object.keys(location.params || {}).filter((paramName) => !matcher.keys.find((k) => k.name === paramName));
|
|
1117
|
+
if (invalidParams.length) {
|
|
1118
|
+
const isInherited = !matcher.keys.length && invalidParams.some((name) => name in currentLocation.params);
|
|
1119
|
+
diagnostics.VUE_ROUTER_R0100({
|
|
1120
|
+
params: invalidParams.join("\", \""),
|
|
1121
|
+
inherited: isInherited ? ` If you are using a catch-all route with a named redirect, pass an empty \`params\` object: \`redirect: { name: '...', params: {} }\`.` : ""
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
name = matcher.record.name;
|
|
1126
|
+
params = assign(pickParams(currentLocation.params, matcher.keys.filter((k) => !k.optional).concat(matcher.parent ? matcher.parent.keys.filter((k) => k.optional) : []).map((k) => k.name)), location.params && pickParams(location.params, matcher.keys.map((k) => k.name)));
|
|
1127
|
+
path = matcher.stringify(params);
|
|
1128
|
+
} else if (location.path != null) {
|
|
1129
|
+
path = location.path;
|
|
1130
|
+
if (process.env.NODE_ENV !== "production" && !isAbsolutePath(path)) diagnostics.VUE_ROUTER_R0101({ path });
|
|
1131
|
+
matcher = matchers.find((m) => m.re.test(path));
|
|
1132
|
+
if (matcher) {
|
|
1133
|
+
params = matcher.parse(path);
|
|
1134
|
+
name = matcher.record.name;
|
|
1135
|
+
matcher.keys.forEach((key) => {
|
|
1136
|
+
if (key.optional && !params[key.name]) delete params[key.name];
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
} else {
|
|
1140
|
+
matcher = currentLocation.name ? matcherMap.get(currentLocation.name) : matchers.find((m) => m.re.test(currentLocation.path));
|
|
1141
|
+
if (!matcher) throw createRouterError(1, {
|
|
1142
|
+
location,
|
|
1143
|
+
currentLocation
|
|
1144
|
+
});
|
|
1145
|
+
name = matcher.record.name;
|
|
1146
|
+
params = assign({}, currentLocation.params, location.params);
|
|
1147
|
+
path = matcher.stringify(params);
|
|
1148
|
+
}
|
|
1149
|
+
const matched = [];
|
|
1150
|
+
let parentMatcher = matcher;
|
|
1151
|
+
while (parentMatcher) {
|
|
1152
|
+
matched.unshift(parentMatcher.record);
|
|
1153
|
+
parentMatcher = parentMatcher.parent;
|
|
1154
|
+
}
|
|
1155
|
+
return {
|
|
1156
|
+
name,
|
|
1157
|
+
path,
|
|
1158
|
+
params,
|
|
1159
|
+
matched,
|
|
1160
|
+
meta: mergeMetaFields(matched)
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
routes.forEach((route) => addRoute(route));
|
|
1164
|
+
function clearRoutes() {
|
|
1165
|
+
matchers.length = 0;
|
|
1166
|
+
matcherMap.clear();
|
|
1167
|
+
}
|
|
1168
|
+
return {
|
|
1169
|
+
addRoute,
|
|
1170
|
+
resolve,
|
|
1171
|
+
removeRoute,
|
|
1172
|
+
clearRoutes,
|
|
1173
|
+
getRoutes,
|
|
1174
|
+
getRecordMatcher
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Picks an object param to contain only specified keys.
|
|
1179
|
+
*
|
|
1180
|
+
* @param params - params object to pick from
|
|
1181
|
+
* @param keys - keys to pick
|
|
1182
|
+
*/
|
|
1183
|
+
function pickParams(params, keys) {
|
|
1184
|
+
const newParams = {};
|
|
1185
|
+
for (const key of keys) if (key in params) newParams[key] = params[key];
|
|
1186
|
+
return newParams;
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Normalizes a RouteRecordRaw. Creates a copy
|
|
1190
|
+
*
|
|
1191
|
+
* @param record
|
|
1192
|
+
* @returns the normalized version
|
|
1193
|
+
*/
|
|
1194
|
+
function normalizeRouteRecord(record) {
|
|
1195
|
+
const normalized = {
|
|
1196
|
+
path: record.path,
|
|
1197
|
+
redirect: record.redirect,
|
|
1198
|
+
name: record.name,
|
|
1199
|
+
meta: record.meta || {},
|
|
1200
|
+
aliasOf: record.aliasOf,
|
|
1201
|
+
beforeEnter: record.beforeEnter,
|
|
1202
|
+
props: normalizeRecordProps(record),
|
|
1203
|
+
children: record.children || [],
|
|
1204
|
+
instances: {},
|
|
1205
|
+
leaveGuards: /* @__PURE__ */ new Set(),
|
|
1206
|
+
updateGuards: /* @__PURE__ */ new Set(),
|
|
1207
|
+
enterCallbacks: {},
|
|
1208
|
+
components: "components" in record ? record.components || null : record.component && { default: record.component }
|
|
1209
|
+
};
|
|
1210
|
+
Object.defineProperty(normalized, "mods", { value: {} });
|
|
1211
|
+
return normalized;
|
|
1212
|
+
}
|
|
1213
|
+
/**
|
|
1214
|
+
* Normalize the optional `props` in a record to always be an object similar to
|
|
1215
|
+
* components. Also accept a boolean for components.
|
|
1216
|
+
* @param record
|
|
1217
|
+
*/
|
|
1218
|
+
function normalizeRecordProps(record) {
|
|
1219
|
+
const propsObject = {};
|
|
1220
|
+
const props = record.props || false;
|
|
1221
|
+
if ("component" in record) propsObject.default = props;
|
|
1222
|
+
else for (const name in record.components) propsObject[name] = typeof props === "object" ? props[name] : props;
|
|
1223
|
+
return propsObject;
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Checks if a record or any of its parent is an alias
|
|
1227
|
+
* @param record
|
|
1228
|
+
*/
|
|
1229
|
+
function isAliasRecord(record) {
|
|
1230
|
+
while (record) {
|
|
1231
|
+
if (record.record.aliasOf) return true;
|
|
1232
|
+
record = record.parent;
|
|
1233
|
+
}
|
|
1234
|
+
return false;
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Merge meta fields of an array of records
|
|
1238
|
+
*
|
|
1239
|
+
* @param matched - array of matched records
|
|
1240
|
+
*/
|
|
1241
|
+
function mergeMetaFields(matched) {
|
|
1242
|
+
return matched.reduce((meta, record) => assign(meta, record.meta), {});
|
|
1243
|
+
}
|
|
1244
|
+
function isSameParam(a, b) {
|
|
1245
|
+
return a.name === b.name && a.optional === b.optional && a.repeatable === b.repeatable;
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Check if a path and its alias have the same required params
|
|
1249
|
+
*
|
|
1250
|
+
* @param a - original record
|
|
1251
|
+
* @param b - alias record
|
|
1252
|
+
*/
|
|
1253
|
+
function checkSameParams(a, b) {
|
|
1254
|
+
for (const key of a.keys) if (!key.optional && !b.keys.find(isSameParam.bind(null, key))) {
|
|
1255
|
+
diagnostics.VUE_ROUTER_R0102({
|
|
1256
|
+
alias: b.record.path,
|
|
1257
|
+
original: a.record.path,
|
|
1258
|
+
name: key.name
|
|
1259
|
+
});
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
for (const key of b.keys) if (!key.optional && !a.keys.find(isSameParam.bind(null, key))) {
|
|
1263
|
+
diagnostics.VUE_ROUTER_R0102({
|
|
1264
|
+
alias: b.record.path,
|
|
1265
|
+
original: a.record.path,
|
|
1266
|
+
name: key.name
|
|
1267
|
+
});
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* A route with a name and a child with an empty path without a name should warn when adding the route
|
|
1273
|
+
*
|
|
1274
|
+
* @param mainNormalizedRecord - RouteRecordNormalized
|
|
1275
|
+
* @param parent - RouteRecordMatcher
|
|
1276
|
+
*/
|
|
1277
|
+
function checkChildMissingNameWithEmptyPath(mainNormalizedRecord, parent) {
|
|
1278
|
+
if (parent && parent.record.name && !mainNormalizedRecord.name && !mainNormalizedRecord.path && mainNormalizedRecord.children.length === 0) diagnostics.VUE_ROUTER_R0103({ name: String(parent.record.name) });
|
|
1279
|
+
}
|
|
1280
|
+
function checkSameNameAsAncestor(record, parent) {
|
|
1281
|
+
for (let ancestor = parent; ancestor; ancestor = ancestor.parent) if (ancestor.record.name === record.name) throw new Error(`A route named "${String(record.name)}" has been added as a ${parent === ancestor ? "child" : "descendant"} of a route with the same name. Route names must be unique and a nested route cannot use the same name as an ancestor.`);
|
|
1282
|
+
}
|
|
1283
|
+
function checkMissingParamsInAbsolutePath(record, parent) {
|
|
1284
|
+
for (const key of parent.keys) if (!record.keys.find(isSameParam.bind(null, key))) {
|
|
1285
|
+
diagnostics.VUE_ROUTER_R0104({
|
|
1286
|
+
path: record.record.path,
|
|
1287
|
+
name: key.name,
|
|
1288
|
+
parent: parent.record.path
|
|
1289
|
+
});
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Performs a binary search to find the correct insertion index for a new matcher.
|
|
1295
|
+
*
|
|
1296
|
+
* Matchers are primarily sorted by their score. If scores are tied then we also consider parent/child relationships,
|
|
1297
|
+
* with descendants coming before ancestors. If there's still a tie, new routes are inserted after existing routes.
|
|
1298
|
+
*
|
|
1299
|
+
* @param matcher - new matcher to be inserted
|
|
1300
|
+
* @param matchers - existing matchers
|
|
1301
|
+
*/
|
|
1302
|
+
function findInsertionIndex(matcher, matchers) {
|
|
1303
|
+
let lower = 0;
|
|
1304
|
+
let upper = matchers.length;
|
|
1305
|
+
while (lower !== upper) {
|
|
1306
|
+
const mid = lower + upper >> 1;
|
|
1307
|
+
if (comparePathParserScore(matcher, matchers[mid]) < 0) upper = mid;
|
|
1308
|
+
else lower = mid + 1;
|
|
1309
|
+
}
|
|
1310
|
+
const insertionAncestor = getInsertionAncestor(matcher);
|
|
1311
|
+
if (insertionAncestor) {
|
|
1312
|
+
upper = matchers.lastIndexOf(insertionAncestor, upper - 1);
|
|
1313
|
+
if (process.env.NODE_ENV !== "production" && upper < 0) diagnostics.VUE_ROUTER_R0105({
|
|
1314
|
+
ancestor: insertionAncestor.record.path,
|
|
1315
|
+
record: matcher.record.path
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
return upper;
|
|
1319
|
+
}
|
|
1320
|
+
function getInsertionAncestor(matcher) {
|
|
1321
|
+
let ancestor = matcher;
|
|
1322
|
+
while (ancestor = ancestor.parent) if (isMatchable(ancestor) && comparePathParserScore(matcher, ancestor) === 0) return ancestor;
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Checks if a matcher can be reachable. This means if it's possible to reach it as a route. For example, routes without
|
|
1326
|
+
* a component, or name, or redirect, are just used to group other routes.
|
|
1327
|
+
* @param matcher
|
|
1328
|
+
* @param matcher.record record of the matcher
|
|
1329
|
+
* @returns
|
|
1330
|
+
*/
|
|
1331
|
+
function isMatchable({ record }) {
|
|
1332
|
+
return !!(record.name || record.components && Object.keys(record.components).length || record.redirect);
|
|
1333
|
+
}
|
|
1334
|
+
//#endregion
|
|
1335
|
+
//#region src/routes.ts
|
|
1336
|
+
function joinPath(parent, path) {
|
|
1337
|
+
if (path.startsWith("/")) return path;
|
|
1338
|
+
if (!path) return parent;
|
|
1339
|
+
return `${parent.replace(/\/$/, "")}/${path}`;
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* The routes of a Nuxt app, from the pages that Nuxt resolves and the layouts that it finds. A nested route renders
|
|
1343
|
+
* every parent page. The layout is the last static `layout` in the page meta of the route, or `default`. A layout
|
|
1344
|
+
* that the app sets at runtime is not known at build time.
|
|
1345
|
+
*/
|
|
1346
|
+
function nuxtPageRoutes(pages, layouts = {}, layoutComponent) {
|
|
1347
|
+
const routes = /* @__PURE__ */ new Map();
|
|
1348
|
+
const walk = (list, parentPaths, parentFiles, parentLayout) => {
|
|
1349
|
+
for (const page of list) {
|
|
1350
|
+
const aliases = typeof page.alias === "string" ? [page.alias] : page.alias ?? [];
|
|
1351
|
+
const paths = [...new Set(parentPaths.flatMap((parent) => [page.path, ...aliases].map((path) => joinPath(parent, path))))];
|
|
1352
|
+
const own = page.components ? Object.values(page.components) : page.file ? [page.file] : [];
|
|
1353
|
+
const files = [...parentFiles, ...own];
|
|
1354
|
+
const layout = typeof page.meta?.layout === "string" || page.meta?.layout === false ? page.meta.layout : parentLayout;
|
|
1355
|
+
const redirect = page.redirect ?? page.meta?.redirect;
|
|
1356
|
+
if (own.length || redirect !== void 0) {
|
|
1357
|
+
const layoutFile = typeof layout === "string" ? layouts[layout]?.file : void 0;
|
|
1358
|
+
for (const path of paths) routes.set(path, {
|
|
1359
|
+
path,
|
|
1360
|
+
files: layoutFile ? [layoutFile, ...files] : files,
|
|
1361
|
+
...layoutFile && layoutComponent ? { layout: {
|
|
1362
|
+
file: layoutFile,
|
|
1363
|
+
component: layoutComponent
|
|
1364
|
+
} } : {},
|
|
1365
|
+
...redirect !== void 0 ? { unavailable: "Page redirects can change the route before its components render." } : {}
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
if (page.children?.length) walk(page.children, paths, files, layout);
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
walk(pages, [""], [], "default");
|
|
1372
|
+
return [...routes.values()].sort((left, right) => left.path < right.path ? -1 : 1);
|
|
1373
|
+
}
|
|
1374
|
+
function graphOf(report) {
|
|
1375
|
+
const holders = /* @__PURE__ */ new Map();
|
|
1376
|
+
for (const chunk of report.chunks) for (const module of chunk.modules) holders.set(module.id, [...holders.get(module.id) ?? [], chunk.file]);
|
|
1377
|
+
return {
|
|
1378
|
+
report,
|
|
1379
|
+
byFile: new Map(report.chunks.map((chunk) => [chunk.file, chunk])),
|
|
1380
|
+
holders,
|
|
1381
|
+
startup: report.chunks.filter((chunk) => chunk.startup).map((chunk) => chunk.file)
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
/** The JavaScript files that a first visit loads: the startup files and the component files with their static imports. */
|
|
1385
|
+
function routeFiles(graph, source) {
|
|
1386
|
+
const files = new Set(graph.startup);
|
|
1387
|
+
const pending = source.components.flatMap((id) => graph.holders.get(id) ?? []);
|
|
1388
|
+
while (pending.length) {
|
|
1389
|
+
const file = pending.pop();
|
|
1390
|
+
if (files.has(file)) continue;
|
|
1391
|
+
files.add(file);
|
|
1392
|
+
pending.push(...graph.byFile.get(file)?.imports ?? []);
|
|
1393
|
+
}
|
|
1394
|
+
return files;
|
|
1395
|
+
}
|
|
1396
|
+
function routeOf(graph, source) {
|
|
1397
|
+
const files = [...routeFiles(graph, source)].flatMap((file) => graph.byFile.get(file) ?? []);
|
|
1398
|
+
const cssSizes = new Map((graph.report.css ?? []).map((file) => [file.file, file]));
|
|
1399
|
+
const css = /* @__PURE__ */ new Map();
|
|
1400
|
+
for (const chunk of files) for (const file of chunk.css ?? []) css.set(file, (css.get(file) ?? false) || chunk.startup);
|
|
1401
|
+
const js = files.map((chunk) => ({
|
|
1402
|
+
file: chunk.file,
|
|
1403
|
+
bytes: chunk.bytes,
|
|
1404
|
+
gzip: chunk.gzip,
|
|
1405
|
+
startup: chunk.startup
|
|
1406
|
+
}));
|
|
1407
|
+
const styles = [...css].flatMap(([file, startup]) => {
|
|
1408
|
+
const size = cssSizes.get(file);
|
|
1409
|
+
return size ? [{
|
|
1410
|
+
...size,
|
|
1411
|
+
startup
|
|
1412
|
+
}] : [];
|
|
1413
|
+
});
|
|
1414
|
+
return {
|
|
1415
|
+
path: source.path,
|
|
1416
|
+
components: source.components,
|
|
1417
|
+
bytes: js.reduce((sum, file) => sum + file.bytes, 0),
|
|
1418
|
+
gzip: js.reduce((sum, file) => sum + file.gzip, 0),
|
|
1419
|
+
pageBytes: js.filter((file) => !file.startup).reduce((sum, file) => sum + file.bytes, 0),
|
|
1420
|
+
cssBytes: styles.reduce((sum, file) => sum + file.bytes, 0),
|
|
1421
|
+
files: [...js, ...styles].sort((left, right) => right.bytes - left.bytes || left.file.localeCompare(right.file))
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
/** What a first visit to each route of a client report loads, largest first. */
|
|
1425
|
+
function routesOf(report) {
|
|
1426
|
+
if (report.routeOptions?.unavailable || !report.routes?.length) return [];
|
|
1427
|
+
const graph = graphOf(report);
|
|
1428
|
+
return report.routes.map((source) => routeOf(graph, source)).sort((left, right) => right.bytes - left.bytes || left.path.localeCompare(right.path));
|
|
1429
|
+
}
|
|
1430
|
+
/** The route that renders `target`, using Vue Router's path grammar and ranking. */
|
|
1431
|
+
function matchRoute(routes, target, options = {}) {
|
|
1432
|
+
if (options.unavailable) return void 0;
|
|
1433
|
+
const path = target.replace(/[?#].*$/, "");
|
|
1434
|
+
const match = createRouterMatcher(routes.map((route, index) => ({
|
|
1435
|
+
path: route.path,
|
|
1436
|
+
name: String(index),
|
|
1437
|
+
children: []
|
|
1438
|
+
})), options).getRoutes().find((route) => route.re.test(path));
|
|
1439
|
+
return match ? routes[Number(match.record.name)] : void 0;
|
|
1440
|
+
}
|
|
1441
|
+
/** What a first visit to the route that renders `target` loads, and the modules of its page files. */
|
|
1442
|
+
function explainRoute(report, target) {
|
|
1443
|
+
const source = matchRoute(report.routes ?? [], target, report.routeOptions);
|
|
1444
|
+
if (!source) return void 0;
|
|
1445
|
+
const graph = graphOf(report);
|
|
1446
|
+
const route = routeOf(graph, source);
|
|
1447
|
+
return {
|
|
1448
|
+
target,
|
|
1449
|
+
route,
|
|
1450
|
+
modules: route.files.filter((file) => !file.startup).flatMap((file) => graph.byFile.get(file.file)?.modules.map((module) => ({
|
|
1451
|
+
id: module.id,
|
|
1452
|
+
file: file.file,
|
|
1453
|
+
bytes: module.bytes
|
|
1454
|
+
})) ?? []).sort((left, right) => right.bytes - left.bytes || left.id.localeCompare(right.id))
|
|
1455
|
+
};
|
|
1456
|
+
}
|
|
1457
|
+
//#endregion
|
|
1458
|
+
//#region src/report.ts
|
|
1459
|
+
/** The reports of the newest build. Reports that an older build left behind are ignored. */
|
|
1460
|
+
function latestBuild(reports) {
|
|
1461
|
+
const build = reports.map((report) => report.build).sort().at(-1);
|
|
1462
|
+
return reports.filter((report) => report.build === build).sort((left, right) => left.environment.localeCompare(right.environment));
|
|
1463
|
+
}
|
|
1464
|
+
function outputPath(report, file) {
|
|
1465
|
+
return report.outDir === "." ? file : `${report.outDir}/${file}`;
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* A server build that bundles the output of another server build, such as Nitro bundling Nuxt's SSR output, holds that
|
|
1469
|
+
* output as opaque modules. This returns, for each such module, the inner environment and chunk.
|
|
1470
|
+
*/
|
|
1471
|
+
function innerOutputs(reports) {
|
|
1472
|
+
const outputs = /* @__PURE__ */ new Map();
|
|
1473
|
+
for (const report of reports) {
|
|
1474
|
+
if (report.side !== "server") continue;
|
|
1475
|
+
for (const chunk of report.chunks) outputs.set(outputPath(report, chunk.file), {
|
|
1476
|
+
report,
|
|
1477
|
+
file: chunk.file
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
return outputs;
|
|
1481
|
+
}
|
|
1482
|
+
function isInner(report, reports) {
|
|
1483
|
+
if (report.side !== "server") return false;
|
|
1484
|
+
const files = new Set(report.chunks.map((chunk) => outputPath(report, chunk.file)));
|
|
1485
|
+
return reports.some((other) => other !== report && other.side === "server" && other.chunks.some((chunk) => chunk.modules.some((module) => files.has(module.id))));
|
|
1486
|
+
}
|
|
1487
|
+
/** Every module of a side, with SSR output that Nitro bundles replaced by the SSR modules, scaled to Nitro's bytes. */
|
|
1488
|
+
function placedModules(outer, all) {
|
|
1489
|
+
const inner = innerOutputs(all.filter((report) => !outer.includes(report)));
|
|
1490
|
+
const placed = [];
|
|
1491
|
+
for (const report of outer) for (const chunk of report.chunks) for (const module of chunk.modules) {
|
|
1492
|
+
const source = inner.get(module.id);
|
|
1493
|
+
const sourceChunk = source?.report.chunks.find((candidate) => candidate.file === source.file);
|
|
1494
|
+
const total = sourceChunk?.modules.reduce((sum, part) => sum + part.bytes, 0) ?? 0;
|
|
1495
|
+
if (!source || !sourceChunk || total === 0) {
|
|
1496
|
+
placed.push({
|
|
1497
|
+
...module,
|
|
1498
|
+
environment: report.environment,
|
|
1499
|
+
startup: chunk.startup
|
|
1500
|
+
});
|
|
1501
|
+
continue;
|
|
1502
|
+
}
|
|
1503
|
+
const shares = allocateBytes(sourceChunk.modules.map((part) => part.bytes), module.bytes);
|
|
1504
|
+
for (const [index, part] of sourceChunk.modules.entries()) placed.push({
|
|
1505
|
+
...part,
|
|
1506
|
+
bytes: shares[index],
|
|
1507
|
+
environment: source.report.environment,
|
|
1508
|
+
startup: chunk.startup
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
return placed;
|
|
1512
|
+
}
|
|
1513
|
+
function groupsOf(modules) {
|
|
1514
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1515
|
+
for (const module of modules) {
|
|
1516
|
+
const { name, kind } = moduleGroup(module.id);
|
|
1517
|
+
const group = groups.get(name) ?? {
|
|
1518
|
+
name,
|
|
1519
|
+
kind,
|
|
1520
|
+
bytes: 0,
|
|
1521
|
+
startupBytes: 0,
|
|
1522
|
+
modules: 0,
|
|
1523
|
+
ids: /* @__PURE__ */ new Set()
|
|
1524
|
+
};
|
|
1525
|
+
group.bytes += module.bytes;
|
|
1526
|
+
if (module.startup) group.startupBytes += module.bytes;
|
|
1527
|
+
group.ids.add(module.id);
|
|
1528
|
+
groups.set(name, group);
|
|
1529
|
+
}
|
|
1530
|
+
return [...groups.values()].map(({ ids, ...group }) => ({
|
|
1531
|
+
...group,
|
|
1532
|
+
modules: ids.size
|
|
1533
|
+
})).sort((left, right) => right.bytes - left.bytes || left.name.localeCompare(right.name));
|
|
1534
|
+
}
|
|
1535
|
+
function sideOf(side, reports) {
|
|
1536
|
+
const own = reports.filter((report) => report.side === side);
|
|
1537
|
+
const outer = own.filter((report) => !isInner(report, reports));
|
|
1538
|
+
if (!outer.length) return void 0;
|
|
1539
|
+
const chunks = outer.flatMap((report) => report.chunks);
|
|
1540
|
+
const startup = chunks.filter((chunk) => chunk.startup);
|
|
1541
|
+
return {
|
|
1542
|
+
environments: own.map((report) => report.environment),
|
|
1543
|
+
bytes: chunks.reduce((sum, chunk) => sum + chunk.bytes, 0),
|
|
1544
|
+
gzip: chunks.reduce((sum, chunk) => sum + chunk.gzip, 0),
|
|
1545
|
+
chunks: chunks.length,
|
|
1546
|
+
startup: {
|
|
1547
|
+
bytes: startup.reduce((sum, chunk) => sum + chunk.bytes, 0),
|
|
1548
|
+
gzip: startup.reduce((sum, chunk) => sum + chunk.gzip, 0),
|
|
1549
|
+
chunks: startup.length
|
|
1550
|
+
},
|
|
1551
|
+
groups: groupsOf(placedModules(outer, reports)),
|
|
1552
|
+
...routesField(outer)
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
function routesField(reports) {
|
|
1556
|
+
const unavailable = reports.find((report) => report.routeOptions?.unavailable)?.routeOptions?.unavailable;
|
|
1557
|
+
if (unavailable) return { routesUnavailable: unavailable };
|
|
1558
|
+
const routes = reports.flatMap(routesOf).sort((left, right) => right.bytes - left.bytes || left.path.localeCompare(right.path));
|
|
1559
|
+
return routes.length ? { routes } : {};
|
|
1560
|
+
}
|
|
1561
|
+
/** Joins the environment reports of one build into the report of the app. */
|
|
1562
|
+
function createBundleReport(reports) {
|
|
1563
|
+
const current = latestBuild(reports);
|
|
1564
|
+
if (!current.length) return void 0;
|
|
1565
|
+
const client = sideOf("client", current);
|
|
1566
|
+
const server = sideOf("server", current);
|
|
1567
|
+
const host = current.find((report) => report.host)?.host;
|
|
1568
|
+
const findings = checkBundle(current, server, host, (target) => explainBundle(current, target));
|
|
1569
|
+
return {
|
|
1570
|
+
schemaVersion: 1,
|
|
1571
|
+
build: current[0].build,
|
|
1572
|
+
...host ? { host } : {},
|
|
1573
|
+
...client ? { client } : {},
|
|
1574
|
+
...server ? { server } : {},
|
|
1575
|
+
findings
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
function matches(id, target) {
|
|
1579
|
+
if (id === target) return true;
|
|
1580
|
+
if (id.startsWith("node_modules/")) {
|
|
1581
|
+
if (moduleGroup(id).name === target || id.startsWith(`node_modules/${target}/`)) return true;
|
|
1582
|
+
}
|
|
1583
|
+
return !id.startsWith("node_modules/") && (id.startsWith(`${target}/`) || id.endsWith(`/${target}`));
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* The shortest import chain from an entry of one environment to a module that matches. Static imports come first: a
|
|
1587
|
+
* module that loads at startup gets the chain that loads it, not a lazy one. Without a static chain, `import()` counts.
|
|
1588
|
+
*/
|
|
1589
|
+
function chainIn(report, found) {
|
|
1590
|
+
return searchChain(report, found, false) ?? searchChain(report, found, true);
|
|
1591
|
+
}
|
|
1592
|
+
function searchChain(report, found, dynamic) {
|
|
1593
|
+
const modules = /* @__PURE__ */ new Map();
|
|
1594
|
+
for (const module of report.chunks.flatMap((chunk) => chunk.modules)) {
|
|
1595
|
+
const row = modules.get(module.id) ?? {
|
|
1596
|
+
entry: false,
|
|
1597
|
+
next: /* @__PURE__ */ new Set()
|
|
1598
|
+
};
|
|
1599
|
+
row.entry ||= module.entry;
|
|
1600
|
+
for (const next of dynamic ? [...module.imports, ...module.dynamicImports] : module.imports) row.next.add(next);
|
|
1601
|
+
modules.set(module.id, row);
|
|
1602
|
+
}
|
|
1603
|
+
const previous = /* @__PURE__ */ new Map();
|
|
1604
|
+
const queue = [...modules].filter(([, module]) => module.entry).map(([id]) => id);
|
|
1605
|
+
for (const id of queue) previous.set(id, void 0);
|
|
1606
|
+
for (let index = 0; index < queue.length; index++) {
|
|
1607
|
+
const id = queue[index];
|
|
1608
|
+
if (found(id)) {
|
|
1609
|
+
const chain = [id];
|
|
1610
|
+
for (let step = previous.get(id); step !== void 0; step = previous.get(step)) chain.unshift(step);
|
|
1611
|
+
return chain;
|
|
1612
|
+
}
|
|
1613
|
+
for (const next of modules.get(id)?.next ?? []) {
|
|
1614
|
+
if (previous.has(next) || !modules.has(next)) continue;
|
|
1615
|
+
previous.set(next, id);
|
|
1616
|
+
queue.push(next);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
/**
|
|
1621
|
+
* Says why a package, a file, or a group is in the output: its bytes on each side, whether it loads at startup, and
|
|
1622
|
+
* the shortest import chain from the entry. A chain through Nuxt's SSR output continues inside the SSR build.
|
|
1623
|
+
*/
|
|
1624
|
+
function explainBundle(reports, target) {
|
|
1625
|
+
const current = latestBuild(reports);
|
|
1626
|
+
const explanations = [];
|
|
1627
|
+
for (const side of ["client", "server"]) {
|
|
1628
|
+
const own = current.filter((report) => report.side === side);
|
|
1629
|
+
const outer = own.filter((report) => !isInner(report, current));
|
|
1630
|
+
const hits = placedModules(outer, current).filter((module) => matches(module.id, target));
|
|
1631
|
+
if (!hits.length) continue;
|
|
1632
|
+
const inner = own.filter((report) => !outer.includes(report));
|
|
1633
|
+
let chain = [];
|
|
1634
|
+
for (const report of outer) {
|
|
1635
|
+
const direct = chainIn(report, (id) => matches(id, target));
|
|
1636
|
+
if (direct) {
|
|
1637
|
+
chain = direct.map((id) => ({
|
|
1638
|
+
environment: report.environment,
|
|
1639
|
+
id
|
|
1640
|
+
}));
|
|
1641
|
+
break;
|
|
1642
|
+
}
|
|
1643
|
+
for (const nested of inner) {
|
|
1644
|
+
const innerChain = chainIn(nested, (id) => matches(id, target));
|
|
1645
|
+
if (!innerChain) continue;
|
|
1646
|
+
const entryFiles = new Set(nested.chunks.filter((chunk) => chunk.entry).map((chunk) => outputPath(nested, chunk.file)));
|
|
1647
|
+
const outerChain = chainIn(report, (id) => entryFiles.has(id));
|
|
1648
|
+
if (!outerChain) continue;
|
|
1649
|
+
chain = [...outerChain.map((id) => ({
|
|
1650
|
+
environment: report.environment,
|
|
1651
|
+
id
|
|
1652
|
+
})), ...innerChain.map((id) => ({
|
|
1653
|
+
environment: nested.environment,
|
|
1654
|
+
id
|
|
1655
|
+
}))];
|
|
1656
|
+
break;
|
|
1657
|
+
}
|
|
1658
|
+
if (chain.length) break;
|
|
1659
|
+
}
|
|
1660
|
+
explanations.push({
|
|
1661
|
+
target: hits.find((module) => module.id === target)?.id ?? chain.at(-1)?.id ?? hits[0].id,
|
|
1662
|
+
group: moduleGroup(hits[0].id).name,
|
|
1663
|
+
side,
|
|
1664
|
+
bytes: hits.reduce((sum, module) => sum + module.bytes, 0),
|
|
1665
|
+
startup: hits.some((module) => module.startup),
|
|
1666
|
+
chain
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
return explanations;
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* Says what the browser loads on a first visit to a page route, such as `/docs/kv`: the startup files, the files of the
|
|
1673
|
+
* route's layout and pages, and the modules that the route adds. `undefined` when no route of the last build matches.
|
|
1674
|
+
*/
|
|
1675
|
+
function explainBundleRoute(reports, target) {
|
|
1676
|
+
for (const report of latestBuild(reports)) {
|
|
1677
|
+
if (report.side !== "client") continue;
|
|
1678
|
+
const explanation = explainRoute(report, target);
|
|
1679
|
+
if (explanation) return explanation;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
//#endregion
|
|
1683
|
+
//#region ../internal/src/object.ts
|
|
1684
|
+
/** A non-null object that is not an array. Functions do not pass. */
|
|
1685
|
+
function isRecord(value) {
|
|
1686
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1687
|
+
}
|
|
1688
|
+
//#endregion
|
|
1689
|
+
//#region src/compare.ts
|
|
1690
|
+
function totals(side) {
|
|
1691
|
+
return side ? {
|
|
1692
|
+
bytes: side.bytes,
|
|
1693
|
+
gzip: side.gzip,
|
|
1694
|
+
startupBytes: side.startup.bytes,
|
|
1695
|
+
startupGzip: side.startup.gzip
|
|
1696
|
+
} : {
|
|
1697
|
+
bytes: 0,
|
|
1698
|
+
gzip: 0,
|
|
1699
|
+
startupBytes: 0,
|
|
1700
|
+
startupGzip: 0
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
function size(group) {
|
|
1704
|
+
return {
|
|
1705
|
+
bytes: group?.bytes ?? 0,
|
|
1706
|
+
startupBytes: group?.startupBytes ?? 0
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
function groupChanges(before, after) {
|
|
1710
|
+
const old = new Map(before.map((group) => [group.name, group]));
|
|
1711
|
+
const current = new Map(after.map((group) => [group.name, group]));
|
|
1712
|
+
const changes = [];
|
|
1713
|
+
for (const name of /* @__PURE__ */ new Set([...old.keys(), ...current.keys()])) {
|
|
1714
|
+
const from = old.get(name);
|
|
1715
|
+
const to = current.get(name);
|
|
1716
|
+
const delta = {
|
|
1717
|
+
bytes: size(to).bytes - size(from).bytes,
|
|
1718
|
+
startupBytes: size(to).startupBytes - size(from).startupBytes
|
|
1719
|
+
};
|
|
1720
|
+
if (from && to && !delta.bytes && !delta.startupBytes) continue;
|
|
1721
|
+
const change = !from ? "added" : !to ? "removed" : (delta.bytes || delta.startupBytes) > 0 ? "grew" : "shrank";
|
|
1722
|
+
changes.push({
|
|
1723
|
+
name,
|
|
1724
|
+
kind: (to ?? from).kind,
|
|
1725
|
+
change,
|
|
1726
|
+
before: size(from),
|
|
1727
|
+
after: size(to),
|
|
1728
|
+
delta
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
return changes.sort((left, right) => Math.abs(right.delta.bytes) - Math.abs(left.delta.bytes) || Math.abs(right.delta.startupBytes) - Math.abs(left.delta.startupBytes) || left.name.localeCompare(right.name));
|
|
1732
|
+
}
|
|
1733
|
+
function compareSide(before, after) {
|
|
1734
|
+
if (!before && !after) return void 0;
|
|
1735
|
+
const from = totals(before);
|
|
1736
|
+
const to = totals(after);
|
|
1737
|
+
return {
|
|
1738
|
+
before: from,
|
|
1739
|
+
after: to,
|
|
1740
|
+
delta: {
|
|
1741
|
+
bytes: to.bytes - from.bytes,
|
|
1742
|
+
gzip: to.gzip - from.gzip,
|
|
1743
|
+
startupBytes: to.startupBytes - from.startupBytes,
|
|
1744
|
+
startupGzip: to.startupGzip - from.startupGzip
|
|
1745
|
+
},
|
|
1746
|
+
groups: groupChanges(before?.groups ?? [], after?.groups ?? [])
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
/** What changed from `before` to `after`: the bytes of each side and of its startup code, and each group that changed. */
|
|
1750
|
+
function compareBundleReports(before, after) {
|
|
1751
|
+
const client = compareSide(before.client, after.client);
|
|
1752
|
+
const server = compareSide(before.server, after.server);
|
|
1753
|
+
return {
|
|
1754
|
+
schemaVersion: 1,
|
|
1755
|
+
builds: {
|
|
1756
|
+
before: before.build,
|
|
1757
|
+
after: after.build
|
|
1758
|
+
},
|
|
1759
|
+
...client ? { client } : {},
|
|
1760
|
+
...server ? { server } : {}
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
function isSize(value) {
|
|
1764
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
1765
|
+
}
|
|
1766
|
+
function isBundleGroup(value) {
|
|
1767
|
+
return isRecord(value) && typeof value.name === "string" && typeof value.kind === "string" && [
|
|
1768
|
+
"app",
|
|
1769
|
+
"dependency",
|
|
1770
|
+
"framework",
|
|
1771
|
+
"generated",
|
|
1772
|
+
"vitehub"
|
|
1773
|
+
].includes(value.kind) && isSize(value.bytes) && isSize(value.startupBytes) && isSize(value.modules);
|
|
1774
|
+
}
|
|
1775
|
+
function isBundleSide(value) {
|
|
1776
|
+
return isRecord(value) && Array.isArray(value.environments) && value.environments.every((environment) => typeof environment === "string") && isSize(value.bytes) && isSize(value.gzip) && isSize(value.chunks) && isRecord(value.startup) && isSize(value.startup.bytes) && isSize(value.startup.gzip) && isSize(value.startup.chunks) && Array.isArray(value.groups) && value.groups.every(isBundleGroup);
|
|
1777
|
+
}
|
|
1778
|
+
function isBundleReport(value) {
|
|
1779
|
+
return isRecord(value) && value.schemaVersion === 1 && typeof value.build === "string" && !("chunks" in value) && (value.client === void 0 || isBundleSide(value.client)) && (value.server === void 0 || isBundleSide(value.server));
|
|
1780
|
+
}
|
|
1781
|
+
/**
|
|
1782
|
+
* Reads a report to compare with. `path` is the output of `vitehub bundle --json`, a copy of `.vitehub/bundle/`, or a
|
|
1783
|
+
* project root that has `.vitehub/bundle/`. Returns `undefined` when `path` holds no report.
|
|
1784
|
+
*/
|
|
1785
|
+
function readSavedBundleReport(path) {
|
|
1786
|
+
if (!existsSync(path)) return void 0;
|
|
1787
|
+
if (statSync(path).isDirectory()) return createBundleReport(readEnvironmentReportFolder(existsSync(join(path, ".vitehub/bundle")) ? join(path, bundleReportDir) : path));
|
|
1788
|
+
try {
|
|
1789
|
+
const value = JSON.parse(readFileSync(path, "utf8"));
|
|
1790
|
+
return isBundleReport(value) ? value : void 0;
|
|
1791
|
+
} catch {
|
|
1792
|
+
return;
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
//#endregion
|
|
1796
|
+
export { explainBundleRoute as a, moduleId as c, bundleReportDir as d, readBundleReportRoot as f, writeEnvironmentReport as h, explainBundle as i, allocateBytes as l, writeBundleReportRoot as m, readSavedBundleReport as n, nuxtPageRoutes as o, readEnvironmentReports as p, createBundleReport as r, moduleGroup as s, compareBundleReports as t, formatBytes as u };
|