qmd 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/sh
  2. # Resolve symlinks so global installs (npm link / npm install -g) can find the
  3. # actual package directory instead of the global bin directory.
  4. SOURCE="$0"
  5. while [ -L "$SOURCE" ]; do
  6. SOURCE_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
  7. TARGET="$(readlink "$SOURCE")"
  8. case "$TARGET" in
  9. /*) SOURCE="$TARGET" ;;
  10. *) SOURCE="$SOURCE_DIR/$TARGET" ;;
  11. esac
  12. done
  13. # Detect the runtime used to install this package and use the matching one
  14. # to avoid native module ABI mismatches (e.g., better-sqlite3 compiled for bun vs node)
  15. DIR="$(cd -P "$(dirname "$SOURCE")/.." && pwd)"
  16. # Detect the package manager that installed dependencies by checking lockfiles.
  17. # $BUN_INSTALL is intentionally NOT checked — it only indicates that bun exists
  18. # on the system, not that it was used to install this package (see #361).
  19. #
  20. # package-lock.json takes priority: if it exists, npm installed the native
  21. # modules for Node. The repo ships bun.lock, so without this check, source
  22. # builds that use npm would be incorrectly routed to bun, causing ABI
  23. # mismatches with better-sqlite3 / sqlite-vec (see #381).
  24. if [ -f "$DIR/package-lock.json" ]; then
  25. exec node "$DIR/dist/cli/qmd.js" "$@"
  26. elif [ -f "$DIR/bun.lock" ] || [ -f "$DIR/bun.lockb" ]; then
  27. exec bun "$DIR/dist/cli/qmd.js" "$@"
  28. else
  29. exec node "$DIR/dist/cli/qmd.js" "$@"
  30. fi