node-version-bridge 0.5.0 → 0.6.1

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.
package/README.md CHANGED
@@ -31,7 +31,24 @@ Aliases like `lts/*`, `lts/iron`, `node`, `stable`, and `latest` are automatical
31
31
 
32
32
  ## Installation
33
33
 
34
- ### Quick install (recommended)
34
+ ### npm (recommended)
35
+
36
+ ```bash
37
+ npm install -g node-version-bridge
38
+ nvb setup
39
+ ```
40
+
41
+ This installs the `nvb` command globally and configures the shell hook automatically.
42
+
43
+ ### GitHub Releases
44
+
45
+ Download the latest release from [GitHub Releases](https://github.com/Marcosreuquen/node-version-bridge/releases), extract it, and run:
46
+
47
+ ```bash
48
+ bash install.sh
49
+ ```
50
+
51
+ ### From source
35
52
 
36
53
  ```bash
37
54
  git clone https://github.com/marcosreuquen/node-version-bridge.git
@@ -58,13 +75,13 @@ Then add the hook to your shell config:
58
75
  **Zsh** — add to `~/.zshrc`:
59
76
 
60
77
  ```bash
61
- source /path/to/node-version-bridge/hooks/nvb.zsh
78
+ eval "$(nvb init zsh)"
62
79
  ```
63
80
 
64
81
  **Bash** — add to `~/.bashrc`:
65
82
 
66
83
  ```bash
67
- source /path/to/node-version-bridge/hooks/nvb.bash
84
+ eval "$(nvb init bash)"
68
85
  ```
69
86
 
70
87
  ### Verify installation
@@ -87,13 +104,16 @@ This removes installed files, the shell hook from your config, and the cache.
87
104
 
88
105
  ### Manual
89
106
 
90
- 1. Remove the `source ...nvb.zsh` (or `nvb.bash`) line from your `.zshrc`/`.bashrc`
107
+ 1. Remove the nvb lines from your `.zshrc`/`.bashrc` (`eval "$(nvb init ...)"` or `source ...nvb.zsh`/`nvb.bash`)
91
108
  2. Delete the install directory: `rm -rf ~/.local/share/nvb`
92
109
  3. Optional — delete the cache: `rm -rf ~/.cache/node-version-bridge`
93
110
 
94
111
  ## Usage
95
112
 
96
113
  ```bash
114
+ # Configure shell hook (run once after install)
115
+ nvb setup
116
+
97
117
  # Show resolved version vs active version
98
118
  nvb current
99
119
 
@@ -156,18 +176,8 @@ bash test/run.sh
156
176
  - No need to commit manager-specific files when `.nvmrc`/`.node-version` already exists.
157
177
  - Works with any popular Node version manager.
158
178
 
159
- ---
160
-
161
- ## Documentation
162
-
163
- - [Product concept](./docs/concept.md)
164
- - [Technical design](./docs/technical-design.md)
165
- - [Roadmap](./docs/roadmap.md)
166
- - [Implementation plan](./docs/implementation-plan.md)
167
- - [Changelog](./CHANGELOG.md)
168
-
169
179
  ## Status
170
180
 
171
- v0.5.0partial version resolution for asdf/mise, config file support, and auto-install. See [Changelog](./CHANGELOG.md).
181
+ v0.6.1automatic shell hook setup, `nvb setup` and `nvb init` commands. See [Changelog](./CHANGELOG.md).
172
182
 
173
183
  **[Full Documentation](https://marcosreuquen.github.io/node-version-bridge/)**
package/bin/nvb CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  set -euo pipefail
7
7
 
8
- NVB_VERSION="0.5.0"
8
+ NVB_VERSION="0.6.1"
9
9
 
10
10
  # Resolve script location (handles symlinks on macOS/Linux)
11
11
  _nvb_resolve_root() {
@@ -46,8 +46,8 @@ nvb_cmd_refresh() {
46
46
  return 0
47
47
  fi
48
48
 
49
- # Check cache — skip if nothing changed
50
- if nvb_cache_is_current "$PWD" "$resolved_version" "$resolved_source"; then
49
+ # Check cache — skip if nothing changed (bypass with NVB_FORCE_REFRESH=1)
50
+ if [[ "${NVB_FORCE_REFRESH:-}" != "1" ]] && nvb_cache_is_current "$PWD" "$resolved_version" "$resolved_source"; then
51
51
  nvb_log debug "Cache hit: ${resolved_version} from ${resolved_source}"
52
52
  return 0
53
53
  fi
@@ -230,6 +230,94 @@ nvb_cmd_config() {
230
230
  esac
231
231
  }
232
232
 
233
+ nvb_cmd_init() {
234
+ local shell_name="${1:-}"
235
+
236
+ if [[ -z "$shell_name" ]]; then
237
+ # Auto-detect from parent shell
238
+ shell_name="$(basename "${SHELL:-}")"
239
+ fi
240
+
241
+ case "$shell_name" in
242
+ zsh)
243
+ cat <<'HOOK'
244
+ _nvb_hook() {
245
+ [[ "${_NVB_LAST_DIR:-}" == "$PWD" ]] && return
246
+ _NVB_LAST_DIR="$PWD"
247
+ eval "$(nvb refresh 2>/dev/null)"
248
+ }
249
+ autoload -U add-zsh-hook
250
+ add-zsh-hook chpwd _nvb_hook
251
+ eval "$(NVB_FORCE_REFRESH=1 nvb refresh 2>/dev/null)"
252
+ _NVB_LAST_DIR="$PWD"
253
+ HOOK
254
+ ;;
255
+ bash)
256
+ cat <<'HOOK'
257
+ _nvb_hook() {
258
+ [[ "${_NVB_LAST_DIR:-}" == "$PWD" ]] && return
259
+ _NVB_LAST_DIR="$PWD"
260
+ eval "$(nvb refresh 2>/dev/null)"
261
+ }
262
+ if [[ ";${PROMPT_COMMAND:-};" != *";_nvb_hook;"* ]]; then
263
+ PROMPT_COMMAND="_nvb_hook;${PROMPT_COMMAND:-}"
264
+ fi
265
+ eval "$(NVB_FORCE_REFRESH=1 nvb refresh 2>/dev/null)"
266
+ _NVB_LAST_DIR="$PWD"
267
+ HOOK
268
+ ;;
269
+ *)
270
+ echo "Unknown shell: ${shell_name}. Supported: zsh, bash" >&2
271
+ return 1
272
+ ;;
273
+ esac
274
+ }
275
+
276
+ nvb_cmd_setup() {
277
+ local shell_name
278
+ shell_name="$(basename "${SHELL:-}")"
279
+
280
+ if [[ "$shell_name" != "zsh" && "$shell_name" != "bash" ]]; then
281
+ echo "[nvb] Could not detect shell (got: ${shell_name}). Supported: zsh, bash" >&2
282
+ echo "[nvb] Add manually to your shell config:" >&2
283
+ # shellcheck disable=SC2016
284
+ echo ' eval "$(nvb init zsh)" # for zsh' >&2
285
+ # shellcheck disable=SC2016
286
+ echo ' eval "$(nvb init bash)" # for bash' >&2
287
+ return 1
288
+ fi
289
+
290
+ local rc_file
291
+ case "$shell_name" in
292
+ zsh) rc_file="${ZDOTDIR:-$HOME}/.zshrc" ;;
293
+ bash) rc_file="$HOME/.bashrc" ;;
294
+ esac
295
+
296
+ # shellcheck disable=SC2016
297
+ local hook_line='eval "$(nvb init '"${shell_name}"')"'
298
+ local marker="# node-version-bridge:hook"
299
+
300
+ # Check if already configured (new or legacy format)
301
+ if [[ -f "$rc_file" ]]; then
302
+ if grep -qF "nvb init" "$rc_file" || grep -qF "$marker" "$rc_file"; then
303
+ echo "[nvb] Shell hook already configured in ${rc_file}"
304
+ return 0
305
+ fi
306
+ fi
307
+
308
+ echo "[nvb] Adding shell hook to ${rc_file}..."
309
+ {
310
+ echo ""
311
+ echo "$marker"
312
+ echo "$hook_line"
313
+ } >> "$rc_file"
314
+
315
+ echo "[nvb] Done! Restart your shell or run:"
316
+ echo ""
317
+ echo " source ${rc_file}"
318
+ echo ""
319
+ }
320
+
233
321
  nvb_cmd_help() {
234
322
  cat <<EOF
235
323
  node-version-bridge v${NVB_VERSION}
@@ -240,6 +328,8 @@ using your preferred version manager.
240
328
  Usage: nvb <command> [options]
241
329
 
242
330
  Commands:
331
+ setup Auto-configure shell hook (run once after install)
332
+ init Output shell hook code for eval (used in shell config)
243
333
  refresh Detect version and output shell commands to apply it (for eval)
244
334
  current Show resolved version, source, and active Node version
245
335
  doctor Check available managers and configuration
@@ -257,9 +347,10 @@ Config examples:
257
347
  Supported version files: .nvmrc, .node-version, .tool-versions, package.json (engines.node)
258
348
  Supported managers: nvm, fnm, mise, asdf, n
259
349
 
260
- Shell integration (add to your shell config):
261
- Zsh: source <path-to-nvb>/hooks/nvb.zsh
262
- Bash: source <path-to-nvb>/hooks/nvb.bash
350
+ Shell integration:
351
+ nvb setup Auto-configure (recommended, run once)
352
+ eval "$(nvb init zsh)" Manual — add to ~/.zshrc
353
+ eval "$(nvb init bash)" Manual — add to ~/.bashrc
263
354
 
264
355
  Environment variables:
265
356
  NVB_MANAGER Force a specific version manager (nvm, fnm, mise, asdf, n)
@@ -276,6 +367,8 @@ EOF
276
367
  # --- Main dispatch ---
277
368
 
278
369
  case "${1:-help}" in
370
+ setup) nvb_cmd_setup ;;
371
+ init) shift; nvb_cmd_init "$@" ;;
279
372
  refresh) nvb_cmd_refresh ;;
