@postxl/cli 1.11.0 → 1.11.2

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"));
@@ -111,6 +113,8 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
111
113
  if (targetModelNames) {
112
114
  console.log(`Restricting generation to models: ${[...targetModelNames].join(', ')}`);
113
115
  }
116
+ // `-m` and `-p` both regenerate a subset of the project's files.
117
+ const isScopedRun = targetModelNames !== undefined || options.pattern !== undefined;
114
118
  const manager = new generator_1.GeneratorManager(localGenerators);
115
119
  const baseContext = (0, generator_1.prepareBaseContext)(schema, {
116
120
  ...options,
@@ -174,16 +178,22 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
174
178
  process.exitCode = 1;
175
179
  }
176
180
  // Persist the current schema as the base for the next generation's
177
- // three-way merge. Skipped on dry runs (which must not touch disk),
178
- // and on an aborted sync - nothing was written, so advancing the
179
- // snapshot would claim a generation that never happened as the next
180
- // run's ancestor.
181
- 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
+ })) {
182
188
  await (0, base_snapshot_1.writeBaseSnapshot)(targetPath, {
183
189
  schemaSnapshot: rawSchema,
184
190
  generatorVersion: (0, base_snapshot_1.resolveGeneratorVersion)(targetPath),
185
191
  });
186
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
+ }
187
197
  return g;
188
198
  })
189
199
  .then((g) => {
@@ -199,7 +209,10 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
199
209
  * `success: false` means generation was aborted outright (unresolved markers
200
210
  * were already on disk); an unverified ancestor means an incoming generator
201
211
  * change may not have been applied; an unparseable merge means reconciliation
202
- * 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.
203
216
  *
204
217
  * Conflict markers on their own keep their existing exit 0. That predates this
205
218
  * change and flipping it would break every pipeline that tolerates conflicts, so
@@ -209,7 +222,37 @@ function needsAttention(result) {
209
222
  if (!result.success) {
210
223
  return true;
211
224
  }
212
- 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;
213
256
  }
214
257
  function hasMergeConflicts(result) {
215
258
  // The `!success` abort reports markers that were already on disk before this
@@ -273,6 +316,7 @@ async function maybeReconstructBaseVfs(params) {
273
316
  ...options,
274
317
  ...(options.pattern ? { filePattern: options.pattern } : {}),
275
318
  ...(targetModelNames ? { targetModelNames } : {}),
319
+ isBaseReconstruction: true,
276
320
  });
277
321
  const baseGenerated = await manager.generate(baseContext);
278
322
  const baseG = await new generator_1.Generator(baseGenerated).generate((g) => g);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/cli",
3
- "version": "1.11.0",
3
+ "version": "1.11.2",
4
4
  "description": "Command-line interface for PostXL code generation framework",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -45,9 +45,9 @@
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.8.0",
49
- "@postxl/generators": "^3.2.1",
50
- "@postxl/schema": "^2.3.0",
48
+ "@postxl/generator": "^1.9.0",
49
+ "@postxl/generators": "^4.0.0",
50
+ "@postxl/schema": "^2.4.0",
51
51
  "@postxl/utils": "^1.4.2"
52
52
  },
53
53
  "devDependencies": {},