@lgtm-hq/lintro 0.69.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.
Files changed (3) hide show
  1. package/bin/lintro +37 -0
  2. package/lib/resolve.js +104 -0
  3. package/package.json +41 -0
package/bin/lintro ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ /**
5
+ * Launcher for the lintro meta-package.
6
+ *
7
+ * Resolves the self-contained binary shipped by the matching
8
+ * `@lgtm-hq/lintro-<platform>` optional dependency and forwards all arguments and
9
+ * stdio to it. Exits with the binary's own exit code.
10
+ */
11
+
12
+ const { execFileSync } = require("child_process");
13
+ const { resolveBinary } = require("../lib/resolve.js");
14
+
15
+ function main() {
16
+ let binaryPath;
17
+ try {
18
+ binaryPath = resolveBinary();
19
+ } catch (err) {
20
+ process.stderr.write(`${err.message}\n`);
21
+ process.exit(1);
22
+ }
23
+
24
+ try {
25
+ execFileSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
26
+ } catch (err) {
27
+ // execFileSync throws for non-zero exit codes; propagate the child's
28
+ // status so callers observe the real result.
29
+ if (typeof err.status === "number") {
30
+ process.exit(err.status);
31
+ }
32
+ process.stderr.write(`lintro: failed to launch binary: ${err.message}\n`);
33
+ process.exit(1);
34
+ }
35
+ }
36
+
37
+ main();
package/lib/resolve.js ADDED
@@ -0,0 +1,104 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Platform resolution for the lintro meta-package.
5
+ *
6
+ * Maps a Node `process.platform`/`process.arch` pair to the scoped
7
+ * `@lgtm-hq/lintro-<platform>` package that ships the matching self-contained
8
+ * binary. The resolution logic is kept pure and side-effect free so it
9
+ * can be unit-tested without a binary present on disk.
10
+ */
11
+
12
+ /**
13
+ * Mapping from a `${platform}-${arch}` key to the scoped package name that
14
+ * provides the binary for that platform. Keys use Node's `process.arch`
15
+ * values (`x64`, `arm64`), which match the npm `cpu` field.
16
+ *
17
+ * @type {Readonly<Record<string, string>>}
18
+ */
19
+ const PLATFORM_PACKAGES = Object.freeze({
20
+ 'darwin-arm64': '@lgtm-hq/lintro-darwin-arm64',
21
+ 'darwin-x64': '@lgtm-hq/lintro-darwin-x64',
22
+ 'linux-arm64': '@lgtm-hq/lintro-linux-arm64',
23
+ 'linux-x64': '@lgtm-hq/lintro-linux-x64',
24
+ });
25
+
26
+ /**
27
+ * Resolve the scoped package name for a platform/arch pair.
28
+ *
29
+ * @param {string} platform - Value of `process.platform` (e.g. `"darwin"`).
30
+ * @param {string} arch - Value of `process.arch` (e.g. `"arm64"`).
31
+ * @returns {string | null} The scoped package name, or `null` when the
32
+ * platform is unsupported.
33
+ */
34
+ function packageForPlatform(platform, arch) {
35
+ const key = `${platform}-${arch}`;
36
+ return Object.prototype.hasOwnProperty.call(PLATFORM_PACKAGES, key)
37
+ ? PLATFORM_PACKAGES[key]
38
+ : null;
39
+ }
40
+
41
+ /**
42
+ * List of platform keys supported by the current distribution.
43
+ *
44
+ * @returns {string[]} Supported `${platform}-${arch}` keys.
45
+ */
46
+ function supportedPlatforms() {
47
+ return Object.keys(PLATFORM_PACKAGES);
48
+ }
49
+
50
+ /**
51
+ * Resolve the absolute path to the lintro binary for the running platform.
52
+ *
53
+ * @param {NodeJS.Require} [requireFn] - Injectable `require` used to resolve
54
+ * the platform package (defaults to this module's `require`).
55
+ * @param {string} [platform] - Override for `process.platform` (testing).
56
+ * @param {string} [arch] - Override for `process.arch` (testing).
57
+ * @returns {string} Absolute path to the binary.
58
+ * @throws {Error} When the platform is unsupported or the platform package
59
+ * is not installed.
60
+ */
61
+ function resolveBinary(requireFn, platform, arch) {
62
+ const req = requireFn || require;
63
+ const plat = platform || process.platform;
64
+ const cpu = arch || process.arch;
65
+ const pkg = packageForPlatform(plat, cpu);
66
+
67
+ if (!pkg) {
68
+ throw new Error(
69
+ `lintro: unsupported platform ${plat}-${cpu}. ` +
70
+ `Supported platforms: ${supportedPlatforms().join(', ')}.`
71
+ );
72
+ }
73
+
74
+ let mod;
75
+ try {
76
+ mod = req(pkg);
77
+ } catch (err) {
78
+ if (err && err.code !== 'MODULE_NOT_FOUND') {
79
+ throw err;
80
+ }
81
+ throw new Error(
82
+ `lintro: the platform package "${pkg}" is not installed. ` +
83
+ 'This usually means optional dependencies were skipped during ' +
84
+ 'install, or the lockfile was generated on a different OS and ' +
85
+ "omits this platform's package (see npm/cli#4828). Reinstall with " +
86
+ 'optional dependencies enabled (e.g. `npm install @lgtm-hq/lintro` ' +
87
+ 'or `bun add @lgtm-hq/lintro`), or refresh the lockfile on this ' +
88
+ 'platform ' +
89
+ `(e.g. \`npm install --force\`). Cause: ${err.message}`
90
+ );
91
+ }
92
+
93
+ if (!mod || typeof mod.path !== 'string') {
94
+ throw new Error(`lintro: platform package "${pkg}" did not export a binary path.`);
95
+ }
96
+ return mod.path;
97
+ }
98
+
99
+ module.exports = {
100
+ PLATFORM_PACKAGES,
101
+ packageForPlatform,
102
+ supportedPlatforms,
103
+ resolveBinary,
104
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@lgtm-hq/lintro",
3
+ "version": "0.69.0",
4
+ "description": "A unified CLI for code formatting, linting, and quality assurance. Ships self-contained platform binaries — no Python required.",
5
+ "keywords": [
6
+ "lint",
7
+ "linter",
8
+ "formatter",
9
+ "ruff",
10
+ "black",
11
+ "mypy",
12
+ "prettier",
13
+ "cli"
14
+ ],
15
+ "homepage": "https://github.com/lgtm-hq/py-lintro#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/lgtm-hq/py-lintro/issues"
18
+ },
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/lgtm-hq/py-lintro.git",
23
+ "directory": "npm/lintro"
24
+ },
25
+ "bin": {
26
+ "lintro": "bin/lintro"
27
+ },
28
+ "files": [
29
+ "bin/lintro",
30
+ "lib/resolve.js"
31
+ ],
32
+ "optionalDependencies": {
33
+ "@lgtm-hq/lintro-darwin-arm64": "0.69.0",
34
+ "@lgtm-hq/lintro-darwin-x64": "0.69.0",
35
+ "@lgtm-hq/lintro-linux-arm64": "0.69.0",
36
+ "@lgtm-hq/lintro-linux-x64": "0.69.0"
37
+ },
38
+ "engines": {
39
+ "node": ">=18"
40
+ }
41
+ }