node-version-use 1.9.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -23
- package/dist/cjs/cli.js +25 -6
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/commands/default.d.cts +7 -0
- package/dist/cjs/commands/default.d.ts +7 -0
- package/dist/cjs/commands/default.js +57 -0
- package/dist/cjs/commands/default.js.map +1 -0
- package/dist/cjs/commands/index.d.cts +3 -0
- package/dist/cjs/commands/index.d.ts +3 -0
- package/dist/cjs/commands/index.js +54 -0
- package/dist/cjs/commands/index.js.map +1 -0
- package/dist/cjs/commands/install.d.cts +6 -0
- package/dist/cjs/commands/install.d.ts +6 -0
- package/dist/cjs/commands/install.js +69 -0
- package/dist/cjs/commands/install.js.map +1 -0
- package/dist/cjs/commands/list.d.cts +6 -0
- package/dist/cjs/commands/list.d.ts +6 -0
- package/dist/cjs/commands/list.js +93 -0
- package/dist/cjs/commands/list.js.map +1 -0
- package/dist/cjs/commands/local.d.cts +7 -0
- package/dist/cjs/commands/local.d.ts +7 -0
- package/dist/cjs/commands/local.js +69 -0
- package/dist/cjs/commands/local.js.map +1 -0
- package/dist/cjs/commands/setup.d.cts +7 -0
- package/dist/cjs/commands/setup.d.ts +7 -0
- package/dist/cjs/commands/setup.js +55 -0
- package/dist/cjs/commands/setup.js.map +1 -0
- package/dist/cjs/commands/teardown.d.cts +6 -0
- package/dist/cjs/commands/teardown.d.ts +6 -0
- package/dist/cjs/commands/teardown.js +66 -0
- package/dist/cjs/commands/teardown.js.map +1 -0
- package/dist/cjs/commands/uninstall.d.cts +6 -0
- package/dist/cjs/commands/uninstall.d.ts +6 -0
- package/dist/cjs/commands/uninstall.js +148 -0
- package/dist/cjs/commands/uninstall.js.map +1 -0
- package/dist/cjs/commands/which.d.cts +7 -0
- package/dist/cjs/commands/which.d.ts +7 -0
- package/dist/cjs/commands/which.js +117 -0
- package/dist/cjs/commands/which.js.map +1 -0
- package/dist/cjs/compat.d.cts +17 -0
- package/dist/cjs/compat.d.ts +17 -0
- package/dist/cjs/compat.js +47 -1
- package/dist/cjs/compat.js.map +1 -1
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/types.d.cts +1 -0
- package/dist/cjs/types.d.ts +1 -0
- package/dist/cjs/worker.js +2 -2
- package/dist/cjs/worker.js.map +1 -1
- package/dist/esm/cli.js +23 -4
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/commands/default.d.ts +7 -0
- package/dist/esm/commands/default.js +41 -0
- package/dist/esm/commands/default.js.map +1 -0
- package/dist/esm/commands/index.d.ts +3 -0
- package/dist/esm/commands/index.js +27 -0
- package/dist/esm/commands/index.js.map +1 -0
- package/dist/esm/commands/install.d.ts +6 -0
- package/dist/esm/commands/install.js +53 -0
- package/dist/esm/commands/install.js.map +1 -0
- package/dist/esm/commands/list.d.ts +6 -0
- package/dist/esm/commands/list.js +52 -0
- package/dist/esm/commands/list.js.map +1 -0
- package/dist/esm/commands/local.d.ts +7 -0
- package/dist/esm/commands/local.js +51 -0
- package/dist/esm/commands/local.js.map +1 -0
- package/dist/esm/commands/setup.d.ts +7 -0
- package/dist/esm/commands/setup.js +39 -0
- package/dist/esm/commands/setup.js.map +1 -0
- package/dist/esm/commands/teardown.d.ts +6 -0
- package/dist/esm/commands/teardown.js +33 -0
- package/dist/esm/commands/teardown.js.map +1 -0
- package/dist/esm/commands/uninstall.d.ts +6 -0
- package/dist/esm/commands/uninstall.js +132 -0
- package/dist/esm/commands/uninstall.js.map +1 -0
- package/dist/esm/commands/which.d.ts +7 -0
- package/dist/esm/commands/which.js +101 -0
- package/dist/esm/commands/which.js.map +1 -0
- package/dist/esm/compat.d.ts +17 -0
- package/dist/esm/compat.js +39 -2
- package/dist/esm/compat.js.map +1 -1
- package/dist/esm/constants.js +2 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/types.d.ts +1 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/worker.js +2 -2
- package/dist/esm/worker.js.map +1 -1
- package/package.json +11 -4
- package/scripts/postinstall.cjs +273 -0
- package/shim/Makefile +58 -0
- package/shim/go.mod +3 -0
- package/shim/main.go +302 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import exit from 'exit';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* nvu local [version] [--nvurc]
|
|
6
|
+
*
|
|
7
|
+
* Write .nvmrc (or .nvurc) to the current directory.
|
|
8
|
+
* This pins the Node version for the current project.
|
|
9
|
+
*/ export default function localCmd(args) {
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
// Check for --nvurc flag
|
|
12
|
+
const useNvurc = args.includes('--nvurc');
|
|
13
|
+
const filteredArgs = args.filter((arg)=>arg !== '--nvurc');
|
|
14
|
+
const fileName = useNvurc ? '.nvurc' : '.nvmrc';
|
|
15
|
+
const filePath = path.join(cwd, fileName);
|
|
16
|
+
// If no version provided, display current local version
|
|
17
|
+
if (filteredArgs.length === 0) {
|
|
18
|
+
// Check for existing version files
|
|
19
|
+
const nvurcPath = path.join(cwd, '.nvurc');
|
|
20
|
+
const nvmrcPath = path.join(cwd, '.nvmrc');
|
|
21
|
+
if (fs.existsSync(nvurcPath)) {
|
|
22
|
+
const version = fs.readFileSync(nvurcPath, 'utf8').trim();
|
|
23
|
+
console.log(`Current local version (.nvurc): ${version}`);
|
|
24
|
+
exit(0);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (fs.existsSync(nvmrcPath)) {
|
|
28
|
+
const version = fs.readFileSync(nvmrcPath, 'utf8').trim();
|
|
29
|
+
console.log(`Current local version (.nvmrc): ${version}`);
|
|
30
|
+
exit(0);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
console.log('No local version set in this directory.');
|
|
34
|
+
console.log('Usage: nvu local <version>');
|
|
35
|
+
console.log(' nvu local <version> --nvurc (use .nvurc instead of .nvmrc)');
|
|
36
|
+
exit(0);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const version = filteredArgs[0].trim();
|
|
40
|
+
// Validate version format (basic check)
|
|
41
|
+
if (!version || version.startsWith('-')) {
|
|
42
|
+
console.log('Usage: nvu local <version>');
|
|
43
|
+
console.log('Example: nvu local 20');
|
|
44
|
+
exit(1);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// Write the version file
|
|
48
|
+
fs.writeFileSync(filePath, `${version}\n`, 'utf8');
|
|
49
|
+
console.log(`Created ${fileName} with version: ${version}`);
|
|
50
|
+
exit(0);
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/local.ts"],"sourcesContent":["import exit from 'exit';\nimport fs from 'fs';\nimport path from 'path';\n\n/**\n * nvu local [version] [--nvurc]\n *\n * Write .nvmrc (or .nvurc) to the current directory.\n * This pins the Node version for the current project.\n */\nexport default function localCmd(args: string[]): void {\n const cwd = process.cwd();\n\n // Check for --nvurc flag\n const useNvurc = args.includes('--nvurc');\n const filteredArgs = args.filter((arg) => arg !== '--nvurc');\n\n const fileName = useNvurc ? '.nvurc' : '.nvmrc';\n const filePath = path.join(cwd, fileName);\n\n // If no version provided, display current local version\n if (filteredArgs.length === 0) {\n // Check for existing version files\n const nvurcPath = path.join(cwd, '.nvurc');\n const nvmrcPath = path.join(cwd, '.nvmrc');\n\n if (fs.existsSync(nvurcPath)) {\n const version = fs.readFileSync(nvurcPath, 'utf8').trim();\n console.log(`Current local version (.nvurc): ${version}`);\n exit(0);\n return;\n }\n if (fs.existsSync(nvmrcPath)) {\n const version = fs.readFileSync(nvmrcPath, 'utf8').trim();\n console.log(`Current local version (.nvmrc): ${version}`);\n exit(0);\n return;\n }\n\n console.log('No local version set in this directory.');\n console.log('Usage: nvu local <version>');\n console.log(' nvu local <version> --nvurc (use .nvurc instead of .nvmrc)');\n exit(0);\n return;\n }\n\n const version = filteredArgs[0].trim();\n\n // Validate version format (basic check)\n if (!version || version.startsWith('-')) {\n console.log('Usage: nvu local <version>');\n console.log('Example: nvu local 20');\n exit(1);\n return;\n }\n\n // Write the version file\n fs.writeFileSync(filePath, `${version}\\n`, 'utf8');\n console.log(`Created ${fileName} with version: ${version}`);\n exit(0);\n}\n"],"names":["exit","fs","path","localCmd","args","cwd","process","useNvurc","includes","filteredArgs","filter","arg","fileName","filePath","join","length","nvurcPath","nvmrcPath","existsSync","version","readFileSync","trim","console","log","startsWith","writeFileSync"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AAExB;;;;;CAKC,GACD,eAAe,SAASC,SAASC,IAAc;IAC7C,MAAMC,MAAMC,QAAQD,GAAG;IAEvB,yBAAyB;IACzB,MAAME,WAAWH,KAAKI,QAAQ,CAAC;IAC/B,MAAMC,eAAeL,KAAKM,MAAM,CAAC,CAACC,MAAQA,QAAQ;IAElD,MAAMC,WAAWL,WAAW,WAAW;IACvC,MAAMM,WAAWX,KAAKY,IAAI,CAACT,KAAKO;IAEhC,wDAAwD;IACxD,IAAIH,aAAaM,MAAM,KAAK,GAAG;QAC7B,mCAAmC;QACnC,MAAMC,YAAYd,KAAKY,IAAI,CAACT,KAAK;QACjC,MAAMY,YAAYf,KAAKY,IAAI,CAACT,KAAK;QAEjC,IAAIJ,GAAGiB,UAAU,CAACF,YAAY;YAC5B,MAAMG,UAAUlB,GAAGmB,YAAY,CAACJ,WAAW,QAAQK,IAAI;YACvDC,QAAQC,GAAG,CAAC,CAAC,gCAAgC,EAAEJ,SAAS;YACxDnB,KAAK;YACL;QACF;QACA,IAAIC,GAAGiB,UAAU,CAACD,YAAY;YAC5B,MAAME,UAAUlB,GAAGmB,YAAY,CAACH,WAAW,QAAQI,IAAI;YACvDC,QAAQC,GAAG,CAAC,CAAC,gCAAgC,EAAEJ,SAAS;YACxDnB,KAAK;YACL;QACF;QAEAsB,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZvB,KAAK;QACL;IACF;IAEA,MAAMmB,UAAUV,YAAY,CAAC,EAAE,CAACY,IAAI;IAEpC,wCAAwC;IACxC,IAAI,CAACF,WAAWA,QAAQK,UAAU,CAAC,MAAM;QACvCF,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZvB,KAAK;QACL;IACF;IAEA,yBAAyB;IACzBC,GAAGwB,aAAa,CAACZ,UAAU,GAAGM,QAAQ,EAAE,CAAC,EAAE;IAC3CG,QAAQC,GAAG,CAAC,CAAC,QAAQ,EAAEX,SAAS,eAAe,EAAEO,SAAS;IAC1DnB,KAAK;AACP"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import exit from 'exit';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import url from 'url';
|
|
6
|
+
import { mkdirpSync } from '../compat.js';
|
|
7
|
+
import { storagePath } from '../constants.js';
|
|
8
|
+
var __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));
|
|
9
|
+
/**
|
|
10
|
+
* nvu setup
|
|
11
|
+
*
|
|
12
|
+
* Install/reinstall nvu shims to ~/.nvu/bin
|
|
13
|
+
* This runs the same logic as the postinstall script.
|
|
14
|
+
*/ export default function setupCmd(_args) {
|
|
15
|
+
var binDir = path.join(storagePath, 'bin');
|
|
16
|
+
// Create directories
|
|
17
|
+
if (!fs.existsSync(storagePath)) {
|
|
18
|
+
mkdirpSync(storagePath);
|
|
19
|
+
}
|
|
20
|
+
if (!fs.existsSync(binDir)) {
|
|
21
|
+
mkdirpSync(binDir);
|
|
22
|
+
}
|
|
23
|
+
// Find the postinstall script relative to this module
|
|
24
|
+
var postinstallPath = path.join(__dirname, '..', '..', '..', 'scripts', 'postinstall.cjs');
|
|
25
|
+
if (fs.existsSync(postinstallPath)) {
|
|
26
|
+
// Run the postinstall script
|
|
27
|
+
try {
|
|
28
|
+
execSync(`node "${postinstallPath}"`, {
|
|
29
|
+
stdio: 'inherit'
|
|
30
|
+
});
|
|
31
|
+
} catch (_err) {
|
|
32
|
+
// postinstall handles its own errors gracefully
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
console.log('Setup script not found.');
|
|
36
|
+
console.log('Try reinstalling: npm install -g node-version-use');
|
|
37
|
+
exit(1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +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';\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 shims 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,OAAO;AACxB,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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import exit from 'exit';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { storagePath } from '../constants.js';
|
|
5
|
+
/**
|
|
6
|
+
* nvu teardown
|
|
7
|
+
*
|
|
8
|
+
* Remove nvu shims from ~/.nvu/bin
|
|
9
|
+
*/ export default function teardownCmd(_args) {
|
|
10
|
+
const binDir = path.join(storagePath, 'bin');
|
|
11
|
+
const shims = [
|
|
12
|
+
'node',
|
|
13
|
+
'npm',
|
|
14
|
+
'npx'
|
|
15
|
+
];
|
|
16
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
17
|
+
let removed = 0;
|
|
18
|
+
for (const shim of shims){
|
|
19
|
+
const shimPath = path.join(binDir, shim + ext);
|
|
20
|
+
if (fs.existsSync(shimPath)) {
|
|
21
|
+
fs.unlinkSync(shimPath);
|
|
22
|
+
removed++;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (removed > 0) {
|
|
26
|
+
console.log(`Removed ${removed} shim(s) from ${binDir}`);
|
|
27
|
+
console.log('');
|
|
28
|
+
console.log('You may also want to remove ~/.nvu/bin from your PATH.');
|
|
29
|
+
} else {
|
|
30
|
+
console.log('No shims found to remove.');
|
|
31
|
+
}
|
|
32
|
+
exit(0);
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/teardown.ts"],"sourcesContent":["import exit from 'exit';\nimport fs from 'fs';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu teardown\n *\n * Remove nvu shims from ~/.nvu/bin\n */\nexport default function teardownCmd(_args: string[]): void {\n const binDir = path.join(storagePath, 'bin');\n\n const shims = ['node', 'npm', 'npx'];\n const ext = process.platform === 'win32' ? '.exe' : '';\n\n let removed = 0;\n for (const shim of shims) {\n const shimPath = path.join(binDir, shim + ext);\n if (fs.existsSync(shimPath)) {\n fs.unlinkSync(shimPath);\n removed++;\n }\n }\n\n if (removed > 0) {\n console.log(`Removed ${removed} shim(s) from ${binDir}`);\n console.log('');\n console.log('You may also want to remove ~/.nvu/bin from your PATH.');\n } else {\n console.log('No shims found to remove.');\n }\n\n exit(0);\n}\n"],"names":["exit","fs","path","storagePath","teardownCmd","_args","binDir","join","shims","ext","process","platform","removed","shim","shimPath","existsSync","unlinkSync","console","log"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,WAAW,QAAQ,kBAAkB;AAE9C;;;;CAIC,GACD,eAAe,SAASC,YAAYC,KAAe;IACjD,MAAMC,SAASJ,KAAKK,IAAI,CAACJ,aAAa;IAEtC,MAAMK,QAAQ;QAAC;QAAQ;QAAO;KAAM;IACpC,MAAMC,MAAMC,QAAQC,QAAQ,KAAK,UAAU,SAAS;IAEpD,IAAIC,UAAU;IACd,KAAK,MAAMC,QAAQL,MAAO;QACxB,MAAMM,WAAWZ,KAAKK,IAAI,CAACD,QAAQO,OAAOJ;QAC1C,IAAIR,GAAGc,UAAU,CAACD,WAAW;YAC3Bb,GAAGe,UAAU,CAACF;YACdF;QACF;IACF;IAEA,IAAIA,UAAU,GAAG;QACfK,QAAQC,GAAG,CAAC,CAAC,QAAQ,EAAEN,QAAQ,cAAc,EAAEN,QAAQ;QACvDW,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;IACd,OAAO;QACLD,QAAQC,GAAG,CAAC;IACd;IAEAlB,KAAK;AACP"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import exit from 'exit';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { readdirWithTypes, rmSync } from '../compat.js';
|
|
5
|
+
import { storagePath } from '../constants.js';
|
|
6
|
+
/**
|
|
7
|
+
* nvu uninstall <version>
|
|
8
|
+
*
|
|
9
|
+
* Remove an installed Node version.
|
|
10
|
+
*/ export default function uninstallCmd(args) {
|
|
11
|
+
if (args.length === 0) {
|
|
12
|
+
console.log('Usage: nvu uninstall <version>');
|
|
13
|
+
console.log('Example: nvu uninstall 20');
|
|
14
|
+
console.log(' nvu uninstall v20.19.6');
|
|
15
|
+
exit(1);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
var version = args[0].trim();
|
|
19
|
+
var versionsPath = path.join(storagePath, 'versions');
|
|
20
|
+
// Find all matching installed versions
|
|
21
|
+
var matches = findInstalledVersions(versionsPath, version);
|
|
22
|
+
if (matches.length === 0) {
|
|
23
|
+
console.log(`Node ${version} is not installed.`);
|
|
24
|
+
console.log('');
|
|
25
|
+
console.log('Installed versions:');
|
|
26
|
+
listInstalledVersions(versionsPath);
|
|
27
|
+
exit(1);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (matches.length > 1) {
|
|
31
|
+
console.log(`Multiple versions match "${version}":`);
|
|
32
|
+
for(var i = 0; i < matches.length; i++){
|
|
33
|
+
console.log(` ${matches[i]}`);
|
|
34
|
+
}
|
|
35
|
+
console.log('');
|
|
36
|
+
console.log('Please specify the exact version to uninstall.');
|
|
37
|
+
exit(1);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var installedVersion = matches[0];
|
|
41
|
+
var versionPath = path.join(versionsPath, installedVersion);
|
|
42
|
+
// Check if this is the current default
|
|
43
|
+
var defaultPath = path.join(storagePath, 'default');
|
|
44
|
+
var isDefault = false;
|
|
45
|
+
if (fs.existsSync(defaultPath)) {
|
|
46
|
+
var defaultVersion = fs.readFileSync(defaultPath, 'utf8').trim();
|
|
47
|
+
var normalizedDefault = defaultVersion.replace(/^v/, '');
|
|
48
|
+
var normalizedInstalled = installedVersion.replace(/^v/, '');
|
|
49
|
+
// Check if default matches this version
|
|
50
|
+
if (normalizedInstalled === normalizedDefault || normalizedInstalled.indexOf(`${normalizedDefault}.`) === 0) {
|
|
51
|
+
isDefault = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Remove the version directory
|
|
55
|
+
try {
|
|
56
|
+
rmSync(versionPath);
|
|
57
|
+
console.log(`Removed Node ${installedVersion}`);
|
|
58
|
+
if (isDefault) {
|
|
59
|
+
// Clear the default since it's no longer installed
|
|
60
|
+
fs.unlinkSync(defaultPath);
|
|
61
|
+
console.log('');
|
|
62
|
+
console.log('Note: This was your default version. Set a new default with:');
|
|
63
|
+
console.log(' nvu default <version>');
|
|
64
|
+
}
|
|
65
|
+
} catch (err) {
|
|
66
|
+
console.error(`Failed to remove Node ${installedVersion}:`, err.message);
|
|
67
|
+
exit(1);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
exit(0);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Find all installed versions matching the given version string
|
|
74
|
+
*/ function findInstalledVersions(versionsPath, version) {
|
|
75
|
+
if (!fs.existsSync(versionsPath)) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
var normalizedVersion = version.replace(/^v/, '');
|
|
79
|
+
var matches = [];
|
|
80
|
+
// Try exact matches first
|
|
81
|
+
var exactMatches = [
|
|
82
|
+
version,
|
|
83
|
+
`v${normalizedVersion}`,
|
|
84
|
+
normalizedVersion
|
|
85
|
+
];
|
|
86
|
+
for(var i = 0; i < exactMatches.length; i++){
|
|
87
|
+
var v = exactMatches[i];
|
|
88
|
+
var versionPath = path.join(versionsPath, v);
|
|
89
|
+
if (fs.existsSync(versionPath) && fs.statSync(versionPath).isDirectory()) {
|
|
90
|
+
if (matches.indexOf(v) === -1) {
|
|
91
|
+
matches.push(v);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// If we have an exact match, return just that
|
|
96
|
+
if (matches.length > 0) {
|
|
97
|
+
return matches;
|
|
98
|
+
}
|
|
99
|
+
// Try partial match (e.g., "20" matches "v20.19.6")
|
|
100
|
+
var entries = readdirWithTypes(versionsPath);
|
|
101
|
+
for(var j = 0; j < entries.length; j++){
|
|
102
|
+
var entry = entries[j];
|
|
103
|
+
if (!entry.isDirectory()) continue;
|
|
104
|
+
var dirVersion = entry.name.replace(/^v/, '');
|
|
105
|
+
if (dirVersion.indexOf(`${normalizedVersion}.`) === 0) {
|
|
106
|
+
matches.push(entry.name);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return matches;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* List installed versions for user reference
|
|
113
|
+
*/ function listInstalledVersions(versionsPath) {
|
|
114
|
+
if (!fs.existsSync(versionsPath)) {
|
|
115
|
+
console.log(' (none)');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
var entries = readdirWithTypes(versionsPath);
|
|
119
|
+
var versions = [];
|
|
120
|
+
for(var i = 0; i < entries.length; i++){
|
|
121
|
+
if (entries[i].isDirectory()) {
|
|
122
|
+
versions.push(entries[i].name);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (versions.length === 0) {
|
|
126
|
+
console.log(' (none)');
|
|
127
|
+
} else {
|
|
128
|
+
for(var j = 0; j < versions.length; j++){
|
|
129
|
+
console.log(` ${versions[j]}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/uninstall.ts"],"sourcesContent":["import exit from 'exit';\nimport fs from 'fs';\nimport path from 'path';\nimport { readdirWithTypes, rmSync } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu uninstall <version>\n *\n * Remove an installed Node version.\n */\nexport default function uninstallCmd(args: string[]): void {\n if (args.length === 0) {\n console.log('Usage: nvu uninstall <version>');\n console.log('Example: nvu uninstall 20');\n console.log(' nvu uninstall v20.19.6');\n exit(1);\n return;\n }\n\n var version = args[0].trim();\n var versionsPath = path.join(storagePath, 'versions');\n\n // Find all matching installed versions\n var matches = findInstalledVersions(versionsPath, version);\n\n if (matches.length === 0) {\n console.log(`Node ${version} is not installed.`);\n console.log('');\n console.log('Installed versions:');\n listInstalledVersions(versionsPath);\n exit(1);\n return;\n }\n\n if (matches.length > 1) {\n console.log(`Multiple versions match \"${version}\":`);\n for (var i = 0; i < matches.length; i++) {\n console.log(` ${matches[i]}`);\n }\n console.log('');\n console.log('Please specify the exact version to uninstall.');\n exit(1);\n return;\n }\n\n var installedVersion = matches[0];\n var versionPath = path.join(versionsPath, installedVersion);\n\n // Check if this is the current default\n var defaultPath = path.join(storagePath, 'default');\n var isDefault = false;\n if (fs.existsSync(defaultPath)) {\n var defaultVersion = fs.readFileSync(defaultPath, 'utf8').trim();\n var normalizedDefault = defaultVersion.replace(/^v/, '');\n var normalizedInstalled = installedVersion.replace(/^v/, '');\n\n // Check if default matches this version\n if (normalizedInstalled === normalizedDefault || normalizedInstalled.indexOf(`${normalizedDefault}.`) === 0) {\n isDefault = true;\n }\n }\n\n // Remove the version directory\n try {\n rmSync(versionPath);\n console.log(`Removed Node ${installedVersion}`);\n\n if (isDefault) {\n // Clear the default since it's no longer installed\n fs.unlinkSync(defaultPath);\n console.log('');\n console.log('Note: This was your default version. Set a new default with:');\n console.log(' nvu default <version>');\n }\n } catch (err) {\n console.error(`Failed to remove Node ${installedVersion}:`, (err as Error).message);\n exit(1);\n return;\n }\n\n exit(0);\n}\n\n/**\n * Find all installed versions matching the given version string\n */\nfunction findInstalledVersions(versionsPath: string, version: string): string[] {\n if (!fs.existsSync(versionsPath)) {\n return [];\n }\n\n var normalizedVersion = version.replace(/^v/, '');\n var matches: string[] = [];\n\n // Try exact matches first\n var exactMatches = [version, `v${normalizedVersion}`, normalizedVersion];\n for (var i = 0; i < exactMatches.length; i++) {\n var v = exactMatches[i];\n var versionPath = path.join(versionsPath, v);\n if (fs.existsSync(versionPath) && fs.statSync(versionPath).isDirectory()) {\n if (matches.indexOf(v) === -1) {\n matches.push(v);\n }\n }\n }\n\n // If we have an exact match, return just that\n if (matches.length > 0) {\n return matches;\n }\n\n // Try partial match (e.g., \"20\" matches \"v20.19.6\")\n var entries = readdirWithTypes(versionsPath);\n for (var j = 0; j < entries.length; j++) {\n var entry = entries[j];\n if (!entry.isDirectory()) continue;\n var dirVersion = entry.name.replace(/^v/, '');\n if (dirVersion.indexOf(`${normalizedVersion}.`) === 0) {\n matches.push(entry.name);\n }\n }\n\n return matches;\n}\n\n/**\n * List installed versions for user reference\n */\nfunction listInstalledVersions(versionsPath: string): void {\n if (!fs.existsSync(versionsPath)) {\n console.log(' (none)');\n return;\n }\n\n var entries = readdirWithTypes(versionsPath);\n var versions: string[] = [];\n for (var i = 0; i < entries.length; i++) {\n if (entries[i].isDirectory()) {\n versions.push(entries[i].name);\n }\n }\n\n if (versions.length === 0) {\n console.log(' (none)');\n } else {\n for (var j = 0; j < versions.length; j++) {\n console.log(` ${versions[j]}`);\n }\n }\n}\n"],"names":["exit","fs","path","readdirWithTypes","rmSync","storagePath","uninstallCmd","args","length","console","log","version","trim","versionsPath","join","matches","findInstalledVersions","listInstalledVersions","i","installedVersion","versionPath","defaultPath","isDefault","existsSync","defaultVersion","readFileSync","normalizedDefault","replace","normalizedInstalled","indexOf","unlinkSync","err","error","message","normalizedVersion","exactMatches","v","statSync","isDirectory","push","entries","j","entry","dirVersion","name","versions"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,gBAAgB,EAAEC,MAAM,QAAQ,eAAe;AACxD,SAASC,WAAW,QAAQ,kBAAkB;AAE9C;;;;CAIC,GACD,eAAe,SAASC,aAAaC,IAAc;IACjD,IAAIA,KAAKC,MAAM,KAAK,GAAG;QACrBC,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZV,KAAK;QACL;IACF;IAEA,IAAIW,UAAUJ,IAAI,CAAC,EAAE,CAACK,IAAI;IAC1B,IAAIC,eAAeX,KAAKY,IAAI,CAACT,aAAa;IAE1C,uCAAuC;IACvC,IAAIU,UAAUC,sBAAsBH,cAAcF;IAElD,IAAII,QAAQP,MAAM,KAAK,GAAG;QACxBC,QAAQC,GAAG,CAAC,CAAC,KAAK,EAAEC,QAAQ,kBAAkB,CAAC;QAC/CF,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZO,sBAA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Ae;QAChCJ,QAAQC,GAAG,CAAC;QACZ;IACF;IAEA,IAAI8B,UAAUrC,iBAAiBU;IAC/B,IAAIgC,WAAqB,EAAE;IAC3B,IAAK,IAAI3B,IAAI,GAAGA,IAAIsB,QAAQhC,MAAM,EAAEU,IAAK;QACvC,IAAIsB,OAAO,CAACtB,EAAE,CAACoB,WAAW,IAAI;YAC5BO,SAASN,IAAI,CAACC,OAAO,CAACtB,EAAE,CAAC0B,IAAI;QAC/B;IACF;IAEA,IAAIC,SAASrC,MAAM,KAAK,GAAG;QACzBC,QAAQC,GAAG,CAAC;IACd,OAAO;QACL,IAAK,IAAI+B,IAAI,GAAGA,IAAII,SAASrC,MAAM,EAAEiC,IAAK;YACxChC,QAAQC,GAAG,CAAC,CAAC,EAAE,EAAEmC,QAAQ,CAACJ,EAAE,EAAE;QAChC;IACF;AACF"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import exit from 'exit';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { storagePath } from '../constants.js';
|
|
5
|
+
/**
|
|
6
|
+
* nvu which
|
|
7
|
+
*
|
|
8
|
+
* Show which Node binary would be used based on current directory.
|
|
9
|
+
* This simulates what the shim would do.
|
|
10
|
+
*/ export default function whichCmd(_args) {
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
// Resolve version using the same logic as the shim
|
|
13
|
+
const version = resolveVersion(cwd);
|
|
14
|
+
if (!version) {
|
|
15
|
+
console.log('No Node version configured for this directory.');
|
|
16
|
+
console.log('');
|
|
17
|
+
console.log('To configure a version:');
|
|
18
|
+
console.log(' nvu local <version> - Set version for this project');
|
|
19
|
+
console.log(' nvu default <version> - Set global default');
|
|
20
|
+
exit(1);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Check if the version is installed
|
|
24
|
+
const versionsPath = path.join(storagePath, 'versions');
|
|
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;
|
|
35
|
+
}
|
|
36
|
+
console.log(`Version: ${version}`);
|
|
37
|
+
console.log(`Source: ${getVersionSource(cwd)}`);
|
|
38
|
+
if (actualVersionPath) {
|
|
39
|
+
const nodePath = path.join(actualVersionPath, 'bin', 'node');
|
|
40
|
+
console.log(`Binary: ${nodePath}`);
|
|
41
|
+
if (fs.existsSync(nodePath)) {
|
|
42
|
+
console.log('Status: Installed');
|
|
43
|
+
} else {
|
|
44
|
+
console.log('Status: Directory exists but binary not found');
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
console.log(`Status: Not installed (run: nvu install ${version})`);
|
|
48
|
+
}
|
|
49
|
+
exit(0);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolve version from config files (mirrors shim logic)
|
|
53
|
+
*/ function resolveVersion(cwd) {
|
|
54
|
+
// Walk up directories looking for .nvurc or .nvmrc
|
|
55
|
+
let dir = cwd;
|
|
56
|
+
while(true){
|
|
57
|
+
// Check .nvurc first
|
|
58
|
+
const nvurcPath = path.join(dir, '.nvurc');
|
|
59
|
+
if (fs.existsSync(nvurcPath)) {
|
|
60
|
+
return fs.readFileSync(nvurcPath, 'utf8').trim();
|
|
61
|
+
}
|
|
62
|
+
// Check .nvmrc
|
|
63
|
+
const nvmrcPath = path.join(dir, '.nvmrc');
|
|
64
|
+
if (fs.existsSync(nvmrcPath)) {
|
|
65
|
+
return fs.readFileSync(nvmrcPath, 'utf8').trim();
|
|
66
|
+
}
|
|
67
|
+
// Move to parent
|
|
68
|
+
const parent = path.dirname(dir);
|
|
69
|
+
if (parent === dir) break;
|
|
70
|
+
dir = parent;
|
|
71
|
+
}
|
|
72
|
+
// Check global default
|
|
73
|
+
const defaultPath = path.join(storagePath, 'default');
|
|
74
|
+
if (fs.existsSync(defaultPath)) {
|
|
75
|
+
return fs.readFileSync(defaultPath, 'utf8').trim();
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Determine the source of the version (for display)
|
|
81
|
+
*/ function getVersionSource(cwd) {
|
|
82
|
+
let dir = cwd;
|
|
83
|
+
while(true){
|
|
84
|
+
const nvurcPath = path.join(dir, '.nvurc');
|
|
85
|
+
if (fs.existsSync(nvurcPath)) {
|
|
86
|
+
return nvurcPath;
|
|
87
|
+
}
|
|
88
|
+
const nvmrcPath = path.join(dir, '.nvmrc');
|
|
89
|
+
if (fs.existsSync(nvmrcPath)) {
|
|
90
|
+
return nvmrcPath;
|
|
91
|
+
}
|
|
92
|
+
const parent = path.dirname(dir);
|
|
93
|
+
if (parent === dir) break;
|
|
94
|
+
dir = parent;
|
|
95
|
+
}
|
|
96
|
+
const defaultPath = path.join(storagePath, 'default');
|
|
97
|
+
if (fs.existsSync(defaultPath)) {
|
|
98
|
+
return `${defaultPath} (global default)`;
|
|
99
|
+
}
|
|
100
|
+
return 'none';
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/which.ts"],"sourcesContent":["import exit from 'exit';\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 shim 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 shim\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, 'versions');\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 shim 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,OAAO;AACxB,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,mDAAmD;IACnD,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;QACZX,KAAK;QACL;IACF;IAEA,oCAAoC;IACpC,MAAMY,eAAeV,KAAKW,IAAI,CAACV,aAAa;IAC5C,MAAMW,cAAcZ,KAAKW,IAAI,CAACD,cAAcJ;IAC5C,MAAMO,mBAAmBb,KAAKW,IAAI,CAACD,cAAc,CAAC,CAAC,EAAEJ,SAAS;IAC9D,MAAMQ,sBAAsBd,KAAKW,IAAI,CAACD,cAAcJ,QAAQS,OAAO,CAAC,MAAM;IAE1E,IAAIC,oBAAoB;IACxB,IAAIjB,GAAGkB,UAAU,CAACL,cAAc;QAC9BI,oBAAoBJ;IACtB,OAAO,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K,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"}
|
package/dist/esm/compat.d.ts
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
1
|
export declare function homedir(): string;
|
|
2
2
|
export declare function stringEndsWith(str: string, search: string, position?: number): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Recursive mkdir for Node.js 0.8+
|
|
5
|
+
*/
|
|
6
|
+
export declare function mkdirpSync(dir: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* Recursive rm for Node.js 0.8+
|
|
9
|
+
*/
|
|
10
|
+
export declare function rmSync(dir: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Read directory entries with types for Node.js 0.8+
|
|
13
|
+
* Returns array of {name, isDirectory()}
|
|
14
|
+
*/
|
|
15
|
+
export interface DirEntry {
|
|
16
|
+
name: string;
|
|
17
|
+
isDirectory(): boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function readdirWithTypes(dir: string): DirEntry[];
|
package/dist/esm/compat.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Compatibility Layer for Node.js 0.8+
|
|
3
3
|
* Local to this package - contains only needed functions.
|
|
4
|
-
*/ import
|
|
4
|
+
*/ import fs from 'fs';
|
|
5
|
+
import _Module from 'module';
|
|
6
|
+
import os from 'os';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
// Use existing require in CJS, or createRequire in ESM (Node 12.2+)
|
|
9
|
+
var _require = typeof require === 'undefined' ? _Module.createRequire(import.meta.url) : require;
|
|
5
10
|
var hasHomedir = typeof os.homedir === 'function';
|
|
6
11
|
export function homedir() {
|
|
7
12
|
if (hasHomedir) {
|
|
8
13
|
return os.homedir();
|
|
9
14
|
}
|
|
10
|
-
var home =
|
|
15
|
+
var home = _require('homedir-polyfill');
|
|
11
16
|
return home();
|
|
12
17
|
}
|
|
13
18
|
/**
|
|
@@ -22,3 +27,35 @@ export function stringEndsWith(str, search, position) {
|
|
|
22
27
|
var len = position === undefined ? str.length : position;
|
|
23
28
|
return str.lastIndexOf(search) === len - search.length;
|
|
24
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Recursive mkdir for Node.js 0.8+
|
|
32
|
+
*/ export function mkdirpSync(dir) {
|
|
33
|
+
var mkdirp = _require('mkdirp-classic');
|
|
34
|
+
mkdirp.sync(dir);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Recursive rm for Node.js 0.8+
|
|
38
|
+
*/ export function rmSync(dir) {
|
|
39
|
+
var safeRmSync = _require('fs-remove-compat').safeRmSync;
|
|
40
|
+
safeRmSync(dir);
|
|
41
|
+
}
|
|
42
|
+
export function readdirWithTypes(dir) {
|
|
43
|
+
var names = fs.readdirSync(dir);
|
|
44
|
+
return names.map((name)=>{
|
|
45
|
+
var fullPath = path.join(dir, name);
|
|
46
|
+
var stat;
|
|
47
|
+
try {
|
|
48
|
+
stat = fs.statSync(fullPath);
|
|
49
|
+
} catch (_e) {
|
|
50
|
+
// If stat fails, treat as non-directory
|
|
51
|
+
return {
|
|
52
|
+
name: name,
|
|
53
|
+
isDirectory: ()=>false
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
name: name,
|
|
58
|
+
isDirectory: ()=>stat.isDirectory()
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
}
|
package/dist/esm/compat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\nimport os from 'os';\n\nvar hasHomedir = typeof os.homedir === 'function';\n\nexport function homedir(): string {\n if (hasHomedir) {\n return os.homedir();\n }\n var home =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\nimport fs from 'fs';\nimport _Module from 'module';\nimport os from 'os';\nimport path from 'path';\n\n// Use existing require in CJS, or createRequire in ESM (Node 12.2+)\nvar _require = typeof require === 'undefined' ? _Module.createRequire(import.meta.url) : require;\n\nvar hasHomedir = typeof os.homedir === 'function';\n\nexport function homedir(): string {\n if (hasHomedir) {\n return os.homedir();\n }\n var home = _require('homedir-polyfill');\n return home();\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nvar hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n var len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * Recursive mkdir for Node.js 0.8+\n */\nexport function mkdirpSync(dir: string): void {\n var mkdirp = _require('mkdirp-classic');\n mkdirp.sync(dir);\n}\n\n/**\n * Recursive rm for Node.js 0.8+\n */\nexport function rmSync(dir: string): void {\n var safeRmSync = _require('fs-remove-compat').safeRmSync;\n safeRmSync(dir);\n}\n\n/**\n * Read directory entries with types for Node.js 0.8+\n * Returns array of {name, isDirectory()}\n */\nexport interface DirEntry {\n name: string;\n isDirectory(): boolean;\n}\n\nexport function readdirWithTypes(dir: string): DirEntry[] {\n var names = fs.readdirSync(dir);\n return names.map((name) => {\n var fullPath = path.join(dir, name);\n var stat: fs.Stats;\n try {\n stat = fs.statSync(fullPath);\n } catch (_e) {\n // If stat fails, treat as non-directory\n return { name: name, isDirectory: () => false };\n }\n return {\n name: name,\n isDirectory: () => stat.isDirectory(),\n };\n });\n}\n"],"names":["fs","_Module","os","path","_require","require","createRequire","url","hasHomedir","homedir","home","hasEndsWith","String","prototype","endsWith","stringEndsWith","str","search","position","len","undefined","length","lastIndexOf","mkdirpSync","dir","mkdirp","sync","rmSync","safeRmSync","readdirWithTypes","names","readdirSync","map","name","fullPath","join","stat","statSync","_e","isDirectory"],"mappings":"AAAA;;;CAGC,GACD,OAAOA,QAAQ,KAAK;AACpB,OAAOC,aAAa,SAAS;AAC7B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AAExB,oEAAoE;AACpE,IAAIC,WAAW,OAAOC,YAAY,cAAcJ,QAAQK,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAEzF,IAAIG,aAAa,OAAON,GAAGO,OAAO,KAAK;AAEvC,OAAO,SAASA;IACd,IAAID,YAAY;QACd,OAAON,GAAGO,OAAO;IACnB;IACA,IAAIC,OAAON,SAAS;IACpB,OAAOM;AACT;AAEA;;;;CAIC,GACD,IAAIC,cAAc,OAAOC,OAAOC,SAAS,CAACC,QAAQ,KAAK;AAEvD,OAAO,SAASC,eAAeC,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIP,aAAa;QACf,OAAOK,IAAIF,QAAQ,CAACG,QAAQC;IAC9B;IACA,IAAIC,MAAMD,aAAaE,YAAYJ,IAAIK,MAAM,GAAGH;IAChD,OAAOF,IAAIM,WAAW,CAACL,YAAYE,MAAMF,OAAOI,MAAM;AACxD;AAEA;;CAEC,GACD,OAAO,SAASE,WAAWC,GAAW;IACpC,IAAIC,SAASrB,SAAS;IACtBqB,OAAOC,IAAI,CAACF;AACd;AAEA;;CAEC,GACD,OAAO,SAASG,OAAOH,GAAW;IAChC,IAAII,aAAaxB,SAAS,oBAAoBwB,UAAU;IACxDA,WAAWJ;AACb;AAWA,OAAO,SAASK,iBAAiBL,GAAW;IAC1C,IAAIM,QAAQ9B,GAAG+B,WAAW,CAACP;IAC3B,OAAOM,MAAME,GAAG,CAAC,CAACC;QAChB,IAAIC,WAAW/B,KAAKgC,IAAI,CAACX,KAAKS;QAC9B,IAAIG;QACJ,IAAI;YACFA,OAAOpC,GAAGqC,QAAQ,CAACH;QACrB,EAAE,OAAOI,IAAI;YACX,wCAAwC;YACxC,OAAO;gBAAEL,MAAMA;gBAAMM,aAAa,IAAM;YAAM;QAChD;QACA,OAAO;YACLN,MAAMA;YACNM,aAAa,IAAMH,KAAKG,WAAW;QACrC;IACF;AACF"}
|
package/dist/esm/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/constants.ts"],"sourcesContent":["import path from 'path';\nimport { homedir } from './compat.ts';\n\nexport const storagePath = path.join(homedir(), '.nvu') as string;\n"],"names":["path","homedir","storagePath","join"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,SAASC,OAAO,QAAQ,cAAc;AAEtC,OAAO,MAAMC,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/constants.ts"],"sourcesContent":["import path from 'path';\nimport { homedir } from './compat.ts';\n\n// Allow NVU_HOME override for testing\nexport const storagePath = (process.env.NVU_HOME || path.join(homedir(), '.nvu')) as string;\n"],"names":["path","homedir","storagePath","process","env","NVU_HOME","join"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,SAASC,OAAO,QAAQ,cAAc;AAEtC,sCAAsC;AACtC,OAAO,MAAMC,cAAeC,QAAQC,GAAG,CAACC,QAAQ,IAAIL,KAAKM,IAAI,CAACL,WAAW,QAAmB"}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export interface Options {
|
|
|
18
18
|
streaming?: boolean;
|
|
19
19
|
expanded?: boolean;
|
|
20
20
|
interactive?: boolean;
|
|
21
|
+
silent?: boolean;
|
|
21
22
|
}
|
|
22
23
|
export type UseOptions = Options & InstallOptions & VersionOptions & SpawnOptions;
|
|
23
24
|
export type UseCallback = (err?: UseError | Error, results?: UseResult[]) => undefined;
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/types.ts"],"sourcesContent":["import type { SpawnOptions, SpawnResult } from 'cross-spawn-cb';\nimport type { VersionOptions } from 'node-resolve-versions';\nimport type { InstallOptions, InstallResult } from 'node-version-install';\n\nexport interface UseResult {\n install: InstallResult;\n command: string;\n version: string;\n result?: SpawnResult;\n error?: Error;\n}\n\nexport interface UseError extends Error {\n results: UseResult[] | undefined;\n}\n\nexport interface Options {\n range?: string;\n concurrency?: number;\n sort?: number;\n streaming?: boolean;\n expanded?: boolean;\n interactive?: boolean;\n}\nexport type UseOptions = Options & InstallOptions & VersionOptions & SpawnOptions;\n\nexport type UseCallback = (err?: UseError | Error, results?: UseResult[]) => undefined;\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/types.ts"],"sourcesContent":["import type { SpawnOptions, SpawnResult } from 'cross-spawn-cb';\nimport type { VersionOptions } from 'node-resolve-versions';\nimport type { InstallOptions, InstallResult } from 'node-version-install';\n\nexport interface UseResult {\n install: InstallResult;\n command: string;\n version: string;\n result?: SpawnResult;\n error?: Error;\n}\n\nexport interface UseError extends Error {\n results: UseResult[] | undefined;\n}\n\nexport interface Options {\n range?: string;\n concurrency?: number;\n sort?: number;\n streaming?: boolean;\n expanded?: boolean;\n interactive?: boolean;\n silent?: boolean;\n}\nexport type UseOptions = Options & InstallOptions & VersionOptions & SpawnOptions;\n\nexport type UseCallback = (err?: UseError | Error, results?: UseResult[]) => undefined;\n"],"names":[],"mappings":"AA2BA,WAAuF"}
|
package/dist/esm/worker.js
CHANGED
|
@@ -140,8 +140,8 @@ export default function worker(versionExpression, command, args, options, callba
|
|
|
140
140
|
// On Windows, resolve npm bin commands to bypass .cmd wrappers
|
|
141
141
|
const resolved = resolveCommand(command, args);
|
|
142
142
|
if (versions.length < 2) {
|
|
143
|
-
// Show command when running single version (no terminal session)
|
|
144
|
-
console.log(`$ ${formatArguments([
|
|
143
|
+
// Show command when running single version (no terminal session, unless silent)
|
|
144
|
+
if (!options.silent) console.log(`$ ${formatArguments([
|
|
145
145
|
resolved.command
|
|
146
146
|
].concat(resolved.args)).join(' ')}`);
|
|
147
147
|
return spawn(resolved.command, resolved.args, spawnOptions, next);
|