node-version-use 2.1.4 → 2.1.6

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.
Files changed (34) hide show
  1. package/{dist/cjs/scripts/postinstall.js → assets/postinstall.cjs} +73 -76
  2. package/dist/cjs/assets/postinstall.cjs +425 -0
  3. package/dist/cjs/assets/postinstall.cjs.map +1 -0
  4. package/dist/cjs/commands/default.js.map +1 -1
  5. package/dist/cjs/commands/list.js.map +1 -1
  6. package/dist/cjs/commands/setup.js.map +1 -1
  7. package/dist/cjs/commands/uninstall.js.map +1 -1
  8. package/dist/cjs/commands/which.js.map +1 -1
  9. package/dist/cjs/compat.js.map +1 -1
  10. package/dist/cjs/lib/findInstalledVersions.js.map +1 -1
  11. package/dist/esm/{scripts/postinstall.js → assets/postinstall.cjs} +18 -13
  12. package/dist/esm/assets/postinstall.cjs.map +1 -0
  13. package/dist/esm/commands/default.js +8 -8
  14. package/dist/esm/commands/default.js.map +1 -1
  15. package/dist/esm/commands/list.js +3 -3
  16. package/dist/esm/commands/list.js.map +1 -1
  17. package/dist/esm/commands/setup.js +20 -20
  18. package/dist/esm/commands/setup.js.map +1 -1
  19. package/dist/esm/commands/uninstall.js +12 -12
  20. package/dist/esm/commands/uninstall.js.map +1 -1
  21. package/dist/esm/commands/which.js +5 -5
  22. package/dist/esm/commands/which.js.map +1 -1
  23. package/dist/esm/compat.js +10 -10
  24. package/dist/esm/compat.js.map +1 -1
  25. package/dist/esm/lib/findInstalledVersions.js +19 -19
  26. package/dist/esm/lib/findInstalledVersions.js.map +1 -1
  27. package/package.json +19 -19
  28. package/dist/cjs/scripts/postinstall.js.map +0 -1
  29. package/dist/esm/scripts/postinstall.d.ts +0 -12
  30. package/dist/esm/scripts/postinstall.js.map +0 -1
  31. package/scripts/ensure-test-binaries.ts +0 -27
  32. package/scripts/postinstall.cjs +0 -9
  33. /package/dist/cjs/{scripts → assets}/postinstall.d.cts +0 -0
  34. /package/dist/{cjs/scripts/postinstall.d.ts → esm/assets/postinstall.d.cts} +0 -0
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * Postinstall script for node-version-use
3
4
  *
@@ -8,36 +9,32 @@
8
9
  * 1. Download to temp file
9
10
  * 2. Extract to temp directory
10
11
  * 3. Atomic rename to final location
11
- */ "use strict";
12
- Object.defineProperty(exports, "__esModule", {
13
- value: true
14
- });
15
- var _child_process = require("child_process");
16
- var _exitcompat = /*#__PURE__*/ _interop_require_default(require("exit-compat"));
17
- var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
18
- var _mkdirpclassic = /*#__PURE__*/ _interop_require_default(require("mkdirp-classic"));
19
- var _module = /*#__PURE__*/ _interop_require_default(require("module"));
20
- var _os = /*#__PURE__*/ _interop_require_default(require("os"));
21
- var _path = /*#__PURE__*/ _interop_require_default(require("path"));
22
- var _url = /*#__PURE__*/ _interop_require_default(require("url"));
23
- var _compatts = require("../compat.js");
24
- function _interop_require_default(obj) {
25
- return obj && obj.__esModule ? obj : {
26
- default: obj
27
- };
12
+ */ var spawn = require('child_process').spawn;
13
+ var exit = require('exit-compat');
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();
28
25
  }
29
- // CJS/ESM compatibility
30
- var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
31
- var __dirname = _path.default.dirname(typeof __filename !== 'undefined' ? __filename : _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()));
26
+ module.exports = {
27
+ homedir: homedir
28
+ };
32
29
  // Configuration
33
30
  var GITHUB_REPO = 'kmalakoff/node-version-use';
34
31
  // Path is relative to dist/cjs/scripts/ at runtime
