Record npx path for deployment runtime

This commit is contained in:
wuyang6
2026-05-11 17:27:40 +08:00
parent 4964548fd1
commit dba827b9b0
3 changed files with 12 additions and 4 deletions
+6 -3
View File
@@ -264,17 +264,19 @@ build_frontend() {
}
remember_node_runtime() {
local npm_bin node_bin node_bin_dir tmp_file
local npm_bin npx_bin node_bin node_bin_dir tmp_file
npm_bin="$(resolve_npm_bin)"
node_bin_dir="$(dirname "${npm_bin}")"
export PATH="${node_bin_dir}:${PATH}"
node_bin="$(PATH="${node_bin_dir}:${PATH}" command -v node || true)"
npx_bin="$(PATH="${node_bin_dir}:${PATH}" command -v npx || true)"
tmp_file="$(mktemp)"
grep -v -E '^(# systemd 用户服务不会读取交互式 shell 配置|export CLAW_(NPM_BIN|NODE_BIN|NODE_BIN_DIR)=)' "${ENV_FILE}" >"${tmp_file}" || true
grep -v -E '^(# systemd 用户服务不会读取交互式 shell 配置|export CLAW_(NPM_BIN|NPX_BIN|NODE_BIN|NODE_BIN_DIR)=)' "${ENV_FILE}" >"${tmp_file}" || true
cat >>"${tmp_file}" <<EOF
# systemd 用户服务不会读取交互式 shell 配置,这里记录部署时可用的 Node.js/npm 路径。
# systemd 用户服务不会读取交互式 shell 配置,这里记录部署时可用的 Node.js/npm/npx 路径。
export CLAW_NPM_BIN=$(printf "%q" "${npm_bin}")
export CLAW_NPX_BIN=$(printf "%q" "${npx_bin}")
export CLAW_NODE_BIN=$(printf "%q" "${node_bin}")
export CLAW_NODE_BIN_DIR=$(printf "%q" "${node_bin_dir}")
EOF
@@ -282,6 +284,7 @@ EOF
rm -f "${tmp_file}"
log "记录 Node.js 运行路径"
echo "npm=${npm_bin}"
echo "npx=${npx_bin:-未检测到}"
echo "node=${node_bin:-未检测到}"
}
+1
View File
@@ -26,6 +26,7 @@ if [[ -n "${CLAW_NODE_BIN_DIR:-}" ]]; then
export PATH="${CLAW_NODE_BIN_DIR}:${PATH}"
fi
export CLAW_NPM_BIN="${CLAW_NPM_BIN:-}"
export CLAW_NPX_BIN="${CLAW_NPX_BIN:-}"
export CLAW_NODE_BIN="${CLAW_NODE_BIN:-}"
export CLAW_NODE_BIN_DIR="${CLAW_NODE_BIN_DIR:-}"