jsii-rosetta 5.9.21-dev.0 → 5.9.21

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.
@@ -1 +1 @@
1
- {"version":3,"file":"translate.js","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":";;;;;;;;;AAyBA,kDAeC;AAkYD,sDAEC;AAKD,8DAMC;AAvbD,kCAAkC;AAClC,yCAAoC;AACpC,iCAAiC;AAEjC,2CAA+D;AAC/D,qEAAwE;AACxE,iEAAgF;AAChF,qCAAqC;AACrC,qCAAsC;AACtC,yCAAyE;AACzE,uCAAiG;AACjG,+DAAkF;AAClF,uCAA2C;AAC3C,6CAAwD;AACxD,+CAAsD;AACtD,0EAAqE;AACrE,0DAAyG;AACzG,8DAAmD;AACnD,iCAAmF;AAOnF,SAAgB,mBAAmB,CACjC,MAAY,EACZ,OAAwB,EACxB,UAAoC,EAAE;IAEtC,MAAM,UAAU,GAAG,IAAI,iBAAiB,CACtC,EAAE,aAAa,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE,EAAE,EACjG,OAAO,CACR,CAAC;IACF,MAAM,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEnD,OAAO;QACL,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,yBAAyB,CAAC;KACnE,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAa,UAAU;IAIrB,IAAW,WAAW;QACpB,OAAO,EAAE,CAAC,6BAA6B,CAAC,uBAAA,IAAI,+BAAa,CAAC,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAC5F,CAAC;IAED,YAAoC,0BAAmC;QAAnC,+BAA0B,GAA1B,0BAA0B,CAAS;QAPtD,aAA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ClB,CAAC;IACD,UAAU;QACR,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC;AAEF;;;GAGG;AACH,SAAS,aAAa,CAAC,CAAS;IAC9B,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC","sourcesContent":["import * as path from 'node:path';\nimport { inspect } from 'node:util';\nimport * as ts from 'typescript';\n\nimport { TARGET_LANGUAGES, TargetLanguage } from './languages';\nimport { RecordReferencesVisitor } from './languages/record-references';\nimport { supportsTransitiveSubmoduleAccess } from './languages/target-language';\nimport * as logging from './logging';\nimport { renderTree } from './o-tree';\nimport { AstRenderer, AstHandler, AstRendererOptions } from './renderer';\nimport { TypeScriptSnippet, completeSource, SnippetParameters, formatLocation } from './snippet';\nimport { SubmoduleReference, SubmoduleReferenceMap } from './submodule-reference';\nimport { snippetKey } from './tablets/key';\nimport { ORIGINAL_SNIPPET_KEY } from './tablets/schema';\nimport { TranslatedSnippet } from './tablets/tablets';\nimport { SyntaxKindCounter } from './typescript/syntax-kind-counter';\nimport { TypeScriptCompiler, CompilationResult, BatchCompilationResult } from './typescript/ts-compiler';\nimport { Spans } from './typescript/visible-spans';\nimport { annotateStrictDiagnostic, File, hasStrictBranding, mkDict } from './util';\n\nexport interface TranslateResult {\n translation: string;\n diagnostics: readonly RosettaDiagnostic[];\n}\n\nexport function translateTypeScript(\n source: File,\n visitor: AstHandler<any>,\n options: SnippetTranslatorOptions = {},\n): TranslateResult {\n const translator = new SnippetTranslator(\n { visibleSource: source.contents, location: { api: { api: 'file', fileName: source.fileName } } },\n options,\n );\n const translated = translator.renderUsing(visitor);\n\n return {\n translation: translated,\n diagnostics: translator.diagnostics.map(rosettaDiagFromTypescript),\n };\n}\n\n/**\n * Translate one or more TypeScript snippets into other languages\n *\n * Can be configured to fully typecheck the samples, or perform only syntactical\n * translation.\n */\nexport class Translator {\n private readonly compiler = new TypeScriptCompiler();\n #diagnostics: ts.Diagnostic[] = [];\n\n public get diagnostics(): readonly RosettaDiagnostic[] {\n return ts.sortAndDeduplicateDiagnostics(this.#diagnostics).map(rosettaDiagFromTypescript);\n }\n\n public constructor(private readonly includeCompilerDiagnostics: boolean) {}\n\n /**\n * Return the snippet translator for the given snippet\n *\n * We used to cache these, but each translator holds on to quite a bit of memory,\n * so we don't do that anymore.\n */\n public translatorFor(snippet: TypeScriptSnippet) {\n const translator = new SnippetTranslator(snippet, {\n compiler: this.compiler,\n includeCompilerDiagnostics: this.includeCompilerDiagnostics,\n });\n return translator;\n }\n\n /**\n * Translates a single snippet in its own TS context.\n */\n public translate(snip: TypeScriptSnippet, languages: readonly TargetLanguage[] = Object.values(TargetLanguage)) {\n const start = performance.now();\n logging.debug(`Translating ${snippetKey(snip)} ${inspect(snip.parameters ?? {})}`);\n\n const translator = this.translatorFor(snip);\n const translated = this.translateSnippet(snip, translator, languages);\n\n const duration = performance.now() - start;\n logging.debug(\n `Completed ${snippetKey(snip)} ${inspect({\n duration: `${(duration / 1000).toFixed(2)}s`,\n })}`,\n );\n\n return translated;\n }\n\n /**\n * Translates a batch of snippets, using a shared TS context.\n */\n public translateSnippets(\n snippets: TypeScriptSnippet[],\n languages: readonly TargetLanguage[] = Object.values(TargetLanguage),\n ): TranslatedSnippet[] {\n const start = performance.now();\n logging.debug(`Translating batch of ${snippets.length} snippets`);\n\n const res = this.translateBatch(snippets, languages);\n\n const duration = performance.now() - start;\n logging.debug(\n `Completed batch ${inspect({\n duration: `${(duration / 1000).toFixed(2)}s`,\n })}`,\n );\n\n return res;\n }\n\n private translateBatch(\n snippets: TypeScriptSnippet[],\n languages: readonly TargetLanguage[] = Object.values(TargetLanguage),\n ): TranslatedSnippet[] {\n const translatedSnippets: TranslatedSnippet[] = [];\n\n const batchTranslator = new BatchSnippetTranslator(snippets, {\n compiler: this.compiler,\n includeCompilerDiagnostics: this.includeCompilerDiagnostics,\n });\n\n for (const [snippet, translator] of batchTranslator) {\n translatedSnippets.push(this.translateSnippet(snippet, translator, languages));\n }\n\n return translatedSnippets;\n }\n\n private translateSnippet(\n snippet: TypeScriptSnippet,\n translator: ISnippetTranslator,\n languages: readonly TargetLanguage[],\n ): TranslatedSnippet {\n const translations = mkDict(\n languages.flatMap((lang, idx, array) => {\n if (array.slice(0, idx).includes(lang)) {\n return [];\n }\n const languageConverterFactory = TARGET_LANGUAGES[lang];\n const translated = translator.renderUsing(languageConverterFactory.createVisitor());\n return [[lang, { source: translated, version: languageConverterFactory.version }] as const];\n }),\n );\n\n if (snippet.parameters?.infused === undefined) {\n this.#diagnostics.push(...translator.diagnostics);\n }\n\n return TranslatedSnippet.fromSchema({\n translations: {\n ...translations,\n [ORIGINAL_SNIPPET_KEY]: { source: snippet.visibleSource, version: '0' },\n },\n location: snippet.location,\n didCompile: translator.didSuccessfullyCompile,\n fqnsReferenced: translator.fqnsReferenced(),\n fullSource: completeSource(snippet),\n syntaxKindCounter: translator.syntaxKindCounter(),\n });\n }\n}\n\nexport interface ISnippetTranslator {\n readonly diagnostics: readonly ts.Diagnostic[];\n readonly didSuccessfullyCompile: boolean | undefined;\n\n renderUsing(visitor: AstHandler<any>): string;\n syntaxKindCounter(): Partial<Record<ts.SyntaxKind, number>>;\n fqnsReferenced(): string[];\n}\n\nexport interface SnippetTranslatorOptions extends AstRendererOptions {\n /**\n * Re-use the given compiler if given\n */\n readonly compiler?: TypeScriptCompiler;\n\n /**\n * Include compiler errors in return diagnostics\n *\n * If false, only translation diagnostics will be returned.\n *\n * @default false\n */\n readonly includeCompilerDiagnostics?: boolean;\n}\n\n/**\n * Internal implementation of a single TypeScript snippet translator.\n *\n * Consumers should either use `SnippetTranslator` or `BatchSnippetTranslator`.\n */\nclass InternalSnippetTranslator implements ISnippetTranslator {\n public readonly translateDiagnostics: ts.Diagnostic[] = [];\n public readonly compileDiagnostics: ts.Diagnostic[] = [];\n\n private readonly visibleSpans: Spans;\n private readonly tryCompile: boolean;\n private readonly submoduleReferences: SubmoduleReferenceMap;\n\n public constructor(\n snippet: TypeScriptSnippet,\n private readonly compilation: CompilationResult,\n private readonly options: SnippetTranslatorOptions,\n ) {\n // Respect '/// !hide' and '/// !show' directives\n // Use the actual compiled source text to ensure spans match the AST\n this.visibleSpans = Spans.visibleSpansFromSource(compilation.rootFile.text);\n\n // Find submodule references on explicit imports\n this.submoduleReferences = SubmoduleReference.inSourceFile(\n compilation.rootFile,\n this.compilation.program.getTypeChecker(),\n );\n\n // This makes it about 5x slower, so only do it on demand\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n this.tryCompile = (this.options.includeCompilerDiagnostics || snippet.strict) ?? false;\n if (this.tryCompile) {\n const program = this.compilation.program;\n const diagnostics = [\n ...neverThrowing(program.getGlobalDiagnostics)(),\n ...neverThrowing(program.getSyntacticDiagnostics)(this.compilation.rootFile),\n ...neverThrowing(program.getDeclarationDiagnostics)(this.compilation.rootFile),\n ...neverThrowing(program.getSemanticDiagnostics)(this.compilation.rootFile),\n ];\n\n if (snippet.strict) {\n // In a strict assembly, so we'll need to brand all diagnostics here...\n for (const diag of diagnostics) {\n annotateStrictDiagnostic(diag);\n }\n }\n this.compileDiagnostics.push(...diagnostics);\n }\n }\n\n /**\n * Returns a boolean if compilation was attempted, and undefined if it was not.\n */\n public get didSuccessfullyCompile() {\n return this.tryCompile ? this.compileDiagnostics.length === 0 : undefined;\n }\n\n public renderUsing(visitor: AstHandler<any>) {\n const converter = new AstRenderer(\n this.compilation.rootFile,\n this.compilation.program.getTypeChecker(),\n visitor,\n this.options,\n // If we support transitive submodule access, don't provide a submodule reference map.\n supportsTransitiveSubmoduleAccess(visitor.language) ? undefined : this.submoduleReferences,\n );\n const converted = converter.convert(this.compilation.rootFile);\n this.translateDiagnostics.push(...filterVisibleDiagnostics(converter.diagnostics, this.visibleSpans));\n return renderTree(converted, { indentChar: visitor.indentChar, visibleSpans: this.visibleSpans });\n }\n\n public syntaxKindCounter(): Partial<Record<ts.SyntaxKind, number>> {\n const kindCounter = new SyntaxKindCounter(this.visibleSpans);\n return kindCounter.countKinds(this.compilation.rootFile);\n }\n\n public fqnsReferenced() {\n const visitor = new RecordReferencesVisitor(this.visibleSpans);\n const converter = new AstRenderer(\n this.compilation.rootFile,\n this.compilation.program.getTypeChecker(),\n visitor,\n this.options,\n this.submoduleReferences,\n );\n converter.convert(this.compilation.rootFile);\n return visitor.fqnsReferenced();\n }\n\n public get diagnostics(): readonly ts.Diagnostic[] {\n return ts.sortAndDeduplicateDiagnostics(this.compileDiagnostics.concat(this.translateDiagnostics));\n }\n}\n\n/**\n * Translate a single TypeScript snippet\n */\nexport class SnippetTranslator extends InternalSnippetTranslator {\n public constructor(snippet: TypeScriptSnippet, options: SnippetTranslatorOptions = {}) {\n const compiler = options.compiler ?? new TypeScriptCompiler();\n const source = completeSource(snippet);\n const fakeCurrentDirectory = snippet.parameters?.[SnippetParameters.$COMPILATION_DIRECTORY] ?? process.cwd();\n const compilation = compiler.compileBatchInMemory(\n [\n {\n filename: removeSlashes(formatLocation(snippet.location)),\n contents: source,\n },\n ],\n fakeCurrentDirectory,\n );\n\n super(\n snippet,\n {\n program: compilation.program,\n rootFile: compilation.rootFiles[0],\n },\n options,\n );\n }\n}\n\nexport interface BatchSnippetTranslatorOptions extends SnippetTranslatorOptions {\n /**\n * What directory to pretend the file is in (system parameter)\n *\n * Attached when compiling a literate file, as they compile in\n * the location where they are stored.\n *\n * @default - current working directory\n */\n readonly compilationDirectory?: string;\n}\n\n/**\n * Translate a single TypeScript snippet\n */\nexport class BatchSnippetTranslator {\n private readonly compilation: BatchCompilationResult;\n\n public constructor(\n private readonly snippets: TypeScriptSnippet[],\n private readonly options: BatchSnippetTranslatorOptions = {},\n ) {\n const compiler = options.compiler ?? new TypeScriptCompiler();\n const workingDir = options.compilationDirectory ?? process.cwd();\n\n const sources = snippets.map((snippet) => {\n const snippetLoc = snippet.parameters?.[SnippetParameters.$COMPILATION_DIRECTORY];\n const filename = removeSlashes(formatLocation(snippet.location));\n\n return {\n filename: snippetLoc ? path.relative(workingDir, path.join(snippetLoc, filename)) : filename,\n contents: completeSource(snippet),\n };\n });\n this.compilation = compiler.compileBatchInMemory(sources, workingDir);\n }\n\n *[Symbol.iterator](): Generator<[TypeScriptSnippet, ISnippetTranslator], void, unknown> {\n for (const [idx, snippet] of this.snippets.entries()) {\n const rootFile = this.compilation.rootFiles[idx];\n\n const translator: ISnippetTranslator = new InternalSnippetTranslator(\n snippet,\n {\n program: this.compilation.program,\n rootFile,\n },\n this.options,\n );\n\n yield [snippet, translator];\n }\n }\n}\n\n/**\n * Intercepts all exceptions thrown by the wrapped call, and logs them to\n * console.error instead of re-throwing, then returns an empty array. This\n * is here to avoid compiler crashes due to broken code examples that cause\n * the TypeScript compiler to hit a \"Debug Failure\".\n */\nfunction neverThrowing<A extends unknown[], R>(call: (...args: A) => readonly R[]): (...args: A) => readonly R[] {\n return (...args: A) => {\n try {\n return call(...args);\n } catch (err: any) {\n const isExpectedTypescriptError = err.message.includes('Debug Failure');\n\n if (!isExpectedTypescriptError) {\n console.error(`Failed to execute ${call.name}: ${err}`);\n }\n\n return [];\n }\n };\n}\n\n/**\n * Hide diagnostics that are rosetta-sourced if they are reported against a non-visible span\n */\nfunction filterVisibleDiagnostics(diags: readonly ts.Diagnostic[], visibleSpans: Spans): ts.Diagnostic[] {\n return diags.filter((d) => d.source !== 'rosetta' || d.start === undefined || visibleSpans.containsPosition(d.start));\n}\n\n/**\n * A translation of a TypeScript diagnostic into a data-only representation for Rosetta\n *\n * We cannot use the original `ts.Diagnostic` since it holds on to way too much\n * state (the source file and by extension the entire parse tree), which grows\n * too big to be properly serialized by a worker and also takes too much memory.\n *\n * Reduce it down to only the information we need.\n */\nexport interface RosettaDiagnostic {\n /**\n * If this is an error diagnostic or not\n */\n readonly isError: boolean;\n\n /**\n * If the diagnostic was emitted from an assembly that has its 'strict' flag set\n */\n readonly isFromStrictAssembly: boolean;\n\n /**\n * The formatted message, ready to be printed (will have colors and newlines in it)\n *\n * Ends in a newline.\n */\n readonly formattedMessage: string;\n}\n\nexport function makeRosettaDiagnostic(isError: boolean, formattedMessage: string): RosettaDiagnostic {\n return { isError, formattedMessage, isFromStrictAssembly: false };\n}\n\n/**\n * Turn TypeScript diagnostics into Rosetta diagnostics\n */\nexport function rosettaDiagFromTypescript(diag: ts.Diagnostic): RosettaDiagnostic {\n return {\n isError: diag.category === ts.DiagnosticCategory.Error,\n isFromStrictAssembly: hasStrictBranding(diag),\n formattedMessage: ts.formatDiagnosticsWithColorAndContext([diag], DIAG_HOST),\n };\n}\n\nconst DIAG_HOST = {\n getCurrentDirectory() {\n return '.';\n },\n getCanonicalFileName(fileName: string) {\n return fileName;\n },\n getNewLine() {\n return '\\n';\n },\n};\n\n/**\n * Remove slashes from a \"where\" description, as the TS compiler will interpret it as a directory\n * and we can't have that for compiling literate files\n */\nfunction removeSlashes(x: string) {\n return x.replace(/\\/|\\\\/g, '.');\n}\n"]}
1
+ {"version":3,"file":"translate.js","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":";;;;;;;;;AAwBA,kDAeC;AAkYD,sDAEC;AAED,oDAOC;AAED,8CAgBC;AAED,8CA0BC;AAKD,8DAMC;AA7eD,kCAAkC;AAClC,yCAAoC;AACpC,iCAAiC;AAEjC,2CAA+D;AAC/D,qEAAwE;AACxE,iEAAgF;AAChF,qCAAqC;AACrC,qCAAsC;AACtC,yCAAyE;AACzE,uCAAiG;AACjG,+DAAkF;AAClF,6CAAwD;AACxD,+CAAsD;AACtD,0EAAqE;AACrE,0DAAyG;AACzG,8DAAmD;AACnD,iCAAmF;AAOnF,SAAgB,mBAAmB,CACjC,MAAY,EACZ,OAAwB,EACxB,UAAoC,EAAE;IAEtC,MAAM,UAAU,GAAG,IAAI,iBAAiB,CACtC,EAAE,aAAa,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE,EAAE,EACjG,O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AAM,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACvF,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,2BAA2B,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACxE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,SAAgB,yBAAyB,CAAC,IAAmB;IAC3D,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,QAAQ,KAAK,EAAE,CAAC,kBAAkB,CAAC,KAAK;QACtD,oBAAoB,EAAE,IAAA,wBAAiB,EAAC,IAAI,CAAC;QAC7C,gBAAgB,EAAE,EAAE,CAAC,oCAAoC,CAAC,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;KAC7E,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAG;IAChB,mBAAmB;QACjB,OAAO,GAAG,CAAC;IACb,CAAC;IACD,oBAAoB,CAAC,QAAgB;QACnC,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,UAAU;QACR,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC;AAEF;;;GAGG;AACH,SAAS,aAAa,CAAC,CAAS;IAC9B,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC","sourcesContent":["import * as path from 'node:path';\nimport { inspect } from 'node:util';\nimport * as ts from 'typescript';\n\nimport { TARGET_LANGUAGES, TargetLanguage } from './languages';\nimport { RecordReferencesVisitor } from './languages/record-references';\nimport { supportsTransitiveSubmoduleAccess } from './languages/target-language';\nimport * as logging from './logging';\nimport { renderTree } from './o-tree';\nimport { AstRenderer, AstHandler, AstRendererOptions } from './renderer';\nimport { TypeScriptSnippet, completeSource, SnippetParameters, formatLocation } from './snippet';\nimport { SubmoduleReference, SubmoduleReferenceMap } from './submodule-reference';\nimport { ORIGINAL_SNIPPET_KEY } from './tablets/schema';\nimport { TranslatedSnippet } from './tablets/tablets';\nimport { SyntaxKindCounter } from './typescript/syntax-kind-counter';\nimport { TypeScriptCompiler, CompilationResult, BatchCompilationResult } from './typescript/ts-compiler';\nimport { Spans } from './typescript/visible-spans';\nimport { annotateStrictDiagnostic, File, hasStrictBranding, mkDict } from './util';\n\nexport interface TranslateResult {\n translation: string;\n diagnostics: readonly RosettaDiagnostic[];\n}\n\nexport function translateTypeScript(\n source: File,\n visitor: AstHandler<any>,\n options: SnippetTranslatorOptions = {},\n): TranslateResult {\n const translator = new SnippetTranslator(\n { visibleSource: source.contents, location: { api: { api: 'file', fileName: source.fileName } } },\n options,\n );\n const translated = translator.renderUsing(visitor);\n\n return {\n translation: translated,\n diagnostics: translator.diagnostics.map(rosettaDiagFromTypescript),\n };\n}\n\n/**\n * Translate one or more TypeScript snippets into other languages\n *\n * Can be configured to fully typecheck the samples, or perform only syntactical\n * translation.\n */\nexport class Translator {\n private readonly compiler = new TypeScriptCompiler();\n #diagnostics: ts.Diagnostic[] = [];\n\n public get diagnostics(): readonly RosettaDiagnostic[] {\n return ts.sortAndDeduplicateDiagnostics(this.#diagnostics).map(rosettaDiagFromTypescript);\n }\n\n public constructor(private readonly includeCompilerDiagnostics: boolean) {}\n\n /**\n * Return the snippet translator for the given snippet\n *\n * We used to cache these, but each translator holds on to quite a bit of memory,\n * so we don't do that anymore.\n */\n public translatorFor(snippet: TypeScriptSnippet) {\n const translator = new SnippetTranslator(snippet, {\n compiler: this.compiler,\n includeCompilerDiagnostics: this.includeCompilerDiagnostics,\n });\n return translator;\n }\n\n /**\n * Translates a single snippet in its own TS context.\n */\n public translate(snip: TypeScriptSnippet, languages: readonly TargetLanguage[] = Object.values(TargetLanguage)) {\n const translator = this.translatorFor(snip);\n const translated = this.translateSnippet(snip, translator, languages);\n return translated;\n }\n\n /**\n * Translates a batch of snippets, using a shared TS context.\n */\n public translateSnippets(\n snippets: TypeScriptSnippet[],\n languages: readonly TargetLanguage[] = Object.values(TargetLanguage),\n ): TranslatedSnippet[] {\n const start = performance.now();\n logging.debug(`Translating batch of ${snippets.length} snippets`);\n\n const res = this.translateBatch(snippets, languages);\n\n const duration = performance.now() - start;\n logging.debug(\n `Completed batch ${inspect({\n duration: `${(duration / 1000).toFixed(2)}s`,\n })}`,\n );\n\n return res;\n }\n\n private translateBatch(\n snippets: TypeScriptSnippet[],\n languages: readonly TargetLanguage[] = Object.values(TargetLanguage),\n ): TranslatedSnippet[] {\n const translatedSnippets: TranslatedSnippet[] = [];\n\n const batchTranslator = new BatchSnippetTranslator(snippets, {\n compiler: this.compiler,\n includeCompilerDiagnostics: this.includeCompilerDiagnostics,\n });\n\n for (const [snippet, translator] of batchTranslator) {\n translatedSnippets.push(this.translateSnippet(snippet, translator, languages));\n }\n\n return translatedSnippets;\n }\n\n private translateSnippet(\n snippet: TypeScriptSnippet,\n translator: ISnippetTranslator,\n languages: readonly TargetLanguage[],\n ): TranslatedSnippet {\n const translations = mkDict(\n languages.flatMap((lang, idx, array) => {\n if (array.slice(0, idx).includes(lang)) {\n return [];\n }\n const languageConverterFactory = TARGET_LANGUAGES[lang];\n const translated = translator.renderUsing(languageConverterFactory.createVisitor());\n return [[lang, { source: translated, version: languageConverterFactory.version }] as const];\n }),\n );\n\n if (snippet.parameters?.infused === undefined) {\n this.#diagnostics.push(...translator.diagnostics);\n }\n\n return TranslatedSnippet.fromSchema({\n translations: {\n ...translations,\n [ORIGINAL_SNIPPET_KEY]: { source: snippet.visibleSource, version: '0' },\n },\n location: snippet.location,\n didCompile: translator.didSuccessfullyCompile,\n fqnsReferenced: translator.fqnsReferenced(),\n fullSource: completeSource(snippet),\n syntaxKindCounter: translator.syntaxKindCounter(),\n });\n }\n}\n\nexport interface ISnippetTranslator {\n readonly diagnostics: readonly ts.Diagnostic[];\n readonly didSuccessfullyCompile: boolean | undefined;\n\n renderUsing(visitor: AstHandler<any>): string;\n syntaxKindCounter(): Partial<Record<ts.SyntaxKind, number>>;\n fqnsReferenced(): string[];\n}\n\nexport interface SnippetTranslatorOptions extends AstRendererOptions {\n /**\n * Re-use the given compiler if given\n */\n readonly compiler?: TypeScriptCompiler;\n\n /**\n * Include compiler errors in return diagnostics\n *\n * If false, only translation diagnostics will be returned.\n *\n * @default false\n */\n readonly includeCompilerDiagnostics?: boolean;\n}\n\n/**\n * Internal implementation of a single TypeScript snippet translator.\n *\n * Consumers should either use `SnippetTranslator` or `BatchSnippetTranslator`.\n */\nclass InternalSnippetTranslator implements ISnippetTranslator {\n public readonly translateDiagnostics: ts.Diagnostic[] = [];\n public readonly compileDiagnostics: ts.Diagnostic[] = [];\n\n private readonly visibleSpans: Spans;\n private readonly tryCompile: boolean;\n private readonly submoduleReferences: SubmoduleReferenceMap;\n\n public constructor(\n snippet: TypeScriptSnippet,\n private readonly compilation: CompilationResult,\n private readonly options: SnippetTranslatorOptions,\n ) {\n // Respect '/// !hide' and '/// !show' directives\n // Use the actual compiled source text to ensure spans match the AST\n this.visibleSpans = Spans.visibleSpansFromSource(compilation.rootFile.text);\n\n // Find submodule references on explicit imports\n this.submoduleReferences = SubmoduleReference.inSourceFile(\n compilation.rootFile,\n this.compilation.program.getTypeChecker(),\n );\n\n // This makes it about 5x slower, so only do it on demand\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n this.tryCompile = (this.options.includeCompilerDiagnostics || snippet.strict) ?? false;\n if (this.tryCompile) {\n const program = this.compilation.program;\n const diagnostics = [\n ...neverThrowing(program.getGlobalDiagnostics)(),\n ...neverThrowing(program.getSyntacticDiagnostics)(this.compilation.rootFile),\n ...neverThrowing(program.getDeclarationDiagnostics)(this.compilation.rootFile),\n ...neverThrowing(program.getSemanticDiagnostics)(this.compilation.rootFile),\n ];\n\n if (snippet.strict) {\n // In a strict assembly, so we'll need to brand all diagnostics here...\n for (const diag of diagnostics) {\n annotateStrictDiagnostic(diag);\n }\n }\n this.compileDiagnostics.push(...diagnostics);\n }\n }\n\n /**\n * Returns a boolean if compilation was attempted, and undefined if it was not.\n */\n public get didSuccessfullyCompile() {\n return this.tryCompile ? this.compileDiagnostics.length === 0 : undefined;\n }\n\n public renderUsing(visitor: AstHandler<any>) {\n const converter = new AstRenderer(\n this.compilation.rootFile,\n this.compilation.program.getTypeChecker(),\n visitor,\n this.options,\n // If we support transitive submodule access, don't provide a submodule reference map.\n supportsTransitiveSubmoduleAccess(visitor.language) ? undefined : this.submoduleReferences,\n );\n const converted = converter.convert(this.compilation.rootFile);\n this.translateDiagnostics.push(...filterVisibleDiagnostics(converter.diagnostics, this.visibleSpans));\n return renderTree(converted, { indentChar: visitor.indentChar, visibleSpans: this.visibleSpans });\n }\n\n public syntaxKindCounter(): Partial<Record<ts.SyntaxKind, number>> {\n const kindCounter = new SyntaxKindCounter(this.visibleSpans);\n return kindCounter.countKinds(this.compilation.rootFile);\n }\n\n public fqnsReferenced() {\n const visitor = new RecordReferencesVisitor(this.visibleSpans);\n const converter = new AstRenderer(\n this.compilation.rootFile,\n this.compilation.program.getTypeChecker(),\n visitor,\n this.options,\n this.submoduleReferences,\n );\n converter.convert(this.compilation.rootFile);\n return visitor.fqnsReferenced();\n }\n\n public get diagnostics(): readonly ts.Diagnostic[] {\n return ts.sortAndDeduplicateDiagnostics(this.compileDiagnostics.concat(this.translateDiagnostics));\n }\n}\n\n/**\n * Translate a single TypeScript snippet\n */\nexport class SnippetTranslator extends InternalSnippetTranslator {\n public constructor(snippet: TypeScriptSnippet, options: SnippetTranslatorOptions = {}) {\n const compiler = options.compiler ?? new TypeScriptCompiler();\n const source = completeSource(snippet);\n const fakeCurrentDirectory = snippet.parameters?.[SnippetParameters.$COMPILATION_DIRECTORY] ?? process.cwd();\n const compilation = compiler.compileBatchInMemory(\n [\n {\n filename: removeSlashes(formatLocation(snippet.location)),\n contents: source,\n },\n ],\n fakeCurrentDirectory,\n );\n\n super(\n snippet,\n {\n program: compilation.program,\n rootFile: compilation.rootFiles[0],\n },\n options,\n );\n }\n}\n\nexport interface BatchSnippetTranslatorOptions extends SnippetTranslatorOptions {\n /**\n * What directory to pretend the file is in (system parameter)\n *\n * Attached when compiling a literate file, as they compile in\n * the location where they are stored.\n *\n * @default - current working directory\n */\n readonly compilationDirectory?: string;\n}\n\n/**\n * Translate a single TypeScript snippet\n */\nexport class BatchSnippetTranslator {\n private readonly compilation: BatchCompilationResult;\n\n public constructor(\n private readonly snippets: TypeScriptSnippet[],\n private readonly options: BatchSnippetTranslatorOptions = {},\n ) {\n const compiler = options.compiler ?? new TypeScriptCompiler();\n const workingDir = options.compilationDirectory ?? process.cwd();\n\n const sources = snippets.map((snippet) => {\n const snippetLoc = snippet.parameters?.[SnippetParameters.$COMPILATION_DIRECTORY];\n const filename = removeSlashes(formatLocation(snippet.location));\n\n return {\n filename: snippetLoc ? path.relative(workingDir, path.join(snippetLoc, filename)) : filename,\n contents: completeSource(snippet),\n };\n });\n this.compilation = compiler.compileBatchInMemory(sources, workingDir);\n }\n\n *[Symbol.iterator](): Generator<[TypeScriptSnippet, ISnippetTranslator], void, unknown> {\n for (const [idx, snippet] of this.snippets.entries()) {\n const rootFile = this.compilation.rootFiles[idx];\n\n const translator: ISnippetTranslator = new InternalSnippetTranslator(\n snippet,\n {\n program: this.compilation.program,\n rootFile,\n },\n this.options,\n );\n\n yield [snippet, translator];\n }\n }\n}\n\n/**\n * Intercepts all exceptions thrown by the wrapped call, and logs them to\n * console.error instead of re-throwing, then returns an empty array. This\n * is here to avoid compiler crashes due to broken code examples that cause\n * the TypeScript compiler to hit a \"Debug Failure\".\n */\nfunction neverThrowing<A extends unknown[], R>(call: (...args: A) => readonly R[]): (...args: A) => readonly R[] {\n return (...args: A) => {\n try {\n return call(...args);\n } catch (err: any) {\n const isExpectedTypescriptError = err.message.includes('Debug Failure');\n\n if (!isExpectedTypescriptError) {\n console.error(`Failed to execute ${call.name}: ${err}`);\n }\n\n return [];\n }\n };\n}\n\n/**\n * Hide diagnostics that are rosetta-sourced if they are reported against a non-visible span\n */\nfunction filterVisibleDiagnostics(diags: readonly ts.Diagnostic[], visibleSpans: Spans): ts.Diagnostic[] {\n return diags.filter((d) => d.source !== 'rosetta' || d.start === undefined || visibleSpans.containsPosition(d.start));\n}\n\n/**\n * A translation of a TypeScript diagnostic into a data-only representation for Rosetta\n *\n * We cannot use the original `ts.Diagnostic` since it holds on to way too much\n * state (the source file and by extension the entire parse tree), which grows\n * too big to be properly serialized by a worker and also takes too much memory.\n *\n * Reduce it down to only the information we need.\n */\nexport interface SnippetTimingInfo {\n readonly name: string;\n readonly snippetKey: string;\n readonly durationMs: number;\n}\n\nexport interface RosettaDiagnostic {\n /**\n * If this is an error diagnostic or not\n */\n readonly isError: boolean;\n\n /**\n * If the diagnostic was emitted from an assembly that has its 'strict' flag set\n */\n readonly isFromStrictAssembly: boolean;\n\n /**\n * The formatted message, ready to be printed (will have colors and newlines in it)\n *\n * Ends in a newline.\n */\n readonly formattedMessage: string;\n\n /**\n * Optional timing information for snippet translation\n */\n readonly timingInfo?: SnippetTimingInfo;\n}\n\nexport function makeRosettaDiagnostic(isError: boolean, formattedMessage: string): RosettaDiagnostic {\n return { isError, formattedMessage, isFromStrictAssembly: false };\n}\n\nexport function makeTimingDiagnostic(snippetKey: string, name: string, durationMs: number): RosettaDiagnostic {\n return {\n isError: false,\n isFromStrictAssembly: false,\n formattedMessage: '',\n timingInfo: { snippetKey, name, durationMs },\n };\n}\n\nexport function extractTimingInfo(diagnostics: readonly RosettaDiagnostic[]): {\n timings: SnippetTimingInfo[];\n diagnostics: RosettaDiagnostic[];\n} {\n const timings: SnippetTimingInfo[] = [];\n const regular: RosettaDiagnostic[] = [];\n\n for (const diag of diagnostics) {\n if (diag.timingInfo) {\n timings.push(diag.timingInfo);\n } else {\n regular.push(diag);\n }\n }\n\n return { timings, diagnostics: regular };\n}\n\nexport function formatTimingTable(timings: SnippetTimingInfo[]): string {\n if (timings.length === 0) {\n return '';\n }\n\n const totalTime = timings.reduce((sum, t) => sum + t.durationMs, 0);\n const sorted = timings.sort((a, b) => b.durationMs - a.durationMs).slice(0, 10);\n\n const lines = [\n '',\n '=== Top 10 Slowest Snippets ===',\n 'Rank | Time (s) | % of Total | Snippet ',\n '-----|----------|------------|--------------------------------',\n ];\n\n for (const [idx, timing] of sorted.entries()) {\n const timeS = (timing.durationMs / 1000).toFixed(2).padStart(8);\n const pct = ((timing.durationMs / totalTime) * 100).toFixed(1).padStart(9) + '%';\n lines.push(`${(idx + 1).toString().padEnd(4)} | ${timeS} | ${pct} | ${timing.name}`);\n }\n\n lines.push('');\n lines.push(`Total translation time: ${(totalTime / 1000).toFixed(2)}s`);\n lines.push('');\n\n return lines.join('\\n');\n}\n\n/**\n * Turn TypeScript diagnostics into Rosetta diagnostics\n */\nexport function rosettaDiagFromTypescript(diag: ts.Diagnostic): RosettaDiagnostic {\n return {\n isError: diag.category === ts.DiagnosticCategory.Error,\n isFromStrictAssembly: hasStrictBranding(diag),\n formattedMessage: ts.formatDiagnosticsWithColorAndContext([diag], DIAG_HOST),\n };\n}\n\nconst DIAG_HOST = {\n getCurrentDirectory() {\n return '.';\n },\n getCanonicalFileName(fileName: string) {\n return fileName;\n },\n getNewLine() {\n return '\\n';\n },\n};\n\n/**\n * Remove slashes from a \"where\" description, as the TS compiler will interpret it as a directory\n * and we can't have that for compiling literate files\n */\nfunction removeSlashes(x: string) {\n return x.replace(/\\/|\\\\/g, '.');\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { TypeScriptSnippet } from './snippet';
2
2
  import { TranslatedSnippet } from './tablets/tablets';
3
- import { RosettaDiagnostic } from './translate';
3
+ import { RosettaDiagnostic, SnippetTimingInfo } from './translate';
4
4
  /**
5
5
  * Divide the work evenly over all processors by running 'translate_all_worker' in Worker Threads, then combine results
6
6
  *
@@ -15,5 +15,6 @@ export declare function translateAll(snippets: TypeScriptSnippet[], includeCompi
15
15
  export interface TranslateAllResult {
16
16
  translatedSnippets: TranslatedSnippet[];
17
17
  diagnostics: RosettaDiagnostic[];
18
+ timings?: SnippetTimingInfo[];
18
19
  }
19
20
  //# sourceMappingURL=translate_all.d.ts.map
@@ -6,6 +6,7 @@ const path = require("node:path");
6
6
  const workerpool = require("workerpool");
7
7
  const logging = require("./logging");
8
8
  const tablets_1 = require("./tablets/tablets");
9
+ const translate_1 = require("./translate");
9
10
  /**
10
11
  * Divide the work evenly over all processors by running 'translate_all_worker' in Worker Threads, then combine results
11
12
  *
@@ -34,14 +35,20 @@ async function translateAll(snippets, includeCompilerDiagnostics, batchSize) {
34
35
  const shouldBatchCompilation = batchSize != null;
35
36
  const requests = batchSnippets(snippetArr, includeCompilerDiagnostics, batchSize, shouldBatchCompilation);
36
37
  const responses = await Promise.all(requests.map((request) => pool.exec('translateBatch', [request])));
37
- const diagnostics = new Array();
38
+ const allDiagnostics = new Array();
38
39
  const translatedSnippets = new Array();
39
40
  // Combine results
40
41
  for (const response of responses) {
41
- diagnostics.push(...response.diagnostics);
42
+ allDiagnostics.push(...response.diagnostics);
42
43
  translatedSnippets.push(...response.translatedSchemas.map(tablets_1.TranslatedSnippet.fromSchema));
43
44
  }
44
- return { diagnostics, translatedSnippets };
45
+ // Extract timing info if enabled
46
+ const { timings, diagnostics } = (0, translate_1.extractTimingInfo)(allDiagnostics);
47
+ return {
48
+ diagnostics,
49
+ translatedSnippets,
50
+ timings: process.env.TIMING === '1' ? timings : undefined,
51
+ };
45
52
  }
46
53
  finally {
47
54
  // Not waiting on purpose
@@ -1 +1 @@
1
- {"version":3,"file":"translate_all.js","sourceRoot":"","sources":["../src/translate_all.ts"],"names":[],"mappings":";;AAoBA,oCAyCC;AA7DD,8BAA8B;AAC9B,kCAAkC;AAClC,yCAAyC;AAEzC,qCAAqC;AAErC,+CAAsD;AAItD;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,QAA6B,EAC7B,0BAAmC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node:os';\nimport * as path from 'node:path';\nimport * as workerpool 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 batchSize?: number,\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 N = process.env.JSII_ROSETTA_MAX_WORKER_COUNT\n ? parseInt(process.env.JSII_ROSETTA_MAX_WORKER_COUNT)\n : Math.min(16, Math.max(1, Math.ceil(os.cpus().length / 2)));\n const snippetArr = Array.from(snippets);\n const batchesOf = batchSize ? ` (in batches of ${batchSize})` : '';\n logging.info(`Translating ${snippetArr.length} snippets using ${N} workers${batchesOf}`);\n\n const pool = workerpool.pool(path.join(__dirname, 'translate_all_worker.js'), {\n maxWorkers: N,\n });\n\n try {\n const shouldBatchCompilation = batchSize != null;\n const requests = batchSnippets(snippetArr, includeCompilerDiagnostics, batchSize, shouldBatchCompilation);\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 shouldBatchCompilation: boolean = false,\n): TranslateBatchRequest[] {\n const logLevel = logging.current();\n const ret: TranslateBatchRequest[] = [];\n\n for (let i = 0; i < snippets.length; i += batchSize) {\n // create a unique worker name, purely for logging so can be pseudo random\n const workerId = Math.random().toString(16).slice(2, 6).toUpperCase();\n ret.push({\n workerName: `Worker#${workerId}`,\n snippets: snippets.slice(i, i + batchSize),\n includeCompilerDiagnostics,\n logLevel,\n batchSize: shouldBatchCompilation ? batchSize : undefined,\n });\n }\n\n return ret;\n}\n\nexport interface TranslateAllResult {\n translatedSnippets: TranslatedSnippet[];\n diagnostics: RosettaDiagnostic[];\n}\n"]}
1
+ {"version":3,"file":"translate_all.js","sourceRoot":"","sources":["../src/translate_all.ts"],"names":[],"mappings":";;AAoBA,oCAiDC;AArED,8BAA8B;AAC9B,kCAAkC;AAClC,yCAAyC;AAEzC,qCAAqC;AAErC,+CAAsD;AACtD,2CAAsF;AAGtF;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,QAA6B,EAC7B,0BAAmC,EACnC,SAAkB;IAElB,6EAA6E;IAC7E,6EAA6E;IAC7E,qDAAqD;IACrD,2FAA2F;IAC3F,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,6BAA6B;QACjD,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC;QACrD,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,QA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,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;SAC1D,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,yBAAyB;QACzB,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;IACxB,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CACpB,QAA6B,EAC7B,0BAAmC,EACnC,SAAS,GAAG,EAAE,EACd,yBAAkC,KAAK;IAEvC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IACnC,MAAM,GAAG,GAA4B,EAAE,CAAC;IAExC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC;QACpD,0EAA0E;QAC1E,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACtE,GAAG,CAAC,IAAI,CAAC;YACP,UAAU,EAAE,UAAU,QAAQ,EAAE;YAChC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC;YAC1C,0BAA0B;YAC1B,QAAQ;YACR,SAAS,EAAE,sBAAsB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;SAC1D,CAAC,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import * as os from 'node:os';\nimport * as path from 'node:path';\nimport * as workerpool from 'workerpool';\n\nimport * as logging from './logging';\nimport { TypeScriptSnippet } from './snippet';\nimport { TranslatedSnippet } from './tablets/tablets';\nimport { RosettaDiagnostic, SnippetTimingInfo, extractTimingInfo } 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 batchSize?: number,\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 N = process.env.JSII_ROSETTA_MAX_WORKER_COUNT\n ? parseInt(process.env.JSII_ROSETTA_MAX_WORKER_COUNT)\n : Math.min(16, Math.max(1, Math.ceil(os.cpus().length / 2)));\n const snippetArr = Array.from(snippets);\n const batchesOf = batchSize ? ` (in batches of ${batchSize})` : '';\n logging.info(`Translating ${snippetArr.length} snippets using ${N} workers${batchesOf}`);\n\n const pool = workerpool.pool(path.join(__dirname, 'translate_all_worker.js'), {\n maxWorkers: N,\n });\n\n try {\n const shouldBatchCompilation = batchSize != null;\n const requests = batchSnippets(snippetArr, includeCompilerDiagnostics, batchSize, shouldBatchCompilation);\n\n const responses: TranslateBatchResponse[] = await Promise.all(\n requests.map((request) => pool.exec('translateBatch', [request])),\n );\n\n const allDiagnostics = new Array<RosettaDiagnostic>();\n const translatedSnippets = new Array<TranslatedSnippet>();\n\n // Combine results\n for (const response of responses) {\n allDiagnostics.push(...response.diagnostics);\n translatedSnippets.push(...response.translatedSchemas.map(TranslatedSnippet.fromSchema));\n }\n\n // Extract timing info if enabled\n const { timings, diagnostics } = extractTimingInfo(allDiagnostics);\n\n return {\n diagnostics,\n translatedSnippets,\n timings: process.env.TIMING === '1' ? timings : undefined,\n };\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 shouldBatchCompilation: boolean = false,\n): TranslateBatchRequest[] {\n const logLevel = logging.current();\n const ret: TranslateBatchRequest[] = [];\n\n for (let i = 0; i < snippets.length; i += batchSize) {\n // create a unique worker name, purely for logging so can be pseudo random\n const workerId = Math.random().toString(16).slice(2, 6).toUpperCase();\n ret.push({\n workerName: `Worker#${workerId}`,\n snippets: snippets.slice(i, i + batchSize),\n includeCompilerDiagnostics,\n logLevel,\n batchSize: shouldBatchCompilation ? batchSize : undefined,\n });\n }\n\n return ret;\n}\n\nexport interface TranslateAllResult {\n translatedSnippets: TranslatedSnippet[];\n diagnostics: RosettaDiagnostic[];\n timings?: SnippetTimingInfo[];\n}\n"]}
@@ -4,12 +4,18 @@ exports.singleThreadedTranslateAll = singleThreadedTranslateAll;
4
4
  /**
5
5
  * Pool worker for extract.ts
6
6
  */
7
+ const node_util_1 = require("node:util");
7
8
  const workerpool = require("workerpool");
8
9
  const logging = require("./logging");
10
+ const snippet_1 = require("./snippet");
11
+ const key_1 = require("./tablets/key");
9
12
  const translate_1 = require("./translate");
10
13
  function translateBatch(request) {
11
14
  // because we are in a worker process we need to explicitly configure the log level again
12
15
  logging.configure({ level: request.logLevel ?? logging.Level.QUIET, prefix: request.workerName });
16
+ if (process.env.TIMING === '1' && request.batchSize) {
17
+ logging.warn('TIMING=1 is not supported in batch compilation mode');
18
+ }
13
19
  const result = request.batchSize
14
20
  ? batchTranslateAll(request.snippets, request.includeCompilerDiagnostics)
15
21
  : singleThreadedTranslateAll(request.snippets, request.includeCompilerDiagnostics);
@@ -40,18 +46,27 @@ function batchTranslateAll(snippets, includeCompilerDiagnostics) {
40
46
  function singleThreadedTranslateAll(snippets, includeCompilerDiagnostics) {
41
47
  const translatedSnippets = new Array();
42
48
  const failures = new Array();
49
+ const timings = new Array();
43
50
  const translator = new translate_1.Translator(includeCompilerDiagnostics);
44
51
  for (const block of snippets) {
52
+ const start = performance.now();
53
+ const currentSnippetKey = (0, key_1.snippetKey)(block);
54
+ logging.debug(`Translating ${currentSnippetKey} ${(0, node_util_1.inspect)(block.parameters ?? {})}`);
45
55
  try {
46
56
  translatedSnippets.push(translator.translate(block));
47
57
  }
48
58
  catch (e) {
49
59
  failures.push((0, translate_1.makeRosettaDiagnostic)(true, `rosetta: error translating snippet: ${e}\n${e.stack}\n${block.completeSource}`));
50
60
  }
61
+ const timing = (0, translate_1.makeTimingDiagnostic)(currentSnippetKey, (0, snippet_1.formatLocation)(block.location), performance.now() - start);
62
+ timings.push(timing);
63
+ logging.debug(`Completed ${timing.timingInfo.snippetKey} ${(0, node_util_1.inspect)({
64
+ duration: `${(timing.timingInfo.durationMs / 1000).toFixed(2)}s`,
65
+ })}`);
51
66
  }
52
67
  return {
53
68
  translatedSnippets,
54
- diagnostics: [...translator.diagnostics, ...failures],
69
+ diagnostics: [...translator.diagnostics, ...failures, ...timings],
55
70
  };
56
71
  }
57
72
  workerpool.worker({ translateBatch });
@@ -1 +1 @@
1
- {"version":3,"file":"translate_all_worker.js","sourceRoot":"","sources":["../src/translate_all_worker.ts"],"names":[],"mappings":";;AA8DA,gEAuBC;AArFD;;GAEG;AACH,yCAAyC;AAEzC,qCAAqC;AAIrC,2CAAmF;AAiBnF,SAAS,cAAc,CAAC,OAA8B;IACpD,yFAAyF;IACzF,OAAO,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAClG,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS;QAC9B,CAAC,CAAC,iBAAiB,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,0BAA0B,CAAC;QACzE,CAAC,CAAC,0BAA0B,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,0BAA0B,CAAC,CAAC;IAErF,OAAO;QACL,iBAAiB,EAAE,MAAM,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YAChB,QAAQ,CAAC,IAAI,CACX,IAAA,iCAAqB,EAAC,IAAI,EAAE,uCAAuC,CAAC,KAAK,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,cAAc,EAAE,CAAC,CAC7G,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,kBAAkB;QAClB,WAAW,EAAE,CAAC,GAAG,UAAU,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC;KACtD,CAAC;AACJ,CAAC;AAED,UAAU,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC","sourcesContent":["/**\n * Pool worker for extract.ts\n */\nimport * as workerpool from 'workerpool';\n\nimport * as logging from './logging';\nimport { TypeScriptSnippet } from './snippet';\nimport { TranslatedSnippetSchema } from './tablets/schema';\nimport { TranslatedSnippet } from './tablets/tablets';\nimport { RosettaDiagnostic, makeRosettaDiagnostic, Translator } from './translate';\nimport { TranslateAllResult } from './translate_all';\n\nexport interface TranslateBatchRequest {\n readonly workerName: string;\n readonly snippets: TypeScriptSnippet[];\n readonly includeCompilerDiagnostics: boolean;\n readonly logLevel?: logging.Level;\n readonly batchSize?: number;\n}\n\nexport interface TranslateBatchResponse {\n // Cannot be 'TranslatedSnippet' because needs to be serializable\n readonly translatedSchemas: TranslatedSnippetSchema[];\n readonly diagnostics: RosettaDiagnostic[];\n}\n\nfunction translateBatch(request: TranslateBatchRequest): TranslateBatchResponse {\n // because we are in a worker process we need to explicitly configure the log level again\n logging.configure({ level: request.logLevel ?? logging.Level.QUIET, prefix: request.workerName });\n const result = request.batchSize\n ? batchTranslateAll(request.snippets, request.includeCompilerDiagnostics)\n : singleThreadedTranslateAll(request.snippets, request.includeCompilerDiagnostics);\n\n return {\n translatedSchemas: result.translatedSnippets.map((s) => s.snippet),\n diagnostics: result.diagnostics,\n };\n}\n\nfunction batchTranslateAll(snippets: TypeScriptSnippet[], includeCompilerDiagnostics: boolean): TranslateAllResult {\n const translatedSnippets = new Array<TranslatedSnippet>();\n\n const failures = new Array<RosettaDiagnostic>();\n\n const translator = new Translator(includeCompilerDiagnostics);\n\n try {\n const results = translator.translateSnippets(snippets);\n translatedSnippets.push(...results);\n } catch (e: any) {\n failures.push(makeRosettaDiagnostic(true, `rosetta: error translating batch: ${e}\\n${e.stack}`));\n }\n\n return {\n translatedSnippets,\n diagnostics: [...translator.diagnostics, ...failures],\n };\n}\n\n/**\n * Translate the given snippets using a single compiler\n */\nexport function singleThreadedTranslateAll(\n snippets: TypeScriptSnippet[],\n includeCompilerDiagnostics: boolean,\n): TranslateAllResult {\n const translatedSnippets = new Array<TranslatedSnippet>();\n\n const failures = new Array<RosettaDiagnostic>();\n\n const translator = new Translator(includeCompilerDiagnostics);\n for (const block of snippets) {\n try {\n translatedSnippets.push(translator.translate(block));\n } catch (e: any) {\n failures.push(\n makeRosettaDiagnostic(true, `rosetta: error translating snippet: ${e}\\n${e.stack}\\n${block.completeSource}`),\n );\n }\n }\n\n return {\n translatedSnippets,\n diagnostics: [...translator.diagnostics, ...failures],\n };\n}\n\nworkerpool.worker({ translateBatch });\n"]}
1
+ {"version":3,"file":"translate_all_worker.js","sourceRoot":"","sources":["../src/translate_all_worker.ts"],"names":[],"mappings":";;AAqEA,gEAmCC;AAxGD;;GAEG;AACH,yCAAoC;AACpC,yCAAyC;AAEzC,qCAAqC;AACrC,uCAA8D;AAC9D,uCAA2C;AAG3C,2CAAyG;AAiBzG,SAAS,cAAc,CAAC,OAA8B;IACpD,yFAAyF;IACzF,OAAO,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAElG,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;IACtE,CAAC;IAED,MAAM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G,QAAQ,EAAE,GAAG,OAAO,CAAC;KAClE,CAAC;AACJ,CAAC;AAED,UAAU,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC","sourcesContent":["/**\n * Pool worker for extract.ts\n */\nimport { inspect } from 'node:util';\nimport * as workerpool from 'workerpool';\n\nimport * as logging from './logging';\nimport { formatLocation, TypeScriptSnippet } from './snippet';\nimport { snippetKey } from './tablets/key';\nimport { TranslatedSnippetSchema } from './tablets/schema';\nimport { TranslatedSnippet } from './tablets/tablets';\nimport { RosettaDiagnostic, makeRosettaDiagnostic, makeTimingDiagnostic, Translator } from './translate';\nimport { TranslateAllResult } from './translate_all';\n\nexport interface TranslateBatchRequest {\n readonly workerName: string;\n readonly snippets: TypeScriptSnippet[];\n readonly includeCompilerDiagnostics: boolean;\n readonly logLevel?: logging.Level;\n readonly batchSize?: number;\n}\n\nexport interface TranslateBatchResponse {\n // Cannot be 'TranslatedSnippet' because needs to be serializable\n readonly translatedSchemas: TranslatedSnippetSchema[];\n readonly diagnostics: RosettaDiagnostic[];\n}\n\nfunction translateBatch(request: TranslateBatchRequest): TranslateBatchResponse {\n // because we are in a worker process we need to explicitly configure the log level again\n logging.configure({ level: request.logLevel ?? logging.Level.QUIET, prefix: request.workerName });\n\n if (process.env.TIMING === '1' && request.batchSize) {\n logging.warn('TIMING=1 is not supported in batch compilation mode');\n }\n\n const result = request.batchSize\n ? batchTranslateAll(request.snippets, request.includeCompilerDiagnostics)\n : singleThreadedTranslateAll(request.snippets, request.includeCompilerDiagnostics);\n\n return {\n translatedSchemas: result.translatedSnippets.map((s) => s.snippet),\n diagnostics: result.diagnostics,\n };\n}\n\nfunction batchTranslateAll(snippets: TypeScriptSnippet[], includeCompilerDiagnostics: boolean): TranslateAllResult {\n const translatedSnippets = new Array<TranslatedSnippet>();\n\n const failures = new Array<RosettaDiagnostic>();\n\n const translator = new Translator(includeCompilerDiagnostics);\n\n try {\n const results = translator.translateSnippets(snippets);\n translatedSnippets.push(...results);\n } catch (e: any) {\n failures.push(makeRosettaDiagnostic(true, `rosetta: error translating batch: ${e}\\n${e.stack}`));\n }\n\n return {\n translatedSnippets,\n diagnostics: [...translator.diagnostics, ...failures],\n };\n}\n\n/**\n * Translate the given snippets using a single compiler\n */\nexport function singleThreadedTranslateAll(\n snippets: TypeScriptSnippet[],\n includeCompilerDiagnostics: boolean,\n): TranslateAllResult {\n const translatedSnippets = new Array<TranslatedSnippet>();\n const failures = new Array<RosettaDiagnostic>();\n const timings = new Array<RosettaDiagnostic>();\n\n const translator = new Translator(includeCompilerDiagnostics);\n for (const block of snippets) {\n const start = performance.now();\n const currentSnippetKey = snippetKey(block);\n logging.debug(`Translating ${currentSnippetKey} ${inspect(block.parameters ?? {})}`);\n\n try {\n translatedSnippets.push(translator.translate(block));\n } catch (e: any) {\n failures.push(\n makeRosettaDiagnostic(true, `rosetta: error translating snippet: ${e}\\n${e.stack}\\n${block.completeSource}`),\n );\n }\n\n const timing = makeTimingDiagnostic(currentSnippetKey, formatLocation(block.location), performance.now() - start);\n timings.push(timing);\n logging.debug(\n `Completed ${timing.timingInfo!.snippetKey} ${inspect({\n duration: `${(timing.timingInfo!.durationMs / 1000).toFixed(2)}s`,\n })}`,\n );\n }\n\n return {\n translatedSnippets,\n diagnostics: [...translator.diagnostics, ...failures, ...timings],\n };\n}\n\nworkerpool.worker({ translateBatch });\n"]}
package/package.json CHANGED
@@ -11,7 +11,6 @@
11
11
  "build": "npx projen build",
12
12
  "clobber": "npx projen clobber",
13
13
  "compile": "npx projen compile",
14
- "contributors:update": "npx projen contributors:update",
15
14
  "default": "npx projen default",
16
15
  "eject": "npx projen eject",
17
16
  "eslint": "npx projen eslint",
@@ -46,7 +45,6 @@
46
45
  "@types/workerpool": "^6.4.7",
47
46
  "@typescript-eslint/eslint-plugin": "^8",
48
47
  "@typescript-eslint/parser": "^8",
49
- "all-contributors-cli": "^6.26.1",
50
48
  "constructs": "^10.0.0",
51
49
  "eslint": "^9",
52
50
  "eslint-config-prettier": "^8.10.2",
@@ -59,7 +57,7 @@
59
57
  "memfs": "^4.51.1",
60
58
  "mock-fs": "^5.5.0",
61
59
  "prettier": "^2.8.8",
62
- "projen": "^0.98.29",
60
+ "projen": "^0.98.30",
63
61
  "tar": "^6.2.1",
64
62
  "ts-jest": "^29.4.6",
65
63
  "ts-node": "^10.9.2"
@@ -88,7 +86,7 @@
88
86
  "publishConfig": {
89
87
  "access": "public"
90
88
  },
91
- "version": "5.9.21-dev.0",
89
+ "version": "5.9.21",
92
90
  "types": "lib/index.d.ts",
93
91
  "exports": {
94
92
  ".": "./lib/index.js",