@multiplatform.one/cli 8.1.0 → 8.2.1

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
@@ -39,7 +39,7 @@ A project is the multiplatform.one monorepo at one commit, pruned:
39
39
  - Without `--service keycloak` the keycloak compose service, `postgres` and
40
40
  its `.env` keys, the `docker-bake.hcl` target and the `docker/Makefile`
41
41
  cert block go. With neither service, `docker/compose.yaml` is
42
- `services: {}` and there is no `pnpm backend`.
42
+ `services: {}`.
43
43
  - `apps/one`, the One platform app, becomes `apps/my-app` (package
44
44
  `@app/my-app`, app.config slug and scheme, bundle id, tauri identifier, the
45
45
  `Makefile` `my-app/%` rules, `.vscode`, `.gitignore`), with
@@ -163,8 +163,8 @@ sh scripts/scaffold.sh [--app <name>]... [--service <name>]... [--mpo-version <r
163
163
  | `mpo frappe types <doctype…>` | Emit doctype TypeScript types from getdoctype; `--check -o <file>` fails on drift |
164
164
  | `mpo build` | Run the build command |
165
165
  | `mpo test [tier]` | Run unit (default), integration, e2e or visual tests (E2E: `--up-only`, …) |
166
- | `mpo lint` | Run the root `lint` script (`//#lint`), then `ruff check` |
167
- | `mpo format` | Run the root `format` script (`//#format`), then `ruff format` |
166
+ | `mpo lint` | Run the root `lint` script, then `black --check` and `basedpyright` |
167
+ | `mpo format` | Run the root `format` script (your uncommitted files), then `black` |
168
168
  | `mpo count` | Count lines of code with `cloc` |
169
169
  | `mpo generate` | Run the turbo `generate` task |
170
170
 
@@ -4,9 +4,9 @@ import { adoptApp } from "../commands/adoptApp.mjs";
4
4
  import { generateDoctypeTypes, typesDrift } from "../commands/doctypeTypes.mjs";
5
5
  import { runE2ESession } from "../commands/e2e.mjs";
6
6
  import { SINGLETON_APPS, init } from "../commands/init.mjs";
7
- import { runRuff } from "../commands/ruff.mjs";
7
+ import { pythonFiles, runPythonTools } from "../commands/pythonTools.mjs";
8
8
  import { updateApp } from "../commands/updateApp.mjs";
9
- import { availableServices, parseTestTiers, runBuild, runFrappeBench, runIntegrationTests, runTurboLint, runUnitTests, testTiers, waitFunctions } from "../commands/verbs.mjs";
9
+ import { availableServices, parseTestTiers, runBuild, runFrappeBench, runIntegrationTests, runRootFormat, runRootLint, runUnitTests, testTiers, waitFunctions } from "../commands/verbs.mjs";
10
10
  import fsSync from "node:fs";
11
11
  import path from "node:path";
12
12
  import { fileURLToPath } from "node:url";
@@ -272,33 +272,32 @@ program.command("test").argument("[args...]", `test to run: ${testTiers.join(",
272
272
  }
273
273
  });
274
274
  /**
275
- * Run ruff format or check on the Frappe Python apps (if present).
276
- * Returns true if the ruff step failed.
275
+ * Run black, or black --check and basedpyright, on the project's Python files (if any).
276
+ * Returns true if the Python step failed.
277
277
  */
278
- async function ruffStep(mode) {
279
- const frappeApps = path.join(projectRoot, "apps", "frappe", "apps");
280
- if (!fsSync.existsSync(frappeApps)) return false;
281
- console.log(`\n── ${mode === "format" ? "ruff format" : "ruff check"} (Python) ──`);
282
- const reason = await runRuff(mode, path.relative(projectRoot, frappeApps), projectRoot);
278
+ async function pythonStep(mode) {
279
+ let files;
280
+ try {
281
+ files = await pythonFiles(projectRoot);
282
+ } catch (error) {
283
+ console.error(`git ls-files could not list the Python files: ${error.message}`);
284
+ return true;
285
+ }
286
+ if (files.length === 0) return false;
287
+ console.log(`\n── ${mode === "format" ? "black" : "black --check, basedpyright"} (Python) ──`);
288
+ const reason = await runPythonTools(mode, files, projectRoot);
283
289
  if (reason === void 0) return false;
284
290
  console.error(reason);
285
291
  return true;
286
292
  }
287
- program.command("format").description("format all supported files (TS, Python, etc.) via turbo").action(async () => {
288
- await spawn("turbo", [
289
- "run",
290
- "format",
291
- "--filter=//"
292
- ], {
293
- stdio: "inherit",
294
- cwd: projectRoot
295
- });
296
- await ruffStep("format");
293
+ program.command("format").description("format your uncommitted files (pnpm format), then the Python apps").action(async () => {
294
+ await runRootFormat(projectRoot);
295
+ await pythonStep("format");
297
296
  });
298
- program.command("lint").description("lint all supported files (TS, Python, etc.) via turbo").action(async () => {
299
- const turboFailed = await runTurboLint(projectRoot);
300
- const ruffFailed = await ruffStep("check");
301
- if (turboFailed || ruffFailed) process.exit(1);
297
+ program.command("lint").description("lint all supported files (TS, Python, etc.) through pnpm lint").action(async () => {
298
+ const lintFailed = await runRootLint(projectRoot);
299
+ const pythonFailed = await pythonStep("check");
300
+ if (lintFailed || pythonFailed) process.exit(1);
302
301
  });
303
302
  program.command("count").description("count lines of code").action(async () => {
304
303
  await spawn("cloc", ["`git ls-files | grep -E '(html)|(s?css)|(md)|(json)|(yaml)|([jt]sx?)$'`"], {
@@ -0,0 +1,81 @@
1
+ import fsSync from "node:fs";
2
+ import path from "node:path";
3
+ import spawn from "nano-spawn";
4
+
5
+ //#region src/commands/pythonTools.ts
6
+ const pinHint = "uv is pinned in .tool-versions; `make configure` installs it through mise or asdf";
7
+ function errorDetail(error) {
8
+ const e = error ?? {};
9
+ return {
10
+ code: e.cause?.code,
11
+ exitCode: e.exitCode,
12
+ signalName: e.signalName,
13
+ stderr: e.stderr?.trim() || void 0,
14
+ message: e.cause?.message ?? e.message ?? String(error)
15
+ };
16
+ }
17
+ /** Why `uv --version` did not answer, as one line for the lint output. */
18
+ function uvStartFailure(error) {
19
+ const d = errorDetail(error);
20
+ if (d.code === "ENOENT") return `uv is not on PATH. ${pinHint}.`;
21
+ return `uv did not start: ${d.stderr ?? d.message}. ${pinHint}.`;
22
+ }
23
+ /** Why a tool failed once uv had started it, as one line for the lint output. */
24
+ function toolFailure(tool, error) {
25
+ const d = errorDetail(error);
26
+ if (d.signalName) return `${tool} was killed by ${d.signalName}.`;
27
+ if (d.exitCode === 1 && tool === "black --check") return "black --check found files to reformat (listed above).";
28
+ if (d.exitCode === 1 && tool === "basedpyright") return "basedpyright found errors .basedpyright/baseline.json does not hold (listed above).";
29
+ if (d.exitCode !== void 0) return `${tool} exited ${d.exitCode}, a configuration or usage error (see above).`;
30
+ return `${tool} failed: ${d.message}.`;
31
+ }
32
+ /**
33
+ * The Python files git knows under `cwd`, tracked or untracked and not
34
+ * ignored, that are still on disk: the set CI's frappe/lint job checks.
35
+ */
36
+ async function pythonFiles(cwd, spawn$1 = spawn) {
37
+ const { stdout } = await spawn$1("git", [
38
+ "ls-files",
39
+ "-z",
40
+ "--cached",
41
+ "--others",
42
+ "--exclude-standard",
43
+ "--",
44
+ "*.py",
45
+ "*.pyi"
46
+ ], { cwd });
47
+ return [...new Set(stdout.split("\0").filter(Boolean))].filter((file) => fsSync.existsSync(path.join(cwd, file)));
48
+ }
49
+ /**
50
+ * Run black, or black --check then basedpyright, on `files` through the uv
51
+ * project at `cwd`, first proving uv starts and the lock is there, so a missing
52
+ * install or project is reported as that instead of as a lint failure. Returns
53
+ * the reasons it failed, one per line, or undefined when it passed.
54
+ */
55
+ async function runPythonTools(mode, files, cwd, spawn$2 = spawn) {
56
+ try {
57
+ await spawn$2("uv", ["--version"], { cwd });
58
+ } catch (error) {
59
+ return uvStartFailure(error);
60
+ }
61
+ if (!fsSync.existsSync(path.join(cwd, "uv.lock"))) return "No uv.lock at the project root pins black and basedpyright; `mpo update` brings it and pyproject.toml.";
62
+ const steps = mode === "format" ? [["black", ["black"]]] : [["black --check", ["black", "--check"]], ["basedpyright", ["basedpyright"]]];
63
+ const reasons = [];
64
+ for (const [tool, args] of steps) try {
65
+ await spawn$2("uv", [
66
+ "run",
67
+ "--locked",
68
+ ...args,
69
+ ...files
70
+ ], {
71
+ stdio: "inherit",
72
+ cwd
73
+ });
74
+ } catch (error) {
75
+ reasons.push(toolFailure(tool, error));
76
+ }
77
+ return reasons.length > 0 ? reasons.join("\n") : void 0;
78
+ }
79
+
80
+ //#endregion
81
+ export { pythonFiles, runPythonTools, toolFailure, uvStartFailure };
@@ -63,6 +63,29 @@ async function getTurboExcludeFiltersForMissing(root) {
63
63
  }
64
64
  return filters;
65
65
  }
66
+ function frappeEntryName(entry) {
67
+ if (typeof entry === "string") return {
68
+ src: entry,
69
+ name: path.basename(entry)
70
+ };
71
+ if (!entry.source || !entry.name) return void 0;
72
+ return {
73
+ src: entry.source,
74
+ name: entry.name
75
+ };
76
+ }
77
+ function resolveFrappeApp(frappeDir, entry) {
78
+ const named = frappeEntryName(entry);
79
+ if (!named) return void 0;
80
+ const src = named.src.startsWith("file://") ? named.src.slice(7) : named.src;
81
+ if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) return void 0;
82
+ const absolutePath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
83
+ if (!fsSync.existsSync(absolutePath)) return void 0;
84
+ return {
85
+ name: named.name,
86
+ absolutePath
87
+ };
88
+ }
66
89
  /** Discover frappe apps from frappe.yaml that have local source paths.
67
90
  * Supports both string entries (`- ./apps/core`) and object entries (`- name: core\n source: ./apps/core`). */
68
91
  async function getFrappeApps(root) {
@@ -70,29 +93,7 @@ async function getFrappeApps(root) {
70
93
  const frappeYamlPath = path.join(frappeDir, "frappe.yaml");
71
94
  if (!fsSync.existsSync(frappeYamlPath)) return [];
72
95
  const raw = await fs.readFile(frappeYamlPath, "utf8");
73
- const config = YAML.parse(raw);
74
- const out = [];
75
- for (const app of config?.apps ?? []) {
76
- let src;
77
- let name;
78
- if (typeof app === "string") {
79
- src = app;
80
- name = path.basename(app);
81
- } else {
82
- if (!app.source || !app.name) continue;
83
- src = app.source;
84
- name = app.name;
85
- }
86
- src = src.startsWith("file://") ? src.slice(7) : src;
87
- if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) continue;
88
- const absPath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
89
- if (!fsSync.existsSync(absPath)) continue;
90
- out.push({
91
- name,
92
- absolutePath: absPath
93
- });
94
- }
95
- return out;
96
+ return (YAML.parse(raw)?.apps ?? []).map((entry) => resolveFrappeApp(frappeDir, entry)).filter((app) => app !== void 0);
96
97
  }
97
98
  const testTiers = [
98
99
  "unit",
@@ -186,17 +187,8 @@ async function runBuild(args, projectRoot, spawn$3 = spawn) {
186
187
  const packages = parsed.includes("packages");
187
188
  const projects = parsed.filter((arg) => arg !== "packages");
188
189
  const presentApps = await getPresentApps(projectRoot);
189
- const presentServices = await getPresentServices(projectRoot);
190
- if (!projects.length && !packages || packages) await spawn$3("pnpm", [
191
- "turbo",
192
- "run",
193
- "build",
194
- "--filter",
195
- "'!./apps/*'",
196
- ...presentServices.flatMap((s) => ["--filter", `'!./${serviceDir(s)}'`])
197
- ], {
190
+ if (!projects.length && !packages || packages) await spawn$3("pnpm", ["run", "build"], {
198
191
  stdio: "inherit",
199
- shell: true,
200
192
  cwd: projectRoot
201
193
  });
202
194
  for (const platform of presentApps) if (!projects.length && !packages || projects.includes(platform)) {
@@ -212,14 +204,10 @@ async function runBuild(args, projectRoot, spawn$3 = spawn) {
212
204
  });
213
205
  }
214
206
  }
215
- /** `mpo lint`'s turbo half: the root `//#lint` task. Resolves true when it failed. */
216
- async function runTurboLint(projectRoot, spawn$4 = spawn) {
207
+ /** `mpo lint`'s pnpm half: the root `lint` script. Resolves true when it failed. */
208
+ async function runRootLint(projectRoot, spawn$4 = spawn) {
217
209
  try {
218
- await spawn$4("turbo", [
219
- "run",
220
- "lint",
221
- "--filter=//"
222
- ], {
210
+ await spawn$4("pnpm", ["run", "lint"], {
223
211
  stdio: "inherit",
224
212
  cwd: projectRoot
225
213
  });
@@ -228,9 +216,16 @@ async function runTurboLint(projectRoot, spawn$4 = spawn) {
228
216
  return true;
229
217
  }
230
218
  }
219
+ /** `mpo format`'s pnpm half: the root `format` script. */
220
+ async function runRootFormat(projectRoot, spawn$5 = spawn) {
221
+ await spawn$5("pnpm", ["run", "format"], {
222
+ stdio: "inherit",
223
+ cwd: projectRoot
224
+ });
225
+ }
231
226
  /** `mpo frappe bench [args...]`: frappe.sh's bench command with the arguments passed through as given. */
232
- async function runFrappeBench(args, frappeScript, projectRoot, spawn$5 = spawn) {
233
- await spawn$5("sh", [
227
+ async function runFrappeBench(args, frappeScript, projectRoot, spawn$6 = spawn) {
228
+ await spawn$6("sh", [
234
229
  frappeScript,
235
230
  "bench",
236
231
  ...args
@@ -248,4 +243,4 @@ const waitFunctions = {
248
243
  };
249
244
 
250
245
  //#endregion
251
- export { availableServices, parseTestTiers, runBuild, runFrappeBench, runIntegrationTests, runTurboLint, runUnitTests, testTiers, waitFunctions };
246
+ export { availableServices, parseTestTiers, runBuild, runFrappeBench, runIntegrationTests, runRootFormat, runRootLint, runUnitTests, testTiers, waitFunctions };
package/lib/source.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "cliVersion": "8.1.0",
2
+ "cliVersion": "8.2.1",
3
3
  "url": "https://git.corp.bitspur.com/multiplatform.one/mpo.git",
4
- "sha": "e31385ea6386809a964fcf0fe7ac01b1dc2c7668"
4
+ "sha": "d378324f3d6c5da52c7ca945c20e049daf128ec8"
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/cli",
3
- "version": "8.1.0",
3
+ "version": "8.2.1",
4
4
  "description": "multiplatform.one cli — mpo init clones and prunes the monorepo, mpo update merges it back",
5
5
  "keywords": [
6
6
  "create-multiplatform-app",
@@ -57,7 +57,7 @@
57
57
  "access": "public"
58
58
  },
59
59
  "dependencies": {
60
- "@multiplatform.one/utils": "^8.1.0",
60
+ "@multiplatform.one/utils": "^8.2.1",
61
61
  "commander": "^15.0.0",
62
62
  "dotenv": "^17.4.2",
63
63
  "inquirer": "^14.2.3",
@@ -555,10 +555,9 @@ fi
555
555
  # redis and mailpit; keycloak: its postgres), when it bind-mounts from under
556
556
  # apps/<app>, or when it depends on a service that went, and so do the named
557
557
  # volumes only those services used. With no service left the file is
558
- # `services: {}`, which compose still reads, and `pnpm backend` goes with the
559
- # services it started. A bake target building from apps/<app> and a
560
- # `# <app>-block` of docker/Makefile go too. Nothing is rewritten while every
561
- # app they name is kept.
558
+ # `services: {}`, which compose still reads. A bake target building from
559
+ # apps/<app> and a `# <app>-block` of docker/Makefile go too. Nothing is
560
+ # rewritten while every app they name is kept.
562
561
  if [ -n "$REMOVED_APPS" ] && [ -f "$TREE/docker/compose.yaml" ]; then
563
562
  awk -v removed="$REMOVED_APPS" '
564
563
  function record(svc, section, value, name) {
@@ -679,17 +678,6 @@ if [ -n "$REMOVED_APPS" ] && [ -f "$TREE/docker/compose.yaml" ]; then
679
678
  }
680
679
  ' "$TREE/docker/compose.yaml" >"$TREE/docker/compose.yaml.scaffold.tmp" &&
681
680
  mv "$TREE/docker/compose.yaml.scaffold.tmp" "$TREE/docker/compose.yaml"
682
- if grep -q '^services: {}$' "$TREE/docker/compose.yaml"; then
683
- node - "$TREE/package.json" <<'NODE'
684
- const fs = require("node:fs");
685
- const file = process.argv[2];
686
- const pkg = JSON.parse(fs.readFileSync(file, "utf8"));
687
- if (pkg.scripts?.backend?.includes("docker/compose.yaml")) {
688
- delete pkg.scripts.backend;
689
- fs.writeFileSync(file, `${JSON.stringify(pkg, null, 2)}\n`);
690
- }
691
- NODE
692
- fi
693
681
  fi
694
682
  if [ -n "$REMOVED_APPS" ] && [ -f "$TREE/docker/docker-bake.hcl" ]; then
695
683
  awk -v removed="$REMOVED_APPS" '
@@ -898,8 +886,8 @@ for (const [name, value] of Object.entries(scripts)) {
898
886
  const kept = value
899
887
  .split(" && ")
900
888
  .filter((segment) => {
901
- const match = segment.match(/^pnpm\s+([\w:.-]+)$/);
902
- return !match || match[1] in scripts;
889
+ const match = segment.match(/^pnpm\s+(?:run\s+)?([a-z][\w:.-]*)(?:\s|$)/);
890
+ return !match || match[1] in scripts || !(match[1] in (pkg.scripts ?? {}));
903
891
  });
904
892
  if (kept.length) scripts[name] = kept.join(" && ");
905
893
  else delete scripts[name];
@@ -19,7 +19,7 @@ import { generateDoctypeTypes, typesDrift } from "../commands/doctypeTypes";
19
19
  import { runE2ESession } from "../commands/e2e";
20
20
  import { SINGLETON_APPS, init } from "../commands/init";
21
21
  import { INIT_APP_PIECES } from "../commands/pieces";
22
- import { runRuff } from "../commands/ruff";
22
+ import { type PythonMode, pythonFiles, runPythonTools } from "../commands/pythonTools";
23
23
  import { updateApp } from "../commands/updateApp";
24
24
  import {
25
25
  availableServices,
@@ -27,7 +27,8 @@ import {
27
27
  runBuild,
28
28
  runFrappeBench,
29
29
  runIntegrationTests,
30
- runTurboLint,
30
+ runRootFormat,
31
+ runRootLint,
31
32
  runUnitTests,
32
33
  testTiers,
33
34
  waitFunctions,
@@ -490,15 +491,21 @@ program
490
491
  });
491
492
 
492
493
  /**
493
- * Run ruff format or check on the Frappe Python apps (if present).
494
- * Returns true if the ruff step failed.
494
+ * Run black, or black --check and basedpyright, on the project's Python files (if any).
495
+ * Returns true if the Python step failed.
495
496
  */
496
- async function ruffStep(mode: "format" | "check"): Promise<boolean> {
497
- const frappeApps = path.join(projectRoot, "apps", "frappe", "apps");
498
- if (!fsSync.existsSync(frappeApps)) return false;
499
- const label = mode === "format" ? "ruff format" : "ruff check";
497
+ async function pythonStep(mode: PythonMode): Promise<boolean> {
498
+ let files: string[];
499
+ try {
500
+ files = await pythonFiles(projectRoot);
501
+ } catch (error) {
502
+ console.error(`git ls-files could not list the Python files: ${(error as Error).message}`);
503
+ return true;
504
+ }
505
+ if (files.length === 0) return false;
506
+ const label = mode === "format" ? "black" : "black --check, basedpyright";
500
507
  console.log(`\n── ${label} (Python) ──`);
501
- const reason = await runRuff(mode, path.relative(projectRoot, frappeApps), projectRoot);
508
+ const reason = await runPythonTools(mode, files, projectRoot);
502
509
  if (reason === undefined) return false;
503
510
  console.error(reason);
504
511
  return true;
@@ -506,22 +513,19 @@ async function ruffStep(mode: "format" | "check"): Promise<boolean> {
506
513
 
507
514
  program
508
515
  .command("format")
509
- .description("format all supported files (TS, Python, etc.) via turbo")
516
+ .description("format your uncommitted files (pnpm format), then the Python apps")
510
517
  .action(async () => {
511
- await spawn("turbo", ["run", "format", "--filter=//"], {
512
- stdio: "inherit",
513
- cwd: projectRoot,
514
- });
515
- await ruffStep("format");
518
+ await runRootFormat(projectRoot);
519
+ await pythonStep("format");
516
520
  });
517
521
 
518
522
  program
519
523
  .command("lint")
520
- .description("lint all supported files (TS, Python, etc.) via turbo")
524
+ .description("lint all supported files (TS, Python, etc.) through pnpm lint")
521
525
  .action(async () => {
522
- const turboFailed = await runTurboLint(projectRoot);
523
- const ruffFailed = await ruffStep("check");
524
- if (turboFailed || ruffFailed) process.exit(1);
526
+ const lintFailed = await runRootLint(projectRoot);
527
+ const pythonFailed = await pythonStep("check");
528
+ if (lintFailed || pythonFailed) process.exit(1);
525
529
  });
526
530
 
527
531
  program
@@ -0,0 +1,134 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import nanoSpawn from "nano-spawn";
5
+ import { afterEach, describe, expect, it } from "vitest";
6
+ import { pythonFiles, runPythonTools } from "./pythonTools";
7
+
8
+ type Spawn = typeof nanoSpawn;
9
+
10
+ // Runs a real subprocess in place of uv, so the errors are nano-spawn's own.
11
+ function standIn(script: (args: readonly string[]) => string, calls: string[][] = []): Spawn {
12
+ return ((_file: string, args: readonly string[] = [], options = {}) => {
13
+ calls.push([...args]);
14
+ return nanoSpawn("sh", ["-c", script(args)], options);
15
+ }) as Spawn;
16
+ }
17
+
18
+ const files = ["apps/frappe/serve_dev.py", "scripts/tool.py"];
19
+
20
+ const dirs: string[] = [];
21
+ afterEach(() => {
22
+ for (const dir of dirs.splice(0)) fs.rmSync(dir, { recursive: true, force: true });
23
+ });
24
+
25
+ function tempDir(): string {
26
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fz-10574-"));
27
+ dirs.push(dir);
28
+ return dir;
29
+ }
30
+
31
+ function project(): string {
32
+ const dir = tempDir();
33
+ fs.writeFileSync(path.join(dir, "uv.lock"), "version = 1\n");
34
+ return dir;
35
+ }
36
+
37
+ describe("runPythonTools (MPO-497, FZ-10574)", () => {
38
+ it("names a missing uv and the pin that provides it", async () => {
39
+ const missing = ((_file: string, args: readonly string[] = [], options = {}) =>
40
+ nanoSpawn("fz-10574-no-such-uv", [...args], options)) as Spawn;
41
+ const reason = await runPythonTools("check", files, project(), missing);
42
+ expect(reason).toMatch(/^uv is not on PATH\./);
43
+ expect(reason).toContain(".tool-versions");
44
+ expect(reason).toContain("make configure");
45
+ });
46
+
47
+ it("reports a uv that will not start with what it printed", async () => {
48
+ const shim = standIn(() => "echo 'mise ERROR No version is set for shim: uv' >&2; exit 1");
49
+ const reason = await runPythonTools("check", files, project(), shim);
50
+ expect(reason).toBe(
51
+ "uv did not start: mise ERROR No version is set for shim: uv. uv is pinned in .tool-versions; `make configure` installs it through mise or asdf.",
52
+ );
53
+ });
54
+
55
+ it("checks with black --check, then basedpyright, over the files through the locked uv project", async () => {
56
+ const calls: string[][] = [];
57
+ expect(
58
+ await runPythonTools(
59
+ "check",
60
+ files,
61
+ project(),
62
+ standIn(() => "true", calls),
63
+ ),
64
+ ).toBe(undefined);
65
+ expect(calls).toEqual([
66
+ ["--version"],
67
+ ["run", "--locked", "black", "--check", ...files],
68
+ ["run", "--locked", "basedpyright", ...files],
69
+ ]);
70
+ });
71
+
72
+ it("formats with black alone", async () => {
73
+ const calls: string[][] = [];
74
+ expect(
75
+ await runPythonTools(
76
+ "format",
77
+ files,
78
+ project(),
79
+ standIn(() => "true", calls),
80
+ ),
81
+ ).toBe(undefined);
82
+ expect(calls).toEqual([["--version"], ["run", "--locked", "black", ...files]]);
83
+ });
84
+
85
+ it("names a project without uv.lock before running anything", async () => {
86
+ const calls: string[][] = [];
87
+ const reason = await runPythonTools(
88
+ "check",
89
+ files,
90
+ tempDir(),
91
+ standIn(() => "true", calls),
92
+ );
93
+ expect(reason).toBe(
94
+ "No uv.lock at the project root pins black and basedpyright; `mpo update` brings it and pyproject.toml.",
95
+ );
96
+ expect(calls).toEqual([["--version"]]);
97
+ });
98
+
99
+ it("runs both checks and separates findings from a configuration error", async () => {
100
+ const findings = standIn((args) => (args[0] === "--version" ? "true" : "exit 1"));
101
+ expect(await runPythonTools("check", files, project(), findings)).toBe(
102
+ [
103
+ "black --check found files to reformat (listed above).",
104
+ "basedpyright found errors .basedpyright/baseline.json does not hold (listed above).",
105
+ ].join("\n"),
106
+ );
107
+ const broken = standIn((args) =>
108
+ args[0] === "--version" ? "true" : args.includes("basedpyright") ? "exit 3" : "true",
109
+ );
110
+ expect(await runPythonTools("check", files, project(), broken)).toBe(
111
+ "basedpyright exited 3, a configuration or usage error (see above).",
112
+ );
113
+ });
114
+ });
115
+
116
+ describe("pythonFiles (FZ-10574)", () => {
117
+ it("lists tracked and untracked Python files, never ignored or deleted ones", async () => {
118
+ const dir = tempDir();
119
+ const write = (file: string) => {
120
+ fs.mkdirSync(path.dirname(path.join(dir, file)), { recursive: true });
121
+ fs.writeFileSync(path.join(dir, file), "x = 1\n");
122
+ };
123
+ await nanoSpawn("git", ["init", "--quiet"], { cwd: dir });
124
+ for (const file of ["tracked.py", "gone.py", "notes.txt", "apps/frappe/env/lib/site.py"])
125
+ write(file);
126
+ fs.writeFileSync(path.join(dir, ".gitignore"), "/apps/frappe/env\n");
127
+ await nanoSpawn("git", ["add", "tracked.py", "gone.py", "notes.txt", ".gitignore"], {
128
+ cwd: dir,
129
+ });
130
+ fs.rmSync(path.join(dir, "gone.py"));
131
+ write("typings/frappe/__init__.pyi");
132
+ expect((await pythonFiles(dir)).sort()).toEqual(["tracked.py", "typings/frappe/__init__.pyi"]);
133
+ });
134
+ });
@@ -0,0 +1,106 @@
1
+ import fsSync from "node:fs";
2
+ import path from "node:path";
3
+ import nanoSpawn from "nano-spawn";
4
+
5
+ export type PythonMode = "format" | "check";
6
+
7
+ type Spawn = typeof nanoSpawn;
8
+
9
+ type Tool = "black" | "black --check" | "basedpyright";
10
+
11
+ const pinHint = "uv is pinned in .tool-versions; `make configure` installs it through mise or asdf";
12
+
13
+ function errorDetail(error: unknown): {
14
+ code?: string;
15
+ exitCode?: number;
16
+ signalName?: string;
17
+ stderr?: string;
18
+ message: string;
19
+ } {
20
+ const e = (error ?? {}) as {
21
+ cause?: { code?: string; message?: string };
22
+ exitCode?: number;
23
+ signalName?: string;
24
+ stderr?: string;
25
+ message?: string;
26
+ };
27
+ return {
28
+ code: e.cause?.code,
29
+ exitCode: e.exitCode,
30
+ signalName: e.signalName,
31
+ stderr: e.stderr?.trim() || undefined,
32
+ message: e.cause?.message ?? e.message ?? String(error),
33
+ };
34
+ }
35
+
36
+ /** Why `uv --version` did not answer, as one line for the lint output. */
37
+ export function uvStartFailure(error: unknown): string {
38
+ const d = errorDetail(error);
39
+ if (d.code === "ENOENT") return `uv is not on PATH. ${pinHint}.`;
40
+ const why = d.stderr ?? d.message;
41
+ return `uv did not start: ${why}. ${pinHint}.`;
42
+ }
43
+
44
+ /** Why a tool failed once uv had started it, as one line for the lint output. */
45
+ export function toolFailure(tool: Tool, error: unknown): string {
46
+ const d = errorDetail(error);
47
+ if (d.signalName) return `${tool} was killed by ${d.signalName}.`;
48
+ if (d.exitCode === 1 && tool === "black --check")
49
+ return "black --check found files to reformat (listed above).";
50
+ if (d.exitCode === 1 && tool === "basedpyright")
51
+ return "basedpyright found errors .basedpyright/baseline.json does not hold (listed above).";
52
+ if (d.exitCode !== undefined)
53
+ return `${tool} exited ${d.exitCode}, a configuration or usage error (see above).`;
54
+ return `${tool} failed: ${d.message}.`;
55
+ }
56
+
57
+ /**
58
+ * The Python files git knows under `cwd`, tracked or untracked and not
59
+ * ignored, that are still on disk: the set CI's frappe/lint job checks.
60
+ */
61
+ export async function pythonFiles(cwd: string, spawn: Spawn = nanoSpawn): Promise<string[]> {
62
+ const { stdout } = await spawn(
63
+ "git",
64
+ ["ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", "*.py", "*.pyi"],
65
+ { cwd },
66
+ );
67
+ const listed = new Set(stdout.split("\0").filter(Boolean));
68
+ return [...listed].filter((file) => fsSync.existsSync(path.join(cwd, file)));
69
+ }
70
+
71
+ /**
72
+ * Run black, or black --check then basedpyright, on `files` through the uv
73
+ * project at `cwd`, first proving uv starts and the lock is there, so a missing
74
+ * install or project is reported as that instead of as a lint failure. Returns
75
+ * the reasons it failed, one per line, or undefined when it passed.
76
+ */
77
+ export async function runPythonTools(
78
+ mode: PythonMode,
79
+ files: readonly string[],
80
+ cwd: string,
81
+ spawn: Spawn = nanoSpawn,
82
+ ): Promise<string | undefined> {
83
+ try {
84
+ await spawn("uv", ["--version"], { cwd });
85
+ } catch (error) {
86
+ return uvStartFailure(error);
87
+ }
88
+ if (!fsSync.existsSync(path.join(cwd, "uv.lock")))
89
+ return "No uv.lock at the project root pins black and basedpyright; `mpo update` brings it and pyproject.toml.";
90
+ const steps: [Tool, string[]][] =
91
+ mode === "format"
92
+ ? [["black", ["black"]]]
93
+ : [
94
+ ["black --check", ["black", "--check"]],
95
+ ["basedpyright", ["basedpyright"]],
96
+ ];
97
+ const reasons: string[] = [];
98
+ for (const [tool, args] of steps) {
99
+ try {
100
+ await spawn("uv", ["run", "--locked", ...args, ...files], { stdio: "inherit", cwd });
101
+ } catch (error) {
102
+ reasons.push(toolFailure(tool, error));
103
+ }
104
+ }
105
+ return reasons.length > 0 ? reasons.join("\n") : undefined;
106
+ }
@@ -11,7 +11,8 @@ import {
11
11
  runBuild,
12
12
  runFrappeBench,
13
13
  runIntegrationTests,
14
- runTurboLint,
14
+ runRootFormat,
15
+ runRootLint,
15
16
  runUnitTests,
16
17
  waitFunctions,
17
18
  } from "./verbs";
@@ -252,20 +253,36 @@ describe("mpo build (FZ-10496)", () => {
252
253
  ["pnpm", "turbo", "run", "build", "--filter=./apps/solana"],
253
254
  ]);
254
255
  });
256
+
257
+ it("builds the packages through the root build script, the one pnpm build runs (FZ-10576)", async () => {
258
+ const { calls, spawn } = recorder();
259
+ await runBuild(["packages"], root, spawn);
260
+ expect(calls).toEqual([{ file: "pnpm", args: ["run", "build"], cwd: root }]);
261
+ calls.length = 0;
262
+ await runBuild([], root, spawn);
263
+ expect(calls[0]).toEqual({ file: "pnpm", args: ["run", "build"], cwd: root });
264
+ });
255
265
  });
256
266
 
257
267
  describe("mpo lint (FZ-10496)", () => {
258
- it("runs the root lint task and no typecheck", async () => {
268
+ it("runs the root lint script and no typecheck", async () => {
259
269
  const { calls, spawn } = recorder();
260
- expect(await runTurboLint("/project", spawn)).toBe(false);
261
- expect(calls).toEqual([
262
- { file: "turbo", args: ["run", "lint", "--filter=//"], cwd: "/project" },
263
- ]);
270
+ expect(await runRootLint("/project", spawn)).toBe(false);
271
+ expect(calls).toEqual([{ file: "pnpm", args: ["run", "lint"], cwd: "/project" }]);
264
272
  });
265
273
 
266
274
  it("reports a failed lint", async () => {
267
275
  const { spawn } = recorder(() => true);
268
- expect(await runTurboLint("/project", spawn)).toBe(true);
276
+ expect(await runRootLint("/project", spawn)).toBe(true);
277
+ });
278
+ });
279
+
280
+ describe("mpo format (FZ-10576)", () => {
281
+ it("runs the root format script and fails with it", async () => {
282
+ const { calls, spawn } = recorder();
283
+ await runRootFormat("/project", spawn);
284
+ expect(calls).toEqual([{ file: "pnpm", args: ["run", "format"], cwd: "/project" }]);
285
+ await expect(runRootFormat("/project", recorder(() => true).spawn)).rejects.toThrow();
269
286
  });
270
287
  });
271
288
 
@@ -78,33 +78,36 @@ async function getTurboExcludeFiltersForMissing(root: string): Promise<string[]>
78
78
  return filters;
79
79
  }
80
80
 
81
+ type FrappeEntry = string | { name?: string; source?: string };
82
+ type FrappeApp = { name: string; absolutePath: string };
83
+
84
+ function frappeEntryName(entry: FrappeEntry): { src: string; name: string } | undefined {
85
+ if (typeof entry === "string") return { src: entry, name: path.basename(entry) };
86
+ if (!entry.source || !entry.name) return undefined;
87
+ return { src: entry.source, name: entry.name };
88
+ }
89
+
90
+ function resolveFrappeApp(frappeDir: string, entry: FrappeEntry): FrappeApp | undefined {
91
+ const named = frappeEntryName(entry);
92
+ if (!named) return undefined;
93
+ const src = named.src.startsWith("file://") ? named.src.slice(7) : named.src;
94
+ if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) return undefined;
95
+ const absolutePath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
96
+ if (!fsSync.existsSync(absolutePath)) return undefined;
97
+ return { name: named.name, absolutePath };
98
+ }
99
+
81
100
  /** Discover frappe apps from frappe.yaml that have local source paths.
82
101
  * Supports both string entries (`- ./apps/core`) and object entries (`- name: core\n source: ./apps/core`). */
83
- async function getFrappeApps(root: string): Promise<{ name: string; absolutePath: string }[]> {
102
+ async function getFrappeApps(root: string): Promise<FrappeApp[]> {
84
103
  const frappeDir = path.join(root, "apps", "frappe");
85
104
  const frappeYamlPath = path.join(frappeDir, "frappe.yaml");
86
105
  if (!fsSync.existsSync(frappeYamlPath)) return [];
87
106
  const raw = await fs.readFile(frappeYamlPath, "utf8");
88
- const config = YAML.parse(raw) as { apps?: (string | { name?: string; source?: string })[] };
89
- const out: { name: string; absolutePath: string }[] = [];
90
- for (const app of config?.apps ?? []) {
91
- let src: string;
92
- let name: string;
93
- if (typeof app === "string") {
94
- src = app;
95
- name = path.basename(app);
96
- } else {
97
- if (!app.source || !app.name) continue;
98
- src = app.source;
99
- name = app.name;
100
- }
101
- src = src.startsWith("file://") ? src.slice(7) : src;
102
- if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) continue;
103
- const absPath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
104
- if (!fsSync.existsSync(absPath)) continue;
105
- out.push({ name, absolutePath: absPath });
106
- }
107
- return out;
107
+ const config = YAML.parse(raw) as { apps?: FrappeEntry[] };
108
+ return (config?.apps ?? [])
109
+ .map((entry) => resolveFrappeApp(frappeDir, entry))
110
+ .filter((app): app is FrappeApp => app !== undefined);
108
111
  }
109
112
 
110
113
  export const testTiers = ["unit", "integration", "e2e", "visual"] as const;
@@ -210,24 +213,8 @@ export async function runBuild(
210
213
  const packages = parsed.includes("packages");
211
214
  const projects = parsed.filter((arg) => arg !== "packages");
212
215
  const presentApps = await getPresentApps(projectRoot);
213
- const presentServices = await getPresentServices(projectRoot);
214
216
  if ((!projects.length && !packages) || packages) {
215
- await spawn(
216
- "pnpm",
217
- [
218
- "turbo",
219
- "run",
220
- "build",
221
- "--filter",
222
- "'!./apps/*'",
223
- ...presentServices.flatMap((s) => ["--filter", `'!./${serviceDir(s)}'`]),
224
- ],
225
- {
226
- stdio: "inherit",
227
- shell: true,
228
- cwd: projectRoot,
229
- },
230
- );
217
+ await spawn("pnpm", ["run", "build"], { stdio: "inherit", cwd: projectRoot });
231
218
  }
232
219
  for (const platform of presentApps) {
233
220
  if ((!projects.length && !packages) || projects.includes(platform)) {
@@ -251,19 +238,21 @@ export async function runBuild(
251
238
  }
252
239
  }
253
240
 
254
- /** `mpo lint`'s turbo half: the root `//#lint` task. Resolves true when it failed. */
255
- export async function runTurboLint(
256
- projectRoot: string,
257
- spawn: Spawn = nanoSpawn,
258
- ): Promise<boolean> {
241
+ /** `mpo lint`'s pnpm half: the root `lint` script. Resolves true when it failed. */
242
+ export async function runRootLint(projectRoot: string, spawn: Spawn = nanoSpawn): Promise<boolean> {
259
243
  try {
260
- await spawn("turbo", ["run", "lint", "--filter=//"], { stdio: "inherit", cwd: projectRoot });
244
+ await spawn("pnpm", ["run", "lint"], { stdio: "inherit", cwd: projectRoot });
261
245
  return false;
262
246
  } catch {
263
247
  return true;
264
248
  }
265
249
  }
266
250
 
251
+ /** `mpo format`'s pnpm half: the root `format` script. */
252
+ export async function runRootFormat(projectRoot: string, spawn: Spawn = nanoSpawn): Promise<void> {
253
+ await spawn("pnpm", ["run", "format"], { stdio: "inherit", cwd: projectRoot });
254
+ }
255
+
267
256
  /** `mpo frappe bench [args...]`: frappe.sh's bench command with the arguments passed through as given. */
268
257
  export async function runFrappeBench(
269
258
  args: string[],
@@ -152,17 +152,20 @@ loading.
152
152
 
153
153
  ## Tooling
154
154
 
155
- | Command | Purpose |
156
- | ----------------------- | -------------------------------------------------------------- |
157
- | `pnpm dev` | The first product app's dev server (`dev:<name>` when several) |
158
- | `pnpm build` | Build every workspace package except the apps |
159
- | `pnpm build:web` | Production web build of the first product app |
160
- | `pnpm serve` | Serve that build on port 3000 |
161
- | `pnpm lint` | oxlint (incl. convention rules) + structural convention checks |
162
- | `pnpm lint:conventions` | Structural checks only (css twin, features twin) |
163
- | `pnpm format` | oxfmt |
164
- | `pnpm ci:local` | format + lint + typecheck + build + test + verify + tree-clean |
165
- | `pnpm doctor:npmrc` | Check registry auth and the installed workspace linker |
155
+ | Command | Purpose |
156
+ | ----------------------- | ---------------------------------------------------------------------- |
157
+ | `pnpm dev` | The first product app's dev server (`dev:<name>` when several) |
158
+ | `pnpm build` | Build every workspace package except the apps |
159
+ | `pnpm build:web` | Production web build of the first product app |
160
+ | `pnpm serve` | Serve that build on port 3000 |
161
+ | `pnpm lint` | oxlint (incl. convention rules) + structural convention checks |
162
+ | `pnpm lint:ci` | The frozen design lint, `pnpm lint` and the changed-files format check |
163
+ | `pnpm lint:conventions` | Structural checks only (css twin, features twin) |
164
+ | `pnpm typecheck` | Typecheck every workspace package |
165
+ | `pnpm format` | oxfmt on your uncommitted files; `pnpm format <base>` for a branch |
166
+ | `pnpm format:all` | oxfmt over the whole tree |
167
+ | `pnpm ci:local` | lint:ci + typecheck + build + build:web + test + verify + tree-clean |
168
+ | `pnpm doctor:npmrc` | Check registry auth and the installed workspace linker |
166
169
 
167
170
  Use **oxlint / oxfmt**, not ESLint / Prettier. Per-app targets are
168
171
  `make <name>/<target>` from the root `Makefile`.
@@ -1 +1 @@
1
- {"version":3,"file":"multiplatformOne.d.ts","sourceRoot":"","sources":["../../src/bin/multiplatformOne.ts"],"names":[],"mappings":"AAsCA,gHAAgH;AAChH,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,kGAAkG;IAClG,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gGAAgG;IAChG,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC"}
1
+ {"version":3,"file":"multiplatformOne.d.ts","sourceRoot":"","sources":["../../src/bin/multiplatformOne.ts"],"names":[],"mappings":"AAuCA,gHAAgH;AAChH,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,kGAAkG;IAClG,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gGAAgG;IAChG,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import nanoSpawn from "nano-spawn";
2
+ export type PythonMode = "format" | "check";
3
+ type Spawn = typeof nanoSpawn;
4
+ type Tool = "black" | "black --check" | "basedpyright";
5
+ /** Why `uv --version` did not answer, as one line for the lint output. */
6
+ export declare function uvStartFailure(error: unknown): string;
7
+ /** Why a tool failed once uv had started it, as one line for the lint output. */
8
+ export declare function toolFailure(tool: Tool, error: unknown): string;
9
+ /**
10
+ * The Python files git knows under `cwd`, tracked or untracked and not
11
+ * ignored, that are still on disk: the set CI's frappe/lint job checks.
12
+ */
13
+ export declare function pythonFiles(cwd: string, spawn?: Spawn): Promise<string[]>;
14
+ /**
15
+ * Run black, or black --check then basedpyright, on `files` through the uv
16
+ * project at `cwd`, first proving uv starts and the lock is there, so a missing
17
+ * install or project is reported as that instead of as a lint failure. Returns
18
+ * the reasons it failed, one per line, or undefined when it passed.
19
+ */
20
+ export declare function runPythonTools(mode: PythonMode, files: readonly string[], cwd: string, spawn?: Spawn): Promise<string | undefined>;
21
+ export {};
22
+ //# sourceMappingURL=pythonTools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pythonTools.d.ts","sourceRoot":"","sources":["../../src/commands/pythonTools.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE5C,KAAK,KAAK,GAAG,OAAO,SAAS,CAAC;AAE9B,KAAK,IAAI,GAAG,OAAO,GAAG,eAAe,GAAG,cAAc,CAAC;AA2BvD,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAKrD;AAED,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAU9D;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,KAAiB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAQ1F;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAwB7B"}
@@ -12,8 +12,10 @@ export declare function runUnitTests(projectRoot: string, spawn?: Spawn): Promis
12
12
  export declare function runIntegrationTests(projectRoot: string, spawn?: Spawn): Promise<void>;
13
13
  /** `mpo build`: the packages, then every present app with a build script, each once. */
14
14
  export declare function runBuild(args: string[], projectRoot: string, spawn?: Spawn): Promise<void>;
15
- /** `mpo lint`'s turbo half: the root `//#lint` task. Resolves true when it failed. */
16
- export declare function runTurboLint(projectRoot: string, spawn?: Spawn): Promise<boolean>;
15
+ /** `mpo lint`'s pnpm half: the root `lint` script. Resolves true when it failed. */
16
+ export declare function runRootLint(projectRoot: string, spawn?: Spawn): Promise<boolean>;
17
+ /** `mpo format`'s pnpm half: the root `format` script. */
18
+ export declare function runRootFormat(projectRoot: string, spawn?: Spawn): Promise<void>;
17
19
  /** `mpo frappe bench [args...]`: frappe.sh's bench command with the arguments passed through as given. */
18
20
  export declare function runFrappeBench(args: string[], frappeScript: string, projectRoot: string, spawn?: Spawn): Promise<void>;
19
21
  /** The readiness probe behind each `mpo wait` service. */
@@ -1 +1 @@
1
- {"version":3,"file":"verbs.d.ts","sourceRoot":"","sources":["../../src/commands/verbs.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,WAAW,EAKjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,KAAK,KAAK,GAAG,OAAO,SAAS,CAAC;AAE9B,eAAO,MAAM,iBAAiB,UAA0C,CAAC;AA8FzE,eAAO,MAAM,SAAS,mDAAoD,CAAC;AAE3E,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAElD,8FAA8F;AAC9F,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAQzD;AA2CD,gGAAgG;AAChG,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,GAAE,KAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAS/F;AAED,2HAA2H;AAC3H,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED,wFAAwF;AACxF,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EAAE,EACd,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CA4Cf;AAED,sFAAsF;AACtF,wBAAsB,YAAY,CAChC,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,0GAA0G;AAC1G,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EAAE,EACd,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,0DAA0D;AAC1D,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAKlF,CAAC"}
1
+ {"version":3,"file":"verbs.d.ts","sourceRoot":"","sources":["../../src/commands/verbs.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,WAAW,EAKjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,KAAK,KAAK,GAAG,OAAO,SAAS,CAAC;AAE9B,eAAO,MAAM,iBAAiB,UAA0C,CAAC;AAiGzE,eAAO,MAAM,SAAS,mDAAoD,CAAC;AAE3E,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAElD,8FAA8F;AAC9F,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAQzD;AA2CD,gGAAgG;AAChG,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,GAAE,KAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAS/F;AAED,2HAA2H;AAC3H,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED,wFAAwF;AACxF,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EAAE,EACd,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CA4Bf;AAED,oFAAoF;AACpF,wBAAsB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,GAAE,KAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAOjG;AAED,0DAA0D;AAC1D,wBAAsB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,GAAE,KAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhG;AAED,0GAA0G;AAC1G,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EAAE,EACd,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,0DAA0D;AAC1D,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAKlF,CAAC"}
@@ -1,52 +0,0 @@
1
- import spawn from "nano-spawn";
2
-
3
- //#region src/commands/ruff.ts
4
- const pinHint = "ruff is pinned in .tool-versions; `make configure` installs it through mise or asdf";
5
- function errorDetail(error) {
6
- const e = error ?? {};
7
- return {
8
- code: e.cause?.code,
9
- exitCode: e.exitCode,
10
- signalName: e.signalName,
11
- stderr: e.stderr?.trim() || void 0,
12
- message: e.cause?.message ?? e.message ?? String(error)
13
- };
14
- }
15
- /** Why `ruff --version` did not answer, as one line for the lint output. */
16
- function ruffStartFailure(error) {
17
- const d = errorDetail(error);
18
- if (d.code === "ENOENT") return `ruff is not on PATH. ${pinHint}.`;
19
- return `ruff did not start: ${d.stderr ?? d.message}. ${pinHint}.`;
20
- }
21
- /** Why `ruff <mode>` failed once it had started, as one line for the lint output. */
22
- function ruffRunFailure(mode, target, error) {
23
- const d = errorDetail(error);
24
- if (d.signalName) return `ruff ${mode} was killed by ${d.signalName}.`;
25
- if (d.exitCode === 1 && mode === "check") return `ruff check found problems in ${target} (listed above).`;
26
- if (d.exitCode !== void 0) return `ruff ${mode} exited ${d.exitCode}, a configuration or usage error (see above).`;
27
- return `ruff ${mode} failed: ${d.message}.`;
28
- }
29
- /**
30
- * Run ruff format or check on `target`, first proving ruff starts so a missing
31
- * or broken install is reported as that instead of as a lint failure. Returns
32
- * the reason it failed, or undefined when it passed.
33
- */
34
- async function runRuff(mode, target, cwd, spawn$1 = spawn) {
35
- try {
36
- await spawn$1("ruff", ["--version"], { cwd });
37
- } catch (error) {
38
- return ruffStartFailure(error);
39
- }
40
- try {
41
- await spawn$1("ruff", [mode, target], {
42
- stdio: "inherit",
43
- cwd
44
- });
45
- return;
46
- } catch (error) {
47
- return ruffRunFailure(mode, target, error);
48
- }
49
- }
50
-
51
- //#endregion
52
- export { ruffRunFailure, ruffStartFailure, runRuff };
@@ -1,46 +0,0 @@
1
- import nanoSpawn from "nano-spawn";
2
- import { describe, expect, it } from "vitest";
3
- import { runRuff } from "./ruff";
4
-
5
- type Spawn = typeof nanoSpawn;
6
-
7
- // Runs a real subprocess in place of ruff, so the errors are nano-spawn's own.
8
- function standIn(script: (args: readonly string[]) => string): Spawn {
9
- return ((_file: string, args: readonly string[] = [], options = {}) =>
10
- nanoSpawn("sh", ["-c", script(args)], options)) as Spawn;
11
- }
12
-
13
- describe("runRuff (MPO-497)", () => {
14
- it("names a missing ruff and the pin that provides it", async () => {
15
- const missing = ((_file: string, args: readonly string[] = [], options = {}) =>
16
- nanoSpawn("mpo-497-no-such-ruff", [...args], options)) as Spawn;
17
- const reason = await runRuff("check", "apps/frappe/apps", process.cwd(), missing);
18
- expect(reason).toMatch(/^ruff is not on PATH\./);
19
- expect(reason).toContain(".tool-versions");
20
- expect(reason).toContain("make configure");
21
- });
22
-
23
- it("reports a ruff that will not start with what it printed", async () => {
24
- const shim = standIn(() => "echo 'mise ERROR No version is set for shim: ruff' >&2; exit 1");
25
- const reason = await runRuff("check", "apps/frappe/apps", process.cwd(), shim);
26
- expect(reason).toBe(
27
- "ruff did not start: mise ERROR No version is set for shim: ruff. ruff is pinned in .tool-versions; `make configure` installs it through mise or asdf.",
28
- );
29
- });
30
-
31
- it("separates findings from a configuration error", async () => {
32
- const findings = standIn((args) => (args[0] === "--version" ? "true" : "exit 1"));
33
- expect(await runRuff("check", "apps/frappe/apps", process.cwd(), findings)).toBe(
34
- "ruff check found problems in apps/frappe/apps (listed above).",
35
- );
36
- const broken = standIn((args) => (args[0] === "--version" ? "true" : "exit 2"));
37
- expect(await runRuff("check", "apps/frappe/apps", process.cwd(), broken)).toBe(
38
- "ruff check exited 2, a configuration or usage error (see above).",
39
- );
40
- });
41
-
42
- it("passes when ruff starts and exits 0", async () => {
43
- const clean = standIn(() => "true");
44
- expect(await runRuff("check", "apps/frappe/apps", process.cwd(), clean)).toBeUndefined();
45
- });
46
- });
@@ -1,74 +0,0 @@
1
- import nanoSpawn from "nano-spawn";
2
-
3
- export type RuffMode = "format" | "check";
4
-
5
- type Spawn = typeof nanoSpawn;
6
-
7
- const pinHint =
8
- "ruff is pinned in .tool-versions; `make configure` installs it through mise or asdf";
9
-
10
- function errorDetail(error: unknown): {
11
- code?: string;
12
- exitCode?: number;
13
- signalName?: string;
14
- stderr?: string;
15
- message: string;
16
- } {
17
- const e = (error ?? {}) as {
18
- cause?: { code?: string; message?: string };
19
- exitCode?: number;
20
- signalName?: string;
21
- stderr?: string;
22
- message?: string;
23
- };
24
- return {
25
- code: e.cause?.code,
26
- exitCode: e.exitCode,
27
- signalName: e.signalName,
28
- stderr: e.stderr?.trim() || undefined,
29
- message: e.cause?.message ?? e.message ?? String(error),
30
- };
31
- }
32
-
33
- /** Why `ruff --version` did not answer, as one line for the lint output. */
34
- export function ruffStartFailure(error: unknown): string {
35
- const d = errorDetail(error);
36
- if (d.code === "ENOENT") return `ruff is not on PATH. ${pinHint}.`;
37
- const why = d.stderr ?? d.message;
38
- return `ruff did not start: ${why}. ${pinHint}.`;
39
- }
40
-
41
- /** Why `ruff <mode>` failed once it had started, as one line for the lint output. */
42
- export function ruffRunFailure(mode: RuffMode, target: string, error: unknown): string {
43
- const d = errorDetail(error);
44
- if (d.signalName) return `ruff ${mode} was killed by ${d.signalName}.`;
45
- if (d.exitCode === 1 && mode === "check")
46
- return `ruff check found problems in ${target} (listed above).`;
47
- if (d.exitCode !== undefined)
48
- return `ruff ${mode} exited ${d.exitCode}, a configuration or usage error (see above).`;
49
- return `ruff ${mode} failed: ${d.message}.`;
50
- }
51
-
52
- /**
53
- * Run ruff format or check on `target`, first proving ruff starts so a missing
54
- * or broken install is reported as that instead of as a lint failure. Returns
55
- * the reason it failed, or undefined when it passed.
56
- */
57
- export async function runRuff(
58
- mode: RuffMode,
59
- target: string,
60
- cwd: string,
61
- spawn: Spawn = nanoSpawn,
62
- ): Promise<string | undefined> {
63
- try {
64
- await spawn("ruff", ["--version"], { cwd });
65
- } catch (error) {
66
- return ruffStartFailure(error);
67
- }
68
- try {
69
- await spawn("ruff", [mode, target], { stdio: "inherit", cwd });
70
- return undefined;
71
- } catch (error) {
72
- return ruffRunFailure(mode, target, error);
73
- }
74
- }
@@ -1,15 +0,0 @@
1
- import nanoSpawn from "nano-spawn";
2
- export type RuffMode = "format" | "check";
3
- type Spawn = typeof nanoSpawn;
4
- /** Why `ruff --version` did not answer, as one line for the lint output. */
5
- export declare function ruffStartFailure(error: unknown): string;
6
- /** Why `ruff <mode>` failed once it had started, as one line for the lint output. */
7
- export declare function ruffRunFailure(mode: RuffMode, target: string, error: unknown): string;
8
- /**
9
- * Run ruff format or check on `target`, first proving ruff starts so a missing
10
- * or broken install is reported as that instead of as a lint failure. Returns
11
- * the reason it failed, or undefined when it passed.
12
- */
13
- export declare function runRuff(mode: RuffMode, target: string, cwd: string, spawn?: Spawn): Promise<string | undefined>;
14
- export {};
15
- //# sourceMappingURL=ruff.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ruff.d.ts","sourceRoot":"","sources":["../../src/commands/ruff.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE1C,KAAK,KAAK,GAAG,OAAO,SAAS,CAAC;AA4B9B,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAKvD;AAED,qFAAqF;AACrF,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAQrF;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAC3B,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAY7B"}