Skip to content

Commit 3eb6ab0

Browse files
authored
feat: stream json stringfy (#109)
1 parent 3f4a4f8 commit 3eb6ab0

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

ts-parser/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"license": "ALv2",
2828
"dependencies": {
2929
"commander": "^11.0.0",
30+
"json-stream-stringify": "^3.1.6",
3031
"json5": "^2.2.3",
3132
"ts-morph": "^23.0.0"
3233
},
@@ -43,4 +44,4 @@
4344
"ts-node": "^10.9.0",
4445
"typescript": "^5.0.0"
4546
}
46-
}
47+
}

ts-parser/src/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env node
22

33
import { Command } from 'commander';
4-
import * as path from 'path';
4+
import fs from 'fs';
5+
import path from 'path';
56
import { RepositoryParser } from './parser/RepositoryParser';
6-
import * as fs from 'fs';
7+
import { JsonStreamStringify } from 'json-stream-stringify';
78

89
const program = new Command();
910

@@ -43,22 +44,22 @@ program
4344

4445
// Output the repository JSON file
4546
const outputPath = path.resolve(options.output);
46-
const jsonOutput = options.pretty
47-
? JSON.stringify(repository, null, 2)
48-
: JSON.stringify(repository);
47+
const jsonStream = new JsonStreamStringify(repository, undefined, options.pretty ? 2 : undefined);
48+
const fileStream = fs.createWriteStream(outputPath);
49+
jsonStream.pipe(fileStream);
4950

50-
fs.writeFileSync(outputPath, jsonOutput);
51+
fileStream.on('finish', () => {
52+
console.log(`Repository has been parsed and saved to ${outputPath}`);
53+
});
5154

52-
console.log(`Successfully parsed repository`);
53-
console.log(`Output written to: ${outputPath}`);
54-
console.log(`Total modules: ${Object.keys(repository.Modules).length}`);
55-
console.log(`Total symbols in graph: ${Object.keys(repository.Graph).length}`);
55+
fileStream.on('error', (err) => {
56+
console.error('Error writing to file:', err);
57+
});
5658

5759
} catch (error) {
5860
console.error('Error parsing repository:', error);
5961
process.exit(1);
6062
}
6163
});
6264

63-
6465
program.parse();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export function processPackagesWithCluster(
149149
totalProcessed: results.length,
150150
errors: [...errors, new Error('Processing timeout')],
151151
});
152-
}, 15 * 60 * 1000); // 15 minutes
152+
}, 120 * 60 * 1000); // 120 minutes
153153
};
154154

155155
cluster.on('message', (worker: Worker, message: WorkerResult) => {

0 commit comments

Comments
 (0)