@teyik0/furin 0.2.0-alpha.2 → 0.2.0-alpha.3

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 (132) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +33 -33
  3. package/dist/adapter/bun.d.ts +3 -0
  4. package/dist/adapter/static.d.ts +3 -0
  5. package/dist/build/client.d.ts +25 -0
  6. package/dist/build/compile-entry.d.ts +9 -0
  7. package/dist/build/compile-entry.ts +109 -0
  8. package/dist/build/entry-template.d.ts +38 -0
  9. package/dist/build/entry-template.ts +156 -0
  10. package/dist/build/hydrate.d.ts +24 -0
  11. package/dist/build/index.d.ts +8 -0
  12. package/dist/build/index.js +8106 -0
  13. package/dist/build/route-types.d.ts +23 -0
  14. package/dist/build/scan-server.d.ts +8 -0
  15. package/dist/build/server-routes-entry.d.ts +13 -0
  16. package/dist/build/server-routes-entry.ts +36 -0
  17. package/dist/build/shared.d.ts +12 -0
  18. package/dist/build/ssg-cache.d.ts +4 -0
  19. package/dist/build/types.d.ts +80 -0
  20. package/dist/cli/config.d.ts +9 -0
  21. package/dist/cli/index.d.ts +2 -0
  22. package/dist/cli/index.js +8097 -0
  23. package/dist/client/boundaries.d.ts +117 -0
  24. package/dist/client/default-screens.d.ts +17 -0
  25. package/dist/client/link.d.ts +22 -0
  26. package/dist/client/link.js +4244 -0
  27. package/dist/client/router/boundary-tree.d.ts +26 -0
  28. package/dist/client/router/context.d.ts +8 -0
  29. package/dist/client/router/history.d.ts +9 -0
  30. package/dist/client/router/index.d.ts +11 -0
  31. package/dist/client/router/link-utils.d.ts +53 -0
  32. package/dist/client/router/navigation.d.ts +10 -0
  33. package/dist/client/router/provider.d.ts +4 -0
  34. package/dist/client/router/search/index.d.ts +18 -0
  35. package/dist/client/router/search-store.d.ts +21 -0
  36. package/dist/client/router/spa-response.d.ts +58 -0
  37. package/dist/client/router/types.d.ts +292 -0
  38. package/dist/client/server-error.d.ts +12 -0
  39. package/dist/client/sync.d.ts +25 -0
  40. package/dist/client.d.ts +243 -0
  41. package/dist/client.js +140 -0
  42. package/dist/config.d.ts +57 -0
  43. package/dist/config.js +29 -0
  44. package/dist/env.d.ts +50 -0
  45. package/dist/furin.d.ts +77 -0
  46. package/dist/furin.js +8693 -0
  47. package/dist/plugin/index.d.ts +20 -0
  48. package/dist/plugin/index.js +1500 -0
  49. package/dist/plugin/transform-client.d.ts +10 -0
  50. package/dist/server/auto-invalidate/index.d.ts +4 -0
  51. package/dist/server/auto-invalidate/plugin.d.ts +38 -0
  52. package/dist/server/auto-invalidate/registry.d.ts +9 -0
  53. package/dist/server/auto-invalidate/runtime.d.ts +9 -0
  54. package/dist/server/auto-invalidate/types.d.ts +12 -0
  55. package/dist/server/cache/dev-loader.d.ts +28 -0
  56. package/dist/server/cache/index.d.ts +10 -0
  57. package/dist/server/cache/invalidation.d.ts +12 -0
  58. package/dist/server/cache/isr-ssg.d.ts +26 -0
  59. package/dist/server/cache/isr.d.ts +6 -0
  60. package/dist/server/cache/registry.d.ts +5 -0
  61. package/dist/server/cache/route-cache.d.ts +26 -0
  62. package/dist/server/cache/ssg.d.ts +5 -0
  63. package/dist/server/context-logger.d.ts +28 -0
  64. package/dist/server/dev-inspector.d.ts +89 -0
  65. package/dist/server/dev-page-plugin.d.ts +112 -0
  66. package/dist/server/internal.d.ts +35 -0
  67. package/dist/server/internal.js +17 -0
  68. package/dist/server/lang-detect.d.ts +5 -0
  69. package/dist/server/render/assemble.d.ts +49 -0
  70. package/dist/server/render/element.d.ts +24 -0
  71. package/dist/server/render/index.d.ts +7 -0
  72. package/dist/server/render/index.ts +22 -0
  73. package/dist/server/render/isr.d.ts +4 -0
  74. package/dist/server/render/loaders.d.ts +64 -0
  75. package/dist/server/render/not-found.d.ts +6 -0
  76. package/dist/server/render/shell.d.ts +39 -0
  77. package/dist/server/render/shell.ts +202 -0
  78. package/dist/server/render/ssg.d.ts +9 -0
  79. package/dist/server/render/ssr.d.ts +108 -0
  80. package/dist/server/render/template.d.ts +6 -0
  81. package/dist/server/router/discovery.d.ts +16 -0
  82. package/dist/server/router/hmr.d.ts +65 -0
  83. package/dist/server/router/index.d.ts +6 -0
  84. package/dist/server/router/index.js +27 -0
  85. package/dist/server/router/index.ts +28 -0
  86. package/dist/server/router/patterns.d.ts +40 -0
  87. package/dist/server/router/plugin.d.ts +21 -0
  88. package/dist/server/router/schemas.d.ts +59 -0
  89. package/dist/server/router/types.d.ts +60 -0
  90. package/dist/server/runtime-env.d.ts +3 -0
  91. package/dist/server/runtime-env.js +10 -0
  92. package/dist/server/sync/config.d.ts +6 -0
  93. package/dist/server/sync/index.d.ts +4 -0
  94. package/dist/server/sync/plugin.d.ts +369 -0
  95. package/dist/server/sync/stream.d.ts +47 -0
  96. package/dist/shared/await.d.ts +67 -0
  97. package/dist/shared/deferred-ndjson.d.ts +32 -0
  98. package/dist/shared/digest.d.ts +16 -0
  99. package/dist/shared/error.d.ts +37 -0
  100. package/dist/shared/not-found.d.ts +19 -0
  101. package/dist/shared/search-params.d.ts +17 -0
  102. package/dist/shared/utils/ast-walk.d.ts +18 -0
  103. package/dist/shared/utils/index.d.ts +13 -0
  104. package/package.json +5 -5
  105. package/src/adapter/README.md +13 -13
  106. package/src/build/client.ts +152 -152
  107. package/src/build/compile-entry.ts +109 -109
  108. package/src/build/entry-template.ts +156 -156
  109. package/src/build/hydrate.ts +340 -337
  110. package/src/build/index.ts +152 -152
  111. package/src/build/route-types.ts +145 -145
  112. package/src/build/scan-server.ts +95 -95
  113. package/src/build/server-routes-entry.ts +36 -36
  114. package/src/build/shared.ts +80 -79
  115. package/src/build/ssg-cache.ts +32 -32
  116. package/src/build/types.ts +89 -89
  117. package/src/client/router/link-utils.ts +184 -177
  118. package/src/client/router/provider.tsx +804 -759
  119. package/src/client/router/types.ts +276 -271
  120. package/src/client/sync.ts +98 -0
  121. package/src/client.ts +369 -355
  122. package/src/furin.ts +465 -444
  123. package/src/server/auto-invalidate/runtime.ts +134 -133
  124. package/src/server/dev-page-plugin.ts +454 -449
  125. package/src/server/render/assemble.ts +160 -133
  126. package/src/server/render/isr.ts +323 -317
  127. package/src/server/render/ssr.ts +585 -583
  128. package/src/server/router/plugin.ts +384 -384
  129. package/src/server/sync/config.ts +29 -0
  130. package/src/server/sync/index.ts +14 -0
  131. package/src/server/sync/plugin.ts +108 -0
  132. package/src/server/sync/stream.ts +144 -0
