@@ -5,10 +5,13 @@ import os from "node:os";
55import path from "node:path" ;
66import url from "node:url" ;
77
8- import { buildSync } from "esbuild" ;
98import { MiddlewareManifest } from "types/next-types.js" ;
109
1110import { isBinaryContentType } from "./adapters/binary.js" ;
11+ import {
12+ compileOpenNextConfigEdge ,
13+ compileOpenNextConfigNode ,
14+ } from "./build/compileConfig.js" ;
1215import { createServerBundle } from "./build/createServerBundle.js" ;
1316import { buildEdgeBundle } from "./build/edge/createEdgeBundle.js" ;
1417import { generateOutput } from "./build/generateOutput.js" ;
@@ -39,15 +42,24 @@ export type PublicFiles = {
3942 files : string [ ] ;
4043} ;
4144
42- export async function build ( openNextConfigPath ?: string ) {
45+ export async function build (
46+ openNextConfigPath ?: string ,
47+ nodeExternals ?: string ,
48+ ) {
4349 showWindowsWarning ( ) ;
4450
4551 // Load open-next.config.ts
4652 const tempDir = initTempDir ( ) ;
47- const configPath = compileOpenNextConfig ( tempDir , openNextConfigPath ) ;
53+ const configPath = compileOpenNextConfigNode (
54+ tempDir ,
55+ openNextConfigPath ,
56+ nodeExternals ,
57+ ) ;
4858 config = ( await import ( configPath ) ) . default as OpenNextConfig ;
4959 validateConfig ( config ) ;
5060
61+ compileOpenNextConfigEdge ( tempDir , config , openNextConfigPath ) ;
62+
5163 const { root : monorepoRoot , packager } = findMonorepoRoot (
5264 path . join ( process . cwd ( ) , config . appPath || "." ) ,
5365 ) ;
@@ -107,40 +119,6 @@ function initTempDir() {
107119 return tempDir ;
108120}
109121
110- function compileOpenNextConfig ( tempDir : string , openNextConfigPath ?: string ) {
111- const sourcePath = path . join (
112- process . cwd ( ) ,
113- openNextConfigPath ?? "open-next.config.ts" ,
114- ) ;
115- const outputPath = path . join ( tempDir , "open-next.config.mjs" ) ;
116-
117- //Check if open-next.config.ts exists
118- if ( ! fs . existsSync ( sourcePath ) ) {
119- //Create a simple open-next.config.mjs file
120- logger . debug ( "Cannot find open-next.config.ts. Using default config." ) ;
121- fs . writeFileSync (
122- outputPath ,
123- [
124- "var config = { default: { } };" ,
125- "var open_next_config_default = config;" ,
126- "export { open_next_config_default as default };" ,
127- ] . join ( "\n" ) ,
128- ) ;
129- } else {
130- buildSync ( {
131- entryPoints : [ sourcePath ] ,
132- outfile : outputPath ,
133- bundle : true ,
134- format : "esm" ,
135- target : [ "node18" ] ,
136- external : [ "node:*" ] ,
137- platform : "neutral" ,
138- } ) ;
139- }
140-
141- return outputPath ;
142- }
143-
144122function checkRunningInsideNextjsApp ( ) {
145123 const { appPath } = options ;
146124 const extension = [ "js" , "cjs" , "mjs" ] . find ( ( ext ) =>
@@ -228,9 +206,22 @@ function initOutputDir() {
228206 path . join ( tempDir , "open-next.config.mjs" ) ,
229207 "utf8" ,
230208 ) ;
209+ let openNextConfigEdge : string | null = null ;
210+ if ( fs . existsSync ( path . join ( tempDir , "open-next.config.edge.mjs" ) ) ) {
211+ openNextConfigEdge = readFileSync (
212+ path . join ( tempDir , "open-next.config.edge.mjs" ) ,
213+ "utf8" ,
214+ ) ;
215+ }
231216 fs . rmSync ( outputDir , { recursive : true , force : true } ) ;
232217 fs . mkdirSync ( tempDir , { recursive : true } ) ;
233218 fs . writeFileSync ( path . join ( tempDir , "open-next.config.mjs" ) , openNextConfig ) ;
219+ if ( openNextConfigEdge ) {
220+ fs . writeFileSync (
221+ path . join ( tempDir , "open-next.config.edge.mjs" ) ,
222+ openNextConfigEdge ,
223+ ) ;
224+ }
234225}
235226
236227async function createWarmerBundle ( config : OpenNextConfig ) {
0 commit comments