Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getPrismaPath(): Promise {
// tslint:disable-next-line
if (process.env.PRISMA_QUERY_ENGINE_BINARY) {
if (!fs.existsSync(process.env.PRISMA_QUERY_ENGINE_BINARY)) {
throw new Error(
`Env var PRISMA_QUERY_ENGINE_BINARY is provided but provided path ${process.env.PRISMA_QUERY_ENGINE_BINARY} can't be resolved.`,
)
}
return process.env.PRISMA_QUERY_ENGINE_BINARY
}
const dir = eval('__dirname')
const platform = await getPlatform()
const extension = platform === 'windows' ? '.exe' : ''
const relative = `query-engine-${platform}${extension}`
let prismaPath = path.join(dir, '..', relative)
if (fs.existsSync(prismaPath)) {
return prismaPath
}
// for pkg
prismaPath = path.join(dir, '../..', relative)
if (fs.existsSync(prismaPath)) {
return prismaPath
}
prismaPath = path.join(__dirname, '..', relative)
if (fs.existsSync(prismaPath)) {
return prismaPath
}
async function getPrismaPath(): Promise {
// tslint:disable-next-line
const dir = eval('__dirname')
const platform = await getPlatform()
const extension = (platform === 'windows') ? '.exe' : ''
const relative = `../query-engine-${platform}${extension}`
return path.join(dir, relative)
}
async function getMigrationEnginePath(): Promise {
// tslint:disable-next-line
const dir = eval('__dirname')
const platform = await getPlatform()
const extension = platform === 'windows' ? '.exe' : ''
const relative = `../migration-engine${extension}`
return path.join(dir, relative)
}
public async start(providerAliases: ProviderAliases): Promise {
try {
if (this.instance) {
throw new Error(`Studio is already started`)
}
const platform = await getPlatform()
const extension = platform === 'windows' ? '.exe' : ''
const pathCandidates = [
// ncc go home
// tslint:disable-next-line
eval(`require('path').join(__dirname, '../node_modules/@prisma/sdk/query-engine-${platform}${extension}')`), // for local dev
// tslint:disable-next-line
eval(`require('path').join(__dirname, '../query-engine-${platform}${extension}')`), // for production
]
const pathsExist = await Promise.all(
pathCandidates.map(async candidate => ({ exists: fs.existsSync(candidate), path: candidate })),
)
const firstExistingPath = pathsExist.find(p => p.exists)
private async getBinaryPath() {
if (this.binaryPath) {
return this.binaryPath
}
const platform = await getPlatform()
const extension = platform === 'windows' ? '.exe' : ''
this.binaryPath = path.join(
eval(`require('path').join(__dirname, '../')`),
`introspection-engine-${platform}${extension}`,
)
if (!fs.existsSync(this.binaryPath)) {
throw new Error(
`Expected introspection engine at ${this.binaryPath} does not exist.`,
)
}
return this.binaryPath
}
private internalInit(): Promise {
async function validateGenerators(generators: GeneratorConfig[]) {
const platform = await getPlatform()
for (const generator of generators) {
if (generator.provider === 'nexus-prisma') {
throw new Error(
'`nexus-prisma` is no longer a generator. You can read more at https://pris.ly/nexus-prisma-upgrade-0.4',
)
}
if (generator.config.platforms) {
throw new Error(
`The \`platforms\` field on the generator definition is deprecated. Please rename it to \`binaryTargets\`.`,
)
}
if (generator.config.pinnedPlatform) {
throw new Error(
`The \`pinnedPlatform\` field on the generator definition is deprecated.
Please use the PRISMA_QUERY_ENGINE_BINARY env var instead to pin the binary target.`,
`Project dir missing. Usage: ts-node examples/generate.ts examples/accounts`,
)
}
if (!fs.existsSync(projectDir)) {
throw new Error(`Path ${projectDir} does not exist`)
}
const schemaPath = getSchemaPath(projectDir)
const datamodel = fs.readFileSync(schemaPath, 'utf-8')
const dmmf = await getDMMF({ datamodel })
const config = await getConfig({ datamodel })
const outputDir = path.join(projectDir, 'node_modules/@prisma/photon')
await getPackedPackage('@prisma/photon', outputDir)
const platform = await getPlatform()
await generateClient({
binaryPaths: {
queryEngine: {
[platform]: path.join(
__dirname,
`../../query-engine-${platform}${
platform === 'windows' ? '.exe' : ''
}`,
),
},
},
datamodel,
dmmf,
...config,
outputDir,
async getPlatform() {
if (this.platformPromise) {
return this.platformPromise
}
this.platformPromise = getPlatform()
return this.platformPromise
}
export async function sendPanic(error: LiftPanic, cliVersion: string, binaryVersion: string): Promise {
try {
const schema = fs.readFileSync(error.schemaPath, 'utf-8')
const maskedSchema = maskSchema(schema)
const signedUrl = await createErrorReport({
area: ErrorArea.LIFT_CLI,
kind: ErrorKind.RUST_PANIC,
cliVersion,
binaryVersion,
command: process.argv.slice(2).join(' '),
jsStackTrace: stripAnsi(error.stack || error.message),
rustStackTrace: error.rustStack,
operatingSystem: `${os.arch()} ${os.platform()} ${os.release()}`,
platform: await getPlatform(),
liftRequest: JSON.stringify(error.request),
schemaFile: maskedSchema,
fingerprint: getFid() || undefined,
})
const zip = await makeErrorZip(error)
await uploadZip(zip, signedUrl)
const id = await makeErrorReportCompleted(signedUrl)
return id
} catch (e) {
debug(e)
}
}
const compatiblePlatforms = knownPlatforms.slice(1).filter(p => mayBeCompatible(p, platform))
const binariesExist = await Promise.all(