Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 704b866

Browse files
authored
fix(lambda-at-edge): also copy chunks for the revalidate lambda (#1099)
1 parent e703135 commit 704b866

File tree

1 file changed

+20
-16
lines changed
  • packages/libs/lambda-at-edge/src

1 file changed

+20
-16
lines changed

packages/libs/lambda-at-edge/src/build.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class Builder {
185185
* @param destination
186186
*/
187187
async processAndCopyRoutesManifest(source: string, destination: string) {
188+
// eslint-disable-next-line @typescript-eslint/no-var-requires
188189
const routesManifest = require(source) as RoutesManifest;
189190

190191
// Remove default trailing slash redirects as they are already handled without regex matching.
@@ -261,6 +262,7 @@ class Builder {
261262
async buildDefaultLambda(
262263
buildManifest: OriginRequestDefaultHandlerManifest
263264
): Promise<void[]> {
265+
// eslint-disable-next-line @typescript-eslint/no-var-requires
264266
const prerenderManifest = require(join(
265267
this.dotNextDir,
266268
"prerender-manifest.json"
@@ -321,14 +323,7 @@ class Builder {
321323
}
322324
}
323325
),
324-
// copy chunks if present and not using serverless trace
325-
!this.buildOptions.useServerlessTraceTarget &&
326-
fse.existsSync(join(this.serverlessDir, "chunks"))
327-
? fse.copy(
328-
join(this.serverlessDir, "chunks"),
329-
join(this.outputDir, DEFAULT_LAMBDA_CODE_DIR, "chunks")
330-
)
331-
: Promise.resolve(),
326+
this.copyChunks(DEFAULT_LAMBDA_CODE_DIR),
332327
fse.copy(
333328
join(this.dotNextDir, "prerender-manifest.json"),
334329
join(this.outputDir, DEFAULT_LAMBDA_CODE_DIR, "prerender-manifest.json")
@@ -388,14 +383,7 @@ class Builder {
388383
join(this.serverlessDir, "pages/api"),
389384
join(this.outputDir, API_LAMBDA_CODE_DIR, "pages/api")
390385
),
391-
// copy chunks if present and not using serverless trace
392-
!this.buildOptions.useServerlessTraceTarget &&
393-
fse.existsSync(join(this.serverlessDir, "chunks"))
394-
? fse.copy(
395-
join(this.serverlessDir, "chunks"),
396-
join(this.outputDir, API_LAMBDA_CODE_DIR, "chunks")
397-
)
398-
: Promise.resolve(),
386+
this.copyChunks(API_LAMBDA_CODE_DIR),
399387
fse.writeJson(
400388
join(this.outputDir, API_LAMBDA_CODE_DIR, "manifest.json"),
401389
apiBuildManifest
@@ -421,6 +409,7 @@ class Builder {
421409
join(this.outputDir, REGENERATION_LAMBDA_CODE_DIR),
422410
!!this.buildOptions.minifyHandlers
423411
),
412+
this.copyChunks(REGENERATION_LAMBDA_CODE_DIR),
424413
fse.copy(
425414
join(this.serverlessDir, "pages"),
426415
join(this.outputDir, REGENERATION_LAMBDA_CODE_DIR, "pages"),
@@ -441,6 +430,19 @@ class Builder {
441430
]);
442431
}
443432

433+
/**
434+
* copy chunks if present and not using serverless trace
435+
*/
436+
async copyChunks(buildDir: string): Promise<void> {
437+
return !this.buildOptions.useServerlessTraceTarget &&
438+
fse.existsSync(join(this.serverlessDir, "chunks"))
439+
? fse.copy(
440+
join(this.serverlessDir, "chunks"),
441+
join(this.outputDir, buildDir, "chunks")
442+
)
443+
: Promise.resolve();
444+
}
445+
444446
/**
445447
* Build image optimization lambda (supported by Next.js 10)
446448
* @param buildManifest
@@ -793,11 +795,13 @@ class Builder {
793795
await restoreUserConfig();
794796
}
795797

798+
// eslint-disable-next-line @typescript-eslint/no-var-requires
796799
const routesManifest = require(join(
797800
this.dotNextDir,
798801
"routes-manifest.json"
799802
));
800803

804+
// eslint-disable-next-line @typescript-eslint/no-var-requires
801805
const prerenderManifest = require(join(
802806
this.dotNextDir,
803807
"prerender-manifest.json"

0 commit comments

Comments
 (0)