@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.
- package/dist/_chunks/{actions-Cw-7NfJJ.js → actions-Dy8vOjFt.js} +6 -6
- package/dist/_chunks/actions-Dy8vOjFt.js.map +1 -0
- package/dist/_chunks/{build-output-helper-DhxiT18k.js → build-output-helper-DYOWsPjZ.js} +47 -6
- package/dist/_chunks/build-output-helper-DYOWsPjZ.js.map +1 -0
- package/dist/_chunks/cli-schema-sync-4HcQIziG.js +2 -0
- package/dist/_chunks/cli-schema-sync-VcCf1TFY.js +738 -0
- package/dist/_chunks/cli-schema-sync-VcCf1TFY.js.map +1 -0
- package/dist/_chunks/{codec-registry-V7ARyeLN.js → codec-registry-G9hD5LOq.js} +1 -1
- package/dist/_chunks/{codec-registry-V7ARyeLN.js.map → codec-registry-G9hD5LOq.js.map} +1 -1
- package/dist/_chunks/{define-zQX6e1tN.js → define-CPVQaWbx.js} +3 -3
- package/dist/_chunks/{define-zQX6e1tN.js.map → define-CPVQaWbx.js.map} +1 -1
- package/dist/_chunks/{define-8zQ8Vm7x.js → define-jeHDXZGq.js} +3 -3
- package/dist/_chunks/{define-8zQ8Vm7x.js.map → define-jeHDXZGq.js.map} +1 -1
- package/dist/_chunks/{format-CR6v1pWE.js → format-BjN9HLu9.js} +1 -1
- package/dist/_chunks/{format-CR6v1pWE.js.map → format-BjN9HLu9.js.map} +1 -1
- package/dist/_chunks/{handler-store-iqnt2ghN.js → handler-store-CcwNX-gk.js} +1 -1
- package/dist/_chunks/{handler-store-iqnt2ghN.js.map → handler-store-CcwNX-gk.js.map} +1 -1
- package/dist/_chunks/{merge-search-params-CwxJzBLS.js → merge-search-params-az6ZiBeU.js} +1 -1
- package/dist/_chunks/{merge-search-params-CwxJzBLS.js.map → merge-search-params-az6ZiBeU.js.map} +1 -1
- package/dist/_chunks/{metadata-routes-Cjmvi3rQ.js → metadata-routes-DESG8uk5.js} +32 -19
- package/dist/_chunks/metadata-routes-DESG8uk5.js.map +1 -0
- package/dist/_chunks/{navigation-root-DKsJ5Di7.js → navigation-root-DoRTeBm5.js} +2 -2
- package/dist/_chunks/{navigation-root-DKsJ5Di7.js.map → navigation-root-DoRTeBm5.js.map} +1 -1
- package/dist/_chunks/{registry-Dp_hJL4s.js → registry-BI9cgCt7.js} +1 -1
- package/dist/_chunks/{registry-Dp_hJL4s.js.map → registry-BI9cgCt7.js.map} +1 -1
- package/dist/_chunks/{resolve-schema-23Mc8aLi.js → resolve-schema-cURaYvaD.js} +15 -3
- package/dist/_chunks/resolve-schema-cURaYvaD.js.map +1 -0
- package/dist/_chunks/{router-ref-sektkr-t.js → router-ref-CpvjBqdu.js} +2 -2
- package/dist/_chunks/{router-ref-sektkr-t.js.map → router-ref-CpvjBqdu.js.map} +1 -1
- package/dist/_chunks/{schema-bridge-eL5vQDSA.js → schema-bridge-o0SwFtXW.js} +1 -1
- package/dist/_chunks/{schema-bridge-eL5vQDSA.js.map → schema-bridge-o0SwFtXW.js.map} +1 -1
- package/dist/_chunks/{segment-classify-CnfLLvir.js → segment-classify-BjfuctV2.js} +1 -1
- package/dist/_chunks/{segment-classify-CnfLLvir.js.map → segment-classify-BjfuctV2.js.map} +1 -1
- package/dist/_chunks/{segment-context-Bg0pFbLT.js → segment-context-EsfQpS--.js} +1 -1
- package/dist/_chunks/{segment-context-Bg0pFbLT.js.map → segment-context-EsfQpS--.js.map} +1 -1
- package/dist/_chunks/{ssr-data-BO5OvEvg.js → ssr-data-m9-cNEIw.js} +1 -1
- package/dist/_chunks/{ssr-data-BO5OvEvg.js.map → ssr-data-m9-cNEIw.js.map} +1 -1
- package/dist/_chunks/{stale-reload-BCPRG0Cv.js → stale-reload-BN2kcE06.js} +1 -1
- package/dist/_chunks/{stale-reload-BCPRG0Cv.js.map → stale-reload-BN2kcE06.js.map} +1 -1
- package/dist/_chunks/{use-query-states-D9SBlAfp.js → use-query-states-C9G6LP0F.js} +2 -2
- package/dist/_chunks/{use-query-states-D9SBlAfp.js.map → use-query-states-C9G6LP0F.js.map} +1 -1
- package/dist/_chunks/{use-segment-params-CskiK-59.js → use-segment-params-CtIAjqK0.js} +2 -2
- package/dist/_chunks/{use-segment-params-CskiK-59.js.map → use-segment-params-CtIAjqK0.js.map} +1 -1
- package/dist/_chunks/{validation-Bm3Je-09.js → validation-BMU5MPzP.js} +1 -1
- package/dist/_chunks/{validation-Bm3Je-09.js.map → validation-BMU5MPzP.js.map} +1 -1
- package/dist/_chunks/{walkers-DgOXkTts.js → walkers-tkw7sDlj.js} +125 -12
- package/dist/_chunks/walkers-tkw7sDlj.js.map +1 -0
- package/dist/adapters/build-output-helper.d.ts.map +1 -1
- package/dist/adapters/cloudflare.js +1 -1
- package/dist/adapters/nitro.js +1 -1
- package/dist/cache/index.js +1 -1
- package/dist/cli-schema-sync.d.ts.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/client/error-boundary.js +2 -2
- package/dist/client/index.js +10 -10
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal.js +7 -7
- package/dist/client/link.d.ts +9 -5
- package/dist/client/link.d.ts.map +1 -1
- package/dist/codec.d.ts +18 -0
- package/dist/codec.d.ts.map +1 -1
- package/dist/codec.js +30 -1
- package/dist/codec.js.map +1 -1
- package/dist/cookies/index.js +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +127 -26
- package/dist/index.js.map +1 -1
- package/dist/params/define-schema.d.ts +32 -4
- package/dist/params/define-schema.d.ts.map +1 -1
- package/dist/params/index.d.ts +1 -1
- package/dist/params/index.d.ts.map +1 -1
- package/dist/params/index.js +2 -2
- package/dist/params/index.js.map +1 -1
- package/dist/params/resolve-schema.d.ts.map +1 -1
- package/dist/plugins/build-manifest.d.ts.map +1 -1
- package/dist/plugins/cloudflare-wasm.d.ts +18 -0
- package/dist/plugins/cloudflare-wasm.d.ts.map +1 -0
- package/dist/plugins/dev-server.d.ts.map +1 -1
- package/dist/plugins/routing.d.ts.map +1 -1
- package/dist/routing/codegen-shared.d.ts +5 -4
- package/dist/routing/codegen-shared.d.ts.map +1 -1
- package/dist/routing/index.d.ts +2 -0
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +4 -4
- package/dist/routing/scanner.d.ts.map +1 -1
- package/dist/routing/schema-validation.d.ts +35 -0
- package/dist/routing/schema-validation.d.ts.map +1 -0
- package/dist/search-params/index.js +3 -3
- package/dist/segment-params/index.js +1 -1
- package/dist/server/actions.d.ts +3 -8
- package/dist/server/actions.d.ts.map +1 -1
- package/dist/server/build-manifest.d.ts +6 -0
- package/dist/server/build-manifest.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/internal.d.ts +1 -1
- package/dist/server/internal.d.ts.map +1 -1
- package/dist/server/internal.js +15 -6
- package/dist/server/internal.js.map +1 -1
- package/dist/server/metadata-routes.d.ts +23 -7
- package/dist/server/metadata-routes.d.ts.map +1 -1
- package/dist/server/pipeline-phases.d.ts.map +1 -1
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts +1 -1
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/route-matcher.d.ts +4 -2
- package/dist/server/route-matcher.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
- package/dist/server/ssr-entry.d.ts.map +1 -1
- package/dist/server/tree-match.d.ts +12 -4
- package/dist/server/tree-match.d.ts.map +1 -1
- package/dist/server/types.d.ts +2 -2
- package/package.json +7 -6
- package/src/adapters/build-output-helper.ts +67 -5
- package/src/cli-schema-sync.ts +25 -4
- package/src/cli.ts +0 -0
- package/src/client/browser-entry/index.ts +1 -1
- package/src/client/link.tsx +9 -9
- package/src/codec.ts +51 -1
- package/src/index.ts +2 -0
- package/src/params/define-schema.ts +46 -5
- package/src/params/index.ts +7 -1
- package/src/params/resolve-schema.ts +28 -0
- package/src/plugins/build-manifest.ts +57 -5
- package/src/plugins/cloudflare-wasm.ts +103 -0
- package/src/plugins/dev-server.ts +4 -2
- package/src/plugins/routing.ts +31 -34
- package/src/routing/codegen-shared.ts +8 -5
- package/src/routing/codegen.ts +59 -5
- package/src/routing/index.ts +5 -0
- package/src/routing/link-codegen.ts +1 -1
- package/src/routing/scanner.ts +58 -0
- package/src/routing/schema-validation.ts +149 -0
- package/src/server/actions.ts +4 -14
- package/src/server/build-manifest.ts +7 -0
- package/src/server/internal.ts +7 -1
- package/src/server/metadata-routes.ts +44 -19
- package/src/server/pipeline-phases.ts +8 -0
- package/src/server/request-context.ts +0 -4
- package/src/server/route-element-builder.ts +57 -11
- package/src/server/route-matcher.ts +81 -49
- package/src/server/rsc-entry/index.ts +7 -1
- package/src/server/rsc-entry/render-route.ts +7 -1
- package/src/server/ssr-entry.ts +6 -0
- package/src/server/tree-match.ts +23 -11
- package/src/server/types.ts +2 -2
- package/LICENSE +0 -8
- package/dist/_chunks/actions-Cw-7NfJJ.js.map +0 -1
- package/dist/_chunks/build-output-helper-DhxiT18k.js.map +0 -1
- package/dist/_chunks/cli-schema-sync-XV0I47Gj.js +0 -2
- package/dist/_chunks/cli-schema-sync-q2wB0DyJ.js +0 -358
- package/dist/_chunks/cli-schema-sync-q2wB0DyJ.js.map +0 -1
- package/dist/_chunks/metadata-routes-Cjmvi3rQ.js.map +0 -1
- package/dist/_chunks/resolve-schema-23Mc8aLi.js.map +0 -1
- package/dist/_chunks/scanner-DmfoB7iK.js +0 -336
- package/dist/_chunks/scanner-DmfoB7iK.js.map +0 -1
- 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 {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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|
|
|
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
|
-
|
|
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
|
|
2447
|
-
var
|
|
2446
|
+
/** Set of warning keys we've already emitted — avoid repeating on every rescan. */
|
|
2447
|
+
var _warnedKeys = /* @__PURE__ */ new Set();
|
|
2448
2448
|
/**
|
|
2449
|
-
*
|
|
2450
|
-
*
|
|
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
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
const
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
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),
|