dprint 0.37.1 → 0.38.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 +10 -9
- package/install_api.js +69 -267
- package/package.json +9 -8
- package/info.json +0 -11
- package/install.js +0 -4
package/bin.js
CHANGED
|
@@ -9,16 +9,17 @@ const fs = require("fs");
|
|
|
9
9
|
const exePath = path.join(__dirname, os.platform() === "win32" ? "dprint.exe" : "dprint");
|
|
10
10
|
|
|
11
11
|
if (!fs.existsSync(exePath)) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
try {
|
|
13
|
+
require("./install_api").runInstall();
|
|
14
|
+
runDprintExe();
|
|
15
|
+
} catch (err) {
|
|
16
|
+
if (err !== undefined && typeof err.message === "string") {
|
|
17
|
+
console.error(err.message);
|
|
18
|
+
} else {
|
|
19
|
+
console.error(err);
|
|
20
|
+
}
|
|
20
21
|
process.exit(1);
|
|
21
|
-
}
|
|
22
|
+
}
|
|
22
23
|
} else {
|
|
23
24
|
runDprintExe();
|
|
24
25
|
}
|
package/install_api.js
CHANGED
|
@@ -1,303 +1,105 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
-
const crypto = require("crypto");
|
|
5
4
|
const fs = require("fs");
|
|
6
|
-
const https = require("https");
|
|
7
5
|
const os = require("os");
|
|
8
6
|
const path = require("path");
|
|
9
|
-
const url = require("url");
|
|
10
|
-
const HttpsProxyAgent = require("https-proxy-agent");
|
|
11
|
-
const yauzl = require("yauzl");
|
|
12
7
|
/** @type {string | undefined} */
|
|
13
8
|
let cachedIsMusl = undefined;
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const info = JSON.parse(fs.readFileSync(path.join(__dirname, "info.json"), "utf8"));
|
|
26
|
-
const zipFilePath = path.join(__dirname, "dprint.zip");
|
|
27
|
-
|
|
28
|
-
const target = getTarget();
|
|
29
|
-
const downloadUrl = "https://github.com/dprint/dprint/releases/download/"
|
|
30
|
-
+ info.version
|
|
31
|
-
+ "/dprint-" + target + ".zip";
|
|
32
|
-
|
|
33
|
-
// remove the old zip file if it exists
|
|
34
|
-
try {
|
|
35
|
-
fs.unlinkSync(zipFilePath);
|
|
36
|
-
} catch (err) {
|
|
37
|
-
// ignore
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// now try to download it
|
|
41
|
-
return downloadZipFileWithRetries(downloadUrl).then(() => {
|
|
42
|
-
verifyZipChecksum();
|
|
43
|
-
return extractZipFile().then(() => {
|
|
44
|
-
// todo: how to just +x? does it matter?
|
|
45
|
-
fs.chmodSync(executableFilePath, 0o755);
|
|
46
|
-
|
|
47
|
-
// delete the zip file
|
|
48
|
-
try {
|
|
49
|
-
fs.unlinkSync(zipFilePath);
|
|
50
|
-
} catch (err) {
|
|
51
|
-
// ignore
|
|
52
|
-
}
|
|
53
|
-
}).catch(err => {
|
|
54
|
-
throw new Error("Error extracting dprint zip file.\n\n" + err);
|
|
55
|
-
});
|
|
56
|
-
}).catch(err => {
|
|
57
|
-
throw new Error("Error downloading dprint zip file.\n\n" + err);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
function getTarget() {
|
|
61
|
-
if (os.platform() === "win32") {
|
|
62
|
-
return "x86_64-pc-windows-msvc";
|
|
63
|
-
} else if (os.platform() === "darwin") {
|
|
64
|
-
return `${getArch()}-apple-darwin`;
|
|
65
|
-
} else {
|
|
66
|
-
return `${getArch()}-unknown-linux-${getLinuxFamily()}`;
|
|
10
|
+
module.exports = {
|
|
11
|
+
runInstall() {
|
|
12
|
+
const dprintFileName = os.platform() === "win32" ? "dprint.exe" : "dprint";
|
|
13
|
+
const executableFilePath = path.join(
|
|
14
|
+
__dirname,
|
|
15
|
+
dprintFileName,
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
if (fs.existsSync(executableFilePath)) {
|
|
19
|
+
return Promise.resolve();
|
|
67
20
|
}
|
|
68
|
-
}
|
|
69
21
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
});
|
|
22
|
+
const target = getTarget();
|
|
23
|
+
const targetPackagePath = path.dirname(require.resolve("@dprint/" + target + "/package.json"));
|
|
24
|
+
const executablePath = path.join(targetPackagePath, dprintFileName);
|
|
25
|
+
if (!fs.existsSync(executablePath)) {
|
|
26
|
+
throw new Error("Could not find executable for @dprint/" + target + " at " + executablePath);
|
|
27
|
+
}
|
|
28
|
+
fs.copyFileSync(executablePath, executableFilePath);
|
|
29
|
+
if (os.platform() !== "win32") {
|
|
30
|
+
// chomd +x
|
|
31
|
+
const perms = fs.statSync(executableFilePath).mode;
|
|
32
|
+
fs.chmodSync(executableFilePath, perms | 0o111);
|
|
83
33
|
}
|
|
84
34
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return new Promise((resolve, reject) => {
|
|
90
|
-
const options = {};
|
|
91
|
-
const proxyUrl = getProxyUrl(url);
|
|
92
|
-
if (proxyUrl != null) {
|
|
93
|
-
options.agent = new HttpsProxyAgent(proxyUrl);
|
|
35
|
+
function getTarget() {
|
|
36
|
+
const platform = os.platform();
|
|
37
|
+
if (platform === "linux") {
|
|
38
|
+
return platform + "-" + getArch() + "-" + getLinuxFamily();
|
|
94
39
|
} else {
|
|
95
|
-
|
|
96
|
-
// that prevents the process from exiting. Work around this by explicitly
|
|
97
|
-
// disabling keepAlive.
|
|
98
|
-
//
|
|
99
|
-
// See: https://github.com/nodejs/node/issues/47228
|
|
100
|
-
options.agent = new https.Agent({ keepAlive: false });
|
|
40
|
+
return platform + "-" + getArch();
|
|
101
41
|
}
|
|
102
|
-
|
|
103
|
-
https.get(url, options, function(response) {
|
|
104
|
-
if (response.statusCode != null && response.statusCode >= 200 && response.statusCode <= 299) {
|
|
105
|
-
downloadResponse(response).then(resolve).catch(reject);
|
|
106
|
-
} else if (response.headers.location) {
|
|
107
|
-
downloadZipFile(response.headers.location).then(resolve).catch(reject);
|
|
108
|
-
} else {
|
|
109
|
-
reject(new Error("Unknown status code " + response.statusCode + " : " + response.statusMessage));
|
|
110
|
-
}
|
|
111
|
-
}).on("error", function(err) {
|
|
112
|
-
try {
|
|
113
|
-
fs.unlinkSync(zipFilePath);
|
|
114
|
-
} catch (err) {
|
|
115
|
-
// ignore
|
|
116
|
-
}
|
|
117
|
-
reject(err);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
/** @param response {import("http").IncomingMessage} */
|
|
122
|
-
function downloadResponse(response) {
|
|
123
|
-
return new Promise((resolve, reject) => {
|
|
124
|
-
const file = fs.createWriteStream(zipFilePath);
|
|
125
|
-
response.pipe(file);
|
|
126
|
-
file.on("finish", function() {
|
|
127
|
-
file.close((err) => {
|
|
128
|
-
if (err) {
|
|
129
|
-
reject(err);
|
|
130
|
-
} else {
|
|
131
|
-
resolve(undefined);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
42
|
}
|
|
137
|
-
}
|
|
138
43
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return undefined;
|
|
144
|
-
}
|
|
145
|
-
if (typeof process.env.NO_PROXY === "string") {
|
|
146
|
-
const noProxyAddresses = process.env.NO_PROXY.split(",");
|
|
147
|
-
const host = url.parse(requestUrl).host;
|
|
148
|
-
if (host == null || noProxyAddresses.indexOf(host) >= 0) {
|
|
149
|
-
return undefined;
|
|
150
|
-
}
|
|
44
|
+
function getArch() {
|
|
45
|
+
const arch = os.arch();
|
|
46
|
+
if (arch !== "arm64" && arch !== "x64") {
|
|
47
|
+
throw new Error("Unsupported architecture " + os.arch() + ". Only x64 and aarch64 binaries are available.");
|
|
151
48
|
}
|
|
152
|
-
return
|
|
153
|
-
} catch (err) {
|
|
154
|
-
console.error("[dprint]: Error getting proxy url.", err);
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function verifyZipChecksum() {
|
|
160
|
-
const fileData = fs.readFileSync(zipFilePath);
|
|
161
|
-
const actualZipChecksum = crypto.createHash("sha256").update(fileData).digest("hex").toLowerCase();
|
|
162
|
-
const expectedZipChecksum = getExpectedZipChecksum().toLowerCase();
|
|
163
|
-
|
|
164
|
-
if (actualZipChecksum !== expectedZipChecksum) {
|
|
165
|
-
throw new Error(
|
|
166
|
-
"Downloaded dprint zip checksum did not match the expected checksum (Actual: "
|
|
167
|
-
+ actualZipChecksum
|
|
168
|
-
+ ", Expected: "
|
|
169
|
-
+ expectedZipChecksum
|
|
170
|
-
+ ").",
|
|
171
|
-
);
|
|
49
|
+
return arch;
|
|
172
50
|
}
|
|
173
51
|
|
|
174
|
-
function
|
|
175
|
-
|
|
176
|
-
if (checksum == null) {
|
|
177
|
-
throw new Error("Could not find checksum for target: " + checksum);
|
|
178
|
-
}
|
|
179
|
-
return checksum;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
52
|
+
function getLinuxFamily() {
|
|
53
|
+
return getIsMusl() ? "musl" : "glibc";
|
|
182
54
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
reject(err);
|
|
189
|
-
return;
|
|
55
|
+
function getIsMusl() {
|
|
56
|
+
// code adapted from https://github.com/lovell/detect-libc
|
|
57
|
+
// Copyright Apache 2.0 license, the detect-libc maintainers
|
|
58
|
+
if (cachedIsMusl == null) {
|
|
59
|
+
cachedIsMusl = innerGet();
|
|
190
60
|
}
|
|
61
|
+
return cachedIsMusl;
|
|
191
62
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (err) {
|
|
203
|
-
reject(err);
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const destination = path.join(__dirname, entry.fileName);
|
|
207
|
-
const writeStream = fs.createWriteStream(destination);
|
|
208
|
-
readStream.pipe(writeStream);
|
|
209
|
-
|
|
210
|
-
writeStream.on("error", (err) => {
|
|
211
|
-
reject(err);
|
|
212
|
-
});
|
|
213
|
-
writeStream.on("finish", () => {
|
|
214
|
-
resolve(undefined);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
}),
|
|
218
|
-
);
|
|
63
|
+
function innerGet() {
|
|
64
|
+
try {
|
|
65
|
+
if (os.platform() !== "linux") {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return isProcessReportMusl() || isConfMusl();
|
|
69
|
+
} catch (err) {
|
|
70
|
+
// just in case
|
|
71
|
+
console.warn("Error checking if musl.", err);
|
|
72
|
+
return false;
|
|
219
73
|
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
zipFile.once("close", function() {
|
|
223
|
-
Promise.all(pendingWrites).then(resolve).catch(reject);
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function getArch() {
|
|
230
|
-
if (os.arch() === "arm64") {
|
|
231
|
-
return "aarch64";
|
|
232
|
-
} else if (os.arch() === "x64") {
|
|
233
|
-
return "x86_64";
|
|
234
|
-
} else {
|
|
235
|
-
throw new Error("Unsupported architecture " + os.arch() + ". Only x64 and aarch64 binaries are available.");
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function getLinuxFamily() {
|
|
240
|
-
return getIsMusl() ? "musl" : "gnu";
|
|
241
|
-
|
|
242
|
-
function getIsMusl() {
|
|
243
|
-
// code adapted from https://github.com/lovell/detect-libc
|
|
244
|
-
// Copyright Apache 2.0 license, the detect-libc maintainers
|
|
245
|
-
if (cachedIsMusl == null) {
|
|
246
|
-
cachedIsMusl = innerGet();
|
|
247
|
-
}
|
|
248
|
-
return cachedIsMusl;
|
|
74
|
+
}
|
|
249
75
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (os.platform() !== "linux") {
|
|
76
|
+
function isProcessReportMusl() {
|
|
77
|
+
if (!process.report) {
|
|
253
78
|
return false;
|
|
254
79
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
80
|
+
const rawReport = process.report.getReport();
|
|
81
|
+
const report = typeof rawReport === "string" ? JSON.parse(rawReport) : rawReport;
|
|
82
|
+
if (!report || !(report.sharedObjects instanceof Array)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return report.sharedObjects.some(o => o.includes("libc.musl-") || o.includes("ld-musl-"));
|
|
260
86
|
}
|
|
261
|
-
}
|
|
262
87
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const report = process.report.getReport();
|
|
268
|
-
if (!report || !(report.sharedObjects instanceof Array)) {
|
|
269
|
-
return false;
|
|
88
|
+
function isConfMusl() {
|
|
89
|
+
const output = getCommandOutput();
|
|
90
|
+
const [_, ldd1] = output.split(/[\r\n]+/);
|
|
91
|
+
return ldd1 && ldd1.includes("musl");
|
|
270
92
|
}
|
|
271
|
-
return report.sharedObjects.some(o => o.includes("libc.musl-") || o.includes("ld-musl-"));
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function isConfMusl() {
|
|
275
|
-
const output = getCommandOutput();
|
|
276
|
-
const [_, ldd1] = output.split(/[\r\n]+/);
|
|
277
|
-
return ldd1 && ldd1.includes("musl");
|
|
278
|
-
}
|
|
279
93
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
94
|
+
function getCommandOutput() {
|
|
95
|
+
try {
|
|
96
|
+
const command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true";
|
|
97
|
+
return require("child_process").execSync(command, { encoding: "utf8" });
|
|
98
|
+
} catch (_err) {
|
|
99
|
+
return "";
|
|
100
|
+
}
|
|
286
101
|
}
|
|
287
102
|
}
|
|
288
103
|
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
module.exports = {
|
|
293
|
-
runInstall() {
|
|
294
|
-
return install().catch(err => {
|
|
295
|
-
if (err !== undefined && typeof err.message === "string") {
|
|
296
|
-
console.error(err.message);
|
|
297
|
-
} else {
|
|
298
|
-
console.error(err);
|
|
299
|
-
}
|
|
300
|
-
process.exit(1);
|
|
301
|
-
});
|
|
302
104
|
},
|
|
303
105
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dprint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "Pluggable and configurable code formatting platform written in Rust.",
|
|
5
5
|
"bin": "bin.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"postinstall": "node ./install.js"
|
|
8
|
-
},
|
|
9
6
|
"repository": {
|
|
10
7
|
"type": "git",
|
|
11
8
|
"url": "git+https://github.com/dprint/dprint.git"
|
|
@@ -20,8 +17,12 @@
|
|
|
20
17
|
"url": "https://github.com/dprint/dprint/issues"
|
|
21
18
|
},
|
|
22
19
|
"homepage": "https://github.com/dprint/dprint#readme",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
20
|
+
"optionalDependencies": {
|
|
21
|
+
"@dprint/win32-x64": "0.38.0",
|
|
22
|
+
"@dprint/darwin-x64": "0.38.0",
|
|
23
|
+
"@dprint/darwin-arm64": "0.38.0",
|
|
24
|
+
"@dprint/linux-x64-glibc": "0.38.0",
|
|
25
|
+
"@dprint/linux-x64-musl": "0.38.0",
|
|
26
|
+
"@dprint/linux-arm64-glibc": "0.38.0"
|
|
26
27
|
}
|
|
27
|
-
}
|
|
28
|
+
}
|
package/info.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "0.37.1",
|
|
3
|
-
"checksums": {
|
|
4
|
-
"x86_64-pc-windows-msvc": "7f25e3cd03aeee23341174f50ceff7d09266d991298b44353883a98cb1b8f67e",
|
|
5
|
-
"x86_64-apple-darwin": "1de7aea5ead649d97c19814d856fab616965177cd77cccc998f4953aa3d8c7c4",
|
|
6
|
-
"aarch64-apple-darwin": "a2c5c7a61ae4ca51140779b1bcc2766d8fe0fad0589828752b29b172f20c083c",
|
|
7
|
-
"x86_64-unknown-linux-gnu": "a65e2dc853cf466ec1c682366cc1655029b7d180414ec53e0e0ecc37e503a28d",
|
|
8
|
-
"x86_64-unknown-linux-musl": "a8a824eed75f1030c721a7e91ae79cbd5f48f8c19470d92ec5fd0dff2715add6",
|
|
9
|
-
"aarch64-unknown-linux-gnu": "17d108c5b27df6233fa63c4f78b8b67c040cb3325a7372c9428da62f09ed8f61"
|
|
10
|
-
}
|
|
11
|
-
}
|
package/install.js
DELETED