@@ -10,6 +10,7 @@ import {
10
10
buildSync ,
11
11
} from "esbuild" ;
12
12
13
+ import logger from "./logger.js" ;
13
14
import { minifyAll } from "./minimize-js.js" ;
14
15
import openNextPlugin from "./plugin.js" ;
15
16
@@ -84,6 +85,7 @@ export async function build(opts: BuildOptions = {}) {
84
85
85
86
// Initialize options
86
87
options = normalizeOptions ( opts , monorepoRoot ) ;
88
+ logger . setLevel ( options . debug ? "debug" : "info" ) ;
87
89
88
90
// Pre-build validation
89
91
checkRunningInsideNextjsApp ( ) ;
@@ -139,7 +141,7 @@ function checkRunningInsideNextjsApp() {
139
141
fs . existsSync ( path . join ( appPath , `next.config.${ ext } ` ) ) ,
140
142
) ;
141
143
if ( ! extension ) {
142
- console . error (
144
+ logger . error (
143
145
"Error: next.config.js not found. Please make sure you are running this command inside a Next.js app." ,
144
146
) ;
145
147
process . exit ( 1 ) ;
@@ -157,7 +159,7 @@ function findMonorepoRoot(appPath: string) {
157
159
158
160
if ( found ) {
159
161
if ( currentPath !== appPath ) {
160
- console . info ( "Monorepo detected at" , currentPath ) ;
162
+ logger . info ( "Monorepo detected at" , currentPath ) ;
161
163
}
162
164
return { root : currentPath , packager : found . packager } ;
163
165
}
@@ -197,7 +199,7 @@ function buildNextjsApp(packager: "npm" | "yarn" | "pnpm") {
197
199
198
200
function printHeader ( header : string ) {
199
201
header = `OpenNext — ${ header } ` ;
200
- console . info (
202
+ logger . info (
201
203
[
202
204
"" ,
203
205
"┌" + "─" . repeat ( header . length + 2 ) + "┐" ,
@@ -226,7 +228,7 @@ function printNextjsVersion() {
226
228
227
229
function printOpenNextVersion ( ) {
228
230
const { openNextVersion } = options ;
229
- console . info ( `OpenNext v${ openNextVersion } ` ) ;
231
+ logger . info ( `OpenNext v${ openNextVersion } ` ) ;
230
232
}
231
233
232
234
function initOutputDir ( ) {
@@ -236,7 +238,7 @@ function initOutputDir() {
236
238
}
237
239
238
240
function createWarmerBundle ( ) {
239
- console . info ( `Bundling warmer function...` ) ;
241
+ logger . info ( `Bundling warmer function...` ) ;
240
242
241
243
const { outputDir } = options ;
242
244
@@ -264,7 +266,7 @@ function createWarmerBundle() {
264
266
}
265
267
266
268
async function minifyServerBundle ( ) {
267
- console . info ( `Minimizing server function...` ) ;
269
+ logger . info ( `Minimizing server function...` ) ;
268
270
const { outputDir } = options ;
269
271
await minifyAll ( path . join ( outputDir , "server-function" ) , {
270
272
compress_json : true ,
@@ -273,7 +275,7 @@ async function minifyServerBundle() {
273
275
}
274
276
275
277
function createRevalidationBundle ( ) {
276
- console . info ( `Bundling revalidation function...` ) ;
278
+ logger . info ( `Bundling revalidation function...` ) ;
277
279
278
280
const { appBuildOutputPath, outputDir } = options ;
279
281
@@ -296,7 +298,7 @@ function createRevalidationBundle() {
296
298
}
297
299
298
300
function createImageOptimizationBundle ( ) {
299
- console . info ( `Bundling image optimization function...` ) ;
301
+ logger . info ( `Bundling image optimization function...` ) ;
300
302
301
303
const { appPath, appBuildOutputPath, outputDir } = options ;
302
304
@@ -364,7 +366,7 @@ function createImageOptimizationBundle() {
364
366
}
365
367
366
368
function createStaticAssets ( ) {
367
- console . info ( `Bundling static assets...` ) ;
369
+ logger . info ( `Bundling static assets...` ) ;
368
370
369
371
const { appBuildOutputPath, appPublicPath, outputDir, appPath } = options ;
370
372
@@ -403,7 +405,7 @@ function createStaticAssets() {
403
405
}
404
406
405
407
function createCacheAssets ( monorepoRoot : string , disableDynamoDBCache = false ) {
406
- console . info ( `Bundling cache assets...` ) ;
408
+ logger . info ( `Bundling cache assets...` ) ;
407
409
408
410
const { appBuildOutputPath, outputDir } = options ;
409
411
const packagePath = path . relative ( monorepoRoot , appBuildOutputPath ) ;
@@ -464,7 +466,7 @@ function createCacheAssets(monorepoRoot: string, disableDynamoDBCache = false) {
464
466
case ".map" :
465
467
break ;
466
468
default :
467
- console . warn ( `Unknown file extension: ${ ext } ` ) ;
469
+ logger . warn ( `Unknown file extension: ${ ext } ` ) ;
468
470
break ;
469
471
}
470
472
} ,
@@ -582,7 +584,7 @@ function createCacheAssets(monorepoRoot: string, disableDynamoDBCache = false) {
582
584
/***************************/
583
585
584
586
async function createServerBundle ( monorepoRoot : string , streaming = false ) {
585
- console . info ( `Bundling server function...` ) ;
587
+ logger . info ( `Bundling server function...` ) ;
586
588
587
589
const { appPath, appBuildOutputPath, outputDir } = options ;
588
590
@@ -670,7 +672,7 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
670
672
}
671
673
672
674
if ( plugins && plugins . length > 0 ) {
673
- console . log (
675
+ logger . debug (
674
676
`Applying plugins:: [${ plugins
675
677
. map ( ( { name } ) => name )
676
678
. join ( "," ) } ] for Next version: ${ options . nextVersion } `,
@@ -844,14 +846,14 @@ function esbuildSync(esbuildOptions: ESBuildOptions) {
844
846
...esbuildOptions . banner ,
845
847
js : [
846
848
esbuildOptions . banner ?. js || "" ,
847
- `globalThis.openNextDebug = ${ process . env . OPEN_NEXT_DEBUG ?? false } ;` ,
849
+ `globalThis.openNextDebug = ${ debug } ;` ,
848
850
`globalThis.openNextVersion = "${ openNextVersion } ";` ,
849
851
] . join ( "" ) ,
850
852
} ,
851
853
} ) ;
852
854
853
855
if ( result . errors . length > 0 ) {
854
- result . errors . forEach ( ( error ) => console . error ( error ) ) ;
856
+ result . errors . forEach ( ( error ) => logger . error ( error ) ) ;
855
857
throw new Error (
856
858
`There was a problem bundling ${
857
859
( esbuildOptions . entryPoints as string [ ] ) [ 0 ]
@@ -874,14 +876,14 @@ async function esbuildAsync(esbuildOptions: ESBuildOptions) {
874
876
...esbuildOptions . banner ,
875
877
js : [
876
878
esbuildOptions . banner ?. js || "" ,
877
- `globalThis.openNextDebug = ${ process . env . OPEN_NEXT_DEBUG ?? false } ;` ,
879
+ `globalThis.openNextDebug = ${ debug } ;` ,
878
880
`globalThis.openNextVersion = "${ openNextVersion } ";` ,
879
881
] . join ( "" ) ,
880
882
} ,
881
883
} ) ;
882
884
883
885
if ( result . errors . length > 0 ) {
884
- result . errors . forEach ( ( error ) => console . error ( error ) ) ;
886
+ result . errors . forEach ( ( error ) => logger . error ( error ) ) ;
885
887
throw new Error (
886
888
`There was a problem bundling ${
887
889
( esbuildOptions . entryPoints as string [ ] ) [ 0 ]
0 commit comments