@monostyle-rs/cli 0.0.0 → 0.1.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.
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+ // Launcher for the platform-specific monostyle binary.
3
+ //
4
+ // npm resolves optional dependencies by platform, so the correct binary package is usually the
5
+ // only one installed. The candidate list exists for the cases where it is not: Alpine and other
6
+ // musl systems can end up with either the gnu or musl package, and a container built on one host
7
+ // may be run on another.
8
+ import { spawnSync } from "node:child_process";
9
+ import fs from "node:fs";
10
+ import { createRequire } from "node:module";
11
+ import path from "node:path";
12
+
13
+ const require = createRequire(import.meta.url);
14
+
15
+ /** Platform packages to try, most likely first. */
16
+ const PLATFORM_PACKAGES = {
17
+ darwin: {
18
+ arm64: ["@monostyle-rs/cli-darwin-arm64"],
19
+ x64: ["@monostyle-rs/cli-darwin-x64"],
20
+ },
21
+ linux: {
22
+ arm64: ["@monostyle-rs/cli-linux-arm64-gnu", "@monostyle-rs/cli-linux-arm64-musl"],
23
+ x64: ["@monostyle-rs/cli-linux-x64-gnu", "@monostyle-rs/cli-linux-x64-musl"],
24
+ },
25
+ win32: {
26
+ arm64: ["@monostyle-rs/cli-win32-arm64-msvc"],
27
+ x64: ["@monostyle-rs/cli-win32-x64-msvc"],
28
+ },
29
+ };
30
+
31
+ /** Returns the candidate package names for this platform. */
32
+ function candidates() {
33
+ return PLATFORM_PACKAGES[process.platform]?.[process.arch] ?? [];
34
+ }
35
+
36
+ /** Resolves a package's binary path, or null when it is not installed. */
37
+ function resolveBinary(packageName) {
38
+ try {
39
+ const packageJson = require.resolve(`${packageName}/package.json`);
40
+ const binary = path.join(
41
+ path.dirname(packageJson),
42
+ "bin",
43
+ process.platform === "win32" ? "monostyle.exe" : "monostyle",
44
+ );
45
+
46
+ return fs.existsSync(binary) ? binary : null;
47
+ } catch {
48
+ return null;
49
+ }
50
+ }
51
+
52
+ /** Whether a failed spawn should fall through to the next candidate package. */
53
+ function shouldTryNext(result) {
54
+ if (result.error) return true;
55
+
56
+ // A libc mismatch surfaces as a missing-interpreter error rather than as an exit code, so the
57
+ // stderr text is what distinguishes "wrong package" from "the tool failed".
58
+ if (result.status !== 127) return false;
59
+
60
+ return /not found|no such file or directory|exec format error/i.test(result.stderr ?? "");
61
+ }
62
+
63
+ /** Runs the first binary that works. */
64
+ function main() {
65
+ const names = candidates();
66
+
67
+ if (names.length === 0) {
68
+ console.error(
69
+ `monostyle does not publish npm binaries for ${process.platform}/${process.arch}. ` +
70
+ "Install from GitHub releases or with `cargo install monostyle` instead.",
71
+ );
72
+ process.exit(1);
73
+ }
74
+
75
+ const failures = [];
76
+
77
+ for (const name of names) {
78
+ const binary = resolveBinary(name);
79
+ if (!binary) continue;
80
+
81
+ const result = spawnSync(binary, process.argv.slice(2), {
82
+ stdio: ["inherit", "pipe", "pipe"],
83
+ encoding: "utf8",
84
+ windowsHide: false,
85
+ });
86
+
87
+ if (shouldTryNext(result)) {
88
+ failures.push(`${name}: ${result.error?.message ?? result.stderr?.trim() ?? "failed to launch"}`);
89
+ continue;
90
+ }
91
+
92
+ process.stdout.write(result.stdout ?? "");
93
+ process.stderr.write(result.stderr ?? "");
94
+ process.exit(result.status ?? 0);
95
+ }
96
+
97
+ console.error("Unable to find a compatible monostyle binary in the installed npm packages.");
98
+ console.error(`Tried: ${names.join(", ")}`);
99
+
100
+ if (failures.length > 0) {
101
+ console.error(failures.join("\n"));
102
+ }
103
+
104
+ console.error(
105
+ "Reinstall with `npm install -g @monostyle-rs/cli`, download a binary from GitHub releases, " +
106
+ "or use `cargo install monostyle`.",
107
+ );
108
+
109
+ process.exit(1);
110
+ }
111
+
112
+ main();
package/package.json CHANGED
@@ -1 +1,47 @@
1
- {"description":"Placeholder package for @monostyle-rs/cli","name":"@monostyle-rs/cli","version":"0.0.0"}
1
+ {
2
+ "name": "@monostyle-rs/cli",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Score the complexity and readability of a codebase, a file, or a function",
6
+ "keywords": [
7
+ "cli",
8
+ "code-quality",
9
+ "complexity",
10
+ "cyclomatic",
11
+ "cognitive-complexity",
12
+ "readability"
13
+ ],
14
+ "homepage": "https://github.com/ifiokjr/monostyle",
15
+ "bugs": {
16
+ "url": "https://github.com/ifiokjr/monostyle/issues"
17
+ },
18
+ "license": "Unlicense",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/ifiokjr/monostyle.git"
22
+ },
23
+ "bin": {
24
+ "monostyle": "bin/monostyle.js"
25
+ },
26
+ "files": [
27
+ "bin",
28
+ "README.md"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "provenance": true
33
+ },
34
+ "optionalDependencies": {
35
+ "@monostyle-rs/cli-darwin-arm64": "^0.1.0",
36
+ "@monostyle-rs/cli-darwin-x64": "^0.1.0",
37
+ "@monostyle-rs/cli-linux-arm64-gnu": "^0.1.0",
38
+ "@monostyle-rs/cli-linux-arm64-musl": "^0.1.0",
39
+ "@monostyle-rs/cli-linux-x64-gnu": "^0.1.0",
40
+ "@monostyle-rs/cli-linux-x64-musl": "^0.1.0",
41
+ "@monostyle-rs/cli-win32-arm64-msvc": "^0.1.0",
42
+ "@monostyle-rs/cli-win32-x64-msvc": "^0.1.0"
43
+ },
44
+ "engines": {
45
+ "node": ">=20"
46
+ }
47
+ }
package/CHANGELOG.md DELETED
@@ -1,3 +0,0 @@
1
- ## 0.0.0
2
-
3
- - Placeholder release.
package/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- This is free and unencumbered software released into the public domain.
2
-
3
- Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either
4
- in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by
5
- any means.
6
-
7
- In jurisdictions that recognize copyright laws, the author or authors of this software dedicate
8
- any and all copyright interest in the software to the public domain. We make this dedication for
9
- the benefit of the public at large and to the detriment of our heirs and successors. We intend
10
- this dedication to be an overt act of relinquishment in perpetuity of all present and future
11
- rights to this software under copyright law.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14
- NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
-
19
- For more information, please refer to <https://unlicense.org>
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # @monostyle-rs/cli
2
-
3
- This is a placeholder release published by monochange to bootstrap trusted publishing.