brumate 0.2.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.
Files changed (101) hide show
  1. package/dist/{boot-D-IdPy7B.d.ts → boot-C25Sa6vq.d.ts} +5 -2
  2. package/dist/cli.js +2 -2
  3. package/dist/{client-C0UCNL3J.js → client-BD6XT-s5.js} +435 -110
  4. package/dist/client-BD6XT-s5.js.map +1 -0
  5. package/dist/{client-MD0ZmcFR.d.ts → client-D0CqSxoO.d.ts} +114 -8
  6. package/dist/{cookies-Av5WFmcf.js → cookies-BzllthiF.js} +2 -1
  7. package/dist/cookies-BzllthiF.js.map +1 -0
  8. package/dist/{defer-D0bo1Gqx.js → defer-BbD7JQhj.js} +6 -2
  9. package/dist/defer-BbD7JQhj.js.map +1 -0
  10. package/dist/devtools-CQgD7NPB.js +623 -0
  11. package/dist/devtools-CQgD7NPB.js.map +1 -0
  12. package/dist/devtools-panel-BVB-W5q4.js +1930 -0
  13. package/dist/devtools-panel-BVB-W5q4.js.map +1 -0
  14. package/dist/events-CSs7OwIC.js +85 -0
  15. package/dist/events-CSs7OwIC.js.map +1 -0
  16. package/dist/{files-Bnn1JqHx.js → files-BXSSrQgc.js} +18 -5
  17. package/dist/files-BXSSrQgc.js.map +1 -0
  18. package/dist/forms-Bg-CwGqX.js +406 -0
  19. package/dist/forms-Bg-CwGqX.js.map +1 -0
  20. package/dist/forms-Cl21hkHt.d.ts +281 -0
  21. package/dist/highlight.d.ts +17 -0
  22. package/dist/highlight.js +269 -0
  23. package/dist/highlight.js.map +1 -0
  24. package/dist/{html-y1q7-t7D.d.ts → html-Bq1rFxX_.d.ts} +36 -4
  25. package/dist/{html-bHZbkK-h.js → html-mNTKzaDD.js} +79 -8
  26. package/dist/html-mNTKzaDD.js.map +1 -0
  27. package/dist/index.d.ts +47 -2
  28. package/dist/index.js +3 -3
  29. package/dist/index.js.map +1 -1
  30. package/dist/{inspect-BJtACnQp.js → inspect-BHpOw1LF.js} +625 -48
  31. package/dist/inspect-BHpOw1LF.js.map +1 -0
  32. package/dist/{loader-B18i3_-T.js → loader-Dos_3NP0.js} +5 -4
  33. package/dist/loader-Dos_3NP0.js.map +1 -0
  34. package/dist/{navigate-BwuZveDF.js → navigate-O78d_zGN.js} +45 -2
  35. package/dist/navigate-O78d_zGN.js.map +1 -0
  36. package/dist/{produce-D4K7qpaL.d.ts → produce-D0V0ICkz.d.ts} +45 -3
  37. package/dist/{produce-CWfJ4byV.js → produce-Doc91GkX.js} +113 -6
  38. package/dist/produce-Doc91GkX.js.map +1 -0
  39. package/dist/{rpc-B-Zkn6Ch.js → rpc-ygMRPmN4.js} +20 -10
  40. package/dist/rpc-ygMRPmN4.js.map +1 -0
  41. package/dist/runtime/client.d.ts +4 -4
  42. package/dist/runtime/client.js +4 -4
  43. package/dist/runtime/devtools.d.ts +188 -3
  44. package/dist/runtime/devtools.js +1 -1
  45. package/dist/runtime/events.d.ts +15 -0
  46. package/dist/runtime/events.js +1 -1
  47. package/dist/runtime/forms.d.ts +2 -0
  48. package/dist/runtime/forms.js +1 -0
  49. package/dist/runtime/gather.d.ts +25 -0
  50. package/dist/runtime/gather.js +33 -0
  51. package/dist/runtime/gather.js.map +1 -0
  52. package/dist/runtime/hot.d.ts +1 -1
  53. package/dist/runtime/html.d.ts +2 -2
  54. package/dist/runtime/html.js +1 -1
  55. package/dist/runtime/loader.d.ts +2 -2
  56. package/dist/runtime/loader.js +2 -2
  57. package/dist/runtime/server.d.ts +5 -4
  58. package/dist/runtime/server.js +5 -5
  59. package/dist/runtime/signals.d.ts +38 -2
  60. package/dist/runtime/signals.js +12 -2
  61. package/dist/runtime/signals.js.map +1 -1
  62. package/dist/runtime/static-loader.d.ts +2 -2
  63. package/dist/runtime/static-loader.js +1 -1
  64. package/dist/runtime/testing.d.ts +2 -2
  65. package/dist/runtime/testing.js +2 -2
  66. package/dist/runtime/values.d.ts +2 -0
  67. package/dist/runtime/values.js +24 -0
  68. package/dist/runtime/values.js.map +1 -0
  69. package/dist/{server-BqfM95r1.js → server-CxVDYE_V.js} +776 -121
  70. package/dist/server-CxVDYE_V.js.map +1 -0
  71. package/dist/{server-BA9SJ2Vm.d.ts → server-DuFYRXrd.d.ts} +284 -15
  72. package/dist/{static-loader-BzE9SRaj.d.ts → static-loader-Drpr0AzI.d.ts} +2 -2
  73. package/dist/{static-loader-DOygOFj5.js → static-loader-nZssh66R.js} +168 -51
  74. package/dist/static-loader-nZssh66R.js.map +1 -0
  75. package/dist/{stream-JaMHMdBD.js → stream-DCYZO4IF.js} +89 -10
  76. package/dist/stream-DCYZO4IF.js.map +1 -0
  77. package/dist/values-B8C7CLvG.d.ts +63 -0
  78. package/dist/vite.d.ts +8 -1
  79. package/dist/vite.js +170 -20
  80. package/dist/vite.js.map +1 -1
  81. package/forms/forms.brm.ts +141 -0
  82. package/package.json +31 -2
  83. package/dist/client-C0UCNL3J.js.map +0 -1
  84. package/dist/cookies-Av5WFmcf.js.map +0 -1
  85. package/dist/defer-D0bo1Gqx.js.map +0 -1
  86. package/dist/devtools-C50VH8gZ.js +0 -113
  87. package/dist/devtools-C50VH8gZ.js.map +0 -1
  88. package/dist/devtools-panel-AYjfwPhj.js +0 -435
  89. package/dist/devtools-panel-AYjfwPhj.js.map +0 -1
  90. package/dist/events-BKWRqtMg.js +0 -52
  91. package/dist/events-BKWRqtMg.js.map +0 -1
  92. package/dist/files-Bnn1JqHx.js.map +0 -1
  93. package/dist/html-bHZbkK-h.js.map +0 -1
  94. package/dist/inspect-BJtACnQp.js.map +0 -1
  95. package/dist/loader-B18i3_-T.js.map +0 -1
  96. package/dist/navigate-BwuZveDF.js.map +0 -1
  97. package/dist/produce-CWfJ4byV.js.map +0 -1
  98. package/dist/rpc-B-Zkn6Ch.js.map +0 -1
  99. package/dist/server-BqfM95r1.js.map +0 -1
  100. package/dist/static-loader-DOygOFj5.js.map +0 -1
  101. package/dist/stream-JaMHMdBD.js.map +0 -1
