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

Commit 1c14f38

Browse files
authored
fix(lambda-at-edge): copy next-i18next files to regeneration handler (#1653)
1 parent a56dd82 commit 1c14f38

File tree

5 files changed

+58
-19
lines changed

5 files changed

+58
-19
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ class Builder {
343343
join(this.outputDir, DEFAULT_LAMBDA_CODE_DIR, "routes-manifest.json")
344344
),
345345
this.runThirdPartyIntegrations(
346-
join(this.outputDir, DEFAULT_LAMBDA_CODE_DIR)
346+
join(this.outputDir, DEFAULT_LAMBDA_CODE_DIR),
347+
join(this.outputDir, REGENERATION_LAMBDA_CODE_DIR)
347348
)
348349
]);
349350
}
@@ -824,11 +825,22 @@ class Builder {
824825
/**
825826
* Run additional integrations for third-party libraries such as next-i18next.
826827
* These are usually needed to add additional files into the lambda, etc.
827-
* @param outputLambdaDir
828+
* @param defaultLambdaDir
829+
* @param regenerationLambdaDir
828830
*/
829-
async runThirdPartyIntegrations(outputLambdaDir: string): Promise<void> {
831+
async runThirdPartyIntegrations(
832+
defaultLambdaDir: string,
833+
regenerationLambdaDir: string
834+
): Promise<void> {
830835
await Promise.all([
831-
new NextI18nextIntegration(this.nextConfigDir, outputLambdaDir).execute()
836+
new NextI18nextIntegration(
837+
this.nextConfigDir,
838+
defaultLambdaDir
839+
).execute(),
840+
new NextI18nextIntegration(
841+
this.nextConfigDir,
842+
regenerationLambdaDir
843+
).execute()
832844
]);
833845
}
834846
}

packages/libs/lambda-at-edge/src/build/third-party/integration-base.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { join } from "path";
22
import fse from "fs-extra";
33

4+
/**
5+
* This class allows one to integrate third party libraries by copying them to a specific Lambda directory.
6+
* Extend from this, implement the execute() method, and keep it generic enough so it can be reused across platforms.
7+
*/
48
export abstract class ThirdPartyIntegrationBase {
59
nextConfigDir: string;
6-
outputLambdaDir: string;
10+
outputHandlerDir: string;
711

8-
constructor(nextConfigDir: string, outputLambdaDir: string) {
12+
constructor(nextConfigDir: string, outputHandlerDir: string) {
913
this.nextConfigDir = nextConfigDir;
10-
this.outputLambdaDir = outputLambdaDir;
14+
this.outputHandlerDir = outputHandlerDir;
1115
}
1216

1317
abstract execute(): void;

packages/libs/lambda-at-edge/src/build/third-party/next-i18next.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class NextI18nextIntegration extends ThirdPartyIntegrationBase {
99
async execute(): Promise<void> {
1010
if (await this.isPackagePresent("next-i18next")) {
1111
const localeSrc = join(this.nextConfigDir, "public", "locales");
12-
const localeDest = join(this.outputLambdaDir, "public", "locales");
12+
const localeDest = join(this.outputHandlerDir, "public", "locales");
1313

1414
if (await fse.pathExists(localeSrc)) {
1515
await fse.copy(localeSrc, localeDest, { recursive: true });
@@ -20,11 +20,14 @@ export class NextI18nextIntegration extends ThirdPartyIntegrationBase {
2020
"next-i18next.config.js"
2121
);
2222
const nextI18nextConfigDest = join(
23-
this.outputLambdaDir,
23+
this.outputHandlerDir,
2424
"next-i18next.config.js"
2525
);
2626

27-
if (await fse.pathExists(nextI18nextConfigSrc)) {
27+
if (
28+
(await fse.pathExists(nextI18nextConfigSrc)) &&
29+
(await fse.pathExists(this.outputHandlerDir))
30+
) {
2831
await fse.copy(nextI18nextConfigSrc, nextI18nextConfigDest);
2932
}
3033
}

packages/libs/lambda-at-edge/tests/build/build-with-third-party-integrations.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import execa from "execa";
44
import Builder, {
55
DEFAULT_LAMBDA_CODE_DIR,
66
API_LAMBDA_CODE_DIR,
7-
IMAGE_LAMBDA_CODE_DIR
7+
IMAGE_LAMBDA_CODE_DIR,
8+
REGENERATION_LAMBDA_CODE_DIR
89
} from "../../src/build";
910
import { cleanupDir } from "../test-utils";
1011
import {
@@ -79,5 +80,30 @@ describe("Builder Tests (with third party integrations)", () => {
7980
expect(localesFiles).toEqual(expect.arrayContaining(["de", "en"]));
8081
});
8182
});
83+
84+
describe("Regeneration Handler Third Party Files", () => {
85+
it("next-i18next files are copied", async () => {
86+
expect(
87+
await fse.pathExists(
88+
join(
89+
outputDir,
90+
`${REGENERATION_LAMBDA_CODE_DIR}`,
91+
"next-i18next.config.js"
92+
)
93+
)
94+
).toBe(true);
95+
96+
const localesFiles = await fse.readdir(
97+
join(
98+
outputDir,
99+
`${REGENERATION_LAMBDA_CODE_DIR}`,
100+
"public",
101+
"locales"
102+
)
103+
);
104+
105+
expect(localesFiles).toEqual(expect.arrayContaining(["de", "en"]));
106+
});
107+
});
82108
});
83109
});

packages/libs/lambda-at-edge/yarn.lock

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,14 +1389,8 @@
13891389
picomatch "^2.2.2"
13901390

13911391
"@sls-next/core@link:../core":
1392-
version "3.4.0-alpha.0"
1393-
dependencies:
1394-
"@hapi/accept" "^5.0.1"
1395-
cookie "^0.4.1"
1396-
jsonwebtoken "^8.5.1"
1397-
next "^11.1.2"
1398-
path-to-regexp "^6.1.0"
1399-
regex-parser "^2.2.10"
1392+
version "0.0.0"
1393+
uid ""
14001394

14011395
"@tsconfig/node10@^1.0.7":
14021396
version "1.0.8"

0 commit comments

Comments
 (0)