(name: BinaryType, proposedPath?: string)
| 19 | } |
| 20 | |
| 21 | export async function resolveBinary(name: BinaryType, proposedPath?: string): Promise<string> { |
| 22 | // if file exists at proposedPath (and does not start with `/snapshot/` (= pkg), use that one |
| 23 | if (proposedPath && !proposedPath.match(vercelPkgPathRegex) && fs.existsSync(proposedPath)) { |
| 24 | return proposedPath |
| 25 | } |
| 26 | |
| 27 | // If engine path was provided via env var, check and use that one |
| 28 | const pathFromEnvVar = getBinaryEnvVarPath(name) |
| 29 | if (pathFromEnvVar !== null) { |
| 30 | return pathFromEnvVar.path |
| 31 | } |
| 32 | |
| 33 | // If still here, try different paths |
| 34 | const binaryName = await getBinaryName(name) |
| 35 | |
| 36 | const prismaPath = path.join(getEnginesPath(), binaryName) |
| 37 | if (fs.existsSync(prismaPath)) { |
| 38 | return maybeCopyToTmp(prismaPath) |
| 39 | } |
| 40 | |
| 41 | // for pkg (related: https://github.com/vercel/pkg#snapshot-filesystem) |
| 42 | const prismaPath2 = path.join(__dirname, '..', binaryName) |
| 43 | if (fs.existsSync(prismaPath2)) { |
| 44 | return maybeCopyToTmp(prismaPath2) |
| 45 | } |
| 46 | |
| 47 | // TODO for ?? |
| 48 | const prismaPath3 = path.join(__dirname, '../..', binaryName) |
| 49 | if (fs.existsSync(prismaPath3)) { |
| 50 | return maybeCopyToTmp(prismaPath3) |
| 51 | } |
| 52 | |
| 53 | // TODO for ?? / needed to come from @prisma/client/generator-build to @prisma/client/runtime |
| 54 | const prismaPath4 = path.join(__dirname, '../runtime', binaryName) |
| 55 | if (fs.existsSync(prismaPath4)) { |
| 56 | return maybeCopyToTmp(prismaPath4) |
| 57 | } |
| 58 | |
| 59 | // Still here? Could not find the engine, so error out. |
| 60 | throw new Error( |
| 61 | `Could not find ${name} binary. Searched in: |
| 62 | - ${prismaPath} |
| 63 | - ${prismaPath2} |
| 64 | - ${prismaPath3} |
| 65 | - ${prismaPath4}`, |
| 66 | ) |
| 67 | } |
| 68 | |
| 69 | export function safeResolveBinary(name: BinaryType, proposedPath?: string): TE.TaskEither<Error, string> { |
| 70 | return TE.tryCatch( |
no test coverage detected