@postxl/cli 1.10.3 → 1.11.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.
@@ -1,2 +1,47 @@
1
1
  import { Command } from 'commander';
2
+ import { SyncResults } from '@postxl/generator';
2
3
  export declare function register(program: Command): void;
4
+ /**
5
+ * True when the run left something a human still has to act on.
6
+ *
7
+ * `success: false` means generation was aborted outright (unresolved markers
8
+ * were already on disk); an unverified ancestor means an incoming generator
9
+ * change may not have been applied; an unparseable merge means reconciliation
10
+ * broke a file outright; an unplaced custom block is code the developer wrote
11
+ * that no longer has a home, appended at the end of a file for a human to move
12
+ * (issue #850 - it may carry an authorization grant). None of those may be built
13
+ * straight through.
14
+ *
15
+ * Conflict markers on their own keep their existing exit 0. That predates this
16
+ * change and flipping it would break every pipeline that tolerates conflicts, so
17
+ * it is a separate call to make.
18
+ */
19
+ export declare function needsAttention(result: SyncResults): boolean;
20
+ /**
21
+ * Whether this run may advance `.postxl/base-snapshot.json` to the current schema.
22
+ *
23
+ * The snapshot's contract is "the schema that produced the generation recorded in
24
+ * `postxl-lock.json`", because the next run reconstructs the merge ancestor by
25
+ * re-generating from it. A **scoped** run breaks that one-to-one relationship: the
26
+ * files it wrote are at `G(schema_new)` while the ones it skipped are still at
27
+ * `G(schema_old)`, and no single schema describes that mixture. Narrowing the
28
+ * snapshot to the regenerated models cannot express it either - `-m` still
29
+ * regenerates aggregate files from the *whole* new schema while holding per-model
30
+ * files back, and `-p` narrows by path, which has no schema form at all.
31
+ *
32
+ * Advancing it anyway claims an ancestor the skipped files never had: the next
33
+ * unscoped run reconstructs a base whose checksum does not match their lock entry,
34
+ * discards it, falls back to a 2-way merge and writes conflict markers into files
35
+ * the scoped run never touched (issue #850). Leaving the snapshot alone keeps it
36
+ * true for exactly those files. The regenerated ones are only merged at all if the
37
+ * developer has since edited them, and that case is detected and reported as
38
+ * `merged without a verified ancestor` rather than silently mis-merged.
39
+ *
40
+ * Dry runs must not touch disk, and an aborted sync wrote nothing - advancing the
41
+ * snapshot there would name a generation that never happened as the next ancestor.
42
+ */
43
+ export declare function shouldAdvanceBaseSnapshot(params: {
44
+ dryRun: boolean;
45
+ success: boolean;
46
+ isScopedRun: boolean;
47
+ }): boolean;
@@ -37,6 +37,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.register = register;
40
+ exports.needsAttention = needsAttention;
41
+ exports.shouldAdvanceBaseSnapshot = shouldAdvanceBaseSnapshot;
40
42
  const child_process_1 = require("child_process");
41
43
  const util_1 = require("util");
42
44
  const dotenv_1 = __importDefault(require("dotenv"));
