node-version-use 2.0.0 → 2.1.1

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 (63) hide show
  1. package/README.md +7 -7
  2. package/dist/cjs/cli.js +20 -35
  3. package/dist/cjs/cli.js.map +1 -1
  4. package/dist/cjs/commands/default.js +6 -6
  5. package/dist/cjs/commands/default.js.map +1 -1
  6. package/dist/cjs/commands/install.js +9 -9
  7. package/dist/cjs/commands/install.js.map +1 -1
  8. package/dist/cjs/commands/list.js +10 -26
  9. package/dist/cjs/commands/list.js.map +1 -1
  10. package/dist/cjs/commands/local.js +10 -10
  11. package/dist/cjs/commands/local.js.map +1 -1
  12. package/dist/cjs/commands/setup.d.cts +1 -1
  13. package/dist/cjs/commands/setup.d.ts +1 -1
  14. package/dist/cjs/commands/setup.js +3 -3
  15. package/dist/cjs/commands/setup.js.map +1 -1
  16. package/dist/cjs/commands/teardown.d.cts +1 -1
  17. package/dist/cjs/commands/teardown.d.ts +1 -1
  18. package/dist/cjs/commands/teardown.js +14 -28
  19. package/dist/cjs/commands/teardown.js.map +1 -1
  20. package/dist/cjs/commands/uninstall.js +7 -7
  21. package/dist/cjs/commands/uninstall.js.map +1 -1
  22. package/dist/cjs/commands/which.d.cts +1 -1
  23. package/dist/cjs/commands/which.d.ts +1 -1
  24. package/dist/cjs/commands/which.js +7 -7
  25. package/dist/cjs/commands/which.js.map +1 -1
  26. package/dist/cjs/worker.js +5 -26
  27. package/dist/cjs/worker.js.map +1 -1
  28. package/dist/esm/cli.js +15 -28
  29. package/dist/esm/cli.js.map +1 -1
  30. package/dist/esm/commands/default.js +3 -3
  31. package/dist/esm/commands/default.js.map +1 -1
  32. package/dist/esm/commands/install.js +4 -4
  33. package/dist/esm/commands/install.js.map +1 -1
  34. package/dist/esm/commands/list.js +4 -3
  35. package/dist/esm/commands/list.js.map +1 -1
  36. package/dist/esm/commands/local.js +5 -5
  37. package/dist/esm/commands/local.js.map +1 -1
  38. package/dist/esm/commands/setup.d.ts +1 -1
  39. package/dist/esm/commands/setup.js +2 -2
  40. package/dist/esm/commands/setup.js.map +1 -1
  41. package/dist/esm/commands/teardown.d.ts +1 -1
  42. package/dist/esm/commands/teardown.js +12 -9
  43. package/dist/esm/commands/teardown.js.map +1 -1
  44. package/dist/esm/commands/uninstall.js +2 -2
  45. package/dist/esm/commands/uninstall.js.map +1 -1
  46. package/dist/esm/commands/which.d.ts +1 -1
  47. package/dist/esm/commands/which.js +5 -5
  48. package/dist/esm/commands/which.js.map +1 -1
  49. package/dist/esm/worker.js +3 -16
  50. package/dist/esm/worker.js.map +1 -1
  51. package/package.json +13 -10
  52. package/scripts/ensure-test-binaries.ts +27 -0
  53. package/scripts/postinstall.cjs +264 -75
  54. package/dist/cjs/lib/loadSpawnTerm.d.cts +0 -19
  55. package/dist/cjs/lib/loadSpawnTerm.d.ts +0 -19
  56. package/dist/cjs/lib/loadSpawnTerm.js +0 -103
  57. package/dist/cjs/lib/loadSpawnTerm.js.map +0 -1
  58. package/dist/esm/lib/loadSpawnTerm.d.ts +0 -19
  59. package/dist/esm/lib/loadSpawnTerm.js +0 -42
  60. package/dist/esm/lib/loadSpawnTerm.js.map +0 -1
  61. package/shim/Makefile +0 -58
  62. package/shim/go.mod +0 -3
  63. package/shim/main.go +0 -302
@@ -1,8 +1,13 @@
1
1
  /**
2
2
  * Postinstall script for node-version-use
3
3
  *
4
- * Downloads the platform-specific shim binary and installs it to ~/.nvu/bin/
5
- * This enables transparent Node version switching via the shim.
4
+ * Downloads the platform-specific binary and installs it to ~/.nvu/bin/
5
+ * This enables transparent Node version switching.
6
+ *
7
+ * Uses safe atomic download pattern:
8
+ * 1. Download to temp file
9
+ * 2. Extract to temp directory
10
+ * 3. Atomic rename to final location
6
11
  *
7
12
  * Compatible with Node.js 0.8+
8
13
  */
