dprint 0.33.0 → 0.34.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.
- package/bin.js +16 -16
- package/info.json +7 -6
- package/install_api.js +101 -29
- package/package.json +2 -1
package/bin.js
CHANGED
|
@@ -10,32 +10,32 @@ const exePath = path.join(__dirname, os.platform() === "win32" ? "dprint.exe" :
|
|
|
10
10
|
|
|
11
11
|
if (!fs.existsSync(exePath)) {
|
|
12
12
|
require("./install_api").runInstall().then(() => {
|
|
13
|
-
|
|
13
|
+
// I'm not sure why (I think due zip extraction), but the executable
|
|
14
|
+
// doesn't seem fully ready unless waiting for the next tick
|
|
15
|
+
setTimeout(() => {
|
|
16
|
+
runDprintExe();
|
|
17
|
+
}, 0);
|
|
14
18
|
}).catch(err => {
|
|
15
19
|
console.error(err);
|
|
16
|
-
process.exit(
|
|
20
|
+
process.exit(1);
|
|
17
21
|
});
|
|
18
22
|
} else {
|
|
19
23
|
runDprintExe();
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
function runDprintExe() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
27
|
+
const result = child_process.spawnSync(
|
|
28
|
+
exePath,
|
|
29
|
+
process.argv.slice(2),
|
|
30
|
+
{ stdio: "inherit" },
|
|
31
|
+
);
|
|
32
|
+
if (result.error) {
|
|
33
|
+
throw result.error;
|
|
34
|
+
}
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
throwIfNoExePath();
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
} catch (err) {
|
|
37
|
-
throw err;
|
|
38
|
-
}
|
|
38
|
+
process.exitCode = result.status;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function throwIfNoExePath() {
|
package/info.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.34.1",
|
|
3
3
|
"checksums": {
|
|
4
|
-
"windows-x86_64": "
|
|
5
|
-
"darwin-x86_64": "
|
|
6
|
-
"darwin-aarch64": "
|
|
7
|
-
"linux-x86_64": "
|
|
8
|
-
"linux-
|
|
4
|
+
"windows-x86_64": "a3a06a8d1a6a2801db11c605b603401c0e5ba8dbc0e65a55c666bdd89fbecddc",
|
|
5
|
+
"darwin-x86_64": "b7d1a456d34cffcf010820e3986b3ebd5d22614556a532dc57f4a25ed8bab6a1",
|
|
6
|
+
"darwin-aarch64": "1aae5c10fcdf4e554b8e75a0e2992eac731e15b8de0d9a2f6ed77d26524e5d5f",
|
|
7
|
+
"linux-x86_64-gnu": "43dd4bab71f3a70738670ef51f1e54c84b89405d9dfe5bec6ae5199ca20c93fe",
|
|
8
|
+
"linux-x86_64-musl": "dd5833178a7986acaeea8abbac687754f3ee7ce39371ac55c3e17113938027c9",
|
|
9
|
+
"linux-aarch64": "105c982071ae43c1e207231cd1516f714d29efd79d050f4415e3707d3baecd54"
|
|
9
10
|
}
|
|
10
11
|
}
|
package/install_api.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
-
const https = require("https");
|
|
5
|
-
const fs = require("fs");
|
|
6
4
|
const crypto = require("crypto");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const https = require("https");
|
|
7
7
|
const os = require("os");
|
|
8
8
|
const path = require("path");
|
|
9
|
+
const url = require("url");
|
|
10
|
+
const HttpsProxyAgent = require("https-proxy-agent");
|
|
9
11
|
const yauzl = require("yauzl");
|
|
12
|
+
/** @type {string | undefined} */
|
|
13
|
+
let cachedIsMusl = undefined;
|
|
10
14
|
|
|
11
15
|
function install() {
|
|
12
16
|
const executableFilePath = path.join(
|
|
@@ -22,7 +26,7 @@ function install() {
|
|
|
22
26
|
const zipFilePath = path.join(__dirname, "dprint.zip");
|
|
23
27
|
|
|
24
28
|
const target = getTarget();
|
|
25
|
-
const
|
|
29
|
+
const downloadUrl = "https://github.com/dprint/dprint/releases/download/"
|
|
26
30
|
+ info.version
|
|
27
31
|
+ "/dprint-" + target + ".zip";
|
|
28
32
|
|
|
@@ -34,7 +38,7 @@ function install() {
|
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
// now try to download it
|
|
37
|
-
return downloadZipFileWithRetries(
|
|
41
|
+
return downloadZipFileWithRetries(downloadUrl).then(() => {
|
|
38
42
|
verifyZipChecksum();
|
|
39
43
|
return extractZipFile().then(() => {
|
|
40
44
|
// todo: how to just +x? does it matter?
|
|
@@ -57,21 +61,9 @@ function install() {
|
|
|
57
61
|
if (os.platform() === "win32") {
|
|
58
62
|
return "x86_64-pc-windows-msvc";
|
|
59
63
|
} else if (os.platform() === "darwin") {
|
|
60
|
-
|
|
61
|
-
return "aarch64-apple-darwin";
|
|
62
|
-
} else if (os.arch() === "x64") {
|
|
63
|
-
return "x86_64-apple-darwin";
|
|
64
|
-
} else {
|
|
65
|
-
throw new Error("Unsupported architecture " + os.arch() + ". Only x64 and M1 binaries are available.");
|
|
66
|
-
}
|
|
64
|
+
return `${getArch()}-apple-darwin`;
|
|
67
65
|
} else {
|
|
68
|
-
|
|
69
|
-
return "aarch64-unknown-linux-gnu";
|
|
70
|
-
} else if (os.arch() === "x64") {
|
|
71
|
-
return "x86_64-unknown-linux-gnu";
|
|
72
|
-
} else {
|
|
73
|
-
throw new Error("Unsupported architecture " + os.arch() + ". Only x64 and aarch64 binaries are available.");
|
|
74
|
-
}
|
|
66
|
+
return `${getArch()}-unknown-linux-${getLinuxFamily()}`;
|
|
75
67
|
}
|
|
76
68
|
}
|
|
77
69
|
|
|
@@ -95,7 +87,13 @@ function install() {
|
|
|
95
87
|
|
|
96
88
|
function downloadZipFile(url) {
|
|
97
89
|
return new Promise((resolve, reject) => {
|
|
98
|
-
|
|
90
|
+
const options = {};
|
|
91
|
+
const proxyUrl = getProxyUrl(url);
|
|
92
|
+
if (proxyUrl != null) {
|
|
93
|
+
options.agent = new HttpsProxyAgent(proxyUrl);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
https.get(url, options, function(response) {
|
|
99
97
|
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
|
100
98
|
downloadResponse(response).then(resolve).catch(reject);
|
|
101
99
|
} else if (response.headers.location) {
|
|
@@ -131,6 +129,26 @@ function install() {
|
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
131
|
|
|
132
|
+
function getProxyUrl(requestUrl) {
|
|
133
|
+
try {
|
|
134
|
+
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
|
|
135
|
+
if (typeof proxyUrl !== "string" || proxyUrl.length === 0) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
if (typeof process.env.NO_PROXY === "string") {
|
|
139
|
+
const noProxyAddresses = process.env.NO_PROXY.split(",");
|
|
140
|
+
const host = url.parse(requestUrl).host;
|
|
141
|
+
if (noProxyAddresses.indexOf(host) >= 0) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return proxyUrl;
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.error("[dprint]: Error getting proxy url.", err);
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
134
152
|
function verifyZipChecksum() {
|
|
135
153
|
const fileData = fs.readFileSync(zipFilePath);
|
|
136
154
|
const actualZipChecksum = crypto.createHash("sha256").update(fileData).digest("hex").toLowerCase();
|
|
@@ -151,17 +169,9 @@ function install() {
|
|
|
151
169
|
case "win32":
|
|
152
170
|
return info.checksums["windows-x86_64"];
|
|
153
171
|
case "darwin":
|
|
154
|
-
|
|
155
|
-
return info.checksums["darwin-aarch64"];
|
|
156
|
-
} else {
|
|
157
|
-
return info.checksums["darwin-x86_64"];
|
|
158
|
-
}
|
|
172
|
+
return info.checksums[`darwin-${getArch()}`];
|
|
159
173
|
default:
|
|
160
|
-
|
|
161
|
-
return info.checksums["linux-aarch64"];
|
|
162
|
-
} else {
|
|
163
|
-
return info.checksums["linux-x86_64"];
|
|
164
|
-
}
|
|
174
|
+
return info.checksums[`linux-${getArch()}-${getLinuxFamily()}`];
|
|
165
175
|
}
|
|
166
176
|
}
|
|
167
177
|
}
|
|
@@ -211,6 +221,68 @@ function install() {
|
|
|
211
221
|
});
|
|
212
222
|
});
|
|
213
223
|
}
|
|
224
|
+
|
|
225
|
+
function getArch() {
|
|
226
|
+
if (os.arch() === "arm64") {
|
|
227
|
+
return "aarch64";
|
|
228
|
+
} else if (os.arch() === "x64") {
|
|
229
|
+
return "x86_64";
|
|
230
|
+
} else {
|
|
231
|
+
throw new Error("Unsupported architecture " + os.arch() + ". Only x64 and aarch64 binaries are available.");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function getLinuxFamily() {
|
|
236
|
+
return getIsMusl() ? "musl" : "gnu";
|
|
237
|
+
|
|
238
|
+
function getIsMusl() {
|
|
239
|
+
// code adapted from https://github.com/lovell/detect-libc
|
|
240
|
+
// Copyright Apache 2.0 license, the detect-libc maintainers
|
|
241
|
+
if (cachedIsMusl == null) {
|
|
242
|
+
cachedIsMusl = innerGet();
|
|
243
|
+
}
|
|
244
|
+
return cachedIsMusl;
|
|
245
|
+
|
|
246
|
+
function innerGet() {
|
|
247
|
+
try {
|
|
248
|
+
if (os.platform() !== "linux") {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
return isProcessReportMusl() || isConfMusl();
|
|
252
|
+
} catch (err) {
|
|
253
|
+
// just in case
|
|
254
|
+
console.warn("Error checking if musl.", err);
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function isProcessReportMusl() {
|
|
260
|
+
if (!process.report) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
const report = process.report.getReport();
|
|
264
|
+
if (!report || !(report.sharedObjects instanceof Array)) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
return report.sharedObjects.some(o => o.includes("libc.musl-") || o.includes("ld-musl-"));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function isConfMusl() {
|
|
271
|
+
const output = getCommandOutput();
|
|
272
|
+
const [_, ldd1] = output.split(/[\r\n]+/);
|
|
273
|
+
return ldd1 && ldd1.includes("musl");
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function getCommandOutput() {
|
|
277
|
+
try {
|
|
278
|
+
const command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true";
|
|
279
|
+
return require("child_process").execSync(command, { encoding: "utf8" });
|
|
280
|
+
} catch (_err) {
|
|
281
|
+
return "";
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
214
286
|
}
|
|
215
287
|
|
|
216
288
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dprint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.1",
|
|
4
4
|
"description": "Pluggable and configurable code formatting platform written in Rust.",
|
|
5
5
|
"bin": "bin.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/dprint/dprint#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"https-proxy-agent": "=5.0.1",
|
|
24
25
|
"yauzl": "=2.10.0"
|
|
25
26
|
}
|
|
26
27
|
}
|