node-version-use 2.4.3 → 2.4.5
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/assets/installBinaries.cjs +8 -7
- package/dist/cjs/assets/installBinaries.cjs +8 -7
- package/dist/cjs/assets/installBinaries.cjs.map +1 -1
- package/dist/cjs/commands/teardown.js +3 -1
- package/dist/cjs/commands/teardown.js.map +1 -1
- package/dist/cjs/lib/resolveSystemBinary.d.cts +3 -2
- package/dist/cjs/lib/resolveSystemBinary.d.ts +3 -2
- package/dist/cjs/lib/resolveSystemBinary.js +18 -19
- package/dist/cjs/lib/resolveSystemBinary.js.map +1 -1
- package/dist/esm/assets/installBinaries.cjs +8 -7
- package/dist/esm/assets/installBinaries.cjs.map +1 -1
- package/dist/esm/commands/teardown.js +3 -1
- package/dist/esm/commands/teardown.js.map +1 -1
- package/dist/esm/lib/resolveSystemBinary.d.ts +3 -2
- package/dist/esm/lib/resolveSystemBinary.js +21 -21
- package/dist/esm/lib/resolveSystemBinary.js.map +1 -1
- package/package.json +1 -1
|
@@ -226,6 +226,13 @@ function removeIfExistsSync(filePath) {
|
|
|
226
226
|
* 2. Copy binary to temp files in destination directory
|
|
227
227
|
* 3. Atomic rename temp files to final names
|
|
228
228
|
*/ function extractAndInstall(archivePath, destDir, binaryName, callback) {
|
|
229
|
+
var binaries = [
|
|
230
|
+
'nvu',
|
|
231
|
+
'node',
|
|
232
|
+
'npm',
|
|
233
|
+
'npx',
|
|
234
|
+
'corepack'
|
|
235
|
+
];
|
|
229
236
|
var ext = isWindows ? '.exe' : '';
|
|
230
237
|
// Create temp extraction directory
|
|
231
238
|
var tempExtractDir = path.join(tmpdir(), "nvu-extract-".concat(Date.now()));
|
|
@@ -243,12 +250,6 @@ function removeIfExistsSync(filePath) {
|
|
|
243
250
|
return;
|
|
244
251
|
}
|
|
245
252
|
// Binary names to install
|
|
246
|
-
var binaries = [
|
|
247
|
-
'node',
|
|
248
|
-
'npm',
|
|
249
|
-
'npx',
|
|
250
|
-
'corepack'
|
|
251
|
-
];
|
|
252
253
|
var timestamp = Date.now();
|
|
253
254
|
var installError = null;
|
|
254
255
|
// Step 1: Copy extracted binary to temp files in destination directory
|
|
@@ -305,7 +306,7 @@ function removeIfExistsSync(filePath) {
|
|
|
305
306
|
*/ module.exports.printInstructions = function printInstructions() {
|
|
306
307
|
var _nvuBinPath = path.join(storagePath, 'bin');
|
|
307
308
|
console.log('nvu binaries installed in ~/.nvu/bin/');
|
|
308
|
-
var pathKey = envPathKey();
|
|
309
|
+
var pathKey = envPathKey(); // PATH or Path or similar
|
|
309
310
|
var envPath = process.env[pathKey] || '';
|
|
310
311
|
if (envPath.indexOf('.nvu/bin') >= 0) return; // path exists
|
|
311
312
|
// provide instructions for path setup
|
|
@@ -226,6 +226,13 @@ function removeIfExistsSync(filePath) {
|
|
|
226
226
|
* 2. Copy binary to temp files in destination directory
|
|
227
227
|
* 3. Atomic rename temp files to final names
|
|
228
228
|
*/ function extractAndInstall(archivePath, destDir, binaryName, callback) {
|
|
229
|
+
var binaries = [
|
|
230
|
+
'nvu',
|
|
231
|
+
'node',
|
|
232
|
+
'npm',
|
|
233
|
+
'npx',
|
|
234
|
+
'corepack'
|
|
235
|
+
];
|
|
229
236
|
var ext = isWindows ? '.exe' : '';
|
|
230
237
|
// Create temp extraction directory
|
|
231
238
|
var tempExtractDir = path.join(tmpdir(), "nvu-extract-".concat(Date.now()));
|
|
@@ -243,12 +250,6 @@ function removeIfExistsSync(filePath) {
|
|
|
243
250
|
return;
|
|
244
251
|
}
|
|
245
252
|
// Binary names to install
|
|
246
|
-
var binaries = [
|
|
247
|
-
'node',
|
|
248
|
-
'npm',
|
|
249
|
-
'npx',
|
|
250
|
-
'corepack'
|
|
251
|
-
];
|
|
252
253
|
var timestamp = Date.now();
|
|
253
254
|
var installError = null;
|
|
254
255
|
// Step 1: Copy extracted binary to temp files in destination directory
|
|
@@ -305,7 +306,7 @@ function removeIfExistsSync(filePath) {
|
|
|
305
306
|
*/ module.exports.printInstructions = function printInstructions() {
|
|
306
307
|
var _nvuBinPath = path.join(storagePath, 'bin');
|
|
307
308
|
console.log('nvu binaries installed in ~/.nvu/bin/');
|
|
308
|
-
var pathKey = envPathKey();
|
|
309
|
+
var pathKey = envPathKey(); // PATH or Path or similar
|
|
309
310
|
var envPath = process.env[pathKey] || '';
|
|
310
311
|
if (envPath.indexOf('.nvu/bin') >= 0) return; // path exists
|
|
311
312
|
// provide instructions for path setup
|
|
@@ -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');\nconst cpuArch = require('cpu-arch');\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 } = process;\n const arch = cpuArch();\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 ${archiveBaseName}...`);\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 ${archiveBaseName}. 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","cpuArch","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;AAC3B,IAAMS,UAAUT,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"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');\nconst cpuArch = require('cpu-arch');\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 } = process;\n const arch = cpuArch();\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 binaries = ['nvu', 'node', 'npm', 'npx', 'corepack'];\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 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(); // PATH or Path or similar\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 ${archiveBaseName}...`);\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 ${archiveBaseName}. 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","cpuArch","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","binaries","tempExtractDir","sync","extractedPath","Error","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;AAC3B,IAAMS,UAAUT,QAAQ;AAExB,IAAMU,OAAOF,WAAWG;AAExB,gBAAgB;AAChB,IAAMC,cAAc;AACpB,IAAMC,iBAAiBb,QAAQM,KAAKQ,IAAI,CAACJ,MAAM,iBAAiBK,aAAa;AAE7E,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAQ3F,IAAMC,aAAa,OAAOjB,GAAGkB,OAAO,KAAK;AACzC,SAASA;IACP,IAAID,YAAY,OAAOjB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,CAACuE,aAAaG,KAAKI,SAAS,CAAC;gBAAEhI,eAAeF;YAAe,GAAG,MAAM,IAAI;YAC1FkH,QAAQC,GAAG,CAAC;YACZhD,SAAS,MAAM;QACjB;QACA;IACF;IAEA,wBAAwB;IACxB+C,QAAQC,GAAG,CAAC,AAAC,0BAAyC,OAAhBM,iBAAgB;IACtD,IAAMb,WAAWnH,KAAKQ,IAAI,CAACc,UAAU,AAAC,cAA0BZ,OAAbqB,KAAKC,GAAG,IAAoC,OAA/BtB,YAAY,SAAS;IAErFb,QAAQ0I,aAAapB,UAAU,SAACvC;QAC9B,IAAIA,KAAK;YACPpD,mBAAmB2F;YACnBzC,SAAS,IAAIoC,MAAM,AAAC,oCAAiEyB,OAA9BP,iBAAgB,gBAAqCpD,OAAvB2D,aAAY,aAAuB,OAAZ3D,IAAI8D,OAAO;YACvH;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;YACzCjF,GAAGgE,aAAa,CAACuE,aAAaG,KAAKI,SAAS,CAAC;gBAAEhI,eAAeF;YAAe,GAAG,MAAM,IAAI;YAC1FkH,QAAQC,GAAG,CAAC;YACZhD,SAAS,MAAM;QACjB;IACF;AACF"}
|
|
@@ -26,9 +26,11 @@ var isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.e
|
|
|
26
26
|
function teardownCmd(_args) {
|
|
27
27
|
var binDir = _path.default.join(_constantsts.storagePath, 'bin');
|
|
28
28
|
var binaries = [
|
|
29
|
+
'nvu',
|
|
29
30
|
'node',
|
|
30
31
|
'npm',
|
|
31
|
-
'npx'
|
|
32
|
+
'npx',
|
|
33
|
+
'corepack'
|
|
32
34
|
];
|
|
33
35
|
var ext = isWindows ? '.exe' : '';
|
|
34
36
|
var removed = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/teardown.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport { rmSync } from 'fs-remove-compat';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\n/**\n * nvu teardown\n *\n * Remove nvu binaries from ~/.nvu/bin\n */\nexport default function teardownCmd(_args: string[]): void {\n const binDir = path.join(storagePath, 'bin');\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/teardown.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport { rmSync } from 'fs-remove-compat';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\n/**\n * nvu teardown\n *\n * Remove nvu binaries from ~/.nvu/bin\n */\nexport default function teardownCmd(_args: string[]): void {\n const binDir = path.join(storagePath, 'bin');\n const binaries = ['nvu', 'node', 'npm', 'npx', 'corepack'];\n const ext = isWindows ? '.exe' : '';\n\n let removed = 0;\n for (let i = 0; i < binaries.length; i++) {\n const binaryPath = path.join(binDir, binaries[i] + ext);\n if (fs.existsSync(binaryPath)) {\n rmSync(binaryPath, { force: true });\n removed++;\n }\n }\n\n if (removed > 0) {\n console.log(`Removed ${removed} binary(s) from ${binDir}`);\n console.log('');\n console.log('You may also want to remove ~/.nvu/bin from your PATH.');\n } else {\n console.log('No binaries found to remove.');\n }\n\n exit(0);\n}\n"],"names":["teardownCmd","isWindows","process","platform","test","env","OSTYPE","_args","binDir","path","join","storagePath","binaries","ext","removed","i","length","binaryPath","fs","existsSync","rmSync","force","console","log","exit"],"mappings":";;;;+BAQA;;;;CAIC,GACD;;;eAAwBA;;;iEAbP;yDACF;8BACQ;2DACN;2BACW;;;;;;AAE5B,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAO5E,SAASN,YAAYO,KAAe;IACjD,IAAMC,SAASC,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IACtC,IAAMC,WAAW;QAAC;QAAO;QAAQ;QAAO;QAAO;KAAW;IAC1D,IAAMC,MAAMZ,YAAY,SAAS;IAEjC,IAAIa,UAAU;IACd,IAAK,IAAIC,IAAI,GAAGA,IAAIH,SAASI,MAAM,EAAED,IAAK;QACxC,IAAME,aAAaR,aAAI,CAACC,IAAI,CAACF,QAAQI,QAAQ,CAACG,EAAE,GAAGF;QACnD,IAAIK,WAAE,CAACC,UAAU,CAACF,aAAa;YAC7BG,IAAAA,sBAAM,EAACH,YAAY;gBAAEI,OAAO;YAAK;YACjCP;QACF;IACF;IAEA,IAAIA,UAAU,GAAG;QACfQ,QAAQC,GAAG,CAAC,AAAC,WAAoCf,OAA1BM,SAAQ,oBAAyB,OAAPN;QACjDc,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;IACd,OAAO;QACLD,QAAQC,GAAG,CAAC;IACd;IAEAC,IAAAA,mBAAI,EAAC;AACP"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Find a system binary by searching PATH, excluding ~/.nvu/bin
|
|
2
|
+
* Find a system binary by searching PATH, excluding ~/.nvu/bin and version directories
|
|
3
3
|
* Returns the full path to the binary, or null if not found
|
|
4
|
+
* NOTE: Keep in sync with Node.js resolveSystemBinary
|
|
4
5
|
*/
|
|
5
6
|
export declare function resolveSystemBinary(name: string): string | null;
|
|
6
7
|
/**
|
|
7
|
-
* Get PATH with ~/.nvu/bin removed
|
|
8
|
+
* Get PATH with ~/.nvu/bin and version directories removed
|
|
8
9
|
* Used to create an environment for spawning system commands
|
|
9
10
|
*/
|
|
10
11
|
export declare function getPathWithoutNvuBin(): string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Find a system binary by searching PATH, excluding ~/.nvu/bin
|
|
2
|
+
* Find a system binary by searching PATH, excluding ~/.nvu/bin and version directories
|
|
3
3
|
* Returns the full path to the binary, or null if not found
|
|
4
|
+
* NOTE: Keep in sync with Node.js resolveSystemBinary
|
|
4
5
|
*/
|
|
5
6
|
export declare function resolveSystemBinary(name: string): string | null;
|
|
6
7
|
/**
|
|
7
|
-
* Get PATH with ~/.nvu/bin removed
|
|
8
|
+
* Get PATH with ~/.nvu/bin and version directories removed
|
|
8
9
|
* Used to create an environment for spawning system commands
|
|
9
10
|
*/
|
|
10
11
|
export declare function getPathWithoutNvuBin(): string;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Resolve system binaries by searching PATH while excluding ~/.nvu/bin
|
|
3
|
-
* This mirrors the Go binary's findSystemBinary() function
|
|
4
|
-
*/ "use strict";
|
|
1
|
+
"use strict";
|
|
5
2
|
Object.defineProperty(exports, "__esModule", {
|
|
6
3
|
value: true
|
|
7
4
|
});
|
|
@@ -19,6 +16,7 @@ _export(exports, {
|
|
|
19
16
|
return resolveSystemBinary;
|
|
20
17
|
}
|
|
21
18
|
});
|
|
19
|
+
var _envpathkey = /*#__PURE__*/ _interop_require_default(require("env-path-key"));
|
|
22
20
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
23
21
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
24
22
|
var _compatts = require("../compat.js");
|
|
@@ -29,28 +27,29 @@ function _interop_require_default(obj) {
|
|
|
29
27
|
}
|
|
30
28
|
var isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
31
29
|
var nvuBinDir = _path.default.join((0, _compatts.homedir)(), '.nvu', 'bin');
|
|
30
|
+
var nvuInstalledDir = _path.default.join((0, _compatts.homedir)(), '.nvu', 'installed');
|
|
31
|
+
var pathKey = (0, _envpathkey.default)(); // PATH or Path or similar
|
|
32
|
+
var pathDelimiter = _path.default.delimiter ? _path.default.delimiter : isWindows ? ';' : ':';
|
|
32
33
|
/**
|
|
33
34
|
* Check if two paths are equal (case-insensitive on Windows)
|
|
34
35
|
*/ function pathsEqual(a, b) {
|
|
35
|
-
if (isWindows)
|
|
36
|
-
return a.toLowerCase() === b.toLowerCase();
|
|
37
|
-
}
|
|
36
|
+
if (isWindows) return a.toLowerCase() === b.toLowerCase();
|
|
38
37
|
return a === b;
|
|
39
38
|
}
|
|
40
39
|
/**
|
|
41
|
-
* Check if a path is within the nvu bin directory
|
|
42
|
-
*/ function
|
|
40
|
+
* Check if a path is within the nvu bin directory or installed versions
|
|
41
|
+
*/ function isInNvuDir(filePath) {
|
|
43
42
|
try {
|
|
44
43
|
var realPath = _fs.default.realpathSync(filePath);
|
|
45
|
-
|
|
44
|
+
// Check for .nvu/bin or .nvu/installed
|
|
45
|
+
return realPath.indexOf(_path.default.join('.nvu', 'bin')) >= 0 || realPath.indexOf(_path.default.join('.nvu', 'installed')) >= 0 || pathsEqual(_path.default.dirname(realPath), nvuBinDir) || pathsEqual(_path.default.dirname(realPath), nvuInstalledDir);
|
|
46
46
|
} catch (_e) {
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
function resolveSystemBinary(name) {
|
|
51
|
-
var pathEnv = process.env
|
|
52
|
-
var
|
|
53
|
-
var dirs = pathEnv.split(pathSep);
|
|
51
|
+
var pathEnv = process.env[pathKey] || '';
|
|
52
|
+
var dirs = pathEnv.split(pathDelimiter);
|
|
54
53
|
for(var i = 0; i < dirs.length; i++){
|
|
55
54
|
var dir = dirs[i];
|
|
56
55
|
if (!dir) continue;
|
|
@@ -69,8 +68,8 @@ function resolveSystemBinary(name) {
|
|
|
69
68
|
try {
|
|
70
69
|
var stat = _fs.default.statSync(candidate);
|
|
71
70
|
if (!stat.isFile()) continue;
|
|
72
|
-
// Make sure it's not in ~/.nvu/bin
|
|
73
|
-
if (
|
|
71
|
+
// Make sure it's not in ~/.nvu/bin or ~/.nvu/installed/*/bin
|
|
72
|
+
if (isInNvuDir(candidate)) continue;
|
|
74
73
|
return candidate;
|
|
75
74
|
} catch (_e) {
|
|
76
75
|
// File doesn't exist, continue
|
|
@@ -80,17 +79,17 @@ function resolveSystemBinary(name) {
|
|
|
80
79
|
return null;
|
|
81
80
|
}
|
|
82
81
|
function getPathWithoutNvuBin() {
|
|
83
|
-
var pathEnv = process.env
|
|
84
|
-
var
|
|
85
|
-
var dirs = pathEnv.split(pathSep);
|
|
82
|
+
var pathEnv = process.env[pathKey] || '';
|
|
83
|
+
var dirs = pathEnv.split(pathDelimiter);
|
|
86
84
|
var filtered = [];
|
|
87
85
|
for(var i = 0; i < dirs.length; i++){
|
|
88
86
|
var dir = dirs[i];
|
|
89
87
|
if (!dir) continue;
|
|
90
88
|
if (pathsEqual(dir, nvuBinDir)) continue;
|
|
91
89
|
if (dir.indexOf(_path.default.join('.nvu', 'bin')) >= 0) continue;
|
|
90
|
+
if (dir.indexOf(_path.default.join('.nvu', 'installed')) >= 0) continue;
|
|
92
91
|
filtered.push(dir);
|
|
93
92
|
}
|
|
94
|
-
return filtered.join(
|
|
93
|
+
return filtered.join(pathDelimiter);
|
|
95
94
|
}
|
|
96
95
|
/* 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/lib/resolveSystemBinary.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/lib/resolveSystemBinary.ts"],"sourcesContent":["import envPathKey from 'env-path-key';\nimport fs from 'fs';\nimport path from 'path';\nimport { homedir } from '../compat.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst nvuBinDir = path.join(homedir(), '.nvu', 'bin');\nconst nvuInstalledDir = path.join(homedir(), '.nvu', 'installed');\nconst pathKey = envPathKey(); // PATH or Path or similar\nconst pathDelimiter = path.delimiter ? path.delimiter : isWindows ? ';' : ':';\n\n/**\n * Check if two paths are equal (case-insensitive on Windows)\n */\nfunction pathsEqual(a: string, b: string): boolean {\n if (isWindows) return a.toLowerCase() === b.toLowerCase();\n return a === b;\n}\n\n/**\n * Check if a path is within the nvu bin directory or installed versions\n */\nfunction isInNvuDir(filePath: string): boolean {\n try {\n const realPath = fs.realpathSync(filePath);\n // Check for .nvu/bin or .nvu/installed\n return realPath.indexOf(path.join('.nvu', 'bin')) >= 0 || realPath.indexOf(path.join('.nvu', 'installed')) >= 0 || pathsEqual(path.dirname(realPath), nvuBinDir) || pathsEqual(path.dirname(realPath), nvuInstalledDir);\n } catch (_e) {\n return false;\n }\n}\n\n/**\n * Find a system binary by searching PATH, excluding ~/.nvu/bin and version directories\n * Returns the full path to the binary, or null if not found\n * NOTE: Keep in sync with Node.js resolveSystemBinary\n */\nexport function resolveSystemBinary(name: string): string | null {\n const pathEnv = process.env[pathKey] || '';\n const dirs = pathEnv.split(pathDelimiter);\n\n for (let i = 0; i < dirs.length; i++) {\n const dir = dirs[i];\n if (!dir) continue;\n\n // Skip ~/.nvu/bin\n if (pathsEqual(dir, nvuBinDir)) continue;\n\n // Build candidate path with appropriate extension\n const candidates = isWindows ? [path.join(dir, `${name}.exe`), path.join(dir, `${name}.cmd`), path.join(dir, name)] : [path.join(dir, name)];\n\n for (let j = 0; j < candidates.length; j++) {\n const candidate = candidates[j];\n try {\n const stat = fs.statSync(candidate);\n if (!stat.isFile()) continue;\n\n // Make sure it's not in ~/.nvu/bin or ~/.nvu/installed/*/bin\n if (isInNvuDir(candidate)) continue;\n\n return candidate;\n } catch (_e) {\n // File doesn't exist, continue\n }\n }\n }\n\n return null;\n}\n\n/**\n * Get PATH with ~/.nvu/bin and version directories removed\n * Used to create an environment for spawning system commands\n */\nexport function getPathWithoutNvuBin(): string {\n const pathEnv = process.env[pathKey] || '';\n const dirs = pathEnv.split(pathDelimiter);\n\n const filtered: string[] = [];\n for (let i = 0; i < dirs.length; i++) {\n const dir = dirs[i];\n if (!dir) continue;\n if (pathsEqual(dir, nvuBinDir)) continue;\n if (dir.indexOf(path.join('.nvu', 'bin')) >= 0) continue;\n if (dir.indexOf(path.join('.nvu', 'installed')) >= 0) continue;\n filtered.push(dir);\n }\n\n return filtered.join(pathDelimiter);\n}\n"],"names":["getPathWithoutNvuBin","resolveSystemBinary","isWindows","process","platform","test","env","OSTYPE","nvuBinDir","path","join","homedir","nvuInstalledDir","pathKey","envPathKey","pathDelimiter","delimiter","pathsEqual","a","b","toLowerCase","isInNvuDir","filePath","realPath","fs","realpathSync","indexOf","dirname","_e","name","pathEnv","dirs","split","i","length","dir","candidates","j","candidate","stat","statSync","isFile","filtered","push"],"mappings":";;;;;;;;;;;QA0EgBA;eAAAA;;QArCAC;eAAAA;;;iEArCO;yDACR;2DACE;wBACO;;;;;;AAExB,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAC3F,IAAMC,YAAYC,aAAI,CAACC,IAAI,CAACC,IAAAA,iBAAO,KAAI,QAAQ;AAC/C,IAAMC,kBAAkBH,aAAI,CAACC,IAAI,CAACC,IAAAA,iBAAO,KAAI,QAAQ;AACrD,IAAME,UAAUC,IAAAA,mBAAU,KAAI,0BAA0B;AACxD,IAAMC,gBAAgBN,aAAI,CAACO,SAAS,GAAGP,aAAI,CAACO,SAAS,GAAGd,YAAY,MAAM;AAE1E;;CAEC,GACD,SAASe,WAAWC,CAAS,EAAEC,CAAS;IACtC,IAAIjB,WAAW,OAAOgB,EAAEE,WAAW,OAAOD,EAAEC,WAAW;IACvD,OAAOF,MAAMC;AACf;AAEA;;C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AE,OAAOV,IAAI;YACX,+BAA+B;YACjC;QACF;IACF;IAEA,OAAO;AACT;AAMO,SAAS5B;IACd,IAAM8B,UAAU3B,QAAQG,GAAG,CAACO,QAAQ,IAAI;IACxC,IAAMkB,OAAOD,QAAQE,KAAK,CAACjB;IAE3B,IAAM2B,WAAqB,EAAE;IAC7B,IAAK,IAAIT,IAAI,GAAGA,IAAIF,KAAKG,MAAM,EAAED,IAAK;QACpC,IAAME,MAAMJ,IAAI,CAACE,EAAE;QACnB,IAAI,CAACE,KAAK;QACV,IAAIlB,WAAWkB,KAAK3B,YAAY;QAChC,IAAI2B,IAAIT,OAAO,CAACjB,aAAI,CAACC,IAAI,CAAC,QAAQ,WAAW,GAAG;QAChD,IAAIyB,IAAIT,OAAO,CAACjB,aAAI,CAACC,IAAI,CAAC,QAAQ,iBAAiB,GAAG;QACtDgC,SAASC,IAAI,CAACR;IAChB;IAEA,OAAOO,SAAShC,IAAI,CAACK;AACvB"}
|
|
@@ -191,6 +191,13 @@ function removeIfExistsSync(filePath) {
|
|
|
191
191
|
* 2. Copy binary to temp files in destination directory
|
|
192
192
|
* 3. Atomic rename temp files to final names
|
|
193
193
|
*/ function extractAndInstall(archivePath, destDir, binaryName, callback) {
|
|
194
|
+
const binaries = [
|
|
195
|
+
'nvu',
|
|
196
|
+
'node',
|
|
197
|
+
'npm',
|
|
198
|
+
'npx',
|
|
199
|
+
'corepack'
|
|
200
|
+
];
|
|
194
201
|
const ext = isWindows ? '.exe' : '';
|
|
195
202
|
// Create temp extraction directory
|
|
196
203
|
const tempExtractDir = path.join(tmpdir(), `nvu-extract-${Date.now()}`);
|
|
@@ -208,12 +215,6 @@ function removeIfExistsSync(filePath) {
|
|
|
208
215
|
return;
|
|
209
216
|
}
|
|
210
217
|
// Binary names to install
|
|
211
|
-
const binaries = [
|
|
212
|
-
'node',
|
|
213
|
-
'npm',
|
|
214
|
-
'npx',
|
|
215
|
-
'corepack'
|
|
216
|
-
];
|
|
217
218
|
const timestamp = Date.now();
|
|
218
219
|
let installError = null;
|
|
219
220
|
// Step 1: Copy extracted binary to temp files in destination directory
|
|
@@ -270,7 +271,7 @@ function removeIfExistsSync(filePath) {
|
|
|
270
271
|
*/ module.exports.printInstructions = function printInstructions() {
|
|
271
272
|
const _nvuBinPath = path.join(storagePath, 'bin');
|
|
272
273
|
console.log('nvu binaries installed in ~/.nvu/bin/');
|
|
273
|
-
const pathKey = envPathKey();
|
|
274
|
+
const pathKey = envPathKey(); // PATH or Path or similar
|
|
274
275
|
const envPath = process.env[pathKey] || '';
|
|
275
276
|
if (envPath.indexOf('.nvu/bin') >= 0) return; // path exists
|
|
276
277
|
// provide instructions for path setup
|
|
@@ -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');\nconst cpuArch = require('cpu-arch');\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 } = process;\n const arch = cpuArch();\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 ${archiveBaseName}...`);\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 ${archiveBaseName}. 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","cpuArch","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,MAAMA,aAAaC,QAAQ;AAC3B,MAAMC,KAAKD,QAAQ;AACnB,MAAM,EAAEE,UAAU,EAAE,GAAGF,QAAQ;AAC/B,MAAMG,UAAUH,QAAQ;AACxB,MAAMI,SAASJ,QAAQ;AACvB,MAAMK,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F,SAASE;YAEzB,yCAAyC;YACzCjF,GAAGgE,aAAa,CAACuE,aAAaG,KAAKI,SAAS,CAAC;gBAAEhI,eAAeF;YAAe,GAAG,MAAM,IAAI;YAC1FkH,QAAQC,GAAG,CAAC;YACZhD,SAAS,MAAM;QACjB;QACA;IACF;IAEA,wBAAwB;IACxB+C,QAAQC,GAAG,CAAC,CAAC,uBAAuB,EAAEM,gBAAgB,GAAG,CAAC;IAC1D,MAAMb,WAAWnH,KAAKQ,IAAI,CAACc,UAAU,CAAC,WAAW,EAAES,KAAKC,GAAG,KAAKtB,YAAY,SAAS,WAAW;IAEhGb,QAAQ0I,aAAapB,UAAU,CAACvC;QAC9B,IAAIA,KAAK;YACPpD,mBAAmB2F;YACnBzC,SAAS,IAAImC,MAAM,CAAC,iCAAiC,EAAEmB,gBAAgB,YAAY,EAAEO,YAAY,SAAS,EAAE3D,IAAI8D,OAAO,EAAE;YACzH;QACF;QAEA,+BAA+B;QAC/B,IAAI;YACFpF,aAAa6D,UAAUqB;QACzB,EAAE,OAAO5G,IAAI;QACX,sCAAsC;QACxC;QAEA2E,kBAAkBY,UAAUpD,QAAQkE,qBAAqB,CAACrD;YACxDpD,mBAAmB2F;YACnB,IAAIvC,KAAK,OAAOF,SAASE;YAEzB,yCAAyC;YACzCjF,GAAGgE,aAAa,CAACuE,aAAaG,KAAKI,SAAS,CAAC;gBAAEhI,eAAeF;YAAe,GAAG,MAAM,IAAI;YAC1FkH,QAAQC,GAAG,CAAC;YACZhD,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');\nconst cpuArch = require('cpu-arch');\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 } = process;\n const arch = cpuArch();\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 binaries = ['nvu', 'node', 'npm', 'npx', 'corepack'];\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 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(); // PATH or Path or similar\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 ${archiveBaseName}...`);\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 ${archiveBaseName}. 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","cpuArch","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","binaries","tempExtractDir","sync","extractedPath","Error","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,MAAMA,aAAaC,QAAQ;AAC3B,MAAMC,KAAKD,QAAQ;AACnB,MAAM,EAAEE,UAAU,EAAE,GAAGF,QAAQ;AAC/B,MAAMG,UAAUH,QAAQ;AACxB,MAAMI,SAASJ,QAAQ;AACvB,MAAMK,KAAKL,QAAQ;AACnB,MAAMM,OAAON,QAAQ;AACrB,MAAMO,QAAQP,QAAQ;AACtB,MAAMQ,aAAaR,QAAQ;AAC3B,MAAMS,UAAUT,QAAQ;AAExB,MAAMU,OAAOF,WAAWG;AAExB,gBAAgB;AAChB,MAAMC,cAAc;AACpB,MAAMC,iBAAiBb,QAAQM,KAAKQ,IAAI,CAACJ,MAAM,iBAAiBK,aAAa;AAE7E,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAQ3F,MAAMC,aAAa,OAAOjB,GAAGkB,OAAO,KAAK;AACzC,SAASA;IACP,IAAID,YAAY,OAAOjB,GAAGkB,OAAO;IACjC,MAAMC,OAAOxB,QAAQ;IACrB,OAAOwB;AACT;AAEA,sCAAsC;AACtC,MAAMC,cAAeR,QAAQG,GAAG,CAACM,QAAQ,IAAIpB,KAAKQ,IAAI,CAACS,WAAW;AAElE,MAAMI,YAAY,OAAOtB,GAAGuB,MAAM,KAAK;AACvC,SAASA;IACP,IAAID,WAAW,OAAOtB,GAAG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QACxC;QAEA2E,kBAAkBY,UAAUpD,QAAQkE,qBAAqB,CAACrD;YACxDpD,mBAAmB2F;YACnB,IAAIvC,KAAK,OAAOF,SAASE;YAEzB,yCAAyC;YACzCjF,GAAGgE,aAAa,CAACuE,aAAaG,KAAKI,SAAS,CAAC;gBAAEhI,eAAeF;YAAe,GAAG,MAAM,IAAI;YAC1FkH,QAAQC,GAAG,CAAC;YACZhD,SAAS,MAAM;QACjB;IACF;AACF"}
|
|
@@ -11,9 +11,11 @@ const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process
|
|
|
11
11
|
*/ export default function teardownCmd(_args) {
|
|
12
12
|
const binDir = path.join(storagePath, 'bin');
|
|
13
13
|
const binaries = [
|
|
14
|
+
'nvu',
|
|
14
15
|
'node',
|
|
15
16
|
'npm',
|
|
16
|
-
'npx'
|
|
17
|
+
'npx',
|
|
18
|
+
'corepack'
|
|
17
19
|
];
|
|
18
20
|
const ext = isWindows ? '.exe' : '';
|
|
19
21
|
let removed = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/teardown.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport { rmSync } from 'fs-remove-compat';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\n/**\n * nvu teardown\n *\n * Remove nvu binaries from ~/.nvu/bin\n */\nexport default function teardownCmd(_args: string[]): void {\n const binDir = path.join(storagePath, 'bin');\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/teardown.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport { rmSync } from 'fs-remove-compat';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\n/**\n * nvu teardown\n *\n * Remove nvu binaries from ~/.nvu/bin\n */\nexport default function teardownCmd(_args: string[]): void {\n const binDir = path.join(storagePath, 'bin');\n const binaries = ['nvu', 'node', 'npm', 'npx', 'corepack'];\n const ext = isWindows ? '.exe' : '';\n\n let removed = 0;\n for (let i = 0; i < binaries.length; i++) {\n const binaryPath = path.join(binDir, binaries[i] + ext);\n if (fs.existsSync(binaryPath)) {\n rmSync(binaryPath, { force: true });\n removed++;\n }\n }\n\n if (removed > 0) {\n console.log(`Removed ${removed} binary(s) from ${binDir}`);\n console.log('');\n console.log('You may also want to remove ~/.nvu/bin from your PATH.');\n } else {\n console.log('No binaries found to remove.');\n }\n\n exit(0);\n}\n"],"names":["exit","fs","rmSync","path","storagePath","isWindows","process","platform","test","env","OSTYPE","teardownCmd","_args","binDir","join","binaries","ext","removed","i","length","binaryPath","existsSync","force","console","log"],"mappings":"AAAA,OAAOA,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,UAAU,OAAO;AACxB,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F;;;;CAIC,GACD,eAAe,SAASC,YAAYC,KAAe;IACjD,MAAMC,SAASV,KAAKW,IAAI,CAACV,aAAa;IACtC,MAAMW,WAAW;QAAC;QAAO;QAAQ;QAAO;QAAO;KAAW;IAC1D,MAAMC,MAAMX,YAAY,SAAS;IAEjC,IAAIY,UAAU;IACd,IAAK,IAAIC,IAAI,GAAGA,IAAIH,SAASI,MAAM,EAAED,IAAK;QACxC,MAAME,aAAajB,KAAKW,IAAI,CAACD,QAAQE,QAAQ,CAACG,EAAE,GAAGF;QACnD,IAAIf,GAAGoB,UAAU,CAACD,aAAa;YAC7BlB,OAAOkB,YAAY;gBAAEE,OAAO;YAAK;YACjCL;QACF;IACF;IAEA,IAAIA,UAAU,GAAG;QACfM,QAAQC,GAAG,CAAC,CAAC,QAAQ,EAAEP,QAAQ,gBAAgB,EAAEJ,QAAQ;QACzDU,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;IACd,OAAO;QACLD,QAAQC,GAAG,CAAC;IACd;IAEAxB,KAAK;AACP"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Find a system binary by searching PATH, excluding ~/.nvu/bin
|
|
2
|
+
* Find a system binary by searching PATH, excluding ~/.nvu/bin and version directories
|
|
3
3
|
* Returns the full path to the binary, or null if not found
|
|
4
|
+
* NOTE: Keep in sync with Node.js resolveSystemBinary
|
|
4
5
|
*/
|
|
5
6
|
export declare function resolveSystemBinary(name: string): string | null;
|
|
6
7
|
/**
|
|
7
|
-
* Get PATH with ~/.nvu/bin removed
|
|
8
|
+
* Get PATH with ~/.nvu/bin and version directories removed
|
|
8
9
|
* Used to create an environment for spawning system commands
|
|
9
10
|
*/
|
|
10
11
|
export declare function getPathWithoutNvuBin(): string;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* This mirrors the Go binary's findSystemBinary() function
|
|
4
|
-
*/ import fs from 'fs';
|
|
1
|
+
import envPathKey from 'env-path-key';
|
|
2
|
+
import fs from 'fs';
|
|
5
3
|
import path from 'path';
|
|
6
4
|
import { homedir } from '../compat.js';
|
|
7
5
|
const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
8
6
|
const nvuBinDir = path.join(homedir(), '.nvu', 'bin');
|
|
7
|
+
const nvuInstalledDir = path.join(homedir(), '.nvu', 'installed');
|
|
8
|
+
const pathKey = envPathKey(); // PATH or Path or similar
|
|
9
|
+
const pathDelimiter = path.delimiter ? path.delimiter : isWindows ? ';' : ':';
|
|
9
10
|
/**
|
|
10
11
|
* Check if two paths are equal (case-insensitive on Windows)
|
|
11
12
|
*/ function pathsEqual(a, b) {
|
|
12
|
-
if (isWindows)
|
|
13
|
-
return a.toLowerCase() === b.toLowerCase();
|
|
14
|
-
}
|
|
13
|
+
if (isWindows) return a.toLowerCase() === b.toLowerCase();
|
|
15
14
|
return a === b;
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
|
-
* Check if a path is within the nvu bin directory
|
|
19
|
-
*/ function
|
|
17
|
+
* Check if a path is within the nvu bin directory or installed versions
|
|
18
|
+
*/ function isInNvuDir(filePath) {
|
|
20
19
|
try {
|
|
21
20
|
const realPath = fs.realpathSync(filePath);
|
|
22
|
-
|
|
21
|
+
// Check for .nvu/bin or .nvu/installed
|
|
22
|
+
return realPath.indexOf(path.join('.nvu', 'bin')) >= 0 || realPath.indexOf(path.join('.nvu', 'installed')) >= 0 || pathsEqual(path.dirname(realPath), nvuBinDir) || pathsEqual(path.dirname(realPath), nvuInstalledDir);
|
|
23
23
|
} catch (_e) {
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Find a system binary by searching PATH, excluding ~/.nvu/bin
|
|
28
|
+
* Find a system binary by searching PATH, excluding ~/.nvu/bin and version directories
|
|
29
29
|
* Returns the full path to the binary, or null if not found
|
|
30
|
+
* NOTE: Keep in sync with Node.js resolveSystemBinary
|
|
30
31
|
*/ export function resolveSystemBinary(name) {
|
|
31
|
-
const pathEnv = process.env
|
|
32
|
-
const
|
|
33
|
-
const dirs = pathEnv.split(pathSep);
|
|
32
|
+
const pathEnv = process.env[pathKey] || '';
|
|
33
|
+
const dirs = pathEnv.split(pathDelimiter);
|
|
34
34
|
for(let i = 0; i < dirs.length; i++){
|
|
35
35
|
const dir = dirs[i];
|
|
36
36
|
if (!dir) continue;
|
|
@@ -49,8 +49,8 @@ const nvuBinDir = path.join(homedir(), '.nvu', 'bin');
|
|
|
49
49
|
try {
|
|
50
50
|
const stat = fs.statSync(candidate);
|
|
51
51
|
if (!stat.isFile()) continue;
|
|
52
|
-
// Make sure it's not in ~/.nvu/bin
|
|
53
|
-
if (
|
|
52
|
+
// Make sure it's not in ~/.nvu/bin or ~/.nvu/installed/*/bin
|
|
53
|
+
if (isInNvuDir(candidate)) continue;
|
|
54
54
|
return candidate;
|
|
55
55
|
} catch (_e) {
|
|
56
56
|
// File doesn't exist, continue
|
|
@@ -60,19 +60,19 @@ const nvuBinDir = path.join(homedir(), '.nvu', 'bin');
|
|
|
60
60
|
return null;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* Get PATH with ~/.nvu/bin removed
|
|
63
|
+
* Get PATH with ~/.nvu/bin and version directories removed
|
|
64
64
|
* Used to create an environment for spawning system commands
|
|
65
65
|
*/ export function getPathWithoutNvuBin() {
|
|
66
|
-
const pathEnv = process.env
|
|
67
|
-
const
|
|
68
|
-
const dirs = pathEnv.split(pathSep);
|
|
66
|
+
const pathEnv = process.env[pathKey] || '';
|
|
67
|
+
const dirs = pathEnv.split(pathDelimiter);
|
|
69
68
|
const filtered = [];
|
|
70
69
|
for(let i = 0; i < dirs.length; i++){
|
|
71
70
|
const dir = dirs[i];
|
|
72
71
|
if (!dir) continue;
|
|
73
72
|
if (pathsEqual(dir, nvuBinDir)) continue;
|
|
74
73
|
if (dir.indexOf(path.join('.nvu', 'bin')) >= 0) continue;
|
|
74
|
+
if (dir.indexOf(path.join('.nvu', 'installed')) >= 0) continue;
|
|
75
75
|
filtered.push(dir);
|
|
76
76
|
}
|
|
77
|
-
return filtered.join(
|
|
77
|
+
return filtered.join(pathDelimiter);
|
|
78
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/lib/resolveSystemBinary.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/lib/resolveSystemBinary.ts"],"sourcesContent":["import envPathKey from 'env-path-key';\nimport fs from 'fs';\nimport path from 'path';\nimport { homedir } from '../compat.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst nvuBinDir = path.join(homedir(), '.nvu', 'bin');\nconst nvuInstalledDir = path.join(homedir(), '.nvu', 'installed');\nconst pathKey = envPathKey(); // PATH or Path or similar\nconst pathDelimiter = path.delimiter ? path.delimiter : isWindows ? ';' : ':';\n\n/**\n * Check if two paths are equal (case-insensitive on Windows)\n */\nfunction pathsEqual(a: string, b: string): boolean {\n if (isWindows) return a.toLowerCase() === b.toLowerCase();\n return a === b;\n}\n\n/**\n * Check if a path is within the nvu bin directory or installed versions\n */\nfunction isInNvuDir(filePath: string): boolean {\n try {\n const realPath = fs.realpathSync(filePath);\n // Check for .nvu/bin or .nvu/installed\n return realPath.indexOf(path.join('.nvu', 'bin')) >= 0 || realPath.indexOf(path.join('.nvu', 'installed')) >= 0 || pathsEqual(path.dirname(realPath), nvuBinDir) || pathsEqual(path.dirname(realPath), nvuInstalledDir);\n } catch (_e) {\n return false;\n }\n}\n\n/**\n * Find a system binary by searching PATH, excluding ~/.nvu/bin and version directories\n * Returns the full path to the binary, or null if not found\n * NOTE: Keep in sync with Node.js resolveSystemBinary\n */\nexport function resolveSystemBinary(name: string): string | null {\n const pathEnv = process.env[pathKey] || '';\n const dirs = pathEnv.split(pathDelimiter);\n\n for (let i = 0; i < dirs.length; i++) {\n const dir = dirs[i];\n if (!dir) continue;\n\n // Skip ~/.nvu/bin\n if (pathsEqual(dir, nvuBinDir)) continue;\n\n // Build candidate path with appropriate extension\n const candidates = isWindows ? [path.join(dir, `${name}.exe`), path.join(dir, `${name}.cmd`), path.join(dir, name)] : [path.join(dir, name)];\n\n for (let j = 0; j < candidates.length; j++) {\n const candidate = candidates[j];\n try {\n const stat = fs.statSync(candidate);\n if (!stat.isFile()) continue;\n\n // Make sure it's not in ~/.nvu/bin or ~/.nvu/installed/*/bin\n if (isInNvuDir(candidate)) continue;\n\n return candidate;\n } catch (_e) {\n // File doesn't exist, continue\n }\n }\n }\n\n return null;\n}\n\n/**\n * Get PATH with ~/.nvu/bin and version directories removed\n * Used to create an environment for spawning system commands\n */\nexport function getPathWithoutNvuBin(): string {\n const pathEnv = process.env[pathKey] || '';\n const dirs = pathEnv.split(pathDelimiter);\n\n const filtered: string[] = [];\n for (let i = 0; i < dirs.length; i++) {\n const dir = dirs[i];\n if (!dir) continue;\n if (pathsEqual(dir, nvuBinDir)) continue;\n if (dir.indexOf(path.join('.nvu', 'bin')) >= 0) continue;\n if (dir.indexOf(path.join('.nvu', 'installed')) >= 0) continue;\n filtered.push(dir);\n }\n\n return filtered.join(pathDelimiter);\n}\n"],"names":["envPathKey","fs","path","homedir","isWindows","process","platform","test","env","OSTYPE","nvuBinDir","join","nvuInstalledDir","pathKey","pathDelimiter","delimiter","pathsEqual","a","b","toLowerCase","isInNvuDir","filePath","realPath","realpathSync","indexOf","dirname","_e","resolveSystemBinary","name","pathEnv","dirs","split","i","length","dir","candidates","j","candidate","stat","statSync","isFile","getPathWithoutNvuBin","filtered","push"],"mappings":"AAAA,OAAOA,gBAAgB,eAAe;AACtC,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,OAAO,QAAQ,eAAe;AAEvC,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAC3F,MAAMC,YAAYR,KAAKS,IAAI,CAACR,WAAW,QAAQ;AAC/C,MAAMS,kBAAkBV,KAAKS,IAAI,CAACR,WAAW,QAAQ;AACrD,MAAMU,UAAUb,cAAc,0BAA0B;AACxD,MAAMc,gBAAgBZ,KAAKa,SAAS,GAAGb,KAAKa,SAAS,GAAGX,YAAY,MAAM;AAE1E;;CAEC,GACD,SAASY,WAAWC,CAAS,EAAEC,CAAS;IACtC,IAAId,WAAW,OAAOa,EAAEE,WAAW,OAAOD,EAAEC,WAAW;IACvD,OAAOF,MAAMC;AACf;AAEA;;CAEC,GACD,SAASE,WA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