Skip to content

Commit

Permalink
Update postinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun Lloyd committed Oct 4, 2023
1 parent 0e159cd commit c9231b7
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ import { spawn } from "child_process";

type PackageManagers = "npm" | "pnpm" | "yarn1" | "yarn2";

const PACKAGE_MANAGER_TO_COMMAND: Record<PackageManagers, string> = {
npm: "npx",
pnpm: "pnpm dlx",
yarn1: "npx",
yarn2: "yarn dlx",
const PACKAGE_MANAGER_TO_COMMAND: Record<PackageManagers, string[]> = {
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,
Expand Down

0 comments on commit c9231b7

Please sign in to comment.