Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: zenstack cli errors while using bun/bunx during docker build #1011

Merged
merged 9 commits into from
Feb 19, 2024
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}`);
ErikMCM marked this conversation as resolved.
Show resolved Hide resolved
} 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