Skip to content

Commit

Permalink
fix(cfn-include): cfn-include fails in mono-CDK
Browse files Browse the repository at this point in the history
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
  • Loading branch information
skinny85 committed Nov 23, 2020
1 parent 1484e61 commit fe4e907
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/monocdk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.js
!cfn-include-rewrite-mappings.js
*.d.ts
!deps.js
!gen.js
Expand Down
17 changes: 17 additions & 0 deletions packages/monocdk/cfn-include-rewrite-mappings.js
Original file line number Diff line number Diff line change
@@ -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-<service> with monocdk/aws-<service>
cfnTypes2Classes[cfnType] = fqn.replace('@aws-cdk', 'monocdk')
}
fs.writeFileSync(mappingFilePath, JSON.stringify(cfnTypes2Classes, undefined, 2) + '\n');
5 changes: 4 additions & 1 deletion packages/monocdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
"jest": true,
"eslint": {
"disable": true
}
},
"post": [
"node ./cfn-include-rewrite-mappings.js"
]
},
"pkglint": {
"exclude": [
Expand Down

0 comments on commit fe4e907

Please sign in to comment.