Explorar el Código

fix(launcher): resolve dependencies beside symlinked dist

Verification:
- bash test/launcher-detection.test.sh
- bash test/launcher-symlinked-dist.test.sh
- ./bin/qmd --version

Session-Id: 01a047e1
Claude hace 2 días
padre
commit
703371b723
Se han modificado 2 ficheros con 33 adiciones y 2 borrados
  1. 5 2
      bin/qmd
  2. 28 0
      test/launcher-symlinked-dist.test.sh

+ 5 - 2
bin/qmd

@@ -32,9 +32,12 @@ fi
 # builds that use npm would be incorrectly routed to bun, causing ABI
 # mismatches with better-sqlite3 / sqlite-vec (see #381).
 if [ -f "$DIR/package-lock.json" ]; then
-  exec node "$DIR/dist/cli/qmd.js" "$@"
+  # Keep the package-visible path when Oivo relocates dist/ behind a symlink.
+  # ESM otherwise resolves imported packages beside the real dist target and
+  # misses this checkout's node_modules (fast-glob, picomatch, ...).
+  exec node --preserve-symlinks --preserve-symlinks-main "$DIR/dist/cli/qmd.js" "$@"
 elif [ -f "$DIR/bun.lock" ] || [ -f "$DIR/bun.lockb" ]; then
   exec bun "$DIR/dist/cli/qmd.js" "$@"
 else
-  exec node "$DIR/dist/cli/qmd.js" "$@"
+  exec node --preserve-symlinks --preserve-symlinks-main "$DIR/dist/cli/qmd.js" "$@"
 fi

+ 28 - 0
test/launcher-symlinked-dist.test.sh

@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+root=$(mktemp -d)
+cleanup() { rm -rf "$root"; }
+trap cleanup EXIT
+
+package="$root/package"
+external_dist="$root/relocated-dist"
+mkdir -p "$package/bin" "$package/node_modules/launcher-probe" "$external_dist/cli"
+cp bin/qmd "$package/bin/qmd"
+touch "$package/package-lock.json"
+ln -s "$external_dist" "$package/dist"
+
+cat >"$package/node_modules/launcher-probe/package.json" <<'JSON'
+{"name":"launcher-probe","type":"module","exports":"./index.js"}
+JSON
+cat >"$package/node_modules/launcher-probe/index.js" <<'JS'
+export const marker = 'symlinked-dist-dependency-resolved';
+JS
+cat >"$external_dist/cli/qmd.js" <<'JS'
+import { marker } from 'launcher-probe';
+console.log(marker);
+JS
+
+output=$("$package/bin/qmd" --version)
+test "$output" = 'symlinked-dist-dependency-resolved'
+printf 'launcher symlinked-dist dependency resolution: OK\n'