@@ -10,8 +15,7 @@
10
15
  var fs = require('fs');
11
16
  var path = require('path');
12
17
  var os = require('os');
13
- var exit = require('exit');
14
- var getRemote = require('get-remote');
18
+ var exit = require('exit-compat');
15
19
 
16
20
  // Polyfills for old Node versions
17
21
  var mkdirp = require('mkdirp-classic');
@@ -22,12 +26,12 @@ var spawn = require('child_process').spawn;
22
26
 
23
27
  // Configuration
24
28
  var GITHUB_REPO = 'kmalakoff/node-version-use';
25
- var SHIM_VERSION = '1.0.2';
29
+ var BINARY_VERSION = require('../package.json').binaryVersion;
26
30
 
27
31
  /**
28
- * Get the platform-specific binary name
32
+ * Get the platform-specific archive base name (without extension)
29
33
  */
30
- function getShimBinaryName() {
34
+ function getArchiveBaseName() {
31
35
  var platform = os.platform();
32
36
  var arch = os.arch();
33
37
 
@@ -50,16 +54,23 @@ function getShimBinaryName() {
50
54
  return null;
51
55
  }
52
56
 
53
- var ext = platform === 'win32' ? '.exe' : '';
54
- return 'nvu-shim-' + platformName + '-' + archName + ext;
57
+ return 'nvu-binary-' + platformName + '-' + archName;
55
58
  }
56
59
 
57
60
  /**
58
- * Get the download URL for the shim binary
61
+ * Get the extracted binary name (includes .exe on Windows)
59
62
  */
60
- function getDownloadUrl(binaryName) {
63
+ function getExtractedBinaryName(archiveBaseName) {
64
+ var ext = os.platform() === 'win32' ? '.exe' : '';
65
+ return archiveBaseName + ext;
66
+ }
67
+
68
+ /**
69
+ * Get the download URL for the binary archive
70
+ */
71
+ function getDownloadUrl(archiveBaseName) {
61
72
  var ext = os.platform() === 'win32' ? '.zip' : '.tar.gz';
62
- return 'https://github.com/' + GITHUB_REPO + '/releases/download/shim-v' + SHIM_VERSION + '/' + binaryName + ext;
73
+ return 'https://github.com/' + GITHUB_REPO + '/releases/download/binary-v' + BINARY_VERSION + '/' + archiveBaseName + ext;
63
74
  }
64
75
 
65
76
  /**
@@ -71,17 +82,127 @@ function copyFileSync(src, dest) {
71
82
  }
72
83
 
73
84
  /**
74
- * Download a file from a URL (using get-remote for Node 0.8+ compatibility)
85
+ * Atomic rename with fallback to copy+delete for cross-device moves
86
+ * (compatible with Node 0.8)
87
+ */
88
+ function atomicRename(src, dest, callback) {
89
+ fs.rename(src, dest, function (err) {
90
+ if (!err) {
91
+ callback(null);
92
+ return;
93
+ }
94
+
95
+ // Cross-device link error - fall back to copy + delete
96
+ if (err.code === 'EXDEV') {
97
+ try {
98
+ copyFileSync(src, dest);
99
+ fs.unlinkSync(src);
100
+ callback(null);
101
+ } catch (copyErr) {
102
+ callback(copyErr);
103
+ }
104
+ return;
105
+ }
106
+
107
+ callback(err);
108
+ });
109
+ }
110
+
111
+ /**
112
+ * Remove directory recursively (compatible with Node 0.8)
113
+ */
114
+ function rmRecursive(dir) {
115
+ if (!fs.existsSync(dir)) return;
116
+
117
+ var files = fs.readdirSync(dir);
118
+ for (var i = 0; i < files.length; i++) {
119
+ var filePath = path.join(dir, files[i]);
120
+ var stat = fs.statSync(filePath);
121
+ if (stat.isDirectory()) {
122
+ rmRecursive(filePath);
123
+ } else {
124
+ fs.unlinkSync(filePath);
125
+ }
126
+ }
127
+ fs.rmdirSync(dir);
128
+ }
129
+
130
+ /**
131
+ * Get temp directory (compatible with Node 0.8)
132
+ */
133
+ function getTmpDir() {
134
+ return typeof os.tmpdir === 'function' ? os.tmpdir() : process.env.TMPDIR || process.env.TMP || process.env.TEMP || '/tmp';
135
+ }
136
+
137
+ /**
138
+ * Download using curl (macOS, Linux, Windows 10+)
139
+ */
140
+ function downloadWithCurl(url, destPath, callback) {
141
+ var curl = spawn('curl', ['-L', '-f', '-s', '-o', destPath, url]);
142
+
143
+ curl.on('close', function (code) {
144
+ if (code !== 0) {
145
+ // curl exit codes: 22 = HTTP error (4xx/5xx), 56 = receive error (often 404 with -f)
146
+ if (code === 22 || code === 56) {
147
+ callback(new Error('HTTP 404'));
148
+ } else {
149
+ callback(new Error('curl failed with exit code ' + code));
150
+ }
151
+ return;
152
+ }
153
+ callback(null);
154
+ });
155
+
156
+ curl.on('error', function (err) {
157
+ callback(err);
158
+ });
159
+ }
160
+
161
+ /**
162
+ * Download using PowerShell (Windows 7+ fallback)
163
+ */
164
+ function downloadWithPowerShell(url, destPath, callback) {
165
+ var psCommand = 'Invoke-WebRequest -Uri "' + url + '" -OutFile "' + destPath + '" -UseBasicParsing';
166
+ var ps = spawn('powershell', ['-NoProfile', '-Command', psCommand]);
167
+
168
+ ps.on('close', function (code) {
169
+ if (code !== 0) {
170
+ callback(new Error('PowerShell download failed with exit code ' + code));
171
+ return;
172
+ }
173
+ callback(null);
174
+ });
175
+
176
+ ps.on('error', function (err) {
177
+ callback(err);
178
+ });
179
+ }
180
+
181
+ /**
182
+ * Download a file - tries curl first, falls back to PowerShell on Windows
183
+ * Node 0.8's OpenSSL doesn't support TLS 1.2+ required by GitHub
75
184
  */
76
185
  function downloadFile(url, destPath, callback) {
77
- var writeStream = fs.createWriteStream(destPath);
78
- getRemote(url).pipe(writeStream, callback);
186
+ downloadWithCurl(url, destPath, function (err) {
187
+ if (!err) {
188
+ callback(null);
189
+ return;
190
+ }
191
+
192
+ // If curl failed and we're on Windows, try PowerShell
193
+ if (os.platform() === 'win32' && err.message && err.message.indexOf('ENOENT') >= 0) {
194
+ downloadWithPowerShell(url, destPath, callback);
195
+ return;
196
+ }
197
+
198
+ callback(err);
199
+ });
79
200
  }
80
201
 
81
202
  /**
82
- * Extract archive and install shims (callback-based)
203
+ * Extract archive to a directory (callback-based)
83
204
  */
84
- function extractAndInstall(archivePath, destDir, binaryName, callback) {
205
+ function extractArchive(archivePath, destDir, callback) {
85
206
  var platform = os.platform();
86
207
 
87
208
  if (platform === 'win32') {
@@ -92,18 +213,6 @@ function extractAndInstall(archivePath, destDir, binaryName, callback) {
92
213
  callback(new Error('Failed to extract archive'));
93
214
  return;
94
215
  }
95
- var extractedPath = path.join(destDir, binaryName);
96
- if (fs.existsSync(extractedPath)) {
97
- try {
98
- copyFileSync(extractedPath, path.join(destDir, 'node.exe'));
99
- copyFileSync(extractedPath, path.join(destDir, 'npm.exe'));
100
- copyFileSync(extractedPath, path.join(destDir, 'npx.exe'));
101
- fs.unlinkSync(extractedPath);
102
- } catch (err) {
103
- callback(err);
104
- return;
105
- }
106
- }
107
216
  callback(null);
108
217
  });
109
218
  } else {
@@ -114,32 +223,117 @@ function extractAndInstall(archivePath, destDir, binaryName, callback) {
114
223
  callback(new Error('Failed to extract archive'));
115
224
  return;
116
225
  }
117
- var extractedPath = path.join(destDir, binaryName);
118
- if (fs.existsSync(extractedPath)) {
119
- var nodePath = path.join(destDir, 'node');
120
- var npmPath = path.join(destDir, 'npm');
121
- var npxPath = path.join(destDir, 'npx');
122
-
123
- try {
124
- copyFileSync(extractedPath, nodePath);
125
- copyFileSync(extractedPath, npmPath);
126
- copyFileSync(extractedPath, npxPath);
127
-
128
- fs.chmodSync(nodePath, 493); // 0755
129
- fs.chmodSync(npmPath, 493);
130
- fs.chmodSync(npxPath, 493);
131
-
132
- fs.unlinkSync(extractedPath);
133
- } catch (err) {
134
- callback(err);
135
- return;
136
- }
137
- }
138
226
  callback(null);
139
227
  });
140
228
  }
141
229
  }
142
230
 
231
+ /**
232
+ * Install binaries using atomic rename pattern
233
+ * 1. Extract to temp directory
234
+ * 2. Copy binary to temp files in destination directory
235
+ * 3. Atomic rename temp files to final names
236
+ */
237
+ function extractAndInstall(archivePath, destDir, binaryName, callback) {
238
+ var platform = os.platform();
239
+ var isWindows = platform === 'win32';
240
+ var ext = isWindows ? '.exe' : '';
241
+
242
+ // Create temp extraction directory
243
+ var tempExtractDir = path.join(getTmpDir(), 'nvu-extract-' + Date.now());
244
+ mkdirp.sync(tempExtractDir);
245
+
246
+ extractArchive(archivePath, tempExtractDir, function (extractErr) {
247
+ if (extractErr) {
248
+ rmRecursive(tempExtractDir);
249
+ callback(extractErr);
250
+ return;
251
+ }
252
+
253
+ var extractedPath = path.join(tempExtractDir, binaryName);
254
+ if (!fs.existsSync(extractedPath)) {
255
+ rmRecursive(tempExtractDir);
256
+ callback(new Error('Extracted binary not found: ' + binaryName));
257
+ return;
258
+ }
259
+
260
+ // Binary names to install
261
+ var binaries = ['node', 'npm', 'npx'];
262
+ var timestamp = Date.now();
263
+ var _pending = binaries.length;
264
+ var installError = null;
265
+
266
+ // Step 1: Copy extracted binary to temp files in destination directory
267
+ // This ensures the temp files are on the same filesystem for atomic rename
268
+ for (var i = 0; i < binaries.length; i++) {
269
+ var name = binaries[i];
270
+ var tempDest = path.join(destDir, name + '.tmp-' + timestamp + ext);
271
+ var _finalDest = path.join(destDir, name + ext);
272
+
273
+ try {
274
+ // Copy to temp file in destination directory
275
+ copyFileSync(extractedPath, tempDest);
276
+
277
+ // Set permissions on Unix
278
+ if (!isWindows) {
279
+ fs.chmodSync(tempDest, 493); // 0755
280
+ }
281
+ } catch (err) {
282
+ installError = err;
283
+ break;
284
+ }
285
+ }
286
+
287
+ if (installError) {
288
+ // Clean up any temp files we created
289
+ for (var j = 0; j < binaries.length; j++) {
290
+ var tempPath = path.join(destDir, binaries[j] + '.tmp-' + timestamp + ext);
291
+ if (fs.existsSync(tempPath)) {
292
+ try {
293
+ fs.unlinkSync(tempPath);
294
+ } catch (_e) {}
295
+ }
296
+ }
297
+ rmRecursive(tempExtractDir);
298
+ callback(installError);
299
+ return;
300
+ }
301
+
302
+ // Step 2: Atomic rename temp files to final names
303
+ var _renamesPending = binaries.length;
304
+ var renameError = null;
305
+
306
+ function doRename(index) {
307
+ if (index >= binaries.length) {
308
+ // All renames complete
309
+ rmRecursive(tempExtractDir);
310
+ callback(renameError);
311
+ return;
312
+ }
313
+
314
+ var name = binaries[index];
315
+ var tempDest = path.join(destDir, name + '.tmp-' + timestamp + ext);
316
+ var finalDest = path.join(destDir, name + ext);
317
+
318
+ // Remove existing file if present (for atomic replacement)
319
+ if (fs.existsSync(finalDest)) {
320
+ try {
321
+ fs.unlinkSync(finalDest);
322
+ } catch (_e) {}
323
+ }
324
+
325
+ atomicRename(tempDest, finalDest, function (err) {
326
+ if (err && !renameError) {
327
+ renameError = err;
328
+ }
329
+ doRename(index + 1);
330
+ });
331
+ }
332
+
333
+ doRename(0);
334
+ });
335
+ }
336
+
143
337
  /**
144
338
  * Print setup instructions
145
339
  */
@@ -150,9 +344,9 @@ function printInstructions(installed) {
150
344
  console.log('');
151
345
  console.log('============================================================');
152
346
  if (installed) {
153
- console.log(' nvu shims installed to ~/.nvu/bin/');
347
+ console.log(' nvu binaries installed to ~/.nvu/bin/');
154
348
  } else {
155
- console.log(' nvu installed (shims not yet available)');
349
+ console.log(' nvu installed (binaries not yet available)');
156
350
  }
157
351
  console.log('============================================================');
158
352
  console.log('');
@@ -184,27 +378,22 @@ function printInstructions(installed) {
184
378
  console.log('============================================================');
185
379
  }
186
380
 
187
- /**
188
- * Get temp directory (compatible with Node 0.8)
189
- */
190
- function getTmpDir() {
191
- return typeof os.tmpdir === 'function' ? os.tmpdir() : process.env.TMPDIR || process.env.TMP || process.env.TEMP || '/tmp';
192
- }
193
-
194
381
  /**
195
382
  * Main installation function
196
383
  */
197
384
  function main() {
198
- var binaryName = getShimBinaryName();
385
+ var archiveBaseName = getArchiveBaseName();
199
386
 
200
- if (!binaryName) {
201
- console.log('postinstall: Unsupported platform/architecture for shim binary.');
387
+ if (!archiveBaseName) {
388
+ console.log('postinstall: Unsupported platform/architecture for binary.');
202
389
  console.log('Platform: ' + os.platform() + ', Arch: ' + os.arch());
203
- console.log('Shim not installed. You can still use nvu with explicit versions: nvu 18 npm test');
390
+ console.log('Binary not installed. You can still use nvu with explicit versions: nvu 18 npm test');
204
391
  exit(0);
205
392
  return;
206
393
  }
207
394
 
395
+ var extractedBinaryName = getExtractedBinaryName(archiveBaseName);
396
+
208
397
  var nvuDir = path.join(homedir, '.nvu');
209
398
  var binDir = path.join(nvuDir, 'bin');
210
399
 
@@ -212,11 +401,11 @@ function main() {
212
401
  mkdirp.sync(nvuDir);
213
402
  mkdirp.sync(binDir);
214
403
 
215
- var downloadUrl = getDownloadUrl(binaryName);
404
+ var downloadUrl = getDownloadUrl(archiveBaseName);
216
405
  var ext = os.platform() === 'win32' ? '.zip' : '.tar.gz';
217
- var tempPath = path.join(getTmpDir(), 'nvu-shim-' + Date.now() + ext);
406
+ var tempPath = path.join(getTmpDir(), 'nvu-binary-' + Date.now() + ext);
218
407
 
219
- console.log('postinstall: Downloading shim binary for ' + os.platform() + '-' + os.arch() + '...');
408
+ console.log('postinstall: Downloading binary for ' + os.platform() + '-' + os.arch() + '...');
220
409
 
221
410
  downloadFile(downloadUrl, tempPath, function (downloadErr) {
222
411
  if (downloadErr) {
@@ -228,26 +417,26 @@ function main() {
228
417
  }
229
418
 
230
419
  if (downloadErr.message && downloadErr.message.indexOf('404') >= 0) {
231
- console.log('postinstall: Shim binaries not yet published to GitHub releases.');
420
+ console.log('postinstall: Binaries not yet published to GitHub releases.');
232
421
  console.log('');
233
- console.log('To build and install shims locally:');
234
- console.log(' cd node_modules/node-version-use/shim');
422
+ console.log('To build and install binaries locally:');
423
+ console.log(' cd node_modules/node-version-use/binary');
235
424
  console.log(' make install');
236
425
  console.log('');
237
426
  console.log('Or wait for the next release which will include pre-built binaries.');
238
427
  } else {
239
- console.log('postinstall warning: Failed to install shim: ' + (downloadErr.message || downloadErr));
428
+ console.log('postinstall warning: Failed to install binary: ' + (downloadErr.message || downloadErr));
240
429
  console.log('You can still use nvu with explicit versions: nvu 18 npm test');
241
- console.log('To install shims manually: cd node_modules/node-version-use/shim && make install');
430
+ console.log('To install binaries manually: cd node_modules/node-version-use/binary && make install');
242
431
  }
243
432
  printInstructions(false);
244
433
  exit(0);
245
434
  return;
246
435
  }
247
436
 
248
- console.log('postinstall: Extracting shim binary...');
437
+ console.log('postinstall: Extracting binary...');
249
438
 
250
- extractAndInstall(tempPath, binDir, binaryName, function (extractErr) {
439
+ extractAndInstall(tempPath, binDir, extractedBinaryName, function (extractErr) {
251
440
  // Clean up temp file
252
441
  if (fs.existsSync(tempPath)) {
253
442
  try {
@@ -256,14 +445,14 @@ function main() {
256
445
  }
257
446
 
258
447
  if (extractErr) {
259
- console.log('postinstall warning: Failed to extract shim: ' + (extractErr.message || extractErr));
448
+ console.log('postinstall warning: Failed to extract binary: ' + (extractErr.message || extractErr));
260
449
  console.log('You can still use nvu with explicit versions: nvu 18 npm test');
261
450
  printInstructions(false);
262
451
  exit(0);
263
452
  return;
264
453
  }
265
454
 
266
- console.log('postinstall: Shim installed successfully!');
455
+ console.log('postinstall: Binary installed successfully!');
267
456
  printInstructions(true);
268
457
  exit(0);
269
458
  });
@@ -1,19 +0,0 @@
1
- type CreateSessionFn = ((options?: {
2
- header?: string;
3
- showStatusBar?: boolean;
4
- interactive?: boolean;
5
- }) => {
6
- spawn: (command: string, args: string[], options: unknown, termOptions: unknown, callback: (err?: Error, res?: unknown) => void) => void;
7
- close: () => void;
8
- waitAndClose: (callback?: () => void) => void;
9
- }) | undefined;
10
- interface SpawnTermModule {
11
- createSession: CreateSessionFn;
12
- figures: {
13
- tick: string;
14
- cross: string;
15
- };
16
- formatArguments: (args: string[]) => string[];
17
- }
18
- export default function loadSpawnTerm(callback: (err: Error | null, result: SpawnTermModule) => void): void;
19
- export {};
@@ -1,19 +0,0 @@
1
- type CreateSessionFn = ((options?: {
2
- header?: string;
3
- showStatusBar?: boolean;
4
- interactive?: boolean;
5
- }) => {
6
- spawn: (command: string, args: string[], options: unknown, termOptions: unknown, callback: (err?: Error, res?: unknown) => void) => void;
7
- close: () => void;
8
- waitAndClose: (callback?: () => void) => void;
9
- }) | undefined;
10
- interface SpawnTermModule {
11
- createSession: CreateSessionFn;
12
- figures: {
13
- tick: string;
14
- cross: string;
15
- };
16
- formatArguments: (args: string[]) => string[];
17
- }
18
- export default function loadSpawnTerm(callback: (err: Error | null, result: SpawnTermModule) => void): void;
19
- export {};
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
8
- return loadSpawnTerm;
9
- }
10
- });
11
- var _installmodulelinked = /*#__PURE__*/ _interop_require_default(require("install-module-linked"));
12
- var _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
- var _url = /*#__PURE__*/ _interop_require_default(require("url"));
14
- function _interop_require_default(obj) {
15
- return obj && obj.__esModule ? obj : {
16
- default: obj
17
- };
18
- }
19
- function _getRequireWildcardCache(nodeInterop) {
20
- if (typeof WeakMap !== "function") return null;
21
- var cacheBabelInterop = new WeakMap();
22
- var cacheNodeInterop = new WeakMap();
23
- return (_getRequireWildcardCache = function(nodeInterop) {
24
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
25
- })(nodeInterop);
26
- }
27
- function _interop_require_wildcard(obj, nodeInterop) {
28
- if (!nodeInterop && obj && obj.__esModule) {
29
- return obj;
30
- }
31
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
32
- return {
33
- default: obj
34
- };
35
- }
36
- var cache = _getRequireWildcardCache(nodeInterop);
37
- if (cache && cache.has(obj)) {
38
- return cache.get(obj);
39
- }
40
- var newObj = {
41
- __proto__: null
42
- };
43
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
44
- for(var key in obj){
45
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
46
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
47
- if (desc && (desc.get || desc.set)) {
48
- Object.defineProperty(newObj, key, desc);
49
- } else {
50
- newObj[key] = obj[key];
51
- }
52
- }
53
- }
54
- newObj.default = obj;
55
- if (cache) {
56
- cache.set(obj, newObj);
57
- }
58
- return newObj;
59
- }
60
- var _dirname = _path.default.dirname(typeof __dirname !== 'undefined' ? __dirname : _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()));
61
- var nodeModules = _path.default.join(_dirname, '..', '..', '..', 'node_modules');
62
- var moduleName = 'spawn-term';
63
- var cached;
64
- function loadModule(moduleName, callback) {
65
- if (typeof require === 'undefined') {
66
- Promise.resolve(moduleName).then(function(p) {
67
- return /*#__PURE__*/ _interop_require_wildcard(require(p));
68
- }).then(function(mod) {
69
- var _mod_createSession, _mod_figures, _mod_formatArguments;
70
- callback(null, {
71
- createSession: (_mod_createSession = mod === null || mod === void 0 ? void 0 : mod.createSession) !== null && _mod_createSession !== void 0 ? _mod_createSession : undefined,
72
- figures: (_mod_figures = mod === null || mod === void 0 ? void 0 : mod.figures) !== null && _mod_figures !== void 0 ? _mod_figures : {
73
- tick: '✓',
74
- cross: '✗'
75
- },
76
- formatArguments: (_mod_formatArguments = mod === null || mod === void 0 ? void 0 : mod.formatArguments) !== null && _mod_formatArguments !== void 0 ? _mod_formatArguments : function(args) {
77
- return args;
78
- }
79
- });
80
- }).catch(callback);
81
- } else {
82
- try {
83
- callback(null, require(moduleName));
84
- } catch (err) {
85
- callback(err, null);
86
- }
87
- }
88
- }
89
- function loadSpawnTerm(callback) {
90
- if (cached !== undefined) {
91
- callback(null, cached);
92
- return;
93
- }
94
- (0, _installmodulelinked.default)(moduleName, nodeModules, {}, function(err) {
95
- if (err) return callback(err, null);
96
- loadModule(moduleName, function(err, _cached) {
97
- if (err) return callback(err, null);
98
- cached = _cached;
99
- callback(null, cached);
100
- });
101
- });
102
- }
103
- /* 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 +0,0 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/lib/loadSpawnTerm.ts"],"sourcesContent":["import installModule from 'install-module-linked';\nimport path from 'path';\nimport url from 'url';\n\nconst _dirname = path.dirname(typeof __dirname !== 'undefined' ? __dirname : url.fileURLToPath(import.meta.url));\nconst nodeModules = path.join(_dirname, '..', '..', '..', 'node_modules');\nconst moduleName = 'spawn-term';\n\ntype CreateSessionFn =\n | ((options?: { header?: string; showStatusBar?: boolean; interactive?: boolean }) => {\n spawn: (command: string, args: string[], options: unknown, termOptions: unknown, callback: (err?: Error, res?: unknown) => void) => void;\n close: () => void;\n waitAndClose: (callback?: () => void) => void;\n })\n | undefined;\n\ninterface SpawnTermModule {\n createSession: CreateSessionFn;\n figures: { tick: string; cross: string };\n formatArguments: (args: string[]) => string[];\n}\n\nlet cached: SpawnTermModule | undefined;\n\nfunction loadModule(moduleName, callback) {\n if (typeof require === 'undefined') {\n import(moduleName)\n .then((mod) => {\n callback(null, {\n createSession: mod?.createSession ?? undefined,\n figures: mod?.figures ?? { tick: '✓', cross: '✗' },\n formatArguments: mod?.formatArguments ?? ((args: string[]) => args),\n });\n })\n .catch(callback);\n } else {\n try {\n callback(null, require(moduleName));\n } catch (err) {\n callback(err, null);\n }\n }\n}\n\nexport default function loadSpawnTerm(callback: (err: Error | null, result: SpawnTermModule) => void): void {\n if (cached !== undefined) {\n callback(null, cached);\n return;\n }\n installModule(moduleName, nodeModules, {}, (err) => {\n if (err) return callback(err, null);\n loadModule(moduleName, (err, _cached: SpawnTermModule) => {\n if (err) return callback(err, null);\n cached = _cached;\n callback(null, cached);\n });\n });\n}\n"],"names":["loadSpawnTerm","_dirname","path","dirname","__dirname","url","fileURLToPath","nodeModules","join","moduleName","cached","loadModule","callback","require","then","mod","createSession","undefined","figures","tick","cross","formatArguments","args","catch","err","installModule","_cached"],"mappings":";;;;+BA4CA;;;eAAwBA;;;0EA5CE;2DACT;0DACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEhB,IAAMC,WAAWC,aAAI,CAACC,OAAO,CAAC,OAAOC,cAAc,cAAcA,YAAYC,YAAG,CAACC,aAAa,CAAC;AAC/F,IAAMC,cAAcL,aAAI,CAACM,IAAI,CAACP,UAAU,MAAM,MAAM,MAAM;AAC1D,IAAMQ,aAAa;AAgBnB,IAAIC;AAEJ,SAASC,WAAWF,UAAU,EAAEG,QAAQ;IACtC,IAAI,OAAOC,YAAY,aAAa;QAClC,gBAAOJ;2DAAP;WACGK,IAAI,CAAC,SAACC;gBAEYA,oBACNA,cACQA;YAHnBH,SAAS,MAAM;gBACbI,eAAeD,CAAAA,qBAAAA,gBAAAA,0BAAAA,IAAKC,aAAa,cAAlBD,gCAAAA,qBAAsBE;gBACrCC,SAASH,CAAAA,eAAAA,gBAAAA,0BAAAA,IAAKG,OAAO,cAAZH,0BAAAA,eAAgB;oBAAEI,MAAM;oBAAKC,OAAO;gBAAI;gBACjDC,iBAAiBN,CAAAA,uBAAAA,gBAAAA,0BAAAA,IAAKM,eAAe,cAApBN,kCAAAA,uBAAyB,SAACO;2BAAmBA;;YAChE;QACF,GACCC,KAAK,CAACX;IACX,OAAO;QACL,IAAI;YACFA,SAAS,MAAMC,QAAQJ;QACzB,EAAE,OAAOe,KAAK;YACZZ,SAASY,KAAK;QAChB;IACF;AACF;AAEe,SAASxB,cAAcY,QAA8D;IAClG,IAAIF,WAAWO,WAAW;QACxBL,SAAS,MAAMF;QACf;IACF;IACAe,IAAAA,4BAAa,EAAChB,YAAYF,aAAa,CAAC,GAAG,SAACiB;QAC1C,IAAIA,KAAK,OAAOZ,SAASY,KAAK;QAC9Bb,WAAWF,YAAY,SAACe,KAAKE;YAC3B,IAAIF,KAAK,OAAOZ,SAASY,KAAK;YAC9Bd,SAASgB;YACTd,SAAS,MAAMF;QACjB;IACF;AACF"}
@@ -1,19 +0,0 @@
1
- type CreateSessionFn = ((options?: {
2
- header?: string;
3
- showStatusBar?: boolean;
4
- interactive?: boolean;
5
- }) => {
6
- spawn: (command: string, args: string[], options: unknown, termOptions: unknown, callback: (err?: Error, res?: unknown) => void) => void;
7
- close: () => void;
8
- waitAndClose: (callback?: () => void) => void;
9
- }) | undefined;
10
- interface SpawnTermModule {
11
- createSession: CreateSessionFn;
12
- figures: {
13
- tick: string;
14
- cross: string;
15
- };
16
- formatArguments: (args: string[]) => string[];
17
- }
18
- export default function loadSpawnTerm(callback: (err: Error | null, result: SpawnTermModule) => void): void;
19
- export {};
@@ -1,42 +0,0 @@
1
- import installModule from 'install-module-linked';
2
- import path from 'path';
3
- import url from 'url';
4
- const _dirname = path.dirname(typeof __dirname !== 'undefined' ? __dirname : url.fileURLToPath(import.meta.url));
5
- const nodeModules = path.join(_dirname, '..', '..', '..', 'node_modules');
6
- const moduleName = 'spawn-term';
7
- let cached;
8
- function loadModule(moduleName, callback) {
9
- if (typeof require === 'undefined') {
10
- import(moduleName).then((mod)=>{
11
- var _mod_createSession, _mod_figures, _mod_formatArguments;
12
- callback(null, {
13
- createSession: (_mod_createSession = mod === null || mod === void 0 ? void 0 : mod.createSession) !== null && _mod_createSession !== void 0 ? _mod_createSession : undefined,
14
- figures: (_mod_figures = mod === null || mod === void 0 ? void 0 : mod.figures) !== null && _mod_figures !== void 0 ? _mod_figures : {
15
- tick: '✓',
16
- cross: '✗'
17
- },
18
- formatArguments: (_mod_formatArguments = mod === null || mod === void 0 ? void 0 : mod.formatArguments) !== null && _mod_formatArguments !== void 0 ? _mod_formatArguments : (args)=>args
19
- });
20
- }).catch(callback);
21
- } else {
22
- try {
23
- callback(null, require(moduleName));
24
- } catch (err) {
25
- callback(err, null);
26
- }
27
- }
28
- }
29
- export default function loadSpawnTerm(callback) {
30
- if (cached !== undefined) {
31
- callback(null, cached);
32
- return;
33
- }
34
- installModule(moduleName, nodeModules, {}, (err)=>{
35
- if (err) return callback(err, null);
36
- loadModule(moduleName, (err, _cached)=>{
37
- if (err) return callback(err, null);
38
- cached = _cached;
39
- callback(null, cached);
40
- });
41
- });
42
- }