Skip to content

Commit cd1aa16

Browse files
committed
feat: migrate OG generation to takumi-js v2
Drop the @takumi-rs/* v1 packages for takumi-js 2.0.0-beta.10. The v2 package picks its backend from `#backend` import conditions, so workerd resolves to wasm automatically — removing the manual vite plugin, alias, and optimizeDeps plumbing that forced the wasm runtime. Rename `persistentImages` to `images` per the v2 ImageResponse API. Claude-Session: https://claude.ai/code/session_01MvKWysun1A8RCvfuvqyYiJ
1 parent 21d585f commit cd1aa16

4 files changed

Lines changed: 29 additions & 167 deletions

File tree

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@
5353
"@shopify/hydrogen-react": "^2026.4.0",
5454
"@tailwindcss/typography": "^0.5.19",
5555
"@tailwindcss/vite": "^4.2.2",
56-
"@takumi-rs/core": "^1.1.2",
57-
"@takumi-rs/helpers": "^1.1.2",
58-
"@takumi-rs/image-response": "^1.1.2",
59-
"@takumi-rs/wasm": "1.3.0",
6056
"@tanstack/ai": "^0.20.1",
6157
"@tanstack/ai-anthropic": "^0.10.1",
6258
"@tanstack/ai-client": "^0.11.3",
@@ -108,6 +104,7 @@
108104
"resend": "^6.10.0",
109105
"streamdown": "^2.5.0",
110106
"tailwind-merge": "^3.5.0",
107+
"takumi-js": "^2.0.0-beta.10",
111108
"tar-stream": "^3.1.8",
112109
"three": "^0.183.2",
113110
"troika-three-text": "^0.52.4",

pnpm-lock.yaml

Lines changed: 26 additions & 126 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server/og/generate.server.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
ImageResponse,
3-
type ImageResponseOptions,
4-
} from '@takumi-rs/image-response'
1+
import { ImageResponse, type ImageResponseOptions } from 'takumi-js/response'
52
import { findLibrary } from '~/libraries'
63
import type { LibraryId } from '~/libraries'
74
import { loadOgAssets as loadNodeOgAssets } from './assets.server'
@@ -74,7 +71,7 @@ export async function generateOgImageResponse(
7471
style: 'normal',
7572
},
7673
],
77-
persistentImages: [{ src: ISLAND_KEY, data: assets.islandPng }],
74+
images: [{ src: ISLAND_KEY, data: assets.islandPng }],
7875
...init,
7976
}
8077

vite.config.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { sentryTanstackStart } from '@sentry/tanstackstart-react/vite'
22
import { defineConfig } from 'vite'
3-
import type { PluginOption } from 'vite'
43
import { redact } from '@tanstack/redact/vite'
54
import contentCollections from '@content-collections/vite'
65
import { devtools as tanstackDevtools } from '@tanstack/devtools-vite'
@@ -10,16 +9,10 @@ import { cloudflare } from '@cloudflare/vite-plugin'
109
import { analyzer } from 'vite-bundle-analyzer'
1110
import viteReact from '@vitejs/plugin-react'
1211
import fs from 'node:fs'
13-
import { createRequire } from 'node:module'
1412
import os from 'node:os'
1513
import path from 'node:path'
1614

17-
const nodeRequire = createRequire(import.meta.url)
1815
const isDev = process.env.NODE_ENV !== 'production'
19-
const takumiWasmRuntimePath = path.join(
20-
path.dirname(path.dirname(nodeRequire.resolve('@takumi-rs/wasm/no-bundler'))),
21-
'bundlers/workerd.js',
22-
)
2316
const shouldUseRedact = process.env.DISABLE_REDACT !== 'true'
2417
const localRedactPackageRoot = process.env.LOCAL_REDACT_PACKAGE_ROOT
2518
const shouldUseSentryPlugin =
@@ -37,21 +30,6 @@ const envDir =
3730
? defaultCheckoutEnvDir
3831
: __dirname
3932

40-
function edgeTakumiWasmImport(): PluginOption {
41-
return {
42-
name: 'tanstack-edge-takumi-wasm-import',
43-
enforce: 'pre',
44-
transform(code, id) {
45-
if (!id.includes('/node_modules/takumi-js/dist/render-')) return
46-
47-
return code.replace(
48-
/import\(\s*\/\*\s*@vite-ignore\s*\*\/\s*['"]@takumi-rs\/wasm['"]\s*\)/g,
49-
'import("@takumi-rs/wasm/no-bundler")',
50-
)
51-
},
52-
}
53-
}
54-
5533
// Runtime-specific `react-dom/server` variants aren't in @tanstack/redact/vite's
5634
// default alias map. Funnel them all to `@tanstack/redact/server` at the
5735
// top-level resolve so Workers get a single server implementation.
@@ -122,10 +100,6 @@ export default defineConfig({
122100
find: 'unicorn-magic',
123101
replacement: 'unicorn-magic/node',
124102
},
125-
{
126-
find: '@takumi-rs/wasm/auto',
127-
replacement: takumiWasmRuntimePath,
128-
},
129103
...(shouldUseRedact
130104
? [
131105
useSyncExternalStoreShimIndexAlias,
@@ -181,11 +155,6 @@ export default defineConfig({
181155
// CTA packages use execa which has a broken unicorn-magic dependency
182156
'@tanstack/create',
183157
'discord-interactions',
184-
// OG image generation: takumi ships a native .node binary
185-
'@takumi-rs/core',
186-
'@takumi-rs/image-response',
187-
'@takumi-rs/helpers',
188-
'takumi-js',
189158
// Don't pre-bundle CLI so we always get fresh changes during dev
190159
...(isDev ? ['@tanstack/cli'] : []),
191160
// Lucide can resolve differently across Vite environments when combined
@@ -249,7 +218,6 @@ export default defineConfig({
249218
},
250219
},
251220
plugins: [
252-
edgeTakumiWasmImport(),
253221
cloudflare({
254222
viteEnvironment: { name: 'ssr' },
255223
}),

0 commit comments

Comments
 (0)