goatly 0.1.0 → 0.1.2

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 (161) hide show
  1. package/README.md +874 -1
  2. package/bin/goatly.js +99 -0
  3. package/dist/cli/index.js +234 -0
  4. package/dist/compat/gatsby-node-entry.js +16 -0
  5. package/dist/compat/gatsby-package.json +6 -0
  6. package/dist/compat/md5-file.js +47 -0
  7. package/dist/compat-apis.json +72 -0
  8. package/dist/compat-apis.json.js +62 -0
  9. package/dist/graphql.js +3 -0
  10. package/dist/node/actions/index.js +619 -0
  11. package/dist/node/actions/job-store.js +180 -0
  12. package/dist/node/actions/jobs.js +174 -0
  13. package/dist/node/api-runner.js +258 -0
  14. package/dist/node/bootstrap.js +569 -0
  15. package/dist/node/build/assets.js +110 -0
  16. package/dist/node/build/incremental.js +208 -0
  17. package/dist/node/build/index.js +763 -0
  18. package/dist/node/build/memory-governor.js +450 -0
  19. package/dist/node/build/output-dirs.js +70 -0
  20. package/dist/node/build/page-data.js +40 -0
  21. package/dist/node/build/page-files.js +186 -0
  22. package/dist/node/build/partitioned-state.js +258 -0
  23. package/dist/node/build/query-worker.js +626 -0
  24. package/dist/node/build/query-workers.js +863 -0
  25. package/dist/node/build/render-thread.js +103 -0
  26. package/dist/node/build/render-worker.js +162 -0
  27. package/dist/node/build/state.js +24 -0
  28. package/dist/node/build/timing-breakdown.js +216 -0
  29. package/dist/node/build/work-clock.js +75 -0
  30. package/dist/node/build/worker-pool.js +242 -0
  31. package/dist/node/cache-layout.js +99 -0
  32. package/dist/node/cache.js +1430 -0
  33. package/dist/node/compat/chokidar-shim.js +148 -0
  34. package/dist/node/compat/core-utils-lmdb.js +145 -0
  35. package/dist/node/compat/create-node-id-shim.js +1 -0
  36. package/dist/node/compat/module-hooks.js +245 -0
  37. package/dist/node/compat/redux-shim.js +1 -0
  38. package/dist/node/config/index.js +162 -0
  39. package/dist/node/config/not-found-pages.js +95 -0
  40. package/dist/node/datastore/codec.js +144 -0
  41. package/dist/node/datastore/index.js +127 -0
  42. package/dist/node/datastore/logfile/cache.js +89 -0
  43. package/dist/node/datastore/logfile/index.js +1329 -0
  44. package/dist/node/datastore/logfile/record.js +71 -0
  45. package/dist/node/datastore/types.js +1 -0
  46. package/dist/node/develop/express-compat.js +207 -0
  47. package/dist/node/develop/graphiql.js +22 -0
  48. package/dist/node/develop/hydration-report.js +41 -0
  49. package/dist/node/develop/index.js +618 -0
  50. package/dist/node/develop/local-url.js +10 -0
  51. package/dist/node/develop/ssr-runner.js +66 -0
  52. package/dist/node/gql.js +5 -0
  53. package/dist/node/index.js +15 -0
  54. package/dist/node/info.js +270 -0
  55. package/dist/node/internal-plugins/data-bridge.js +196 -0
  56. package/dist/node/internal-plugins/page-creator.js +318 -0
  57. package/dist/node/loader/import-module.js +160 -0
  58. package/dist/node/node-helpers.js +66 -0
  59. package/dist/node/not-found-pages.js +220 -0
  60. package/dist/node/plugins/api-list.js +12 -0
  61. package/dist/node/plugins/load-plugins.js +427 -0
  62. package/dist/node/plugins/resolve-plugin.js +79 -0
  63. package/dist/node/plugins/static-exports.js +64 -0
  64. package/dist/node/query/compile.js +326 -0
  65. package/dist/node/query/dependencies.js +45 -0
  66. package/dist/node/query/execute.js +417 -0
  67. package/dist/node/query/extract.js +372 -0
  68. package/dist/node/query/gql-tada-introspection.js +124 -0
  69. package/dist/node/query/graphql-env.js +231 -0
  70. package/dist/node/query/graphql-runner.js +79 -0
  71. package/dist/node/redux/actions.js +1 -0
  72. package/dist/node/redux/index.js +133 -0
  73. package/dist/node/redux/node-changes.js +128 -0
  74. package/dist/node/redux/reducers.js +193 -0
  75. package/dist/node/redux/state.js +71 -0
  76. package/dist/node/renderer.js +124 -0
  77. package/dist/node/reporter-transports.js +259 -0
  78. package/dist/node/reporter.js +497 -0
  79. package/dist/node/schema/date.js +539 -0
  80. package/dist/node/schema/extensions.js +315 -0
  81. package/dist/node/schema/index.js +542 -0
  82. package/dist/node/schema/infer.js +388 -0
  83. package/dist/node/schema/inline-objects.js +128 -0
  84. package/dist/node/schema/naming.js +20 -0
  85. package/dist/node/schema/node-model.js +207 -0
  86. package/dist/node/schema/query-engine.js +1808 -0
  87. package/dist/node/schema/resolver-kinds.js +7 -0
  88. package/dist/node/schema/resolvers.js +273 -0
  89. package/dist/node/schema/type-builders.js +45 -0
  90. package/dist/node/schema/types.js +241 -0
  91. package/dist/node/serve.js +90 -0
  92. package/dist/node/site-page-nodes.js +277 -0
  93. package/dist/node/types.js +1 -0
  94. package/dist/node/utils/content-digest.js +107 -0
  95. package/dist/node/utils/cpus.js +104 -0
  96. package/dist/node/utils/create-node-id.js +51 -0
  97. package/dist/node/utils/env.js +25 -0
  98. package/dist/node/utils/fs-retry.js +74 -0
  99. package/dist/node/utils/memory-signals.js +441 -0
  100. package/dist/node/utils/memory.js +657 -0
  101. package/dist/node/utils/murmurhash.js +32 -0
  102. package/dist/node/utils/parser.js +33 -0
  103. package/dist/node/utils/partition-hash.js +19 -0
  104. package/dist/node/utils/paths.js +122 -0
  105. package/dist/node/utils/resolver.js +48 -0
  106. package/dist/node/utils/runtime.js +5 -0
  107. package/dist/node/utils/serializable.js +41 -0
  108. package/dist/node/utils/strings.js +41 -0
  109. package/dist/node/vite/config.js +289 -0
  110. package/dist/node/vite/paths.js +12 -0
  111. package/dist/node/vite/plugin-deps.js +232 -0
  112. package/dist/node/vite/plugin.js +283 -0
  113. package/dist/node/vite/react-compiler.js +362 -0
  114. package/dist/node/vite/source-files.js +83 -0
  115. package/dist/node/vite/static-image.js +136 -0
  116. package/dist/node/vite/styled-components.js +73 -0
  117. package/dist/node/vite/transforms.js +330 -0
  118. package/dist/node/wasm-data/host.js +406 -0
  119. package/dist/node/wasm-data/lower.js +406 -0
  120. package/dist/node/wasm-data/runner.js +79 -0
  121. package/dist/node/wasm-data/worker.js +95 -0
  122. package/dist/reporter.js +5 -0
  123. package/dist/runtime/api-runner.js +81 -0
  124. package/dist/runtime/app.js +256 -0
  125. package/dist/runtime/client-entry.js +4 -0
  126. package/dist/runtime/client.js +383 -0
  127. package/dist/runtime/default-html.js +31 -0
  128. package/dist/runtime/head-markup.js +100 -0
  129. package/dist/runtime/head-sync.js +101 -0
  130. package/dist/runtime/head-tags.js +45 -0
  131. package/dist/runtime/hydration-report.js +111 -0
  132. package/dist/runtime/index.js +12 -0
  133. package/dist/runtime/link.js +293 -0
  134. package/dist/runtime/loader.js +449 -0
  135. package/dist/runtime/not-found.js +61 -0
  136. package/dist/runtime/page-renderer.js +35 -0
  137. package/dist/runtime/preamble.js +47 -0
  138. package/dist/runtime/react-compat.js +14 -0
  139. package/dist/runtime/renderer-shared.js +10 -0
  140. package/dist/runtime/renderers/react-client.js +14 -0
  141. package/dist/runtime/renderers/react-server.js +99 -0
  142. package/dist/runtime/renderers/react.js +17 -0
  143. package/dist/runtime/renderers/types.js +1 -0
  144. package/dist/runtime/root-error-handlers.js +29 -0
  145. package/dist/runtime/router/history.js +132 -0
  146. package/dist/runtime/router/index.js +240 -0
  147. package/dist/runtime/router/utils.js +118 -0
  148. package/dist/runtime/script.js +110 -0
  149. package/dist/runtime/scroll.js +40 -0
  150. package/dist/runtime/slice.js +11 -0
  151. package/dist/runtime/ssr.js +240 -0
  152. package/dist/runtime/static-query.js +47 -0
  153. package/dist/utils.js +4 -0
  154. package/package.json +105 -3
  155. package/types/graphql-tada.d.ts +223 -0
  156. package/types/graphql.d.ts +2 -0
  157. package/types/index.d.ts +2287 -0
  158. package/types/node.d.ts +389 -0
  159. package/types/reporter.d.ts +187 -0
  160. package/types/router.d.ts +102 -0
  161. package/types/vendor/gql-tada.d.ts +2529 -0
