node-version-use 2.1.0 → 2.1.2
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/cli.js +7 -7
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/commands/default.js +73 -7
- package/dist/cjs/commands/default.js.map +1 -1
- package/dist/cjs/commands/install.js +6 -6
- package/dist/cjs/commands/install.js.map +1 -1
- package/dist/cjs/commands/list.js +4 -4
- package/dist/cjs/commands/list.js.map +1 -1
- package/dist/cjs/commands/local.js +6 -6
- package/dist/cjs/commands/local.js.map +1 -1
- package/dist/cjs/commands/setup.js +2 -2
- package/dist/cjs/commands/setup.js.map +1 -1
- package/dist/cjs/commands/teardown.js +2 -2
- package/dist/cjs/commands/teardown.js.map +1 -1
- package/dist/cjs/commands/uninstall.js +20 -71
- package/dist/cjs/commands/uninstall.js.map +1 -1
- package/dist/cjs/commands/which.js +3 -3
- package/dist/cjs/commands/which.js.map +1 -1
- package/dist/cjs/lib/findInstalledVersions.d.cts +9 -0
- package/dist/cjs/lib/findInstalledVersions.d.ts +9 -0
- package/dist/cjs/lib/findInstalledVersions.js +95 -0
- package/dist/cjs/lib/findInstalledVersions.js.map +1 -0
- package/dist/esm/cli.js +1 -1
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/commands/default.js +70 -4
- package/dist/esm/commands/default.js.map +1 -1
- package/dist/esm/commands/install.js +1 -1
- package/dist/esm/commands/install.js.map +1 -1
- package/dist/esm/commands/list.js +1 -1
- package/dist/esm/commands/list.js.map +1 -1
- package/dist/esm/commands/local.js +1 -1
- package/dist/esm/commands/local.js.map +1 -1
- package/dist/esm/commands/setup.js +1 -1
- package/dist/esm/commands/setup.js.map +1 -1
- package/dist/esm/commands/teardown.js +1 -1
- package/dist/esm/commands/teardown.js.map +1 -1
- package/dist/esm/commands/uninstall.js +15 -66
- package/dist/esm/commands/uninstall.js.map +1 -1
- package/dist/esm/commands/which.js +1 -1
- package/dist/esm/commands/which.js.map +1 -1
- package/dist/esm/lib/findInstalledVersions.d.ts +9 -0
- package/dist/esm/lib/findInstalledVersions.js +76 -0
- package/dist/esm/lib/findInstalledVersions.js.map +1 -0
- package/package.json +6 -6
- package/scripts/postinstall.cjs +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/list.ts"],"sourcesContent":["import exit from 'exit';\nimport fs from 'fs';\nimport path from 'path';\nimport { readdirWithTypes } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu list\n *\n * List all installed Node versions.\n */\nexport default function listCmd(_args: string[]): void {\n var versionsPath = path.join(storagePath, 'installed');\n\n // Check if versions directory exists\n if (!fs.existsSync(versionsPath)) {\n console.log('No Node versions installed.');\n console.log('Install a version: nvu install <version>');\n exit(0);\n return;\n }\n\n // Read all directories in versions folder\n var entries = readdirWithTypes(versionsPath);\n var versions = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);\n\n if (versions.length === 0) {\n console.log('No Node versions installed.');\n console.log('Install a version: nvu install <version>');\n exit(0);\n return;\n }\n\n // Get the current default\n const defaultFilePath = path.join(storagePath, 'default');\n let defaultVersion = '';\n if (fs.existsSync(defaultFilePath)) {\n defaultVersion = fs.readFileSync(defaultFilePath, 'utf8').trim();\n }\n\n // Sort versions (simple string sort, could be improved with semver)\n versions.sort((a, b) => {\n const aParts = a.split('.').map((n) => parseInt(n, 10) || 0);\n const bParts = b.split('.').map((n) => parseInt(n, 10) || 0);\n for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {\n const aVal = aParts[i] || 0;\n const bVal = bParts[i] || 0;\n if (aVal !== bVal) return bVal - aVal; // Descending order\n }\n return 0;\n });\n\n console.log('Installed Node versions:');\n for (let i = 0; i < versions.length; i++) {\n const version = versions[i];\n const isDefault = version === defaultVersion || `v${version}` === defaultVersion || version === `v${defaultVersion}`;\n const marker = isDefault ? ' (default)' : '';\n console.log(` ${version}${marker}`);\n }\n exit(0);\n}\n"],"names":["exit","fs","path","readdirWithTypes","storagePath","listCmd","_args","versionsPath","join","existsSync","console","log","entries","versions","filter","entry","isDirectory","map","name","length","defaultFilePath","defaultVersion","readFileSync","trim","sort","a","b","aParts","split","n","parseInt","bParts","i","Math","max","aVal","bVal","version","isDefault","marker"],"mappings":"AAAA,OAAOA,UAAU,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/list.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { readdirWithTypes } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu list\n *\n * List all installed Node versions.\n */\nexport default function listCmd(_args: string[]): void {\n var versionsPath = path.join(storagePath, 'installed');\n\n // Check if versions directory exists\n if (!fs.existsSync(versionsPath)) {\n console.log('No Node versions installed.');\n console.log('Install a version: nvu install <version>');\n exit(0);\n return;\n }\n\n // Read all directories in versions folder\n var entries = readdirWithTypes(versionsPath);\n var versions = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);\n\n if (versions.length === 0) {\n console.log('No Node versions installed.');\n console.log('Install a version: nvu install <version>');\n exit(0);\n return;\n }\n\n // Get the current default\n const defaultFilePath = path.join(storagePath, 'default');\n let defaultVersion = '';\n if (fs.existsSync(defaultFilePath)) {\n defaultVersion = fs.readFileSync(defaultFilePath, 'utf8').trim();\n }\n\n // Sort versions (simple string sort, could be improved with semver)\n versions.sort((a, b) => {\n const aParts = a.split('.').map((n) => parseInt(n, 10) || 0);\n const bParts = b.split('.').map((n) => parseInt(n, 10) || 0);\n for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {\n const aVal = aParts[i] || 0;\n const bVal = bParts[i] || 0;\n if (aVal !== bVal) return bVal - aVal; // Descending order\n }\n return 0;\n });\n\n console.log('Installed Node versions:');\n for (let i = 0; i < versions.length; i++) {\n const version = versions[i];\n const isDefault = version === defaultVersion || `v${version}` === defaultVersion || version === `v${defaultVersion}`;\n const marker = isDefault ? ' (default)' : '';\n console.log(` ${version}${marker}`);\n }\n exit(0);\n}\n"],"names":["exit","fs","path","readdirWithTypes","storagePath","listCmd","_args","versionsPath","join","existsSync","console","log","entries","versions","filter","entry","isDirectory","map","name","length","defaultFilePath","defaultVersion","readFileSync","trim","sort","a","b","aParts","split","n","parseInt","bParts","i","Math","max","aVal","bVal","version","isDefault","marker"],"mappings":"AAAA,OAAOA,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,gBAAgB,QAAQ,eAAe;AAChD,SAASC,WAAW,QAAQ,kBAAkB;AAE9C;;;;CAIC,GACD,eAAe,SAASC,QAAQC,KAAe;IAC7C,IAAIC,eAAeL,KAAKM,IAAI,CAACJ,aAAa;IAE1C,qCAAqC;IACrC,IAAI,CAACH,GAAGQ,UAAU,CAACF,eAAe;QAChCG,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZX,KAAK;QACL;IACF;IAEA,0CAA0C;IAC1C,IAAIY,UAAUT,iBAAiBI;IAC/B,IAAIM,WAAWD,QAAQE,MAAM,CAAC,CAACC,QAAUA,MAAMC,WAAW,IAAIC,GAAG,CAAC,CAACF,QAAUA,MAAMG,IAAI;IAEvF,IAAIL,SAASM,MAAM,KAAK,GAAG;QACzBT,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZX,KAAK;QACL;IACF;IAEA,0BAA0B;IAC1B,MAAMoB,kBAAkBlB,KAAKM,IAAI,CAACJ,aAAa;IAC/C,IAAIiB,iBAAiB;IACrB,IAAIpB,GAAGQ,UAAU,CAACW,kBAAkB;QAClCC,iBAAiBpB,GAAGqB,YAAY,CAACF,iBAAiB,QAAQG,IAAI;IAChE;IAEA,oEAAoE;IACpEV,SAASW,IAAI,CAAC,CAACC,GAAGC;QAChB,MAAMC,SAASF,EAAEG,KAAK,CAAC,KAAKX,GAAG,CAAC,CAACY,IAAMC,SAASD,GAAG,OAAO;QAC1D,MAAME,SAASL,EAAEE,KAAK,CAAC,KAAKX,GAAG,CAAC,CAACY,IAAMC,SAASD,GAAG,OAAO;QAC1D,IAAK,IAAIG,IAAI,GAAGA,IAAIC,KAAKC,GAAG,CAACP,OAAOR,MAAM,EAAEY,OAAOZ,MAAM,GAAGa,IAAK;YAC/D,MAAMG,OAAOR,MAAM,CAACK,EAAE,IAAI;YAC1B,MAAMI,OAAOL,MAAM,CAACC,EAAE,IAAI;YAC1B,IAAIG,SAASC,MAAM,OAAOA,OAAOD,MAAM,mBAAmB;QAC5D;QACA,OAAO;IACT;IAEAzB,QAAQC,GAAG,CAAC;IACZ,IAAK,IAAIqB,IAAI,GAAGA,IAAInB,SAASM,MAAM,EAAEa,IAAK;QACxC,MAAMK,UAAUxB,QAAQ,CAACmB,EAAE;QAC3B,MAAMM,YAAYD,YAAYhB,kBAAkB,CAAC,CAAC,EAAEgB,SAAS,KAAKhB,kBAAkBgB,YAAY,CAAC,CAAC,EAAEhB,gBAAgB;QACpH,MAAMkB,SAASD,YAAY,eAAe;QAC1C5B,QAAQC,GAAG,CAAC,CAAC,EAAE,EAAE0B,UAAUE,QAAQ;IACrC;IACAvC,KAAK;AACP"}
|
|
@@ -1 +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 (indexOf for Node 0.8+ compat)\n const useNvurc = args.indexOf('--nvurc') !== -1;\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, indexOf for Node 0.8+ compat)\n if (!version || version.indexOf('-') === 0) {\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","indexOf","filteredArgs","filter","arg","fileName","filePath","join","length","nvurcPath","nvmrcPath","existsSync","version","readFileSync","trim","console","log","writeFileSync"],"mappings":"AAAA,OAAOA,UAAU,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/local.ts"],"sourcesContent":["import exit from 'exit-compat';\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 (indexOf for Node 0.8+ compat)\n const useNvurc = args.indexOf('--nvurc') !== -1;\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, indexOf for Node 0.8+ compat)\n if (!version || version.indexOf('-') === 0) {\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","indexOf","filteredArgs","filter","arg","fileName","filePath","join","length","nvurcPath","nvmrcPath","existsSync","version","readFileSync","trim","console","log","writeFileSync"],"mappings":"AAAA,OAAOA,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AAExB;;;;;CAKC,GACD,eAAe,SAASC,SAASC,IAAc;IAC7C,MAAMC,MAAMC,QAAQD,GAAG;IAEvB,wDAAwD;IACxD,MAAME,WAAWH,KAAKI,OAAO,CAAC,eAAe,CAAC;IAC9C,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,sEAAsE;IACtE,IAAI,CAACF,WAAWA,QAAQX,OAAO,CAAC,SAAS,GAAG;QAC1Cc,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZvB,KAAK;QACL;IACF;IAEA,yBAAyB;IACzBC,GAAGuB,aAAa,CAACX,UAAU,GAAGM,QAAQ,EAAE,CAAC,EAAE;IAC3CG,QAAQC,GAAG,CAAC,CAAC,QAAQ,EAAEX,SAAS,eAAe,EAAEO,SAAS;IAC1DnB,KAAK;AACP"}
|
|
@@ -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';\nimport fs from 'fs';\nimport path from 'path';\nimport url from 'url';\nimport { mkdirpSync } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\n\nvar __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n/**\n * nvu setup\n *\n * Install/reinstall nvu binaries to ~/.nvu/bin\n * This runs the same logic as the postinstall script.\n */\nexport default function setupCmd(_args: string[]): void {\n var binDir = path.join(storagePath, 'bin');\n\n // Create directories\n if (!fs.existsSync(storagePath)) {\n mkdirpSync(storagePath);\n }\n if (!fs.existsSync(binDir)) {\n mkdirpSync(binDir);\n }\n\n // Find the postinstall script relative to this module\n var postinstallPath = path.join(__dirname, '..', '..', '..', 'scripts', 'postinstall.cjs');\n\n if (fs.existsSync(postinstallPath)) {\n // Run the postinstall script\n try {\n execSync(`node \"${postinstallPath}\"`, { stdio: 'inherit' });\n } catch (_err) {\n // postinstall handles its own errors gracefully\n }\n } else {\n console.log('Setup script not found.');\n console.log('Try reinstalling: npm install -g node-version-use');\n exit(1);\n }\n}\n"],"names":["execSync","exit","fs","path","url","mkdirpSync","storagePath","__dirname","dirname","__filename","fileURLToPath","setupCmd","_args","binDir","join","existsSync","postinstallPath","stdio","_err","console","log"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,gBAAgB;AACzC,OAAOC,UAAU,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/setup.ts"],"sourcesContent":["import { execSync } from 'child_process';\nimport exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport url from 'url';\nimport { mkdirpSync } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\n\nvar __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n/**\n * nvu setup\n *\n * Install/reinstall nvu binaries to ~/.nvu/bin\n * This runs the same logic as the postinstall script.\n */\nexport default function setupCmd(_args: string[]): void {\n var binDir = path.join(storagePath, 'bin');\n\n // Create directories\n if (!fs.existsSync(storagePath)) {\n mkdirpSync(storagePath);\n }\n if (!fs.existsSync(binDir)) {\n mkdirpSync(binDir);\n }\n\n // Find the postinstall script relative to this module\n var postinstallPath = path.join(__dirname, '..', '..', '..', 'scripts', 'postinstall.cjs');\n\n if (fs.existsSync(postinstallPath)) {\n // Run the postinstall script\n try {\n execSync(`node \"${postinstallPath}\"`, { stdio: 'inherit' });\n } catch (_err) {\n // postinstall handles its own errors gracefully\n }\n } else {\n console.log('Setup script not found.');\n console.log('Try reinstalling: npm install -g node-version-use');\n exit(1);\n }\n}\n"],"names":["execSync","exit","fs","path","url","mkdirpSync","storagePath","__dirname","dirname","__filename","fileURLToPath","setupCmd","_args","binDir","join","existsSync","postinstallPath","stdio","_err","console","log"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,gBAAgB;AACzC,OAAOC,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,IAAIC,YAAYJ,KAAKK,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaL,IAAIM,aAAa,CAAC,YAAYN,GAAG;AAE/G;;;;;CAKC,GACD,eAAe,SAASO,SAASC,KAAe;IAC9C,IAAIC,SAASV,KAAKW,IAAI,CAACR,aAAa;IAEpC,qBAAqB;IACrB,IAAI,CAACJ,GAAGa,UAAU,CAACT,cAAc;QAC/BD,WAAWC;IACb;IACA,IAAI,CAACJ,GAAGa,UAAU,CAACF,SAAS;QAC1BR,WAAWQ;IACb;IAEA,sDAAsD;IACtD,IAAIG,kBAAkBb,KAAKW,IAAI,CAACP,WAAW,MAAM,MAAM,MAAM,WAAW;IAExE,IAAIL,GAAGa,UAAU,CAACC,kBAAkB;QAClC,6BAA6B;QAC7B,IAAI;YACFhB,SAAS,CAAC,MAAM,EAAEgB,gBAAgB,CAAC,CAAC,EAAE;gBAAEC,OAAO;YAAU;QAC3D,EAAE,OAAOC,MAAM;QACb,gDAAgD;QAClD;IACF,OAAO;QACLC,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZnB,KAAK;IACP;AACF"}
|
|
@@ -1 +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 { rmSync } from 'fs-remove-compat';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu teardown\n *\n * Remove nvu binaries from ~/.nvu/bin\n */\nexport default function teardownCmd(_args: string[]): void {\n const binDir = path.join(storagePath, 'bin');\n\n const binaries = ['node', 'npm', 'npx'];\n const ext = process.platform === 'win32' ? '.exe' : '';\n\n let removed = 0;\n for (let i = 0; i < binaries.length; i++) {\n const binaryPath = path.join(binDir, binaries[i] + ext);\n if (fs.existsSync(binaryPath)) {\n rmSync(binaryPath, { force: true });\n removed++;\n }\n }\n\n if (removed > 0) {\n console.log(`Removed ${removed} binary(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 binaries found to remove.');\n }\n\n exit(0);\n}\n"],"names":["exit","fs","rmSync","path","storagePath","teardownCmd","_args","binDir","join","binaries","ext","process","platform","removed","i","length","binaryPath","existsSync","force","console","log"],"mappings":"AAAA,OAAOA,UAAU,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/teardown.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport { rmSync } from 'fs-remove-compat';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu teardown\n *\n * Remove nvu binaries from ~/.nvu/bin\n */\nexport default function teardownCmd(_args: string[]): void {\n const binDir = path.join(storagePath, 'bin');\n\n const binaries = ['node', 'npm', 'npx'];\n const ext = process.platform === 'win32' ? '.exe' : '';\n\n let removed = 0;\n for (let i = 0; i < binaries.length; i++) {\n const binaryPath = path.join(binDir, binaries[i] + ext);\n if (fs.existsSync(binaryPath)) {\n rmSync(binaryPath, { force: true });\n removed++;\n }\n }\n\n if (removed > 0) {\n console.log(`Removed ${removed} binary(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 binaries found to remove.');\n }\n\n exit(0);\n}\n"],"names":["exit","fs","rmSync","path","storagePath","teardownCmd","_args","binDir","join","binaries","ext","process","platform","removed","i","length","binaryPath","existsSync","force","console","log"],"mappings":"AAAA,OAAOA,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,UAAU,OAAO;AACxB,SAASC,WAAW,QAAQ,kBAAkB;AAE9C;;;;CAIC,GACD,eAAe,SAASC,YAAYC,KAAe;IACjD,MAAMC,SAASJ,KAAKK,IAAI,CAACJ,aAAa;IAEtC,MAAMK,WAAW;QAAC;QAAQ;QAAO;KAAM;IACvC,MAAMC,MAAMC,QAAQC,QAAQ,KAAK,UAAU,SAAS;IAEpD,IAAIC,UAAU;IACd,IAAK,IAAIC,IAAI,GAAGA,IAAIL,SAASM,MAAM,EAAED,IAAK;QACxC,MAAME,aAAab,KAAKK,IAAI,CAACD,QAAQE,QAAQ,CAACK,EAAE,GAAGJ;QACnD,IAAIT,GAAGgB,UAAU,CAACD,aAAa;YAC7Bd,OAAOc,YAAY;gBAAEE,OAAO;YAAK;YACjCL;QACF;IACF;IAEA,IAAIA,UAAU,GAAG;QACfM,QAAQC,GAAG,CAAC,CAAC,QAAQ,EAAEP,QAAQ,gBAAgB,EAAEN,QAAQ;QACzDY,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;IACd,OAAO;QACLD,QAAQC,GAAG,CAAC;IACd;IAEApB,KAAK;AACP"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import exit from 'exit';
|
|
1
|
+
import exit from 'exit-compat';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import {
|
|
4
|
+
import { rmSync } from '../compat.js';
|
|
5
5
|
import { storagePath } from '../constants.js';
|
|
6
|
+
import { findInstalledVersions, getAllInstalledVersions } from '../lib/findInstalledVersions.js';
|
|
6
7
|
/**
|
|
7
8
|
* nvu uninstall <version>
|
|
8
9
|
*
|
|
@@ -39,29 +40,26 @@ import { storagePath } from '../constants.js';
|
|
|
39
40
|
}
|
|
40
41
|
var installedVersion = matches[0];
|
|
41
42
|
var versionPath = path.join(versionsPath, installedVersion);
|
|
42
|
-
// Check if this is the current default
|
|
43
|
+
// Check if this is the current default (exact match since we store exact versions)
|
|
43
44
|
var defaultPath = path.join(storagePath, 'default');
|
|
44
|
-
var isDefault = false;
|
|
45
45
|
if (fs.existsSync(defaultPath)) {
|
|
46
46
|
var defaultVersion = fs.readFileSync(defaultPath, 'utf8').trim();
|
|
47
|
+
// Normalize both for comparison
|
|
47
48
|
var normalizedDefault = defaultVersion.replace(/^v/, '');
|
|
48
49
|
var normalizedInstalled = installedVersion.replace(/^v/, '');
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
if (normalizedInstalled === normalizedDefault) {
|
|
51
|
+
console.error(`Cannot uninstall default version ${installedVersion}.`);
|
|
52
|
+
console.error('');
|
|
53
|
+
console.error('Change your default first:');
|
|
54
|
+
console.error(' nvu default <version>');
|
|
55
|
+
exit(1);
|
|
56
|
+
return;
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
// Remove the version directory
|
|
55
60
|
try {
|
|
56
61
|
rmSync(versionPath);
|
|
57
62
|
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
63
|
} catch (err) {
|
|
66
64
|
console.error(`Failed to remove Node ${installedVersion}:`, err.message);
|
|
67
65
|
exit(1);
|
|
@@ -69,64 +67,15 @@ import { storagePath } from '../constants.js';
|
|
|
69
67
|
}
|
|
70
68
|
exit(0);
|
|
71
69
|
}
|
|
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
70
|
/**
|
|
112
71
|
* List installed versions for user reference
|
|
113
72
|
*/ function listInstalledVersions(versionsPath) {
|
|
114
|
-
|
|
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
|
-
}
|
|
73
|
+
var versions = getAllInstalledVersions(versionsPath);
|
|
125
74
|
if (versions.length === 0) {
|
|
126
75
|
console.log(' (none)');
|
|
127
76
|
} else {
|
|
128
|
-
for(var
|
|
129
|
-
console.log(` ${versions[
|
|
77
|
+
for(var i = 0; i < versions.length; i++){
|
|
78
|
+
console.log(` ${versions[i]}`);
|
|
130
79
|
}
|
|
131
80
|
}
|
|
132
81
|
}
|
|
@@ -1 +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 {
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/uninstall.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { rmSync } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\nimport { findInstalledVersions, getAllInstalledVersions } from '../lib/findInstalledVersions.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, 'installed');\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 (exact match since we store exact versions)\n var defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n var defaultVersion = fs.readFileSync(defaultPath, 'utf8').trim();\n\n // Normalize both for comparison\n var normalizedDefault = defaultVersion.replace(/^v/, '');\n var normalizedInstalled = installedVersion.replace(/^v/, '');\n\n if (normalizedInstalled === normalizedDefault) {\n console.error(`Cannot uninstall default version ${installedVersion}.`);\n console.error('');\n console.error('Change your default first:');\n console.error(' nvu default <version>');\n exit(1);\n return;\n }\n }\n\n // Remove the version directory\n try {\n rmSync(versionPath);\n console.log(`Removed Node ${installedVersion}`);\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 * List installed versions for user reference\n */\nfunction listInstalledVersions(versionsPath: string): void {\n var versions = getAllInstalledVersions(versionsPath);\n\n if (versions.length === 0) {\n console.log(' (none)');\n } else {\n for (var i = 0; i < versions.length; i++) {\n console.log(` ${versions[i]}`);\n }\n }\n}\n"],"names":["exit","fs","path","rmSync","storagePath","findInstalledVersions","getAllInstalledVersions","uninstallCmd","args","length","console","log","version","trim","versionsPath","join","matches","listInstalledVersions","i","installedVersion","versionPath","defaultPath","existsSync","defaultVersion","readFileSync","normalizedDefault","replace","normalizedInstalled","error","err","message","versions"],"mappings":"AAAA,OAAOA,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,MAAM,QAAQ,eAAe;AACtC,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,qBAAqB,EAAEC,uBAAuB,QAAQ,kCAAkC;AAEjG;;;;CAIC,GACD,eAAe,SAASC,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AAQkB,KAAK,CAAC,CAAC,iCAAiC,EAAET,iBAAiB,CAAC,CAAC;YACrET,QAAQkB,KAAK,CAAC;YACdlB,QAAQkB,KAAK,CAAC;YACdlB,QAAQkB,KAAK,CAAC;YACd5B,KAAK;YACL;QACF;IACF;IAEA,+BAA+B;IAC/B,IAAI;QACFG,OAAOiB;QACPV,QAAQC,GAAG,CAAC,CAAC,aAAa,EAAEQ,kBAAkB;IAChD,EAAE,OAAOU,KAAK;QACZnB,QAAQkB,KAAK,CAAC,CAAC,sBAAsB,EAAET,iBAAiB,CAAC,CAAC,EAAE,AAACU,IAAcC,OAAO;QAClF9B,KAAK;QACL;IACF;IAEAA,KAAK;AACP;AAEA;;CAEC,GACD,SAASiB,sBAAsBH,YAAoB;IACjD,IAAIiB,WAAWzB,wBAAwBQ;IAEvC,IAAIiB,SAAStB,MAAM,KAAK,GAAG;QACzBC,QAAQC,GAAG,CAAC;IACd,OAAO;QACL,IAAK,IAAIO,IAAI,GAAGA,IAAIa,SAAStB,MAAM,EAAES,IAAK;YACxCR,QAAQC,GAAG,CAAC,CAAC,EAAE,EAAEoB,QAAQ,CAACb,EAAE,EAAE;QAChC;IACF;AACF"}
|
|
@@ -1 +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 nvu binary would do.\n */\nexport default function whichCmd(_args: string[]): void {\n const cwd = process.cwd();\n\n // Resolve version using the same logic as the nvu binary\n const version = resolveVersion(cwd);\n\n if (!version) {\n console.log('No Node version configured for this directory.');\n console.log('');\n console.log('To configure a version:');\n console.log(' nvu local <version> - Set version for this project');\n console.log(' nvu default <version> - Set global default');\n exit(1);\n return;\n }\n\n // Check if the version is installed\n const versionsPath = path.join(storagePath, 'installed');\n const versionPath = path.join(versionsPath, version);\n const versionPathWithV = path.join(versionsPath, `v${version}`);\n const versionPathWithoutV = path.join(versionsPath, version.replace(/^v/, ''));\n\n let actualVersionPath = '';\n if (fs.existsSync(versionPath)) {\n actualVersionPath = versionPath;\n } else if (fs.existsSync(versionPathWithV)) {\n actualVersionPath = versionPathWithV;\n } else if (fs.existsSync(versionPathWithoutV)) {\n actualVersionPath = versionPathWithoutV;\n }\n\n console.log(`Version: ${version}`);\n console.log(`Source: ${getVersionSource(cwd)}`);\n\n if (actualVersionPath) {\n const nodePath = path.join(actualVersionPath, 'bin', 'node');\n console.log(`Binary: ${nodePath}`);\n if (fs.existsSync(nodePath)) {\n console.log('Status: Installed');\n } else {\n console.log('Status: Directory exists but binary not found');\n }\n } else {\n console.log(`Status: Not installed (run: nvu install ${version})`);\n }\n\n exit(0);\n}\n\n/**\n * Resolve version from config files (mirrors nvu binary logic)\n */\nfunction resolveVersion(cwd: string): string | null {\n // Walk up directories looking for .nvurc or .nvmrc\n let dir = cwd;\n while (true) {\n // Check .nvurc first\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return fs.readFileSync(nvurcPath, 'utf8').trim();\n }\n\n // Check .nvmrc\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return fs.readFileSync(nvmrcPath, 'utf8').trim();\n }\n\n // Move to parent\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n // Check global default\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return fs.readFileSync(defaultPath, 'utf8').trim();\n }\n\n return null;\n}\n\n/**\n * Determine the source of the version (for display)\n */\nfunction getVersionSource(cwd: string): string {\n let dir = cwd;\n while (true) {\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return nvurcPath;\n }\n\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return nvmrcPath;\n }\n\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return `${defaultPath} (global default)`;\n }\n\n return 'none';\n}\n"],"names":["exit","fs","path","storagePath","whichCmd","_args","cwd","process","version","resolveVersion","console","log","versionsPath","join","versionPath","versionPathWithV","versionPathWithoutV","replace","actualVersionPath","existsSync","getVersionSource","nodePath","dir","nvurcPath","readFileSync","trim","nvmrcPath","parent","dirname","defaultPath"],"mappings":"AAAA,OAAOA,UAAU,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/which.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu which\n *\n * Show which Node binary would be used based on current directory.\n * This simulates what the nvu binary would do.\n */\nexport default function whichCmd(_args: string[]): void {\n const cwd = process.cwd();\n\n // Resolve version using the same logic as the nvu binary\n const version = resolveVersion(cwd);\n\n if (!version) {\n console.log('No Node version configured for this directory.');\n console.log('');\n console.log('To configure a version:');\n console.log(' nvu local <version> - Set version for this project');\n console.log(' nvu default <version> - Set global default');\n exit(1);\n return;\n }\n\n // Check if the version is installed\n const versionsPath = path.join(storagePath, 'installed');\n const versionPath = path.join(versionsPath, version);\n const versionPathWithV = path.join(versionsPath, `v${version}`);\n const versionPathWithoutV = path.join(versionsPath, version.replace(/^v/, ''));\n\n let actualVersionPath = '';\n if (fs.existsSync(versionPath)) {\n actualVersionPath = versionPath;\n } else if (fs.existsSync(versionPathWithV)) {\n actualVersionPath = versionPathWithV;\n } else if (fs.existsSync(versionPathWithoutV)) {\n actualVersionPath = versionPathWithoutV;\n }\n\n console.log(`Version: ${version}`);\n console.log(`Source: ${getVersionSource(cwd)}`);\n\n if (actualVersionPath) {\n const nodePath = path.join(actualVersionPath, 'bin', 'node');\n console.log(`Binary: ${nodePath}`);\n if (fs.existsSync(nodePath)) {\n console.log('Status: Installed');\n } else {\n console.log('Status: Directory exists but binary not found');\n }\n } else {\n console.log(`Status: Not installed (run: nvu install ${version})`);\n }\n\n exit(0);\n}\n\n/**\n * Resolve version from config files (mirrors nvu binary logic)\n */\nfunction resolveVersion(cwd: string): string | null {\n // Walk up directories looking for .nvurc or .nvmrc\n let dir = cwd;\n while (true) {\n // Check .nvurc first\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return fs.readFileSync(nvurcPath, 'utf8').trim();\n }\n\n // Check .nvmrc\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return fs.readFileSync(nvmrcPath, 'utf8').trim();\n }\n\n // Move to parent\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n // Check global default\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return fs.readFileSync(defaultPath, 'utf8').trim();\n }\n\n return null;\n}\n\n/**\n * Determine the source of the version (for display)\n */\nfunction getVersionSource(cwd: string): string {\n let dir = cwd;\n while (true) {\n const nvurcPath = path.join(dir, '.nvurc');\n if (fs.existsSync(nvurcPath)) {\n return nvurcPath;\n }\n\n const nvmrcPath = path.join(dir, '.nvmrc');\n if (fs.existsSync(nvmrcPath)) {\n return nvmrcPath;\n }\n\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n const defaultPath = path.join(storagePath, 'default');\n if (fs.existsSync(defaultPath)) {\n return `${defaultPath} (global default)`;\n }\n\n return 'none';\n}\n"],"names":["exit","fs","path","storagePath","whichCmd","_args","cwd","process","version","resolveVersion","console","log","versionsPath","join","versionPath","versionPathWithV","versionPathWithoutV","replace","actualVersionPath","existsSync","getVersionSource","nodePath","dir","nvurcPath","readFileSync","trim","nvmrcPath","parent","dirname","defaultPath"],"mappings":"AAAA,OAAOA,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU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YAAY,iBAAiB,CAAC;IAC1C;IAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find all installed versions matching the given version string
|
|
3
|
+
* Results are sorted in ascending semver order (lowest first, highest last)
|
|
4
|
+
*/
|
|
5
|
+
export declare function findInstalledVersions(versionsPath: string, version: string): string[];
|
|
6
|
+
/**
|
|
7
|
+
* Get all installed versions
|
|
8
|
+
*/
|
|
9
|
+
export declare function getAllInstalledVersions(versionsPath: string): string[];
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { readdirWithTypes } from '../compat.js';
|
|
4
|
+
/**
|
|
5
|
+
* Compare two semver version strings (e.g., "20.19.0" vs "20.9.1")
|
|
6
|
+
* Returns: negative if a < b, positive if a > b, 0 if equal
|
|
7
|
+
*/ function compareVersions(a, b) {
|
|
8
|
+
var aParts = a.replace(/^v/, '').split('.');
|
|
9
|
+
var bParts = b.replace(/^v/, '').split('.');
|
|
10
|
+
var len = Math.max(aParts.length, bParts.length);
|
|
11
|
+
for(var i = 0; i < len; i++){
|
|
12
|
+
var aNum = parseInt(aParts[i], 10) || 0;
|
|
13
|
+
var bNum = parseInt(bParts[i], 10) || 0;
|
|
14
|
+
if (aNum !== bNum) {
|
|
15
|
+
return aNum - bNum;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Find all installed versions matching the given version string
|
|
22
|
+
* Results are sorted in ascending semver order (lowest first, highest last)
|
|
23
|
+
*/ export function findInstalledVersions(versionsPath, version) {
|
|
24
|
+
if (!fs.existsSync(versionsPath)) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
var normalizedVersion = version.replace(/^v/, '');
|
|
28
|
+
var matches = [];
|
|
29
|
+
// Try exact matches first
|
|
30
|
+
var exactMatches = [
|
|
31
|
+
version,
|
|
32
|
+
`v${normalizedVersion}`,
|
|
33
|
+
normalizedVersion
|
|
34
|
+
];
|
|
35
|
+
for(var i = 0; i < exactMatches.length; i++){
|
|
36
|
+
var v = exactMatches[i];
|
|
37
|
+
var versionPath = path.join(versionsPath, v);
|
|
38
|
+
if (fs.existsSync(versionPath) && fs.statSync(versionPath).isDirectory()) {
|
|
39
|
+
if (matches.indexOf(v) === -1) {
|
|
40
|
+
matches.push(v);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// If we have an exact match, return just that
|
|
45
|
+
if (matches.length > 0) {
|
|
46
|
+
return matches;
|
|
47
|
+
}
|
|
48
|
+
// Try partial match (e.g., "20" matches "v20.19.6")
|
|
49
|
+
var entries = readdirWithTypes(versionsPath);
|
|
50
|
+
for(var j = 0; j < entries.length; j++){
|
|
51
|
+
var entry = entries[j];
|
|
52
|
+
if (!entry.isDirectory()) continue;
|
|
53
|
+
var dirVersion = entry.name.replace(/^v/, '');
|
|
54
|
+
if (dirVersion.indexOf(`${normalizedVersion}.`) === 0) {
|
|
55
|
+
matches.push(entry.name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Sort by semver (ascending) so highest version is last
|
|
59
|
+
matches.sort(compareVersions);
|
|
60
|
+
return matches;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get all installed versions
|
|
64
|
+
*/ export function getAllInstalledVersions(versionsPath) {
|
|
65
|
+
if (!fs.existsSync(versionsPath)) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
var entries = readdirWithTypes(versionsPath);
|
|
69
|
+
var versions = [];
|
|
70
|
+
for(var i = 0; i < entries.length; i++){
|
|
71
|
+
if (entries[i].isDirectory()) {
|
|
72
|
+
versions.push(entries[i].name);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return versions;
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/lib/findInstalledVersions.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { readdirWithTypes } from '../compat.ts';\n\n/**\n * Compare two semver version strings (e.g., \"20.19.0\" vs \"20.9.1\")\n * Returns: negative if a < b, positive if a > b, 0 if equal\n */\nfunction compareVersions(a: string, b: string): number {\n var aParts = a.replace(/^v/, '').split('.');\n var bParts = b.replace(/^v/, '').split('.');\n var len = Math.max(aParts.length, bParts.length);\n\n for (var i = 0; i < len; i++) {\n var aNum = parseInt(aParts[i], 10) || 0;\n var bNum = parseInt(bParts[i], 10) || 0;\n if (aNum !== bNum) {\n return aNum - bNum;\n }\n }\n return 0;\n}\n\n/**\n * Find all installed versions matching the given version string\n * Results are sorted in ascending semver order (lowest first, highest last)\n */\nexport function 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 // Sort by semver (ascending) so highest version is last\n matches.sort(compareVersions);\n\n return matches;\n}\n\n/**\n * Get all installed versions\n */\nexport function getAllInstalledVersions(versionsPath: string): string[] {\n if (!fs.existsSync(versionsPath)) {\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 return versions;\n}\n"],"names":["fs","path","readdirWithTypes","compareVersions","a","b","aParts","replace","split","bParts","len","Math","max","length","i","aNum","parseInt","bNum","findInstalledVersions","versionsPath","version","existsSync","normalizedVersion","matches","exactMatches","v","versionPath","join","statSync","isDirectory","indexOf","push","entries","j","entry","dirVersion","name","sort","getAllInstalledVersions","versions"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,gBAAgB,QAAQ,eAAe;AAEhD;;;CAGC,GACD,SAASC,gBAAgBC,CAAS,EAAEC,CAAS;IAC3C,IAAIC,SAASF,EAAEG,OAAO,CAAC,MAAM,IAAIC,KAAK,CAAC;IACvC,IAAIC,SAASJ,EAAEE,OAAO,CAAC,MAAM,IAAIC,KAAK,CAAC;IACvC,IAAIE,MAAMC,KAAKC,GAAG,CAACN,OAAOO,MAAM,EAAEJ,OAAOI,MAAM;IAE/C,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,KAAKI,IAAK;QAC5B,IAAIC,OAAOC,SAASV,MAAM,CAACQ,EAAE,EAAE,OAAO;QACtC,IAAIG,OAAOD,SAASP,MAAM,CAACK,EAAE,EAAE,OAAO;QACtC,IAAIC,SAASE,MAAM;YACjB,OAAOF,OAAOE;QAChB;IACF;IACA,OAAO;AACT;AAEA;;;CAGC,GACD,OAAO,SAASC,sBAAsBC,YAAoB,EAAEC,OAAe;IACzE,IAAI,CAACpB,GAAGqB,UAAU,CAACF,eAAe;QAChC,OAAO,EAAE;IACX;IAEA,IAAIG,oBAAoBF,QAAQb,OAAO,CAAC,MAAM;IAC9C,IAAIgB,UAAoB,EAAE;IAE1B,0BAA0B;IAC1B,IAAIC,eAAe;QAACJ;QAAS,CAAC,CAAC,EAAEE,mBAAmB;QAAEA;KAAkB;IACxE,IAAK,I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json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-version-use",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Cross-platform solution for using multiple versions of node. Useful for compatibility testing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"cross-spawn-cb": "^2.4.10",
|
|
52
|
-
"exit": "^0.
|
|
52
|
+
"exit-compat": "^1.0.0",
|
|
53
53
|
"fs-remove-compat": "^0.2.1",
|
|
54
54
|
"getopts-compat": "^2.2.6",
|
|
55
55
|
"homedir-polyfill": "^1.0.3",
|
|
56
|
-
"install-module-linked": "^1.3.
|
|
56
|
+
"install-module-linked": "^1.3.12",
|
|
57
57
|
"mkdirp-classic": "^0.5.3",
|
|
58
58
|
"node-resolve-versions": "^1.3.11",
|
|
59
59
|
"node-version-utils": "^1.3.15",
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
"fs-remove-compat": "^0.2.1",
|
|
71
71
|
"is-version": "^1.0.7",
|
|
72
72
|
"mkdirp-classic": "^0.5.3",
|
|
73
|
-
"node-version-install": "^1.
|
|
74
|
-
"node-version-use": "^2.
|
|
73
|
+
"node-version-install": "^1.5.0",
|
|
74
|
+
"node-version-use": "^2.1.1",
|
|
75
75
|
"os-shim": "^0.1.3",
|
|
76
76
|
"pinkie-promise": "^2.0.1",
|
|
77
|
-
"ts-dev-stack": "^1.21.
|
|
77
|
+
"ts-dev-stack": "^1.21.3",
|
|
78
78
|
"tsds-config": "^0.2.0"
|
|
79
79
|
},
|
|
80
80
|
"engines": {
|
package/scripts/postinstall.cjs
CHANGED