@@ -57,14 +59,19 @@ function register(program) {
57
59
  .description(`Generates the project.
58
60
 
59
61
  This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the generators specified in ${(0, utils_1.yellow)('generate.ts')}.`)
60
- .option('-d, --diff', 'shows diff between ejected and generated files')
61
- .option('-e, --ejected', 'lists ejected files')
62
- .option('-f, --force', 'overwrites ejected files')
62
+ .option('-d, --diff', 'shows diff between each modified file and its generated content')
63
+ .option('--modified', 'lists files edited on disk (what `pxl status` calls modified) and any ejected ones')
64
+ // `-e, --ejected` listed files the developer had edited, which `pxl status`
65
+ // calls `modified` -- while `pxl status -e` filters the actual `"ejected"`
66
+ // sentinel. Same flag, two commands, opposite meanings. Kept as a working
67
+ // alias so existing scripts do not break.
68
+ .option('-e, --ejected', 'deprecated alias for --modified')
69
+ .option('-f, --force', 'overwrites modified files (ejected files are still skipped -- force respects the sentinel)')
63
70
  .option('-i, --ignore-errors', 'ignores errors during generation')
64
71
  .option('--dry-run', 'compute the changes that would be made without writing or updating the lockfile')
65
72
  .option('-m, --model <names...>', 'regenerate only for the given models (accepts multiple, e.g. -m Country City)')
66
73
  .option('-n, --no-fix', 'does not attempt to fix linting errors')
67
- .option('--no-three-way', 'skips reconstructing the previous generation for three-way merges (faster; ejected files fall back to the 2-way merge)')
74
+ .option('--no-three-way', 'skips reconstructing the previous generation for three-way merges (faster; modified files fall back to the 2-way merge)')
68
75
  .option('-p, --pattern <glob>', 'filters files by glob pattern (e.g., "**/*.ts" or "backend/libs/**")')
69
76
  .option('-q, --quiet', 'does not print errors')
70
77
  .option('-s, --skip-lint', 'skips linting')
@@ -94,7 +101,7 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
94
101
  const verb = options.dryRun ? 'Would generate' : 'Generating';
95
102
  console.log(`${verb} project from ${projectPath} to ${targetPath}`);
96
103
  if (options.force) {
97
- console.log((0, utils_1.yellow)('Warning: Forcing generation of ejected files!'));
104
+ console.log((0, utils_1.yellow)('Warning: Forcing generation of modified files!'));
98
105
  }
99
106
  if (options.dryRun) {
100
107
  console.log((0, utils_1.yellow)('Dry run: no files will be written and the lockfile will not be updated.'));
@@ -106,6 +113,8 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
106
113
  if (targetModelNames) {
107
114
  console.log(`Restricting generation to models: ${[...targetModelNames].join(', ')}`);
108
115
  }
116
+ // `-m` and `-p` both regenerate a subset of the project's files.
117
+ const isScopedRun = targetModelNames !== undefined || options.pattern !== undefined;
109
118
  const manager = new generator_1.GeneratorManager(localGenerators);
110
119
  const baseContext = (0, generator_1.prepareBaseContext)(schema, {
111
120
  ...options,
@@ -153,8 +162,8 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
153
162
  ...(baseVfs ? { baseVfs } : {}),
154
163
  });
155
164
  (0, generator_1.logSyncResult)(result, {
156
- showEjectedStats: options.ejected ?? false,
157
- showEjectedDiff: options.diff ?? false,
165
+ showModifiedStats: options.modified ?? options.ejected ?? false,
166
+ showModifiedDiff: options.diff ?? false,
158
167
  });
159
168
  // A 2-way merge conflicts far more eagerly than diff3 does. Without
160
169
  // this note a conflict list produced without a base reads as "these
@@ -169,16 +178,22 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
169
178
  process.exitCode = 1;
170
179
  }
171
180
  // Persist the current schema as the base for the next generation's
172
- // three-way merge. Skipped on dry runs (which must not touch disk),
173
- // and on an aborted sync - nothing was written, so advancing the
174
- // snapshot would claim a generation that never happened as the next
175
- // run's ancestor.
176
- if (!options.dryRun && result.success) {
181
+ // three-way merge - but only when this run actually regenerated the
182
+ // whole project. See shouldAdvanceBaseSnapshot.
183
+ if (shouldAdvanceBaseSnapshot({
184
+ dryRun: options.dryRun ?? false,
185
+ success: result.success,
186
+ isScopedRun,
187
+ })) {
177
188
  await (0, base_snapshot_1.writeBaseSnapshot)(targetPath, {
178
189
  schemaSnapshot: rawSchema,
179
190
  generatorVersion: (0, base_snapshot_1.resolveGeneratorVersion)(targetPath),
180
191
  });
181
192
  }
193
+ else if (isScopedRun && !options.dryRun && result.success) {
194
+ console.log((0, utils_1.yellow)('Note: `.postxl/base-snapshot.json` was left as it was, because this run regenerated only part of the project. ' +
195
+ 'Run `pxl generate` without `-m`/`-p` to advance it.'));
196
+ }
182
197
  return g;
183
198
  })