@@ -0,0 +1,71 @@
1
+ // src/node/datastore/logfile/record.ts
2
+ /**
3
+ * A node record in a segment file (little endian):
4
+ *
5
+ * | offset | size | content |
6
+ * | -----: | ---- | ---------------------------------------- |
7
+ * | 0 | u32 | data length (msgpack) |
8
+ * | 4 | u32 | type index (into the store's type table) |
9
+ * | 8 | u32 | id length (UTF-8 bytes) |
10
+ * | 12 | u32 | parent id length (0: no parent) |
11
+ * | 16 | u32 | content digest length (0: none) |
12
+ * | 20 | … | id, parent id, content digest, data |
13
+ *
14
+ * Records are only appended: an updated node gets a new record, the old one becomes garbage until
15
+ * the file is compacted.
16
+ */
17
+ const HEADER_BYTES = 20;
18
+ function readHeader(buffer, offset = 0) {
19
+ return {
20
+ dataLength: buffer.readUInt32LE(offset),
21
+ typeIndex: buffer.readUInt32LE(offset + 4),
22
+ idLength: buffer.readUInt32LE(offset + 8),
23
+ parentLength: buffer.readUInt32LE(offset + 12),
24
+ digestLength: buffer.readUInt32LE(offset + 16)
25
+ };
26
+ }
27
+ /** size of a record in bytes, header included */
28
+ function recordSize(header) {
29
+ return 20 + header.idLength + header.parentLength + header.digestLength + header.dataLength;
30
+ }
31
+ /** where the record's strings and data start (relative to the record) */
32
+ function parentStart(header) {
33
+ return 20 + header.idLength;
34
+ }
35
+ function digestStart(header) {
36
+ return 20 + header.idLength + header.parentLength;
37
+ }
38
+ function dataStart(header) {
39
+ return 20 + header.idLength + header.parentLength + header.digestLength;
40
+ }
41
+ /** `dataStart` and `recordSize` of the record at `offset` of `buffer`, read in place (no header object) */
42
+ function dataStartAt(buffer, offset) {
43
+ return 20 + buffer.readUInt32LE(offset + 8) + buffer.readUInt32LE(offset + 12) + buffer.readUInt32LE(offset + 16);
44
+ }
45
+ function recordSizeAt(buffer, offset) {
46
+ return dataStartAt(buffer, offset) + buffer.readUInt32LE(offset);
47
+ }
48
+ /** bytes a record needs */
49
+ function encodedSize(id, parent, digest, data) {
50
+ return 20 + Buffer.byteLength(id) + (parent ? Buffer.byteLength(parent) : 0) + (digest ? Buffer.byteLength(digest) : 0) + data.length;
51
+ }
52
+ /** writes a record at `offset` of `buffer` (which has room for it), returns its size */
53
+ function writeRecord(buffer, offset, id, typeIndex, parent, digest, data) {
54
+ let position = offset + 20;
55
+ const idLength = buffer.write(id, position, "utf8");
56
+ position += idLength;
57
+ const parentLength = parent ? buffer.write(parent, position, "utf8") : 0;
58
+ position += parentLength;
59
+ const digestLength = digest ? buffer.write(digest, position, "utf8") : 0;
60
+ position += digestLength;
61
+ if (Buffer.isBuffer(data)) data.copy(buffer, position);
62
+ else buffer.set(data, position);
63
+ position += data.length;
64
+ buffer.writeUInt32LE(data.length, offset);
65
+ buffer.writeUInt32LE(typeIndex, offset + 4);
66
+ buffer.writeUInt32LE(idLength, offset + 8);
67
+ buffer.writeUInt32LE(parentLength, offset + 12);
68
+ buffer.writeUInt32LE(digestLength, offset + 16);
69
+ return position - offset;
70
+ }
71
+ export { HEADER_BYTES, dataStart, dataStartAt, digestStart, encodedSize, parentStart, readHeader, recordSize, recordSizeAt, writeRecord };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,207 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs";
3
+ import { pipeline } from "node:stream/promises";
4
+ import { lookup } from "mrmime";
5
+ // src/node/develop/express-compat.ts
6
+ function compilePath(path) {
7
+ if (path instanceof RegExp) return (p) => path.test(p) ? {} : null;
8
+ const keys = [];
9
+ const pattern = path.replace(/\/$/, "").replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\\\(|\\\)/g, "").replace(/:(\w+)/g, (_m, key) => {
10
+ keys.push(key);
11
+ return "([^/]+)";
12
+ }).replace(/\*/g, ".*");
13
+ const re = new RegExp(`^${pattern}/?$`);
14
+ return (p) => {
15
+ const m = re.exec(p);
16
+ if (!m) return null;
17
+ const params = {};
18
+ keys.forEach((k, i) => params[k] = decodeURIComponent(m[i + 1]));
19
+ return params;
20
+ };
21
+ }
22
+ function httpError(status, message, code) {
23
+ return Object.assign(new Error(message), {
24
+ status,
25
+ statusCode: status,
26
+ code
27
+ });
28
+ }
29
+ /** a `..` segment (the check of the `send` package behind Express' `res.sendFile`) */
30
+ const UP_PATH_RE = /(?:^|[\\/])\.\.(?:[\\/]|$)/;
31
+ /**
32
+ * Express 4 `res.sendFile` semantics (the `send` package): an absolute path, or one relative to
33
+ * `root`. The path is used as given – like Express, it is not URL-decoded, so `%2F` or `%2e` stay
34
+ * part of the file name. `..` segments are rejected (403) with or without `root`, and the
35
+ * `dotfiles` option applies to every segment (below `root`), not only to the file name.
36
+ */
37
+ async function sendFile(req, res, file, options) {
38
+ if (typeof file !== "string") throw new TypeError("path argument is required to res.sendFile");
39
+ if (file.includes("\0")) throw httpError(400, "Bad Request");
40
+ let full;
41
+ let segments;
42
+ if (options.root) {
43
+ const relative = path.normalize(`.${path.sep}${file}`);
44
+ if (UP_PATH_RE.test(relative)) throw httpError(403, "Forbidden");
45
+ segments = relative.split(path.sep);
46
+ full = path.join(path.resolve(options.root), relative);
47
+ } else {
48
+ if (!path.isAbsolute(file)) throw new TypeError("path must be absolute or specify root to res.sendFile");
49
+ if (UP_PATH_RE.test(file)) throw httpError(403, "Forbidden");
50
+ segments = path.normalize(file).split(path.sep);
51
+ full = path.resolve(file);
52
+ }
53
+ const dotted = segments.some((s) => s.length > 1 && s.startsWith("."));
54
+ const access = options.dotfiles ?? (segments[segments.length - 1]?.startsWith(".") ? "ignore" : "allow");
55
+ if (dotted && access !== "allow") throw access === "deny" ? httpError(403, "Forbidden") : httpError(404, `ENOENT: no such file or directory, stat '${full}'`, "ENOENT");
56
+ let stat;
57
+ try {
58
+ stat = await fs.promises.stat(full);
59
+ } catch (e) {
60
+ throw httpError(404, e.message, e.code);
61
+ }
62
+ if (!stat.isFile()) throw httpError(404, `EISDIR: not a file, '${full}'`, "EISDIR");
63
+ if (!res.getHeader("Content-Type")) res.setHeader("Content-Type", lookup(full) ?? "application/octet-stream");
64
+ for (const [k, v] of Object.entries(options.headers ?? {})) res.setHeader(k, v);
65
+ res.setHeader("Content-Length", stat.size);
66
+ res.setHeader("Last-Modified", stat.mtime.toUTCString());
67
+ if (req.method === "HEAD") {
68
+ res.end();
69
+ return;
70
+ }
71
+ await pipeline(fs.createReadStream(full), res);
72
+ }
73
+ function enhance(req, res) {
74
+ if (res.__goatlyEnhanced) return;
75
+ res.__goatlyEnhanced = true;
76
+ const url = new URL(req.url ?? "/", "http://localhost");
77
+ req.path = url.pathname;
78
+ req.query = Object.fromEntries(url.searchParams);
79
+ req.originalUrl ??= req.url;
80
+ req.get = (name) => req.headers[name.toLowerCase()];
81
+ req.header = req.get;
82
+ res.status = (code) => {
83
+ res.statusCode = code;
84
+ return res;
85
+ };
86
+ res.set = res.header = (name, value) => {
87
+ if (typeof name === "object") for (const [k, v] of Object.entries(name)) res.setHeader(k, v);
88
+ else res.setHeader(name, value);
89
+ return res;
90
+ };
91
+ res.type = (type) => {
92
+ res.setHeader("Content-Type", type.includes("/") ? type : type === "html" ? "text/html; charset=utf-8" : type === "json" ? "application/json" : "text/plain");
93
+ return res;
94
+ };
95
+ res.send = (body) => {
96
+ if (body === void 0 || body === null) {
97
+ res.end();
98
+ return res;
99
+ }
100
+ if (typeof body === "object" && !Buffer.isBuffer(body)) return res.json(body);
101
+ if (!res.getHeader("Content-Type")) res.setHeader("Content-Type", typeof body === "string" ? "text/html; charset=utf-8" : "application/octet-stream");
102
+ res.end(body);
103
+ return res;
104
+ };
105
+ res.json = (body) => {
106
+ res.setHeader("Content-Type", "application/json; charset=utf-8");
107
+ res.end(JSON.stringify(body));
108
+ return res;
109
+ };
110
+ res.sendStatus = (code) => {
111
+ res.statusCode = code;
112
+ res.end(String(code));
113
+ return res;
114
+ };
115
+ res.sendFile = (file, optionsOrCallback, maybeCallback) => {
116
+ const options = typeof optionsOrCallback === "object" && optionsOrCallback || {};
117
+ const callback = typeof optionsOrCallback === "function" ? optionsOrCallback : maybeCallback;
118
+ sendFile(req, res, file, options).then(() => callback?.(), (err) => {
119
+ if (callback) return callback(err);
120
+ if (res.headersSent) return res.end();
121
+ res.statusCode = err.status ?? 500;
122
+ res.end(err.status === 404 ? "Not found" : String(err.message));
123
+ });
124
+ return res;
125
+ };
126
+ res.redirect = (statusOrUrl, maybeUrl) => {
127
+ const status = typeof statusOrUrl === "number" ? statusOrUrl : 302;
128
+ const location = typeof statusOrUrl === "string" ? statusOrUrl : maybeUrl;
129
+ res.statusCode = status;
130
+ res.setHeader("Location", location);
131
+ res.end();
132
+ return res;
133
+ };
134
+ }
135
+ function runHandlers(handlers, req, res, done) {
136
+ let i = 0;
137
+ const next = (err) => {
138
+ if (err) return done(err);
139
+ const handler = handlers[i++];
140
+ if (!handler) return done();
141
+ try {
142
+ const r = handler(req, res, next);
143
+ if (r && typeof r.catch === "function") r.catch(done);
144
+ } catch (e) {
145
+ done(e);
146
+ }
147
+ };
148
+ next();
149
+ }
150
+ /**
151
+ * A minimal Express compatible app (`app.use/get/post/...`, `res.send/json/status`) so
152
+ * `onCreateDevServer({ app })` and `developMiddleware(app)` work without Express.
153
+ */
154
+ function createApp() {
155
+ const stack = [];
156
+ const app = (req, res, out) => {
157
+ enhance(req, res);
158
+ runHandlers(stack, req, res, (err) => {
159
+ if (out) return out(err);
160
+ if (err) {
161
+ res.statusCode = 500;
162
+ res.end(String(err?.stack ?? err));
163
+ } else {
164
+ res.statusCode = 404;
165
+ res.end("Not found");
166
+ }
167
+ });
168
+ };
169
+ app.use = (pathOrHandler, ...handlers) => {
170
+ if (typeof pathOrHandler === "function") {
171
+ stack.push(pathOrHandler, ...handlers);
172
+ return app;
173
+ }
174
+ const prefix = pathOrHandler;
175
+ stack.push((req, res, next) => {
176
+ const pathname = (req.url ?? "/").split("?")[0];
177
+ if (!(typeof prefix === "string" ? pathname === prefix || pathname.startsWith(prefix.endsWith("/") ? prefix : `${prefix}/`) : prefix.test(pathname))) return next();
178
+ runHandlers(handlers, req, res, next);
179
+ });
180
+ return app;
181
+ };
182
+ for (const method of [
183
+ "get",
184
+ "post",
185
+ "put",
186
+ "delete",
187
+ "patch",
188
+ "options",
189
+ "head",
190
+ "all"
191
+ ]) app[method] = (path, ...handlers) => {
192
+ const match = compilePath(path);
193
+ stack.push((req, res, next) => {
194
+ if (method !== "all" && req.method?.toLowerCase() !== method) return next();
195
+ const params = match((req.url ?? "/").split("?")[0]);
196
+ if (!params) return next();
197
+ req.params = params;
198
+ runHandlers(handlers, req, res, next);
199
+ });
200
+ return app;
201
+ };
202
+ app.listen = () => {
203
+ throw new Error("app.listen() is not supported in goatly's dev server");
204
+ };
205
+ return app;
206
+ }
207
+ export { createApp };
@@ -0,0 +1,22 @@
1
+ // src/node/develop/graphiql.ts
2
+ const graphiqlHtml = (endpoint) => `<!doctype html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <title>GraphiQL – goatly</title>
7
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
8
+ <style>body{margin:0;height:100vh}#graphiql{height:100vh}</style>
9
+ <link rel="stylesheet" href="https://unpkg.com/graphiql@3.8.3/graphiql.min.css" />
10
+ </head>
11
+ <body>
12
+ <div id="graphiql">Loading GraphiQL…</div>
13
+ <script crossorigin src="https://unpkg.com/react@18.3.1/umd/react.production.min.js"><\/script>
14
+ <script crossorigin src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js"><\/script>
15
+ <script crossorigin src="https://unpkg.com/graphiql@3.8.3/graphiql.min.js"><\/script>
16
+ <script>
17
+ const fetcher = GraphiQL.createFetcher({ url: ${JSON.stringify(endpoint)} });
18
+ ReactDOM.createRoot(document.getElementById("graphiql")).render(React.createElement(GraphiQL, { fetcher, defaultEditorToolsVisibility: true }));
19
+ <\/script>
20
+ </body>
21
+ </html>`;
22
+ export { graphiqlHtml };
@@ -0,0 +1,41 @@
1
+ import { HYDRATION_EVENT } from "../../runtime/hydration-report.js";
2
+ // src/node/develop/hydration-report.ts
3
+ const MAX_MESSAGE_LINES = 30;
4
+ function indent(text, prefix) {
5
+ return text.split("\n").map((l) => `${prefix}${l}`).join("\n");
6
+ }
7
+ /**
8
+ * Terminal text for a batch of hydration mismatches reported by the browser. The payload comes
9
+ * over the HMR websocket, so anything that isn't shaped like a report is ignored, not trusted.
10
+ */
11
+ function formatHydrationReport(report) {
12
+ if (!report || typeof report.path !== "string" || !Array.isArray(report.issues)) return null;
13
+ const issues = report.issues.filter((i) => i && typeof i === "object");
14
+ const dropped = Number.isFinite(report.dropped) && report.dropped > 0 ? report.dropped : 0;
15
+ const count = issues.length + dropped;
16
+ if (count === 0) return null;
17
+ const lines = [`Hydration mismatch${count === 1 ? "" : "es"} on "${report.path}" – the server-rendered HTML differs from the first client render:`];
18
+ for (const issue of issues) {
19
+ let message = String(issue.message ?? "");
20
+ const messageLines = message.split("\n");
21
+ if (messageLines.length > MAX_MESSAGE_LINES) message = [...messageLines.slice(0, MAX_MESSAGE_LINES), "…"].join("\n");
22
+ const label = issue.kind === "error" ? "re-rendered on the client" : "DOM keeps the server value";
23
+ lines.push(indent(message, " ").replace(/^ {2}/, " • ") + `\n (${label})`);
24
+ if (typeof issue.componentStack === "string" && issue.componentStack) lines.push(indent(issue.componentStack, " "));
25
+ }
26
+ if (dropped > 0) lines.push(` … and ${dropped} more (see the browser console)`);
27
+ return lines.join("\n");
28
+ }
29
+ /**
30
+ * Listener for the hydration event on the client hot channel. Vite calls these without a
31
+ * try/catch from its websocket message handler, so a throw there would end the dev server.
32
+ */
33
+ function createHydrationReportListener(warn) {
34
+ return (report) => {
35
+ try {
36
+ const text = formatHydrationReport(report);
37
+ if (text) warn(text);
38
+ } catch {}
39
+ };
40
+ }
41
+ export { HYDRATION_EVENT, createHydrationReportListener, formatHydrationReport };