@postxl/cli 2.0.1 → 2.1.0

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.
@@ -25,11 +25,25 @@ export declare function register(program: Command): void;
25
25
  * which, and both want a human once. It clears itself: the file is on disk
26
26
  * afterwards, so the next run is green whichever way the human decides.
27
27
  *
28
- * Conflict markers on their own keep their existing exit 0. That predates this
29
- * change and flipping it would break every pipeline that tolerates conflicts, so
30
- * it is a separate call to make.
28
+ * Conflict markers on their own keep their existing exit 0 by default so
29
+ * existing pipelines that tolerate conflicts are not broken. Pass
30
+ * `--fail-on-conflict` (`options.failOnConflict: true`) to fail the run and
31
+ * list every conflicted file path whenever conflict markers are produced (#973).
31
32
  */
32
- export declare function needsAttention(result: SyncResults): boolean;
33
+ export declare function needsAttention(result: SyncResults, options?: {
34
+ failOnConflict?: boolean;
35
+ }): boolean;
36
+ /**
37
+ * Returns the sorted list of file paths that carry merge-conflict markers in
38
+ * the given sync result (either newly produced conflicts on a completed run or
39
+ * pre-existing unresolved conflicts that aborted the run).
40
+ */
41
+ export declare function getConflictedFiles(result: SyncResults): string[];
42
+ /**
43
+ * Formats a concise error message listing every file with merge-conflict markers
44
+ * for `--fail-on-conflict`.
45
+ */
46
+ export declare function formatFailOnConflictSummary(conflictedFiles: readonly string[]): string;
33
47
  /**
34
48
  * Whether this run may advance `.postxl/base-snapshot.json` to the current schema.
35
49
  *
@@ -38,6 +38,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.register = register;
40
40
  exports.needsAttention = needsAttention;
41
+ exports.getConflictedFiles = getConflictedFiles;
42
+ exports.formatFailOnConflictSummary = formatFailOnConflictSummary;
41
43
  exports.shouldAdvanceBaseSnapshot = shouldAdvanceBaseSnapshot;
42
44
  const child_process_1 = require("child_process");
43
45
  const util_1 = require("util");
@@ -67,6 +69,7 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
67
69
  // alias so existing scripts do not break.
68
70
  .option('-e, --ejected', 'deprecated alias for --modified')
69
71
  .option('-f, --force', 'overwrites modified files (ejected files are still skipped -- force respects the sentinel)')
72
+ .option('--fail-on-conflict', 'exits with a non-zero status code and lists all conflicted file paths when merge-conflict markers are produced')
70
73
  .option('-i, --ignore-errors', 'ignores errors during generation')
71
74
  .option('--dry-run', 'compute the changes that would be made without writing or updating the lockfile')
72
75
  .option('-m, --model <names...>', 'regenerate only for the given models (accepts multiple, e.g. -m Country City)')
@@ -172,10 +175,14 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
172
175
  if (!baseVfs && hasMergeConflicts(result)) {
173
176
  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.'));
174
177
  }
178
+ const conflictedFiles = getConflictedFiles(result);
179
+ if (options.failOnConflict && result.success && conflictedFiles.length > 0) {
180
+ console.error((0, utils_1.red)(formatFailOnConflictSummary(conflictedFiles)));
181
+ }
175
182
  // The summary already says a human has to look at this run; the exit
176
183
  // code has to say the same thing, or `pxl generate && pnpm build`
177
184
  // carries on over output the generator itself flagged.
178
- if (needsAttention(result)) {
185
+ if (needsAttention(result, { failOnConflict: options.failOnConflict ?? false })) {
179
186
  process.exitCode = 1;
180
187
  }
181
188
  // Persist the current schema as the base for the next generation's
@@ -228,23 +235,51 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
228
235
  * which, and both want a human once. It clears itself: the file is on disk
229
236
  * afterwards, so the next run is green whichever way the human decides.
230
237
  *
231
- * Conflict markers on their own keep their existing exit 0. That predates this
232
- * change and flipping it would break every pipeline that tolerates conflicts, so
233
- * it is a separate call to make.
238
+ * Conflict markers on their own keep their existing exit 0 by default so
239
+ * existing pipelines that tolerate conflicts are not broken. Pass
240
+ * `--fail-on-conflict` (`options.failOnConflict: true`) to fail the run and
241
+ * list every conflicted file path whenever conflict markers are produced (#973).
234
242
  */
235
- function needsAttention(result) {
243
+ function needsAttention(result, options = {}) {
236
244
  if (!result.success) {
237
245
  return true;
238
246
  }
239
247
  if (result.errors.length > 0) {
240
248
  return true;
241
249
  }
250
+ if (options.failOnConflict && hasMergeConflicts(result)) {
251
+ return true;
252
+ }
242
253
  return Object.values(result.files).some((file) => file.isRestored ||
243
254
  (file.action.type === 'MergeConflict' &&
244
255
  (file.action.hasUnverifiedBase ||
245
256
  file.action.mergeIsUnparseable ||
246
257
  file.action.unplacedCustomBlocks !== undefined)));
247
258
  }
259
+ /**
260
+ * Returns the sorted list of file paths that carry merge-conflict markers in
261
+ * the given sync result (either newly produced conflicts on a completed run or
262
+ * pre-existing unresolved conflicts that aborted the run).
263
+ */
264
+ function getConflictedFiles(result) {
265
+ if (!result.success) {
266
+ return [...result.error.filesWithConflicts].sort((a, b) => a.localeCompare(b));
267
+ }
268
+ return Object.entries(result.files)
269
+ .filter(([, file]) => file.action.type === 'MergeConflict' && file.action.hasConflicts)
270
+ .map(([filePath]) => filePath)
271
+ .sort((a, b) => a.localeCompare(b));
272
+ }
273
+ /**
274
+ * Formats a concise error message listing every file with merge-conflict markers
275
+ * for `--fail-on-conflict`.
276
+ */
277
+ function formatFailOnConflictSummary(conflictedFiles) {
278
+ const count = conflictedFiles.length;
279
+ const noun = count === 1 ? 'file contains' : 'files contain';
280
+ const lines = conflictedFiles.map((filePath) => ` - ${filePath}`);
281
+ return `Generation failed (--fail-on-conflict): ${count} ${noun} merge-conflict markers:\n${lines.join('\n')}`;
282
+ }
248
283
  /**
249
284
  * Whether this run may advance `.postxl/base-snapshot.json` to the current schema.
250
285
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/cli",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Command-line interface for PostXL code generation framework",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -46,8 +46,8 @@
46
46
  "ts-morph": "26.0.0",
47
47
  "zod-validation-error": "5.0.0",
48
48
  "@postxl/generator": "^2.2.0",
49
- "@postxl/generators": "^6.2.0",
50
- "@postxl/schema": "^2.5.0",
49
+ "@postxl/generators": "^6.3.0",
50
+ "@postxl/schema": "^2.6.0",
51
51
  "@postxl/utils": "^1.4.3"
52
52
  },
53
53
  "devDependencies": {},