( launchJsonFilePath: string | undefined, bazel: BazelClient, tsConfigDirs: readonly TsConfigDir[], )
| 364 | } |
| 365 | |
| 366 | async function processLaunchJSONFile( |
| 367 | launchJsonFilePath: string | undefined, |
| 368 | bazel: BazelClient, |
| 369 | tsConfigDirs: readonly TsConfigDir[], |
| 370 | ): Promise<void> { |
| 371 | const workspaceRoot = await bazel.getWorkspaceRoot(); |
| 372 | if (!launchJsonFilePath) { |
| 373 | launchJsonFilePath = path.join(workspaceRoot, '.vscode/launch.json'); |
| 374 | } |
| 375 | |
| 376 | let launchJsonFile: JSONCFile<VSCodeLaunchInfo>; |
| 377 | if (fsSync.existsSync(launchJsonFilePath)) { |
| 378 | const launchJsonFileContent = await fs.readFile(launchJsonFilePath, 'utf8'); |
| 379 | launchJsonFile = JSONCFile.parse(launchJsonFileContent); |
| 380 | } else { |
| 381 | launchJsonFile = JSONCFile.fromObject(DEFAULT_VSCODE_LAUNCH_JSON); |
| 382 | } |
| 383 | |
| 384 | const valdiLaunchConfigurationIndex = |
| 385 | launchJsonFile.value.configurations?.findIndex(c => c.name === VSCODE_VALDI_LAUNCH_CONFIGURATION.name) ?? -1; |
| 386 | let valdiLaunchConfiguration = |
| 387 | valdiLaunchConfigurationIndex >= 0 |
| 388 | ? launchJsonFile.value.configurations![valdiLaunchConfigurationIndex]! |
| 389 | : VSCODE_VALDI_LAUNCH_CONFIGURATION; |
| 390 | valdiLaunchConfiguration = { ...valdiLaunchConfiguration }; |
| 391 | valdiLaunchConfiguration.sourceMapPathOverrides = computeSourceMapPathOverrides(workspaceRoot, tsConfigDirs); |
| 392 | |
| 393 | if (valdiLaunchConfigurationIndex >= 0) { |
| 394 | launchJsonFile = launchJsonFile.updating( |
| 395 | ['configurations', valdiLaunchConfigurationIndex], |
| 396 | valdiLaunchConfiguration, |
| 397 | { |
| 398 | formattingOptions: { insertSpaces: true }, |
| 399 | }, |
| 400 | ); |
| 401 | } else if (launchJsonFile.value.configurations) { |
| 402 | launchJsonFile = launchJsonFile.updating( |
| 403 | ['configurations', launchJsonFile.value.configurations.length], |
| 404 | valdiLaunchConfiguration, |
| 405 | { |
| 406 | formattingOptions: { insertSpaces: true }, |
| 407 | isArrayInsertion: true, |
| 408 | }, |
| 409 | ); |
| 410 | } else { |
| 411 | launchJsonFile = launchJsonFile.updating(['configurations'], [valdiLaunchConfiguration], { |
| 412 | formattingOptions: { insertSpaces: true }, |
| 413 | }); |
| 414 | } |
| 415 | |
| 416 | const launchJsonFileDir = path.dirname(launchJsonFilePath); |
| 417 | if (!fsSync.existsSync(launchJsonFileDir)) { |
| 418 | await fs.mkdir(launchJsonFileDir, { recursive: true }); |
| 419 | } |
| 420 | await fs.writeFile(launchJsonFilePath, launchJsonFile.toJSONString()); |
| 421 | } |
| 422 | |
| 423 | export async function getAllProjectSyncTargets(bazel: BazelClient): Promise<string[]> { |
no test coverage detected