The bin/qmd wrapper checks for bun.lock to select the runtime, but since bun.lock is committed to the repo, source builds using npm install are incorrectly routed to Bun — causing native module ABI mismatches (#381) and sqlite-vec crashes (#380). Add package-lock.json as a higher-priority signal: if it exists, npm installed the dependencies and Node should be used. Also fix cleanupOrphanedVectors() to use the existing isSqliteVecAvailable() guard instead of checking sqlite_master, which can report the virtual table even when the vec0 module isn't loaded. Fixes #381, fixes #380 Continuation of #362 (runtime detection false positives)
33 lines
1.3 KiB
Bash
Executable File
33 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
# Resolve symlinks so global installs (npm link / npm install -g) can find the
|
|
# actual package directory instead of the global bin directory.
|
|
SOURCE="$0"
|
|
while [ -L "$SOURCE" ]; do
|
|
SOURCE_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
|
TARGET="$(readlink "$SOURCE")"
|
|
case "$TARGET" in
|
|
/*) SOURCE="$TARGET" ;;
|
|
*) SOURCE="$SOURCE_DIR/$TARGET" ;;
|
|
esac
|
|
done
|
|
|
|
# Detect the runtime used to install this package and use the matching one
|
|
# to avoid native module ABI mismatches (e.g., better-sqlite3 compiled for bun vs node)
|
|
DIR="$(cd -P "$(dirname "$SOURCE")/.." && pwd)"
|
|
|
|
# Detect the package manager that installed dependencies by checking lockfiles.
|
|
# $BUN_INSTALL is intentionally NOT checked — it only indicates that bun exists
|
|
# on the system, not that it was used to install this package (see #361).
|
|
#
|
|
# package-lock.json takes priority: if it exists, npm installed the native
|
|
# modules for Node. The repo ships bun.lock, so without this check, source
|
|
# 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" "$@"
|
|
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" "$@"
|
|
fi
|