node-version-use 2.1.9 → 2.1.10

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.
@@ -65,10 +65,7 @@ function removeIfExistsSync(filePath) {
65
65
  * Atomic rename with fallback to copy+delete for cross-device moves
66
66
  */ function atomicRename(src, dest, callback) {
67
67
  fs.rename(src, dest, function(err) {
68
- if (!err) {
69
- callback(null);
70
- return;
71
- }
68
+ if (!err) return callback(null);
72
69
  // Cross-device link error - fall back to copy + delete
73
70
  if (err.code === 'EXDEV') {
74
71
  try {
@@ -199,7 +196,7 @@ function removeIfExistsSync(filePath) {
199
196
  /**
200
197
  * Print setup instructions
201
198
  */ module.exports.printInstructions = function printInstructions() {
202
- var nvuBinPath = path.join(storagePath, 'bin');
199
+ var _nvuBinPath = path.join(storagePath, 'bin');
203
200
  console.log('nvu binaries installed in ~/.nvu/bin/');
204
201
  var pathKey = envPathKey();
205
202
  var envPath = process.env[pathKey] || '';
@@ -211,11 +208,14 @@ function removeIfExistsSync(filePath) {
211
208
  console.log('============================================================');
212
209
  console.log('');
213
210
  if (isWindows) {
214
- console.log(' PowerShell (add to $PROFILE):');
215
- console.log(' $env:PATH = "'.concat(nvuBinPath, ';$env:PATH"'));
211
+ console.log(' # Edit your PowerShell profile');
212
+ console.log(' # Open with: notepad $PROFILE');
213
+ console.log(' # Add this line:');
214
+ console.log(' $env:PATH = "$HOME\\.nvu\\bin;$env:APPDATA\\npm;$env:PATH"');
216
215
  console.log('');
217
- console.log(' CMD (run as administrator):');
218
- console.log(' setx PATH "'.concat(nvuBinPath, ';%PATH%"'));
216
+ console.log(' # This adds:');
217
+ console.log(' # ~/.nvu/bin - node/npm version switching shims');
218
+ console.log(' # %APPDATA%/npm - globally installed npm packages (like nvu)');
219
219
  } else {
220
220
  console.log(' # For bash (~/.bashrc):');
221
221
  console.log(' echo \'export PATH="$HOME/.nvu/bin:$PATH"\' >> ~/.bashrc');
@@ -270,10 +270,7 @@ function removeIfExistsSync(filePath) {
270
270
  console.log('Extracting binary...');
271
271
  extractAndInstall(tempPath, binDir, extractedBinaryName, function(err) {
272
272
  removeIfExistsSync(tempPath);
273
- if (err) {
274
- callback(err);
275
- return;
276
- }
273
+ if (err) return callback(err);
277
274
  // save binary version for upgrade checks
278
275
  fs.writeFileSync(path.join(binDir, 'version.txt'), BINARY_VERSION, 'utf8');
279
276
  console.log('Binary installed successfully!');
@@ -65,10 +65,7 @@ function removeIfExistsSync(filePath) {
65
65
  * Atomic rename with fallback to copy+delete for cross-device moves
66
66
  */ function atomicRename(src, dest, callback) {
67
67
  fs.rename(src, dest, function(err) {
68
- if (!err) {
69
- callback(null);
70
- return;
71
- }
68
+ if (!err) return callback(null);
72
69
  // Cross-device link error - fall back to copy + delete
73
70
  if (err.code === 'EXDEV') {
74
71
  try {
@@ -199,7 +196,7 @@ function removeIfExistsSync(filePath) {
199
196
  /**
200
197
  * Print setup instructions
201
198
  */ module.exports.printInstructions = function printInstructions() {
202
- var nvuBinPath = path.join(storagePath, 'bin');
199
+ var _nvuBinPath = path.join(storagePath, 'bin');
203
200
  console.log('nvu binaries installed in ~/.nvu/bin/');
204
201
  var pathKey = envPathKey();
205
202
  var envPath = process.env[pathKey] || '';
@@ -211,11 +208,14 @@ function removeIfExistsSync(filePath) {
211
208
  console.log('============================================================');
212
209
  console.log('');
213
210
  if (isWindows) {
214
- console.log(' PowerShell (add to $PROFILE):');
215
- console.log(' $env:PATH = "'.concat(nvuBinPath, ';$env:PATH"'));
211
+ console.log(' # Edit your PowerShell profile');
212
+ console.log(' # Open with: notepad $PROFILE');
213
+ console.log(' # Add this line:');
214
+ console.log(' $env:PATH = "$HOME\\.nvu\\bin;$env:APPDATA\\npm;$env:PATH"');
216
215
  console.log('');
217
- console.log(' CMD (run as administrator):');
218
- console.log(' setx PATH "'.concat(nvuBinPath, ';%PATH%"'));
216
+ console.log(' # This adds:');
217
+ console.log(' # ~/.nvu/bin - node/npm version switching shims');
218
+ console.log(' # %APPDATA%/npm - globally installed npm packages (like nvu)');
219
219
  } else {
220
220
  console.log(' # For bash (~/.bashrc):');
221
221
  console.log(' echo \'export PATH="$HOME/.nvu/bin:$PATH"\' >> ~/.bashrc');
@@ -270,10 +270,7 @@ function removeIfExistsSync(filePath) {
270
270
  console.log('Extracting binary...');
271
271
  extractAndInstall(tempPath, binDir, extractedBinaryName, function(err) {
272
272
  removeIfExistsSync(tempPath);
273
- if (err) {
274
- callback(err);
275
- return;
276
- }
273
+ if (err) return callback(err);
277
274
  // save binary version for upgrade checks
278
275
  fs.writeFileSync(path.join(binDir, 'version.txt'), BINARY_VERSION, 'utf8');
279
276
  console.log('Binary installed successfully!');
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/assets/installBinaries.cts"],"sourcesContent":["const envPathKey = require('env-path-key');\nconst fs = require('fs');\nconst { safeRmSync } = require('fs-remove-compat');\nconst getFile = require('get-file-compat');\nconst mkdirp = require('mkdirp-classic');\nconst os = require('os');\nconst path = require('path');\nconst Queue = require('queue-cb');\nconst moduleRoot = require('module-root-sync');\n\nconst root = moduleRoot(__dirname);\n\n// Configuration\nconst GITHUB_REPO = 'kmalakoff/node-version-use';\nconst BINARY_VERSION = require(path.join(root, 'package.json')).binaryVersion;\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\ntype Callback = (err?: Error | null) => void;\n\ninterface PlatformMap {\n [key: string]: string;\n}\n\nconst hasHomedir = typeof os.homedir === 'function';\nfunction homedir(): string {\n if (hasHomedir) return os.homedir();\n const home = require('homedir-polyfill');\n return home();\n}\n\n// Allow NVU_HOME override for testing\nconst storagePath = (process.env.NVU_HOME || path.join(homedir(), '.nvu')) as string;\n\nconst hasTmpdir = typeof os.tmpdir === 'function';\nfunction tmpdir(): string {\n if (hasTmpdir) return os.tmpdir();\n const osShim = require('os-shim');\n return osShim.tmpdir();\n}\n\nfunction removeIfExistsSync(filePath: string): void {\n if (fs.existsSync(filePath)) {\n try {\n fs.unlinkSync(filePath);\n } catch (_e) {\n // ignore cleanup errors\n }\n }\n}\n\n/**\n * Get the platform-specific archive base name (without extension)\n */\nfunction getArchiveBaseName(): string | null {\n const { platform, arch } = process;\n\n const platformMap: PlatformMap = {\n darwin: 'darwin',\n linux: 'linux',\n win32: 'win32',\n };\n\n const archMap: PlatformMap = {\n x64: 'x64',\n arm64: 'arm64',\n amd64: 'x64',\n };\n\n const platformName = platformMap[platform];\n const archName = archMap[arch];\n\n if (!platformName || !archName) return null;\n return `nvu-binary-${platformName}-${archName}`;\n}\n\n/**\n * Copy file\n */\nfunction copyFileSync(src: string, dest: string): void {\n const content = fs.readFileSync(src);\n fs.writeFileSync(dest, content);\n}\n\n/**\n * Atomic rename with fallback to copy+delete for cross-device moves\n */\nfunction atomicRename(src: string, dest: string, callback: Callback): void {\n fs.rename(src, dest, (err) => {\n if (!err) {\n callback(null);\n return;\n }\n\n // Cross-device link error - fall back to copy + delete\n if ((err as NodeJS.ErrnoException).code === 'EXDEV') {\n try {\n copyFileSync(src, dest);\n fs.unlinkSync(src);\n callback(null);\n } catch (copyErr) {\n callback(copyErr as Error);\n }\n return;\n }\n\n callback(err);\n });\n}\n\n/**\n * Extract archive to a directory (callback-based)\n */\nfunction extractArchive(archivePath: string, dest: string, callback: Callback): void {\n const Iterator = isWindows ? require('zip-iterator') : require('tar-iterator');\n const stream = isWindows ? fs.createReadStream(archivePath) : fs.createReadStream(archivePath).pipe(require('zlib').createGunzip());\n let iterator = new Iterator(stream);\n\n // one by one\n const links = [];\n iterator.forEach(\n (entry, callback) => {\n if (entry.type === 'link') {\n links.unshift(entry);\n callback();\n } else if (entry.type === 'symlink') {\n links.push(entry);\n callback();\n } else entry.create(dest, callback);\n },\n { callbacks: true, concurrency: 1 },\n (_err) => {\n // create links after directories and files\n const queue = new Queue();\n for (let index = 0; index < links.length; index++) {\n const entry = links[index];\n queue.defer(entry.create.bind(entry, dest));\n }\n queue.await((err) => {\n iterator.destroy();\n iterator = null;\n callback(err);\n });\n }\n );\n}\n\n/**\n * Install binaries using atomic rename pattern\n * 1. Extract to temp directory\n * 2. Copy binary to temp files in destination directory\n * 3. Atomic rename temp files to final names\n */\nfunction extractAndInstall(archivePath: string, destDir: string, binaryName: string, callback: Callback): void {\n const ext = isWindows ? '.exe' : '';\n\n // Create temp extraction directory\n const tempExtractDir = path.join(tmpdir(), `nvu-extract-${Date.now()}`);\n mkdirp.sync(tempExtractDir);\n\n extractArchive(archivePath, tempExtractDir, (err) => {\n if (err) {\n safeRmSync(tempExtractDir);\n callback(err);\n return;\n }\n\n const extractedPath = path.join(tempExtractDir, binaryName);\n if (!fs.existsSync(extractedPath)) {\n safeRmSync(tempExtractDir);\n callback(new Error(`Extracted binary not found: ${binaryName}. ${archivePath} ${tempExtractDir}`));\n return;\n }\n\n // Binary names to install\n const binaries = ['node', 'npm', 'npx', 'corepack'];\n const timestamp = Date.now();\n let installError: Error | null = null;\n\n // Step 1: Copy extracted binary to temp files in destination directory\n // This ensures the temp files are on the same filesystem for atomic rename\n for (let i = 0; i < binaries.length; i++) {\n const name = binaries[i];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n\n try {\n // Copy to temp file in destination directory\n copyFileSync(extractedPath, tempDest);\n\n // Set permissions on Unix\n if (!isWindows) fs.chmodSync(tempDest, 0o755);\n } catch (err) {\n installError = err as Error;\n break;\n }\n }\n\n if (installError) {\n // Clean up any temp files we created\n for (let j = 0; j < binaries.length; j++) {\n const tempPath = path.join(destDir, `${binaries[j]}.tmp-${timestamp}${ext}`);\n removeIfExistsSync(tempPath);\n }\n safeRmSync(tempExtractDir);\n callback(installError);\n return;\n }\n\n // Step 2: Atomic rename temp files to final names\n let renameError: Error | null = null;\n\n function doRename(index: number): void {\n if (index >= binaries.length) {\n // All renames complete\n safeRmSync(tempExtractDir);\n callback(renameError);\n return;\n }\n\n const name = binaries[index];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n const finalDest = path.join(destDir, `${name}${ext}`);\n\n // Remove existing file if present (for atomic replacement)\n removeIfExistsSync(finalDest);\n\n atomicRename(tempDest, finalDest, (err) => {\n if (err && !renameError) {\n renameError = err;\n }\n doRename(index + 1);\n });\n }\n\n doRename(0);\n });\n}\n\n/**\n * Print setup instructions\n */\nmodule.exports.printInstructions = function printInstructions(): void {\n const nvuBinPath = path.join(storagePath, 'bin');\n\n console.log('nvu binaries installed in ~/.nvu/bin/');\n\n const pathKey = envPathKey();\n const envPath = process.env[pathKey] || '';\n if (envPath.indexOf('.nvu/bin') >= 0) return; // path exists\n\n // provide instructions for path setup\n console.log('');\n console.log('============================================================');\n console.log(' Global node setup');\n console.log('============================================================');\n console.log('');\n if (isWindows) {\n console.log(' PowerShell (add to $PROFILE):');\n console.log(` $env:PATH = \"${nvuBinPath};$env:PATH\"`);\n console.log('');\n console.log(' CMD (run as administrator):');\n console.log(` setx PATH \"${nvuBinPath};%PATH%\"`);\n } else {\n console.log(' # For bash (~/.bashrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.bashrc');\n console.log('');\n console.log(' # For zsh (~/.zshrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.zshrc');\n console.log('');\n console.log(' # For fish (~/.config/fish/config.fish):');\n console.log(\" echo 'set -gx PATH $HOME/.nvu/bin $PATH' >> ~/.config/fish/config.fish\");\n }\n\n console.log('');\n console.log('Then restart your terminal or source your shell profile.');\n console.log('');\n console.log(\"Without this, 'nvu 18 npm test' still works - you just won't have\");\n console.log(\"transparent 'node' command override.\");\n console.log('============================================================');\n};\n\n/**\n * Main installation function\n */\nmodule.exports.installBinaries = function installBinaries(options, callback): void {\n const archiveBaseName = getArchiveBaseName();\n\n if (!archiveBaseName) {\n callback(new Error('Unsupported platform/architecture for binary.'));\n return;\n }\n\n const extractedBinaryName = `${archiveBaseName}${isWindows ? '.exe' : ''}`;\n const binDir = path.join(storagePath, 'bin');\n\n // check if we need to upgrade\n if (!options.force) {\n try {\n // already installed\n if (fs.statSync(binDir)) {\n if (fs.readFileSync(path.join(binDir, 'version.txt'), 'utf8') === BINARY_VERSION) {\n callback(null, false);\n return;\n }\n }\n } catch (_err) {}\n }\n\n // Create directories\n mkdirp.sync(storagePath);\n mkdirp.sync(binDir);\n\n const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/binary-v${BINARY_VERSION}/${archiveBaseName}${isWindows ? '.zip' : '.tar.gz'}`;\n const tempPath = path.join(tmpdir(), `nvu-binary-${Date.now()}${isWindows ? '.zip' : '.tar.gz'}`);\n\n console.log(`Downloading binary for ${process.platform}-${process.arch}...`);\n\n getFile(downloadUrl, tempPath, (err) => {\n if (err) {\n removeIfExistsSync(tempPath);\n callback(new Error(`No prebuilt binary available for ${process.platform}-${process.arch}. Download: ${downloadUrl}. Error: ${err.message}`));\n return;\n }\n\n console.log('Extracting binary...');\n\n extractAndInstall(tempPath, binDir, extractedBinaryName, (err) => {\n removeIfExistsSync(tempPath);\n if (err) {\n callback(err);\n return;\n }\n\n // save binary version for upgrade checks\n fs.writeFileSync(path.join(binDir, 'version.txt'), BINARY_VERSION, 'utf8');\n console.log('Binary installed successfully!');\n callback(null, true);\n });\n });\n};\n"],"names":["envPathKey","require","fs","safeRmSync","getFile","mkdirp","os","path","Queue","moduleRoot","root","__dirname","GITHUB_REPO","BINARY_VERSION","join","binaryVersion","isWindows","process","platform","test","env","OSTYPE","hasHomedir","homedir","home","storagePath","NVU_HOME","hasTmpdir","tmpdir","osShim","removeIfExistsSync","filePath","existsSync","unlinkSync","_e","getArchiveBaseName","arch","platformMap","darwin","linux","win32","archMap","x64","arm64","amd64","platformName","archName","copyFileSync","src","dest","content","readFileSync","writeFileSync","atomicRename","callback","rename","err","code","copyErr","extractArchive","archivePath","Iterator","stream","createReadStream","pipe","createGunzip","iterator","links","forEach","entry","type","unshift","push","create","callbacks","concurrency","_err","queue","index","length","defer","bind","await","destroy","extractAndInstall","destDir","binaryName","ext","tempExtractDir","Date","now","sync","extractedPath","Error","binaries","timestamp","installError","i","name","tempDest","chmodSync","j","tempPath","renameError","doRename","finalDest","module","exports","printInstructions","nvuBinPath","console","log","pathKey","envPath","indexOf","installBinaries","options","archiveBaseName","extractedBinaryName","binDir","force","statSync","downloadUrl","message"],"mappings":";AAAA,IAAMA,aAAaC,QAAQ;AAC3B,IAAMC,KAAKD,QAAQ;AACnB,IAAM,AAAEE,aAAeF,QAAQ,oBAAvBE;AACR,IAAMC,UAAUH,QAAQ;AACxB,IAAMI,SAASJ,QAAQ;AACvB,IAAMK,KAAKL,QAAQ;AACnB,IAAMM,OAAON,QAAQ;AACrB,IAAMO,QAAQP,QAAQ;AACtB,IAAMQ,aAAaR,QAAQ;AAE3B,IAAMS,OAAOD,WAAWE;AAExB,gBAAgB;AAChB,IAAMC,cAAc;AACpB,IAAMC,iBAAiBZ,QAAQM,KAAKO,IAAI,CAACJ,MAAM,iBAAiBK,aAAa;AAE7E,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAQ3F,IAAMC,aAAa,OAAOhB,GAAGiB,OAAO,KAAK;AACzC,SAASA;IACP,IAAID,YAAY,OAAOhB,GAAGiB,OAAO;IACjC,IAAMC,OAAOvB,QAAQ;IACrB,OAAOuB;AACT;AAEA,sCAAsC;AACtC,IAAMC,cAAeR,QAAQG,GAAG,CAACM,QAAQ,IAAInB,KAAKO,IAAI,CAACS,WAAW;AAElE,IAAMI,YAAY,OAAOrB,GAAGsB,MAAM,KAAK;AACvC,SAASA;IACP,IAAID,WAAW,OAAOrB,GAAGsB,MAAM;IAC/B,IAAMC,SAAS5B,QAAQ;IACvB,OAAO4B,OAAOD,MAAM;AACtB;AAEA,SAASE,mBAAmBC,QAAgB;IAC1C,IAAI7B,GAAG8B,UAAU,CAACD,WAAW;QAC3B,IAAI;YACF7B,GAAG+B,UAAU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AZlE,IAAImE,OAAO;YACxI;QACF;QAEAb,QAAQC,GAAG,CAAC;QAEZ3B,kBAAkBkB,UAAUiB,QAAQD,qBAAqB,SAAC9D;YACxD1B,mBAAmBwE;YACnB,IAAI9C,KAAK;gBACPF,SAASE;gBACT;YACF;YAEA,yCAAyC;YACzCtD,GAAGkD,aAAa,CAAC7C,KAAKO,IAAI,CAACyG,QAAQ,gBAAgB1G,gBAAgB;YACnEiG,QAAQC,GAAG,CAAC;YACZzD,SAAS,MAAM;QACjB;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/assets/installBinaries.cts"],"sourcesContent":["const envPathKey = require('env-path-key');\nconst fs = require('fs');\nconst { safeRmSync } = require('fs-remove-compat');\nconst getFile = require('get-file-compat');\nconst mkdirp = require('mkdirp-classic');\nconst os = require('os');\nconst path = require('path');\nconst Queue = require('queue-cb');\nconst moduleRoot = require('module-root-sync');\n\nconst root = moduleRoot(__dirname);\n\n// Configuration\nconst GITHUB_REPO = 'kmalakoff/node-version-use';\nconst BINARY_VERSION = require(path.join(root, 'package.json')).binaryVersion;\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\ntype Callback = (err?: Error | null) => void;\n\ninterface PlatformMap {\n [key: string]: string;\n}\n\nconst hasHomedir = typeof os.homedir === 'function';\nfunction homedir(): string {\n if (hasHomedir) return os.homedir();\n const home = require('homedir-polyfill');\n return home();\n}\n\n// Allow NVU_HOME override for testing\nconst storagePath = (process.env.NVU_HOME || path.join(homedir(), '.nvu')) as string;\n\nconst hasTmpdir = typeof os.tmpdir === 'function';\nfunction tmpdir(): string {\n if (hasTmpdir) return os.tmpdir();\n const osShim = require('os-shim');\n return osShim.tmpdir();\n}\n\nfunction removeIfExistsSync(filePath: string): void {\n if (fs.existsSync(filePath)) {\n try {\n fs.unlinkSync(filePath);\n } catch (_e) {\n // ignore cleanup errors\n }\n }\n}\n\n/**\n * Get the platform-specific archive base name (without extension)\n */\nfunction getArchiveBaseName(): string | null {\n const { platform, arch } = process;\n\n const platformMap: PlatformMap = {\n darwin: 'darwin',\n linux: 'linux',\n win32: 'win32',\n };\n\n const archMap: PlatformMap = {\n x64: 'x64',\n arm64: 'arm64',\n amd64: 'x64',\n };\n\n const platformName = platformMap[platform];\n const archName = archMap[arch];\n\n if (!platformName || !archName) return null;\n return `nvu-binary-${platformName}-${archName}`;\n}\n\n/**\n * Copy file\n */\nfunction copyFileSync(src: string, dest: string): void {\n const content = fs.readFileSync(src);\n fs.writeFileSync(dest, content);\n}\n\n/**\n * Atomic rename with fallback to copy+delete for cross-device moves\n */\nfunction atomicRename(src: string, dest: string, callback: Callback) {\n fs.rename(src, dest, (err) => {\n if (!err) return callback(null);\n\n // Cross-device link error - fall back to copy + delete\n if ((err as NodeJS.ErrnoException).code === 'EXDEV') {\n try {\n copyFileSync(src, dest);\n fs.unlinkSync(src);\n callback(null);\n } catch (copyErr) {\n callback(copyErr as Error);\n }\n return;\n }\n\n callback(err);\n });\n}\n\n/**\n * Extract archive to a directory (callback-based)\n */\nfunction extractArchive(archivePath: string, dest: string, callback: Callback) {\n const Iterator = isWindows ? require('zip-iterator') : require('tar-iterator');\n const stream = isWindows ? fs.createReadStream(archivePath) : fs.createReadStream(archivePath).pipe(require('zlib').createGunzip());\n let iterator = new Iterator(stream);\n\n // one by one\n const links = [];\n iterator.forEach(\n (entry, callback) => {\n if (entry.type === 'link') {\n links.unshift(entry);\n callback();\n } else if (entry.type === 'symlink') {\n links.push(entry);\n callback();\n } else entry.create(dest, callback);\n },\n { callbacks: true, concurrency: 1 },\n (_err) => {\n // create links after directories and files\n const queue = new Queue();\n for (let index = 0; index < links.length; index++) {\n const entry = links[index];\n queue.defer(entry.create.bind(entry, dest));\n }\n queue.await((err) => {\n iterator.destroy();\n iterator = null;\n callback(err);\n });\n }\n );\n}\n\n/**\n * Install binaries using atomic rename pattern\n * 1. Extract to temp directory\n * 2. Copy binary to temp files in destination directory\n * 3. Atomic rename temp files to final names\n */\nfunction extractAndInstall(archivePath: string, destDir: string, binaryName: string, callback: Callback) {\n const ext = isWindows ? '.exe' : '';\n\n // Create temp extraction directory\n const tempExtractDir = path.join(tmpdir(), `nvu-extract-${Date.now()}`);\n mkdirp.sync(tempExtractDir);\n\n extractArchive(archivePath, tempExtractDir, (err) => {\n if (err) {\n safeRmSync(tempExtractDir);\n callback(err);\n return;\n }\n\n const extractedPath = path.join(tempExtractDir, binaryName);\n if (!fs.existsSync(extractedPath)) {\n safeRmSync(tempExtractDir);\n callback(new Error(`Extracted binary not found: ${binaryName}. ${archivePath} ${tempExtractDir}`));\n return;\n }\n\n // Binary names to install\n const binaries = ['node', 'npm', 'npx', 'corepack'];\n const timestamp = Date.now();\n let installError: Error | null = null;\n\n // Step 1: Copy extracted binary to temp files in destination directory\n // This ensures the temp files are on the same filesystem for atomic rename\n for (let i = 0; i < binaries.length; i++) {\n const name = binaries[i];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n\n try {\n // Copy to temp file in destination directory\n copyFileSync(extractedPath, tempDest);\n\n // Set permissions on Unix\n if (!isWindows) fs.chmodSync(tempDest, 0o755);\n } catch (err) {\n installError = err as Error;\n break;\n }\n }\n\n if (installError) {\n // Clean up any temp files we created\n for (let j = 0; j < binaries.length; j++) {\n const tempPath = path.join(destDir, `${binaries[j]}.tmp-${timestamp}${ext}`);\n removeIfExistsSync(tempPath);\n }\n safeRmSync(tempExtractDir);\n callback(installError);\n return;\n }\n\n // Step 2: Atomic rename temp files to final names\n let renameError: Error | null = null;\n\n function doRename(index: number): void {\n if (index >= binaries.length) {\n // All renames complete\n safeRmSync(tempExtractDir);\n callback(renameError);\n return;\n }\n\n const name = binaries[index];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n const finalDest = path.join(destDir, `${name}${ext}`);\n\n // Remove existing file if present (for atomic replacement)\n removeIfExistsSync(finalDest);\n\n atomicRename(tempDest, finalDest, (err) => {\n if (err && !renameError) {\n renameError = err;\n }\n doRename(index + 1);\n });\n }\n\n doRename(0);\n });\n}\n\n/**\n * Print setup instructions\n */\nmodule.exports.printInstructions = function printInstructions(): void {\n const _nvuBinPath = path.join(storagePath, 'bin');\n\n console.log('nvu binaries installed in ~/.nvu/bin/');\n\n const pathKey = envPathKey();\n const envPath = process.env[pathKey] || '';\n if (envPath.indexOf('.nvu/bin') >= 0) return; // path exists\n\n // provide instructions for path setup\n console.log('');\n console.log('============================================================');\n console.log(' Global node setup');\n console.log('============================================================');\n console.log('');\n if (isWindows) {\n console.log(' # Edit your PowerShell profile');\n console.log(' # Open with: notepad $PROFILE');\n console.log(' # Add this line:');\n console.log(' $env:PATH = \"$HOME\\\\.nvu\\\\bin;$env:APPDATA\\\\npm;$env:PATH\"');\n console.log('');\n console.log(' # This adds:');\n console.log(' # ~/.nvu/bin - node/npm version switching shims');\n console.log(' # %APPDATA%/npm - globally installed npm packages (like nvu)');\n } else {\n console.log(' # For bash (~/.bashrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.bashrc');\n console.log('');\n console.log(' # For zsh (~/.zshrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.zshrc');\n console.log('');\n console.log(' # For fish (~/.config/fish/config.fish):');\n console.log(\" echo 'set -gx PATH $HOME/.nvu/bin $PATH' >> ~/.config/fish/config.fish\");\n }\n\n console.log('');\n console.log('Then restart your terminal or source your shell profile.');\n console.log('');\n console.log(\"Without this, 'nvu 18 npm test' still works - you just won't have\");\n console.log(\"transparent 'node' command override.\");\n console.log('============================================================');\n};\n\n/**\n * Main installation function\n */\nmodule.exports.installBinaries = function installBinaries(options, callback): void {\n const archiveBaseName = getArchiveBaseName();\n\n if (!archiveBaseName) {\n callback(new Error('Unsupported platform/architecture for binary.'));\n return;\n }\n\n const extractedBinaryName = `${archiveBaseName}${isWindows ? '.exe' : ''}`;\n const binDir = path.join(storagePath, 'bin');\n\n // check if we need to upgrade\n if (!options.force) {\n try {\n // already installed\n if (fs.statSync(binDir)) {\n if (fs.readFileSync(path.join(binDir, 'version.txt'), 'utf8') === BINARY_VERSION) {\n callback(null, false);\n return;\n }\n }\n } catch (_err) {}\n }\n\n // Create directories\n mkdirp.sync(storagePath);\n mkdirp.sync(binDir);\n\n const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/binary-v${BINARY_VERSION}/${archiveBaseName}${isWindows ? '.zip' : '.tar.gz'}`;\n const tempPath = path.join(tmpdir(), `nvu-binary-${Date.now()}${isWindows ? '.zip' : '.tar.gz'}`);\n\n console.log(`Downloading binary for ${process.platform}-${process.arch}...`);\n\n getFile(downloadUrl, tempPath, (err) => {\n if (err) {\n removeIfExistsSync(tempPath);\n callback(new Error(`No prebuilt binary available for ${process.platform}-${process.arch}. Download: ${downloadUrl}. Error: ${err.message}`));\n return;\n }\n\n console.log('Extracting binary...');\n\n extractAndInstall(tempPath, binDir, extractedBinaryName, (err) => {\n removeIfExistsSync(tempPath);\n if (err) return callback(err);\n\n // save binary version for upgrade checks\n fs.writeFileSync(path.join(binDir, 'version.txt'), BINARY_VERSION, 'utf8');\n console.log('Binary installed successfully!');\n callback(null, true);\n });\n });\n};\n"],"names":["envPathKey","require","fs","safeRmSync","getFile","mkdirp","os","path","Queue","moduleRoot","root","__dirname","GITHUB_REPO","BINARY_VERSION","join","binaryVersion","isWindows","process","platform","test","env","OSTYPE","hasHomedir","homedir","home","storagePath","NVU_HOME","hasTmpdir","tmpdir","osShim","removeIfExistsSync","filePath","existsSync","unlinkSync","_e","getArchiveBaseName","arch","platformMap","darwin","linux","win32","archMap","x64","arm64","amd64","platformName","archName","copyFileSync","src","dest","content","readFileSync","writeFileSync","atomicRename","callback","rename","err","code","copyErr","extractArchive","archivePath","Iterator","stream","createReadStream","pipe","createGunzip","iterator","links","forEach","entry","type","unshift","push","create","callbacks","concurrency","_err","queue","index","length","defer","bind","await","destroy","extractAndInstall","destDir","binaryName","ext","tempExtractDir","Date","now","sync","extractedPath","Error","binaries","timestamp","installError","i","name","tempDest","chmodSync","j","tempPath","renameError","doRename","finalDest","module","exports","printInstructions","_nvuBinPath","console","log","pathKey","envPath","indexOf","installBinaries","options","archiveBaseName","extractedBinaryName","binDir","force","statSync","downloadUrl","message"],"mappings":";AAAA,IAAMA,aAAaC,QAAQ;AAC3B,IAAMC,KAAKD,QAAQ;AACnB,IAAM,AAAEE,aAAeF,QAAQ,oBAAvBE;AACR,IAAMC,UAAUH,QAAQ;AACxB,IAAMI,SAASJ,QAAQ;AACvB,IAAMK,KAAKL,QAAQ;AACnB,IAAMM,OAAON,QAAQ;AACrB,IAAMO,QAAQP,QAAQ;AACtB,IAAMQ,aAAaR,QAAQ;AAE3B,IAAMS,OAAOD,WAAWE;AAExB,gBAAgB;AAChB,IAAMC,cAAc;AACpB,IAAMC,iBAAiBZ,QAAQM,KAAKO,IAAI,CAACJ,MAAM,iBAAiBK,aAAa;AAE7E,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAQ3F,IAAMC,aAAa,OAAOhB,GAAGiB,OAAO,KAAK;AACzC,SAASA;IACP,IAAID,YAAY,OAAOhB,GAAGiB,OAAO;IACjC,IAAMC,OAAOvB,QAAQ;IACrB,OAAOuB;AACT;AAEA,sCAAsC;AACtC,IAAMC,cAAeR,QAAQG,GAAG,CAACM,QAAQ,IAAInB,KAAKO,IAAI,CAACS,WAAW;AAElE,IAAMI,YAAY,OAAOrB,GAAGsB,MAAM,KAAK;AACvC,SAASA;IACP,IAAID,WAAW,OAAOrB,GAAGsB,MAAM;IAC/B,IAAMC,SAAS5B,QAAQ;IACvB,OAAO4B,OAAOD,MAAM;AACtB;AAEA,SAASE,mBAAmBC,QAAgB;IAC1C,IAAI7B,GAAG8B,UAAU,CAACD,WAAW;QAC3B,IAAI;YACF7B,GAAG+B,UAAU,CAACF;QAChB,EAAE,OAAOG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;YACxI;QACF;QAEAb,QAAQC,GAAG,CAAC;QAEZ3B,kBAAkBkB,UAAUiB,QAAQD,qBAAqB,SAAC9D;YACxD1B,mBAAmBwE;YACnB,IAAI9C,KAAK,OAAOF,SAASE;YAEzB,yCAAyC;YACzCtD,GAAGkD,aAAa,CAAC7C,KAAKO,IAAI,CAACyG,QAAQ,gBAAgB1G,gBAAgB;YACnEiG,QAAQC,GAAG,CAAC;YACZzD,SAAS,MAAM;QACjB;IACF;AACF"}
@@ -1,2 +1,2 @@
1
- declare const _default: (argv: string[], name: string) => undefined;
1
+ declare const _default: (argv: string[], name: string) => void;
2
2
  export default _default;
package/dist/cjs/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: (argv: string[], name: string) => undefined;
1
+ declare const _default: (argv: string[], name: string) => void;
2
2
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/cli.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport getopts from 'getopts-compat';\nimport path from 'path';\nimport { createSession, figures, formatArguments } from 'spawn-term';\nimport url from 'url';\nimport { isCommand, runCommand } from './commands/index.ts';\nimport run from './index.ts';\nimport type { UseError, UseOptions, UseResult } from './types.ts';\n\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nconst ERROR_CODE = 13;\n\nfunction getVersion(): string {\n const packagePath = path.join(__dirname, '..', '..', 'package.json');\n const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));\n return packageJson.version;\n}\n\nfunction printHelp(name: string): void {\n const version = getVersion();\n console.log(`${name} v${version}`);\n console.log('');\n console.log(`Usage: ${name} [options] <version> <command> [args...]`);\n console.log(` ${name} <subcommand> [args...]`);\n console.log('');\n console.log('Run commands with specific Node.js versions');\n console.log('');\n console.log('Subcommands:');\n console.log(' default [version] Set or display the global default Node version');\n console.log(' local [version] Set or display the local Node version (.nvmrc)');\n console.log(' install <version> Download and install a Node version');\n console.log(' uninstall <version> Remove an installed Node version');\n console.log(' list List installed Node versions');\n console.log(' which Show which Node version would be used');\n console.log(' setup Install/reinstall binaries to ~/.nvu/bin');\n console.log(' teardown Remove binaries from ~/.nvu/bin');\n console.log('');\n console.log('Options:');\n console.log(' -v, --version Print version number');\n console.log(' -h, --help Print this help message');\n console.log(' -r, --range Range type (major, minor, patch) with filters (lts, even, odd)');\n console.log(' Default: major,even');\n console.log(' -d, --desc Sort versions in descending order');\n console.log(' -e, --expanded Use expanded version format');\n console.log(' -s, --streaming Enable streaming output');\n console.log(' --silent Suppress logging');\n console.log('');\n console.log('Examples:');\n console.log(` ${name} 22 node --version Run with Node 22`);\n console.log(` ${name} 22,20,18 npm test Run with multiple versions`);\n console.log(` ${name} engines node --version Use version from package.json`);\n console.log(` ${name} default 20 Set global default to Node 20`);\n console.log(` ${name} local 18 Create .nvmrc with Node 18`);\n}\n\nexport default (argv: string[], name: string): undefined => {\n const options = getopts(argv, {\n alias: { range: 'r', desc: 'd', expanded: 'e', streaming: 's', silent: 'si', version: 'v', help: 'h' },\n default: { range: 'major,even', interactive: true },\n boolean: ['silent', 'desc', 'expanded', 'streaming', 'interactive', 'version', 'help'],\n stopEarly: true,\n });\n\n if (options.version) {\n console.log(getVersion());\n exit(0);\n return;\n }\n\n if (options.help) {\n printHelp(name);\n exit(0);\n return;\n }\n\n // Check if first argument is a subcommand\n const args = options._;\n if (args.length > 0 && isCommand(args[0])) {\n runCommand(args[0], args.slice(1));\n return;\n }\n\n // define.option('-r, --range [range]', 'range type of major, minor, or patch with filters of lts, even, odd for version string expressions', 'major,even');\n // define.option('-s, --silent', 'suppress logging', false);\n options.sort = options.desc ? -1 : 1;\n\n if (args.length === 0) {\n console.log(`Missing version expression. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n if (args.length === 1) {\n console.log(`Missing command. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n\n options.stdio = 'inherit'; // pass through stdio\n run(args[0], args[1], args.slice(2), options as unknown as UseOptions, (err: UseError, results: UseResult[]): undefined => {\n if (err && !err.results) {\n console.log(err.message);\n exit(ERROR_CODE);\n return;\n }\n if (err) results = err.results;\n const errors = results.filter((result) => !!result.error);\n\n if (!options.silent) {\n if (!createSession) {\n console.log('\\n======================');\n results.forEach((res) => {\n console.log(`${res.error ? figures.cross : figures.tick} ${res.version}${res.error ? ` Error: ${res.error.message}` : ''}`);\n });\n console.log('\\n----------------------');\n console.log(`${name} ${formatArguments(args).join(' ')}`);\n console.log(`${figures.tick} ${results.length - errors.length} succeeded`);\n if (errors.length) console.log(`${figures.cross} ${errors.length} failed`);\n }\n }\n exit(err || errors.length ? ERROR_CODE : 0);\n });\n};\n"],"names":["__dirname","path","dirname","__filename","url","fileURLToPath","ERROR_CODE","getVersion","packagePath","join","packageJson","JSON","parse","fs","readFileSync","version","printHelp","name","console","log","argv","options","getopts","alias","range","desc","expanded","streaming","silent","help","default","interactive","boolean","stopEarly","exit","args","_","length","isCommand","runCommand","slice","sort","stdio","run","err","results","message","errors","filter","result","error","createSession","forEach","res","figures","cross","tick","formatArguments"],"mappings":";;;;+BAyDA;;;eAAA;;;iEAzDiB;yDACF;oEACK;2DACH;yBACuC;0DACxC;uBACsB;+DACtB;;;;;;AAGhB,IAAMA,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAElG,IAAMC,aAAa;AAEnB,SAASC;IACP,IAAMC,cAAcP,aAAI,CAACQ,IAAI,CAACT,WAAW,MAAM,MAAM;IACrD,IAAMU,cAAcC,KAAKC,KAAK,CAACC,WAAE,CAACC,YAAY,CAACN,aAAa;IAC5D,OAAOE,YAAYK,OAAO;AAC5B;AAEA,SAASC,UAAUC,IAAY;IAC7B,IAAMF,UAAUR;IAChBW,QAAQC,GAAG,CAAC,AAAC,GAAWJ,OAATE,MAAK,MAAY,OAARF;IAC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,CAACA,OAAOC,KAAK;;QAExD,IAAI,CAAC7B,QAAQO,MAAM,EAAE;YACnB,IAAI,CAACuB,wBAAa,EAAE;gBAClBjC,QAAQC,GAAG,CAAC;gBACZ0B,QAAQO,OAAO,CAAC,SAACC;oBACfnC,QAAQC,GAAG,CAAC,AAAC,GAA8CkC,OAA5CA,IAAIH,KAAK,GAAGI,kBAAO,CAACC,KAAK,GAAGD,kBAAO,CAACE,IAAI,EAAC,KAAiBH,OAAdA,IAAItC,OAAO,EAAmD,OAAhDsC,IAAIH,KAAK,GAAG,AAAC,WAA4B,OAAlBG,IAAIH,KAAK,CAACJ,OAAO,IAAK;gBACxH;gBACA5B,QAAQC,GAAG,CAAC;gBACZD,QAAQC,GAAG,CAAC,AAAC,GAAUsC,OAARxC,MAAK,KAAmC,OAAhCwC,IAAAA,0BAAe,EAACtB,MAAM1B,IAAI,CAAC;gBAClDS,QAAQC,GAAG,CAAC,AAAC,GAAkB0B,OAAhBS,kBAAO,CAACE,IAAI,EAAC,KAAkC,OAA/BX,QAAQR,MAAM,GAAGU,OAAOV,MAAM,EAAC;gBAC9D,IAAIU,OAAOV,MAAM,EAAEnB,QAAQC,GAAG,CAAC,AAAC,GAAmB4B,OAAjBO,kBAAO,CAACC,KAAK,EAAC,KAAiB,OAAdR,OAAOV,MAAM,EAAC;YACnE;QACF;QACAH,IAAAA,mBAAI,EAACU,OAAOG,OAAOV,MAAM,GAAG/B,aAAa;IAC3C;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/cli.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport getopts from 'getopts-compat';\nimport path from 'path';\nimport { createSession, figures, formatArguments } from 'spawn-term';\nimport url from 'url';\nimport { isCommand, runCommand } from './commands/index.ts';\nimport run from './index.ts';\nimport type { UseError, UseOptions, UseResult } from './types.ts';\n\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nconst ERROR_CODE = 13;\n\nfunction getVersion(): string {\n const packagePath = path.join(__dirname, '..', '..', 'package.json');\n const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));\n return packageJson.version;\n}\n\nfunction printHelp(name: string): void {\n const version = getVersion();\n console.log(`${name} v${version}`);\n console.log('');\n console.log(`Usage: ${name} [options] <version> <command> [args...]`);\n console.log(` ${name} <subcommand> [args...]`);\n console.log('');\n console.log('Run commands with specific Node.js versions');\n console.log('');\n console.log('Subcommands:');\n console.log(' default [version] Set or display the global default Node version');\n console.log(' local [version] Set or display the local Node version (.nvmrc)');\n console.log(' install <version> Download and install a Node version');\n console.log(' uninstall <version> Remove an installed Node version');\n console.log(' list List installed Node versions');\n console.log(' which Show which Node version would be used');\n console.log(' setup Install/reinstall binaries to ~/.nvu/bin');\n console.log(' teardown Remove binaries from ~/.nvu/bin');\n console.log('');\n console.log('Options:');\n console.log(' -v, --version Print version number');\n console.log(' -h, --help Print this help message');\n console.log(' -r, --range Range type (major, minor, patch) with filters (lts, even, odd)');\n console.log(' Default: major,even');\n console.log(' -d, --desc Sort versions in descending order');\n console.log(' -e, --expanded Use expanded version format');\n console.log(' -s, --streaming Enable streaming output');\n console.log(' --silent Suppress logging');\n console.log('');\n console.log('Examples:');\n console.log(` ${name} 22 node --version Run with Node 22`);\n console.log(` ${name} 22,20,18 npm test Run with multiple versions`);\n console.log(` ${name} engines node --version Use version from package.json`);\n console.log(` ${name} default 20 Set global default to Node 20`);\n console.log(` ${name} local 18 Create .nvmrc with Node 18`);\n}\n\nexport default (argv: string[], name: string): void => {\n const options = getopts(argv, {\n alias: { range: 'r', desc: 'd', expanded: 'e', streaming: 's', silent: 'si', version: 'v', help: 'h' },\n default: { range: 'major,even', interactive: true },\n boolean: ['silent', 'desc', 'expanded', 'streaming', 'interactive', 'version', 'help'],\n stopEarly: true,\n });\n\n if (options.version) {\n console.log(getVersion());\n exit(0);\n return;\n }\n\n if (options.help) {\n printHelp(name);\n exit(0);\n return;\n }\n\n // Check if first argument is a subcommand\n const args = options._;\n if (args.length > 0 && isCommand(args[0])) {\n runCommand(args[0], args.slice(1));\n return;\n }\n\n // define.option('-r, --range [range]', 'range type of major, minor, or patch with filters of lts, even, odd for version string expressions', 'major,even');\n // define.option('-s, --silent', 'suppress logging', false);\n options.sort = options.desc ? -1 : 1;\n\n if (args.length === 0) {\n console.log(`Missing version expression. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n if (args.length === 1) {\n console.log(`Missing command. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n\n options.stdio = 'inherit'; // pass through stdio\n run(args[0], args[1], args.slice(2), options as unknown as UseOptions, (err: UseError, results: UseResult[]): void => {\n if (err && !err.results) {\n console.log(err.message);\n exit(ERROR_CODE);\n return;\n }\n if (err) results = err.results;\n const errors = results.filter((result) => !!result.error);\n\n if (!options.silent) {\n if (!createSession) {\n console.log('\\n======================');\n results.forEach((res) => {\n console.log(`${res.error ? figures.cross : figures.tick} ${res.version}${res.error ? ` Error: ${res.error.message}` : ''}`);\n });\n console.log('\\n----------------------');\n console.log(`${name} ${formatArguments(args).join(' ')}`);\n console.log(`${figures.tick} ${results.length - errors.length} succeeded`);\n if (errors.length) console.log(`${figures.cross} ${errors.length} failed`);\n }\n }\n exit(err || errors.length ? ERROR_CODE : 0);\n });\n};\n"],"names":["__dirname","path","dirname","__filename","url","fileURLToPath","ERROR_CODE","getVersion","packagePath","join","packageJson","JSON","parse","fs","readFileSync","version","printHelp","name","console","log","argv","options","getopts","alias","range","desc","expanded","streaming","silent","help","default","interactive","boolean","stopEarly","exit","args","_","length","isCommand","runCommand","slice","sort","stdio","run","err","results","message","errors","filter","result","error","createSession","forEach","res","figures","cross","tick","formatArguments"],"mappings":";;;;+BAyDA;;;eAAA;;;iEAzDiB;yDACF;oEACK;2DACH;yBACuC;0DACxC;uBACsB;+DACtB;;;;;;AAGhB,IAAMA,YAAYC,aAAI,CAACC,OAAO,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AOG,OAAOV,MAAM,GAAG/B,aAAa;IAC3C;AACF"}
@@ -42,17 +42,11 @@ function _interop_require_default(obj) {
42
42
  }
43
43
  // Use existing require in CJS, or createRequire in ESM (Node 12.2+)
44
44
  var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
45
- var hasHomedir = typeof _os.default.homedir === 'function';
46
45
  function homedir() {
47
- if (hasHomedir) return _os.default.homedir();
48
- var home = require('homedir-polyfill');
49
- return home();
46
+ return typeof _os.default.homedir === 'function' ? _os.default.homedir() : require('homedir-polyfill')();
50
47
  }
51
- var hasTmpdir = typeof _os.default.tmpdir === 'function';
52
48
  function tmpdir() {
53
- if (hasTmpdir) return _os.default.tmpdir();
54
- var osShim = require('os-shim');
55
- return osShim.tmpdir();
49
+ return typeof _os.default.tmpdir === 'function' ? _os.default.tmpdir() : require('os-shim').tmpdir();
56
50
  }
57
51
  /**
58
52
  * String.prototype.endsWith wrapper for Node.js 0.8+
@@ -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 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+)\nconst _require = typeof require === 'undefined' ? _Module.createRequire(import.meta.url) : require;\n\nconst hasHomedir = typeof os.homedir === 'function';\nexport function homedir(): string {\n if (hasHomedir) return os.homedir();\n const home = require('homedir-polyfill');\n return home();\n}\n\nconst hasTmpdir = typeof os.tmpdir === 'function';\nexport function tmpdir(): string {\n if (hasTmpdir) return os.tmpdir();\n const osShim = require('os-shim');\n return osShim.tmpdir();\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 */\nconst 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 const 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 const 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 const 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 const names = fs.readdirSync(dir);\n return names.map((name) => {\n const fullPath = path.join(dir, name);\n let 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":["homedir","mkdirpSync","readdirWithTypes","rmSync","stringEndsWith","tmpdir","_require","require","_Module","createRequire","hasHomedir","os","home","hasTmpdir","osShim","hasEndsWith","String","prototype","endsWith","str","search","position","len","undefined","length","lastIndexOf","dir","mkdirp","sync","safeRmSync","names","fs","readdirSync","map","name","fullPath","path","join","stat","statSync","_e","isDirectory"],"mappings":"AAAA;;;CAGC;;;;;;;;;;;QAUeA;eAAAA;;QA+BAC;eAAAA;;QAsBAC;eAAAA;;QAdAC;eAAAA;;QAnBAC;eAAAA;;QAbAC;eAAAA;;;yDAhBD;6DACK;yDACL;2DACE;;;;;;AAEjB,oEAAoE;AACpE,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAO,CAACC,aAAa,CAAC,uDAAmBF;AAE3F,IAAMG,aAAa,OAAOC,WAAE,CAACX,OAAO,KAAK;AAClC,SAASA;IACd,IAAIU,YAAY,OAAOC,WAAE,CAACX,OAAO;IACjC,IAAMY,OAAOL,QAAQ;IACrB,OAAOK;AACT;AAEA,IAAMC,YAAY,OAAOF,WAAE,CAACN,MAAM,KAAK;AAChC,SAASA;IACd,IAAIQ,WAAW,OAAOF,WAAE,CAACN,MAAM;IAC/B,IAAMS,SAASP,QAAQ;IACvB,OAAOO,OAAOT,MAAM;AACtB;AAEA;;;;CAIC,GACD,IAAMU,cAAc,OAAOC,OAAOC,SAAS,CAACC,QAAQ,KAAK;AAElD,SAASd,eAAee,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIN,aAAa;QACf,OAAOI,IAAID,QAAQ,CAACE,QAAQC;IAC9B;IACA,IAAMC,MAAMD,aAAaE,YAAYJ,IAAIK,MAAM,GAAGH;IAClD,OAAOF,IAAIM,WAAW,CAACL,YAAYE,MAAMF,OAAOI,MAAM;AACxD;AAKO,SAASvB,WAAWyB,GAAW;IACpC,IAAMC,SAASrB,SAAS;IACxBqB,OAAOC,IAAI,CAACF;AACd;AAKO,SAASvB,OAAOuB,GAAW;IAChC,IAAMG,aAAavB,SAAS,oBAAoBuB,UAAU;IAC1DA,WAAWH;AACb;AAWO,SAASxB,iBAAiBwB,GAAW;IAC1C,IAAMI,QAAQC,WAAE,CAACC,WAAW,CAACN;IAC7B,OAAOI,MAAMG,GAAG,CAAC,SAACC;QAChB,IAAMC,WAAWC,aAAI,CAACC,IAAI,CAACX,KAAKQ;QAChC,IAAII;QACJ,IAAI;YACFA,OAAOP,WAAE,CAACQ,QAAQ,CAACJ;QACrB,EAAE,OAAOK,IAAI;YACX,wCAAwC;YACxC,OAAO;gBAAEN,MAAMA;gBAAMO,aAAa;2BAAM;;YAAM;QAChD;QACA,OAAO;YACLP,MAAMA;YACNO,aAAa;uBAAMH,KAAKG,WAAW;;QACrC;IACF;AACF"}
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+)\nconst _require = typeof require === 'undefined' ? _Module.createRequire(import.meta.url) : require;\n\nexport function homedir(): string {\n return typeof os.homedir === 'function' ? os.homedir() : require('homedir-polyfill')();\n}\n\nexport function tmpdir(): string {\n return typeof os.tmpdir === 'function' ? os.tmpdir() : require('os-shim').tmpdir();\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 */\nconst 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 const 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 const 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 const 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 const names = fs.readdirSync(dir);\n return names.map((name) => {\n const fullPath = path.join(dir, name);\n let 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":["homedir","mkdirpSync","readdirWithTypes","rmSync","stringEndsWith","tmpdir","_require","require","_Module","createRequire","os","hasEndsWith","String","prototype","endsWith","str","search","position","len","undefined","length","lastIndexOf","dir","mkdirp","sync","safeRmSync","names","fs","readdirSync","map","name","fullPath","path","join","stat","statSync","_e","isDirectory"],"mappings":"AAAA;;;CAGC;;;;;;;;;;;QASeA;eAAAA;;QA0BAC;eAAAA;;QAsBAC;eAAAA;;QAdAC;eAAAA;;QAnBAC;eAAAA;;QAXAC;eAAAA;;;yDAZD;6DACK;yDACL;2DACE;;;;;;AAEjB,oEAAoE;AACpE,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAO,CAACC,aAAa,CAAC,uDAAmBF;AAEpF,SAASP;IACd,OAAO,OAAOU,WAAE,CAACV,OAAO,KAAK,aAAaU,WAAE,CAACV,OAAO,KAAKO,QAAQ;AACnE;AAEO,SAASF;IACd,OAAO,OAAOK,WAAE,CAACL,MAAM,KAAK,aAAaK,WAAE,CAACL,MAAM,KAAKE,QAAQ,WAAWF,MAAM;AAClF;AAEA;;;;CAIC,GACD,IAAMM,cAAc,OAAOC,OAAOC,SAAS,CAACC,QAAQ,KAAK;AAElD,SAASV,eAAeW,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIN,aAAa;QACf,OAAOI,IAAID,QAAQ,CAACE,QAAQC;IAC9B;IACA,IAAMC,MAAMD,aAAaE,YAAYJ,IAAIK,MAAM,GAAGH;IAClD,OAAOF,IAAIM,WAAW,CAACL,YAAYE,MAAMF,OAAOI,MAAM;AACxD;AAKO,SAASnB,WAAWqB,GAAW;IACpC,IAAMC,SAASjB,SAAS;IACxBiB,OAAOC,IAAI,CAACF;AACd;AAKO,SAASnB,OAAOmB,GAAW;IAChC,IAAMG,aAAanB,SAAS,oBAAoBmB,UAAU;IAC1DA,WAAWH;AACb;AAWO,SAASpB,iBAAiBoB,GAAW;IAC1C,IAAMI,QAAQC,WAAE,CAACC,WAAW,CAACN;IAC7B,OAAOI,MAAMG,GAAG,CAAC,SAACC;QAChB,IAAMC,WAAWC,aAAI,CAACC,IAAI,CAACX,KAAKQ;QAChC,IAAII;QACJ,IAAI;YACFA,OAAOP,WAAE,CAACQ,QAAQ,CAACJ;QACrB,EAAE,OAAOK,IAAI;YACX,wCAAwC;YACxC,OAAO;gBAAEN,MAAMA;gBAAMO,aAAa;2BAAM;;YAAM;QAChD;QACA,OAAO;YACLP,MAAMA;YACNO,aAAa;uBAAMH,KAAKG,WAAW;;QACrC;IACF;AACF"}
@@ -2,5 +2,5 @@ import type { UseCallback, UseOptions, UseResult } from './types.js';
2
2
  export type * from './types.js';
3
3
  export default function nodeVersionUse(versionExpression: string, command: string, args: string[]): Promise<UseResult[]>;
4
4
  export default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions): Promise<UseResult[]>;
5
- export default function nodeVersionUse(versionExpression: string, command: string, args: string[], callback: UseCallback): undefined;
6
- export default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): undefined;
5
+ export default function nodeVersionUse(versionExpression: string, command: string, args: string[], callback: UseCallback): void;
6
+ export default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void;
@@ -2,5 +2,5 @@ import type { UseCallback, UseOptions, UseResult } from './types.js';
2
2
  export type * from './types.js';
3
3
  export default function nodeVersionUse(versionExpression: string, command: string, args: string[]): Promise<UseResult[]>;
4
4
  export default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions): Promise<UseResult[]>;
5
- export default function nodeVersionUse(versionExpression: string, command: string, args: string[], callback: UseCallback): undefined;
6
- export default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): undefined;
5
+ export default function nodeVersionUse(versionExpression: string, command: string, args: string[], callback: UseCallback): void;
6
+ export default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/index.ts"],"sourcesContent":["import type { UseCallback, UseOptions, UseResult } from './types.ts';\nimport worker from './worker.ts';\n\nexport type * from './types.ts';\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[]): Promise<UseResult[]>;\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions): Promise<UseResult[]>;\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], callback: UseCallback): undefined;\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): undefined;\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options?: UseOptions | UseCallback, callback?: UseCallback): undefined | Promise<UseResult[]> {\n if (typeof options === 'function') {\n callback = options as UseCallback;\n options = {};\n }\n options = options || {};\n\n if (typeof callback === 'function') return worker(versionExpression, command, args, options, callback) as undefined;\n return new Promise((resolve, reject) =>\n worker(versionExpression, command, args, options, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n}\n"],"names":["nodeVersionUse","versionExpression","command","args","options","callback","worker","Promise","resolve","reject","err","result"],"mappings":";;;;+BAWA;;;eAAwBA;;;+DAVL;;;;;;AAUJ,SAASA,eAAeC,iBAAyB,EAAEC,OAAe,EAAEC,IAAc,EAAEC,OAAkC,EAAEC,QAAsB;IAC3J,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOC,IAAAA,iBAAM,EAACL,mBAAmBC,SAASC,MAAMC,SAASC;IAC7F,OAAO,IAAIE,QAAQ,SAACC,SAASC;eAC3BH,IAAAA,iBAAM,EAACL,mBAAmBC,SAASC,MAAMC,SAAS,SAACM,KAAKC;YACtDD,MAAMD,OAAOC,OAAOF,QAAQG;QAC9B;;AAEJ"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/index.ts"],"sourcesContent":["import type { UseCallback, UseOptions, UseResult } from './types.ts';\nimport worker from './worker.ts';\n\nexport type * from './types.ts';\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[]): Promise<UseResult[]>;\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions): Promise<UseResult[]>;\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], callback: UseCallback): void;\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void;\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options?: UseOptions | UseCallback, callback?: UseCallback): void | Promise<UseResult[]> {\n if (typeof options === 'function') {\n callback = options as UseCallback;\n options = {};\n }\n options = options || {};\n\n if (typeof callback === 'function') return worker(versionExpression, command, args, options, callback);\n return new Promise((resolve, reject) =>\n worker(versionExpression, command, args, options as UseOptions, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n}\n"],"names":["nodeVersionUse","versionExpression","command","args","options","callback","worker","Promise","resolve","reject","err","result"],"mappings":";;;;+BAWA;;;eAAwBA;;;+DAVL;;;;;;AAUJ,SAASA,eAAeC,iBAAyB,EAAEC,OAAe,EAAEC,IAAc,EAAEC,OAAkC,EAAEC,QAAsB;IAC3J,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOC,IAAAA,iBAAM,EAACL,mBAAmBC,SAASC,MAAMC,SAASC;IAC7F,OAAO,IAAIE,QAAQ,SAACC,SAASC;eAC3BH,IAAAA,iBAAM,EAACL,mBAAmBC,SAASC,MAAMC,SAAuB,SAACM,KAAKC;YACpED,MAAMD,OAAOC,OAAOF,QAAQG;QAC9B;;AAEJ"}
@@ -78,10 +78,7 @@ function loadModule(moduleName, callback) {
78
78
  }
79
79
  }
80
80
  function loadNodeVersionInstall(callback) {
81
- if (cached !== undefined) {
82
- callback(null, cached);
83
- return;
84
- }
81
+ if (cached !== undefined) return callback(null, cached);
85
82
  (0, _installmodulelinked.default)(moduleName, nodeModules, {}, function(err) {
86
83
  if (err) return callback(err, null);
87
84
  loadModule(moduleName, function(err, _cached) {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/lib/loadNodeVersionInstall.ts"],"sourcesContent":["import installModule from 'install-module-linked';\nimport type { InstallOptions, InstallResult } from 'node-version-install';\nimport path from 'path';\nimport url from 'url';\n\nconst _dirname = path.dirname(typeof __dirname !== 'undefined' ? __dirname : url.fileURLToPath(import.meta.url));\nconst nodeModules = path.join(_dirname, '..', '..', '..', 'node_modules');\nconst moduleName = 'node-version-install';\n\ntype InstallCallback = (err?: Error, results?: InstallResult[]) => void;\ntype InstallVersionFn = (version: string, options: InstallOptions, callback: InstallCallback) => void;\n\nlet cached: InstallVersionFn | undefined;\n\nfunction loadModule(moduleName, callback) {\n if (typeof require === 'undefined') {\n import(moduleName)\n .then((mod) => {\n callback(null, mod?.default ?? null);\n })\n .catch(callback);\n } else {\n try {\n callback(null, require(moduleName));\n } catch (err) {\n callback(err, null);\n }\n }\n}\n\nexport default function loadNodeVersionInstall(callback: (err: Error | null, installVersion: InstallVersionFn) => void): void {\n if (cached !== undefined) {\n callback(null, cached);\n return;\n }\n\n installModule(moduleName, nodeModules, {}, (err) => {\n if (err) return callback(err, null);\n loadModule(moduleName, (err, _cached: InstallVersionFn) => {\n if (err) return callback(err, null);\n cached = _cached;\n callback(null, cached);\n });\n });\n}\n"],"names":["loadNodeVersionInstall","_dirname","path","dirname","__dirname","url","fileURLToPath","nodeModules","join","moduleName","cached","loadModule","callback","require","then","mod","default","catch","err","undefined","installModule","_cached"],"mappings":";;;;+BA8BA;;;eAAwBA;;;0EA9BE;2DAET;0DACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEhB,IAAMC,WAAWC,aAAI,CAACC,OAAO,CAAC,OAAOC,cAAc,cAAcA,YAAYC,YAAG,CAACC,aAAa,CAAC;AAC/F,IAAMC,cAAcL,aAAI,CAACM,IAAI,CAACP,UAAU,MAAM,MAAM,MAAM;AAC1D,IAAMQ,aAAa;AAKnB,IAAIC;AAEJ,SAASC,WAAWF,UAAU,EAAEG,QAAQ;IACtC,IAAI,OAAOC,YAAY,aAAa;QAClC,gBAAOJ;2DAAP;WACGK,IAAI,CAAC,SAACC;;YACLH,SAAS,cAAMG,gBAAAA,0BAAAA,IAAKC,OAAO,uCAAI;QACjC,GACCC,KAAK,CAACL;IACX,OAAO;QACL,IAAI;YACFA,SAAS,MAAMC,QAAQJ;QACzB,EAAE,OAAOS,KAAK;YACZN,SAASM,KAAK;QAChB;IACF;AACF;AAEe,SAASlB,uBAAuBY,QAAuE;IACpH,IAAIF,WAAWS,WAAW;QACxBP,SAAS,MAAMF;QACf;IACF;IAEAU,IAAAA,4BAAa,EAACX,YAAYF,aAAa,CAAC,GAAG,SAACW;QAC1C,IAAIA,KAAK,OAAON,SAASM,KAAK;QAC9BP,WAAWF,YAAY,SAACS,KAAKG;YAC3B,IAAIH,KAAK,OAAON,SAASM,KAAK;YAC9BR,SAASW;YACTT,SAAS,MAAMF;QACjB;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/lib/loadNodeVersionInstall.ts"],"sourcesContent":["import installModule from 'install-module-linked';\nimport type { InstallOptions, InstallResult } from 'node-version-install';\nimport path from 'path';\nimport url from 'url';\n\nconst _dirname = path.dirname(typeof __dirname !== 'undefined' ? __dirname : url.fileURLToPath(import.meta.url));\nconst nodeModules = path.join(_dirname, '..', '..', '..', 'node_modules');\nconst moduleName = 'node-version-install';\n\ntype InstallCallback = (err?: Error, results?: InstallResult[]) => void;\ntype InstallVersionFn = (version: string, options: InstallOptions, callback: InstallCallback) => void;\n\nlet cached: InstallVersionFn | undefined;\n\nfunction loadModule(moduleName, callback) {\n if (typeof require === 'undefined') {\n import(moduleName)\n .then((mod) => {\n callback(null, mod?.default ?? null);\n })\n .catch(callback);\n } else {\n try {\n callback(null, require(moduleName));\n } catch (err) {\n callback(err, null);\n }\n }\n}\n\nexport default function loadNodeVersionInstall(callback: (err: Error | null, installVersion: InstallVersionFn) => void): void {\n if (cached !== undefined) return callback(null, cached);\n\n installModule(moduleName, nodeModules, {}, (err) => {\n if (err) return callback(err, null);\n loadModule(moduleName, (err, _cached: InstallVersionFn) => {\n if (err) return callback(err, null);\n cached = _cached;\n callback(null, cached);\n });\n });\n}\n"],"names":["loadNodeVersionInstall","_dirname","path","dirname","__dirname","url","fileURLToPath","nodeModules","join","moduleName","cached","loadModule","callback","require","then","mod","default","catch","err","undefined","installModule","_cached"],"mappings":";;;;+BA8BA;;;eAAwBA;;;0EA9BE;2DAET;0DACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEhB,IAAMC,WAAWC,aAAI,CAACC,OAAO,CAAC,OAAOC,cAAc,cAAcA,YAAYC,YAAG,CAACC,aAAa,CAAC;AAC/F,IAAMC,cAAcL,aAAI,CAACM,IAAI,CAACP,UAAU,MAAM,MAAM,MAAM;AAC1D,IAAMQ,aAAa;AAKnB,IAAIC;AAEJ,SAASC,WAAWF,UAAU,EAAEG,QAAQ;IACtC,IAAI,OAAOC,YAAY,aAAa;QAClC,gBAAOJ;2DAAP;WACGK,IAAI,CAAC,SAACC;;YACLH,SAAS,cAAMG,gBAAAA,0BAAAA,IAAKC,OAAO,uCAAI;QACjC,GACCC,KAAK,CAACL;IACX,OAAO;QACL,IAAI;YACFA,SAAS,MAAMC,QAAQJ;QACzB,EAAE,OAAOS,KAAK;YACZN,SAASM,KAAK;QAChB;IACF;AACF;AAEe,SAASlB,uBAAuBY,QAAuE;IACpH,IAAIF,WAAWS,WAAW,OAAOP,SAAS,MAAMF;IAEhDU,IAAAA,4BAAa,EAACX,YAAYF,aAAa,CAAC,GAAG,SAACW;QAC1C,IAAIA,KAAK,OAAON,SAASM,KAAK;QAC9BP,WAAWF,YAAY,SAACS,KAAKG;YAC3B,IAAIH,KAAK,OAAON,SAASM,KAAK;YAC9BR,SAASW;YACTT,SAAS,MAAMF;QACjB;IACF;AACF"}
@@ -21,4 +21,4 @@ export interface Options {
21
21
  silent?: boolean;
22
22
  }
23
23
  export type UseOptions = Options & InstallOptions & VersionOptions & SpawnOptions;
24
- export type UseCallback = (err?: UseError | Error, results?: UseResult[]) => undefined;
24
+ export type UseCallback = (err?: UseError | Error, results?: UseResult[]) => void;
@@ -21,4 +21,4 @@ export interface Options {
21
21
  silent?: boolean;
22
22
  }
23
23
  export type UseOptions = Options & InstallOptions & VersionOptions & SpawnOptions;
24
- export type UseCallback = (err?: UseError | Error, results?: UseResult[]) => undefined;
24
+ export type UseCallback = (err?: UseError | Error, results?: UseResult[]) => void;
@@ -1,2 +1,2 @@
1
1
  import type { UseCallback, UseOptions } from './types.js';
2
- export default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): undefined;
2
+ export default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void;
@@ -1,2 +1,2 @@
1
1
  import type { UseCallback, UseOptions } from './types.js';
2
- export default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): undefined;
2
+ export default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void;
@@ -138,10 +138,7 @@ function worker(versionExpression, command, args, options, callback) {
138
138
  (0, _loadNodeVersionInstallts.default)(function(loadErr, installVersion) {
139
139
  if (loadErr) return callback(loadErr);
140
140
  (0, _noderesolveversions.default)(versionExpression, options, function(err, versions) {
141
- if (err) {
142
- callback(err);
143
- return;
144
- }
141
+ if (err) return callback(err);
145
142
  if (!versions.length) {
146
143
  callback(new Error("No versions found from expression: ".concat(versionExpression)));
147
144
  return;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/worker.ts"],"sourcesContent":["import spawn, { type SpawnOptions } from 'cross-spawn-cb';\nimport fs from 'fs';\nimport resolveVersions, { type VersionOptions } from 'node-resolve-versions';\nimport type { InstallOptions } from 'node-version-install';\nimport { spawnOptions as createSpawnOptions } from 'node-version-utils';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport resolveBin from 'resolve-bin-sync';\nimport spawnStreaming from 'spawn-streaming';\nimport { createSession, formatArguments } from 'spawn-term';\nimport { stringEndsWith } from './compat.ts';\nimport { storagePath } from './constants.ts';\nimport loadNodeVersionInstall from './lib/loadNodeVersionInstall.ts';\n\nimport type { Options, UseCallback, UseOptions, UseResult } from './types.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst NODE = isWindows ? 'node.exe' : 'node';\n\n// Parse npm-generated .cmd wrapper to extract the JS script path\nfunction parseNpmCmdWrapper(cmdPath: string): string | null {\n try {\n const content = fs.readFileSync(cmdPath, 'utf8');\n // Match: \"%_prog%\" \"%dp0%\\node_modules\\...\\cli.js\" %*\n // or: \"%_prog%\" \"%dp0%\\path\\to\\script.js\" %*\n const match = content.match(/\"%_prog%\"\\s+\"?%dp0%\\\\([^\"]+)\"?\\s+%\\*/);\n if (match) {\n const relativePath = match[1];\n const cmdDir = path.dirname(cmdPath);\n return path.join(cmdDir, relativePath);\n }\n } catch (_e) {\n // ignore\n }\n return null;\n}\n\n// On Windows, resolve npm bin commands to their JS entry points to bypass .cmd wrappers\n// This fixes issues with nvm-windows where .cmd wrappers use symlinked node.exe directly\nfunction resolveCommand(command: string, args: string[]): { command: string; args: string[] } {\n if (!isWindows) return { command, args };\n\n // Case 1: Command is a .cmd file path\n if (stringEndsWith(command.toLowerCase(), '.cmd')) {\n const scriptPath = parseNpmCmdWrapper(command);\n if (scriptPath) {\n return { command: NODE, args: [scriptPath, ...args] };\n }\n }\n\n // Case 2: Try to resolve the command as an npm package bin from node_modules\n try {\n const binPath = resolveBin(command);\n return { command: NODE, args: [binPath, ...args] };\n } catch (_e) {\n // Not an npm package bin, use original command\n }\n\n return { command, args };\n}\n\nexport default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): undefined {\n // Load node-version-install lazily\n loadNodeVersionInstall((loadErr, installVersion) => {\n if (loadErr) return callback(loadErr);\n\n resolveVersions(versionExpression, options as VersionOptions, (err?: Error, versions?: string[]) => {\n if (err) {\n callback(err);\n return;\n }\n if (!versions.length) {\n callback(new Error(`No versions found from expression: ${versionExpression}`));\n return;\n }\n\n const installOptions = { storagePath, ...options } as InstallOptions;\n const streamingOptions = options as Options;\n const results: UseResult[] = [];\n const queue = new Queue(1);\n\n // Create session once for all processes (only if multiple versions)\n const interactive = options.interactive !== false;\n const session = versions.length >= 2 && createSession && !streamingOptions.streaming ? createSession({ header: `${command} ${args.join(' ')}`, showStatusBar: true, interactive }) : null;\n\n versions.forEach((version: string) => {\n queue.defer((cb) => {\n installVersion(version, installOptions, (err, installs) => {\n const install = installs && installs.length === 1 ? installs[0] : null;\n if (err || !install) {\n const error = err || new Error(`Unexpected version results for version ${version}. Install ${JSON.stringify(installs)}`);\n results.push({ install, command, version, error, result: null });\n return cb();\n }\n const spawnOptions = createSpawnOptions(install.installPath, options as SpawnOptions);\n const prefix = install.version;\n\n function next(err?, res?): undefined {\n if (err && err.message.indexOf('ExperimentalWarning') >= 0) {\n res = err;\n err = null;\n }\n results.push({ install, command, version, error: err, result: res });\n cb();\n }\n\n // On Windows, resolve npm bin commands to bypass .cmd wrappers\n const resolved = resolveCommand(command, args);\n\n if (versions.length < 2) {\n // Show command when running single version (no terminal session, unless silent)\n if (!options.silent) console.log(`$ ${formatArguments([resolved.command].concat(resolved.args)).join(' ')}`);\n return spawn(resolved.command, resolved.args, spawnOptions, next);\n }\n if (session) session.spawn(resolved.command, resolved.args, spawnOptions, { group: prefix, expanded: streamingOptions.expanded }, next);\n else spawnStreaming(resolved.command, resolved.args, spawnOptions, { prefix }, next);\n });\n });\n });\n queue.await((err) => {\n if (session) {\n session.waitAndClose(() => {\n err ? callback(err) : callback(null, results);\n });\n } else {\n err ? callback(err) : callback(null, results);\n }\n });\n });\n });\n}\n"],"names":["worker","isWindows","process","platform","test","env","OSTYPE","NODE","parseNpmCmdWrapper","cmdPath","content","fs","readFileSync","match","relativePath","cmdDir","path","dirname","join","_e","resolveCommand","command","args","stringEndsWith","toLowerCase","scriptPath","binPath","resolveBin","versionExpression","options","callback","loadNodeVersionInstall","loadErr","installVersion","resolveVersions","err","versions","length","Error","installOptions","storagePath","streamingOptions","results","queue","Queue","interactive","session","createSession","streaming","header","showStatusBar","forEach","version","defer","cb","installs","next","res","message","indexOf","push","install","error","result","JSON","stringify","spawnOptions","createSpawnOptions","installPath","prefix","resolved","silent","console","log","formatArguments","concat","spawn","group","expanded","spawnStreaming","await","waitAndClose"],"mappings":";;;;+BA6DA;;;eAAwBA;;;mEA7DiB;yDAC1B;0EACsC;gCAEF;2DAClC;8DACC;qEACK;qEACI;yBACoB;wBAChB;2BACH;+EACO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAInC,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAC3F,IAAMC,OAAON,YAAY,aAAa;AAEtC,iEAAiE;AACjE,SAASO,mBAAmBC,OAAe;IACzC,IAAI;QACF,IAAMC,UAAUC,WAAE,CAACC,YAAY,CAACH,SAAS;QACzC,uDAAuD;QACvD,8CAA8C;QAC9C,IAAMI,QAAQH,QAAQG,KAAK,CAAC;QAC5B,IAAIA,OAAO;YACT,IAAMC,eAAeD,KAAK,CAAC,EAAE;YAC7B,IAAME,SAASC,aAAI,CAACC,OAAO,CAACR;YAC5B,OAAOO,aAAI,CAACE,IAAI,CAACH,QAAQD;QAC3B;IACF,EAAE,OAAOK,IAAI;IACX,SAAS;IACX;IACA,OAAO;AACT;AAEA,wFAAwF;AACxF,yFAAyF;AACzF,SAASC,eAAeC,OAAe,EAAEC,IAAc;IACrD,IAAI,CAACrB,WAAW,OAAO;QAAEoB,SAAAA;QAASC,MAAAA;IAAK;IAEvC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,OAAO,EAAEiD,SAAShD,IAAI,EAAE4C,cAAcV;wBAC9D;wBACA,IAAIV,SAASA,QAAQ8B,KAAK,CAACN,SAASjD,OAAO,EAAEiD,SAAShD,IAAI,EAAE4C,cAAc;4BAAEW,OAAOR;4BAAQS,UAAUrC,iBAAiBqC,QAAQ;wBAAC,GAAGtB;6BAC7HuB,IAAAA,uBAAc,EAACT,SAASjD,OAAO,EAAEiD,SAAShD,IAAI,EAAE4C,cAAc;4BAAEG,QAAAA;wBAAO,GAAGb;oBACjF;gBACF;YACF;YACAb,MAAMqC,KAAK,CAAC,SAAC7C;gBACX,IAAIW,SAAS;oBACXA,QAAQmC,YAAY,CAAC;wBACnB9C,MAAML,SAASK,OAAOL,SAAS,MAAMY;oBACvC;gBACF,OAAO;oBACLP,MAAML,SAASK,OAAOL,SAAS,MAAMY;gBACvC;YACF;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/worker.ts"],"sourcesContent":["import spawn, { type SpawnOptions } from 'cross-spawn-cb';\nimport fs from 'fs';\nimport resolveVersions, { type VersionOptions } from 'node-resolve-versions';\nimport type { InstallOptions } from 'node-version-install';\nimport { spawnOptions as createSpawnOptions } from 'node-version-utils';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport resolveBin from 'resolve-bin-sync';\nimport spawnStreaming from 'spawn-streaming';\nimport { createSession, formatArguments } from 'spawn-term';\nimport { stringEndsWith } from './compat.ts';\nimport { storagePath } from './constants.ts';\nimport loadNodeVersionInstall from './lib/loadNodeVersionInstall.ts';\n\nimport type { Options, UseCallback, UseOptions, UseResult } from './types.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst NODE = isWindows ? 'node.exe' : 'node';\n\n// Parse npm-generated .cmd wrapper to extract the JS script path\nfunction parseNpmCmdWrapper(cmdPath: string): string | null {\n try {\n const content = fs.readFileSync(cmdPath, 'utf8');\n // Match: \"%_prog%\" \"%dp0%\\node_modules\\...\\cli.js\" %*\n // or: \"%_prog%\" \"%dp0%\\path\\to\\script.js\" %*\n const match = content.match(/\"%_prog%\"\\s+\"?%dp0%\\\\([^\"]+)\"?\\s+%\\*/);\n if (match) {\n const relativePath = match[1];\n const cmdDir = path.dirname(cmdPath);\n return path.join(cmdDir, relativePath);\n }\n } catch (_e) {\n // ignore\n }\n return null;\n}\n\n// On Windows, resolve npm bin commands to their JS entry points to bypass .cmd wrappers\n// This fixes issues with nvm-windows where .cmd wrappers use symlinked node.exe directly\nfunction resolveCommand(command: string, args: string[]): { command: string; args: string[] } {\n if (!isWindows) return { command, args };\n\n // Case 1: Command is a .cmd file path\n if (stringEndsWith(command.toLowerCase(), '.cmd')) {\n const scriptPath = parseNpmCmdWrapper(command);\n if (scriptPath) {\n return { command: NODE, args: [scriptPath, ...args] };\n }\n }\n\n // Case 2: Try to resolve the command as an npm package bin from node_modules\n try {\n const binPath = resolveBin(command);\n return { command: NODE, args: [binPath, ...args] };\n } catch (_e) {\n // Not an npm package bin, use original command\n }\n\n return { command, args };\n}\n\nexport default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void {\n // Load node-version-install lazily\n loadNodeVersionInstall((loadErr, installVersion) => {\n if (loadErr) return callback(loadErr);\n\n resolveVersions(versionExpression, options as VersionOptions, (err?: Error, versions?: string[]) => {\n if (err) return callback(err);\n if (!versions.length) {\n callback(new Error(`No versions found from expression: ${versionExpression}`));\n return;\n }\n\n const installOptions = { storagePath, ...options } as InstallOptions;\n const streamingOptions = options as Options;\n const results: UseResult[] = [];\n const queue = new Queue(1);\n\n // Create session once for all processes (only if multiple versions)\n const interactive = options.interactive !== false;\n const session = versions.length >= 2 && createSession && !streamingOptions.streaming ? createSession({ header: `${command} ${args.join(' ')}`, showStatusBar: true, interactive }) : null;\n\n versions.forEach((version: string) => {\n queue.defer((cb) => {\n installVersion(version, installOptions, (err, installs) => {\n const install = installs && installs.length === 1 ? installs[0] : null;\n if (err || !install) {\n const error = err || new Error(`Unexpected version results for version ${version}. Install ${JSON.stringify(installs)}`);\n results.push({ install, command, version, error, result: null });\n return cb();\n }\n const spawnOptions = createSpawnOptions(install.installPath, options as SpawnOptions);\n const prefix = install.version;\n\n function next(err?, res?): void {\n if (err && err.message.indexOf('ExperimentalWarning') >= 0) {\n res = err;\n err = null;\n }\n results.push({ install, command, version, error: err, result: res });\n cb();\n }\n\n // On Windows, resolve npm bin commands to bypass .cmd wrappers\n const resolved = resolveCommand(command, args);\n\n if (versions.length < 2) {\n // Show command when running single version (no terminal session, unless silent)\n if (!options.silent) console.log(`$ ${formatArguments([resolved.command].concat(resolved.args)).join(' ')}`);\n return spawn(resolved.command, resolved.args, spawnOptions, next);\n }\n if (session) session.spawn(resolved.command, resolved.args, spawnOptions, { group: prefix, expanded: streamingOptions.expanded }, next);\n else spawnStreaming(resolved.command, resolved.args, spawnOptions, { prefix }, next);\n });\n });\n });\n queue.await((err) => {\n if (session) {\n session.waitAndClose(() => {\n err ? callback(err) : callback(null, results);\n });\n } else {\n err ? callback(err) : callback(null, results);\n }\n });\n });\n });\n}\n"],"names":["worker","isWindows","process","platform","test","env","OSTYPE","NODE","parseNpmCmdWrapper","cmdPath","content","fs","readFileSync","match","relativePath","cmdDir","path","dirname","join","_e","resolveCommand","command","args","stringEndsWith","toLowerCase","scriptPath","binPath","resolveBin","versionExpression","options","callback","loadNodeVersionInstall","loadErr","installVersion","resolveVersions","err","versions","length","Error","installOptions","storagePath","streamingOptions","results","queue","Queue","interactive","session","createSession","streaming","header","showStatusBar","forEach","version","defer","cb","installs","next","res","message","indexOf","push","install","error","result","JSON","stringify","spawnOptions","createSpawnOptions","installPath","prefix","resolved","silent","console","log","formatArguments","concat","spawn","group","expanded","spawnStreaming","await","waitAndClose"],"mappings":";;;;+BA6DA;;;eAAwBA;;;mEA7DiB;yDAC1B;0EACsC;gCAEF;2DAClC;8DACC;qEACK;qEACI;yBACoB;wBAChB;2BACH;+EACO;;;;;;;;;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;QACF;IACF;AACF"}
@@ -64,10 +64,7 @@ function removeIfExistsSync(filePath) {
64
64
  * Atomic rename with fallback to copy+delete for cross-device moves
65
65
  */ function atomicRename(src, dest, callback) {
66
66
  fs.rename(src, dest, (err)=>{
67
- if (!err) {
68
- callback(null);
69
- return;
70
- }
67
+ if (!err) return callback(null);
71
68
  // Cross-device link error - fall back to copy + delete
72
69
  if (err.code === 'EXDEV') {
73
70
  try {
@@ -198,7 +195,7 @@ function removeIfExistsSync(filePath) {
198
195
  /**
199
196
  * Print setup instructions
200
197
  */ module.exports.printInstructions = function printInstructions() {
201
- const nvuBinPath = path.join(storagePath, 'bin');
198
+ const _nvuBinPath = path.join(storagePath, 'bin');
202
199
  console.log('nvu binaries installed in ~/.nvu/bin/');
203
200
  const pathKey = envPathKey();
204
201
  const envPath = process.env[pathKey] || '';
@@ -210,11 +207,14 @@ function removeIfExistsSync(filePath) {
210
207
  console.log('============================================================');
211
208
  console.log('');
212
209
  if (isWindows) {
213
- console.log(' PowerShell (add to $PROFILE):');
214
- console.log(` $env:PATH = "${nvuBinPath};$env:PATH"`);
210
+ console.log(' # Edit your PowerShell profile');
211
+ console.log(' # Open with: notepad $PROFILE');
212
+ console.log(' # Add this line:');
213
+ console.log(' $env:PATH = "$HOME\\.nvu\\bin;$env:APPDATA\\npm;$env:PATH"');
215
214
  console.log('');
216
- console.log(' CMD (run as administrator):');
217
- console.log(` setx PATH "${nvuBinPath};%PATH%"`);
215
+ console.log(' # This adds:');
216
+ console.log(' # ~/.nvu/bin - node/npm version switching shims');
217
+ console.log(' # %APPDATA%/npm - globally installed npm packages (like nvu)');
218
218
  } else {
219
219
  console.log(' # For bash (~/.bashrc):');
220
220
  console.log(' echo \'export PATH="$HOME/.nvu/bin:$PATH"\' >> ~/.bashrc');
@@ -269,10 +269,7 @@ function removeIfExistsSync(filePath) {
269
269
  console.log('Extracting binary...');
270
270
  extractAndInstall(tempPath, binDir, extractedBinaryName, (err)=>{
271
271
  removeIfExistsSync(tempPath);
272
- if (err) {
273
- callback(err);
274
- return;
275
- }
272
+ if (err) return callback(err);
276
273
  // save binary version for upgrade checks
277
274
  fs.writeFileSync(path.join(binDir, 'version.txt'), BINARY_VERSION, 'utf8');
278
275
  console.log('Binary installed successfully!');
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/assets/installBinaries.cts"],"sourcesContent":["const envPathKey = require('env-path-key');\nconst fs = require('fs');\nconst { safeRmSync } = require('fs-remove-compat');\nconst getFile = require('get-file-compat');\nconst mkdirp = require('mkdirp-classic');\nconst os = require('os');\nconst path = require('path');\nconst Queue = require('queue-cb');\nconst moduleRoot = require('module-root-sync');\n\nconst root = moduleRoot(__dirname);\n\n// Configuration\nconst GITHUB_REPO = 'kmalakoff/node-version-use';\nconst BINARY_VERSION = require(path.join(root, 'package.json')).binaryVersion;\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\ntype Callback = (err?: Error | null) => void;\n\ninterface PlatformMap {\n [key: string]: string;\n}\n\nconst hasHomedir = typeof os.homedir === 'function';\nfunction homedir(): string {\n if (hasHomedir) return os.homedir();\n const home = require('homedir-polyfill');\n return home();\n}\n\n// Allow NVU_HOME override for testing\nconst storagePath = (process.env.NVU_HOME || path.join(homedir(), '.nvu')) as string;\n\nconst hasTmpdir = typeof os.tmpdir === 'function';\nfunction tmpdir(): string {\n if (hasTmpdir) return os.tmpdir();\n const osShim = require('os-shim');\n return osShim.tmpdir();\n}\n\nfunction removeIfExistsSync(filePath: string): void {\n if (fs.existsSync(filePath)) {\n try {\n fs.unlinkSync(filePath);\n } catch (_e) {\n // ignore cleanup errors\n }\n }\n}\n\n/**\n * Get the platform-specific archive base name (without extension)\n */\nfunction getArchiveBaseName(): string | null {\n const { platform, arch } = process;\n\n const platformMap: PlatformMap = {\n darwin: 'darwin',\n linux: 'linux',\n win32: 'win32',\n };\n\n const archMap: PlatformMap = {\n x64: 'x64',\n arm64: 'arm64',\n amd64: 'x64',\n };\n\n const platformName = platformMap[platform];\n const archName = archMap[arch];\n\n if (!platformName || !archName) return null;\n return `nvu-binary-${platformName}-${archName}`;\n}\n\n/**\n * Copy file\n */\nfunction copyFileSync(src: string, dest: string): void {\n const content = fs.readFileSync(src);\n fs.writeFileSync(dest, content);\n}\n\n/**\n * Atomic rename with fallback to copy+delete for cross-device moves\n */\nfunction atomicRename(src: string, dest: string, callback: Callback): void {\n fs.rename(src, dest, (err) => {\n if (!err) {\n callback(null);\n return;\n }\n\n // Cross-device link error - fall back to copy + delete\n if ((err as NodeJS.ErrnoException).code === 'EXDEV') {\n try {\n copyFileSync(src, dest);\n fs.unlinkSync(src);\n callback(null);\n } catch (copyErr) {\n callback(copyErr as Error);\n }\n return;\n }\n\n callback(err);\n });\n}\n\n/**\n * Extract archive to a directory (callback-based)\n */\nfunction extractArchive(archivePath: string, dest: string, callback: Callback): void {\n const Iterator = isWindows ? require('zip-iterator') : require('tar-iterator');\n const stream = isWindows ? fs.createReadStream(archivePath) : fs.createReadStream(archivePath).pipe(require('zlib').createGunzip());\n let iterator = new Iterator(stream);\n\n // one by one\n const links = [];\n iterator.forEach(\n (entry, callback) => {\n if (entry.type === 'link') {\n links.unshift(entry);\n callback();\n } else if (entry.type === 'symlink') {\n links.push(entry);\n callback();\n } else entry.create(dest, callback);\n },\n { callbacks: true, concurrency: 1 },\n (_err) => {\n // create links after directories and files\n const queue = new Queue();\n for (let index = 0; index < links.length; index++) {\n const entry = links[index];\n queue.defer(entry.create.bind(entry, dest));\n }\n queue.await((err) => {\n iterator.destroy();\n iterator = null;\n callback(err);\n });\n }\n );\n}\n\n/**\n * Install binaries using atomic rename pattern\n * 1. Extract to temp directory\n * 2. Copy binary to temp files in destination directory\n * 3. Atomic rename temp files to final names\n */\nfunction extractAndInstall(archivePath: string, destDir: string, binaryName: string, callback: Callback): void {\n const ext = isWindows ? '.exe' : '';\n\n // Create temp extraction directory\n const tempExtractDir = path.join(tmpdir(), `nvu-extract-${Date.now()}`);\n mkdirp.sync(tempExtractDir);\n\n extractArchive(archivePath, tempExtractDir, (err) => {\n if (err) {\n safeRmSync(tempExtractDir);\n callback(err);\n return;\n }\n\n const extractedPath = path.join(tempExtractDir, binaryName);\n if (!fs.existsSync(extractedPath)) {\n safeRmSync(tempExtractDir);\n callback(new Error(`Extracted binary not found: ${binaryName}. ${archivePath} ${tempExtractDir}`));\n return;\n }\n\n // Binary names to install\n const binaries = ['node', 'npm', 'npx', 'corepack'];\n const timestamp = Date.now();\n let installError: Error | null = null;\n\n // Step 1: Copy extracted binary to temp files in destination directory\n // This ensures the temp files are on the same filesystem for atomic rename\n for (let i = 0; i < binaries.length; i++) {\n const name = binaries[i];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n\n try {\n // Copy to temp file in destination directory\n copyFileSync(extractedPath, tempDest);\n\n // Set permissions on Unix\n if (!isWindows) fs.chmodSync(tempDest, 0o755);\n } catch (err) {\n installError = err as Error;\n break;\n }\n }\n\n if (installError) {\n // Clean up any temp files we created\n for (let j = 0; j < binaries.length; j++) {\n const tempPath = path.join(destDir, `${binaries[j]}.tmp-${timestamp}${ext}`);\n removeIfExistsSync(tempPath);\n }\n safeRmSync(tempExtractDir);\n callback(installError);\n return;\n }\n\n // Step 2: Atomic rename temp files to final names\n let renameError: Error | null = null;\n\n function doRename(index: number): void {\n if (index >= binaries.length) {\n // All renames complete\n safeRmSync(tempExtractDir);\n callback(renameError);\n return;\n }\n\n const name = binaries[index];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n const finalDest = path.join(destDir, `${name}${ext}`);\n\n // Remove existing file if present (for atomic replacement)\n removeIfExistsSync(finalDest);\n\n atomicRename(tempDest, finalDest, (err) => {\n if (err && !renameError) {\n renameError = err;\n }\n doRename(index + 1);\n });\n }\n\n doRename(0);\n });\n}\n\n/**\n * Print setup instructions\n */\nmodule.exports.printInstructions = function printInstructions(): void {\n const nvuBinPath = path.join(storagePath, 'bin');\n\n console.log('nvu binaries installed in ~/.nvu/bin/');\n\n const pathKey = envPathKey();\n const envPath = process.env[pathKey] || '';\n if (envPath.indexOf('.nvu/bin') >= 0) return; // path exists\n\n // provide instructions for path setup\n console.log('');\n console.log('============================================================');\n console.log(' Global node setup');\n console.log('============================================================');\n console.log('');\n if (isWindows) {\n console.log(' PowerShell (add to $PROFILE):');\n console.log(` $env:PATH = \"${nvuBinPath};$env:PATH\"`);\n console.log('');\n console.log(' CMD (run as administrator):');\n console.log(` setx PATH \"${nvuBinPath};%PATH%\"`);\n } else {\n console.log(' # For bash (~/.bashrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.bashrc');\n console.log('');\n console.log(' # For zsh (~/.zshrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.zshrc');\n console.log('');\n console.log(' # For fish (~/.config/fish/config.fish):');\n console.log(\" echo 'set -gx PATH $HOME/.nvu/bin $PATH' >> ~/.config/fish/config.fish\");\n }\n\n console.log('');\n console.log('Then restart your terminal or source your shell profile.');\n console.log('');\n console.log(\"Without this, 'nvu 18 npm test' still works - you just won't have\");\n console.log(\"transparent 'node' command override.\");\n console.log('============================================================');\n};\n\n/**\n * Main installation function\n */\nmodule.exports.installBinaries = function installBinaries(options, callback): void {\n const archiveBaseName = getArchiveBaseName();\n\n if (!archiveBaseName) {\n callback(new Error('Unsupported platform/architecture for binary.'));\n return;\n }\n\n const extractedBinaryName = `${archiveBaseName}${isWindows ? '.exe' : ''}`;\n const binDir = path.join(storagePath, 'bin');\n\n // check if we need to upgrade\n if (!options.force) {\n try {\n // already installed\n if (fs.statSync(binDir)) {\n if (fs.readFileSync(path.join(binDir, 'version.txt'), 'utf8') === BINARY_VERSION) {\n callback(null, false);\n return;\n }\n }\n } catch (_err) {}\n }\n\n // Create directories\n mkdirp.sync(storagePath);\n mkdirp.sync(binDir);\n\n const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/binary-v${BINARY_VERSION}/${archiveBaseName}${isWindows ? '.zip' : '.tar.gz'}`;\n const tempPath = path.join(tmpdir(), `nvu-binary-${Date.now()}${isWindows ? '.zip' : '.tar.gz'}`);\n\n console.log(`Downloading binary for ${process.platform}-${process.arch}...`);\n\n getFile(downloadUrl, tempPath, (err) => {\n if (err) {\n removeIfExistsSync(tempPath);\n callback(new Error(`No prebuilt binary available for ${process.platform}-${process.arch}. Download: ${downloadUrl}. Error: ${err.message}`));\n return;\n }\n\n console.log('Extracting binary...');\n\n extractAndInstall(tempPath, binDir, extractedBinaryName, (err) => {\n removeIfExistsSync(tempPath);\n if (err) {\n callback(err);\n return;\n }\n\n // save binary version for upgrade checks\n fs.writeFileSync(path.join(binDir, 'version.txt'), BINARY_VERSION, 'utf8');\n console.log('Binary installed successfully!');\n callback(null, true);\n });\n });\n};\n"],"names":["envPathKey","require","fs","safeRmSync","getFile","mkdirp","os","path","Queue","moduleRoot","root","__dirname","GITHUB_REPO","BINARY_VERSION","join","binaryVersion","isWindows","process","platform","test","env","OSTYPE","hasHomedir","homedir","home","storagePath","NVU_HOME","hasTmpdir","tmpdir","osShim","removeIfExistsSync","filePath","existsSync","unlinkSync","_e","getArchiveBaseName","arch","platformMap","darwin","linux","win32","archMap","x64","arm64","amd64","platformName","archName","copyFileSync","src","dest","content","readFileSync","writeFileSync","atomicRename","callback","rename","err","code","copyErr","extractArchive","archivePath","Iterator","stream","createReadStream","pipe","createGunzip","iterator","links","forEach","entry","type","unshift","push","create","callbacks","concurrency","_err","queue","index","length","defer","bind","await","destroy","extractAndInstall","destDir","binaryName","ext","tempExtractDir","Date","now","sync","extractedPath","Error","binaries","timestamp","installError","i","name","tempDest","chmodSync","j","tempPath","renameError","doRename","finalDest","module","exports","printInstructions","nvuBinPath","console","log","pathKey","envPath","indexOf","installBinaries","options","archiveBaseName","extractedBinaryName","binDir","force","statSync","downloadUrl","message"],"mappings":"AAAA,MAAMA,aAAaC,QAAQ;AAC3B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ACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/assets/installBinaries.cts"],"sourcesContent":["const envPathKey = require('env-path-key');\nconst fs = require('fs');\nconst { safeRmSync } = require('fs-remove-compat');\nconst getFile = require('get-file-compat');\nconst mkdirp = require('mkdirp-classic');\nconst os = require('os');\nconst path = require('path');\nconst Queue = require('queue-cb');\nconst moduleRoot = require('module-root-sync');\n\nconst root = moduleRoot(__dirname);\n\n// Configuration\nconst GITHUB_REPO = 'kmalakoff/node-version-use';\nconst BINARY_VERSION = require(path.join(root, 'package.json')).binaryVersion;\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\ntype Callback = (err?: Error | null) => void;\n\ninterface PlatformMap {\n [key: string]: string;\n}\n\nconst hasHomedir = typeof os.homedir === 'function';\nfunction homedir(): string {\n if (hasHomedir) return os.homedir();\n const home = require('homedir-polyfill');\n return home();\n}\n\n// Allow NVU_HOME override for testing\nconst storagePath = (process.env.NVU_HOME || path.join(homedir(), '.nvu')) as string;\n\nconst hasTmpdir = typeof os.tmpdir === 'function';\nfunction tmpdir(): string {\n if (hasTmpdir) return os.tmpdir();\n const osShim = require('os-shim');\n return osShim.tmpdir();\n}\n\nfunction removeIfExistsSync(filePath: string): void {\n if (fs.existsSync(filePath)) {\n try {\n fs.unlinkSync(filePath);\n } catch (_e) {\n // ignore cleanup errors\n }\n }\n}\n\n/**\n * Get the platform-specific archive base name (without extension)\n */\nfunction getArchiveBaseName(): string | null {\n const { platform, arch } = process;\n\n const platformMap: PlatformMap = {\n darwin: 'darwin',\n linux: 'linux',\n win32: 'win32',\n };\n\n const archMap: PlatformMap = {\n x64: 'x64',\n arm64: 'arm64',\n amd64: 'x64',\n };\n\n const platformName = platformMap[platform];\n const archName = archMap[arch];\n\n if (!platformName || !archName) return null;\n return `nvu-binary-${platformName}-${archName}`;\n}\n\n/**\n * Copy file\n */\nfunction copyFileSync(src: string, dest: string): void {\n const content = fs.readFileSync(src);\n fs.writeFileSync(dest, content);\n}\n\n/**\n * Atomic rename with fallback to copy+delete for cross-device moves\n */\nfunction atomicRename(src: string, dest: string, callback: Callback) {\n fs.rename(src, dest, (err) => {\n if (!err) return callback(null);\n\n // Cross-device link error - fall back to copy + delete\n if ((err as NodeJS.ErrnoException).code === 'EXDEV') {\n try {\n copyFileSync(src, dest);\n fs.unlinkSync(src);\n callback(null);\n } catch (copyErr) {\n callback(copyErr as Error);\n }\n return;\n }\n\n callback(err);\n });\n}\n\n/**\n * Extract archive to a directory (callback-based)\n */\nfunction extractArchive(archivePath: string, dest: string, callback: Callback) {\n const Iterator = isWindows ? require('zip-iterator') : require('tar-iterator');\n const stream = isWindows ? fs.createReadStream(archivePath) : fs.createReadStream(archivePath).pipe(require('zlib').createGunzip());\n let iterator = new Iterator(stream);\n\n // one by one\n const links = [];\n iterator.forEach(\n (entry, callback) => {\n if (entry.type === 'link') {\n links.unshift(entry);\n callback();\n } else if (entry.type === 'symlink') {\n links.push(entry);\n callback();\n } else entry.create(dest, callback);\n },\n { callbacks: true, concurrency: 1 },\n (_err) => {\n // create links after directories and files\n const queue = new Queue();\n for (let index = 0; index < links.length; index++) {\n const entry = links[index];\n queue.defer(entry.create.bind(entry, dest));\n }\n queue.await((err) => {\n iterator.destroy();\n iterator = null;\n callback(err);\n });\n }\n );\n}\n\n/**\n * Install binaries using atomic rename pattern\n * 1. Extract to temp directory\n * 2. Copy binary to temp files in destination directory\n * 3. Atomic rename temp files to final names\n */\nfunction extractAndInstall(archivePath: string, destDir: string, binaryName: string, callback: Callback) {\n const ext = isWindows ? '.exe' : '';\n\n // Create temp extraction directory\n const tempExtractDir = path.join(tmpdir(), `nvu-extract-${Date.now()}`);\n mkdirp.sync(tempExtractDir);\n\n extractArchive(archivePath, tempExtractDir, (err) => {\n if (err) {\n safeRmSync(tempExtractDir);\n callback(err);\n return;\n }\n\n const extractedPath = path.join(tempExtractDir, binaryName);\n if (!fs.existsSync(extractedPath)) {\n safeRmSync(tempExtractDir);\n callback(new Error(`Extracted binary not found: ${binaryName}. ${archivePath} ${tempExtractDir}`));\n return;\n }\n\n // Binary names to install\n const binaries = ['node', 'npm', 'npx', 'corepack'];\n const timestamp = Date.now();\n let installError: Error | null = null;\n\n // Step 1: Copy extracted binary to temp files in destination directory\n // This ensures the temp files are on the same filesystem for atomic rename\n for (let i = 0; i < binaries.length; i++) {\n const name = binaries[i];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n\n try {\n // Copy to temp file in destination directory\n copyFileSync(extractedPath, tempDest);\n\n // Set permissions on Unix\n if (!isWindows) fs.chmodSync(tempDest, 0o755);\n } catch (err) {\n installError = err as Error;\n break;\n }\n }\n\n if (installError) {\n // Clean up any temp files we created\n for (let j = 0; j < binaries.length; j++) {\n const tempPath = path.join(destDir, `${binaries[j]}.tmp-${timestamp}${ext}`);\n removeIfExistsSync(tempPath);\n }\n safeRmSync(tempExtractDir);\n callback(installError);\n return;\n }\n\n // Step 2: Atomic rename temp files to final names\n let renameError: Error | null = null;\n\n function doRename(index: number): void {\n if (index >= binaries.length) {\n // All renames complete\n safeRmSync(tempExtractDir);\n callback(renameError);\n return;\n }\n\n const name = binaries[index];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n const finalDest = path.join(destDir, `${name}${ext}`);\n\n // Remove existing file if present (for atomic replacement)\n removeIfExistsSync(finalDest);\n\n atomicRename(tempDest, finalDest, (err) => {\n if (err && !renameError) {\n renameError = err;\n }\n doRename(index + 1);\n });\n }\n\n doRename(0);\n });\n}\n\n/**\n * Print setup instructions\n */\nmodule.exports.printInstructions = function printInstructions(): void {\n const _nvuBinPath = path.join(storagePath, 'bin');\n\n console.log('nvu binaries installed in ~/.nvu/bin/');\n\n const pathKey = envPathKey();\n const envPath = process.env[pathKey] || '';\n if (envPath.indexOf('.nvu/bin') >= 0) return; // path exists\n\n // provide instructions for path setup\n console.log('');\n console.log('============================================================');\n console.log(' Global node setup');\n console.log('============================================================');\n console.log('');\n if (isWindows) {\n console.log(' # Edit your PowerShell profile');\n console.log(' # Open with: notepad $PROFILE');\n console.log(' # Add this line:');\n console.log(' $env:PATH = \"$HOME\\\\.nvu\\\\bin;$env:APPDATA\\\\npm;$env:PATH\"');\n console.log('');\n console.log(' # This adds:');\n console.log(' # ~/.nvu/bin - node/npm version switching shims');\n console.log(' # %APPDATA%/npm - globally installed npm packages (like nvu)');\n } else {\n console.log(' # For bash (~/.bashrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.bashrc');\n console.log('');\n console.log(' # For zsh (~/.zshrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.zshrc');\n console.log('');\n console.log(' # For fish (~/.config/fish/config.fish):');\n console.log(\" echo 'set -gx PATH $HOME/.nvu/bin $PATH' >> ~/.config/fish/config.fish\");\n }\n\n console.log('');\n console.log('Then restart your terminal or source your shell profile.');\n console.log('');\n console.log(\"Without this, 'nvu 18 npm test' still works - you just won't have\");\n console.log(\"transparent 'node' command override.\");\n console.log('============================================================');\n};\n\n/**\n * Main installation function\n */\nmodule.exports.installBinaries = function installBinaries(options, callback): void {\n const archiveBaseName = getArchiveBaseName();\n\n if (!archiveBaseName) {\n callback(new Error('Unsupported platform/architecture for binary.'));\n return;\n }\n\n const extractedBinaryName = `${archiveBaseName}${isWindows ? '.exe' : ''}`;\n const binDir = path.join(storagePath, 'bin');\n\n // check if we need to upgrade\n if (!options.force) {\n try {\n // already installed\n if (fs.statSync(binDir)) {\n if (fs.readFileSync(path.join(binDir, 'version.txt'), 'utf8') === BINARY_VERSION) {\n callback(null, false);\n return;\n }\n }\n } catch (_err) {}\n }\n\n // Create directories\n mkdirp.sync(storagePath);\n mkdirp.sync(binDir);\n\n const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/binary-v${BINARY_VERSION}/${archiveBaseName}${isWindows ? '.zip' : '.tar.gz'}`;\n const tempPath = path.join(tmpdir(), `nvu-binary-${Date.now()}${isWindows ? '.zip' : '.tar.gz'}`);\n\n console.log(`Downloading binary for ${process.platform}-${process.arch}...`);\n\n getFile(downloadUrl, tempPath, (err) => {\n if (err) {\n removeIfExistsSync(tempPath);\n callback(new Error(`No prebuilt binary available for ${process.platform}-${process.arch}. Download: ${downloadUrl}. Error: ${err.message}`));\n return;\n }\n\n console.log('Extracting binary...');\n\n extractAndInstall(tempPath, binDir, extractedBinaryName, (err) => {\n removeIfExistsSync(tempPath);\n if (err) return callback(err);\n\n // save binary version for upgrade checks\n fs.writeFileSync(path.join(binDir, 'version.txt'), BINARY_VERSION, 'utf8');\n console.log('Binary installed successfully!');\n callback(null, true);\n });\n });\n};\n"],"names":["envPathKey","require","fs","safeRmSync","getFile","mkdirp","os","path","Queue","moduleRoot","root","__dirname","GITHUB_REPO","BINARY_VERSION","join","binaryVersion","isWindows","process","platform","test","env","OSTYPE","hasHomedir","homedir","home","storagePath","NVU_HOME","hasTmpdir","tmpdir","osShim","removeIfExistsSync","filePath","existsSync","unlinkSync","_e","getArchiveBaseName","arch","platformMap","darwin","linux","win32","archMap","x64","arm64","amd64","platformName","archName","copyFileSync","src","dest","content","readFileSync","writeFileSync","atomicRename","callback","rename","err","code","copyErr","extractArchive","archivePath","Iterator","stream","createReadStream","pipe","createGunzip","iterator","links","forEach","entry","type","unshift","push","create","callbacks","concurrency","_err","queue","index","length","defer","bind","await","destroy","extractAndInstall","destDir","binaryName","ext","tempExtractDir","Date","now","sync","extractedPath","Error","binaries","timestamp","installError","i","name","tempDest","chmodSync","j","tempPath","renameError","doRename","finalDest","module","exports","printInstructions","_nvuBinPath","console","log","pathKey","envPath","indexOf","installBinaries","options","archiveBaseName","extractedBinaryName","binDir","force","statSync","downloadUrl","message"],"mappings":"AAAA,MAAMA,aAAaC,QAAQ;AAC3B,MAAMC,KAAKD,QAAQ;AACnB,MAAM,EAAEE,UAAU,EAAE,GAAGF,QAAQ;AAC/B,MAAMG,UAAUH,QA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;gBACvB,IAAIrH,GAAGiD,YAAY,CAAC5C,KAAKO,IAAI,CAACyG,QAAQ,gBAAgB,YAAY1G,gBAAgB;oBAChFyC,SAAS,MAAM;oBACf;gBACF;YACF;QACF,EAAE,OAAOsB,MAAM,CAAC;IAClB;IAEA,qBAAqB;IACrBvE,OAAOsF,IAAI,CAAClE;IACZpB,OAAOsF,IAAI,CAAC4B;IAEZ,MAAMG,cAAc,CAAC,mBAAmB,EAAE9G,YAAY,2BAA2B,EAAEC,eAAe,CAAC,EAAEwG,kBAAkBrG,YAAY,SAAS,WAAW;IACvJ,MAAMsF,WAAW/F,KAAKO,IAAI,CAACc,UAAU,CAAC,WAAW,EAAE6D,KAAKC,GAAG,KAAK1E,YAAY,SAAS,WAAW;IAEhG8F,QAAQC,GAAG,CAAC,CAAC,uBAAuB,EAAE9F,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQmB,IAAI,CAAC,GAAG,CAAC;IAE3EhC,QAAQsH,aAAapB,UAAU,CAAC9C;QAC9B,IAAIA,KAAK;YACP1B,mBAAmBwE;YACnBhD,SAAS,IAAIuC,MAAM,CAAC,iCAAiC,EAAE5E,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQmB,IAAI,CAAC,YAAY,EAAEsF,YAAY,SAAS,EAAElE,IAAImE,OAAO,EAAE;YAC1I;QACF;QAEAb,QAAQC,GAAG,CAAC;QAEZ3B,kBAAkBkB,UAAUiB,QAAQD,qBAAqB,CAAC9D;YACxD1B,mBAAmBwE;YACnB,IAAI9C,KAAK,OAAOF,SAASE;YAEzB,yCAAyC;YACzCtD,GAAGkD,aAAa,CAAC7C,KAAKO,IAAI,CAACyG,QAAQ,gBAAgB1G,gBAAgB;YACnEiG,QAAQC,GAAG,CAAC;YACZzD,SAAS,MAAM;QACjB;IACF;AACF"}
package/dist/esm/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: (argv: string[], name: string) => undefined;
1
+ declare const _default: (argv: string[], name: string) => void;
2
2
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/cli.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport getopts from 'getopts-compat';\nimport path from 'path';\nimport { createSession, figures, formatArguments } from 'spawn-term';\nimport url from 'url';\nimport { isCommand, runCommand } from './commands/index.ts';\nimport run from './index.ts';\nimport type { UseError, UseOptions, UseResult } from './types.ts';\n\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nconst ERROR_CODE = 13;\n\nfunction getVersion(): string {\n const packagePath = path.join(__dirname, '..', '..', 'package.json');\n const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));\n return packageJson.version;\n}\n\nfunction printHelp(name: string): void {\n const version = getVersion();\n console.log(`${name} v${version}`);\n console.log('');\n console.log(`Usage: ${name} [options] <version> <command> [args...]`);\n console.log(` ${name} <subcommand> [args...]`);\n console.log('');\n console.log('Run commands with specific Node.js versions');\n console.log('');\n console.log('Subcommands:');\n console.log(' default [version] Set or display the global default Node version');\n console.log(' local [version] Set or display the local Node version (.nvmrc)');\n console.log(' install <version> Download and install a Node version');\n console.log(' uninstall <version> Remove an installed Node version');\n console.log(' list List installed Node versions');\n console.log(' which Show which Node version would be used');\n console.log(' setup Install/reinstall binaries to ~/.nvu/bin');\n console.log(' teardown Remove binaries from ~/.nvu/bin');\n console.log('');\n console.log('Options:');\n console.log(' -v, --version Print version number');\n console.log(' -h, --help Print this help message');\n console.log(' -r, --range Range type (major, minor, patch) with filters (lts, even, odd)');\n console.log(' Default: major,even');\n console.log(' -d, --desc Sort versions in descending order');\n console.log(' -e, --expanded Use expanded version format');\n console.log(' -s, --streaming Enable streaming output');\n console.log(' --silent Suppress logging');\n console.log('');\n console.log('Examples:');\n console.log(` ${name} 22 node --version Run with Node 22`);\n console.log(` ${name} 22,20,18 npm test Run with multiple versions`);\n console.log(` ${name} engines node --version Use version from package.json`);\n console.log(` ${name} default 20 Set global default to Node 20`);\n console.log(` ${name} local 18 Create .nvmrc with Node 18`);\n}\n\nexport default (argv: string[], name: string): undefined => {\n const options = getopts(argv, {\n alias: { range: 'r', desc: 'd', expanded: 'e', streaming: 's', silent: 'si', version: 'v', help: 'h' },\n default: { range: 'major,even', interactive: true },\n boolean: ['silent', 'desc', 'expanded', 'streaming', 'interactive', 'version', 'help'],\n stopEarly: true,\n });\n\n if (options.version) {\n console.log(getVersion());\n exit(0);\n return;\n }\n\n if (options.help) {\n printHelp(name);\n exit(0);\n return;\n }\n\n // Check if first argument is a subcommand\n const args = options._;\n if (args.length > 0 && isCommand(args[0])) {\n runCommand(args[0], args.slice(1));\n return;\n }\n\n // define.option('-r, --range [range]', 'range type of major, minor, or patch with filters of lts, even, odd for version string expressions', 'major,even');\n // define.option('-s, --silent', 'suppress logging', false);\n options.sort = options.desc ? -1 : 1;\n\n if (args.length === 0) {\n console.log(`Missing version expression. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n if (args.length === 1) {\n console.log(`Missing command. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n\n options.stdio = 'inherit'; // pass through stdio\n run(args[0], args[1], args.slice(2), options as unknown as UseOptions, (err: UseError, results: UseResult[]): undefined => {\n if (err && !err.results) {\n console.log(err.message);\n exit(ERROR_CODE);\n return;\n }\n if (err) results = err.results;\n const errors = results.filter((result) => !!result.error);\n\n if (!options.silent) {\n if (!createSession) {\n console.log('\\n======================');\n results.forEach((res) => {\n console.log(`${res.error ? figures.cross : figures.tick} ${res.version}${res.error ? ` Error: ${res.error.message}` : ''}`);\n });\n console.log('\\n----------------------');\n console.log(`${name} ${formatArguments(args).join(' ')}`);\n console.log(`${figures.tick} ${results.length - errors.length} succeeded`);\n if (errors.length) console.log(`${figures.cross} ${errors.length} failed`);\n }\n }\n exit(err || errors.length ? ERROR_CODE : 0);\n });\n};\n"],"names":["exit","fs","getopts","path","createSession","figures","formatArguments","url","isCommand","runCommand","run","__dirname","dirname","__filename","fileURLToPath","ERROR_CODE","getVersion","packagePath","join","packageJson","JSON","parse","readFileSync","version","printHelp","name","console","log","argv","options","alias","range","desc","expanded","streaming","silent","help","default","interactive","boolean","stopEarly","args","_","length","slice","sort","stdio","err","results","message","errors","filter","result","error","forEach","res","cross","tick"],"mappings":"AAAA,OAAOA,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,aAAa,iBAAiB;AACrC,OAAOC,UAAU,OAAO;AACxB,SAASC,aAAa,EAAEC,OAAO,EAAEC,eAAe,QAAQ,aAAa;AACrE,OAAOC,SAAS,MAAM;AACtB,SAASC,SAAS,EAAEC,UAAU,QAAQ,sBAAsB;AAC5D,OAAOC,SAAS,aAAa;AAG7B,MAAMC,YAAYR,KAAKS,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaN,IAAIO,aAAa,CAAC,YAAYP,GAAG;AAEjH,MAAMQ,aAAa;AAEnB,SAASC;IACP,MAAMC,cAAcd,KAAKe,IAAI,CAACP,WAAW,MAAM,MAAM;IACrD,MAAMQ,cAAcC,KAAKC,KAAK,CAACpB,GAAGqB,YAAY,CAACL,aAAa;IAC5D,OAAOE,YAAYI,OAAO;AAC5B;AAEA,SAASC,UAAUC,IAAY;IAC7B,MAAMF,UAAUP;IAChBU,QAAQC,GAAG,CAAC,GAAGF,KAAK,EAAE,EAAEF,SAAS;IACjCG,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC,CAAC,OAAO,EAAEF,KAAK,wCAAwC,CAAC;IACpEC,QAAQC,GAAG,CAAC,CAAC,OAAO,EAAEF,KAAK,uBAAuB,CAAC;IACnDC,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;IACZD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AAQ,EAAEE,IAAIF,KAAK,CAACJ,OAAO,EAAE,GAAG,IAAI;gBAC5H;gBACAvB,QAAQC,GAAG,CAAC;gBACZD,QAAQC,GAAG,CAAC,GAAGF,KAAK,CAAC,EAAEnB,gBAAgBmC,MAAMvB,IAAI,CAAC,MAAM;gBACxDQ,QAAQC,GAAG,CAAC,GAAGtB,QAAQoD,IAAI,CAAC,CAAC,EAAET,QAAQL,MAAM,GAAGO,OAAOP,MAAM,CAAC,UAAU,CAAC;gBACzE,IAAIO,OAAOP,MAAM,EAAEjB,QAAQC,GAAG,CAAC,GAAGtB,QAAQmD,KAAK,CAAC,CAAC,EAAEN,OAAOP,MAAM,CAAC,OAAO,CAAC;YAC3E;QACF;QACA3C,KAAK+C,OAAOG,OAAOP,MAAM,GAAG5B,aAAa;IAC3C;AACF,CAAA,EAAE"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/cli.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport getopts from 'getopts-compat';\nimport path from 'path';\nimport { createSession, figures, formatArguments } from 'spawn-term';\nimport url from 'url';\nimport { isCommand, runCommand } from './commands/index.ts';\nimport run from './index.ts';\nimport type { UseError, UseOptions, UseResult } from './types.ts';\n\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\nconst ERROR_CODE = 13;\n\nfunction getVersion(): string {\n const packagePath = path.join(__dirname, '..', '..', 'package.json');\n const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));\n return packageJson.version;\n}\n\nfunction printHelp(name: string): void {\n const version = getVersion();\n console.log(`${name} v${version}`);\n console.log('');\n console.log(`Usage: ${name} [options] <version> <command> [args...]`);\n console.log(` ${name} <subcommand> [args...]`);\n console.log('');\n console.log('Run commands with specific Node.js versions');\n console.log('');\n console.log('Subcommands:');\n console.log(' default [version] Set or display the global default Node version');\n console.log(' local [version] Set or display the local Node version (.nvmrc)');\n console.log(' install <version> Download and install a Node version');\n console.log(' uninstall <version> Remove an installed Node version');\n console.log(' list List installed Node versions');\n console.log(' which Show which Node version would be used');\n console.log(' setup Install/reinstall binaries to ~/.nvu/bin');\n console.log(' teardown Remove binaries from ~/.nvu/bin');\n console.log('');\n console.log('Options:');\n console.log(' -v, --version Print version number');\n console.log(' -h, --help Print this help message');\n console.log(' -r, --range Range type (major, minor, patch) with filters (lts, even, odd)');\n console.log(' Default: major,even');\n console.log(' -d, --desc Sort versions in descending order');\n console.log(' -e, --expanded Use expanded version format');\n console.log(' -s, --streaming Enable streaming output');\n console.log(' --silent Suppress logging');\n console.log('');\n console.log('Examples:');\n console.log(` ${name} 22 node --version Run with Node 22`);\n console.log(` ${name} 22,20,18 npm test Run with multiple versions`);\n console.log(` ${name} engines node --version Use version from package.json`);\n console.log(` ${name} default 20 Set global default to Node 20`);\n console.log(` ${name} local 18 Create .nvmrc with Node 18`);\n}\n\nexport default (argv: string[], name: string): void => {\n const options = getopts(argv, {\n alias: { range: 'r', desc: 'd', expanded: 'e', streaming: 's', silent: 'si', version: 'v', help: 'h' },\n default: { range: 'major,even', interactive: true },\n boolean: ['silent', 'desc', 'expanded', 'streaming', 'interactive', 'version', 'help'],\n stopEarly: true,\n });\n\n if (options.version) {\n console.log(getVersion());\n exit(0);\n return;\n }\n\n if (options.help) {\n printHelp(name);\n exit(0);\n return;\n }\n\n // Check if first argument is a subcommand\n const args = options._;\n if (args.length > 0 && isCommand(args[0])) {\n runCommand(args[0], args.slice(1));\n return;\n }\n\n // define.option('-r, --range [range]', 'range type of major, minor, or patch with filters of lts, even, odd for version string expressions', 'major,even');\n // define.option('-s, --silent', 'suppress logging', false);\n options.sort = options.desc ? -1 : 1;\n\n if (args.length === 0) {\n console.log(`Missing version expression. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n if (args.length === 1) {\n console.log(`Missing command. Example usage: ${name} version command arg1 arg2`);\n exit(ERROR_CODE);\n return;\n }\n\n options.stdio = 'inherit'; // pass through stdio\n run(args[0], args[1], args.slice(2), options as unknown as UseOptions, (err: UseError, results: UseResult[]): void => {\n if (err && !err.results) {\n console.log(err.message);\n exit(ERROR_CODE);\n return;\n }\n if (err) results = err.results;\n const errors = results.filter((result) => !!result.error);\n\n if (!options.silent) {\n if (!createSession) {\n console.log('\\n======================');\n results.forEach((res) => {\n console.log(`${res.error ? figures.cross : figures.tick} ${res.version}${res.error ? ` Error: ${res.error.message}` : ''}`);\n });\n console.log('\\n----------------------');\n console.log(`${name} ${formatArguments(args).join(' ')}`);\n console.log(`${figures.tick} ${results.length - errors.length} succeeded`);\n if (errors.length) console.log(`${figures.cross} ${errors.length} failed`);\n }\n }\n exit(err || errors.length ? ERROR_CODE : 0);\n });\n};\n"],"names":["exit","fs","getopts","path","createSession","figures","formatArguments","url","isCommand","runCommand","run","__dirname","dirname","__filename","fileURLToPath","ERROR_CODE","getVersion","packagePath","join","packageJson","JSON","parse","readFileSync","version","printHelp","name","console","log","argv","options","alias","range","desc","expanded","streaming","silent","help","default","interactive","boolean","stopEarly","args","_","length","slice","sort","stdio","err","results","message","errors","filter","result","error","forEach","res","cross","tick"],"mappings":"AAAA,OAAOA,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,aAAa,iBAAiB;AACrC,OAAOC,UAAU,OAAO;AACxB,SAASC,aAAa,EAAEC,OAAO,EAAEC,eAAe,QAAQ,aAAa;AACrE,OAAOC,SAAS,MAAM;AACtB,SAASC,SAAS,EAAEC,UAAU,QAAQ,sBAAsB;AAC5D,OAAOC,SAAS,aAAa;AAG7B,MAAMC,YAAYR,KAAKS,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaN,IAAIO,aAAa,CAAC,YAAYP,GAAG;AAEjH,MAAMQ,aAAa;AAEnB,SAASC;IACP,MAAMC,cAAcd,KAAKe,IAAI,CAACP,WAAW,MAAM,MAAM;IACrD,MAAMQ,cAAcC,KAAKC,KAAK,CAACpB,GAAGqB,YA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A,IAAIC,OAAO,EAAE;YACvBtB,QAAQC,GAAG,CAACoB,IAAIE,OAAO;YACvBjD,KAAKe;YACL;QACF;QACA,IAAIgC,KAAKC,UAAUD,IAAIC,OAAO;QAC9B,MAAME,SAASF,QAAQG,MAAM,CAAC,CAACC,SAAW,CAAC,CAACA,OAAOC,KAAK;QAExD,IAAI,CAACxB,QAAQM,MAAM,EAAE;YACnB,IAAI,CAAC/B,eAAe;gBAClBsB,QAAQC,GAAG,CAAC;gBACZqB,QAAQM,OAAO,CAAC,CAACC;oBACf7B,QAAQC,GAAG,CAAC,GAAG4B,IAAIF,KAAK,GAAGhD,QAAQmD,KAAK,GAAGnD,QAAQoD,IAAI,CAAC,CAAC,EAAEF,IAAIhC,OAAO,GAAGgC,IAAIF,KAAK,GAAG,CAAC,QAAQ,EAAEE,IAAIF,KAAK,CAACJ,OAAO,EAAE,GAAG,IAAI;gBAC5H;gBACAvB,QAAQC,GAAG,CAAC;gBACZD,QAAQC,GAAG,CAAC,GAAGF,KAAK,CAAC,EAAEnB,gBAAgBmC,MAAMvB,IAAI,CAAC,MAAM;gBACxDQ,QAAQC,GAAG,CAAC,GAAGtB,QAAQoD,IAAI,CAAC,CAAC,EAAET,QAAQL,MAAM,GAAGO,OAAOP,MAAM,CAAC,UAAU,CAAC;gBACzE,IAAIO,OAAOP,MAAM,EAAEjB,QAAQC,GAAG,CAAC,GAAGtB,QAAQmD,KAAK,CAAC,CAAC,EAAEN,OAAOP,MAAM,CAAC,OAAO,CAAC;YAC3E;QACF;QACA3C,KAAK+C,OAAOG,OAAOP,MAAM,GAAG5B,aAAa;IAC3C;AACF,CAAA,EAAE"}
@@ -7,17 +7,11 @@ import os from 'os';
7
7
  import path from 'path';
8
8
  // Use existing require in CJS, or createRequire in ESM (Node 12.2+)
9
9
  const _require = typeof require === 'undefined' ? _Module.createRequire(import.meta.url) : require;
10
- const hasHomedir = typeof os.homedir === 'function';
11
10
  export function homedir() {
12
- if (hasHomedir) return os.homedir();
13
- const home = require('homedir-polyfill');
14
- return home();
11
+ return typeof os.homedir === 'function' ? os.homedir() : require('homedir-polyfill')();
15
12
  }
16
- const hasTmpdir = typeof os.tmpdir === 'function';
17
13
  export function tmpdir() {
18
- if (hasTmpdir) return os.tmpdir();
19
- const osShim = require('os-shim');
20
- return osShim.tmpdir();
14
+ return typeof os.tmpdir === 'function' ? os.tmpdir() : require('os-shim').tmpdir();
21
15
  }
22
16
  /**
23
17
  * String.prototype.endsWith wrapper for Node.js 0.8+
@@ -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 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+)\nconst _require = typeof require === 'undefined' ? _Module.createRequire(import.meta.url) : require;\n\nconst hasHomedir = typeof os.homedir === 'function';\nexport function homedir(): string {\n if (hasHomedir) return os.homedir();\n const home = require('homedir-polyfill');\n return home();\n}\n\nconst hasTmpdir = typeof os.tmpdir === 'function';\nexport function tmpdir(): string {\n if (hasTmpdir) return os.tmpdir();\n const osShim = require('os-shim');\n return osShim.tmpdir();\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 */\nconst 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 const 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 const 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 const 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 const names = fs.readdirSync(dir);\n return names.map((name) => {\n const fullPath = path.join(dir, name);\n let 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","hasTmpdir","tmpdir","osShim","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,MAAMC,WAAW,OAAOC,YAAY,cAAcJ,QAAQK,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE3F,MAAMG,aAAa,OAAON,GAAGO,OAAO,KAAK;AACzC,OAAO,SAASA;IACd,IAAID,YAAY,OAAON,GAAGO,OAAO;IACjC,MAAMC,OAAOL,QAAQ;IACrB,OAAOK;AACT;AAEA,MAAMC,YAAY,OAAOT,GAAGU,MAAM,KAAK;AACvC,OAAO,SAASA;IACd,IAAID,WAAW,OAAOT,GAAGU,MAAM;IAC/B,MAAMC,SAASR,QAAQ;IACvB,OAAOQ,OAAOD,MAAM;AACtB;AAEA;;;;CAIC,GACD,MAAME,cAAc,OAAOC,OAAOC,SAAS,CAACC,QAAQ,KAAK;AAEzD,OAAO,SAASC,eAAeC,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIP,aAAa;QACf,OAAOK,IAAIF,QAAQ,CAACG,QAAQC;IAC9B;IACA,MAAMC,MAAMD,aAAaE,YAAYJ,IAAIK,MAAM,GAAGH;IAClD,OAAOF,IAAIM,WAAW,CAACL,YAAYE,MAAMF,OAAOI,MAAM;AACxD;AAEA;;CAEC,GACD,OAAO,SAASE,WAAWC,GAAW;IACpC,MAAMC,SAASxB,SAAS;IACxBwB,OAAOC,IAAI,CAACF;AACd;AAEA;;CAEC,GACD,OAAO,SAASG,OAAOH,GAAW;IAChC,MAAMI,aAAa3B,SAAS,oBAAoB2B,UAAU;IAC1DA,WAAWJ;AACb;AAWA,OAAO,SAASK,iBAAiBL,GAAW;IAC1C,MAAMM,QAAQjC,GAAGkC,WAAW,CAACP;IAC7B,OAAOM,MAAME,GAAG,CAAC,CAACC;QAChB,MAAMC,WAAWlC,KAAKmC,IAAI,CAACX,KAAKS;QAChC,IAAIG;QACJ,IAAI;YACFA,OAAOvC,GAAGwC,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"}
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+)\nconst _require = typeof require === 'undefined' ? _Module.createRequire(import.meta.url) : require;\n\nexport function homedir(): string {\n return typeof os.homedir === 'function' ? os.homedir() : require('homedir-polyfill')();\n}\n\nexport function tmpdir(): string {\n return typeof os.tmpdir === 'function' ? os.tmpdir() : require('os-shim').tmpdir();\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 */\nconst 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 const 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 const 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 const 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 const names = fs.readdirSync(dir);\n return names.map((name) => {\n const fullPath = path.join(dir, name);\n let 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","homedir","tmpdir","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,MAAMC,WAAW,OAAOC,YAAY,cAAcJ,QAAQK,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE3F,OAAO,SAASG;IACd,OAAO,OAAON,GAAGM,OAAO,KAAK,aAAaN,GAAGM,OAAO,KAAKH,QAAQ;AACnE;AAEA,OAAO,SAASI;IACd,OAAO,OAAOP,GAAGO,MAAM,KAAK,aAAaP,GAAGO,MAAM,KAAKJ,QAAQ,WAAWI,MAAM;AAClF;AAEA;;;;CAIC,GACD,MAAMC,cAAc,OAAOC,OAAOC,SAAS,CAACC,QAAQ,KAAK;AAEzD,OAAO,SAASC,eAAeC,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIP,aAAa;QACf,OAAOK,IAAIF,QAAQ,CAACG,QAAQC;IAC9B;IACA,MAAMC,MAAMD,aAAaE,YAAYJ,IAAIK,MAAM,GAAGH;IAClD,OAAOF,IAAIM,WAAW,CAACL,YAAYE,MAAMF,OAAOI,MAAM;AACxD;AAEA;;CAEC,GACD,OAAO,SAASE,WAAWC,GAAW;IACpC,MAAMC,SAASpB,SAAS;IACxBoB,OAAOC,IAAI,CAACF;AACd;AAEA;;CAEC,GACD,OAAO,SAASG,OAAOH,GAAW;IAChC,MAAMI,aAAavB,SAAS,oBAAoBuB,UAAU;IAC1DA,WAAWJ;AACb;AAWA,OAAO,SAASK,iBAAiBL,GAAW;IAC1C,MAAMM,QAAQ7B,GAAG8B,WAAW,CAACP;IAC7B,OAAOM,MAAME,GAAG,CAAC,CAACC;QAChB,MAAMC,WAAW9B,KAAK+B,IAAI,CAACX,KAAKS;QAChC,IAAIG;QACJ,IAAI;YACFA,OAAOnC,GAAGoC,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"}
@@ -2,5 +2,5 @@ import type { UseCallback, UseOptions, UseResult } from './types.js';
2
2
  export type * from './types.js';
3
3
  export default function nodeVersionUse(versionExpression: string, command: string, args: string[]): Promise<UseResult[]>;
4
4
  export default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions): Promise<UseResult[]>;
5
- export default function nodeVersionUse(versionExpression: string, command: string, args: string[], callback: UseCallback): undefined;
6
- export default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): undefined;
5
+ export default function nodeVersionUse(versionExpression: string, command: string, args: string[], callback: UseCallback): void;
6
+ export default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/index.ts"],"sourcesContent":["import type { UseCallback, UseOptions, UseResult } from './types.ts';\nimport worker from './worker.ts';\n\nexport type * from './types.ts';\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[]): Promise<UseResult[]>;\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions): Promise<UseResult[]>;\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], callback: UseCallback): undefined;\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): undefined;\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options?: UseOptions | UseCallback, callback?: UseCallback): undefined | Promise<UseResult[]> {\n if (typeof options === 'function') {\n callback = options as UseCallback;\n options = {};\n }\n options = options || {};\n\n if (typeof callback === 'function') return worker(versionExpression, command, args, options, callback) as undefined;\n return new Promise((resolve, reject) =>\n worker(versionExpression, command, args, options, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n}\n"],"names":["worker","nodeVersionUse","versionExpression","command","args","options","callback","Promise","resolve","reject","err","result"],"mappings":"AACA,OAAOA,YAAY,cAAc;AAUjC,eAAe,SAASC,eAAeC,iBAAyB,EAAEC,OAAe,EAAEC,IAAc,EAAEC,OAAkC,EAAEC,QAAsB;IAC3J,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAON,OAAOE,mBAAmBC,SAASC,MAAMC,SAASC;IAC7F,OAAO,IAAIC,QAAQ,CAACC,SAASC,SAC3BT,OAAOE,mBAAmBC,SAASC,MAAMC,SAAS,CAACK,KAAKC;YACtDD,MAAMD,OAAOC,OAAOF,QAAQG;QAC9B;AAEJ"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/index.ts"],"sourcesContent":["import type { UseCallback, UseOptions, UseResult } from './types.ts';\nimport worker from './worker.ts';\n\nexport type * from './types.ts';\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[]): Promise<UseResult[]>;\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions): Promise<UseResult[]>;\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], callback: UseCallback): void;\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void;\n\nexport default function nodeVersionUse(versionExpression: string, command: string, args: string[], options?: UseOptions | UseCallback, callback?: UseCallback): void | Promise<UseResult[]> {\n if (typeof options === 'function') {\n callback = options as UseCallback;\n options = {};\n }\n options = options || {};\n\n if (typeof callback === 'function') return worker(versionExpression, command, args, options, callback);\n return new Promise((resolve, reject) =>\n worker(versionExpression, command, args, options as UseOptions, (err, result) => {\n err ? reject(err) : resolve(result);\n })\n );\n}\n"],"names":["worker","nodeVersionUse","versionExpression","command","args","options","callback","Promise","resolve","reject","err","result"],"mappings":"AACA,OAAOA,YAAY,cAAc;AAUjC,eAAe,SAASC,eAAeC,iBAAyB,EAAEC,OAAe,EAAEC,IAAc,EAAEC,OAAkC,EAAEC,QAAsB;IAC3J,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAON,OAAOE,mBAAmBC,SAASC,MAAMC,SAASC;IAC7F,OAAO,IAAIC,QAAQ,CAACC,SAASC,SAC3BT,OAAOE,mBAAmBC,SAASC,MAAMC,SAAuB,CAACK,KAAKC;YACpED,MAAMD,OAAOC,OAAOF,QAAQG;QAC9B;AAEJ"}
@@ -20,10 +20,7 @@ function loadModule(moduleName, callback) {
20
20
  }
21
21
  }
22
22
  export default function loadNodeVersionInstall(callback) {
23
- if (cached !== undefined) {
24
- callback(null, cached);
25
- return;
26
- }
23
+ if (cached !== undefined) return callback(null, cached);
27
24
  installModule(moduleName, nodeModules, {}, (err)=>{
28
25
  if (err) return callback(err, null);
29
26
  loadModule(moduleName, (err, _cached)=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/lib/loadNodeVersionInstall.ts"],"sourcesContent":["import installModule from 'install-module-linked';\nimport type { InstallOptions, InstallResult } from 'node-version-install';\nimport path from 'path';\nimport url from 'url';\n\nconst _dirname = path.dirname(typeof __dirname !== 'undefined' ? __dirname : url.fileURLToPath(import.meta.url));\nconst nodeModules = path.join(_dirname, '..', '..', '..', 'node_modules');\nconst moduleName = 'node-version-install';\n\ntype InstallCallback = (err?: Error, results?: InstallResult[]) => void;\ntype InstallVersionFn = (version: string, options: InstallOptions, callback: InstallCallback) => void;\n\nlet cached: InstallVersionFn | undefined;\n\nfunction loadModule(moduleName, callback) {\n if (typeof require === 'undefined') {\n import(moduleName)\n .then((mod) => {\n callback(null, mod?.default ?? null);\n })\n .catch(callback);\n } else {\n try {\n callback(null, require(moduleName));\n } catch (err) {\n callback(err, null);\n }\n }\n}\n\nexport default function loadNodeVersionInstall(callback: (err: Error | null, installVersion: InstallVersionFn) => void): void {\n if (cached !== undefined) {\n callback(null, cached);\n return;\n }\n\n installModule(moduleName, nodeModules, {}, (err) => {\n if (err) return callback(err, null);\n loadModule(moduleName, (err, _cached: InstallVersionFn) => {\n if (err) return callback(err, null);\n cached = _cached;\n callback(null, cached);\n });\n });\n}\n"],"names":["installModule","path","url","_dirname","dirname","__dirname","fileURLToPath","nodeModules","join","moduleName","cached","loadModule","callback","require","then","mod","default","catch","err","loadNodeVersionInstall","undefined","_cached"],"mappings":"AAAA,OAAOA,mBAAmB,wBAAwB;AAElD,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,MAAMC,WAAWF,KAAKG,OAAO,CAAC,OAAOC,cAAc,cAAcA,YAAYH,IAAII,aAAa,CAAC,YAAYJ,GAAG;AAC9G,MAAMK,cAAcN,KAAKO,IAAI,CAACL,UAAU,MAAM,MAAM,MAAM;AAC1D,MAAMM,aAAa;AAKnB,IAAIC;AAEJ,SAASC,WAAWF,UAAU,EAAEG,QAAQ;IACtC,IAAI,OAAOC,YAAY,aAAa;QAClC,MAAM,CAACJ,YACJK,IAAI,CAAC,CAACC;;YACLH,SAAS,cAAMG,gBAAAA,0BAAAA,IAAKC,OAAO,uCAAI;QACjC,GACCC,KAAK,CAACL;IACX,OAAO;QACL,IAAI;YACFA,SAAS,MAAMC,QAAQJ;QACzB,EAAE,OAAOS,KAAK;YACZN,SAASM,KAAK;QAChB;IACF;AACF;AAEA,eAAe,SAASC,uBAAuBP,QAAuE;IACpH,IAAIF,WAAWU,WAAW;QACxBR,SAAS,MAAMF;QACf;IACF;IAEAV,cAAcS,YAAYF,aAAa,CAAC,GAAG,CAACW;QAC1C,IAAIA,KAAK,OAAON,SAASM,KAAK;QAC9BP,WAAWF,YAAY,CAACS,KAAKG;YAC3B,IAAIH,KAAK,OAAON,SAASM,KAAK;YAC9BR,SAASW;YACTT,SAAS,MAAMF;QACjB;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/lib/loadNodeVersionInstall.ts"],"sourcesContent":["import installModule from 'install-module-linked';\nimport type { InstallOptions, InstallResult } from 'node-version-install';\nimport path from 'path';\nimport url from 'url';\n\nconst _dirname = path.dirname(typeof __dirname !== 'undefined' ? __dirname : url.fileURLToPath(import.meta.url));\nconst nodeModules = path.join(_dirname, '..', '..', '..', 'node_modules');\nconst moduleName = 'node-version-install';\n\ntype InstallCallback = (err?: Error, results?: InstallResult[]) => void;\ntype InstallVersionFn = (version: string, options: InstallOptions, callback: InstallCallback) => void;\n\nlet cached: InstallVersionFn | undefined;\n\nfunction loadModule(moduleName, callback) {\n if (typeof require === 'undefined') {\n import(moduleName)\n .then((mod) => {\n callback(null, mod?.default ?? null);\n })\n .catch(callback);\n } else {\n try {\n callback(null, require(moduleName));\n } catch (err) {\n callback(err, null);\n }\n }\n}\n\nexport default function loadNodeVersionInstall(callback: (err: Error | null, installVersion: InstallVersionFn) => void): void {\n if (cached !== undefined) return callback(null, cached);\n\n installModule(moduleName, nodeModules, {}, (err) => {\n if (err) return callback(err, null);\n loadModule(moduleName, (err, _cached: InstallVersionFn) => {\n if (err) return callback(err, null);\n cached = _cached;\n callback(null, cached);\n });\n });\n}\n"],"names":["installModule","path","url","_dirname","dirname","__dirname","fileURLToPath","nodeModules","join","moduleName","cached","loadModule","callback","require","then","mod","default","catch","err","loadNodeVersionInstall","undefined","_cached"],"mappings":"AAAA,OAAOA,mBAAmB,wBAAwB;AAElD,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,MAAMC,WAAWF,KAAKG,OAAO,CAAC,OAAOC,cAAc,cAAcA,YAAYH,IAAII,aAAa,CAAC,YAAYJ,GAAG;AAC9G,MAAMK,cAAcN,KAAKO,IAAI,CAACL,UAAU,MAAM,MAAM,MAAM;AAC1D,MAAMM,aAAa;AAKnB,IAAIC;AAEJ,SAASC,WAAWF,UAAU,EAAEG,QAAQ;IACtC,IAAI,OAAOC,YAAY,aAAa;QAClC,MAAM,CAACJ,YACJK,IAAI,CAAC,CAACC;;YACLH,SAAS,cAAMG,gBAAAA,0BAAAA,IAAKC,OAAO,uCAAI;QACjC,GACCC,KAAK,CAACL;IACX,OAAO;QACL,IAAI;YACFA,SAAS,MAAMC,QAAQJ;QACzB,EAAE,OAAOS,KAAK;YACZN,SAASM,KAAK;QAChB;IACF;AACF;AAEA,eAAe,SAASC,uBAAuBP,QAAuE;IACpH,IAAIF,WAAWU,WAAW,OAAOR,SAAS,MAAMF;IAEhDV,cAAcS,YAAYF,aAAa,CAAC,GAAG,CAACW;QAC1C,IAAIA,KAAK,OAAON,SAASM,KAAK;QAC9BP,WAAWF,YAAY,CAACS,KAAKG;YAC3B,IAAIH,KAAK,OAAON,SAASM,KAAK;YAC9BR,SAASW;YACTT,SAAS,MAAMF;QACjB;IACF;AACF"}
@@ -21,4 +21,4 @@ export interface Options {
21
21
  silent?: boolean;
22
22
  }
23
23
  export type UseOptions = Options & InstallOptions & VersionOptions & SpawnOptions;
24
- export type UseCallback = (err?: UseError | Error, results?: UseResult[]) => undefined;
24
+ export type UseCallback = (err?: UseError | Error, results?: UseResult[]) => void;
@@ -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 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"}
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[]) => void;\n"],"names":[],"mappings":"AA2BA,WAAkF"}
@@ -1,2 +1,2 @@
1
1
  import type { UseCallback, UseOptions } from './types.js';
2
- export default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): undefined;
2
+ export default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void;
@@ -72,10 +72,7 @@ export default function worker(versionExpression, command, args, options, callba
72
72
  loadNodeVersionInstall((loadErr, installVersion)=>{
73
73
  if (loadErr) return callback(loadErr);
74
74
  resolveVersions(versionExpression, options, (err, versions)=>{
75
- if (err) {
76
- callback(err);
77
- return;
78
- }
75
+ if (err) return callback(err);
79
76
  if (!versions.length) {
80
77
  callback(new Error(`No versions found from expression: ${versionExpression}`));
81
78
  return;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/worker.ts"],"sourcesContent":["import spawn, { type SpawnOptions } from 'cross-spawn-cb';\nimport fs from 'fs';\nimport resolveVersions, { type VersionOptions } from 'node-resolve-versions';\nimport type { InstallOptions } from 'node-version-install';\nimport { spawnOptions as createSpawnOptions } from 'node-version-utils';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport resolveBin from 'resolve-bin-sync';\nimport spawnStreaming from 'spawn-streaming';\nimport { createSession, formatArguments } from 'spawn-term';\nimport { stringEndsWith } from './compat.ts';\nimport { storagePath } from './constants.ts';\nimport loadNodeVersionInstall from './lib/loadNodeVersionInstall.ts';\n\nimport type { Options, UseCallback, UseOptions, UseResult } from './types.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst NODE = isWindows ? 'node.exe' : 'node';\n\n// Parse npm-generated .cmd wrapper to extract the JS script path\nfunction parseNpmCmdWrapper(cmdPath: string): string | null {\n try {\n const content = fs.readFileSync(cmdPath, 'utf8');\n // Match: \"%_prog%\" \"%dp0%\\node_modules\\...\\cli.js\" %*\n // or: \"%_prog%\" \"%dp0%\\path\\to\\script.js\" %*\n const match = content.match(/\"%_prog%\"\\s+\"?%dp0%\\\\([^\"]+)\"?\\s+%\\*/);\n if (match) {\n const relativePath = match[1];\n const cmdDir = path.dirname(cmdPath);\n return path.join(cmdDir, relativePath);\n }\n } catch (_e) {\n // ignore\n }\n return null;\n}\n\n// On Windows, resolve npm bin commands to their JS entry points to bypass .cmd wrappers\n// This fixes issues with nvm-windows where .cmd wrappers use symlinked node.exe directly\nfunction resolveCommand(command: string, args: string[]): { command: string; args: string[] } {\n if (!isWindows) return { command, args };\n\n // Case 1: Command is a .cmd file path\n if (stringEndsWith(command.toLowerCase(), '.cmd')) {\n const scriptPath = parseNpmCmdWrapper(command);\n if (scriptPath) {\n return { command: NODE, args: [scriptPath, ...args] };\n }\n }\n\n // Case 2: Try to resolve the command as an npm package bin from node_modules\n try {\n const binPath = resolveBin(command);\n return { command: NODE, args: [binPath, ...args] };\n } catch (_e) {\n // Not an npm package bin, use original command\n }\n\n return { command, args };\n}\n\nexport default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): undefined {\n // Load node-version-install lazily\n loadNodeVersionInstall((loadErr, installVersion) => {\n if (loadErr) return callback(loadErr);\n\n resolveVersions(versionExpression, options as VersionOptions, (err?: Error, versions?: string[]) => {\n if (err) {\n callback(err);\n return;\n }\n if (!versions.length) {\n callback(new Error(`No versions found from expression: ${versionExpression}`));\n return;\n }\n\n const installOptions = { storagePath, ...options } as InstallOptions;\n const streamingOptions = options as Options;\n const results: UseResult[] = [];\n const queue = new Queue(1);\n\n // Create session once for all processes (only if multiple versions)\n const interactive = options.interactive !== false;\n const session = versions.length >= 2 && createSession && !streamingOptions.streaming ? createSession({ header: `${command} ${args.join(' ')}`, showStatusBar: true, interactive }) : null;\n\n versions.forEach((version: string) => {\n queue.defer((cb) => {\n installVersion(version, installOptions, (err, installs) => {\n const install = installs && installs.length === 1 ? installs[0] : null;\n if (err || !install) {\n const error = err || new Error(`Unexpected version results for version ${version}. Install ${JSON.stringify(installs)}`);\n results.push({ install, command, version, error, result: null });\n return cb();\n }\n const spawnOptions = createSpawnOptions(install.installPath, options as SpawnOptions);\n const prefix = install.version;\n\n function next(err?, res?): undefined {\n if (err && err.message.indexOf('ExperimentalWarning') >= 0) {\n res = err;\n err = null;\n }\n results.push({ install, command, version, error: err, result: res });\n cb();\n }\n\n // On Windows, resolve npm bin commands to bypass .cmd wrappers\n const resolved = resolveCommand(command, args);\n\n if (versions.length < 2) {\n // Show command when running single version (no terminal session, unless silent)\n if (!options.silent) console.log(`$ ${formatArguments([resolved.command].concat(resolved.args)).join(' ')}`);\n return spawn(resolved.command, resolved.args, spawnOptions, next);\n }\n if (session) session.spawn(resolved.command, resolved.args, spawnOptions, { group: prefix, expanded: streamingOptions.expanded }, next);\n else spawnStreaming(resolved.command, resolved.args, spawnOptions, { prefix }, next);\n });\n });\n });\n queue.await((err) => {\n if (session) {\n session.waitAndClose(() => {\n err ? callback(err) : callback(null, results);\n });\n } else {\n err ? callback(err) : callback(null, results);\n }\n });\n });\n });\n}\n"],"names":["spawn","fs","resolveVersions","spawnOptions","createSpawnOptions","path","Queue","resolveBin","spawnStreaming","createSession","formatArguments","stringEndsWith","storagePath","loadNodeVersionInstall","isWindows","process","platform","test","env","OSTYPE","NODE","parseNpmCmdWrapper","cmdPath","content","readFileSync","match","relativePath","cmdDir","dirname","join","_e","resolveCommand","command","args","toLowerCase","scriptPath","binPath","worker","versionExpression","options","callback","loadErr","installVersion","err","versions","length","Error","installOptions","streamingOptions","results","queue","interactive","session","streaming","header","showStatusBar","forEach","version","defer","cb","installs","install","error","JSON","stringify","push","result","installPath","prefix","next","res","message","indexOf","resolved","silent","console","log","concat","group","expanded","await","waitAndClose"],"mappings":"AAAA,OAAOA,WAAkC,iBAAiB;AAC1D,OAAOC,QAAQ,KAAK;AACpB,OAAOC,qBAA8C,wBAAwB;AAE7E,SAASC,gBAAgBC,kBAAkB,QAAQ,qBAAqB;AACxE,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,gBAAgB,mBAAmB;AAC1C,OAAOC,oBAAoB,kBAAkB;AAC7C,SAASC,aAAa,EAAEC,eAAe,QAAQ,aAAa;AAC5D,SAASC,cAAc,QAAQ,cAAc;AAC7C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,4BAA4B,kCAAkC;AAIrE,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAC3F,MAAMC,OAAON,YAAY,aAAa;AAEtC,iEAAiE;AACjE,SAASO,mBAAmBC,OAAe;IACzC,IAAI;QACF,MAAMC,UAAUtB,GAAGuB,YAAY,CAACF,SAAS;QACzC,uDAAuD;QACvD,8CAA8C;QAC9C,MAAMG,QAAQF,QAAQE,KAAK,CAAC;QAC5B,IAAIA,OAAO;YACT,MAAMC,eAAeD,KAAK,CAAC,EAAE;YAC7B,MAAME,SAAStB,KAAKuB,OAAO,CAACN;YAC5B,OAAOjB,KAAKwB,IAAI,CAACF,QAAQD;QAC3B;IACF,EAAE,OAAOI,IAAI;IACX,SAAS;IACX;IACA,OAAO;AACT;AAEA,wFAAwF;AACxF,yFAAyF;AACzF,SAASC,eAAeC,OAAe,EAAEC,IAAc;IACrD,IAAI,CAACnB,WAAW,OAAO;QAAEkB;QAASC;IAAK;IAEvC,sCAAsC;IACtC,IAAItB,eAAeqB,QAAQE,WAAW,IAAI,SAAS;QACj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yC,SAASxC,IAAI,EAAE9B,cAAc;4BAAEiE;wBAAO,GAAGC;oBACjF;gBACF;YACF;YACAnB,MAAM8B,KAAK,CAAC,CAACrC;gBACX,IAAIS,SAAS;oBACXA,QAAQ6B,YAAY,CAAC;wBACnBtC,MAAMH,SAASG,OAAOH,SAAS,MAAMS;oBACvC;gBACF,OAAO;oBACLN,MAAMH,SAASG,OAAOH,SAAS,MAAMS;gBACvC;YACF;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/worker.ts"],"sourcesContent":["import spawn, { type SpawnOptions } from 'cross-spawn-cb';\nimport fs from 'fs';\nimport resolveVersions, { type VersionOptions } from 'node-resolve-versions';\nimport type { InstallOptions } from 'node-version-install';\nimport { spawnOptions as createSpawnOptions } from 'node-version-utils';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport resolveBin from 'resolve-bin-sync';\nimport spawnStreaming from 'spawn-streaming';\nimport { createSession, formatArguments } from 'spawn-term';\nimport { stringEndsWith } from './compat.ts';\nimport { storagePath } from './constants.ts';\nimport loadNodeVersionInstall from './lib/loadNodeVersionInstall.ts';\n\nimport type { Options, UseCallback, UseOptions, UseResult } from './types.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst NODE = isWindows ? 'node.exe' : 'node';\n\n// Parse npm-generated .cmd wrapper to extract the JS script path\nfunction parseNpmCmdWrapper(cmdPath: string): string | null {\n try {\n const content = fs.readFileSync(cmdPath, 'utf8');\n // Match: \"%_prog%\" \"%dp0%\\node_modules\\...\\cli.js\" %*\n // or: \"%_prog%\" \"%dp0%\\path\\to\\script.js\" %*\n const match = content.match(/\"%_prog%\"\\s+\"?%dp0%\\\\([^\"]+)\"?\\s+%\\*/);\n if (match) {\n const relativePath = match[1];\n const cmdDir = path.dirname(cmdPath);\n return path.join(cmdDir, relativePath);\n }\n } catch (_e) {\n // ignore\n }\n return null;\n}\n\n// On Windows, resolve npm bin commands to their JS entry points to bypass .cmd wrappers\n// This fixes issues with nvm-windows where .cmd wrappers use symlinked node.exe directly\nfunction resolveCommand(command: string, args: string[]): { command: string; args: string[] } {\n if (!isWindows) return { command, args };\n\n // Case 1: Command is a .cmd file path\n if (stringEndsWith(command.toLowerCase(), '.cmd')) {\n const scriptPath = parseNpmCmdWrapper(command);\n if (scriptPath) {\n return { command: NODE, args: [scriptPath, ...args] };\n }\n }\n\n // Case 2: Try to resolve the command as an npm package bin from node_modules\n try {\n const binPath = resolveBin(command);\n return { command: NODE, args: [binPath, ...args] };\n } catch (_e) {\n // Not an npm package bin, use original command\n }\n\n return { command, args };\n}\n\nexport default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void {\n // Load node-version-install lazily\n loadNodeVersionInstall((loadErr, installVersion) => {\n if (loadErr) return callback(loadErr);\n\n resolveVersions(versionExpression, options as VersionOptions, (err?: Error, versions?: string[]) => {\n if (err) return callback(err);\n if (!versions.length) {\n callback(new Error(`No versions found from expression: ${versionExpression}`));\n return;\n }\n\n const installOptions = { storagePath, ...options } as InstallOptions;\n const streamingOptions = options as Options;\n const results: UseResult[] = [];\n const queue = new Queue(1);\n\n // Create session once for all processes (only if multiple versions)\n const interactive = options.interactive !== false;\n const session = versions.length >= 2 && createSession && !streamingOptions.streaming ? createSession({ header: `${command} ${args.join(' ')}`, showStatusBar: true, interactive }) : null;\n\n versions.forEach((version: string) => {\n queue.defer((cb) => {\n installVersion(version, installOptions, (err, installs) => {\n const install = installs && installs.length === 1 ? installs[0] : null;\n if (err || !install) {\n const error = err || new Error(`Unexpected version results for version ${version}. Install ${JSON.stringify(installs)}`);\n results.push({ install, command, version, error, result: null });\n return cb();\n }\n const spawnOptions = createSpawnOptions(install.installPath, options as SpawnOptions);\n const prefix = install.version;\n\n function next(err?, res?): void {\n if (err && err.message.indexOf('ExperimentalWarning') >= 0) {\n res = err;\n err = null;\n }\n results.push({ install, command, version, error: err, result: res });\n cb();\n }\n\n // On Windows, resolve npm bin commands to bypass .cmd wrappers\n const resolved = resolveCommand(command, args);\n\n if (versions.length < 2) {\n // Show command when running single version (no terminal session, unless silent)\n if (!options.silent) console.log(`$ ${formatArguments([resolved.command].concat(resolved.args)).join(' ')}`);\n return spawn(resolved.command, resolved.args, spawnOptions, next);\n }\n if (session) session.spawn(resolved.command, resolved.args, spawnOptions, { group: prefix, expanded: streamingOptions.expanded }, next);\n else spawnStreaming(resolved.command, resolved.args, spawnOptions, { prefix }, next);\n });\n });\n });\n queue.await((err) => {\n if (session) {\n session.waitAndClose(() => {\n err ? callback(err) : callback(null, results);\n });\n } else {\n err ? callback(err) : callback(null, results);\n }\n });\n });\n });\n}\n"],"names":["spawn","fs","resolveVersions","spawnOptions","createSpawnOptions","path","Queue","resolveBin","spawnStreaming","createSession","formatArguments","stringEndsWith","storagePath","loadNodeVersionInstall","isWindows","process","platform","test","env","OSTYPE","NODE","parseNpmCmdWrapper","cmdPath","content","readFileSync","match","relativePath","cmdDir","dirname","join","_e","resolveCommand","command","args","toLowerCase","scriptPath","binPath","worker","versionExpression","options","callback","loadErr","installVersion","err","versions","length","Error","installOptions","streamingOptions","results","queue","interactive","session","streaming","header","showStatusBar","forEach","version","defer","cb","installs","install","error","JSON","stringify","push","result","installPath","prefix","next","res","message","indexOf","resolved","silent","console","log","concat","group","expanded","await","waitAndClose"],"mappings":"AAAA,OAAOA,WAAkC,iBAAiB;AAC1D,OAAOC,QAAQ,KAAK;AACpB,OAAOC,qBAA8C,wBAAwB;AAE7E,SAASC,gBAAgBC,kBAAkB,QAAQ,qBAAqB;AACxE,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,gBAAgB,mBAAmB;AAC1C,OAAOC,oBAAoB,kBAAkB;AAC7C,SAASC,aAAa,EAAEC,eAAe,QAAQ,aAAa;AAC5D,SAASC,cAAc,QAAQ,cAAc;AAC7C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,4BAA4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A,MAAM;4BACR;4BACAM,QAAQgB,IAAI,CAAC;gCAAEJ;gCAAS7B;gCAASyB;gCAASK,OAAOnB;gCAAKuB,QAAQI;4BAAI;4BAClEX;wBACF;wBAEA,+DAA+D;wBAC/D,MAAMc,WAAW1C,eAAeC,SAASC;wBAEzC,IAAIW,SAASC,MAAM,GAAG,GAAG;4BACvB,gFAAgF;4BAChF,IAAI,CAACN,QAAQmC,MAAM,EAAEC,QAAQC,GAAG,CAAC,CAAC,EAAE,EAAElE,gBAAgB;gCAAC+D,SAASzC,OAAO;6BAAC,CAAC6C,MAAM,CAACJ,SAASxC,IAAI,GAAGJ,IAAI,CAAC,MAAM;4BAC3G,OAAO7B,MAAMyE,SAASzC,OAAO,EAAEyC,SAASxC,IAAI,EAAE9B,cAAckE;wBAC9D;wBACA,IAAIjB,SAASA,QAAQpD,KAAK,CAACyE,SAASzC,OAAO,EAAEyC,SAASxC,IAAI,EAAE9B,cAAc;4BAAE2E,OAAOV;4BAAQW,UAAU/B,iBAAiB+B,QAAQ;wBAAC,GAAGV;6BAC7H7D,eAAeiE,SAASzC,OAAO,EAAEyC,SAASxC,IAAI,EAAE9B,cAAc;4BAAEiE;wBAAO,GAAGC;oBACjF;gBACF;YACF;YACAnB,MAAM8B,KAAK,CAAC,CAACrC;gBACX,IAAIS,SAAS;oBACXA,QAAQ6B,YAAY,CAAC;wBACnBtC,MAAMH,SAASG,OAAOH,SAAS,MAAMS;oBACvC;gBACF,OAAO;oBACLN,MAAMH,SAASG,OAAOH,SAAS,MAAMS;gBACvC;YACF;QACF;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-version-use",
3
- "version": "2.1.9",
3
+ "version": "2.1.10",
4
4
  "description": "Cross-platform solution for using multiple versions of node. Useful for compatibility testing",
5
5
  "keywords": [
6
6
  "node",
@@ -48,14 +48,14 @@
48
48
  "version": "tsds version"
49
49
  },
50
50
  "dependencies": {
51
- "cross-spawn-cb": "^2.0.0",
51
+ "cross-spawn-cb": "^3.0.0",
52
52
  "env-path-key": "^1.0.0",
53
53
  "exit-compat": "^1.0.0",
54
54
  "fs-remove-compat": "^1.0.0",
55
55
  "get-file-compat": "^2.0.0",
56
56
  "getopts-compat": "^2.2.6",
57
57
  "homedir-polyfill": "^1.0.3",
58
- "install-module-linked": "^1.3.17",
58
+ "install-module-linked": "^1.3.16",
59
59
  "mkdirp-classic": "^0.5.2",
60
60
  "module-root-sync": "^2.0.2",
61
61
  "node-resolve-versions": "^1.0.0",
@@ -80,7 +80,7 @@
80
80
  "os-shim": "^0.1.0",
81
81
  "pinkie-promise": "*",
82
82
  "ts-dev-stack": "*",
83
- "tsds-config": "*"
83
+ "tsds-config": "^1.0.4"
84
84
  },
85
85
  "engines": {
86
86
  "node": ">=0.8"