diff --git a/packages/open-next/package.json b/packages/open-next/package.json index 83732ed3b..0790e1cdd 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.6", "bin": { "open-next": "./dist/index.js" }, diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts index 929a88fdb..e61635829 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, @@ -707,6 +708,34 @@ async function createServerBundle(monorepoRoot: string, streaming = false) { injectMiddlewareGeolocation(outputPath, packagePath); removeCachedPages(outputPath, packagePath); addCacheHandler(outputPath, options.dangerous); + + 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*", + "rollup*", + "sass*", + + "uglify-js*", + "webpack*", + // "react", // TODO: remove react/react-dom when nextjs updates its precompile versions + // "react-dom", + ]); } function addMonorepoEntrypoint(outputPath: string, packagePath: string) { @@ -996,3 +1025,25 @@ 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); + const isWindows = process.platform === "win32"; + + for (const module of modules) { + 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}`); + } + } +}