Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/unlucky-olives-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

use correct version for applying stableIncrementalCache (It failed for next 14.0.4)
2 changes: 1 addition & 1 deletion packages/open-next/src/build/createServerBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async function generateBundle(
const isBefore13413 =
buildHelper.compareSemver(options.nextVersion, "13.4.13") <= 0;
const isAfter141 =
buildHelper.compareSemver(options.nextVersion, "14.0.4") >= 0;
buildHelper.compareSemver(options.nextVersion, "14.1") >= 0;

const disableRouting = isBefore13413 || config.middleware?.external;

Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/build/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export function compareSemver(v1: string, v2: string): number {

if (major1 !== major2) return major1 - major2;
if (minor1 !== minor2) return minor1 - minor2;
return patch1 - patch2;
return (patch1 ?? 0) - (patch2 ?? 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you have the same issue with minor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically we could have this issue for minor2 only.
We only use this to compare with next version, and the next version comes from next/package.json (so should always contain major, minor and patch)

v2 is the one we provide to test, i don't see in which scenario we'd use latest

I should add a comment above the function so that we know about its limitation and how it should be used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function assumes that M, m, p exists.

 const [major1 = 0, minor1 = 0, patch1 = 0] = v1.split(".").map(Number);
 const [major2 = 0, minor2 = 0, patch2 = 0] = v2.split(".").map(Number);

This should default those values.

}

export function copyOpenNextConfig(
Expand Down
25 changes: 25 additions & 0 deletions packages/tests-unit/tests/build/helper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { compareSemver } from "@opennextjs/aws/build/helper.js";

// We don't need to test canary versions, they are stripped out
describe("compareSemver", () => {
it("should return 0 when versions are equal", () => {
expect(compareSemver("1.0.0", "1.0.0")).toBe(0);
});

it("should return 1 when first version is greater", () => {
expect(compareSemver("1.0.1", "1.0.0")).toBe(1);
});

it("should return -1 when first version is smaller", () => {
expect(compareSemver("1.0.0", "1.0.1")).toBe(-1);
});

it("should work with latest", () => {
expect(compareSemver("latest", "1.0.0")).toBe(1);
});

it("should work with incomplete version", () => {
expect(compareSemver("14.1.0", "14.1")).toBe(0);
expect(compareSemver("14.1", "14.1.0")).toBe(0);
});
});
Loading