node-version-use 2.1.2 → 2.1.4

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"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Postinstall script for node-version-use
3
+ *
4
+ * Downloads the platform-specific binary and installs it to ~/.nvu/bin/
5
+ * This enables transparent Node version switching.
6
+ *
7
+ * Uses safe atomic download pattern:
8
+ * 1. Download to temp file
9
+ * 2. Extract to temp directory
10
+ * 3. Atomic rename to final location
11
+ */
12
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Postinstall script for node-version-use
3
+ *
4
+ * Downloads the platform-specific binary and installs it to ~/.nvu/bin/
5
+ * This enables transparent Node version switching.
6
+ *
7
+ * Uses safe atomic download pattern:
8
+ * 1. Download to temp file
9
+ * 2. Extract to temp directory
10
+ * 3. Atomic rename to final location
11
+ */
12
+ export {};