node-version-use 2.3.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -84
- package/assets/bin/node +0 -0
- package/assets/installBinaries.cjs +95 -18
- package/assets/postinstall.cjs +16 -1
- package/dist/cjs/assets/installBinaries.cjs +95 -18
- package/dist/cjs/assets/installBinaries.cjs.map +1 -1
- package/dist/cjs/assets/postinstall.cjs +16 -1
- package/dist/cjs/assets/postinstall.cjs.map +1 -1
- package/dist/cjs/commands/default.js +30 -4
- package/dist/cjs/commands/default.js.map +1 -1
- package/dist/cjs/commands/setup.d.cts +2 -3
- package/dist/cjs/commands/setup.d.ts +2 -3
- package/dist/cjs/commands/setup.js +9 -84
- package/dist/cjs/commands/setup.js.map +1 -1
- package/dist/cjs/compat.js.map +1 -1
- package/dist/cjs/index.js +2 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/assets/installBinaries.cjs +78 -18
- package/dist/esm/assets/installBinaries.cjs.map +1 -1
- package/dist/esm/assets/postinstall.cjs +16 -1
- package/dist/esm/assets/postinstall.cjs.map +1 -1
- package/dist/esm/commands/default.js +30 -4
- package/dist/esm/commands/default.js.map +1 -1
- package/dist/esm/commands/setup.d.ts +2 -3
- package/dist/esm/commands/setup.js +9 -84
- package/dist/esm/commands/setup.js.map +1 -1
- package/dist/esm/compat.js.map +1 -1
- package/dist/esm/index.js +2 -5
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -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 * On Windows, rename a file out of the way instead of deleting.\n * This works even if the file is currently running.\n */\nfunction moveOutOfWay(filePath: string): void {\n if (!fs.existsSync(filePath)) return;\n\n const timestamp = Date.now();\n const oldPath = `${filePath}.old-${timestamp}`;\n\n try {\n fs.renameSync(filePath, oldPath);\n } catch (_e) {\n // If rename fails, try delete as fallback (works on Unix)\n try {\n fs.unlinkSync(filePath);\n } catch (_e2) {\n // ignore - will fail on atomic rename instead\n }\n }\n}\n\n/**\n * Clean up old .old-* files from previous installs\n */\nfunction cleanupOldFiles(dir: string): void {\n try {\n const entries = fs.readdirSync(dir);\n for (const entry of entries) {\n if (entry.includes('.old-')) {\n try {\n fs.unlinkSync(path.join(dir, entry));\n } catch (_e) {\n // ignore - file may still be in use\n }\n }\n }\n } catch (_e) {\n // ignore if dir doesn't exist\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 // Move existing file out of the way (works even if running on Windows)\n moveOutOfWay(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 // Clean up old .old-* files from previous installs\n cleanupOldFiles(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","moveOutOfWay","timestamp","Date","now","oldPath","renameSync","_e2","cleanupOldFiles","dir","entries","readdirSync","entry","includes","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","type","unshift","push","create","callbacks","concurrency","_err","queue","index","length","defer","bind","await","destroy","extractAndInstall","destDir","binaryName","ext","tempExtractDir","sync","extractedPath","Error","binaries","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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;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 * Move a file out of the way (works even if running on Windows)\n * First tries to unlink; if that fails (Windows locked), rename to .old-timestamp\n */\nfunction moveOutOfWay(filePath: string): void {\n if (!fs.existsSync(filePath)) return;\n\n // First try to unlink (works on Unix, fails on Windows if running)\n try {\n fs.unlinkSync(filePath);\n return;\n } catch (_e) {\n // Unlink failed (likely Windows locked file), try rename\n }\n\n // Rename to .old-timestamp as fallback\n const timestamp = Date.now();\n const oldPath = `${filePath}.old-${timestamp}`;\n\n try {\n fs.renameSync(filePath, oldPath);\n } catch (_e2) {\n // Both unlink and rename failed - will fail on atomic rename instead\n }\n}\n\n/**\n * Clean up old .old-* files from previous installs\n */\nfunction cleanupOldFiles(dir: string): void {\n try {\n const entries = fs.readdirSync(dir);\n for (const entry of entries) {\n if (entry.includes('.old-')) {\n try {\n fs.unlinkSync(path.join(dir, entry));\n } catch (_e) {\n // ignore - file may still be in use\n }\n }\n }\n } catch (_e) {\n // ignore if dir doesn't exist\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 * Sync all shims by copying the nvu binary to all other files in the bin directory\n * All shims (node, npm, npx, corepack, eslint, etc.) are copies of the same binary\n */\nmodule.exports.syncAllShims = function syncAllShims(binDir: string): void {\n const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n const ext = isWindows ? '.exe' : '';\n\n // Source: nvu binary\n const nvuSource = path.join(binDir, `nvu${ext}`);\n if (!fs.existsSync(nvuSource)) return;\n\n try {\n const entries = fs.readdirSync(binDir);\n for (const name of entries) {\n // Skip nvu itself and nvu.json\n if (name === `nvu${ext}` || name === 'nvu.json') continue;\n\n // On Windows, only process .exe files\n if (isWindows && !name.endsWith('.exe')) continue;\n\n const shimPath = path.join(binDir, name);\n const stat = fs.statSync(shimPath);\n if (!stat.isFile()) continue;\n\n // Move existing file out of the way (Windows compatibility)\n moveOutOfWay(shimPath);\n\n // Copy nvu binary to shim\n copyFileSync(nvuSource, shimPath);\n\n // Make executable on Unix\n if (!isWindows) {\n fs.chmodSync(shimPath, 0o755);\n }\n }\n } catch (_e) {\n // Ignore errors - shim sync is best effort\n }\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 // Move existing file out of the way (works even if running on Windows)\n moveOutOfWay(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 const nvuJsonPath = path.join(binDir, 'nvu.json');\n\n // check if we need to upgrade\n if (!options.force) {\n try {\n // already installed - read nvu.json\n const nvuJson = JSON.parse(fs.readFileSync(nvuJsonPath, 'utf8'));\n if (nvuJson.binaryVersion === BINARY_VERSION) {\n callback(null, false);\n return;\n }\n } catch (_err) {}\n }\n\n // Create directories\n mkdirp.sync(storagePath);\n mkdirp.sync(binDir);\n mkdirp.sync(path.join(storagePath, 'cache'));\n\n // Clean up old .old-* files from previous installs\n cleanupOldFiles(binDir);\n\n const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/binary-v${BINARY_VERSION}/${archiveBaseName}${isWindows ? '.zip' : '.tar.gz'}`;\n const cachePath = path.join(storagePath, 'cache', `${archiveBaseName}${isWindows ? '.zip' : '.tar.gz'}`);\n\n // Check cache first\n if (fs.existsSync(cachePath)) {\n console.log('Using cached binary...');\n\n // Use cached file\n extractAndInstall(cachePath, binDir, extractedBinaryName, (err) => {\n if (err) return callback(err);\n\n // save binary version for upgrade checks\n fs.writeFileSync(nvuJsonPath, JSON.stringify({ binaryVersion: BINARY_VERSION }, null, 2), 'utf8');\n console.log('Binary installed successfully!');\n callback(null, true);\n });\n return;\n }\n\n // Download to temp file\n console.log(`Downloading binary for ${process.platform}-${process.arch}...`);\n const tempPath = path.join(tmpdir(), `nvu-binary-${Date.now()}${isWindows ? '.zip' : '.tar.gz'}`);\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 // Copy to cache for future use\n try {\n copyFileSync(tempPath, cachePath);\n } catch (_e) {\n // Cache write failed, continue anyway\n }\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(nvuJsonPath, JSON.stringify({ binaryVersion: BINARY_VERSION }, null, 2), '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","moveOutOfWay","timestamp","Date","now","oldPath","renameSync","_e2","cleanupOldFiles","dir","entries","readdirSync","entry","includes","getArchiveBaseName","arch","platformMap","darwin","linux","win32","archMap","x64","arm64","amd64","platformName","archName","copyFileSync","src","dest","content","readFileSync","writeFileSync","module","exports","syncAllShims","binDir","ext","nvuSource","name","endsWith","shimPath","stat","statSync","isFile","chmodSync","atomicRename","callback","rename","err","code","copyErr","extractArchive","archivePath","Iterator","stream","createReadStream","pipe","createGunzip","iterator","links","forEach","type","unshift","push","create","callbacks","concurrency","_err","queue","index","length","defer","bind","await","destroy","extractAndInstall","destDir","binaryName","tempExtractDir","sync","extractedPath","Error","binaries","installError","i","tempDest","j","tempPath","renameError","doRename","finalDest","printInstructions","_nvuBinPath","console","log","pathKey","envPath","indexOf","installBinaries","options","archiveBaseName","extractedBinaryName","nvuJsonPath","force","nvuJson","JSON","parse","downloadUrl","cachePath","stringify","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,O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CAAC;YACZhD,SAAS,MAAM;QACjB;QACA;IACF;IAEA,wBAAwB;IACxB+C,QAAQC,GAAG,CAAC,AAAC,0BAA6C/G,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQgC,IAAI,EAAC;IACvE,IAAMwE,WAAWlH,KAAKO,IAAI,CAACc,UAAU,AAAC,cAA0BZ,OAAbqB,KAAKC,GAAG,IAAoC,OAA/BtB,YAAY,SAAS;IAErFZ,QAAQyI,aAAapB,UAAU,SAACvC;QAC9B,IAAIA,KAAK;YACPpD,mBAAmB2F;YACnBzC,SAAS,IAAImC,MAAM,AAAC,oCAAuDlG,OAApBA,QAAQC,QAAQ,EAAC,KAA8B2H,OAA3B5H,QAAQgC,IAAI,EAAC,gBAAqCiC,OAAvB2D,aAAY,aAAuB,OAAZ3D,IAAI8D,OAAO;YACxI;QACF;QAEA,+BAA+B;QAC/B,IAAI;YACFpF,aAAa6D,UAAUqB;QACzB,EAAE,OAAO5G,IAAI;QACX,sCAAsC;QACxC;QAEA2E,kBAAkBY,UAAUpD,QAAQkE,qBAAqB,SAACrD;YACxDpD,mBAAmB2F;YACnB,IAAIvC,KAAK,OAAOF,SAASE;YAEzB,yCAAyC;YACzChF,GAAG+D,aAAa,CAACuE,aAAaG,KAAKI,SAAS,CAAC;gBAAEhI,eAAeF;YAAe,GAAG,MAAM,IAAI;YAC1FkH,QAAQC,GAAG,CAAC;YACZhD,SAAS,MAAM;QACjB;IACF;AACF"}
|
|
@@ -10,7 +10,17 @@
|
|
|
10
10
|
* 2. Extract to temp directory
|
|
11
11
|
* 3. Atomic rename to final location
|
|
12
12
|
*/ var exit = require('exit-compat');
|
|
13
|
-
var
|
|
13
|
+
var path = require('path');
|
|
14
|
+
var os = require('os');
|
|
15
|
+
var _require = require('./installBinaries.cjs'), installBinaries = _require.installBinaries, printInstructions = _require.printInstructions, syncAllShims = _require.syncAllShims;
|
|
16
|
+
var hasHomedir = typeof os.homedir === 'function';
|
|
17
|
+
function homedir() {
|
|
18
|
+
if (hasHomedir) return os.homedir();
|
|
19
|
+
var home = require('homedir-polyfill');
|
|
20
|
+
return home();
|
|
21
|
+
}
|
|
22
|
+
// Allow NVU_HOME override for testing
|
|
23
|
+
var storagePath = process.env.NVU_HOME || path.join(homedir(), '.nvu');
|
|
14
24
|
/**
|
|
15
25
|
* Main installation function
|
|
16
26
|
*/ function main() {
|
|
@@ -22,8 +32,13 @@ var _require = require('./installBinaries.cjs'), installBinaries = _require.inst
|
|
|
22
32
|
return;
|
|
23
33
|
}
|
|
24
34
|
if (installed) {
|
|
35
|
+
// Sync all shims to the new binary version
|
|
36
|
+
var binDir = path.join(storagePath, 'bin');
|
|
37
|
+
syncAllShims(binDir);
|
|
25
38
|
printInstructions();
|
|
26
39
|
console.log('postinstall: Binary installed successfully!');
|
|
40
|
+
} else {
|
|
41
|
+
console.log('postinstall: Binaries already up to date.');
|
|
27
42
|
}
|
|
28
43
|
exit(0);
|
|
29
44
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/assets/postinstall.cts"],"sourcesContent":["/**\n * Postinstall script for node-version-use\n *\n * Downloads the platform-specific binary and installs it to ~/.nvu/bin/\n * This enables transparent Node version switching.\n *\n * Uses safe atomic download pattern:\n * 1. Download to temp file\n * 2. Extract to temp directory\n * 3. Atomic rename to final location\n */\n\nconst exit = require('exit-compat');\nconst { installBinaries, printInstructions } = require('./installBinaries.cjs');\n\n/**\n * Main installation function\n */\nfunction main(): void {\n installBinaries({}, (err, installed) => {\n if (err) {\n console.log(`postinstall warning: Failed to install binary: ${err.message || err}`);\n console.log('You can still use nvu with explicit versions: nvu 18 npm test');\n exit(1);\n return;\n }\n\n if (installed) {\n printInstructions();\n console.log('postinstall: Binary installed successfully!');\n }\n exit(0);\n });\n}\n\nmain();\n"],"names":["exit","require","installBinaries","printInstructions","main","err","installed","console","log","message"],"mappings":";AAAA;;;;;;;;;;CAUC,GAED,IAAMA,OAAOC,QAAQ;AACrB,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/assets/postinstall.cts"],"sourcesContent":["/**\n * Postinstall script for node-version-use\n *\n * Downloads the platform-specific binary and installs it to ~/.nvu/bin/\n * This enables transparent Node version switching.\n *\n * Uses safe atomic download pattern:\n * 1. Download to temp file\n * 2. Extract to temp directory\n * 3. Atomic rename to final location\n */\n\nconst exit = require('exit-compat');\nconst path = require('path');\nconst os = require('os');\nconst { installBinaries, printInstructions, syncAllShims } = require('./installBinaries.cjs');\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');\n\n/**\n * Main installation function\n */\nfunction main(): void {\n installBinaries({}, (err, installed) => {\n if (err) {\n console.log(`postinstall warning: Failed to install binary: ${err.message || err}`);\n console.log('You can still use nvu with explicit versions: nvu 18 npm test');\n exit(1);\n return;\n }\n\n if (installed) {\n // Sync all shims to the new binary version\n const binDir = path.join(storagePath, 'bin');\n syncAllShims(binDir);\n\n printInstructions();\n console.log('postinstall: Binary installed successfully!');\n } else {\n console.log('postinstall: Binaries already up to date.');\n }\n exit(0);\n });\n}\n\nmain();\n"],"names":["exit","require","path","os","installBinaries","printInstructions","syncAllShims","hasHomedir","homedir","home","storagePath","process","env","NVU_HOME","join","main","err","installed","console","log","message","binDir"],"mappings":";AAAA;;;;;;;;;;CAUC,GAED,IAAMA,OAAOC,QAAQ;AACrB,IAAMC,OAAOD,QAAQ;AACrB,IAAME,KAAKF,QAAQ;AACnB,IAA6DA,WAAAA,QAAQ,0BAA7DG,kBAAqDH,SAArDG,iBAAiBC,oBAAoCJ,SAApCI,mBAAmBC,eAAiBL,SAAjBK;AAE5C,IAAMC,aAAa,OAAOJ,GAAGK,OAAO,KAAK;AACzC,SAASA;IACP,IAAID,YAAY,OAAOJ,GAAGK,OAAO;IACjC,IAAMC,OAAOR,QAAQ;IACrB,OAAOQ;AACT;AAEA,sCAAsC;AACtC,IAAMC,cAAcC,QAAQC,GAAG,CAACC,QAAQ,IAAIX,KAAKY,IAAI,CAACN,WAAW;AAEjE;;CAEC,GACD,SAASO;IACPX,gBAAgB,CAAC,GAAG,SAACY,KAAKC;QACxB,IAAID,KAAK;YACPE,QAAQC,GAAG,CAAC,AAAC,kDAAoE,OAAnBH,IAAII,OAAO,IAAIJ;YAC7EE,QAAQC,GAAG,CAAC;YACZnB,KAAK;YACL;QACF;QAEA,IAAIiB,WAAW;YACb,2CAA2C;YAC3C,IAAMI,SAASnB,KAAKY,IAAI,CAACJ,aAAa;YACtCJ,aAAae;YAEbhB;YACAa,QAAQC,GAAG,CAAC;QACd,OAAO;YACLD,QAAQC,GAAG,CAAC;QACd;QACAnB,KAAK;IACP;AACF;AAEAe"}
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, /**
|
|
|
15
15
|
});
|
|
16
16
|
var _exitcompat = /*#__PURE__*/ _interop_require_default(require("exit-compat"));
|
|
17
17
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
18
|
+
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
18
19
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
19
20
|
var _compatts = require("../compat.js");
|
|
20
21
|
var _constantsts = require("../constants.js");
|
|
@@ -25,9 +26,12 @@ function _interop_require_default(obj) {
|
|
|
25
26
|
default: obj
|
|
26
27
|
};
|
|
27
28
|
}
|
|
29
|
+
var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
30
|
+
var syncAllShims = _require('../assets/installBinaries.cjs').syncAllShims;
|
|
28
31
|
function defaultCmd(args) {
|
|
29
32
|
var defaultFilePath = _path.default.join(_constantsts.storagePath, 'default');
|
|
30
33
|
var versionsPath = _path.default.join(_constantsts.storagePath, 'installed');
|
|
34
|
+
var binDir = _path.default.join(_constantsts.storagePath, 'bin');
|
|
31
35
|
// If no version provided, display current default
|
|
32
36
|
if (args.length === 0) {
|
|
33
37
|
if (_fs.default.existsSync(defaultFilePath)) {
|
|
@@ -41,6 +45,13 @@ function defaultCmd(args) {
|
|
|
41
45
|
return;
|
|
42
46
|
}
|
|
43
47
|
var version = args[0].trim();
|
|
48
|
+
// Special case: "system" means use system Node (no installation needed)
|
|
49
|
+
if (version === 'system') {
|
|
50
|
+
_fs.default.writeFileSync(defaultFilePath, 'system\n', 'utf8');
|
|
51
|
+
console.log('Default Node version set to: system');
|
|
52
|
+
(0, _exitcompat.default)(0);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
44
55
|
// Validate version format (basic check, indexOf for Node 0.8+ compat)
|
|
45
56
|
if (!version || version.indexOf('-') === 0) {
|
|
46
57
|
console.log('Usage: nvu default <version>');
|
|
@@ -56,16 +67,16 @@ function defaultCmd(args) {
|
|
|
56
67
|
var matches = (0, _findInstalledVersionsts.findInstalledVersions)(versionsPath, version);
|
|
57
68
|
if (matches.length > 0) {
|
|
58
69
|
// Version is installed - resolve to exact and set default
|
|
59
|
-
setDefaultToExact(defaultFilePath, matches);
|
|
70
|
+
setDefaultToExact(defaultFilePath, matches, binDir);
|
|
60
71
|
} else {
|
|
61
72
|
// Version not installed - auto-install it
|
|
62
73
|
console.log("Node ".concat(version, " is not installed. Installing..."));
|
|
63
|
-
autoInstallAndSetDefault(version, versionsPath, defaultFilePath);
|
|
74
|
+
autoInstallAndSetDefault(version, versionsPath, defaultFilePath, binDir);
|
|
64
75
|
}
|
|
65
76
|
}
|
|
66
77
|
/**
|
|
67
78
|
* Set the default to the highest matching installed version
|
|
68
|
-
*/ function setDefaultToExact(defaultFilePath, matches) {
|
|
79
|
+
*/ function setDefaultToExact(defaultFilePath, matches, binDir) {
|
|
69
80
|
// matches are sorted by findInstalledVersions, take the last (highest)
|
|
70
81
|
var exactVersion = matches[matches.length - 1];
|
|
71
82
|
// Ensure it has v prefix for consistency
|
|
@@ -75,11 +86,13 @@ function defaultCmd(args) {
|
|
|
75
86
|
// Write the exact version
|
|
76
87
|
_fs.default.writeFileSync(defaultFilePath, "".concat(exactVersion, "\n"), 'utf8');
|
|
77
88
|
console.log("Default Node version set to: ".concat(exactVersion));
|
|
89
|
+
// Sync all shims (first time setup)
|
|
90
|
+
syncAllShimsIfNeeded(binDir);
|
|
78
91
|
(0, _exitcompat.default)(0);
|
|
79
92
|
}
|
|
80
93
|
/**
|
|
81
94
|
* Auto-install the version and then set it as default
|
|
82
|
-
*/ function autoInstallAndSetDefault(version, versionsPath, defaultFilePath) {
|
|
95
|
+
*/ function autoInstallAndSetDefault(version, versionsPath, defaultFilePath, binDir) {
|
|
83
96
|
(0, _loadNodeVersionInstallts.default)(function(err, nodeVersionInstall) {
|
|
84
97
|
if (err || !nodeVersionInstall) {
|
|
85
98
|
console.error('Failed to load node-version-install:', err ? err.message : 'Module not available');
|
|
@@ -116,8 +129,21 @@ function defaultCmd(args) {
|
|
|
116
129
|
_fs.default.writeFileSync(defaultFilePath, "".concat(installedVersion, "\n"), 'utf8');
|
|
117
130
|
console.log("Node ".concat(installedVersion, " installed successfully."));
|
|
118
131
|
console.log("Default Node version set to: ".concat(installedVersion));
|
|
132
|
+
// Sync all shims (first time setup)
|
|
133
|
+
syncAllShimsIfNeeded(binDir);
|
|
119
134
|
(0, _exitcompat.default)(0);
|
|
120
135
|
});
|
|
121
136
|
});
|
|
122
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Sync all shims if this is the first time setting a default
|
|
140
|
+
* First time is detected by checking if ~/.nvu/bin/nvu exists
|
|
141
|
+
*/ function syncAllShimsIfNeeded(binDir) {
|
|
142
|
+
var isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
143
|
+
var nvuPath = _path.default.join(binDir, "nvu".concat(isWindows ? '.exe' : ''));
|
|
144
|
+
// Only sync if nvu binary exists (first time setup)
|
|
145
|
+
if (_fs.default.existsSync(nvuPath)) {
|
|
146
|
+
syncAllShims(binDir);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
123
149
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/default.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { mkdirpSync } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\nimport { findInstalledVersions } from '../lib/findInstalledVersions.ts';\nimport loadNodeVersionInstall from '../lib/loadNodeVersionInstall.ts';\n\n/**\n * nvu default [version]\n *\n * Set or display the global default Node version.\n * This is used when no .nvmrc or .nvurc is found in the project.\n */\nexport default function defaultCmd(args: string[]): void {\n const defaultFilePath = path.join(storagePath, 'default');\n const versionsPath = path.join(storagePath, 'installed');\n\n // If no version provided, display current default\n if (args.length === 0) {\n if (fs.existsSync(defaultFilePath)) {\n const currentVersion = fs.readFileSync(defaultFilePath, 'utf8').trim();\n console.log(`Current default: ${currentVersion}`);\n } else {\n console.log('No default version set.');\n console.log('Usage: nvu default <version>');\n }\n exit(0);\n return;\n }\n\n const version = args[0].trim();\n\n // Validate version format (basic check, indexOf for Node 0.8+ compat)\n if (!version || version.indexOf('-') === 0) {\n console.log('Usage: nvu default <version>');\n console.log('Example: nvu default 20');\n exit(1);\n return;\n }\n\n // Ensure storage directory exists\n if (!fs.existsSync(storagePath)) {\n mkdirpSync(storagePath);\n }\n\n // Check if any installed versions match\n const matches = findInstalledVersions(versionsPath, version);\n\n if (matches.length > 0) {\n // Version is installed - resolve to exact and set default\n setDefaultToExact(defaultFilePath, matches);\n } else {\n // Version not installed - auto-install it\n console.log(`Node ${version} is not installed. Installing...`);\n autoInstallAndSetDefault(version, versionsPath, defaultFilePath);\n }\n}\n\n/**\n * Set the default to the highest matching installed version\n */\nfunction setDefaultToExact(defaultFilePath: string, matches: string[]): void {\n // matches are sorted by findInstalledVersions, take the last (highest)\n let exactVersion = matches[matches.length - 1];\n\n // Ensure it has v prefix for consistency\n if (exactVersion.indexOf('v') !== 0) {\n exactVersion = `v${exactVersion}`;\n }\n\n // Write the exact version\n fs.writeFileSync(defaultFilePath, `${exactVersion}\\n`, 'utf8');\n console.log(`Default Node version set to: ${exactVersion}`);\n\n exit(0);\n}\n\n/**\n * Auto-install the version and then set it as default\n */\nfunction autoInstallAndSetDefault(version: string, versionsPath: string, defaultFilePath: string): void {\n loadNodeVersionInstall((err, nodeVersionInstall) => {\n if (err || !nodeVersionInstall) {\n console.error('Failed to load node-version-install:', err ? err.message : 'Module not available');\n exit(1);\n return;\n }\n\n nodeVersionInstall(\n version,\n {\n installPath: versionsPath,\n },\n (installErr, results) => {\n if (installErr) {\n console.error(`Failed to install Node ${version}:`, installErr.message);\n exit(1);\n return;\n }\n\n // Get the installed version from results\n let installedVersion: string;\n if (results && results.length > 0) {\n installedVersion = results[0].version;\n } else {\n // Fallback: re-scan installed versions\n const matches = findInstalledVersions(versionsPath, version);\n if (matches.length === 0) {\n console.error('Installation completed but version not found');\n exit(1);\n return;\n }\n installedVersion = matches[matches.length - 1];\n }\n\n // Ensure it has v prefix for consistency\n if (installedVersion.indexOf('v') !== 0) {\n installedVersion = `v${installedVersion}`;\n }\n\n // Write the exact version\n fs.writeFileSync(defaultFilePath, `${installedVersion}\\n`, 'utf8');\n console.log(`Node ${installedVersion} installed successfully.`);\n console.log(`Default Node version set to: ${installedVersion}`);\n\n exit(0);\n }\n );\n });\n}\n"],"names":["defaultCmd","args","defaultFilePath","path","join","storagePath","versionsPath","length","fs","existsSync","currentVersion","readFileSync","trim","console","log","exit","version","indexOf","mkdirpSync","matches","findInstalledVersions","setDefaultToExact","autoInstallAndSetDefault","exactVersion","
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/default.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport Module from 'module';\nimport path from 'path';\nimport { mkdirpSync } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\nimport { findInstalledVersions } from '../lib/findInstalledVersions.ts';\nimport loadNodeVersionInstall from '../lib/loadNodeVersionInstall.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst { syncAllShims } = _require('../assets/installBinaries.cjs');\n\n/**\n * nvu default [version]\n *\n * Set or display the global default Node version.\n * This is used when no .nvmrc or .nvurc is found in the project.\n */\nexport default function defaultCmd(args: string[]): void {\n const defaultFilePath = path.join(storagePath, 'default');\n const versionsPath = path.join(storagePath, 'installed');\n const binDir = path.join(storagePath, 'bin');\n\n // If no version provided, display current default\n if (args.length === 0) {\n if (fs.existsSync(defaultFilePath)) {\n const currentVersion = fs.readFileSync(defaultFilePath, 'utf8').trim();\n console.log(`Current default: ${currentVersion}`);\n } else {\n console.log('No default version set.');\n console.log('Usage: nvu default <version>');\n }\n exit(0);\n return;\n }\n\n const version = args[0].trim();\n\n // Special case: \"system\" means use system Node (no installation needed)\n if (version === 'system') {\n fs.writeFileSync(defaultFilePath, 'system\\n', 'utf8');\n console.log('Default Node version set to: system');\n exit(0);\n return;\n }\n\n // Validate version format (basic check, indexOf for Node 0.8+ compat)\n if (!version || version.indexOf('-') === 0) {\n console.log('Usage: nvu default <version>');\n console.log('Example: nvu default 20');\n exit(1);\n return;\n }\n\n // Ensure storage directory exists\n if (!fs.existsSync(storagePath)) {\n mkdirpSync(storagePath);\n }\n\n // Check if any installed versions match\n const matches = findInstalledVersions(versionsPath, version);\n\n if (matches.length > 0) {\n // Version is installed - resolve to exact and set default\n setDefaultToExact(defaultFilePath, matches, binDir);\n } else {\n // Version not installed - auto-install it\n console.log(`Node ${version} is not installed. Installing...`);\n autoInstallAndSetDefault(version, versionsPath, defaultFilePath, binDir);\n }\n}\n\n/**\n * Set the default to the highest matching installed version\n */\nfunction setDefaultToExact(defaultFilePath: string, matches: string[], binDir: string): void {\n // matches are sorted by findInstalledVersions, take the last (highest)\n let exactVersion = matches[matches.length - 1];\n\n // Ensure it has v prefix for consistency\n if (exactVersion.indexOf('v') !== 0) {\n exactVersion = `v${exactVersion}`;\n }\n\n // Write the exact version\n fs.writeFileSync(defaultFilePath, `${exactVersion}\\n`, 'utf8');\n console.log(`Default Node version set to: ${exactVersion}`);\n\n // Sync all shims (first time setup)\n syncAllShimsIfNeeded(binDir);\n\n exit(0);\n}\n\n/**\n * Auto-install the version and then set it as default\n */\nfunction autoInstallAndSetDefault(version: string, versionsPath: string, defaultFilePath: string, binDir: string): void {\n loadNodeVersionInstall((err, nodeVersionInstall) => {\n if (err || !nodeVersionInstall) {\n console.error('Failed to load node-version-install:', err ? err.message : 'Module not available');\n exit(1);\n return;\n }\n\n nodeVersionInstall(\n version,\n {\n installPath: versionsPath,\n },\n (installErr, results) => {\n if (installErr) {\n console.error(`Failed to install Node ${version}:`, installErr.message);\n exit(1);\n return;\n }\n\n // Get the installed version from results\n let installedVersion: string;\n if (results && results.length > 0) {\n installedVersion = results[0].version;\n } else {\n // Fallback: re-scan installed versions\n const matches = findInstalledVersions(versionsPath, version);\n if (matches.length === 0) {\n console.error('Installation completed but version not found');\n exit(1);\n return;\n }\n installedVersion = matches[matches.length - 1];\n }\n\n // Ensure it has v prefix for consistency\n if (installedVersion.indexOf('v') !== 0) {\n installedVersion = `v${installedVersion}`;\n }\n\n // Write the exact version\n fs.writeFileSync(defaultFilePath, `${installedVersion}\\n`, 'utf8');\n console.log(`Node ${installedVersion} installed successfully.`);\n console.log(`Default Node version set to: ${installedVersion}`);\n\n // Sync all shims (first time setup)\n syncAllShimsIfNeeded(binDir);\n\n exit(0);\n }\n );\n });\n}\n\n/**\n * Sync all shims if this is the first time setting a default\n * First time is detected by checking if ~/.nvu/bin/nvu exists\n */\nfunction syncAllShimsIfNeeded(binDir: string): void {\n const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n const nvuPath = path.join(binDir, `nvu${isWindows ? '.exe' : ''}`);\n\n // Only sync if nvu binary exists (first time setup)\n if (fs.existsSync(nvuPath)) {\n syncAllShims(binDir);\n }\n}\n"],"names":["defaultCmd","_require","require","Module","createRequire","syncAllShims","args","defaultFilePath","path","join","storagePath","versionsPath","binDir","length","fs","existsSync","currentVersion","readFileSync","trim","console","log","exit","version","writeFileSync","indexOf","mkdirpSync","matches","findInstalledVersions","setDefaultToExact","autoInstallAndSetDefault","exactVersion","syncAllShimsIfNeeded","loadNodeVersionInstall","err","nodeVersionInstall","error","message","installPath","installErr","results","installedVersion","isWindows","process","platform","test","env","OSTYPE","nvuPath"],"mappings":";;;;+BAYA;;;;;CAKC,GACD;;;eAAwBA;;;iEAlBP;yDACF;6DACI;2DACF;wBACU;2BACC;uCACU;+EACH;;;;;;AAEnC,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAM,AAAEG,eAAiBJ,SAAS,iCAA1BI;AAQO,SAASL,WAAWM,IAAc;IAC/C,IAAMC,kBAAkBC,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAC/C,IAAMC,eAAeH,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAC5C,IAAME,SAASJ,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAEtC,kDAAkD;IAClD,IAAIJ,KAAKO,MAAM,KAAK,GAAG;QACrB,IAAIC,WAAE,CAACC,UAAU,CAACR,kBAAkB;YAClC,IAAMS,iBAAiBF,WAAE,CAACG,YAAY,CAACV,iBAAiB,QAAQW,IAAI;YACpEC,QAAQC,GAAG,CAAC,AAAC,oBAAkC,OAAfJ;QAClC,OAAO;YACLG,QAAQC,GAAG,CAAC;YACZD,QAAQC,GAAG,CAAC;QACd;QACAC,IAAAA,mBAAI,EAAC;QACL;IACF;IA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,qBAAqBnB,MAAc;IAC1C,IAAM6B,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;IAC3F,IAAMC,UAAUvC,aAAI,CAACC,IAAI,CAACG,QAAQ,AAAC,MAA6B,OAAxB6B,YAAY,SAAS;IAE7D,oDAAoD;IACpD,IAAI3B,WAAE,CAACC,UAAU,CAACgC,UAAU;QAC1B1C,aAAaO;IACf;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* nvu setup
|
|
2
|
+
* nvu setup
|
|
3
3
|
*
|
|
4
4
|
* Install/reinstall nvu binaries to ~/.nvu/bin
|
|
5
|
-
* With --shims: create shims for existing global packages
|
|
6
5
|
*/
|
|
7
|
-
export default function setupCmd(
|
|
6
|
+
export default function setupCmd(_args: string[]): void;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* nvu setup
|
|
2
|
+
* nvu setup
|
|
3
3
|
*
|
|
4
4
|
* Install/reinstall nvu binaries to ~/.nvu/bin
|
|
5
|
-
* With --shims: create shims for existing global packages
|
|
6
5
|
*/
|
|
7
|
-
export default function setupCmd(
|
|
6
|
+
export default function setupCmd(_args: string[]): void;
|
|
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, /**
|
|
6
|
-
* nvu setup
|
|
6
|
+
* nvu setup
|
|
7
7
|
*
|
|
8
8
|
* Install/reinstall nvu binaries to ~/.nvu/bin
|
|
9
|
-
* With --shims: create shims for existing global packages
|
|
10
9
|
*/ "default", {
|
|
11
10
|
enumerable: true,
|
|
12
11
|
get: function() {
|
|
@@ -14,103 +13,29 @@ Object.defineProperty(exports, /**
|
|
|
14
13
|
}
|
|
15
14
|
});
|
|
16
15
|
var _exitcompat = /*#__PURE__*/ _interop_require_default(require("exit-compat"));
|
|
17
|
-
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
18
|
-
var _getoptscompat = /*#__PURE__*/ _interop_require_default(require("getopts-compat"));
|
|
19
16
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
20
17
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
21
|
-
var _compatts = require("../compat.js");
|
|
22
18
|
var _constantsts = require("../constants.js");
|
|
23
|
-
var _findInstalledVersionsts = require("../lib/findInstalledVersions.js");
|
|
24
19
|
function _interop_require_default(obj) {
|
|
25
20
|
return obj && obj.__esModule ? obj : {
|
|
26
21
|
default: obj
|
|
27
22
|
};
|
|
28
23
|
}
|
|
29
24
|
var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
30
|
-
var _require1 = _require('../assets/installBinaries.cjs'), installBinaries = _require1.installBinaries, printInstructions = _require1.printInstructions;
|
|
31
|
-
function setupCmd(
|
|
32
|
-
|
|
33
|
-
boolean: [
|
|
34
|
-
'force'
|
|
35
|
-
]
|
|
36
|
-
});
|
|
37
|
-
installBinaries(options, function(err, installed) {
|
|
25
|
+
var _require1 = _require('../assets/installBinaries.cjs'), installBinaries = _require1.installBinaries, printInstructions = _require1.printInstructions, syncAllShims = _require1.syncAllShims;
|
|
26
|
+
function setupCmd(_args) {
|
|
27
|
+
installBinaries({}, function(err, installed) {
|
|
38
28
|
if (err) {
|
|
39
29
|
console.error("Setup failed: ".concat(err.message || err));
|
|
40
30
|
(0, _exitcompat.default)(1);
|
|
41
31
|
return;
|
|
42
32
|
}
|
|
33
|
+
// Sync all shims to the new binary
|
|
34
|
+
var binDir = _path.default.join(_constantsts.storagePath, 'bin');
|
|
35
|
+
syncAllShims(binDir);
|
|
43
36
|
printInstructions();
|
|
44
|
-
if (!installed) console.log('Use --force to reinstall.');
|
|
45
|
-
|
|
46
|
-
var binDir = _path.default.join(_constantsts.storagePath, 'bin');
|
|
47
|
-
createShimsForGlobalPackages(binDir);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
37
|
+
if (!installed) console.log('Use --force to reinstall binaries.');
|
|
38
|
+
(0, _exitcompat.default)(0);
|
|
50
39
|
});
|
|
51
40
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Create shims for all global packages in the default Node version
|
|
54
|
-
*/ function createShimsForGlobalPackages(binDir) {
|
|
55
|
-
// Read default version
|
|
56
|
-
var defaultPath = _path.default.join(_constantsts.storagePath, 'default');
|
|
57
|
-
if (!_fs.default.existsSync(defaultPath)) {
|
|
58
|
-
console.log('No default Node version set.');
|
|
59
|
-
console.log('Set one with: nvu default <version>');
|
|
60
|
-
(0, _exitcompat.default)(1);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
var defaultVersion = _fs.default.readFileSync(defaultPath, 'utf8').trim();
|
|
64
|
-
var versionsDir = _path.default.join(_constantsts.storagePath, 'installed');
|
|
65
|
-
// Resolve to exact version
|
|
66
|
-
var matches = (0, _findInstalledVersionsts.findInstalledVersions)(versionsDir, defaultVersion);
|
|
67
|
-
if (matches.length === 0) {
|
|
68
|
-
console.log("Default version ".concat(defaultVersion, " is not installed."));
|
|
69
|
-
(0, _exitcompat.default)(1);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
var resolvedVersion = matches[matches.length - 1];
|
|
73
|
-
var nodeBinDir = _path.default.join(versionsDir, resolvedVersion, 'bin');
|
|
74
|
-
if (!_fs.default.existsSync(nodeBinDir)) {
|
|
75
|
-
console.log("No bin directory found for ".concat(resolvedVersion));
|
|
76
|
-
(0, _exitcompat.default)(1);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
// Get the node shim to copy from
|
|
80
|
-
var nodeShim = _path.default.join(binDir, 'node');
|
|
81
|
-
if (!_fs.default.existsSync(nodeShim)) {
|
|
82
|
-
console.log('Node shim not found. Run: nvu setup');
|
|
83
|
-
(0, _exitcompat.default)(1);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
// Scan binaries in Node's bin directory
|
|
87
|
-
var entries = (0, _compatts.readdirWithTypes)(nodeBinDir);
|
|
88
|
-
var created = 0;
|
|
89
|
-
var skipped = 0;
|
|
90
|
-
for(var i = 0; i < entries.length; i++){
|
|
91
|
-
var entry = entries[i];
|
|
92
|
-
var name = entry.name;
|
|
93
|
-
// Skip our routing shims (node/npm/npx) - don't overwrite them
|
|
94
|
-
if (name === 'node' || name === 'npm' || name === 'npx') continue;
|
|
95
|
-
var shimPath = _path.default.join(binDir, name);
|
|
96
|
-
// Skip if shim already exists
|
|
97
|
-
if (_fs.default.existsSync(shimPath)) {
|
|
98
|
-
skipped++;
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
// Copy the node shim
|
|
102
|
-
try {
|
|
103
|
-
var shimContent = _fs.default.readFileSync(nodeShim);
|
|
104
|
-
_fs.default.writeFileSync(shimPath, shimContent);
|
|
105
|
-
_fs.default.chmodSync(shimPath, 493); // 0755
|
|
106
|
-
console.log("Created shim: ".concat(name));
|
|
107
|
-
created++;
|
|
108
|
-
} catch (err) {
|
|
109
|
-
console.error("Failed to create shim for ".concat(name, ": ").concat(err.message));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
console.log('');
|
|
113
|
-
console.log("Done. Created ".concat(created, " shims, skipped ").concat(skipped, " (already exists)."));
|
|
114
|
-
(0, _exitcompat.default)(0);
|
|
115
|
-
}
|
|
116
41
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/setup.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/setup.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport Module from 'module';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst { installBinaries, printInstructions, syncAllShims } = _require('../assets/installBinaries.cjs');\n\n/**\n * nvu setup\n *\n * Install/reinstall nvu binaries to ~/.nvu/bin\n */\nexport default function setupCmd(_args: string[]): void {\n installBinaries({}, (err, installed) => {\n if (err) {\n console.error(`Setup failed: ${err.message || err}`);\n exit(1);\n return;\n }\n\n // Sync all shims to the new binary\n const binDir = path.join(storagePath, 'bin');\n syncAllShims(binDir);\n\n printInstructions();\n if (!installed) console.log('Use --force to reinstall binaries.');\n\n exit(0);\n });\n}\n"],"names":["setupCmd","_require","require","Module","createRequire","installBinaries","printInstructions","syncAllShims","_args","err","installed","console","error","message","exit","binDir","path","join","storagePath","log"],"mappings":";;;;+BAQA;;;;CAIC,GACD;;;eAAwBA;;;iEAbP;6DACE;2DACF;2BACW;;;;;;AAE5B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAA6DD,YAAAA,SAAS,kCAA9DI,kBAAqDJ,UAArDI,iBAAiBC,oBAAoCL,UAApCK,mBAAmBC,eAAiBN,UAAjBM;AAO7B,SAASP,SAASQ,KAAe;IAC9CH,gBAAgB,CAAC,GAAG,SAACI,KAAKC;QACxB,IAAID,KAAK;YACPE,QAAQC,KAAK,CAAC,AAAC,iBAAmC,OAAnBH,IAAII,OAAO,IAAIJ;YAC9CK,IAAAA,mBAAI,EAAC;YACL;QACF;QAEA,mCAAmC;QACnC,IAAMC,SAASC,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;QACtCX,aAAaQ;QAEbT;QACA,IAAI,CAACI,WAAWC,QAAQQ,GAAG,CAAC;QAE5BL,IAAAA,mBAAI,EAAC;IACP;AACF"}
|
package/dist/cjs/compat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\nimport 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';\
|
|
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';\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;;QAyBAC;eAAAA;;QAsBAC;eAAAA;;QAdAC;eAAAA;;QAnBAC;eAAAA;;QAVAC;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;AAClD,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"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -15,11 +15,8 @@ function _interop_require_default(obj) {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
function nodeVersionUse(versionExpression, command, args, options, callback) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
options = {};
|
|
21
|
-
}
|
|
22
|
-
options = options || {};
|
|
18
|
+
callback = typeof options === 'function' ? options : callback;
|
|
19
|
+
options = typeof options === 'function' ? {} : options || {};
|
|
23
20
|
if (typeof callback === 'function') return (0, _workerts.default)(versionExpression, command, args, options, callback);
|
|
24
21
|
return new Promise(function(resolve, reject) {
|
|
25
22
|
return (0, _workerts.default)(versionExpression, command, args, options, function(err, result) {
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -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): 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
|
|
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 callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as UseOptions);\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, (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;IAC3JA,WAAW,OAAOD,YAAY,aAAaA,UAAUC;IACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;IAE7D,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"}
|