From fe4e9078436246b1488b808c5d004d6812782e18 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Thu, 19 Nov 2020 13:31:49 -0800 Subject: [PATCH] fix(cfn-include): cfn-include fails in mono-CDK The cloudformation-include module generates a big JSON file at build time that contains the mapping from the CloudFormation resource type to the fully-qualified class name of the corresponding L1 (something like "AWS::S3::Bucket": "@aws-cdk/aws-s3.CfnBucket"). The problem is that mono-CDK re-packages all of the per-service modules into one big module, and requiring the module from the mapping fails for it. Solve the issue by adding an additional build step in mono-CDK that re-writes that file with the mapping values changed (to something like "monocdk/aws-s3.CfnBucket"). Fixes #11342 --- packages/monocdk/.gitignore | 1 + .../monocdk/cfn-include-rewrite-mappings.js | 17 +++++++++++++++++ packages/monocdk/package.json | 5 ++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 packages/monocdk/cfn-include-rewrite-mappings.js diff --git a/packages/monocdk/.gitignore b/packages/monocdk/.gitignore index 155eb4afc38a9..b68c3fa1bfb96 100644 --- a/packages/monocdk/.gitignore +++ b/packages/monocdk/.gitignore @@ -1,4 +1,5 @@ *.js +!cfn-include-rewrite-mappings.js *.d.ts !deps.js !gen.js diff --git a/packages/monocdk/cfn-include-rewrite-mappings.js b/packages/monocdk/cfn-include-rewrite-mappings.js new file mode 100644 index 0000000000000..e3d9ad70f7b8a --- /dev/null +++ b/packages/monocdk/cfn-include-rewrite-mappings.js @@ -0,0 +1,17 @@ +/* + * This script modifies the cfn-types-2-classes.json + * file that is generated by the build of the cloudformation-include package. + * It changes the values of the mappings to point to monocdk instead of the service-specific packages. + */ + +const fs = require('fs'); +const path = require('path'); + +const mappingFilePath = path.resolve(path.join(__dirname, 'lib', 'cloudformation-include', 'cfn-types-2-classes.json')); +const cfnTypes2Classes = require(mappingFilePath); +for (const cfnType of Object.keys(cfnTypes2Classes)) { + const fqn = cfnTypes2Classes[cfnType]; + // replace @aws-cdk/aws- with monocdk/aws- + cfnTypes2Classes[cfnType] = fqn.replace('@aws-cdk', 'monocdk') +} +fs.writeFileSync(mappingFilePath, JSON.stringify(cfnTypes2Classes, undefined, 2) + '\n'); diff --git a/packages/monocdk/package.json b/packages/monocdk/package.json index 5ef18cf33c921..cd383303fa9c7 100644 --- a/packages/monocdk/package.json +++ b/packages/monocdk/package.json @@ -32,7 +32,10 @@ "jest": true, "eslint": { "disable": true - } + }, + "post": [ + "node ./cfn-include-rewrite-mappings.js" + ] }, "pkglint": { "exclude": [