diff --git a/packages/jsii-rosetta/lib/commands/extract.ts b/packages/jsii-rosetta/lib/commands/extract.ts index f3637f7651..08e7a7a4da 100644 --- a/packages/jsii-rosetta/lib/commands/extract.ts +++ b/packages/jsii-rosetta/lib/commands/extract.ts @@ -1,6 +1,7 @@ import * as os from 'os'; import * as path from 'path'; import * as ts from 'typescript'; +import * as v8 from 'v8'; import { loadAssemblies, allTypeScriptSnippets } from '../jsii/assemblies'; import * as logging from '../logging'; @@ -210,6 +211,12 @@ async function workerBasedTranslateAll( ): Promise { return new Promise((resolve, reject) => { const wrk = new worker.Worker(path.join(__dirname, 'extract_worker.js'), { + resourceLimits: { + // Note: V8 heap statistics are expressed in bytes, so we divide by 1MiB (1,048,576 bytes) + maxOldGenerationSizeMb: Math.ceil( + v8.getHeapStatistics().heap_size_limit / 1_048_576, + ), + }, workerData: request, }); wrk.on('message', resolve);