Skip to content

Commit

Permalink
use exec to delete folders
Browse files Browse the repository at this point in the history
  • Loading branch information
khuezy committed Nov 15, 2023
1 parent cd9a661 commit fd2a90d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/open-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
25 changes: 19 additions & 6 deletions packages/open-next/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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*",
Expand Down Expand Up @@ -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}`);
}
}
}

0 comments on commit fd2a90d

Please sign in to comment.