@metaobjectsdev/cli 1.0.0-rc.5 → 1.0.0-rc.6

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 (106) hide show
  1. package/dist/src/commands/docs.d.ts.map +1 -1
  2. package/dist/src/commands/docs.js +41 -9
  3. package/dist/src/commands/docs.js.map +1 -1
  4. package/dist/src/commands/gen.d.ts +5 -0
  5. package/dist/src/commands/gen.d.ts.map +1 -1
  6. package/dist/src/commands/gen.js +12 -1
  7. package/dist/src/commands/gen.js.map +1 -1
  8. package/dist/src/commands/init.d.ts.map +1 -1
  9. package/dist/src/commands/init.js +27 -3
  10. package/dist/src/commands/init.js.map +1 -1
  11. package/dist/src/commands/migrate.d.ts +5 -0
  12. package/dist/src/commands/migrate.d.ts.map +1 -1
  13. package/dist/src/commands/migrate.js +10 -4
  14. package/dist/src/commands/migrate.js.map +1 -1
  15. package/dist/src/commands/prompt-snapshot.d.ts.map +1 -1
  16. package/dist/src/commands/prompt-snapshot.js +2 -1
  17. package/dist/src/commands/prompt-snapshot.js.map +1 -1
  18. package/dist/src/commands/types.d.ts.map +1 -1
  19. package/dist/src/commands/types.js +12 -3
  20. package/dist/src/commands/types.js.map +1 -1
  21. package/dist/src/commands/upgrade.d.ts.map +1 -1
  22. package/dist/src/commands/upgrade.js +38 -4
  23. package/dist/src/commands/upgrade.js.map +1 -1
  24. package/dist/src/commands/verify.d.ts.map +1 -1
  25. package/dist/src/commands/verify.js +69 -21
  26. package/dist/src/commands/verify.js.map +1 -1
  27. package/dist/src/index.d.ts.map +1 -1
  28. package/dist/src/index.js +37 -18
  29. package/dist/src/index.js.map +1 -1
  30. package/dist/src/lib/advisory.d.ts +6 -0
  31. package/dist/src/lib/advisory.d.ts.map +1 -1
  32. package/dist/src/lib/advisory.js +13 -0
  33. package/dist/src/lib/advisory.js.map +1 -1
  34. package/dist/src/lib/anti-patterns.d.ts.map +1 -1
  35. package/dist/src/lib/anti-patterns.js +2 -4
  36. package/dist/src/lib/anti-patterns.js.map +1 -1
  37. package/dist/src/lib/args.d.ts +23 -12
  38. package/dist/src/lib/args.d.ts.map +1 -1
  39. package/dist/src/lib/args.js +33 -22
  40. package/dist/src/lib/args.js.map +1 -1
  41. package/dist/src/lib/base-url-advisory.d.ts +37 -0
  42. package/dist/src/lib/base-url-advisory.d.ts.map +1 -0
  43. package/dist/src/lib/base-url-advisory.js +162 -0
  44. package/dist/src/lib/base-url-advisory.js.map +1 -0
  45. package/dist/src/lib/codegen-drift.d.ts +8 -0
  46. package/dist/src/lib/codegen-drift.d.ts.map +1 -1
  47. package/dist/src/lib/codegen-drift.js +43 -10
  48. package/dist/src/lib/codegen-drift.js.map +1 -1
  49. package/dist/src/lib/detect-stack.d.ts +17 -0
  50. package/dist/src/lib/detect-stack.d.ts.map +1 -1
  51. package/dist/src/lib/detect-stack.js +64 -2
  52. package/dist/src/lib/detect-stack.js.map +1 -1
  53. package/dist/src/lib/docs-drift.d.ts.map +1 -1
  54. package/dist/src/lib/docs-drift.js +16 -7
  55. package/dist/src/lib/docs-drift.js.map +1 -1
  56. package/dist/src/lib/git-ignore.d.ts +19 -0
  57. package/dist/src/lib/git-ignore.d.ts.map +1 -1
  58. package/dist/src/lib/git-ignore.js +46 -3
  59. package/dist/src/lib/git-ignore.js.map +1 -1
  60. package/dist/src/lib/ignored-scaffold-check.d.ts +12 -0
  61. package/dist/src/lib/ignored-scaffold-check.d.ts.map +1 -0
  62. package/dist/src/lib/ignored-scaffold-check.js +75 -0
  63. package/dist/src/lib/ignored-scaffold-check.js.map +1 -0
  64. package/dist/src/lib/load-error.d.ts +46 -0
  65. package/dist/src/lib/load-error.d.ts.map +1 -0
  66. package/dist/src/lib/load-error.js +51 -0
  67. package/dist/src/lib/load-error.js.map +1 -0
  68. package/dist/src/lib/manifest-ignored-check.d.ts.map +1 -1
  69. package/dist/src/lib/manifest-ignored-check.js +19 -6
  70. package/dist/src/lib/manifest-ignored-check.js.map +1 -1
  71. package/dist/src/lib/output.d.ts +13 -1
  72. package/dist/src/lib/output.d.ts.map +1 -1
  73. package/dist/src/lib/output.js +26 -8
  74. package/dist/src/lib/output.js.map +1 -1
  75. package/dist/src/lib/rel-posix.d.ts +5 -0
  76. package/dist/src/lib/rel-posix.d.ts.map +1 -0
  77. package/dist/src/lib/rel-posix.js +23 -0
  78. package/dist/src/lib/rel-posix.js.map +1 -0
  79. package/dist/src/lib/replay-remedy.d.ts +2 -0
  80. package/dist/src/lib/replay-remedy.d.ts.map +1 -0
  81. package/dist/src/lib/replay-remedy.js +69 -0
  82. package/dist/src/lib/replay-remedy.js.map +1 -0
  83. package/package.json +10 -10
  84. package/src/commands/docs.ts +51 -12
  85. package/src/commands/gen.ts +14 -1
  86. package/src/commands/init.ts +27 -3
  87. package/src/commands/migrate.ts +12 -4
  88. package/src/commands/prompt-snapshot.ts +2 -1
  89. package/src/commands/types.ts +12 -3
  90. package/src/commands/upgrade.ts +44 -4
  91. package/src/commands/verify.ts +74 -23
  92. package/src/index.ts +37 -18
  93. package/src/lib/advisory.ts +15 -0
  94. package/src/lib/anti-patterns.ts +2 -5
  95. package/src/lib/args.ts +60 -39
  96. package/src/lib/base-url-advisory.ts +173 -0
  97. package/src/lib/codegen-drift.ts +52 -9
  98. package/src/lib/detect-stack.ts +73 -2
  99. package/src/lib/docs-drift.ts +17 -7
  100. package/src/lib/git-ignore.ts +47 -3
  101. package/src/lib/ignored-scaffold-check.ts +78 -0
  102. package/src/lib/load-error.ts +89 -0
  103. package/src/lib/manifest-ignored-check.ts +21 -6
  104. package/src/lib/output.ts +36 -8
  105. package/src/lib/rel-posix.ts +25 -0
  106. package/src/lib/replay-remedy.ts +78 -0
