From 036e0fc23a71f417620e4afa865e406a78e90151 Mon Sep 17 00:00:00 2001 From: Mason Hall Date: Sat, 4 Apr 2026 04:03:41 -0400 Subject: [PATCH] fix(x402): add tsdown config to build middleware entry point (#48) * fix(x402): add tsdown config to build middleware entry point * adds optimizeDeps.exclude and ssr.optimizeDeps.exclude for @emdash-cms/x402 in the integration's Vite config * fix CI typecheck --------- Co-authored-by: Matt Kane --- packages/x402/src/index.ts | 12 +++++++++++- packages/x402/tsdown.config.ts | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 packages/x402/tsdown.config.ts diff --git a/packages/x402/src/index.ts b/packages/x402/src/index.ts index eaf378e..2605c9e 100644 --- a/packages/x402/src/index.ts +++ b/packages/x402/src/index.ts @@ -49,7 +49,9 @@ export function x402(config: X402Config): AstroIntegration { name: "@emdash-cms/x402", hooks: { "astro:config:setup": ({ addMiddleware, updateConfig }) => { - // Inject the virtual module that provides config to the middleware + // Inject the virtual module that provides config to the middleware. + // The middleware must be excluded from Vite's SSR dependency optimizer + // because esbuild cannot resolve virtual modules — only Vite plugins can. updateConfig({ vite: { plugins: [ @@ -65,6 +67,14 @@ export function x402(config: X402Config): AstroIntegration { }, }, ], + optimizeDeps: { + exclude: ["@emdash-cms/x402"], + }, + ssr: { + optimizeDeps: { + exclude: ["@emdash-cms/x402"], + }, + }, }, }); diff --git a/packages/x402/tsdown.config.ts b/packages/x402/tsdown.config.ts new file mode 100644 index 0000000..174d841 --- /dev/null +++ b/packages/x402/tsdown.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from "tsdown"; + +export default defineConfig({ + entry: ["src/index.ts", "src/middleware.ts"], + format: ["esm"], + dts: true, + clean: true, + inlineOnly: false, + external: ["astro:middleware", "virtual:x402/config"], +});