@@ -3,7 +3,7 @@ import { mkdirSync } from "node:fs";
3
3
import fs from "node:fs" ;
4
4
import path from "node:path" ;
5
5
import { build } from "esbuild" ;
6
- import type { MiddlewareInfo , MiddlewareManifest } from "types/next-types" ;
6
+ import type { MiddlewareInfo } from "types/next-types" ;
7
7
import type {
8
8
IncludedConverter ,
9
9
IncludedOriginResolver ,
@@ -13,6 +13,7 @@ import type {
13
13
SplittedFunctionOptions ,
14
14
} from "types/open-next" ;
15
15
16
+ import { loadMiddlewareManifest } from "config/util.js" ;
16
17
import type { OriginResolver } from "types/overrides.js" ;
17
18
import logger from "../../logger.js" ;
18
19
import { openNextEdgePlugins } from "../../plugins/edge.js" ;
@@ -173,23 +174,19 @@ export async function generateEdgeBundle(
173
174
options : BuildOptions ,
174
175
fnOptions : SplittedFunctionOptions ,
175
176
) {
176
- const { appBuildOutputPath, outputDir } = options ;
177
177
logger . info ( `Generating edge bundle for: ${ name } ` ) ;
178
178
179
+ const buildOutputDotNextDir = path . join ( options . appBuildOutputPath , ".next" ) ;
180
+
179
181
// Create output folder
180
- const outputPath = path . join ( outputDir , "server-functions" , name ) ;
181
- fs . mkdirSync ( outputPath , { recursive : true } ) ;
182
+ const outputDir = path . join ( options . outputDir , "server-functions" , name ) ;
183
+ fs . mkdirSync ( outputDir , { recursive : true } ) ;
182
184
183
185
// Copy open-next.config.mjs
184
- copyOpenNextConfig ( options . buildDir , outputPath , true ) ;
186
+ copyOpenNextConfig ( options . buildDir , outputDir , true ) ;
185
187
186
188
// Load middleware manifest
187
- const middlewareManifest = JSON . parse (
188
- fs . readFileSync (
189
- path . join ( appBuildOutputPath , ".next/server/middleware-manifest.json" ) ,
190
- "utf8" ,
191
- ) ,
192
- ) as MiddlewareManifest ;
189
+ const middlewareManifest = loadMiddlewareManifest ( buildOutputDotNextDir ) ;
193
190
194
191
// Find functions
195
192
const functions = Object . values ( middlewareManifest . functions ) . filter ( ( fn ) =>
@@ -203,32 +200,28 @@ export async function generateEdgeBundle(
203
200
204
201
//Copy wasm files
205
202
const wasmFiles = middlewareInfo . wasm ;
206
- mkdirSync ( path . join ( outputPath , "wasm" ) , { recursive : true } ) ;
203
+ mkdirSync ( path . join ( outputDir , "wasm" ) , { recursive : true } ) ;
207
204
for ( const wasmFile of wasmFiles ) {
208
205
fs . copyFileSync (
209
- path . join ( appBuildOutputPath , ".next" , wasmFile . filePath ) ,
210
- path . join ( outputPath , `wasm/${ wasmFile . name } .wasm` ) ,
206
+ path . join ( buildOutputDotNextDir , wasmFile . filePath ) ,
207
+ path . join ( outputDir , `wasm/${ wasmFile . name } .wasm` ) ,
211
208
) ;
212
209
}
213
210
214
211
// Copy assets
215
212
const assets = middlewareInfo . assets ;
216
- mkdirSync ( path . join ( outputPath , "assets" ) , { recursive : true } ) ;
213
+ mkdirSync ( path . join ( outputDir , "assets" ) , { recursive : true } ) ;
217
214
for ( const asset of assets ) {
218
215
fs . copyFileSync (
219
- path . join ( appBuildOutputPath , ".next" , asset . filePath ) ,
220
- path . join ( outputPath , `assets/${ asset . name } ` ) ,
216
+ path . join ( buildOutputDotNextDir , asset . filePath ) ,
217
+ path . join ( outputDir , `assets/${ asset . name } ` ) ,
221
218
) ;
222
219
}
223
220
224
221
await buildEdgeBundle ( {
225
222
middlewareInfo,
226
- entrypoint : path . join (
227
- options . openNextDistDir ,
228
- "adapters" ,
229
- "edge-adapter.js" ,
230
- ) ,
231
- outfile : path . join ( outputPath , "index.mjs" ) ,
223
+ entrypoint : path . join ( options . openNextDistDir , "adapters/edge-adapter.js" ) ,
224
+ outfile : path . join ( outputDir , "index.mjs" ) ,
232
225
options,
233
226
overrides : fnOptions . override ,
234
227
additionalExternals : options . config . edgeExternals ,
0 commit comments