Skip to content

Commit 4889a15

Browse files
james-elicxvicb
authored andcommitted
prevent eval patch from failing build (#190)
1 parent 068033a commit 4889a15

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/cloudflare/src/cli/build/bundle-server.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ async function updateWorkerBundledCode(
167167
// TODO: implement for cf (possibly in @opennextjs/aws)
168168
.replace("patchAsyncStorage();", "//patchAsyncStorage();"),
169169
],
170-
['`eval("require")` calls', (code) => code.replaceAll('eval("require")', "require")],
170+
[
171+
'`eval("require")` calls',
172+
(code) => code.replaceAll('eval("require")', "require"),
173+
{ isOptional: true },
174+
],
171175
[
172176
"`require.resolve` call",
173177
// workers do not support dynamic require nor require.resolve
@@ -204,18 +208,18 @@ function createFixRequiresESBuildPlugin(config: Config): Plugin {
204208
*/
205209
async function patchCodeWithValidations(
206210
code: string,
207-
patches: [string, (code: string) => string | Promise<string>][]
211+
patches: [string, (code: string) => string | Promise<string>, opts?: { isOptional?: boolean }][]
208212
): Promise<string> {
209213
console.log(`Applying code patches:`);
210214
let patchedCode = code;
211215

212-
for (const [target, patchFunction] of patches) {
216+
for (const [target, patchFunction, opts] of patches) {
213217
console.log(` - patching ${target}`);
214218

215219
const prePatchCode = patchedCode;
216220
patchedCode = await patchFunction(patchedCode);
217221

218-
if (prePatchCode === patchedCode) {
222+
if (!opts?.isOptional && prePatchCode === patchedCode) {
219223
throw new Error(`Failed to patch ${target}`);
220224
}
221225
}

0 commit comments

Comments
 (0)