node-version-use 2.1.5 → 2.1.7
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 +284 -0
- package/assets/postinstall.cjs +11 -404
- package/dist/cjs/assets/installBinaries.cjs +284 -0
- package/dist/cjs/assets/installBinaries.cjs.map +1 -0
- package/dist/cjs/assets/installBinaries.d.cts +1 -0
- package/dist/cjs/assets/postinstall.cjs +11 -404
- package/dist/cjs/assets/postinstall.cjs.map +1 -1
- package/dist/cjs/commands/default.js.map +1 -1
- package/dist/cjs/commands/index.js +2 -3
- package/dist/cjs/commands/index.js.map +1 -1
- package/dist/cjs/commands/list.js.map +1 -1
- package/dist/cjs/commands/setup.js +23 -41
- package/dist/cjs/commands/setup.js.map +1 -1
- package/dist/cjs/commands/teardown.js +2 -1
- package/dist/cjs/commands/teardown.js.map +1 -1
- package/dist/cjs/commands/uninstall.js.map +1 -1
- package/dist/cjs/commands/which.js.map +1 -1
- package/dist/cjs/compat.d.cts +1 -0
- package/dist/cjs/compat.d.ts +1 -0
- package/dist/cjs/compat.js +11 -4
- package/dist/cjs/compat.js.map +1 -1
- package/dist/cjs/lib/findInstalledVersions.js.map +1 -1
- package/dist/esm/assets/installBinaries.cjs +282 -0
- package/dist/esm/assets/installBinaries.cjs.map +1 -0
- package/dist/esm/assets/installBinaries.d.cts +1 -0
- package/dist/esm/assets/postinstall.cjs +11 -404
- package/dist/esm/assets/postinstall.cjs.map +1 -1
- package/dist/esm/commands/default.js +8 -8
- package/dist/esm/commands/default.js.map +1 -1
- package/dist/esm/commands/index.js +2 -3
- package/dist/esm/commands/index.js.map +1 -1
- package/dist/esm/commands/list.js +3 -3
- package/dist/esm/commands/list.js.map +1 -1
- package/dist/esm/commands/setup.js +39 -57
- package/dist/esm/commands/setup.js.map +1 -1
- package/dist/esm/commands/teardown.js +2 -1
- package/dist/esm/commands/teardown.js.map +1 -1
- package/dist/esm/commands/uninstall.js +12 -12
- package/dist/esm/commands/uninstall.js.map +1 -1
- package/dist/esm/commands/which.js +5 -5
- package/dist/esm/commands/which.js.map +1 -1
- package/dist/esm/compat.d.ts +1 -0
- package/dist/esm/compat.js +17 -13
- package/dist/esm/compat.js.map +1 -1
- package/dist/esm/lib/findInstalledVersions.js +19 -19
- package/dist/esm/lib/findInstalledVersions.js.map +1 -1
- package/package.json +24 -19
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/assets/installBinaries.cts"],"sourcesContent":["const envPathKey = require('env-path-key');\nconst fs = require('fs');\nconst { safeRmSync } = require('fs-remove-compat');\nconst getFile = require('get-file-compat');\nconst mkdirp = require('mkdirp-classic');\nconst os = require('os');\nconst path = require('path');\nconst Queue = require('queue-cb');\nconst moduleRoot = require('module-root-sync');\n\nconst root = moduleRoot(__dirname);\n\n// Configuration\nconst GITHUB_REPO = 'kmalakoff/node-version-use';\nconst BINARY_VERSION = require(path.join(root, 'package.json')).binaryVersion;\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\ntype Callback = (err?: Error | null) => void;\n\ninterface PlatformMap {\n [key: string]: string;\n}\n\nconst hasHomedir = typeof os.homedir === 'function';\nfunction homedir(): string {\n if (hasHomedir) return os.homedir();\n const home = require('homedir-polyfill');\n return home();\n}\n\n// Allow NVU_HOME override for testing\nconst storagePath = (process.env.NVU_HOME || path.join(homedir(), '.nvu')) as string;\n\nconst hasTmpdir = typeof os.tmpdir === 'function';\nfunction tmpdir(): string {\n if (hasTmpdir) return os.tmpdir();\n const osShim = require('os-shim');\n return osShim.tmpdir();\n}\n\nfunction removeIfExistsSync(filePath: string): void {\n if (fs.existsSync(filePath)) {\n try {\n fs.unlinkSync(filePath);\n } catch (_e) {\n // ignore cleanup errors\n }\n }\n}\n\n/**\n * Get the platform-specific archive base name (without extension)\n */\nfunction getArchiveBaseName(): string | null {\n const { platform, arch } = process;\n\n const platformMap: PlatformMap = {\n darwin: 'darwin',\n linux: 'linux',\n win32: 'win32',\n };\n\n const archMap: PlatformMap = {\n x64: 'x64',\n arm64: 'arm64',\n amd64: 'x64',\n };\n\n const platformName = platformMap[platform];\n const archName = archMap[arch];\n\n if (!platformName || !archName) return null;\n return `nvu-binary-${platformName}-${archName}`;\n}\n\n/**\n * Copy file\n */\nfunction copyFileSync(src: string, dest: string): void {\n const content = fs.readFileSync(src);\n fs.writeFileSync(dest, content);\n}\n\n/**\n * Atomic rename with fallback to copy+delete for cross-device moves\n */\nfunction atomicRename(src: string, dest: string, callback: Callback): void {\n fs.rename(src, dest, (err) => {\n if (!err) {\n callback(null);\n return;\n }\n\n // Cross-device link error - fall back to copy + delete\n if ((err as NodeJS.ErrnoException).code === 'EXDEV') {\n try {\n copyFileSync(src, dest);\n fs.unlinkSync(src);\n callback(null);\n } catch (copyErr) {\n callback(copyErr as Error);\n }\n return;\n }\n\n callback(err);\n });\n}\n\n/**\n * Extract archive to a directory (callback-based)\n */\nfunction extractArchive(archivePath: string, dest: string, callback: Callback): void {\n const Iterator = isWindows ? require('zip-iterator') : require('tar-iterator');\n const stream = isWindows ? fs.createReadStream(archivePath) : fs.createReadStream(archivePath).pipe(require('zlib').createGunzip());\n let iterator = new Iterator(stream);\n\n // one by one\n const links = [];\n iterator.forEach(\n (entry, callback) => {\n if (entry.type === 'link') {\n links.unshift(entry);\n callback();\n } else if (entry.type === 'symlink') {\n links.push(entry);\n callback();\n } else entry.create(dest, callback);\n },\n { callbacks: true, concurrency: 1 },\n (_err) => {\n // create links after directories and files\n const queue = new Queue();\n for (let index = 0; index < links.length; index++) {\n const entry = links[index];\n queue.defer(entry.create.bind(entry, dest));\n }\n queue.await((err) => {\n iterator.destroy();\n iterator = null;\n callback(err);\n });\n }\n );\n}\n\n/**\n * Install binaries using atomic rename pattern\n * 1. Extract to temp directory\n * 2. Copy binary to temp files in destination directory\n * 3. Atomic rename temp files to final names\n */\nfunction extractAndInstall(archivePath: string, destDir: string, binaryName: string, callback: Callback): void {\n const ext = isWindows ? '.exe' : '';\n\n // Create temp extraction directory\n const tempExtractDir = path.join(tmpdir(), `nvu-extract-${Date.now()}`);\n mkdirp.sync(tempExtractDir);\n\n extractArchive(archivePath, tempExtractDir, (err) => {\n if (err) {\n safeRmSync(tempExtractDir);\n callback(err);\n return;\n }\n\n const extractedPath = path.join(tempExtractDir, binaryName);\n if (!fs.existsSync(extractedPath)) {\n safeRmSync(tempExtractDir);\n callback(new Error(`Extracted binary not found: ${binaryName}. ${archivePath} ${tempExtractDir}`));\n return;\n }\n\n // Binary names to install\n const binaries = ['node', 'npm', 'npx', 'corepack'];\n const timestamp = Date.now();\n let installError: Error | null = null;\n\n // Step 1: Copy extracted binary to temp files in destination directory\n // This ensures the temp files are on the same filesystem for atomic rename\n for (let i = 0; i < binaries.length; i++) {\n const name = binaries[i];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n\n try {\n // Copy to temp file in destination directory\n copyFileSync(extractedPath, tempDest);\n\n // Set permissions on Unix\n if (!isWindows) fs.chmodSync(tempDest, 0o755);\n } catch (err) {\n installError = err as Error;\n break;\n }\n }\n\n if (installError) {\n // Clean up any temp files we created\n for (let j = 0; j < binaries.length; j++) {\n const tempPath = path.join(destDir, `${binaries[j]}.tmp-${timestamp}${ext}`);\n removeIfExistsSync(tempPath);\n }\n safeRmSync(tempExtractDir);\n callback(installError);\n return;\n }\n\n // Step 2: Atomic rename temp files to final names\n let renameError: Error | null = null;\n\n function doRename(index: number): void {\n if (index >= binaries.length) {\n // All renames complete\n safeRmSync(tempExtractDir);\n callback(renameError);\n return;\n }\n\n const name = binaries[index];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n const finalDest = path.join(destDir, `${name}${ext}`);\n\n // Remove existing file if present (for atomic replacement)\n removeIfExistsSync(finalDest);\n\n atomicRename(tempDest, finalDest, (err) => {\n if (err && !renameError) {\n renameError = err;\n }\n doRename(index + 1);\n });\n }\n\n doRename(0);\n });\n}\n\n/**\n * Print setup instructions\n */\nmodule.exports.printInstructions = function printInstructions(): void {\n const nvuBinPath = path.join(storagePath, 'bin');\n\n console.log('nvu binaries installed in ~/.nvu/bin/');\n\n const pathKey = envPathKey();\n const envPath = process.env[pathKey] || '';\n if (envPath.indexOf('.nvu/bin') >= 0) return; // path exists\n\n // provide instructions for path setup\n console.log('');\n console.log('============================================================');\n console.log(' Global node setup');\n console.log('============================================================');\n console.log('');\n if (isWindows) {\n console.log(' PowerShell (add to $PROFILE):');\n console.log(` $env:PATH = \"${nvuBinPath};$env:PATH\"`);\n console.log('');\n console.log(' CMD (run as administrator):');\n console.log(` setx PATH \"${nvuBinPath};%PATH%\"`);\n } else {\n console.log(' # For bash (~/.bashrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.bashrc');\n console.log('');\n console.log(' # For zsh (~/.zshrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.zshrc');\n console.log('');\n console.log(' # For fish (~/.config/fish/config.fish):');\n console.log(\" echo 'set -gx PATH $HOME/.nvu/bin $PATH' >> ~/.config/fish/config.fish\");\n }\n\n console.log('');\n console.log('Then restart your terminal or source your shell profile.');\n console.log('');\n console.log(\"Without this, 'nvu 18 npm test' still works - you just won't have\");\n console.log(\"transparent 'node' command override.\");\n console.log('============================================================');\n};\n\n/**\n * Main installation function\n */\nmodule.exports.installBinaries = function installBinaries(options, callback): void {\n const archiveBaseName = getArchiveBaseName();\n\n if (!archiveBaseName) {\n callback(new Error('Unsupported platform/architecture for binary.'));\n return;\n }\n\n const extractedBinaryName = `${archiveBaseName}${isWindows ? '.exe' : ''}`;\n const binDir = path.join(storagePath, 'bin');\n\n // check if we need to upgrade\n if (!options.force) {\n try {\n // already installed\n if (fs.statSync(binDir)) {\n if (fs.readFileSync(path.join(binDir, 'version.txt'), 'utf8') === BINARY_VERSION) {\n callback(null, false);\n return;\n }\n }\n } catch (_err) {}\n }\n\n // Create directories\n mkdirp.sync(storagePath);\n mkdirp.sync(binDir);\n\n const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/binary-v${BINARY_VERSION}/${archiveBaseName}${isWindows ? '.zip' : '.tar.gz'}`;\n const tempPath = path.join(tmpdir(), `nvu-binary-${Date.now()}${isWindows ? '.zip' : '.tar.gz'}`);\n\n console.log(`Downloading binary for ${process.platform}-${process.arch}...`);\n\n getFile(downloadUrl, tempPath, (err) => {\n if (err) {\n removeIfExistsSync(tempPath);\n callback(new Error(`No prebuilt binary available for ${process.platform}-${process.arch}. Download: ${downloadUrl}. Error: ${err.message}`));\n return;\n }\n\n console.log('Extracting binary...');\n\n extractAndInstall(tempPath, binDir, extractedBinaryName, (err) => {\n removeIfExistsSync(tempPath);\n if (err) {\n callback(err);\n return;\n }\n\n // save binary version for upgrade checks\n fs.writeFileSync(path.join(binDir, 'version.txt'), BINARY_VERSION, 'utf8');\n console.log('Binary installed successfully!');\n callback(null, true);\n });\n });\n};\n"],"names":["envPathKey","require","fs","safeRmSync","getFile","mkdirp","os","path","Queue","moduleRoot","root","__dirname","GITHUB_REPO","BINARY_VERSION","join","binaryVersion","isWindows","process","platform","test","env","OSTYPE","hasHomedir","homedir","home","storagePath","NVU_HOME","hasTmpdir","tmpdir","osShim","removeIfExistsSync","filePath","existsSync","unlinkSync","_e","getArchiveBaseName","arch","platformMap","darwin","linux","win32","archMap","x64","arm64","amd64","platformName","archName","copyFileSync","src","dest","content","readFileSync","writeFileSync","atomicRename","callback","rename","err","code","copyErr","extractArchive","archivePath","Iterator","stream","createReadStream","pipe","createGunzip","iterator","links","forEach","entry","type","unshift","push","create","callbacks","concurrency","_err","queue","index","length","defer","bind","await","destroy","extractAndInstall","destDir","binaryName","ext","tempExtractDir","Date","now","sync","extractedPath","Error","binaries","timestamp","installError","i","name","tempDest","chmodSync","j","tempPath","renameError","doRename","finalDest","module","exports","printInstructions","nvuBinPath","console","log","pathKey","envPath","indexOf","installBinaries","options","archiveBaseName","extractedBinaryName","binDir","force","statSync","downloadUrl","message"],"mappings":"AAAA,MAAMA,aAAaC,QAAQ;AAC3B,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;AAE3B,MAAMS,OAAOD,WAAWE;AAExB,gBAAgB;AAChB,MAAMC,cAAc;AACpB,MAAMC,iBAAiBZ,QAAQM,KAAKO,IAAI,CAACJ,MAAM,iBAAiBK,aAAa;AAE7E,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAQ3F,MAAMC,aAAa,OAAOhB,GAAGiB,OAAO,KAAK;AACzC,SAASA;IACP,IAAID,YAAY,OAAOhB,GAAGiB,OAAO;IACjC,MAAMC,OAAOvB,QAAQ;IACrB,OAAOuB;AACT;AAEA,sCAAsC;AACtC,MAAMC,cAAeR,QAAQG,GAAG,CAACM,QAAQ,IAAInB,KAAKO,IAAI,CAACS,WAAW;AAElE,MAAMI,YAAY,OAAOrB,GAAGsB,MAAM,KAAK;AACvC,SAASA;IACP,IAAID,WAAW,OAAOrB,GAAGsB,MAAM;IAC/B,MAAMC,SAAS5B,QAAQ;IACvB,OAAO4B,OAAOD,MAAM;AACtB;AAEA,SAASE,mBAAmBC,QAAgB;IAC1C,IAAI7B,GAAG8B,UAAU,CAACD,WAAW;QAC3B,IAAI;YACF7B,GAAG+B,UAAU,CAACF;QAChB,EAAE,OAAOG,IAAI;QACX,wBAAwB;QAC1B;IACF;AACF;AAEA;;CAEC,GACD,SAASC;IACP,MAAM,EAAEjB,QAAQ,EAAEkB,IAAI,EAAE,GAAGnB;IAE3B,MAAMoB,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I,CAACyG,QAAQ,gBAAgB1G,gBAAgB;YACnEiG,QAAQC,GAAG,CAAC;YACZzD,SAAS,MAAM;QACjB;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -8,416 +8,23 @@
|
|
|
8
8
|
* 1. Download to temp file
|
|
9
9
|
* 2. Extract to temp directory
|
|
10
10
|
* 3. Atomic rename to final location
|
|
11
|
-
*/ const
|
|
12
|
-
const
|
|
13
|
-
const fs = require('fs');
|
|
14
|
-
const mkdirp = require('mkdirp-classic');
|
|
15
|
-
const os = require('os');
|
|
16
|
-
const path = require('path');
|
|
17
|
-
const hasHomedir = typeof os.homedir === 'function';
|
|
18
|
-
function homedir() {
|
|
19
|
-
if (hasHomedir) {
|
|
20
|
-
return os.homedir();
|
|
21
|
-
}
|
|
22
|
-
var home = require('homedir-polyfill');
|
|
23
|
-
return home();
|
|
24
|
-
}
|
|
25
|
-
module.exports = {
|
|
26
|
-
homedir
|
|
27
|
-
};
|
|
28
|
-
// Configuration
|
|
29
|
-
const GITHUB_REPO = 'kmalakoff/node-version-use';
|
|
30
|
-
// Path is relative to dist/cjs/scripts/ at runtime
|
|
31
|
-
const BINARY_VERSION = require(path.join(__dirname, '..', 'package.json')).binaryVersion;
|
|
32
|
-
/**
|
|
33
|
-
* Get the platform-specific archive base name (without extension)
|
|
34
|
-
*/ function getArchiveBaseName() {
|
|
35
|
-
const platform = os.platform();
|
|
36
|
-
const arch = os.arch();
|
|
37
|
-
const platformMap = {
|
|
38
|
-
darwin: 'darwin',
|
|
39
|
-
linux: 'linux',
|
|
40
|
-
win32: 'win32'
|
|
41
|
-
};
|
|
42
|
-
const archMap = {
|
|
43
|
-
x64: 'x64',
|
|
44
|
-
arm64: 'arm64',
|
|
45
|
-
amd64: 'x64'
|
|
46
|
-
};
|
|
47
|
-
const platformName = platformMap[platform];
|
|
48
|
-
const archName = archMap[arch];
|
|
49
|
-
if (!platformName || !archName) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
return `nvu-binary-${platformName}-${archName}`;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get the extracted binary name (includes .exe on Windows)
|
|
56
|
-
*/ function getExtractedBinaryName(archiveBaseName) {
|
|
57
|
-
const ext = os.platform() === 'win32' ? '.exe' : '';
|
|
58
|
-
return archiveBaseName + ext;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Get the download URL for the binary archive
|
|
62
|
-
*/ function getDownloadUrl(archiveBaseName) {
|
|
63
|
-
const ext = os.platform() === 'win32' ? '.zip' : '.tar.gz';
|
|
64
|
-
return `https://github.com/${GITHUB_REPO}/releases/download/binary-v${BINARY_VERSION}/${archiveBaseName}${ext}`;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Copy file
|
|
68
|
-
*/ function copyFileSync(src, dest) {
|
|
69
|
-
const content = fs.readFileSync(src);
|
|
70
|
-
fs.writeFileSync(dest, content);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Atomic rename with fallback to copy+delete for cross-device moves
|
|
74
|
-
*/ function atomicRename(src, dest, callback) {
|
|
75
|
-
fs.rename(src, dest, (err)=>{
|
|
76
|
-
if (!err) {
|
|
77
|
-
callback(null);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
// Cross-device link error - fall back to copy + delete
|
|
81
|
-
if (err.code === 'EXDEV') {
|
|
82
|
-
try {
|
|
83
|
-
copyFileSync(src, dest);
|
|
84
|
-
fs.unlinkSync(src);
|
|
85
|
-
callback(null);
|
|
86
|
-
} catch (copyErr) {
|
|
87
|
-
callback(copyErr);
|
|
88
|
-
}
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
callback(err);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Remove directory recursively
|
|
96
|
-
*/ function rmRecursive(dir) {
|
|
97
|
-
if (!fs.existsSync(dir)) return;
|
|
98
|
-
const files = fs.readdirSync(dir);
|
|
99
|
-
for(let i = 0; i < files.length; i++){
|
|
100
|
-
const filePath = path.join(dir, files[i]);
|
|
101
|
-
const stat = fs.statSync(filePath);
|
|
102
|
-
if (stat.isDirectory()) {
|
|
103
|
-
rmRecursive(filePath);
|
|
104
|
-
} else {
|
|
105
|
-
fs.unlinkSync(filePath);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
fs.rmdirSync(dir);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Get temp directory
|
|
112
|
-
*/ function getTmpDir() {
|
|
113
|
-
return typeof os.tmpdir === 'function' ? os.tmpdir() : process.env.TMPDIR || process.env.TMP || process.env.TEMP || '/tmp';
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Download using curl (macOS, Linux, Windows 10+)
|
|
117
|
-
*/ function downloadWithCurl(downloadUrl, destPath, callback) {
|
|
118
|
-
const curl = spawn('curl', [
|
|
119
|
-
'-L',
|
|
120
|
-
'-f',
|
|
121
|
-
'-s',
|
|
122
|
-
'-o',
|
|
123
|
-
destPath,
|
|
124
|
-
downloadUrl
|
|
125
|
-
]);
|
|
126
|
-
curl.on('close', (code)=>{
|
|
127
|
-
if (code !== 0) {
|
|
128
|
-
// curl exit codes: 22 = HTTP error (4xx/5xx), 56 = receive error (often 404 with -f)
|
|
129
|
-
if (code === 22 || code === 56) {
|
|
130
|
-
callback(new Error('HTTP 404'));
|
|
131
|
-
} else {
|
|
132
|
-
callback(new Error(`curl failed with exit code ${code}`));
|
|
133
|
-
}
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
callback(null);
|
|
137
|
-
});
|
|
138
|
-
curl.on('error', (err)=>{
|
|
139
|
-
callback(err);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Download using PowerShell (Windows 7+ fallback)
|
|
144
|
-
*/ function downloadWithPowerShell(downloadUrl, destPath, callback) {
|
|
145
|
-
const psCommand = `Invoke-WebRequest -Uri "${downloadUrl}" -OutFile "${destPath}" -UseBasicParsing`;
|
|
146
|
-
const ps = spawn('powershell', [
|
|
147
|
-
'-NoProfile',
|
|
148
|
-
'-Command',
|
|
149
|
-
psCommand
|
|
150
|
-
]);
|
|
151
|
-
ps.on('close', (code)=>{
|
|
152
|
-
if (code !== 0) {
|
|
153
|
-
callback(new Error(`PowerShell download failed with exit code ${code}`));
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
callback(null);
|
|
157
|
-
});
|
|
158
|
-
ps.on('error', (err)=>{
|
|
159
|
-
callback(err);
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Download a file - tries curl first, falls back to PowerShell on Windows
|
|
164
|
-
* Node 0.8's OpenSSL doesn't support TLS 1.2+ required by GitHub
|
|
165
|
-
*/ function downloadFile(downloadUrl, destPath, callback) {
|
|
166
|
-
downloadWithCurl(downloadUrl, destPath, (err)=>{
|
|
167
|
-
var _err_message;
|
|
168
|
-
if (!err) {
|
|
169
|
-
callback(null);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
// If curl failed and we're on Windows, try PowerShell
|
|
173
|
-
if (os.platform() === 'win32' && (err === null || err === void 0 ? void 0 : (_err_message = err.message) === null || _err_message === void 0 ? void 0 : _err_message.indexOf('ENOENT')) >= 0) {
|
|
174
|
-
downloadWithPowerShell(downloadUrl, destPath, callback);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
callback(err);
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Extract archive to a directory (callback-based)
|
|
182
|
-
*/ function extractArchive(archivePath, destDir, callback) {
|
|
183
|
-
const platform = os.platform();
|
|
184
|
-
if (platform === 'win32') {
|
|
185
|
-
// Windows: extract zip using PowerShell
|
|
186
|
-
const ps = spawn('powershell', [
|
|
187
|
-
'-Command',
|
|
188
|
-
`Expand-Archive -Path '${archivePath}' -DestinationPath '${destDir}' -Force`
|
|
189
|
-
]);
|
|
190
|
-
ps.on('close', (code)=>{
|
|
191
|
-
if (code !== 0) {
|
|
192
|
-
callback(new Error('Failed to extract archive'));
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
callback(null);
|
|
196
|
-
});
|
|
197
|
-
} else {
|
|
198
|
-
// Unix: extract tar.gz
|
|
199
|
-
const tar = spawn('tar', [
|
|
200
|
-
'-xzf',
|
|
201
|
-
archivePath,
|
|
202
|
-
'-C',
|
|
203
|
-
destDir
|
|
204
|
-
]);
|
|
205
|
-
tar.on('close', (code)=>{
|
|
206
|
-
if (code !== 0) {
|
|
207
|
-
callback(new Error('Failed to extract archive'));
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
callback(null);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Install binaries using atomic rename pattern
|
|
216
|
-
* 1. Extract to temp directory
|
|
217
|
-
* 2. Copy binary to temp files in destination directory
|
|
218
|
-
* 3. Atomic rename temp files to final names
|
|
219
|
-
*/ function extractAndInstall(archivePath, destDir, binaryName, callback) {
|
|
220
|
-
const platform = os.platform();
|
|
221
|
-
const isWindows = platform === 'win32';
|
|
222
|
-
const ext = isWindows ? '.exe' : '';
|
|
223
|
-
// Create temp extraction directory
|
|
224
|
-
const tempExtractDir = path.join(getTmpDir(), `nvu-extract-${Date.now()}`);
|
|
225
|
-
mkdirp.sync(tempExtractDir);
|
|
226
|
-
extractArchive(archivePath, tempExtractDir, (extractErr)=>{
|
|
227
|
-
if (extractErr) {
|
|
228
|
-
rmRecursive(tempExtractDir);
|
|
229
|
-
callback(extractErr);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
const extractedPath = path.join(tempExtractDir, binaryName);
|
|
233
|
-
if (!fs.existsSync(extractedPath)) {
|
|
234
|
-
rmRecursive(tempExtractDir);
|
|
235
|
-
callback(new Error(`Extracted binary not found: ${binaryName}`));
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
// Binary names to install
|
|
239
|
-
const binaries = [
|
|
240
|
-
'node',
|
|
241
|
-
'npm',
|
|
242
|
-
'npx',
|
|
243
|
-
'corepack'
|
|
244
|
-
];
|
|
245
|
-
const timestamp = Date.now();
|
|
246
|
-
let installError = null;
|
|
247
|
-
// Step 1: Copy extracted binary to temp files in destination directory
|
|
248
|
-
// This ensures the temp files are on the same filesystem for atomic rename
|
|
249
|
-
for(let i = 0; i < binaries.length; i++){
|
|
250
|
-
const name = binaries[i];
|
|
251
|
-
const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);
|
|
252
|
-
try {
|
|
253
|
-
// Copy to temp file in destination directory
|
|
254
|
-
copyFileSync(extractedPath, tempDest);
|
|
255
|
-
// Set permissions on Unix
|
|
256
|
-
if (!isWindows) {
|
|
257
|
-
fs.chmodSync(tempDest, 0o755);
|
|
258
|
-
}
|
|
259
|
-
} catch (err) {
|
|
260
|
-
installError = err;
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
if (installError) {
|
|
265
|
-
// Clean up any temp files we created
|
|
266
|
-
for(let j = 0; j < binaries.length; j++){
|
|
267
|
-
const tempPath = path.join(destDir, `${binaries[j]}.tmp-${timestamp}${ext}`);
|
|
268
|
-
if (fs.existsSync(tempPath)) {
|
|
269
|
-
try {
|
|
270
|
-
fs.unlinkSync(tempPath);
|
|
271
|
-
} catch (_e) {
|
|
272
|
-
// ignore cleanup errors
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
rmRecursive(tempExtractDir);
|
|
277
|
-
callback(installError);
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
// Step 2: Atomic rename temp files to final names
|
|
281
|
-
let renameError = null;
|
|
282
|
-
function doRename(index) {
|
|
283
|
-
if (index >= binaries.length) {
|
|
284
|
-
// All renames complete
|
|
285
|
-
rmRecursive(tempExtractDir);
|
|
286
|
-
callback(renameError);
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
const name = binaries[index];
|
|
290
|
-
const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);
|
|
291
|
-
const finalDest = path.join(destDir, `${name}${ext}`);
|
|
292
|
-
// Remove existing file if present (for atomic replacement)
|
|
293
|
-
if (fs.existsSync(finalDest)) {
|
|
294
|
-
try {
|
|
295
|
-
fs.unlinkSync(finalDest);
|
|
296
|
-
} catch (_e) {
|
|
297
|
-
// ignore cleanup errors
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
atomicRename(tempDest, finalDest, (err)=>{
|
|
301
|
-
if (err && !renameError) {
|
|
302
|
-
renameError = err;
|
|
303
|
-
}
|
|
304
|
-
doRename(index + 1);
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
doRename(0);
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Print setup instructions
|
|
312
|
-
*/ function printInstructions(installed) {
|
|
313
|
-
const homedirPath = homedir();
|
|
314
|
-
const nvuBinPath = path.join(homedirPath, '.nvu', 'bin');
|
|
315
|
-
const platform = os.platform();
|
|
316
|
-
console.log('');
|
|
317
|
-
console.log('============================================================');
|
|
318
|
-
if (installed) {
|
|
319
|
-
console.log(' nvu binaries installed to ~/.nvu/bin/');
|
|
320
|
-
} else {
|
|
321
|
-
console.log(' nvu installed (binaries not yet available)');
|
|
322
|
-
}
|
|
323
|
-
console.log('============================================================');
|
|
324
|
-
console.log('');
|
|
325
|
-
console.log('To enable transparent Node version switching, add to your shell profile:');
|
|
326
|
-
console.log('');
|
|
327
|
-
if (platform === 'win32') {
|
|
328
|
-
console.log(' PowerShell (add to $PROFILE):');
|
|
329
|
-
console.log(` $env:PATH = "${nvuBinPath};$env:PATH"`);
|
|
330
|
-
console.log('');
|
|
331
|
-
console.log(' CMD (run as administrator):');
|
|
332
|
-
console.log(` setx PATH "${nvuBinPath};%PATH%"`);
|
|
333
|
-
} else {
|
|
334
|
-
console.log(' # For bash (~/.bashrc):');
|
|
335
|
-
console.log(' export PATH="$HOME/.nvu/bin:$PATH"');
|
|
336
|
-
console.log('');
|
|
337
|
-
console.log(' # For zsh (~/.zshrc):');
|
|
338
|
-
console.log(' export PATH="$HOME/.nvu/bin:$PATH"');
|
|
339
|
-
console.log('');
|
|
340
|
-
console.log(' # For fish (~/.config/fish/config.fish):');
|
|
341
|
-
console.log(' set -gx PATH $HOME/.nvu/bin $PATH');
|
|
342
|
-
}
|
|
343
|
-
console.log('');
|
|
344
|
-
console.log('Then restart your terminal or source your shell profile.');
|
|
345
|
-
console.log('');
|
|
346
|
-
console.log("Without this, 'nvu 18 npm test' still works - you just won't have");
|
|
347
|
-
console.log("transparent 'node' command override.");
|
|
348
|
-
console.log('============================================================');
|
|
349
|
-
}
|
|
11
|
+
*/ const exit = require('exit-compat');
|
|
12
|
+
const { installBinaries, printInstructions } = require('./installBinaries.cjs');
|
|
350
13
|
/**
|
|
351
14
|
* Main installation function
|
|
352
15
|
*/ function main() {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
exit(0);
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
const extractedBinaryName = getExtractedBinaryName(archiveBaseName);
|
|
362
|
-
const homedirPath = homedir();
|
|
363
|
-
const nvuDir = path.join(homedirPath, '.nvu');
|
|
364
|
-
const binDir = path.join(nvuDir, 'bin');
|
|
365
|
-
// Create directories
|
|
366
|
-
mkdirp.sync(nvuDir);
|
|
367
|
-
mkdirp.sync(binDir);
|
|
368
|
-
const downloadUrl = getDownloadUrl(archiveBaseName);
|
|
369
|
-
const ext = os.platform() === 'win32' ? '.zip' : '.tar.gz';
|
|
370
|
-
const tempPath = path.join(getTmpDir(), `nvu-binary-${Date.now()}${ext}`);
|
|
371
|
-
console.log(`postinstall: Downloading binary for ${os.platform()}-${os.arch()}...`);
|
|
372
|
-
downloadFile(downloadUrl, tempPath, (downloadErr)=>{
|
|
373
|
-
if (downloadErr) {
|
|
374
|
-
var _downloadErr_message;
|
|
375
|
-
// Clean up temp file if it exists
|
|
376
|
-
if (fs.existsSync(tempPath)) {
|
|
377
|
-
try {
|
|
378
|
-
fs.unlinkSync(tempPath);
|
|
379
|
-
} catch (_e) {
|
|
380
|
-
// ignore cleanup errors
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
if (((_downloadErr_message = downloadErr.message) === null || _downloadErr_message === void 0 ? void 0 : _downloadErr_message.indexOf('404')) >= 0) {
|
|
384
|
-
console.log('postinstall: Binaries not yet published to GitHub releases.');
|
|
385
|
-
console.log('');
|
|
386
|
-
console.log('To build and install binaries locally:');
|
|
387
|
-
console.log(' cd node_modules/node-version-use/binary');
|
|
388
|
-
console.log(' make install');
|
|
389
|
-
console.log('');
|
|
390
|
-
console.log('Or wait for the next release which will include pre-built binaries.');
|
|
391
|
-
} else {
|
|
392
|
-
console.log(`postinstall warning: Failed to install binary: ${downloadErr.message || downloadErr}`);
|
|
393
|
-
console.log('You can still use nvu with explicit versions: nvu 18 npm test');
|
|
394
|
-
console.log('To install binaries manually: cd node_modules/node-version-use/binary && make install');
|
|
395
|
-
}
|
|
396
|
-
printInstructions(false);
|
|
397
|
-
exit(0);
|
|
16
|
+
installBinaries({}, (err, installed)=>{
|
|
17
|
+
if (err) {
|
|
18
|
+
console.log(`postinstall warning: Failed to install binary: ${err.message || err}`);
|
|
19
|
+
console.log('You can still use nvu with explicit versions: nvu 18 npm test');
|
|
20
|
+
exit(1);
|
|
398
21
|
return;
|
|
399
22
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
// Clean up temp file
|
|
403
|
-
if (fs.existsSync(tempPath)) {
|
|
404
|
-
try {
|
|
405
|
-
fs.unlinkSync(tempPath);
|
|
406
|
-
} catch (_e) {
|
|
407
|
-
// ignore cleanup errors
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
if (extractErr) {
|
|
411
|
-
console.log(`postinstall warning: Failed to extract binary: ${extractErr.message || extractErr}`);
|
|
412
|
-
console.log('You can still use nvu with explicit versions: nvu 18 npm test');
|
|
413
|
-
printInstructions(false);
|
|
414
|
-
exit(0);
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
23
|
+
if (installed) {
|
|
24
|
+
printInstructions();
|
|
417
25
|
console.log('postinstall: Binary installed successfully!');
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
});
|
|
26
|
+
}
|
|
27
|
+
exit(0);
|
|
421
28
|
});
|
|
422
29
|
}
|
|
423
30
|
main();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/assets/postinstall.cts"],"sourcesContent":["/**\n * Postinstall script for node-version-use\n *\n * Downloads the platform-specific binary and installs it to ~/.nvu/bin/\n * This enables transparent Node version switching.\n *\n * Uses safe atomic download pattern:\n * 1. Download to temp file\n * 2. Extract to temp directory\n * 3. Atomic rename to final location\n */\n\nconst { spawn } = require('child_process');\nconst exit = require('exit-compat');\nconst fs = require('fs');\nconst mkdirp = require('mkdirp-classic');\nconst os = require('os');\nconst path = require('path');\n\nconst hasHomedir = typeof os.homedir === 'function';\nfunction homedir(): string {\n if (hasHomedir) {\n return os.homedir();\n }\n var home = require('homedir-polyfill');\n return home();\n}\n\nmodule.exports = { homedir };\n\n// Configuration\nconst GITHUB_REPO = 'kmalakoff/node-version-use';\n// Path is relative to dist/cjs/scripts/ at runtime\nconst BINARY_VERSION = require(path.join(__dirname, '..', 'package.json')).binaryVersion;\n\ntype Callback = (err?: Error | null) => void;\n\ninterface PlatformMap {\n [key: string]: string;\n}\n\n/**\n * Get the platform-specific archive base name (without extension)\n */\nfunction getArchiveBaseName(): string | null {\n const platform = os.platform();\n const arch = os.arch();\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) {\n return null;\n }\n\n return `nvu-binary-${platformName}-${archName}`;\n}\n\n/**\n * Get the extracted binary name (includes .exe on Windows)\n */\nfunction getExtractedBinaryName(archiveBaseName: string): string {\n const ext = os.platform() === 'win32' ? '.exe' : '';\n return archiveBaseName + ext;\n}\n\n/**\n * Get the download URL for the binary archive\n */\nfunction getDownloadUrl(archiveBaseName: string): string {\n const ext = os.platform() === 'win32' ? '.zip' : '.tar.gz';\n return `https://github.com/${GITHUB_REPO}/releases/download/binary-v${BINARY_VERSION}/${archiveBaseName}${ext}`;\n}\n\n/**\n * Copy file\n */\nfunction copyFileSync(src: string, dest: string): void {\n const content = fs.readFileSync(src);\n fs.writeFileSync(dest, content);\n}\n\n/**\n * Atomic rename with fallback to copy+delete for cross-device moves\n */\nfunction atomicRename(src: string, dest: string, callback: Callback): void {\n fs.rename(src, dest, (err) => {\n if (!err) {\n callback(null);\n return;\n }\n\n // Cross-device link error - fall back to copy + delete\n if ((err as NodeJS.ErrnoException).code === 'EXDEV') {\n try {\n copyFileSync(src, dest);\n fs.unlinkSync(src);\n callback(null);\n } catch (copyErr) {\n callback(copyErr as Error);\n }\n return;\n }\n\n callback(err);\n });\n}\n\n/**\n * Remove directory recursively\n */\nfunction rmRecursive(dir: string): void {\n if (!fs.existsSync(dir)) return;\n\n const files = fs.readdirSync(dir);\n for (let i = 0; i < files.length; i++) {\n const filePath = path.join(dir, files[i]);\n const stat = fs.statSync(filePath);\n if (stat.isDirectory()) {\n rmRecursive(filePath);\n } else {\n fs.unlinkSync(filePath);\n }\n }\n fs.rmdirSync(dir);\n}\n\n/**\n * Get temp directory\n */\nfunction getTmpDir(): string {\n return typeof os.tmpdir === 'function' ? os.tmpdir() : process.env.TMPDIR || process.env.TMP || process.env.TEMP || '/tmp';\n}\n\n/**\n * Download using curl (macOS, Linux, Windows 10+)\n */\nfunction downloadWithCurl(downloadUrl: string, destPath: string, callback: Callback): void {\n const curl = spawn('curl', ['-L', '-f', '-s', '-o', destPath, downloadUrl]);\n\n curl.on('close', (code) => {\n if (code !== 0) {\n // curl exit codes: 22 = HTTP error (4xx/5xx), 56 = receive error (often 404 with -f)\n if (code === 22 || code === 56) {\n callback(new Error('HTTP 404'));\n } else {\n callback(new Error(`curl failed with exit code ${code}`));\n }\n return;\n }\n callback(null);\n });\n\n curl.on('error', (err) => {\n callback(err);\n });\n}\n\n/**\n * Download using PowerShell (Windows 7+ fallback)\n */\nfunction downloadWithPowerShell(downloadUrl: string, destPath: string, callback: Callback): void {\n const psCommand = `Invoke-WebRequest -Uri \"${downloadUrl}\" -OutFile \"${destPath}\" -UseBasicParsing`;\n const ps = spawn('powershell', ['-NoProfile', '-Command', psCommand]);\n\n ps.on('close', (code) => {\n if (code !== 0) {\n callback(new Error(`PowerShell download failed with exit code ${code}`));\n return;\n }\n callback(null);\n });\n\n ps.on('error', (err) => {\n callback(err);\n });\n}\n\n/**\n * Download a file - tries curl first, falls back to PowerShell on Windows\n * Node 0.8's OpenSSL doesn't support TLS 1.2+ required by GitHub\n */\nfunction downloadFile(downloadUrl: string, destPath: string, callback: Callback): void {\n downloadWithCurl(downloadUrl, destPath, (err) => {\n if (!err) {\n callback(null);\n return;\n }\n\n // If curl failed and we're on Windows, try PowerShell\n if (os.platform() === 'win32' && err?.message?.indexOf('ENOENT') >= 0) {\n downloadWithPowerShell(downloadUrl, destPath, callback);\n return;\n }\n\n callback(err);\n });\n}\n\n/**\n * Extract archive to a directory (callback-based)\n */\nfunction extractArchive(archivePath: string, destDir: string, callback: Callback): void {\n const platform = os.platform();\n\n if (platform === 'win32') {\n // Windows: extract zip using PowerShell\n const ps = spawn('powershell', ['-Command', `Expand-Archive -Path '${archivePath}' -DestinationPath '${destDir}' -Force`]);\n ps.on('close', (code) => {\n if (code !== 0) {\n callback(new Error('Failed to extract archive'));\n return;\n }\n callback(null);\n });\n } else {\n // Unix: extract tar.gz\n const tar = spawn('tar', ['-xzf', archivePath, '-C', destDir]);\n tar.on('close', (code) => {\n if (code !== 0) {\n callback(new Error('Failed to extract archive'));\n return;\n }\n callback(null);\n });\n }\n}\n\n/**\n * Install binaries using atomic rename pattern\n * 1. Extract to temp directory\n * 2. Copy binary to temp files in destination directory\n * 3. Atomic rename temp files to final names\n */\nfunction extractAndInstall(archivePath: string, destDir: string, binaryName: string, callback: Callback): void {\n const platform = os.platform();\n const isWindows = platform === 'win32';\n const ext = isWindows ? '.exe' : '';\n\n // Create temp extraction directory\n const tempExtractDir = path.join(getTmpDir(), `nvu-extract-${Date.now()}`);\n mkdirp.sync(tempExtractDir);\n\n extractArchive(archivePath, tempExtractDir, (extractErr) => {\n if (extractErr) {\n rmRecursive(tempExtractDir);\n callback(extractErr);\n return;\n }\n\n const extractedPath = path.join(tempExtractDir, binaryName);\n if (!fs.existsSync(extractedPath)) {\n rmRecursive(tempExtractDir);\n callback(new Error(`Extracted binary not found: ${binaryName}`));\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) {\n fs.chmodSync(tempDest, 0o755);\n }\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 if (fs.existsSync(tempPath)) {\n try {\n fs.unlinkSync(tempPath);\n } catch (_e) {\n // ignore cleanup errors\n }\n }\n }\n rmRecursive(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 rmRecursive(tempExtractDir);\n callback(renameError);\n return;\n }\n\n const name = binaries[index];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n const finalDest = path.join(destDir, `${name}${ext}`);\n\n // Remove existing file if present (for atomic replacement)\n if (fs.existsSync(finalDest)) {\n try {\n fs.unlinkSync(finalDest);\n } catch (_e) {\n // ignore cleanup errors\n }\n }\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 */\nfunction printInstructions(installed: boolean): void {\n const homedirPath = homedir();\n const nvuBinPath = path.join(homedirPath, '.nvu', 'bin');\n const platform = os.platform();\n\n console.log('');\n console.log('============================================================');\n if (installed) {\n console.log(' nvu binaries installed to ~/.nvu/bin/');\n } else {\n console.log(' nvu installed (binaries not yet available)');\n }\n console.log('============================================================');\n console.log('');\n console.log('To enable transparent Node version switching, add to your shell profile:');\n console.log('');\n\n if (platform === 'win32') {\n console.log(' PowerShell (add to $PROFILE):');\n console.log(` $env:PATH = \"${nvuBinPath};$env:PATH\"`);\n console.log('');\n console.log(' CMD (run as administrator):');\n console.log(` setx PATH \"${nvuBinPath};%PATH%\"`);\n } else {\n console.log(' # For bash (~/.bashrc):');\n console.log(' export PATH=\"$HOME/.nvu/bin:$PATH\"');\n console.log('');\n console.log(' # For zsh (~/.zshrc):');\n console.log(' export PATH=\"$HOME/.nvu/bin:$PATH\"');\n console.log('');\n console.log(' # For fish (~/.config/fish/config.fish):');\n console.log(' set -gx PATH $HOME/.nvu/bin $PATH');\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 */\nfunction main(): void {\n const archiveBaseName = getArchiveBaseName();\n\n if (!archiveBaseName) {\n console.log('postinstall: Unsupported platform/architecture for binary.');\n console.log(`Platform: ${os.platform()}, Arch: ${os.arch()}`);\n console.log('Binary not installed. You can still use nvu with explicit versions: nvu 18 npm test');\n exit(0);\n return;\n }\n\n const extractedBinaryName = getExtractedBinaryName(archiveBaseName);\n\n const homedirPath = homedir();\n const nvuDir = path.join(homedirPath, '.nvu');\n const binDir = path.join(nvuDir, 'bin');\n\n // Create directories\n mkdirp.sync(nvuDir);\n mkdirp.sync(binDir);\n\n const downloadUrl = getDownloadUrl(archiveBaseName);\n const ext = os.platform() === 'win32' ? '.zip' : '.tar.gz';\n const tempPath = path.join(getTmpDir(), `nvu-binary-${Date.now()}${ext}`);\n\n console.log(`postinstall: Downloading binary for ${os.platform()}-${os.arch()}...`);\n\n downloadFile(downloadUrl, tempPath, (downloadErr) => {\n if (downloadErr) {\n // Clean up temp file if it exists\n if (fs.existsSync(tempPath)) {\n try {\n fs.unlinkSync(tempPath);\n } catch (_e) {\n // ignore cleanup errors\n }\n }\n\n if (downloadErr.message?.indexOf('404') >= 0) {\n console.log('postinstall: Binaries not yet published to GitHub releases.');\n console.log('');\n console.log('To build and install binaries locally:');\n console.log(' cd node_modules/node-version-use/binary');\n console.log(' make install');\n console.log('');\n console.log('Or wait for the next release which will include pre-built binaries.');\n } else {\n console.log(`postinstall warning: Failed to install binary: ${downloadErr.message || downloadErr}`);\n console.log('You can still use nvu with explicit versions: nvu 18 npm test');\n console.log('To install binaries manually: cd node_modules/node-version-use/binary && make install');\n }\n printInstructions(false);\n exit(0);\n return;\n }\n\n console.log('postinstall: Extracting binary...');\n\n extractAndInstall(tempPath, binDir, extractedBinaryName, (extractErr) => {\n // Clean up temp file\n if (fs.existsSync(tempPath)) {\n try {\n fs.unlinkSync(tempPath);\n } catch (_e) {\n // ignore cleanup errors\n }\n }\n\n if (extractErr) {\n console.log(`postinstall warning: Failed to extract binary: ${extractErr.message || extractErr}`);\n console.log('You can still use nvu with explicit versions: nvu 18 npm test');\n printInstructions(false);\n exit(0);\n return;\n }\n\n console.log('postinstall: Binary installed successfully!');\n printInstructions(true);\n exit(0);\n });\n });\n}\n\nmain();\n"],"names":["spawn","require","exit","fs","mkdirp","os","path","hasHomedir","homedir","home","module","exports","GITHUB_REPO","BINARY_VERSION","join","__dirname","binaryVersion","getArchiveBaseName","platform","arch","platformMap","darwin","linux","win32","archMap","x64","arm64","amd64","platformName","archName","getExtractedBinaryName","archiveBaseName","ext","getDownloadUrl","copyFileSync","src","dest","content","readFileSync","writeFileSync","atomicRename","callback","rename","err","code","unlinkSync","copyErr","rmRecursive","dir","existsSync","files","readdirSync","i","length","filePath","stat","statSync","isDirectory","rmdirSync","getTmpDir","tmpdir","process","env","TMPDIR","TMP","TEMP","downloadWithCurl","downloadUrl","destPath","curl","on","Error","downloadWithPowerShell","psCommand","ps","downloadFile","message","indexOf","extractArchive","archivePath","destDir","tar","extractAndInstall","binaryName","isWindows","tempExtractDir","Date","now","sync","extractErr","extractedPath","binaries","timestamp","installError","name","tempDest","chmodSync","j","tempPath","_e","renameError","doRename","index","finalDest","printInstructions","installed","homedirPath","nvuBinPath","console","log","main","extractedBinaryName","nvuDir","binDir","downloadErr"],"mappings":"AAAA;;;;;;;;;;CAUC,GAED,MAAM,EAAEA,KAAK,EAAE,GAAGC,QAAQ;AAC1B,MAAMC,OAAOD,QAAQ;AACrB,MAAME,KAAKF,QAAQ;AACnB,MAAMG,SAASH,QAAQ;AACvB,MAAMI,KAAKJ,QAAQ;AACnB,MAAMK,OAAOL,QAAQ;AAErB,MAAMM,aAAa,OAAOF,GAAGG,OAAO,KAAK;AACzC,SAASA;IACP,IAAID,YAAY;QACd,OAAOF,GAAGG,OAAO;IACnB;IACA,IAAIC,OAAOR,QAAQ;IACnB,OAAOQ;AACT;AAEAC,OAAOC,OAAO,GAAG;IAAEH;AAAQ;AAE3B,gBAAgB;AAChB,MAAMI,cAAc;AACpB,mDAAmD;AACnD,MAAMC,iBAAiBZ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,CAACtB;YACxD,qBAAqB;YACrB,IAAItF,GAAG8C,UAAU,CAACiD,WAAW;gBAC3B,IAAI;oBACF/F,GAAG0C,UAAU,CAACqD;gBAChB,EAAE,OAAOC,IAAI;gBACX,wBAAwB;gBAC1B;YACF;YAEA,IAAIV,YAAY;gBACdmB,QAAQC,GAAG,CAAC,CAAC,+CAA+C,EAAEpB,WAAWb,OAAO,IAAIa,YAAY;gBAChGmB,QAAQC,GAAG,CAAC;gBACZL,kBAAkB;gBAClBtG,KAAK;gBACL;YACF;YAEA0G,QAAQC,GAAG,CAAC;YACZL,kBAAkB;YAClBtG,KAAK;QACP;IACF;AACF;AAEA4G"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/assets/postinstall.cts"],"sourcesContent":["/**\n * Postinstall script for node-version-use\n *\n * Downloads the platform-specific binary and installs it to ~/.nvu/bin/\n * This enables transparent Node version switching.\n *\n * Uses safe atomic download pattern:\n * 1. Download to temp file\n * 2. Extract to temp directory\n * 3. Atomic rename to final location\n */\n\nconst exit = require('exit-compat');\nconst { installBinaries, printInstructions } = require('./installBinaries.cjs');\n\n/**\n * Main installation function\n */\nfunction main(): void {\n installBinaries({}, (err, installed) => {\n if (err) {\n console.log(`postinstall warning: Failed to install binary: ${err.message || err}`);\n console.log('You can still use nvu with explicit versions: nvu 18 npm test');\n exit(1);\n return;\n }\n\n if (installed) {\n printInstructions();\n console.log('postinstall: Binary installed successfully!');\n }\n exit(0);\n });\n}\n\nmain();\n"],"names":["exit","require","installBinaries","printInstructions","main","err","installed","console","log","message"],"mappings":"AAAA;;;;;;;;;;CAUC,GAED,MAAMA,OAAOC,QAAQ;AACrB,MAAM,EAAEC,eAAe,EAAEC,iBAAiB,EAAE,GAAGF,QAAQ;AAEvD;;CAEC,GACD,SAASG;IACPF,gBAAgB,CAAC,GAAG,CAACG,KAAKC;QACxB,IAAID,KAAK;YACPE,QAAQC,GAAG,CAAC,CAAC,+CAA+C,EAAEH,IAAII,OAAO,IAAIJ,KAAK;YAClFE,QAAQC,GAAG,CAAC;YACZR,KAAK;YACL;QACF;QAEA,IAAIM,WAAW;YACbH;YACAI,QAAQC,GAAG,CAAC;QACd;QACAR,KAAK;IACP;AACF;AAEAI"}
|
|
@@ -11,12 +11,12 @@ import loadNodeVersionInstall from '../lib/loadNodeVersionInstall.js';
|
|
|
11
11
|
* Set or display the global default Node version.
|
|
12
12
|
* This is used when no .nvmrc or .nvurc is found in the project.
|
|
13
13
|
*/ export default function defaultCmd(args) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const defaultFilePath = path.join(storagePath, 'default');
|
|
15
|
+
const versionsPath = path.join(storagePath, 'installed');
|
|
16
16
|
// If no version provided, display current default
|
|
17
17
|
if (args.length === 0) {
|
|
18
18
|
if (fs.existsSync(defaultFilePath)) {
|
|
19
|
-
|
|
19
|
+
const currentVersion = fs.readFileSync(defaultFilePath, 'utf8').trim();
|
|
20
20
|
console.log(`Current default: ${currentVersion}`);
|
|
21
21
|
} else {
|
|
22
22
|
console.log('No default version set.');
|
|
@@ -25,7 +25,7 @@ import loadNodeVersionInstall from '../lib/loadNodeVersionInstall.js';
|
|
|
25
25
|
exit(0);
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
const version = args[0].trim();
|
|
29
29
|
// Validate version format (basic check, indexOf for Node 0.8+ compat)
|
|
30
30
|
if (!version || version.indexOf('-') === 0) {
|
|
31
31
|
console.log('Usage: nvu default <version>');
|
|
@@ -38,7 +38,7 @@ import loadNodeVersionInstall from '../lib/loadNodeVersionInstall.js';
|
|
|
38
38
|
mkdirpSync(storagePath);
|
|
39
39
|
}
|
|
40
40
|
// Check if any installed versions match
|
|
41
|
-
|
|
41
|
+
const matches = findInstalledVersions(versionsPath, version);
|
|
42
42
|
if (matches.length > 0) {
|
|
43
43
|
// Version is installed - resolve to exact and set default
|
|
44
44
|
setDefaultToExact(defaultFilePath, matches);
|
|
@@ -52,7 +52,7 @@ import loadNodeVersionInstall from '../lib/loadNodeVersionInstall.js';
|
|
|
52
52
|
* Set the default to the highest matching installed version
|
|
53
53
|
*/ function setDefaultToExact(defaultFilePath, matches) {
|
|
54
54
|
// matches are sorted by findInstalledVersions, take the last (highest)
|
|
55
|
-
|
|
55
|
+
let exactVersion = matches[matches.length - 1];
|
|
56
56
|
// Ensure it has v prefix for consistency
|
|
57
57
|
if (exactVersion.indexOf('v') !== 0) {
|
|
58
58
|
exactVersion = `v${exactVersion}`;
|
|
@@ -80,12 +80,12 @@ import loadNodeVersionInstall from '../lib/loadNodeVersionInstall.js';
|
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
82
|
// Get the installed version from results
|
|
83
|
-
|
|
83
|
+
let installedVersion;
|
|
84
84
|
if (results && results.length > 0) {
|
|
85
85
|
installedVersion = results[0].version;
|
|
86
86
|
} else {
|
|
87
87
|
// Fallback: re-scan installed versions
|
|
88
|
-
|
|
88
|
+
const matches = findInstalledVersions(versionsPath, version);
|
|
89
89
|
if (matches.length === 0) {
|
|
90
90
|
console.error('Installation completed but version not found');
|
|
91
91
|
exit(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/default.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { mkdirpSync } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\nimport { findInstalledVersions } from '../lib/findInstalledVersions.ts';\nimport loadNodeVersionInstall from '../lib/loadNodeVersionInstall.ts';\n\n/**\n * nvu default [version]\n *\n * Set or display the global default Node version.\n * This is used when no .nvmrc or .nvurc is found in the project.\n */\nexport default function defaultCmd(args: string[]): void {\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/default.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { mkdirpSync } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\nimport { findInstalledVersions } from '../lib/findInstalledVersions.ts';\nimport loadNodeVersionInstall from '../lib/loadNodeVersionInstall.ts';\n\n/**\n * nvu default [version]\n *\n * Set or display the global default Node version.\n * This is used when no .nvmrc or .nvurc is found in the project.\n */\nexport default function defaultCmd(args: string[]): void {\n const defaultFilePath = path.join(storagePath, 'default');\n const versionsPath = path.join(storagePath, 'installed');\n\n // If no version provided, display current default\n if (args.length === 0) {\n if (fs.existsSync(defaultFilePath)) {\n const currentVersion = fs.readFileSync(defaultFilePath, 'utf8').trim();\n console.log(`Current default: ${currentVersion}`);\n } else {\n console.log('No default version set.');\n console.log('Usage: nvu default <version>');\n }\n exit(0);\n return;\n }\n\n const version = args[0].trim();\n\n // Validate version format (basic check, indexOf for Node 0.8+ compat)\n if (!version || version.indexOf('-') === 0) {\n console.log('Usage: nvu default <version>');\n console.log('Example: nvu default 20');\n exit(1);\n return;\n }\n\n // Ensure storage directory exists\n if (!fs.existsSync(storagePath)) {\n mkdirpSync(storagePath);\n }\n\n // Check if any installed versions match\n const matches = findInstalledVersions(versionsPath, version);\n\n if (matches.length > 0) {\n // Version is installed - resolve to exact and set default\n setDefaultToExact(defaultFilePath, matches);\n } else {\n // Version not installed - auto-install it\n console.log(`Node ${version} is not installed. Installing...`);\n autoInstallAndSetDefault(version, versionsPath, defaultFilePath);\n }\n}\n\n/**\n * Set the default to the highest matching installed version\n */\nfunction setDefaultToExact(defaultFilePath: string, matches: string[]): void {\n // matches are sorted by findInstalledVersions, take the last (highest)\n let exactVersion = matches[matches.length - 1];\n\n // Ensure it has v prefix for consistency\n if (exactVersion.indexOf('v') !== 0) {\n exactVersion = `v${exactVersion}`;\n }\n\n // Write the exact version\n fs.writeFileSync(defaultFilePath, `${exactVersion}\\n`, 'utf8');\n console.log(`Default Node version set to: ${exactVersion}`);\n\n exit(0);\n}\n\n/**\n * Auto-install the version and then set it as default\n */\nfunction autoInstallAndSetDefault(version: string, versionsPath: string, defaultFilePath: string): void {\n loadNodeVersionInstall((err, nodeVersionInstall) => {\n if (err || !nodeVersionInstall) {\n console.error('Failed to load node-version-install:', err ? err.message : 'Module not available');\n exit(1);\n return;\n }\n\n nodeVersionInstall(\n version,\n {\n installPath: versionsPath,\n },\n (installErr, results) => {\n if (installErr) {\n console.error(`Failed to install Node ${version}:`, installErr.message);\n exit(1);\n return;\n }\n\n // Get the installed version from results\n let installedVersion: string;\n if (results && results.length > 0) {\n installedVersion = results[0].version;\n } else {\n // Fallback: re-scan installed versions\n const matches = findInstalledVersions(versionsPath, version);\n if (matches.length === 0) {\n console.error('Installation completed but version not found');\n exit(1);\n return;\n }\n installedVersion = matches[matches.length - 1];\n }\n\n // Ensure it has v prefix for consistency\n if (installedVersion.indexOf('v') !== 0) {\n installedVersion = `v${installedVersion}`;\n }\n\n // Write the exact version\n fs.writeFileSync(defaultFilePath, `${installedVersion}\\n`, 'utf8');\n console.log(`Node ${installedVersion} installed successfully.`);\n console.log(`Default Node version set to: ${installedVersion}`);\n\n exit(0);\n }\n );\n });\n}\n"],"names":["exit","fs","path","mkdirpSync","storagePath","findInstalledVersions","loadNodeVersionInstall","defaultCmd","args","defaultFilePath","join","versionsPath","length","existsSync","currentVersion","readFileSync","trim","console","log","version","indexOf","matches","setDefaultToExact","autoInstallAndSetDefault","exactVersion","writeFileSync","err","nodeVersionInstall","error","message","installPath","installErr","results","installedVersion"],"mappings":"AAAA,OAAOA,UAAU,cAAc;AAC/B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,qBAAqB,QAAQ,kCAAkC;AACxE,OAAOC,4BAA4B,mCAAmC;AAEtE;;;;;CAKC,GACD,eAAe,SAASC,WAAWC,IAAc;IAC/C,MAAMC,kBAAkBP,KAAKQ,IAAI,CAACN,aAAa;IAC/C,MAAMO,eAAeT,KAAKQ,IAAI,CAACN,aAAa;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