uncomment-cli 2.9.2 → 2.10.2

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 (3) hide show
  1. package/index.js +2 -2
  2. package/install.js +45 -27
  3. package/package.json +2 -1
package/index.js CHANGED
@@ -13,13 +13,13 @@ function getPlatform() {
13
13
  if (type === "Linux") {
14
14
  if (arch === "x64") return "x86_64-unknown-linux-gnu";
15
15
  if (arch === "arm64") return "aarch64-unknown-linux-gnu";
16
- return "x86_64-unknown-linux-gnu"; // fallback
16
+ return "x86_64-unknown-linux-gnu";
17
17
  }
18
18
 
19
19
  if (type === "Darwin") {
20
20
  if (arch === "x64") return "x86_64-apple-darwin";
21
21
  if (arch === "arm64") return "aarch64-apple-darwin";
22
- return "x86_64-apple-darwin"; // fallback
22
+ return "x86_64-apple-darwin";
23
23
  }
24
24
 
25
25
  throw new Error(`Unsupported platform: ${type} ${arch}`);
package/install.js CHANGED
@@ -1,38 +1,43 @@
1
- const https = require("https");
2
- const http = require("http");
3
- const fs = require("fs");
4
- const path = require("path");
5
- const os = require("os");
1
+ const fs = require("node:fs");
2
+ const os = require("node:os");
3
+ const path = require("node:path");
4
+ const https = require("node:https");
5
+ const http = require("node:http");
6
6
  const tar = require("tar");
7
+ const AdmZip = require("adm-zip");
8
+
7
9
  const { version } = require("./package.json");
8
10
 
9
- function getPlatform() {
11
+ function getPlatformTriple() {
10
12
  const type = os.type();
11
13
  const arch = os.arch();
12
14
 
13
15
  if (type === "Windows_NT") {
14
- return arch === "x64" ? "x86_64-pc-windows-msvc" : "i686-pc-windows-msvc";
16
+ if (arch === "x64") return "x86_64-pc-windows-gnu";
17
+ if (arch === "ia32") return "i686-pc-windows-gnu";
18
+ throw new Error(`Unsupported Windows architecture: ${arch}`);
15
19
  }
16
20
 
17
21
  if (type === "Linux") {
18
22
  if (arch === "x64") return "x86_64-unknown-linux-gnu";
19
23
  if (arch === "arm64") return "aarch64-unknown-linux-gnu";
20
- return "x86_64-unknown-linux-gnu"; // fallback
24
+ return "x86_64-unknown-linux-gnu";
21
25
  }
22
26
 
23
27
  if (type === "Darwin") {
24
28
  if (arch === "x64") return "x86_64-apple-darwin";
25
29
  if (arch === "arm64") return "aarch64-apple-darwin";
26
- return "x86_64-apple-darwin"; // fallback
30
+ return "x86_64-apple-darwin";
27
31
  }
28
32
 
29
33
  throw new Error(`Unsupported platform: ${type} ${arch}`);
30
34
  }
31
35
 
32
36
  function getBinaryUrl() {
33
- const platform = getPlatform();
37
+ const platform = getPlatformTriple();
34
38
  const baseUrl = `https://github.com/Goldziher/uncomment/releases/download/v${version}`;
35
- return `${baseUrl}/uncomment-${platform}.tar.gz`;
39
+ const ext = platform.includes("windows") ? "zip" : "tar.gz";
40
+ return `${baseUrl}/uncomment-${platform}.${ext}`;
36
41
  }
37
42
 
38
43
  function downloadWithRedirects(url, dest, maxRedirects = 5) {
@@ -52,7 +57,6 @@ function downloadWithRedirects(url, dest, maxRedirects = 5) {
52
57
  },
53
58
  },
54
59
  (res) => {
55
- // Handle redirects
56
60
  if (
57
61
  res.statusCode >= 300 &&
58
62
  res.statusCode < 400 &&
@@ -82,7 +86,7 @@ function downloadWithRedirects(url, dest, maxRedirects = 5) {
82
86
  });
83
87
 
84
88
  file.on("error", (err) => {
85
- fs.unlink(dest, () => {}); // Delete partial file
89
+ fs.unlink(dest, () => {});
86
90
  reject(err);
87
91
  });
88
92
  },
@@ -99,36 +103,50 @@ function downloadWithRedirects(url, dest, maxRedirects = 5) {
99
103
  async function installBinary() {
100
104
  try {
101
105
  const url = getBinaryUrl();
106
+ const isZip = url.endsWith(".zip");
102
107
  const binDir = path.join(__dirname, "bin");
103
- const tarPath = path.join(binDir, "uncomment.tar.gz");
108
+ const archivePath = path.join(
109
+ binDir,
110
+ isZip ? "uncomment.zip" : "uncomment.tar.gz",
111
+ );
104
112
  const binaryName =
105
113
  os.type() === "Windows_NT" ? "uncomment.exe" : "uncomment";
114
+ const binaryPath = path.join(binDir, binaryName);
106
115
 
107
- // Ensure bin directory exists
108
116
  if (!fs.existsSync(binDir)) {
109
117
  fs.mkdirSync(binDir, { recursive: true });
110
118
  }
111
119
 
120
+ if (fs.existsSync(binaryPath)) {
121
+ return;
122
+ }
123
+
112
124
  console.log(`Downloading uncomment binary from ${url}...`);
113
125
 
114
- // Download the tar.gz file
115
- await downloadWithRedirects(url, tarPath);
126
+ await downloadWithRedirects(url, archivePath);
116
127
 
117
128
  console.log("Extracting binary...");
118
129
 
119
- // Extract the binary from tar.gz
120
- await tar.extract({
121
- file: tarPath,
122
- cwd: binDir,
123
- filter: (path) => path.endsWith(binaryName),
124
- });
130
+ if (isZip) {
131
+ const zip = new AdmZip(archivePath);
132
+ const entry = zip
133
+ .getEntries()
134
+ .find((e) => e.entryName.endsWith(binaryName));
135
+ if (!entry) {
136
+ throw new Error("Binary not found in downloaded archive");
137
+ }
138
+ zip.extractEntryTo(entry, binDir, false, true);
139
+ } else {
140
+ await tar.extract({
141
+ file: archivePath,
142
+ cwd: binDir,
143
+ filter: (entryPath) => entryPath.endsWith(binaryName),
144
+ });
145
+ }
125
146
 
126
- // Clean up tar file
127
- fs.unlinkSync(tarPath);
147
+ fs.unlinkSync(archivePath);
128
148
 
129
- // Make binary executable on Unix systems
130
149
  if (os.type() !== "Windows_NT") {
131
- const binaryPath = path.join(binDir, binaryName);
132
150
  fs.chmodSync(binaryPath, 0o755);
133
151
  }
134
152
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uncomment-cli",
3
- "version": "2.9.2",
3
+ "version": "2.10.2",
4
4
  "description": "A fast Rust-based CLI tool for removing comments from source code",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -31,6 +31,7 @@
31
31
  "url": "https://github.com/Goldziher/uncomment/issues"
32
32
  },
33
33
  "dependencies": {
34
+ "adm-zip": "^0.5.12",
34
35
  "tar": "^6.0.0"
35
36
  },
36
37
  "files": [