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

Commit 8dfd19d

Browse files
fix(lambda-at-edge): dont throw when no prev .next dir
1 parent 31878b8 commit 8dfd19d

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,22 @@ class Builder {
246246
};
247247
}
248248

249-
async cleanupDotNext(): Promise<void[]> {
249+
async cleanupDotNext(): Promise<void> {
250250
const dotNextDirectory = join(path.resolve(this.nextConfigDir), ".next");
251-
const fileItems = await fse.readdir(dotNextDirectory);
252251

253-
return Promise.all(
254-
fileItems
255-
.filter(
256-
fileItem => fileItem !== "cache" // avoid deleting the cache folder as that would lead to slow builds!
257-
)
258-
.map(fileItem => fse.remove(join(dotNextDirectory, fileItem)))
259-
);
252+
const exists = await fse.pathExists(dotNextDirectory);
253+
254+
if (exists) {
255+
const fileItems = await fse.readdir(dotNextDirectory);
256+
257+
await Promise.all(
258+
fileItems
259+
.filter(
260+
fileItem => fileItem !== "cache" // avoid deleting the cache folder as that would lead to slow builds!
261+
)
262+
.map(fileItem => fse.remove(join(dotNextDirectory, fileItem)))
263+
);
264+
}
260265
}
261266

262267
async build(): Promise<void> {

packages/lambda-at-edge/tests/build.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ describe("Builder Tests", () => {
6161

6262
it("output directory is cleanup before building", () => {
6363
expect(fseEmptyDirSpy).toBeCalledWith(
64-
expect.stringContaining(".test_sls_next_output/default-lambda")
64+
expect.stringContaining(join(".test_sls_next_output", "default-lambda"))
6565
);
6666
expect(fseEmptyDirSpy).toBeCalledWith(
67-
expect.stringContaining(".test_sls_next_output/api-lambda")
67+
expect.stringContaining(join(".test_sls_next_output", "api-lambda"))
6868
);
6969
});
7070
});

0 commit comments

Comments
 (0)