184
199
  .then((g) => {
@@ -194,7 +209,10 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
194
209
  * `success: false` means generation was aborted outright (unresolved markers
195
210
  * were already on disk); an unverified ancestor means an incoming generator
196
211
  * change may not have been applied; an unparseable merge means reconciliation
197
- * broke a file outright. None of those may be built straight through.
212
+ * broke a file outright; an unplaced custom block is code the developer wrote
213
+ * that no longer has a home, appended at the end of a file for a human to move
214
+ * (issue #850 - it may carry an authorization grant). None of those may be built
215
+ * straight through.
198
216
  *
199
217
  * Conflict markers on their own keep their existing exit 0. That predates this
200
218
  * change and flipping it would break every pipeline that tolerates conflicts, so
@@ -204,7 +222,37 @@ function needsAttention(result) {
204
222
  if (!result.success) {
205
223
  return true;
206
224
  }
207
- return Object.values(result.files).some((file) => file.action.type === 'MergeConflict' && (file.action.hasUnverifiedBase || file.action.mergeIsUnparseable));
225
+ return Object.values(result.files).some((file) => file.action.type === 'MergeConflict' &&
226
+ (file.action.hasUnverifiedBase ||
227
+ file.action.mergeIsUnparseable ||
228
+ file.action.unplacedCustomBlocks !== undefined));
229
+ }
230
+ /**
231
+ * Whether this run may advance `.postxl/base-snapshot.json` to the current schema.
232
+ *
233
+ * The snapshot's contract is "the schema that produced the generation recorded in
234
+ * `postxl-lock.json`", because the next run reconstructs the merge ancestor by
235
+ * re-generating from it. A **scoped** run breaks that one-to-one relationship: the
236
+ * files it wrote are at `G(schema_new)` while the ones it skipped are still at
237
+ * `G(schema_old)`, and no single schema describes that mixture. Narrowing the
238
+ * snapshot to the regenerated models cannot express it either - `-m` still
239
+ * regenerates aggregate files from the *whole* new schema while holding per-model
240
+ * files back, and `-p` narrows by path, which has no schema form at all.
241
+ *
242
+ * Advancing it anyway claims an ancestor the skipped files never had: the next
243
+ * unscoped run reconstructs a base whose checksum does not match their lock entry,
244
+ * discards it, falls back to a 2-way merge and writes conflict markers into files
245
+ * the scoped run never touched (issue #850). Leaving the snapshot alone keeps it
246
+ * true for exactly those files. The regenerated ones are only merged at all if the
247
+ * developer has since edited them, and that case is detected and reported as
248
+ * `merged without a verified ancestor` rather than silently mis-merged.
249
+ *
250
+ * Dry runs must not touch disk, and an aborted sync wrote nothing - advancing the
251
+ * snapshot there would name a generation that never happened as the next ancestor.
252
+ */
253
+ function shouldAdvanceBaseSnapshot(params) {
254
+ const { dryRun, success, isScopedRun } = params;
255
+ return !dryRun && success && !isScopedRun;
208
256
  }
209
257
  function hasMergeConflicts(result) {
210
258
  // The `!success` abort reports markers that were already on disk before this
@@ -232,7 +280,7 @@ function hasMergeConflicts(result) {
232
280
  async function maybeReconstructBaseVfs(params) {
233
281
  const { manager, targetPath, options, targetModelNames } = params;
234
282
  // `--no-three-way` opts out of base reconstruction entirely (fast iteration);
235
- // ejected files then fall back to the 2-way merge.
283
+ // modified files then fall back to the 2-way merge.
236
284
  if (options.threeWay === false) {
237
285
  return undefined;
238
286
  }
@@ -242,7 +290,7 @@ async function maybeReconstructBaseVfs(params) {
242
290
  }
243
291
  // Reported before every check below, all of which decide whether reconstructing a base is worth
244
292
  // the second generation - a question independent of whether the generator changed. It used to sit
245
- // after them, so the clean-project skip below swallowed it: on a tree with nothing ejected, a
293
+ // after them, so the clean-project skip below swallowed it: on a tree with nothing modified, a
246
294
  // generator change rewrote every tracked file and said nothing, which is the one run where this
247
295
  // note is the only warning there is.
248
296
  const driftNote = (0, base_snapshot_1.generatorDriftNote)({
@@ -253,7 +301,7 @@ async function maybeReconstructBaseVfs(params) {
253
301
  console.log((0, utils_1.yellow)(driftNote));
254
302
  }
255
303
  // The base is only ever consulted to merge files that were edited on disk.
256
- // When nothing is ejected, reconstructing it (a second full generation +
304
+ // When nothing is modified, reconstructing it (a second full generation +
257
305
  // lint + format) would be wasted work, so skip it — the common, clean-project
258
306
  // case pays nothing.
259
307
  if (!(await (0, base_snapshot_1.hasLocallyEditedFiles)(targetPath))) {
@@ -8,13 +8,13 @@ export declare function writeBaseSnapshot(targetPath: string, snapshot: BaseSnap
8
8
  /**
9
9
  * Returns true if any tracked generated file has been edited on disk (its content
10
10
  * no longer matches its lock-file checksum) — i.e. the project has at least one
11
- * "ejected" file that a regeneration could need to merge.
11
+ * "modified" file that a regeneration could need to merge.
12
12
  *
13
13
  * The three-way merge base is only ever consulted for such files (the
14
14
  * `MergeConflict` sync state requires a disk file that diverges from both the
15
15
  * lock and the fresh output). When nothing is edited on disk, reconstructing the
16
16
  * base would be pure wasted work, so the caller can skip the second generation
17
- * pass entirely. Permanently-ejected entries (the `"ejected"` sentinel) are
17
+ * pass entirely. Ejected entries (the `"ejected"` sentinel) are
18
18
  * skipped because sync never merges them.
19
19
  */
20
20
  export declare function hasLocallyEditedFiles(targetPath: string): Promise<boolean>;
@@ -92,13 +92,13 @@ async function writeBaseSnapshot(targetPath, snapshot) {
92
92
  /**
93
93
  * Returns true if any tracked generated file has been edited on disk (its content
94
94
  * no longer matches its lock-file checksum) — i.e. the project has at least one
95
- * "ejected" file that a regeneration could need to merge.
95
+ * "modified" file that a regeneration could need to merge.
96
96
  *
97
97
  * The three-way merge base is only ever consulted for such files (the
98
98
  * `MergeConflict` sync state requires a disk file that diverges from both the
99
99
  * lock and the fresh output). When nothing is edited on disk, reconstructing the
100
100
  * base would be pure wasted work, so the caller can skip the second generation
101
- * pass entirely. Permanently-ejected entries (the `"ejected"` sentinel) are
101
+ * pass entirely. Ejected entries (the `"ejected"` sentinel) are
102
102
  * skipped because sync never merges them.
103
103
  */
104
104
  async function hasLocallyEditedFiles(targetPath) {
@@ -148,7 +148,7 @@ function generatorDriftNote(params) {
148
148
  return undefined;
149
149
  }
150
150
  return (`Note: @postxl/generators changed since the last generation (${snapshotVersion} → ${currentVersion}). ` +
151
- `Files it generates differently will be rewritten; any ejected file whose output changed with it ` +
151
+ `Files it generates differently will be rewritten; any modified file whose output changed with it ` +
152
152
  `has no reproducible ancestor and falls back to a 2-way merge.`);
153
153
  }
154
154
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/cli",
3
- "version": "1.10.3",
3
+ "version": "1.11.1",
4
4
  "description": "Command-line interface for PostXL code generation framework",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -45,8 +45,8 @@
45
45
  "dotenv": "17.4.2",
46
46
  "ts-morph": "26.0.0",
47
47
  "zod-validation-error": "5.0.0",
48
- "@postxl/generator": "^1.7.2",
49
- "@postxl/generators": "^3.2.0",
48
+ "@postxl/generator": "^1.8.1",
49
+ "@postxl/generators": "^3.2.2",
50
50
  "@postxl/schema": "^2.3.0",
51
51
  "@postxl/utils": "^1.4.2"
52
52
  },