From ff507eaf3e5ba0a3ffa7851fe451b137ed497622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Bar=C3=B3n?= Date: Mon, 16 Feb 2026 10:34:36 +0100 Subject: [PATCH] fix: move tsx to dependencies and resolve from script dir tsx is required at runtime by the qmd wrapper script via `node --import tsx`, but was listed in devDependencies. Global installs (npm install -g, bun install -g) skip devDependencies, so tsx was never available after install. Additionally, Node's ESM resolver walks up from the current working directory when resolving bare specifiers like `--import tsx`, so even a separate `npm install -g tsx` doesn't help. Fix both issues by: 1. Moving tsx from devDependencies to dependencies so it's always installed alongside qmd 2. Using an explicit path to tsx's ESM loader in the wrapper script instead of a bare specifier, so Node resolves it from qmd's own node_modules regardless of CWD Fixes #182 --- package.json | 2 +- qmd | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b0e066cd..0b6430d2 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "node-llama-cpp": "^3.14.5", "picomatch": "^4.0.0", "sqlite-vec": "^0.1.7-alpha.2", + "tsx": "^4.0.0", "yaml": "^2.8.2", "zod": "^4.2.1" }, @@ -54,7 +55,6 @@ }, "devDependencies": { "@types/better-sqlite3": "^7.6.0", - "tsx": "^4.0.0", "vitest": "^3.0.0" }, "peerDependencies": { diff --git a/qmd b/qmd index 1cac947f..3ba444df 100755 --- a/qmd +++ b/qmd @@ -43,4 +43,13 @@ while [[ -L "$SOURCE" ]]; do done SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)" -exec "$NODE" --import tsx "$SCRIPT_DIR/src/qmd.ts" "$@" +# Resolve tsx from qmd's own node_modules to avoid ESM bare-specifier +# resolution issues (Node resolves from CWD, not from the script location) +TSX_LOADER="$SCRIPT_DIR/node_modules/tsx/dist/esm/index.mjs" +if [[ ! -f "$TSX_LOADER" ]]; then + echo "Error: tsx not found at $TSX_LOADER" >&2 + echo "Run: cd $SCRIPT_DIR && npm install" >&2 + exit 1 +fi + +exec "$NODE" --import "$TSX_LOADER" "$SCRIPT_DIR/src/qmd.ts" "$@"