diff --git a/packages/@aws-cdk/cdk/lib/app.ts b/packages/@aws-cdk/cdk/lib/app.ts index 4212b43683fa7..604f4295df332 100644 --- a/packages/@aws-cdk/cdk/lib/app.ts +++ b/packages/@aws-cdk/cdk/lib/app.ts @@ -133,6 +133,9 @@ export class App extends Root { } } + // add jsii runtime version + libraries['jsii-runtime'] = getJsiiAgentVersion(); + return { libraries }; } @@ -205,3 +208,15 @@ function findNpmPackage(fileName: string): { name: string, version: string, priv return s; } } + +function getJsiiAgentVersion() { + let jsiiAgent = process.env.JSII_AGENT; + + // if JSII_AGENT is not specified, we will assume this is a node.js runtime + // and plug in our node.js version + if (!jsiiAgent) { + jsiiAgent = `node.js/${process.version}`; + } + + return jsiiAgent; +} \ No newline at end of file diff --git a/packages/@aws-cdk/cdk/test/test.app.ts b/packages/@aws-cdk/cdk/test/test.app.ts index 7d32d714da2db..dabdd852b2997 100644 --- a/packages/@aws-cdk/cdk/test/test.app.ts +++ b/packages/@aws-cdk/cdk/test/test.app.ts @@ -17,6 +17,7 @@ function withApp(context: { [key: string]: any } | undefined, block: (app: App) } const app = new App(); + block(app); app.run(); @@ -266,6 +267,36 @@ export = { test.done(); }, + + 'runtime library versions'(test: Test) { + const response = withApp({}, app => { + const stack = new Stack(app, 'stack1'); + new Resource(stack, 'MyResource', { type: 'Resource::Type' }); + }); + + const libs = response.runtime.libraries; + + const version = require('../package.json').version; + test.deepEqual(libs['@aws-cdk/cdk'], version); + test.deepEqual(libs['@aws-cdk/cx-api'], version); + test.deepEqual(libs['jsii-runtime'], `node.js/${process.version}`); + test.done(); + }, + + 'jsii-runtime version loaded from JSII_AGENT'(test: Test) { + process.env.JSII_AGENT = 'Java/1.2.3.4'; + + const response = withApp({}, app => { + const stack = new Stack(app, 'stack1'); + new Resource(stack, 'MyResource', { type: 'Resource::Type' }); + }); + + const libs = response.runtime.libraries; + test.deepEqual(libs['jsii-runtime'], `Java/1.2.3.4`); + + delete process.env.JSII_AGENT; + test.done(); + } }; class MyConstruct extends Construct {