@@ -3,11 +3,13 @@ import { readFile, writeFile } from "node:fs/promises";
3
3
import path from "node:path" ;
4
4
import { fileURLToPath } from "node:url" ;
5
5
6
+ import { Lang , parse } from "@ast-grep/napi" ;
6
7
import type { BuildOptions } from "@opennextjs/aws/build/helper.js" ;
7
8
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js" ;
8
9
import { build , Plugin } from "esbuild" ;
9
10
10
11
import { Config } from "../config.js" ;
12
+ import { patchOptionalDependencies } from "./patches/ast/optional-deps.js" ;
11
13
import * as patches from "./patches/index.js" ;
12
14
import { normalizePath , patchCodeWithValidations } from "./utils/index.js" ;
13
15
@@ -44,7 +46,7 @@ export async function bundleServer(config: Config, openNextOptions: BuildOptions
44
46
target : "esnext" ,
45
47
minify : false ,
46
48
plugins : [ createFixRequiresESBuildPlugin ( config ) ] ,
47
- external : [ "./middleware/handler.mjs" ] ,
49
+ external : [ "./middleware/handler.mjs" , "caniuse-lite" ] ,
48
50
alias : {
49
51
// Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s:
50
52
// eval("require")("bufferutil");
@@ -176,7 +178,11 @@ async function updateWorkerBundledCode(
176
178
] ,
177
179
] ) ;
178
180
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 ) ) ;
180
186
}
181
187
182
188
function createFixRequiresESBuildPlugin ( config : Config ) : Plugin {
0 commit comments