dprint 0.33.0 → 0.34.0

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 CHANGED
@@ -13,29 +13,25 @@ if (!fs.existsSync(exePath)) {
13
13
  runDprintExe();
14
14
  }).catch(err => {
15
15
  console.error(err);
16
- process.exit(child_process.exitCode || 1);
16
+ process.exit(1);
17
17
  });
18
18
  } else {
19
19
  runDprintExe();
20
20
  }
21
21
 
22
22
  function runDprintExe() {
23
- try {
24
- const result = child_process.spawnSync(
25
- exePath,
26
- process.argv.slice(2),
27
- { stdio: "inherit" },
28
- );
29
- if (result.error) {
30
- throw result.error;
31
- }
23
+ const result = child_process.spawnSync(
24
+ exePath,
25
+ process.argv.slice(2),
26
+ { stdio: "inherit" },
27
+ );
28
+ if (result.error) {
29
+ throw result.error;
30
+ }
32
31
 
33
- throwIfNoExePath();
32
+ throwIfNoExePath();
34
33
 
35
- process.exitCode = result.status;
36
- } catch (err) {
37
- throw err;
38
- }
34
+ process.exitCode = result.status;
39
35
  }
40
36
 
41
37
  function throwIfNoExePath() {
package/info.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
- "version": "0.33.0",
2
+ "version": "0.34.0",
3
3
  "checksums": {
4
- "windows-x86_64": "98d3e6616e23cb9b2a969975b9c34b4b571e40725b0348d19cebedcb9c584be5",
5
- "darwin-x86_64": "d4b502bb00bd4e3e19657092648883e8d8270de32f61a0ff78af7709dc70b9b2",
6
- "darwin-aarch64": "df3a99c68d7229125040e720990d70fcec0e16b64e7ccba266f5771e2e9e7edd",
7
- "linux-x86_64": "77c52e21df129e96a7860163029e267f38e705bc7be014b79668ad15f6e0c8e2",
8
- "linux-aarch64": "9762ae7b175d68d853daed32a17580b0662a3a46402053d1770ee6e7f355b2e5"
4
+ "windows-x86_64": "29da4f68d07cab10d0d90fdcf671c3ccdda15503ac5aa5c23c72534064b0e0b4",
5
+ "darwin-x86_64": "e9907275ab476897a72f99e279f137df0cea81b63a78da9367d3027ff072b18e",
6
+ "darwin-aarch64": "21a43b89adc42fc563371b6807642c8eb8669e75471a57bef67de99bd1bb7b75",
7
+ "linux-x86_64-gnu": "9bf233635ed8f0871fa7285ab40ea78c9216650073ad25ffec097b57738da268",
8
+ "linux-x86_64-musl": "227572fbcb761310dd21c2286fdc56a033f408919706895f7bf3913f241cf63a",
9
+ "linux-aarch64": "ef75ba1e02064a1f22184aab1888d0040e795e996c27c5339694e45cbad0500e"
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(
@@ -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
- if (os.arch() === "arm64") {
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
- if (os.arch() === "arm64") {
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
- https.get(url, function(response) {
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,21 @@ function install() {
131
129
  }
132
130
  }
133
131
 
132
+ function getProxyUrl(requestUrl) {
133
+ const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
134
+ if (typeof proxyUrl !== "string" || proxyUrl.length === 0) {
135
+ return undefined;
136
+ }
137
+ if (typeof process.env.NO_PROXY === "string") {
138
+ const noProxyAddresses = process.env.NO_PROXY.split(",");
139
+ const host = url.parse(requestUrl).host;
140
+ if (noProxyAddresses.indexOf(host) >= 0) {
141
+ return undefined;
142
+ }
143
+ }
144
+ return proxyUrl;
145
+ }
146
+
134
147
  function verifyZipChecksum() {
135
148
  const fileData = fs.readFileSync(zipFilePath);
136
149
  const actualZipChecksum = crypto.createHash("sha256").update(fileData).digest("hex").toLowerCase();
@@ -151,17 +164,9 @@ function install() {
151
164
  case "win32":
152
165
  return info.checksums["windows-x86_64"];
153
166
  case "darwin":
154
- if (os.arch() === "arm64") {
155
- return info.checksums["darwin-aarch64"];
156
- } else {
157
- return info.checksums["darwin-x86_64"];
158
- }
167
+ return info.checksums[`darwin-${getArch()}`];
159
168
  default:
160
- if (os.arch() === "arm64") {
161
- return info.checksums["linux-aarch64"];
162
- } else {
163
- return info.checksums["linux-x86_64"];
164
- }
169
+ return info.checksums[`linux-${getArch()}-${getLinuxFamily()}`];
165
170
  }
166
171
  }
167
172
  }
@@ -211,6 +216,68 @@ function install() {
211
216
  });
212
217
  });
213
218
  }
219
+
220
+ function getArch() {
221
+ if (os.arch() === "arm64") {
222
+ return "aarch64";
223
+ } else if (os.arch() === "x64") {
224
+ return "x86_64";
225
+ } else {
226
+ throw new Error("Unsupported architecture " + os.arch() + ". Only x64 and aarch64 binaries are available.");
227
+ }
228
+ }
229
+
230
+ function getLinuxFamily() {
231
+ return getIsMusl() ? "musl" : "gnu";
232
+
233
+ function getIsMusl() {
234
+ // code adapted from https://github.com/lovell/detect-libc
235
+ // Copyright Apache 2.0 license, the detect-libc maintainers
236
+ if (cachedIsMusl == null) {
237
+ cachedIsMusl = innerGet();
238
+ }
239
+ return cachedIsMusl;
240
+
241
+ function innerGet() {
242
+ try {
243
+ if (os.platform() !== "linux") {
244
+ return false;
245
+ }
246
+ return isProcessReportMusl() || isConfMusl();
247
+ } catch (err) {
248
+ // just in case
249
+ console.warn("Error checking if musl.", err);
250
+ return false;
251
+ }
252
+ }
253
+
254
+ function isProcessReportMusl() {
255
+ if (!process.report) {
256
+ return false;
257
+ }
258
+ const report = process.report.getReport();
259
+ if (!report || !(report.sharedObjects instanceof Array)) {
260
+ return false;
261
+ }
262
+ return report.sharedObjects.some(o => o.includes("libc.musl-") || o.includes("ld-musl-"));
263
+ }
264
+
265
+ function isConfMusl() {
266
+ const output = getCommandOutput();
267
+ const [_, ldd1] = output.split(/[\r\n]+/);
268
+ return ldd1 && ldd1.includes("musl");
269
+ }
270
+
271
+ function getCommandOutput() {
272
+ try {
273
+ const command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true";
274
+ return require("child_process").execSync(command, { encoding: "utf8" });
275
+ } catch (_err) {
276
+ return "";
277
+ }
278
+ }
279
+ }
280
+ }
214
281
  }
215
282
 
216
283
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dprint",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
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
  }