@runroom/code-quality 1.1.5

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 (2) hide show
  1. package/dist/cli.js +89 -0
  2. package/package.json +28 -0
package/dist/cli.js ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+
3
+ // launcher/src/main.ts
4
+ import { spawnSync } from "node:child_process";
5
+ import { createRequire } from "node:module";
6
+
7
+ // launcher/src/args.ts
8
+ import { constants } from "node:os";
9
+ var IMAGE_REPOSITORY = "ghcr.io/runroom/code-quality";
10
+ var IMAGE_REFERENCE = /^[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[0-9]+)?(?:\/[a-z0-9]+(?:[._-][a-z0-9]+)*)*(?::[A-Za-z0-9_][A-Za-z0-9._-]{0,127})?(?:@sha256:[a-f0-9]{64})?$/u;
11
+ var LauncherError = class extends Error {
12
+ constructor(message, exitCode = 2) {
13
+ super(message);
14
+ this.exitCode = exitCode;
15
+ }
16
+ exitCode;
17
+ };
18
+ function imageFor(version, env) {
19
+ const image = env.CODE_QUALITY_IMAGE;
20
+ if (!image) return `${IMAGE_REPOSITORY}:v${version}`;
21
+ if (!IMAGE_REFERENCE.test(image)) {
22
+ throw new LauncherError(
23
+ `Invalid CODE_QUALITY_IMAGE "${image}": expected an image reference such as ghcr.io/runroom/code-quality:v1`
24
+ );
25
+ }
26
+ return image;
27
+ }
28
+ function assertMountableCwd(cwd) {
29
+ if (cwd.includes(":")) {
30
+ throw new LauncherError(
31
+ `Working directory "${cwd}" contains ":" and cannot be bind-mounted; run from a path without colons`,
32
+ 2
33
+ );
34
+ }
35
+ }
36
+ function buildDockerArgs(ctx) {
37
+ const args = ["run", "--rm", "-v", `${ctx.cwd}:/work`];
38
+ if (ctx.platform === "linux" && ctx.uid !== void 0 && ctx.gid !== void 0) {
39
+ args.push("--user", `${ctx.uid}:${ctx.gid}`);
40
+ }
41
+ for (const name of ["CI", "GITHUB_ACTIONS"]) {
42
+ if (ctx.env[name] !== void 0) args.push("-e", name);
43
+ }
44
+ args.push(ctx.image, ...ctx.argv);
45
+ return args;
46
+ }
47
+ function dockerHint(image) {
48
+ return `docker not found. @runroom/code-quality runs the pinned image and needs Docker (https://docs.docker.com/get-docker/). Equivalent command: docker run --rm -v "$PWD:/work" ${image} <args>`;
49
+ }
50
+ function resolveOutcome(result, image) {
51
+ if (result.error) {
52
+ const message = result.error.code === "ENOENT" ? dockerHint(image) : `docker could not start (${result.error.code ?? result.error.message}). ${dockerHint(image)}`;
53
+ return { exitCode: 127, message };
54
+ }
55
+ if (result.signal) return { exitCode: 128 + (constants.signals[result.signal] ?? 2) };
56
+ return { exitCode: result.status ?? 1 };
57
+ }
58
+
59
+ // launcher/src/main.ts
60
+ try {
61
+ const require2 = createRequire(import.meta.url);
62
+ const { version } = require2("../package.json");
63
+ const env = process.env;
64
+ const cwd = process.cwd();
65
+ const image = imageFor(version, env);
66
+ assertMountableCwd(cwd);
67
+ const args = buildDockerArgs({
68
+ argv: process.argv.slice(2),
69
+ cwd,
70
+ env,
71
+ platform: process.platform,
72
+ ...process.getuid ? { uid: process.getuid() } : {},
73
+ ...process.getgid ? { gid: process.getgid() } : {},
74
+ image
75
+ });
76
+ const result = spawnSync("docker", args, { stdio: "inherit" });
77
+ const outcome = resolveOutcome(result, image);
78
+ if (outcome.message) process.stderr.write(`${outcome.message}
79
+ `);
80
+ process.exitCode = outcome.exitCode;
81
+ } catch (error) {
82
+ if (error instanceof LauncherError) {
83
+ process.stderr.write(`${error.message}
84
+ `);
85
+ process.exitCode = error.exitCode;
86
+ } else {
87
+ throw error;
88
+ }
89
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@runroom/code-quality",
3
+ "version": "1.1.5",
4
+ "description": "Runroom incremental quality gate — runs the pinned ghcr.io/runroom/code-quality image",
5
+ "type": "module",
6
+ "scripts": {
7
+ "prepack": "node -e \"require('node:fs').accessSync('dist/cli.js')\""
8
+ },
9
+ "bin": {
10
+ "code-quality": "dist/cli.js"
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public",
20
+ "registry": "https://registry.npmjs.org"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/Runroom/code-quality.git",
25
+ "directory": "launcher"
26
+ },
27
+ "license": "MIT"
28
+ }