@timber-js/app 0.2.0-alpha.120 → 0.2.0-alpha.122

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 (157) hide show
  1. package/dist/_chunks/{actions-Cw-7NfJJ.js → actions-Dy8vOjFt.js} +6 -6
  2. package/dist/_chunks/actions-Dy8vOjFt.js.map +1 -0
  3. package/dist/_chunks/{build-output-helper-DhxiT18k.js → build-output-helper-DYOWsPjZ.js} +47 -6
  4. package/dist/_chunks/build-output-helper-DYOWsPjZ.js.map +1 -0
  5. package/dist/_chunks/cli-schema-sync-4HcQIziG.js +2 -0
  6. package/dist/_chunks/cli-schema-sync-VcCf1TFY.js +738 -0
  7. package/dist/_chunks/cli-schema-sync-VcCf1TFY.js.map +1 -0
  8. package/dist/_chunks/{codec-registry-V7ARyeLN.js → codec-registry-G9hD5LOq.js} +1 -1
  9. package/dist/_chunks/{codec-registry-V7ARyeLN.js.map → codec-registry-G9hD5LOq.js.map} +1 -1
  10. package/dist/_chunks/{define-zQX6e1tN.js → define-CPVQaWbx.js} +3 -3
  11. package/dist/_chunks/{define-zQX6e1tN.js.map → define-CPVQaWbx.js.map} +1 -1
  12. package/dist/_chunks/{define-8zQ8Vm7x.js → define-jeHDXZGq.js} +3 -3
  13. package/dist/_chunks/{define-8zQ8Vm7x.js.map → define-jeHDXZGq.js.map} +1 -1
  14. package/dist/_chunks/{format-CR6v1pWE.js → format-BjN9HLu9.js} +1 -1
  15. package/dist/_chunks/{format-CR6v1pWE.js.map → format-BjN9HLu9.js.map} +1 -1
  16. package/dist/_chunks/{handler-store-iqnt2ghN.js → handler-store-CcwNX-gk.js} +1 -1
  17. package/dist/_chunks/{handler-store-iqnt2ghN.js.map → handler-store-CcwNX-gk.js.map} +1 -1
  18. package/dist/_chunks/{merge-search-params-CwxJzBLS.js → merge-search-params-az6ZiBeU.js} +1 -1
  19. package/dist/_chunks/{merge-search-params-CwxJzBLS.js.map → merge-search-params-az6ZiBeU.js.map} +1 -1
  20. package/dist/_chunks/{metadata-routes-Cjmvi3rQ.js → metadata-routes-DESG8uk5.js} +32 -19
  21. package/dist/_chunks/metadata-routes-DESG8uk5.js.map +1 -0
  22. package/dist/_chunks/{navigation-root-DKsJ5Di7.js → navigation-root-DoRTeBm5.js} +2 -2
  23. package/dist/_chunks/{navigation-root-DKsJ5Di7.js.map → navigation-root-DoRTeBm5.js.map} +1 -1
  24. package/dist/_chunks/{registry-Dp_hJL4s.js → registry-BI9cgCt7.js} +1 -1
  25. package/dist/_chunks/{registry-Dp_hJL4s.js.map → registry-BI9cgCt7.js.map} +1 -1
  26. package/dist/_chunks/{resolve-schema-23Mc8aLi.js → resolve-schema-cURaYvaD.js} +15 -3
  27. package/dist/_chunks/resolve-schema-cURaYvaD.js.map +1 -0
  28. package/dist/_chunks/{router-ref-sektkr-t.js → router-ref-CpvjBqdu.js} +2 -2
  29. package/dist/_chunks/{router-ref-sektkr-t.js.map → router-ref-CpvjBqdu.js.map} +1 -1
  30. package/dist/_chunks/{schema-bridge-eL5vQDSA.js → schema-bridge-o0SwFtXW.js} +1 -1
  31. package/dist/_chunks/{schema-bridge-eL5vQDSA.js.map → schema-bridge-o0SwFtXW.js.map} +1 -1
  32. package/dist/_chunks/{segment-classify-CnfLLvir.js → segment-classify-BjfuctV2.js} +1 -1
  33. package/dist/_chunks/{segment-classify-CnfLLvir.js.map → segment-classify-BjfuctV2.js.map} +1 -1
  34. package/dist/_chunks/{segment-context-Bg0pFbLT.js → segment-context-EsfQpS--.js} +1 -1
  35. package/dist/_chunks/{segment-context-Bg0pFbLT.js.map → segment-context-EsfQpS--.js.map} +1 -1
  36. package/dist/_chunks/{ssr-data-BO5OvEvg.js → ssr-data-m9-cNEIw.js} +1 -1
  37. package/dist/_chunks/{ssr-data-BO5OvEvg.js.map → ssr-data-m9-cNEIw.js.map} +1 -1
  38. package/dist/_chunks/{stale-reload-BCPRG0Cv.js → stale-reload-BN2kcE06.js} +1 -1
  39. package/dist/_chunks/{stale-reload-BCPRG0Cv.js.map → stale-reload-BN2kcE06.js.map} +1 -1
  40. package/dist/_chunks/{use-query-states-D9SBlAfp.js → use-query-states-C9G6LP0F.js} +2 -2
  41. package/dist/_chunks/{use-query-states-D9SBlAfp.js.map → use-query-states-C9G6LP0F.js.map} +1 -1
  42. package/dist/_chunks/{use-segment-params-CskiK-59.js → use-segment-params-CtIAjqK0.js} +2 -2
  43. package/dist/_chunks/{use-segment-params-CskiK-59.js.map → use-segment-params-CtIAjqK0.js.map} +1 -1
  44. package/dist/_chunks/{validation-Bm3Je-09.js → validation-BMU5MPzP.js} +1 -1
  45. package/dist/_chunks/{validation-Bm3Je-09.js.map → validation-BMU5MPzP.js.map} +1 -1
  46. package/dist/_chunks/{walkers-DgOXkTts.js → walkers-tkw7sDlj.js} +125 -12
  47. package/dist/_chunks/walkers-tkw7sDlj.js.map +1 -0
  48. package/dist/adapters/build-output-helper.d.ts.map +1 -1
  49. package/dist/adapters/cloudflare.js +1 -1
  50. package/dist/adapters/nitro.js +1 -1
  51. package/dist/cache/index.js +1 -1
  52. package/dist/cli-schema-sync.d.ts.map +1 -1
  53. package/dist/cli.js +1 -1
  54. package/dist/client/error-boundary.js +2 -2
  55. package/dist/client/index.js +10 -10
  56. package/dist/client/index.js.map +1 -1
  57. package/dist/client/internal.js +7 -7
  58. package/dist/client/link.d.ts +9 -5
  59. package/dist/client/link.d.ts.map +1 -1
  60. package/dist/codec.d.ts +18 -0
  61. package/dist/codec.d.ts.map +1 -1
  62. package/dist/codec.js +30 -1
  63. package/dist/codec.js.map +1 -1
  64. package/dist/cookies/index.js +3 -3
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +127 -26
  67. package/dist/index.js.map +1 -1
  68. package/dist/params/define-schema.d.ts +32 -4
  69. package/dist/params/define-schema.d.ts.map +1 -1
  70. package/dist/params/index.d.ts +1 -1
  71. package/dist/params/index.d.ts.map +1 -1
  72. package/dist/params/index.js +2 -2
  73. package/dist/params/index.js.map +1 -1
  74. package/dist/params/resolve-schema.d.ts.map +1 -1
  75. package/dist/plugins/build-manifest.d.ts.map +1 -1
  76. package/dist/plugins/cloudflare-wasm.d.ts +18 -0
  77. package/dist/plugins/cloudflare-wasm.d.ts.map +1 -0
  78. package/dist/plugins/dev-server.d.ts.map +1 -1
  79. package/dist/plugins/routing.d.ts.map +1 -1
  80. package/dist/routing/codegen-shared.d.ts +5 -4
  81. package/dist/routing/codegen-shared.d.ts.map +1 -1
  82. package/dist/routing/index.d.ts +2 -0
  83. package/dist/routing/index.d.ts.map +1 -1
  84. package/dist/routing/index.js +4 -4
  85. package/dist/routing/scanner.d.ts.map +1 -1
  86. package/dist/routing/schema-validation.d.ts +35 -0
  87. package/dist/routing/schema-validation.d.ts.map +1 -0
  88. package/dist/search-params/index.js +3 -3
  89. package/dist/segment-params/index.js +1 -1
  90. package/dist/server/actions.d.ts +3 -8
  91. package/dist/server/actions.d.ts.map +1 -1
  92. package/dist/server/build-manifest.d.ts +6 -0
  93. package/dist/server/build-manifest.d.ts.map +1 -1
  94. package/dist/server/index.js +2 -2
  95. package/dist/server/internal.d.ts +1 -1
  96. package/dist/server/internal.d.ts.map +1 -1
  97. package/dist/server/internal.js +15 -6
  98. package/dist/server/internal.js.map +1 -1
  99. package/dist/server/metadata-routes.d.ts +23 -7
  100. package/dist/server/metadata-routes.d.ts.map +1 -1
  101. package/dist/server/pipeline-phases.d.ts.map +1 -1
  102. package/dist/server/request-context.d.ts.map +1 -1
  103. package/dist/server/route-element-builder.d.ts +1 -1
  104. package/dist/server/route-element-builder.d.ts.map +1 -1
  105. package/dist/server/route-matcher.d.ts +4 -2
  106. package/dist/server/route-matcher.d.ts.map +1 -1
  107. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  108. package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
  109. package/dist/server/ssr-entry.d.ts.map +1 -1
  110. package/dist/server/tree-match.d.ts +12 -4
  111. package/dist/server/tree-match.d.ts.map +1 -1
  112. package/dist/server/types.d.ts +2 -2
  113. package/package.json +7 -6
  114. package/src/adapters/build-output-helper.ts +67 -5
  115. package/src/cli-schema-sync.ts +25 -4
  116. package/src/cli.ts +0 -0
  117. package/src/client/browser-entry/index.ts +1 -1
  118. package/src/client/link.tsx +9 -9
  119. package/src/codec.ts +51 -1
  120. package/src/index.ts +2 -0
  121. package/src/params/define-schema.ts +46 -5
  122. package/src/params/index.ts +7 -1
  123. package/src/params/resolve-schema.ts +28 -0
  124. package/src/plugins/build-manifest.ts +57 -5
  125. package/src/plugins/cloudflare-wasm.ts +103 -0
  126. package/src/plugins/dev-server.ts +4 -2
  127. package/src/plugins/routing.ts +31 -34
  128. package/src/routing/codegen-shared.ts +8 -5
  129. package/src/routing/codegen.ts +59 -5
  130. package/src/routing/index.ts +5 -0
  131. package/src/routing/link-codegen.ts +1 -1
  132. package/src/routing/scanner.ts +58 -0
  133. package/src/routing/schema-validation.ts +149 -0
  134. package/src/server/actions.ts +4 -14
  135. package/src/server/build-manifest.ts +7 -0
  136. package/src/server/internal.ts +7 -1
  137. package/src/server/metadata-routes.ts +44 -19
  138. package/src/server/pipeline-phases.ts +8 -0
  139. package/src/server/request-context.ts +0 -4
  140. package/src/server/route-element-builder.ts +57 -11
  141. package/src/server/route-matcher.ts +81 -49
  142. package/src/server/rsc-entry/index.ts +7 -1
  143. package/src/server/rsc-entry/render-route.ts +7 -1
  144. package/src/server/ssr-entry.ts +6 -0
  145. package/src/server/tree-match.ts +23 -11
  146. package/src/server/types.ts +2 -2
  147. package/LICENSE +0 -8
  148. package/dist/_chunks/actions-Cw-7NfJJ.js.map +0 -1
  149. package/dist/_chunks/build-output-helper-DhxiT18k.js.map +0 -1
  150. package/dist/_chunks/cli-schema-sync-XV0I47Gj.js +0 -2
  151. package/dist/_chunks/cli-schema-sync-q2wB0DyJ.js +0 -358
  152. package/dist/_chunks/cli-schema-sync-q2wB0DyJ.js.map +0 -1
  153. package/dist/_chunks/metadata-routes-Cjmvi3rQ.js.map +0 -1
  154. package/dist/_chunks/resolve-schema-23Mc8aLi.js.map +0 -1
  155. package/dist/_chunks/scanner-DmfoB7iK.js +0 -336
  156. package/dist/_chunks/scanner-DmfoB7iK.js.map +0 -1
  157. package/dist/_chunks/walkers-DgOXkTts.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import { n as setViteServer } from "./_chunks/warnings-B30wpfaS.js";
