Skip to content

chore: fix generate-function-bindings tool - #262

Closed
X-Guardian wants to merge 2 commits into
open-constructs:mainfrom
X-Guardian:chore/fix-generate-function-bindings
Closed

X-Guardian wants to merge 2 commits into
open-constructs:mainfrom
X-Guardian:chore/fix-generate-function-bindings

Conversation

@X-Guardian

Copy link
Copy Markdown
Contributor

Description

Repairs the tools/generate-function-bindings tool, which broke during the yarn→pnpm migration, and removes its dead library/test/publish scaffolding. No runtime/library behaviour changes — the two generated files (packages/cdktn/src/functions/terraform-functions.generated.ts and packages/@cdktn/hcl2cdk/src/function-bindings/functions.generated.ts) regenerate byte-for-byte identically to what's already committed, so this is tooling-only.

Why it was broken: the migration bumped Prettier v2→v3 and tightened pnpm's dependency isolation, and an earlier @cdktn restructure had moved sources to src/. None of that was reflected in this tool, so pnpm run generate-function-bindings failed.

Fixes (each surfaced as a failure when running the tool):

  1. Prettier v3 is async. prettier.format() now returns Promise<string>; the tool was writing the unresolved promise to disk. Added await at both call sites in generate.ts and the one in fetch-metadata.ts.
  2. Prettier v3's babel parser rejects TypeScript. The generator emits TS type annotations (e.g. static "abs"(num: number)), so formatting failed with a syntax error. Switched both generate.ts calls from parser: "babel" to parser: "babel-ts".
  3. Output paths pointed at lib/. Sources live in src/ (lib/build are gitignored tsc output); the tool wrote a stray file into cdktn/lib/ and failed with ENOENT for hcl2cdk/lib/ (whose build dir is build/, not lib/). Repointed both output paths to src/.
  4. Missing @babel/* type declarations. @types/babel__generator and @types/babel__template were present at the workspace root but hidden from the tool by pnpm's strict isolation, so ts-node failed to type-check. Declared both as direct devDependencies.

Cleanup of dead scaffolding (this is a private, run-via-ts-node script collection — no tests, no build output, no consumers):

  • Deleted jest.config.js (no *.test.ts files exist — jest never ran), package.sh + .npmignore (the tool is private and outside lerna/nx scope, so it's never packed/published), ambient.d.ts (augmented SpawnOptions.signal, which nothing here uses — fetch-metadata only calls execSync, and @types/node 20.x already declares it), and .gitignore (every rule was a no-op or vestigial boilerplate copied from the @cdktn/* packages; the root .gitignore already covers anything this tool produces).
  • Trimmed package.json to the two scripts that are actually invoked (fetch-metadata, generate); removed the never-run build/watch/test/package/dist-clean lifecycle and the main/types fields (which pointed at a non-existent src/index.*).
  • Fixed tsconfig.json include and the lint-staged glob from src/** to scripts/** so they point at the real code (both previously matched nothing); dropped the now-obsolete files: [ambient.d.ts] and *.test.tsx exclude.
  • Updated the root generate-function-bindings script to drive the tool by workspace filter (pnpm --filter generate-function-bindings run …) instead of cd … && pnpm install, since the tool is a workspace member whose deps are installed by the root.

Checklist

  • I have updated the PR title to match CDKTN's style guide
  • I have run the linter on my code locally
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation if applicable
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works if applicable
  • New and existing unit tests pass locally with my changes

so0k added a commit that referenced this pull request Jun 13, 2026
## Summary
- Supersedes #262 by carrying forward the existing X-Guardian
`generate-function-bindings` fix history and adding a minimal follow-up
fix.
- Preserves the original X-Guardian contribution commits in this branch
history for author attribution, including `3e3741298 chore: fix
generate-function-bindings tool`.
- Fixes the root generator command to run through the pnpm workspace
instead of running a nested install.
- Avoids requiring `@cdktn/commons` as a tool package workspace
dependency by using a type-only source import for `AttributeType`.

## Test Plan
- `pnpm install --frozen-lockfile --ignore-scripts`
- `pnpm run generate-function-bindings`
- `git diff --exit-code --
packages/cdktn/src/functions/terraform-functions.generated.ts
packages/@cdktn/hcl2cdk/src/function-bindings/functions.generated.ts`
- `pnpm --filter generate-function-bindings exec tsc --noEmit`
- `pnpm exec prettier --check package.json
tools/generate-function-bindings/package.json
tools/generate-function-bindings/scripts/generate.ts pnpm-lock.yaml`

## Notes
- I could not push the branch directly to `open-constructs/cdk-terrain`
with the available `sakul-learning` GitHub token (`403 Permission
denied`), so this PR uses
`sakul-learning:chore/supersede-262-generate-function-bindings` as the
head while targeting `open-constructs/cdk-terrain:main`.
- The submitted branch preserves the original commit SHAs where possible
instead of cherry-picking/squashing them.

Supersedes #262.

---------

Co-authored-by: Simon Heather <simon.heather@yulife.com>
Co-authored-by: Simon Heather <32168619+X-Guardian@users.noreply.github.com>
Co-authored-by: so0k <vincent.drl@gmail.com>
@so0k

so0k commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

merged via #273

@so0k so0k closed this Jun 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

I'm going to lock this pull request because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants