@ranger1/dx 0.1.75 → 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.
@@ -136,6 +136,46 @@ install_pnpm() {
136
136
  fi
137
137
  }
138
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
+
139
179
  ensure_agent_browser() {
140
180
  # 优先使用用户态 pnpm,减少全局权限问题。
141
181
  if command -v pnpm >/dev/null 2>&1; then
@@ -423,7 +463,7 @@ check_codex_config() {
423
463
  }
424
464
 
425
465
  force_dx() {
426
- local pnpm_bin dx_cmd
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 强制初始化"
@@ -432,21 +472,34 @@ force_dx() {
432
472
 
433
473
  if pnpm add -g @ranger1/dx@latest >/dev/null 2>&1; then
434
474
  pnpm_bin="$(pnpm bin -g 2>/dev/null || true)"
435
- dx_cmd=""
475
+ dx_installed=""
436
476
  if [[ -n "$pnpm_bin" && -x "$pnpm_bin/dx" ]]; then
437
- dx_cmd="$pnpm_bin/dx"
477
+ dx_installed="$pnpm_bin/dx"
438
478
  elif command -v dx >/dev/null 2>&1; then
439
- dx_cmd="$(command -v dx)"
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
440
492
  fi
441
493
 
442
- if [[ -n "$dx_cmd" ]] && "$dx_cmd" initial >/dev/null 2>&1; then
494
+ dx_cmd="$(command -v dx || true)"
495
+ if [[ -n "$dx_cmd" ]] && dx initial >/dev/null 2>&1; then
443
496
  DX_FORCE_OK=1
444
- DX_FORCE_MSG="已执行 pnpm add -g @ranger1/dx@latest && ${dx_cmd} initial"
497
+ DX_FORCE_MSG="已安装并暴露全局 dx(${dx_cmd}),并执行 dx initial"
445
498
  return 0
446
499
  fi
447
500
 
448
501
  DX_FORCE_OK=0
449
- DX_FORCE_MSG="dx 已安装但无法调用(请检查 PATH,pnpm bin: ${pnpm_bin:-N/A})"
502
+ DX_FORCE_MSG="dx 已暴露为全局命令但 dx initial 执行失败(dx: ${dx_cmd:-N/A})"
450
503
  return 1
451
504
  fi
452
505
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.75",
3
+ "version": "0.1.76",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {