#!/bin/sh
# dsh launcher: runs the apps/cli `dsh` bin FROM SOURCE through Node's native
# TypeScript transform, so a symlink from anywhere (e.g. ~/.local/bin/dsh)
# always executes the current working tree without a build step.
set -eu

# Resolve symlink chains without readlink -f (not on every macOS).
script=$0
while [ -L "$script" ]; do
  target=$(readlink "$script")
  case $target in
    /*) script=$target ;;
    *) script=$(dirname "$script")/$target ;;
  esac
done
root=$(CDPATH='' cd -- "$(dirname -- "$script")/.." && pwd)

# The preloader projects this checkout's tsconfig paths into Node resolution;
# TypeScript transformation itself remains Node-owned (no tsx/esbuild hook).
exec node --experimental-transform-types \
  --import "$root/scripts/tspath-loader.ts" \
  "$root/apps/cli/src/bin.ts" "$@"