35
- var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'package.json')).binaryVersion;
32
+ var BINARY_VERSION = require(path.join(__dirname, '..', 'package.json')).binaryVersion;
36
33
  /**
37
34
  * Get the platform-specific archive base name (without extension)
38
35
  */ function getArchiveBaseName() {
39
- var platform = _os.default.platform();
40
- var arch = _os.default.arch();
36
+ var platform = os.platform();
37
+ var arch = os.arch();
41
38
  var platformMap = {
42
39
  darwin: 'darwin',
43
40
  linux: 'linux',
@@ -58,25 +55,25 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
58
55
  /**
59
56
  * Get the extracted binary name (includes .exe on Windows)
60
57
  */ function getExtractedBinaryName(archiveBaseName) {
61
- var ext = _os.default.platform() === 'win32' ? '.exe' : '';
58
+ var ext = os.platform() === 'win32' ? '.exe' : '';
62
59
  return archiveBaseName + ext;
63
60
  }
64
61
  /**
65
62
  * Get the download URL for the binary archive
66
63
  */ function getDownloadUrl(archiveBaseName) {
67
- var ext = _os.default.platform() === 'win32' ? '.zip' : '.tar.gz';
64
+ var ext = os.platform() === 'win32' ? '.zip' : '.tar.gz';
68
65
  return "https://github.com/".concat(GITHUB_REPO, "/releases/download/binary-v").concat(BINARY_VERSION, "/").concat(archiveBaseName).concat(ext);
69
66
  }
70
67
  /**
71
68
  * Copy file
72
69
  */ function copyFileSync(src, dest) {
73
- var content = _fs.default.readFileSync(src);
74
- _fs.default.writeFileSync(dest, content);
70
+ var content = fs.readFileSync(src);
71
+ fs.writeFileSync(dest, content);
75
72
  }
76
73
  /**
77
74
  * Atomic rename with fallback to copy+delete for cross-device moves
78
75
  */ function atomicRename(src, dest, callback) {
79
- _fs.default.rename(src, dest, function(err) {
76
+ fs.rename(src, dest, function(err) {
80
77
  if (!err) {
81
78
  callback(null);
82
79
  return;
@@ -85,7 +82,7 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
85
82
  if (err.code === 'EXDEV') {
86
83
  try {
87
84
  copyFileSync(src, dest);
88
- _fs.default.unlinkSync(src);
85
+ fs.unlinkSync(src);
89
86
  callback(null);
90
87
  } catch (copyErr) {
91
88
  callback(copyErr);
@@ -98,28 +95,28 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
98
95
  /**
99
96
  * Remove directory recursively
100
97
  */ function rmRecursive(dir) {
101
- if (!_fs.default.existsSync(dir)) return;
102
- var files = _fs.default.readdirSync(dir);
98
+ if (!fs.existsSync(dir)) return;
99
+ var files = fs.readdirSync(dir);
103
100
  for(var i = 0; i < files.length; i++){
104
- var filePath = _path.default.join(dir, files[i]);
105
- var stat = _fs.default.statSync(filePath);
101
+ var filePath = path.join(dir, files[i]);
102
+ var stat = fs.statSync(filePath);
106
103
  if (stat.isDirectory()) {
107
104
  rmRecursive(filePath);
108
105
  } else {
109
- _fs.default.unlinkSync(filePath);
106
+ fs.unlinkSync(filePath);
110
107
  }
111
108
  }
112
- _fs.default.rmdirSync(dir);
109
+ fs.rmdirSync(dir);
113
110
  }
114
111
  /**
115
112
  * Get temp directory
116
113
  */ function getTmpDir() {
117
- return typeof _os.default.tmpdir === 'function' ? _os.default.tmpdir() : process.env.TMPDIR || process.env.TMP || process.env.TEMP || '/tmp';
114
+ return typeof os.tmpdir === 'function' ? os.tmpdir() : process.env.TMPDIR || process.env.TMP || process.env.TEMP || '/tmp';
118
115
  }
119
116
  /**
120
117
  * Download using curl (macOS, Linux, Windows 10+)
121
118
  */ function downloadWithCurl(downloadUrl, destPath, callback) {
122
- var curl = (0, _child_process.spawn)('curl', [
119
+ var curl = spawn('curl', [
123
120
  '-L',
124
121
  '-f',
125
122
  '-s',
@@ -147,7 +144,7 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
147
144
  * Download using PowerShell (Windows 7+ fallback)
148
145
  */ function downloadWithPowerShell(downloadUrl, destPath, callback) {
149
146
  var psCommand = 'Invoke-WebRequest -Uri "'.concat(downloadUrl, '" -OutFile "').concat(destPath, '" -UseBasicParsing');
150
- var ps = (0, _child_process.spawn)('powershell', [
147
+ var ps = spawn('powershell', [
151
148
  '-NoProfile',
152
149
  '-Command',
153
150
  psCommand
@@ -174,7 +171,7 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
174
171
  return;
175
172
  }
176
173
  // If curl failed and we're on Windows, try PowerShell
177
- if (_os.default.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
+ 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) {
178
175
  downloadWithPowerShell(downloadUrl, destPath, callback);
179
176
  return;
180
177
  }
@@ -184,10 +181,10 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
184
181
  /**
185
182
  * Extract archive to a directory (callback-based)
186
183
  */ function extractArchive(archivePath, destDir, callback) {
187
- var platform = _os.default.platform();
184
+ var platform = os.platform();
188
185
  if (platform === 'win32') {
189
186
  // Windows: extract zip using PowerShell
190
- var ps = (0, _child_process.spawn)('powershell', [
187
+ var ps = spawn('powershell', [
191
188
  '-Command',
192
189
  "Expand-Archive -Path '".concat(archivePath, "' -DestinationPath '").concat(destDir, "' -Force")
193
190
  ]);
@@ -200,7 +197,7 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
200
197
  });
201
198
  } else {
202
199
  // Unix: extract tar.gz
203
- var tar = (0, _child_process.spawn)('tar', [
200
+ var tar = spawn('tar', [
204
201
  '-xzf',
205
202
  archivePath,
206
203
  '-C',
@@ -221,20 +218,20 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
221
218
  * 2. Copy binary to temp files in destination directory
222
219
  * 3. Atomic rename temp files to final names
223
220
  */ function extractAndInstall(archivePath, destDir, binaryName, callback) {
224
- var platform = _os.default.platform();
221
+ var platform = os.platform();
225
222
  var isWindows = platform === 'win32';
226
223
  var ext = isWindows ? '.exe' : '';
227
224
  // Create temp extraction directory
228
- var tempExtractDir = _path.default.join(getTmpDir(), "nvu-extract-".concat(Date.now()));
229
- _mkdirpclassic.default.sync(tempExtractDir);
225
+ var tempExtractDir = path.join(getTmpDir(), "nvu-extract-".concat(Date.now()));
226
+ mkdirp.sync(tempExtractDir);
230
227
  extractArchive(archivePath, tempExtractDir, function(extractErr) {
231
228
  if (extractErr) {
232
229
  rmRecursive(tempExtractDir);
233
230
  callback(extractErr);
234
231
  return;
235
232
  }
236
- var extractedPath = _path.default.join(tempExtractDir, binaryName);
237
- if (!_fs.default.existsSync(extractedPath)) {
233
+ var extractedPath = path.join(tempExtractDir, binaryName);
234
+ if (!fs.existsSync(extractedPath)) {
238
235
  rmRecursive(tempExtractDir);
239
236
  callback(new Error("Extracted binary not found: ".concat(binaryName)));
240
237
  return;
@@ -252,13 +249,13 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
252
249
  // This ensures the temp files are on the same filesystem for atomic rename
253
250
  for(var i = 0; i < binaries.length; i++){
254
251
  var name = binaries[i];
255
- var tempDest = _path.default.join(destDir, "".concat(name, ".tmp-").concat(timestamp).concat(ext));
252
+ var tempDest = path.join(destDir, "".concat(name, ".tmp-").concat(timestamp).concat(ext));
256
253
  try {
257
254
  // Copy to temp file in destination directory
258
255
  copyFileSync(extractedPath, tempDest);
259
256
  // Set permissions on Unix
260
257
  if (!isWindows) {
261
- _fs.default.chmodSync(tempDest, 493);
258
+ fs.chmodSync(tempDest, 493);
262
259
  }
263
260
  } catch (err) {
264
261
  installError = err;
@@ -268,10 +265,10 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
268
265
  if (installError) {
269
266
  // Clean up any temp files we created
270
267
  for(var j = 0; j < binaries.length; j++){
271
- var tempPath = _path.default.join(destDir, "".concat(binaries[j], ".tmp-").concat(timestamp).concat(ext));
272
- if (_fs.default.existsSync(tempPath)) {
268
+ var tempPath = path.join(destDir, "".concat(binaries[j], ".tmp-").concat(timestamp).concat(ext));
269
+ if (fs.existsSync(tempPath)) {
273
270
  try {
274
- _fs.default.unlinkSync(tempPath);
271
+ fs.unlinkSync(tempPath);
275
272
  } catch (_e) {
276
273
  // ignore cleanup errors
277
274
  }
@@ -291,12 +288,12 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
291
288
  return;
292
289
  }
293
290
  var name = binaries[index];
294
- var tempDest = _path.default.join(destDir, "".concat(name, ".tmp-").concat(timestamp).concat(ext));
295
- var finalDest = _path.default.join(destDir, "".concat(name).concat(ext));
291
+ var tempDest = path.join(destDir, "".concat(name, ".tmp-").concat(timestamp).concat(ext));
292
+ var finalDest = path.join(destDir, "".concat(name).concat(ext));
296
293
  // Remove existing file if present (for atomic replacement)
297
- if (_fs.default.existsSync(finalDest)) {
294
+ if (fs.existsSync(finalDest)) {
298
295
  try {
299
- _fs.default.unlinkSync(finalDest);
296
+ fs.unlinkSync(finalDest);
300
297
  } catch (_e) {
301
298
  // ignore cleanup errors
302
299
  }
@@ -314,9 +311,9 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
314
311
  /**
315
312
  * Print setup instructions
316
313
  */ function printInstructions(installed) {
317
- var homedirPath = (0, _compatts.homedir)();
318
- var nvuBinPath = _path.default.join(homedirPath, '.nvu', 'bin');
319
- var platform = _os.default.platform();
314
+ var homedirPath = homedir();
315
+ var nvuBinPath = path.join(homedirPath, '.nvu', 'bin');
316
+ var platform = os.platform();
320
317
  console.log('');
321
318
  console.log('============================================================');
322
319
  if (installed) {
@@ -357,29 +354,29 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
357
354
  var archiveBaseName = getArchiveBaseName();
358
355
  if (!archiveBaseName) {
359
356
  console.log('postinstall: Unsupported platform/architecture for binary.');
360
- console.log("Platform: ".concat(_os.default.platform(), ", Arch: ").concat(_os.default.arch()));
357
+ console.log("Platform: ".concat(os.platform(), ", Arch: ").concat(os.arch()));
361
358
  console.log('Binary not installed. You can still use nvu with explicit versions: nvu 18 npm test');
362
- (0, _exitcompat.default)(0);
359
+ exit(0);
363
360
  return;
364
361
  }
365
362
  var extractedBinaryName = getExtractedBinaryName(archiveBaseName);
366
- var homedirPath = (0, _compatts.homedir)();
367
- var nvuDir = _path.default.join(homedirPath, '.nvu');
368
- var binDir = _path.default.join(nvuDir, 'bin');
363
+ var homedirPath = homedir();
364
+ var nvuDir = path.join(homedirPath, '.nvu');
365
+ var binDir = path.join(nvuDir, 'bin');
369
366
  // Create directories
370
- _mkdirpclassic.default.sync(nvuDir);
371
- _mkdirpclassic.default.sync(binDir);
367
+ mkdirp.sync(nvuDir);
368
+ mkdirp.sync(binDir);
372
369
  var downloadUrl = getDownloadUrl(archiveBaseName);
373
- var ext = _os.default.platform() === 'win32' ? '.zip' : '.tar.gz';
374
- var tempPath = _path.default.join(getTmpDir(), "nvu-binary-".concat(Date.now()).concat(ext));
375
- console.log("postinstall: Downloading binary for ".concat(_os.default.platform(), "-").concat(_os.default.arch(), "..."));
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(), "..."));
376
373
  downloadFile(downloadUrl, tempPath, function(downloadErr) {
377
374
  if (downloadErr) {
378
375
  var _downloadErr_message;
379
376
  // Clean up temp file if it exists
380
- if (_fs.default.existsSync(tempPath)) {
377
+ if (fs.existsSync(tempPath)) {
381
378
  try {
382
- _fs.default.unlinkSync(tempPath);
379
+ fs.unlinkSync(tempPath);
383
380
  } catch (_e) {
384
381
  // ignore cleanup errors
385
382
  }
@@ -398,15 +395,15 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
398
395
  console.log('To install binaries manually: cd node_modules/node-version-use/binary && make install');
399
396
  }
400
397
  printInstructions(false);
401
- (0, _exitcompat.default)(0);
398
+ exit(0);
402
399
  return;
403
400
  }
404
401
  console.log('postinstall: Extracting binary...');
405
402
  extractAndInstall(tempPath, binDir, extractedBinaryName, function(extractErr) {
406
403
  // Clean up temp file
407
- if (_fs.default.existsSync(tempPath)) {
404
+ if (fs.existsSync(tempPath)) {
408
405
  try {
409
- _fs.default.unlinkSync(tempPath);
406
+ fs.unlinkSync(tempPath);
410
407
  } catch (_e) {
411
408
  // ignore cleanup errors
412
409
  }
@@ -415,12 +412,12 @@ var BINARY_VERSION = _require(_path.default.join(__dirname, '..', '..', '..', 'p
415
412
  console.log("postinstall warning: Failed to extract binary: ".concat(extractErr.message || extractErr));
416
413
  console.log('You can still use nvu with explicit versions: nvu 18 npm test');
417
414
  printInstructions(false);
418
- (0, _exitcompat.default)(0);
415
+ exit(0);
419
416
  return;
420
417
  }
421
418
  console.log('postinstall: Binary installed successfully!');
422
419
  printInstructions(true);
423
- (0, _exitcompat.default)(0);
420
+ exit(0);
424
421
  });
425
422
  });
426
423
  }