dsh 1.0 KB

1234567891011121314151617181920212223242526
  1. #!/bin/sh
  2. # dsh launcher: runs the apps/cli `dsh` bin FROM SOURCE through the tsx ESM
  3. # hook, so a symlink from anywhere (e.g. ~/.local/bin/dsh) always executes the
  4. # current working tree without a build step.
  5. set -eu
  6. # Resolve symlink chains without readlink -f (not on every macOS).
  7. script=$0
  8. while [ -L "$script" ]; do
  9. target=$(readlink "$script")
  10. case $target in
  11. /*) script=$target ;;
  12. *) script=$(dirname "$script")/$target ;;
  13. esac
  14. done
  15. root=$(CDPATH='' cd -- "$(dirname -- "$script")/.." && pwd)
  16. # The ESM-only tsx hook transforms TypeScript and projects this checkout's
  17. # tsconfig paths into Node resolution (the CJS hook stays off: the graph is
  18. # ESM-only and the CJS resolver costs ~0.4s of startup). Absolute paths keep
  19. # both the hook and the tsconfig anchored to this checkout when the launcher
  20. # runs from any cwd, where bare `tsx/esm` would not resolve.
  21. NODE_USE_ENV_PROXY=1 \
  22. TSX_TSCONFIG_PATH="$root/tsconfig.json" \
  23. exec node --import "$root/node_modules/tsx/dist/esm/index.mjs" \
  24. "$root/apps/cli/src/bin.ts" "$@"