Hey team, I'm not a TypeScript developer, so apologies for any syntax errors or missed troubleshooting steps that are in the below.
When calling cdk-import cfn -l <language> <resource>, the generated jsii_type key appears to be using the same hash for every module. Which means that when using multiple Level 1 CDK Constructs generated by cdk-import, only one of the resources are recognised. Note: This is only impacts languages other than typescript.
Looking through the compile.ts in the jsii-srcmak library: https://github.com/cdklabs/jsii-srcmak/blob/main/src/compile.ts
This appears to be because the jsii_type key is generated using the value provided to the moduleKey argument, else it defaults to a SHA256 hash of the basepath variable. However, when logging the value of the basepath variable, it appears as though this always defaults to index.ts, meaning the created hash is always the same.
https://github.com/cdklabs/jsii-srcmak/blob/5c32a498d369edfb401d5e923d6255bfc21fdd91/src/compile.ts#L29
Generated hash:
1bc04b5291c26a46d918139138b992d2de976d6851d0893b0476b85bfbdfc6e6
Resulting in the following assembly code (for python, but similar outputs exist for other languages):
__jsii_assembly__ = jsii.JSIIAssembly.load(
"1bc04b5291c26a46d918139138b992d2de976d6851d0893b0476b85bfbdfc6e6",
"0.0.0",
__name__[0:-6],
"1bc04b5291c26a46d918139138b992d2de976d6851d0893b0476b85bfbdfc6e6@0.0.0.jsii.tgz",
)
A workaround that I've used for this in local testing is to pass a modified version of the typeName as the 'moduleKey'.
e.g.
async function renderCode(options) {
const srcmakopts = {
deps: cdkDeps.map(x => path.dirname(require.resolve(`${x}/package.json`))),
moduleKey: options.typeName.replace(/:/g, ''),
};
The resulting jsii_type, and generated prefix of the *.tgz file, is prefixed with the name of the resource type, and thus allows for multiple imported type modules to be used within the same CDK application.
Can we please have something like this implemented? Or alternatively have an option provided in the CLI in which we can define an override for the moduleKey?
Thanks.
Hey team, I'm not a TypeScript developer, so apologies for any syntax errors or missed troubleshooting steps that are in the below.
When calling
cdk-import cfn -l <language> <resource>, the generatedjsii_typekey appears to be using the same hash for every module. Which means that when using multiple Level 1 CDK Constructs generated bycdk-import, only one of the resources are recognised. Note: This is only impacts languages other thantypescript.Looking through the
compile.tsin thejsii-srcmaklibrary: https://github.com/cdklabs/jsii-srcmak/blob/main/src/compile.tsThis appears to be because the
jsii_typekey is generated using the value provided to themoduleKeyargument, else it defaults to a SHA256 hash of thebasepathvariable. However, when logging the value of thebasepathvariable, it appears as though this always defaults toindex.ts, meaning the created hash is always the same.https://github.com/cdklabs/jsii-srcmak/blob/5c32a498d369edfb401d5e923d6255bfc21fdd91/src/compile.ts#L29
Generated hash:
1bc04b5291c26a46d918139138b992d2de976d6851d0893b0476b85bfbdfc6e6Resulting in the following assembly code (for python, but similar outputs exist for other languages):
A workaround that I've used for this in local testing is to pass a modified version of the typeName as the 'moduleKey'.
e.g.
The resulting
jsii_type, and generated prefix of the *.tgz file, is prefixed with the name of the resource type, and thus allows for multiple imported type modules to be used within the same CDK application.Can we please have something like this implemented? Or alternatively have an option provided in the CLI in which we can define an override for the
moduleKey?Thanks.