Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(dev): prefer worktree source in delegate_ts

Sidwebworks05cb18f03ebe
diff --git a/packages/dev/bin/crbn b/packages/dev/bin/crbn
index 0e12bf0c13..92286ad43b 100755
--- a/packages/dev/bin/crbn
+++ b/packages/dev/bin/crbn
@@ -67,17 +67,30 @@ slugify_branch() {
}
delegate_ts() {
- # Run citty entry through tsx. Prefer the locally-installed binary in the
- # main checkout (single process under the shell — keeps Ctrl+C / SIGTERM
- # semantics clean for the `crbn up` → graceful-`down` teardown flow).
- # Falls back to `pnpx tsx` for fresh checkouts where node_modules isn't
- # populated yet (e.g. immediately after `crbn checkout`).
- local root
- root="$(repo_root)"
- if [[ -x "$root/node_modules/.bin/tsx" ]]; then
- exec "$root/node_modules/.bin/tsx" "$root/packages/dev/src/main.ts" "$@"
+ # Run citty entry through tsx. Prefer the current worktree's source so CLI
+ # changes in a branch are testable immediately; fall back to main checkout.
+ # tsx binary: prefer worktree's node_modules, then main's, then pnpx.
+ local wt_root main_root src tsx
+ wt_root="$(git rev-parse --show-toplevel 2>/dev/null)"
+ main_root="$(repo_root)"
+
+ # Pick source: worktree first, main fallback.
+ if [[ -n "$wt_root" && -f "$wt_root/packages/dev/src/main.ts" ]]; then
+ src="$wt_root/packages/dev/src/main.ts"
+ else
+ src="$main_root/packages/dev/src/main.ts"
+ fi
+
+ # Pick tsx binary.
+ if [[ -n "$wt_root" && -x "$wt_root/node_modules/.bin/tsx" ]]; then
+ tsx="$wt_root/node_modules/.bin/tsx"
+ elif [[ -x "$main_root/node_modules/.bin/tsx" ]]; then
+ tsx="$main_root/node_modules/.bin/tsx"
+ else
+ exec pnpx tsx "$src" "$@"
fi
- exec pnpx tsx "$root/packages/dev/src/main.ts" "$@"
+
+ exec "$tsx" "$src" "$@"
}
# ---------------------------------------------------------------------------