@@ -13,6 +13,7 @@ import isDynamicRoute from "./lib/isDynamicRoute";
13
13
import pathToPosix from "./lib/pathToPosix" ;
14
14
import expressifyDynamicRoute from "./lib/expressifyDynamicRoute" ;
15
15
import pathToRegexStr from "./lib/pathToRegexStr" ;
16
+ import normalizeNodeModules from "./lib/normalizeNodeModules" ;
16
17
import createServerlessConfig from "./lib/createServerlessConfig" ;
17
18
18
19
export const DEFAULT_LAMBDA_CODE_DIR = "default-lambda" ;
@@ -36,7 +37,8 @@ const defaultBuildOptions = {
36
37
37
38
class Builder {
38
39
nextConfigDir : string ;
39
- dotNextDirectory : string ;
40
+ dotNextDir : string ;
41
+ serverlessDir : string ;
40
42
outputDir : string ;
41
43
buildOptions : BuildOptions = defaultBuildOptions ;
42
44
@@ -46,7 +48,8 @@ class Builder {
46
48
buildOptions ?: BuildOptions
47
49
) {
48
50
this . nextConfigDir = path . resolve ( nextConfigDir ) ;
49
- this . dotNextDirectory = path . join ( this . nextConfigDir , ".next" ) ;
51
+ this . dotNextDir = path . join ( this . nextConfigDir , ".next" ) ;
52
+ this . serverlessDir = path . join ( this . dotNextDir , "serverless" ) ;
50
53
this . outputDir = outputDir ;
51
54
if ( buildOptions ) {
52
55
this . buildOptions = buildOptions ;
@@ -70,10 +73,7 @@ class Builder {
70
73
}
71
74
72
75
async readPagesManifest ( ) : Promise < { [ key : string ] : string } > {
73
- const path = join (
74
- this . nextConfigDir ,
75
- ".next/serverless/pages-manifest.json"
76
- ) ;
76
+ const path = join ( this . serverlessDir , "pages-manifest.json" ) ;
77
77
const hasServerlessPageManifest = await fse . pathExists ( path ) ;
78
78
79
79
if ( ! hasServerlessPageManifest ) {
@@ -121,7 +121,9 @@ class Builder {
121
121
} )
122
122
. map ( ( filePath : string ) => {
123
123
const resolvedFilePath = path . resolve ( filePath ) ;
124
- const dst = path . relative ( this . nextConfigDir , resolvedFilePath ) ;
124
+ const dst = normalizeNodeModules (
125
+ path . relative ( this . serverlessDir , resolvedFilePath )
126
+ ) ;
125
127
126
128
return fse . copy (
127
129
resolvedFilePath ,
@@ -149,7 +151,7 @@ class Builder {
149
151
] . filter ( ignoreAppAndDocumentPages ) ;
150
152
151
153
const ssrPages = Object . values ( allSsrPages ) . map ( pageFile =>
152
- path . join ( this . dotNextDirectory , "serverless" , pageFile )
154
+ path . join ( this . serverlessDir , pageFile )
153
155
) ;
154
156
155
157
const { fileList, reasons } = await nodeFileTrace ( ssrPages , {
@@ -182,7 +184,7 @@ class Builder {
182
184
)
183
185
) ,
184
186
fse . copy (
185
- join ( this . nextConfigDir , ".next/serverless/ pages" ) ,
187
+ join ( this . serverlessDir , "pages" ) ,
186
188
join ( this . outputDir , DEFAULT_LAMBDA_CODE_DIR , "pages" ) ,
187
189
{
188
190
filter : ( file : string ) => {
@@ -199,7 +201,7 @@ class Builder {
199
201
}
200
202
) ,
201
203
fse . copy (
202
- join ( this . nextConfigDir , ".next/ prerender-manifest.json" ) ,
204
+ join ( this . dotNextDir , "prerender-manifest.json" ) ,
203
205
join ( this . outputDir , DEFAULT_LAMBDA_CODE_DIR , "prerender-manifest.json" )
204
206
)
205
207
] ) ;
@@ -217,7 +219,7 @@ class Builder {
217
219
] ;
218
220
219
221
const apiPages = Object . values ( allApiPages ) . map ( pageFile =>
220
- path . join ( this . dotNextDirectory , "serverless" , pageFile )
222
+ path . join ( this . serverlessDir , pageFile )
221
223
) ;
222
224
223
225
const { fileList, reasons } = await nodeFileTrace ( apiPages , {
@@ -246,11 +248,11 @@ class Builder {
246
248
)
247
249
) ,
248
250
fse . copy (
249
- join ( this . nextConfigDir , ".next/serverless/ pages/api" ) ,
251
+ join ( this . serverlessDir , "pages/api" ) ,
250
252
join ( this . outputDir , API_LAMBDA_CODE_DIR , "pages/api" )
251
253
) ,
252
254
fse . copy (
253
- join ( this . nextConfigDir , ".next/serverless/ pages/_error.js" ) ,
255
+ join ( this . serverlessDir , "pages/_error.js" ) ,
254
256
join ( this . outputDir , API_LAMBDA_CODE_DIR , "pages/_error.js" )
255
257
) ,
256
258
fse . writeJson (
@@ -342,19 +344,17 @@ class Builder {
342
344
}
343
345
344
346
async cleanupDotNext ( ) : Promise < void > {
345
- const dotNextDirectory = join ( this . nextConfigDir , ".next" ) ;
346
-
347
- const exists = await fse . pathExists ( dotNextDirectory ) ;
347
+ const exists = await fse . pathExists ( this . dotNextDir ) ;
348
348
349
349
if ( exists ) {
350
- const fileItems = await fse . readdir ( dotNextDirectory ) ;
350
+ const fileItems = await fse . readdir ( this . dotNextDir ) ;
351
351
352
352
await Promise . all (
353
353
fileItems
354
354
. filter (
355
355
fileItem => fileItem !== "cache" // avoid deleting the cache folder as that would lead to slow builds!
356
356
)
357
- . map ( fileItem => fse . remove ( join ( dotNextDirectory , fileItem ) ) )
357
+ . map ( fileItem => fse . remove ( join ( this . dotNextDir , fileItem ) ) )
358
358
) ;
359
359
}
360
360
}
0 commit comments