@@ -1,449 +1,454 @@
1
- /**
2
- * Bun.plugin that loads page modules into a virtual namespace so they stay
3
- * out of `--hot`'s file watcher.
4
- *
5
- * `--hot` re-evaluates every real source file in the module graph when any
6
- * tracked file changes. By resolving page imports to a virtual namespace
7
- * (`furin-dev-page`), the actual `.tsx` files are never registered as
8
- * watched sources — edits trigger only the client-side dev bundler (React
9
- * Fast Refresh) without a full server restart.
10
- *
11
- * ## Cache-busting (prevents hydration mismatches)
12
- *
13
- * Bun caches every resolved module by its `(namespace, path)` identity.
14
- * Without cache-busting, the first import of `pages/index.tsx` would be
15
- * permanently frozen: after a file edit the server would keep returning the
16
- * stale module while the client received fresh HMR code, causing a React
17
- * hydration mismatch.
18
- *
19
- * Solution: the caller appends `?furin-server&t=<timestamp>` to the import
20
- * specifier (a new timestamp on every request). `onResolve` preserves the
21
- * `?t=...` fragment in the resolved path so each request gets a unique
22
- * `(namespace, path)` key and Bun always calls `onLoad` fresh.
23
- *
24
- * ## Relative import rewriting
25
- *
26
- * Modules in a virtual namespace cannot resolve relative specifiers on their
27
- * own (there is no real directory context). We rewrite every `./` / `../`
28
- * path to an absolute one before returning the source.
29
- *
30
- * ## Bare specifier rewriting
31
- *
32
- * When `onLoad` returns `loader: "js"`, Bun resolves bare specifiers
33
- * (e.g. `@teyik0/furin/link`, `shiki`) from the process CWD — not from the
34
- * page file's directory. On a cold start the CWD and the file's directory
35
- * often agree, but after `bun --hot` re-evaluates the server the module
36
- * cache for project-local packages (like `packages/core/src/link.tsx`) may
37
- * be cleared and re-loaded with a fresh React instance that diverges from the
38
- * one already cached by `react-dom/server`. The result is the classic
39
- * "two React copies" crash: `dispatcher.useState === null`.
40
- *
41
- * Fix: after transpilation, resolve every bare specifier from the page
42
- * file's directory via `Bun.resolveSync` and replace it with the
43
- * canonical on-disk path. This pins each import to exactly the same
44
- * file-system location that Bun's native module resolver would choose,
45
- * guaranteeing a single shared React instance regardless of CWD or
46
- * hot-reload state.
47
- *
48
- * All import/re-export occurrences of each quoted specifier are replaced using
49
- * a context-aware regex (requires a preceding `from` or `import` keyword) so
50
- * that modules which both import and re-export from the same package are fully
51
- * rewritten while string literals in non-import positions are left untouched.
52
- */
53
-
54
- import { dirname, resolve } from "node:path";
55
- import { fileURLToPath } from "node:url";
56
- import { invalidateDevLoaderCacheBySource } from "./cache/dev-loader.ts";
57
-
58
- // Matches ?furin-server with an optional &t=<ms> cache-buster.
59
- const FURIN_SERVER_FILTER = /\?furin-server(?:&t=\d+)?$/;
60
- const ANY_FILTER = /.*/;
61
- const WORKSPACE_SOURCE_FILTER =
62
- /^(?!.*(?:\/node_modules\/|\/\.bun\/))(?!.*\.(?:test|spec)\.[jt]sx?$).*\.[jt]sx?$/;
63
- const T_PARAM_RE = /&t=(\d+)/;
64
- const STRIP_FURIN_SERVER_RE = /\?furin-server.*$/;
65
- const STRIP_T_PARAM_RE = /\?t=\d+$/;
66
-
67
- let _pluginRegistered = false;
68
-
69
- type SourceLoader = "js" | "jsx" | "ts" | "tsx";
70
-
71
- // ── Singleton package resolution ───────────────────────────────────────────────
72
- //
73
- // React (and react-dom) must be singletons: every module in the render graph
74
- // must import the EXACT same object instance so that ReactSharedInternals.H
75
- // (the hooks dispatcher) is shared between react-dom/server and the page.
76
- //
77
- // We resolve the absolute on-disk path once at module-evaluation time and
78
- // rewrite every explicit import in the transpiled source to use that path.
79
- // The auto-injected jsx-dev-runtime import (added by Bun.Transpiler AFTER the
80
- // source is transformed) is handled by injectJsxHelperImports below.
81
-
82
- /** React packages that must share a single instance across the module graph. */
83
- const SINGLETON_PKGS = [
84
- "react",
85
- "react/jsx-runtime",
86
- "react/jsx-dev-runtime",
87
- "react-dom",
88
- "react-dom/server",
89
- "react-dom/client",
90
- ] as const;
91
-
92
- /** package specifier → absolute file path, resolved once at plugin registration time. */
93
- const SINGLETON_PATHS = new Map<string, string>();
94
- for (const pkg of SINGLETON_PKGS) {
95
- try {
96
- SINGLETON_PATHS.set(pkg, fileURLToPath(import.meta.resolve(pkg)));
97
- } catch {
98
- // Package not installed — skip (e.g. react-dom/client in a server-only env)
99
- }
100
- }
101
-
102
- function escapeRegExp(s: string): string {
103
- return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
104
- }
105
-
106
- /**
107
- * Rewrites bare React/react-dom singleton imports in source text to their
108
- * absolute resolved paths. Handles explicit static import / re-export forms:
109
- *
110
- * import { useState } from "react" → import { useState } from "/abs/…"
111
- * import type { FC } from "react"
112
- * export { x } from "react"
113
- * import "react/jsx-dev-runtime"
114
- *
115
- * Does NOT touch dynamic `import("react")` or `require("react")`.
116
- *
117
- * @internal exported for testing
118
- */
119
- export function rewriteSingletonImports(source: string): string {
120
- let result = source;
121
- for (const [pkg, absPath] of SINGLETON_PATHS) {
122
- // react-doctor-disable-next-line react-doctor/js-hoist-regexp
123
- const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(pkg)}["']`, "g");
124
- result = result.replace(re, (_, g1: string) => `${g1}"${absPath}"`);
125
- }
126
- return result;
127
- }
128
-
129
- /**
130
- * `Bun.Transpiler.transformSync` converts JSX syntax to function calls using
131
- * mangled helper names (e.g. `jsxDEV_7x81h0kn`, `Fragment_8vg9x3sq`) but does
132
- * NOT emit the corresponding import statement — it expects Bun's full bundler
133
- * pipeline to inject it later.
134
- *
135
- * When we return pre-transpiled JS from `onLoad`, that pipeline step never
136
- * runs, leaving the helpers as undefined free variables. This function scans
137
- * the transpiled source, detects which mangled helper names are used, and
138
- * prepends the correct import statements using absolute on-disk paths from
139
- * `SINGLETON_PATHS`.
140
- *
141
- * Helper → package mapping:
142
- * jsxDEV_* → `{ jsxDEV as … }` from react/jsx-dev-runtime
143
- * Fragment_* → `{ Fragment as … }` from react/jsx-dev-runtime
144
- * jsx_* → `{ jsx as … }` from react/jsx-runtime (prod only)
145
- * jsxs_* → `{ jsxs as … }` from react/jsx-runtime (prod only)
146
- *
147
- * @internal exported for testing
148
- */
149
- export function injectJsxHelperImports(transpiled: string): string {
150
- // Match mangled JSX helper names. Alternation order matters: try longer
151
- // prefixes first so "jsxDEV_xxx" isn't partially matched as "jsx_xxx".
152
- const JSX_HELPER_RE = /\b(jsxDEV|jsxs|jsx|Fragment)_([0-9a-z]{8})\b/g;
153
-
154
- // Package → Map<varName, exportName>
155
- const devRuntime = new Map<string, string>(); // react/jsx-dev-runtime
156
- const prodRuntime = new Map<string, string>(); // react/jsx-runtime
157
-
158
- for (const [, base, hash] of transpiled.matchAll(JSX_HELPER_RE)) {
159
- if (!(base && hash)) {
160
- continue;
161
- }
162
- const varName = `${base}_${hash}`;
163
- if (base === "jsxDEV" || base === "Fragment") {
164
- devRuntime.set(varName, base);
165
- } else {
166
- prodRuntime.set(varName, base);
167
- }
168
- }
169
-
170
- const lines: string[] = [];
171
-
172
- if (devRuntime.size > 0) {
173
- const absPath = SINGLETON_PATHS.get("react/jsx-dev-runtime");
174
- if (absPath) {
175
- const specifiers = [...devRuntime.entries()]
176
- .map(([varName, exportName]) => `${exportName} as ${varName}`)
177
- .join(", ");
178
- lines.push(`import { ${specifiers} } from "${absPath}";`);
179
- }
180
- }
181
-
182
- if (prodRuntime.size > 0) {
183
- const absPath = SINGLETON_PATHS.get("react/jsx-runtime");
184
- if (absPath) {
185
- const specifiers = [...prodRuntime.entries()]
186
- .map(([varName, exportName]) => `${exportName} as ${varName}`)
187
- .join(", ");
188
- lines.push(`import { ${specifiers} } from "${absPath}";`);
189
- }
190
- }
191
-
192
- if (lines.length === 0) {
193
- return transpiled;
194
- }
195
- return `${lines.join("\n")}\n${transpiled}`;
196
- }
197
-
198
- /**
199
- * Matches relative specifiers in all ESM import / re-export forms:
200
- *
201
- * import { foo } from "./bar" ← named import
202
- * import foo from "../baz" ← default import
203
- * import "./side-effect" ← side-effect import
204
- * export { x } from "./mod" ← re-export
205
- * export * from "./mod" ← namespace re-export
206
- * import type { T } from "./types" ← type import (harmless to rewrite)
207
- */
208
- const RELATIVE_SPECIFIER_RE = /(?:from|import)\s+["'](\.\.?\/[^"']+)["']/g;
209
-
210
- /** @internal exported for testing */
211
- export function rewriteRelativeImports(source: string, dir: string): string {
212
- return source.replace(RELATIVE_SPECIFIER_RE, (match, relPath, offset) => {
213
- // Skip matches that appear on a comment line (// ...)
214
- const lineStart = source.lastIndexOf("\n", offset - 1) + 1;
215
- const linePrefix = source.slice(lineStart, offset).trimStart();
216
- if (linePrefix.startsWith("//") || linePrefix.startsWith("*")) {
217
- return match;
218
- }
219
- const absPath = resolve(dir, relPath);
220
- const keyword = match.startsWith("import") ? "import" : "from";
221
- return `${keyword} "${absPath}"`;
222
- });
223
- }
224
-
225
- /**
226
- * Rewrites all remaining bare specifiers in the transpiled JS to absolute
227
- * on-disk paths resolved from `dir` (the page file's directory).
228
- *
229
- * Uses `Bun.Transpiler.scan()` on the original source to get the authoritative
230
- * list of *actual* import specifiers (parsing correctly handles template
231
- * literals, comments, etc.). For each bare specifier that is not already
232
- * handled by `rewriteSingletonImports`, it calls `Bun.resolveSync` and
233
- * replaces **every** import/re-export occurrence of the quoted specifier using
234
- * a context-aware regex with the `g` flag — mirroring the approach used by
235
- * `rewriteSingletonImports`. This correctly handles modules that both import
236
- * and re-export from the same package without leaving any bare specifier
237
- * behind. String literals that happen to contain the same text (inside
238
- * template literals, JSX props, etc.) are not touched because the regex
239
- * requires a preceding `from` or `import` keyword.
240
- *
241
- * @internal exported for testing
242
- */
243
- export function rewriteBareImports(source: string, transpiled: string, dir: string): string {
244
- const scanner = new Bun.Transpiler({ loader: "tsx" });
245
- let { imports } = scanner.scan(source);
246
- // Deduplicate: scan() may return the same specifier multiple times if it
247
- // appears in both `import` and `export ... from` positions.
248
- const seen = new Set<string>();
249
- imports = imports.filter((imp) => {
250
- if (seen.has(imp.path)) {
251
- return false;
252
- }
253
- seen.add(imp.path);
254
- return true;
255
- });
256
-
257
- let result = transpiled;
258
- for (const imp of imports) {
259
- const spec = imp.path;
260
- // Skip relative paths (already rewritten by rewriteRelativeImports before transpilation)
261
- // and already-absolute paths.
262
- if (spec.startsWith(".") || spec.startsWith("/") || spec.startsWith("file:")) {
263
- continue;
264
- }
265
- // Skip React singletons — already handled by rewriteSingletonImports.
266
- if (SINGLETON_PATHS.has(spec)) {
267
- continue;
268
- }
269
-
270
- let resolved: string;
271
- try {
272
- resolved = Bun.resolveSync(spec, dir);
273
- } catch {
274
- // Not resolvable from the file's directory — leave as a bare specifier
275
- // so Bun falls back to CWD-relative resolution (adequate for most cases).
276
- continue;
277
- }
278
-
279
- // Replace ALL import/re-export occurrences of the bare specifier using a
280
- // context-aware regex with the `g` flag. This correctly handles modules
281
- // that both import and re-export from the same package. The regex only
282
- // matches when the specifier is preceded by `from` or `import` so string
283
- // literals in non-import positions are left untouched.
284
- // react-doctor-disable-next-line react-doctor/js-hoist-regexp
285
- const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(spec)}["']`, "g");
286
- result = result.replace(re, (_, g1: string) => `${g1}"${resolved}"`);
287
- }
288
- return result;
289
- }
290
-
291
- function getSourceLoader(filePath: string): SourceLoader | null {
292
- if (filePath.endsWith(".tsx")) {
293
- return "tsx";
294
- }
295
- if (filePath.endsWith(".ts")) {
296
- return "ts";
297
- }
298
- if (filePath.endsWith(".jsx")) {
299
- return "jsx";
300
- }
301
- if (filePath.endsWith(".js")) {
302
- return "js";
303
- }
304
- return null;
305
- }
306
-
307
- function shouldSkipWorkspaceTransform(filePath: string): boolean {
308
- const normalized = filePath.replace(/\\/g, "/");
309
- return normalized.includes("/.furin/");
310
- }
311
-
312
- function transformDevSource(
313
- raw: string,
314
- filePath: string,
315
- options: { rewriteBareImports: boolean; rewriteRelativeImports: boolean }
316
- ): string {
317
- const loader = getSourceLoader(filePath);
318
- if (!loader) {
319
- throw new Error(`[furin] Unsupported source loader for ${filePath}`);
320
- }
321
-
322
- const dir = dirname(filePath);
323
- const sourceForTranspile = options.rewriteRelativeImports
324
- ? rewriteRelativeImports(raw, dir)
325
- : raw;
326
- const transpiler = new Bun.Transpiler({ loader });
327
- const transpiled = transpiler.transformSync(sourceForTranspile, loader);
328
-
329
- let result = transpiled;
330
- if (options.rewriteBareImports) {
331
- result = rewriteBareImports(raw, result, dir);
332
- }
333
-
334
- result = rewriteSingletonImports(result);
335
- return injectJsxHelperImports(result);
336
- }
337
-
338
- export function registerDevPagePlugin(): void {
339
- if (_pluginRegistered) {
340
- return;
341
- }
342
- _pluginRegistered = true;
343
- Bun.plugin({
344
- name: "furin-dev-page-loader",
345
- setup(build) {
346
- /**
347
- * Strip `?furin-server` but keep `?t=<ms>` in the resolved path so
348
- * each request gets a unique module identity, bypassing Bun's cache.
349
- */
350
- build.onResolve({ filter: FURIN_SERVER_FILTER }, (args) => {
351
- const tMatch = T_PARAM_RE.exec(args.path);
352
- const filePath = args.path.replace(STRIP_FURIN_SERVER_RE, "");
353
- const resolvedPath = tMatch ? `${filePath}?t=${tMatch[1]}` : filePath;
354
- return { path: resolvedPath, namespace: "furin-dev-page" };
355
- });
356
-
357
- /**
358
- * Workspace source files (root.tsx, _route.tsx, local components, core
359
- * packages, etc.) still load through Bun's normal file namespace in dev.
360
- *
361
- * After bun --hot re-evaluates part of that graph, those modules can
362
- * re-import React through a different logical path than react-dom/server,
363
- * which recreates the classic "dispatcher is null" invalid hook crash.
364
- *
365
- * Pre-transpile those files and rewrite only the React singleton imports
366
- * so every SSR module observes the exact same React instance, while still
367
- * keeping the files in Bun's watched graph for root.tsx HMR.
368
- */
369
- build.onLoad({ filter: WORKSPACE_SOURCE_FILTER }, async (args) => {
370
- const raw = await Bun.file(args.path).text();
371
- const loader = getSourceLoader(args.path);
372
- if (!loader) {
373
- throw new Error(`[furin] Unsupported source loader for ${args.path}`);
374
- }
375
-
376
- // Every re-evaluation of a workspace source in dev is either the
377
- // initial load (cache empty → no-op) or a post-edit HMR re-read.
378
- // Both are correct moments to drop dependent dev loader cache
379
- // entries — they will be re-populated on the next request.
380
- invalidateDevLoaderCacheBySource(args.path);
381
-
382
- if (shouldSkipWorkspaceTransform(args.path)) {
383
- return {
384
- contents: raw,
385
- loader,
386
- };
387
- }
388
-
389
- const contents = transformDevSource(raw, args.path, {
390
- rewriteBareImports: false,
391
- rewriteRelativeImports: false,
392
- });
393
-
394
- return {
395
- contents,
396
- loader: "js",
397
- };
398
- });
399
-
400
- /**
401
- * Read the page file fresh from disk. The `?t=...` suffix guarantees
402
- * this handler is called on every request; strip it before file I/O.
403
- *
404
- * ## Why we pre-transpile with Bun.Transpiler
405
- *
406
- * Bun's runtime plugin system (used by `bun --hot`) does NOT route
407
- * sub-imports from virtual-namespace modules through `onResolve` hooks —
408
- * the `namespace` filter on `onResolve` only works in the bundler context
409
- * (`Bun.build()`), not in the runtime module loader. This means two
410
- * classes of specifiers inside a `furin-dev-page` module cannot be
411
- * intercepted after the fact:
412
- *
413
- * 1. **Relative imports** (`./root`, `../utils`) — no real directory
414
- * context in the virtual namespace → Bun fails to resolve them.
415
- * 2. **Auto-injected JSX runtime** — `import { jsx } from
416
- * "react/jsx-dev-runtime"` added by Bun's TSX transpiler AFTER
417
- * `onLoad` returns → cannot be rewritten in the source text.
418
- *
419
- * Solution: pre-transpile the source with `Bun.Transpiler` ourselves,
420
- * then rewrite all specifiers in the resulting JS text before returning
421
- * it with `loader: "js"` (which Bun loads as-is, with no further
422
- * transpilation or automatic import injection):
423
- *
424
- * • `rewriteRelativeImports` → converts `./root` to `/abs/path/root`
425
- * • `rewriteBareImports` → resolves ALL bare specifiers (including
426
- * `@teyik0/furin/link`, `shiki`, etc.) to canonical absolute paths
427
- * from the page file's directory, preventing "two React copies" after
428
- * bun --hot re-evaluation.
429
- * • `rewriteSingletonImports` → belt-and-suspenders for react singletons
430
- * (covered by rewriteBareImports but kept for safety).
431
- * • `injectJsxHelperImports` → adds the JSX helper imports that
432
- * `Bun.Transpiler` emits as free variables without corresponding imports.
433
- */
434
- build.onLoad({ namespace: "furin-dev-page", filter: ANY_FILTER }, async (args) => {
435
- const filePath = args.path.replace(STRIP_T_PARAM_RE, "");
436
- const raw = await Bun.file(filePath).text();
437
- const contents = transformDevSource(raw, filePath, {
438
- rewriteBareImports: true,
439
- rewriteRelativeImports: true,
440
- });
441
-
442
- return {
443
- contents,
444
- loader: "js", // Already fully transpiled — skip Bun's own TSX step.
445
- };
446
- });
447
- },
448
- });
449
- }
1
+ /**
2
+ * Bun.plugin that loads page modules into a virtual namespace so they stay
3
+ * out of `--hot`'s file watcher.
4
+ *
5
+ * `--hot` re-evaluates every real source file in the module graph when any
6
+ * tracked file changes. By resolving page imports to a virtual namespace
7
+ * (`furin-dev-page`), the actual `.tsx` files are never registered as
8
+ * watched sources — edits trigger only the client-side dev bundler (React
9
+ * Fast Refresh) without a full server restart.
10
+ *
11
+ * ## Cache-busting (prevents hydration mismatches)
12
+ *
13
+ * Bun caches every resolved module by its `(namespace, path)` identity.
14
+ * Without cache-busting, the first import of `pages/index.tsx` would be
15
+ * permanently frozen: after a file edit the server would keep returning the
16
+ * stale module while the client received fresh HMR code, causing a React
17
+ * hydration mismatch.
18
+ *
19
+ * Solution: the caller appends `?furin-server&t=<timestamp>` to the import
20
+ * specifier (a new timestamp on every request). `onResolve` preserves the
21
+ * `?t=...` fragment in the resolved path so each request gets a unique
22
+ * `(namespace, path)` key and Bun always calls `onLoad` fresh.
23
+ *
24
+ * ## Relative import rewriting
25
+ *
26
+ * Modules in a virtual namespace cannot resolve relative specifiers on their
27
+ * own (there is no real directory context). We rewrite every `./` / `../`
28
+ * path to an absolute one before returning the source.
29
+ *
30
+ * ## Bare specifier rewriting
31
+ *
32
+ * When `onLoad` returns `loader: "js"`, Bun resolves bare specifiers
33
+ * (e.g. `@teyik0/furin/link`, `shiki`) from the process CWD — not from the
34
+ * page file's directory. On a cold start the CWD and the file's directory
35
+ * often agree, but after `bun --hot` re-evaluates the server the module
36
+ * cache for project-local packages (like `packages/core/src/link.tsx`) may
37
+ * be cleared and re-loaded with a fresh React instance that diverges from the
38
+ * one already cached by `react-dom/server`. The result is the classic
39
+ * "two React copies" crash: `dispatcher.useState === null`.
40
+ *
41
+ * Fix: after transpilation, resolve every bare specifier from the page
42
+ * file's directory via `Bun.resolveSync` and replace it with the
43
+ * canonical on-disk path. This pins each import to exactly the same
44
+ * file-system location that Bun's native module resolver would choose,
45
+ * guaranteeing a single shared React instance regardless of CWD or
46
+ * hot-reload state.
47
+ *
48
+ * All import/re-export occurrences of each quoted specifier are replaced using
49
+ * a context-aware regex (requires a preceding `from` or `import` keyword) so
50
+ * that modules which both import and re-export from the same package are fully
51
+ * rewritten while string literals in non-import positions are left untouched.
52
+ */
53
+
54
+ import { dirname, resolve } from "node:path";
55
+ import { fileURLToPath } from "node:url";
56
+ import { invalidateDevLoaderCacheBySource } from "./cache/dev-loader.ts";
57
+
58
+ // Matches ?furin-server with an optional &t=<ms> cache-buster.
59
+ const FURIN_SERVER_FILTER = /\?furin-server(?:&t=\d+)?$/;
60
+ const ANY_FILTER = /.*/;
61
+ export const WORKSPACE_SOURCE_FILTER =
62
+ /^(?!.*(?:[\\/]node_modules[\\/]|[\\/]\.bun[\\/]))(?!.*\.(?:test|spec)\.[jt]sx?$).*\.[jt]sx?$/;
63
+ const T_PARAM_RE = /&t=(\d+)/;
64
+ const STRIP_FURIN_SERVER_RE = /\?furin-server.*$/;
65
+ const STRIP_T_PARAM_RE = /\?t=\d+$/;
66
+
67
+ let _pluginRegistered = false;
68
+
69
+ type SourceLoader = "js" | "jsx" | "ts" | "tsx";
70
+
71
+ // ── Singleton package resolution ───────────────────────────────────────────────
72
+ //
73
+ // React (and react-dom) must be singletons: every module in the render graph
74
+ // must import the EXACT same object instance so that ReactSharedInternals.H
75
+ // (the hooks dispatcher) is shared between react-dom/server and the page.
76
+ //
77
+ // We resolve the absolute on-disk path once at module-evaluation time and
78
+ // rewrite every explicit import in the transpiled source to use that path.
79
+ // The auto-injected jsx-dev-runtime import (added by Bun.Transpiler AFTER the
80
+ // source is transformed) is handled by injectJsxHelperImports below.
81
+
82
+ /** React packages that must share a single instance across the module graph. */
83
+ const SINGLETON_PKGS = [
84
+ "react",
85
+ "react/jsx-runtime",
86
+ "react/jsx-dev-runtime",
87
+ "react-dom",
88
+ "react-dom/server",
89
+ "react-dom/client",
90
+ ] as const;
91
+
92
+ /** package specifier → absolute file path, resolved once at plugin registration time. */
93
+ const SINGLETON_PATHS = new Map<string, string>();
94
+ for (const pkg of SINGLETON_PKGS) {
95
+ try {
96
+ SINGLETON_PATHS.set(pkg, toImportSpecifier(fileURLToPath(import.meta.resolve(pkg))));
97
+ } catch {
98
+ // Package not installed — skip (e.g. react-dom/client in a server-only env)
99
+ }
100
+ }
101
+
102
+ /** Converts a native absolute path to Bun's cross-platform import format. */
103
+ export function toImportSpecifier(filePath: string): string {
104
+ return filePath.replaceAll("\\", "/");
105
+ }
106
+
107
+ function escapeRegExp(s: string): string {
108
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
109
+ }
110
+
111
+ /**
112
+ * Rewrites bare React/react-dom singleton imports in source text to their
113
+ * absolute resolved paths. Handles explicit static import / re-export forms:
114
+ *
115
+ * import { useState } from "react" → import { useState } from "/abs/…"
116
+ * import type { FC } from "react"
117
+ * export { x } from "react"
118
+ * import "react/jsx-dev-runtime"
119
+ *
120
+ * Does NOT touch dynamic `import("react")` or `require("react")`.
121
+ *
122
+ * @internal exported for testing
123
+ */
124
+ export function rewriteSingletonImports(source: string): string {
125
+ let result = source;
126
+ for (const [pkg, absPath] of SINGLETON_PATHS) {
127
+ // react-doctor-disable-next-line react-doctor/js-hoist-regexp
128
+ const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(pkg)}["']`, "g");
129
+ result = result.replace(re, (_, g1: string) => `${g1}${JSON.stringify(absPath)}`);
130
+ }
131
+ return result;
132
+ }
133
+
134
+ /**
135
+ * `Bun.Transpiler.transformSync` converts JSX syntax to function calls using
136
+ * mangled helper names (e.g. `jsxDEV_7x81h0kn`, `Fragment_8vg9x3sq`) but does
137
+ * NOT emit the corresponding import statement — it expects Bun's full bundler
138
+ * pipeline to inject it later.
139
+ *
140
+ * When we return pre-transpiled JS from `onLoad`, that pipeline step never
141
+ * runs, leaving the helpers as undefined free variables. This function scans
142
+ * the transpiled source, detects which mangled helper names are used, and
143
+ * prepends the correct import statements using absolute on-disk paths from
144
+ * `SINGLETON_PATHS`.
145
+ *
146
+ * Helper → package mapping:
147
+ * jsxDEV_* → `{ jsxDEV as … }` from react/jsx-dev-runtime
148
+ * Fragment_* → `{ Fragment as … }` from react/jsx-dev-runtime
149
+ * jsx_* → `{ jsx as … }` from react/jsx-runtime (prod only)
150
+ * jsxs_* → `{ jsxs as … }` from react/jsx-runtime (prod only)
151
+ *
152
+ * @internal exported for testing
153
+ */
154
+ export function injectJsxHelperImports(transpiled: string): string {
155
+ // Match mangled JSX helper names. Alternation order matters: try longer
156
+ // prefixes first so "jsxDEV_xxx" isn't partially matched as "jsx_xxx".
157
+ const JSX_HELPER_RE = /\b(jsxDEV|jsxs|jsx|Fragment)_([0-9a-z]{8})\b/g;
158
+
159
+ // Package → Map<varName, exportName>
160
+ const devRuntime = new Map<string, string>(); // react/jsx-dev-runtime
161
+ const prodRuntime = new Map<string, string>(); // react/jsx-runtime
162
+
163
+ for (const [, base, hash] of transpiled.matchAll(JSX_HELPER_RE)) {
164
+ if (!(base && hash)) {
165
+ continue;
166
+ }
167
+ const varName = `${base}_${hash}`;
168
+ if (base === "jsxDEV" || base === "Fragment") {
169
+ devRuntime.set(varName, base);
170
+ } else {
171
+ prodRuntime.set(varName, base);
172
+ }
173
+ }
174
+
175
+ const lines: string[] = [];
176
+
177
+ if (devRuntime.size > 0) {
178
+ const absPath = SINGLETON_PATHS.get("react/jsx-dev-runtime");
179
+ if (absPath) {
180
+ const specifiers = [...devRuntime.entries()]
181
+ .map(([varName, exportName]) => `${exportName} as ${varName}`)
182
+ .join(", ");
183
+ lines.push(`import { ${specifiers} } from ${JSON.stringify(absPath)};`);
184
+ }
185
+ }
186
+
187
+ if (prodRuntime.size > 0) {
188
+ const absPath = SINGLETON_PATHS.get("react/jsx-runtime");
189
+ if (absPath) {
190
+ const specifiers = [...prodRuntime.entries()]
191
+ .map(([varName, exportName]) => `${exportName} as ${varName}`)
192
+ .join(", ");
193
+ lines.push(`import { ${specifiers} } from ${JSON.stringify(absPath)};`);
194
+ }
195
+ }
196
+
197
+ if (lines.length === 0) {
198
+ return transpiled;
199
+ }
200
+ return `${lines.join("\n")}\n${transpiled}`;
201
+ }
202
+
203
+ /**
204
+ * Matches relative specifiers in all ESM import / re-export forms:
205
+ *
206
+ * import { foo } from "./bar" ← named import
207
+ * import foo from "../baz" ← default import
208
+ * import "./side-effect" ← side-effect import
209
+ * export { x } from "./mod" ← re-export
210
+ * export * from "./mod" ← namespace re-export
211
+ * import type { T } from "./types" ← type import (harmless to rewrite)
212
+ */
213
+ const RELATIVE_SPECIFIER_RE = /(?:from|import)\s+["'](\.\.?\/[^"']+)["']/g;
214
+
215
+ /** @internal exported for testing */
216
+ export function rewriteRelativeImports(source: string, dir: string): string {
217
+ return source.replace(RELATIVE_SPECIFIER_RE, (match, relPath, offset) => {
218
+ // Skip matches that appear on a comment line (// ...)
219
+ const lineStart = source.lastIndexOf("\n", offset - 1) + 1;
220
+ const linePrefix = source.slice(lineStart, offset).trimStart();
221
+ if (linePrefix.startsWith("//") || linePrefix.startsWith("*")) {
222
+ return match;
223
+ }
224
+ const absPath = toImportSpecifier(resolve(dir, relPath));
225
+ const keyword = match.startsWith("import") ? "import" : "from";
226
+ return `${keyword} ${JSON.stringify(absPath)}`;
227
+ });
228
+ }
229
+
230
+ /**
231
+ * Rewrites all remaining bare specifiers in the transpiled JS to absolute
232
+ * on-disk paths resolved from `dir` (the page file's directory).
233
+ *
234
+ * Uses `Bun.Transpiler.scan()` on the original source to get the authoritative
235
+ * list of *actual* import specifiers (parsing correctly handles template
236
+ * literals, comments, etc.). For each bare specifier that is not already
237
+ * handled by `rewriteSingletonImports`, it calls `Bun.resolveSync` and
238
+ * replaces **every** import/re-export occurrence of the quoted specifier using
239
+ * a context-aware regex with the `g` flag — mirroring the approach used by
240
+ * `rewriteSingletonImports`. This correctly handles modules that both import
241
+ * and re-export from the same package without leaving any bare specifier
242
+ * behind. String literals that happen to contain the same text (inside
243
+ * template literals, JSX props, etc.) are not touched because the regex
244
+ * requires a preceding `from` or `import` keyword.
245
+ *
246
+ * @internal exported for testing
247
+ */
248
+ export function rewriteBareImports(source: string, transpiled: string, dir: string): string {
249
+ const scanner = new Bun.Transpiler({ loader: "tsx" });
250
+ let { imports } = scanner.scan(source);
251
+ // Deduplicate: scan() may return the same specifier multiple times if it
252
+ // appears in both `import` and `export ... from` positions.
253
+ const seen = new Set<string>();
254
+ imports = imports.filter((imp) => {
255
+ if (seen.has(imp.path)) {
256
+ return false;
257
+ }
258
+ seen.add(imp.path);
259
+ return true;
260
+ });
261
+
262
+ let result = transpiled;
263
+ for (const imp of imports) {
264
+ const spec = imp.path;
265
+ // Skip relative paths (already rewritten by rewriteRelativeImports before transpilation)
266
+ // and already-absolute paths.
267
+ if (spec.startsWith(".") || spec.startsWith("/") || spec.startsWith("file:")) {
268
+ continue;
269
+ }
270
+ // Skip React singletons — already handled by rewriteSingletonImports.
271
+ if (SINGLETON_PATHS.has(spec)) {
272
+ continue;
273
+ }
274
+
275
+ let resolved: string;
276
+ try {
277
+ resolved = toImportSpecifier(Bun.resolveSync(spec, dir));
278
+ } catch {
279
+ // Not resolvable from the file's directory — leave as a bare specifier
280
+ // so Bun falls back to CWD-relative resolution (adequate for most cases).
281
+ continue;
282
+ }
283
+
284
+ // Replace ALL import/re-export occurrences of the bare specifier using a
285
+ // context-aware regex with the `g` flag. This correctly handles modules
286
+ // that both import and re-export from the same package. The regex only
287
+ // matches when the specifier is preceded by `from` or `import` so string
288
+ // literals in non-import positions are left untouched.
289
+ // react-doctor-disable-next-line react-doctor/js-hoist-regexp
290
+ const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(spec)}["']`, "g");
291
+ result = result.replace(re, (_, g1: string) => `${g1}${JSON.stringify(resolved)}`);
292
+ }
293
+ return result;
294
+ }
295
+
296
+ function getSourceLoader(filePath: string): SourceLoader | null {
297
+ if (filePath.endsWith(".tsx")) {
298
+ return "tsx";
299
+ }
300
+ if (filePath.endsWith(".ts")) {
301
+ return "ts";
302
+ }
303
+ if (filePath.endsWith(".jsx")) {
304
+ return "jsx";
305
+ }
306
+ if (filePath.endsWith(".js")) {
307
+ return "js";
308
+ }
309
+ return null;
310
+ }
311
+
312
+ function shouldSkipWorkspaceTransform(filePath: string): boolean {
313
+ const normalized = filePath.replace(/\\/g, "/");
314
+ return normalized.includes("/.furin/");
315
+ }
316
+
317
+ function transformDevSource(
318
+ raw: string,
319
+ filePath: string,
320
+ options: { rewriteBareImports: boolean; rewriteRelativeImports: boolean }
321
+ ): string {
322
+ const loader = getSourceLoader(filePath);
323
+ if (!loader) {
324
+ throw new Error(`[furin] Unsupported source loader for ${filePath}`);
325
+ }
326
+
327
+ const dir = dirname(filePath);
328
+ const sourceForTranspile = options.rewriteRelativeImports
329
+ ? rewriteRelativeImports(raw, dir)
330
+ : raw;
331
+ const transpiler = new Bun.Transpiler({ loader });
332
+ const transpiled = transpiler.transformSync(sourceForTranspile, loader);
333
+
334
+ let result = transpiled;
335
+ if (options.rewriteBareImports) {
336
+ result = rewriteBareImports(raw, result, dir);
337
+ }
338
+
339
+ result = rewriteSingletonImports(result);
340
+ return injectJsxHelperImports(result);
341
+ }
342
+
343
+ export function registerDevPagePlugin(): void {
344
+ if (_pluginRegistered) {
345
+ return;
346
+ }
347
+ _pluginRegistered = true;
348
+ Bun.plugin({
349
+ name: "furin-dev-page-loader",
350
+ setup(build) {
351
+ /**
352
+ * Strip `?furin-server` but keep `?t=<ms>` in the resolved path so
353
+ * each request gets a unique module identity, bypassing Bun's cache.
354
+ */
355
+ build.onResolve({ filter: FURIN_SERVER_FILTER }, (args) => {
356
+ const tMatch = T_PARAM_RE.exec(args.path);
357
+ const filePath = args.path.replace(STRIP_FURIN_SERVER_RE, "");
358
+ const resolvedPath = tMatch ? `${filePath}?t=${tMatch[1]}` : filePath;
359
+ return { path: resolvedPath, namespace: "furin-dev-page" };
360
+ });
361
+
362
+ /**
363
+ * Workspace source files (root.tsx, _route.tsx, local components, core
364
+ * packages, etc.) still load through Bun's normal file namespace in dev.
365
+ *
366
+ * After bun --hot re-evaluates part of that graph, those modules can
367
+ * re-import React through a different logical path than react-dom/server,
368
+ * which recreates the classic "dispatcher is null" invalid hook crash.
369
+ *
370
+ * Pre-transpile those files and rewrite only the React singleton imports
371
+ * so every SSR module observes the exact same React instance, while still
372
+ * keeping the files in Bun's watched graph for root.tsx HMR.
373
+ */
374
+ build.onLoad({ filter: WORKSPACE_SOURCE_FILTER }, async (args) => {
375
+ const raw = await Bun.file(args.path).text();
376
+ const loader = getSourceLoader(args.path);
377
+ if (!loader) {
378
+ throw new Error(`[furin] Unsupported source loader for ${args.path}`);
379
+ }
380
+
381
+ // Every re-evaluation of a workspace source in dev is either the
382
+ // initial load (cache empty → no-op) or a post-edit HMR re-read.
383
+ // Both are correct moments to drop dependent dev loader cache
384
+ // entries — they will be re-populated on the next request.
385
+ invalidateDevLoaderCacheBySource(args.path);
386
+
387
+ if (shouldSkipWorkspaceTransform(args.path)) {
388
+ return {
389
+ contents: raw,
390
+ loader,
391
+ };
392
+ }
393
+
394
+ const contents = transformDevSource(raw, args.path, {
395
+ rewriteBareImports: false,
396
+ rewriteRelativeImports: false,
397
+ });
398
+
399
+ return {
400
+ contents,
401
+ loader: "js",
402
+ };
403
+ });
404
+
405
+ /**
406
+ * Read the page file fresh from disk. The `?t=...` suffix guarantees
407
+ * this handler is called on every request; strip it before file I/O.
408
+ *
409
+ * ## Why we pre-transpile with Bun.Transpiler
410
+ *
411
+ * Bun's runtime plugin system (used by `bun --hot`) does NOT route
412
+ * sub-imports from virtual-namespace modules through `onResolve` hooks —
413
+ * the `namespace` filter on `onResolve` only works in the bundler context
414
+ * (`Bun.build()`), not in the runtime module loader. This means two
415
+ * classes of specifiers inside a `furin-dev-page` module cannot be
416
+ * intercepted after the fact:
417
+ *
418
+ * 1. **Relative imports** (`./root`, `../utils`) — no real directory
419
+ * context in the virtual namespace → Bun fails to resolve them.
420
+ * 2. **Auto-injected JSX runtime** — `import { jsx } from
421
+ * "react/jsx-dev-runtime"` added by Bun's TSX transpiler AFTER
422
+ * `onLoad` returns → cannot be rewritten in the source text.
423
+ *
424
+ * Solution: pre-transpile the source with `Bun.Transpiler` ourselves,
425
+ * then rewrite all specifiers in the resulting JS text before returning
426
+ * it with `loader: "js"` (which Bun loads as-is, with no further
427
+ * transpilation or automatic import injection):
428
+ *
429
+ * • `rewriteRelativeImports` → converts `./root` to `/abs/path/root`
430
+ * • `rewriteBareImports` → resolves ALL bare specifiers (including
431
+ * `@teyik0/furin/link`, `shiki`, etc.) to canonical absolute paths
432
+ * from the page file's directory, preventing "two React copies" after
433
+ * bun --hot re-evaluation.
434
+ * • `rewriteSingletonImports` → belt-and-suspenders for react singletons
435
+ * (covered by rewriteBareImports but kept for safety).
436
+ * • `injectJsxHelperImports` → adds the JSX helper imports that
437
+ * `Bun.Transpiler` emits as free variables without corresponding imports.
438
+ */
439
+ build.onLoad({ namespace: "furin-dev-page", filter: ANY_FILTER }, async (args) => {
440
+ const filePath = args.path.replace(STRIP_T_PARAM_RE, "");
441
+ const raw = await Bun.file(filePath).text();
442
+ const contents = transformDevSource(raw, filePath, {
443
+ rewriteBareImports: true,
444
+ rewriteRelativeImports: true,
445
+ });
446
+
447
+ return {
448
+ contents,
449
+ loader: "js", // Already fully transpiled — skip Bun's own TSX step.
450
+ };
451
+ });
452
+ },
453
+ });
454
+ }