Skip to content

Commit 222493d

Browse files
committed
feat:(ts) update uniast
1 parent 244f149 commit 222493d

5 files changed

Lines changed: 29 additions & 15 deletions

File tree

ts-parser/package-lock.json

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts-parser/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "abcoder-ts-parser",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "TypeScript AST parser for UNIAST v0.1.3 specification",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -43,4 +43,4 @@
4343
"ts-node": "^10.9.0",
4444
"typescript": "^5.0.0"
4545
}
46-
}
46+
}

ts-parser/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const program = new Command();
1010
program
1111
.name('abcoder-ts-parser')
1212
.description('TypeScript AST parser for UNIAST v0.1.3 specification')
13-
.version('1.0.0');
13+
.version('0.0.4');
1414

1515
program
1616
.command('parse')
@@ -25,14 +25,14 @@ program
2525
.action(async (directory, options) => {
2626
try {
2727
const repoPath = path.resolve(directory);
28-
28+
2929
if (!fs.existsSync(repoPath)) {
3030
console.error(`Error: Directory ${repoPath} does not exist`);
3131
process.exit(1);
3232
}
3333

3434
console.log(`Parsing TypeScript repository: ${repoPath}`);
35-
35+
3636
const parser = new RepositoryParser(repoPath, options.tsconfig);
3737
const repository = await parser.parseRepository(repoPath, {
3838
loadExternalSymbols: false,
@@ -43,12 +43,12 @@ program
4343

4444
// Output the repository JSON file
4545
const outputPath = path.resolve(options.output);
46-
const jsonOutput = options.pretty
46+
const jsonOutput = options.pretty
4747
? JSON.stringify(repository, null, 2)
4848
: JSON.stringify(repository);
4949

5050
fs.writeFileSync(outputPath, jsonOutput);
51-
51+
5252
console.log(`Successfully parsed repository`);
5353
console.log(`Output written to: ${outputPath}`);
5454
console.log(`Total modules: ${Object.keys(repository.Modules).length}`);

ts-parser/src/types/uniast.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
* Root object representing an entire code repository.
1010
*/
1111
export interface Repository {
12-
/** UNIAST specification version. Fixed to "v0.1.3". */
13-
ASTVersion: string;
1412
/** Unique identifier for the repository. Field name in JSON is "id". */
1513
id: string;
14+
/** UNIAST specification version. Fixed to "v0.1.3". */
15+
ASTVersion: string;
16+
/** abcoder version used to parse the repository. Field name in JSON is "ToolVersion". */
17+
ToolVersion: string;
18+
/** File directory of the repository, usually should be an absolute path. */
19+
Path: string;
1620
/** Map of all modules in the repository. Keys are unique path identifiers. */
1721
Modules: Record<string, Module>;
1822
/**

ts-parser/src/utils/package-processor.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ export class ProjectFactory {
371371
* Handles tsconfig.json resolution and project references
372372
*/
373373
static createProjectForSingleRepo(
374-
projectRoot: string,
374+
projectRoot: string,
375375
tsConfigPath?: string,
376376
tsConfigCache?: TsConfigCache
377377
): Project {
@@ -492,7 +492,7 @@ export class ProjectFactory {
492492
return false;
493493
}
494494
});
495-
495+
496496
if (existingFiles.length > 0) {
497497
try {
498498
project.addSourceFilesAtPaths(existingFiles);
@@ -523,7 +523,8 @@ export class ProjectFactory {
523523
* Repository Factory - Centralized creation of Repository objects
524524
*/
525525
export class RepositoryFactory {
526-
private static readonly AST_VERSION = 'v0.1.3';
526+
private static AST_VERSION = process.env.ABCODER_AST_VERSION || 'unknown';
527+
private static TOOL_VERSION = process.env.ABCODER_TOOL_VERSION || 'unknown';
527528

528529
/**
529530
* Create a repository for a single project/repository
@@ -532,7 +533,9 @@ export class RepositoryFactory {
532533
const absolutePath = path.resolve(repoPath);
533534
return {
534535
ASTVersion: RepositoryFactory.AST_VERSION,
536+
ToolVersion: RepositoryFactory.TOOL_VERSION,
535537
id: path.basename(absolutePath),
538+
Path: absolutePath,
536539
Modules: {},
537540
Graph: {},
538541
};
@@ -544,6 +547,8 @@ export class RepositoryFactory {
544547
static createPackageRepository(pkg: MonorepoPackage, module: Module): Repository {
545548
return {
546549
ASTVersion: RepositoryFactory.AST_VERSION,
550+
ToolVersion: RepositoryFactory.TOOL_VERSION,
551+
Path: pkg.absolutePath,
547552
id: pkg.name || path.basename(pkg.absolutePath),
548553
Modules: { [module.Name]: module },
549554
Graph: {},
@@ -556,6 +561,8 @@ export class RepositoryFactory {
556561
static createEmptyRepository(id: string): Repository {
557562
return {
558563
ASTVersion: RepositoryFactory.AST_VERSION,
564+
ToolVersion: RepositoryFactory.TOOL_VERSION,
565+
Path: '',
559566
id,
560567
Modules: {},
561568
Graph: {},

0 commit comments

Comments
 (0)