Skip to content

Commit 7da13fe

Browse files
committed
review fix
1 parent 0beaee9 commit 7da13fe

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

packages/open-next/src/build/createServerBundle.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import { type CodePatcher, applyCodePatches } from "./patch/codePatcher.js";
2020

2121
interface CodeCustomization {
2222
// These patches are meant to apply on user and next generated code
23-
additionalCodePatches: CodePatcher[];
23+
additionalCodePatches?: CodePatcher[];
2424
// These plugins are meant to apply during the esbuild bundling process.
2525
// This will only apply to OpenNext code.
26-
additionalPlugins: (contentUpdater: ContentUpdater) => Plugin[];
26+
additionalPlugins?: (contentUpdater: ContentUpdater) => Plugin[];
2727
}
2828

2929
export async function createServerBundle(
@@ -167,7 +167,7 @@ async function generateBundle(
167167
// Copy env files
168168
buildHelper.copyEnvFile(appBuildOutputPath, packagePath, outputPath);
169169

170-
// Copy all necessary traced files{
170+
// Copy all necessary traced files
171171
const { tracedFiles, manifests } = await copyTracedFiles({
172172
buildOutputPath: appBuildOutputPath,
173173
packagePath,
@@ -179,15 +179,6 @@ async function generateBundle(
179179
const additionalCodePatches = codeCustomization?.additionalCodePatches ?? [];
180180

181181
await applyCodePatches(options, Array.from(tracedFiles), manifests, [
182-
// TODO: create real code patchers here
183-
{
184-
name: "fakePatchChunks",
185-
pathFilter: /chunks\/\d+\.js/,
186-
patchCode: async ({ code, manifests }) => {
187-
console.log(manifests);
188-
return `console.log("patched chunk");\n${code}`;
189-
},
190-
},
191182
...additionalCodePatches,
192183
]);
193184

@@ -211,7 +202,9 @@ async function generateBundle(
211202

212203
const updater = new ContentUpdater(options);
213204

214-
const additionalPlugins = codeCustomization?.additionalPlugins(updater) ?? [];
205+
const additionalPlugins = codeCustomization?.additionalPlugins
206+
? codeCustomization.additionalPlugins(updater)
207+
: [];
215208

216209
const plugins = [
217210
openNextReplacementPlugin({
@@ -239,6 +232,7 @@ async function generateBundle(
239232
overrides,
240233
}),
241234
...additionalPlugins,
235+
// The content updater plugin must be the last plugin
242236
updater.plugin,
243237
];
244238

packages/open-next/src/build/edge/createEdgeBundle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export async function buildEdgeBundle({
104104
isInCloudfare,
105105
}),
106106
...additionalPlugins,
107+
// The content updater plugin must be the last plugin
107108
contentUpdater.plugin,
108109
],
109110
treeShaking: true,

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ import * as buildHelper from "../helper.js";
44

55
// Either before or after should be provided, otherwise just use the field directly
66
export interface VersionedField<T> {
7-
// The version before which the field should be used
7+
/**
8+
* The version before which the field should be used
9+
* If the version is less than or equal to this, the field will be used
10+
*/
811
before?:
912
| `${number}`
1013
| `${number}.${number}`
1114
| `${number}.${number}.${number}`;
12-
// The version after which the field should be used
15+
/**
16+
* The version after which the field should be used
17+
* If the version is greater than this, the field will be used
18+
*/
1319
after?: `${number}` | `${number}.${number}` | `${number}.${number}.${number}`;
1420
field: T;
1521
}
@@ -67,7 +73,7 @@ export async function applyCodePatches(
6773
codePatcher: CodePatcher[],
6874
) {
6975
const nextVersion = buildOptions.nextVersion;
70-
console.time("Applying code patches");
76+
logger.time("Applying code patches");
7177
await Promise.all(
7278
tracedFiles.map(async (filePath) => {
7379
// We check the filename against the filter to see if we should apply the patch
@@ -120,5 +126,5 @@ export async function applyCodePatches(
120126
await fs.writeFile(filePath, patchedContent);
121127
}),
122128
);
123-
console.timeEnd("Applying code patches");
129+
logger.timeEnd("Applying code patches");
124130
}

packages/open-next/src/logger.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ export default {
1313
info: console.log,
1414
warn: (...args: any[]) => console.warn(chalk.yellow("WARN"), ...args),
1515
error: (...args: any[]) => console.error(chalk.red("ERROR"), ...args),
16+
time: console.time,
17+
timeEnd: console.timeEnd,
1618
};

packages/open-next/src/plugins/content-updater.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/**
2-
* Mostly copied from the cloudflare adapter
32
* ESBuild stops calling `onLoad` hooks after the first hook returns an updated content.
43
*
54
* The updater allows multiple plugins to update the content.

0 commit comments

Comments
 (0)