Skip to content

chore(cli): decouple cdktn bin entry point from build output#232

Draft
X-Guardian wants to merge 3 commits into
open-constructs:mainfrom
X-Guardian:chore/decouple-cli-bin
Draft

chore(cli): decouple cdktn bin entry point from build output#232
X-Guardian wants to merge 3 commits into
open-constructs:mainfrom
X-Guardian:chore/decouple-cli-bin

Conversation

@X-Guardian
Copy link
Copy Markdown
Contributor

@X-Guardian X-Guardian commented Jun 2, 2026

Description

Two changes to how cdktn-cli builds. The CLI launcher moves out of the build output into a committed bin/cdktn, and the esbuild build config compiles into a gitignored build-config/ directory instead of next to its source. No user-facing CLI behaviour changes — same cdktn command, same flags.

Why

Previously the bin field pointed at bundle/bin/cdktn, a file that only exists after build.ts copies it in (fs.copySync("src/bin/cdktn", "./bundle/bin/cdktn")). That means the bin target is absent until a build runs. yarn 1 tolerates this, but stricter package managers validate bin targets when linking workspace packages, so a bin pointing at a not-yet-built path breaks install. Committing a stable top-level launcher that lazily requires the bundle makes the bin target always present — before any build — and removes a build-time copy step.

This is a prerequisite for #170.

Approach:

  1. New committed launcher packages/cdktn-cli/bin/cdktn#!/usr/bin/env node + require("../bundle/bin/cdktn.js"). The bin field in package.json now points here (bin/cdktn) instead of bundle/bin/cdktn.
  2. Delete src/bin/cdktn and drop the fs.copySync("src/bin/cdktn", "./bundle/bin/cdktn") step from build.ts — the launcher is no longer generated as build output.
  3. Compile the build config to build-config/: compile-build-config now runs tsc build.ts --outDir build-config, and postbuild / watch invoke node build-config/build.js. Keeps a stray compiled build.js out of the package root; build-config is added to .gitignore.
  4. Tests resolve the bin from package.json: convert.test.ts and init.test.ts now read cdktnCliPkg.bin.cdktn and resolve it against the package root, rather than hardcoding bundle/bin/cdktn — one source of truth that tracks the bin field.
  5. Type let t: number in the rebuild-log plugin: also a consequence of (3) — compiling build.ts now type-checks it, and the bare let t; left t implicitly any. The annotation makes Date.now() - t well-typed.
  6. Add build.ts to knip's cdktn-cli entry list: also a consequence of (3) — knip can no longer trace esbuild through postbuild (now a gitignored build-config/build.js) and flags it unused. Listing build.ts makes knip parse the import * as esbuild directly.

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

@X-Guardian X-Guardian force-pushed the chore/decouple-cli-bin branch from d1dab61 to 0a5c9b3 Compare June 2, 2026 20:26
@X-Guardian X-Guardian force-pushed the chore/decouple-cli-bin branch from 0a5c9b3 to c068b74 Compare June 2, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant