The `jsii-rosetta` library, currently at version 5.9.39, is an essential tool within the `jsii` ecosystem, developed by AWS. Its core purpose is to translate code snippets written in one `jsii`-supported language (primarily TypeScript) into other target languages such as Python, Java, C#, and Go. This functionality is crucial for projects like the AWS Cloud Development Kit (CDK), enabling documentation to display examples across various programming languages from a single source. `jsii-rosetta` maintains a rapid and continuous release cadence, frequently updating its internal `jsii` and TypeScript dependencies to ensure compatibility and leverage the latest `jsii` features. Its key differentiator is its specialized focus on `jsii`-compliant code translation, providing robust tools for syntax analysis, type resolution, and idiomatic translation across multiple language runtimes.
npm install jsii-rosettaVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to initialize the `Rosetta` translator and translate a TypeScript AWS CDK code snippet into Python and Java, handling potential translation failures.
Always ensure your `jsii-rosetta` version is compatible with your project's `jsii` and `typescript` versions. Refer to the `jsii-rosetta` release notes and `jsii` compatibility matrix.
Ensure your Node.js environment meets or exceeds the specified minimum version (currently `>= 20.16.0`). Use a Node.js version manager like `nvm` to easily switch versions.
Design `jsii` constructs with clarity and strong typing. Test translations for complex snippets. Simplify TypeScript patterns where direct translation might be ambiguous or non-idiomatic in target languages.
Install all necessary `jsii` packages (e.g., `aws-cdk-lib`) as `devDependencies` or `dependencies` in your project. If running in a separate context, ensure the `node_modules` are properly resolved or paths configured.
Run `npm install jsii-rosetta` or `yarn add jsii-rosetta`. Verify your `tsconfig.json` includes `node_modules` in its `typeRoots` or `moduleResolution` settings.
Ensure you are using `import { Rosetta } from 'jsii-rosetta';` and instantiate it with `new Rosetta()`. Check `jsii-rosetta` documentation for API changes if using an older version.Ensure your Node.js version meets the `jsii-rosetta` requirements (e.g., `>= 20.16.0`). Reinstall `jsii-rosetta` to ensure all its peer dependencies, including the `jsii-runtime`, are correctly linked.
Ensure that the `jsii` packages referenced in your code snippets are installed in your project's `node_modules` (e.g., `npm install aws-cdk-lib`). If running programmatically, you might need to specify a `projectRoot` in `Rosetta`'s options for proper module resolution.