Skip to content

Commit dc53b11

Browse files
authored
fix(cli): add a npx/bunx fallback for running prisma commands (#409)
1 parent 9e3964d commit dc53b11

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

packages/cli/src/utils/exec-utils.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,24 @@ export function execPackage(
3030
* Utility for running prisma commands
3131
*/
3232
export function execPrisma(args: string, options?: Omit<ExecSyncOptions, 'env'> & { env?: Record<string, string> }) {
33-
let prismaPath: string;
34-
if (typeof import.meta.resolve === 'function') {
35-
// esm
36-
prismaPath = fileURLToPath(import.meta.resolve('prisma/build/index.js'));
37-
} else {
38-
// cjs
39-
prismaPath = require.resolve('prisma/build/index.js');
33+
let prismaPath: string | undefined;
34+
try {
35+
if (typeof import.meta.resolve === 'function') {
36+
// esm
37+
prismaPath = fileURLToPath(import.meta.resolve('prisma/build/index.js'));
38+
} else {
39+
// cjs
40+
prismaPath = require.resolve('prisma/build/index.js');
41+
}
42+
} catch {
43+
// ignore and fallback
4044
}
45+
46+
if (!prismaPath) {
47+
// fallback to npx/bunx execute
48+
execPackage(`prisma ${args}`, options);
49+
return;
50+
}
51+
4152
execSync(`node ${prismaPath} ${args}`, options);
4253
}

0 commit comments

Comments
 (0)