From fde8d34a28a019d8e60d4312b55b4c7d8759641b Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Wed, 5 Dec 2018 12:29:20 +0200 Subject: [PATCH 1/2] feat(core): only include cdk libs in version reporting Include only libraries with names that start with "@aws-cdk", "aws-cdk" or "jsii-". Fixes awslabs/cdk-ops#172 --- packages/@aws-cdk/cdk/lib/app.ts | 23 +++++++++++++++++++++++ packages/@aws-cdk/cdk/test/test.app.ts | 20 +++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/cdk/lib/app.ts b/packages/@aws-cdk/cdk/lib/app.ts index 604f4295df332..0257c7bfb03b6 100644 --- a/packages/@aws-cdk/cdk/lib/app.ts +++ b/packages/@aws-cdk/cdk/lib/app.ts @@ -136,7 +136,30 @@ export class App extends Root { // add jsii runtime version libraries['jsii-runtime'] = getJsiiAgentVersion(); + // filter out any non-CDK libraries + for (const name of Object.keys(libraries)) { + if (!filterCDKLibraries(name)) { + delete libraries[name]; + } + } + return { libraries }; + + function filterCDKLibraries(name: string) { + if (name.startsWith('@aws-cdk')) { + return true; + } + + if (name === 'aws-cdk') { + return true; + } + + if (name.startsWith('jsii-')) { + return true; + } + + return false; + } } private getStack(stackname: string) { diff --git a/packages/@aws-cdk/cdk/test/test.app.ts b/packages/@aws-cdk/cdk/test/test.app.ts index dabdd852b2997..1f3712dfefc87 100644 --- a/packages/@aws-cdk/cdk/test/test.app.ts +++ b/packages/@aws-cdk/cdk/test/test.app.ts @@ -296,7 +296,25 @@ export = { delete process.env.JSII_AGENT; test.done(); - } + }, + + 'version reporting includes only @aws-cdk, aws-cdk and jsii libraries'(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, + '@aws-cdk/cx-api': version, + 'jsii-runtime': `node.js/${process.version}` + }); + + test.done(); + }, }; class MyConstruct extends Construct { From 2b58b65fabdd9f4a3cfaf9b0eac65102e55e848a Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Wed, 5 Dec 2018 13:28:47 +0200 Subject: [PATCH 2/2] Only include pacakges in the @aw-cdk scope --- packages/@aws-cdk/cdk/lib/app.ts | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/packages/@aws-cdk/cdk/lib/app.ts b/packages/@aws-cdk/cdk/lib/app.ts index 0257c7bfb03b6..bdf013f5091ac 100644 --- a/packages/@aws-cdk/cdk/lib/app.ts +++ b/packages/@aws-cdk/cdk/lib/app.ts @@ -133,33 +133,17 @@ export class App extends Root { } } - // add jsii runtime version - libraries['jsii-runtime'] = getJsiiAgentVersion(); - - // filter out any non-CDK libraries + // include only libraries that are in the @aws-cdk npm scope for (const name of Object.keys(libraries)) { - if (!filterCDKLibraries(name)) { + if (!name.startsWith('@aws-cdk/')) { delete libraries[name]; } } - return { libraries }; - - function filterCDKLibraries(name: string) { - if (name.startsWith('@aws-cdk')) { - return true; - } - - if (name === 'aws-cdk') { - return true; - } - - if (name.startsWith('jsii-')) { - return true; - } + // add jsii runtime version + libraries['jsii-runtime'] = getJsiiAgentVersion(); - return false; - } + return { libraries }; } private getStack(stackname: string) {