| 30 | * Utility for running prisma commands |
| 31 | */ |
| 32 | export function execPrisma(args: string, options?: Omit<ExecSyncOptions, 'env'> & { env?: Record<string, string> }) { |
| 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 |
| 44 | } |
| 45 | |
| 46 | const _options = { |
| 47 | ...options, |
| 48 | env: { |
| 49 | ...options?.env, |
| 50 | PRISMA_HIDE_UPDATE_MESSAGE: '1', |
| 51 | }, |
| 52 | }; |
| 53 | |
| 54 | if (!prismaPath) { |
| 55 | // fallback to npx/bunx execute |
| 56 | execPackage(`prisma ${args}`, _options); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | execSync(`node "${prismaPath}" ${args}`, _options); |
| 61 | } |