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.
- package/dist/cjs/commands/setup.d.cts +3 -3
- package/dist/cjs/commands/setup.d.ts +3 -3
- package/dist/cjs/commands/setup.js +82 -3
- package/dist/cjs/commands/setup.js.map +1 -1
- package/dist/cjs/commands/which.js +11 -13
- package/dist/cjs/commands/which.js.map +1 -1
- package/dist/esm/commands/setup.d.ts +3 -3
- package/dist/esm/commands/setup.js +83 -4
- package/dist/esm/commands/setup.js.map +1 -1
- package/dist/esm/commands/which.js +13 -15
- package/dist/esm/commands/which.js.map +1 -1
- package/package.json +1 -1
- package/scripts/postinstall.cjs +1 -1
|
@@ -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
|
-
*
|
|
5
|
+
* With --shims: create shims for existing global packages
|
|
6
6
|
*/
|
|
7
|
-
export default function setupCmd(
|
|
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
|
-
*
|
|
5
|
+
* With --shims: create shims for existing global packages
|
|
6
6
|
*/
|
|
7
|
-
export default function setupCmd(
|
|
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
|
-
*
|
|
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(
|
|
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 *
|
|
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,QAAQC,GAAG,CAAC;QACZC,IAAAA,mBAAI,EAAC;IACP;AACF;AAEA;;CAEC,GACD,SAASP,6BAA6BT,MAAc;IAClD,uBAAuB;IACvB,IAAIiB,cAAcvB,aAAI,CAACO,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AS,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
|
-
//
|
|
39
|
+
// Resolve partial version to exact installed version
|
|
39
40
|
var versionsPath = _path.default.join(_constantsts.storagePath, 'installed');
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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 (
|
|
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 //
|
|
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,UA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AQD,IAAI;QAChD;QAEA,iBAAiB;QACjB,IAAME,SAASjB,aAAI,CAACkB,OAAO,CAACN;QAC5B,IAAIK,WAAWL,KAAK;QACpBA,MAAMK;IACR;IAEA,uBAAuB;IACvB,IAAME,cAAcnB,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAC3C,IAAIQ,WAAE,CAACC,UAAU,CAACQ,cAAc;QAC9B,OAAOT,WAAE,CAACI,YAAY,CAACK,aAAa,QAAQJ,IAAI;IAClD;IAEA,OAAO;AACT;AAEA;;CAEC,GACD,SAASR,iBAAiBf,GAAW;IACnC,IAAIoB,MAAMpB;IACV,MAAO,KAAM;QACX,IAAMqB,YAAYb,aAAI,CAACC,IAAI,CAACW,KAAK;QACjC,IAAIF,WAAE,CAACC,UAAU,CAACE,YAAY;YAC5B,OAAOA;QACT;QAEA,IAAMG,YAAYhB,aAAI,CAACC,IAAI,CAACW,KAAK;QACjC,IAAIF,WAAE,CAACC,UAAU,CAACK,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,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
|
-
*
|
|
5
|
+
* With --shims: create shims for existing global packages
|
|
6
6
|
*/
|
|
7
|
-
export default function setupCmd(
|
|
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
|
-
*
|
|
14
|
-
*/ export default function setupCmd(
|
|
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 *
|
|
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,eAA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AK;YACZpB,QAAQqB,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
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 (
|
|
39
|
-
|
|
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 //
|
|
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,GAAG,IAAIF,OAAO,CAACA,QAAQE,MAAM,GAAG,EAAE,GAAG;IAEzE,iDAAiD;IACjD,IAAID,mBAAmBA,oBAAoBP,WAAWO,oBAAoB,CAAC,CAAC,EAAEP,SAAS,EAAE;QACvFE,QAAQC,GAAG,CAAC,CAAC,SAAS,EAAEH,QAAQ,QAAQ,EAAEO,iBAAiB;IAC7D,OAAO;QACLL,QAAQC,GAAG,CAAC,CAAC,SAAS,EAAEI,mBAAmBP,SAAS;IACtD;IACAE,QAAQC,GAAG,CAAC,CAAC,QAAQ,EAAEM,iBAAiBX,MAAM;IAE9C,IAAIS,iBAAiB;QACnB,I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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
package/scripts/postinstall.cjs
CHANGED
|
@@ -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;
|