From 7ebefb7b178713d7d6762e6be1562e5d5c9e2231 Mon Sep 17 00:00:00 2001
From: Khue Nguyen <khuezy.nguyen@gmail.com>
Date: Wed, 20 Sep 2023 14:37:05 -0700
Subject: [PATCH 01/11] feat: remove dev node_modules deps

---
 packages/open-next/src/build.ts | 73 ++++++++++++++++++++++-----------
 1 file changed, 49 insertions(+), 24 deletions(-)

diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts
index 929a88fdb..3555918ec 100644
--- a/packages/open-next/src/build.ts
+++ b/packages/open-next/src/build.ts
@@ -626,22 +626,22 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   let plugins =
     compareSemver(options.nextVersion, "13.4.13") >= 0
       ? [
-          openNextPlugin({
-            name: "opennext-13.4.13-serverHandler",
-            target: /plugins\/serverHandler\.js/g,
-            replacements: ["./serverHandler.replacement.js"],
-          }),
-          openNextPlugin({
-            name: "opennext-13.4.13-util",
-            target: /plugins\/util\.js/g,
-            replacements: ["./util.replacement.js"],
-          }),
-          openNextPlugin({
-            name: "opennext-13.4.13-default",
-            target: /plugins\/routing\/default\.js/g,
-            replacements: ["./default.replacement.js"],
-          }),
-        ]
+        openNextPlugin({
+          name: "opennext-13.4.13-serverHandler",
+          target: /plugins\/serverHandler\.js/g,
+          replacements: ["./serverHandler.replacement.js"],
+        }),
+        openNextPlugin({
+          name: "opennext-13.4.13-util",
+          target: /plugins\/util\.js/g,
+          replacements: ["./util.replacement.js"],
+        }),
+        openNextPlugin({
+          name: "opennext-13.4.13-default",
+          target: /plugins\/routing\/default\.js/g,
+          replacements: ["./default.replacement.js"],
+        }),
+      ]
       : undefined;
 
   if (compareSemver(options.nextVersion, "13.5.1") >= 0) {
@@ -707,6 +707,25 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   injectMiddlewareGeolocation(outputPath, packagePath);
   removeCachedPages(outputPath, packagePath);
   addCacheHandler(outputPath, options.dangerous);
+
+  if (options.minify) {
+    removeNodeModule(path.join(outputPath, "node_modules"), [
+      "@esbuild",
+      "prisma/libquery_engine-darwin-arm64.dylib.node",
+      "@swc/core-darwin-arm64",
+      "@swc/core",
+      "better-sqlite3",
+      "esbuild",
+      "webpack",
+      "uglify-js",
+      // "react", // TODO: remove react/react-dom when nextjs updates its precompile versions
+      // "react-dom",
+      "@webassemblyjs",
+      "uglify-js",
+      "sass",
+      "caniuse-lite",
+    ]);
+  }
 }
 
 function addMonorepoEntrypoint(outputPath: string, packagePath: string) {
@@ -823,11 +842,9 @@ function addCacheHandler(outputPath: string, options?: DangerousOptions) {
     format: "cjs",
     banner: {
       js: [
-        `globalThis.disableIncrementalCache = ${
-          options?.disableIncrementalCache ?? false
+        `globalThis.disableIncrementalCache = ${options?.disableIncrementalCache ?? false
         };`,
-        `globalThis.disableDynamoDBCache = ${
-          options?.disableDynamoDBCache ?? false
+        `globalThis.disableDynamoDBCache = ${options?.disableDynamoDBCache ?? false
         };`,
       ].join(""),
     },
@@ -861,8 +878,7 @@ function esbuildSync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${
-        (esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }
@@ -891,8 +907,7 @@ async function esbuildAsync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${
-        (esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }
@@ -996,3 +1011,13 @@ function compareSemver(v1: string, v2: string): number {
   if (minor1 !== minor2) return minor1 - minor2;
   return patch1 - patch2;
 }
+
+function removeNodeModule(nodeModulesPath: string, modules: string[]) {
+  console.log("removing: ", modules);
+  for (const module of modules) {
+    fs.rmSync(path.join(nodeModulesPath, module), {
+      force: true,
+      recursive: true,
+    });
+  }
+}

From 12e2bb198056b65b4810193d8ae6349ef2ba520d Mon Sep 17 00:00:00 2001
From: Khue Nguyen <khuezy.nguyen@gmail.com>
Date: Wed, 15 Nov 2023 09:16:44 -0800
Subject: [PATCH 02/11] add prisma junk

---
 packages/open-next/src/build.ts | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts
index 3555918ec..c0fbee480 100644
--- a/packages/open-next/src/build.ts
+++ b/packages/open-next/src/build.ts
@@ -711,19 +711,29 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   if (options.minify) {
     removeNodeModule(path.join(outputPath, "node_modules"), [
       "@esbuild",
-      "prisma/libquery_engine-darwin-arm64.dylib.node",
+      "@prisma/engines/download",
+      "@prisma/internals/dist/libquery_engine*",
+      "@prisma/internals/dist/get-generators/libquery_engine*",
+      "@prisma/internals/dist/get-generators/engines",
       "@swc/core-darwin-arm64",
       "@swc/core",
+      "@types",
+      "@webassemblyjs",
+
       "better-sqlite3",
+      "caniuse-lite",
       "esbuild",
-      "webpack",
+      ".prisma",
+      "prisma/libquery_engine-darwin-arm64.dylib.node",
+      "prisma/build/public",
+      "prisma/prisma-client/src/__tests__",
+      "prisma/prisma-client/generator-build",
+      "sass",
+
       "uglify-js",
+      "webpack",
       // "react", // TODO: remove react/react-dom when nextjs updates its precompile versions
       // "react-dom",
-      "@webassemblyjs",
-      "uglify-js",
-      "sass",
-      "caniuse-lite",
     ]);
   }
 }

From c966c26becbd66211ef9583d080dc49b457189db Mon Sep 17 00:00:00 2001
From: Khue Nguyen <khuezy.nguyen@gmail.com>
Date: Wed, 15 Nov 2023 09:20:24 -0800
Subject: [PATCH 03/11] prerelease version

---
 packages/open-next/package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/open-next/package.json b/packages/open-next/package.json
index 83732ed3b..9ea67af75 100644
--- a/packages/open-next/package.json
+++ b/packages/open-next/package.json
@@ -3,7 +3,7 @@
     "access": "public"
   },
   "name": "open-next",
-  "version": "2.3.2",
+  "version": "0.0.0-bloat.1",
   "bin": {
     "open-next": "./dist/index.js"
   },

From add810383203a60a97fae80cffce47ff0c1d0649 Mon Sep 17 00:00:00 2001
From: Khue Nguyen <khuezy.nguyen@gmail.com>
Date: Wed, 15 Nov 2023 09:23:55 -0800
Subject: [PATCH 04/11] fix lint

---
 packages/open-next/src/build.ts | 44 ++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts
index c0fbee480..c39326d12 100644
--- a/packages/open-next/src/build.ts
+++ b/packages/open-next/src/build.ts
@@ -626,22 +626,22 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   let plugins =
     compareSemver(options.nextVersion, "13.4.13") >= 0
       ? [
-        openNextPlugin({
-          name: "opennext-13.4.13-serverHandler",
-          target: /plugins\/serverHandler\.js/g,
-          replacements: ["./serverHandler.replacement.js"],
-        }),
-        openNextPlugin({
-          name: "opennext-13.4.13-util",
-          target: /plugins\/util\.js/g,
-          replacements: ["./util.replacement.js"],
-        }),
-        openNextPlugin({
-          name: "opennext-13.4.13-default",
-          target: /plugins\/routing\/default\.js/g,
-          replacements: ["./default.replacement.js"],
-        }),
-      ]
+          openNextPlugin({
+            name: "opennext-13.4.13-serverHandler",
+            target: /plugins\/serverHandler\.js/g,
+            replacements: ["./serverHandler.replacement.js"],
+          }),
+          openNextPlugin({
+            name: "opennext-13.4.13-util",
+            target: /plugins\/util\.js/g,
+            replacements: ["./util.replacement.js"],
+          }),
+          openNextPlugin({
+            name: "opennext-13.4.13-default",
+            target: /plugins\/routing\/default\.js/g,
+            replacements: ["./default.replacement.js"],
+          }),
+        ]
       : undefined;
 
   if (compareSemver(options.nextVersion, "13.5.1") >= 0) {
@@ -852,9 +852,11 @@ function addCacheHandler(outputPath: string, options?: DangerousOptions) {
     format: "cjs",
     banner: {
       js: [
-        `globalThis.disableIncrementalCache = ${options?.disableIncrementalCache ?? false
+        `globalThis.disableIncrementalCache = ${
+          options?.disableIncrementalCache ?? false
         };`,
-        `globalThis.disableDynamoDBCache = ${options?.disableDynamoDBCache ?? false
+        `globalThis.disableDynamoDBCache = ${
+          options?.disableDynamoDBCache ?? false
         };`,
       ].join(""),
     },
@@ -888,7 +890,8 @@ function esbuildSync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${
+        (esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }
@@ -917,7 +920,8 @@ async function esbuildAsync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${
+        (esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }

From 86842eda0eacf032a61a378624dc46beb91c493a Mon Sep 17 00:00:00 2001
From: Khue Nguyen <khuezy.nguyen@gmail.com>
Date: Wed, 15 Nov 2023 09:31:56 -0800
Subject: [PATCH 05/11] remove minify check

---
 packages/open-next/package.json |  2 +-
 packages/open-next/src/build.ts | 98 ++++++++++++++++-----------------
 2 files changed, 47 insertions(+), 53 deletions(-)

diff --git a/packages/open-next/package.json b/packages/open-next/package.json
index 9ea67af75..129665eab 100644
--- a/packages/open-next/package.json
+++ b/packages/open-next/package.json
@@ -3,7 +3,7 @@
     "access": "public"
   },
   "name": "open-next",
-  "version": "0.0.0-bloat.1",
+  "version": "0.0.0-bloat.2",
   "bin": {
     "open-next": "./dist/index.js"
   },
diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts
index c39326d12..82443029d 100644
--- a/packages/open-next/src/build.ts
+++ b/packages/open-next/src/build.ts
@@ -626,22 +626,22 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   let plugins =
     compareSemver(options.nextVersion, "13.4.13") >= 0
       ? [
-          openNextPlugin({
-            name: "opennext-13.4.13-serverHandler",
-            target: /plugins\/serverHandler\.js/g,
-            replacements: ["./serverHandler.replacement.js"],
-          }),
-          openNextPlugin({
-            name: "opennext-13.4.13-util",
-            target: /plugins\/util\.js/g,
-            replacements: ["./util.replacement.js"],
-          }),
-          openNextPlugin({
-            name: "opennext-13.4.13-default",
-            target: /plugins\/routing\/default\.js/g,
-            replacements: ["./default.replacement.js"],
-          }),
-        ]
+        openNextPlugin({
+          name: "opennext-13.4.13-serverHandler",
+          target: /plugins\/serverHandler\.js/g,
+          replacements: ["./serverHandler.replacement.js"],
+        }),
+        openNextPlugin({
+          name: "opennext-13.4.13-util",
+          target: /plugins\/util\.js/g,
+          replacements: ["./util.replacement.js"],
+        }),
+        openNextPlugin({
+          name: "opennext-13.4.13-default",
+          target: /plugins\/routing\/default\.js/g,
+          replacements: ["./default.replacement.js"],
+        }),
+      ]
       : undefined;
 
   if (compareSemver(options.nextVersion, "13.5.1") >= 0) {
@@ -708,34 +708,32 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   removeCachedPages(outputPath, packagePath);
   addCacheHandler(outputPath, options.dangerous);
 
-  if (options.minify) {
-    removeNodeModule(path.join(outputPath, "node_modules"), [
-      "@esbuild",
-      "@prisma/engines/download",
-      "@prisma/internals/dist/libquery_engine*",
-      "@prisma/internals/dist/get-generators/libquery_engine*",
-      "@prisma/internals/dist/get-generators/engines",
-      "@swc/core-darwin-arm64",
-      "@swc/core",
-      "@types",
-      "@webassemblyjs",
-
-      "better-sqlite3",
-      "caniuse-lite",
-      "esbuild",
-      ".prisma",
-      "prisma/libquery_engine-darwin-arm64.dylib.node",
-      "prisma/build/public",
-      "prisma/prisma-client/src/__tests__",
-      "prisma/prisma-client/generator-build",
-      "sass",
-
-      "uglify-js",
-      "webpack",
-      // "react", // TODO: remove react/react-dom when nextjs updates its precompile versions
-      // "react-dom",
-    ]);
-  }
+  removeNodeModule(path.join(outputPath, "node_modules"), [
+    "@esbuild",
+    "@prisma/engines/download",
+    "@prisma/internals/dist/libquery_engine*",
+    "@prisma/internals/dist/get-generators/libquery_engine*",
+    "@prisma/internals/dist/get-generators/engines",
+    "@swc/core-darwin-arm64",
+    "@swc/core",
+    "@types",
+    "@webassemblyjs",
+
+    "better-sqlite3",
+    "caniuse-lite",
+    "esbuild",
+    ".prisma",
+    "prisma/libquery_engine-darwin-arm64.dylib.node",
+    "prisma/build/public",
+    "prisma/prisma-client/src/__tests__",
+    "prisma/prisma-client/generator-build",
+    "sass",
+
+    "uglify-js",
+    "webpack",
+    // "react", // TODO: remove react/react-dom when nextjs updates its precompile versions
+    // "react-dom",
+  ]);
 }
 
 function addMonorepoEntrypoint(outputPath: string, packagePath: string) {
@@ -852,11 +850,9 @@ function addCacheHandler(outputPath: string, options?: DangerousOptions) {
     format: "cjs",
     banner: {
       js: [
-        `globalThis.disableIncrementalCache = ${
-          options?.disableIncrementalCache ?? false
+        `globalThis.disableIncrementalCache = ${options?.disableIncrementalCache ?? false
         };`,
-        `globalThis.disableDynamoDBCache = ${
-          options?.disableDynamoDBCache ?? false
+        `globalThis.disableDynamoDBCache = ${options?.disableDynamoDBCache ?? false
         };`,
       ].join(""),
     },
@@ -890,8 +886,7 @@ function esbuildSync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${
-        (esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }
@@ -920,8 +915,7 @@ async function esbuildAsync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${
-        (esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }

From 0385b3735b8b63c5e28094f279aa4aebfcd69c2c Mon Sep 17 00:00:00 2001
From: Khue Nguyen <khuezy.nguyen@gmail.com>
Date: Wed, 15 Nov 2023 09:34:50 -0800
Subject: [PATCH 06/11] fix lint

---
 packages/open-next/src/build.ts | 44 ++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts
index 82443029d..b2de1da5b 100644
--- a/packages/open-next/src/build.ts
+++ b/packages/open-next/src/build.ts
@@ -626,22 +626,22 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   let plugins =
     compareSemver(options.nextVersion, "13.4.13") >= 0
       ? [
-        openNextPlugin({
-          name: "opennext-13.4.13-serverHandler",
-          target: /plugins\/serverHandler\.js/g,
-          replacements: ["./serverHandler.replacement.js"],
-        }),
-        openNextPlugin({
-          name: "opennext-13.4.13-util",
-          target: /plugins\/util\.js/g,
-          replacements: ["./util.replacement.js"],
-        }),
-        openNextPlugin({
-          name: "opennext-13.4.13-default",
-          target: /plugins\/routing\/default\.js/g,
-          replacements: ["./default.replacement.js"],
-        }),
-      ]
+          openNextPlugin({
+            name: "opennext-13.4.13-serverHandler",
+            target: /plugins\/serverHandler\.js/g,
+            replacements: ["./serverHandler.replacement.js"],
+          }),
+          openNextPlugin({
+            name: "opennext-13.4.13-util",
+            target: /plugins\/util\.js/g,
+            replacements: ["./util.replacement.js"],
+          }),
+          openNextPlugin({
+            name: "opennext-13.4.13-default",
+            target: /plugins\/routing\/default\.js/g,
+            replacements: ["./default.replacement.js"],
+          }),
+        ]
       : undefined;
 
   if (compareSemver(options.nextVersion, "13.5.1") >= 0) {
@@ -850,9 +850,11 @@ function addCacheHandler(outputPath: string, options?: DangerousOptions) {
     format: "cjs",
     banner: {
       js: [
-        `globalThis.disableIncrementalCache = ${options?.disableIncrementalCache ?? false
+        `globalThis.disableIncrementalCache = ${
+          options?.disableIncrementalCache ?? false
         };`,
-        `globalThis.disableDynamoDBCache = ${options?.disableDynamoDBCache ?? false
+        `globalThis.disableDynamoDBCache = ${
+          options?.disableDynamoDBCache ?? false
         };`,
       ].join(""),
     },
@@ -886,7 +888,8 @@ function esbuildSync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${
+        (esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }
@@ -915,7 +918,8 @@ async function esbuildAsync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${
+        (esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }

From fdbdc90d1bd45dee6542daf53854f13d42cbbadc Mon Sep 17 00:00:00 2001
From: Khue Nguyen <khuezy.nguyen@gmail.com>
Date: Wed, 15 Nov 2023 09:59:15 -0800
Subject: [PATCH 07/11] add rollup

---
 packages/open-next/package.json |  2 +-
 packages/open-next/src/build.ts | 45 +++++++++++++++------------------
 2 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/packages/open-next/package.json b/packages/open-next/package.json
index 129665eab..b3e3314de 100644
--- a/packages/open-next/package.json
+++ b/packages/open-next/package.json
@@ -3,7 +3,7 @@
     "access": "public"
   },
   "name": "open-next",
-  "version": "0.0.0-bloat.2",
+  "version": "0.0.0-bloat.3",
   "bin": {
     "open-next": "./dist/index.js"
   },
diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts
index b2de1da5b..f655003aa 100644
--- a/packages/open-next/src/build.ts
+++ b/packages/open-next/src/build.ts
@@ -626,22 +626,22 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   let plugins =
     compareSemver(options.nextVersion, "13.4.13") >= 0
       ? [
-          openNextPlugin({
-            name: "opennext-13.4.13-serverHandler",
-            target: /plugins\/serverHandler\.js/g,
-            replacements: ["./serverHandler.replacement.js"],
-          }),
-          openNextPlugin({
-            name: "opennext-13.4.13-util",
-            target: /plugins\/util\.js/g,
-            replacements: ["./util.replacement.js"],
-          }),
-          openNextPlugin({
-            name: "opennext-13.4.13-default",
-            target: /plugins\/routing\/default\.js/g,
-            replacements: ["./default.replacement.js"],
-          }),
-        ]
+        openNextPlugin({
+          name: "opennext-13.4.13-serverHandler",
+          target: /plugins\/serverHandler\.js/g,
+          replacements: ["./serverHandler.replacement.js"],
+        }),
+        openNextPlugin({
+          name: "opennext-13.4.13-util",
+          target: /plugins\/util\.js/g,
+          replacements: ["./util.replacement.js"],
+        }),
+        openNextPlugin({
+          name: "opennext-13.4.13-default",
+          target: /plugins\/routing\/default\.js/g,
+          replacements: ["./default.replacement.js"],
+        }),
+      ]
       : undefined;
 
   if (compareSemver(options.nextVersion, "13.5.1") >= 0) {
@@ -727,6 +727,7 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
     "prisma/build/public",
     "prisma/prisma-client/src/__tests__",
     "prisma/prisma-client/generator-build",
+    "rollup",
     "sass",
 
     "uglify-js",
@@ -850,11 +851,9 @@ function addCacheHandler(outputPath: string, options?: DangerousOptions) {
     format: "cjs",
     banner: {
       js: [
-        `globalThis.disableIncrementalCache = ${
-          options?.disableIncrementalCache ?? false
+        `globalThis.disableIncrementalCache = ${options?.disableIncrementalCache ?? false
         };`,
-        `globalThis.disableDynamoDBCache = ${
-          options?.disableDynamoDBCache ?? false
+        `globalThis.disableDynamoDBCache = ${options?.disableDynamoDBCache ?? false
         };`,
       ].join(""),
     },
@@ -888,8 +887,7 @@ function esbuildSync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${
-        (esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }
@@ -918,8 +916,7 @@ async function esbuildAsync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${
-        (esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }

From cd9a6612c846fba56425d01ce4dce96296ffa050 Mon Sep 17 00:00:00 2001
From: Khue Nguyen <khuezy.nguyen@gmail.com>
Date: Wed, 15 Nov 2023 09:59:50 -0800
Subject: [PATCH 08/11] fix lint

---
 packages/open-next/src/build.ts | 44 ++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts
index f655003aa..c469db512 100644
--- a/packages/open-next/src/build.ts
+++ b/packages/open-next/src/build.ts
@@ -626,22 +626,22 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   let plugins =
     compareSemver(options.nextVersion, "13.4.13") >= 0
       ? [
-        openNextPlugin({
-          name: "opennext-13.4.13-serverHandler",
-          target: /plugins\/serverHandler\.js/g,
-          replacements: ["./serverHandler.replacement.js"],
-        }),
-        openNextPlugin({
-          name: "opennext-13.4.13-util",
-          target: /plugins\/util\.js/g,
-          replacements: ["./util.replacement.js"],
-        }),
-        openNextPlugin({
-          name: "opennext-13.4.13-default",
-          target: /plugins\/routing\/default\.js/g,
-          replacements: ["./default.replacement.js"],
-        }),
-      ]
+          openNextPlugin({
+            name: "opennext-13.4.13-serverHandler",
+            target: /plugins\/serverHandler\.js/g,
+            replacements: ["./serverHandler.replacement.js"],
+          }),
+          openNextPlugin({
+            name: "opennext-13.4.13-util",
+            target: /plugins\/util\.js/g,
+            replacements: ["./util.replacement.js"],
+          }),
+          openNextPlugin({
+            name: "opennext-13.4.13-default",
+            target: /plugins\/routing\/default\.js/g,
+            replacements: ["./default.replacement.js"],
+          }),
+        ]
       : undefined;
 
   if (compareSemver(options.nextVersion, "13.5.1") >= 0) {
@@ -851,9 +851,11 @@ function addCacheHandler(outputPath: string, options?: DangerousOptions) {
     format: "cjs",
     banner: {
       js: [
-        `globalThis.disableIncrementalCache = ${options?.disableIncrementalCache ?? false
+        `globalThis.disableIncrementalCache = ${
+          options?.disableIncrementalCache ?? false
         };`,
-        `globalThis.disableDynamoDBCache = ${options?.disableDynamoDBCache ?? false
+        `globalThis.disableDynamoDBCache = ${
+          options?.disableDynamoDBCache ?? false
         };`,
       ].join(""),
     },
@@ -887,7 +889,8 @@ function esbuildSync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${
+        (esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }
@@ -916,7 +919,8 @@ async function esbuildAsync(esbuildOptions: ESBuildOptions) {
   if (result.errors.length > 0) {
     result.errors.forEach((error) => logger.error(error));
     throw new Error(
-      `There was a problem bundling ${(esbuildOptions.entryPoints as string[])[0]
+      `There was a problem bundling ${
+        (esbuildOptions.entryPoints as string[])[0]
       }.`,
     );
   }

From fd2a90d2f8f11de81402153652693b059e76ab51 Mon Sep 17 00:00:00 2001
From: Khue Nguyen <khuezy.nguyen@gmail.com>
Date: Wed, 15 Nov 2023 12:02:07 -0800
Subject: [PATCH 09/11] use exec to delete folders

---
 packages/open-next/package.json |  2 +-
 packages/open-next/src/build.ts | 25 +++++++++++++++++++------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/packages/open-next/package.json b/packages/open-next/package.json
index b3e3314de..bfee0f146 100644
--- a/packages/open-next/package.json
+++ b/packages/open-next/package.json
@@ -3,7 +3,7 @@
     "access": "public"
   },
   "name": "open-next",
-  "version": "0.0.0-bloat.3",
+  "version": "0.0.0-bloat.4",
   "bin": {
     "open-next": "./dist/index.js"
   },
diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts
index c469db512..6678a0cf3 100644
--- a/packages/open-next/src/build.ts
+++ b/packages/open-next/src/build.ts
@@ -4,6 +4,7 @@ import { createRequire as topLevelCreateRequire } from "node:module";
 import path from "node:path";
 import url from "node:url";
 
+import { exec } from "child_process";
 import {
   build as buildAsync,
   BuildOptions as ESBuildOptions,
@@ -709,7 +710,7 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   addCacheHandler(outputPath, options.dangerous);
 
   removeNodeModule(path.join(outputPath, "node_modules"), [
-    "@esbuild",
+    "@esbuild*",
     "@prisma/engines/download",
     "@prisma/internals/dist/libquery_engine*",
     "@prisma/internals/dist/get-generators/libquery_engine*",
@@ -1026,11 +1027,23 @@ function compareSemver(v1: string, v2: string): number {
 }
 
 function removeNodeModule(nodeModulesPath: string, modules: string[]) {
-  console.log("removing: ", modules);
+  console.log("Removing: ", modules);
+  const isWindows = process.platform === "win32";
+
   for (const module of modules) {
-    fs.rmSync(path.join(nodeModulesPath, module), {
-      force: true,
-      recursive: true,
-    });
+    const modulePath = path.join(nodeModulesPath, module);
+    const pnpmModulePath = path.join(nodeModulesPath, ".pnpm", module);
+
+    if (isWindows) {
+      exec(
+        `PowerShell -Command "Remove-Item -Path '${modulePath}' -Recurse -Force"`,
+      );
+      exec(
+        `PowerShell -Command "Remove-Item -Path '${pnpmModulePath}' -Recurse -Force"`,
+      );
+    } else {
+      exec(`rm -rf ${modulePath}`);
+      exec(`rm -rf ${pnpmModulePath}`);
+    }
   }
 }

From 432be9056b63b4482a036c2f5e38928b00e12206 Mon Sep 17 00:00:00 2001
From: Khue Nguyen <khuezy.nguyen@gmail.com>
Date: Wed, 15 Nov 2023 12:25:13 -0800
Subject: [PATCH 10/11] remove .pnpm suffix

---
 packages/open-next/package.json | 2 +-
 packages/open-next/src/build.ts | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/packages/open-next/package.json b/packages/open-next/package.json
index bfee0f146..4d345cf6c 100644
--- a/packages/open-next/package.json
+++ b/packages/open-next/package.json
@@ -3,7 +3,7 @@
     "access": "public"
   },
   "name": "open-next",
-  "version": "0.0.0-bloat.4",
+  "version": "0.0.0-bloat.5",
   "bin": {
     "open-next": "./dist/index.js"
   },
diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts
index 6678a0cf3..754269b54 100644
--- a/packages/open-next/src/build.ts
+++ b/packages/open-next/src/build.ts
@@ -1032,7 +1032,8 @@ function removeNodeModule(nodeModulesPath: string, modules: string[]) {
 
   for (const module of modules) {
     const modulePath = path.join(nodeModulesPath, module);
-    const pnpmModulePath = path.join(nodeModulesPath, ".pnpm", module);
+    // modules in .pnpm have the version suffix, eg: .pnpm/something@1.1.1
+    const pnpmModulePath = path.join(nodeModulesPath, ".pnpm", `${module}@*`);
 
     if (isWindows) {
       exec(

From c47c0acc031d4922944af42eda64196dca0d437a Mon Sep 17 00:00:00 2001
From: Khue Nguyen <khuezy.nguyen@gmail.com>
Date: Wed, 15 Nov 2023 14:05:25 -0800
Subject: [PATCH 11/11] fix wildcard with pnpm

---
 packages/open-next/package.json |  2 +-
 packages/open-next/src/build.ts | 43 ++++++++++++++++-----------------
 2 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/packages/open-next/package.json b/packages/open-next/package.json
index 4d345cf6c..0790e1cdd 100644
--- a/packages/open-next/package.json
+++ b/packages/open-next/package.json
@@ -3,7 +3,7 @@
     "access": "public"
   },
   "name": "open-next",
-  "version": "0.0.0-bloat.5",
+  "version": "0.0.0-bloat.6",
   "bin": {
     "open-next": "./dist/index.js"
   },
diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts
index 754269b54..e61635829 100644
--- a/packages/open-next/src/build.ts
+++ b/packages/open-next/src/build.ts
@@ -711,28 +711,28 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
 
   removeNodeModule(path.join(outputPath, "node_modules"), [
     "@esbuild*",
-    "@prisma/engines/download",
+    "@prisma/engines/download*",
     "@prisma/internals/dist/libquery_engine*",
     "@prisma/internals/dist/get-generators/libquery_engine*",
-    "@prisma/internals/dist/get-generators/engines",
-    "@swc/core-darwin-arm64",
-    "@swc/core",
-    "@types",
-    "@webassemblyjs",
-
-    "better-sqlite3",
-    "caniuse-lite",
-    "esbuild",
-    ".prisma",
-    "prisma/libquery_engine-darwin-arm64.dylib.node",
-    "prisma/build/public",
-    "prisma/prisma-client/src/__tests__",
-    "prisma/prisma-client/generator-build",
-    "rollup",
-    "sass",
-
-    "uglify-js",
-    "webpack",
+    "@prisma/internals/dist/get-generators/engines*",
+    "@swc/core-darwin-arm64*",
+    "@swc/core*",
+    "@types*",
+    "@webassemblyjs*",
+
+    "better-sqlite3*",
+    "caniuse-lite*",
+    "esbuild*",
+    ".prisma*",
+    "prisma/libquery_engine-darwin-arm64.dylib.node*",
+    "prisma/build/public*",
+    "prisma/prisma-client/src/__tests__*",
+    "prisma/prisma-client/generator-build*",
+    "rollup*",
+    "sass*",
+
+    "uglify-js*",
+    "webpack*",
     // "react", // TODO: remove react/react-dom when nextjs updates its precompile versions
     // "react-dom",
   ]);
@@ -1032,8 +1032,7 @@ function removeNodeModule(nodeModulesPath: string, modules: string[]) {
 
   for (const module of modules) {
     const modulePath = path.join(nodeModulesPath, module);
-    // modules in .pnpm have the version suffix, eg: .pnpm/something@1.1.1
-    const pnpmModulePath = path.join(nodeModulesPath, ".pnpm", `${module}@*`);
+    const pnpmModulePath = path.join(nodeModulesPath, ".pnpm", module);
 
     if (isWindows) {
       exec(
