@maniumek/suwgate 0.20.0 → 0.21.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/README.md CHANGED
@@ -19,6 +19,17 @@ pnpm add -D --save-exact @maniumek/suwgate
19
19
  pnpm installs a version only once it is a day old (`minimumReleaseAge`). To take a new suwgate the day it is published, exclude the
20
20
  package by name in `pnpm-workspace.yaml`: `minimumReleaseAgeExclude: ["@maniumek/suwgate"]`.
21
21
 
22
+ Once per machine, so that `suwgate` is a command in every repository:
23
+
24
+ ```sh
25
+ npm install --global @maniumek/suwgate
26
+ ```
27
+
28
+ The command on the machine is only a way in: started in a repository, it hands over to the version that repository pins, which is
29
+ the one CI runs, so the verdict is the same in both places. A repository that pins a version and has not installed it gets a
30
+ refusal with the folder to run `pnpm install` in, never a verdict from another version. Hooks keep calling the repository's own
31
+ binary by its path, so they work on a machine without the global command.
32
+
22
33
  ## Quick start
23
34
 
24
35
  ```sh
@@ -252,7 +263,7 @@ The plugin has two agents, each with its own clean context. `/suwgate:ship` star
252
263
  | `suwgate:shipper` | shell, files, `Agent`, `Skill` | takes the change to a pull request: `suwgate ship`, push, CI, and starts the simplifier and the suwagent skills |
253
264
  | `suwgate:simplifier` | shell, files | makes the change simpler without changing its behaviour; commits it, never pushes |
254
265
 
255
- The plugin describes suwgate 0.20.0; a repository on an older package lacks `stats`, `doctor`, `dashboard` and `garden-ran`, and the skills say so instead of working around it.
266
+ The plugin describes suwgate 0.21.0; a repository on an older package lacks `stats`, `doctor`, `dashboard` and `garden-ran`, and the skills say so instead of working around it.
256
267
 
257
268
  ## Configuration
258
269
 
package/dist/cli.js CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { readdirSync, readFileSync } from "node:fs";
2
+ import { spawnSync } from "node:child_process";
3
+ import { readdirSync, readFileSync, realpathSync } from "node:fs";
3
4
  import { homedir } from "node:os";
4
5
  import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
5
7
  import { parseArgs } from "node:util";
6
8
  import { check, step } from "./gate/check.js";
7
9
  import { dev, realEnvironment } from "./dev/index.js";
@@ -27,6 +29,7 @@ import { guardPr } from "./session/guardPr.js";
27
29
  import { guardEdit } from "./session/guardEdit.js";
28
30
  import { preCommit, runTool } from "./session/preCommit.js";
29
31
  import { prePush } from "./session/prePush.js";
32
+ import { findOwnInstall } from "./session/ownInstall.js";
30
33
  import { LEFT_TO_CI, ship } from "./session/ship.js";
31
34
  import { stop } from "./session/stop.js";
32
35
  const USAGE = `usage: suwgate check [--quick] [--verbose] | suwgate step [<id> [--only] [--verbose] [-- <args>]] | suwgate hook <guard-edit|guard-pr|stop|pre-commit|pre-push> | suwgate ship | suwgate stats [--days <n>] [--json] | suwgate doctor | suwgate context | suwgate dashboard [--days <n>] [--no-ci] [--out <path> | --serve [--port <n>] | --json] | suwgate garden-ran <kind>=<count>... | suwgate dev <command> | suwgate agents-shared | suwgate --help | --version
@@ -202,7 +205,29 @@ async function runStep(argv) {
202
205
  (result.exitCode === 0 ? console.log : console.error)(result.text);
203
206
  return result.exitCode;
204
207
  }
208
+ const HANDED_OVER = "SUWGATE_OWN";
209
+ function ownVersionFirst(argv) {
210
+ if (process.env[HANDED_OVER] === "1")
211
+ return null;
212
+ const root = repositoryRoot(process.cwd());
213
+ if (root === null)
214
+ return null;
215
+ const own = findOwnInstall(root);
216
+ if (own.cli === null) {
217
+ if (own.declaredIn === null)
218
+ return null;
219
+ console.error(`suwgate: this repository pins its own suwgate in ${path.join(path.relative(root, own.declaredIn), "package.json")}, and it is not installed: run pnpm install there. Its version, not the one on this machine, is the one CI runs.`);
220
+ return 2;
221
+ }
222
+ if (realpathSync(own.cli) === realpathSync(fileURLToPath(import.meta.url)))
223
+ return null;
224
+ const handed = spawnSync(process.execPath, [own.cli, ...argv], { stdio: "inherit", env: { ...process.env, [HANDED_OVER]: "1" } });
225
+ return handed.status ?? 1;
226
+ }
205
227
  async function main(argv) {
228
+ const handed = ownVersionFirst(argv);
229
+ if (handed !== null)
230
+ return handed;
206
231
  if (argv[0] === "dev")
207
232
  return dev(argv.slice(1), realEnvironment(discoverApi, slowTestsSteps));
208
233
  if (argv[0] === "step")
@@ -0,0 +1,5 @@
1
+ export interface OwnInstall {
2
+ cli: string | null;
3
+ declaredIn: string | null;
4
+ }
5
+ export declare function findOwnInstall(root: string): OwnInstall;
@@ -0,0 +1,38 @@
1
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ const PACKAGE = "@maniumek/suwgate";
4
+ function manifest(file) {
5
+ try {
6
+ return JSON.parse(readFileSync(file, "utf8"));
7
+ }
8
+ catch {
9
+ return null;
10
+ }
11
+ }
12
+ function declares(folder) {
13
+ const own = manifest(path.join(folder, "package.json"));
14
+ return ["dependencies", "devDependencies"].some((field) => {
15
+ const listed = own?.[field];
16
+ return typeof listed === "object" && listed !== null && PACKAGE in listed;
17
+ });
18
+ }
19
+ function cliOf(folder) {
20
+ const installed = path.join(folder, "node_modules", PACKAGE);
21
+ const bin = manifest(path.join(installed, "package.json"))?.["bin"];
22
+ const entry = typeof bin === "object" && bin !== null ? bin["suwgate"] : bin;
23
+ if (typeof entry !== "string")
24
+ return null;
25
+ const cli = path.join(installed, entry);
26
+ return existsSync(cli) ? cli : null;
27
+ }
28
+ function folders(root) {
29
+ const inner = readdirSync(root, { withFileTypes: true })
30
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules")
31
+ .map((entry) => path.join(root, entry.name));
32
+ return [root, ...inner.toSorted()];
33
+ }
34
+ export function findOwnInstall(root) {
35
+ const declaring = folders(root).filter(declares);
36
+ const cli = declaring.map(cliOf).find((found) => found !== null) ?? null;
37
+ return { cli, declaredIn: declaring[0] ?? null };
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maniumek/suwgate",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "One quality gate for every repository: suwgate check runs the steps of the repository's profiles and its guards, configured in suwgate.yml",
5
5
  "license": "MIT",
6
6
  "author": "Manomenu",