jsii-rosetta 5.3.5-dev.7 → 5.3.5-dev.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/fixtures.js +1 -1
- package/lib/fixtures.js.map +1 -1
- package/lib/translate_all.js +2 -3
- package/lib/translate_all.js.map +1 -1
- package/package.json +2 -2
package/lib/fixtures.js
CHANGED
|
@@ -52,7 +52,7 @@ function loadLiterateSource(directory, literateFileName) {
|
|
|
52
52
|
// This couldn't really happen in practice, but do the check anyway
|
|
53
53
|
throw new Error(`Sample uses literate source ${literateFileName}, but not found: ${fullPath}`);
|
|
54
54
|
}
|
|
55
|
-
return fs.readFileSync(fullPath
|
|
55
|
+
return fs.readFileSync(fullPath, { encoding: 'utf-8' });
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Load the fixture with the given name, and substitute the source into it
|
package/lib/fixtures.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../src/fixtures.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,kCAAkC;AAClC,2CAAoF;AAEpF,uCAA8E;AAE9E;;GAEG;AACH,SAAgB,SAAS,CAAC,OAA0B,EAAE,KAAK,GAAG,KAAK;IACjE,IAAI,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IACnC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;IAE5C,MAAM,SAAS,GAAG,UAAU,CAAC,2BAAiB,CAAC,kBAAkB,CAAC,CAAC;IACnE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,cAAc,GAAG,UAAU,CAAC,2BAAiB,CAAC,eAAe,CAAC,CAAC;IACrE,IAAI,cAAc,EAAE,CAAC;QACnB,mEAAmE;QACnE,uEAAuE;QACvE,IAAI,CAAC;YACH,MAAM,GAAG,kBAAkB,CAA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AC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,SAAS,MAAM,CAAC,EAAY;QAC1B,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,eAAe,CAAC,MAAc;IAIrC,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,UAAU,GAAG,IAAA,6BAAgB,EAAC,UAAU,EAAE,MAAM,EAAE,yBAAY,CAAC,MAAM,EAAE,IAAI,EAAE,uBAAU,CAAC,EAAE,CAAC,CAAC;IAClG,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QAC9C,IACE,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,iBAAiB;YAC/C,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,uBAAuB;YACrD,CAAC,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,iBAAiB;gBAC9C,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,uBAAU,CAAC,cAAc,CAAC,EAC3E,CAAC;YACD,OAAO,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC;aAAM,CAAC;YACN,UAAU,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACjC,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { createSourceFile, ScriptKind, ScriptTarget, SyntaxKind } from 'typescript';\n\nimport { TypeScriptSnippet, SnippetParameters, ApiLocation } from './snippet';\n\n/**\n * Complete snippets with fixtures, if required\n */\nexport function fixturize(snippet: TypeScriptSnippet, loose = false): TypeScriptSnippet {\n let source = snippet.visibleSource;\n const parameters = snippet.parameters ?? {};\n\n const directory = parameters[SnippetParameters.$PROJECT_DIRECTORY];\n if (!directory) {\n return snippet;\n }\n\n const literateSource = parameters[SnippetParameters.LITERATE_SOURCE];\n if (literateSource) {\n // Compatibility with the \"old school\" example inclusion mechanism.\n // Completely load this file and attach a parameter with its directory.\n try {\n source = loadLiterateSource(directory, literateSource);\n } catch (ex) {\n // In loose mode, we ignore this failure and stick to the visible source.\n if (!loose) {\n throw ex;\n }\n }\n parameters[SnippetParameters.$COMPILATION_DIRECTORY] = path.join(directory, path.dirname(literateSource));\n } else if (parameters[SnippetParameters.FIXTURE]) {\n // Explicitly requested fixture must exist, unless we are operating in loose mode\n source = loadAndSubFixture(directory, snippet.location.api, parameters.fixture, source, !loose);\n } else if (parameters[SnippetParameters.NO_FIXTURE] === undefined) {\n // Don't explicitly request no fixture, load the default.\n source = loadAndSubFixture(directory, snippet.location.api, 'default', source, false);\n }\n\n return {\n ...snippet,\n completeSource: source,\n parameters,\n };\n}\n\nfunction loadLiterateSource(directory: string, literateFileName: string) {\n const fullPath = path.join(directory, literateFileName);\n const exists = fs.existsSync(fullPath);\n if (!exists) {\n // This couldn't really happen in practice, but do the check anyway\n throw new Error(`Sample uses literate source ${literateFileName}, but not found: ${fullPath}`);\n }\n return fs.readFileSync(fullPath).toString('utf-8');\n}\n\n/**\n * Load the fixture with the given name, and substitute the source into it\n *\n * If no fixture could be found and `mustExist` is true, and error will be thrown.\n *\n * In principle, the fixture we're looking for is `rosetta/FIXTURE.ts-fixture`.\n * However, we want to support an automatic transform of many small packages\n * combined into a single large package, perhaps into submodules (i.e., we want\n * to support monocdk), and in those cases the names of fixtures might conflict.\n * For example, all of them will have a `default.ts-fixture`, and there won't be\n * any explicit reference to that file anywhere... yet in the combined\n * monopackage we have to distinguish those fixtures.\n *\n * Therefore, we will consider submodule names as subdirectories, based on the\n * API location of the snippet we're fixturizing.\n *\n * (For example, the fixtures for a type called `monocdk.aws_s3.Bucket` will be\n * searched both in `rosetta/aws_s3/default.ts-fixture` as well as\n * `rosetta/default.ts-fixture`).\n */\nfunction loadAndSubFixture(\n directory: string,\n location: ApiLocation,\n fixtureName: string,\n source: string,\n mustExist: boolean,\n) {\n const candidates = fixtureCandidates(directory, fixtureName, location);\n const fixtureFileName = candidates.find((n) => fs.existsSync(n));\n\n if (!fixtureFileName) {\n if (mustExist) {\n throw new Error(`Sample uses fixture ${fixtureName}, but not found: ${JSON.stringify(candidates)}`);\n }\n return source;\n }\n\n const fixtureContents = fs.readFileSync(fixtureFileName, {\n encoding: 'utf-8',\n });\n\n const subRegex = /[/]{3}[ \\t]*here[ \\t]*$/im;\n if (!subRegex.test(fixtureContents)) {\n throw new Error(`Fixture does not contain '/// here': ${fixtureFileName}`);\n }\n\n const { imports, statements } = sidelineImports(source);\n const show = '/// !show';\n const hide = '/// !hide';\n\n const result = fixtureContents.replace(\n subRegex,\n [\n '// Code snippet begins after !show marker below',\n show,\n statements,\n hide,\n '// Code snippet ended before !hide marker above',\n ].join('\\n'),\n );\n\n return imports\n ? [\n '// Hoisted imports begin after !show marker below',\n show,\n imports,\n hide,\n '// Hoisted imports ended before !hide marker above',\n result,\n ].join('\\n')\n : result;\n}\n\nfunction fixtureCandidates(directory: string, fixtureName: string, location: ApiLocation): string[] {\n const ret = new Array<string>();\n const fileName = `${fixtureName}.ts-fixture`;\n const mods = submodules(location);\n\n ret.push(path.join(directory, 'rosetta', fileName));\n for (let i = 0; i < mods.length; i++) {\n ret.push(path.join(directory, 'rosetta', ...mods.slice(0, i + 1), fileName));\n }\n\n // Most specific one up front\n ret.reverse();\n return ret;\n}\n\n/**\n * Return the submodule parts from a given ApiLocation\n */\nfunction submodules(location: ApiLocation): string[] {\n switch (location.api) {\n case 'file':\n return [];\n case 'initializer':\n case 'member':\n case 'type':\n case 'parameter':\n return middle(location.fqn.split('.'));\n case 'moduleReadme':\n return location.moduleFqn.split('.').slice(1);\n }\n\n function middle(xs: string[]) {\n return xs.slice(1, xs.length - 1);\n }\n}\n\n/**\n * When embedding code fragments in a fixture, \"import\" statements must be\n * hoisted up to the top of the resulting document, as TypeScript only allows\n * those to be present in the top-level context of an ESM.\n *\n * @param source a block of TypeScript source\n *\n * @returns an object containing the import statements on one end, and the rest\n * on the other hand.\n */\nfunction sidelineImports(source: string): {\n imports: string;\n statements: string;\n} {\n let imports = '';\n let statements = '';\n\n const sourceFile = createSourceFile('index.ts', source, ScriptTarget.Latest, true, ScriptKind.TS);\n for (const statement of sourceFile.statements) {\n if (\n statement.kind === SyntaxKind.ImportDeclaration ||\n statement.kind === SyntaxKind.ImportEqualsDeclaration ||\n (statement.kind === SyntaxKind.VariableStatement &&\n statement.getChildAt(0).getChildAt(0).kind === SyntaxKind.DeclareKeyword)\n ) {\n imports += statement.getFullText(sourceFile);\n } else {\n statements += statement.getFullText(sourceFile);\n }\n }\n\n return { imports, statements };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../src/fixtures.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,kCAAkC;AAClC,2CAAoF;AAEpF,uCAA8E;AAE9E;;GAEG;AACH,SAAgB,SAAS,CAAC,OAA0B,EAAE,KAAK,GAAG,KAAK;IACjE,IAAI,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IACnC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;IAE5C,MAAM,SAAS,GAAG,UAAU,CAAC,2BAAiB,CAAC,kBAAkB,CAAC,CAAC;IACnE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,cAAc,GAAG,UAAU,CAAC,2BAAiB,CAAC,eAAe,CAAC,CAAC;IACrE,IAAI,cAAc,EAAE,CAAC;QACnB,mEAAmE;QACnE,uEAAuE;QACvE,IAAI,CAAC;YACH,MAAM,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AO,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,SAAS,MAAM,CAAC,EAAY;QAC1B,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,eAAe,CAAC,MAAc;IAIrC,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,UAAU,GAAG,EAAE,CAAC;IAEpB,MAAM,UAAU,GAAG,IAAA,6BAAgB,EAAC,UAAU,EAAE,MAAM,EAAE,yBAAY,CAAC,MAAM,EAAE,IAAI,EAAE,uBAAU,CAAC,EAAE,CAAC,CAAC;IAClG,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QAC9C,IACE,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,iBAAiB;YAC/C,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,uBAAuB;YACrD,CAAC,SAAS,CAAC,IAAI,KAAK,uBAAU,CAAC,iBAAiB;gBAC9C,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,uBAAU,CAAC,cAAc,CAAC,EAC3E,CAAC;YACD,OAAO,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC;aAAM,CAAC;YACN,UAAU,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACjC,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { createSourceFile, ScriptKind, ScriptTarget, SyntaxKind } from 'typescript';\n\nimport { TypeScriptSnippet, SnippetParameters, ApiLocation } from './snippet';\n\n/**\n * Complete snippets with fixtures, if required\n */\nexport function fixturize(snippet: TypeScriptSnippet, loose = false): TypeScriptSnippet {\n let source = snippet.visibleSource;\n const parameters = snippet.parameters ?? {};\n\n const directory = parameters[SnippetParameters.$PROJECT_DIRECTORY];\n if (!directory) {\n return snippet;\n }\n\n const literateSource = parameters[SnippetParameters.LITERATE_SOURCE];\n if (literateSource) {\n // Compatibility with the \"old school\" example inclusion mechanism.\n // Completely load this file and attach a parameter with its directory.\n try {\n source = loadLiterateSource(directory, literateSource);\n } catch (ex) {\n // In loose mode, we ignore this failure and stick to the visible source.\n if (!loose) {\n throw ex;\n }\n }\n parameters[SnippetParameters.$COMPILATION_DIRECTORY] = path.join(directory, path.dirname(literateSource));\n } else if (parameters[SnippetParameters.FIXTURE]) {\n // Explicitly requested fixture must exist, unless we are operating in loose mode\n source = loadAndSubFixture(directory, snippet.location.api, parameters.fixture, source, !loose);\n } else if (parameters[SnippetParameters.NO_FIXTURE] === undefined) {\n // Don't explicitly request no fixture, load the default.\n source = loadAndSubFixture(directory, snippet.location.api, 'default', source, false);\n }\n\n return {\n ...snippet,\n completeSource: source,\n parameters,\n };\n}\n\nfunction loadLiterateSource(directory: string, literateFileName: string) {\n const fullPath = path.join(directory, literateFileName);\n const exists = fs.existsSync(fullPath);\n if (!exists) {\n // This couldn't really happen in practice, but do the check anyway\n throw new Error(`Sample uses literate source ${literateFileName}, but not found: ${fullPath}`);\n }\n return fs.readFileSync(fullPath, { encoding: 'utf-8' });\n}\n\n/**\n * Load the fixture with the given name, and substitute the source into it\n *\n * If no fixture could be found and `mustExist` is true, and error will be thrown.\n *\n * In principle, the fixture we're looking for is `rosetta/FIXTURE.ts-fixture`.\n * However, we want to support an automatic transform of many small packages\n * combined into a single large package, perhaps into submodules (i.e., we want\n * to support monocdk), and in those cases the names of fixtures might conflict.\n * For example, all of them will have a `default.ts-fixture`, and there won't be\n * any explicit reference to that file anywhere... yet in the combined\n * monopackage we have to distinguish those fixtures.\n *\n * Therefore, we will consider submodule names as subdirectories, based on the\n * API location of the snippet we're fixturizing.\n *\n * (For example, the fixtures for a type called `monocdk.aws_s3.Bucket` will be\n * searched both in `rosetta/aws_s3/default.ts-fixture` as well as\n * `rosetta/default.ts-fixture`).\n */\nfunction loadAndSubFixture(\n directory: string,\n location: ApiLocation,\n fixtureName: string,\n source: string,\n mustExist: boolean,\n) {\n const candidates = fixtureCandidates(directory, fixtureName, location);\n const fixtureFileName = candidates.find((n) => fs.existsSync(n));\n\n if (!fixtureFileName) {\n if (mustExist) {\n throw new Error(`Sample uses fixture ${fixtureName}, but not found: ${JSON.stringify(candidates)}`);\n }\n return source;\n }\n\n const fixtureContents = fs.readFileSync(fixtureFileName, {\n encoding: 'utf-8',\n });\n\n const subRegex = /[/]{3}[ \\t]*here[ \\t]*$/im;\n if (!subRegex.test(fixtureContents)) {\n throw new Error(`Fixture does not contain '/// here': ${fixtureFileName}`);\n }\n\n const { imports, statements } = sidelineImports(source);\n const show = '/// !show';\n const hide = '/// !hide';\n\n const result = fixtureContents.replace(\n subRegex,\n [\n '// Code snippet begins after !show marker below',\n show,\n statements,\n hide,\n '// Code snippet ended before !hide marker above',\n ].join('\\n'),\n );\n\n return imports\n ? [\n '// Hoisted imports begin after !show marker below',\n show,\n imports,\n hide,\n '// Hoisted imports ended before !hide marker above',\n result,\n ].join('\\n')\n : result;\n}\n\nfunction fixtureCandidates(directory: string, fixtureName: string, location: ApiLocation): string[] {\n const ret = new Array<string>();\n const fileName = `${fixtureName}.ts-fixture`;\n const mods = submodules(location);\n\n ret.push(path.join(directory, 'rosetta', fileName));\n for (let i = 0; i < mods.length; i++) {\n ret.push(path.join(directory, 'rosetta', ...mods.slice(0, i + 1), fileName));\n }\n\n // Most specific one up front\n ret.reverse();\n return ret;\n}\n\n/**\n * Return the submodule parts from a given ApiLocation\n */\nfunction submodules(location: ApiLocation): string[] {\n switch (location.api) {\n case 'file':\n return [];\n case 'initializer':\n case 'member':\n case 'type':\n case 'parameter':\n return middle(location.fqn.split('.'));\n case 'moduleReadme':\n return location.moduleFqn.split('.').slice(1);\n }\n\n function middle(xs: string[]) {\n return xs.slice(1, xs.length - 1);\n }\n}\n\n/**\n * When embedding code fragments in a fixture, \"import\" statements must be\n * hoisted up to the top of the resulting document, as TypeScript only allows\n * those to be present in the top-level context of an ESM.\n *\n * @param source a block of TypeScript source\n *\n * @returns an object containing the import statements on one end, and the rest\n * on the other hand.\n */\nfunction sidelineImports(source: string): {\n imports: string;\n statements: string;\n} {\n let imports = '';\n let statements = '';\n\n const sourceFile = createSourceFile('index.ts', source, ScriptTarget.Latest, true, ScriptKind.TS);\n for (const statement of sourceFile.statements) {\n if (\n statement.kind === SyntaxKind.ImportDeclaration ||\n statement.kind === SyntaxKind.ImportEqualsDeclaration ||\n (statement.kind === SyntaxKind.VariableStatement &&\n statement.getChildAt(0).getChildAt(0).kind === SyntaxKind.DeclareKeyword)\n ) {\n imports += statement.getFullText(sourceFile);\n } else {\n statements += statement.getFullText(sourceFile);\n }\n }\n\n return { imports, statements };\n}\n"]}
|
package/lib/translate_all.js
CHANGED
|
@@ -21,9 +21,8 @@ async function translateAll(snippets, includeCompilerDiagnostics) {
|
|
|
21
21
|
// help that much, or we become I/O-bound at some point. On my machine, using
|
|
22
22
|
// more than half the cores actually makes it slower.
|
|
23
23
|
// Cap to a reasonable top-level limit to prevent thrash on machines with many, many cores.
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
: Math.min(16, Math.max(1, Math.ceil(os.cpus().length / 2)));
|
|
24
|
+
const maxWorkers = parseInt(process.env.JSII_ROSETTA_MAX_WORKER_COUNT ?? '16');
|
|
25
|
+
const N = Math.min(maxWorkers, Math.max(1, Math.ceil(os.cpus().length / 2)));
|
|
27
26
|
const snippetArr = Array.from(snippets);
|
|
28
27
|
logging.info(`Translating ${snippetArr.length} snippets using ${N} workers`);
|
|
29
28
|
const pool = workerpool.pool(path.join(__dirname, 'translate_all_worker.js'), {
|
package/lib/translate_all.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translate_all.js","sourceRoot":"","sources":["../src/translate_all.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,kCAAkC;AAClC,yCAAyC;AAEzC,qCAAqC;AAErC,+CAAsD;AAItD;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,QAA6B,EAC7B,0BAAmC;IAEnC,6EAA6E;IAC7E,6EAA6E;IAC7E,qDAAqD;IACrD,2FAA2F;IAC3F,MAAM,
|
|
1
|
+
{"version":3,"file":"translate_all.js","sourceRoot":"","sources":["../src/translate_all.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,kCAAkC;AAClC,yCAAyC;AAEzC,qCAAqC;AAErC,+CAAsD;AAItD;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,QAA6B,EAC7B,0BAAmC;IAEnC,6EAA6E;IAC7E,6EAA6E;IAC7E,qDAAqD;IACrD,2FAA2F;IAC3F,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,6BAA6B,IAAI,IAAI,CAAC,CAAC;IAC/E,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7E,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,eAAe,UAAU,CAAC,MAAM,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAE7E,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC,EAAE;QAC5E,UAAU,EAAE,CAAC;KACd,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,QAAQ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ool from 'workerpool';\n\nimport * as logging from './logging';\nimport { TypeScriptSnippet } from './snippet';\nimport { TranslatedSnippet } from './tablets/tablets';\nimport { RosettaDiagnostic } from './translate';\nimport type { TranslateBatchRequest, TranslateBatchResponse } from './translate_all_worker';\n\n/**\n * Divide the work evenly over all processors by running 'translate_all_worker' in Worker Threads, then combine results\n *\n * The workers are fed small queues of work each. We used to divide the entire queue into N\n * but since the work is divided unevenly that led to some workers stopping early, idling while\n * waiting for more work.\n *\n * Never include 'translate_all_worker' directly, only do TypeScript type references (so that in\n * the script we may assume that 'worker_threads' successfully imports).\n */\nexport async function translateAll(\n snippets: TypeScriptSnippet[],\n includeCompilerDiagnostics: boolean,\n): Promise<TranslateAllResult> {\n // Use about half the advertised cores because hyperthreading doesn't seem to\n // help that much, or we become I/O-bound at some point. On my machine, using\n // more than half the cores actually makes it slower.\n // Cap to a reasonable top-level limit to prevent thrash on machines with many, many cores.\n const maxWorkers = parseInt(process.env.JSII_ROSETTA_MAX_WORKER_COUNT ?? '16');\n const N = Math.min(maxWorkers, Math.max(1, Math.ceil(os.cpus().length / 2)));\n const snippetArr = Array.from(snippets);\n logging.info(`Translating ${snippetArr.length} snippets using ${N} workers`);\n\n const pool = workerpool.pool(path.join(__dirname, 'translate_all_worker.js'), {\n maxWorkers: N,\n });\n\n try {\n const requests = batchSnippets(snippetArr, includeCompilerDiagnostics);\n\n const responses: TranslateBatchResponse[] = await Promise.all(\n requests.map((request) => pool.exec('translateBatch', [request])),\n );\n\n const diagnostics = new Array<RosettaDiagnostic>();\n const translatedSnippets = new Array<TranslatedSnippet>();\n\n // Combine results\n for (const response of responses) {\n diagnostics.push(...response.diagnostics);\n translatedSnippets.push(...response.translatedSchemas.map(TranslatedSnippet.fromSchema));\n }\n return { diagnostics, translatedSnippets };\n } finally {\n // Not waiting on purpose\n void pool.terminate();\n }\n}\n\nfunction batchSnippets(\n snippets: TypeScriptSnippet[],\n includeCompilerDiagnostics: boolean,\n batchSize = 10,\n): TranslateBatchRequest[] {\n const ret = [];\n\n for (let i = 0; i < snippets.length; i += batchSize) {\n ret.push({\n snippets: snippets.slice(i, i + batchSize),\n includeCompilerDiagnostics,\n });\n }\n\n return ret;\n}\n\nexport interface TranslateAllResult {\n translatedSnippets: TranslatedSnippet[];\n diagnostics: RosettaDiagnostic[];\n}\n"]}
|
package/package.json
CHANGED
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"memfs": "^4.6.0",
|
|
59
59
|
"mock-fs": "^5.2.0",
|
|
60
60
|
"prettier": "^2.8.8",
|
|
61
|
-
"projen": "^0.79.
|
|
61
|
+
"projen": "^0.79.1",
|
|
62
62
|
"tar": "^6.2.0",
|
|
63
63
|
"ts-jest": "^29.1.1",
|
|
64
64
|
"ts-node": "^10.9.2"
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"main": "lib/index.js",
|
|
85
85
|
"license": "Apache-2.0",
|
|
86
86
|
"homepage": "https://aws.github.io/jsii",
|
|
87
|
-
"version": "5.3.5-dev.
|
|
87
|
+
"version": "5.3.5-dev.9",
|
|
88
88
|
"types": "lib/index.d.ts",
|
|
89
89
|
"exports": {
|
|
90
90
|
".": "./lib/index.js",
|