@postxl/cli 2.0.0 → 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.
@@ -43,8 +43,6 @@ const devDependencies = [
43
43
  { packageName: Generator.toPostXlPackageName('@postxl/generator') },
44
44
  { packageName: Generator.toPostXlPackageName('@postxl/generators') },
45
45
  { packageName: Generator.toPostXlPackageName('@postxl/schema') },
46
- { packageName: 'prettier', version: '3.7.4' },
47
- { packageName: 'eslint', version: '9.39.2' },
48
46
  ];
49
47
  const scripts = [
50
48
  { name: 'generate', command: 'pnpm run generate:project && pnpm run generate:prisma' },
@@ -69,10 +69,10 @@ Installation flow:
69
69
  1. Writes initial project files (schema, generate.ts, tsconfig, package.json, .env)
70
70
  Uses the simple schema for the first pass even if a custom schema is provided
71
71
  2. Runs pnpm install to fetch initial dependencies
72
- 3. Runs first code generation without formatting (as prettier/eslint not yet installed)
72
+ 3. Runs first code generation without linting and formatting, to produce the full package.json
73
73
  4. Runs pnpm install again to fetch devDependencies added by the generated package.json
74
74
  5. Swaps in the custom schema (if provided) before the final generation
75
- 6. Runs second code generation with full formatting (prettier, eslint)
75
+ 6. Runs second code generation with linting and formatting (Oxlint, Oxfmt)
76
76
  7. Generates TanStack Router route tree
77
77
  8. Generates Prisma client
78
78
  9. Initializes a git repository (unless --skip-git)
@@ -105,17 +105,17 @@ If --skip-generate is used with a custom schema, the custom schema is written di
105
105
  });
106
106
  await installDependencies({ targetPath: projectPath, link });
107
107
  if (!options.skipGenerate) {
108
- // We initially only install the PostXL generator - without prettier, eslint and eslint rules. Hence, we run the first generation
109
- // without transformations. This generates the full package.json with all scripts and dependencies.
108
+ // We initially only install the PostXL generator, so the first generation runs without
109
+ // transformations. It writes the full package.json with all scripts and dependencies.
110
110
  await runGenerate({ projectPath, transform: false });
111
- // After the generation, we now have the full package.json including devDependencies for prettier, eslint, etc.
111
+ // After the generation, we now have the full package.json including all devDependencies.
112
112
  // So we install dependencies again to get those.
113
113
  await installDependencies({ targetPath: projectPath, link });
114
114
  // If a custom schema was provided, write it now before the second (final) generation pass.
115
115
  if (customSchema) {
116
116
  await writeSchema({ name, slug, schema: customSchema, projectPath });
117
117
  }
118
- // The second generation runs with transformations - setting up prettier, eslint, etc.
118
+ // The second generation runs with transformations: linting (Oxlint) and formatting (Oxfmt).
119
119
  await runGenerate({ projectPath, transform: true });
120
120
  await generateTanStackRouter(projectPath);
121
121
  await generatePrismaClient(projectPath);
@@ -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)')
@@ -160,6 +163,7 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
160
163
  ...(targetModelNames ? { selectiveGeneration: true } : {}),
161
164
  ...(options.dryRun ? { dryRun: true } : {}),
162
165
  ...(baseVfs ? { baseVfs } : {}),
166
+ ...(options.threeWay === false ? { recoverBase: false } : {}),
163
167
  });
164
168
  (0, generator_1.logSyncResult)(result, {
165
169
  showModifiedStats: options.modified ?? options.ejected ?? false,
@@ -171,10 +175,14 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
171
175
  if (!baseVfs && hasMergeConflicts(result)) {
172
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.'));
173
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
+ }
174
182
  // The summary already says a human has to look at this run; the exit
175
183
  // code has to say the same thing, or `pxl generate && pnpm build`
176
184
  // carries on over output the generator itself flagged.
177
- if (needsAttention(result)) {
185
+ if (needsAttention(result, { failOnConflict: options.failOnConflict ?? false })) {
178
186
  process.exitCode = 1;
179
187
  }
180
188
  // Persist the current schema as the base for the next generation's
@@ -227,23 +235,51 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
227
235
  * which, and both want a human once. It clears itself: the file is on disk
228
236
  * afterwards, so the next run is green whichever way the human decides.
229
237
  *
230
- * Conflict markers on their own keep their existing exit 0. That predates this
231
- * change and flipping it would break every pipeline that tolerates conflicts, so
232
- * 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).
233
242
  */
234
- function needsAttention(result) {
243
+ function needsAttention(result, options = {}) {
235
244
  if (!result.success) {
236
245
  return true;
237
246
  }
238
247
  if (result.errors.length > 0) {
239
248
  return true;
240
249
  }
250
+ if (options.failOnConflict && hasMergeConflicts(result)) {
251
+ return true;
252
+ }
241
253
  return Object.values(result.files).some((file) => file.isRestored ||
242
254
  (file.action.type === 'MergeConflict' &&
243
255
  (file.action.hasUnverifiedBase ||
244
256
  file.action.mergeIsUnparseable ||
245
257
  file.action.unplacedCustomBlocks !== undefined)));
246
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
+ }
247
283
  /**
248
284
  * Whether this run may advance `.postxl/base-snapshot.json` to the current schema.
249
285
  *
@@ -338,7 +374,10 @@ async function maybeReconstructBaseVfs(params) {
338
374
  const baseGenerated = await manager.generate(baseContext);
339
375
  const baseG = await new generator_1.Generator(baseGenerated).generate((g) => g);
340
376
  if (!options.skipTransform) {
341
- await (0, generator_1.lint)(baseG.context.vfs, options);
377
+ // An unlinted base would not match the lockfile's checksums, so it is no ancestor: let a lint
378
+ // failure fall through to the 2-way fallback below, even under `-i`, rather than logging it
379
+ // a second time and returning a base that fails verification anyway.
380
+ await (0, generator_1.lint)(baseG.context.vfs, { ...options, ignoreErrors: false });
342
381
  await baseG.context.vfs.transform(generator_1.format, {
343
382
  onError: ({ error }) => {
344
383
  if (!options.ignoreErrors) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/cli",
3
- "version": "2.0.0",
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",
@@ -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/generators": "^6.0.0",
49
- "@postxl/schema": "^2.4.0",
50
- "@postxl/generator": "^2.0.0",
51
- "@postxl/utils": "^1.4.2"
48
+ "@postxl/generator": "^2.2.0",
49
+ "@postxl/generators": "^6.3.0",
50
+ "@postxl/schema": "^2.6.0",
51
+ "@postxl/utils": "^1.4.3"
52
52
  },
53
53
  "devDependencies": {},
54
54
  "wallaby": {
@@ -61,8 +61,8 @@
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsc -b tsconfig.build.json",
64
- "lint": "eslint .",
65
- "prettier:check": "prettier --check \"**/*.{ts,tsx}\" --config ../../prettier.config.js --ignore-path ../../.prettierignore",
64
+ "lint": "oxlint",
65
+ "format:check": "oxfmt --check \"**/*.{ts,tsx}\"",
66
66
  "test:jest": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest",
67
67
  "test:coverage": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --coverage",
68
68
  "test:types": "tsc --noEmit"