@@ -18,14 +18,14 @@ import {
1818export interface IPluginSettings {
1919 nextDir : string ;
2020 edgeFunctionHandlerPath ?: string ;
21- middlewareInfo : MiddlewareInfo ;
21+ middlewareInfo ? : MiddlewareInfo ;
2222 isInCloudfare ?: boolean ;
2323}
2424
2525/**
2626 * @param opts.nextDir - The path to the .next directory
2727 * @param opts.edgeFunctionHandlerPath - The path to the edgeFunctionHandler.js file that we'll use to bundle the routing
28- * @param opts.entryFiles - The entry files that we'll inject into the edgeFunctionHandler.js file
28+ * @param opts.middlewareInfo - The entry files that we'll inject into the edgeFunctionHandler.js file
2929 * @returns
3030 */
3131export function openNextEdgePlugins ( {
@@ -34,17 +34,19 @@ export function openNextEdgePlugins({
3434 middlewareInfo,
3535 isInCloudfare,
3636} : IPluginSettings ) : Plugin {
37- const entryFiles = middlewareInfo . files . map ( ( file : string ) =>
38- path . join ( nextDir , file ) ,
39- ) ;
40- const routes = [
41- {
42- name : middlewareInfo . name || "/" ,
43- page : middlewareInfo . page ,
44- regex : middlewareInfo . matchers . map ( ( m ) => m . regexp ) ,
45- } ,
46- ] ;
47- const wasmFiles = middlewareInfo . wasm ?? [ ] ;
37+ const entryFiles =
38+ middlewareInfo ?. files . map ( ( file : string ) => path . join ( nextDir , file ) ) ?? [ ] ;
39+ const routes = middlewareInfo
40+ ? [
41+ {
42+ name : middlewareInfo . name || "/" ,
43+ page : middlewareInfo . page ,
44+ regex : middlewareInfo . matchers . map ( ( m ) => m . regexp ) ,
45+ } ,
46+ ]
47+ : [ ] ;
48+ const wasmFiles = middlewareInfo ?. wasm ?? [ ] ;
49+
4850 return {
4951 name : "opennext-edge" ,
5052 setup ( build ) {
@@ -134,7 +136,7 @@ if(!globalThis.Crypto) {
134136 globalThis.Crypto = webcrypto.Crypto
135137}
136138// We also need to polyfill URLPattern
137- if (!globalThis.URLPattern) {
139+ if (!globalThis.URLPattern) {
138140 await import("urlpattern-polyfill");
139141}
140142`
@@ -146,8 +148,8 @@ ${wasmFiles
146148 : `const ${ file . name } = readFileSync(path.join(__dirname,'/wasm/${ file . name } .wasm'));` ,
147149 )
148150 . join ( "\n" ) }
149- ${ entryFiles ? .map ( ( file ) => `require("${ file } ");` ) . join ( "\n" ) }
150- ${ contents }
151+ ${ entryFiles . map ( ( file ) => `require("${ file } ");` ) . join ( "\n" ) }
152+ ${ contents }
151153 ` ;
152154 return {
153155 contents,
@@ -166,18 +168,18 @@ ${contents}
166168
167169 const contents = `
168170 import path from "path";
169-
171+
170172 import { debug } from "../logger";
171-
173+
172174 if(!globalThis.__dirname) {
173175 globalThis.__dirname = ""
174176 }
175-
177+
176178 export const NEXT_DIR = path.join(__dirname, ".next");
177179 export const OPEN_NEXT_DIR = path.join(__dirname, ".open-next");
178-
180+
179181 debug({ NEXT_DIR, OPEN_NEXT_DIR });
180-
182+
181183 export const NextConfig = ${ JSON . stringify ( NextConfig ) } ;
182184 export const BuildId = ${ JSON . stringify ( BuildId ) } ;
183185 export const HtmlPages = ${ JSON . stringify ( HtmlPages ) } ;
@@ -188,7 +190,7 @@ ${contents}
188190 export const MiddlewareManifest = ${ JSON . stringify ( MiddlewareManifest ) } ;
189191
190192 process.env.NEXT_BUILD_ID = BuildId;
191-
193+
192194 ` ;
193195 return {
194196 contents,
0 commit comments