@vite-hub/bundle 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{cli-CJOjJmEo.js → cli-DMNhyWe9.js} +7 -6
- package/dist/{cli-ubYJpAL_.d.ts → cli-NCtitmny.d.ts} +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +2 -2
- package/dist/{compare-87VKOrA3.js → compare-CHsAWnIP.js} +43 -44
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CI2PJGqu.d.ts} +8 -2
- package/dist/operations.d.ts +1 -1
- package/dist/operations.js +5 -3
- package/dist/vite.d.ts +2 -3
- package/dist/vite.js +15 -26
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as explainBundleRoute, f as readBundleReportRoot, i as explainBundle, n as readSavedBundleReport, p as readEnvironmentReports, r as createBundleReport, t as compareBundleReports, u as formatBytes } from "./compare-
|
|
1
|
+
import { a as explainBundleRoute, f as readBundleReportRoot, i as explainBundle, n as readSavedBundleReport, p as readEnvironmentReports, r as createBundleReport, t as compareBundleReports, u as formatBytes } from "./compare-CHsAWnIP.js";
|
|
2
2
|
import { statSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, parse, resolve } from "node:path";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
@@ -47,7 +47,7 @@ function hasProjectRootDirectoryMarker(root) {
|
|
|
47
47
|
for (const marker of projectRootDirectoryMarkers) try {
|
|
48
48
|
if (statSync(resolve(root, ...marker)).isDirectory()) return true;
|
|
49
49
|
} catch (error) {
|
|
50
|
-
if (error
|
|
50
|
+
if (!isMissingProjectMarker(error)) throw error;
|
|
51
51
|
}
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
@@ -61,17 +61,20 @@ function hasProjectRootFileMarker(root, markers) {
|
|
|
61
61
|
try {
|
|
62
62
|
if (statSync(resolve(root, ...path)).isFile()) return true;
|
|
63
63
|
} catch (error) {
|
|
64
|
-
if (error
|
|
64
|
+
if (!isMissingProjectMarker(error)) throw error;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
return false;
|
|
68
68
|
}
|
|
69
|
+
function isMissingProjectMarker(error) {
|
|
70
|
+
const code = error.code;
|
|
71
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
72
|
+
}
|
|
69
73
|
//#endregion
|
|
70
74
|
//#region src/cli.ts
|
|
71
75
|
const reportUsage = "vitehub bundle [--against <report>] [--json]";
|
|
72
76
|
const whyUsage = "vitehub bundle why <package|file|/route> [--json]";
|
|
73
77
|
const missingReport = "No bundle report in .vitehub/bundle/. Set `bundle: true` in vitehub() (vite.config.ts) or in `vitehub` (nuxt.config.ts), then run a production build.\n";
|
|
74
|
-
/** A loaded project supplies its Vite root; runtime dispatch uses the last build's location. */
|
|
75
78
|
function projectRoot(context) {
|
|
76
79
|
const root = resolveViteHubProjectRoot(context.rootDir);
|
|
77
80
|
if (resolve(context.cwd) !== resolve(context.rootDir)) return root;
|
|
@@ -149,11 +152,9 @@ function findingLines(findings) {
|
|
|
149
152
|
lines.push("");
|
|
150
153
|
return lines;
|
|
151
154
|
}
|
|
152
|
-
/** Like `vite-doctor`: an error finding fails the command, a warning does not. */
|
|
153
155
|
function exitCode(findings) {
|
|
154
156
|
return findings.some((finding) => finding.severity === "error") ? 1 : 0;
|
|
155
157
|
}
|
|
156
|
-
/** `+1.2 kB`, `-300 B`, or `0 B`. */
|
|
157
158
|
function formatDelta(bytes) {
|
|
158
159
|
return bytes > 0 ? `+${formatBytes(bytes)}` : bytes < 0 ? `-${formatBytes(-bytes)}` : "0 B";
|
|
159
160
|
}
|
|
@@ -3,6 +3,7 @@ import "nostics";
|
|
|
3
3
|
interface HostCliRunResult {
|
|
4
4
|
exitCode: number | null;
|
|
5
5
|
stdout: string;
|
|
6
|
+
stderr?: string;
|
|
6
7
|
}
|
|
7
8
|
/** Runs a host CLI with an argument array and no shell, and returns its stdout. */
|
|
8
9
|
type HostCliRun = (command: string, args: readonly string[], options: {
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as ViteHubCliContributor } from "./cli-
|
|
1
|
+
import { t as ViteHubCliContributor } from "./cli-NCtitmny.js";
|
|
2
2
|
//#region src/bytes.d.ts
|
|
3
3
|
/** `1234567` becomes `1.23 MB`, like Vite's build output. */
|
|
4
4
|
export declare function formatBytes(bytes: number): string;
|
package/dist/cli.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { u as formatBytes } from "./compare-
|
|
2
|
-
import { t as bundleCliContributor } from "./cli-
|
|
1
|
+
import { u as formatBytes } from "./compare-CHsAWnIP.js";
|
|
2
|
+
import { t as bundleCliContributor } from "./cli-DMNhyWe9.js";
|
|
3
3
|
export { bundleCliContributor, formatBytes };
|
|
@@ -76,7 +76,6 @@ function formatBytes(bytes) {
|
|
|
76
76
|
}
|
|
77
77
|
//#endregion
|
|
78
78
|
//#region src/diagnostics.ts
|
|
79
|
-
/** The largest Worker that Cloudflare accepts, before compression. */
|
|
80
79
|
const cloudflareWorkerSizeLimit = 67108864;
|
|
81
80
|
const bundleDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
82
81
|
docsBase: "https://vitehub.dev/docs/bundle/diagnostics",
|
|
@@ -112,6 +111,12 @@ const frameworkPackages = /* @__PURE__ */ new Set([
|
|
|
112
111
|
"vue",
|
|
113
112
|
"vue-router"
|
|
114
113
|
]);
|
|
114
|
+
function manifestPackageName(manifestFile) {
|
|
115
|
+
if (!existsSync(manifestFile)) return void 0;
|
|
116
|
+
const manifest = JSON.parse(readFileSync(manifestFile, "utf8").replace(/^\uFEFF/, ""));
|
|
117
|
+
const name = manifest && typeof manifest === "object" ? Reflect.get(manifest, "name") : void 0;
|
|
118
|
+
return typeof name === "string" ? name : void 0;
|
|
119
|
+
}
|
|
115
120
|
/** The root-relative id of a module. Dependencies become `node_modules/<package>/<file>`, wherever pnpm stores them. */
|
|
116
121
|
function moduleId(id, root, packages = /* @__PURE__ */ new Map()) {
|
|
117
122
|
const clean = id.replace(/\\/g, "/").replace(/\?.*$/, "").replace(/^\0/, "");
|
|
@@ -129,14 +134,7 @@ function moduleId(id, root, packages = /* @__PURE__ */ new Map()) {
|
|
|
129
134
|
if (!withinRoot) {
|
|
130
135
|
let dir = posix.dirname(clean);
|
|
131
136
|
while (dir !== ".") {
|
|
132
|
-
if (!packages.has(dir)) {
|
|
133
|
-
let name;
|
|
134
|
-
try {
|
|
135
|
-
const manifest = JSON.parse(readFileSync(`${dir}/package.json`, "utf8"));
|
|
136
|
-
if (manifest && typeof manifest === "object" && typeof Reflect.get(manifest, "name") === "string") name = Reflect.get(manifest, "name");
|
|
137
|
-
} catch {}
|
|
138
|
-
packages.set(dir, name);
|
|
139
|
-
}
|
|
137
|
+
if (!packages.has(dir)) packages.set(dir, manifestPackageName(`${dir}/package.json`));
|
|
140
138
|
const name = packages.get(dir);
|
|
141
139
|
if (name) return `node_modules/${name}/${posix.relative(dir, clean)}`;
|
|
142
140
|
const parent = posix.dirname(dir);
|
|
@@ -223,13 +221,11 @@ function finding(code, diagnostic, rest) {
|
|
|
223
221
|
function serverChain(explain, target) {
|
|
224
222
|
return explain(target).find((explanation) => explanation.side === "server")?.chain ?? [];
|
|
225
223
|
}
|
|
226
|
-
/** Each rule once, also when several server environments carry it. */
|
|
227
224
|
function uniqueRules(reports) {
|
|
228
225
|
const rules = /* @__PURE__ */ new Map();
|
|
229
226
|
for (const report of reports) for (const rule of report.side === "server" ? report.rules ?? [] : []) rules.set(JSON.stringify(rule), rule);
|
|
230
227
|
return [...rules.values()];
|
|
231
228
|
}
|
|
232
|
-
/** A feature's configuration says nothing about independent consumers of the same packages. */
|
|
233
229
|
function exclusivelyOwned(reports, rule) {
|
|
234
230
|
let ownedImport = false;
|
|
235
231
|
for (const report of reports) {
|
|
@@ -246,7 +242,6 @@ function exclusivelyOwned(reports, rule) {
|
|
|
246
242
|
}
|
|
247
243
|
return ownedImport;
|
|
248
244
|
}
|
|
249
|
-
/** A package that a feature declared as not needed at startup, and that loads at startup. */
|
|
250
245
|
function startupUnused(server, rules, explain) {
|
|
251
246
|
return rules.flatMap((rule) => {
|
|
252
247
|
const packages = server.groups.filter((group) => rule.packages.includes(group.name) && group.startupBytes > 0).map((group) => ({
|
|
@@ -268,7 +263,6 @@ function startupUnused(server, rules, explain) {
|
|
|
268
263
|
})];
|
|
269
264
|
});
|
|
270
265
|
}
|
|
271
|
-
/** Server output over the size that the host accepts. */
|
|
272
266
|
function hostSizeLimit(server, host, explain) {
|
|
273
267
|
if (!host?.startsWith("cloudflare") || server.bytes <= 67108864) return [];
|
|
274
268
|
const largest = server.groups[0];
|
|
@@ -1376,13 +1370,12 @@ function graphOf(report) {
|
|
|
1376
1370
|
const holders = /* @__PURE__ */ new Map();
|
|
1377
1371
|
for (const chunk of report.chunks) for (const module of chunk.modules) holders.set(module.id, [...holders.get(module.id) ?? [], chunk.file]);
|
|
1378
1372
|
return {
|
|
1379
|
-
report,
|
|
1380
1373
|
byFile: new Map(report.chunks.map((chunk) => [chunk.file, chunk])),
|
|
1374
|
+
stylesheets: new Map((report.css ?? []).map((file) => [file.file, file])),
|
|
1381
1375
|
holders,
|
|
1382
1376
|
startup: report.chunks.filter((chunk) => chunk.startup).map((chunk) => chunk.file)
|
|
1383
1377
|
};
|
|
1384
1378
|
}
|
|
1385
|
-
/** The JavaScript files that a first visit loads: the startup files and the component files with their static imports. */
|
|
1386
1379
|
function routeFiles(graph, source) {
|
|
1387
1380
|
const files = new Set(graph.startup);
|
|
1388
1381
|
const pending = source.components.flatMap((id) => graph.holders.get(id) ?? []);
|
|
@@ -1396,7 +1389,6 @@ function routeFiles(graph, source) {
|
|
|
1396
1389
|
}
|
|
1397
1390
|
function routeOf(graph, source) {
|
|
1398
1391
|
const files = [...routeFiles(graph, source)].flatMap((file) => graph.byFile.get(file) ?? []);
|
|
1399
|
-
const cssSizes = new Map((graph.report.css ?? []).map((file) => [file.file, file]));
|
|
1400
1392
|
const css = /* @__PURE__ */ new Map();
|
|
1401
1393
|
for (const chunk of files) for (const file of chunk.css ?? []) css.set(file, (css.get(file) ?? false) || chunk.startup);
|
|
1402
1394
|
const js = files.map((chunk) => ({
|
|
@@ -1406,7 +1398,7 @@ function routeOf(graph, source) {
|
|
|
1406
1398
|
startup: chunk.startup
|
|
1407
1399
|
}));
|
|
1408
1400
|
const styles = [...css].flatMap(([file, startup]) => {
|
|
1409
|
-
const size =
|
|
1401
|
+
const size = graph.stylesheets.get(file);
|
|
1410
1402
|
return size ? [{
|
|
1411
1403
|
...size,
|
|
1412
1404
|
startup
|
|
@@ -1465,17 +1457,13 @@ function latestBuild(reports) {
|
|
|
1465
1457
|
function outputPath(report, file) {
|
|
1466
1458
|
return report.outDir === "." ? file : `${report.outDir}/${file}`;
|
|
1467
1459
|
}
|
|
1468
|
-
/**
|
|
1469
|
-
* A server build that bundles the output of another server build, such as Nitro bundling Nuxt's SSR output, holds that
|
|
1470
|
-
* output as opaque modules. This returns, for each such module, the inner environment and chunk.
|
|
1471
|
-
*/
|
|
1472
1460
|
function innerOutputs(reports) {
|
|
1473
1461
|
const outputs = /* @__PURE__ */ new Map();
|
|
1474
1462
|
for (const report of reports) {
|
|
1475
1463
|
if (report.side !== "server") continue;
|
|
1476
1464
|
for (const chunk of report.chunks) outputs.set(outputPath(report, chunk.file), {
|
|
1477
|
-
report,
|
|
1478
|
-
|
|
1465
|
+
environment: report.environment,
|
|
1466
|
+
chunk
|
|
1479
1467
|
});
|
|
1480
1468
|
}
|
|
1481
1469
|
return outputs;
|
|
@@ -1485,15 +1473,13 @@ function isInner(report, reports) {
|
|
|
1485
1473
|
const files = new Set(report.chunks.map((chunk) => outputPath(report, chunk.file)));
|
|
1486
1474
|
return reports.some((other) => other !== report && other.side === "server" && other.chunks.some((chunk) => chunk.modules.some((module) => files.has(module.id))));
|
|
1487
1475
|
}
|
|
1488
|
-
/** Every module of a side, with SSR output that Nitro bundles replaced by the SSR modules, scaled to Nitro's bytes. */
|
|
1489
1476
|
function placedModules(outer, all) {
|
|
1490
1477
|
const inner = innerOutputs(all.filter((report) => !outer.includes(report)));
|
|
1491
1478
|
const placed = [];
|
|
1492
1479
|
for (const report of outer) for (const chunk of report.chunks) for (const module of chunk.modules) {
|
|
1493
1480
|
const source = inner.get(module.id);
|
|
1494
|
-
const
|
|
1495
|
-
|
|
1496
|
-
if (!source || !sourceChunk || total === 0) {
|
|
1481
|
+
const total = source?.chunk.modules.reduce((sum, part) => sum + part.bytes, 0) ?? 0;
|
|
1482
|
+
if (!source || total === 0) {
|
|
1497
1483
|
placed.push({
|
|
1498
1484
|
...module,
|
|
1499
1485
|
environment: report.environment,
|
|
@@ -1501,11 +1487,11 @@ function placedModules(outer, all) {
|
|
|
1501
1487
|
});
|
|
1502
1488
|
continue;
|
|
1503
1489
|
}
|
|
1504
|
-
const shares = allocateBytes(
|
|
1505
|
-
for (const [index, part] of
|
|
1490
|
+
const shares = allocateBytes(source.chunk.modules.map((part) => part.bytes), module.bytes);
|
|
1491
|
+
for (const [index, part] of source.chunk.modules.entries()) placed.push({
|
|
1506
1492
|
...part,
|
|
1507
1493
|
bytes: shares[index],
|
|
1508
|
-
environment: source.
|
|
1494
|
+
environment: source.environment,
|
|
1509
1495
|
startup: chunk.startup
|
|
1510
1496
|
});
|
|
1511
1497
|
}
|
|
@@ -1576,17 +1562,17 @@ function createBundleReport(reports) {
|
|
|
1576
1562
|
findings
|
|
1577
1563
|
};
|
|
1578
1564
|
}
|
|
1579
|
-
function
|
|
1580
|
-
if (
|
|
1581
|
-
|
|
1582
|
-
|
|
1565
|
+
function moduleMatcher(target, reports) {
|
|
1566
|
+
if (target.startsWith("./") || target.startsWith(".\\")) {
|
|
1567
|
+
const file = reports.some((report) => report.chunks.some((chunk) => chunk.modules.some((module) => module.id === target))) ? target : posix.normalize(target.replaceAll("\\", "/"));
|
|
1568
|
+
return (id) => id === file;
|
|
1583
1569
|
}
|
|
1584
|
-
return
|
|
1570
|
+
return (id) => {
|
|
1571
|
+
if (id === target) return true;
|
|
1572
|
+
if (id.startsWith("node_modules/")) return moduleGroup(id).name === target || id.startsWith(`node_modules/${target}/`);
|
|
1573
|
+
return id.startsWith(`${target}/`) || id.endsWith(`/${target}`);
|
|
1574
|
+
};
|
|
1585
1575
|
}
|
|
1586
|
-
/**
|
|
1587
|
-
* The shortest import chain from an entry of one environment to a module that matches. Static imports come first: a
|
|
1588
|
-
* module that loads at startup gets the chain that loads it, not a lazy one. Without a static chain, `import()` counts.
|
|
1589
|
-
*/
|
|
1590
1576
|
function chainIn(report, found) {
|
|
1591
1577
|
return searchChain(report, found, false) ?? searchChain(report, found, true);
|
|
1592
1578
|
}
|
|
@@ -1624,16 +1610,17 @@ function searchChain(report, found, dynamic) {
|
|
|
1624
1610
|
*/
|
|
1625
1611
|
function explainBundle(reports, target) {
|
|
1626
1612
|
const current = latestBuild(reports);
|
|
1613
|
+
const matches = moduleMatcher(target, current);
|
|
1627
1614
|
const explanations = [];
|
|
1628
1615
|
for (const side of ["client", "server"]) {
|
|
1629
1616
|
const own = current.filter((report) => report.side === side);
|
|
1630
1617
|
const outer = own.filter((report) => !isInner(report, current));
|
|
1631
|
-
const hits = placedModules(outer, current).filter((module) => matches(module.id
|
|
1618
|
+
const hits = placedModules(outer, current).filter((module) => matches(module.id));
|
|
1632
1619
|
if (!hits.length) continue;
|
|
1633
1620
|
const inner = own.filter((report) => !outer.includes(report));
|
|
1634
1621
|
let chain = [];
|
|
1635
1622
|
for (const report of outer) {
|
|
1636
|
-
const direct = chainIn(report,
|
|
1623
|
+
const direct = chainIn(report, matches);
|
|
1637
1624
|
if (direct) {
|
|
1638
1625
|
chain = direct.map((id) => ({
|
|
1639
1626
|
environment: report.environment,
|
|
@@ -1642,7 +1629,7 @@ function explainBundle(reports, target) {
|
|
|
1642
1629
|
break;
|
|
1643
1630
|
}
|
|
1644
1631
|
for (const nested of inner) {
|
|
1645
|
-
const innerChain = chainIn(nested,
|
|
1632
|
+
const innerChain = chainIn(nested, matches);
|
|
1646
1633
|
if (!innerChain) continue;
|
|
1647
1634
|
const entryFiles = new Set(nested.chunks.filter((chunk) => chunk.entry).map((chunk) => outputPath(nested, chunk.file)));
|
|
1648
1635
|
const outerChain = chainIn(report, (id) => entryFiles.has(id));
|
|
@@ -1775,11 +1762,23 @@ function isBundleReport(value) {
|
|
|
1775
1762
|
}
|
|
1776
1763
|
/**
|
|
1777
1764
|
* Reads a report to compare with. `path` is the output of `vitehub bundle --json`, a copy of `.vitehub/bundle/`, or a
|
|
1778
|
-
* project root that has `.vitehub/bundle
|
|
1765
|
+
* project root that has `.vitehub/bundle/` or a `.vitehub/bundle-root.json` that points to it. Returns `undefined` when
|
|
1766
|
+
* `path` holds no report.
|
|
1779
1767
|
*/
|
|
1780
1768
|
function readSavedBundleReport(path) {
|
|
1781
1769
|
if (!existsSync(path)) return void 0;
|
|
1782
|
-
if (statSync(path).isDirectory())
|
|
1770
|
+
if (statSync(path).isDirectory()) {
|
|
1771
|
+
const reportRoot = readBundleReportRoot(path);
|
|
1772
|
+
for (const folder of [
|
|
1773
|
+
...reportRoot ? [join(reportRoot, bundleReportDir)] : [],
|
|
1774
|
+
join(path, bundleReportDir),
|
|
1775
|
+
path
|
|
1776
|
+
]) {
|
|
1777
|
+
const report = createBundleReport(readEnvironmentReportFolder(folder));
|
|
1778
|
+
if (report) return report;
|
|
1779
|
+
}
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1783
1782
|
try {
|
|
1784
1783
|
const value = JSON.parse(readFileSync(path, "utf8"));
|
|
1785
1784
|
return isBundleReport(value) ? value : void 0;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { C as BundleStartupRule, S as BundleSideComparison, _ as BundleRouteFile
|
|
|
4
4
|
export declare function compareBundleReports(before: BundleReport, after: BundleReport): BundleComparison;
|
|
5
5
|
/**
|
|
6
6
|
* Reads a report to compare with. `path` is the output of `vitehub bundle --json`, a copy of `.vitehub/bundle/`, or a
|
|
7
|
-
* project root that has `.vitehub/bundle
|
|
7
|
+
* project root that has `.vitehub/bundle/` or a `.vitehub/bundle-root.json` that points to it. Returns `undefined` when
|
|
8
|
+
* `path` holds no report.
|
|
8
9
|
*/
|
|
9
10
|
export declare function readSavedBundleReport(path: string): BundleReport | undefined;
|
|
10
11
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as explainBundleRoute, d as bundleReportDir, i as explainBundle, n as readSavedBundleReport, p as readEnvironmentReports, r as createBundleReport, s as moduleGroup, t as compareBundleReports } from "./compare-
|
|
1
|
+
import { a as explainBundleRoute, d as bundleReportDir, i as explainBundle, n as readSavedBundleReport, p as readEnvironmentReports, r as createBundleReport, s as moduleGroup, t as compareBundleReports } from "./compare-CHsAWnIP.js";
|
|
2
2
|
//#region src/index.ts
|
|
3
3
|
/** The report of the last build with `bundle` on, or `undefined` when there is none. */
|
|
4
4
|
function readBundleReport(root) {
|
|
@@ -104,6 +104,11 @@ interface OperationAccess {
|
|
|
104
104
|
*/
|
|
105
105
|
readonly sections: "all" | readonly string[];
|
|
106
106
|
readonly user?: OperationUser;
|
|
107
|
+
/**
|
|
108
|
+
* Who signed the call: `"console"` when the ViteHub Console signed it for a person, whose `user` is then a Console
|
|
109
|
+
* account and not an app user, or `"cli"` for a key. Not set for other calls.
|
|
110
|
+
*/
|
|
111
|
+
readonly via?: "console" | "cli";
|
|
107
112
|
}
|
|
108
113
|
interface OperationContext {
|
|
109
114
|
/** The checked Console access of the call. */
|
|
@@ -166,7 +171,8 @@ interface OperationDefinition<Input, Output> {
|
|
|
166
171
|
/** Standard Schema (valibot in this repo). Its Standard JSON Schema builds CLI flags and the MCP input schema. */
|
|
167
172
|
input: StandardSchemaV1<unknown, Input>;
|
|
168
173
|
output?: StandardSchemaV1<unknown, Output>;
|
|
169
|
-
|
|
174
|
+
/** `false`: no `vitehub` command. The Console and MCP still call the operation. */
|
|
175
|
+
cli?: false | {
|
|
170
176
|
/** Defaults: namespace = section, command = verb. */
|
|
171
177
|
namespace?: string;
|
|
172
178
|
/** A space groups commands: `jobs list` and `jobs show` run as `vitehub <namespace> jobs list` and `jobs show`. */
|
|
@@ -207,7 +213,7 @@ interface OperationDefinition<Input, Output> {
|
|
|
207
213
|
/** An operation of any input and output, as a registry holds it. */
|
|
208
214
|
interface AnyOperation extends Omit<OperationDefinition<unknown, unknown>, "cli" | "input" | "mcp" | "output" | "readOnlyWhen" | "run" | "scope" | "section"> {
|
|
209
215
|
readOnlyWhen?: (input: never) => boolean;
|
|
210
|
-
cli?: {
|
|
216
|
+
cli?: false | {
|
|
211
217
|
namespace?: string;
|
|
212
218
|
command?: string;
|
|
213
219
|
default?: boolean;
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as BundleExplanation, g as BundleRouteExplanation } from "./types-DBa_sXqC.js";
|
|
2
|
-
import { t as AnyOperation } from "./operation-definition-
|
|
2
|
+
import { t as AnyOperation } from "./operation-definition-CI2PJGqu.js";
|
|
3
3
|
//#region src/operations.d.ts
|
|
4
4
|
/** What `bundle.why` returns. `vitehub bundle why --json` prints the same object. */
|
|
5
5
|
export type BundleWhyResult = BundleRouteExplanation | {
|
package/dist/operations.js
CHANGED
|
@@ -28,7 +28,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
28
28
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
29
29
|
},
|
|
30
30
|
INTERNAL_R0022: {
|
|
31
|
-
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
|
|
31
|
+
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
|
|
32
32
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
33
33
|
},
|
|
34
34
|
INTERNAL_R0024: {
|
|
@@ -247,6 +247,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
247
247
|
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
248
248
|
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
249
249
|
},
|
|
250
|
+
INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
|
|
251
|
+
why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
|
|
252
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
|
|
253
|
+
},
|
|
250
254
|
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
251
255
|
why: "[vitehub] A derived secret requires a purpose.",
|
|
252
256
|
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
@@ -404,7 +408,6 @@ function operationInputJsonSchema(operation) {
|
|
|
404
408
|
}
|
|
405
409
|
//#endregion
|
|
406
410
|
//#region src/operations.ts
|
|
407
|
-
/** Why `bundle.report` and `bundle.why` cannot answer. The checks of a report are in `bundleDiagnostics`. */
|
|
408
411
|
const bundleOperationDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
409
412
|
docsBase: "https://vitehub.dev/docs/bundle/diagnostics",
|
|
410
413
|
codes: {
|
|
@@ -419,7 +422,6 @@ const bundleOperationDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
419
422
|
}
|
|
420
423
|
});
|
|
421
424
|
const reader = () => import("./index.js");
|
|
422
|
-
/** The environment reports of the project that the dev server runs. A deployed server has no project files. */
|
|
423
425
|
async function reportsOf(context) {
|
|
424
426
|
if (context.development !== true || !context.projectRoot) throw Object.assign(bundleOperationDiagnostics.BUNDLE_DEV_SERVER_REQUIRED(), { status: 409 });
|
|
425
427
|
const reports = (await reader()).readEnvironmentReports(context.projectRoot);
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as ViteHubCliPluginMetadata } from "./cli-
|
|
1
|
+
import { n as ViteHubCliPluginMetadata } from "./cli-NCtitmny.js";
|
|
2
2
|
import { C as BundleStartupRule, y as BundleRouteOptions } from "./types-DBa_sXqC.js";
|
|
3
|
-
import { n as OperationContributionEntry } from "./operation-definition-
|
|
3
|
+
import { n as OperationContributionEntry } from "./operation-definition-CI2PJGqu.js";
|
|
4
4
|
import { Plugin } from "vite";
|
|
5
5
|
//#region src/routes.d.ts
|
|
6
6
|
/** A page route with the absolute files of the components that render it, outermost first. */
|
|
@@ -42,7 +42,6 @@ export declare function nuxtPageRoutes(pages: readonly NuxtPageLike[], layouts?:
|
|
|
42
42
|
interface BundlerConfig {
|
|
43
43
|
plugins?: unknown;
|
|
44
44
|
}
|
|
45
|
-
/** The parts of a Nitro 3 instance that the server report reads. */
|
|
46
45
|
interface NitroLike {
|
|
47
46
|
hooks: {
|
|
48
47
|
hook: (name: "build:config", callback: (nitro: unknown, config: {
|
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as moduleId, h as writeEnvironmentReport, l as allocateBytes, m as writeBundleReportRoot, o as nuxtPageRoutes } from "./compare-
|
|
2
|
-
import { n as resolveViteHubProjectRoot, t as bundleCliContributor } from "./cli-
|
|
1
|
+
import { c as moduleId, h as writeEnvironmentReport, l as allocateBytes, m as writeBundleReportRoot, o as nuxtPageRoutes } from "./compare-CHsAWnIP.js";
|
|
2
|
+
import { n as resolveViteHubProjectRoot, t as bundleCliContributor } from "./cli-DMNhyWe9.js";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { dirname, resolve } from "node:path";
|
|
5
5
|
import { defineDiagnostics } from "nostics";
|
|
@@ -161,11 +161,6 @@ function relativeTo(root, path) {
|
|
|
161
161
|
const normalized = path.replace(/\\/g, "/");
|
|
162
162
|
return normalized === base ? "." : normalized.startsWith(`${base}/`) ? normalized.slice(base.length + 1) : normalized;
|
|
163
163
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Reads the imports of a module as report ids. The bundler drops modules that leave no code, such as a package index
|
|
166
|
-
* that only re-exports, so an import of such a module continues to the modules that it imports. An edge is dynamic
|
|
167
|
-
* when one step on the way is `import()`.
|
|
168
|
-
*/
|
|
169
164
|
function createEdgeReader(ids, getModuleInfo) {
|
|
170
165
|
const through = /* @__PURE__ */ new Map();
|
|
171
166
|
const visit = (raw, visiting) => {
|
|
@@ -198,18 +193,21 @@ function createEdgeReader(ids, getModuleInfo) {
|
|
|
198
193
|
};
|
|
199
194
|
return (raw) => visit(raw, /* @__PURE__ */ new Set());
|
|
200
195
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const chunks = Object.values(bundle).filter(isChunk);
|
|
204
|
-
const byFile = new Map(chunks.map((chunk) => [chunk.fileName, chunk]));
|
|
205
|
-
const startup = /* @__PURE__ */ new Set();
|
|
206
|
-
const pending = chunks.filter((chunk) => chunk.isEntry).map((chunk) => chunk.fileName);
|
|
196
|
+
function staticChunkFiles(byFile, pending) {
|
|
197
|
+
const loaded = /* @__PURE__ */ new Set();
|
|
207
198
|
while (pending.length) {
|
|
208
199
|
const file = pending.pop();
|
|
209
|
-
if (
|
|
210
|
-
|
|
200
|
+
if (loaded.has(file)) continue;
|
|
201
|
+
loaded.add(file);
|
|
211
202
|
pending.push(...byFile.get(file)?.imports ?? []);
|
|
212
203
|
}
|
|
204
|
+
return loaded;
|
|
205
|
+
}
|
|
206
|
+
/** Reads one build's output: the bytes of each chunk, the share of each module, and the startup files. */
|
|
207
|
+
function collectEnvironmentReport(bundle, options) {
|
|
208
|
+
const chunks = Object.values(bundle).filter(isChunk);
|
|
209
|
+
const byFile = new Map(chunks.map((chunk) => [chunk.fileName, chunk]));
|
|
210
|
+
const startup = staticChunkFiles(byFile, chunks.filter((chunk) => chunk.isEntry).map((chunk) => chunk.fileName));
|
|
213
211
|
const ids = /* @__PURE__ */ new Map();
|
|
214
212
|
const packages = /* @__PURE__ */ new Map();
|
|
215
213
|
const isEntry = (id, chunk) => options.getModuleInfo(id)?.isEntry ?? chunk.facadeModuleId === id;
|
|
@@ -266,14 +264,8 @@ function collectEnvironmentReport(bundle, options) {
|
|
|
266
264
|
const layout = route.layout;
|
|
267
265
|
if (layout) {
|
|
268
266
|
const pages = new Set(files.filter((file) => file !== layout.file).map((file) => moduleId(file, options.root, packages)));
|
|
269
|
-
const
|
|
270
|
-
const
|
|
271
|
-
while (pending.length) {
|
|
272
|
-
const chunk = pending.pop();
|
|
273
|
-
if (loaded.has(chunk.file)) continue;
|
|
274
|
-
loaded.add(chunk.file);
|
|
275
|
-
pending.push(...rows.filter((candidate) => chunk.imports?.includes(candidate.file)));
|
|
276
|
-
}
|
|
267
|
+
const roots = rows.filter((chunk) => chunk.startup || chunk.modules.some((module) => pages.has(module.id)));
|
|
268
|
+
const loaded = staticChunkFiles(byFile, roots.map((chunk) => chunk.file));
|
|
277
269
|
const renderer = moduleId(layout.component, options.root, packages);
|
|
278
270
|
if (!rows.some((chunk) => loaded.has(chunk.file) && chunk.modules.some((module) => module.id === renderer))) files = files.filter((file) => file !== layout.file);
|
|
279
271
|
}
|
|
@@ -297,7 +289,6 @@ function collectEnvironmentReport(bundle, options) {
|
|
|
297
289
|
//#endregion
|
|
298
290
|
//#region src/vite.ts
|
|
299
291
|
const outputsKey = Symbol.for("vitehub.bundle.outputs");
|
|
300
|
-
/** Vite and Nitro can observe the same output; only that output object is deduplicated. */
|
|
301
292
|
function writtenOutputs() {
|
|
302
293
|
const outputs = Reflect.get(globalThis, outputsKey) ?? /* @__PURE__ */ new WeakMap();
|
|
303
294
|
Reflect.set(globalThis, outputsKey, outputs);
|
|
@@ -306,7 +297,6 @@ function writtenOutputs() {
|
|
|
306
297
|
function newBuildId() {
|
|
307
298
|
return `${(/* @__PURE__ */ new Date()).toISOString()}-${randomUUID()}`;
|
|
308
299
|
}
|
|
309
|
-
/** Asks the features of the build for their rules. Each feature adds them to `rules` in its `vitehub:bundle:rules` hook. */
|
|
310
300
|
async function serverFacts(nitro) {
|
|
311
301
|
const rules = [];
|
|
312
302
|
if (!nitro) return { rules };
|
|
@@ -343,7 +333,6 @@ function writeReport(context, bundle, options, facts) {
|
|
|
343
333
|
written.add(key);
|
|
344
334
|
outputs.set(bundle, written);
|
|
345
335
|
}
|
|
346
|
-
/** Adds a Rolldown plugin to a Nitro build that bundles on its own, such as the server build of Nuxt 5. */
|
|
347
336
|
function bundleNitroModule(buildId, onSetup) {
|
|
348
337
|
return {
|
|
349
338
|
name: "@vite-hub/bundle/nitro",
|