Skip to content
8 changes: 7 additions & 1 deletion packages/schema/src/cli/actions/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`);
Expand Down
6 changes: 4 additions & 2 deletions packages/schema/src/plugins/prisma/schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ export default class PrismaSchemaGenerator {
}
await writeFile(outFile, this.PRELUDE + prisma.toString());

const packageManager = process?.versions?.bun ? 'bunx' : 'npx';

if (options.format === true) {
try {
// run 'prisma format'
await execSync(`npx prisma format --schema ${outFile}`);
await execSync(`${packageManager} prisma format --schema ${outFile}`);
} catch {
warnings.push(`Failed to format Prisma schema file`);
}
Expand All @@ -136,7 +138,7 @@ export default class PrismaSchemaGenerator {
const generateClient = options.generateClient !== false;

if (generateClient) {
let generateCmd = `npx prisma generate --schema "${outFile}"`;
let generateCmd = `${packageManager} prisma generate --schema "${outFile}"`;
if (typeof options.generateArgs === 'string') {
generateCmd += ` ${options.generateArgs}`;
}
Expand Down