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