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