(ctx: QuirkContext)
| 144 | export const prismaQuirk: Quirk = { |
| 145 | dependency: 'prisma', |
| 146 | async run(ctx: QuirkContext): Promise<QuirkResult> { |
| 147 | const { venvPath, pythonEnv, workPath } = ctx; |
| 148 | const pythonPath = getVenvPythonBin(venvPath); |
| 149 | |
| 150 | // The runtime cache dir is where the engine binary and openssl shim |
| 151 | // will live inside the Lambda bundle. Derived from resolveVendorDir() |
| 152 | // so it stays in sync with the vendor directory used by the builder. |
| 153 | const runtimeCacheDir = join( |
| 154 | LAMBDA_ROOT, |
| 155 | resolveVendorDir(), |
| 156 | 'prisma', |
| 157 | '__bincache__' |
| 158 | ); |
| 159 | |
| 160 | // 1. Find the site-packages directory that actually contains prisma. |
| 161 | // getVenvSitePackagesDirs() can return multiple dirs (e.g. virtualenv |
| 162 | // with system site-packages); we must operate on the one where prisma |
| 163 | // is installed so that cache paths and RECORD patching target the |
| 164 | // correct location. |
| 165 | const sitePackagesDirs = await getVenvSitePackagesDirs(venvPath); |
| 166 | let sitePackages: string | undefined; |
| 167 | for (const dir of sitePackagesDirs) { |
| 168 | try { |
| 169 | await fs.promises.access(join(dir, 'prisma')); |
| 170 | sitePackages = dir; |
| 171 | break; |
| 172 | } catch { |
| 173 | // not in this dir |
| 174 | } |
| 175 | } |
| 176 | if (!sitePackages) { |
| 177 | console.warn( |
| 178 | 'prisma: could not find prisma in any site-packages directory' |
| 179 | ); |
| 180 | return {}; |
| 181 | } |
| 182 | |
| 183 | // 2. Create cache directory inside prisma package |
| 184 | const cacheDir = join(sitePackages, 'prisma', '__bincache__'); |
| 185 | await fs.promises.mkdir(cacheDir, { recursive: true }); |
| 186 | |
| 187 | const generateEnv = { |
| 188 | ...pythonEnv, |
| 189 | PRISMA_BINARY_CACHE_DIR: cacheDir, |
| 190 | }; |
| 191 | |
| 192 | // 3. Write dummy schema to force downloading engine binaries for |
| 193 | // the Lambda target platforms via binaryTargets. |
| 194 | // Generated output goes to workPath (NOT inside site-packages/prisma/) |
| 195 | // to avoid copytree recursion when the generator copies the prisma package. |
| 196 | const generatedDir = join(workPath, '_prisma_generated'); |
| 197 | const dummySchemaPath = join(workPath, DUMMY_SCHEMA_NAME); |
| 198 | await fs.promises.writeFile( |
| 199 | dummySchemaPath, |
| 200 | buildDummySchema(generatedDir) |
| 201 | ); |
| 202 | |
| 203 | // 4. Run `python -m prisma generate --schema=<dummy>` with |
nothing calls this directly
no test coverage detected