@kprint/kprint 0.0.0-stage → 0.60.6

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 David Sherret
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,35 @@
1
- # Temporary Holding Version
1
+ # @kprint/kprint
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [kprint](https://dprint.kjanat.dev) is a pluggable and configurable code
4
+ formatter written in Rust, forked from dprint. It has formatters built in (ex.
5
+ exec) and runs dprint's plugins.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install --global @kprint/kprint
11
+ ```
12
+
13
+ This installs the `kprint` command, also as `dprint` for tools
14
+ that call that. npm only downloads the binary for your platform, from its
15
+ `@kprint/kprint-<platform>` package.
16
+
17
+ ## Use
18
+
19
+ ```sh
20
+ kprint init # create a configuration file
21
+ kprint fmt # format the files
22
+ kprint check # check they're formatted
23
+ ```
24
+
25
+ Or in a project, as a dev dependency:
26
+
27
+ ```sh
28
+ npm install --save-dev @kprint/kprint
29
+ npx kprint fmt
30
+ ```
31
+
32
+ [@kjanat/fmt](https://www.npmjs.com/package/@kjanat/fmt) runs `kprint fmt` as `fmt`.
33
+
34
+ See [dprint.kjanat.dev](https://dprint.kjanat.dev) for the configuration and the
35
+ plugins, and [the repository](https://github.com/kjanat/dprint) for its source.
package/bin.cjs ADDED
@@ -0,0 +1,365 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ 1 ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+
25
+ // deployment/npm/bin.ts
26
+ var import_node_child_process2 = require("node:child_process");
27
+ var import_node_fs = require("node:fs");
28
+ var import_node_os = require("node:os");
29
+ var import_node_path = require("node:path");
30
+
31
+ // deployment/npm/install_api.ts
32
+ var import_node_child_process = require("node:child_process");
33
+ var import_node_crypto = require("node:crypto");
34
+ var fs = __toESM(require("node:fs"));
35
+ var import_node_module = require("node:module");
36
+ var os = __toESM(require("node:os"));
37
+ var path = __toESM(require("node:path"));
38
+ var import_node_zlib = require("node:zlib");
39
+
40
+ // deployment/npm/names.ts
41
+ var scope = "@kprint";
42
+ var mainPackage = `${scope}/kprint`;
43
+ var platformPrefix = "kprint";
44
+ function platformPackage(platform3) {
45
+ return `${scope}/${platformDir(platform3)}`;
46
+ }
47
+ function platformDir(platform3) {
48
+ return `${platformPrefix}-${platform3}`;
49
+ }
50
+
51
+ // deployment/npm/install_api.ts
52
+ var cachedIsMusl;
53
+ function runInstall() {
54
+ const dprintFileName = os.platform() === "win32" ? "kprint.exe" : "kprint";
55
+ const targetExecutablePath = path.join(__dirname, dprintFileName);
56
+ if (fs.existsSync(targetExecutablePath)) return targetExecutablePath;
57
+ const target = getTarget();
58
+ const sourceExecutablePath = resolveSourceExecutablePath(target, dprintFileName);
59
+ if (sourceExecutablePath == null) {
60
+ downloadExecutable(target, dprintFileName, targetExecutablePath);
61
+ if (os.platform() !== "win32") chmodX(targetExecutablePath);
62
+ return targetExecutablePath;
63
+ }
64
+ try {
65
+ if (process.env.DPRINT_SIMULATED_READONLY_FILE_SYSTEM === "1") {
66
+ console.warn("Simulating readonly file system for testing.");
67
+ throw new Error("Throwing for testing purposes.");
68
+ }
69
+ hardLinkOrCopy(sourceExecutablePath, targetExecutablePath);
70
+ if (os.platform() !== "win32") chmodX(targetExecutablePath);
71
+ return targetExecutablePath;
72
+ } catch (err) {
73
+ if (process.env.DPRINT_DEBUG === "1") {
74
+ console.warn(`Failed to copy executable from ${sourceExecutablePath} to ${targetExecutablePath}. Using resolved package path instead.`, err);
75
+ }
76
+ return sourceExecutablePath;
77
+ }
78
+ }
79
+ function packageName(target) {
80
+ return platformPackage(target);
81
+ }
82
+ function resolveSourceExecutablePath(target, dprintFileName) {
83
+ let sourcePackagePath;
84
+ try {
85
+ sourcePackagePath = path.dirname((0, import_node_module.createRequire)(__filename).resolve(`${packageName(target)}/package.json`));
86
+ } catch {
87
+ return void 0;
88
+ }
89
+ const sourceExecutablePath = path.join(sourcePackagePath, dprintFileName);
90
+ return fs.existsSync(sourceExecutablePath) ? sourceExecutablePath : void 0;
91
+ }
92
+ function readPackageField(fileName, field) {
93
+ const parsed = JSON.parse(fs.readFileSync(path.join(__dirname, fileName), "utf8"));
94
+ if (typeof parsed !== "object" || parsed === null) throw new Error(`${fileName} is not an object`);
95
+ return Object.fromEntries(Object.entries(parsed))[field];
96
+ }
97
+ function downloadExecutable(target, dprintFileName, destinationPath) {
98
+ const version = readPackageField("package.json", "version");
99
+ if (typeof version !== "string") throw new Error("package.json has no version");
100
+ const registry = (process.env.npm_config_registry || "https://registry.npmjs.org").replace(/\/+$/, "");
101
+ const tarballUrl = `${registry}/${packageName(target)}/-/${platformDir(target)}-${version}.tgz`;
102
+ console.error(`[kprint] Optional dependency ${packageName(target)} was not installed. Downloading from ${tarballUrl}`);
103
+ const tarballBuffer = downloadBufferSync(tarballUrl);
104
+ const executableBuffer = extractFileFromTarGzip(tarballBuffer, `package/${dprintFileName}`);
105
+ verifyExecutableHash(target, executableBuffer);
106
+ atomicWriteFile(destinationPath, executableBuffer);
107
+ }
108
+ function verifyExecutableHash(target, buffer) {
109
+ let expected;
110
+ try {
111
+ expected = readPackageField("hashes.json", target);
112
+ } catch (err) {
113
+ throw new Error(`Could not load hashes.json to verify the downloaded binary: ${err instanceof Error ? err.message : err}`);
114
+ }
115
+ if (typeof expected !== "string") {
116
+ throw new Error(`No known hash for ${packageName(target)} to verify the download against.`);
117
+ }
118
+ const actual = (0, import_node_crypto.createHash)("sha256").update(buffer).digest("hex");
119
+ if (actual !== expected) {
120
+ throw new Error(`Integrity check failed for the downloaded ${packageName(target)} binary.
121
+ Expected sha256: ${expected}
122
+ Actual sha256: ${actual}`);
123
+ }
124
+ }
125
+ function downloadBufferSync(url) {
126
+ const fromCurl = downloadBufferWithCurl(url);
127
+ return fromCurl != null ? fromCurl : downloadBufferWithNode(url);
128
+ }
129
+ function downloadBufferWithCurl(url) {
130
+ const args = [
131
+ "-fsSL"
132
+ ];
133
+ const proxy = process.env.npm_config_https_proxy || process.env.npm_config_proxy || process.env.HTTPS_PROXY || process.env.https_proxy;
134
+ if (proxy) {
135
+ args.push("--proxy", proxy);
136
+ }
137
+ const noProxy = process.env.npm_config_noproxy || process.env.NO_PROXY || process.env.no_proxy;
138
+ if (noProxy) {
139
+ args.push("--noproxy", noProxy);
140
+ }
141
+ args.push("-o", "-", url);
142
+ try {
143
+ return (0, import_node_child_process.execFileSync)("curl", args, {
144
+ maxBuffer: 512 * 1024 * 1024
145
+ });
146
+ } catch (err) {
147
+ if (err instanceof Error && "code" in err && err.code === "ENOENT") {
148
+ return void 0;
149
+ }
150
+ throw err;
151
+ }
152
+ }
153
+ function downloadBufferWithNode(url) {
154
+ const script = `const https = require("node:https");
155
+ function f(u) {
156
+ https.get(u, r => {
157
+ const s = r.statusCode;
158
+ if ((s === 301 || s === 302 || s === 303 || s === 307 || s === 308) && r.headers.location) {
159
+ f(new URL(r.headers.location, u).toString());
160
+ return;
161
+ }
162
+ if (s !== 200) {
163
+ console.error(\`[kprint] Unexpected status code \${s} downloading \${u}\`);
164
+ process.exit(1);
165
+ }
166
+ r.pipe(process.stdout);
167
+ }).on("error", e => {
168
+ console.error(String(e?.message || e));
169
+ process.exit(1);
170
+ });
171
+ }
172
+ f(process.argv[1]);
173
+ `;
174
+ return (0, import_node_child_process.execFileSync)(process.execPath, [
175
+ "-e",
176
+ script,
177
+ url
178
+ ], {
179
+ maxBuffer: 512 * 1024 * 1024
180
+ });
181
+ }
182
+ function extractFileFromTarGzip(buffer, subpath) {
183
+ let tar;
184
+ try {
185
+ tar = (0, import_node_zlib.gunzipSync)(buffer);
186
+ } catch (err) {
187
+ throw new Error(`Invalid gzip data in downloaded tarball: ${err instanceof Error ? err.message : err}`);
188
+ }
189
+ let offset = 0;
190
+ while (offset < tar.length) {
191
+ const name = readTarString(tar, offset, 100);
192
+ const size = parseInt(readTarString(tar, offset + 124, 12).trim(), 8);
193
+ offset += 512;
194
+ if (!Number.isNaN(size)) {
195
+ if (name === subpath) return tar.subarray(offset, offset + size);
196
+ offset += size + 511 & ~511;
197
+ }
198
+ }
199
+ throw new Error(`Could not find ${JSON.stringify(subpath)} in downloaded tarball`);
200
+ }
201
+ function readTarString(buffer, offset, length) {
202
+ return buffer.toString("utf8", offset, offset + length).replace(/\0.*$/, "");
203
+ }
204
+ function atomicWriteFile(destinationPath, buffer) {
205
+ const rand = (0, import_node_crypto.randomBytes)(4).toString("hex");
206
+ const tempFilePath = `${destinationPath}.${rand}`;
207
+ fs.writeFileSync(tempFilePath, buffer);
208
+ try {
209
+ fs.renameSync(tempFilePath, destinationPath);
210
+ } catch (err) {
211
+ try {
212
+ fs.unlinkSync(tempFilePath);
213
+ } catch {
214
+ }
215
+ throw err;
216
+ }
217
+ }
218
+ function chmodX(filePath) {
219
+ const fd = fs.openSync(filePath, "r");
220
+ try {
221
+ const perms = fs.fstatSync(fd).mode;
222
+ fs.fchmodSync(fd, perms | 73);
223
+ } finally {
224
+ fs.closeSync(fd);
225
+ }
226
+ }
227
+ function getTarget() {
228
+ const platform3 = os.platform();
229
+ if (platform3 === "linux") {
230
+ return `${platform3}-${getArch()}-${getLinuxFamily()}`;
231
+ } else {
232
+ return `${platform3}-${getArch()}`;
233
+ }
234
+ }
235
+ function getArch() {
236
+ const arch2 = os.arch();
237
+ if (arch2 !== "arm64" && arch2 !== "x64" && arch2 !== "riscv64" && arch2 !== "loong64" && arch2 !== "ppc64") {
238
+ throw new Error(`Unsupported architecture ${os.arch()}. Only x64, arm64, riscv64, loong64 and ppc64 binaries are available.`);
239
+ }
240
+ return arch2;
241
+ }
242
+ function getLinuxFamily() {
243
+ return getIsMusl() ? "musl" : "glibc";
244
+ function getIsMusl() {
245
+ if (cachedIsMusl == null) {
246
+ cachedIsMusl = innerGet();
247
+ }
248
+ return cachedIsMusl;
249
+ function innerGet() {
250
+ try {
251
+ if (os.platform() !== "linux") {
252
+ return false;
253
+ }
254
+ let musl = isMuslFromFilesystem();
255
+ if (musl == null) {
256
+ musl = isMuslFromReport();
257
+ }
258
+ if (musl == null) {
259
+ musl = isMuslFromChildProcess();
260
+ }
261
+ return musl;
262
+ } catch (err) {
263
+ console.warn("Error checking if musl.", err);
264
+ return false;
265
+ }
266
+ }
267
+ function isMuslFromFilesystem() {
268
+ try {
269
+ return fs.readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
270
+ } catch {
271
+ return null;
272
+ }
273
+ }
274
+ function isMuslFromReport() {
275
+ const processReport = process.report;
276
+ if (typeof processReport !== "object" || processReport === null || !("getReport" in processReport) || typeof processReport.getReport !== "function") {
277
+ return null;
278
+ }
279
+ const originalExcludeNetwork = Reflect.get(processReport, "excludeNetwork");
280
+ let rawReport;
281
+ try {
282
+ Reflect.set(processReport, "excludeNetwork", true);
283
+ rawReport = processReport.getReport();
284
+ } finally {
285
+ Reflect.set(processReport, "excludeNetwork", originalExcludeNetwork);
286
+ }
287
+ const report = typeof rawReport === "string" ? JSON.parse(rawReport) : rawReport;
288
+ if (typeof report !== "object" || report === null) {
289
+ return null;
290
+ }
291
+ const fields = Object.fromEntries(Object.entries(report));
292
+ const header = fields.header;
293
+ if (typeof header === "object" && header !== null && "glibcVersionRuntime" in header && header.glibcVersionRuntime) {
294
+ return false;
295
+ }
296
+ const sharedObjects = fields.sharedObjects;
297
+ if (Array.isArray(sharedObjects)) {
298
+ return sharedObjects.some((entry) => typeof entry === "string" && isFileMusl(entry));
299
+ }
300
+ return false;
301
+ }
302
+ function isMuslFromChildProcess() {
303
+ try {
304
+ return (0, import_node_child_process.execSync)("ldd --version", {
305
+ encoding: "utf8"
306
+ }).includes("musl");
307
+ } catch {
308
+ return false;
309
+ }
310
+ }
311
+ function isFileMusl(f) {
312
+ return f.includes("libc.musl-") || f.includes("ld-musl-");
313
+ }
314
+ }
315
+ }
316
+ function hardLinkOrCopy(sourcePath, destinationPath) {
317
+ try {
318
+ fs.linkSync(sourcePath, destinationPath);
319
+ } catch {
320
+ atomicCopyFile(sourcePath, destinationPath);
321
+ }
322
+ }
323
+ function atomicCopyFile(sourcePath, destinationPath) {
324
+ const rand = (0, import_node_crypto.randomBytes)(4).toString("hex");
325
+ const tempFilePath = `${destinationPath}.${rand}`;
326
+ fs.copyFileSync(sourcePath, tempFilePath);
327
+ try {
328
+ fs.renameSync(tempFilePath, destinationPath);
329
+ } catch (err) {
330
+ try {
331
+ fs.unlinkSync(tempFilePath);
332
+ } catch {
333
+ }
334
+ throw err;
335
+ }
336
+ }
337
+
338
+ // deployment/npm/bin.ts
339
+ var exePath = (0, import_node_path.join)(__dirname, (0, import_node_os.platform)() === "win32" ? "kprint.exe" : "kprint");
340
+ if (!(0, import_node_fs.existsSync)(exePath)) {
341
+ try {
342
+ runDprintExe(runInstall());
343
+ } catch (err) {
344
+ if (err instanceof Error) {
345
+ console.error(err.message);
346
+ } else {
347
+ console.error(err);
348
+ }
349
+ process.exit(1);
350
+ }
351
+ } else {
352
+ runDprintExe(exePath);
353
+ }
354
+ function runDprintExe(exePath2) {
355
+ const result = (0, import_node_child_process2.spawnSync)(exePath2, process.argv.slice(2), {
356
+ stdio: "inherit"
357
+ });
358
+ if (result.error) {
359
+ if (!(0, import_node_fs.existsSync)(exePath2)) {
360
+ throw new Error("Could not find exe at path '" + exePath2 + "'. Maybe try installing kprint again.");
361
+ }
362
+ throw result.error;
363
+ }
364
+ process.exit(result.status ?? 1);
365
+ }
package/hashes.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "freebsd-x64": "b4f113c0ed36f2bc225f3008020a3f2d4e1708bb109b1ae8fa577a721c32c7df",
3
+ "win32-x64": "d8f725136aa4ea0e4c0cea3568df06935731296eb49356f2570386b93e584990",
4
+ "win32-arm64": "4f76f977865bfa877a99737c3ffa73e052a9e25f5bf25c00c453fb40cf6b0f7c",
5
+ "darwin-x64": "793e7e41dd562c8467486207773f260ab53e75130058b4d962e7f96272a7cc29",
6
+ "darwin-arm64": "91cce0bc4403844c8f22919bb1cff6217b9b70061f953b506f7b7592372533ba",
7
+ "linux-x64-glibc": "9b40a3b5d1b88e61f4cd344af0db27e73ed191b4c6877557957cbfa8fb16e5a3",
8
+ "linux-x64-musl": "9862dbe85354068e3e1875d9feab963ba36a6ce53d995000472273598c23645d",
9
+ "linux-arm64-glibc": "29ca735535518e1c2a2bfa25fa8f796c99a9a5eb729a86332e5f569902a6760e",
10
+ "linux-arm64-musl": "11bd8e75168110f6a2a4018a36fd7cd2cb0c103de2b11d5cd93175ee9da4f5a6",
11
+ "linux-riscv64-glibc": "4979d3d68fb7fb339f3a950987bfb90a47fd48210c484c269617f7340f621921",
12
+ "linux-loong64-glibc": "a691bf35b5ca1b514a0addefa6b3c1d7ba1d46e16a5c71bdf2092e15336c8d32",
13
+ "linux-loong64-musl": "bde33362abc59ba321ad132f37dfcf3b9afa2509f7de089a97609f6c67effbc2",
14
+ "linux-ppc64-glibc": "5fa333f5994e3bf017c99be84a318837697d21d5d4a1f149ef3706bbf2fd9536",
15
+ "linux-ppc64-musl": "7859bbb430136a319c60ad820250cd063c667e5e16bb2ba82ff538da406bc27c",
16
+ "android-arm64": "7182eb339e928aed3bf3ecac0b7e096bff2c7411514b4d414dc4d361a65f7fae",
17
+ "android-x64": "05d2d8ed5b4f1572fce26b1441c31e0b6e56c2b63f3e5a3560e549a326b4c894"
18
+ }
package/install.cjs ADDED
@@ -0,0 +1,400 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ 1 ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+
24
+ // deployment/npm/install_api.ts
25
+ var import_node_child_process = require("node:child_process");
26
+ var import_node_crypto = require("node:crypto");
27
+ var fs = __toESM(require("node:fs"));
28
+ var import_node_module = require("node:module");
29
+ var os = __toESM(require("node:os"));
30
+ var path = __toESM(require("node:path"));
31
+ var import_node_zlib = require("node:zlib");
32
+
33
+ // deployment/npm/names.ts
34
+ var scope = "@kprint";
35
+ var mainPackage = `${scope}/kprint`;
36
+ var platformPrefix = "kprint";
37
+ function platformPackage(platform2) {
38
+ return `${scope}/${platformDir(platform2)}`;
39
+ }
40
+ function platformDir(platform2) {
41
+ return `${platformPrefix}-${platform2}`;
42
+ }
43
+
44
+ // deployment/npm/install_api.ts
45
+ var BIN_COMMANDS = [
46
+ "kprint",
47
+ "dprint"
48
+ ];
49
+ var cachedIsMusl;
50
+ function runInstall() {
51
+ const dprintFileName = os.platform() === "win32" ? "kprint.exe" : "kprint";
52
+ const targetExecutablePath = path.join(__dirname, dprintFileName);
53
+ if (fs.existsSync(targetExecutablePath)) return targetExecutablePath;
54
+ const target = getTarget();
55
+ const sourceExecutablePath = resolveSourceExecutablePath(target, dprintFileName);
56
+ if (sourceExecutablePath == null) {
57
+ downloadExecutable(target, dprintFileName, targetExecutablePath);
58
+ if (os.platform() !== "win32") chmodX(targetExecutablePath);
59
+ return targetExecutablePath;
60
+ }
61
+ try {
62
+ if (process.env.DPRINT_SIMULATED_READONLY_FILE_SYSTEM === "1") {
63
+ console.warn("Simulating readonly file system for testing.");
64
+ throw new Error("Throwing for testing purposes.");
65
+ }
66
+ hardLinkOrCopy(sourceExecutablePath, targetExecutablePath);
67
+ if (os.platform() !== "win32") chmodX(targetExecutablePath);
68
+ return targetExecutablePath;
69
+ } catch (err) {
70
+ if (process.env.DPRINT_DEBUG === "1") {
71
+ console.warn(`Failed to copy executable from ${sourceExecutablePath} to ${targetExecutablePath}. Using resolved package path instead.`, err);
72
+ }
73
+ return sourceExecutablePath;
74
+ }
75
+ }
76
+ function packageName(target) {
77
+ return platformPackage(target);
78
+ }
79
+ function resolveSourceExecutablePath(target, dprintFileName) {
80
+ let sourcePackagePath;
81
+ try {
82
+ sourcePackagePath = path.dirname((0, import_node_module.createRequire)(__filename).resolve(`${packageName(target)}/package.json`));
83
+ } catch {
84
+ return void 0;
85
+ }
86
+ const sourceExecutablePath = path.join(sourcePackagePath, dprintFileName);
87
+ return fs.existsSync(sourceExecutablePath) ? sourceExecutablePath : void 0;
88
+ }
89
+ function readPackageField(fileName, field) {
90
+ const parsed = JSON.parse(fs.readFileSync(path.join(__dirname, fileName), "utf8"));
91
+ if (typeof parsed !== "object" || parsed === null) throw new Error(`${fileName} is not an object`);
92
+ return Object.fromEntries(Object.entries(parsed))[field];
93
+ }
94
+ function downloadExecutable(target, dprintFileName, destinationPath) {
95
+ const version = readPackageField("package.json", "version");
96
+ if (typeof version !== "string") throw new Error("package.json has no version");
97
+ const registry = (process.env.npm_config_registry || "https://registry.npmjs.org").replace(/\/+$/, "");
98
+ const tarballUrl = `${registry}/${packageName(target)}/-/${platformDir(target)}-${version}.tgz`;
99
+ console.error(`[kprint] Optional dependency ${packageName(target)} was not installed. Downloading from ${tarballUrl}`);
100
+ const tarballBuffer = downloadBufferSync(tarballUrl);
101
+ const executableBuffer = extractFileFromTarGzip(tarballBuffer, `package/${dprintFileName}`);
102
+ verifyExecutableHash(target, executableBuffer);
103
+ atomicWriteFile(destinationPath, executableBuffer);
104
+ }
105
+ function verifyExecutableHash(target, buffer) {
106
+ let expected;
107
+ try {
108
+ expected = readPackageField("hashes.json", target);
109
+ } catch (err) {
110
+ throw new Error(`Could not load hashes.json to verify the downloaded binary: ${err instanceof Error ? err.message : err}`);
111
+ }
112
+ if (typeof expected !== "string") {
113
+ throw new Error(`No known hash for ${packageName(target)} to verify the download against.`);
114
+ }
115
+ const actual = (0, import_node_crypto.createHash)("sha256").update(buffer).digest("hex");
116
+ if (actual !== expected) {
117
+ throw new Error(`Integrity check failed for the downloaded ${packageName(target)} binary.
118
+ Expected sha256: ${expected}
119
+ Actual sha256: ${actual}`);
120
+ }
121
+ }
122
+ function downloadBufferSync(url) {
123
+ const fromCurl = downloadBufferWithCurl(url);
124
+ return fromCurl != null ? fromCurl : downloadBufferWithNode(url);
125
+ }
126
+ function downloadBufferWithCurl(url) {
127
+ const args = [
128
+ "-fsSL"
129
+ ];
130
+ const proxy = process.env.npm_config_https_proxy || process.env.npm_config_proxy || process.env.HTTPS_PROXY || process.env.https_proxy;
131
+ if (proxy) {
132
+ args.push("--proxy", proxy);
133
+ }
134
+ const noProxy = process.env.npm_config_noproxy || process.env.NO_PROXY || process.env.no_proxy;
135
+ if (noProxy) {
136
+ args.push("--noproxy", noProxy);
137
+ }
138
+ args.push("-o", "-", url);
139
+ try {
140
+ return (0, import_node_child_process.execFileSync)("curl", args, {
141
+ maxBuffer: 512 * 1024 * 1024
142
+ });
143
+ } catch (err) {
144
+ if (err instanceof Error && "code" in err && err.code === "ENOENT") {
145
+ return void 0;
146
+ }
147
+ throw err;
148
+ }
149
+ }
150
+ function downloadBufferWithNode(url) {
151
+ const script = `const https = require("node:https");
152
+ function f(u) {
153
+ https.get(u, r => {
154
+ const s = r.statusCode;
155
+ if ((s === 301 || s === 302 || s === 303 || s === 307 || s === 308) && r.headers.location) {
156
+ f(new URL(r.headers.location, u).toString());
157
+ return;
158
+ }
159
+ if (s !== 200) {
160
+ console.error(\`[kprint] Unexpected status code \${s} downloading \${u}\`);
161
+ process.exit(1);
162
+ }
163
+ r.pipe(process.stdout);
164
+ }).on("error", e => {
165
+ console.error(String(e?.message || e));
166
+ process.exit(1);
167
+ });
168
+ }
169
+ f(process.argv[1]);
170
+ `;
171
+ return (0, import_node_child_process.execFileSync)(process.execPath, [
172
+ "-e",
173
+ script,
174
+ url
175
+ ], {
176
+ maxBuffer: 512 * 1024 * 1024
177
+ });
178
+ }
179
+ function extractFileFromTarGzip(buffer, subpath) {
180
+ let tar;
181
+ try {
182
+ tar = (0, import_node_zlib.gunzipSync)(buffer);
183
+ } catch (err) {
184
+ throw new Error(`Invalid gzip data in downloaded tarball: ${err instanceof Error ? err.message : err}`);
185
+ }
186
+ let offset = 0;
187
+ while (offset < tar.length) {
188
+ const name = readTarString(tar, offset, 100);
189
+ const size = parseInt(readTarString(tar, offset + 124, 12).trim(), 8);
190
+ offset += 512;
191
+ if (!Number.isNaN(size)) {
192
+ if (name === subpath) return tar.subarray(offset, offset + size);
193
+ offset += size + 511 & ~511;
194
+ }
195
+ }
196
+ throw new Error(`Could not find ${JSON.stringify(subpath)} in downloaded tarball`);
197
+ }
198
+ function readTarString(buffer, offset, length) {
199
+ return buffer.toString("utf8", offset, offset + length).replace(/\0.*$/, "");
200
+ }
201
+ function atomicWriteFile(destinationPath, buffer) {
202
+ const rand = (0, import_node_crypto.randomBytes)(4).toString("hex");
203
+ const tempFilePath = `${destinationPath}.${rand}`;
204
+ fs.writeFileSync(tempFilePath, buffer);
205
+ try {
206
+ fs.renameSync(tempFilePath, destinationPath);
207
+ } catch (err) {
208
+ try {
209
+ fs.unlinkSync(tempFilePath);
210
+ } catch {
211
+ }
212
+ throw err;
213
+ }
214
+ }
215
+ function chmodX(filePath) {
216
+ const fd = fs.openSync(filePath, "r");
217
+ try {
218
+ const perms = fs.fstatSync(fd).mode;
219
+ fs.fchmodSync(fd, perms | 73);
220
+ } finally {
221
+ fs.closeSync(fd);
222
+ }
223
+ }
224
+ function getTarget() {
225
+ const platform2 = os.platform();
226
+ if (platform2 === "linux") {
227
+ return `${platform2}-${getArch()}-${getLinuxFamily()}`;
228
+ } else {
229
+ return `${platform2}-${getArch()}`;
230
+ }
231
+ }
232
+ function getArch() {
233
+ const arch2 = os.arch();
234
+ if (arch2 !== "arm64" && arch2 !== "x64" && arch2 !== "riscv64" && arch2 !== "loong64" && arch2 !== "ppc64") {
235
+ throw new Error(`Unsupported architecture ${os.arch()}. Only x64, arm64, riscv64, loong64 and ppc64 binaries are available.`);
236
+ }
237
+ return arch2;
238
+ }
239
+ function getLinuxFamily() {
240
+ return getIsMusl() ? "musl" : "glibc";
241
+ function getIsMusl() {
242
+ if (cachedIsMusl == null) {
243
+ cachedIsMusl = innerGet();
244
+ }
245
+ return cachedIsMusl;
246
+ function innerGet() {
247
+ try {
248
+ if (os.platform() !== "linux") {
249
+ return false;
250
+ }
251
+ let musl = isMuslFromFilesystem();
252
+ if (musl == null) {
253
+ musl = isMuslFromReport();
254
+ }
255
+ if (musl == null) {
256
+ musl = isMuslFromChildProcess();
257
+ }
258
+ return musl;
259
+ } catch (err) {
260
+ console.warn("Error checking if musl.", err);
261
+ return false;
262
+ }
263
+ }
264
+ function isMuslFromFilesystem() {
265
+ try {
266
+ return fs.readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
267
+ } catch {
268
+ return null;
269
+ }
270
+ }
271
+ function isMuslFromReport() {
272
+ const processReport = process.report;
273
+ if (typeof processReport !== "object" || processReport === null || !("getReport" in processReport) || typeof processReport.getReport !== "function") {
274
+ return null;
275
+ }
276
+ const originalExcludeNetwork = Reflect.get(processReport, "excludeNetwork");
277
+ let rawReport;
278
+ try {
279
+ Reflect.set(processReport, "excludeNetwork", true);
280
+ rawReport = processReport.getReport();
281
+ } finally {
282
+ Reflect.set(processReport, "excludeNetwork", originalExcludeNetwork);
283
+ }
284
+ const report = typeof rawReport === "string" ? JSON.parse(rawReport) : rawReport;
285
+ if (typeof report !== "object" || report === null) {
286
+ return null;
287
+ }
288
+ const fields = Object.fromEntries(Object.entries(report));
289
+ const header = fields.header;
290
+ if (typeof header === "object" && header !== null && "glibcVersionRuntime" in header && header.glibcVersionRuntime) {
291
+ return false;
292
+ }
293
+ const sharedObjects = fields.sharedObjects;
294
+ if (Array.isArray(sharedObjects)) {
295
+ return sharedObjects.some((entry) => typeof entry === "string" && isFileMusl(entry));
296
+ }
297
+ return false;
298
+ }
299
+ function isMuslFromChildProcess() {
300
+ try {
301
+ return (0, import_node_child_process.execSync)("ldd --version", {
302
+ encoding: "utf8"
303
+ }).includes("musl");
304
+ } catch {
305
+ return false;
306
+ }
307
+ }
308
+ function isFileMusl(f) {
309
+ return f.includes("libc.musl-") || f.includes("ld-musl-");
310
+ }
311
+ }
312
+ }
313
+ function replaceBinEntry(exePath2) {
314
+ const binDir = findBinDir();
315
+ if (binDir === void 0) return;
316
+ const relative2 = path.relative(binDir, exePath2);
317
+ for (const command of BIN_COMMANDS) {
318
+ if (!isOurBinEntry(binDir, command)) continue;
319
+ if (os.platform() === "win32") {
320
+ fs.writeFileSync(path.join(binDir, `${command}.cmd`), `@"%~dp0${relative2}" %*\r
321
+ `);
322
+ fs.writeFileSync(path.join(binDir, `${command}.ps1`), `& (Join-Path $PSScriptRoot "${relative2.replace(/\\/g, "/")}") $args\r
323
+ exit $LASTEXITCODE\r
324
+ `);
325
+ } else {
326
+ const link = path.join(binDir, command);
327
+ fs.unlinkSync(link);
328
+ fs.symlinkSync(relative2, link);
329
+ }
330
+ }
331
+ }
332
+ function findBinDir() {
333
+ if (process.env.npm_config_global === "true") {
334
+ const prefix = process.env.npm_config_prefix;
335
+ if (prefix) {
336
+ const binDir = os.platform() === "win32" ? prefix : path.join(prefix, "bin");
337
+ if (isBinDirForThisPackage(binDir)) return binDir;
338
+ }
339
+ }
340
+ let dir = __dirname;
341
+ for (let i = 0; i < 64; i++) {
342
+ const parent = path.dirname(dir);
343
+ if (parent === dir) {
344
+ break;
345
+ }
346
+ if (path.basename(parent) === "node_modules") {
347
+ const binDir = path.join(parent, ".bin");
348
+ if (isBinDirForThisPackage(binDir)) {
349
+ return binDir;
350
+ }
351
+ }
352
+ dir = parent;
353
+ }
354
+ return void 0;
355
+ }
356
+ function isBinDirForThisPackage(binDir) {
357
+ return isOurBinEntry(binDir, "kprint");
358
+ }
359
+ function isOurBinEntry(binDir, command) {
360
+ try {
361
+ if (os.platform() === "win32") {
362
+ const content = fs.readFileSync(path.join(binDir, `${command}.cmd`), "utf8");
363
+ return content.includes("bin.cjs");
364
+ } else {
365
+ const linkTarget = fs.readlinkSync(path.join(binDir, command));
366
+ const resolved = path.resolve(binDir, linkTarget);
367
+ return resolved.endsWith("bin.cjs");
368
+ }
369
+ } catch {
370
+ return false;
371
+ }
372
+ }
373
+ function hardLinkOrCopy(sourcePath, destinationPath) {
374
+ try {
375
+ fs.linkSync(sourcePath, destinationPath);
376
+ } catch {
377
+ atomicCopyFile(sourcePath, destinationPath);
378
+ }
379
+ }
380
+ function atomicCopyFile(sourcePath, destinationPath) {
381
+ const rand = (0, import_node_crypto.randomBytes)(4).toString("hex");
382
+ const tempFilePath = `${destinationPath}.${rand}`;
383
+ fs.copyFileSync(sourcePath, tempFilePath);
384
+ try {
385
+ fs.renameSync(tempFilePath, destinationPath);
386
+ } catch (err) {
387
+ try {
388
+ fs.unlinkSync(tempFilePath);
389
+ } catch {
390
+ }
391
+ throw err;
392
+ }
393
+ }
394
+
395
+ // deployment/npm/install.ts
396
+ var exePath = runInstall();
397
+ try {
398
+ replaceBinEntry(exePath);
399
+ } catch {
400
+ }
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@kprint/kprint",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.60.6",
4
+ "description": "kprint: a pluggable and configurable code formatter written in Rust, forked from dprint.",
5
+ "bin": {
6
+ "kprint": "bin.cjs",
7
+ "dprint": "bin.cjs"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/kjanat/dprint.git"
12
+ },
13
+ "keywords": [
14
+ "dprint",
15
+ "formatter",
16
+ "format",
17
+ "code",
18
+ "cli"
19
+ ],
20
+ "author": "Kaj Kowalski",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/kjanat/dprint/issues"
24
+ },
25
+ "homepage": "https://dprint.kjanat.dev",
26
+ "preferUnplugged": true,
27
+ "scripts": {
28
+ "postinstall": "node ./install.cjs"
29
+ },
30
+ "optionalDependencies": {
31
+ "@kprint/kprint-freebsd-x64": "0.60.6",
32
+ "@kprint/kprint-win32-x64": "0.60.6",
33
+ "@kprint/kprint-win32-arm64": "0.60.6",
34
+ "@kprint/kprint-darwin-x64": "0.60.6",
35
+ "@kprint/kprint-darwin-arm64": "0.60.6",
36
+ "@kprint/kprint-linux-x64-glibc": "0.60.6",
37
+ "@kprint/kprint-linux-x64-musl": "0.60.6",
38
+ "@kprint/kprint-linux-arm64-glibc": "0.60.6",
39
+ "@kprint/kprint-linux-arm64-musl": "0.60.6",
40
+ "@kprint/kprint-linux-riscv64-glibc": "0.60.6",
41
+ "@kprint/kprint-linux-loong64-glibc": "0.60.6",
42
+ "@kprint/kprint-linux-loong64-musl": "0.60.6",
43
+ "@kprint/kprint-linux-ppc64-glibc": "0.60.6",
44
+ "@kprint/kprint-linux-ppc64-musl": "0.60.6",
45
+ "@kprint/kprint-android-arm64": "0.60.6",
46
+ "@kprint/kprint-android-x64": "0.60.6"
47
+ }
48
+ }