Skip to content

fix extractVersionedField #790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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/red-houses-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

fix `extractVersionedField` to always extract when no version is specified
50 changes: 31 additions & 19 deletions packages/open-next/src/build/patch/codePatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,38 @@ export function extractVersionedField<T>(
const result: T[] = [];

for (const field of fields) {
const { before, after } = parseVersions(field.versions);
if (
before &&
after &&
buildHelper.compareSemver(version, "<=", before) &&
buildHelper.compareSemver(version, ">=", after)
) {
result.push(field.field);
} else if (
before &&
!after &&
buildHelper.compareSemver(version, "<=", before)
) {
result.push(field.field);
} else if (
after &&
!before &&
buildHelper.compareSemver(version, ">=", after)
) {
// No versions specified, the patch always apply
if (!field.versions) {
result.push(field.field);
continue;
}

const { before, after } = parseVersions(field.versions);

// range
if (before && after) {
if (
buildHelper.compareSemver(version, "<=", before) &&
buildHelper.compareSemver(version, ">=", after)
) {
result.push(field.field);
}
continue;
}

// before only
if (before) {
if (buildHelper.compareSemver(version, "<=", before)) {
result.push(field.field);
}
continue;
}

// after only
if (after) {
if (buildHelper.compareSemver(version, ">=", after)) {
result.push(field.field);
}
}
}
return result;
Expand Down
2 changes: 2 additions & 0 deletions packages/open-next/src/plugins/content-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
extractVersionedField,
} from "../build/patch/codePatcher.js";

export type * from "esbuild";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed until we have a mono-repo with the same ESBuild version


/**
* The callbacks returns either an updated content or undefined if the content is unchanged.
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/tests-unit/tests/build/patch/codePatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ describe("extractVersionedField", () => {
expect(result).toEqual([]);
});

it("should return the field when versions is not specified", () => {
const result = extractVersionedField([{ field: 0 }], "15.1.0");

expect(result).toEqual([0]);
});

it("should throw an error if a single version range is invalid because of a space before", () => {
expect(() =>
extractVersionedField([{ versions: "<= 15.0.0", field: 0 }], "15.0.0"),
Expand Down