#!/usr/bin/env bash # # sf-from-source — run SF directly from this source checkout via node. # # Purpose: every local commit in this repo is live immediately without # rebuilding dist/. Subagents can spawn sf by pointing SF_BIN_PATH at # this script instead of dist/loader.js. # # Why node, not bun: # - bun doesn't ship node:sqlite (sf-db.ts falls back to filesystem- # derivation degraded mode under bun). # - bun's native-addon loader doesn't inherit the system library # search path under Nix (libz.so.1 not found for forge_engine.node). # - node 22.5+ has node:sqlite built-in; node 24 supports # --experimental-strip-types so .ts runs directly. # - The src/resources/extensions/sf/tests/resolve-ts.mjs loader hook # already handles .js → .ts import-specifier remapping for runtime # resolution. # # Contract: # - Executable shim; spawn() / exec() can launch directly. # - Exports SF_BIN_PATH before handing off to loader.ts so loader.ts's # `SF_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: node >= 22.5 on PATH (24+ recommended for strip-types), # node_modules populated. set -euo pipefail SCRIPT_DIR=$(cd -- "$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")" &>/dev/null && pwd) SF_SOURCE_ROOT=$(cd -- "$SCRIPT_DIR/.." &>/dev/null && pwd) export SF_BIN_PATH="$SCRIPT_DIR/sf-from-source" exec node \ --import "$SF_SOURCE_ROOT/src/resources/extensions/sf/tests/resolve-ts.mjs" \ --experimental-strip-types \ --no-warnings \ "$SF_SOURCE_ROOT/src/loader.ts" "$@"