@@ -18,14 +18,14 @@ import {
18
18
export interface IPluginSettings {
19
19
nextDir : string ;
20
20
edgeFunctionHandlerPath ?: string ;
21
- middlewareInfo : MiddlewareInfo ;
21
+ middlewareInfo ? : MiddlewareInfo ;
22
22
isInCloudfare ?: boolean ;
23
23
}
24
24
25
25
/**
26
26
* @param opts.nextDir - The path to the .next directory
27
27
* @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
29
29
* @returns
30
30
*/
31
31
export function openNextEdgePlugins ( {
@@ -34,17 +34,19 @@ export function openNextEdgePlugins({
34
34
middlewareInfo,
35
35
isInCloudfare,
36
36
} : 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
+
48
50
return {
49
51
name : "opennext-edge" ,
50
52
setup ( build ) {
@@ -134,7 +136,7 @@ if(!globalThis.Crypto) {
134
136
globalThis.Crypto = webcrypto.Crypto
135
137
}
136
138
// We also need to polyfill URLPattern
137
- if (!globalThis.URLPattern) {
139
+ if (!globalThis.URLPattern) {
138
140
await import("urlpattern-polyfill");
139
141
}
140
142
`
@@ -146,8 +148,8 @@ ${wasmFiles
146
148
: `const ${ file . name } = readFileSync(path.join(__dirname,'/wasm/${ file . name } .wasm'));` ,
147
149
)
148
150
. join ( "\n" ) }
149
- ${ entryFiles ? .map ( ( file ) => `require("${ file } ");` ) . join ( "\n" ) }
150
- ${ contents }
151
+ ${ entryFiles . map ( ( file ) => `require("${ file } ");` ) . join ( "\n" ) }
152
+ ${ contents }
151
153
` ;
152
154
return {
153
155
contents,
@@ -166,18 +168,18 @@ ${contents}
166
168
167
169
const contents = `
168
170
import path from "path";
169
-
171
+
170
172
import { debug } from "../logger";
171
-
173
+
172
174
if(!globalThis.__dirname) {
173
175
globalThis.__dirname = ""
174
176
}
175
-
177
+
176
178
export const NEXT_DIR = path.join(__dirname, ".next");
177
179
export const OPEN_NEXT_DIR = path.join(__dirname, ".open-next");
178
-
180
+
179
181
debug({ NEXT_DIR, OPEN_NEXT_DIR });
180
-
182
+
181
183
export const NextConfig = ${ JSON . stringify ( NextConfig ) } ;
182
184
export const BuildId = ${ JSON . stringify ( BuildId ) } ;
183
185
export const HtmlPages = ${ JSON . stringify ( HtmlPages ) } ;
@@ -188,7 +190,7 @@ ${contents}
188
190
export const MiddlewareManifest = ${ JSON . stringify ( MiddlewareManifest ) } ;
189
191
190
192
process.env.NEXT_BUILD_ID = BuildId;
191
-
193
+
192
194
` ;
193
195
return {
194
196
contents,
0 commit comments