MCPcopy
hub / github.com/microsoft/vscode-js-debug / PackageJsonProvider

Class PackageJsonProvider

src/targets/node/packageJsonProvider.ts:48–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46
47@injectable()
48export class PackageJsonProvider implements IPackageJsonProvider {
49 constructor(
50 @inject(IFsUtils) private readonly fs: IFsUtils,
51 @inject(AnyLaunchConfiguration) private readonly config: AnyLaunchConfiguration,
52 ) {}
53
54 /**
55 * Gets the package.json for the debugged program.
56 */
57 public readonly getPath = once(async () => {
58 if (this.config.type !== DebugType.Node || this.config.request !== 'launch') {
59 return;
60 }
61
62 const dir = await nearestDirectoryContaining(this.fs, this.config.cwd, 'package.json');
63 return dir ? join(dir, 'package.json') : undefined;
64 });
65
66 /**
67 * Gets the package.json contents for the debugged program.
68 */
69 public readonly getContents = once(async () => {
70 const path = await this.getPath();
71 if (!path) {
72 return;
73 }
74
75 try {
76 const contents = await this.fs.readFile(path);
77 return JSON.parse(contents.toString()) as IPackageJson;
78 } catch {
79 return;
80 }
81 });
82}

Callers

nothing calls this directly

Calls 6

onceFunction · 0.90
getPathMethod · 0.80
readFileMethod · 0.65
parseMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected