@postxl/cli 1.10.1 → 1.10.3
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.
package/dist/generate.command.js
CHANGED
|
@@ -156,12 +156,27 @@ 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
|
-
|
|
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
|
-
generatorVersion: (0, base_snapshot_1.resolveGeneratorVersion)(),
|
|
179
|
+
generatorVersion: (0, base_snapshot_1.resolveGeneratorVersion)(targetPath),
|
|
165
180
|
});
|
|
166
181
|
}
|
|
167
182
|
return g;
|
|
@@ -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
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
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,13 +233,25 @@ 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
|
|
236
|
+
if (options.threeWay === false) {
|
|
197
237
|
return undefined;
|
|
198
238
|
}
|
|
199
239
|
const snapshot = await (0, base_snapshot_1.readBaseSnapshot)(targetPath);
|
|
200
240
|
if (!snapshot) {
|
|
201
241
|
return undefined;
|
|
202
242
|
}
|
|
243
|
+
// Reported before every check below, all of which decide whether reconstructing a base is worth
|
|
244
|
+
// 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
|
|
246
|
+
// generator change rewrote every tracked file and said nothing, which is the one run where this
|
|
247
|
+
// note is the only warning there is.
|
|
248
|
+
const driftNote = (0, base_snapshot_1.generatorDriftNote)({
|
|
249
|
+
snapshotVersion: snapshot.generatorVersion,
|
|
250
|
+
currentVersion: (0, base_snapshot_1.resolveGeneratorVersion)(targetPath),
|
|
251
|
+
});
|
|
252
|
+
if (driftNote) {
|
|
253
|
+
console.log((0, utils_1.yellow)(driftNote));
|
|
254
|
+
}
|
|
203
255
|
// The base is only ever consulted to merge files that were edited on disk.
|
|
204
256
|
// When nothing is ejected, reconstructing it (a second full generation +
|
|
205
257
|
// lint + format) would be wasted work, so skip it — the common, clean-project
|
|
@@ -211,14 +263,12 @@ async function maybeReconstructBaseVfs(params) {
|
|
|
211
263
|
if (!parsed.success) {
|
|
212
264
|
return undefined;
|
|
213
265
|
}
|
|
214
|
-
const currentGeneratorVersion = (0, base_snapshot_1.resolveGeneratorVersion)();
|
|
215
|
-
if (snapshot.generatorVersion !== 'unknown' &&
|
|
216
|
-
currentGeneratorVersion !== 'unknown' &&
|
|
217
|
-
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.`));
|
|
219
|
-
}
|
|
220
266
|
try {
|
|
221
|
-
const baseContext = (0, generator_1.prepareBaseContext)(parsed.data, {
|
|
267
|
+
const baseContext = (0, generator_1.prepareBaseContext)(parsed.data, {
|
|
268
|
+
...options,
|
|
269
|
+
...(options.pattern ? { filePattern: options.pattern } : {}),
|
|
270
|
+
...(targetModelNames ? { targetModelNames } : {}),
|
|
271
|
+
});
|
|
222
272
|
const baseGenerated = await manager.generate(baseContext);
|
|
223
273
|
const baseG = await new generator_1.Generator(baseGenerated).generate((g) => g);
|
|
224
274
|
if (!options.skipTransform) {
|
|
@@ -19,8 +19,32 @@ export declare function writeBaseSnapshot(targetPath: string, snapshot: BaseSnap
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function hasLocallyEditedFiles(targetPath: string): Promise<boolean>;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* The warning to print when the generator itself changed since the last generation, or
|
|
23
|
+
* `undefined` when it did not (or when either side is unrecorded — drift detection is advisory,
|
|
24
|
+
* so an unknown version is never reported as a change).
|
|
25
|
+
*
|
|
26
|
+
* Takes only the two versions, deliberately. This says something about the *generator*, not about
|
|
27
|
+
* the merge, so it must not be reachable only on runs that reconstruct a base: a clean project
|
|
28
|
+
* skips reconstruction as wasted work, and that is precisely the run where a generator change
|
|
29
|
+
* rewrites every tracked file with nothing else to signal it. Callers print it before any of the
|
|
30
|
+
* checks that decide whether a base is worth rebuilding.
|
|
31
|
+
*/
|
|
32
|
+
export declare function generatorDriftNote(params: {
|
|
33
|
+
snapshotVersion: string;
|
|
34
|
+
currentVersion: string;
|
|
35
|
+
}): string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Best-effort read of the `@postxl/generators` version that will actually generate, used to
|
|
38
|
+
* detect generator drift between the snapshot and the current run. Falls back to `'unknown'`
|
|
39
|
+
* if it cannot be resolved (drift detection is advisory only).
|
|
40
|
+
*
|
|
41
|
+
* Resolved from `targetPath`, not from this file. The CLI never imports `@postxl/generators`
|
|
42
|
+
* itself — the project's `generate.ts` does, and that is compiled to `<project>/dist/generate.js`
|
|
43
|
+
* and imported from there, so the copy under the *project* is the one whose output lands on disk.
|
|
44
|
+
* A consumer's lockfile may also nest an older copy under `@postxl/cli`; resolving from here would
|
|
45
|
+
* report that one, which generates nothing. Worse, it would be reported on both sides of the drift
|
|
46
|
+
* comparison, so a genuine generator change between two runs would compare equal and the warning
|
|
47
|
+
* would never fire. Falls back to this file's resolution when the project has no copy of its own,
|
|
48
|
+
* which keeps the monorepo and any workspace-linked setup working as before.
|
|
25
49
|
*/
|
|
26
|
-
export declare function resolveGeneratorVersion(): string;
|
|
50
|
+
export declare function resolveGeneratorVersion(targetPath?: string): string;
|
|
@@ -37,6 +37,7 @@ exports.baseSnapshotPath = baseSnapshotPath;
|
|
|
37
37
|
exports.readBaseSnapshot = readBaseSnapshot;
|
|
38
38
|
exports.writeBaseSnapshot = writeBaseSnapshot;
|
|
39
39
|
exports.hasLocallyEditedFiles = hasLocallyEditedFiles;
|
|
40
|
+
exports.generatorDriftNote = generatorDriftNote;
|
|
40
41
|
exports.resolveGeneratorVersion = resolveGeneratorVersion;
|
|
41
42
|
/**
|
|
42
43
|
* Base-snapshot management for the generator's three-way (diff3) merge.
|
|
@@ -131,17 +132,52 @@ async function hasLocallyEditedFiles(targetPath) {
|
|
|
131
132
|
return false;
|
|
132
133
|
}
|
|
133
134
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
135
|
+
* The warning to print when the generator itself changed since the last generation, or
|
|
136
|
+
* `undefined` when it did not (or when either side is unrecorded — drift detection is advisory,
|
|
137
|
+
* so an unknown version is never reported as a change).
|
|
138
|
+
*
|
|
139
|
+
* Takes only the two versions, deliberately. This says something about the *generator*, not about
|
|
140
|
+
* the merge, so it must not be reachable only on runs that reconstruct a base: a clean project
|
|
141
|
+
* skips reconstruction as wasted work, and that is precisely the run where a generator change
|
|
142
|
+
* rewrites every tracked file with nothing else to signal it. Callers print it before any of the
|
|
143
|
+
* checks that decide whether a base is worth rebuilding.
|
|
137
144
|
*/
|
|
138
|
-
function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return pkg.version ?? 'unknown';
|
|
145
|
+
function generatorDriftNote(params) {
|
|
146
|
+
const { snapshotVersion, currentVersion } = params;
|
|
147
|
+
if (snapshotVersion === 'unknown' || currentVersion === 'unknown' || snapshotVersion === currentVersion) {
|
|
148
|
+
return undefined;
|
|
143
149
|
}
|
|
144
|
-
|
|
145
|
-
|
|
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 ` +
|
|
152
|
+
`has no reproducible ancestor and falls back to a 2-way merge.`);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Best-effort read of the `@postxl/generators` version that will actually generate, used to
|
|
156
|
+
* detect generator drift between the snapshot and the current run. Falls back to `'unknown'`
|
|
157
|
+
* if it cannot be resolved (drift detection is advisory only).
|
|
158
|
+
*
|
|
159
|
+
* Resolved from `targetPath`, not from this file. The CLI never imports `@postxl/generators`
|
|
160
|
+
* itself — the project's `generate.ts` does, and that is compiled to `<project>/dist/generate.js`
|
|
161
|
+
* and imported from there, so the copy under the *project* is the one whose output lands on disk.
|
|
162
|
+
* A consumer's lockfile may also nest an older copy under `@postxl/cli`; resolving from here would
|
|
163
|
+
* report that one, which generates nothing. Worse, it would be reported on both sides of the drift
|
|
164
|
+
* comparison, so a genuine generator change between two runs would compare equal and the warning
|
|
165
|
+
* would never fire. Falls back to this file's resolution when the project has no copy of its own,
|
|
166
|
+
* which keeps the monorepo and any workspace-linked setup working as before.
|
|
167
|
+
*/
|
|
168
|
+
function resolveGeneratorVersion(targetPath) {
|
|
169
|
+
const bases = targetPath ? [path.resolve(targetPath, 'noop.js'), __filename] : [__filename];
|
|
170
|
+
for (const base of bases) {
|
|
171
|
+
try {
|
|
172
|
+
const require = (0, node_module_1.createRequire)(base);
|
|
173
|
+
const pkg = require('@postxl/generators/package.json');
|
|
174
|
+
if (pkg.version) {
|
|
175
|
+
return pkg.version;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// Not resolvable from this base — try the next one.
|
|
180
|
+
}
|
|
146
181
|
}
|
|
182
|
+
return 'unknown';
|
|
147
183
|
}
|
|
@@ -94,6 +94,13 @@ exports.GENERATOR_REGISTRY = [
|
|
|
94
94
|
importFrom: '@postxl/generators',
|
|
95
95
|
defaultOptions: () => `{ useDatabase: true, keycloakComponents: [], useS3: false, useBitbucket: false }`,
|
|
96
96
|
},
|
|
97
|
+
{
|
|
98
|
+
kind: 'configure',
|
|
99
|
+
name: 'skailify',
|
|
100
|
+
configureFn: 'configureSkailifyGenerator',
|
|
101
|
+
importFrom: '@postxl/generators',
|
|
102
|
+
defaultOptions: () => `{}`,
|
|
103
|
+
},
|
|
97
104
|
];
|
|
98
105
|
/**
|
|
99
106
|
* Reverse mapping: a top-level call expression in `generate.ts` is matched
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postxl/cli",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.3",
|
|
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.7.
|
|
49
|
-
"@postxl/generators": "^3.
|
|
50
|
-
"@postxl/schema": "^2.
|
|
48
|
+
"@postxl/generator": "^1.7.2",
|
|
49
|
+
"@postxl/generators": "^3.2.0",
|
|
50
|
+
"@postxl/schema": "^2.3.0",
|
|
51
51
|
"@postxl/utils": "^1.4.2"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {},
|