diff --git a/packages/schema/src/cli/actions/repl.ts b/packages/schema/src/cli/actions/repl.ts index 6ca3c3503..df15e30fb 100644 --- a/packages/schema/src/cli/actions/repl.ts +++ b/packages/schema/src/cli/actions/repl.ts @@ -2,7 +2,6 @@ /* eslint-disable @typescript-eslint/no-var-requires */ import colors from 'colors'; import path from 'path'; -import prettyRepl from 'pretty-repl'; import { inspect } from 'util'; // inspired by: https://github.com/Kinjalrk2k/prisma-console @@ -11,6 +10,13 @@ import { inspect } from 'util'; * CLI action for starting a REPL session */ export async function repl(projectPath: string, options: { prismaClient?: string; debug?: boolean; table?: boolean }) { + if (!process?.stdout?.isTTY && process?.versions?.bun) { + console.error('REPL on Bun is only available in a TTY terminal at this time. Please use npm/npx to run the command in this context instead of bun/bunx.'); + return; + } + + const prettyRepl = await import('pretty-repl') + console.log('Welcome to ZenStack REPL. See help with the ".help" command.'); console.log('Global variables:'); console.log(` ${colors.blue('db')} to access enhanced PrismaClient`); diff --git a/packages/schema/src/plugins/prisma/schema-generator.ts b/packages/schema/src/plugins/prisma/schema-generator.ts index 2aa426b57..881983caa 100644 --- a/packages/schema/src/plugins/prisma/schema-generator.ts +++ b/packages/schema/src/plugins/prisma/schema-generator.ts @@ -47,7 +47,7 @@ import stripColor from 'strip-color'; import { name } from '.'; import { getStringLiteral } from '../../language-server/validator/utils'; import telemetry from '../../telemetry'; -import { execSync } from '../../utils/exec-utils'; +import { execPackage } from '../../utils/exec-utils'; import { findPackageJson } from '../../utils/pkg-utils'; import { ModelFieldType, @@ -127,7 +127,7 @@ export default class PrismaSchemaGenerator { if (options.format === true) { try { // run 'prisma format' - await execSync(`npx prisma format --schema ${outFile}`); + await execPackage(`prisma format --schema ${outFile}`); } catch { warnings.push(`Failed to format Prisma schema file`); } @@ -136,18 +136,18 @@ export default class PrismaSchemaGenerator { const generateClient = options.generateClient !== false; if (generateClient) { - let generateCmd = `npx prisma generate --schema "${outFile}"`; + let generateCmd = `prisma generate --schema "${outFile}"`; if (typeof options.generateArgs === 'string') { generateCmd += ` ${options.generateArgs}`; } try { // run 'prisma generate' - await execSync(generateCmd, 'ignore'); + await execPackage(generateCmd, 'ignore'); } catch { await this.trackPrismaSchemaError(outFile); try { // run 'prisma generate' again with output to the console - await execSync(generateCmd); + await execPackage(generateCmd); } catch { // noop } diff --git a/packages/schema/src/utils/exec-utils.ts b/packages/schema/src/utils/exec-utils.ts index f355ae2b4..8f0508dbb 100644 --- a/packages/schema/src/utils/exec-utils.ts +++ b/packages/schema/src/utils/exec-utils.ts @@ -7,3 +7,12 @@ export function execSync(cmd: string, stdio: StdioOptions = 'inherit', env?: Rec const mergedEnv = { ...process.env, ...env }; _exec(cmd, { encoding: 'utf-8', stdio, env: mergedEnv }); } + +/** + * Utility for running package commands through npx/bunx + */ +export function execPackage(cmd: string, stdio: StdioOptions = 'inherit', env?: Record): void { + const packageManager = process?.versions?.bun ? 'bunx' : 'npx'; + const mergedEnv = { ...process.env, ...env }; + _exec(`${packageManager} ${cmd}`, { encoding: 'utf-8', stdio, env: mergedEnv }); +} \ No newline at end of file