dprint 0.38.0 → 0.38.2
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 +9 -8
- package/install_api.js +107 -72
- package/package.json +8 -7
package/bin.js
CHANGED
|
@@ -10,8 +10,8 @@ const exePath = path.join(__dirname, os.platform() === "win32" ? "dprint.exe" :
|
|
|
10
10
|
|
|
11
11
|
if (!fs.existsSync(exePath)) {
|
|
12
12
|
try {
|
|
13
|
-
require("./install_api").runInstall();
|
|
14
|
-
runDprintExe();
|
|
13
|
+
const resolvedExePath = require("./install_api").runInstall();
|
|
14
|
+
runDprintExe(resolvedExePath);
|
|
15
15
|
} catch (err) {
|
|
16
16
|
if (err !== undefined && typeof err.message === "string") {
|
|
17
17
|
console.error(err.message);
|
|
@@ -21,10 +21,11 @@ if (!fs.existsSync(exePath)) {
|
|
|
21
21
|
process.exit(1);
|
|
22
22
|
}
|
|
23
23
|
} else {
|
|
24
|
-
runDprintExe();
|
|
24
|
+
runDprintExe(exePath);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
/** @param exePath {string} */
|
|
28
|
+
function runDprintExe(exePath) {
|
|
28
29
|
const result = child_process.spawnSync(
|
|
29
30
|
exePath,
|
|
30
31
|
process.argv.slice(2),
|
|
@@ -37,10 +38,10 @@ function runDprintExe() {
|
|
|
37
38
|
throwIfNoExePath();
|
|
38
39
|
|
|
39
40
|
process.exitCode = result.status;
|
|
40
|
-
}
|
|
41
41
|
|
|
42
|
-
function throwIfNoExePath() {
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
function throwIfNoExePath() {
|
|
43
|
+
if (!fs.existsSync(exePath)) {
|
|
44
|
+
throw new Error("Could not find exe at path '" + exePath + "'. Maybe try running dprint again.");
|
|
45
|
+
}
|
|
45
46
|
}
|
|
46
47
|
}
|
package/install_api.js
CHANGED
|
@@ -10,96 +10,131 @@ let cachedIsMusl = undefined;
|
|
|
10
10
|
module.exports = {
|
|
11
11
|
runInstall() {
|
|
12
12
|
const dprintFileName = os.platform() === "win32" ? "dprint.exe" : "dprint";
|
|
13
|
-
const
|
|
13
|
+
const targetExecutablePath = path.join(
|
|
14
14
|
__dirname,
|
|
15
15
|
dprintFileName,
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
-
if (fs.existsSync(
|
|
19
|
-
return
|
|
18
|
+
if (fs.existsSync(targetExecutablePath)) {
|
|
19
|
+
return targetExecutablePath;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const target = getTarget();
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
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);
|
|
23
|
+
const sourcePackagePath = path.dirname(require.resolve("@dprint/" + target + "/package.json"));
|
|
24
|
+
const sourceExecutablePath = path.join(sourcePackagePath, dprintFileName);
|
|
25
|
+
|
|
26
|
+
if (!fs.existsSync(sourceExecutablePath)) {
|
|
27
|
+
throw new Error("Could not find executable for @dprint/" + target + " at " + sourceExecutablePath);
|
|
33
28
|
}
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} else {
|
|
40
|
-
return platform + "-" + getArch();
|
|
30
|
+
try {
|
|
31
|
+
if (process.env.DPRINT_SIMULATED_READONLY_FILE_SYSTEM === "1") {
|
|
32
|
+
console.warn("Simulating readonly file system for testing.");
|
|
33
|
+
throw new Error("Throwing for testing purposes.");
|
|
41
34
|
}
|
|
42
|
-
}
|
|
43
35
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
// in order to make things faster the next time we run, copy the
|
|
37
|
+
// executable into the dprint package folder
|
|
38
|
+
fs.copyFileSync(sourceExecutablePath, targetExecutablePath);
|
|
39
|
+
if (os.platform() !== "win32") {
|
|
40
|
+
// chomd +x
|
|
41
|
+
chmodX(targetExecutablePath);
|
|
48
42
|
}
|
|
49
|
-
return
|
|
43
|
+
return targetExecutablePath;
|
|
44
|
+
} catch (err) {
|
|
45
|
+
// this may fail on readonly file systems... in this case, fall
|
|
46
|
+
// back to using the resolved package path
|
|
47
|
+
if (process.env.DPRINT_DEBUG === "1") {
|
|
48
|
+
console.warn(
|
|
49
|
+
"Failed to copy executable from "
|
|
50
|
+
+ sourceExecutablePath + " to " + targetExecutablePath
|
|
51
|
+
+ ". Using resolved package path instead.",
|
|
52
|
+
err,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
// use the path found in the specific package
|
|
56
|
+
try {
|
|
57
|
+
chmodX(sourceExecutablePath);
|
|
58
|
+
} catch (_err) {
|
|
59
|
+
// ignore
|
|
60
|
+
}
|
|
61
|
+
return sourceExecutablePath;
|
|
50
62
|
}
|
|
63
|
+
},
|
|
64
|
+
};
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
/** @filePath {string} */
|
|
67
|
+
function chmodX(filePath) {
|
|
68
|
+
const perms = fs.statSync(filePath).mode;
|
|
69
|
+
fs.chmodSync(filePath, perms | 0o111);
|
|
70
|
+
}
|
|
54
71
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
72
|
+
function getTarget() {
|
|
73
|
+
const platform = os.platform();
|
|
74
|
+
if (platform === "linux") {
|
|
75
|
+
return platform + "-" + getArch() + "-" + getLinuxFamily();
|
|
76
|
+
} else {
|
|
77
|
+
return platform + "-" + getArch();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
75
80
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
return report.sharedObjects.some(o => o.includes("libc.musl-") || o.includes("ld-musl-"));
|
|
86
|
-
}
|
|
81
|
+
function getArch() {
|
|
82
|
+
const arch = os.arch();
|
|
83
|
+
if (arch !== "arm64" && arch !== "x64") {
|
|
84
|
+
throw new Error("Unsupported architecture " + os.arch() + ". Only x64 and aarch64 binaries are available.");
|
|
85
|
+
}
|
|
86
|
+
return arch;
|
|
87
|
+
}
|
|
87
88
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
function getLinuxFamily() {
|
|
90
|
+
return getIsMusl() ? "musl" : "glibc";
|
|
91
|
+
|
|
92
|
+
function getIsMusl() {
|
|
93
|
+
// code adapted from https://github.com/lovell/detect-libc
|
|
94
|
+
// Copyright Apache 2.0 license, the detect-libc maintainers
|
|
95
|
+
if (cachedIsMusl == null) {
|
|
96
|
+
cachedIsMusl = innerGet();
|
|
97
|
+
}
|
|
98
|
+
return cachedIsMusl;
|
|
93
99
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} catch (_err) {
|
|
99
|
-
return "";
|
|
100
|
-
}
|
|
100
|
+
function innerGet() {
|
|
101
|
+
try {
|
|
102
|
+
if (os.platform() !== "linux") {
|
|
103
|
+
return false;
|
|
101
104
|
}
|
|
105
|
+
return isProcessReportMusl() || isConfMusl();
|
|
106
|
+
} catch (err) {
|
|
107
|
+
// just in case
|
|
108
|
+
console.warn("Error checking if musl.", err);
|
|
109
|
+
return false;
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
|
|
113
|
+
function isProcessReportMusl() {
|
|
114
|
+
if (!process.report) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const rawReport = process.report.getReport();
|
|
118
|
+
const report = typeof rawReport === "string" ? JSON.parse(rawReport) : rawReport;
|
|
119
|
+
if (!report || !(report.sharedObjects instanceof Array)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
return report.sharedObjects.some(o => o.includes("libc.musl-") || o.includes("ld-musl-"));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function isConfMusl() {
|
|
126
|
+
const output = getCommandOutput();
|
|
127
|
+
const [_, ldd1] = output.split(/[\r\n]+/);
|
|
128
|
+
return ldd1 && ldd1.includes("musl");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function getCommandOutput() {
|
|
132
|
+
try {
|
|
133
|
+
const command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true";
|
|
134
|
+
return require("child_process").execSync(command, { encoding: "utf8" });
|
|
135
|
+
} catch (_err) {
|
|
136
|
+
return "";
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dprint",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.2",
|
|
4
4
|
"description": "Pluggable and configurable code formatting platform written in Rust.",
|
|
5
5
|
"bin": "bin.js",
|
|
6
6
|
"repository": {
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
"url": "https://github.com/dprint/dprint/issues"
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/dprint/dprint#readme",
|
|
20
|
+
"preferUnplugged": true,
|
|
20
21
|
"optionalDependencies": {
|
|
21
|
-
"@dprint/win32-x64": "0.38.
|
|
22
|
-
"@dprint/darwin-x64": "0.38.
|
|
23
|
-
"@dprint/darwin-arm64": "0.38.
|
|
24
|
-
"@dprint/linux-x64-glibc": "0.38.
|
|
25
|
-
"@dprint/linux-x64-musl": "0.38.
|
|
26
|
-
"@dprint/linux-arm64-glibc": "0.38.
|
|
22
|
+
"@dprint/win32-x64": "0.38.2",
|
|
23
|
+
"@dprint/darwin-x64": "0.38.2",
|
|
24
|
+
"@dprint/darwin-arm64": "0.38.2",
|
|
25
|
+
"@dprint/linux-x64-glibc": "0.38.2",
|
|
26
|
+
"@dprint/linux-x64-musl": "0.38.2",
|
|
27
|
+
"@dprint/linux-arm64-glibc": "0.38.2"
|
|
27
28
|
}
|
|
28
29
|
}
|