singularity-forge/bin/gsd-from-source
Mikael Hugo 2f2f1845f7 fix(source): resolve symlink before computing SCRIPT_DIR
When gsd-from-source is invoked via a symlink (e.g. ~/.bun/bin/gsd-real
pointing at it so `gsd` resolves to source without further indirection),
BASH_SOURCE[0] is the symlink path, not the real file. The previous
dirname-of-BASH_SOURCE[0] approach resolved SCRIPT_DIR to the symlink's
parent dir (e.g. ~/.bun/bin) and tried to bun-run ~/.bun/src/loader.ts,
which doesn't exist.

Wrapping BASH_SOURCE[0] in readlink -f resolves the physical path first,
so SCRIPT_DIR always points at bin/ inside the gsd source checkout
regardless of how the script is reached.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 11:07:00 +02:00

24 lines
1,015 B
Bash
Executable file

#!/usr/bin/env bash
#
# gsd-from-source — run GSD directly from this source checkout via bun.
#
# Purpose: every local commit in this repo (e.g. the #4251 fix) is live
# immediately without reinstalling the bun-packaged gsd-pi. Subagents can
# spawn gsd by pointing GSD_BIN_PATH at this script instead of dist/loader.js.
#
# Contract:
# - Executable shim spawn() / exec() can launch directly.
# - Exports GSD_BIN_PATH before handing off to loader.ts so loader.ts's
# `GSD_BIN_PATH ||= process.argv[1]` branch preserves the shim path
# instead of clobbering it with the .ts loader path (which is not
# directly executable by child_process.spawn).
#
# Requirements: bun on PATH, node_modules populated (`bun install` once).
set -euo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")" &>/dev/null && pwd)
GSD_SOURCE_ROOT=$(cd -- "$SCRIPT_DIR/.." &>/dev/null && pwd)
export GSD_BIN_PATH="$SCRIPT_DIR/gsd-from-source"
exec bun run "$GSD_SOURCE_ROOT/src/loader.ts" "$@"