@ranger1/dx 0.1.74 → 0.1.76

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() {
@@ -141,11 +136,52 @@ install_pnpm() {
141
136
  fi
142
137
  }
143
138
 
139
+ persist_user_local_bin_path() {
140
+ local line='export PATH="$HOME/.local/bin:$PATH"'
141
+ local rc
142
+ for rc in "$HOME/.zshrc" "$HOME/.bashrc" "$HOME/.profile"; do
143
+ if [[ -f "$rc" ]]; then
144
+ if ! grep -F "$line" "$rc" >/dev/null 2>&1; then
145
+ printf '\n%s\n' "$line" >>"$rc"
146
+ fi
147
+ fi
148
+ done
149
+ }
150
+
151
+ expose_dx_globally() {
152
+ local source_dx="$1"
153
+ local target_dir target_path
154
+
155
+ if [[ ! -x "$source_dx" ]]; then
156
+ echo "dx 源可执行文件不存在:$source_dx" >&2
157
+ return 1
158
+ fi
159
+
160
+ target_dir=""
161
+ if [[ -w "/usr/local/bin" ]]; then
162
+ target_dir="/usr/local/bin"
163
+ elif [[ -w "/opt/homebrew/bin" ]]; then
164
+ target_dir="/opt/homebrew/bin"
165
+ else
166
+ target_dir="$HOME/.local/bin"
167
+ mkdir -p "$target_dir"
168
+ if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
169
+ export PATH="$HOME/.local/bin:$PATH"
170
+ fi
171
+ persist_user_local_bin_path
172
+ fi
173
+
174
+ target_path="$target_dir/dx"
175
+ ln -sf "$source_dx" "$target_path"
176
+ command -v dx >/dev/null 2>&1
177
+ }
178
+
144
179
  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
180
+ # 优先使用用户态 pnpm,减少全局权限问题。
181
+ if command -v pnpm >/dev/null 2>&1; then
148
182
  pnpm add -g agent-browser@latest
183
+ elif command -v npm >/dev/null 2>&1; then
184
+ npm install -g agent-browser@latest
149
185
  elif command -v brew >/dev/null 2>&1; then
150
186
  brew install agent-browser
151
187
  else
@@ -154,7 +190,10 @@ ensure_agent_browser() {
154
190
  fi
155
191
 
156
192
  if ! command -v agent-browser >/dev/null 2>&1; then
157
- echo "agent-browser 安装后仍不可用" >&2
193
+ local pnpm_bin npm_prefix
194
+ pnpm_bin="$(pnpm bin -g 2>/dev/null || true)"
195
+ npm_prefix="$(npm prefix -g 2>/dev/null || true)"
196
+ echo "agent-browser 安装后仍不可用,请检查 PATH(pnpm: ${pnpm_bin:-N/A},npm: ${npm_prefix:-N/A}/bin)" >&2
158
197
  return 1
159
198
  fi
160
199
 
@@ -424,20 +463,48 @@ check_codex_config() {
424
463
  }
425
464
 
426
465
  force_dx() {
466
+ local pnpm_bin dx_installed dx_cmd
427
467
  if ! install_pnpm; then
428
468
  DX_FORCE_OK=0
429
469
  DX_FORCE_MSG="pnpm 不可用,无法执行 dx 强制初始化"
430
470
  return 1
431
471
  fi
432
472
 
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
473
+ if pnpm add -g @ranger1/dx@latest >/dev/null 2>&1; then
474
+ pnpm_bin="$(pnpm bin -g 2>/dev/null || true)"
475
+ dx_installed=""
476
+ if [[ -n "$pnpm_bin" && -x "$pnpm_bin/dx" ]]; then
477
+ dx_installed="$pnpm_bin/dx"
478
+ elif command -v dx >/dev/null 2>&1; then
479
+ dx_installed="$(command -v dx)"
480
+ fi
481
+
482
+ if [[ -z "$dx_installed" ]]; then
483
+ DX_FORCE_OK=0
484
+ DX_FORCE_MSG="dx 安装后未找到可执行文件(pnpm bin: ${pnpm_bin:-N/A})"
485
+ return 1
486
+ fi
487
+
488
+ if ! expose_dx_globally "$dx_installed"; then
489
+ DX_FORCE_OK=0
490
+ DX_FORCE_MSG="dx 已安装但未能暴露为全局命令(pnpm bin: ${pnpm_bin:-N/A})"
491
+ return 1
492
+ fi
493
+
494
+ dx_cmd="$(command -v dx || true)"
495
+ if [[ -n "$dx_cmd" ]] && dx initial >/dev/null 2>&1; then
496
+ DX_FORCE_OK=1
497
+ DX_FORCE_MSG="已安装并暴露全局 dx(${dx_cmd}),并执行 dx initial"
498
+ return 0
499
+ fi
500
+
501
+ DX_FORCE_OK=0
502
+ DX_FORCE_MSG="dx 已暴露为全局命令但 dx initial 执行失败(dx: ${dx_cmd:-N/A})"
503
+ return 1
437
504
  fi
438
505
 
439
506
  DX_FORCE_OK=0
440
- DX_FORCE_MSG="强制命令执行失败:pnpm add -g @ranger1/dx@latest && dx initial"
507
+ DX_FORCE_MSG="强制命令执行失败:pnpm add -g @ranger1/dx@latest"
441
508
  return 1
442
509
  }
443
510
 
@@ -476,7 +543,14 @@ run_parallel_checks() {
476
543
 
477
544
  (
478
545
  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"
546
+ local py_ver py_major
547
+ py_ver="$(python --version 2>&1 | head -n1)"
548
+ py_major="$(python -c 'import sys; print(sys.version_info[0])' 2>/dev/null || true)"
549
+ if [[ "$py_major" == "3" ]]; then
550
+ write_check_file "python_alias" "1" "$py_ver" "ok" "$dir/python_alias.res"
551
+ else
552
+ write_check_file "python_alias" "0" "$py_ver" "python 存在但不是 Python 3" "$dir/python_alias.res"
553
+ fi
480
554
  else
481
555
  write_check_file "python_alias" "0" "" "python 别名不可用" "$dir/python_alias.res"
482
556
  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.76",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {