@@ -3,11 +3,13 @@ import { readFile, writeFile } from "node:fs/promises";
33import path from "node:path" ;
44import { fileURLToPath } from "node:url" ;
55
6+ import { Lang , parse } from "@ast-grep/napi" ;
67import type { BuildOptions } from "@opennextjs/aws/build/helper.js" ;
78import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js" ;
89import { build , Plugin } from "esbuild" ;
910
1011import { Config } from "../config.js" ;
12+ import { patchOptionalDependencies } from "./patches/ast/optional-deps.js" ;
1113import * as patches from "./patches/index.js" ;
1214import { normalizePath , patchCodeWithValidations } from "./utils/index.js" ;
1315
@@ -44,7 +46,7 @@ export async function bundleServer(config: Config, openNextOptions: BuildOptions
4446 target : "esnext" ,
4547 minify : false ,
4648 plugins : [ createFixRequiresESBuildPlugin ( config ) ] ,
47- external : [ "./middleware/handler.mjs" ] ,
49+ external : [ "./middleware/handler.mjs" , "caniuse-lite" ] ,
4850 alias : {
4951 // Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s:
5052 // eval("require")("bufferutil");
@@ -176,7 +178,11 @@ async function updateWorkerBundledCode(
176178 ] ,
177179 ] ) ;
178180
179- await writeFile ( workerOutputFile , patchedCode ) ;
181+ const bundle = parse ( Lang . TypeScript , patchedCode ) . root ( ) ;
182+
183+ const edits = patchOptionalDependencies ( bundle ) ;
184+
185+ await writeFile ( workerOutputFile , bundle . commitEdits ( edits ) ) ;
180186}
181187
182188function createFixRequiresESBuildPlugin ( config : Config ) : Plugin {
0 commit comments