MCPcopy Create free account
hub / github.com/Snapchat/Valdi / processLaunchJSONFile

Function processLaunchJSONFile

npm_modules/cli/src/commands/projectsync.ts:366–421  ·  view source on GitHub ↗
(
  launchJsonFilePath: string | undefined,
  bazel: BazelClient,
  tsConfigDirs: readonly TsConfigDir[],
)

Source from the content-addressed store, hash-verified

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
385async 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,

Callers 1

runProjectSyncFunction · 0.85

Calls 9

getWorkspaceRootMethod · 0.80
fromObjectMethod · 0.80
updatingMethod · 0.80
toJSONStringMethod · 0.80
readFileMethod · 0.65
writeFileMethod · 0.65
joinMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected