Skip to content

Commit

Permalink
fix(pm-i): don't modify global array!
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 24, 2024
1 parent cbf800f commit 977c2c3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/generators/pm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const INSTALL_COMMANDS = [
["yarn", "add"],
["pnpm", "install"],
["bun", "install"],
];
] as const;

const NYPM_COMMAND = ["npx nypm", "install"] as const;

const RUN_COMMANDS = [
["npm", "npx"],
["pnpm", "pnpm dlx"],
["bun", "bunx"],
];
] as const;

export const pmInstall = defineGenerator({
name: "pm-install",
Expand All @@ -26,17 +28,18 @@ export const pmInstall = defineGenerator({
};
}

if (args.auto ?? true) {
INSTALL_COMMANDS.unshift(["npx nypm", "i"]);
}

let versionSuffix = "";
if (args.version) {
versionSuffix =
typeof args.version === "string" ? `@${args.version}` : `@^${version}`;
}

const contents = INSTALL_COMMANDS.map(
const commands =
args.auto === false
? INSTALL_COMMANDS
: [NYPM_COMMAND, ...INSTALL_COMMANDS];

const contents = commands.map(
([cmd, install]) =>
`# ${cmd.includes("nypm") ? "✨ Auto-detect" : cmd}\n${cmd} ${install}${args.dev ? " -D" : ""} ${name}${versionSuffix}`,
);
Expand Down

0 comments on commit 977c2c3

Please sign in to comment.