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
|
@@ -9,416 +9,23 @@
|
|
|
9
9
|
* 1. Download to temp file
|
|
10
10
|
* 2. Extract to temp directory
|
|
11
11
|
* 3. Atomic rename to final location
|
|
12
|
-
*/ var
|
|
13
|
-
var
|
|
14
|
-
var fs = require('fs');
|
|
15
|
-
var mkdirp = require('mkdirp-classic');
|
|
16
|
-
var os = require('os');
|
|
17
|
-
var path = require('path');
|
|
18
|
-
var hasHomedir = typeof os.homedir === 'function';
|
|
19
|
-
function homedir() {
|
|
20
|
-
if (hasHomedir) {
|
|
21
|
-
return os.homedir();
|
|
22
|
-
}
|
|
23
|
-
var home = require('homedir-polyfill');
|
|
24
|
-
return home();
|
|
25
|
-
}
|
|
26
|
-
module.exports = {
|
|
27
|
-
homedir: homedir
|
|
28
|
-
};
|
|
29
|
-
// Configuration
|
|
30
|
-
var GITHUB_REPO = 'kmalakoff/node-version-use';
|
|
31
|
-
// Path is relative to dist/cjs/scripts/ at runtime
|
|
32
|
-
var BINARY_VERSION = require(path.join(__dirname, '..', 'package.json')).binaryVersion;
|
|
33
|
-
/**
|
|
34
|
-
* Get the platform-specific archive base name (without extension)
|
|
35
|
-
*/ function getArchiveBaseName() {
|
|
36
|
-
var platform = os.platform();
|
|
37
|
-
var arch = os.arch();
|
|
38
|
-
var platformMap = {
|
|
39
|
-
darwin: 'darwin',
|
|
40
|
-
linux: 'linux',
|
|
41
|
-
win32: 'win32'
|
|
42
|
-
};
|
|
43
|
-
var archMap = {
|
|
44
|
-
x64: 'x64',
|
|
45
|
-
arm64: 'arm64',
|
|
46
|
-
amd64: 'x64'
|
|
47
|
-
};
|
|
48
|
-
var platformName = platformMap[platform];
|
|
49
|
-
var archName = archMap[arch];
|
|
50
|
-
if (!platformName || !archName) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
return "nvu-binary-".concat(platformName, "-").concat(archName);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get the extracted binary name (includes .exe on Windows)
|
|
57
|
-
*/ function getExtractedBinaryName(archiveBaseName) {
|
|
58
|
-
var ext = os.platform() === 'win32' ? '.exe' : '';
|
|
59
|
-
return archiveBaseName + ext;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get the download URL for the binary archive
|
|
63
|
-
*/ function getDownloadUrl(archiveBaseName) {
|
|
64
|
-
var ext = os.platform() === 'win32' ? '.zip' : '.tar.gz';
|
|
65
|
-
return "https://github.com/".concat(GITHUB_REPO, "/releases/download/binary-v").concat(BINARY_VERSION, "/").concat(archiveBaseName).concat(ext);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Copy file
|
|
69
|
-
*/ function copyFileSync(src, dest) {
|
|
70
|
-
var content = fs.readFileSync(src);
|
|
71
|
-
fs.writeFileSync(dest, content);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Atomic rename with fallback to copy+delete for cross-device moves
|
|
75
|
-
*/ function atomicRename(src, dest, callback) {
|
|
76
|
-
fs.rename(src, dest, function(err) {
|
|
77
|
-
if (!err) {
|
|
78
|
-
callback(null);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
// Cross-device link error - fall back to copy + delete
|
|
82
|
-
if (err.code === 'EXDEV') {
|
|
83
|
-
try {
|
|
84
|
-
copyFileSync(src, dest);
|
|
85
|
-
fs.unlinkSync(src);
|
|
86
|
-
callback(null);
|
|
87
|
-
} catch (copyErr) {
|
|
88
|
-
callback(copyErr);
|
|
89
|
-
}
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
callback(err);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Remove directory recursively
|
|
97
|
-
*/ function rmRecursive(dir) {
|
|
98
|
-
if (!fs.existsSync(dir)) return;
|
|
99
|
-
var files = fs.readdirSync(dir);
|
|
100
|
-
for(var i = 0; i < files.length; i++){
|
|
101
|
-
var filePath = path.join(dir, files[i]);
|
|
102
|
-
var stat = fs.statSync(filePath);
|
|
103
|
-
if (stat.isDirectory()) {
|
|
104
|
-
rmRecursive(filePath);
|
|
105
|
-
} else {
|
|
106
|
-
fs.unlinkSync(filePath);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
fs.rmdirSync(dir);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Get temp directory
|
|
113
|
-
*/ function getTmpDir() {
|
|
114
|
-
return typeof os.tmpdir === 'function' ? os.tmpdir() : process.env.TMPDIR || process.env.TMP || process.env.TEMP || '/tmp';
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Download using curl (macOS, Linux, Windows 10+)
|
|
118
|
-
*/ function downloadWithCurl(downloadUrl, destPath, callback) {
|
|
119
|
-
var curl = spawn('curl', [
|
|
120
|
-
'-L',
|
|
121
|
-
'-f',
|
|
122
|
-
'-s',
|
|
123
|
-
'-o',
|
|
124
|
-
destPath,
|
|
125
|
-
downloadUrl
|
|
126
|
-
]);
|
|
127
|
-
curl.on('close', function(code) {
|
|
128
|
-
if (code !== 0) {
|
|
129
|
-
// curl exit codes: 22 = HTTP error (4xx/5xx), 56 = receive error (often 404 with -f)
|
|
130
|
-
if (code === 22 || code === 56) {
|
|
131
|
-
callback(new Error('HTTP 404'));
|
|
132
|
-
} else {
|
|
133
|
-
callback(new Error("curl failed with exit code ".concat(code)));
|
|
134
|
-
}
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
callback(null);
|
|
138
|
-
});
|
|
139
|
-
curl.on('error', function(err) {
|
|
140
|
-
callback(err);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Download using PowerShell (Windows 7+ fallback)
|
|
145
|
-
*/ function downloadWithPowerShell(downloadUrl, destPath, callback) {
|
|
146
|
-
var psCommand = 'Invoke-WebRequest -Uri "'.concat(downloadUrl, '" -OutFile "').concat(destPath, '" -UseBasicParsing');
|
|
147
|
-
var ps = spawn('powershell', [
|
|
148
|
-
'-NoProfile',
|
|
149
|
-
'-Command',
|
|
150
|
-
psCommand
|
|
151
|
-
]);
|
|
152
|
-
ps.on('close', function(code) {
|
|
153
|
-
if (code !== 0) {
|
|
154
|
-
callback(new Error("PowerShell download failed with exit code ".concat(code)));
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
callback(null);
|
|
158
|
-
});
|
|
159
|
-
ps.on('error', function(err) {
|
|
160
|
-
callback(err);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Download a file - tries curl first, falls back to PowerShell on Windows
|
|
165
|
-
* Node 0.8's OpenSSL doesn't support TLS 1.2+ required by GitHub
|
|
166
|
-
*/ function downloadFile(downloadUrl, destPath, callback) {
|
|
167
|
-
downloadWithCurl(downloadUrl, destPath, function(err) {
|
|
168
|
-
var _err_message;
|
|
169
|
-
if (!err) {
|
|
170
|
-
callback(null);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
// If curl failed and we're on Windows, try PowerShell
|
|
174
|
-
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) {
|
|
175
|
-
downloadWithPowerShell(downloadUrl, destPath, callback);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
callback(err);
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Extract archive to a directory (callback-based)
|
|
183
|
-
*/ function extractArchive(archivePath, destDir, callback) {
|
|
184
|
-
var platform = os.platform();
|
|
185
|
-
if (platform === 'win32') {
|
|
186
|
-
// Windows: extract zip using PowerShell
|
|
187
|
-
var ps = spawn('powershell', [
|
|
188
|
-
'-Command',
|
|
189
|
-
"Expand-Archive -Path '".concat(archivePath, "' -DestinationPath '").concat(destDir, "' -Force")
|
|
190
|
-
]);
|
|
191
|
-
ps.on('close', function(code) {
|
|
192
|
-
if (code !== 0) {
|
|
193
|
-
callback(new Error('Failed to extract archive'));
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
callback(null);
|
|
197
|
-
});
|
|
198
|
-
} else {
|
|
199
|
-
// Unix: extract tar.gz
|
|
200
|
-
var tar = spawn('tar', [
|
|
201
|
-
'-xzf',
|
|
202
|
-
archivePath,
|
|
203
|
-
'-C',
|
|
204
|
-
destDir
|
|
205
|
-
]);
|
|
206
|
-
tar.on('close', function(code) {
|
|
207
|
-
if (code !== 0) {
|
|
208
|
-
callback(new Error('Failed to extract archive'));
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
callback(null);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Install binaries using atomic rename pattern
|
|
217
|
-
* 1. Extract to temp directory
|
|
218
|
-
* 2. Copy binary to temp files in destination directory
|
|
219
|
-
* 3. Atomic rename temp files to final names
|
|
220
|
-
*/ function extractAndInstall(archivePath, destDir, binaryName, callback) {
|
|
221
|
-
var platform = os.platform();
|
|
222
|
-
var isWindows = platform === 'win32';
|
|
223
|
-
var ext = isWindows ? '.exe' : '';
|
|
224
|
-
// Create temp extraction directory
|
|
225
|
-
var tempExtractDir = path.join(getTmpDir(), "nvu-extract-".concat(Date.now()));
|
|
226
|
-
mkdirp.sync(tempExtractDir);
|
|
227
|
-
extractArchive(archivePath, tempExtractDir, function(extractErr) {
|
|
228
|
-
if (extractErr) {
|
|
229
|
-
rmRecursive(tempExtractDir);
|
|
230
|
-
callback(extractErr);
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
var extractedPath = path.join(tempExtractDir, binaryName);
|
|
234
|
-
if (!fs.existsSync(extractedPath)) {
|
|
235
|
-
rmRecursive(tempExtractDir);
|
|
236
|
-
callback(new Error("Extracted binary not found: ".concat(binaryName)));
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
// Binary names to install
|
|
240
|
-
var binaries = [
|
|
241
|
-
'node',
|
|
242
|
-
'npm',
|
|
243
|
-
'npx',
|
|
244
|
-
'corepack'
|
|
245
|
-
];
|
|
246
|
-
var timestamp = Date.now();
|
|
247
|
-
var installError = null;
|
|
248
|
-
// Step 1: Copy extracted binary to temp files in destination directory
|
|
249
|
-
// This ensures the temp files are on the same filesystem for atomic rename
|
|
250
|
-
for(var i = 0; i < binaries.length; i++){
|
|
251
|
-
var name = binaries[i];
|
|
252
|
-
var tempDest = path.join(destDir, "".concat(name, ".tmp-").concat(timestamp).concat(ext));
|
|
253
|
-
try {
|
|
254
|
-
// Copy to temp file in destination directory
|
|
255
|
-
copyFileSync(extractedPath, tempDest);
|
|
256
|
-
// Set permissions on Unix
|
|
257
|
-
if (!isWindows) {
|
|
258
|
-
fs.chmodSync(tempDest, 493);
|
|
259
|
-
}
|
|
260
|
-
} catch (err) {
|
|
261
|
-
installError = err;
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
if (installError) {
|
|
266
|
-
// Clean up any temp files we created
|
|
267
|
-
for(var j = 0; j < binaries.length; j++){
|
|
268
|
-
var tempPath = path.join(destDir, "".concat(binaries[j], ".tmp-").concat(timestamp).concat(ext));
|
|
269
|
-
if (fs.existsSync(tempPath)) {
|
|
270
|
-
try {
|
|
271
|
-
fs.unlinkSync(tempPath);
|
|
272
|
-
} catch (_e) {
|
|
273
|
-
// ignore cleanup errors
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
rmRecursive(tempExtractDir);
|
|
278
|
-
callback(installError);
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
// Step 2: Atomic rename temp files to final names
|
|
282
|
-
var renameError = null;
|
|
283
|
-
function doRename(index) {
|
|
284
|
-
if (index >= binaries.length) {
|
|
285
|
-
// All renames complete
|
|
286
|
-
rmRecursive(tempExtractDir);
|
|
287
|
-
callback(renameError);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
var name = binaries[index];
|
|
291
|
-
var tempDest = path.join(destDir, "".concat(name, ".tmp-").concat(timestamp).concat(ext));
|
|
292
|
-
var finalDest = path.join(destDir, "".concat(name).concat(ext));
|
|
293
|
-
// Remove existing file if present (for atomic replacement)
|
|
294
|
-
if (fs.existsSync(finalDest)) {
|
|
295
|
-
try {
|
|
296
|
-
fs.unlinkSync(finalDest);
|
|
297
|
-
} catch (_e) {
|
|
298
|
-
// ignore cleanup errors
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
atomicRename(tempDest, finalDest, function(err) {
|
|
302
|
-
if (err && !renameError) {
|
|
303
|
-
renameError = err;
|
|
304
|
-
}
|
|
305
|
-
doRename(index + 1);
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
doRename(0);
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Print setup instructions
|
|
313
|
-
*/ function printInstructions(installed) {
|
|
314
|
-
var homedirPath = homedir();
|
|
315
|
-
var nvuBinPath = path.join(homedirPath, '.nvu', 'bin');
|
|
316
|
-
var platform = os.platform();
|
|
317
|
-
console.log('');
|
|
318
|
-
console.log('============================================================');
|
|
319
|
-
if (installed) {
|
|
320
|
-
console.log(' nvu binaries installed to ~/.nvu/bin/');
|
|
321
|
-
} else {
|
|
322
|
-
console.log(' nvu installed (binaries not yet available)');
|
|
323
|
-
}
|
|
324
|
-
console.log('============================================================');
|
|
325
|
-
console.log('');
|
|
326
|
-
console.log('To enable transparent Node version switching, add to your shell profile:');
|
|
327
|
-
console.log('');
|
|
328
|
-
if (platform === 'win32') {
|
|
329
|
-
console.log(' PowerShell (add to $PROFILE):');
|
|
330
|
-
console.log(' $env:PATH = "'.concat(nvuBinPath, ';$env:PATH"'));
|
|
331
|
-
console.log('');
|
|
332
|
-
console.log(' CMD (run as administrator):');
|
|
333
|
-
console.log(' setx PATH "'.concat(nvuBinPath, ';%PATH%"'));
|
|
334
|
-
} else {
|
|
335
|
-
console.log(' # For bash (~/.bashrc):');
|
|
336
|
-
console.log(' export PATH="$HOME/.nvu/bin:$PATH"');
|
|
337
|
-
console.log('');
|
|
338
|
-
console.log(' # For zsh (~/.zshrc):');
|
|
339
|
-
console.log(' export PATH="$HOME/.nvu/bin:$PATH"');
|
|
340
|
-
console.log('');
|
|
341
|
-
console.log(' # For fish (~/.config/fish/config.fish):');
|
|
342
|
-
console.log(' set -gx PATH $HOME/.nvu/bin $PATH');
|
|
343
|
-
}
|
|
344
|
-
console.log('');
|
|
345
|
-
console.log('Then restart your terminal or source your shell profile.');
|
|
346
|
-
console.log('');
|
|
347
|
-
console.log("Without this, 'nvu 18 npm test' still works - you just won't have");
|
|
348
|
-
console.log("transparent 'node' command override.");
|
|
349
|
-
console.log('============================================================');
|
|
350
|
-
}
|
|
12
|
+
*/ var exit = require('exit-compat');
|
|
13
|
+
var _require = require('./installBinaries.cjs'), installBinaries = _require.installBinaries, printInstructions = _require.printInstructions;
|
|
351
14
|
/**
|
|
352
15
|
* Main installation function
|
|
353
16
|
*/ function main() {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
exit(0);
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
var extractedBinaryName = getExtractedBinaryName(archiveBaseName);
|
|
363
|
-
var homedirPath = homedir();
|
|
364
|
-
var nvuDir = path.join(homedirPath, '.nvu');
|
|
365
|
-
var binDir = path.join(nvuDir, 'bin');
|
|
366
|
-
// Create directories
|
|
367
|
-
mkdirp.sync(nvuDir);
|
|
368
|
-
mkdirp.sync(binDir);
|
|
369
|
-
var downloadUrl = getDownloadUrl(archiveBaseName);
|
|
370
|
-
var ext = os.platform() === 'win32' ? '.zip' : '.tar.gz';
|
|
371
|
-
var tempPath = path.join(getTmpDir(), "nvu-binary-".concat(Date.now()).concat(ext));
|
|
372
|
-
console.log("postinstall: Downloading binary for ".concat(os.platform(), "-").concat(os.arch(), "..."));
|
|
373
|
-
downloadFile(downloadUrl, tempPath, function(downloadErr) {
|
|
374
|
-
if (downloadErr) {
|
|
375
|
-
var _downloadErr_message;
|
|
376
|
-
// Clean up temp file if it exists
|
|
377
|
-
if (fs.existsSync(tempPath)) {
|
|
378
|
-
try {
|
|
379
|
-
fs.unlinkSync(tempPath);
|
|
380
|
-
} catch (_e) {
|
|
381
|
-
// ignore cleanup errors
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
if (((_downloadErr_message = downloadErr.message) === null || _downloadErr_message === void 0 ? void 0 : _downloadErr_message.indexOf('404')) >= 0) {
|
|
385
|
-
console.log('postinstall: Binaries not yet published to GitHub releases.');
|
|
386
|
-
console.log('');
|
|
387
|
-
console.log('To build and install binaries locally:');
|
|
388
|
-
console.log(' cd node_modules/node-version-use/binary');
|
|
389
|
-
console.log(' make install');
|
|
390
|
-
console.log('');
|
|
391
|
-
console.log('Or wait for the next release which will include pre-built binaries.');
|
|
392
|
-
} else {
|
|
393
|
-
console.log("postinstall warning: Failed to install binary: ".concat(downloadErr.message || downloadErr));
|
|
394
|
-
console.log('You can still use nvu with explicit versions: nvu 18 npm test');
|
|
395
|
-
console.log('To install binaries manually: cd node_modules/node-version-use/binary && make install');
|
|
396
|
-
}
|
|
397
|
-
printInstructions(false);
|
|
398
|
-
exit(0);
|
|
17
|
+
installBinaries({}, function(err, installed) {
|
|
18
|
+
if (err) {
|
|
19
|
+
console.log("postinstall warning: Failed to install binary: ".concat(err.message || err));
|
|
20
|
+
console.log('You can still use nvu with explicit versions: nvu 18 npm test');
|
|
21
|
+
exit(1);
|
|
399
22
|
return;
|
|
400
23
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
// Clean up temp file
|
|
404
|
-
if (fs.existsSync(tempPath)) {
|
|
405
|
-
try {
|
|
406
|
-
fs.unlinkSync(tempPath);
|
|
407
|
-
} catch (_e) {
|
|
408
|
-
// ignore cleanup errors
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
if (extractErr) {
|
|
412
|
-
console.log("postinstall warning: Failed to extract binary: ".concat(extractErr.message || extractErr));
|
|
413
|
-
console.log('You can still use nvu with explicit versions: nvu 18 npm test');
|
|
414
|
-
printInstructions(false);
|
|
415
|
-
exit(0);
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
24
|
+
if (installed) {
|
|
25
|
+
printInstructions();
|
|
418
26
|
console.log('postinstall: Binary installed successfully!');
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
});
|
|
27
|
+
}
|
|
28
|
+
exit(0);
|
|
422
29
|
});
|
|
423
30
|
}
|
|
424
31
|
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,IAAM,AAAEA,QAAUC,QAAQ,iBAAlBD;AACR,IAAME,OAAOD,QAAQ;AACrB,IAAME,KAAKF,QAAQ;AACnB,IAAMG,SAASH,QAAQ;AACvB,IAAMI,KAAKJ,QAAQ;AACnB,IAAMK,OAAOL,QAAQ;AAErB,IAAMM,aAAa,OAAOF,GAAGG,OAAO,KAAK;AACzC,SAASA;IACP,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,CAAC,AAAC,kDAAoF,OAAnCK,YAAYtC,OAAO,IAAIsC;gBACrFN,QAAQC,GAAG,CAAC;gBACZD,QAAQC,GAAG,CAAC;YACd;YACAL,kBAAkB;YAClBtG,KAAK;YACL;QACF;QAEA0G,QAAQC,GAAG,CAAC;QAEZ3B,kBAAkBgB,UAAUe,QAAQF,qBAAqB,SAACtB;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,AAAC,kDAAkF,OAAjCpB,WAAWb,OAAO,IAAIa;gBACpFmB,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,IAAMA,OAAOC,QAAQ;AACrB,IAA+CA,WAAAA,QAAQ,0BAA/CC,kBAAuCD,SAAvCC,iBAAiBC,oBAAsBF,SAAtBE;AAEzB;;CAEC,GACD,SAASC;IACPF,gBAAgB,CAAC,GAAG,SAACG,KAAKC;QACxB,IAAID,KAAK;YACPE,QAAQC,GAAG,CAAC,AAAC,kDAAoE,OAAnBH,IAAII,OAAO,IAAIJ;YAC7EE,QAAQC,GAAG,CAAC;YACZR,KAAK;YACL;QACF;QAEA,IAAIM,WAAW;YACbH;YACAI,QAAQC,GAAG,CAAC;QACd;QACAR,KAAK;IACP;AACF;AAEAI"}
|
|
@@ -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":["defaultCmd","args","defaultFilePath","path","join","storagePath","versionsPath","length","fs","existsSync","currentVersion","readFileSync","trim","console","log","exit","version","indexOf","mkdirpSync","matches","findInstalledVersions","setDefaultToExact","autoInstallAndSetDefault","exactVersion","writeFileSync","loadNodeVersionInstall","err","nodeVersionInstall","error","message","installPath","installErr","results","installedVersion"],"mappings":";;;;+BAQA;;;;;CAKC,GACD;;;eAAwBA;;;iEAdP;yDACF;2DACE;wBACU;2BACC;uCACU;+EACH;;;;;;AAQpB,SAASA,WAAWC,IAAc;IAC/C,IAAMC,kBAAkBC,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAC/C,IAAMC,eAAeH,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAE5C,kDAAkD;IAClD,IAAIJ,KAAKM,MAAM,KAAK,GAAG;QACrB,IAAIC,WAAE,CAACC,UAAU,CAACP,kBAAkB;YAClC,IAAMQ,iBAAiBF,WAAE,CAACG,YAAY,CAACT,iBAAiB,QAAQU,IAAI;YACpEC,QAAQC,GAAG,CAAC,AAAC,oBAAkC,OAAfJ;QAClC,OAAO;YACLG,QAAQC,GAAG,CAAC;YACZD,QAAQC,GAAG,CAAC;QACd;QACAC,IAAAA,mBAAI,EAAC;QACL;IACF;IAEA,IAAMC,UAAUf,IAAI,CAAC,EAAE,CAACW,IAAI;IAE5B,sEAAsE;IACtE,IAAI,CAACI,WAAWA,QAAQC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AY;gBACdlB,QAAQe,KAAK,CAAC,AAAC,0BAAiC,OAARZ,SAAQ,MAAIe,WAAWF,OAAO;gBACtEd,IAAAA,mBAAI,EAAC;gBACL;YACF;YAEA,yCAAyC;YACzC,IAAIkB;YACJ,IAAID,WAAWA,QAAQzB,MAAM,GAAG,GAAG;gBACjC0B,mBAAmBD,OAAO,CAAC,EAAE,CAAChB,OAAO;YACvC,OAAO;gBACL,uCAAuC;gBACvC,IAAMG,UAAUC,IAAAA,8CAAqB,EAACd,cAAcU;gBACpD,IAAIG,QAAQZ,MAAM,KAAK,GAAG;oBACxBM,QAAQe,KAAK,CAAC;oBACdb,IAAAA,mBAAI,EAAC;oBACL;gBACF;gBACAkB,mBAAmBd,OAAO,CAACA,QAAQZ,MAAM,GAAG,EAAE;YAChD;YAEA,yCAAyC;YACzC,IAAI0B,iBAAiBhB,OAAO,CAAC,SAAS,GAAG;gBACvCgB,mBAAmB,AAAC,IAAoB,OAAjBA;YACzB;YAEA,0BAA0B;YAC1BzB,WAAE,CAACgB,aAAa,CAACtB,iBAAiB,AAAC,GAAmB,OAAjB+B,kBAAiB,OAAK;YAC3DpB,QAAQC,GAAG,CAAC,AAAC,QAAwB,OAAjBmB,kBAAiB;YACrCpB,QAAQC,GAAG,CAAC,AAAC,gCAAgD,OAAjBmB;YAE5ClB,IAAAA,mBAAI,EAAC;QACP;IAEJ;AACF"}
|
|
@@ -47,8 +47,7 @@ function isCommand(name) {
|
|
|
47
47
|
}
|
|
48
48
|
function runCommand(name, args) {
|
|
49
49
|
var cmd = commands[name];
|
|
50
|
-
if (cmd)
|
|
51
|
-
|
|
52
|
-
}
|
|
50
|
+
if (cmd) cmd(args);
|
|
51
|
+
else console.error("Unknown command: ".concat(name));
|
|
53
52
|
}
|
|
54
53
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/index.ts"],"sourcesContent":["import defaultCmd from './default.ts';\nimport installCmd from './install.ts';\nimport listCmd from './list.ts';\nimport localCmd from './local.ts';\nimport setupCmd from './setup.ts';\nimport teardownCmd from './teardown.ts';\nimport uninstallCmd from './uninstall.ts';\nimport whichCmd from './which.ts';\n\nexport const commands: Record<string, (args: string[]) => void> = {\n default: defaultCmd,\n local: localCmd,\n list: listCmd,\n which: whichCmd,\n install: installCmd,\n uninstall: uninstallCmd,\n setup: setupCmd,\n teardown: teardownCmd,\n};\n\nexport function isCommand(name: string): boolean {\n return name in commands;\n}\n\nexport function runCommand(name: string, args: string[]): void {\n const cmd = commands[name];\n if (cmd)
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/index.ts"],"sourcesContent":["import defaultCmd from './default.ts';\nimport installCmd from './install.ts';\nimport listCmd from './list.ts';\nimport localCmd from './local.ts';\nimport setupCmd from './setup.ts';\nimport teardownCmd from './teardown.ts';\nimport uninstallCmd from './uninstall.ts';\nimport whichCmd from './which.ts';\n\nexport const commands: Record<string, (args: string[]) => void> = {\n default: defaultCmd,\n local: localCmd,\n list: listCmd,\n which: whichCmd,\n install: installCmd,\n uninstall: uninstallCmd,\n setup: setupCmd,\n teardown: teardownCmd,\n};\n\nexport function isCommand(name: string): boolean {\n return name in commands;\n}\n\nexport function runCommand(name: string, args: string[]): void {\n const cmd = commands[name];\n if (cmd) cmd(args);\n else console.error(`Unknown command: ${name}`);\n}\n"],"names":["commands","isCommand","runCommand","default","defaultCmd","local","localCmd","list","listCmd","which","whichCmd","install","installCmd","uninstall","uninstallCmd","setup","setupCmd","teardown","teardownCmd","name","args","cmd","console","error"],"mappings":";;;;;;;;;;;QASaA;eAAAA;;QAWGC;eAAAA;;QAIAC;eAAAA;;;gEAxBO;gEACA;6DACH;8DACC;8DACA;iEACG;kEACC;8DACJ;;;;;;AAEd,IAAMF,WAAqD;IAChEG,SAASC,kBAAU;IACnBC,OAAOC,gBAAQ;IACfC,MAAMC,eAAO;IACbC,OAAOC,gBAAQ;IACfC,SAASC,kBAAU;IACnBC,WAAWC,oBAAY;IACvBC,OAAOC,gBAAQ;IACfC,UAAUC,mBAAW;AACvB;AAEO,SAASjB,UAAUkB,IAAY;IACpC,OAAOA,QAAQnB;AACjB;AAEO,SAASE,WAAWiB,IAAY,EAAEC,IAAc;IACrD,IAAMC,MAAMrB,QAAQ,CAACmB,KAAK;IAC1B,IAAIE,KAAKA,IAAID;SACRE,QAAQC,KAAK,CAAC,AAAC,oBAAwB,OAALJ;AACzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/list.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { readdirWithTypes } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu list\n *\n * List all installed Node versions.\n */\nexport default function listCmd(_args: string[]): void {\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/list.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport path from 'path';\nimport { readdirWithTypes } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu list\n *\n * List all installed Node versions.\n */\nexport default function listCmd(_args: string[]): void {\n const versionsPath = path.join(storagePath, 'installed');\n\n // Check if versions directory exists\n if (!fs.existsSync(versionsPath)) {\n console.log('No Node versions installed.');\n console.log('Install a version: nvu install <version>');\n exit(0);\n return;\n }\n\n // Read all directories in versions folder\n const entries = readdirWithTypes(versionsPath);\n const versions = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);\n\n if (versions.length === 0) {\n console.log('No Node versions installed.');\n console.log('Install a version: nvu install <version>');\n exit(0);\n return;\n }\n\n // Get the current default\n const defaultFilePath = path.join(storagePath, 'default');\n let defaultVersion = '';\n if (fs.existsSync(defaultFilePath)) {\n defaultVersion = fs.readFileSync(defaultFilePath, 'utf8').trim();\n }\n\n // Sort versions (simple string sort, could be improved with semver)\n versions.sort((a, b) => {\n const aParts = a.split('.').map((n) => parseInt(n, 10) || 0);\n const bParts = b.split('.').map((n) => parseInt(n, 10) || 0);\n for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {\n const aVal = aParts[i] || 0;\n const bVal = bParts[i] || 0;\n if (aVal !== bVal) return bVal - aVal; // Descending order\n }\n return 0;\n });\n\n console.log('Installed Node versions:');\n for (let i = 0; i < versions.length; i++) {\n const version = versions[i];\n const isDefault = version === defaultVersion || `v${version}` === defaultVersion || version === `v${defaultVersion}`;\n const marker = isDefault ? ' (default)' : '';\n console.log(` ${version}${marker}`);\n }\n exit(0);\n}\n"],"names":["listCmd","_args","versionsPath","path","join","storagePath","fs","existsSync","console","log","exit","entries","readdirWithTypes","versions","filter","entry","isDirectory","map","name","length","defaultFilePath","defaultVersion","readFileSync","trim","sort","a","b","aParts","split","n","parseInt","bParts","i","Math","max","aVal","bVal","version","isDefault","marker"],"mappings":";;;;+BAMA;;;;CAIC,GACD;;;eAAwBA;;;iEAXP;yDACF;2DACE;wBACgB;2BACL;;;;;;AAOb,SAASA,QAAQC,KAAe;IAC7C,IAAMC,eAAeC,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAE5C,qCAAqC;IACrC,IAAI,CAACC,WAAE,CAACC,UAAU,CAACL,eAAe;QAChCM,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;QACZC,IAAAA,mBAAI,EAAC;QACL;IACF;IAEA,0CAA0C;IAC1C,IAAMC,UAAUC,IAAAA,0BAAgB,EAACV;IACjC,IAAMW,WAAWF,QAAQG,MAAM,CAAC,SAACC;eAAUA,MAAMC,WAAW;OAAIC,GAAG,CAAC,SAACF;eAAUA,MAAMG,IAAI;;IAEzF,IAAIL,SAASM,M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