Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core): include aws-rfdk in version reporting #9337

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/@aws-cdk/core/lib/private/runtime-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { major as nodeMajorVersion } from './node-version';

// list of NPM scopes included in version reporting e.g. @aws-cdk and @aws-solutions-konstruk
const WHITELIST_SCOPES = ['@aws-cdk', '@aws-solutions-konstruk', '@aws-solutions-constructs'];
// list of NPM packages included in version reporting
const WHITELIST_PACKAGES = ['aws-rfdk'];

/**
* Returns a list of loaded modules and their versions.
Expand All @@ -26,6 +28,7 @@ export function collectRuntimeInformation(): cxschema.RuntimeInfo {
foundMatch = true;
}
}
foundMatch = foundMatch || WHITELIST_PACKAGES.includes(name);

if (!foundMatch) {
delete libraries[name];
Expand Down
28 changes: 28 additions & 0 deletions packages/@aws-cdk/core/test/test.runtime-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,34 @@ export = {
test.done();
},

'version reporting finds aws-rfdk package'(test: Test) {
const pkgdir = fs.mkdtempSync(path.join(os.tmpdir(), 'runtime-info-rfdk'));
const mockVersion = '1.2.3';

fs.writeFileSync(path.join(pkgdir, 'index.js'), 'module.exports = \'this is foo\';');
fs.writeFileSync(path.join(pkgdir, 'package.json'), JSON.stringify({
name: 'aws-rfdk',
version: mockVersion,
}));

// eslint-disable-next-line @typescript-eslint/no-require-imports, import/no-extraneous-dependencies
require(pkgdir);

const runtimeInfo = collectRuntimeInformation();

// eslint-disable-next-line @typescript-eslint/no-require-imports
const version = require('../package.json').version;
test.deepEqual(runtimeInfo.libraries , {
'@aws-cdk/core': version,
'@aws-cdk/cx-api': version,
'@aws-cdk/cloud-assembly-schema': version,
'@aws-solutions-konstruk/foo': mockVersion, // picks up the module from the other test.
'aws-rfdk': mockVersion,
'jsii-runtime': `node.js/${process.version}`,
});
test.done();
},

'version reporting finds no version with no associated package.json'(test: Test) {
const pkgdir = fs.mkdtempSync(path.join(os.tmpdir(), 'runtime-info-find-npm-package-fixture'));
const mockVersion = '1.2.3';
Expand Down