()
| 372 | } |
| 373 | |
| 374 | private internalInit(): Promise<void> { |
| 375 | // eslint-disable-next-line no-async-promise-executor |
| 376 | return new Promise(async (resolve, reject) => { |
| 377 | try { |
| 378 | const { PWD, ...processEnv } = process.env |
| 379 | const binaryPath = await resolveBinary(BinaryType.SchemaEngineBinary) |
| 380 | debugRpc('starting Schema engine with binary: ' + binaryPath) |
| 381 | const args: string[] = [] |
| 382 | |
| 383 | if (this.schemaContext) { |
| 384 | // list of paths to the schema files |
| 385 | const schemaArgs = this.schemaContext.schemaFiles.flatMap(([path]) => ['--datamodels', path]) |
| 386 | args.push(...schemaArgs) |
| 387 | } |
| 388 | |
| 389 | if (this.datasource) { |
| 390 | args.push(...['--datasource', JSON.stringify(this.datasource)]) |
| 391 | } |
| 392 | |
| 393 | if ( |
| 394 | this.enabledPreviewFeatures && |
| 395 | Array.isArray(this.enabledPreviewFeatures) && |
| 396 | this.enabledPreviewFeatures.length > 0 |
| 397 | ) { |
| 398 | args.push(...['--enabled-preview-features', this.enabledPreviewFeatures.join(',')]) |
| 399 | } |
| 400 | |
| 401 | if (this.extensionConfig) { |
| 402 | args.push(...['--extension-types', JSON.stringify(this.extensionConfig)]) |
| 403 | } |
| 404 | |
| 405 | this.child = spawn(binaryPath, args, { |
| 406 | cwd: this.baseDir, |
| 407 | stdio: ['pipe', 'pipe', this.debug ? process.stderr : 'pipe'], |
| 408 | env: { |
| 409 | // The following environment variables can be overridden by the user. |
| 410 | RUST_LOG: 'info', |
| 411 | RUST_BACKTRACE: '1', |
| 412 | // Take env values from process.env (will override values set before) |
| 413 | ...processEnv, |
| 414 | }, |
| 415 | }) |
| 416 | |
| 417 | this.isRunning = true |
| 418 | |
| 419 | this.child.on('error', (err) => { |
| 420 | console.error('[schema-engine] error: %s', err) |
| 421 | this.rejectAll(err) |
| 422 | reject(err) |
| 423 | }) |
| 424 | |
| 425 | this.child.on('exit', (code: number | null): void => { |
| 426 | const exitWithErr = (err: RustPanic | Error): void => { |
| 427 | this.rejectAll(err) |
| 428 | reject(err) |
| 429 | } |
| 430 | const processMessages = this.messages.join('\n') |
| 431 | const engineMessage = this.lastError?.message || processMessages |
no test coverage detected