node-version-use 2.1.2 → 2.1.3

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.
@@ -1,7 +1,7 @@
1
1
  /**
2
- * nvu setup
2
+ * nvu setup [--shims]
3
3
  *
4
4
  * Install/reinstall nvu binaries to ~/.nvu/bin
5
- * This runs the same logic as the postinstall script.
5
+ * With --shims: create shims for existing global packages
6
6
  */
7
- export default function setupCmd(_args: string[]): void;
7
+ export default function setupCmd(args: string[]): void;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * nvu setup
2
+ * nvu setup [--shims]
3
3
  *
4
4
  * Install/reinstall nvu binaries to ~/.nvu/bin
5
- * This runs the same logic as the postinstall script.
5
+ * With --shims: create shims for existing global packages
6
6
  */
7
- export default function setupCmd(_args: string[]): void;
7
+ export default function setupCmd(args: string[]): void;
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  Object.defineProperty(exports, /**
6
- * nvu setup
6
+ * nvu setup [--shims]
7
7
  *
8
8
  * Install/reinstall nvu binaries to ~/.nvu/bin
9
- * This runs the same logic as the postinstall script.
9
+ * With --shims: create shims for existing global packages
10
10
  */ "default", {
11
11
  enumerable: true,
12
12
  get: function() {
@@ -20,13 +20,14 @@ var _path = /*#__PURE__*/ _interop_require_default(require("path"));
20
20
  var _url = /*#__PURE__*/ _interop_require_default(require("url"));
21
21
  var _compatts = require("../compat.js");
22
22
  var _constantsts = require("../constants.js");
23
+ var _findInstalledVersionsts = require("../lib/findInstalledVersions.js");
23
24
  function _interop_require_default(obj) {
24
25
  return obj && obj.__esModule ? obj : {
25
26
  default: obj
26
27
  };
27
28
  }
28
29
  var __dirname = _path.default.dirname(typeof __filename !== 'undefined' ? __filename : _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()));
29
- function setupCmd(_args) {
30
+ function setupCmd(args) {
30
31
  var binDir = _path.default.join(_constantsts.storagePath, 'bin');
31
32
  // Create directories
32
33
  if (!_fs.default.existsSync(_constantsts.storagePath)) {
@@ -35,6 +36,18 @@ function setupCmd(_args) {
35
36
  if (!_fs.default.existsSync(binDir)) {
36
37
  (0, _compatts.mkdirpSync)(binDir);
37
38
  }
39
+ // Check for --shims flag
40
+ var hasShimsFlag = false;
41
+ for(var i = 0; i < args.length; i++){
42
+ if (args[i] === '--shims') {
43
+ hasShimsFlag = true;
44
+ break;
45
+ }
46
+ }
47
+ if (hasShimsFlag) {
48
+ createShimsForGlobalPackages(binDir);
49
+ return;
50
+ }
38
51
  // Find the postinstall script relative to this module
39
52
  var postinstallPath = _path.default.join(__dirname, '..', '..', '..', 'scripts', 'postinstall.cjs');
40
53
  if (_fs.default.existsSync(postinstallPath)) {
@@ -52,4 +65,70 @@ function setupCmd(_args) {
52
65
  (0, _exitcompat.default)(1);
53
66
  }
54
67
  }
68
+ /**
69
+ * Create shims for all global packages in the default Node version
70
+ */ function createShimsForGlobalPackages(binDir) {
71
+ // Read default version
72
+ var defaultPath = _path.default.join(_constantsts.storagePath, 'default');
73
+ if (!_fs.default.existsSync(defaultPath)) {
74
+ console.log('No default Node version set.');
75
+ console.log('Set one with: nvu default <version>');
76
+ (0, _exitcompat.default)(1);
77
+ return;
78
+ }
79
+ var defaultVersion = _fs.default.readFileSync(defaultPath, 'utf8').trim();
80
+ var versionsDir = _path.default.join(_constantsts.storagePath, 'installed');
81
+ // Resolve to exact version
82
+ var matches = (0, _findInstalledVersionsts.findInstalledVersions)(versionsDir, defaultVersion);
83
+ if (matches.length === 0) {
84
+ console.log("Default version ".concat(defaultVersion, " is not installed."));
85
+ (0, _exitcompat.default)(1);
86
+ return;
87
+ }
88
+ var resolvedVersion = matches[matches.length - 1];
89
+ var nodeBinDir = _path.default.join(versionsDir, resolvedVersion, 'bin');
90
+ if (!_fs.default.existsSync(nodeBinDir)) {
91
+ console.log("No bin directory found for ".concat(resolvedVersion));
92
+ (0, _exitcompat.default)(1);
93
+ return;
94
+ }
95
+ // Get the node shim to copy from
96
+ var nodeShim = _path.default.join(binDir, 'node');
97
+ if (!_fs.default.existsSync(nodeShim)) {
98
+ console.log('Node shim not found. Run: nvu setup');
99
+ (0, _exitcompat.default)(1);
100
+ return;
101
+ }
102
+ // Scan binaries in Node's bin directory
103
+ var entries = (0, _compatts.readdirWithTypes)(nodeBinDir);
104
+ var created = 0;
105
+ var skipped = 0;
106
+ for(var i = 0; i < entries.length; i++){
107
+ var entry = entries[i];
108
+ var name = entry.name;
109
+ // Skip our routing shims (node/npm/npx) - don't overwrite them
110
+ if (name === 'node' || name === 'npm' || name === 'npx') {
111
+ continue;
112
+ }
113
+ var shimPath = _path.default.join(binDir, name);
114
+ // Skip if shim already exists
115
+ if (_fs.default.existsSync(shimPath)) {
116
+ skipped++;
117
+ continue;
118
+ }
119
+ // Copy the node shim
120
+ try {
121
+ var shimContent = _fs.default.readFileSync(nodeShim);
122
+ _fs.default.writeFileSync(shimPath, shimContent);
123
+ _fs.default.chmodSync(shimPath, 493); // 0755
124
+ console.log("Created shim: ".concat(name));
125
+ created++;
126
+ } catch (err) {
127
+ console.error("Failed to create shim for ".concat(name, ": ").concat(err.message));
128
+ }
129
+ }
130
+ console.log('');
131
+ console.log("Done. Created ".concat(created, " shims, skipped ").concat(skipped, " (already exist)."));
132
+ (0, _exitcompat.default)(0);
133
+ }
55
134
  /* 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; }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/setup.ts"],"sourcesContent":["import { execSync } from 'child_process';\nimport exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport url from 'url';\nimport { mkdirpSync } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\n\nvar __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n/**\n * nvu setup\n *\n * Install/reinstall nvu binaries to ~/.nvu/bin\n * This runs the same logic as the postinstall script.\n */\nexport default function setupCmd(_args: string[]): void {\n var binDir = path.join(storagePath, 'bin');\n\n // Create directories\n if (!fs.existsSync(storagePath)) {\n mkdirpSync(storagePath);\n }\n if (!fs.existsSync(binDir)) {\n mkdirpSync(binDir);\n }\n\n // Find the postinstall script relative to this module\n var postinstallPath = path.join(__dirname, '..', '..', '..', 'scripts', 'postinstall.cjs');\n\n if (fs.existsSync(postinstallPath)) {\n // Run the postinstall script\n try {\n execSync(`node \"${postinstallPath}\"`, { stdio: 'inherit' });\n } catch (_err) {\n // postinstall handles its own errors gracefully\n }\n } else {\n console.log('Setup script not found.');\n console.log('Try reinstalling: npm install -g node-version-use');\n exit(1);\n }\n}\n"],"names":["setupCmd","__dirname","path","dirname","__filename","url","fileURLToPath","_args","binDir","join","storagePath","fs","existsSync","mkdirpSync","postinstallPath","execSync","stdio","_err","console","log","exit"],"mappings":";;;;+BAUA;;;;;CAKC,GACD;;;eAAwBA;;;6BAhBC;iEACR;yDACF;2DACE;0DACD;wBACW;2BACC;;;;;;AAE5B,IAAIC,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAQjF,SAASN,SAASO,KAAe;IAC9C,IAAIC,SAASN,aAAI,CAACO,IAAI,CAACC,wBAAW,EAAE;IAEpC,qBAAqB;IACrB,IAAI,CAACC,WAAE,CAACC,UAAU,CAACF,wBAAW,GAAG;QAC/BG,IAAAA,oBAAU,EAACH,wBAAW;IACxB;IACA,IAAI,CAACC,WAAE,CAACC,UAAU,CAACJ,SAAS;QAC1BK,IAAAA,oBAAU,EAACL;IACb;IAEA,sDAAsD;IACtD,IAAIM,kBAAkBZ,aAAI,CAACO,IAAI,CAACR,WAAW,MAAM,MAAM,MAAM,WAAW;IAExE,IAAIU,WAAE,CAACC,UAAU,CAACE,kBAAkB;QAClC,6BAA6B;QAC7B,IAAI;YACFC,IAAAA,uBAAQ,EAAC,AAAC,SAAwB,OAAhBD,iBAAgB,MAAI;gBAAEE,OAAO;YAAU;QAC3D,EAAE,OAAOC,MAAM;QACb,gDAAgD;QAClD;IACF,OAAO;QACLC,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZC,IAAAA,mBAAI,EAAC;IACP;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/setup.ts"],"sourcesContent":["import { execSync } from 'child_process';\nimport exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport url from 'url';\nimport { mkdirpSync, readdirWithTypes } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\nimport { findInstalledVersions } from '../lib/findInstalledVersions.ts';\n\nvar __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n/**\n * nvu setup [--shims]\n *\n * Install/reinstall nvu binaries to ~/.nvu/bin\n * With --shims: create shims for existing global packages\n */\nexport default function setupCmd(args: string[]): void {\n var binDir = path.join(storagePath, 'bin');\n\n // Create directories\n if (!fs.existsSync(storagePath)) {\n mkdirpSync(storagePath);\n }\n if (!fs.existsSync(binDir)) {\n mkdirpSync(binDir);\n }\n\n // Check for --shims flag\n var hasShimsFlag = false;\n for (var i = 0; i < args.length; i++) {\n if (args[i] === '--shims') {\n hasShimsFlag = true;\n break;\n }\n }\n\n if (hasShimsFlag) {\n createShimsForGlobalPackages(binDir);\n return;\n }\n\n // Find the postinstall script relative to this module\n var postinstallPath = path.join(__dirname, '..', '..', '..', 'scripts', 'postinstall.cjs');\n\n if (fs.existsSync(postinstallPath)) {\n // Run the postinstall script\n try {\n execSync(`node \"${postinstallPath}\"`, { stdio: 'inherit' });\n } catch (_err) {\n // postinstall handles its own errors gracefully\n }\n } else {\n console.log('Setup script not found.');\n console.log('Try reinstalling: npm install -g node-version-use');\n exit(1);\n }\n}\n\n/**\n * Create shims for all global packages in the default Node version\n */\nfunction createShimsForGlobalPackages(binDir: string): void {\n // Read default version\n var defaultPath = path.join(storagePath, 'default');\n if (!fs.existsSync(defaultPath)) {\n console.log('No default Node version set.');\n console.log('Set one with: nvu default <version>');\n exit(1);\n return;\n }\n\n var defaultVersion = fs.readFileSync(defaultPath, 'utf8').trim();\n var versionsDir = path.join(storagePath, 'installed');\n\n // Resolve to exact version\n var matches = findInstalledVersions(versionsDir, defaultVersion);\n if (matches.length === 0) {\n console.log(`Default version ${defaultVersion} is not installed.`);\n exit(1);\n return;\n }\n\n var resolvedVersion = matches[matches.length - 1];\n var nodeBinDir = path.join(versionsDir, resolvedVersion, 'bin');\n\n if (!fs.existsSync(nodeBinDir)) {\n console.log(`No bin directory found for ${resolvedVersion}`);\n exit(1);\n return;\n }\n\n // Get the node shim to copy from\n var nodeShim = path.join(binDir, 'node');\n if (!fs.existsSync(nodeShim)) {\n console.log('Node shim not found. Run: nvu setup');\n exit(1);\n return;\n }\n\n // Scan binaries in Node's bin directory\n var entries = readdirWithTypes(nodeBinDir);\n var created = 0;\n var skipped = 0;\n\n for (var i = 0; i < entries.length; i++) {\n var entry = entries[i];\n var name = entry.name;\n\n // Skip our routing shims (node/npm/npx) - don't overwrite them\n if (name === 'node' || name === 'npm' || name === 'npx') {\n continue;\n }\n\n var shimPath = path.join(binDir, name);\n\n // Skip if shim already exists\n if (fs.existsSync(shimPath)) {\n skipped++;\n continue;\n }\n\n // Copy the node shim\n try {\n var shimContent = fs.readFileSync(nodeShim);\n fs.writeFileSync(shimPath, shimContent);\n fs.chmodSync(shimPath, 493); // 0755\n console.log(`Created shim: ${name}`);\n created++;\n } catch (err) {\n console.error(`Failed to create shim for ${name}: ${(err as Error).message}`);\n }\n }\n\n console.log('');\n console.log(`Done. Created ${created} shims, skipped ${skipped} (already exist).`);\n exit(0);\n}\n"],"names":["setupCmd","__dirname","path","dirname","__filename","url","fileURLToPath","args","binDir","join","storagePath","fs","existsSync","mkdirpSync","hasShimsFlag","i","length","createShimsForGlobalPackages","postinstallPath","execSync","stdio","_err","console","log","exit","defaultPath","defaultVersion","readFileSync","trim","versionsDir","matches","findInstalledVersions","resolvedVersion","nodeBinDir","nodeShim","entries","readdirWithTypes","created","skipped","entry","name","shimPath","shimContent","writeFileSync","chmodSync","err","error","message"],"mappings":";;;;+BAWA;;;;;CAKC,GACD;;;eAAwBA;;;6BAjBC;iEACR;yDACF;2DACE;0DACD;wBAC6B;2BACjB;uCACU;;;;;;AAEtC,IAAIC,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAQjF,SAASN,SAASO,IAAc;IAC7C,IAAIC,SAASN,aAAI,CAACO,IAAI,CAACC,wBAAW,EAAE;IAEpC,qBAAqB;IACrB,IAAI,CAACC,WAAE,CAACC,UAAU,CAACF,wBAAW,GAAG;QAC/BG,IAAAA,oBAAU,EAACH,wBAAW;IACxB;IACA,IAAI,CAACC,WAAE,CAACC,UAAU,CAACJ,SAAS;QAC1BK,IAAAA,oBAAU,EAACL;IACb;IAEA,yBAAyB;IACzB,IAAIM,eAAe;IACnB,IAAK,IAAIC,IAAI,GAAGA,IAAIR,KAAKS,MAAM,EAAED,IAAK;QACpC,IAAIR,IAAI,CAACQ,EAAE,KAAK,WAAW;YACzBD,eAAe;YACf;QACF;IACF;IAEA,IAAIA,cAAc;QAChBG,6BAA6BT;QAC7B;IACF;IAEA,sDAAsD;IACtD,IAAIU,kBAAkBhB,aAAI,CAACO,IAAI,CAACR,WAAW,MAAM,MAAM,MAAM,WAAW;IAExE,IAAIU,WAAE,CAACC,UAAU,CAACM,kBAAkB;QAClC,6BAA6B;QAC7B,IAAI;YACFC,IAAAA,uBAAQ,EAAC,AAAC,SAAwB,OAAhBD,iBAAgB,MAAI;gBAAEE,OAAO;YAAU;QAC3D,EAAE,OAAOC,MAAM;QACb,gDAAgD;QAClD;IACF,OAAO;QACLC,QAAQC,GAAG,CAAC;QACZD,QAAQ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IAAK;QACvC,IAAIwB,QAAQJ,OAAO,CAACpB,EAAE;QACtB,IAAIyB,OAAOD,MAAMC,IAAI;QAErB,+DAA+D;QAC/D,IAAIA,SAAS,UAAUA,SAAS,SAASA,SAAS,OAAO;YACvD;QACF;QAEA,IAAIC,WAAWvC,aAAI,CAACO,IAAI,CAACD,QAAQgC;QAEjC,8BAA8B;QAC9B,IAAI7B,WAAE,CAACC,UAAU,CAAC6B,WAAW;YAC3BH;YACA;QACF;QAEA,qBAAqB;QACrB,IAAI;YACF,IAAII,cAAc/B,WAAE,CAACgB,YAAY,CAACO;YAClCvB,WAAE,CAACgC,aAAa,CAACF,UAAUC;YAC3B/B,WAAE,CAACiC,SAAS,CAACH,UAAU,MAAM,OAAO;YACpCnB,QAAQC,GAAG,CAAC,AAAC,iBAAqB,OAALiB;YAC7BH;QACF,EAAE,OAAOQ,KAAK;YACZvB,QAAQwB,KAAK,CAAC,AAAC,6BAAqC,OAATN,MAAK,MAA2B,OAAvB,AAACK,IAAcE,OAAO;QAC5E;IACF;IAEAzB,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC,AAAC,iBAA0Ce,OAA1BD,SAAQ,oBAA0B,OAARC,SAAQ;IAC/Dd,IAAAA,mBAAI,EAAC;AACP"}
@@ -17,6 +17,7 @@ var _exitcompat = /*#__PURE__*/ _interop_require_default(require("exit-compat"))
17
17
  var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
18
18
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
19
19
  var _constantsts = require("../constants.js");
20
+ var _findInstalledVersionsts = require("../lib/findInstalledVersions.js");
20
21
  function _interop_require_default(obj) {
21
22
  return obj && obj.__esModule ? obj : {
22
23
  default: obj
@@ -35,22 +36,19 @@ function whichCmd(_args) {
35
36
  (0, _exitcompat.default)(1);
36
37
  return;
37
38
  }
38
- // Check if the version is installed
39
+ // Resolve partial version to exact installed version
39
40
  var versionsPath = _path.default.join(_constantsts.storagePath, 'installed');
40
- var versionPath = _path.default.join(versionsPath, version);
41
- var versionPathWithV = _path.default.join(versionsPath, "v".concat(version));
42
- var versionPathWithoutV = _path.default.join(versionsPath, version.replace(/^v/, ''));
43
- var actualVersionPath = '';
44
- if (_fs.default.existsSync(versionPath)) {
45
- actualVersionPath = versionPath;
46
- } else if (_fs.default.existsSync(versionPathWithV)) {
47
- actualVersionPath = versionPathWithV;
48
- } else if (_fs.default.existsSync(versionPathWithoutV)) {
49
- actualVersionPath = versionPathWithoutV;
41
+ var matches = (0, _findInstalledVersionsts.findInstalledVersions)(versionsPath, version);
42
+ var resolvedVersion = matches.length > 0 ? matches[matches.length - 1] : null;
43
+ // Display version (show resolution if different)
44
+ if (resolvedVersion && resolvedVersion !== version && resolvedVersion !== "v".concat(version)) {
45
+ console.log("Version: ".concat(version, " → ").concat(resolvedVersion));
46
+ } else {
47
+ console.log("Version: ".concat(resolvedVersion || version));
50
48
  }
51
- console.log("Version: ".concat(version));
52
49
  console.log("Source: ".concat(getVersionSource(cwd)));
53
- if (actualVersionPath) {
50
+ if (resolvedVersion) {
51
+ var actualVersionPath = _path.default.join(versionsPath, resolvedVersion);
54
52
  var nodePath = _path.default.join(actualVersionPath, 'bin', 'node');
55
53
  console.log("Binary: ".concat(nodePath));
56
54
  if (_fs.default.existsSync(nodePath)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/which.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu which\n *\n * Show which Node binary would be used based on current directory.\n * This simulates what the nvu binary would do.\n */\nexport default function whichCmd(_args: string[]): void {\n const cwd = process.cwd();\n\n // Resolve version using the same logic as the nvu binary\n const version = resolveVersion(cwd);\n\n if (!version) {\n console.log('No Node version configured for this directory.');\n console.log('');\n console.log('To configure a version:');\n console.log(' nvu local <version> - Set version for this project');\n console.log(' nvu default <version> - Set global default');\n exit(1);\n return;\n }\n\n // Check if the version is installed\n const versionsPath = path.join(storagePath, 'installed');\n const versionPath = path.join(versionsPath, version);\n const versionPathWithV = path.join(versionsPath, `v${version}`);\n const versionPathWithoutV = path.join(versionsPath, version.replace(/^v/, ''));\n\n let actualVersionPath = '';\n if (fs.existsSync(versionPath)) {\n actualVersionPath = versionPath;\n } else if (fs.existsSync(versionPathWithV)) {\n actualVersionPath = versionPathWithV;\n } else if (fs.existsSync(versionPathWithoutV)) {\n actualVersionPath = versionPathWithoutV;\n }\n\n console.log(`Version: ${version}`);\n console.log(`Source: ${getVersionSource(cwd)}`);\n\n if (actualVersionPath) {\n const nodePath = path.join(actualVersionPath, 'bin', 'node');\n console.log(`Binary: ${nodePath}`);\n if (fs.existsSync(nodePath)) {\n console.log('Status: Installed');\n } else {\n console.log('Status: Directory exists but binary not found');\n }\n } else {\n console.log(`Status: Not installed (run: nvu install ${version})`);\n }\n\n exit(0);\n}\n\n/**\n * Resolve version from config files (mirrors nvu binary logic)\n */\nfunction resolveVersion(cwd: string): string | null {\n // Walk up directories looking for .nvurc or .nvmrc\n let dir = cwd;\n while (true) {\n // Check .nvurc first\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return fs.readFileSync(nvurcPath, 'utf8').trim();\n }\n\n // Check .nvmrc\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return fs.readFileSync(nvmrcPath, 'utf8').trim();\n }\n\n // Move to parent\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n // Check global default\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return fs.readFileSync(defaultPath, 'utf8').trim();\n }\n\n return null;\n}\n\n/**\n * Determine the source of the version (for display)\n */\nfunction getVersionSource(cwd: string): string {\n let dir = cwd;\n while (true) {\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return nvurcPath;\n }\n\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return nvmrcPath;\n }\n\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return `${defaultPath} (global default)`;\n }\n\n return 'none';\n}\n"],"names":["whichCmd","_args","cwd","process","version","resolveVersion","console","log","exit","versionsPath","path","join","storagePath","versionPath","versionPathWithV","versionPathWithoutV","replace","actualVersionPath","fs","existsSync","getVersionSource","nodePath","dir","nvurcPath","readFileSync","trim","nvmrcPath","parent","dirname","defaultPath"],"mappings":";;;;+BAKA;;;;;CAKC,GACD;;;eAAwBA;;;iEAXP;yDACF;2DACE;2BACW;;;;;;AAQb,SAASA,SAASC,KAAe;IAC9C,IAAMC,MAAMC,QAAQD,GAAG;IAEvB,yDAAyD;IACzD,IAAME,UAAUC,eAAeH;IAE/B,IAAI,CAACE,SAAS;QACZE,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZC,IAAAA,mBAAI,EAAC;QACL;IACF;IAEA,oCAAoC;IACpC,IAAMC,eAAeC,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAC5C,IAAMC,cAAcH,aAAI,CAACC,IAAI,CAACF,cAAcL;IAC5C,IAAMU,mBAAmBJ,aAAI,CAACC,IAAI,CAACF,cAAc,AAAC,IAAW,OAARL;IACrD,IAAMW,sBAAsBL,aAAI,CAACC,IAAI,CAACF,cAAcL,QAAQY,OAAO,CAAC,MAAM;IAE1E,IAAIC,oBAAoB;IACxB,IAAIC,WAAE,CAACC,UAAU,CAACN,cAAc;QAC9BI,oBAAoBJ;IACtB,OAAO,IAAIK,WAAE,CAACC,UAAU,CAACL,mBAAmB;QAC1CG,oBAAoBH;IACtB,OAAO,IAAII,WAAE,CAACC,UAAU,CAACJ,sBAAs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AASL,iBAAiBlB,GAAW;IACnC,IAAIoB,MAAMpB;IACV,MAAO,KAAM;QACX,IAAMqB,YAAYb,aAAI,CAACC,IAAI,CAACW,KAAK;QACjC,IAAIJ,WAAE,CAACC,UAAU,CAACI,YAAY;YAC5B,OAAOA;QACT;QAEA,IAAMG,YAAYhB,aAAI,CAACC,IAAI,CAACW,KAAK;QACjC,IAAIJ,WAAE,CAACC,UAAU,CAACO,YAAY;YAC5B,OAAOA;QACT;QAEA,IAAMC,SAASjB,aAAI,CAACkB,OAAO,CAACN;QAC5B,IAAIK,WAAWL,KAAK;QACpBA,MAAMK;IACR;IAEA,IAAME,cAAcnB,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAC3C,IAAIM,WAAE,CAACC,UAAU,CAACU,cAAc;QAC9B,OAAO,AAAC,GAAc,OAAZA,aAAY;IACxB;IAEA,OAAO;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/which.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\nimport { findInstalledVersions } from '../lib/findInstalledVersions.ts';\n\n/**\n * nvu which\n *\n * Show which Node binary would be used based on current directory.\n * This simulates what the nvu binary would do.\n */\nexport default function whichCmd(_args: string[]): void {\n const cwd = process.cwd();\n\n // Resolve version using the same logic as the nvu binary\n const version = resolveVersion(cwd);\n\n if (!version) {\n console.log('No Node version configured for this directory.');\n console.log('');\n console.log('To configure a version:');\n console.log(' nvu local <version> - Set version for this project');\n console.log(' nvu default <version> - Set global default');\n exit(1);\n return;\n }\n\n // Resolve partial version to exact installed version\n var versionsPath = path.join(storagePath, 'installed');\n var matches = findInstalledVersions(versionsPath, version);\n var resolvedVersion = matches.length > 0 ? matches[matches.length - 1] : null;\n\n // Display version (show resolution if different)\n if (resolvedVersion && resolvedVersion !== version && resolvedVersion !== `v${version}`) {\n console.log(`Version: ${version} \\u2192 ${resolvedVersion}`);\n } else {\n console.log(`Version: ${resolvedVersion || version}`);\n }\n console.log(`Source: ${getVersionSource(cwd)}`);\n\n if (resolvedVersion) {\n var actualVersionPath = path.join(versionsPath, resolvedVersion);\n var nodePath = path.join(actualVersionPath, 'bin', 'node');\n console.log(`Binary: ${nodePath}`);\n if (fs.existsSync(nodePath)) {\n console.log('Status: Installed');\n } else {\n console.log('Status: Directory exists but binary not found');\n }\n } else {\n console.log(`Status: Not installed (run: nvu install ${version})`);\n }\n\n exit(0);\n}\n\n/**\n * Resolve version from config files (mirrors nvu binary logic)\n */\nfunction resolveVersion(cwd: string): string | null {\n // Walk up directories looking for .nvurc or .nvmrc\n let dir = cwd;\n while (true) {\n // Check .nvurc first\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return fs.readFileSync(nvurcPath, 'utf8').trim();\n }\n\n // Check .nvmrc\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return fs.readFileSync(nvmrcPath, 'utf8').trim();\n }\n\n // Move to parent\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n // Check global default\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return fs.readFileSync(defaultPath, 'utf8').trim();\n }\n\n return null;\n}\n\n/**\n * Determine the source of the version (for display)\n */\nfunction getVersionSource(cwd: string): string {\n let dir = cwd;\n while (true) {\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return nvurcPath;\n }\n\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return nvmrcPath;\n }\n\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return `${defaultPath} (global default)`;\n }\n\n return 'none';\n}\n"],"names":["whichCmd","_args","cwd","process","version","resolveVersion","console","log","exit","versionsPath","path","join","storagePath","matches","findInstalledVersions","resolvedVersion","length","getVersionSource","actualVersionPath","nodePath","fs","existsSync","dir","nvurcPath","readFileSync","trim","nvmrcPath","parent","dirname","defaultPath"],"mappings":";;;;+BAMA;;;;;CAKC,GACD;;;eAAwBA;;;iEAZP;yDACF;2DACE;2BACW;uCACU;;;;;;AAQvB,SAASA,SAASC,KAAe;IAC9C,IAAMC,MAAMC,QAAQD,GAAG;IAEvB,yDAAyD;IACzD,IAAME,UAAUC,eAAeH;IAE/B,IAAI,CAACE,SAAS;QACZE,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZC,IAAAA,mBAAI,EAAC;QACL;IACF;IAEA,qDAAqD;IACrD,IAAIC,eAAeC,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAC1C,IAAIC,UAAUC,IAAAA,8CAAqB,EAACL,cAAcL;IAClD,IAAIW,kBAAkBF,QAAQG,MAAM,GAAG,IAAIH,OAAO,CAACA,QAAQG,MAAM,GAAG,EAAE,GAAG;IAEzE,iDAAiD;IACjD,IAAID,mBAAmBA,oBAAoBX,WAAWW,oBAAoB,AAAC,IAAW,OAARX,UAAW;QACvFE,QAAQC,GAAG,CAAC,AAAC,YAA6BQ,OAAlBX,SAAQ,OAA0B,OAAhBW;IAC5C,OAAO;QACLT,QAAQC,GAAG,CAAC,AAAC,YAAsC,OAA3BQ,mBAAmBX;IAC7C;IACAE,QAAQC,GAAG,CAAC,AAAC,WAAgC,OAAtBU,iBAAiBf;IAExC,IAAIa,iBAAiB;QACnB,IAAIG,oBAAoBR,aAAI,CAACC,IAAI,CAACF,cAAcM;QAChD,IAAII,WAAWT,aAAI,CAACC,IAAI,CAACO,mBAAmB,OAAO;QACnDZ,QAAQC,GAAG,CAAC,AAAC,WAAmB,OAATY;QACvB,IAAIC,WAAE,CAACC,UAAU,CAACF,WAAW;YAC3Bb,QAA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AACkB,OAAO,CAACN;QAC5B,IAAIK,WAAWL,KAAK;QACpBA,MAAMK;IACR;IAEA,IAAME,cAAcnB,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAC3C,IAAIQ,WAAE,CAACC,UAAU,CAACQ,cAAc;QAC9B,OAAO,AAAC,GAAc,OAAZA,aAAY;IACxB;IAEA,OAAO;AACT"}
@@ -1,7 +1,7 @@
1
1
  /**
2
- * nvu setup
2
+ * nvu setup [--shims]
3
3
  *
4
4
  * Install/reinstall nvu binaries to ~/.nvu/bin
5
- * This runs the same logic as the postinstall script.
5
+ * With --shims: create shims for existing global packages
6
6
  */
7
- export default function setupCmd(_args: string[]): void;
7
+ export default function setupCmd(args: string[]): void;
@@ -3,15 +3,16 @@ import exit from 'exit-compat';
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
5
  import url from 'url';
6
- import { mkdirpSync } from '../compat.js';
6
+ import { mkdirpSync, readdirWithTypes } from '../compat.js';
7
7
  import { storagePath } from '../constants.js';
8
+ import { findInstalledVersions } from '../lib/findInstalledVersions.js';
8
9
  var __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));
9
10
  /**
10
- * nvu setup
11
+ * nvu setup [--shims]
11
12
  *
12
13
  * Install/reinstall nvu binaries to ~/.nvu/bin
13
- * This runs the same logic as the postinstall script.
14
- */ export default function setupCmd(_args) {
14
+ * With --shims: create shims for existing global packages
15
+ */ export default function setupCmd(args) {
15
16
  var binDir = path.join(storagePath, 'bin');
16
17
  // Create directories
17
18
  if (!fs.existsSync(storagePath)) {
@@ -20,6 +21,18 @@ var __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : ur
20
21
  if (!fs.existsSync(binDir)) {
21
22
  mkdirpSync(binDir);
22
23
  }
24
+ // Check for --shims flag
25
+ var hasShimsFlag = false;
26
+ for(var i = 0; i < args.length; i++){
27
+ if (args[i] === '--shims') {
28
+ hasShimsFlag = true;
29
+ break;
30
+ }
31
+ }
32
+ if (hasShimsFlag) {
33
+ createShimsForGlobalPackages(binDir);
34
+ return;
35
+ }
23
36
  // Find the postinstall script relative to this module
24
37
  var postinstallPath = path.join(__dirname, '..', '..', '..', 'scripts', 'postinstall.cjs');
25
38
  if (fs.existsSync(postinstallPath)) {
@@ -37,3 +50,69 @@ var __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : ur
37
50
  exit(1);
38
51
  }
39
52
  }
53
+ /**
54
+ * Create shims for all global packages in the default Node version
55
+ */ function createShimsForGlobalPackages(binDir) {
56
+ // Read default version
57
+ var defaultPath = path.join(storagePath, 'default');
58
+ if (!fs.existsSync(defaultPath)) {
59
+ console.log('No default Node version set.');
60
+ console.log('Set one with: nvu default <version>');
61
+ exit(1);
62
+ return;
63
+ }
64
+ var defaultVersion = fs.readFileSync(defaultPath, 'utf8').trim();
65
+ var versionsDir = path.join(storagePath, 'installed');
66
+ // Resolve to exact version
67
+ var matches = findInstalledVersions(versionsDir, defaultVersion);
68
+ if (matches.length === 0) {
69
+ console.log(`Default version ${defaultVersion} is not installed.`);
70
+ exit(1);
71
+ return;
72
+ }
73
+ var resolvedVersion = matches[matches.length - 1];
74
+ var nodeBinDir = path.join(versionsDir, resolvedVersion, 'bin');
75
+ if (!fs.existsSync(nodeBinDir)) {
76
+ console.log(`No bin directory found for ${resolvedVersion}`);
77
+ exit(1);
78
+ return;
79
+ }
80
+ // Get the node shim to copy from
81
+ var nodeShim = path.join(binDir, 'node');
82
+ if (!fs.existsSync(nodeShim)) {
83
+ console.log('Node shim not found. Run: nvu setup');
84
+ exit(1);
85
+ return;
86
+ }
87
+ // Scan binaries in Node's bin directory
88
+ var entries = readdirWithTypes(nodeBinDir);
89
+ var created = 0;
90
+ var skipped = 0;
91
+ for(var i = 0; i < entries.length; i++){
92
+ var entry = entries[i];
93
+ var name = entry.name;
94
+ // Skip our routing shims (node/npm/npx) - don't overwrite them
95
+ if (name === 'node' || name === 'npm' || name === 'npx') {
96
+ continue;
97
+ }
98
+ var shimPath = path.join(binDir, name);
99
+ // Skip if shim already exists
100
+ if (fs.existsSync(shimPath)) {
101
+ skipped++;
102
+ continue;
103
+ }
104
+ // Copy the node shim
105
+ try {
106
+ var shimContent = fs.readFileSync(nodeShim);
107
+ fs.writeFileSync(shimPath, shimContent);
108
+ fs.chmodSync(shimPath, 493); // 0755
109
+ console.log(`Created shim: ${name}`);
110
+ created++;
111
+ } catch (err) {
112
+ console.error(`Failed to create shim for ${name}: ${err.message}`);
113
+ }
114
+ }
115
+ console.log('');
116
+ console.log(`Done. Created ${created} shims, skipped ${skipped} (already exist).`);
117
+ exit(0);
118
+ }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/setup.ts"],"sourcesContent":["import { execSync } from 'child_process';\nimport exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport url from 'url';\nimport { mkdirpSync } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\n\nvar __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n/**\n * nvu setup\n *\n * Install/reinstall nvu binaries to ~/.nvu/bin\n * This runs the same logic as the postinstall script.\n */\nexport default function setupCmd(_args: string[]): void {\n var binDir = path.join(storagePath, 'bin');\n\n // Create directories\n if (!fs.existsSync(storagePath)) {\n mkdirpSync(storagePath);\n }\n if (!fs.existsSync(binDir)) {\n mkdirpSync(binDir);\n }\n\n // Find the postinstall script relative to this module\n var postinstallPath = path.join(__dirname, '..', '..', '..', 'scripts', 'postinstall.cjs');\n\n if (fs.existsSync(postinstallPath)) {\n // Run the postinstall script\n try {\n execSync(`node \"${postinstallPath}\"`, { stdio: 'inherit' });\n } catch (_err) {\n // postinstall handles its own errors gracefully\n }\n } else {\n console.log('Setup script not found.');\n console.log('Try reinstalling: npm install -g node-version-use');\n exit(1);\n }\n}\n"],"names":["execSync","exit","fs","path","url","mkdirpSync","storagePath","__dirname","dirname","__filename","fileURLToPath","setupCmd","_args","binDir","join","existsSync","postinstallPath","stdio","_err","console","log"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,gBAAgB;AACzC,OAAOC,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,IAAIC,YAAYJ,KAAKK,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaL,IAAIM,aAAa,CAAC,YAAYN,GAAG;AAE/G;;;;;CAKC,GACD,eAAe,SAASO,SAASC,KAAe;IAC9C,IAAIC,SAASV,KAAKW,IAAI,CAACR,aAAa;IAEpC,qBAAqB;IACrB,IAAI,CAACJ,GAAGa,UAAU,CAACT,cAAc;QAC/BD,WAAWC;IACb;IACA,IAAI,CAACJ,GAAGa,UAAU,CAACF,SAAS;QAC1BR,WAAWQ;IACb;IAEA,sDAAsD;IACtD,IAAIG,kBAAkBb,KAAKW,IAAI,CAACP,WAAW,MAAM,MAAM,MAAM,WAAW;IAExE,IAAIL,GAAGa,UAAU,CAACC,kBAAkB;QAClC,6BAA6B;QAC7B,IAAI;YACFhB,SAAS,CAAC,MAAM,EAAEgB,gBAAgB,CAAC,CAAC,EAAE;gBAAEC,OAAO;YAAU;QAC3D,EAAE,OAAOC,MAAM;QACb,gDAAgD;QAClD;IACF,OAAO;QACLC,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZnB,KAAK;IACP;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/setup.ts"],"sourcesContent":["import { execSync } from 'child_process';\nimport exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport url from 'url';\nimport { mkdirpSync, readdirWithTypes } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\nimport { findInstalledVersions } from '../lib/findInstalledVersions.ts';\n\nvar __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n/**\n * nvu setup [--shims]\n *\n * Install/reinstall nvu binaries to ~/.nvu/bin\n * With --shims: create shims for existing global packages\n */\nexport default function setupCmd(args: string[]): void {\n var binDir = path.join(storagePath, 'bin');\n\n // Create directories\n if (!fs.existsSync(storagePath)) {\n mkdirpSync(storagePath);\n }\n if (!fs.existsSync(binDir)) {\n mkdirpSync(binDir);\n }\n\n // Check for --shims flag\n var hasShimsFlag = false;\n for (var i = 0; i < args.length; i++) {\n if (args[i] === '--shims') {\n hasShimsFlag = true;\n break;\n }\n }\n\n if (hasShimsFlag) {\n createShimsForGlobalPackages(binDir);\n return;\n }\n\n // Find the postinstall script relative to this module\n var postinstallPath = path.join(__dirname, '..', '..', '..', 'scripts', 'postinstall.cjs');\n\n if (fs.existsSync(postinstallPath)) {\n // Run the postinstall script\n try {\n execSync(`node \"${postinstallPath}\"`, { stdio: 'inherit' });\n } catch (_err) {\n // postinstall handles its own errors gracefully\n }\n } else {\n console.log('Setup script not found.');\n console.log('Try reinstalling: npm install -g node-version-use');\n exit(1);\n }\n}\n\n/**\n * Create shims for all global packages in the default Node version\n */\nfunction createShimsForGlobalPackages(binDir: string): void {\n // Read default version\n var defaultPath = path.join(storagePath, 'default');\n if (!fs.existsSync(defaultPath)) {\n console.log('No default Node version set.');\n console.log('Set one with: nvu default <version>');\n exit(1);\n return;\n }\n\n var defaultVersion = fs.readFileSync(defaultPath, 'utf8').trim();\n var versionsDir = path.join(storagePath, 'installed');\n\n // Resolve to exact version\n var matches = findInstalledVersions(versionsDir, defaultVersion);\n if (matches.length === 0) {\n console.log(`Default version ${defaultVersion} is not installed.`);\n exit(1);\n return;\n }\n\n var resolvedVersion = matches[matches.length - 1];\n var nodeBinDir = path.join(versionsDir, resolvedVersion, 'bin');\n\n if (!fs.existsSync(nodeBinDir)) {\n console.log(`No bin directory found for ${resolvedVersion}`);\n exit(1);\n return;\n }\n\n // Get the node shim to copy from\n var nodeShim = path.join(binDir, 'node');\n if (!fs.existsSync(nodeShim)) {\n console.log('Node shim not found. Run: nvu setup');\n exit(1);\n return;\n }\n\n // Scan binaries in Node's bin directory\n var entries = readdirWithTypes(nodeBinDir);\n var created = 0;\n var skipped = 0;\n\n for (var i = 0; i < entries.length; i++) {\n var entry = entries[i];\n var name = entry.name;\n\n // Skip our routing shims (node/npm/npx) - don't overwrite them\n if (name === 'node' || name === 'npm' || name === 'npx') {\n continue;\n }\n\n var shimPath = path.join(binDir, name);\n\n // Skip if shim already exists\n if (fs.existsSync(shimPath)) {\n skipped++;\n continue;\n }\n\n // Copy the node shim\n try {\n var shimContent = fs.readFileSync(nodeShim);\n fs.writeFileSync(shimPath, shimContent);\n fs.chmodSync(shimPath, 493); // 0755\n console.log(`Created shim: ${name}`);\n created++;\n } catch (err) {\n console.error(`Failed to create shim for ${name}: ${(err as Error).message}`);\n }\n }\n\n console.log('');\n console.log(`Done. Created ${created} shims, skipped ${skipped} (already exist).`);\n exit(0);\n}\n"],"names":["execSync","exit","fs","path","url","mkdirpSync","readdirWithTypes","storagePath","findInstalledVersions","__dirname","dirname","__filename","fileURLToPath","setupCmd","args","binDir","join","existsSync","hasShimsFlag","i","length","createShimsForGlobalPackages","postinstallPath","stdio","_err","console","log","defaultPath","defaultVersion","readFileSync","trim","versionsDir","matches","resolvedVersion","nodeBinDir","nodeShim","entries","created","skipped","entry","name","shimPath","shimContent","writeFileSync","chmodSync","err","error","message"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,gBAAgB;AACzC,OAAOC,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,SAASC,UAAU,EAAEC,gBAAgB,QAAQ,eAAe;AAC5D,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,qBAAqB,QAAQ,kCAAkC;AAExE,IAAIC,YAAYN,KAAKO,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAa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QqB,KAAK,CAAC,CAAC,0BAA0B,EAAEN,KAAK,EAAE,EAAE,AAACK,IAAcE,OAAO,EAAE;QAC9E;IACF;IAEAtB,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC,CAAC,cAAc,EAAEW,QAAQ,gBAAgB,EAAEC,QAAQ,iBAAiB,CAAC;IACjFrC,KAAK;AACP"}
@@ -2,6 +2,7 @@ import exit from 'exit-compat';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
4
  import { storagePath } from '../constants.js';
5
+ import { findInstalledVersions } from '../lib/findInstalledVersions.js';
5
6
  /**
6
7
  * nvu which
7
8
  *
@@ -20,23 +21,20 @@ import { storagePath } from '../constants.js';
20
21
  exit(1);
21
22
  return;
22
23
  }
23
- // Check if the version is installed
24
- const versionsPath = path.join(storagePath, 'installed');
25
- const versionPath = path.join(versionsPath, version);
26
- const versionPathWithV = path.join(versionsPath, `v${version}`);
27
- const versionPathWithoutV = path.join(versionsPath, version.replace(/^v/, ''));
28
- let actualVersionPath = '';
29
- if (fs.existsSync(versionPath)) {
30
- actualVersionPath = versionPath;
31
- } else if (fs.existsSync(versionPathWithV)) {
32
- actualVersionPath = versionPathWithV;
33
- } else if (fs.existsSync(versionPathWithoutV)) {
34
- actualVersionPath = versionPathWithoutV;
24
+ // Resolve partial version to exact installed version
25
+ var versionsPath = path.join(storagePath, 'installed');
26
+ var matches = findInstalledVersions(versionsPath, version);
27
+ var resolvedVersion = matches.length > 0 ? matches[matches.length - 1] : null;
28
+ // Display version (show resolution if different)
29
+ if (resolvedVersion && resolvedVersion !== version && resolvedVersion !== `v${version}`) {
30
+ console.log(`Version: ${version} \u2192 ${resolvedVersion}`);
31
+ } else {
32
+ console.log(`Version: ${resolvedVersion || version}`);
35
33
  }
36
- console.log(`Version: ${version}`);
37
34
  console.log(`Source: ${getVersionSource(cwd)}`);
38
- if (actualVersionPath) {
39
- const nodePath = path.join(actualVersionPath, 'bin', 'node');
35
+ if (resolvedVersion) {
36
+ var actualVersionPath = path.join(versionsPath, resolvedVersion);
37
+ var nodePath = path.join(actualVersionPath, 'bin', 'node');
40
38
  console.log(`Binary: ${nodePath}`);
41
39
  if (fs.existsSync(nodePath)) {
42
40
  console.log('Status: Installed');
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/which.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu which\n *\n * Show which Node binary would be used based on current directory.\n * This simulates what the nvu binary would do.\n */\nexport default function whichCmd(_args: string[]): void {\n const cwd = process.cwd();\n\n // Resolve version using the same logic as the nvu binary\n const version = resolveVersion(cwd);\n\n if (!version) {\n console.log('No Node version configured for this directory.');\n console.log('');\n console.log('To configure a version:');\n console.log(' nvu local <version> - Set version for this project');\n console.log(' nvu default <version> - Set global default');\n exit(1);\n return;\n }\n\n // Check if the version is installed\n const versionsPath = path.join(storagePath, 'installed');\n const versionPath = path.join(versionsPath, version);\n const versionPathWithV = path.join(versionsPath, `v${version}`);\n const versionPathWithoutV = path.join(versionsPath, version.replace(/^v/, ''));\n\n let actualVersionPath = '';\n if (fs.existsSync(versionPath)) {\n actualVersionPath = versionPath;\n } else if (fs.existsSync(versionPathWithV)) {\n actualVersionPath = versionPathWithV;\n } else if (fs.existsSync(versionPathWithoutV)) {\n actualVersionPath = versionPathWithoutV;\n }\n\n console.log(`Version: ${version}`);\n console.log(`Source: ${getVersionSource(cwd)}`);\n\n if (actualVersionPath) {\n const nodePath = path.join(actualVersionPath, 'bin', 'node');\n console.log(`Binary: ${nodePath}`);\n if (fs.existsSync(nodePath)) {\n console.log('Status: Installed');\n } else {\n console.log('Status: Directory exists but binary not found');\n }\n } else {\n console.log(`Status: Not installed (run: nvu install ${version})`);\n }\n\n exit(0);\n}\n\n/**\n * Resolve version from config files (mirrors nvu binary logic)\n */\nfunction resolveVersion(cwd: string): string | null {\n // Walk up directories looking for .nvurc or .nvmrc\n let dir = cwd;\n while (true) {\n // Check .nvurc first\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return fs.readFileSync(nvurcPath, 'utf8').trim();\n }\n\n // Check .nvmrc\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return fs.readFileSync(nvmrcPath, 'utf8').trim();\n }\n\n // Move to parent\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n // Check global default\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return fs.readFileSync(defaultPath, 'utf8').trim();\n }\n\n return null;\n}\n\n/**\n * Determine the source of the version (for display)\n */\nfunction getVersionSource(cwd: string): string {\n let dir = cwd;\n while (true) {\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return nvurcPath;\n }\n\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return nvmrcPath;\n }\n\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return `${defaultPath} (global default)`;\n }\n\n return 'none';\n}\n"],"names":["exit","fs","path","storagePath","whichCmd","_args","cwd","process","version","resolveVersion","console","log","versionsPath","join","versionPath","versionPathWithV","versionPathWithoutV","replace","actualVersionPath","existsSync","getVersionSource","nodePath","dir","nvurcPath","readFileSync","trim","nvmrcPath","parent","dirname","defaultPath"],"mappings":"AAAA,OAAOA,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,WAAW,QAAQ,kBAAkB;AAE9C;;;;;CAKC,GACD,eAAe,SAASC,SAASC,KAAe;IAC9C,MAAMC,MAAMC,QAAQD,GAAG;IAEvB,yDAAyD;IACzD,MAAME,UAAUC,eAAeH;IAE/B,IAAI,CAACE,SAAS;QACZE,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AK;QACjC,IAAIrB,GAAGkB,UAAU,CAACI,YAAY;YAC5B,OAAOtB,GAAGuB,YAAY,CAACD,WAAW,QAAQE,IAAI;QAChD;QAEA,eAAe;QACf,MAAMC,YAAYxB,KAAKW,IAAI,CAACS,KAAK;QACjC,IAAIrB,GAAGkB,UAAU,CAACO,YAAY;YAC5B,OAAOzB,GAAGuB,YAAY,CAACE,WAAW,QAAQD,IAAI;QAChD;QAEA,iBAAiB;QACjB,MAAME,SAASzB,KAAK0B,OAAO,CAACN;QAC5B,IAAIK,WAAWL,KAAK;QACpBA,MAAMK;IACR;IAEA,uBAAuB;IACvB,MAAME,cAAc3B,KAAKW,IAAI,CAACV,aAAa;IAC3C,IAAIF,GAAGkB,UAAU,CAACU,cAAc;QAC9B,OAAO5B,GAAGuB,YAAY,CAACK,aAAa,QAAQJ,IAAI;IAClD;IAEA,OAAO;AACT;AAEA;;CAEC,GACD,SAASL,iBAAiBd,GAAW;IACnC,IAAIgB,MAAMhB;IACV,MAAO,KAAM;QACX,MAAMiB,YAAYrB,KAAKW,IAAI,CAACS,KAAK;QACjC,IAAIrB,GAAGkB,UAAU,CAACI,YAAY;YAC5B,OAAOA;QACT;QAEA,MAAMG,YAAYxB,KAAKW,IAAI,CAACS,KAAK;QACjC,IAAIrB,GAAGkB,UAAU,CAACO,YAAY;YAC5B,OAAOA;QACT;QAEA,MAAMC,SAASzB,KAAK0B,OAAO,CAACN;QAC5B,IAAIK,WAAWL,KAAK;QACpBA,MAAMK;IACR;IAEA,MAAME,cAAc3B,KAAKW,IAAI,CAACV,aAAa;IAC3C,IAAIF,GAAGkB,UAAU,CAACU,cAAc;QAC9B,OAAO,GAAGA,YAAY,iBAAiB,CAAC;IAC1C;IAEA,OAAO;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/which.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\nimport { findInstalledVersions } from '../lib/findInstalledVersions.ts';\n\n/**\n * nvu which\n *\n * Show which Node binary would be used based on current directory.\n * This simulates what the nvu binary would do.\n */\nexport default function whichCmd(_args: string[]): void {\n const cwd = process.cwd();\n\n // Resolve version using the same logic as the nvu binary\n const version = resolveVersion(cwd);\n\n if (!version) {\n console.log('No Node version configured for this directory.');\n console.log('');\n console.log('To configure a version:');\n console.log(' nvu local <version> - Set version for this project');\n console.log(' nvu default <version> - Set global default');\n exit(1);\n return;\n }\n\n // Resolve partial version to exact installed version\n var versionsPath = path.join(storagePath, 'installed');\n var matches = findInstalledVersions(versionsPath, version);\n var resolvedVersion = matches.length > 0 ? matches[matches.length - 1] : null;\n\n // Display version (show resolution if different)\n if (resolvedVersion && resolvedVersion !== version && resolvedVersion !== `v${version}`) {\n console.log(`Version: ${version} \\u2192 ${resolvedVersion}`);\n } else {\n console.log(`Version: ${resolvedVersion || version}`);\n }\n console.log(`Source: ${getVersionSource(cwd)}`);\n\n if (resolvedVersion) {\n var actualVersionPath = path.join(versionsPath, resolvedVersion);\n var nodePath = path.join(actualVersionPath, 'bin', 'node');\n console.log(`Binary: ${nodePath}`);\n if (fs.existsSync(nodePath)) {\n console.log('Status: Installed');\n } else {\n console.log('Status: Directory exists but binary not found');\n }\n } else {\n console.log(`Status: Not installed (run: nvu install ${version})`);\n }\n\n exit(0);\n}\n\n/**\n * Resolve version from config files (mirrors nvu binary logic)\n */\nfunction resolveVersion(cwd: string): string | null {\n // Walk up directories looking for .nvurc or .nvmrc\n let dir = cwd;\n while (true) {\n // Check .nvurc first\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return fs.readFileSync(nvurcPath, 'utf8').trim();\n }\n\n // Check .nvmrc\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return fs.readFileSync(nvmrcPath, 'utf8').trim();\n }\n\n // Move to parent\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n // Check global default\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return fs.readFileSync(defaultPath, 'utf8').trim();\n }\n\n return null;\n}\n\n/**\n * Determine the source of the version (for display)\n */\nfunction getVersionSource(cwd: string): string {\n let dir = cwd;\n while (true) {\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return nvurcPath;\n }\n\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return nvmrcPath;\n }\n\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return `${defaultPath} (global default)`;\n }\n\n return 'none';\n}\n"],"names":["exit","fs","path","storagePath","findInstalledVersions","whichCmd","_args","cwd","process","version","resolveVersion","console","log","versionsPath","join","matches","resolvedVersion","length","getVersionSource","actualVersionPath","nodePath","existsSync","dir","nvurcPath","readFileSync","trim","nvmrcPath","parent","dirname","defaultPath"],"mappings":"AAAA,OAAOA,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,qBAAqB,QAAQ,kCAAkC;AAExE;;;;;CAKC,GACD,eAAe,SAASC,SAASC,KAAe;IAC9C,MAAMC,MAAMC,QAAQD,GAAG;IAEvB,yDAAyD;IACzD,MAAME,UAAUC,eAAeH;IAE/B,IAAI,CAACE,SAAS;QACZE,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZZ,KAAK;QACL;IACF;IAEA,qDAAqD;IACrD,IAAIa,eAAeX,KAAKY,IAAI,CAACX,aAAa;IAC1C,IAAIY,UAAUX,sBAAsBS,cAAcJ;IAClD,IAAIO,kBAAkBD,QAAQE,MAAM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5B,IAAIK,WAAWL,KAAK;QACpBA,MAAMK;IACR;IAEA,uBAAuB;IACvB,MAAME,cAAc3B,KAAKY,IAAI,CAACX,aAAa;IAC3C,IAAIF,GAAGoB,UAAU,CAACQ,cAAc;QAC9B,OAAO5B,GAAGuB,YAAY,CAACK,aAAa,QAAQJ,IAAI;IAClD;IAEA,OAAO;AACT;AAEA;;CAEC,GACD,SAASP,iBAAiBX,GAAW;IACnC,IAAIe,MAAMf;IACV,MAAO,KAAM;QACX,MAAMgB,YAAYrB,KAAKY,IAAI,CAACQ,KAAK;QACjC,IAAIrB,GAAGoB,UAAU,CAACE,YAAY;YAC5B,OAAOA;QACT;QAEA,MAAMG,YAAYxB,KAAKY,IAAI,CAACQ,KAAK;QACjC,IAAIrB,GAAGoB,UAAU,CAACK,YAAY;YAC5B,OAAOA;QACT;QAEA,MAAMC,SAASzB,KAAK0B,OAAO,CAACN;QAC5B,IAAIK,WAAWL,KAAK;QACpBA,MAAMK;IACR;IAEA,MAAME,cAAc3B,KAAKY,IAAI,CAACX,aAAa;IAC3C,IAAIF,GAAGoB,UAAU,CAACQ,cAAc;QAC9B,OAAO,GAAGA,YAAY,iBAAiB,CAAC;IAC1C;IAEA,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-version-use",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "Cross-platform solution for using multiple versions of node. Useful for compatibility testing",
5
5
  "keywords": [
6
6
  "node",
@@ -258,7 +258,7 @@ function extractAndInstall(archivePath, destDir, binaryName, callback) {
258
258
  }
259
259
 
260
260
  // Binary names to install
261
- var binaries = ['node', 'npm', 'npx'];
261
+ var binaries = ['node', 'npm', 'npx', 'corepack'];
262
262
  var timestamp = Date.now();
263
263
  var _pending = binaries.length;
264
264
  var installError = null;