From 1fc92bd08636c07d0acb69fd5d10f60d0b5babc4 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Wed, 15 May 2024 14:07:47 +0900 Subject: [PATCH] fix: support bun in addition to tsx --- src/commands/run.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/commands/run.ts b/src/commands/run.ts index 12b98301..ace0b0ed 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -28,15 +28,18 @@ export const run: CommandModule> = const file = argv.file?.toString() || ''; - const args = ['--no-warnings', '--import', 'tsx', file]; + const isRunningOnBun = process.argv[0].endsWith('/bun'); + const runtime = isRunningOnBun ? 'bun' : 'node'; + const args = isRunningOnBun ? [] : ['--no-warnings', '--import', 'tsx', file]; if (argv.watch) { args.push('--watch'); } const [, ...additionalArguments] = argv._; + const runtimeArgs = [...args, ...additionalArguments.map((arg) => arg.toString())]; if (argv.verbose) { - console.info(`Running 'node ${[...args, ...additionalArguments.map((arg) => arg.toString())].join(' ')}'`); + console.info(`Running '${runtime} ${runtimeArgs.join(' ')}'`); } - const ret = child_process.spawnSync('node', [...args, ...additionalArguments.map((arg) => arg.toString())], { + const ret = child_process.spawnSync(runtime, runtimeArgs, { stdio: 'inherit', env: { ...process.env, NODE_NO_WARNINGS: '1' }, });