node-version-use 1.9.8 → 2.0.0

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.
Files changed (92) hide show
  1. package/README.md +121 -23
  2. package/dist/cjs/cli.js +25 -6
  3. package/dist/cjs/cli.js.map +1 -1
  4. package/dist/cjs/commands/default.d.cts +7 -0
  5. package/dist/cjs/commands/default.d.ts +7 -0
  6. package/dist/cjs/commands/default.js +57 -0
  7. package/dist/cjs/commands/default.js.map +1 -0
  8. package/dist/cjs/commands/index.d.cts +3 -0
  9. package/dist/cjs/commands/index.d.ts +3 -0
  10. package/dist/cjs/commands/index.js +54 -0
  11. package/dist/cjs/commands/index.js.map +1 -0
  12. package/dist/cjs/commands/install.d.cts +6 -0
  13. package/dist/cjs/commands/install.d.ts +6 -0
  14. package/dist/cjs/commands/install.js +69 -0
  15. package/dist/cjs/commands/install.js.map +1 -0
  16. package/dist/cjs/commands/list.d.cts +6 -0
  17. package/dist/cjs/commands/list.d.ts +6 -0
  18. package/dist/cjs/commands/list.js +93 -0
  19. package/dist/cjs/commands/list.js.map +1 -0
  20. package/dist/cjs/commands/local.d.cts +7 -0
  21. package/dist/cjs/commands/local.d.ts +7 -0
  22. package/dist/cjs/commands/local.js +69 -0
  23. package/dist/cjs/commands/local.js.map +1 -0
  24. package/dist/cjs/commands/setup.d.cts +7 -0
  25. package/dist/cjs/commands/setup.d.ts +7 -0
  26. package/dist/cjs/commands/setup.js +55 -0
  27. package/dist/cjs/commands/setup.js.map +1 -0
  28. package/dist/cjs/commands/teardown.d.cts +6 -0
  29. package/dist/cjs/commands/teardown.d.ts +6 -0
  30. package/dist/cjs/commands/teardown.js +66 -0
  31. package/dist/cjs/commands/teardown.js.map +1 -0
  32. package/dist/cjs/commands/uninstall.d.cts +6 -0
  33. package/dist/cjs/commands/uninstall.d.ts +6 -0
  34. package/dist/cjs/commands/uninstall.js +148 -0
  35. package/dist/cjs/commands/uninstall.js.map +1 -0
  36. package/dist/cjs/commands/which.d.cts +7 -0
  37. package/dist/cjs/commands/which.d.ts +7 -0
  38. package/dist/cjs/commands/which.js +117 -0
  39. package/dist/cjs/commands/which.js.map +1 -0
  40. package/dist/cjs/compat.d.cts +17 -0
  41. package/dist/cjs/compat.d.ts +17 -0
  42. package/dist/cjs/compat.js +47 -1
  43. package/dist/cjs/compat.js.map +1 -1
  44. package/dist/cjs/constants.js +1 -1
  45. package/dist/cjs/constants.js.map +1 -1
  46. package/dist/cjs/types.d.cts +1 -0
  47. package/dist/cjs/types.d.ts +1 -0
  48. package/dist/cjs/worker.js +2 -2
  49. package/dist/cjs/worker.js.map +1 -1
  50. package/dist/esm/cli.js +23 -4
  51. package/dist/esm/cli.js.map +1 -1
  52. package/dist/esm/commands/default.d.ts +7 -0
  53. package/dist/esm/commands/default.js +41 -0
  54. package/dist/esm/commands/default.js.map +1 -0
  55. package/dist/esm/commands/index.d.ts +3 -0
  56. package/dist/esm/commands/index.js +27 -0
  57. package/dist/esm/commands/index.js.map +1 -0
  58. package/dist/esm/commands/install.d.ts +6 -0
  59. package/dist/esm/commands/install.js +53 -0
  60. package/dist/esm/commands/install.js.map +1 -0
  61. package/dist/esm/commands/list.d.ts +6 -0
  62. package/dist/esm/commands/list.js +52 -0
  63. package/dist/esm/commands/list.js.map +1 -0
  64. package/dist/esm/commands/local.d.ts +7 -0
  65. package/dist/esm/commands/local.js +51 -0
  66. package/dist/esm/commands/local.js.map +1 -0
  67. package/dist/esm/commands/setup.d.ts +7 -0
  68. package/dist/esm/commands/setup.js +39 -0
  69. package/dist/esm/commands/setup.js.map +1 -0
  70. package/dist/esm/commands/teardown.d.ts +6 -0
  71. package/dist/esm/commands/teardown.js +33 -0
  72. package/dist/esm/commands/teardown.js.map +1 -0
  73. package/dist/esm/commands/uninstall.d.ts +6 -0
  74. package/dist/esm/commands/uninstall.js +132 -0
  75. package/dist/esm/commands/uninstall.js.map +1 -0
  76. package/dist/esm/commands/which.d.ts +7 -0
  77. package/dist/esm/commands/which.js +101 -0
  78. package/dist/esm/commands/which.js.map +1 -0
  79. package/dist/esm/compat.d.ts +17 -0
  80. package/dist/esm/compat.js +39 -2
  81. package/dist/esm/compat.js.map +1 -1
  82. package/dist/esm/constants.js +2 -1
  83. package/dist/esm/constants.js.map +1 -1
  84. package/dist/esm/types.d.ts +1 -0
  85. package/dist/esm/types.js.map +1 -1
  86. package/dist/esm/worker.js +2 -2
  87. package/dist/esm/worker.js.map +1 -1
  88. package/package.json +11 -4
  89. package/scripts/postinstall.cjs +273 -0
  90. package/shim/Makefile +58 -0
  91. package/shim/go.mod +3 -0
  92. package/shim/main.go +302 -0
package/README.md CHANGED
@@ -1,42 +1,140 @@
1
1
  ## node-version-use
2
2
 
3
- Cross-platform solution for using multiple versions of node. Useful for compatibility testing
3
+ Cross-platform solution for using multiple versions of Node.js. Useful for compatibility testing and transparent version switching.
4
4
 
5
- cli
5
+ ### Installation
6
6
 
