dprint 0.26.0 → 0.28.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/info.json +5 -5
- package/install.js +154 -24
- package/package.json +5 -2
- package/install.ps1 +0 -33
- package/install.sh +0 -27
- package/install_verify_checksum.js +0 -38
package/info.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.28.0",
|
|
3
3
|
"checksums": {
|
|
4
|
-
"windows-x86_64": "
|
|
5
|
-
"darwin-x86_64": "
|
|
6
|
-
"darwin-aarch64": "
|
|
7
|
-
"linux-x86_64": "
|
|
4
|
+
"windows-x86_64": "7a9ebfdd87e31b67432315364430a4b07792bc1aa2ce21ef53b1eb92fcbf060a",
|
|
5
|
+
"darwin-x86_64": "ecabf3729a31f8d8c64d14e8ce841c1638f0b6a60bdc28c147a8462b6b9f1aad",
|
|
6
|
+
"darwin-aarch64": "3d05c3825cdaa3b091c7a768c06b432159f4eba56d6c0ddcf2632198c74afd7b",
|
|
7
|
+
"linux-x86_64": "c53ff412c826749a3ff7a1c13265bd2012e03130600868656bb3d43c23e9768c"
|
|
8
8
|
}
|
|
9
9
|
}
|
package/install.js
CHANGED
|
@@ -1,40 +1,170 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
const https = require("https");
|
|
4
5
|
const fs = require("fs");
|
|
6
|
+
const crypto = require("crypto");
|
|
5
7
|
const os = require("os");
|
|
6
8
|
const path = require("path");
|
|
7
|
-
const
|
|
9
|
+
const yauzl = require("yauzl");
|
|
10
|
+
|
|
8
11
|
const info = JSON.parse(fs.readFileSync(path.join(__dirname, "info.json"), "utf8"));
|
|
12
|
+
const executableFilePath = path.join(
|
|
13
|
+
__dirname,
|
|
14
|
+
os.platform() === "win32" ? "dprint.exe" : "dprint",
|
|
15
|
+
);
|
|
16
|
+
const zipFilePath = path.join(__dirname, "dprint.zip");
|
|
9
17
|
|
|
10
|
-
if (
|
|
11
|
-
|
|
18
|
+
if (fs.existsSync(executableFilePath)) {
|
|
19
|
+
process.exit(0);
|
|
12
20
|
}
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const target = getTarget();
|
|
23
|
+
const url = "https://github.com/dprint/dprint/releases/download/"
|
|
24
|
+
+ info.version
|
|
25
|
+
+ "/dprint-" + target + ".zip";
|
|
26
|
+
|
|
27
|
+
// remove the old zip file if it exists
|
|
28
|
+
try {
|
|
29
|
+
fs.unlinkSync(zipFilePath);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
// ignore
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// now try to download it
|
|
35
|
+
downloadZipFile(url).then(() => {
|
|
36
|
+
verifyZipChecksum();
|
|
37
|
+
extractZipFile().then(() => {
|
|
38
|
+
// todo: how to just +x? does it matter?
|
|
39
|
+
fs.chmodSync(executableFilePath, 0o755);
|
|
40
|
+
|
|
41
|
+
// delete the zip file
|
|
42
|
+
try {
|
|
43
|
+
fs.unlinkSync(zipFilePath);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
// ignore
|
|
46
|
+
}
|
|
47
|
+
}).catch(err => {
|
|
48
|
+
console.error("Error extracting dprint zip file.", err);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
});
|
|
51
|
+
}).catch(err => {
|
|
52
|
+
console.error("Error downloading dprint zip file.", err);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
function getTarget() {
|
|
57
|
+
if (os.platform() === "win32") {
|
|
58
|
+
return "x86_64-pc-windows-msvc";
|
|
59
|
+
} 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
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
return "x86_64-unknown-linux-gnu";
|
|
26
69
|
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function downloadZipFile(url) {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
https.get(url, function(response) {
|
|
75
|
+
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
|
76
|
+
downloadResponse(response).then(resolve).catch(reject);
|
|
77
|
+
} else if (response.headers.location) {
|
|
78
|
+
downloadZipFile(response.headers.location).then(resolve).catch(reject);
|
|
79
|
+
} else {
|
|
80
|
+
reject(new Error("Unknown status code " + response.statusCode + " : " + response.statusMessage));
|
|
81
|
+
}
|
|
82
|
+
}).on("error", function(err) {
|
|
83
|
+
try {
|
|
84
|
+
fs.unlinkSync(zipFilePath);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
// ignore
|
|
87
|
+
}
|
|
88
|
+
reject(err);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
/** @param response {import("http").IncomingMessage} */
|
|
93
|
+
function downloadResponse(response) {
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const file = fs.createWriteStream(zipFilePath);
|
|
96
|
+
response.pipe(file);
|
|
97
|
+
file.on("finish", function() {
|
|
98
|
+
file.close((err) => {
|
|
99
|
+
if (err) {
|
|
100
|
+
reject(err);
|
|
101
|
+
} else {
|
|
102
|
+
resolve();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
34
106
|
});
|
|
35
107
|
}
|
|
36
108
|
}
|
|
37
109
|
|
|
38
|
-
function
|
|
39
|
-
|
|
110
|
+
function verifyZipChecksum() {
|
|
111
|
+
const fileData = fs.readFileSync(zipFilePath);
|
|
112
|
+
const actualZipChecksum = crypto.createHash("sha256").update(fileData).digest("hex").toLowerCase();
|
|
113
|
+
const expectedZipChecksum = getExpectedZipChecksum().toLowerCase();
|
|
114
|
+
|
|
115
|
+
if (actualZipChecksum !== expectedZipChecksum) {
|
|
116
|
+
console.error(
|
|
117
|
+
"Downloaded dprint zip checksum did not match the expected checksum (Actual: "
|
|
118
|
+
+ actualZipChecksum
|
|
119
|
+
+ ", Expected: "
|
|
120
|
+
+ expectedZipChecksum
|
|
121
|
+
+ ").",
|
|
122
|
+
);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function getExpectedZipChecksum() {
|
|
127
|
+
switch (os.platform()) {
|
|
128
|
+
case "win32":
|
|
129
|
+
return info.checksums["windows-x86_64"];
|
|
130
|
+
case "darwin":
|
|
131
|
+
if (os.arch() === "arm64") {
|
|
132
|
+
return info.checksums["darwin-aarch64"];
|
|
133
|
+
} else {
|
|
134
|
+
return info.checksums["darwin-x86_64"];
|
|
135
|
+
}
|
|
136
|
+
default:
|
|
137
|
+
return info.checksums["linux-x86_64"];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function extractZipFile() {
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
|
+
// code adapted from: https://github.com/thejoshwolfe/yauzl#usage
|
|
145
|
+
yauzl.open(zipFilePath, { autoClose: true }, (err, zipFile) => {
|
|
146
|
+
if (err) {
|
|
147
|
+
reject(err);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
zipFile.on("entry", (entry) => {
|
|
152
|
+
if (!/\/$/.test(entry.fileName)) {
|
|
153
|
+
// file entry
|
|
154
|
+
zipFile.openReadStream(entry, (err, readStream) => {
|
|
155
|
+
if (err) {
|
|
156
|
+
reject(err);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const destination = path.join(__dirname, entry.fileName);
|
|
160
|
+
readStream.pipe(fs.createWriteStream(destination));
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
zipFile.once("close", function() {
|
|
166
|
+
resolve();
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
40
170
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dprint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Pluggable and configurable code formatting platform written in Rust.",
|
|
5
5
|
"bin": "bin.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,5 +19,8 @@
|
|
|
19
19
|
"bugs": {
|
|
20
20
|
"url": "https://github.com/dprint/dprint/issues"
|
|
21
21
|
},
|
|
22
|
-
"homepage": "https://github.com/dprint/dprint#readme"
|
|
22
|
+
"homepage": "https://github.com/dprint/dprint#readme",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"yauzl": "=2.10.0"
|
|
25
|
+
}
|
|
23
26
|
}
|
package/install.ps1
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env pwsh
|
|
2
|
-
|
|
3
|
-
$ErrorActionPreference = 'Stop'
|
|
4
|
-
|
|
5
|
-
$Version = $args.Get(0)
|
|
6
|
-
$DprintZip = "dprint.zip"
|
|
7
|
-
$DprintExe = "dprint.exe"
|
|
8
|
-
$Target = 'x86_64-pc-windows-msvc'
|
|
9
|
-
$DprintUri = "https://github.com/dprint/dprint/releases/download/$Version/dprint-${Target}.zip"
|
|
10
|
-
|
|
11
|
-
# GitHub requires TLS 1.2
|
|
12
|
-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
13
|
-
|
|
14
|
-
# download zip
|
|
15
|
-
Invoke-WebRequest $DprintUri -OutFile $DprintZip -UseBasicParsing
|
|
16
|
-
|
|
17
|
-
# verify zip checksum
|
|
18
|
-
& node install_verify_checksum.js
|
|
19
|
-
if ($LASTEXITCODE -ne 0) { throw "[dprint]: Checksum verification failed." }
|
|
20
|
-
|
|
21
|
-
# extract executable
|
|
22
|
-
if (Get-Command Expand-Archive -ErrorAction SilentlyContinue) {
|
|
23
|
-
Expand-Archive $DprintZip -Destination $PSScriptRoot -Force
|
|
24
|
-
} else {
|
|
25
|
-
if (Test-Path $DprintExe) {
|
|
26
|
-
Remove-Item $DprintExe
|
|
27
|
-
}
|
|
28
|
-
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
29
|
-
[IO.Compression.ZipFile]::ExtractToDirectory($DprintZip)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
# remove zip
|
|
33
|
-
Remove-Item $DprintZip
|
package/install.sh
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
set -e
|
|
3
|
-
|
|
4
|
-
if ! command -v unzip >/dev/null; then
|
|
5
|
-
echo "Error: unzip is required to install dprint." 1>&2
|
|
6
|
-
exit 1
|
|
7
|
-
fi
|
|
8
|
-
|
|
9
|
-
case $(uname -sm) in
|
|
10
|
-
"Darwin x86_64") target="x86_64-apple-darwin" ;;
|
|
11
|
-
"Darwin arm64") target="aarch64-apple-darwin" ;;
|
|
12
|
-
*) target="x86_64-unknown-linux-gnu" ;;
|
|
13
|
-
esac
|
|
14
|
-
|
|
15
|
-
dprint_uri="https://github.com/dprint/dprint/releases/download/${1}/dprint-${target}.zip"
|
|
16
|
-
exe="dprint"
|
|
17
|
-
|
|
18
|
-
# download
|
|
19
|
-
curl --fail --location --progress-bar --output "$exe.zip" "$dprint_uri"
|
|
20
|
-
|
|
21
|
-
# verify zip checksum
|
|
22
|
-
node install_verify_checksum.js
|
|
23
|
-
|
|
24
|
-
# unzip
|
|
25
|
-
unzip -o "$exe.zip"
|
|
26
|
-
chmod +x "$exe"
|
|
27
|
-
rm "$exe.zip"
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const crypto = require("crypto");
|
|
6
|
-
const os = require("os");
|
|
7
|
-
const path = require("path");
|
|
8
|
-
|
|
9
|
-
const info = JSON.parse(fs.readFileSync(path.join(__dirname, "info.json"), "utf8"));
|
|
10
|
-
const fileData = fs.readFileSync("dprint.zip");
|
|
11
|
-
const actualZipChecksum = crypto.createHash("sha256").update(fileData).digest("hex").toLowerCase();
|
|
12
|
-
const expectedZipChecksum = getExpectedZipChecksum().toLowerCase();
|
|
13
|
-
|
|
14
|
-
if (actualZipChecksum !== expectedZipChecksum) {
|
|
15
|
-
console.error(
|
|
16
|
-
"Downloaded dprint zip checksum did not match the expected checksum (Actual: "
|
|
17
|
-
+ actualZipChecksum
|
|
18
|
-
+ ", Expected: "
|
|
19
|
-
+ expectedZipChecksum
|
|
20
|
-
+ ").",
|
|
21
|
-
);
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getExpectedZipChecksum() {
|
|
26
|
-
switch (os.platform()) {
|
|
27
|
-
case "win32":
|
|
28
|
-
return info.checksums["windows-x86_64"];
|
|
29
|
-
case "darwin":
|
|
30
|
-
if (os.arch() === "arm64") {
|
|
31
|
-
return info.checksums["darwin-aarch64"];
|
|
32
|
-
} else {
|
|
33
|
-
return info.checksums["darwin-x86_64"];
|
|
34
|
-
}
|
|
35
|
-
default:
|
|
36
|
-
return info.checksums["linux-x86_64"];
|
|
37
|
-
}
|
|
38
|
-
}
|