@@ -18,7 +18,7 @@
18
18
  import { existsSync } from "node:fs";
19
19
  import { join } from "node:path";
20
20
  import { log } from "./log.js";
21
- import { isGitIgnored } from "./git-ignore.js";
21
+ import { gitIgnoreSource, isGitIgnored } from "./git-ignore.js";
22
22
 
23
23
  /** Project-relative path of the manifest — the one artifact of `.gen-state/` that is
24
24
  * meant to be committed. */
@@ -40,13 +40,28 @@ export function warnIfManifestIgnored(cwd: string): void {
40
40
  // per-user ignore file answers it just as truly as a committed .gitignore does.
41
41
  if (isGitIgnored(cwd, HASH_MANIFEST_REL, { honourGlobalExcludes: true }) !== true) return;
42
42
 
43
+ // WHERE the rule actually lives, asked of git rather than assumed. This used to name
44
+ // `.metaobjects/.gitignore` and the literal pattern `.gen-state/`, which is only one of
45
+ // the places the exclusion can sit: an adopter estate had it in the ROOT `.gitignore` as
46
+ // `.metaobjects/.gen-state/`, so following this advisory to the letter edited a file that
47
+ // did not hold the rule, changed nothing, and printed this same line again — the loop
48
+ // shape. `git check-ignore -v` knows the answer, so nothing is guessed. When git cannot
49
+ // say, the wording degrades to the generic form rather than asserting a location.
50
+ const src = gitIgnoreSource(cwd, HASH_MANIFEST_REL, { honourGlobalExcludes: true });
51
+ const where =
52
+ src !== undefined
53
+ ? `The rule is '${src.pattern}' at ${src.file}:${src.line} — replace it there with ` +
54
+ `a '/*' form plus a '!' negation for the manifest ` +
55
+ `(e.g. '${src.pattern.replace(/\/$/, "")}/*' and '!${src.pattern.replace(/\/$/, "")}/.hashes.json')`
56
+ : `Find the rule with 'git check-ignore -v ${HASH_MANIFEST_REL}' and replace it with ` +
57
+ `a '/*' form plus a '!' negation for the manifest`;
58
+
43
59
  log.warn(
44
60
  `${HASH_MANIFEST_REL} is git-ignored, so it never reaches another machine — ` +
45
61
  `on a fresh clone or CI runner 'meta gen' cannot tell your hand edits from its ` +
46
- `own stale output, and will refuse to overwrite rather than guess. Fix it in ` +
47
- `.metaobjects/.gitignore by replacing '.gen-state/' with '.gen-state/*' plus ` +
48
- `'!.gen-state/.hashes.json' (the glob matters — git will not descend into an ` +
49
- `excluded directory, so a negation under '.gen-state/' can never apply), then ` +
50
- `commit the manifest. If you deliberately do not commit generated output, ignore this.`,
62
+ `own stale output, and will refuse to overwrite rather than guess. ${where} ` +
63
+ `(the glob matters — git will not descend into an excluded directory, so a negation ` +
64
+ `INSIDE an excluded directory can never apply), then commit the manifest. ` +
65
+ `If you deliberately do not commit generated output, ignore this.`,
51
66
  );
52
67
  }
