xero-cli-bin 1.7.2 → 1.7.4

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/package.json +2 -2
  2. package/scripts/install.js +20 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xero-cli-bin",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "description": "Xero Accounting API CLI - Xero 會計 API 命令行工具",
5
5
  "bin": {
6
6
  "xero-cli": "./bin/xero-cli"
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "extract-zip": "^2.0.1",
17
17
  "node-downloader-helper": "^2.1.9",
18
- "tar": "^6.2.0"
18
+ "tar": "^7.0.0"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",
@@ -28,6 +28,24 @@ function getFileName() {
28
28
  return platform === 'win32' ? 'xero-cli.exe' : 'xero-cli';
29
29
  }
30
30
 
31
+ async function deleteWithRetry(filePath, maxRetries = 3) {
32
+ for (let i = 0; i < maxRetries; i++) {
33
+ try {
34
+ if (platform === 'win32') {
35
+ fs.rmSync(filePath, { force: true, recursive: true });
36
+ } else {
37
+ fs.unlinkSync(filePath);
38
+ }
39
+ return;
40
+ } catch (error) {
41
+ if (i === maxRetries - 1) {
42
+ throw error;
43
+ }
44
+ await new Promise(resolve => setTimeout(resolve, 500 * (i + 1)));
45
+ }
46
+ }
47
+ }
48
+
31
49
  async function downloadFromGitHubRelease() {
32
50
  const pkg = require('../package.json');
33
51
  const version = pkg.version.replace(/^v/, '');
@@ -87,7 +105,7 @@ async function downloadFromGitHubRelease() {
87
105
  });
88
106
  }
89
107
 
90
- fs.unlinkSync(downloadPath);
108
+ await deleteWithRetry(downloadPath);
91
109
 
92
110
  const binaryPath = join(extractDir, getFileName());
93
111
 
@@ -99,7 +117,7 @@ async function downloadFromGitHubRelease() {
99
117
  console.log(`[xero-cli-bin] Binary installed to: ${binaryPath}`);
100
118
  } catch (error) {
101
119
  if (fs.existsSync(downloadPath)) {
102
- fs.unlinkSync(downloadPath);
120
+ await deleteWithRetry(downloadPath);
103
121
  }
104
122
  throw error;
105
123
  }