CodeGraph/docs
Section 2.4

Metadata Extraction

Extracting declared dependencies from package.json manifests and path aliases from tsconfig.json and jsconfig.json to power import resolution.

Source: server/src/parser/extractors/PackageJsonExtractor.ts

PackageJsonExtractor

PackageJsonExtractor parses project manifests using standard JSON.parse. It normalizes dependencies and devDependencies objects into flat arrays of{ name, version }:

server/src/parser/extractors/PackageJsonExtractor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
export class PackageJsonExtractor { extract(filePath: string): ParsedPackageJson { const fileContent = fs.readFileSync(filePath, "utf-8"); const parsedJson = JSON.parse(fileContent); return { name: parsedJson.name, dependencies: this.extractDependencies(parsedJson.dependencies || {}), devDependencies: this.extractDependencies(parsedJson.devDependencies || {}), filePath, }; } private extractDependencies(dependencies: Record<string, string>): ParsedDependency[] { return Object.entries(dependencies).map(([name, version]) => ({ name, version })); } }

PathConfigExtractor & JSONC Support

Unlike standard JSON files, tsconfig.json and jsconfig.json files frequently contain comments (// or /* */) and trailing commas. Standard JSON.parsewould throw syntax errors.

CodeGraph utilizes Microsoft's jsonc-parser library to parse comments safely and transforms the compilerOptions.paths map into an array of PathAlias rules:

server/src/parser/extractors/PathConfigExtractor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export class PathConfigExtractor { extract(filePath: string): ParsedPathConfig { const fileContent = fs.readFileSync(filePath, "utf-8"); const parsedJson = parse(fileContent); // jsonc-parser return { baseUrl: parsedJson.compilerOptions?.baseUrl, pathAliases: this.extractPathAliases(parsedJson.compilerOptions?.paths || {}), filePath, }; } private extractPathAliases(paths: Record<string, string[]>): PathAlias[] { return Object.entries(paths).map(([alias, paths]) => ({ alias, paths })); } }

The `RepositoryMetadata` Object

Both configuration sources are merged into a single metadata container passed to Stage 5:

server/src/parser/models/RepositoryMetadata.ts
1
2
3
4
export interface RepositoryMetadata { packageJsons: ParsedPackageJson[]; pathConfigs: ParsedPathConfig[]; }
Downstream Consumer
This metadata is not used immediately in Stage 4. It is passed downstream to Stage 5 (Relationship Extraction), where the findNearestPathConfig() and findNearestPackageJson() helpers use it to resolve path aliases (e.g. @/components/*) and identify external vs module imports.