brumate 0.8.0 → 0.9.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/{boot-BkUdiYOF.d.ts → boot-ej-9NRT3.d.ts} +20 -2
- package/dist/cli.js +88 -82
- package/dist/cli.js.map +1 -1
- package/dist/{client-B0FXW5Kw.js → client-B-ww-PQ7.js} +402 -63
- package/dist/client-B-ww-PQ7.js.map +1 -0
- package/dist/{client-Cq6aTiDs.d.ts → client-Do6IBIhI.d.ts} +58 -14
- package/dist/{defer-BMIMP4Hq.js → defer-JD2FK9mV.js} +5 -3
- package/dist/defer-JD2FK9mV.js.map +1 -0
- package/dist/{devtools-calls-DGW6nLZ2.js → devtools-calls-DCjuSkim.js} +3 -3
- package/dist/{devtools-calls-DGW6nLZ2.js.map → devtools-calls-DCjuSkim.js.map} +1 -1
- package/dist/{devtools-panel-B1nF1KB7.js → devtools-panel-DLeWTPhU.js} +4 -4
- package/dist/{devtools-panel-B1nF1KB7.js.map → devtools-panel-DLeWTPhU.js.map} +1 -1
- package/dist/{devtools-B4prrxht.js → devtools-tuq7ATGN.js} +10 -7
- package/dist/devtools-tuq7ATGN.js.map +1 -0
- package/dist/{error-catalog-DakxjSgj.js → error-catalog-BBWB7w-E.js} +11 -4
- package/dist/error-catalog-BBWB7w-E.js.map +1 -0
- package/dist/{error-catalog-VxLbz-6p.js → error-catalog-CbmQqfat.js} +1 -1
- package/dist/{events-LgLdp1R7.js → events-BDVITj3P.js} +3 -5
- package/dist/events-BDVITj3P.js.map +1 -0
- package/dist/{features-DwMYKBIC.js → features-Cte5aj20.js} +8 -2
- package/dist/features-Cte5aj20.js.map +1 -0
- package/dist/{files-D5GtxwEQ.js → files-Bz0lAQzD.js} +2 -2
- package/dist/{files-D5GtxwEQ.js.map → files-Bz0lAQzD.js.map} +1 -1
- package/dist/{html-Cf5uKhLs.js → html-BYuHDvxy.js} +10 -3
- package/dist/html-BYuHDvxy.js.map +1 -0
- package/dist/index.d.ts +71 -19
- package/dist/index.js +3 -3
- package/dist/{inspect-CGl5Y8q6.js → inspect-fpaBJ5pm.js} +1305 -75
- package/dist/inspect-fpaBJ5pm.js.map +1 -0
- package/dist/{loader-BsaSuIoG.js → loader-DMxuZ6He.js} +14 -6
- package/dist/loader-DMxuZ6He.js.map +1 -0
- package/dist/{navigate-BlowKvhB.js → navigate-C5PjwYMh.js} +108 -20
- package/dist/navigate-C5PjwYMh.js.map +1 -0
- package/dist/{produce-CLABZ8k2.d.ts → produce-BDkCsGH7.d.ts} +3 -3
- package/dist/{rpc-C1jYVNAe.js → rpc-DOdrekhP.js} +23 -13
- package/dist/rpc-DOdrekhP.js.map +1 -0
- package/dist/runtime/bundles.d.ts +3 -2
- package/dist/runtime/bundles.js +20 -5
- package/dist/runtime/bundles.js.map +1 -1
- package/dist/runtime/client.d.ts +4 -3
- package/dist/runtime/client.js +5 -5
- package/dist/runtime/devtools.d.ts +3 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/events.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/html.js +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/otel.d.ts +18 -0
- package/dist/runtime/otel.js +127 -0
- package/dist/runtime/otel.js.map +1 -0
- package/dist/runtime/server.d.ts +4 -3
- package/dist/runtime/server.js +5 -5
- package/dist/runtime/signals.d.ts +2 -2
- package/dist/runtime/signals.js +4 -1
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/store.d.ts +2 -2
- package/dist/runtime/store.js +1 -1
- package/dist/runtime/testing.d.ts +2 -2
- package/dist/runtime/testing.js +2 -2
- package/dist/search-params-qGERTLi3.js +382 -0
- package/dist/search-params-qGERTLi3.js.map +1 -0
- package/dist/{serial-ribg9NAj.js → serial-B2AJ9VGx.js} +1 -1
- package/dist/{serial-ioa17MuY.js → serial-Cj6pDGOq.js} +6 -6
- package/dist/{serial-ioa17MuY.js.map → serial-Cj6pDGOq.js.map} +1 -1
- package/dist/{server-DesBZv5g.d.ts → server-2-LS_KFo.d.ts} +125 -9
- package/dist/{server-BUuf7XPZ.js → server-CRGZMWnK.js} +545 -236
- package/dist/server-CRGZMWnK.js.map +1 -0
- package/dist/{shared-CX_YacDm.js → shared-CUBWrbiM.js} +4 -4
- package/dist/{shared-CX_YacDm.js.map → shared-CUBWrbiM.js.map} +1 -1
- package/dist/sheets-B9Zr50mf.js +105 -0
- package/dist/sheets-B9Zr50mf.js.map +1 -0
- package/dist/{signals-7VVD9C_H.d.ts → signals-BgsJK-uT.d.ts} +16 -6
- package/dist/{static-loader-C_en-4v8.js → static-loader-BDBtWsdg.js} +107 -19
- package/dist/static-loader-BDBtWsdg.js.map +1 -0
- package/dist/{static-loader-UKnK11Em.d.ts → static-loader-CAFn6p0l.d.ts} +2 -2
- package/dist/{store-9_oa0HG1.d.ts → store-BwWg-Iei.d.ts} +79 -2
- package/dist/store-DNr24Z8L.js +950 -0
- package/dist/store-DNr24Z8L.js.map +1 -0
- package/dist/{stream-read-BTsYstJY.js → stream-read-CiLDH60b.js} +2 -2
- package/dist/{stream-read-BTsYstJY.js.map → stream-read-CiLDH60b.js.map} +1 -1
- package/dist/{stream-read-Dek3HnqO.js → stream-read-DVoregpA.js} +1 -1
- package/dist/trace-DT7RGRAV.d.ts +52 -0
- package/dist/trace-browser-C7MFMove.js +170 -0
- package/dist/trace-browser-C7MFMove.js.map +1 -0
- package/dist/trace-flag-Dy267snx.js +7 -0
- package/dist/trace-flag-Dy267snx.js.map +1 -0
- package/dist/{trusted-g_zUJbh2.js → trusted-Bmwg4_hf.js} +12 -5
- package/dist/trusted-Bmwg4_hf.js.map +1 -0
- package/dist/view-transitions-BpnVwtS4.js +141 -0
- package/dist/view-transitions-BpnVwtS4.js.map +1 -0
- package/dist/vite.d.ts +8 -1
- package/dist/vite.js +356 -46
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +8 -0
- package/package.json +13 -1
- package/skills/brumate/SKILL.md +9 -5
- package/skills/brumate/references/errors.md +95 -14
- package/skills/brumate/references/events.md +27 -1
- package/skills/brumate/references/signals.md +4 -4
- package/skills/brumate/references/state.md +79 -4
- package/skills/brumate/references/syntax.md +58 -9
- package/dist/client-B0FXW5Kw.js.map +0 -1
- package/dist/defer-BMIMP4Hq.js.map +0 -1
- package/dist/devtools-B4prrxht.js.map +0 -1
- package/dist/error-catalog-DakxjSgj.js.map +0 -1
- package/dist/events-LgLdp1R7.js.map +0 -1
- package/dist/features-DwMYKBIC.js.map +0 -1
- package/dist/html-Cf5uKhLs.js.map +0 -1
- package/dist/inspect-CGl5Y8q6.js.map +0 -1
- package/dist/loader-BsaSuIoG.js.map +0 -1
- package/dist/navigate-BlowKvhB.js.map +0 -1
- package/dist/rpc-C1jYVNAe.js.map +0 -1
- package/dist/search-params-Wg-0FsMj.js +0 -148
- package/dist/search-params-Wg-0FsMj.js.map +0 -1
- package/dist/server-BUuf7XPZ.js.map +0 -1
- package/dist/static-loader-C_en-4v8.js.map +0 -1
- package/dist/store-Cy4EEyZ7.js +0 -439
- package/dist/store-Cy4EEyZ7.js.map +0 -1
- package/dist/trusted-g_zUJbh2.js.map +0 -1
package/dist/vite.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as resolveFromDisk, E as isReactiveModule, F as importSource, H as forEachNode, I as importedComponents, K as resolveMacros, L as resolveRelative, M as refreshedNames, N as analyzeProject, O as builtin, Q as nameBridges, T as ModuleError, U as analyze, X as hasBridge, Y as bridgeModuleId, Z as mayHaveBridge, _ as getComponentName, a as scopeLabel, b as generateShared, f as instanceScope, g as functionId, i as report, j as entryClasses, k as originalPosition, n as formatReport, nt as getLocation, p as slotIndex, q as walk$1, rt as withCode, s as compile, t as anchorLabel, v as hash, w as transformModuleSignals, y as SHARED_QUERY, z as parse$1 } from "./inspect-fpaBJ5pm.js";
|
|
2
2
|
import { s as toNodeHeaders } from "./cookies-Cnbf4w-S.js";
|
|
3
3
|
import { t as LOGO } from "./logo-DQ_OYhBi.js";
|
|
4
|
-
import { _ as findPackages, a as findScripts, b as resolveComponentPackage, d as isScriptFile, f as serverExports, g as findPackage, h as findBridgePackages, i as findFiles, l as hasServerMiddleware, m as serverStubs, n as defaultExclude, o as findServerFiles, p as serverModule, r as findBridgeFiles, s as findPackageServerFile, u as hasUseServer, v as packageFileName, y as reachableFiles } from "./files-
|
|
4
|
+
import { _ as findPackages, a as findScripts, b as resolveComponentPackage, d as isScriptFile, f as serverExports, g as findPackage, h as findBridgePackages, i as findFiles, l as hasServerMiddleware, m as serverStubs, n as defaultExclude, o as findServerFiles, p as serverModule, r as findBridgeFiles, s as findPackageServerFile, u as hasUseServer, v as packageFileName, y as reachableFiles } from "./files-Bz0lAQzD.js";
|
|
5
5
|
import { parseSync } from "oxc-parser";
|
|
6
|
+
import { parse } from "postcss";
|
|
6
7
|
import { createHash } from "node:crypto";
|
|
7
8
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
9
|
+
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
9
10
|
import path, { resolve } from "node:path";
|
|
10
11
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
11
|
-
import { isFileLoadingAllowed, isRunnableDevEnvironment, normalizePath, searchForWorkspaceRoot, transformWithOxc, version } from "vite";
|
|
12
|
+
import { isFileLoadingAllowed, isRunnableDevEnvironment, normalizePath, preprocessCSS, searchForWorkspaceRoot, transformWithOxc, version } from "vite";
|
|
12
13
|
//#region src/env-file.ts
|
|
13
14
|
/** The name of the function that declares the variables. */
|
|
14
15
|
const DEFINE = "defineEnv";
|
|
@@ -131,7 +132,10 @@ function noFeatures() {
|
|
|
131
132
|
rootWait: false,
|
|
132
133
|
searchParams: false,
|
|
133
134
|
stores: false,
|
|
134
|
-
bridges: false
|
|
135
|
+
bridges: false,
|
|
136
|
+
moduleMemos: false,
|
|
137
|
+
scripts: false,
|
|
138
|
+
viewTransitions: false
|
|
135
139
|
};
|
|
136
140
|
}
|
|
137
141
|
/** Every feature, for a build that compiles components in the browser. */
|
|
@@ -167,7 +171,10 @@ function getFeatures(result) {
|
|
|
167
171
|
rootWait: /\$\$b\.wait\(/.test(client),
|
|
168
172
|
searchParams: /\$\$b\.(?:searchParam|paramEffect)\(/.test(all),
|
|
169
173
|
stores: /\$\$(?:b|ctx)\.(?:toStore|consumeStore)\(|['"]brumate\/store['"]/.test(all),
|
|
170
|
-
bridges: /\$\$nameBridge\(/.test(all)
|
|
174
|
+
bridges: /\$\$nameBridge\(/.test(all),
|
|
175
|
+
moduleMemos: /\$\$ms_\w+\.i\b/.test(all),
|
|
176
|
+
scripts: result.plan.scripts,
|
|
177
|
+
viewTransitions: result.plan.viewTransitions
|
|
171
178
|
};
|
|
172
179
|
}
|
|
173
180
|
/** The features of several components together. */
|
|
@@ -193,6 +200,9 @@ function joinFeatures(all) {
|
|
|
193
200
|
joined.searchParams ||= features.searchParams;
|
|
194
201
|
joined.stores ||= features.stores;
|
|
195
202
|
joined.bridges ||= features.bridges;
|
|
203
|
+
joined.moduleMemos ||= features.moduleMemos;
|
|
204
|
+
joined.scripts ||= features.scripts;
|
|
205
|
+
joined.viewTransitions ||= features.viewTransitions;
|
|
196
206
|
}
|
|
197
207
|
return joined;
|
|
198
208
|
}
|
|
@@ -216,7 +226,10 @@ const GLOBALS = {
|
|
|
216
226
|
rootWait: "__BRUMATE_HAS_ROOT_WAIT__",
|
|
217
227
|
searchParams: "__BRUMATE_HAS_SEARCH_PARAMS__",
|
|
218
228
|
stores: "__BRUMATE_HAS_STORES__",
|
|
219
|
-
bridges: "__BRUMATE_HAS_BRIDGES__"
|
|
229
|
+
bridges: "__BRUMATE_HAS_BRIDGES__",
|
|
230
|
+
moduleMemos: "__BRUMATE_HAS_MODULE_MEMOS__",
|
|
231
|
+
scripts: "__BRUMATE_HAS_SCRIPTS__",
|
|
232
|
+
viewTransitions: "__BRUMATE_HAS_VIEW_TRANSITIONS__"
|
|
220
233
|
};
|
|
221
234
|
/** True for code that reads a feature, such as the core. */
|
|
222
235
|
function readsFeatures(code) {
|
|
@@ -1042,7 +1055,7 @@ function ownNeeds(file, options) {
|
|
|
1042
1055
|
}
|
|
1043
1056
|
const functions = [];
|
|
1044
1057
|
const calls = [];
|
|
1045
|
-
walk([
|
|
1058
|
+
walk$1([
|
|
1046
1059
|
file.moduleScript?.program,
|
|
1047
1060
|
file.instanceScript?.program,
|
|
1048
1061
|
file.children,
|
|
@@ -1105,7 +1118,7 @@ function classifyComponents(files, options = {}) {
|
|
|
1105
1118
|
let file;
|
|
1106
1119
|
let own;
|
|
1107
1120
|
try {
|
|
1108
|
-
file = parse(source, { filename });
|
|
1121
|
+
file = parse$1(source, { filename });
|
|
1109
1122
|
own = ownNeeds(file, options);
|
|
1110
1123
|
} catch {
|
|
1111
1124
|
continue;
|
|
@@ -1339,6 +1352,45 @@ function propControls(file) {
|
|
|
1339
1352
|
return [];
|
|
1340
1353
|
}
|
|
1341
1354
|
//#endregion
|
|
1355
|
+
//#region src/browser-trace.ts
|
|
1356
|
+
const SCRIPT = /\.[cm]?[jt]sx?$/;
|
|
1357
|
+
const LOADER = /['"]brumate\/(?:static-)?loader['"]/;
|
|
1358
|
+
const SERVER$1 = /['"]brumate\/server['"]/;
|
|
1359
|
+
const SKIPPED = /* @__PURE__ */ new Set([
|
|
1360
|
+
"node_modules",
|
|
1361
|
+
"dist",
|
|
1362
|
+
".git",
|
|
1363
|
+
".output"
|
|
1364
|
+
]);
|
|
1365
|
+
/** Reads the scripts under `dir`. `skip` is a file to leave out, such as the middleware of the server. */
|
|
1366
|
+
async function usesBrowserTrace(dir, skip) {
|
|
1367
|
+
const result = {
|
|
1368
|
+
on: false,
|
|
1369
|
+
hints: []
|
|
1370
|
+
};
|
|
1371
|
+
await walk(dir, skip === void 0 ? void 0 : path.normalize(skip), result);
|
|
1372
|
+
return result;
|
|
1373
|
+
}
|
|
1374
|
+
async function walk(dir, skip, result) {
|
|
1375
|
+
let entries;
|
|
1376
|
+
try {
|
|
1377
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
1378
|
+
} catch {
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
for (const entry of entries) {
|
|
1382
|
+
const file = path.join(dir, entry.name);
|
|
1383
|
+
if (entry.isDirectory()) {
|
|
1384
|
+
if (!SKIPPED.has(entry.name)) await walk(file, skip, result);
|
|
1385
|
+
} else if (SCRIPT.test(entry.name) && path.normalize(file) !== skip) {
|
|
1386
|
+
const code = await readFile(file, "utf8");
|
|
1387
|
+
if (!/\bonTrace\b/.test(code)) continue;
|
|
1388
|
+
if (LOADER.test(code)) result.on = true;
|
|
1389
|
+
else if (!SERVER$1.test(code)) result.hints.push(path.basename(file));
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
//#endregion
|
|
1342
1394
|
//#region src/prerender.ts
|
|
1343
1395
|
/** The file of a page: `index.html` in a folder of its path. */
|
|
1344
1396
|
function getPageFile(pathname) {
|
|
@@ -1450,7 +1502,7 @@ function withImports(name, chunks, into = /* @__PURE__ */ new Set()) {
|
|
|
1450
1502
|
function componentImports(file, source) {
|
|
1451
1503
|
let parsed;
|
|
1452
1504
|
try {
|
|
1453
|
-
parsed = parse(source, { filename: file });
|
|
1505
|
+
parsed = parse$1(source, { filename: file });
|
|
1454
1506
|
} catch {
|
|
1455
1507
|
return [];
|
|
1456
1508
|
}
|
|
@@ -1694,11 +1746,11 @@ function routeModule(tree, resolve, rpc = "/_brumate", origins = [], dev = false
|
|
|
1694
1746
|
return [
|
|
1695
1747
|
"import { handleRoute } from 'brumate/server';",
|
|
1696
1748
|
"import { functions, fileMiddleware } from 'virtual:brumate/server';",
|
|
1697
|
-
...middleware ? [`import * as entry from ${JSON.stringify(middleware)};`, "const { default: middleware, onError } = { ...entry };"] : [],
|
|
1749
|
+
...middleware ? [`import * as entry from ${JSON.stringify(middleware)};`, "const { default: middleware, onError, onTrace } = { ...entry };"] : [],
|
|
1698
1750
|
...imports,
|
|
1699
1751
|
`export const routes = ${routes};`,
|
|
1700
1752
|
"export function handle(request, options) {",
|
|
1701
|
-
` return handleRoute(routes, request, { rpc: ${JSON.stringify(rpc)}, origins: ${JSON.stringify(origins)}, functions, fileMiddleware${middleware ? ", middleware, onError" : ""}${dev ? ", dev: true" : ""}${build === void 0 ? "" : `, build: ${JSON.stringify(build)}`}${hints.length > 0 ? `, hints: ${JSON.stringify(hints)}` : ""}${Object.keys(bundleHints).length > 0 ? `, bundleHints: ${JSON.stringify(bundleHints)}` : ""}, ...options });`,
|
|
1753
|
+
` return handleRoute(routes, request, { rpc: ${JSON.stringify(rpc)}, origins: ${JSON.stringify(origins)}, functions, fileMiddleware${middleware ? ", middleware, onError, onTrace" : ""}${dev ? ", dev: true" : ""}${build === void 0 ? "" : `, build: ${JSON.stringify(build)}`}${hints.length > 0 ? `, hints: ${JSON.stringify(hints)}` : ""}${Object.keys(bundleHints).length > 0 ? `, bundleHints: ${JSON.stringify(bundleHints)}` : ""}, ...options });`,
|
|
1702
1754
|
"}"
|
|
1703
1755
|
].join("\n");
|
|
1704
1756
|
}
|
|
@@ -1783,6 +1835,25 @@ const PRERENDER_ENTRY = "brumate-routes";
|
|
|
1783
1835
|
const CLIENT_QUERY = "?brumate-client";
|
|
1784
1836
|
const RENDER_QUERY = "?brumate-render";
|
|
1785
1837
|
const SERVER_QUERY = "?brumate-server";
|
|
1838
|
+
/**
|
|
1839
|
+
* The query of the style module of a component in a build: its scoped CSS, as a CSS file that
|
|
1840
|
+
* Vite's CSS pipeline makes into the stylesheet of the chunk that imports it. `lang.css` makes
|
|
1841
|
+
* Vite treat it as CSS, as the style blocks of Vue and Svelte do.
|
|
1842
|
+
*/
|
|
1843
|
+
const STYLE_QUERY = "?brumate-style&lang.css";
|
|
1844
|
+
/**
|
|
1845
|
+
* A style module ends with a rule that names it. The sheet of a chunk is the rules of its modules
|
|
1846
|
+
* after the CSS pipeline (urls, imports, PostCSS, minifier), so the text between two marks is the
|
|
1847
|
+
* CSS of one component, as the sheet has it. The build cuts the marks out of the sheets.
|
|
1848
|
+
*/
|
|
1849
|
+
const MARK = "b-mark-";
|
|
1850
|
+
const MARK_RULE = /\.(b-mark-[\w-]+)\s*\{\s*--b-mark:\s*\1\s*;?\s*\}\s*/g;
|
|
1851
|
+
/** CSS files and languages that Vite's CSS pipeline handles. */
|
|
1852
|
+
const CSS_FILE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
1853
|
+
/** The parameter of `STYLE_QUERY` that marks a style module. */
|
|
1854
|
+
const STYLE_PARAM = "brumate-style";
|
|
1855
|
+
/** A `url()` in CSS, with its quote and its value. */
|
|
1856
|
+
const CSS_URL = /url\(\s*(['"]?)([^'")]+)\1\s*\)/g;
|
|
1786
1857
|
/** Exports `mount` from `brumate/testing`, with the loader of this project's client modules. */
|
|
1787
1858
|
const TESTING = "virtual:brumate/testing";
|
|
1788
1859
|
/** The ID of the module of Vite's preload helper, which a client build gets from `preloadHelper`. */
|
|
@@ -2010,8 +2081,15 @@ function brumate(options = {}) {
|
|
|
2010
2081
|
let base = "/";
|
|
2011
2082
|
/** Whether a build writes URLs that need the URL of the importing chunk to resolve. */
|
|
2012
2083
|
let relativeUrls = false;
|
|
2084
|
+
/**
|
|
2085
|
+
* Whether the project sets a relative base. Vite resolves it to "/" in a server build, so
|
|
2086
|
+
* `relativeUrls` is false there, but the server must still match the client build.
|
|
2087
|
+
*/
|
|
2088
|
+
let relativeBase = false;
|
|
2013
2089
|
let isSsrBuild = false;
|
|
2014
2090
|
let isServe = false;
|
|
2091
|
+
/** The resolved config, for the CSS pipeline of the inline styles. */
|
|
2092
|
+
let resolvedConfig;
|
|
2015
2093
|
/** Component IDs to absolute file paths. */
|
|
2016
2094
|
const files = /* @__PURE__ */ new Map();
|
|
2017
2095
|
const compiled = /* @__PURE__ */ new Map();
|
|
@@ -2150,6 +2228,15 @@ function brumate(options = {}) {
|
|
|
2150
2228
|
let builtFeatures;
|
|
2151
2229
|
/** The files that `builtFeatures` counted, and the features it found. */
|
|
2152
2230
|
let counted = /* @__PURE__ */ new Set();
|
|
2231
|
+
let traceBrowser;
|
|
2232
|
+
/** Whether the client code has the spans of the browser, from the option and the scan of `src/`. */
|
|
2233
|
+
async function resolveTrace(context) {
|
|
2234
|
+
if (options.trace !== void 0 && options.trace !== "auto") return options.trace;
|
|
2235
|
+
if (isServe) return true;
|
|
2236
|
+
const found = await usesBrowserTrace(path.join(root, "src"), middlewareFile());
|
|
2237
|
+
if (!found.on && found.hints.length > 0) context.warn(`${found.hints.join(", ")} names onTrace, but no script that imports brumate/loader does, so the build leaves the spans of the browser out. Set \`trace: true\` in the brumate plugin options if the loader starts elsewhere.`);
|
|
2238
|
+
return found.on;
|
|
2239
|
+
}
|
|
2153
2240
|
let knownFeatures;
|
|
2154
2241
|
/** The components that the client build loaded. */
|
|
2155
2242
|
const loadedComponents = /* @__PURE__ */ new Set();
|
|
@@ -2205,6 +2292,7 @@ function brumate(options = {}) {
|
|
|
2205
2292
|
merge: options.merge ?? 4096,
|
|
2206
2293
|
a11y: options.a11y,
|
|
2207
2294
|
hideNames: !isServe,
|
|
2295
|
+
styleFiles: styleFiles(),
|
|
2208
2296
|
sendableClasses: serialClasses(),
|
|
2209
2297
|
serverImport: (specifier, name) => serverImport(file, specifier, name),
|
|
2210
2298
|
resolveModule: (specifier, importer) => {
|
|
@@ -2217,13 +2305,58 @@ function brumate(options = {}) {
|
|
|
2217
2305
|
}
|
|
2218
2306
|
};
|
|
2219
2307
|
}
|
|
2308
|
+
/** The files that the CSS of each component imports, from the CSS pipeline. */
|
|
2309
|
+
const cssImports = /* @__PURE__ */ new Map();
|
|
2310
|
+
/** Adds a file to the watcher of the dev server, once the server exists. */
|
|
2311
|
+
let watchFile;
|
|
2312
|
+
const unwatched = /* @__PURE__ */ new Set();
|
|
2313
|
+
/** A file that a component's CSS imports changes the component, as a style import does. */
|
|
2314
|
+
function watchDependency(dependency, importer) {
|
|
2315
|
+
if (!dependents.has(dependency)) dependents.set(dependency, /* @__PURE__ */ new Set());
|
|
2316
|
+
dependents.get(dependency).add(importer);
|
|
2317
|
+
if (!isServe) return;
|
|
2318
|
+
if (watchFile) watchFile(dependency);
|
|
2319
|
+
else unwatched.add(dependency);
|
|
2320
|
+
}
|
|
2321
|
+
/**
|
|
2322
|
+
* The dev server serves files by path, so a relative `url()` in the CSS of a component, which
|
|
2323
|
+
* the page would resolve against its own URL, names the file in the root or in `/@fs/`.
|
|
2324
|
+
*/
|
|
2325
|
+
function devUrls(css, file) {
|
|
2326
|
+
const prefix = resolvedConfig?.base.startsWith("/") ? resolvedConfig.base : "/";
|
|
2327
|
+
return css.replace(CSS_URL, (match, quote, value) => {
|
|
2328
|
+
if (/^(?:[a-z][a-z\d+.-]*:|\/|#)/i.test(value) || value.includes("${")) return match;
|
|
2329
|
+
const [location = ""] = value.split(/[?#]/, 1);
|
|
2330
|
+
const absolute = normalizePath(path.resolve(path.dirname(file), location));
|
|
2331
|
+
if (!existsSync(absolute)) return match;
|
|
2332
|
+
return `url(${quote}${absolute.startsWith(`${normalizePath(root)}/`) ? `${prefix}${path.posix.relative(normalizePath(root), absolute)}` : `/@fs${absolute}`}${value.slice(location.length)}${quote})`;
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2220
2335
|
async function compileFile(file) {
|
|
2221
2336
|
const source = await readFile(file, "utf8");
|
|
2222
2337
|
let cached = compiled.get(file);
|
|
2223
2338
|
if (cached?.source !== source) {
|
|
2339
|
+
let result = compile(source, compileOptions(file));
|
|
2340
|
+
if (result.css && !styleFiles() && resolvedConfig) {
|
|
2341
|
+
const input = isServe ? devUrls(result.css, file) : result.css;
|
|
2342
|
+
const piped = await preprocessCSS(input, `${file}?brumate-inline&lang.css`, resolvedConfig);
|
|
2343
|
+
const imports = /* @__PURE__ */ new Set();
|
|
2344
|
+
for (const dependency of piped.deps ?? []) {
|
|
2345
|
+
const normalized = normalizePath(dependency);
|
|
2346
|
+
if (normalized !== normalizePath(file)) {
|
|
2347
|
+
imports.add(normalized);
|
|
2348
|
+
watchDependency(normalized, file);
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
cssImports.set(file, imports);
|
|
2352
|
+
if (piped.code !== result.css) result = compile(source, {
|
|
2353
|
+
...compileOptions(file),
|
|
2354
|
+
css: piped.code
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2224
2357
|
cached = {
|
|
2225
2358
|
source,
|
|
2226
|
-
result
|
|
2359
|
+
result
|
|
2227
2360
|
};
|
|
2228
2361
|
compiled.set(file, cached);
|
|
2229
2362
|
shapes.set(file, getShape(cached.result));
|
|
@@ -2270,11 +2403,12 @@ function brumate(options = {}) {
|
|
|
2270
2403
|
}
|
|
2271
2404
|
/**
|
|
2272
2405
|
* The bundles of a build: for each component that no other component imports, such as a
|
|
2273
|
-
* route or a page, the components with client code that it can render
|
|
2274
|
-
*
|
|
2275
|
-
*
|
|
2406
|
+
* route or a page, the components with client code that it can render (`members`), and the
|
|
2407
|
+
* components with CSS that it can render (`styles`), whose style modules it imports. The page
|
|
2408
|
+
* loads the bundles of its roots at once, as one chunk each, so its code comes in one request,
|
|
2409
|
+
* and links to their stylesheets. Components that only import each other get a bundle too.
|
|
2276
2410
|
*/
|
|
2277
|
-
async function bundles(kept) {
|
|
2411
|
+
async function bundles(kept, styled = /* @__PURE__ */ new Set()) {
|
|
2278
2412
|
const imports = /* @__PURE__ */ new Map();
|
|
2279
2413
|
await inBatches([...files.values()], async (file) => {
|
|
2280
2414
|
try {
|
|
@@ -2297,24 +2431,55 @@ function brumate(options = {}) {
|
|
|
2297
2431
|
}
|
|
2298
2432
|
walk(file);
|
|
2299
2433
|
const members = [];
|
|
2300
|
-
|
|
2301
|
-
|
|
2434
|
+
const styles = [];
|
|
2435
|
+
for (const member of seen) {
|
|
2436
|
+
if (kept.has(member)) members.push(member);
|
|
2437
|
+
if (styled.has(member)) styles.push(member);
|
|
2438
|
+
}
|
|
2439
|
+
if (members.length > 0 || styles.length > 0) result.set(id, {
|
|
2440
|
+
members,
|
|
2441
|
+
styles
|
|
2442
|
+
});
|
|
2302
2443
|
}
|
|
2303
2444
|
for (const [id, file] of files) if (!imported.has(file)) addRoot(id, file);
|
|
2304
|
-
for (const [id, file] of files) if (!reached.has(file) && kept.has(file)) addRoot(id, file);
|
|
2445
|
+
for (const [id, file] of files) if (!reached.has(file) && (kept.has(file) || styled.has(file))) addRoot(id, file);
|
|
2305
2446
|
return result;
|
|
2306
2447
|
}
|
|
2448
|
+
/** The bundles of this build, which `buildStart` forgets. */
|
|
2449
|
+
let builtBundles;
|
|
2450
|
+
/**
|
|
2451
|
+
* The bundles of a build, from the components with client code and, when the CSS is in style
|
|
2452
|
+
* modules, those with CSS. Computed once per build: the manifest and every bundle module read it.
|
|
2453
|
+
*/
|
|
2454
|
+
function buildBundles() {
|
|
2455
|
+
builtBundles ??= findBundles();
|
|
2456
|
+
return builtBundles;
|
|
2457
|
+
}
|
|
2458
|
+
async function findBundles() {
|
|
2459
|
+
const list = [...files.values()];
|
|
2460
|
+
const results = await inBatches(list, async (file) => (await compileFile(file)).result);
|
|
2461
|
+
const kept = /* @__PURE__ */ new Set();
|
|
2462
|
+
const styled = /* @__PURE__ */ new Set();
|
|
2463
|
+
for (const [index, file] of list.entries()) {
|
|
2464
|
+
if (results[index].clientCode) kept.add(file);
|
|
2465
|
+
if (styleFiles() && results[index].css) styled.add(file);
|
|
2466
|
+
}
|
|
2467
|
+
return bundles(kept, styled);
|
|
2468
|
+
}
|
|
2469
|
+
/** Whether the CSS of components is in style modules (`STYLE_QUERY`) instead of their modules. */
|
|
2470
|
+
function styleFiles() {
|
|
2471
|
+
return !isServe && !relativeUrls && !relativeBase;
|
|
2472
|
+
}
|
|
2307
2473
|
/** The ID of each component file. */
|
|
2308
2474
|
function findComponentId(file) {
|
|
2309
2475
|
for (const [id, other] of files) if (other === file) return id;
|
|
2310
2476
|
}
|
|
2311
2477
|
/** A bundle module: the client modules of a root component and of those it renders. */
|
|
2312
2478
|
async function bundleModule(root) {
|
|
2313
|
-
const
|
|
2314
|
-
const
|
|
2315
|
-
const
|
|
2316
|
-
for (const
|
|
2317
|
-
const members = (await bundles(kept)).get(root) ?? [];
|
|
2479
|
+
const bundle = (await buildBundles()).get(root);
|
|
2480
|
+
const members = bundle?.members ?? [];
|
|
2481
|
+
const styles = [];
|
|
2482
|
+
for (const file of bundle?.styles ?? []) styles.push(`import ${JSON.stringify(`${file}${STYLE_QUERY}`)};`);
|
|
2318
2483
|
const imports = [];
|
|
2319
2484
|
const objects = [];
|
|
2320
2485
|
for (const [index, file] of members.entries()) {
|
|
@@ -2332,16 +2497,89 @@ function brumate(options = {}) {
|
|
|
2332
2497
|
objects.push(` ${JSON.stringify(findComponentId(file))}: { ${fields.join(", ")} },`);
|
|
2333
2498
|
}
|
|
2334
2499
|
return [
|
|
2500
|
+
...styles,
|
|
2335
2501
|
...imports,
|
|
2336
2502
|
"export const modules = {",
|
|
2337
2503
|
...objects,
|
|
2338
2504
|
"};"
|
|
2339
2505
|
].join("\n");
|
|
2340
2506
|
}
|
|
2507
|
+
/** The marks of the style modules, by mark, to the ID of their component. */
|
|
2508
|
+
const marks = /* @__PURE__ */ new Map();
|
|
2509
|
+
/** The CSS of each component and the sheets that load late, from the last client bundle. */
|
|
2510
|
+
let cut = {
|
|
2511
|
+
css: {},
|
|
2512
|
+
deferred: {}
|
|
2513
|
+
};
|
|
2514
|
+
/** True when a component's CSS has a rule that is not scoped to the component. */
|
|
2515
|
+
async function hasGlobalRules(file) {
|
|
2516
|
+
const found = { value: false };
|
|
2517
|
+
parse((await compileFile(file)).result.css).walkRules((rule) => {
|
|
2518
|
+
const parent = rule.parent;
|
|
2519
|
+
if (parent?.type === "atrule" && /keyframes$/i.test(parent.name)) return;
|
|
2520
|
+
if (!rule.selector.includes("[b-c-")) found.value = true;
|
|
2521
|
+
});
|
|
2522
|
+
parse((await compileFile(file)).result.css).walkAtRules("import", () => {
|
|
2523
|
+
found.value = true;
|
|
2524
|
+
});
|
|
2525
|
+
return found.value;
|
|
2526
|
+
}
|
|
2527
|
+
/**
|
|
2528
|
+
* Cuts the marks out of the sheets of the chunks, and returns the CSS text of each component, as
|
|
2529
|
+
* its sheet has it, and the sheets that hold the CSS of components only.
|
|
2530
|
+
*/
|
|
2531
|
+
async function cutMarks(chunks, bundle) {
|
|
2532
|
+
const css = {};
|
|
2533
|
+
const deferred = {};
|
|
2534
|
+
for (const chunk of chunks.values()) {
|
|
2535
|
+
const sheets = chunk.viteMetadata?.importedCss;
|
|
2536
|
+
if (!sheets || sheets.size === 0) continue;
|
|
2537
|
+
const styled = [];
|
|
2538
|
+
let other = false;
|
|
2539
|
+
for (const moduleId of chunk.moduleIds) if (moduleId.endsWith(STYLE_QUERY)) styled.push(moduleId.slice(0, -23));
|
|
2540
|
+
else if (CSS_FILE.test(moduleId)) other = true;
|
|
2541
|
+
if (styled.length === 0) continue;
|
|
2542
|
+
for (const name of sheets) {
|
|
2543
|
+
const asset = bundle[name];
|
|
2544
|
+
if (asset?.type !== "asset") continue;
|
|
2545
|
+
const text = String(asset.source);
|
|
2546
|
+
const found = [];
|
|
2547
|
+
const order = [];
|
|
2548
|
+
let rest = "";
|
|
2549
|
+
let position = 0;
|
|
2550
|
+
for (const match of text.matchAll(MARK_RULE)) {
|
|
2551
|
+
const id = marks.get(match[1]);
|
|
2552
|
+
if (id !== void 0) {
|
|
2553
|
+
found.push([id, text.slice(position, match.index)]);
|
|
2554
|
+
order.push(id);
|
|
2555
|
+
}
|
|
2556
|
+
rest += text.slice(position, match.index);
|
|
2557
|
+
position = match.index + match[0].length;
|
|
2558
|
+
}
|
|
2559
|
+
rest += text.slice(position);
|
|
2560
|
+
asset.source = rest;
|
|
2561
|
+
const expected = styled.map((file) => componentId(file));
|
|
2562
|
+
if (order.length !== expected.length || order.some((id, index) => id !== expected[index])) continue;
|
|
2563
|
+
const globals = [];
|
|
2564
|
+
for (const [id, rules] of found) {
|
|
2565
|
+
css[id] = rules;
|
|
2566
|
+
const file = files.get(id);
|
|
2567
|
+
if (file !== void 0 && await hasGlobalRules(file)) globals.push(id);
|
|
2568
|
+
}
|
|
2569
|
+
if (!other && sheets.size === 1) deferred[`${base}${name}`] = globals;
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
return {
|
|
2573
|
+
css,
|
|
2574
|
+
deferred
|
|
2575
|
+
};
|
|
2576
|
+
}
|
|
2341
2577
|
/** The hints of the client build of this process, for a server build that follows it. */
|
|
2342
2578
|
let builtHints;
|
|
2343
2579
|
/** The IDs of the components in each bundle of the client build, by root, for `hints.json`. */
|
|
2344
2580
|
const bundleMembers = /* @__PURE__ */ new Map();
|
|
2581
|
+
/** The roots whose bundles hold style modules and no client code, by component ID. */
|
|
2582
|
+
const styleRoots = /* @__PURE__ */ new Set();
|
|
2345
2583
|
/** `bridges`: the loaders of the modules with a `bridge`, by module ID. */
|
|
2346
2584
|
function bridgeLoaders() {
|
|
2347
2585
|
const lines = ["const bridges = {"];
|
|
@@ -2355,11 +2593,14 @@ function brumate(options = {}) {
|
|
|
2355
2593
|
const kept = [];
|
|
2356
2594
|
for (const [index, entry] of list.entries()) if (needed[index]) kept.push(entry);
|
|
2357
2595
|
if (!isServe) {
|
|
2358
|
-
const
|
|
2359
|
-
for (const [, file] of kept) keptFiles.add(file);
|
|
2360
|
-
const groups = await bundles(keptFiles);
|
|
2596
|
+
const groups = await buildBundles();
|
|
2361
2597
|
bundleMembers.clear();
|
|
2362
|
-
|
|
2598
|
+
styleRoots.clear();
|
|
2599
|
+
for (const [root, { members }] of groups) {
|
|
2600
|
+
if (members.length === 0) {
|
|
2601
|
+
styleRoots.add(root);
|
|
2602
|
+
continue;
|
|
2603
|
+
}
|
|
2363
2604
|
const ids = [];
|
|
2364
2605
|
for (const member of members) {
|
|
2365
2606
|
const id = findComponentId(member);
|
|
@@ -2463,7 +2704,7 @@ function brumate(options = {}) {
|
|
|
2463
2704
|
...env ? [`import ${JSON.stringify(env)};`] : [],
|
|
2464
2705
|
...serialImports(),
|
|
2465
2706
|
"import { handleRequest } from 'brumate/server';",
|
|
2466
|
-
...entry ? [`import * as entry from ${JSON.stringify(entry)};`, "const { default: middleware, onError } = { ...entry };"] : [],
|
|
2707
|
+
...entry ? [`import * as entry from ${JSON.stringify(entry)};`, "const { default: middleware, onError, onTrace } = { ...entry };"] : [],
|
|
2467
2708
|
...imports,
|
|
2468
2709
|
...fileImports,
|
|
2469
2710
|
"export const functions = {",
|
|
@@ -2474,7 +2715,7 @@ function brumate(options = {}) {
|
|
|
2474
2715
|
...guards,
|
|
2475
2716
|
"};",
|
|
2476
2717
|
"export function handle(request, options) {",
|
|
2477
|
-
` return handleRequest(functions, request, ${JSON.stringify(rpc)}, { origins: ${JSON.stringify(options.origins ?? [])}, ${entry ? "middleware, onError, " : ""}fileMiddleware${buildId === void 0 ? "" : `, build: ${JSON.stringify(buildId)}`}, ...options });`,
|
|
2718
|
+
` return handleRequest(functions, request, ${JSON.stringify(rpc)}, { origins: ${JSON.stringify(options.origins ?? [])}, ${entry ? "middleware, onError, onTrace, " : ""}fileMiddleware${buildId === void 0 ? "" : `, build: ${JSON.stringify(buildId)}`}, ...options });`,
|
|
2478
2719
|
"}"
|
|
2479
2720
|
].join("\n");
|
|
2480
2721
|
}
|
|
@@ -2706,7 +2947,7 @@ function brumate(options = {}) {
|
|
|
2706
2947
|
const found = classes.get(file);
|
|
2707
2948
|
let controls = [];
|
|
2708
2949
|
try {
|
|
2709
|
-
controls = propControls(parse(sources.get(file), { filename: file }));
|
|
2950
|
+
controls = propControls(parse$1(sources.get(file), { filename: file }));
|
|
2710
2951
|
} catch {
|
|
2711
2952
|
controls = void 0;
|
|
2712
2953
|
}
|
|
@@ -2811,7 +3052,7 @@ function brumate(options = {}) {
|
|
|
2811
3052
|
const [{ AsyncLocalStorage }, { format }, { createRecorder }] = await Promise.all([
|
|
2812
3053
|
import("node:async_hooks"),
|
|
2813
3054
|
import("node:util"),
|
|
2814
|
-
import("./devtools-calls-
|
|
3055
|
+
import("./devtools-calls-DCjuSkim.js")
|
|
2815
3056
|
]);
|
|
2816
3057
|
recording = createRecorder(new AsyncLocalStorage(), format);
|
|
2817
3058
|
}
|
|
@@ -2857,6 +3098,7 @@ function brumate(options = {}) {
|
|
|
2857
3098
|
const normalized = normalizePath(file);
|
|
2858
3099
|
const targets = file.endsWith(".brm") ? [normalized] : [...dependents.get(normalized) ?? []];
|
|
2859
3100
|
if (targets.length === 0) return;
|
|
3101
|
+
if (!file.endsWith(".brm")) for (const target of targets) compiled.delete(target);
|
|
2860
3102
|
function invalidate() {
|
|
2861
3103
|
for (const module of server.moduleGraph.idToModuleMap.values()) {
|
|
2862
3104
|
const id = module.id ?? "";
|
|
@@ -2949,6 +3191,7 @@ function brumate(options = {}) {
|
|
|
2949
3191
|
name: "brumate",
|
|
2950
3192
|
enforce: "pre",
|
|
2951
3193
|
async config(config, env) {
|
|
3194
|
+
relativeBase = config.base === "./" || config.base === "";
|
|
2952
3195
|
const appRoot = path.resolve(config.root ?? process.cwd());
|
|
2953
3196
|
packages = findPackages(appRoot);
|
|
2954
3197
|
bridgePackages = [];
|
|
@@ -3027,6 +3270,7 @@ function brumate(options = {}) {
|
|
|
3027
3270
|
(context.defineCacheKeyGenerator ?? context.experimental_defineCacheKeyGenerator)?.(cacheKey);
|
|
3028
3271
|
},
|
|
3029
3272
|
configResolved(config) {
|
|
3273
|
+
resolvedConfig = config;
|
|
3030
3274
|
root = config.root;
|
|
3031
3275
|
isServe = config.command === "serve";
|
|
3032
3276
|
outDir = path.resolve(config.root, config.build.outDir);
|
|
@@ -3050,6 +3294,9 @@ function brumate(options = {}) {
|
|
|
3050
3294
|
if (item.moduleIds.includes(`\0${MANIFEST}`)) loaderChunk = item.fileName;
|
|
3051
3295
|
if (coreModule && item.moduleIds.includes(coreModule)) coreChunk = item.fileName;
|
|
3052
3296
|
}
|
|
3297
|
+
const sheetChunks = /* @__PURE__ */ new Map();
|
|
3298
|
+
for (const item of Object.values(bundle)) if (item.type === "chunk") sheetChunks.set(item.fileName, item);
|
|
3299
|
+
cut = await cutMarks(sheetChunks, bundle);
|
|
3053
3300
|
startChunks = /* @__PURE__ */ new Set();
|
|
3054
3301
|
bundleChunks = /* @__PURE__ */ new Set();
|
|
3055
3302
|
function addStart(name) {
|
|
@@ -3138,13 +3385,26 @@ function brumate(options = {}) {
|
|
|
3138
3385
|
}
|
|
3139
3386
|
const id = facade.slice(24);
|
|
3140
3387
|
const styleNames = [...styles];
|
|
3141
|
-
bundleHints[id] = urls;
|
|
3388
|
+
bundleHints[id] = styleRoots.has(id) ? [] : urls;
|
|
3142
3389
|
for (const name of styleNames) bundleHints[id].push(`${base}${name}`);
|
|
3390
|
+
if (styleRoots.has(id)) continue;
|
|
3143
3391
|
chunkUrls[id] = loadUrl(chunk.fileName);
|
|
3144
3392
|
styleUrls[id] = [];
|
|
3145
3393
|
for (const name of styleNames) styleUrls[id].push(loadUrl(name));
|
|
3146
3394
|
members[id] = bundleMembers.get(id) ?? [];
|
|
3147
3395
|
}
|
|
3396
|
+
const components = {};
|
|
3397
|
+
for (const chunk of chunks.values()) {
|
|
3398
|
+
const sheets = chunk.viteMetadata?.importedCss;
|
|
3399
|
+
if (!sheets || sheets.size === 0) continue;
|
|
3400
|
+
for (const moduleId of chunk.moduleIds) if (moduleId.endsWith(STYLE_QUERY)) {
|
|
3401
|
+
const file = moduleId.slice(0, -23);
|
|
3402
|
+
const urls = [];
|
|
3403
|
+
for (const name of sheets) urls.push(`${base}${name}`);
|
|
3404
|
+
components[componentId(file)] = urls;
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
const { css, deferred } = cut;
|
|
3148
3408
|
let hasManifest = false;
|
|
3149
3409
|
for (const chunk of chunks.values()) hasManifest ||= chunk.moduleIds.includes(`\0${MANIFEST}`);
|
|
3150
3410
|
for (const root of hasManifest ? bundleMembers.keys() : []) if (chunkUrls[root] === void 0) this.error(`The client build has no chunk for the bundle of ${root}`);
|
|
@@ -3156,7 +3416,10 @@ function brumate(options = {}) {
|
|
|
3156
3416
|
bundles: bundleHints,
|
|
3157
3417
|
chunks: chunkUrls,
|
|
3158
3418
|
styles: styleUrls,
|
|
3159
|
-
members
|
|
3419
|
+
members,
|
|
3420
|
+
components,
|
|
3421
|
+
css,
|
|
3422
|
+
deferred
|
|
3160
3423
|
};
|
|
3161
3424
|
if (hasManifest) builtHints = clientOutput;
|
|
3162
3425
|
await writeFile(path.join(outDir, HINTS_FILE), JSON.stringify(clientOutput));
|
|
@@ -3191,7 +3454,9 @@ function brumate(options = {}) {
|
|
|
3191
3454
|
coreModule = isServe ? void 0 : (await this.resolve("brumate/client", path.join(root, "index.html")))?.id;
|
|
3192
3455
|
await scan();
|
|
3193
3456
|
builtFeatures = void 0;
|
|
3457
|
+
builtBundles = void 0;
|
|
3194
3458
|
knownFeatures = void 0;
|
|
3459
|
+
traceBrowser = void 0;
|
|
3195
3460
|
loadedComponents.clear();
|
|
3196
3461
|
writeRouteTypes();
|
|
3197
3462
|
},
|
|
@@ -3263,7 +3528,7 @@ function brumate(options = {}) {
|
|
|
3263
3528
|
if (id === `\0${MANIFEST}`) return await manifest();
|
|
3264
3529
|
if (id === `\0${BUNDLES}`) {
|
|
3265
3530
|
const lines = [];
|
|
3266
|
-
for (const root of bundleMembers.keys()) lines.push(` ${JSON.stringify(root)}: () => import(${JSON.stringify(`${BUNDLE}${root}`)}),`);
|
|
3531
|
+
for (const root of [...bundleMembers.keys(), ...styleRoots]) lines.push(` ${JSON.stringify(root)}: () => import(${JSON.stringify(`${BUNDLE}${root}`)}),`);
|
|
3267
3532
|
return [
|
|
3268
3533
|
"export default {",
|
|
3269
3534
|
...lines,
|
|
@@ -3276,7 +3541,10 @@ function brumate(options = {}) {
|
|
|
3276
3541
|
const bundles = hints.chunks && hints.members ? {
|
|
3277
3542
|
chunks: hints.chunks,
|
|
3278
3543
|
styles: hints.styles,
|
|
3279
|
-
members: hints.members
|
|
3544
|
+
members: hints.members,
|
|
3545
|
+
components: hints.components,
|
|
3546
|
+
css: hints.css,
|
|
3547
|
+
deferred: hints.deferred
|
|
3280
3548
|
} : void 0;
|
|
3281
3549
|
return ["import { setClientBundles } from 'brumate/server';", `setClientBundles(${JSON.stringify(bundles)});`].join("\n");
|
|
3282
3550
|
}
|
|
@@ -3287,7 +3555,7 @@ function brumate(options = {}) {
|
|
|
3287
3555
|
return [
|
|
3288
3556
|
"import { answerCalls as answer, createMount, createVisit } from 'brumate/testing';",
|
|
3289
3557
|
`import { load } from ${JSON.stringify(MANIFEST)};`,
|
|
3290
|
-
...entry ? [`import * as entry from ${JSON.stringify(entry)};`, "const { default: middleware, onError } = { ...entry };"] : [],
|
|
3558
|
+
...entry ? [`import * as entry from ${JSON.stringify(entry)};`, "const { default: middleware, onError, onTrace } = { ...entry };"] : [],
|
|
3291
3559
|
`export const mount = createMount({ load, rpc: ${JSON.stringify(rpc)} });`,
|
|
3292
3560
|
"export const visit = createVisit({",
|
|
3293
3561
|
" load,",
|
|
@@ -3297,13 +3565,14 @@ function brumate(options = {}) {
|
|
|
3297
3565
|
"});",
|
|
3298
3566
|
"export function answerCalls(options) {",
|
|
3299
3567
|
` const server = import(${JSON.stringify(SERVER)});`,
|
|
3300
|
-
` return answer(async () => (await server).functions, { rpc: ${JSON.stringify(rpc)}, ${entry ? "middleware, onError, " : ""}fileMiddleware: async () => (await server).fileMiddleware, ...options });`,
|
|
3568
|
+
` return answer(async () => (await server).functions, { rpc: ${JSON.stringify(rpc)}, ${entry ? "middleware, onError, onTrace, " : ""}fileMiddleware: async () => (await server).fileMiddleware, ...options });`,
|
|
3301
3569
|
"}"
|
|
3302
3570
|
].join("\n");
|
|
3303
3571
|
}
|
|
3304
3572
|
const [file, query] = id.split("?");
|
|
3305
3573
|
if (!file?.endsWith(".brm")) return;
|
|
3306
3574
|
const params = new URLSearchParams(query);
|
|
3575
|
+
const isStyle = params.has(STYLE_PARAM);
|
|
3307
3576
|
const isRender = params.has(RENDER_QUERY.slice(1));
|
|
3308
3577
|
const isServer = params.has(SERVER_QUERY.slice(1));
|
|
3309
3578
|
const isClient = !isServer && (params.has(CLIENT_QUERY.slice(1)) || !loadOptions?.ssr);
|
|
@@ -3324,16 +3593,24 @@ function brumate(options = {}) {
|
|
|
3324
3593
|
});
|
|
3325
3594
|
}
|
|
3326
3595
|
const { source, result } = output;
|
|
3327
|
-
if (!isServe && !isSsrBuild && isClient) loadedComponents.add(file);
|
|
3596
|
+
if (!isServe && !isSsrBuild && isClient && !isStyle) loadedComponents.add(file);
|
|
3328
3597
|
for (const dependency of [...result.plan.styles.dependencies, ...result.modules]) {
|
|
3329
3598
|
const normalized = normalizePath(dependency);
|
|
3330
3599
|
this.addWatchFile(normalized);
|
|
3331
3600
|
if (!dependents.has(normalized)) dependents.set(normalized, /* @__PURE__ */ new Set());
|
|
3332
3601
|
dependents.get(normalized).add(file);
|
|
3333
3602
|
}
|
|
3603
|
+
if (isStyle) {
|
|
3604
|
+
const mark = `${MARK}${hash(file)}`;
|
|
3605
|
+
marks.set(mark, componentId(file));
|
|
3606
|
+
return {
|
|
3607
|
+
code: `${result.css}\n.${mark}{--b-mark:${mark}}\n`,
|
|
3608
|
+
map: null
|
|
3609
|
+
};
|
|
3610
|
+
}
|
|
3334
3611
|
for (const warning of isClient && !params.has("part") ? result.warnings : []) {
|
|
3335
3612
|
const { line, column } = getLocation(source, warning.range.start);
|
|
3336
|
-
this.warn(`${warning.message} (${getFileName(file)}:${line}:${column})`);
|
|
3613
|
+
this.warn(`${withCode(warning.message)} (${getFileName(file)}:${line}:${column})`);
|
|
3337
3614
|
}
|
|
3338
3615
|
const part = params.get("part");
|
|
3339
3616
|
let code;
|
|
@@ -3363,10 +3640,21 @@ function brumate(options = {}) {
|
|
|
3363
3640
|
};
|
|
3364
3641
|
},
|
|
3365
3642
|
async transform(code, id, transformOptions) {
|
|
3366
|
-
if (!
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3643
|
+
if (!transformOptions?.ssr && code.includes("__BRUMATE_TRACE__")) {
|
|
3644
|
+
traceBrowser ??= resolveTrace(this);
|
|
3645
|
+
code = code.replace(/(?<!declare const )\b__BRUMATE_TRACE__\b/g, String(await traceBrowser));
|
|
3646
|
+
if (!readsFeatures(code)) return {
|
|
3647
|
+
code,
|
|
3648
|
+
map: null
|
|
3649
|
+
};
|
|
3650
|
+
}
|
|
3651
|
+
if (!isServe && !isSsrBuild && !transformOptions?.ssr && readsFeatures(code)) {
|
|
3652
|
+
const features = options.features === "all" ? allFeatures() : await buildFeatures();
|
|
3653
|
+
return {
|
|
3654
|
+
code: writeFeatures(code, features),
|
|
3655
|
+
map: null
|
|
3656
|
+
};
|
|
3657
|
+
}
|
|
3370
3658
|
const [file] = id.split("?");
|
|
3371
3659
|
if (file && !transformOptions?.ssr && file === envFile()) try {
|
|
3372
3660
|
return {
|
|
@@ -3411,8 +3699,25 @@ function brumate(options = {}) {
|
|
|
3411
3699
|
} catch (error) {
|
|
3412
3700
|
this.error(error.message);
|
|
3413
3701
|
}
|
|
3702
|
+
if (file && isReactiveModule(file) && !id.endsWith("?brumate-shared")) try {
|
|
3703
|
+
const compiled = transformModuleSignals({
|
|
3704
|
+
path: file,
|
|
3705
|
+
source: code
|
|
3706
|
+
});
|
|
3707
|
+
if (compiled !== void 0) return {
|
|
3708
|
+
code: compiled,
|
|
3709
|
+
map: null
|
|
3710
|
+
};
|
|
3711
|
+
} catch (error) {
|
|
3712
|
+
if (error instanceof ModuleError) this.error({
|
|
3713
|
+
message: error.message,
|
|
3714
|
+
id: file,
|
|
3715
|
+
pos: error.offset
|
|
3716
|
+
});
|
|
3717
|
+
throw error;
|
|
3718
|
+
}
|
|
3414
3719
|
const shared = isReactiveModule(file ?? "") && id.endsWith("?brumate-shared");
|
|
3415
|
-
if (!file?.endsWith(".brm") && !shared) return;
|
|
3720
|
+
if (!file?.endsWith(".brm") && !shared || new URLSearchParams(id.split("?")[1]).has(STYLE_PARAM)) return;
|
|
3416
3721
|
const result = await transformWithOxc(code, `${file}.ts`, {
|
|
3417
3722
|
lang: "ts",
|
|
3418
3723
|
sourcemap: true
|
|
@@ -3429,6 +3734,11 @@ function brumate(options = {}) {
|
|
|
3429
3734
|
const manifests = [normalizePath(path.join(root, "package.json"))];
|
|
3430
3735
|
for (const item of packages) manifests.push(normalizePath(`${item.root}/package.json`));
|
|
3431
3736
|
server.watcher.add(manifests);
|
|
3737
|
+
watchFile = (file) => server.watcher.add(file);
|
|
3738
|
+
if (unwatched.size > 0) {
|
|
3739
|
+
server.watcher.add([...unwatched]);
|
|
3740
|
+
unwatched.clear();
|
|
3741
|
+
}
|
|
3432
3742
|
server.watcher.on("change", (file) => {
|
|
3433
3743
|
if (manifests.includes(normalizePath(file)) && packagesKey(findPackages(root)) !== packagesKey(packages)) server.restart();
|
|
3434
3744
|
});
|