jsii-pacmak: jsii Package Maker

1.128.0 · active · verified Sun Apr 19

jsii-pacmak is a critical component of the `jsii` project, an AWS-developed code generation framework. Its core function is to generate and build ready-to-publish, language-specific packages (e.g., for Java, Python, .NET, Go, C#) from a TypeScript-defined `jsii` module. This capability allows developers to author libraries once in TypeScript and then consume them consistently across multiple programming languages, facilitating polyglot development for cloud constructs, notably within the AWS Cloud Development Kit (CDK). The package is currently at version 1.128.0 and is part of an actively maintained ecosystem, characterized by frequent patch and minor releases, often on a weekly or bi-weekly cadence, as seen in its recent release history. Its primary differentiator is its robust ability to bridge TypeScript definitions to fully functional APIs in various target languages, ensuring a uniform developer experience across the polyglot landscape.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic `jsii` project, define a simple TypeScript class, and then use `jsii-pacmak` to generate language-specific packages (Java and Python in this example) ready for publishing.

mkdir my-jsii-lib
cd my-jsii-lib
npm init -y
npm install jsii
npm install -D typescript @types/node

cat > tsconfig.json <<EOF
{
  "compilerOptions": {
    "alwaysStrict": true,
    "declaration": true,
    "experimentalDecorators": true,
    "lib": ["es2018"],
    "module": "commonjs",
    "noEmitOnError": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noPropertyAccessFromIndexSignature": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "resolveJsonModule": true,
    "strict": true,
    "strictBindCallApply": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": true,
    "stripInternal": true,
    "target": "es2018",
    "outDir": "lib"
  },
  "include": ["src/**/*.ts"]
}
EOF

mkdir src
cat > src/index.ts <<EOF
export interface MyProps {
  readonly message: string;
}

export class Greeter {
  public readonly greeting: string;

  constructor(props: MyProps) {
    this.greeting = `Hello, ${props.message} from jsii!`;
  }

  public sayHello(): string {
    return this.greeting;
  }
}
EOF

# Configure package.json for jsii targets
node -e "const pkg = require('./package.json'); pkg.jsii = { 'outdir': 'dist', 'targets': { 'java': { 'package': 'com.myorg.mylib', 'maven': { 'groupId': 'com.myorg', 'artifactId': 'mylib' } }, 'python': { 'distName': 'my-jsii-lib', 'module': 'my_jsii_lib' } } }; require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2));"

npx jsii
npx jsii-pacmak

view raw JSON →