Skip to content

Commit 3542789

Browse files
committed
fix and add logs
1 parent c9b8917 commit 3542789

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

packages/open-next/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"esbuild": "0.19.2",
5252
"express": "5.0.1",
5353
"path-to-regexp": "^6.3.0",
54-
"urlpattern-polyfill": "^10.0.0"
54+
"urlpattern-polyfill": "^10.0.0",
55+
"yaml": "^2.7.0"
5556
},
5657
"devDependencies": {
5758
"@types/aws-lambda": "^8.10.109",

packages/open-next/src/build/patch/codePatcher.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import * as fs from "node:fs/promises";
22
import * as buildHelper from "../helper.js";
3+
import logger from "../../logger.js";
34

45
// Either before or after should be provided, otherwise just use the field directly
56
export interface VersionedField<T> {
7+
// The version before which the field should be used
68
before?:
79
| `${number}`
810
| `${number}.${number}`
911
| `${number}.${number}.${number}`;
12+
// The version after which the field should be used
1013
after?: `${number}` | `${number}.${number}` | `${number}.${number}.${number}`;
1114
field: T;
1215
}
@@ -38,18 +41,18 @@ export function extractVersionedField<T>(
3841
if (
3942
field.before &&
4043
field.after &&
41-
buildHelper.compareSemver(version, field.before) >= 0 &&
42-
buildHelper.compareSemver(version, field.after) < 0
44+
buildHelper.compareSemver(version, field.before) <= 0 &&
45+
buildHelper.compareSemver(version, field.after) > 0
4346
) {
4447
result.push(field.field);
4548
} else if (
4649
field.before &&
47-
buildHelper.compareSemver(version, field.before) >= 0
50+
buildHelper.compareSemver(version, field.before) <= 0
4851
) {
4952
result.push(field.field);
5053
} else if (
5154
field.after &&
52-
buildHelper.compareSemver(version, field.after) < 0
55+
buildHelper.compareSemver(version, field.after) > 0
5356
) {
5457
result.push(field.field);
5558
}
@@ -64,6 +67,7 @@ export async function applyCodePatches(
6467
codePatcher: CodePatcher[],
6568
) {
6669
const nextVersion = buildOptions.nextVersion;
70+
console.time("Applying code patches");
6771
await Promise.all(
6872
tracedFiles.map(async (filePath) => {
6973
// We check the filename against the filter to see if we should apply the patch
@@ -101,6 +105,9 @@ export async function applyCodePatches(
101105
? extractVersionedField(patch.patchCode, nextVersion)
102106
: [patch.patchCode];
103107
let patchedContent = content;
108+
logger.debug(
109+
`Applying ${patchCodeFns.length} patches to ${filePath} for ${patch.name}`,
110+
);
104111
for (const patchCodeFn of patchCodeFns) {
105112
patchedContent = await patchCodeFn({
106113
code: patchedContent,
@@ -113,4 +120,5 @@ export async function applyCodePatches(
113120
});
114121
}),
115122
);
123+
console.timeEnd("Applying code patches");
116124
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { extractVersionedField } from "@opennextjs/aws/build/patch/codePatcher.js";
2+
3+
describe("extractVersionedField", () => {
4+
it("should return the field if the version is between before and after", () => {
5+
const result = extractVersionedField(
6+
[{ before: "16.0.0", after: "15.0.0", field: 0 }],
7+
"15.5.0",
8+
);
9+
10+
expect(result).toEqual([0]);
11+
});
12+
13+
it("should return the field if the version is equal to before", () => {
14+
const result = extractVersionedField(
15+
[{ before: "15.0.0", after: "16.0.0", field: 0 }],
16+
"15.0.0",
17+
);
18+
19+
expect(result).toEqual([0]);
20+
});
21+
22+
it("should return the field if the version is greater than after", () => {
23+
const result = extractVersionedField(
24+
[{ after: "16.0.0", field: 0 }],
25+
"16.5.0",
26+
);
27+
28+
expect(result).toEqual([0]);
29+
});
30+
31+
it("should return the field if the version is less than before", () => {
32+
const result = extractVersionedField(
33+
[{ before: "15.0.0", field: 0 }],
34+
"14.0.0",
35+
);
36+
37+
expect(result).toEqual([0]);
38+
});
39+
40+
it("should return an empty array if version is after before", () => {
41+
const result = extractVersionedField(
42+
[{ before: "15.0.0", field: 0 }],
43+
"15.1.0",
44+
);
45+
46+
expect(result).toEqual([]);
47+
});
48+
});

pnpm-lock.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)