From 2c033f9540d4e9b7c252c0b35946991d36fabdc5 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Mills Date: Tue, 22 Mar 2022 10:29:32 +0100 Subject: [PATCH] fix(client): fix syntax error and simplify --- .../client/src/generation/utils/buildDirname.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/client/src/generation/utils/buildDirname.ts b/packages/client/src/generation/utils/buildDirname.ts index 23b20e0e8e3a..504918bc9f49 100644 --- a/packages/client/src/generation/utils/buildDirname.ts +++ b/packages/client/src/generation/utils/buildDirname.ts @@ -35,20 +35,16 @@ function buildDirnameFind(defaultRelativeOutdir: string, runtimePath: string) { return ` const { findSync } = require('${runtimePath}') +const fs = require('fs') -// some frameworks or bundlers disallow or totally remove __dirname +// some frameworks or bundlers replace or totally remove __dirname const hasDirname = typeof __dirname !== 'undefined' && __dirname !== '/' // will work in most cases, ie. if the client has not been bundled -const regularFilename = hasDirname ? findSync(__dirname, [ - ${JSON.stringify('schema.prisma')}, -], ['f'], ['d'], 1)[0]) : undefined +const regularDirname = hasDirname && fs.existsSync(path.join(__dirname, 'schema.prisma')) && __dirname -// here we just ditch the filename as we just want the directory -const regularDirname = regularFilename ? path.dirname(regularFilename) : undefined - -// if the client has been bundled, we need to look for the folder -const foundDirname = findSync(process.cwd(), [ +// if the client has been bundled, we need to look for the folders +const foundDirname = !regularDirname && findSync(process.cwd(), [ ${defaultRelativeOutdir ? `${JSON.stringify(defaultRelativeOutdir)},` : ''} ${serverlessRelativeOutdir ? `${JSON.stringify(serverlessRelativeOutdir)},` : ''} ], ['d'], ['d'], 1)[0]