@ranger1/dx 0.1.74 → 0.1.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,7 +67,7 @@ install_python3() {
67
67
  }
68
68
 
69
69
  ensure_python_alias() {
70
- local py3 py3_dir target_dir target
70
+ local py3 target_dir target py_major
71
71
  py3="$(command -v python3 || true)"
72
72
  if [[ -z "$py3" ]]; then
73
73
  echo "python3 不存在,无法创建 python 别名" >&2
@@ -75,29 +75,24 @@ ensure_python_alias() {
75
75
  fi
76
76
 
77
77
  if command -v python >/dev/null 2>&1; then
78
- return 0
79
- fi
80
-
81
- py3_dir="$(dirname "$py3")"
82
- if [[ -w "$py3_dir" ]]; then
83
- target_dir="$py3_dir"
84
- elif [[ -w "/usr/local/bin" ]]; then
85
- target_dir="/usr/local/bin"
86
- elif [[ -w "/opt/homebrew/bin" ]]; then
87
- target_dir="/opt/homebrew/bin"
88
- else
89
- target_dir="$HOME/.local/bin"
90
- mkdir -p "$target_dir"
78
+ py_major="$(python -c 'import sys; print(sys.version_info[0])' 2>/dev/null || true)"
79
+ if [[ "$py_major" == "3" ]]; then
80
+ return 0
81
+ fi
91
82
  fi
92
83
 
84
+ # 避免污染系统/工具链目录,统一落到用户态目录。
85
+ target_dir="$HOME/.local/bin"
86
+ mkdir -p "$target_dir"
93
87
  target="$target_dir/python"
94
88
  ln -sf "$py3" "$target"
95
89
 
96
- if [[ "$target_dir" == "$HOME/.local/bin" ]]; then
90
+ if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
97
91
  export PATH="$HOME/.local/bin:$PATH"
98
92
  fi
99
93
 
100
- command -v python >/dev/null 2>&1
94
+ py_major="$(python -c 'import sys; print(sys.version_info[0])' 2>/dev/null || true)"
95
+ [[ "$py_major" == "3" ]]
101
96
  }
102
97
 
103
98
  install_rg() {
@@ -142,10 +137,11 @@ install_pnpm() {
142
137
  }
143
138
 
144
139
  ensure_agent_browser() {
145
- if command -v npm >/dev/null 2>&1; then
146
- npm install -g agent-browser@latest
147
- elif command -v pnpm >/dev/null 2>&1; then
140
+ # 优先使用用户态 pnpm,减少全局权限问题。
141
+ if command -v pnpm >/dev/null 2>&1; then
148
142
  pnpm add -g agent-browser@latest
143
+ elif command -v npm >/dev/null 2>&1; then
144
+ npm install -g agent-browser@latest
149
145
  elif command -v brew >/dev/null 2>&1; then
150
146
  brew install agent-browser
151
147
  else
@@ -154,7 +150,10 @@ ensure_agent_browser() {
154
150
  fi
155
151
 
156
152
  if ! command -v agent-browser >/dev/null 2>&1; then
157
- echo "agent-browser 安装后仍不可用" >&2
153
+ local pnpm_bin npm_prefix
154
+ pnpm_bin="$(pnpm bin -g 2>/dev/null || true)"
155
+ npm_prefix="$(npm prefix -g 2>/dev/null || true)"
156
+ echo "agent-browser 安装后仍不可用,请检查 PATH(pnpm: ${pnpm_bin:-N/A},npm: ${npm_prefix:-N/A}/bin)" >&2
158
157
  return 1
159
158
  fi
160
159
 
@@ -424,20 +423,35 @@ check_codex_config() {
424
423
  }
425
424
 
426
425
  force_dx() {
426
+ local pnpm_bin dx_cmd
427
427
  if ! install_pnpm; then
428
428
  DX_FORCE_OK=0
429
429
  DX_FORCE_MSG="pnpm 不可用,无法执行 dx 强制初始化"
430
430
  return 1
431
431
  fi
432
432
 
433
- if pnpm add -g @ranger1/dx@latest >/dev/null 2>&1 && dx initial >/dev/null 2>&1; then
434
- DX_FORCE_OK=1
435
- DX_FORCE_MSG="已执行 pnpm add -g @ranger1/dx@latest && dx initial"
436
- return 0
433
+ if pnpm add -g @ranger1/dx@latest >/dev/null 2>&1; then
434
+ pnpm_bin="$(pnpm bin -g 2>/dev/null || true)"
435
+ dx_cmd=""
436
+ if [[ -n "$pnpm_bin" && -x "$pnpm_bin/dx" ]]; then
437
+ dx_cmd="$pnpm_bin/dx"
438
+ elif command -v dx >/dev/null 2>&1; then
439
+ dx_cmd="$(command -v dx)"
440
+ fi
441
+
442
+ if [[ -n "$dx_cmd" ]] && "$dx_cmd" initial >/dev/null 2>&1; then
443
+ DX_FORCE_OK=1
444
+ DX_FORCE_MSG="已执行 pnpm add -g @ranger1/dx@latest && ${dx_cmd} initial"
445
+ return 0
446
+ fi
447
+
448
+ DX_FORCE_OK=0
449
+ DX_FORCE_MSG="dx 已安装但无法调用(请检查 PATH,pnpm bin: ${pnpm_bin:-N/A})"
450
+ return 1
437
451
  fi
438
452
 
439
453
  DX_FORCE_OK=0
440
- DX_FORCE_MSG="强制命令执行失败:pnpm add -g @ranger1/dx@latest && dx initial"
454
+ DX_FORCE_MSG="强制命令执行失败:pnpm add -g @ranger1/dx@latest"
441
455
  return 1
442
456
  }
443
457
 
@@ -476,7 +490,14 @@ run_parallel_checks() {
476
490
 
477
491
  (
478
492
  if command -v python >/dev/null 2>&1; then
479
- write_check_file "python_alias" "1" "$(python --version 2>&1 | head -n1)" "ok" "$dir/python_alias.res"
493
+ local py_ver py_major
494
+ py_ver="$(python --version 2>&1 | head -n1)"
495
+ py_major="$(python -c 'import sys; print(sys.version_info[0])' 2>/dev/null || true)"
496
+ if [[ "$py_major" == "3" ]]; then
497
+ write_check_file "python_alias" "1" "$py_ver" "ok" "$dir/python_alias.res"
498
+ else
499
+ write_check_file "python_alias" "0" "$py_ver" "python 存在但不是 Python 3" "$dir/python_alias.res"
500
+ fi
480
501
  else
481
502
  write_check_file "python_alias" "0" "" "python 别名不可用" "$dir/python_alias.res"
482
503
  fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.74",
3
+ "version": "0.1.75",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {