Skip to content

Commit

Permalink
fix(client): usage with .pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Apr 28, 2020
1 parent 33fe1cb commit 2be6b71
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/packages/client/src/generation/generateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export async function buildClient({
function getDotPrismaDir(outputDir: string): string {
if (
process.env.INIT_CWD &&
!process.cwd().includes('.pnpm') &&
process.env.npm_lifecycle_hook === 'postinstall'
process.env.npm_lifecycle_event === 'postinstall' &&
!process.env.PWD?.includes('.pnpm')
) {
return path.join(process.env.INIT_CWD, 'node_modules/.prisma/client')
}
Expand All @@ -125,14 +125,13 @@ export async function generateClient({
clientVersion,
engineVersion,
}: GenerateClientOptions): Promise<BuildClientResult | undefined> {
const useDotPrisma =
!generator?.isCustomOutput || (testMode && !process.cwd().includes('.pnpm'))
const useDotPrisma = !generator?.isCustomOutput || testMode

runtimePath =
runtimePath || (useDotPrisma ? '@prisma/client/runtime' : './runtime')

const finalOutputDir = useDotPrisma ? getDotPrismaDir(outputDir) : outputDir
debug({ outputDir, finalOutputDir })
debug({ useDotPrisma, outputDir, finalOutputDir })

const { prismaClientDmmf, fileMap } = await buildClient({
datamodel,
Expand Down Expand Up @@ -259,6 +258,36 @@ export async function generateClient({
await copyFile(datamodelPath, datamodelTargetPath)
}

const packageJsonTargetPath = path.join(finalOutputDir, 'package.json')
const pkgJson = JSON.stringify(
{
name: '.prisma/client',
main: 'index.js',
types: 'index.d.ts',
},
null,
2,
)
await writeFile(packageJsonTargetPath, pkgJson)

if (process.env.INIT_CWD) {
const backupPath = path.join(
process.env.INIT_CWD,
'node_modules/.prisma/client',
)
debug({ finalOutputDir, backupPath })
if (finalOutputDir !== backupPath) {
await copy({
from: finalOutputDir,
to: backupPath,
recursive: true,
parallelJobs: process.platform === 'win32' ? 1 : 20,
overwrite: true,
})
}
}
// }

if (transpile) {
await writeFile(path.join(outputDir, 'runtime/index.d.ts'), backup)
}
Expand Down
7 changes: 7 additions & 0 deletions src/packages/engine-core/src/NodeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ You may have to run ${chalk.greenBright(
if (fs.existsSync(parentDirName)) {
return parentDirName
}
const datamodelDirName = await this.getQueryEnginePath(
this.platform,
path.dirname(this.datamodelPath),
)
if (fs.existsSync(datamodelDirName)) {
return datamodelDirName
}
const cwdPath = await this.getQueryEnginePath(this.platform, this.cwd)
if (fs.existsSync(cwdPath)) {
return cwdPath
Expand Down

0 comments on commit 2be6b71

Please sign in to comment.