@@ -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 */
205209async 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