@@ -0,0 +1,63 @@
1
+ //#region src/runtime/values.d.ts
2
+ /**
3
+ * How a value of the app becomes data that brumate can send, and back.
4
+ * `data` can hold anything that brumate sends, such as numbers, strings,
5
+ * arrays, plain objects and dates.
6
+ */
7
+ interface ValuePlugin<T = any, D = any> {
8
+ /** A name of the plugin that no other plugin has, such as `app/money`. */
9
+ tag: string;
10
+ /** True for a value of the plugin, such as `value instanceof Money`. */
11
+ test: (value: unknown) => boolean;
12
+ /** The data of a value, such as `[money.amount, money.currency]`. */
13
+ toData: (value: T) => D;
14
+ /** Makes the value again from its data, in the browser or on the server. */
15
+ fromData: (data: D) => T;
16
+ }
17
+ /**
18
+ * Makes a plugin for a value of the app. Export it from the entry,
19
+ * `src/serial.ts`, in `plugins`:
20
+ *
21
+ * ```ts
22
+ * export const plugins = [
23
+ * definePlugin({
24
+ * tag: 'app/money',
25
+ * test: (value) => value instanceof Money,
26
+ * toData: (money: Money) => [money.amount, money.currency],
27
+ * fromData: ([amount, currency]) => new Money(amount, currency),
28
+ * }),
29
+ * ];
30
+ * ```
31
+ */
32
+ declare function definePlugin<T, D>(plugin: ValuePlugin<T, D>): ValuePlugin<T, D>;
33
+ /** The exports of the serial entry, `src/serial.ts`. Each is optional. */
34
+ interface SerialEntry {
35
+ /** Plugins for values of the app, which `definePlugin` makes. */
36
+ plugins?: readonly ValuePlugin[];
37
+ /**
38
+ * The features of seroval that are off, as its `Feature` flags. Brumate
39
+ * turns off `ErrorPrototypeStack` and `RegExp`, and warns when the entry
40
+ * turns one of them on.
41
+ */
42
+ disabledFeatures?: number;
43
+ /** How deep a value can be. Deeper values throw instead of being sent. */
44
+ depthLimit?: number;
45
+ }
46
+ /**
47
+ * The values that plugins of the app send, for the type checker. Add each
48
+ * class to it, so a signal or memo can hold one:
49
+ *
50
+ * ```ts
51
+ * declare module 'brumate/serial' {
52
+ * interface SendableValues {
53
+ * money: Money;
54
+ * }
55
+ * }
56
+ * ```
57
+ */
58
+ interface SendableValues {}
59
+ /** A value that a plugin of the app sends. */
60
+ type AppValue = SendableValues[keyof SendableValues];
61
+ //#endregion
62
+ export { definePlugin as a, ValuePlugin as i, SendableValues as n, SerialEntry as r, AppValue as t };
63
+ //# sourceMappingURL=values-B8C7CLvG.d.ts.map
package/dist/vite.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as NavigateOptions } from "./boot-D-IdPy7B.js";
1
+ import { n as NavigateOptions } from "./boot-C25Sa6vq.js";
2
2
  import { Plugin, ViteDevServer } from "vite";