7
+ ```bash
8
+ npm install -g node-version-use
7
9
  ```
8
- # specific version
9
- $ nvu 14.4.0 npm run test
10
10
 
11
- # highest of version
12
- $ nvu 12 npm run test
11
+ On install, nvu automatically downloads platform-specific shims to `~/.nvu/bin/`. To enable transparent Node version switching, add to your shell profile:
13
12
 
14
- # lts
15
- $ nvu lts npm run test
13
+ ```bash
14
+ # For bash (~/.bashrc) or zsh (~/.zshrc):
15
+ export PATH="$HOME/.nvu/bin:$PATH"
16
16
 
17
- # comma-delimited list
18
- $ nvu 0.8,4,8,14 npm run test
17
+ # For fish (~/.config/fish/config.fish):
18
+ set -gx PATH $HOME/.nvu/bin $PATH
19
+ ```
20
+
21
+ ### Quick Start
22
+
23
+ ```bash
24
+ # Set a global default Node version
25
+ nvu default 20
26
+
27
+ # Or set a project-specific version (creates .nvmrc)
28
+ nvu local 18
29
+
30
+ # Now 'node' and 'npm' use the configured version automatically
31
+ node --version # v20.x.x (or v18.x.x in project directory)
32
+ ```
33
+
34
+ ### Commands
35
+
36
+ #### Version Management
37
+
38
+ ```bash
39
+ # Set global default version
40
+ nvu default 20
19
41
 
20
- # use expression
21
- $ nvu >=0.8 node --version
42
+ # Set local version for current directory (creates .nvmrc)
43
+ nvu local 18
22
44
 
23
- # use engines.node from package.json
24
- $ nvu engines node --version
45
+ # Install a Node version
46
+ nvu install 22
47
+
48
+ # Uninstall a Node version
49
+ nvu uninstall 22
50
+
51
+ # List installed versions
52
+ nvu list
53
+
54
+ # Show which version would be used
55
+ nvu which
25
56
  ```
26
57
 
27
- JavaScript
58
+ #### Shim Management
59
+
60
+ ```bash
61
+ # Install/reinstall shims
62
+ nvu setup
63
+
64
+ # Remove shims
65
+ nvu teardown
66
+ ```
67
+
68
+ #### Run Commands with Specific Versions
69
+
70
+ ```bash
71
+ # Run with a specific version
72
+ nvu 14.4.0 npm run test
73
+
74
+ # Run with highest matching major version
75
+ nvu 12 npm run test
28
76
 
77
+ # Run with LTS version
78
+ nvu lts npm run test
79
+
80
+ # Run with multiple versions (comma-delimited)
81
+ nvu 0.8,4,8,14 npm run test
82
+
83
+ # Run with version expression
84
+ nvu >=0.8 node --version
85
+
86
+ # Use engines.node from package.json
87
+ nvu engines node --version
29
88
  ```
30
- var assert = require('assert');
31
- var nvu = require('node-version-use');
32
89
 
33
- var isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
34
- var NODE = isWindows ? 'node.exe' : 'node';
90
+ ### How It Works
91
+
92
+ nvu uses lightweight shim binaries that intercept `node`, `npm`, and `npx` commands. When you run `node`, the shim:
93
+
94
+ 1. Checks for `.nvurc` in current/parent directories
95
+ 2. Checks for `.nvmrc` in current/parent directories
96
+ 3. Falls back to `~/.nvu/default`
97
+ 4. Executes the matching installed Node version
98
+
99
+ This works in all contexts: terminals, IDEs, CI, scripts - without shell integration.
100
+
101
+ ### Version Resolution
102
+
103
+ The shim resolves partial versions to installed versions:
104
+ - `20` matches `v20.19.6`
105
+ - `18.19` matches `v18.19.0`
106
+ - `v22` matches `v22.0.0`
107
+
108
+ ### JavaScript API
35
109
 
