{"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: NodeJS.ErrnoException | null) => {\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: unknown[] = [];\n  iterator.forEach(\n    (entry: { type: string; create: (dest: string, cb: Callback) => void }, callback: 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: unknown) => {\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] as { create: (dest: string, cb: Callback) => void };\n        queue.defer(entry.create.bind(entry, dest));\n      }\n      queue.await((err: Error | null) => {\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      return callback(err);\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: { force?: boolean }, callback: (err: Error | null, installed?: boolean) => void): 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: Error | null) => {\n    if (err) {\n      removeIfExistsSync(tempPath);\n      return callback(new Error(`No prebuilt binary available for ${archiveBaseName}. Download: ${downloadUrl}. Error: ${err.message}`));\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":["process","envPathKey","require","fs","safeRmSync","getFile","mkdirp","os","path","Queue","moduleRoot","cpuArch","root","__dirname","GITHUB_REPO","BINARY_VERSION","join","binaryVersion","isWindows","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":";IAiByEA;AAjBzE,IAAMC,aAAaC,QAAQ;AAC3B,IAAMC,KAAKD,QAAQ;AACnB,IAAM,AAAEE,aAAeF,QAAQ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