Skip to content

Commit d89a30c

Browse files
committed
feat: improve runCommand to support multiple package managers
1 parent 6ef6218 commit d89a30c

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/index.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,28 @@ type ExtraTool = {
232232
command?: string;
233233
};
234234

235-
function runCommand(command: string, cwd: string) {
235+
function runCommand(command: string, cwd: string, packageManager: string) {
236+
// Replace `npm create` with the equivalent command for the detected package manager
237+
if (command.startsWith('npm create ')) {
238+
const createReplacements: Record<string, string> = {
239+
bun: 'bun create ',
240+
pnpm: 'pnpm create ',
241+
yarn: 'yarn create ',
242+
deno: 'deno run -A npm:create-',
243+
};
244+
const replacement = createReplacements[packageManager];
245+
if (replacement) {
246+
command = command
247+
.replace(/^npm create /, replacement)
248+
// other package managers don't need the extra `--`
249+
.replace(/ -- --/, ' --');
250+
}
251+
// Yarn v1 does not support `@latest` tag
252+
if (packageManager === 'yarn') {
253+
command = command.replace('@latest', '');
254+
}
255+
}
256+
236257
const [bin, ...args] = command.split(' ');
237258
spawn.sync(bin, args, {
238259
stdio: 'inherit',
@@ -386,7 +407,7 @@ export async function create({
386407
});
387408
}
388409
if (matchedTool.command) {
389-
runCommand(matchedTool.command, distFolder);
410+
runCommand(matchedTool.command, distFolder, packageManager);
390411
}
391412
continue;
392413
}

0 commit comments

Comments
 (0)