36
- // results is an array per-version of form {version, error, result}
37
- nvu('>=0.8', NODE, ['--version'], { versions: '12', stdio: 'inherit' }, function (err, results) {
110
+ ```javascript
111
+ const nvu = require('node-version-use');
112
+
113
+ // Run with callback
114
+ nvu('>=0.8', 'node', ['--version'], { versions: '12', stdio: 'inherit' }, (err, results) => {
115
+ // results is an array per-version of form {version, error, result}
38
116
  });
39
117
 
40
- // results is an array per-version of form {version, error, result}
41
- await nvu('engines', NODE, ['--version'], { versions: '12', stdio: 'inherit' });
118
+ // Run with async/await
119
+ const results = await nvu('engines', 'node', ['--version'], { stdio: 'inherit' });
120
+ ```
121
+
122
+ ### Uninstalling
123
+
124
+ ```bash
125
+ # Remove shims
126
+ nvu teardown
127
+
128
+ # Optionally remove all nvu data
129
+ rm -rf ~/.nvu
42
130
  ```
131
+
132
+ Then remove the PATH line from your shell profile.
133
+
134
+ ### Compatibility
135
+
136
+ - macOS (arm64, x64)
137
+ - Linux (arm64, x64)
138
+ - Windows (arm64, x64)
139
+
140
+ Compatible with `.nvmrc` files from nvm, fnm, and other version managers.
package/dist/cjs/cli.js CHANGED
@@ -13,7 +13,8 @@ var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
13
13
  var _getoptscompat = /*#__PURE__*/ _interop_require_default(require("getopts-compat"));
14
14
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
15
15
  var _url = /*#__PURE__*/ _interop_require_default(require("url"));
16
- var _indexts = /*#__PURE__*/ _interop_require_default(require("./index.js"));
16
+ var _indexts = require("./commands/index.js");
17
+ var _indexts1 = /*#__PURE__*/ _interop_require_default(require("./index.js"));
17
18
  var _loadSpawnTermts = /*#__PURE__*/ _interop_require_default(require("./lib/loadSpawnTerm.js"));
18
19
  function _interop_require_default(obj) {
19
20
  return obj && obj.__esModule ? obj : {
@@ -32,9 +33,20 @@ function printHelp(name) {
32
33
  console.log("".concat(name, " v").concat(version));
33
34
  console.log('');
34
35
  console.log("Usage: ".concat(name, " [options] <version> <command> [args...]"));
36
+ console.log(" ".concat(name, " <subcommand> [args...]"));
35
37
  console.log('');
36
38
  console.log('Run commands with specific Node.js versions');
37
39
  console.log('');
40
+ console.log('Subcommands:');
41
+ console.log(' default [version] Set or display the global default Node version');
42
+ console.log(' local [version] Set or display the local Node version (.nvmrc)');
43
+ console.log(' install <version> Download and install a Node version');
44
+ console.log(' uninstall <version> Remove an installed Node version');
45
+ console.log(' list List installed Node versions');
46
+ console.log(' which Show which Node version would be used');
47
+ console.log(' setup Install/reinstall shims to ~/.nvu/bin');
48
+ console.log(' teardown Remove shims from ~/.nvu/bin');
49
+ console.log('');
38
50
  console.log('Options:');
39
51
  console.log(' -v, --version Print version number');
40
52
  console.log(' -h, --help Print this help message');
@@ -46,9 +58,11 @@ function printHelp(name) {
46
58
  console.log(' --silent Suppress logging');
47
59
  console.log('');
48
60
  console.log('Examples:');
49
- console.log(" ".concat(name, " 22 node --version"));
50
- console.log(" ".concat(name, " 22,20,18 npm test"));
51
- console.log(" ".concat(name, " engines node --version"));
61
+ console.log(" ".concat(name, " 22 node --version Run with Node 22"));
62
+ console.log(" ".concat(name, " 22,20,18 npm test Run with multiple versions"));
63
+ console.log(" ".concat(name, " engines node --version Use version from package.json"));
64
+ console.log(" ".concat(name, " default 20 Set global default to Node 20"));
65
+ console.log(" ".concat(name, " local 18 Create .nvmrc with Node 18"));
52
66
  }
53
67
  var _default = function(argv, name) {
54
68
  var options = (0, _getoptscompat.default)(argv, {
@@ -86,10 +100,15 @@ var _default = function(argv, name) {
86
100
  (0, _exit.default)(0);
87
101
  return;
88
102
  }
103
+ // Check if first argument is a subcommand
104
+ var args = options._;
105
+ if (args.length > 0 && (0, _indexts.isCommand)(args[0])) {
106
+ (0, _indexts.runCommand)(args[0], args.slice(1));
107
+ return;
108
+ }
89
109
  // define.option('-r, --range [range]', 'range type of major, minor, or patch with filters of lts, even, odd for version string expressions', 'major,even');
90
110
  // define.option('-s, --silent', 'suppress logging', false);
91
111
  options.sort = options.desc ? -1 : 1;
92
- var args = options._;
93
112
  if (args.length === 0) {
94
113
  console.log("Missing version expression. Example usage: ".concat(name, " version command arg1 arg2"));
95
114
  (0, _exit.default)(ERROR_CODE);
@@ -101,7 +120,7 @@ var _default = function(argv, name) {
101
120
  return;
102
121
  }
103
122
  options.stdio = 'inherit'; // pass through stdio
104
- (0, _indexts.default)(args[0], args[1], args.slice(2), options, function(err, results) {
123
+ (0, _indexts1.default)(args[0], args[1], args.slice(2), options, function(err, results) {
105
124
  if (err && !err.results) {
106
125
  console.log(err.message);
107
126
  (0, _exit.default)(ERROR_CODE);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/cli.ts"],"sourcesContent":["import exit from 'exit';\nimport fs from 'fs';\nimport getopts from 'getopts-compat';\nimport path from 'path';\nimport url from 'url';\nimport run from './index.ts';\nimport loadSpawnTerm from './lib/loadSpawnTerm.ts';\nimport type { UseError, UseOptions, UseResult } from './types.ts';\n\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nconst ERROR_CODE = 13;\n\nfunction getVersion(): string {\n const packagePath = path.join(__dirname, '..', '..', 'package.json');\n const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));\n return packageJson.version;\n}\n\nfunction printHelp(name: string): void {\n const version = getVersion();\n console.log(`${name} v${version}`);\n console.log('');\n console.log(`Usage: ${name} [options] <version> <command> [args...]`);\n console.log('');\n console.log('Run commands with specific Node.js versions');\n console.log('');\n console.log('Options:');\n console.log(' -v, --version Print version number');\n console.log(' -h, --help Print this help message');\n console.log(' -r, --range Range type (major, minor, patch) with filters (lts, even, odd)');\n console.log(' Default: major,even');\n console.log(' -d, --desc Sort versions in descending order');\n console.log(' -e, --expanded Use expanded version format');\n console.log(' -s, --streaming Enable streaming output');\n console.log(' --silent Suppress logging');\n console.log('');\n console.log('Examples:');\n console.log(` ${name} 22 node --version`);\n console.log(` ${name} 22,20,18 npm test`);\n console.log(` ${name} engines node --version`);\n}\n\nexport default (argv: string[], name: string): undefined => {\n const options = getopts(argv, {\n alias: { range: 'r', desc: 'd', expanded: 'e', streaming: 's', silent: 'si', version: 'v', help: 'h' },\n default: { range: 'major,even', interactive: true },\n boolean: ['silent', 'desc', 'expanded', 'streaming', 'interactive', 'version', 'help'],\n stopEarly: true,\n });\n\n if (options.version) {\n console.log(getVersion());\n exit(0);\n return;\n }\n\n if (options.help) {\n printHelp(name);\n exit(0);\n return;\n }\n\n // define.option('-r, --range [range]', 'range type of major, minor, or patch with filters of lts, even, odd for version string expressions', 'major,even');\n // define.option('-s, --silent', 'suppress logging', false);\n options.sort = options.desc ? -1 : 1;\n\n const args = options._;\n if (args.length === 0) {\n console.log(`Missing version expression. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n if (args.length === 1) {\n console.log(`Missing command. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n\n options.stdio = 'inherit'; // pass through stdio\n run(args[0], args[1], args.slice(2), options as unknown as UseOptions, (err: UseError, results: UseResult[]): undefined => {\n if (err && !err.results) {\n console.log(err.message);\n exit(ERROR_CODE);\n return;\n }\n if (err) results = err.results;\n const errors = results.filter((result) => !!result.error);\n\n if (!options.silent) {\n // Load spawn-term to get figures/formatArguments for output formatting\n loadSpawnTerm((_loadErr, mod) => {\n const { createSession, figures, formatArguments } = mod || { createSession: undefined, figures: { tick: '✓', cross: '✗' }, formatArguments: (x: string[]) => x };\n if (!createSession) {\n console.log('\\n======================');\n results.forEach((res) => {\n console.log(`${res.error ? figures.cross : figures.tick} ${res.version}${res.error ? ` Error: ${res.error.message}` : ''}`);\n });\n console.log('\\n----------------------');\n console.log(`${name} ${formatArguments(args).join(' ')}`);\n console.log(`${figures.tick} ${results.length - errors.length} succeeded`);\n if (errors.length) console.log(`${figures.cross} ${errors.length} failed`);\n }\n exit(err || errors.length ? ERROR_CODE : 0);\n });\n } else {\n exit(err || errors.length ? ERROR_CODE : 0);\n }\n });\n};\n"],"names":["__dirname","path","dirname","__filename","url","fileURLToPath","ERROR_CODE","getVersion","packagePath","join","packageJson","JSON","parse","fs","readFileSync","version","printHelp","name","console","log","argv","options","getopts","alias","range","desc","expanded","streaming","silent","help","default","interactive","boolean","stopEarly","exit","sort","args","_","length","stdio","run","slice","err","results","message","errors","filter","result","error","loadSpawnTerm","_loadErr","mod","createSession","undefined","figures","tick","cross","formatArguments","x","forEach","res"],"mappings":";;;;+BA2CA;;;eAAA;;;2DA3CiB;yDACF;oEACK;2DACH;0DACD;8DACA;sEACU;;;;;;AAG1B,IAAMA,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAElG,IAAMC,aAAa;AAEnB,SAASC;IACP,IAAMC,cAAcP,aAAI,CAACQ,IAAI,CAACT,WAAW,MAAM,MAAM;IACrD,IAAMU,cAAcC,KAAKC,KAAK,CAACC,WAAE,CAACC,YAAY,CAACN,aAAa;IAC5D,OAAOE,YAAYK,OAAO;AAC5B;AAEA,SAASC,UAAUC,IAAY;IAC7B,IAAMF,UAAUR;IAChBW,QAAQC,GAAG,CAAC,AAAC,GAAWJ,OAATE,MAAK,MAAY,OAARF;IACxBG,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC,AAAC,UAAc,OAALF,MAAK;IAC3BC,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,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AC;gBACnE;gBACAJ,IAAAA,aAAI,EAACQ,OAAOG,OAAOP,MAAM,GAAGhC,aAAa;YAC3C;QACF,OAAO;YACL4B,IAAAA,aAAI,EAACQ,OAAOG,OAAOP,MAAM,GAAGhC,aAAa;QAC3C;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/cli.ts"],"sourcesContent":["import exit from 'exit';\nimport fs from 'fs';\nimport getopts from 'getopts-compat';\nimport path from 'path';\nimport url from 'url';\nimport { isCommand, runCommand } from './commands/index.ts';\nimport run from './index.ts';\nimport loadSpawnTerm from './lib/loadSpawnTerm.ts';\nimport type { UseError, UseOptions, UseResult } from './types.ts';\n\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nconst ERROR_CODE = 13;\n\nfunction getVersion(): string {\n const packagePath = path.join(__dirname, '..', '..', 'package.json');\n const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));\n return packageJson.version;\n}\n\nfunction printHelp(name: string): void {\n const version = getVersion();\n console.log(`${name} v${version}`);\n console.log('');\n console.log(`Usage: ${name} [options] <version> <command> [args...]`);\n console.log(` ${name} <subcommand> [args...]`);\n console.log('');\n console.log('Run commands with specific Node.js versions');\n console.log('');\n console.log('Subcommands:');\n console.log(' default [version] Set or display the global default Node version');\n console.log(' local [version] Set or display the local Node version (.nvmrc)');\n console.log(' install <version> Download and install a Node version');\n console.log(' uninstall <version> Remove an installed Node version');\n console.log(' list List installed Node versions');\n console.log(' which Show which Node version would be used');\n console.log(' setup Install/reinstall shims to ~/.nvu/bin');\n console.log(' teardown Remove shims from ~/.nvu/bin');\n console.log('');\n console.log('Options:');\n console.log(' -v, --version Print version number');\n console.log(' -h, --help Print this help message');\n console.log(' -r, --range Range type (major, minor, patch) with filters (lts, even, odd)');\n console.log(' Default: major,even');\n console.log(' -d, --desc Sort versions in descending order');\n console.log(' -e, --expanded Use expanded version format');\n console.log(' -s, --streaming Enable streaming output');\n console.log(' --silent Suppress logging');\n console.log('');\n console.log('Examples:');\n console.log(` ${name} 22 node --version Run with Node 22`);\n console.log(` ${name} 22,20,18 npm test Run with multiple versions`);\n console.log(` ${name} engines node --version Use version from package.json`);\n console.log(` ${name} default 20 Set global default to Node 20`);\n console.log(` ${name} local 18 Create .nvmrc with Node 18`);\n}\n\nexport default (argv: string[], name: string): undefined => {\n const options = getopts(argv, {\n alias: { range: 'r', desc: 'd', expanded: 'e', streaming: 's', silent: 'si', version: 'v', help: 'h' },\n default: { range: 'major,even', interactive: true },\n boolean: ['silent', 'desc', 'expanded', 'streaming', 'interactive', 'version', 'help'],\n stopEarly: true,\n });\n\n if (options.version) {\n console.log(getVersion());\n exit(0);\n return;\n }\n\n if (options.help) {\n printHelp(name);\n exit(0);\n return;\n }\n\n // Check if first argument is a subcommand\n const args = options._;\n if (args.length > 0 && isCommand(args[0])) {\n runCommand(args[0], args.slice(1));\n return;\n }\n\n // define.option('-r, --range [range]', 'range type of major, minor, or patch with filters of lts, even, odd for version string expressions', 'major,even');\n // define.option('-s, --silent', 'suppress logging', false);\n options.sort = options.desc ? -1 : 1;\n\n if (args.length === 0) {\n console.log(`Missing version expression. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n if (args.length === 1) {\n console.log(`Missing command. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n\n options.stdio = 'inherit'; // pass through stdio\n run(args[0], args[1], args.slice(2), options as unknown as UseOptions, (err: UseError, results: UseResult[]): undefined => {\n if (err && !err.results) {\n console.log(err.message);\n exit(ERROR_CODE);\n return;\n }\n if (err) results = err.results;\n const errors = results.filter((result) => !!result.error);\n\n if (!options.silent) {\n // Load spawn-term to get figures/formatArguments for output formatting\n loadSpawnTerm((_loadErr, mod) => {\n const { createSession, figures, formatArguments } = mod || { createSession: undefined, figures: { tick: '✓', cross: '✗' }, formatArguments: (x: string[]) => x };\n if (!createSession) {\n console.log('\\n======================');\n results.forEach((res) => {\n console.log(`${res.error ? figures.cross : figures.tick} ${res.version}${res.error ? ` Error: ${res.error.message}` : ''}`);\n });\n console.log('\\n----------------------');\n console.log(`${name} ${formatArguments(args).join(' ')}`);\n console.log(`${figures.tick} ${results.length - errors.length} succeeded`);\n if (errors.length) console.log(`${figures.cross} ${errors.length} failed`);\n }\n exit(err || errors.length ? ERROR_CODE : 0);\n });\n } else {\n exit(err || errors.length ? ERROR_CODE : 0);\n }\n });\n};\n"],"names":["__dirname","path","dirname","__filename","url","fileURLToPath","ERROR_CODE","getVersion","packagePath","join","packageJson","JSON","parse","fs","readFileSync","version","printHelp","name","console","log","argv","options","getopts","alias","range","desc","expanded","streaming","silent","help","default","interactive","boolean","stopEarly","exit","args","_","length","isCommand","runCommand","slice","sort","stdio","run","err","results","message","errors","filter","result","error","loadSpawnTerm","_loadErr","mod","createSession","undefined","figures","tick","cross","formatArguments","x","forEach","res"],"mappings":";;;;+BAyDA;;;eAAA;;;2DAzDiB;yDACF;oEACK;2DACH;0DACD;uBACsB;+DACtB;sEACU;;;;;;AAG1B,IAAMA,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAElG,IAAMC,aAAa;AAEnB,SAASC;IACP,IAAMC,cAAcP,aAAI,CAACQ,IAAI,CAACT,WAAW,MAAM,MAAM;IACrD,IAAMU,cAAcC,KAAKC,KAAK,CAACC,WAAE,CAACC,YAAY,CAACN,aAAa;IAC5D,OAAOE,YAAYK,OAAO;AAC5B;AAEA,SAASC,UAAUC,IAAY;IAC7B,IAAMF,UAAUR;IAChBW,QAAQC,GAAG,CAAC,AAAC,GAAWJ,OAATE,MAAK,MAAY,OAARF;IACxBG,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC,AAAC,UAAc,OAALF,MAAK;IAC3BC,QAAQC,GAAG,CAAC,AAAC,UAAc,OAALF,MAAK;IAC3BC,QAAQC,GAAG,CAAC;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eC;oBAAWC,SAAS;wBAAEC,MAAM;wBAAKC,OAAO;oBAAI;oBAAGC,iBAAiB,SAACC;+BAAgBA;;gBAAE,GAAvJN,gBAA4CD,KAA5CC,eAAeE,UAA6BH,KAA7BG,SAASG,kBAAoBN,KAApBM;gBAChC,IAAI,CAACL,eAAe;oBAClBpC,QAAQC,GAAG,CAAC;oBACZ0B,QAAQgB,OAAO,CAAC,SAACC;wBACf5C,QAAQC,GAAG,CAAC,AAAC,GAA8C2C,OAA5CA,IAAIZ,KAAK,GAAGM,QAAQE,KAAK,GAAGF,QAAQC,IAAI,EAAC,KAAiBK,OAAdA,IAAI/C,OAAO,EAAmD,OAAhD+C,IAAIZ,KAAK,GAAG,AAAC,WAA4B,OAAlBY,IAAIZ,KAAK,CAACJ,OAAO,IAAK;oBACxH;oBACA5B,QAAQC,GAAG,CAAC;oBACZD,QAAQC,GAAG,CAAC,AAAC,GAAUwC,OAAR1C,MAAK,KAAmC,OAAhC0C,gBAAgBxB,MAAM1B,IAAI,CAAC;oBAClDS,QAAQC,GAAG,CAAC,AAAC,GAAkB0B,OAAhBW,QAAQC,IAAI,EAAC,KAAkC,OAA/BZ,QAAQR,MAAM,GAAGU,OAAOV,MAAM,EAAC;oBAC9D,IAAIU,OAAOV,MAAM,EAAEnB,QAAQC,GAAG,CAAC,AAAC,GAAmB4B,OAAjBS,QAAQE,KAAK,EAAC,KAAiB,OAAdX,OAAOV,MAAM,EAAC;gBACnE;gBACAH,IAAAA,aAAI,EAACU,OAAOG,OAAOV,MAAM,GAAG/B,aAAa;YAC3C;QACF,OAAO;YACL4B,IAAAA,aAAI,EAACU,OAAOG,OAAOV,MAAM,GAAG/B,aAAa;QAC3C;IACF;AACF"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * nvu default [version]
3
+ *
4
+ * Set or display the global default Node version.
5
+ * This is used when no .nvmrc or .nvurc is found in the project.
6
+ */
7
+ export default function defaultCmd(args: string[]): void;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * nvu default [version]
3
+ *
4
+ * Set or display the global default Node version.
5
+ * This is used when no .nvmrc or .nvurc is found in the project.
6
+ */
7
+ export default function defaultCmd(args: string[]): void;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, /**
6
+ * nvu default [version]
7
+ *
8
+ * Set or display the global default Node version.
9
+ * This is used when no .nvmrc or .nvurc is found in the project.
10
+ */ "default", {
11
+ enumerable: true,
12
+ get: function() {
13
+ return defaultCmd;
14
+ }
15
+ });
16
+ var _exit = /*#__PURE__*/ _interop_require_default(require("exit"));
17
+ var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
18
+ var _path = /*#__PURE__*/ _interop_require_default(require("path"));
19
+ var _compatts = require("../compat.js");
20
+ var _constantsts = require("../constants.js");
21
+ function _interop_require_default(obj) {
22
+ return obj && obj.__esModule ? obj : {
23
+ default: obj
24
+ };
25
+ }
26
+ function defaultCmd(args) {
27
+ var defaultFilePath = _path.default.join(_constantsts.storagePath, 'default');
28
+ // If no version provided, display current default
29
+ if (args.length === 0) {
30
+ if (_fs.default.existsSync(defaultFilePath)) {
31
+ var currentVersion = _fs.default.readFileSync(defaultFilePath, 'utf8').trim();
32
+ console.log("Current default: ".concat(currentVersion));
33
+ } else {
34
+ console.log('No default version set.');
35
+ console.log('Usage: nvu default <version>');
36
+ }
37
+ (0, _exit.default)(0);
38
+ return;
39
+ }
40
+ var version = args[0].trim();
41
+ // Validate version format (basic check)
42
+ if (!version || version.startsWith('-')) {
43
+ console.log('Usage: nvu default <version>');
44
+ console.log('Example: nvu default 20');
45
+ (0, _exit.default)(1);
46
+ return;
47
+ }
48
+ // Ensure storage directory exists
49
+ if (!_fs.default.existsSync(_constantsts.storagePath)) {
50
+ (0, _compatts.mkdirpSync)(_constantsts.storagePath);
51
+ }
52
+ // Write the default version
53
+ _fs.default.writeFileSync(defaultFilePath, "".concat(version, "\n"), 'utf8');
54
+ console.log("Default Node version set to: ".concat(version));
55
+ (0, _exit.default)(0);
56
+ }
57
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/default.ts"],"sourcesContent":["import exit from 'exit';\nimport fs from 'fs';\nimport path from 'path';\nimport { mkdirpSync } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu default [version]\n *\n * Set or display the global default Node version.\n * This is used when no .nvmrc or .nvurc is found in the project.\n */\nexport default function defaultCmd(args: string[]): void {\n var defaultFilePath = path.join(storagePath, 'default');\n\n // If no version provided, display current default\n if (args.length === 0) {\n if (fs.existsSync(defaultFilePath)) {\n var currentVersion = fs.readFileSync(defaultFilePath, 'utf8').trim();\n console.log(`Current default: ${currentVersion}`);\n } else {\n console.log('No default version set.');\n console.log('Usage: nvu default <version>');\n }\n exit(0);\n return;\n }\n\n var version = args[0].trim();\n\n // Validate version format (basic check)\n if (!version || version.startsWith('-')) {\n console.log('Usage: nvu default <version>');\n console.log('Example: nvu default 20');\n exit(1);\n return;\n }\n\n // Ensure storage directory exists\n if (!fs.existsSync(storagePath)) {\n mkdirpSync(storagePath);\n }\n\n // Write the default version\n fs.writeFileSync(defaultFilePath, `${version}\\n`, 'utf8');\n console.log(`Default Node version set to: ${version}`);\n exit(0);\n}\n"],"names":["defaultCmd","args","defaultFilePath","path","join","storagePath","length","fs","existsSync","currentVersion","readFileSync","trim","console","log","exit","version","startsWith","mkdirpSync","writeFileSync"],"mappings":";;;;+BAMA;;;;;CAKC,GACD;;;eAAwBA;;;2DAZP;yDACF;2DACE;wBACU;2BACC;;;;;;AAQb,SAASA,WAAWC,IAAc;IAC/C,IAAIC,kBAAkBC,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAE7C,kDAAkD;IAClD,IAAIJ,KAAKK,MAAM,KAAK,GAAG;QACrB,IAAIC,WAAE,CAACC,UAAU,CAACN,kBAAkB;YAClC,IAAIO,iBAAiBF,WAAE,CAACG,YAAY,CAACR,iBAAiB,QAAQS,IAAI;YAClEC,QAAQC,GAAG,CAAC,AAAC,oBAAkC,OAAfJ;QAClC,OAAO;YACLG,QAAQC,GAAG,CAAC;YACZD,QAAQC,GAAG,CAAC;QACd;QACAC,IAAAA,aAAI,EAAC;QACL;IACF;IAEA,IAAIC,UAAUd,IAAI,CAAC,EAAE,CAACU,IAAI;IAE1B,wCAAwC;IACxC,IAAI,CAACI,WAAWA,QAAQC,UAAU,CAAC,MAAM;QACvCJ,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZC,IAAAA,aAAI,EAAC;QACL;IACF;IAEA,kCAAkC;IAClC,IAAI,CAACP,WAAE,CAACC,UAAU,CAACH,wBAAW,GAAG;QAC/BY,IAAAA,oBAAU,EAACZ,wBAAW;IACxB;IAEA,4BAA4B;IAC5BE,WAAE,CAACW,aAAa,CAAChB,iBAAiB,AAAC,GAAU,OAARa,SAAQ,OAAK;IAClDH,QAAQC,GAAG,CAAC,AAAC,gCAAuC,OAARE;IAC5CD,IAAAA,aAAI,EAAC;AACP"}
@@ -0,0 +1,3 @@
1
+ export declare const commands: Record<string, (args: string[]) => void>;
2
+ export declare function isCommand(name: string): boolean;
3
+ export declare function runCommand(name: string, args: string[]): void;
@@ -0,0 +1,3 @@
1
+ export declare const commands: Record<string, (args: string[]) => void>;
2
+ export declare function isCommand(name: string): boolean;
3
+ export declare function runCommand(name: string, args: string[]): void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get commands () {
13
+ return commands;
14
+ },
15
+ get isCommand () {
16
+ return isCommand;
17
+ },
18
+ get runCommand () {
19
+ return runCommand;
20
+ }
21
+ });
22
+ var _defaultts = /*#__PURE__*/ _interop_require_default(require("./default.js"));
23
+ var _installts = /*#__PURE__*/ _interop_require_default(require("./install.js"));
24
+ var _listts = /*#__PURE__*/ _interop_require_default(require("./list.js"));
25
+ var _localts = /*#__PURE__*/ _interop_require_default(require("./local.js"));
26
+ var _setupts = /*#__PURE__*/ _interop_require_default(require("./setup.js"));
27
+ var _teardownts = /*#__PURE__*/ _interop_require_default(require("./teardown.js"));
28
+ var _uninstallts = /*#__PURE__*/ _interop_require_default(require("./uninstall.js"));
29
+ var _whichts = /*#__PURE__*/ _interop_require_default(require("./which.js"));
30
+ function _interop_require_default(obj) {
31
+ return obj && obj.__esModule ? obj : {
32
+ default: obj
33
+ };
34
+ }
35
+ var commands = {
36
+ default: _defaultts.default,
37
+ local: _localts.default,
38
+ list: _listts.default,
39
+ which: _whichts.default,
40
+ install: _installts.default,
41
+ uninstall: _uninstallts.default,
42
+ setup: _setupts.default,
43
+ teardown: _teardownts.default
44
+ };
45
+ function isCommand(name) {
46
+ return name in commands;
47
+ }
48
+ function runCommand(name, args) {
49
+ var cmd = commands[name];
50
+ if (cmd) {
51
+ cmd(args);
52
+ }
53
+ }
54
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/index.ts"],"sourcesContent":["import defaultCmd from './default.ts';\nimport installCmd from './install.ts';\nimport listCmd from './list.ts';\nimport localCmd from './local.ts';\nimport setupCmd from './setup.ts';\nimport teardownCmd from './teardown.ts';\nimport uninstallCmd from './uninstall.ts';\nimport whichCmd from './which.ts';\n\nexport const commands: Record<string, (args: string[]) => void> = {\n default: defaultCmd,\n local: localCmd,\n list: listCmd,\n which: whichCmd,\n install: installCmd,\n uninstall: uninstallCmd,\n setup: setupCmd,\n teardown: teardownCmd,\n};\n\nexport function isCommand(name: string): boolean {\n return name in commands;\n}\n\nexport function runCommand(name: string, args: string[]): void {\n const cmd = commands[name];\n if (cmd) {\n cmd(args);\n }\n}\n"],"names":["commands","isCommand","runCommand","default","defaultCmd","local","localCmd","list","listCmd","which","whichCmd","install","installCmd","uninstall","uninstallCmd","setup","setupCmd","teardown","teardownCmd","name","args","cmd"],"mappings":";;;;;;;;;;;QASaA;eAAAA;;QAWGC;eAAAA;;QAIAC;eAAAA;;;gEAxBO;gEACA;6DACH;8DACC;8DACA;iEACG;kEACC;8DACJ;;;;;;AAEd,IAAMF,WAAqD;IAChEG,SAASC,kBAAU;IACnBC,OAAOC,gBAAQ;IACfC,MAAMC,eAAO;IACbC,OAAOC,gBAAQ;IACfC,SAASC,kBAAU;IACnBC,WAAWC,oBAAY;IACvBC,OAAOC,gBAAQ;IACfC,UAAUC,mBAAW;AACvB;AAEO,SAASjB,UAAUkB,IAAY;IACpC,OAAOA,QAAQnB;AACjB;AAEO,SAASE,WAAWiB,IAAY,EAAEC,IAAc;IACrD,IAAMC,MAAMrB,QAAQ,CAACmB,KAAK;IAC1B,IAAIE,KAAK;QACPA,IAAID;IACN;AACF"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * nvu install <version>
3
+ *
4
+ * Download and install a specific Node version.
5
+ */
6
+ export default function installCmd(args: string[]): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * nvu install <version>
3
+ *
4
+ * Download and install a specific Node version.
5
+ */
6
+ export default function installCmd(args: string[]): void;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, /**
6
+ * nvu install <version>
7
+ *
8
+ * Download and install a specific Node version.
9
+ */ "default", {
10
+ enumerable: true,
11
+ get: function() {
12
+ return installCmd;
13
+ }
14
+ });
15
+ var _exit = /*#__PURE__*/ _interop_require_default(require("exit"));
16
+ var _path = /*#__PURE__*/ _interop_require_default(require("path"));
17
+ var _constantsts = require("../constants.js");
18
+ var _loadNodeVersionInstallts = /*#__PURE__*/ _interop_require_default(require("../lib/loadNodeVersionInstall.js"));
19
+ function _interop_require_default(obj) {
20
+ return obj && obj.__esModule ? obj : {
21
+ default: obj
22
+ };
23
+ }
24
+ function installCmd(args) {
25
+ if (args.length === 0) {
26
+ console.log('Usage: nvu install <version>');
27
+ console.log('Example: nvu install 20');
28
+ console.log(' nvu install 20.10.0');
29
+ console.log(' nvu install lts');
30
+ (0, _exit.default)(1);
31
+ return;
32
+ }
33
+ var version = args[0].trim();
34
+ // Validate version format (basic check)
35
+ if (!version || version.startsWith('-')) {
36
+ console.log('Usage: nvu install <version>');
37
+ (0, _exit.default)(1);
38
+ return;
39
+ }
40
+ console.log("Installing Node ".concat(version, "..."));
41
+ // Load node-version-install dynamically
42
+ (0, _loadNodeVersionInstallts.default)(function(err, nodeVersionInstall) {
43
+ if (err || !nodeVersionInstall) {
44
+ console.error('Failed to load node-version-install:', (err === null || err === void 0 ? void 0 : err.message) || 'Module not available');
45
+ console.error('Make sure node-version-install is installed: npm install node-version-install');
46
+ (0, _exit.default)(1);
47
+ return;
48
+ }
49
+ var versionsPath = _path.default.join(_constantsts.storagePath, 'versions');
50
+ nodeVersionInstall(version, {
51
+ installPath: versionsPath
52
+ }, function(installErr, results) {
53
+ if (installErr) {
54
+ console.error("Failed to install Node ".concat(version, ":"), installErr.message);
55
+ (0, _exit.default)(1);
56
+ return;
57
+ }
58
+ if (results && results.length > 0) {
59
+ var result = results[0];
60
+ console.log("Successfully installed Node ".concat(result.version));
61
+ console.log("Location: ".concat(result.installPath));
62
+ } else {
63
+ console.log("Node ".concat(version, " installed successfully."));
64
+ }
65
+ (0, _exit.default)(0);
66
+ });
67
+ });
68
+ }
69
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/install.ts"],"sourcesContent":["import exit from 'exit';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\nimport loadNodeVersionInstall from '../lib/loadNodeVersionInstall.ts';\n\n/**\n * nvu install <version>\n *\n * Download and install a specific Node version.\n */\nexport default function installCmd(args: string[]): void {\n if (args.length === 0) {\n console.log('Usage: nvu install <version>');\n console.log('Example: nvu install 20');\n console.log(' nvu install 20.10.0');\n console.log(' nvu install lts');\n exit(1);\n return;\n }\n\n const version = args[0].trim();\n\n // Validate version format (basic check)\n if (!version || version.startsWith('-')) {\n console.log('Usage: nvu install <version>');\n exit(1);\n return;\n }\n\n console.log(`Installing Node ${version}...`);\n\n // Load node-version-install dynamically\n loadNodeVersionInstall((err, nodeVersionInstall) => {\n if (err || !nodeVersionInstall) {\n console.error('Failed to load node-version-install:', err?.message || 'Module not available');\n console.error('Make sure node-version-install is installed: npm install node-version-install');\n exit(1);\n return;\n }\n\n const versionsPath = path.join(storagePath, 'versions');\n\n nodeVersionInstall(\n version,\n {\n installPath: versionsPath,\n },\n (installErr?: Error, results?: { version: string; installPath: string }[]) => {\n if (installErr) {\n console.error(`Failed to install Node ${version}:`, installErr.message);\n exit(1);\n return;\n }\n\n if (results && results.length > 0) {\n const result = results[0];\n console.log(`Successfully installed Node ${result.version}`);\n console.log(`Location: ${result.installPath}`);\n } else {\n console.log(`Node ${version} installed successfully.`);\n }\n exit(0);\n }\n );\n });\n}\n"],"names":["installCmd","args","length","console","log","exit","version","trim","startsWith","loadNodeVersionInstall","err","nodeVersionInstall","error","message","versionsPath","path","join","storagePath","installPath","installErr","results","result"],"mappings":";;;;+BAKA;;;;CAIC,GACD;;;eAAwBA;;;2DAVP;2DACA;2BACW;+EACO;;;;;;AAOp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EJ;AACF"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * nvu list
3
+ *
4
+ * List all installed Node versions.
5
+ */
6
+ export default function listCmd(_args: string[]): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * nvu list
3
+ *
4
+ * List all installed Node versions.
5
+ */
6
+ export default function listCmd(_args: string[]): void;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, /**
6
+ * nvu list
7
+ *
8
+ * List all installed Node versions.
9
+ */ "default", {
10
+ enumerable: true,
11
+ get: function() {
12
+ return listCmd;
13
+ }
14
+ });
15
+ var _exit = /*#__PURE__*/ _interop_require_default(require("exit"));
16
+ var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
17
+ var _path = /*#__PURE__*/ _interop_require_default(require("path"));
18
+ var _compatts = require("../compat.js");
19
+ var _constantsts = require("../constants.js");
20
+ function _interop_require_default(obj) {
21
+ return obj && obj.__esModule ? obj : {
22
+ default: obj
23
+ };
24
+ }
25
+ function listCmd(_args) {
26
+ var versionsPath = _path.default.join(_constantsts.storagePath, 'versions');
27
+ // Check if versions directory exists
28
+ if (!_fs.default.existsSync(versionsPath)) {
29
+ console.log('No Node versions installed.');
30
+ console.log('Install a version: nvu install <version>');
31
+ (0, _exit.default)(0);
32
+ return;
33
+ }
34
+ // Read all directories in versions folder
35
+ var entries = (0, _compatts.readdirWithTypes)(versionsPath);
36
+ var versions = entries.filter(function(entry) {
37
+ return entry.isDirectory();
38
+ }).map(function(entry) {
39
+ return entry.name;
40
+ });
41
+ if (versions.length === 0) {
42
+ console.log('No Node versions installed.');
43
+ console.log('Install a version: nvu install <version>');
44
+ (0, _exit.default)(0);
45
+ return;
46
+ }
47
+ // Get the current default
48
+ var defaultFilePath = _path.default.join(_constantsts.storagePath, 'default');
49
+ var defaultVersion = '';
50
+ if (_fs.default.existsSync(defaultFilePath)) {
51
+ defaultVersion = _fs.default.readFileSync(defaultFilePath, 'utf8').trim();
52
+ }
53
+ // Sort versions (simple string sort, could be improved with semver)
54
+ versions.sort(function(a, b) {
55
+ var aParts = a.split('.').map(function(n) {
56
+ return parseInt(n, 10) || 0;
57
+ });
58
+ var bParts = b.split('.').map(function(n) {
59
+ return parseInt(n, 10) || 0;
60
+ });
61
+ for(var i = 0; i < Math.max(aParts.length, bParts.length); i++){
62
+ var aVal = aParts[i] || 0;
63
+ var bVal = bParts[i] || 0;
64
+ if (aVal !== bVal) return bVal - aVal; // Descending order
65
+ }
66
+ return 0;
67
+ });
68
+ console.log('Installed Node versions:');
69
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
70
+ try {
71
+ for(var _iterator = versions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
72
+ var version = _step.value;
73
+ var isDefault = version === defaultVersion || "v".concat(version) === defaultVersion || version === "v".concat(defaultVersion);
74
+ var marker = isDefault ? ' (default)' : '';
75
+ console.log(" ".concat(version).concat(marker));
76
+ }
77
+ } catch (err) {
78
+ _didIteratorError = true;
79
+ _iteratorError = err;
80
+ } finally{
81
+ try {
82
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
83
+ _iterator.return();
84
+ }
85
+ } finally{
86
+ if (_didIteratorError) {
87
+ throw _iteratorError;
88
+ }
89
+ }
90
+ }
91
+ (0, _exit.default)(0);
92
+ }
93
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }