@shenvy/cli 0.1.6 → 0.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.
Files changed (2) hide show
  1. package/bin/install.js +25 -11
  2. package/package.json +1 -1
package/bin/install.js CHANGED
@@ -49,8 +49,9 @@ function download(url, dest) {
49
49
  return;
50
50
  }
51
51
  response.pipe(file);
52
- // Wait for 'close' instead of 'finish' to ensure OS handle is released
53
- file.on('close', resolve);
52
+ file.on('finish', () => {
53
+ file.close(() => resolve());
54
+ });
54
55
  }).on('error', (err) => {
55
56
  fs.unlink(dest, () => {});
56
57
  reject(err);
@@ -58,22 +59,35 @@ function download(url, dest) {
58
59
  });
59
60
  }
60
61
 
62
+ async function extractWithRetry(retries = 5) {
63
+ for (let i = 0; i < retries; i++) {
64
+ try {
65
+ console.log(`Extracting archive (attempt ${i + 1}/${retries})...`);
66
+ if (platform === 'win32') {
67
+ const psCommand = `powershell.exe -NoProfile -Command "Expand-Archive -Path '${tempArchive.replace(/'/g, "''")}' -DestinationPath '${binDir.replace(/'/g, "''")}' -Force"`;
68
+ execSync(psCommand, { stdio: 'inherit' });
69
+ } else {
70
+ execSync(`tar -xzf "${tempArchive}" -C "${binDir}"`, { stdio: 'inherit' });
71
+ }
72
+ return; // Success!
73
+ } catch (e) {
74
+ if (i === retries - 1) throw e;
75
+ console.log(`Archive locked, retrying in 1s...`);
76
+ await new Promise(r => setTimeout(r, 1000));
77
+ }
78
+ }
79
+ }
80
+
61
81
  async function install() {
62
82
  try {
63
83
  if (fs.existsSync(tempArchive)) fs.unlinkSync(tempArchive);
64
84
 
65
85
  await download(url, tempArchive);
66
86
 
67
- // Small delay to let the OS settle
68
- await new Promise(r => setTimeout(r, 500));
87
+ // Initial delay to let OS release handles
88
+ await new Promise(r => setTimeout(r, 1000));
69
89
 
70
- console.log('Extracting archive...');
71
- if (platform === 'win32') {
72
- const psCommand = `powershell.exe -NoProfile -Command "Expand-Archive -Path '${tempArchive.replace(/'/g, "''")}' -DestinationPath '${binDir.replace(/'/g, "''")}' -Force"`;
73
- execSync(psCommand);
74
- } else {
75
- execSync(`tar -xzf "${tempArchive}" -C "${binDir}"`);
76
- }
90
+ await extractWithRetry();
77
91
 
78
92
  const extractedBinPath = path.join(binDir, finalBinName);
79
93
  if (fs.existsSync(extractedBinPath)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shenvy/cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Securely manage environment variables with E2EE (Go implementation wrapper)",
5
5
  "main": "bin/install.js",
6
6
  "bin": {