@postxl/cli 1.10.0 → 1.10.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.
@@ -156,9 +156,24 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
156
156
  showEjectedStats: options.ejected ?? false,
157
157
  showEjectedDiff: options.diff ?? false,
158
158
  });
159
+ // A 2-way merge conflicts far more eagerly than diff3 does. Without
160
+ // this note a conflict list produced without a base reads as "these
161
+ // files cannot merge", when a run with a base may merge them cleanly.
162
+ if (!baseVfs && hasMergeConflicts(result)) {
163
+ console.log((0, utils_1.yellow)('Note: these conflicts were computed with a 2-way merge (no three-way base). Re-run without `--no-three-way`, after committing a generation that writes `.postxl/base-snapshot.json`, before concluding the files cannot be merged.'));
164
+ }
165
+ // The summary already says a human has to look at this run; the exit
166
+ // code has to say the same thing, or `pxl generate && pnpm build`
167
+ // carries on over output the generator itself flagged.
168
+ if (needsAttention(result)) {
169
+ process.exitCode = 1;
170
+ }
159
171
  // Persist the current schema as the base for the next generation's
160
- // three-way merge. Skipped on dry runs (which must not touch disk).
161
- if (!options.dryRun) {
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) {
162
177
  await (0, base_snapshot_1.writeBaseSnapshot)(targetPath, {
163
178
  schemaSnapshot: rawSchema,
164
179
  generatorVersion: (0, base_snapshot_1.resolveGeneratorVersion)(),
@@ -173,6 +188,30 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
173
188
  }));
174
189
  });
175
190
  }
191
+ /**
192
+ * True when the run left something a human still has to act on.
193
+ *
194
+ * `success: false` means generation was aborted outright (unresolved markers
195
+ * were already on disk); an unverified ancestor means an incoming generator
196
+ * change may not have been applied; an unparseable merge means reconciliation
197
+ * broke a file outright. None of those may be built straight through.
198
+ *
199
+ * Conflict markers on their own keep their existing exit 0. That predates this
200
+ * change and flipping it would break every pipeline that tolerates conflicts, so
201
+ * it is a separate call to make.
202
+ */
203
+ function needsAttention(result) {
204
+ if (!result.success) {
205
+ return true;
206
+ }
207
+ return Object.values(result.files).some((file) => file.action.type === 'MergeConflict' && (file.action.hasUnverifiedBase || file.action.mergeIsUnparseable));
208
+ }
209
+ function hasMergeConflicts(result) {
210
+ // The `!success` abort reports markers that were already on disk before this
211
+ // run, not conflicts this run computed — the note would be wrong there.
212
+ return (result.success &&
213
+ Object.values(result.files).some((file) => file.action.type === 'MergeConflict' && file.action.hasConflicts));
214
+ }
176
215
  /**
177
216
  * Reconstructs the previous generation (`B = G(schema_old)`) to serve as the
178
217
  * common ancestor for sync's three-way merge.
@@ -183,9 +222,10 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
183
222
  * lint/format transform as the fresh output, so formatting churn cannot
184
223
  * manufacture false conflicts.
185
224
  *
186
- * Scoped to full, writing runs: skipped for dry runs (no disk effects),
187
- * `-m`/selective runs and `-p`/pattern runs (narrowed output sets don't line up
188
- * with a full-base comparison). Those fall back to the 2-way merge. Returns
225
+ * The base is narrowed by the same `-m`/`-p` filters as the fresh output, so
226
+ * selective and pattern runs compare like with like (and pay only for what they
227
+ * regenerate). Dry runs reconstruct it too - a preview that reported conflicts
228
+ * the real run would merge away is worse than a slow preview. Returns
189
229
  * `undefined` whenever a base cannot be reconstructed (no snapshot, unparseable
190
230
  * snapshot, or a generation error), in which case sync uses the 2-way path.
191
231
  */
@@ -193,7 +233,7 @@ async function maybeReconstructBaseVfs(params) {
193
233
  const { manager, targetPath, options, targetModelNames } = params;
194
234
  // `--no-three-way` opts out of base reconstruction entirely (fast iteration);
195
235
  // ejected files then fall back to the 2-way merge.
196
- if (options.threeWay === false || options.dryRun || targetModelNames || options.pattern) {
236
+ if (options.threeWay === false) {
197
237
  return undefined;
198
238
  }
199
239
  const snapshot = await (0, base_snapshot_1.readBaseSnapshot)(targetPath);
@@ -215,10 +255,15 @@ async function maybeReconstructBaseVfs(params) {
215
255
  if (snapshot.generatorVersion !== 'unknown' &&
216
256
  currentGeneratorVersion !== 'unknown' &&
217
257
  snapshot.generatorVersion !== currentGeneratorVersion) {
218
- console.log((0, utils_1.yellow)(`Note: @postxl/generators changed since the last generation (${snapshot.generatorVersion} → ${currentGeneratorVersion}); the three-way merge base is approximate.`));
258
+ console.log((0, utils_1.yellow)(`Note: @postxl/generators changed since the last generation (${snapshot.generatorVersion} → ${currentGeneratorVersion}). ` +
259
+ `Any ejected file whose generated output changed with it has no reproducible ancestor and falls back to a 2-way merge.`));
219
260
  }
220
261
  try {
221
- const baseContext = (0, generator_1.prepareBaseContext)(parsed.data, { ...options });
262
+ const baseContext = (0, generator_1.prepareBaseContext)(parsed.data, {
263
+ ...options,
264
+ ...(options.pattern ? { filePattern: options.pattern } : {}),
265
+ ...(targetModelNames ? { targetModelNames } : {}),
266
+ });
222
267
  const baseGenerated = await manager.generate(baseContext);
223
268
  const baseG = await new generator_1.Generator(baseGenerated).generate((g) => g);
224
269
  if (!options.skipTransform) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/cli",
3
- "version": "1.10.0",
3
+ "version": "1.10.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,10 +45,10 @@
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.0",
49
- "@postxl/generators": "^2.3.1",
50
- "@postxl/schema": "^2.1.0",
51
- "@postxl/utils": "^1.4.1"
48
+ "@postxl/generator": "^1.7.2",
49
+ "@postxl/generators": "^3.1.1",
50
+ "@postxl/schema": "^2.2.0",
51
+ "@postxl/utils": "^1.4.2"
52
52
  },
53
53
  "devDependencies": {},
54
54
  "wallaby": {