280
373
  current) nvb_cmd_current ;;
281
374
  doctor) nvb_cmd_doctor ;;
package/hooks/nvb.bash CHANGED
@@ -16,3 +16,7 @@ _nvb_hook() {
16
16
  if [[ ";${PROMPT_COMMAND:-};" != *";_nvb_hook;"* ]]; then
17
17
  PROMPT_COMMAND="_nvb_hook;${PROMPT_COMMAND:-}"
18
18
  fi
19
+
20
+ # Force refresh on shell start (cache may be stale from previous session)
21
+ eval "$(NVB_FORCE_REFRESH=1 "${_NVB_BIN}" refresh 2>/dev/null)"
22
+ _NVB_LAST_DIR="$PWD"
package/hooks/nvb.zsh CHANGED
@@ -15,5 +15,6 @@ _nvb_hook() {
15
15
  autoload -U add-zsh-hook
16
16
  add-zsh-hook chpwd _nvb_hook
17
17
 
18
- # Run once on shell start
19
- _nvb_hook
18
+ # Force refresh on shell start (cache may be stale from previous session)
19
+ eval "$(NVB_FORCE_REFRESH=1 "${_NVB_BIN}" refresh 2>/dev/null)"
20
+ _NVB_LAST_DIR="$PWD"
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "node-version-bridge",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "Detect Node.js version from project files and apply it via any version manager",
5
5
  "bin": {
6
6
  "nvb": "bin/nvb"
7
7
  },
8
+ "scripts": {
9
+ "postinstall": "echo '\\n Run \"nvb setup\" to configure your shell hook.\\n'"
10
+ },
8
11
  "files": [
9
12
  "bin/",
10
13
  "lib/",