@@ -3,6 +3,7 @@ import path from "node:path";
33
44import type { FunctionOptions , SplittedFunctionOptions } from "types/open-next" ;
55
6+ import { loadMiddlewareManifest } from "config/util.js" ;
67import type { Plugin } from "esbuild" ;
78import logger from "../logger.js" ;
89import { minifyAll } from "../minimize-js.js" ;
@@ -135,12 +136,14 @@ async function generateBundle(
135136 // `.next/standalone/package/path` (ie. `.next`, `server.js`).
136137 // We need to output the handler file inside the package path.
137138 const packagePath = buildHelper . getPackagePath ( options ) ;
138- fs . mkdirSync ( path . join ( outputPath , packagePath ) , { recursive : true } ) ;
139+ const outPackagePath = path . join ( outputPath , packagePath ) ;
140+
141+ fs . mkdirSync ( outPackagePath , { recursive : true } ) ;
139142
140143 const ext = fnOptions . runtime === "deno" ? "mjs" : "cjs" ;
141144 fs . copyFileSync (
142145 path . join ( options . buildDir , `cache.${ ext } ` ) ,
143- path . join ( outputPath , packagePath , "cache.cjs" ) ,
146+ path . join ( outPackagePath , "cache.cjs" ) ,
144147 ) ;
145148
146149 if ( fnOptions . runtime === "deno" ) {
@@ -150,7 +153,7 @@ async function generateBundle(
150153 // Bundle next server if necessary
151154 const isBundled = fnOptions . experimentalBundledNextServer ?? false ;
152155 if ( isBundled ) {
153- await bundleNextServer ( path . join ( outputPath , packagePath ) , appPath , {
156+ await bundleNextServer ( outPackagePath , appPath , {
154157 minify : options . minify ,
155158 } ) ;
156159 }
@@ -159,15 +162,26 @@ async function generateBundle(
159162 if ( ! config . middleware ?. external ) {
160163 fs . copyFileSync (
161164 path . join ( options . buildDir , "middleware.mjs" ) ,
162- path . join ( outputPath , packagePath , "middleware.mjs" ) ,
165+ path . join ( outPackagePath , "middleware.mjs" ) ,
166+ ) ;
167+
168+ const middlewareManifest = loadMiddlewareManifest (
169+ path . join ( options . appBuildOutputPath , ".next" ) ,
163170 ) ;
171+ const wasmFiles = middlewareManifest . middleware [ "/" ] ?. wasm ?? [ ] ;
172+ if ( wasmFiles . length > 0 ) {
173+ fs . mkdirSync ( path . join ( outPackagePath , "wasm" ) , { recursive : true } ) ;
174+ for ( const wasmFile of wasmFiles ) {
175+ fs . copyFileSync (
176+ path . join ( options . appBuildOutputPath , ".next" , wasmFile . filePath ) ,
177+ path . join ( outPackagePath , `wasm/${ wasmFile . name } .wasm` ) ,
178+ ) ;
179+ }
180+ }
164181 }
165182
166183 // Copy open-next.config.mjs
167- buildHelper . copyOpenNextConfig (
168- options . buildDir ,
169- path . join ( outputPath , packagePath ) ,
170- ) ;
184+ buildHelper . copyOpenNextConfig ( options . buildDir , outPackagePath ) ;
171185
172186 // Copy env files
173187 buildHelper . copyEnvFile ( appBuildOutputPath , packagePath , outputPath ) ;
0 commit comments