Skip to content

Commit a0b60fe

Browse files
committed
chore: cleanup asts before exiting
1 parent 5ec465a commit a0b60fe

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

packages/codemods/src/cli/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ createListCommand(program);
1919
program.showHelpAfterError();
2020

2121
await program.parseAsync(process.argv);
22-
await new Promise((resolve) => setTimeout(resolve, 5000));

packages/codemods/src/schema-migration/codemod.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ export class Codemod {
149149
this.entityRegistry = new Map();
150150
}
151151

152+
releaseASTs() {
153+
for (const parsed of this.input.parsedModels.values()) {
154+
(parsed as { ast: unknown; root: unknown }).ast = null;
155+
(parsed as { ast: unknown; root: unknown }).root = null;
156+
}
157+
for (const parsed of this.input.parsedMixins.values()) {
158+
(parsed as { ast: unknown; root: unknown }).ast = null;
159+
(parsed as { ast: unknown; root: unknown }).root = null;
160+
}
161+
}
162+
152163
findMixinsUsedByModels() {
153164
const result = analyzeModelMixinUsage(this, this.finalOptions);
154165
linkEntities(this.entityRegistry, result.modelToMixinsMap);

packages/codemods/src/schema-migration/tasks/migrate.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@ export async function runMigration(options: MigrateOptions): Promise<void> {
468468
log,
469469
});
470470

471+
// Release AST references so native tree-sitter trees are finalized
472+
// individually by GC rather than all at once during process exit,
473+
// which causes a stack overflow in tree-sitter's recursive destructor.
474+
codemod.releaseASTs();
475+
471476
// Aggregate all skipped files from every phase
472477
const allSkipped: SkippedFile[] = [...codemod.input.skipped, ...results.skipped];
473478

0 commit comments

Comments
 (0)