dprint 0.51.1 → 0.53.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 → bin.cjs} +8 -10
- package/install.cjs +10 -0
- package/{install_api.js → install_api.cjs} +92 -9
- package/package.json +14 -14
- package/install.js +0 -4
package/{bin.js → bin.cjs}
RENAMED
|
@@ -10,7 +10,7 @@ const exePath = path.join(__dirname, os.platform() === "win32" ? "dprint.exe" :
|
|
|
10
10
|
|
|
11
11
|
if (!fs.existsSync(exePath)) {
|
|
12
12
|
try {
|
|
13
|
-
const resolvedExePath = require("./install_api").runInstall();
|
|
13
|
+
const resolvedExePath = require("./install_api.cjs").runInstall();
|
|
14
14
|
runDprintExe(resolvedExePath);
|
|
15
15
|
} catch (err) {
|
|
16
16
|
if (err !== undefined && typeof err.message === "string") {
|
|
@@ -32,16 +32,14 @@ function runDprintExe(exePath) {
|
|
|
32
32
|
{ stdio: "inherit" },
|
|
33
33
|
);
|
|
34
34
|
if (result.error) {
|
|
35
|
-
throw result.error;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
throwIfNoExePath();
|
|
39
|
-
|
|
40
|
-
process.exitCode = result.status;
|
|
41
|
-
|
|
42
|
-
function throwIfNoExePath() {
|
|
43
35
|
if (!fs.existsSync(exePath)) {
|
|
44
|
-
throw new Error(
|
|
36
|
+
throw new Error(
|
|
37
|
+
"Could not find exe at path '" + exePath
|
|
38
|
+
+ "'. Maybe try installing dprint again.",
|
|
39
|
+
);
|
|
45
40
|
}
|
|
41
|
+
throw result.error;
|
|
46
42
|
}
|
|
43
|
+
|
|
44
|
+
process.exit(result.status ?? 1);
|
|
47
45
|
}
|
package/install.cjs
ADDED
|
@@ -8,6 +8,7 @@ const path = require("path");
|
|
|
8
8
|
let cachedIsMusl = undefined;
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
+
replaceBinEntry,
|
|
11
12
|
runInstall() {
|
|
12
13
|
const dprintFileName = os.platform() === "win32" ? "dprint.exe" : "dprint";
|
|
13
14
|
const targetExecutablePath = path.join(
|
|
@@ -38,7 +39,7 @@ module.exports = {
|
|
|
38
39
|
// into the dprint package folder
|
|
39
40
|
hardLinkOrCopy(sourceExecutablePath, targetExecutablePath);
|
|
40
41
|
if (os.platform() !== "win32") {
|
|
41
|
-
//
|
|
42
|
+
// chmod +x
|
|
42
43
|
chmodX(targetExecutablePath);
|
|
43
44
|
}
|
|
44
45
|
return targetExecutablePath;
|
|
@@ -53,12 +54,6 @@ module.exports = {
|
|
|
53
54
|
err,
|
|
54
55
|
);
|
|
55
56
|
}
|
|
56
|
-
// use the path found in the specific package
|
|
57
|
-
try {
|
|
58
|
-
chmodX(sourceExecutablePath);
|
|
59
|
-
} catch (_err) {
|
|
60
|
-
// ignore
|
|
61
|
-
}
|
|
62
57
|
return sourceExecutablePath;
|
|
63
58
|
}
|
|
64
59
|
},
|
|
@@ -66,8 +61,13 @@ module.exports = {
|
|
|
66
61
|
|
|
67
62
|
/** @filePath {string} */
|
|
68
63
|
function chmodX(filePath) {
|
|
69
|
-
const
|
|
70
|
-
|
|
64
|
+
const fd = fs.openSync(filePath, "r");
|
|
65
|
+
try {
|
|
66
|
+
const perms = fs.fstatSync(fd).mode;
|
|
67
|
+
fs.fchmodSync(fd, perms | 0o111);
|
|
68
|
+
} finally {
|
|
69
|
+
fs.closeSync(fd);
|
|
70
|
+
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
function getTarget() {
|
|
@@ -140,6 +140,89 @@ function getLinuxFamily() {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Replaces the bin entry in node_modules/.bin to point directly at the
|
|
145
|
+
* native binary, avoiding Node.js startup overhead on each invocation.
|
|
146
|
+
* @param exePath {string}
|
|
147
|
+
*/
|
|
148
|
+
function replaceBinEntry(exePath) {
|
|
149
|
+
const binDir = findBinDir();
|
|
150
|
+
if (binDir === undefined) return;
|
|
151
|
+
|
|
152
|
+
const relative = path.relative(binDir, exePath);
|
|
153
|
+
if (os.platform() === "win32") {
|
|
154
|
+
// rewrite .cmd and .ps1 wrappers to invoke the native binary directly
|
|
155
|
+
fs.writeFileSync(
|
|
156
|
+
path.join(binDir, "dprint.cmd"),
|
|
157
|
+
"@\"%~dp0" + relative + "\" %*\r\n",
|
|
158
|
+
);
|
|
159
|
+
fs.writeFileSync(
|
|
160
|
+
path.join(binDir, "dprint.ps1"),
|
|
161
|
+
"& \"$PSScriptRoot/" + relative.replace(/\\/g, "/")
|
|
162
|
+
+ "\" $args\r\nexit $LASTEXITCODE\r\n",
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
// replace symlink to point directly at the native binary
|
|
166
|
+
const binDprint = path.join(binDir, "dprint");
|
|
167
|
+
fs.unlinkSync(binDprint);
|
|
168
|
+
fs.symlinkSync(relative, binDprint);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function findBinDir() {
|
|
173
|
+
// For global installs, npm sets npm_config_global=true and npm_config_prefix
|
|
174
|
+
// to the install prefix. The bin dir is {prefix}/bin on Linux/Mac or
|
|
175
|
+
// {prefix} on Windows (e.g. %APPDATA%\npm).
|
|
176
|
+
if (process.env.npm_config_global === "true") {
|
|
177
|
+
const prefix = process.env.npm_config_prefix;
|
|
178
|
+
if (prefix) {
|
|
179
|
+
const binDir = os.platform() === "win32"
|
|
180
|
+
? prefix
|
|
181
|
+
: path.join(prefix, "bin");
|
|
182
|
+
if (isBinDirForThisPackage(binDir)) {
|
|
183
|
+
return binDir;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// For local installs, walk up looking for node_modules/.bin
|
|
189
|
+
let dir = __dirname;
|
|
190
|
+
for (let i = 0; i < 64; i++) {
|
|
191
|
+
const parent = path.dirname(dir);
|
|
192
|
+
if (parent === dir) {
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
if (path.basename(parent) === "node_modules") {
|
|
196
|
+
const binDir = path.join(parent, ".bin");
|
|
197
|
+
if (isBinDirForThisPackage(binDir)) {
|
|
198
|
+
return binDir;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
dir = parent;
|
|
202
|
+
}
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function isBinDirForThisPackage(binDir) {
|
|
207
|
+
try {
|
|
208
|
+
if (os.platform() === "win32") {
|
|
209
|
+
// verify the .cmd wrapper references our bin.cjs
|
|
210
|
+
const content = fs.readFileSync(
|
|
211
|
+
path.join(binDir, "dprint.cmd"),
|
|
212
|
+
"utf8",
|
|
213
|
+
);
|
|
214
|
+
return content.includes("bin.cjs");
|
|
215
|
+
} else {
|
|
216
|
+
// verify the symlink points into our package directory
|
|
217
|
+
const linkTarget = fs.readlinkSync(path.join(binDir, "dprint"));
|
|
218
|
+
const resolved = path.resolve(binDir, linkTarget);
|
|
219
|
+
return resolved.endsWith("bin.cjs");
|
|
220
|
+
}
|
|
221
|
+
} catch (_err) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
143
226
|
/**
|
|
144
227
|
* @param sourcePath {string}
|
|
145
228
|
* @param destinationPath {string}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dprint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "Pluggable and configurable code formatting platform written in Rust.",
|
|
5
|
-
"bin": "bin.
|
|
5
|
+
"bin": "bin.cjs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/dprint/dprint.git"
|
|
@@ -19,19 +19,19 @@
|
|
|
19
19
|
"homepage": "https://github.com/dprint/dprint#readme",
|
|
20
20
|
"preferUnplugged": true,
|
|
21
21
|
"scripts": {
|
|
22
|
-
"postinstall": "node ./install.
|
|
22
|
+
"postinstall": "node ./install.cjs"
|
|
23
23
|
},
|
|
24
24
|
"optionalDependencies": {
|
|
25
|
-
"@dprint/win32-x64": "0.
|
|
26
|
-
"@dprint/win32-arm64": "0.
|
|
27
|
-
"@dprint/darwin-x64": "0.
|
|
28
|
-
"@dprint/darwin-arm64": "0.
|
|
29
|
-
"@dprint/linux-x64-glibc": "0.
|
|
30
|
-
"@dprint/linux-x64-musl": "0.
|
|
31
|
-
"@dprint/linux-arm64-glibc": "0.
|
|
32
|
-
"@dprint/linux-arm64-musl": "0.
|
|
33
|
-
"@dprint/linux-riscv64-glibc": "0.
|
|
34
|
-
"@dprint/linux-loong64-glibc": "0.
|
|
35
|
-
"@dprint/linux-loong64-musl": "0.
|
|
25
|
+
"@dprint/win32-x64": "0.53.0",
|
|
26
|
+
"@dprint/win32-arm64": "0.53.0",
|
|
27
|
+
"@dprint/darwin-x64": "0.53.0",
|
|
28
|
+
"@dprint/darwin-arm64": "0.53.0",
|
|
29
|
+
"@dprint/linux-x64-glibc": "0.53.0",
|
|
30
|
+
"@dprint/linux-x64-musl": "0.53.0",
|
|
31
|
+
"@dprint/linux-arm64-glibc": "0.53.0",
|
|
32
|
+
"@dprint/linux-arm64-musl": "0.53.0",
|
|
33
|
+
"@dprint/linux-riscv64-glibc": "0.53.0",
|
|
34
|
+
"@dprint/linux-loong64-glibc": "0.53.0",
|
|
35
|
+
"@dprint/linux-loong64-musl": "0.53.0"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/install.js
DELETED