From 2c033e83644dc4a813e7a3ff2edc9c2caf30896c Mon Sep 17 00:00:00 2001 From: Josh Hook Date: Wed, 18 Mar 2026 10:57:22 +0000 Subject: [PATCH 1/2] fix(cdktn get): handle inline comments with brackets --- packages/@cdktn/hcl-tools/prebuild.sh | 12 ++++++---- packages/@cdktn/hcl2json/prebuild.sh | 12 ++++++---- .../local-module-inline-comments/module.tf | 22 +++++++++++++++++++ .../src/__tests__/provider-schema.test.ts | 15 +++++++++++++ .../provider-schema/src/provider-schema.ts | 13 +++++++++-- 5 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 packages/@cdktn/provider-schema/src/__tests__/fixtures/local-module-inline-comments/module.tf diff --git a/packages/@cdktn/hcl-tools/prebuild.sh b/packages/@cdktn/hcl-tools/prebuild.sh index 4a845b274..e4700fa32 100755 --- a/packages/@cdktn/hcl-tools/prebuild.sh +++ b/packages/@cdktn/hcl-tools/prebuild.sh @@ -11,12 +11,16 @@ if [[ -z "${GOROOT-}" ]]; then exit 1 fi -if [ ! -f "$GOROOT/misc/wasm/wasm_exec.js" ] -then - echo "File $GOROOT/misc/wasm/wasm_exec.js does not exist!" +WASM_EXEC_PATH="" +if [ -f "$GOROOT/misc/wasm/wasm_exec.js" ]; then + WASM_EXEC_PATH="$GOROOT/misc/wasm/wasm_exec.js" +elif [ -f "$GOROOT/lib/wasm/wasm_exec.js" ]; then + WASM_EXEC_PATH="$GOROOT/lib/wasm/wasm_exec.js" +else + echo "File wasm_exec.js does not exist under either \$GOROOT/misc/wasm/ or \$GOROOT/lib/wasm/!" exit 1 fi -cp "$GOROOT/misc/wasm/wasm_exec.js" ./wasm/wasm_exec.js +cp "$WASM_EXEC_PATH" ./wasm/wasm_exec.js echo "Copied build system wasm_exec.js file to wasm/ directory." \ No newline at end of file diff --git a/packages/@cdktn/hcl2json/prebuild.sh b/packages/@cdktn/hcl2json/prebuild.sh index 4a845b274..e4700fa32 100755 --- a/packages/@cdktn/hcl2json/prebuild.sh +++ b/packages/@cdktn/hcl2json/prebuild.sh @@ -11,12 +11,16 @@ if [[ -z "${GOROOT-}" ]]; then exit 1 fi -if [ ! -f "$GOROOT/misc/wasm/wasm_exec.js" ] -then - echo "File $GOROOT/misc/wasm/wasm_exec.js does not exist!" +WASM_EXEC_PATH="" +if [ -f "$GOROOT/misc/wasm/wasm_exec.js" ]; then + WASM_EXEC_PATH="$GOROOT/misc/wasm/wasm_exec.js" +elif [ -f "$GOROOT/lib/wasm/wasm_exec.js" ]; then + WASM_EXEC_PATH="$GOROOT/lib/wasm/wasm_exec.js" +else + echo "File wasm_exec.js does not exist under either \$GOROOT/misc/wasm/ or \$GOROOT/lib/wasm/!" exit 1 fi -cp "$GOROOT/misc/wasm/wasm_exec.js" ./wasm/wasm_exec.js +cp "$WASM_EXEC_PATH" ./wasm/wasm_exec.js echo "Copied build system wasm_exec.js file to wasm/ directory." \ No newline at end of file diff --git a/packages/@cdktn/provider-schema/src/__tests__/fixtures/local-module-inline-comments/module.tf b/packages/@cdktn/provider-schema/src/__tests__/fixtures/local-module-inline-comments/module.tf new file mode 100644 index 000000000..770209528 --- /dev/null +++ b/packages/@cdktn/provider-schema/src/__tests__/fixtures/local-module-inline-comments/module.tf @@ -0,0 +1,22 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +variable "iam_policy_statements" { + description = "A list of IAM policy statements" + type = list(object({ # TODO - change to map(object({...})) in next major version + sid = optional(string) + actions = optional(list(string)) + effect = optional(string) + resources = optional(list(string)) + })) + default = null +} + +variable "name" { + description = "The name" + type = string +} + +output "result" { + value = "result" +} diff --git a/packages/@cdktn/provider-schema/src/__tests__/provider-schema.test.ts b/packages/@cdktn/provider-schema/src/__tests__/provider-schema.test.ts index 3808b4592..b12d36cb0 100644 --- a/packages/@cdktn/provider-schema/src/__tests__/provider-schema.test.ts +++ b/packages/@cdktn/provider-schema/src/__tests__/provider-schema.test.ts @@ -64,6 +64,21 @@ describe("readSchema", () => { expect(sanitizeJson(result)).toMatchSnapshot(); }, 120000); + it("generates a local module with inline comments in type constraints", async () => { + const module = new TerraformModuleConstraint({ + name: "local_module", + fqn: "local_module", + source: path.resolve( + __dirname, + "fixtures", + "local-module-inline-comments", + ), + }); + const target = new ConstructsMakerModuleTarget(module, Language.TYPESCRIPT); + const result = await readModuleSchema(target); + expect(sanitizeJson(result)).toMatchSnapshot(); + }, 120000); + it("generates a local json module", async () => { const module = new TerraformModuleConstraint({ name: "local_module", diff --git a/packages/@cdktn/provider-schema/src/provider-schema.ts b/packages/@cdktn/provider-schema/src/provider-schema.ts index 0c2ca84f7..5cca81ea5 100644 --- a/packages/@cdktn/provider-schema/src/provider-schema.ts +++ b/packages/@cdktn/provider-schema/src/provider-schema.ts @@ -73,8 +73,17 @@ const transformVariables = (variables: any) => { variableType = "any"; } } else { - const matched = (variable["type"] as string)?.match(/\$\{(.*)\}/); - variableType = matched ? matched[1] : "any"; + const rawVariableType = variable["type"]; + if ( + typeof rawVariableType === "string" && + rawVariableType.startsWith("${") && + rawVariableType.endsWith("}") && + !rawVariableType.includes("\n") + ) { + variableType = rawVariableType.slice(2, -1); + } else { + variableType = "any"; + } } const item: Input = { From 84c898d3365c97a1dd6c86245d295e4b9f24097f Mon Sep 17 00:00:00 2001 From: so0k Date: Fri, 20 Mar 2026 11:30:02 +0700 Subject: [PATCH 2/2] fix(provider-generator): add missing snapshot for inline comment type parsing test Co-Authored-By: Claude Opus 4.6 (1M context) --- .../provider-schema.test.ts.snap | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/@cdktn/provider-schema/src/__tests__/__snapshots__/provider-schema.test.ts.snap b/packages/@cdktn/provider-schema/src/__tests__/__snapshots__/provider-schema.test.ts.snap index e55d6e57f..cf17e3806 100644 --- a/packages/@cdktn/provider-schema/src/__tests__/__snapshots__/provider-schema.test.ts.snap +++ b/packages/@cdktn/provider-schema/src/__tests__/__snapshots__/provider-schema.test.ts.snap @@ -69,6 +69,35 @@ exports[`readSchema generates a local module 1`] = ` }" `; +exports[`readSchema generates a local module with inline comments in type constraints 1`] = ` +"{ + "format_version": "STUBBED VERSION", + "local_module": { + "inputs": [ + { + "default": null, + "description": "A list of IAM policy statements", + "name": "iam_policy_statements", + "required": false, + "type": "any" + }, + { + "description": "The name", + "name": "name", + "required": true, + "type": "string" + } + ], + "name": "local_module", + "outputs": [ + { + "name": "result" + } + ] + } +}" +`; + exports[`readSchema generates a more complex schema 1`] = ` "{ "format_version": "STUBBED VERSION",