Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions packages/cli/src/utils/exec-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,24 @@ export function execPackage(
* Utility for running prisma commands
*/
export function execPrisma(args: string, options?: Omit<ExecSyncOptions, 'env'> & { env?: Record<string, string> }) {
let prismaPath: string;
if (typeof import.meta.resolve === 'function') {
// esm
prismaPath = fileURLToPath(import.meta.resolve('prisma/build/index.js'));
} else {
// cjs
prismaPath = require.resolve('prisma/build/index.js');
let prismaPath: string | undefined;
try {
if (typeof import.meta.resolve === 'function') {
// esm
prismaPath = fileURLToPath(import.meta.resolve('prisma/build/index.js'));
} else {
// cjs
prismaPath = require.resolve('prisma/build/index.js');
}
} catch {
// ignore and fallback
}

if (!prismaPath) {
// fallback to npx/bunx execute
execPackage(`prisma ${args}`, options);
return;
}

execSync(`node ${prismaPath} ${args}`, options);
}
Loading