3
3
  //#region src/report.d.ts
4
4
  /** Sizes in bytes, after gzip. */
@@ -107,6 +107,13 @@ export interface BrumateOptions {
107
107
  * `false` runs none.
108
108
  */
109
109
  middleware?: string | false;
110
+ /**
111
+ * The serial entry, relative to the root. It exports `plugins` for values
112
+ * of the app, such as a class, and the options of the serializer that it
113
+ * changes. The server and the browser load it. Defaults to `src/serial.ts`
114
+ * when the file exists. `false` uses none.
115
+ */
116
+ serial?: string | false;
110
117
  /**
111
118
  * The file of environment variables, relative to the root, which calls
112
119
  * `defineEnv` from `brumate/env`. The server checks them when it starts,
package/dist/vite.js CHANGED
@@ -1,13 +1,13 @@
1
- import { C as resolveFromDisk, E as analyzeProject, O as forEachNode, P as getLocation, S as isReactiveModule, _ as getComponentName, b as generateShared, d as instanceScope, f as slotIndex, g as functionId, i as scopeLabel, j as parse, k as resolveRelative, o as compile, r as report, t as formatReport, v as hash, w as builtin, y as SHARED_QUERY } from "./inspect-BJtACnQp.js";
2
- import { s as toNodeHeaders } from "./cookies-Av5WFmcf.js";
3
- import { a as hasServerMiddleware, c as serverExports, i as findServerFiles, l as serverModule, n as findFiles, o as hasUseServer, r as findScripts, s as isScriptFile, t as defaultExclude, u as serverStubs } from "./files-Bnn1JqHx.js";
1
+ import { A as analyzeProject, C as isReactiveModule, E as originalPosition, F as parse, M as forEachNode, N as resolveRelative, O as entryClasses, R as getLocation, T as builtin, _ as functionId, a as scopeLabel, b as SHARED_QUERY, f as instanceScope, i as report, k as refreshedNames, n as formatReport, p as slotIndex, s as compile, t as anchorLabel, v as getComponentName, w as resolveFromDisk, x as generateShared, y as hash } from "./inspect-BHpOw1LF.js";
2
+ import { s as toNodeHeaders } from "./cookies-BzllthiF.js";
3
+ import { a as hasServerMiddleware, c as serverExports, i as findServerFiles, l as serverModule, n as findFiles, o as hasUseServer, r as findScripts, s as isScriptFile, t as defaultExclude, u as serverStubs } from "./files-BXSSrQgc.js";
4
4
  import { parseSync } from "oxc-parser";
5
5
  import { createHash } from "node:crypto";
6
6
  import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
7
7
  import { mkdir, readFile, writeFile } from "node:fs/promises";
8
8
  import path, { resolve } from "node:path";
9
9
  import { fileURLToPath, pathToFileURL } from "node:url";
10
- import { isRunnableDevEnvironment, normalizePath, searchForWorkspaceRoot, transformWithOxc } from "vite";
10
+ import { isFileLoadingAllowed, isRunnableDevEnvironment, normalizePath, searchForWorkspaceRoot, transformWithOxc, version } from "vite";
11
11
  //#region src/env-file.ts
12
12
  /** The name of the function that declares the variables. */
13
13
  const DEFINE = "defineEnv";
@@ -60,7 +60,9 @@ function parseEnvFile(source, filename) {
60
60
  if (group === "server") {
61
61
  const next = schema.properties[index + 1];
62
62
  const comma = source.indexOf(",", property.end);
63
- const end = next ? next.start : comma !== -1 && comma < schema.end ? comma + 1 : property.end;
63
+ let end = property.end;
64
+ if (next) end = next.start;
65
+ else if (comma !== -1 && comma < schema.end) end = comma + 1;
64
66
  result.serverRange = {
65
67
  start: property.start,
66
68
  end
@@ -365,6 +367,10 @@ function reachableFiles(packages, appFiles, read) {
365
367
  return reached;
366
368
  }
367
369
  //#endregion
370
+ //#region src/version.ts
371
+ /** The version of brumate, which the devtools show. `package.json` is next to `src` and `dist`. */
372
+ const BRUMATE_VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
373
+ //#endregion
368
374
  //#region src/dev-error.ts
369
375
  /** The overlay payload of an error, with the file, line and lines around it for compile errors. */
370
376
  function errorPayload(error, root = process.cwd()) {
@@ -428,11 +434,20 @@ function errorPage(error, server) {
428
434
  <script type="module">
429
435
  import { createHotContext } from '${base}@vite/client';
430
436
  const error = ${json};
431
- const Overlay = customElements.get('vite-error-overlay');
432
- if (Overlay) {
433
- document.body.append(new Overlay(error));
434
- } else {
435
- document.getElementById('brumate-error').textContent = [error.message, error.frame, error.stack].filter(Boolean).join('\\n\\n');
437
+ // The Errors tab of the devtools shows the error with its code. Vite's overlay is the fallback.
438
+ try {
439
+ const devtools = await import('${base}@id/brumate/devtools');
440
+ devtools.reportError(devtools.installDevtools(undefined, undefined, ${JSON.stringify({
441
+ version: BRUMATE_VERSION,
442
+ vite: version
443
+ })}), error, 'server');
444
+ } catch {
445
+ const Overlay = customElements.get('vite-error-overlay');
446
+ if (Overlay) {
447
+ document.body.append(new Overlay(error));
448
+ } else {
449
+ document.getElementById('brumate-error').textContent = [error.message, error.frame, error.stack].filter(Boolean).join('\\n\\n');
450
+ }
436
451
  }
437
452
  // A component that updates in place, after a fix, loads the page again.
438
453
  const hot = createHotContext('/@brumate/error');
@@ -777,6 +792,7 @@ function routeFiles(paths) {
777
792
  function routeModule(tree, resolve, rpc = "/_brumate", origins = [], dev = false, middleware, build, hints = []) {
778
793
  const imports = [];
779
794
  const load = (file) => {
795
+ if (dev) return `() => import(${JSON.stringify(resolve(file))})`;
780
796
  const name = `m${imports.length}`;
781
797
  imports.push(`import * as ${name} from ${JSON.stringify(resolve(file))};`);
782
798
  return `() => Promise.resolve(${name})`;
@@ -873,6 +889,10 @@ const TESTING = "virtual:brumate/testing";
873
889
  const HINTS_FILE = ".brumate/hints.json";
874
890
  /** The dev server answers the devtools panel about a component at this path. */
875
891
  const INSPECT = "/__brumate/inspect";
892
+ /** Maps a position of a module that the browser ran to its source, for the Errors tab. */
893
+ const POSITION = "/__brumate/position";
894
+ /** The dev server sends the source of a file for the Errors tab of the devtools at this path. */
895
+ const SOURCE = "/__brumate/source";
876
896
  /** What tells two lists of packages of components apart. */
877
897
  function packagesKey(list) {
878
898
  return JSON.stringify(list.map((item) => [
@@ -961,6 +981,40 @@ function brumate(options = {}) {
961
981
  }
962
982
  return file;
963
983
  };
984
+ /** The serial entry, when the app has one. */
985
+ const serialFile = () => {
986
+ if (options.serial === false) return;
987
+ const file = normalizePath(path.resolve(root, options.serial ?? "src/serial.ts"));
988
+ if (!existsSync(file)) {
989
+ if (options.serial !== void 0) throw new Error(`The serial entry ${options.serial} does not exist`);
990
+ return;
991
+ }
992
+ return file;
993
+ };
994
+ /** The classes that the plugins of the serial entry send, read from its `instanceof` checks. */
995
+ let serialRead;
996
+ const serialClasses = () => {
997
+ const file = serialFile();
998
+ if (!file) return [];
999
+ const source = readFileSync(file, "utf8");
1000
+ if (serialRead?.source !== source) {
1001
+ const { program } = parseSync(file, source, { lang: "ts" });
1002
+ serialRead = {
1003
+ source,
1004
+ classes: entryClasses(program)
1005
+ };
1006
+ }
1007
+ return serialRead.classes;
1008
+ };
1009
+ /** The lines that give the server the serial entry, before anything is written or read. */
1010
+ const serialImports = () => {
1011
+ const file = serialFile();
1012
+ return file ? [
1013
+ `import * as $$serial from ${JSON.stringify(file)};`,
1014
+ "import { useSerialEntry } from 'brumate/server';",
1015
+ "useSerialEntry($$serial);"
1016
+ ] : [];
1017
+ };
964
1018
  /** The file of environment variables, when the app has one. */
965
1019
  const envFile = () => {
966
1020
  if (options.env === false) return;
@@ -1000,6 +1054,8 @@ function brumate(options = {}) {
1000
1054
  const shapes = /* @__PURE__ */ new Map();
1001
1055
  /** The props that parents can change, by absolute file path. */
1002
1056
  let liveProps = /* @__PURE__ */ new Map();
1057
+ /** The names of the server functions that the app refreshes, or undefined before the first scan. */
1058
+ let refreshed;
1003
1059
  /** The dependencies of the app that ship `.brm` files. See `packages.ts`. */
1004
1060
  let packages = [];
1005
1061
  const relative = (file) => normalizePath(path.relative(root, file));
@@ -1083,16 +1139,21 @@ function brumate(options = {}) {
1083
1139
  const contents = await Promise.all(list.map((file) => readFile(file, "utf8")));
1084
1140
  const sources = new Map(list.map((file, index) => [file, contents[index]]));
1085
1141
  liveProps = analyzeProject(sources, resolveComponent);
1142
+ const scripts = await findScripts(root, exclude);
1143
+ const scriptSources = await Promise.all([.../* @__PURE__ */ new Set([...scripts, ...serverFiles.values()])].map((file) => readFile(file, "utf8").catch(() => "")));
1144
+ refreshed = refreshedNames([...contents, ...scriptSources]);
1086
1145
  compiled.clear();
1087
1146
  };
1088
1147
  /** The options of the compile of a file. */
1089
1148
  const compileOptions = (file) => ({
1090
1149
  filename: nameOf(file),
1091
1150
  liveProps: liveProps.get(file),
1151
+ refreshed,
1092
1152
  path: file,
1093
1153
  merge: options.merge ?? 4096,
1094
1154
  a11y: options.a11y,
1095
1155
  hideNames: !isServe,
1156
+ sendableClasses: serialClasses(),
1096
1157
  serverImport: (specifier, name) => serverImport(file, specifier, name),
1097
1158
  resolveModule: (specifier, importer) => {
1098
1159
  const local = resolveFromDisk(specifier, importer);
@@ -1169,10 +1230,16 @@ function brumate(options = {}) {
1169
1230
  registered = packages.length > 0 ? reachable() : /* @__PURE__ */ new Set();
1170
1231
  const keep = (file) => registered.has(file) || !packageOf(packages, file);
1171
1232
  const components = [...files.values()].filter(keep);
1172
- const imports = components.map((file, index) => `import * as m${index} from ${JSON.stringify(file + query)};`);
1233
+ const importAll = (prefix, list) => {
1234
+ if (!isServe) return list.map((file, index) => `import * as ${prefix}${index} from ${JSON.stringify(file + query)};`);
1235
+ if (list.length === 0) return [];
1236
+ const loads = list.map((file) => `import(${JSON.stringify(file + query)})`);
1237
+ return [`const [${list.map((_, index) => `${prefix}${index}`).join(", ")}] = (await Promise.allSettled([${loads.join(", ")}])).map((result) => (result.status === 'fulfilled' ? result.value : {}));`];
1238
+ };
1239
+ const imports = importAll("m", components);
1173
1240
  const spreads = components.map((_, index) => ` ...m${index}.rpc,`);
1174
1241
  const functionFiles = [...serverFiles.entries()].filter(([, file]) => keep(file));
1175
- const fileImports = functionFiles.map(([, file], index) => `import * as f${index} from ${JSON.stringify(file + query)};`);
1242
+ const fileImports = importAll("f", functionFiles.map(([, file]) => file));
1176
1243
  const guards = [];
1177
1244
  const fileSpreads = functionFiles.map(([id, file], index) => {
1178
1245
  const source = readFileSync(file, "utf8");
@@ -1188,6 +1255,7 @@ function brumate(options = {}) {
1188
1255
  const entry = middlewareFile();
1189
1256
  return [
1190
1257
  ...env ? [`import ${JSON.stringify(env)};`] : [],
1258
+ ...serialImports(),
1191
1259
  "import { handleRequest } from 'brumate/server';",
1192
1260
  ...entry ? [`import middleware from ${JSON.stringify(entry)};`] : [],
1193
1261
  ...imports,
@@ -1230,7 +1298,12 @@ function brumate(options = {}) {
1230
1298
  const routeTree = (server = false) => {
1231
1299
  const env = envFile();
1232
1300
  const code = routeModule(currentRoutes(), (file) => `${routesDirectory()}/${file}${server && file.endsWith(".brm") ? SERVER_QUERY : ""}`, rpc, options.origins, isServe, middlewareFile(), buildId, clientHints());
1233
- return env ? `import ${JSON.stringify(env)};\n${code}` : code;
1301
+ const serial = serialImports().join("\n");
1302
+ return [
1303
+ env ? `import ${JSON.stringify(env)};` : "",
1304
+ serial,
1305
+ code
1306
+ ].filter(Boolean).join("\n");
1234
1307
  };
1235
1308
  /** Writes the paths of the routes as types for `href`, when they changed. */
1236
1309
  const writeRouteTypes = () => {
@@ -1246,9 +1319,16 @@ function brumate(options = {}) {
1246
1319
  const { source, result } = await compileFile(file);
1247
1320
  const { plan } = result;
1248
1321
  const scopes = {};
1322
+ const siteLabel = (site) => {
1323
+ const at = result.locate(site.range.start);
1324
+ const where = at.file === void 0 ? getLocation(source, at.offset) : void 0;
1325
+ return where ? `${site.label} ${where.line}:${where.column}` : site.label;
1326
+ };
1327
+ const liveSites = new Set([...plan.graph.live].flatMap((node) => "site" in node ? [node.site] : []));
1249
1328
  for (const layout of plan.scopes.values()) scopes[layout.scope.id] = {
1250
1329
  label: scopeLabel(result.file.source, layout.scope),
1251
- slots: layout.slots.map((slot) => slot.name)
1330
+ slots: layout.slots.map((slot) => slot.name),
1331
+ readers: layout.slots.map((slot) => [...new Set(slot.reads.filter((ref) => plan.graph.reached.has(ref.site) || liveSites.has(ref.site)).map((ref) => siteLabel(ref.site)))])
1252
1332
  };
1253
1333
  const nodes = plan.graph.nodes.filter((node) => plan.graph.live.has(node));
1254
1334
  const indexes = new Map(nodes.map((node, index) => [node, index]));
@@ -1270,11 +1350,41 @@ function brumate(options = {}) {
1270
1350
  }),
1271
1351
  edges: plan.graph.edges.filter((edge) => indexes.has(edge.from) && indexes.has(edge.to)).map((edge) => [indexes.get(edge.from), indexes.get(edge.to)])
1272
1352
  };
1353
+ const anchors = {};
1354
+ for (const [target, index] of plan.anchors) {
1355
+ const scope = plan.anchorScopes.get(target);
1356
+ if (!scope) continue;
1357
+ const at = result.locate("range" in target ? target.range.start : target.start);
1358
+ const where = at.file === void 0 ? getLocation(source, at.offset) : void 0;
1359
+ const reads = /* @__PURE__ */ new Set();
1360
+ for (const edge of plan.graph.edges) {
1361
+ const node = edge.to;
1362
+ if (node.kind === "source" || node.kind === "memo") continue;
1363
+ const site = node.site;
1364
+ const range = !("range" in target) && target.kind === "insert" ? target : void 0;
1365
+ if (site === target || site.owner === target || site.block === target || range && site.range.start >= range.start && site.range.end <= range.end) {
1366
+ if (edge.from.kind === "source" || edge.from.kind === "memo") reads.add(edge.from.declaration.name);
1367
+ }
1368
+ }
1369
+ const known = anchors[scope.id]?.[index];
1370
+ if (known) {
1371
+ known.reads = [.../* @__PURE__ */ new Set([...known.reads, ...reads])];
1372
+ continue;
1373
+ }
1374
+ (anchors[scope.id] ??= {})[index] = {
1375
+ label: anchorLabel(target),
1376
+ ...where ? { at: `${where.line}:${where.column}` } : {},
1377
+ reads: [...reads]
1378
+ };
1379
+ }
1273
1380
  const text = formatReport(report(source, result, liveProps.get(file)));
1274
1381
  return {
1275
1382
  name: plan.name,
1276
1383
  file: nameOf(file),
1384
+ path: file,
1385
+ url: file.startsWith(`${normalizePath(root)}/`) ? file.slice(normalizePath(root).length) : `/@fs${file}`,
1277
1386
  scopes,
1387
+ anchors,
1278
1388
  graph,
1279
1389
  text
1280
1390
  };
@@ -1295,11 +1405,14 @@ function brumate(options = {}) {
1295
1405
  }
1296
1406
  try {
1297
1407
  const { handle } = await server.ssrLoadModule(SERVER);
1298
- const answer = await handle(new Request(new URL(request.url ?? "/", "http://localhost"), {
1408
+ const webRequest = new Request(new URL(request.url ?? "/", "http://localhost"), {
1299
1409
  method: "POST",
1300
1410
  headers: Object.entries(request.headers).flatMap(([name, value]) => value === void 0 ? [] : [[name, String(value)]]),
1301
1411
  body: new Uint8Array(await readBody(request))
1302
- }), { address: request.socket.remoteAddress });
1412
+ });
1413
+ const began = performance.now();
1414
+ const answer = await handle(webRequest, { address: request.socket.remoteAddress });
1415
+ answer.headers.append("server-timing", `brumate;dur=${(performance.now() - began).toFixed(1)};desc="server function"`);
1303
1416
  response.statusCode = answer.status;
1304
1417
  for (const [name, value] of Object.entries(toNodeHeaders(answer.headers))) response.setHeader(name, value);
1305
1418
  response.end(await answer.text());
@@ -1391,6 +1504,8 @@ function brumate(options = {}) {
1391
1504
  config(config, env) {
1392
1505
  packages = findPackages(path.resolve(config.root ?? process.cwd()));
1393
1506
  const shared = packageConfig(config);
1507
+ const hmr = config.server?.hmr;
1508
+ if (env.command === "serve" && options.devtools !== false && hmr !== false && (typeof hmr !== "object" || hmr.overlay === void 0)) shared.server = { hmr: { overlay: false } };
1394
1509
  if (!env.isSsrBuild) {
1395
1510
  const preload = config.build?.modulePreload;
1396
1511
  const keep = options.skew?.keep ? { build: { emptyOutDir: false } } : {};
@@ -1415,7 +1530,10 @@ function brumate(options = {}) {
1415
1530
  if (!options.prerender) return shared;
1416
1531
  const ssr = config.build?.ssr;
1417
1532
  const input = typeof ssr === "string" ? ssr : config.build?.rolldownOptions?.input;
1418
- const entries = typeof input === "string" ? { [path.basename(input).replace(/\.[^.]+$/, "")]: input } : Array.isArray(input) ? Object.fromEntries(input.map((item) => [path.basename(item).replace(/\.[^.]+$/, ""), item])) : { ...input };
1533
+ let entries;
1534
+ if (typeof input === "string") entries = { [path.basename(input).replace(/\.[^.]+$/, "")]: input };
1535
+ else if (Array.isArray(input)) entries = Object.fromEntries(input.map((item) => [path.basename(item).replace(/\.[^.]+$/, ""), item]));
1536
+ else entries = { ...input };
1419
1537
  return {
1420
1538
  ...shared,
1421
1539
  build: {
@@ -1569,8 +1687,11 @@ function brumate(options = {}) {
1569
1687
  options.navigate === false ? "import { startWithoutNavigation as start } from 'brumate/static-loader';" : "import { start } from 'brumate/loader';",
1570
1688
  `import { load } from ${JSON.stringify(MANIFEST)};`,
1571
1689
  ...isServe ? ["import { hotLoad } from 'brumate/hot';"] : [],
1572
- `start({ load${isServe ? ": hotLoad(import.meta.hot, load)" : ""}, rpc: ${JSON.stringify(rpc)}, navigate: ${JSON.stringify(options.navigate ?? true)}${options.preload === false ? ", preload: false" : ""}${buildId === void 0 ? "" : `, build: ${JSON.stringify(buildId)}`} });`,
1573
- ...isServe && options.devtools !== false ? [`import('brumate/devtools').then((m) => m.installDevtools(${JSON.stringify(INSPECT)}, ${JSON.stringify(rpc)}));`] : []
1690
+ `start({ load${isServe ? ": hotLoad(import.meta.hot, load)" : ""}${serialFile() ? `, serial: () => import(${JSON.stringify(serialFile())})` : ""}, rpc: ${JSON.stringify(rpc)}, navigate: ${JSON.stringify(options.navigate ?? true)}${options.preload === false ? ", preload: false" : ""}${buildId === void 0 ? "" : `, build: ${JSON.stringify(buildId)}`} });`,
1691
+ ...isServe && options.devtools !== false ? [`import('brumate/devtools').then((m) => m.installDevtools(${JSON.stringify(INSPECT)}, ${JSON.stringify(rpc)}, ${JSON.stringify({
1692
+ version: BRUMATE_VERSION,
1693
+ vite: version
1694
+ })}, import.meta.hot));`] : []
1574
1695
  ].join("\n");
1575
1696
  if (id === `\0${MANIFEST}`) return await manifest();
1576
1697
  if (id === `\0${SERVER}`) return serverRegistry(!loadOptions?.ssr);
@@ -1668,8 +1789,11 @@ function brumate(options = {}) {
1668
1789
  map: null
1669
1790
  };
1670
1791
  if (id.includes(SERVER_QUERY)) {
1792
+ let lang = "jsx";
1793
+ if (/\.[cm]?ts$/.test(file)) lang = "ts";
1794
+ else if (file.endsWith(".tsx")) lang = "tsx";
1671
1795
  const result = await transformWithOxc(serverModule(code, file, fileId), file, {
1672
- lang: /\.[cm]?ts$/.test(file) ? "ts" : file.endsWith(".tsx") ? "tsx" : "jsx",
1796
+ lang,
1673
1797
  sourcemap: true
1674
1798
  });
1675
1799
  return {
@@ -1742,6 +1866,32 @@ function brumate(options = {}) {
1742
1866
  handleDevRPC(server, request, response);
1743
1867
  return;
1744
1868
  }
1869
+ if (request.method === "GET" && request.url?.startsWith(`${SOURCE}?`)) {
1870
+ const asked = new URL(request.url, "http://localhost").searchParams.get("file") ?? "";
1871
+ const file = normalizePath(path.isAbsolute(asked) && existsSync(asked) ? asked : path.join(server.config.root, asked));
1872
+ if (!existsSync(file) || !isFileLoadingAllowed(server.config, file)) {
1873
+ response.statusCode = 404;
1874
+ response.end();
1875
+ return;
1876
+ }
1877
+ response.setHeader("content-type", "text/plain; charset=utf-8");
1878
+ response.end(readFileSync(file, "utf8"));
1879
+ return;
1880
+ }
1881
+ if (request.method === "GET" && request.url?.startsWith(`${POSITION}?`)) {
1882
+ const params = new URL(request.url, "http://localhost").searchParams;
1883
+ server.environments.client.moduleGraph.getModuleByUrl(params.get("url") ?? "").then((module) => {
1884
+ const map = module?.transformResult?.map;
1885
+ const place = map && module?.file ? originalPosition(map, Number(params.get("line")), Number(params.get("column"))) : void 0;
1886
+ const file = place && normalizePath(place.source.startsWith("/") && !existsSync(place.source) ? path.join(server.config.root, place.source) : path.resolve(path.dirname(module.file), place.source));
1887
+ response.setHeader("content-type", "application/json");
1888
+ response.end(JSON.stringify(place ? {
1889
+ ...place,
1890
+ file
1891
+ } : null));
1892
+ }).catch(next);
1893
+ return;
1894
+ }
1745
1895
  if (request.method === "GET" && request.url?.startsWith(`${INSPECT}/`)) {
1746
1896
  inspectComponent(decodeURIComponent(request.url.slice(19))).then((info) => {
1747
1897
  response.statusCode = info ? 200 : 404;