node-version-use 2.1.6 → 2.1.8
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/index.js +2 -3
- package/dist/cjs/commands/index.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/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/loadNodeVersionInstall.js +2 -2
- package/dist/cjs/lib/loadNodeVersionInstall.js.map +1 -1
- package/dist/cjs/worker.js +1 -1
- package/dist/cjs/worker.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/index.js +2 -3
- package/dist/esm/commands/index.js.map +1 -1
- package/dist/esm/commands/setup.js +24 -42
- 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/compat.d.ts +1 -0
- package/dist/esm/compat.js +8 -4
- package/dist/esm/compat.js.map +1 -1
- package/dist/esm/lib/loadNodeVersionInstall.js +2 -2
- package/dist/esm/lib/loadNodeVersionInstall.js.map +1 -1
- package/dist/esm/worker.js +1 -1
- package/dist/esm/worker.js.map +1 -1
- package/package.json +27 -22
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var envPathKey = require('env-path-key');
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var safeRmSync = require('fs-remove-compat').safeRmSync;
|
|
5
|
+
var getFile = require('get-file-compat');
|
|
6
|
+
var mkdirp = require('mkdirp-classic');
|
|
7
|
+
var os = require('os');
|
|
8
|
+
var path = require('path');
|
|
9
|
+
var Queue = require('queue-cb');
|
|
10
|
+
var moduleRoot = require('module-root-sync');
|
|
11
|
+
var root = moduleRoot(__dirname);
|
|
12
|
+
// Configuration
|
|
13
|
+
var GITHUB_REPO = 'kmalakoff/node-version-use';
|
|
14
|
+
var BINARY_VERSION = require(path.join(root, 'package.json')).binaryVersion;
|
|
15
|
+
var isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
16
|
+
var hasHomedir = typeof os.homedir === 'function';
|
|
17
|
+
function homedir() {
|
|
18
|
+
if (hasHomedir) return os.homedir();
|
|
19
|
+
var home = require('homedir-polyfill');
|
|
20
|
+
return home();
|
|
21
|
+
}
|
|
22
|
+
// Allow NVU_HOME override for testing
|
|
23
|
+
var storagePath = process.env.NVU_HOME || path.join(homedir(), '.nvu');
|
|
24
|
+
var hasTmpdir = typeof os.tmpdir === 'function';
|
|
25
|
+
function tmpdir() {
|
|
26
|
+
if (hasTmpdir) return os.tmpdir();
|
|
27
|
+
var osShim = require('os-shim');
|
|
28
|
+
return osShim.tmpdir();
|
|
29
|
+
}
|
|
30
|
+
function removeIfExistsSync(filePath) {
|
|
31
|
+
if (fs.existsSync(filePath)) {
|
|
32
|
+
try {
|
|
33
|
+
fs.unlinkSync(filePath);
|
|
34
|
+
} catch (_e) {
|
|
35
|
+
// ignore cleanup errors
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the platform-specific archive base name (without extension)
|
|
41
|
+
*/ function getArchiveBaseName() {
|
|
42
|
+
var platform = process.platform, arch = process.arch;
|
|
43
|
+
var platformMap = {
|
|
44
|
+
darwin: 'darwin',
|
|
45
|
+
linux: 'linux',
|
|
46
|
+
win32: 'win32'
|
|
47
|
+
};
|
|
48
|
+
var archMap = {
|
|
49
|
+
x64: 'x64',
|
|
50
|
+
arm64: 'arm64',
|
|
51
|
+
amd64: 'x64'
|
|
52
|
+
};
|
|
53
|
+
var platformName = platformMap[platform];
|
|
54
|
+
var archName = archMap[arch];
|
|
55
|
+
if (!platformName || !archName) return null;
|
|
56
|
+
return "nvu-binary-".concat(platformName, "-").concat(archName);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Copy file
|
|
60
|
+
*/ function copyFileSync(src, dest) {
|
|
61
|
+
var content = fs.readFileSync(src);
|
|
62
|
+
fs.writeFileSync(dest, content);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Atomic rename with fallback to copy+delete for cross-device moves
|
|
66
|
+
*/ function atomicRename(src, dest, callback) {
|
|
67
|
+
fs.rename(src, dest, function(err) {
|
|
68
|
+
if (!err) {
|
|
69
|
+
callback(null);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// Cross-device link error - fall back to copy + delete
|
|
73
|
+
if (err.code === 'EXDEV') {
|
|
74
|
+
try {
|
|
75
|
+
copyFileSync(src, dest);
|
|
76
|
+
fs.unlinkSync(src);
|
|
77
|
+
callback(null);
|
|
78
|
+
} catch (copyErr) {
|
|
79
|
+
callback(copyErr);
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
callback(err);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Extract archive to a directory (callback-based)
|
|
88
|
+
*/ function extractArchive(archivePath, dest, callback) {
|
|
89
|
+
var Iterator = isWindows ? require('zip-iterator') : require('tar-iterator');
|
|
90
|
+
var stream = isWindows ? fs.createReadStream(archivePath) : fs.createReadStream(archivePath).pipe(require('zlib').createGunzip());
|
|
91
|
+
var iterator = new Iterator(stream);
|
|
92
|
+
// one by one
|
|
93
|
+
var links = [];
|
|
94
|
+
iterator.forEach(function(entry, callback) {
|
|
95
|
+
if (entry.type === 'link') {
|
|
96
|
+
links.unshift(entry);
|
|
97
|
+
callback();
|
|
98
|
+
} else if (entry.type === 'symlink') {
|
|
99
|
+
links.push(entry);
|
|
100
|
+
callback();
|
|
101
|
+
} else entry.create(dest, callback);
|
|
102
|
+
}, {
|
|
103
|
+
callbacks: true,
|
|
104
|
+
concurrency: 1
|
|
105
|
+
}, function(_err) {
|
|
106
|
+
// create links after directories and files
|
|
107
|
+
var queue = new Queue();
|
|
108
|
+
for(var index = 0; index < links.length; index++){
|
|
109
|
+
var entry = links[index];
|
|
110
|
+
queue.defer(entry.create.bind(entry, dest));
|
|
111
|
+
}
|
|
112
|
+
queue.await(function(err) {
|
|
113
|
+
iterator.destroy();
|
|
114
|
+
iterator = null;
|
|
115
|
+
callback(err);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Install binaries using atomic rename pattern
|
|
121
|
+
* 1. Extract to temp directory
|
|
122
|
+
* 2. Copy binary to temp files in destination directory
|
|
123
|
+
* 3. Atomic rename temp files to final names
|
|
124
|
+
*/ function extractAndInstall(archivePath, destDir, binaryName, callback) {
|
|
125
|
+
var ext = isWindows ? '.exe' : '';
|
|
126
|
+
// Create temp extraction directory
|
|
127
|
+
var tempExtractDir = path.join(tmpdir(), "nvu-extract-".concat(Date.now()));
|
|
128
|
+
mkdirp.sync(tempExtractDir);
|
|
129
|
+
extractArchive(archivePath, tempExtractDir, function(err) {
|
|
130
|
+
if (err) {
|
|
131
|
+
safeRmSync(tempExtractDir);
|
|
132
|
+
callback(err);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
var extractedPath = path.join(tempExtractDir, binaryName);
|
|
136
|
+
if (!fs.existsSync(extractedPath)) {
|
|
137
|
+
safeRmSync(tempExtractDir);
|
|
138
|
+
callback(new Error("Extracted binary not found: ".concat(binaryName, ". ").concat(archivePath, " ").concat(tempExtractDir)));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
// Binary names to install
|
|
142
|
+
var binaries = [
|
|
143
|
+
'node',
|
|
144
|
+
'npm',
|
|
145
|
+
'npx',
|
|
146
|
+
'corepack'
|
|
147
|
+
];
|
|
148
|
+
var timestamp = Date.now();
|
|
149
|
+
var installError = null;
|
|
150
|
+
// Step 1: Copy extracted binary to temp files in destination directory
|
|
151
|
+
// This ensures the temp files are on the same filesystem for atomic rename
|
|
152
|
+
for(var i = 0; i < binaries.length; i++){
|
|
153
|
+
var name = binaries[i];
|
|
154
|
+
var tempDest = path.join(destDir, "".concat(name, ".tmp-").concat(timestamp).concat(ext));
|
|
155
|
+
try {
|
|
156
|
+
// Copy to temp file in destination directory
|
|
157
|
+
copyFileSync(extractedPath, tempDest);
|
|
158
|
+
// Set permissions on Unix
|
|
159
|
+
if (!isWindows) fs.chmodSync(tempDest, 493);
|
|
160
|
+
} catch (err) {
|
|
161
|
+
installError = err;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (installError) {
|
|
166
|
+
// Clean up any temp files we created
|
|
167
|
+
for(var j = 0; j < binaries.length; j++){
|
|
168
|
+
var tempPath = path.join(destDir, "".concat(binaries[j], ".tmp-").concat(timestamp).concat(ext));
|
|
169
|
+
removeIfExistsSync(tempPath);
|
|
170
|
+
}
|
|
171
|
+
safeRmSync(tempExtractDir);
|
|
172
|
+
callback(installError);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
// Step 2: Atomic rename temp files to final names
|
|
176
|
+
var renameError = null;
|
|
177
|
+
function doRename(index) {
|
|
178
|
+
if (index >= binaries.length) {
|
|
179
|
+
// All renames complete
|
|
180
|
+
safeRmSync(tempExtractDir);
|
|
181
|
+
callback(renameError);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
var name = binaries[index];
|
|
185
|
+
var tempDest = path.join(destDir, "".concat(name, ".tmp-").concat(timestamp).concat(ext));
|
|
186
|
+
var finalDest = path.join(destDir, "".concat(name).concat(ext));
|
|
187
|
+
// Remove existing file if present (for atomic replacement)
|
|
188
|
+
removeIfExistsSync(finalDest);
|
|
189
|
+
atomicRename(tempDest, finalDest, function(err) {
|
|
190
|
+
if (err && !renameError) {
|
|
191
|
+
renameError = err;
|
|
192
|
+
}
|
|
193
|
+
doRename(index + 1);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
doRename(0);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Print setup instructions
|
|
201
|
+
*/ module.exports.printInstructions = function printInstructions() {
|
|
202
|
+
var nvuBinPath = path.join(storagePath, 'bin');
|
|
203
|
+
console.log('nvu binaries installed in ~/.nvu/bin/');
|
|
204
|
+
var pathKey = envPathKey();
|
|
205
|
+
var envPath = process.env[pathKey] || '';
|
|
206
|
+
if (envPath.indexOf('.nvu/bin') >= 0) return; // path exists
|
|
207
|
+
// provide instructions for path setup
|
|
208
|
+
console.log('');
|
|
209
|
+
console.log('============================================================');
|
|
210
|
+
console.log(' Global node setup');
|
|
211
|
+
console.log('============================================================');
|
|
212
|
+
console.log('');
|
|
213
|
+
if (isWindows) {
|
|
214
|
+
console.log(' PowerShell (add to $PROFILE):');
|
|
215
|
+
console.log(' $env:PATH = "'.concat(nvuBinPath, ';$env:PATH"'));
|
|
216
|
+
console.log('');
|
|
217
|
+
console.log(' CMD (run as administrator):');
|
|
218
|
+
console.log(' setx PATH "'.concat(nvuBinPath, ';%PATH%"'));
|
|
219
|
+
} else {
|
|
220
|
+
console.log(' # For bash (~/.bashrc):');
|
|
221
|
+
console.log(' echo \'export PATH="$HOME/.nvu/bin:$PATH"\' >> ~/.bashrc');
|
|
222
|
+
console.log('');
|
|
223
|
+
console.log(' # For zsh (~/.zshrc):');
|
|
224
|
+
console.log(' echo \'export PATH="$HOME/.nvu/bin:$PATH"\' >> ~/.zshrc');
|
|
225
|
+
console.log('');
|
|
226
|
+
console.log(' # For fish (~/.config/fish/config.fish):');
|
|
227
|
+
console.log(" echo 'set -gx PATH $HOME/.nvu/bin $PATH' >> ~/.config/fish/config.fish");
|
|
228
|
+
}
|
|
229
|
+
console.log('');
|
|
230
|
+
console.log('Then restart your terminal or source your shell profile.');
|
|
231
|
+
console.log('');
|
|
232
|
+
console.log("Without this, 'nvu 18 npm test' still works - you just won't have");
|
|
233
|
+
console.log("transparent 'node' command override.");
|
|
234
|
+
console.log('============================================================');
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Main installation function
|
|
238
|
+
*/ module.exports.installBinaries = function installBinaries(options, callback) {
|
|
239
|
+
var archiveBaseName = getArchiveBaseName();
|
|
240
|
+
if (!archiveBaseName) {
|
|
241
|
+
callback(new Error('Unsupported platform/architecture for binary.'));
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
var extractedBinaryName = "".concat(archiveBaseName).concat(isWindows ? '.exe' : '');
|
|
245
|
+
var binDir = path.join(storagePath, 'bin');
|
|
246
|
+
// check if we need to upgrade
|
|
247
|
+
if (!options.force) {
|
|
248
|
+
try {
|
|
249
|
+
// already installed
|
|
250
|
+
if (fs.statSync(binDir)) {
|
|
251
|
+
if (fs.readFileSync(path.join(binDir, 'version.txt'), 'utf8') === BINARY_VERSION) {
|
|
252
|
+
callback(null, false);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
} catch (_err) {}
|
|
257
|
+
}
|
|
258
|
+
// Create directories
|
|
259
|
+
mkdirp.sync(storagePath);
|
|
260
|
+
mkdirp.sync(binDir);
|
|
261
|
+
var downloadUrl = "https://github.com/".concat(GITHUB_REPO, "/releases/download/binary-v").concat(BINARY_VERSION, "/").concat(archiveBaseName).concat(isWindows ? '.zip' : '.tar.gz');
|
|
262
|
+
var tempPath = path.join(tmpdir(), "nvu-binary-".concat(Date.now()).concat(isWindows ? '.zip' : '.tar.gz'));
|
|
263
|
+
console.log("Downloading binary for ".concat(process.platform, "-").concat(process.arch, "..."));
|
|
264
|
+
getFile(downloadUrl, tempPath, function(err) {
|
|
265
|
+
if (err) {
|
|
266
|
+
removeIfExistsSync(tempPath);
|
|
267
|
+
callback(new Error("No prebuilt binary available for ".concat(process.platform, "-").concat(process.arch, ". Download: ").concat(downloadUrl, ". Error: ").concat(err.message)));
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
console.log('Extracting binary...');
|
|
271
|
+
extractAndInstall(tempPath, binDir, extractedBinaryName, function(err) {
|
|
272
|
+
removeIfExistsSync(tempPath);
|
|
273
|
+
if (err) {
|
|
274
|
+
callback(err);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
// save binary version for upgrade checks
|
|
278
|
+
fs.writeFileSync(path.join(binDir, 'version.txt'), BINARY_VERSION, 'utf8');
|
|
279
|
+
console.log('Binary installed successfully!');
|
|
280
|
+
callback(null, true);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
/* 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; }
|
|
@@ -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,IAAMA,aAAaC,QAAQ;AAC3B,IAAMC,KAAKD,QAAQ;AACnB,IAAM,AAAEE,aAAeF,QAAQ,oBAAvBE;AACR,IAAMC,UAAUH,QAAQ;AACxB,IAAMI,SAASJ,QAAQ;AACvB,IAAMK,KAAKL,QAAQ;AACnB,IAAMM,OAAON,QAAQ;AACrB,IAAMO,QAAQP,QAAQ;AACtB,IAAMQ,aAAaR,QAAQ;AAE3B,IAAMS,OAAOD,WAAWE;AAExB,gBAAgB;AAChB,IAAMC,cAAc;AACpB,IAAMC,iBAAiBZ,QAAQM,KAAKO,IAAI,CAACJ,MAAM,iBAAiBK,aAAa;AAE7E,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAQ3F,IAAMC,aAAa,OAAOhB,GAAGiB,OAAO,KAAK;AACzC,SAASA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