package/src/lib/output.ts CHANGED
@@ -31,6 +31,10 @@ export type GenFileStatus =
31
31
  | "conflict"
32
32
  | "unchanged"
33
33
  | "refused"
34
+ /** `--baseline=adopt`: the file's existing content became the merge base and
35
+ * nothing was written. Never folded into "unchanged" — the run's product is the
36
+ * manifest, and a summary that showed these as unchanged would hide it. */
37
+ | "adopted"
34
38
  | "removed";
35
39
 
36
40
  export interface GenFileEntry {
@@ -57,6 +61,14 @@ export interface GenResultShape {
57
61
  * structured payload carries every finding.
58
62
  */
59
63
  antiPatterns?: AdvisorySection<AdvisoryFindingRow>;
64
+ /**
65
+ * How many generators the config wired. Required, because the alternative is a
66
+ * message that GUESSES: with no generators wired, a run over a project with five
67
+ * entities emitted nothing and reported "no entities to generate … author entities
68
+ * in this project's metadata sources", sending the reader to edit a file that was
69
+ * already correct. The output's own first line (`gen: []`) already knew.
70
+ */
71
+ generatorCount: number;
60
72
  }
61
73
 
62
74
  const GEN_GLYPHS: Record<GenFileStatus, string> = {
@@ -66,6 +78,7 @@ const GEN_GLYPHS: Record<GenFileStatus, string> = {
66
78
  conflict: "✗",
67
79
  unchanged: "=",
68
80
  refused: "⚠",
81
+ adopted: "⊕",
69
82
  removed: "−",
70
83
  };
71
84
 
@@ -76,6 +89,7 @@ const GEN_WORDS: Record<GenFileStatus, string> = {
76
89
  conflict: "CONFLICT",
77
90
  unchanged: "UNCHANGED",
78
91
  refused: "REFUSED",
92
+ adopted: "ADOPTED",
79
93
  removed: "REMOVED",
80
94
  };
81
95
 
@@ -106,7 +120,7 @@ export function formatGenResult(result: GenResultShape, opts: FormatOptions): st
106
120
  acc[f.status] = (acc[f.status] ?? 0) + 1;
107
121
  return acc;
108
122
  },
109
- { new: 0, overwrite: 0, merged: 0, conflict: 0, unchanged: 0, refused: 0, removed: 0 },
123
+ { new: 0, overwrite: 0, merged: 0, conflict: 0, unchanged: 0, refused: 0, adopted: 0, removed: 0 },
110
124
  );
111
125
  const parts: string[] = [];
112
126
  // "written" stays the sum of new + overwrite: that number was always correct and
@@ -118,6 +132,10 @@ export function formatGenResult(result: GenResultShape, opts: FormatOptions): st
118
132
  if (counts.conflict > 0) parts.push(`${counts.conflict} conflict`);
119
133
  if (counts.unchanged > 0) parts.push(`${counts.unchanged} unchanged`);
120
134
  if (counts.refused > 0) parts.push(`${counts.refused} refused`);
135
+ // `--baseline=adopt`: recorded as the merge base, nothing written. Counted separately
136
+ // from `unchanged` because the run's product is the manifest, and an adopter who cannot
137
+ // see how many files it now covers has no way to review what they are about to commit.
138
+ if (counts.adopted > 0) parts.push(`${counts.adopted} adopted`);
121
139
  if (counts.removed > 0) parts.push(`${counts.removed} removed`);