2
+ import { a as isDynamicMetadataExtension, o as isMetadataRouteServePath } from "./_chunks/metadata-routes-DESG8uk5.js";
2
3
  import { h as swallow } from "./_chunks/logger-DDmK5skc.js";
3
- import { t as scanRoutes } from "./_chunks/scanner-DmfoB7iK.js";
4
- import { n as collectInterceptionRewrites, r as generateRouteMap, t as collectLeafRoutes } from "./_chunks/walkers-DgOXkTts.js";
5
- import { a as DEFAULT_BUILD_DIR, c as mergeFileConfig, d as resolveClientJavascript, f as createNoopTimer, l as resolveAppDir, n as findSchemaFile, o as createPluginContext, r as parseExistingSchemaKeys, s as loadTimberConfigFile, t as collectDynamicSegments, u as resolveBuildDir } from "./_chunks/cli-schema-sync-q2wB0DyJ.js";
6
- import { t as formatSize } from "./_chunks/format-CR6v1pWE.js";
7
- import { dirname, extname, join, normalize, resolve } from "node:path";
4
+ import { a as DEFAULT_BUILD_DIR, c as mergeFileConfig, d as resolveClientJavascript, f as createNoopTimer, l as resolveAppDir, o as createPluginContext, p as scanRoutes, s as loadTimberConfigFile, u as resolveBuildDir } from "./_chunks/cli-schema-sync-VcCf1TFY.js";
5
+ import { a as generateRouteMap, i as collectInterceptionRewrites, r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "./_chunks/walkers-tkw7sDlj.js";
6
+ import { t as formatSize } from "./_chunks/format-BjN9HLu9.js";
7
+ import { basename, dirname, extname, join, normalize, resolve } from "node:path";
8
8
  import { createRequire } from "node:module";
9
9
  import react, { reactCompilerPreset } from "@vitejs/plugin-react";
10
10
  import { existsSync, readFileSync } from "node:fs";
11
11
  import { fileURLToPath, pathToFileURL } from "node:url";
12
12
  import { constants, createGzip, gzipSync } from "node:zlib";
13
13
  import { Readable } from "node:stream";
14
- import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
14
+ import { copyFile, mkdir, readFile, stat, writeFile } from "node:fs/promises";
15
15
  import { createHash, randomUUID } from "node:crypto";
16
16
  import { parseAst } from "vite";
17
17
  import http from "node:http";
@@ -1413,7 +1413,7 @@ function createTimberMiddleware(server, projectRoot) {
1413
1413
  next();
1414
1414
  return;
1415
1415
  }
1416
- if (isAssetRequest(url)) {
1416
+ if (isAssetRequest(url) && !isMetadataRouteServePath(url)) {
1417
1417
  next();
1418
1418
  return;
1419
1419
  }
@@ -2280,7 +2280,7 @@ var SEGMENT_PREFIX = "\0$segment:";
2280
2280
  /**
2281
2281
  * File convention names we track for changes that require manifest regeneration.
2282
2282
  */
2283
- var ROUTE_FILE_PATTERNS = /\/(page|layout|middleware|access|route|error|global-error|default|denied|params|schema|\d{3}|[45]xx|not-found|forbidden|unauthorized|sitemap|robots|manifest|favicon|icon|opengraph-image|twitter-image|apple-icon)\./;
2283
+ var ROUTE_FILE_PATTERNS = /\/(page|layout|middleware|access|route|error|global-error|default|denied|params|schema|\d{3}|[45]xx|not-found|forbidden|unauthorized|sitemap|robots|manifest|favicon|icon|opengraph-image|apple-icon)\./;
2284
2284
  /**
2285
2285
  * Create the timber-routing Vite plugin.
2286
2286
  *
@@ -2349,7 +2349,7 @@ function timberRouting(ctx) {
2349
2349
  ctx.timer.end("route-scan");
2350
2350
  dirToRoute = buildDirToRouteMap(ctx.routeTree, ctx.appDir);
2351
2351
  writeCodegen(ctx);
2352
- warnUnregisteredSegments(ctx);
2352
+ warnSchemaValidation(ctx);
2353
2353
  const newConventionWarnings = lintConventions(ctx.routeTree, ctx.appDir).filter((w) => !warnedFiles.has(w.id));
2354
2354
  if (newConventionWarnings.length > 0) {
2355
2355
  for (const w of newConventionWarnings) warnedFiles.add(w.id);
@@ -2443,22 +2443,32 @@ function timberRouting(ctx) {
2443
2443
  * When the route tree changes, any environment that has imported the manifest
2444
2444
  * needs to be invalidated so the next request/transform picks up the new tree.
2445
2445
  */
2446
- /** Set of segments we've already warned about — avoid repeating on every rescan. */
2447
- var _warnedSegments = /* @__PURE__ */ new Set();
2446
+ /** Set of warning keys we've already emitted — avoid repeating on every rescan. */
2447
+ var _warnedKeys = /* @__PURE__ */ new Set();
2448
2448
  /**
2449
- * Warn about dynamic segments not registered in app/schema.ts.
2450
- * Only fires when a schema file exists. Logs once per segment per session.
2449
+ * Validate schema keys against the filesystem route tree.
2450
+ * Warns on stale keys, bracket form mismatches, and missing keys.
2451
+ * Uses the already-scanned route tree instead of re-scanning.
2451
2452
  */
2452
- function warnUnregisteredSegments(ctx) {
2453
- const schemaPath = findSchemaFile(ctx.appDir);
2454
- if (!schemaPath) return;
2455
- const filesystemSegments = collectDynamicSegments(ctx.appDir);
2456
- if (filesystemSegments.length === 0) return;
2457
- const existingKeys = parseExistingSchemaKeys(readFileSync(schemaPath, "utf-8"));
2458
- const missing = filesystemSegments.filter((seg) => !existingKeys.includes(seg) && !_warnedSegments.has(seg));
2459
- if (missing.length === 0) return;
2460
- for (const seg of missing) _warnedSegments.add(seg);
2461
- console.warn(`[timber] New segment${missing.length > 1 ? "s" : ""} not in schema: ${missing.join(", ")}\n Run: timber schema sync`);
2453
+ function warnSchemaValidation(ctx) {
2454
+ if (!ctx.routeTree) return;
2455
+ const warnings = validateSchemaAgainstRoutes(ctx.routeTree, ctx.appDir);
2456
+ for (const w of warnings) {
2457
+ const warnKey = `${w.type}:${w.key}`;
2458
+ if (_warnedKeys.has(warnKey)) continue;
2459
+ _warnedKeys.add(warnKey);
2460
+ switch (w.type) {
2461
+ case "stale-key":
2462
+ console.warn(`[timber] ${w.message}`);
2463
+ break;
2464
+ case "bracket-mismatch":
2465
+ console.warn(`[timber] ${w.message}`);
2466
+ break;
2467
+ case "missing-key":
2468
+ console.warn(`[timber] ${w.message}`);
2469
+ break;
2470
+ }
2471
+ }
2462
2472
  }
2463
2473
  function invalidateManifest(server) {
2464
2474
  for (const envName of Object.keys(server.environments)) {
@@ -5693,7 +5703,8 @@ function buildManifestFromBundle(bundle, base, root) {
5693
5703
  css,
5694
5704
  js,
5695
5705
  modulepreload,
5696
- fonts: {}
5706
+ fonts: {},
5707
+ metadataRouteHashes: {}
5697
5708
  };
5698
5709
  }
5699
5710
  /**
@@ -5715,6 +5726,27 @@ function collectTransitiveBundleDeps(chunk, chunksByFileName, base) {
5715
5726
  return result;
5716
5727
  }
5717
5728
  /**
5729
+ * Walk the route tree and compute short content hashes for metadata route files
5730
+ * (opengraph-image, icon, apple-icon) used for cache-busting
5731
+ * the auto-linked URLs in <head>.
5732
+ */
5733
+ function computeMetadataRouteHashes(node) {
5734
+ const hashes = {};
5735
+ if (node.metadataRoutes) for (const [baseName, file] of Object.entries(node.metadataRoutes)) if (!isDynamicMetadataExtension(baseName, file.extension)) try {
5736
+ const content = readFileSync(file.filePath);
5737
+ const hash = createHash("sha256").update(content).digest("hex").slice(0, 8);
5738
+ hashes[file.filePath] = hash;
5739
+ } catch {}
5740
+ else try {
5741
+ const content = readFileSync(file.filePath);
5742
+ const hash = createHash("sha256").update(content).digest("hex").slice(0, 8);
5743
+ hashes[file.filePath] = hash;
5744
+ } catch {}
5745
+ for (const child of node.children) Object.assign(hashes, computeMetadataRouteHashes(child));
5746
+ for (const slot of Object.values(node.slots)) Object.assign(hashes, computeMetadataRouteHashes(slot));
5747
+ return hashes;
5748
+ }
5749
+ /**
5718
5750
  * Create the timber-build-manifest Vite plugin.
5719
5751
  *
5720
5752
  * Hooks: configResolved, resolveId, load, generateBundle (client env only)
@@ -5741,7 +5773,7 @@ function timberBuildManifest(ctx) {
5741
5773
  "// Auto-generated build manifest — do not edit.",
5742
5774
  "// Dev mode: empty manifest (Vite HMR handles CSS/JS).",
5743
5775
  "",
5744
- "const manifest = { css: {}, js: {}, modulepreload: {}, fonts: {} };",
5776
+ "const manifest = { css: {}, js: {}, modulepreload: {}, fonts: {}, metadataRouteHashes: {} };",
5745
5777
  "",
5746
5778
  "export default manifest;"
5747
5779
  ].join("\n");
@@ -5749,7 +5781,7 @@ function timberBuildManifest(ctx) {
5749
5781
  "// Auto-generated build manifest — do not edit.",
5750
5782
  "// Production: reads manifest from globalThis (set by _timber-manifest-init.js).",
5751
5783
  "",
5752
- "const manifest = globalThis.__TIMBER_BUILD_MANIFEST__ ?? { css: {}, js: {}, modulepreload: {}, fonts: {} };",
5784
+ "const manifest = globalThis.__TIMBER_BUILD_MANIFEST__ ?? { css: {}, js: {}, modulepreload: {}, fonts: {}, metadataRouteHashes: {} };",
5753
5785
  "",
5754
5786
  "export default manifest;"
5755
5787
  ].join("\n");
@@ -5758,6 +5790,7 @@ function timberBuildManifest(ctx) {
5758
5790
  if (isDev) return;
5759
5791
  if (this.environment?.name === "client") {
5760
5792
  ctx.buildManifest = buildManifestFromBundle(bundle, resolvedBase, ctx.root);
5793
+ if (ctx.routeTree) ctx.buildManifest.metadataRouteHashes = computeMetadataRouteHashes(ctx.routeTree.root);
5761
5794
  if (ctx.clientJavascript.disabled) {
5762
5795
  ctx.buildManifest.js = {};
5763
5796
  ctx.buildManifest.modulepreload = {};
@@ -6289,6 +6322,73 @@ function timberServerBundle() {
6289
6322
  ];
6290
6323
  }
6291
6324
  //#endregion
6325
+ //#region src/plugins/cloudflare-wasm.ts
6326
+ /**
6327
+ * timber-cloudflare-wasm — Handle WASM modules for Cloudflare Workers builds.
6328
+ *
6329
+ * Cloudflare Workers can natively import `.wasm` files as compiled
6330
+ * WebAssembly.Module. But Rolldown can't load `.wasm` files at build time.
6331
+ *
6332
+ * This plugin bridges the gap:
6333
+ * 1. Adds the `workerd` resolve condition so libraries like @takumi-rs/wasm
6334
+ * resolve to their Cloudflare-native entry (bare `.wasm` import)
6335
+ * 2. Externalizes `.wasm` imports so Rolldown skips them
6336
+ * 3. Copies the WASM files to the build output so wrangler can find them
6337
+ *
6338
+ * Only active for Cloudflare adapter production builds.
6339
+ */
6340
+ function isCloudflareAdapter(ctx) {
6341
+ return ctx.config.adapter?.name === "cloudflare";
6342
+ }
6343
+ function timberCloudflareWasm(ctx) {
6344
+ const wasmFiles = /* @__PURE__ */ new Map();
6345
+ return [{
6346
+ name: "timber-cloudflare-wasm",
6347
+ configResolved(resolved) {
6348
+ if (resolved.command !== "build") return;
6349
+ if (!isCloudflareAdapter(ctx)) return;
6350
+ for (const envName of ["rsc", "ssr"]) {
6351
+ const env = resolved.environments[envName];
6352
+ if (!env) continue;
6353
+ const conditions = env.resolve.conditions;
6354
+ if (!conditions.includes("workerd")) conditions.unshift("workerd");
6355
+ }
6356
+ },
6357
+ resolveId: {
6358
+ order: "pre",
6359
+ async handler(source, importer) {
6360
+ if (!source.endsWith(".wasm")) return;
6361
+ let absolutePath;
6362
+ if (source.startsWith(".") && importer) absolutePath = resolve(dirname(importer), source);
6363
+ else return;
6364
+ const filename = basename(absolutePath);
6365
+ wasmFiles.set(filename, absolutePath);
6366
+ return {
6367
+ id: "./" + filename,
6368
+ external: true
6369
+ };
6370
+ }
6371
+ },
6372
+ async writeBundle(options, bundle) {
6373
+ if (wasmFiles.size === 0) return;
6374
+ const outDir = options.dir;
6375
+ if (!outDir) return;
6376
+ const targetDirs = /* @__PURE__ */ new Set();
6377
+ for (const chunk of Object.values(bundle)) {
6378
+ if (chunk.type !== "chunk") continue;
6379
+ for (const filename of wasmFiles.keys()) if (chunk.code.includes(filename)) targetDirs.add(dirname(resolve(outDir, chunk.fileName)));
6380
+ }
6381
+ if (targetDirs.size === 0) return;
6382
+ const copies = [];
6383
+ for (const dir of targetDirs) {
6384
+ await mkdir(dir, { recursive: true });
6385
+ for (const [filename, absolutePath] of wasmFiles) copies.push(copyFile(absolutePath, resolve(dir, filename)));
6386
+ }
6387
+ await Promise.all(copies);
6388
+ }
6389
+ }];
6390
+ }
6391
+ //#endregion
6292
6392
  //#region src/plugins/adapter-build.ts
6293
6393
  function timberAdapterBuild(ctx) {
6294
6394
  return {
@@ -7130,6 +7230,7 @@ function timber(config) {
7130
7230
  timberMdx(ctx),
7131
7231
  timberContent(ctx),
7132
7232
  timberServerBundle(),
7233
+ timberCloudflareWasm(ctx),
7133
7234
  timberChunks(),
7134
7235
  timberBuildReport(ctx),
7135
7236
  timberAdapterBuild(ctx),