@@ -33,8 +33,10 @@ import type { FunctionOptions, SplittedFunctionOptions } from "@opennextjs/aws/t
33
33
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js" ;
34
34
import type { Plugin } from "esbuild" ;
35
35
36
+ import { getOpenNextConfig } from "../../../api/config.js" ;
36
37
import { patchResRevalidate } from "../patches/plugins/res-revalidate.js" ;
37
38
import { normalizePath } from "../utils/index.js" ;
39
+ import { copyWorkerdPackages } from "../utils/workerd.js" ;
38
40
39
41
interface CodeCustomization {
40
42
// These patches are meant to apply on user and next generated code
@@ -180,14 +182,20 @@ async function generateBundle(
180
182
buildHelper . copyEnvFile ( appBuildOutputPath , packagePath , outputPath ) ;
181
183
182
184
// Copy all necessary traced files
183
- const { tracedFiles, manifests } = await copyTracedFiles ( {
185
+ const { tracedFiles, manifests, nodePackages } = await copyTracedFiles ( {
184
186
buildOutputPath : appBuildOutputPath ,
185
187
packagePath,
186
188
outputDir : outputPath ,
187
189
routes : fnOptions . routes ?? [ "app/page.tsx" ] ,
188
190
bundledNextServer : isBundled ,
189
191
} ) ;
190
192
193
+ if ( getOpenNextConfig ( options ) . cloudflare ?. useWorkerdCondition !== false ) {
194
+ // Next does not trace the "workerd" build condition
195
+ // So we need to copy the whole packages using the condition
196
+ await copyWorkerdPackages ( options , nodePackages ) ;
197
+ }
198
+
191
199
const additionalCodePatches = codeCustomization ?. additionalCodePatches ?? [ ] ;
192
200
193
201
await applyCodePatches ( options , tracedFiles , manifests , [
0 commit comments