Skip to content

Commit

Permalink
fix: use bun/bunx when running on bun
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikMCM committed Feb 14, 2024
1 parent ad18291 commit 42ffcf6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 4 additions & 2 deletions packages/misc/redwood/src/cli-passthrough.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ async function runCommand(command: string, options: any) {
}
}

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

console.log();
console.log(colors.green('Running ZenStack CLI...'));
console.log(colors.underline('$ npx ' + args.join(' ')));
console.log(colors.underline(`$ ${packageExec} ` + args.join(' ')));
console.log();

try {
await execa('npx', args, { cwd: getPaths().api.base, shell: true, stdio: 'inherit', cleanup: true });
await execa(packageExec, args, { cwd: getPaths().api.base, shell: true, stdio: 'inherit', cleanup: true });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
process.exit(e?.exitCode || 1);
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 packageExec = process?.versions?.bun ? 'bunx' : 'npx';

if (options.format === true) {
try {
// run 'prisma format'
await execSync(`npx prisma format --schema ${outFile}`);
await execSync(`${packageExec} 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 = `${packageExec} prisma generate --schema "${outFile}"`;
if (typeof options.generateArgs === 'string') {
generateCmd += ` ${options.generateArgs}`;
}
Expand Down
15 changes: 9 additions & 6 deletions packages/testtools/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,23 @@ export async function loadSchema(schema: string, options?: SchemaLoadOptions) {
}
}

run('npm install');
const packageManager = process?.versions?.bun ? 'bun' : 'npm';
const packageExec = packageManager === 'bun' ? 'bunx' : 'npx';

run(`${packageManager} install`);

const outputArg = opt.output ? ` --output ${opt.output}` : '';

if (opt.customSchemaFilePath) {
run(`npx zenstack generate --schema ${zmodelPath} --no-dependency-check${outputArg}`, {
run(`${packageExec} zenstack generate --schema ${zmodelPath} --no-dependency-check${outputArg}`, {
NODE_PATH: './node_modules',
});
} else {
run(`npx zenstack generate --no-dependency-check${outputArg}`, { NODE_PATH: './node_modules' });
run(`${packageExec} zenstack generate --no-dependency-check${outputArg}`, { NODE_PATH: './node_modules' });
}

if (opt.pushDb) {
run('npx prisma db push');
run(`${packageExec} prisma db push`);
}

if (opt.pulseApiKey) {
Expand Down Expand Up @@ -233,7 +236,7 @@ export async function loadSchema(schema: string, options?: SchemaLoadOptions) {

if (opt.compile) {
console.log('Compiling...');
run('npx tsc --init');
run(`${packageExec} tsc --init`);

// add generated '.zenstack/zod' folder to typescript's search path,
// so that it can be resolved from symbolic-linked files
Expand All @@ -242,7 +245,7 @@ export async function loadSchema(schema: string, options?: SchemaLoadOptions) {
'.zenstack/zod/input': ['./node_modules/.zenstack/zod/input/index.d.ts'],
};
fs.writeFileSync(path.join(projectRoot, './tsconfig.json'), JSON.stringify(tsconfig, null, 2));
run('npx tsc --project tsconfig.json');
run(`${packageExec} tsc --project tsconfig.json`);
}

if (options?.getPrismaOnly) {
Expand Down

0 comments on commit 42ffcf6

Please sign in to comment.