diff --git a/src/postinstall.ts b/src/postinstall.ts index 9b5d735..58feec9 100644 --- a/src/postinstall.ts +++ b/src/postinstall.ts @@ -2,25 +2,24 @@ import { spawn } from "child_process"; type PackageManagers = "npm" | "pnpm" | "yarn1" | "yarn2"; -const PACKAGE_MANAGER_TO_COMMAND: Record = { - npm: "npx", - pnpm: "pnpm dlx", - yarn1: "npx", - yarn2: "yarn dlx", +const PACKAGE_MANAGER_TO_COMMAND: Record = { + npm: ["npx"], + pnpm: ["pnpm", "dlx"], + yarn1: ["npx"], + yarn2: ["yarn", "dlx"], }; -const selectPackageManagerCommand = (packageManager: PackageManagers): string => - PACKAGE_MANAGER_TO_COMMAND[packageManager]; +const selectPackageManagerCommand = ( + packageManager: PackageManagers +): string[] => PACKAGE_MANAGER_TO_COMMAND[packageManager]; const spawnPackageManagerScript = async ( packageManager: PackageManagers, args: string[] ) => { - const command = selectPackageManagerCommand(packageManager); + const [command, ...baseArgs] = selectPackageManagerCommand(packageManager); - const [pm, ...rest] = command.split(" "); - - await spawn(pm, [...rest, ...args], { + await spawn(command, [...baseArgs, ...args], { stdio: "inherit", cwd: process.cwd(), shell: true,