122
140
  lines.push("", ` ${parts.join(", ")}`, "");
123
141
 
@@ -220,7 +238,7 @@ export function genResultToData(result: GenResultShape): {
220
238
  } {
221
239
  const counts = result.files.reduce<Record<GenFileStatus, number>>(
222
240
  (a, f) => ((a[f.status] = (a[f.status] ?? 0) + 1), a),
223
- { new: 0, overwrite: 0, merged: 0, conflict: 0, unchanged: 0, refused: 0, removed: 0 },
241
+ { new: 0, overwrite: 0, merged: 0, conflict: 0, unchanged: 0, refused: 0, adopted: 0, removed: 0 },
224
242
  );
225
243
  const parts: string[] = [];
226
244
  // Same split as the text formatter: `written` is new + overwrite, and the
@@ -231,13 +249,23 @@ export function genResultToData(result: GenResultShape): {
231
249
  if (counts.conflict) parts.push(`${counts.conflict} conflict`);
232
250
  if (counts.unchanged) parts.push(`${counts.unchanged} unchanged`);
233
251
  if (counts.refused) parts.push(`${counts.refused} refused`);
252
+ if (counts.adopted) parts.push(`${counts.adopted} adopted`);
234
253
  if (counts.removed) parts.push(`${counts.removed} removed`);
235
- const summary = result.files.length === 0
236
- ? `no entities to generate in ${result.outDir}`
237
- : parts.join(", ");
238
- const help = result.files.length === 0
239
- ? ["author entities in this project's metadata sources then re-run `meta gen`"]
240
- : ["typecheck the generated code with `npx tsc`", "create your database tables with `meta migrate --from-db --db <url> --dialect <sqlite|postgres> --slug init --apply`"];
254
+ // Two ways to emit nothing, and they send the reader to different files. Name the
255
+ // one that is actually true: a config wiring no generators cannot produce output
256
+ // however good the metadata is, and telling its author to go write entities is a
257
+ // false statement about a project that already has them.
258
+ const noGenerators = result.generatorCount === 0;
259
+ const summary = result.files.length !== 0
260
+ ? parts.join(", ")
261
+ : noGenerators
262
+ ? "no generators are wired in metaobjects.config.ts, so nothing was generated"
263
+ : `no entities to generate in ${result.outDir}`;
264
+ const help = result.files.length !== 0
265
+ ? ["typecheck the generated code with `npx tsc`", "create your database tables with `meta migrate --from-db --db <url> --dialect <sqlite|postgres> --slug init --apply`"]
266
+ : noGenerators
267
+ ? ["add generators to the `generators: []` array in metaobjects.config.ts — `meta eject --list` names every generator you can own, and `meta init` scaffolds the usual set"]
268
+ : ["author entities in this project's metadata sources then re-run `meta gen`"];
241
269
  // An absent section is STATED, never omitted: a reader must be able to tell
242
270
  // "the scan found nothing" from "the scan never ran".
243
271
  const antiPatterns = result.antiPatterns
@@ -0,0 +1,25 @@
1
+ // One spelling of "a path, with forward slashes".
2
+ //
3
+ // Six modules under lib/ carried this rule inline — `git-ignore`, `docs-drift` (twice),
4
+ // `anti-patterns`, `base-url-advisory` and `ignored-scaffold-check` — and one of the six
5
+ // was spelled differently: `.split("\\").join("/")` rather than `.split(sep).join("/")`.
6
+ // On Windows those agree, because `sep` IS a backslash. On POSIX they do not: `sep` is
7
+ // already "/" so the correct form is a no-op, while splitting on a literal backslash
8
+ // rewrites a filename that legitimately CONTAINS one. That is the drift six copies of a
9
+ // one-line rule invite, and it had already happened.
10
+ //
11
+ // Comparisons against git's output are the reason the rule exists at all: `git check-ignore`
12
+ // and `git ls-files` speak forward slashes on every platform, so a Windows path has to be
13
+ // normalized before it can be looked up in a set built from git's answer.
14
+
15
+ import { relative, sep } from "node:path";
16
+
17
+ /** A path with the platform separator replaced by "/" — a no-op on POSIX. */
18
+ export function toPosix(p: string): string {
19
+ return p.split(sep).join("/");
20
+ }
21
+
22
+ /** `abs` relative to `root`, forward-slashed. */
23
+ export function relPosix(root: string, abs: string): string {
24
+ return toPosix(relative(root, abs));
25
+ }
@@ -0,0 +1,78 @@
1
+ import { MigrationApplyError } from "@metaobjectsdev/migrate-ts";
2
+
3
+ /**
4
+ * What to tell someone whose committed chain will not apply to an empty database.
5
+ *
6
+ * The message this replaces prescribed ONE fix — *"fix this with a NEW migration that
7
+ * creates the missing object"* — and it cannot work, in any case. Migrations apply in
8
+ * timestamp order, so anything authored now sorts AFTER the migration that failed; the
9
+ * object is still missing when that file runs. Two estates found it from opposite
10
+ * directions and it is the same defect both times:
11
+ *
12
+ * - a chain whose FIRST migration needs a schema an out-of-band script creates (the third
13
+ * migration emits `CREATE SCHEMA IF NOT EXISTS`, the first predates it). A new migration
14
+ * sorts last, after the one that needs the schema.
15
+ * - a project where **another tool owns schema creation** — drizzle-kit's chain builds the
16
+ * tables, `.metaobjects/migrations/` holds later incremental patches. Following the
17
+ * printed remedy literally means hand-authoring every `CREATE TABLE` into the MetaObjects
18
+ * chain, i.e. duplicating a schema this project does not own, which is the opposite of
19
+ * what the agent context teaches two paragraphs into its own Principles.
20
+ *
21
+ * The old message assumed MetaObjects is the only schema authority and offered no third
22
+ * possibility. These name the fixes that exist, and the head-of-chain case gets the extra
23
+ * sentence that is only true there: nothing in this chain could have created what the
24
+ * first migration needs, so the base schema comes from outside it.
25
+ *
26
+ * "Applied migrations are immutable" is kept, because it is true and it is the reason the
27
+ * obvious fix is not offered first — but it is stated as the CONDITION it actually is
28
+ * (a checksum guard on databases that already ran the file), not as a blanket ban, because
29
+ * a migration no database has applied yet is edited in place every day.
30
+ */
31
+ /**
32
+ * Is this the migrate engine's own apply failure?
33
+ *
34
+ * By NAME, not `instanceof`. Two physical copies of `@metaobjectsdev/migrate-ts` in one
35
+ * process — a globally-installed or linked `meta` alongside a project-local dependency —
36
+ * give the class object and the instance different identities, so `instanceof` returns
37
+ * false for a real error and the remedy silently degrades to its un-positioned form. That
38
+ * is the same class-identity defect that split ts-poet's `Code` in 0.21.6 and drove the
39
+ * exported node guards in `metadata`. Unreachable through today's single import; costs one
40
+ * line to make unreachable by construction.
41
+ */
42
+ function isApplyError(err: unknown): err is MigrationApplyError {
43
+ return err instanceof MigrationApplyError
44
+ || (err instanceof Error && err.name === "MigrationApplyError"
45
+ && typeof (err as MigrationApplyError).migration === "string"
46
+ && typeof (err as MigrationApplyError).index === "number");
47
+ }
48
+
49
+ export function replayRemedy(err: unknown): string[] {
50
+ const applyErr = isApplyError(err) ? err : undefined;
51
+ const head = applyErr !== undefined && applyErr.index === 0;
52
+ const which =
53
+ applyErr === undefined
54
+ ? "the committed chain does not apply to an empty database."
55
+ : `'${applyErr.migration}' (migration ${applyErr.index + 1} of ${applyErr.pendingCount}) ` +
56
+ `does not apply to an empty database.`;
57
+
58
+ const out = [which];
59
+ if (head) {
60
+ out.push(
61
+ "It is the FIRST migration in the chain, so nothing here could have created what it " +
62
+ "needs — this chain has never built a database from empty, and its base schema comes " +
63
+ "from outside it.",
64
+ );
65
+ }
66
+ out.push(
67
+ "A NEW migration cannot fix this: migrations apply in timestamp order, so anything you " +
68
+ "author now sorts after the file that failed.",
69
+ );
70
+ out.push(
71
+ "The fixes that do work: if another tool or an out-of-band script owns schema creation " +
72
+ "for this project, --replay asserts a property this chain does not have — don't wire " +
73
+ "it. Otherwise correct the migration in place if no database has applied it yet " +
74
+ "(the ledger's checksum guard is what stops you once one has), or re-baseline from a " +
75
+ "live database with `meta migrate baseline --from-db --db <url>`.",
76
+ );
77
+ return out;
78
+ }