@hexagen-monaco/sync 0.6.0 → 0.7.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.
- package/dist/cli.js +698 -510
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +17 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/domain/types.d.ts +8 -1
- package/dist/domain/types.d.ts.map +1 -1
- package/dist/fs-utils.d.ts +4 -4
- package/dist/fs-utils.d.ts.map +1 -1
- package/dist/generators/apps-framework-templates.d.ts.map +1 -1
- package/dist/generators/apps.d.ts.map +1 -1
- package/dist/generators/architecture-files.d.ts.map +1 -1
- package/dist/generators/barrels/recursive.d.ts +2 -3
- package/dist/generators/barrels/recursive.d.ts.map +1 -1
- package/dist/generators/barrels.d.ts +2 -3
- package/dist/generators/barrels.d.ts.map +1 -1
- package/dist/generators/cross-context.d.ts.map +1 -1
- package/dist/generators/eslint.d.ts.map +1 -1
- package/dist/generators/layer-folders.d.ts +18 -6
- package/dist/generators/layer-folders.d.ts.map +1 -1
- package/dist/generators/package-json.d.ts +2 -3
- package/dist/generators/package-json.d.ts.map +1 -1
- package/dist/generators/reap.d.ts +7 -3
- package/dist/generators/reap.d.ts.map +1 -1
- package/dist/generators/root-file-templates.d.ts +1 -1
- package/dist/generators/root-file-templates.d.ts.map +1 -1
- package/dist/generators/root-files.d.ts.map +1 -1
- package/dist/generators/shared-kernel.d.ts.map +1 -1
- package/dist/generators/stubs.d.ts.map +1 -1
- package/dist/generators/tsconfig.d.ts.map +1 -1
- package/dist/index.js +572 -379
- package/dist/index.js.map +1 -1
- package/dist/journal.d.ts +64 -0
- package/dist/journal.d.ts.map +1 -0
- package/dist/migration-report.d.ts +13 -2
- package/dist/migration-report.d.ts.map +1 -1
- package/dist/results.d.ts +66 -0
- package/dist/results.d.ts.map +1 -1
- package/dist/sync-engine-helpers.d.ts.map +1 -1
- package/dist/sync-engine.d.ts +13 -1
- package/dist/sync-engine.d.ts.map +1 -1
- package/dist/toolchain-version.d.ts +14 -0
- package/dist/toolchain-version.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/application/use-cases/stub-generation.use-case.d.ts +0 -23
- package/dist/application/use-cases/stub-generation.use-case.d.ts.map +0 -1
- package/dist/generators/migration-assistant.d.ts +0 -7
- package/dist/generators/migration-assistant.d.ts.map +0 -1
- package/dist/generators/migration-audit.d.ts +0 -28
- package/dist/generators/migration-audit.d.ts.map +0 -1
- package/dist/generators/migration-stubs.d.ts +0 -7
- package/dist/generators/migration-stubs.d.ts.map +0 -1
- package/dist/generators/test-generator.d.ts +0 -7
- package/dist/generators/test-generator.d.ts.map +0 -1
- package/dist/generators/test-templates/data-builder.d.ts +0 -2
- package/dist/generators/test-templates/data-builder.d.ts.map +0 -1
- package/dist/generators/test-templates/enhanced-test-double.d.ts +0 -2
- package/dist/generators/test-templates/enhanced-test-double.d.ts.map +0 -1
- package/dist/generators/test-templates/index.d.ts +0 -5
- package/dist/generators/test-templates/index.d.ts.map +0 -1
- package/dist/generators/test-templates/integration-test.d.ts +0 -2
- package/dist/generators/test-templates/integration-test.d.ts.map +0 -1
- package/dist/generators/test-templates/unit-test.d.ts +0 -2
- package/dist/generators/test-templates/unit-test.d.ts.map +0 -1
- package/dist/generators/wiring.d.ts +0 -20
- package/dist/generators/wiring.d.ts.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import * as fs22 from 'fs';
|
|
3
|
-
import fs22__default, { mkdirSync, writeFileSync, renameSync, unlinkSync, existsSync, readFileSync, realpathSync, lstatSync, createWriteStream } from 'fs';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
import * as path33 from 'path';
|
|
6
|
-
import path33__default, { dirname, join } from 'path';
|
|
7
2
|
import { Command } from 'commander';
|
|
8
|
-
import
|
|
3
|
+
import * as path34 from 'path';
|
|
4
|
+
import path34__default, { dirname, join } from 'path';
|
|
5
|
+
import * as fs24 from 'fs';
|
|
6
|
+
import fs24__default, { mkdirSync, writeFileSync, renameSync, unlinkSync, existsSync, readFileSync, realpathSync, lstatSync, createWriteStream } from 'fs';
|
|
7
|
+
import fs27, { readFile } from 'fs/promises';
|
|
9
8
|
import { promisify } from 'util';
|
|
10
9
|
import { exec, execSync, spawn } from 'child_process';
|
|
11
10
|
import yaml9 from 'js-yaml';
|
|
12
11
|
import crypto from 'crypto';
|
|
12
|
+
import { fileURLToPath } from 'url';
|
|
13
13
|
import { Project, SyntaxKind, MethodSignature } from 'ts-morph';
|
|
14
14
|
import * as readline from 'readline';
|
|
15
15
|
import { tmpdir } from 'os';
|
|
@@ -25,26 +25,132 @@ var MigrationReport = class {
|
|
|
25
25
|
this.entries.push({ type, target, message });
|
|
26
26
|
}
|
|
27
27
|
async writeReport(config) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
if (config.dryRun && !config.report) {
|
|
29
|
+
const counts = /* @__PURE__ */ new Map();
|
|
30
|
+
for (const e of this.entries) {
|
|
31
|
+
counts.set(e.type, (counts.get(e.type) ?? 0) + 1);
|
|
32
|
+
}
|
|
33
|
+
const breakdown = [...counts.entries()].map(([type, n]) => `${n} ${type}`).join(", ");
|
|
34
|
+
config.logger.info(
|
|
35
|
+
`[DRY-RUN] skipping migration report file (${this.entries.length} entries${breakdown ? `: ${breakdown}` : ""}) — pass --report <path> to write it anyway`
|
|
36
|
+
);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const reportPath = config.report ? path34__default.resolve(config.workspaceRoot, config.report) : path34__default.join(config.workspaceRoot, "SYNC-MIGRATION-REPORT.md");
|
|
40
|
+
await fs27.mkdir(path34__default.dirname(reportPath), { recursive: true });
|
|
41
|
+
let preContent = null;
|
|
42
|
+
try {
|
|
43
|
+
preContent = await fs27.readFile(reportPath, "utf8");
|
|
44
|
+
} catch (e) {
|
|
45
|
+
if (!(e instanceof Error && "code" in e && e.code === "ENOENT"))
|
|
46
|
+
throw e;
|
|
47
|
+
}
|
|
48
|
+
config.journal?.recordWrite(reportPath, preContent);
|
|
32
49
|
const stream = createWriteStream(reportPath, { flags: "w" });
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
stream.write(
|
|
36
|
-
|
|
50
|
+
await new Promise((resolve, reject) => {
|
|
51
|
+
stream.on("error", reject);
|
|
52
|
+
stream.write("# Sync Migration Report\n\n");
|
|
53
|
+
for (const e of this.entries) {
|
|
54
|
+
stream.write(
|
|
55
|
+
`- ${e.type.toUpperCase()}: ${e.target}${e.message ? ` – ${e.message}` : ""}
|
|
37
56
|
`
|
|
38
|
-
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
stream.end(resolve);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var SyncJournal = class {
|
|
64
|
+
entries = [];
|
|
65
|
+
/**
|
|
66
|
+
* Record a write BEFORE it is attempted. `preContent: null` means the file
|
|
67
|
+
* did not exist (a create); a string is the full pre-image of an overwrite.
|
|
68
|
+
* Over-recording is safe: rolling back a write that never happened either
|
|
69
|
+
* restores identical content or unlinks a file that is not there (ENOENT
|
|
70
|
+
* tolerated below). Under-recording loses user data — so mutation sites
|
|
71
|
+
* record first, mutate second.
|
|
72
|
+
*/
|
|
73
|
+
recordWrite(filePath, preContent) {
|
|
74
|
+
this.entries.push({
|
|
75
|
+
path: filePath,
|
|
76
|
+
kind: preContent === null ? "created" : "overwritten",
|
|
77
|
+
preContent
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** Record a deletion BEFORE the unlink, with the full pre-image. */
|
|
81
|
+
recordDelete(filePath, preContent) {
|
|
82
|
+
this.entries.push({ path: filePath, kind: "deleted", preContent });
|
|
83
|
+
}
|
|
84
|
+
get size() {
|
|
85
|
+
return this.entries.length;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Human-readable journal lines (workspace-relative), oldest first — printed
|
|
89
|
+
* verbatim when a failed run must NOT roll back (--allow-dirty).
|
|
90
|
+
*/
|
|
91
|
+
describeEntries(workspaceRoot) {
|
|
92
|
+
return this.entries.map(
|
|
93
|
+
(e) => `${e.kind} ${path34__default.relative(workspaceRoot, e.path)}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Replay the journal in REVERSE order: restore pre-images, unlink created
|
|
98
|
+
* files. Reverse order makes repeated writes to the same path converge on
|
|
99
|
+
* the OLDEST pre-image (pass-1 barrel pre-image is restored last), i.e. the
|
|
100
|
+
* true pre-sync state.
|
|
101
|
+
*
|
|
102
|
+
* Per-entry best-effort: a failing inverse op is collected and replay
|
|
103
|
+
* CONTINUES — restoring nine of ten files beats aborting at the first
|
|
104
|
+
* error. The caller prints the failures; nothing here (or anywhere) falls
|
|
105
|
+
* back to a git-wide reset/clean.
|
|
106
|
+
*
|
|
107
|
+
* Restores use a plain writeFile, not the atomic tmp+rename protocol: the
|
|
108
|
+
* rollback may be running on the same broken substrate that failed the
|
|
109
|
+
* sync, and the simplest possible write maximizes the odds of getting the
|
|
110
|
+
* user's bytes back on disk.
|
|
111
|
+
*/
|
|
112
|
+
async rollback(logger2, workspaceRoot) {
|
|
113
|
+
const outcome = {
|
|
114
|
+
attempted: this.entries.length,
|
|
115
|
+
restored: 0,
|
|
116
|
+
failures: []
|
|
117
|
+
};
|
|
118
|
+
for (const entry of [...this.entries].reverse()) {
|
|
119
|
+
const relative = path34__default.relative(workspaceRoot, entry.path);
|
|
120
|
+
try {
|
|
121
|
+
if (entry.preContent === null) {
|
|
122
|
+
try {
|
|
123
|
+
await fs27.unlink(entry.path);
|
|
124
|
+
} catch (err3) {
|
|
125
|
+
if (!(err3 instanceof Error && "code" in err3 && err3.code === "ENOENT")) {
|
|
126
|
+
throw err3;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
logger2.info(`rolled back (removed) ${relative}`);
|
|
130
|
+
} else {
|
|
131
|
+
await fs27.mkdir(path34__default.dirname(entry.path), { recursive: true });
|
|
132
|
+
await fs27.writeFile(entry.path, entry.preContent, {
|
|
133
|
+
encoding: "utf8"
|
|
134
|
+
});
|
|
135
|
+
logger2.info(`rolled back (restored) ${relative}`);
|
|
136
|
+
}
|
|
137
|
+
outcome.restored += 1;
|
|
138
|
+
} catch (err3) {
|
|
139
|
+
outcome.failures.push({
|
|
140
|
+
path: entry.path,
|
|
141
|
+
intended: entry.preContent === null ? "remove created file" : "restore pre-image",
|
|
142
|
+
error: err3 instanceof Error ? err3.message : String(err3)
|
|
143
|
+
});
|
|
144
|
+
}
|
|
39
145
|
}
|
|
40
|
-
|
|
146
|
+
return outcome;
|
|
41
147
|
}
|
|
42
148
|
};
|
|
43
149
|
var LOCK_FILE = ".architecture/.sync.lock";
|
|
44
150
|
var LockFile = class {
|
|
45
|
-
constructor(workspaceRoot, fsImpl =
|
|
151
|
+
constructor(workspaceRoot, fsImpl = fs27, logger2 = console) {
|
|
46
152
|
this.workspaceRoot = workspaceRoot;
|
|
47
|
-
this.lockPath =
|
|
153
|
+
this.lockPath = path34__default.join(workspaceRoot, LOCK_FILE);
|
|
48
154
|
this.fsImpl = fsImpl;
|
|
49
155
|
this.logger = logger2;
|
|
50
156
|
}
|
|
@@ -111,11 +217,11 @@ var LockFile = class {
|
|
|
111
217
|
};
|
|
112
218
|
var BIN_NAME = process.platform === "win32" ? "hexagen-lint.cmd" : "hexagen-lint";
|
|
113
219
|
function resolveArchLinterBin(startDir) {
|
|
114
|
-
let dir =
|
|
220
|
+
let dir = path34__default.resolve(startDir);
|
|
115
221
|
for (; ; ) {
|
|
116
|
-
const candidate =
|
|
117
|
-
if (
|
|
118
|
-
const parent =
|
|
222
|
+
const candidate = path34__default.join(dir, "node_modules", ".bin", BIN_NAME);
|
|
223
|
+
if (fs24__default.existsSync(candidate)) return candidate;
|
|
224
|
+
const parent = path34__default.dirname(dir);
|
|
119
225
|
if (parent === dir) return null;
|
|
120
226
|
dir = parent;
|
|
121
227
|
}
|
|
@@ -161,9 +267,24 @@ function createEmptyResult() {
|
|
|
161
267
|
created: [],
|
|
162
268
|
skipped: [],
|
|
163
269
|
updated: [],
|
|
270
|
+
deleted: [],
|
|
271
|
+
unchanged: [],
|
|
164
272
|
totalOps: 0
|
|
165
273
|
};
|
|
166
274
|
}
|
|
275
|
+
function recordWriteStatus(result, filePath, status) {
|
|
276
|
+
if (status === "created") {
|
|
277
|
+
result.created.push(filePath);
|
|
278
|
+
result.totalOps += 1;
|
|
279
|
+
} else if (status === "updated") {
|
|
280
|
+
result.updated.push(filePath);
|
|
281
|
+
result.totalOps += 1;
|
|
282
|
+
} else if (status === "unchanged") {
|
|
283
|
+
result.unchanged.push(filePath);
|
|
284
|
+
} else {
|
|
285
|
+
result.skipped.push(filePath);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
167
288
|
|
|
168
289
|
// src/scope-filter.ts
|
|
169
290
|
var GLOB_META = /[*?]/;
|
|
@@ -230,7 +351,7 @@ function isGeneratedFile(content) {
|
|
|
230
351
|
return content.includes(GENERATED_MARKER);
|
|
231
352
|
}
|
|
232
353
|
function isProtectedRoot(filePath, config) {
|
|
233
|
-
const relative =
|
|
354
|
+
const relative = path34__default.relative(config.workspaceRoot, filePath);
|
|
234
355
|
const isRootLevel = !relative.startsWith("packages/") && !relative.startsWith("tools/") && !relative.startsWith("apps/");
|
|
235
356
|
return isRootLevel && Array.from(protectedFiles).some(
|
|
236
357
|
(f) => relative.endsWith(f) || relative.includes(f)
|
|
@@ -238,12 +359,12 @@ function isProtectedRoot(filePath, config) {
|
|
|
238
359
|
}
|
|
239
360
|
function isInScope(filePath, config) {
|
|
240
361
|
if (!config.only || config.only.length === 0) return true;
|
|
241
|
-
const relativePath =
|
|
362
|
+
const relativePath = path34__default.relative(config.workspaceRoot, filePath);
|
|
242
363
|
return matchesScope(relativePath, config.only);
|
|
243
364
|
}
|
|
244
365
|
async function safeWriteFileAtomic(filePath, content, config, report, skipGeneratedCheck = false) {
|
|
245
366
|
const { dryRun, forceRoot, logger: logger2, workspaceRoot } = config;
|
|
246
|
-
const relativePath =
|
|
367
|
+
const relativePath = path34__default.relative(workspaceRoot, filePath);
|
|
247
368
|
if (!isInScope(filePath, config)) {
|
|
248
369
|
logger2.debug(`skipped (outside --only) ${relativePath}`);
|
|
249
370
|
return "skipped";
|
|
@@ -252,7 +373,7 @@ async function safeWriteFileAtomic(filePath, content, config, report, skipGenera
|
|
|
252
373
|
let currentContent = "";
|
|
253
374
|
let currentHash = "";
|
|
254
375
|
try {
|
|
255
|
-
currentContent = await
|
|
376
|
+
currentContent = await fs27.readFile(filePath, "utf8");
|
|
256
377
|
currentHash = contentHash(currentContent);
|
|
257
378
|
exists = true;
|
|
258
379
|
} catch (e) {
|
|
@@ -282,20 +403,21 @@ async function safeWriteFileAtomic(filePath, content, config, report, skipGenera
|
|
|
282
403
|
logger2.info(`[DRY-RUN] would ${action} ${relativePath}`);
|
|
283
404
|
return exists ? "updated" : "created";
|
|
284
405
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
|
|
406
|
+
config.journal?.recordWrite(filePath, exists ? currentContent : null);
|
|
407
|
+
await fs27.mkdir(path34__default.dirname(filePath), { recursive: true });
|
|
408
|
+
const tmpName = `.${path34__default.basename(filePath)}.${crypto.randomUUID()}.tmp`;
|
|
409
|
+
const tmpPath = path34__default.join(path34__default.dirname(filePath), tmpName);
|
|
410
|
+
await fs27.writeFile(tmpPath, content, { encoding: "utf8" });
|
|
289
411
|
try {
|
|
290
|
-
await
|
|
412
|
+
await fs27.rename(tmpPath, filePath);
|
|
291
413
|
const status = exists ? "updated" : "created";
|
|
292
414
|
logger2.info(`${status} ${relativePath}`);
|
|
293
415
|
return status;
|
|
294
416
|
} catch (err3) {
|
|
295
417
|
if (err3 instanceof Error && "code" in err3 && err3.code === "EXDEV") {
|
|
296
418
|
try {
|
|
297
|
-
await
|
|
298
|
-
await
|
|
419
|
+
await fs27.copyFile(tmpPath, filePath);
|
|
420
|
+
await fs27.unlink(tmpPath);
|
|
299
421
|
const status = exists ? "updated" : "created";
|
|
300
422
|
logger2.info(`${status} ${relativePath}`);
|
|
301
423
|
return status;
|
|
@@ -303,55 +425,52 @@ async function safeWriteFileAtomic(filePath, content, config, report, skipGenera
|
|
|
303
425
|
logger2.warn(`EXDEV fallback failed for ${relativePath}: ${copyErr}`);
|
|
304
426
|
}
|
|
305
427
|
}
|
|
306
|
-
await
|
|
428
|
+
await fs27.unlink(tmpPath).catch(() => {
|
|
307
429
|
});
|
|
308
430
|
throw err3;
|
|
309
431
|
}
|
|
310
432
|
}
|
|
311
433
|
|
|
312
434
|
// src/generators/layer-folders.ts
|
|
313
|
-
|
|
314
|
-
async function loadYamlSafe(filePath) {
|
|
435
|
+
async function directoryExists(dirPath) {
|
|
315
436
|
try {
|
|
316
|
-
const
|
|
317
|
-
return
|
|
437
|
+
const stats = await fs27.stat(dirPath);
|
|
438
|
+
return stats.isDirectory();
|
|
318
439
|
} catch (e) {
|
|
319
440
|
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
|
|
320
|
-
return
|
|
441
|
+
return false;
|
|
321
442
|
}
|
|
322
443
|
throw e;
|
|
323
444
|
}
|
|
324
445
|
}
|
|
325
|
-
async function
|
|
326
|
-
const
|
|
446
|
+
async function ensureDirectoryCounted(dirPath, config, result) {
|
|
447
|
+
const existed = await directoryExists(dirPath);
|
|
448
|
+
if (existed) return;
|
|
449
|
+
const relativePath = path34__default.relative(config.workspaceRoot, dirPath);
|
|
450
|
+
if (config.dryRun) {
|
|
451
|
+
config.logger.info(`[DRY-RUN] would create directory ${relativePath}`);
|
|
452
|
+
} else {
|
|
453
|
+
await fs27.mkdir(dirPath, { recursive: true });
|
|
454
|
+
config.logger.info(`created directory ${relativePath}`);
|
|
455
|
+
}
|
|
456
|
+
result.created.push(dirPath);
|
|
457
|
+
result.totalOps += 1;
|
|
458
|
+
}
|
|
459
|
+
async function loadYamlSafe(filePath) {
|
|
327
460
|
try {
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
if (entry.name === "index.ts" || entry.name.startsWith(".")) continue;
|
|
331
|
-
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
332
|
-
const base = entry.name.replace(/\.ts$/, "");
|
|
333
|
-
exportLines.push(`export * from './${base}.js';`);
|
|
334
|
-
} else if (entry.isDirectory()) {
|
|
335
|
-
exportLines.push(`export * from './${entry.name}/index.js';`);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
461
|
+
const content = await fs27.readFile(filePath, "utf8");
|
|
462
|
+
return yaml9.load(content);
|
|
338
463
|
} catch (e) {
|
|
339
|
-
if (e instanceof Error && "code" in e && e.code === "ENOENT")
|
|
340
|
-
|
|
464
|
+
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
|
|
465
|
+
return null;
|
|
341
466
|
}
|
|
467
|
+
throw e;
|
|
342
468
|
}
|
|
343
|
-
return exportLines.length > 0 ? `${GENERATED_MARKER2}
|
|
344
|
-
|
|
345
|
-
${exportLines.join("\n")}
|
|
346
|
-
` : `${GENERATED_MARKER2}
|
|
347
|
-
|
|
348
|
-
// No exports yet
|
|
349
|
-
`;
|
|
350
469
|
}
|
|
351
|
-
async function ensureLayerFolders(moduleDir, layers, config
|
|
470
|
+
async function ensureLayerFolders(moduleDir, layers, config) {
|
|
352
471
|
const result = createEmptyResult();
|
|
353
472
|
const { logger: logger2 } = config;
|
|
354
|
-
const layerRulesPath =
|
|
473
|
+
const layerRulesPath = path34__default.join(
|
|
355
474
|
config.workspaceRoot,
|
|
356
475
|
".architecture",
|
|
357
476
|
"invariants",
|
|
@@ -362,64 +481,18 @@ async function ensureLayerFolders(moduleDir, layers, config, report) {
|
|
|
362
481
|
logger2.warn("layer-rules.yaml not found — skipping layer rule enforcement");
|
|
363
482
|
}
|
|
364
483
|
for (const [, layerConfig] of Object.entries(layers)) {
|
|
365
|
-
const layerPath =
|
|
366
|
-
|
|
367
|
-
if (!isInScope(barrelPath, config)) {
|
|
484
|
+
const layerPath = path34__default.join(moduleDir, layerConfig.folder);
|
|
485
|
+
if (!isInScope(layerPath, config) && !isInScope(path34__default.join(layerPath, "index.ts"), config)) {
|
|
368
486
|
continue;
|
|
369
487
|
}
|
|
370
|
-
|
|
371
|
-
await fs25.mkdir(layerPath, { recursive: true });
|
|
372
|
-
result.created.push(layerPath);
|
|
373
|
-
result.totalOps += 1;
|
|
374
|
-
} catch (e) {
|
|
375
|
-
if (e instanceof Error && "code" in e && e.code === "EEXIST") {
|
|
376
|
-
result.skipped.push(layerPath);
|
|
377
|
-
} else {
|
|
378
|
-
throw e;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
const barrelContent = await generateBarrelContent(layerPath);
|
|
382
|
-
const barrelStatus = await safeWriteFileAtomic(
|
|
383
|
-
barrelPath,
|
|
384
|
-
barrelContent,
|
|
385
|
-
config,
|
|
386
|
-
report
|
|
387
|
-
);
|
|
388
|
-
if (barrelStatus === "created") result.created.push(barrelPath);
|
|
389
|
-
if (barrelStatus === "updated") result.updated.push(barrelPath);
|
|
390
|
-
if (barrelStatus === "skipped" || barrelStatus === "protected")
|
|
391
|
-
result.skipped.push(barrelPath);
|
|
392
|
-
result.totalOps += barrelStatus === "created" || barrelStatus === "updated" ? 1 : 0;
|
|
488
|
+
await ensureDirectoryCounted(layerPath, config, result);
|
|
393
489
|
const subfolders = layerConfig.subfolders ?? [];
|
|
394
490
|
for (const sub of subfolders) {
|
|
395
|
-
const subPath =
|
|
396
|
-
|
|
397
|
-
if (!isInScope(subBarrelPath, config)) {
|
|
491
|
+
const subPath = path34__default.join(layerPath, sub);
|
|
492
|
+
if (!isInScope(subPath, config) && !isInScope(path34__default.join(subPath, "index.ts"), config)) {
|
|
398
493
|
continue;
|
|
399
494
|
}
|
|
400
|
-
|
|
401
|
-
await fs25.mkdir(subPath, { recursive: true });
|
|
402
|
-
result.created.push(subPath);
|
|
403
|
-
result.totalOps += 1;
|
|
404
|
-
} catch (e) {
|
|
405
|
-
if (e instanceof Error && "code" in e && e.code === "EEXIST") {
|
|
406
|
-
result.skipped.push(subPath);
|
|
407
|
-
} else {
|
|
408
|
-
throw e;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
const subBarrelContent = await generateBarrelContent(subPath);
|
|
412
|
-
const subBarrelStatus = await safeWriteFileAtomic(
|
|
413
|
-
subBarrelPath,
|
|
414
|
-
subBarrelContent,
|
|
415
|
-
config,
|
|
416
|
-
report
|
|
417
|
-
);
|
|
418
|
-
if (subBarrelStatus === "created") result.created.push(subBarrelPath);
|
|
419
|
-
if (subBarrelStatus === "updated") result.updated.push(subBarrelPath);
|
|
420
|
-
if (subBarrelStatus === "skipped" || subBarrelStatus === "protected")
|
|
421
|
-
result.skipped.push(subBarrelPath);
|
|
422
|
-
result.totalOps += subBarrelStatus === "created" || subBarrelStatus === "updated" ? 1 : 0;
|
|
495
|
+
await ensureDirectoryCounted(subPath, config, result);
|
|
423
496
|
}
|
|
424
497
|
}
|
|
425
498
|
return result;
|
|
@@ -440,10 +513,10 @@ var BARREL_EXCLUSIONS = /* @__PURE__ */ new Set([
|
|
|
440
513
|
function isExcludedDirectory(name) {
|
|
441
514
|
return BARREL_EXCLUSIONS.has(name) || name.startsWith(".");
|
|
442
515
|
}
|
|
443
|
-
var
|
|
516
|
+
var GENERATED_MARKER2 = "// @generated by @hexagen/sync";
|
|
444
517
|
var LEGACY_GENERATED_MARKER = "— generated by sync.ts";
|
|
445
518
|
function isGeneratedFile2(content) {
|
|
446
|
-
return content.includes(
|
|
519
|
+
return content.includes(GENERATED_MARKER2) || content.includes(LEGACY_GENERATED_MARKER);
|
|
447
520
|
}
|
|
448
521
|
function contentHash2(content) {
|
|
449
522
|
return crypto.createHash("sha256").update(content).digest("hex");
|
|
@@ -451,18 +524,18 @@ function contentHash2(content) {
|
|
|
451
524
|
function detectCircularExports(exportGraph) {
|
|
452
525
|
const visited = /* @__PURE__ */ new Set();
|
|
453
526
|
const recursionStack = /* @__PURE__ */ new Set();
|
|
454
|
-
const
|
|
527
|
+
const path38 = [];
|
|
455
528
|
function dfs(node) {
|
|
456
529
|
if (recursionStack.has(node)) {
|
|
457
|
-
const cycleStart =
|
|
458
|
-
return [...
|
|
530
|
+
const cycleStart = path38.indexOf(node);
|
|
531
|
+
return [...path38.slice(cycleStart), node];
|
|
459
532
|
}
|
|
460
533
|
if (visited.has(node)) {
|
|
461
534
|
return null;
|
|
462
535
|
}
|
|
463
536
|
visited.add(node);
|
|
464
537
|
recursionStack.add(node);
|
|
465
|
-
|
|
538
|
+
path38.push(node);
|
|
466
539
|
const exports$1 = exportGraph.get(node) ?? [];
|
|
467
540
|
for (const exportPath of exports$1) {
|
|
468
541
|
const cycle = dfs(exportPath);
|
|
@@ -470,7 +543,7 @@ function detectCircularExports(exportGraph) {
|
|
|
470
543
|
return cycle;
|
|
471
544
|
}
|
|
472
545
|
}
|
|
473
|
-
|
|
546
|
+
path38.pop();
|
|
474
547
|
recursionStack.delete(node);
|
|
475
548
|
return null;
|
|
476
549
|
}
|
|
@@ -482,15 +555,15 @@ function detectCircularExports(exportGraph) {
|
|
|
482
555
|
}
|
|
483
556
|
return { hasCircular: false, cycle: null };
|
|
484
557
|
}
|
|
485
|
-
function
|
|
558
|
+
function generateBarrelContent(entries) {
|
|
486
559
|
if (entries.length === 0) {
|
|
487
560
|
return null;
|
|
488
561
|
}
|
|
489
562
|
const exportLines = entries.sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
|
|
490
|
-
const
|
|
491
|
-
return `export * from "${
|
|
563
|
+
const path38 = entry.isDirectory ? `./${entry.name}/index.js` : `./${entry.name}.js`;
|
|
564
|
+
return `export * from "${path38}";`;
|
|
492
565
|
});
|
|
493
|
-
return `${
|
|
566
|
+
return `${GENERATED_MARKER2}
|
|
494
567
|
|
|
495
568
|
${exportLines.join("\n")}
|
|
496
569
|
`;
|
|
@@ -510,16 +583,16 @@ var CircularExportError = class extends Error {
|
|
|
510
583
|
};
|
|
511
584
|
async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
512
585
|
const result = createEmptyResult();
|
|
513
|
-
const srcDir =
|
|
586
|
+
const srcDir = path34__default.join(moduleDir, "src");
|
|
514
587
|
const layers = ["domain", "application", "infrastructure"];
|
|
515
588
|
const pendingWrites = [];
|
|
516
589
|
const preserved = [];
|
|
517
590
|
const exportGraph = /* @__PURE__ */ new Map();
|
|
518
591
|
const layersWithContent = [];
|
|
519
592
|
for (const layer of layers) {
|
|
520
|
-
const layerDir =
|
|
593
|
+
const layerDir = path34__default.join(srcDir, layer);
|
|
521
594
|
try {
|
|
522
|
-
await
|
|
595
|
+
await fs27.access(layerDir);
|
|
523
596
|
} catch {
|
|
524
597
|
continue;
|
|
525
598
|
}
|
|
@@ -533,9 +606,9 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
|
533
606
|
if (layerExports.length > 0) layersWithContent.push(layer);
|
|
534
607
|
}
|
|
535
608
|
if (config.mode === "external" && layersWithContent.length > 0) {
|
|
536
|
-
const rootBarrelPath =
|
|
609
|
+
const rootBarrelPath = path34__default.join(srcDir, "index.ts");
|
|
537
610
|
if (await shouldGenerateBarrel(rootBarrelPath, preserved, config.logger)) {
|
|
538
|
-
const content =
|
|
611
|
+
const content = generateBarrelContent(
|
|
539
612
|
layersWithContent.map((name) => ({ name, isDirectory: true }))
|
|
540
613
|
);
|
|
541
614
|
const existing = await readFileIfExists(rootBarrelPath);
|
|
@@ -547,7 +620,7 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
|
547
620
|
});
|
|
548
621
|
exportGraph.set(
|
|
549
622
|
rootBarrelPath,
|
|
550
|
-
layersWithContent.map((name) =>
|
|
623
|
+
layersWithContent.map((name) => path34__default.join(srcDir, name, "index.ts"))
|
|
551
624
|
);
|
|
552
625
|
}
|
|
553
626
|
}
|
|
@@ -558,9 +631,19 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
|
558
631
|
}
|
|
559
632
|
for (const pending of pendingWrites) {
|
|
560
633
|
if (pending.content === "") {
|
|
634
|
+
if (config.dryRun) {
|
|
635
|
+
config.logger.info(
|
|
636
|
+
`[DRY-RUN] would delete empty barrel ${pending.filePath}`
|
|
637
|
+
);
|
|
638
|
+
result.deleted.push(pending.filePath);
|
|
639
|
+
result.totalOps++;
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
561
642
|
try {
|
|
562
|
-
await
|
|
563
|
-
|
|
643
|
+
const preContent = await fs27.readFile(pending.filePath, "utf8");
|
|
644
|
+
config.journal?.recordDelete(pending.filePath, preContent);
|
|
645
|
+
await fs27.unlink(pending.filePath);
|
|
646
|
+
result.deleted.push(pending.filePath);
|
|
564
647
|
result.totalOps++;
|
|
565
648
|
continue;
|
|
566
649
|
} catch (err3) {
|
|
@@ -576,15 +659,7 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
|
576
659
|
config,
|
|
577
660
|
report
|
|
578
661
|
);
|
|
579
|
-
|
|
580
|
-
result.created.push(pending.filePath);
|
|
581
|
-
result.totalOps++;
|
|
582
|
-
} else if (status === "updated") {
|
|
583
|
-
result.updated.push(pending.filePath);
|
|
584
|
-
result.totalOps++;
|
|
585
|
-
} else if (status === "skipped" || status === "protected") {
|
|
586
|
-
result.skipped.push(pending.filePath);
|
|
587
|
-
}
|
|
662
|
+
recordWriteStatus(result, pending.filePath, status);
|
|
588
663
|
}
|
|
589
664
|
result.skipped.push(...preserved);
|
|
590
665
|
return result;
|
|
@@ -594,7 +669,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
594
669
|
const exportEntries = [];
|
|
595
670
|
let entries;
|
|
596
671
|
try {
|
|
597
|
-
entries = await
|
|
672
|
+
entries = await fs27.readdir(dirPath, { withFileTypes: true });
|
|
598
673
|
} catch {
|
|
599
674
|
return exportEntries;
|
|
600
675
|
}
|
|
@@ -611,7 +686,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
611
686
|
}
|
|
612
687
|
}
|
|
613
688
|
for (const dir of directories) {
|
|
614
|
-
const subDirPath =
|
|
689
|
+
const subDirPath = path34__default.join(dirPath, dir);
|
|
615
690
|
const subExports = await walkDirectory(
|
|
616
691
|
subDirPath,
|
|
617
692
|
pendingWrites,
|
|
@@ -619,7 +694,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
619
694
|
exportGraph,
|
|
620
695
|
config
|
|
621
696
|
);
|
|
622
|
-
const subBarrelPath =
|
|
697
|
+
const subBarrelPath = path34__default.join(subDirPath, "index.ts");
|
|
623
698
|
const isQueuedForDeletion = pendingWrites.some(
|
|
624
699
|
(p) => p.filePath === subBarrelPath && p.content === ""
|
|
625
700
|
);
|
|
@@ -631,9 +706,9 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
631
706
|
exportEntries.push({ name: file, isDirectory: false });
|
|
632
707
|
}
|
|
633
708
|
if (exportEntries.length === 0) {
|
|
634
|
-
const barrelPath2 =
|
|
709
|
+
const barrelPath2 = path34__default.join(dirPath, "index.ts");
|
|
635
710
|
const existingBarrel = await readFileIfExists(barrelPath2);
|
|
636
|
-
const dirName =
|
|
711
|
+
const dirName = path34__default.basename(dirPath);
|
|
637
712
|
const isLayerDir = ["domain", "application", "infrastructure"].includes(
|
|
638
713
|
dirName
|
|
639
714
|
);
|
|
@@ -648,7 +723,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
648
723
|
isNew: false
|
|
649
724
|
});
|
|
650
725
|
} else if (isEmptyStub && isLayerDir) {
|
|
651
|
-
const newContent = `${
|
|
726
|
+
const newContent = `${GENERATED_MARKER2}
|
|
652
727
|
|
|
653
728
|
export {};
|
|
654
729
|
`;
|
|
@@ -660,7 +735,7 @@ export {};
|
|
|
660
735
|
});
|
|
661
736
|
}
|
|
662
737
|
} else if (!existingBarrel.includes("export {}") && isLayerDir) {
|
|
663
|
-
const newContent = `${
|
|
738
|
+
const newContent = `${GENERATED_MARKER2}
|
|
664
739
|
|
|
665
740
|
export {};
|
|
666
741
|
`;
|
|
@@ -671,7 +746,7 @@ export {};
|
|
|
671
746
|
});
|
|
672
747
|
}
|
|
673
748
|
} else if (isLayerDir) {
|
|
674
|
-
const newContent = `${
|
|
749
|
+
const newContent = `${GENERATED_MARKER2}
|
|
675
750
|
|
|
676
751
|
export {};
|
|
677
752
|
`;
|
|
@@ -683,14 +758,14 @@ export {};
|
|
|
683
758
|
}
|
|
684
759
|
return [];
|
|
685
760
|
}
|
|
686
|
-
const barrelPath =
|
|
761
|
+
const barrelPath = path34__default.join(dirPath, "index.ts");
|
|
687
762
|
const shouldCreateBarrel = await shouldGenerateBarrel(
|
|
688
763
|
barrelPath,
|
|
689
764
|
preserved,
|
|
690
765
|
logger2
|
|
691
766
|
);
|
|
692
767
|
if (shouldCreateBarrel) {
|
|
693
|
-
const content =
|
|
768
|
+
const content = generateBarrelContent(exportEntries);
|
|
694
769
|
if (content === null) {
|
|
695
770
|
return [];
|
|
696
771
|
}
|
|
@@ -703,14 +778,14 @@ export {};
|
|
|
703
778
|
content,
|
|
704
779
|
isNew: !existingContent
|
|
705
780
|
});
|
|
706
|
-
const exportPaths = exportEntries.filter((e) => e.isDirectory).map((e) =>
|
|
781
|
+
const exportPaths = exportEntries.filter((e) => e.isDirectory).map((e) => path34__default.join(dirPath, e.name, "index.ts"));
|
|
707
782
|
exportGraph.set(barrelPath, exportPaths);
|
|
708
783
|
}
|
|
709
784
|
return exportEntries;
|
|
710
785
|
}
|
|
711
786
|
async function hasBarrel(dirPath) {
|
|
712
787
|
try {
|
|
713
|
-
await
|
|
788
|
+
await fs27.access(path34__default.join(dirPath, "index.ts"));
|
|
714
789
|
return true;
|
|
715
790
|
} catch {
|
|
716
791
|
return false;
|
|
@@ -730,7 +805,7 @@ async function shouldGenerateBarrel(barrelPath, preserved, logger2) {
|
|
|
730
805
|
}
|
|
731
806
|
async function readFileIfExists(filePath) {
|
|
732
807
|
try {
|
|
733
|
-
return await
|
|
808
|
+
return await fs27.readFile(filePath, "utf8");
|
|
734
809
|
} catch (err3) {
|
|
735
810
|
if (err3 && typeof err3 === "object" && "code" in err3 && err3.code === "ENOENT") {
|
|
736
811
|
return null;
|
|
@@ -775,7 +850,12 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
|
|
|
775
850
|
const moduleOverrides = context?.packageJson ?? {};
|
|
776
851
|
const scope = config.manifest ? resolveScope(config.manifest) : "generated-project";
|
|
777
852
|
const dependsOnDeps = context ? expandDependsOn(context, scope) : {};
|
|
778
|
-
const pkgPath =
|
|
853
|
+
const pkgPath = path34__default.join(modulePath, "package.json");
|
|
854
|
+
const dependencies = {
|
|
855
|
+
...dependsOnDeps,
|
|
856
|
+
...defaults.dependencies ?? {},
|
|
857
|
+
...moduleOverrides.dependencies ?? {}
|
|
858
|
+
};
|
|
779
859
|
const desiredPkg = {
|
|
780
860
|
name: `@${scope}/${moduleName}`,
|
|
781
861
|
version: "0.1.0",
|
|
@@ -796,11 +876,17 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
|
|
|
796
876
|
...defaults.scripts ?? {},
|
|
797
877
|
...moduleOverrides.scripts ?? {}
|
|
798
878
|
},
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
879
|
+
// Emitted only when non-empty (PR-B2, capstone 6f): Yarn 4 deletes an
|
|
880
|
+
// empty `"dependencies": {}` from workspace manifests during install, so
|
|
881
|
+
// emitting one creates a permanent install↔sync churn loop — install
|
|
882
|
+
// strips the key, the next sync re-injects it (`dependencies` is
|
|
883
|
+
// protected, but a protected key MISSING from the current file is
|
|
884
|
+
// re-added), and the tree never converges across the consumer's
|
|
885
|
+
// sync → install → sync workflow. A dependency-less package carries no
|
|
886
|
+
// block at all, matching yarn's normalized form. Existing trees that
|
|
887
|
+
// still carry `{}` on disk stay untouched via the protected-key merge.
|
|
888
|
+
// devDependencies/scripts can't go empty (both have built-in entries).
|
|
889
|
+
...Object.keys(dependencies).length > 0 ? { dependencies } : {},
|
|
804
890
|
devDependencies: {
|
|
805
891
|
typescript: "^5.0.0",
|
|
806
892
|
...defaults.devDependencies ?? {},
|
|
@@ -809,7 +895,7 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
|
|
|
809
895
|
};
|
|
810
896
|
let currentPkg = {};
|
|
811
897
|
try {
|
|
812
|
-
const currentContent = await
|
|
898
|
+
const currentContent = await fs27.readFile(pkgPath, "utf8");
|
|
813
899
|
currentPkg = JSON.parse(currentContent);
|
|
814
900
|
} catch (e) {
|
|
815
901
|
if (!(e instanceof Error && "code" in e && e.code === "ENOENT")) {
|
|
@@ -849,11 +935,7 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
|
|
|
849
935
|
report,
|
|
850
936
|
true
|
|
851
937
|
);
|
|
852
|
-
|
|
853
|
-
if (status === "updated") result.updated.push(pkgPath);
|
|
854
|
-
if (status === "skipped" || status === "protected")
|
|
855
|
-
result.skipped.push(pkgPath);
|
|
856
|
-
result.totalOps += status === "created" || status === "updated" ? 1 : 0;
|
|
938
|
+
recordWriteStatus(result, pkgPath, status);
|
|
857
939
|
return result;
|
|
858
940
|
}
|
|
859
941
|
var BUILTIN_FALLBACK_TEMPLATE = {
|
|
@@ -923,7 +1005,7 @@ function buildTemplate(base, context, scope) {
|
|
|
923
1005
|
}
|
|
924
1006
|
async function generateTsconfig(moduleDir, moduleName, config, report) {
|
|
925
1007
|
const result = createEmptyResult();
|
|
926
|
-
const filePath =
|
|
1008
|
+
const filePath = path34__default.join(moduleDir, "tsconfig.json");
|
|
927
1009
|
try {
|
|
928
1010
|
const base = resolveWorkspaceTemplate(config.manifest);
|
|
929
1011
|
const context = config.manifest.bounded_contexts?.find(
|
|
@@ -938,16 +1020,14 @@ async function generateTsconfig(moduleDir, moduleName, config, report) {
|
|
|
938
1020
|
config,
|
|
939
1021
|
report
|
|
940
1022
|
);
|
|
941
|
-
|
|
942
|
-
if (status === "updated") result.updated.push(filePath);
|
|
943
|
-
if (status === "skipped" || status === "protected")
|
|
944
|
-
result.skipped.push(filePath);
|
|
945
|
-
result.totalOps += status === "created" || status === "updated" ? 1 : 0;
|
|
1023
|
+
recordWriteStatus(result, filePath, status);
|
|
946
1024
|
return result;
|
|
947
1025
|
} catch (err3) {
|
|
948
1026
|
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
949
1027
|
result.error = err3 instanceof Error ? err3 : new Error(`tsconfig generation failed for ${moduleName}: ${message}`);
|
|
950
1028
|
result.summary = `tsconfig generation failed for ${moduleName}: ${message}`;
|
|
1029
|
+
config.logger.error(result.summary);
|
|
1030
|
+
if (report) report.record("error", filePath, result.summary);
|
|
951
1031
|
return result;
|
|
952
1032
|
}
|
|
953
1033
|
}
|
|
@@ -955,15 +1035,15 @@ async function reapLegacyFolders(moduleDir, config, report) {
|
|
|
955
1035
|
const { dryRun, logger: logger2 } = config;
|
|
956
1036
|
const legacyLayers = ["domain", "application", "infrastructure"];
|
|
957
1037
|
for (const layer of legacyLayers) {
|
|
958
|
-
const layerPath =
|
|
959
|
-
const relativePath =
|
|
1038
|
+
const layerPath = path34__default.join(moduleDir, layer);
|
|
1039
|
+
const relativePath = path34__default.relative(config.workspaceRoot, layerPath);
|
|
960
1040
|
try {
|
|
961
|
-
const entries = await
|
|
1041
|
+
const entries = await fs27.readdir(layerPath);
|
|
962
1042
|
if (entries.length === 0) {
|
|
963
1043
|
if (dryRun) {
|
|
964
1044
|
logger2.info(`[DRY-RUN] would delete empty folder ${relativePath}`);
|
|
965
1045
|
} else {
|
|
966
|
-
await
|
|
1046
|
+
await fs27.rmdir(layerPath);
|
|
967
1047
|
logger2.info(`deleted empty folder ${relativePath}`);
|
|
968
1048
|
if (report) report.record("deleted", layerPath);
|
|
969
1049
|
}
|
|
@@ -1453,8 +1533,8 @@ function getErrorMap() {
|
|
|
1453
1533
|
|
|
1454
1534
|
// ../../node_modules/zod/v3/helpers/parseUtil.js
|
|
1455
1535
|
var makeIssue = (params) => {
|
|
1456
|
-
const { data, path:
|
|
1457
|
-
const fullPath = [...
|
|
1536
|
+
const { data, path: path38, errorMaps, issueData } = params;
|
|
1537
|
+
const fullPath = [...path38, ...issueData.path || []];
|
|
1458
1538
|
const fullIssue = {
|
|
1459
1539
|
...issueData,
|
|
1460
1540
|
path: fullPath
|
|
@@ -1570,11 +1650,11 @@ var errorUtil;
|
|
|
1570
1650
|
|
|
1571
1651
|
// ../../node_modules/zod/v3/types.js
|
|
1572
1652
|
var ParseInputLazyPath = class {
|
|
1573
|
-
constructor(parent, value,
|
|
1653
|
+
constructor(parent, value, path38, key) {
|
|
1574
1654
|
this._cachedPath = [];
|
|
1575
1655
|
this.parent = parent;
|
|
1576
1656
|
this.data = value;
|
|
1577
|
-
this._path =
|
|
1657
|
+
this._path = path38;
|
|
1578
1658
|
this._key = key;
|
|
1579
1659
|
}
|
|
1580
1660
|
get path() {
|
|
@@ -5085,6 +5165,7 @@ var BUILTIN_PACKAGE_JSON_TEMPLATE = `{
|
|
|
5085
5165
|
"sync": "hexagen sync",
|
|
5086
5166
|
"sync:dry": "hexagen sync --dry-run",
|
|
5087
5167
|
"sync:force": "hexagen sync --force",
|
|
5168
|
+
"sync:check": "hexagen sync --check",
|
|
5088
5169
|
"lint:arch": "hexagen arch validate",
|
|
5089
5170
|
"templates:add": "hexagen add",
|
|
5090
5171
|
"templates:validate": "hexagen validate-templates",
|
|
@@ -5095,8 +5176,8 @@ var BUILTIN_PACKAGE_JSON_TEMPLATE = `{
|
|
|
5095
5176
|
"typescript": "^5.5.4",
|
|
5096
5177
|
"eslint": "^9.0.0",
|
|
5097
5178
|
"prettier": "^3.0.0",
|
|
5098
|
-
"@hexagen-monaco/sync": "^
|
|
5099
|
-
"@hexagen-monaco/arch-linter": "^
|
|
5179
|
+
"@hexagen-monaco/sync": "^{toolchainVersion}",
|
|
5180
|
+
"@hexagen-monaco/arch-linter": "^{toolchainVersion}"
|
|
5100
5181
|
}
|
|
5101
5182
|
}`;
|
|
5102
5183
|
var BUILTIN_TSCONFIG_BASE_TEMPLATE = `{
|
|
@@ -5208,15 +5289,33 @@ adding \`--immutable\` to the \`yarn install\` step in
|
|
|
5208
5289
|
Its pre-lockfile guidance goes stale once \`yarn.lock\` is committed. (Run
|
|
5209
5290
|
\`hexagen sync\` won't bring it back — it's a protected root file.)
|
|
5210
5291
|
`;
|
|
5292
|
+
var SEMVER_2_0_0 = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
5293
|
+
function assertValidToolchainVersion(version, source) {
|
|
5294
|
+
const invalid = !SEMVER_2_0_0.test(version) || /^0\.0\.0(?:$|[-+])/.test(version);
|
|
5295
|
+
if (invalid) {
|
|
5296
|
+
throw new Error(
|
|
5297
|
+
`Toolchain version unavailable, malformed, or degenerate (${source} → ${JSON.stringify(version)}). Refusing to continue: the scaffold would pin @hexagen-monaco/* devDependencies to a version that does not exist (RCA #1 — never emit a degenerate pin).`
|
|
5298
|
+
);
|
|
5299
|
+
}
|
|
5300
|
+
return version;
|
|
5301
|
+
}
|
|
5302
|
+
function resolveToolchainVersion() {
|
|
5303
|
+
{
|
|
5304
|
+
return assertValidToolchainVersion(
|
|
5305
|
+
"0.7.0",
|
|
5306
|
+
"build-injected __HEXAGEN_TOOLCHAIN_VERSION__"
|
|
5307
|
+
);
|
|
5308
|
+
}
|
|
5309
|
+
}
|
|
5211
5310
|
|
|
5212
5311
|
// src/generators/root-files.ts
|
|
5213
|
-
function buildVars(manifest) {
|
|
5312
|
+
function buildVars(manifest, toolchainVersion) {
|
|
5214
5313
|
const system = typeof manifest.system === "string" && manifest.system.length > 0 ? manifest.system : "generated-project";
|
|
5215
5314
|
const scope = resolveScope(manifest);
|
|
5216
5315
|
const packageManager = typeof manifest.monorepo?.packageManager === "string" && manifest.monorepo.packageManager.length > 0 ? manifest.monorepo.packageManager : "yarn@4.12.0";
|
|
5217
5316
|
const workspacesArray = Array.isArray(manifest.monorepo?.workspaces) && manifest.monorepo.workspaces.length > 0 ? manifest.monorepo.workspaces : ["apps/*", "packages/*"];
|
|
5218
5317
|
const workspaces = "[\n" + workspacesArray.map((w) => ` ${JSON.stringify(w)}`).join(",\n") + "\n ]";
|
|
5219
|
-
return { system, scope, packageManager, workspaces };
|
|
5318
|
+
return { system, scope, packageManager, workspaces, toolchainVersion };
|
|
5220
5319
|
}
|
|
5221
5320
|
function resolveTemplate(manifestTemplate, builtin) {
|
|
5222
5321
|
if (typeof manifestTemplate === "string" && manifestTemplate.length > 0) {
|
|
@@ -5242,17 +5341,14 @@ async function writeRootFile(filePath, content, config, report, result) {
|
|
|
5242
5341
|
report,
|
|
5243
5342
|
true
|
|
5244
5343
|
);
|
|
5245
|
-
|
|
5246
|
-
if (status === "updated") result.updated.push(filePath);
|
|
5247
|
-
if (status === "skipped" || status === "protected")
|
|
5248
|
-
result.skipped.push(filePath);
|
|
5249
|
-
if (status === "created" || status === "updated") result.totalOps += 1;
|
|
5344
|
+
recordWriteStatus(result, filePath, status);
|
|
5250
5345
|
}
|
|
5251
5346
|
async function generateRootFiles(config, report) {
|
|
5252
5347
|
const result = createEmptyResult();
|
|
5348
|
+
const toolchainVersion = resolveToolchainVersion();
|
|
5253
5349
|
try {
|
|
5254
5350
|
const rootFiles = config.manifest.monorepo?.rootFiles;
|
|
5255
|
-
const vars = buildVars(config.manifest);
|
|
5351
|
+
const vars = buildVars(config.manifest, toolchainVersion);
|
|
5256
5352
|
const packageJsonTemplate = resolveTemplate(
|
|
5257
5353
|
rootFiles?.packageJson?.template,
|
|
5258
5354
|
BUILTIN_PACKAGE_JSON_TEMPLATE
|
|
@@ -5264,7 +5360,7 @@ async function generateRootFiles(config, report) {
|
|
|
5264
5360
|
"package.json"
|
|
5265
5361
|
);
|
|
5266
5362
|
await writeRootFile(
|
|
5267
|
-
|
|
5363
|
+
path34__default.join(config.workspaceRoot, "package.json"),
|
|
5268
5364
|
packageJsonContent,
|
|
5269
5365
|
config,
|
|
5270
5366
|
report,
|
|
@@ -5281,7 +5377,7 @@ async function generateRootFiles(config, report) {
|
|
|
5281
5377
|
"tsconfig.base.json"
|
|
5282
5378
|
);
|
|
5283
5379
|
await writeRootFile(
|
|
5284
|
-
|
|
5380
|
+
path34__default.join(config.workspaceRoot, "tsconfig.base.json"),
|
|
5285
5381
|
tsconfigContent,
|
|
5286
5382
|
config,
|
|
5287
5383
|
report,
|
|
@@ -5298,7 +5394,7 @@ async function generateRootFiles(config, report) {
|
|
|
5298
5394
|
"turbo.json"
|
|
5299
5395
|
);
|
|
5300
5396
|
await writeRootFile(
|
|
5301
|
-
|
|
5397
|
+
path34__default.join(config.workspaceRoot, "turbo.json"),
|
|
5302
5398
|
turboContent,
|
|
5303
5399
|
config,
|
|
5304
5400
|
report,
|
|
@@ -5309,7 +5405,7 @@ async function generateRootFiles(config, report) {
|
|
|
5309
5405
|
BUILTIN_GITIGNORE_TEMPLATE
|
|
5310
5406
|
);
|
|
5311
5407
|
await writeRootFile(
|
|
5312
|
-
|
|
5408
|
+
path34__default.join(config.workspaceRoot, ".gitignore"),
|
|
5313
5409
|
interpolateAndWarn(gitignoreTemplate, vars, config, ".gitignore"),
|
|
5314
5410
|
config,
|
|
5315
5411
|
report,
|
|
@@ -5320,7 +5416,7 @@ async function generateRootFiles(config, report) {
|
|
|
5320
5416
|
BUILTIN_YARNRC_TEMPLATE
|
|
5321
5417
|
);
|
|
5322
5418
|
await writeRootFile(
|
|
5323
|
-
|
|
5419
|
+
path34__default.join(config.workspaceRoot, ".yarnrc.yml"),
|
|
5324
5420
|
interpolateAndWarn(yarnrcTemplate, vars, config, ".yarnrc.yml"),
|
|
5325
5421
|
config,
|
|
5326
5422
|
report,
|
|
@@ -5331,7 +5427,7 @@ async function generateRootFiles(config, report) {
|
|
|
5331
5427
|
BUILTIN_SETUP_MD_TEMPLATE
|
|
5332
5428
|
);
|
|
5333
5429
|
await writeRootFile(
|
|
5334
|
-
|
|
5430
|
+
path34__default.join(config.workspaceRoot, "SETUP.md"),
|
|
5335
5431
|
interpolateAndWarn(setupTemplate, vars, config, "SETUP.md"),
|
|
5336
5432
|
config,
|
|
5337
5433
|
report,
|
|
@@ -5342,6 +5438,8 @@ async function generateRootFiles(config, report) {
|
|
|
5342
5438
|
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
5343
5439
|
result.error = err3 instanceof Error ? err3 : new Error(`root-files generation failed: ${message}`);
|
|
5344
5440
|
result.summary = `root-files generation failed: ${message}`;
|
|
5441
|
+
config.logger.error(result.summary);
|
|
5442
|
+
if (report) report.record("error", "root-files", result.summary);
|
|
5345
5443
|
return result;
|
|
5346
5444
|
}
|
|
5347
5445
|
}
|
|
@@ -5557,20 +5655,13 @@ function interpolateWithLogging(label, template, vars, config) {
|
|
|
5557
5655
|
}
|
|
5558
5656
|
return output;
|
|
5559
5657
|
}
|
|
5560
|
-
function recordStatus(result, filePath, status) {
|
|
5561
|
-
if (status === "created") result.created.push(filePath);
|
|
5562
|
-
else if (status === "updated") result.updated.push(filePath);
|
|
5563
|
-
else if (status === "skipped" || status === "protected")
|
|
5564
|
-
result.skipped.push(filePath);
|
|
5565
|
-
if (status === "created" || status === "updated") result.totalOps += 1;
|
|
5566
|
-
}
|
|
5567
5658
|
async function writeManifestIfFreshExternal(config, result, report) {
|
|
5568
5659
|
if (config.mode !== "external") {
|
|
5569
5660
|
return;
|
|
5570
5661
|
}
|
|
5571
|
-
const archDir =
|
|
5572
|
-
const manifestPath =
|
|
5573
|
-
const relative =
|
|
5662
|
+
const archDir = path34__default.join(config.workspaceRoot, ".architecture");
|
|
5663
|
+
const manifestPath = path34__default.join(archDir, "manifest.yaml");
|
|
5664
|
+
const relative = path34__default.relative(config.workspaceRoot, manifestPath);
|
|
5574
5665
|
if (!isInScope(manifestPath, config)) {
|
|
5575
5666
|
config.logger.debug(`skipped (outside --only) ${relative}`);
|
|
5576
5667
|
result.skipped.push(manifestPath);
|
|
@@ -5578,7 +5669,7 @@ async function writeManifestIfFreshExternal(config, result, report) {
|
|
|
5578
5669
|
}
|
|
5579
5670
|
let exists = false;
|
|
5580
5671
|
try {
|
|
5581
|
-
await
|
|
5672
|
+
await fs27.access(manifestPath);
|
|
5582
5673
|
exists = true;
|
|
5583
5674
|
} catch {
|
|
5584
5675
|
exists = false;
|
|
@@ -5597,8 +5688,9 @@ async function writeManifestIfFreshExternal(config, result, report) {
|
|
|
5597
5688
|
return;
|
|
5598
5689
|
}
|
|
5599
5690
|
const content = yaml9.dump(config.manifest);
|
|
5600
|
-
|
|
5601
|
-
await
|
|
5691
|
+
config.journal?.recordWrite(manifestPath, null);
|
|
5692
|
+
await fs27.mkdir(archDir, { recursive: true });
|
|
5693
|
+
await fs27.writeFile(manifestPath, content, { encoding: "utf8" });
|
|
5602
5694
|
config.logger.info(`created ${relative}`);
|
|
5603
5695
|
if (report)
|
|
5604
5696
|
report.record(
|
|
@@ -5612,12 +5704,12 @@ async function writeManifestIfFreshExternal(config, result, report) {
|
|
|
5612
5704
|
async function generateArchitectureFiles(config, report) {
|
|
5613
5705
|
const result = createEmptyResult();
|
|
5614
5706
|
const manifest = config.manifest;
|
|
5615
|
-
const archRoot =
|
|
5707
|
+
const archRoot = path34__default.join(config.workspaceRoot, ".architecture");
|
|
5616
5708
|
const archInvariants = manifest.monorepo?.archInvariants;
|
|
5617
5709
|
const vars = buildInterpolationVars(manifest);
|
|
5618
5710
|
const workspaceTemplate = vars.workspaceTemplate ?? "modular-monolith";
|
|
5619
5711
|
await writeManifestIfFreshExternal(config, result, report);
|
|
5620
|
-
const layerRulesPath =
|
|
5712
|
+
const layerRulesPath = path34__default.join(archRoot, "invariants", "layer-rules.yaml");
|
|
5621
5713
|
const layerRulesTemplate = resolveTemplate2(
|
|
5622
5714
|
archInvariants?.layerRules,
|
|
5623
5715
|
builtInLayerRules(workspaceTemplate)
|
|
@@ -5635,8 +5727,8 @@ async function generateArchitectureFiles(config, report) {
|
|
|
5635
5727
|
report,
|
|
5636
5728
|
true
|
|
5637
5729
|
);
|
|
5638
|
-
|
|
5639
|
-
const linterConfigPath =
|
|
5730
|
+
recordWriteStatus(result, layerRulesPath, layerRulesStatus);
|
|
5731
|
+
const linterConfigPath = path34__default.join(
|
|
5640
5732
|
archRoot,
|
|
5641
5733
|
"invariants",
|
|
5642
5734
|
"linter-config.yaml"
|
|
@@ -5658,8 +5750,8 @@ async function generateArchitectureFiles(config, report) {
|
|
|
5658
5750
|
report,
|
|
5659
5751
|
true
|
|
5660
5752
|
);
|
|
5661
|
-
|
|
5662
|
-
const generatorConfigPath =
|
|
5753
|
+
recordWriteStatus(result, linterConfigPath, linterConfigStatus);
|
|
5754
|
+
const generatorConfigPath = path34__default.join(archRoot, "generator.config.yaml");
|
|
5663
5755
|
const generatorConfigTemplate = resolveTemplate2(
|
|
5664
5756
|
archInvariants?.generatorConfig,
|
|
5665
5757
|
GENERATOR_CONFIG_TEMPLATE
|
|
@@ -5677,7 +5769,7 @@ async function generateArchitectureFiles(config, report) {
|
|
|
5677
5769
|
report,
|
|
5678
5770
|
true
|
|
5679
5771
|
);
|
|
5680
|
-
|
|
5772
|
+
recordWriteStatus(result, generatorConfigPath, generatorConfigStatus);
|
|
5681
5773
|
return result;
|
|
5682
5774
|
}
|
|
5683
5775
|
|
|
@@ -5781,7 +5873,6 @@ var PLAIN_TS_PACKAGE_JSON_TEMPLATE = `{
|
|
|
5781
5873
|
"lint": "eslint src --ext .ts,.tsx",
|
|
5782
5874
|
"typecheck": "tsc --noEmit"
|
|
5783
5875
|
},
|
|
5784
|
-
"dependencies": {},
|
|
5785
5876
|
"devDependencies": {
|
|
5786
5877
|
"typescript": "^5.5.4",
|
|
5787
5878
|
"eslint": "^9.0.0",
|
|
@@ -5928,7 +6019,7 @@ ${content}`;
|
|
|
5928
6019
|
}
|
|
5929
6020
|
async function generateEslintConfig(moduleDir, moduleName, config, report, options = {}) {
|
|
5930
6021
|
const result = createEmptyResult();
|
|
5931
|
-
const filePath =
|
|
6022
|
+
const filePath = path34__default.join(moduleDir, "eslint.config.js");
|
|
5932
6023
|
try {
|
|
5933
6024
|
const { template, source } = resolveTemplate3(
|
|
5934
6025
|
config.manifest,
|
|
@@ -5961,11 +6052,7 @@ async function generateEslintConfig(moduleDir, moduleName, config, report, optio
|
|
|
5961
6052
|
report,
|
|
5962
6053
|
false
|
|
5963
6054
|
);
|
|
5964
|
-
|
|
5965
|
-
if (status === "updated") result.updated.push(filePath);
|
|
5966
|
-
if (status === "skipped" || status === "protected")
|
|
5967
|
-
result.skipped.push(filePath);
|
|
5968
|
-
result.totalOps += status === "created" || status === "updated" ? 1 : 0;
|
|
6055
|
+
recordWriteStatus(result, filePath, status);
|
|
5969
6056
|
return result;
|
|
5970
6057
|
} catch (err3) {
|
|
5971
6058
|
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
@@ -6000,21 +6087,12 @@ function interpolateWithLogging2(template, vars, context, config) {
|
|
|
6000
6087
|
}
|
|
6001
6088
|
return output;
|
|
6002
6089
|
}
|
|
6003
|
-
function recordStatus2(result, filePath, status) {
|
|
6004
|
-
if (status === "created") {
|
|
6005
|
-
result.created.push(filePath);
|
|
6006
|
-
result.totalOps += 1;
|
|
6007
|
-
} else if (status === "updated") {
|
|
6008
|
-
result.updated.push(filePath);
|
|
6009
|
-
result.totalOps += 1;
|
|
6010
|
-
} else {
|
|
6011
|
-
result.skipped.push(filePath);
|
|
6012
|
-
}
|
|
6013
|
-
}
|
|
6014
6090
|
function mergeResult(result, sub) {
|
|
6015
6091
|
result.created.push(...sub.created);
|
|
6016
6092
|
result.updated.push(...sub.updated);
|
|
6017
6093
|
result.skipped.push(...sub.skipped);
|
|
6094
|
+
result.deleted.push(...sub.deleted);
|
|
6095
|
+
result.unchanged.push(...sub.unchanged);
|
|
6018
6096
|
result.totalOps += sub.totalOps;
|
|
6019
6097
|
if (sub.error && !result.error) {
|
|
6020
6098
|
result.error = sub.error;
|
|
@@ -6028,9 +6106,9 @@ async function emitAppFile(appDir, relPath, template, vars, config, report, resu
|
|
|
6028
6106
|
`apps/${appName}/${relPath}`,
|
|
6029
6107
|
config
|
|
6030
6108
|
);
|
|
6031
|
-
const target =
|
|
6032
|
-
const relative =
|
|
6033
|
-
if (relative === "" || relative.startsWith("..") ||
|
|
6109
|
+
const target = path34__default.resolve(appDir, relPath);
|
|
6110
|
+
const relative = path34__default.relative(appDir, target);
|
|
6111
|
+
if (relative === "" || relative.startsWith("..") || path34__default.isAbsolute(relative)) {
|
|
6034
6112
|
config.logger.warn(
|
|
6035
6113
|
`[apps] skipping file with unsafe path (escapes apps/${appName}): ${relPath}`
|
|
6036
6114
|
);
|
|
@@ -6043,9 +6121,9 @@ async function emitAppFile(appDir, relPath, template, vars, config, report, resu
|
|
|
6043
6121
|
}
|
|
6044
6122
|
return "unsafe";
|
|
6045
6123
|
}
|
|
6046
|
-
if (isInScope(target, config)) {
|
|
6124
|
+
if (!config.dryRun && isInScope(target, config)) {
|
|
6047
6125
|
try {
|
|
6048
|
-
await
|
|
6126
|
+
await fs27.mkdir(path34__default.dirname(target), { recursive: true });
|
|
6049
6127
|
} catch (err3) {
|
|
6050
6128
|
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
6051
6129
|
config.logger.error(
|
|
@@ -6055,7 +6133,7 @@ async function emitAppFile(appDir, relPath, template, vars, config, report, resu
|
|
|
6055
6133
|
return "error";
|
|
6056
6134
|
}
|
|
6057
6135
|
}
|
|
6058
|
-
|
|
6136
|
+
recordWriteStatus(
|
|
6059
6137
|
result,
|
|
6060
6138
|
target,
|
|
6061
6139
|
await safeWriteFileAtomic(target, content, config, report)
|
|
@@ -6136,12 +6214,12 @@ async function generateApps(config, report) {
|
|
|
6136
6214
|
version: app.version ?? "",
|
|
6137
6215
|
depends_on: (app.depends_on ?? []).join(", ")
|
|
6138
6216
|
};
|
|
6139
|
-
const appDir =
|
|
6140
|
-
const srcDir =
|
|
6141
|
-
if (isInScope(appDir, config)) {
|
|
6217
|
+
const appDir = path34__default.join(config.workspaceRoot, "apps", app.name);
|
|
6218
|
+
const srcDir = path34__default.join(appDir, "src");
|
|
6219
|
+
if (!config.dryRun && isInScope(appDir, config)) {
|
|
6142
6220
|
try {
|
|
6143
|
-
await
|
|
6144
|
-
await
|
|
6221
|
+
await fs27.mkdir(appDir, { recursive: true });
|
|
6222
|
+
await fs27.mkdir(srcDir, { recursive: true });
|
|
6145
6223
|
} catch (err3) {
|
|
6146
6224
|
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
6147
6225
|
config.logger.error(
|
|
@@ -6159,14 +6237,14 @@ async function generateApps(config, report) {
|
|
|
6159
6237
|
`apps/${app.name}/package.json`,
|
|
6160
6238
|
config
|
|
6161
6239
|
);
|
|
6162
|
-
const pkgPath =
|
|
6240
|
+
const pkgPath = path34__default.join(appDir, "package.json");
|
|
6163
6241
|
const status = await safeWriteFileAtomic(
|
|
6164
6242
|
pkgPath,
|
|
6165
6243
|
pkgContent,
|
|
6166
6244
|
config,
|
|
6167
6245
|
report
|
|
6168
6246
|
);
|
|
6169
|
-
|
|
6247
|
+
recordWriteStatus(result, pkgPath, status);
|
|
6170
6248
|
} else {
|
|
6171
6249
|
config.logger.warn(
|
|
6172
6250
|
`[apps] framework "${framework}" has no package.json template — skipping package.json for "${app.name}"`
|
|
@@ -6175,14 +6253,14 @@ async function generateApps(config, report) {
|
|
|
6175
6253
|
const tsConfig = frameworkConfig.tsConfig;
|
|
6176
6254
|
if (tsConfig) {
|
|
6177
6255
|
const tsContent = JSON.stringify(tsConfig, null, 2) + "\n";
|
|
6178
|
-
const tsPath =
|
|
6256
|
+
const tsPath = path34__default.join(appDir, "tsconfig.json");
|
|
6179
6257
|
const status = await safeWriteFileAtomic(
|
|
6180
6258
|
tsPath,
|
|
6181
6259
|
tsContent,
|
|
6182
6260
|
config,
|
|
6183
6261
|
report
|
|
6184
6262
|
);
|
|
6185
|
-
|
|
6263
|
+
recordWriteStatus(result, tsPath, status);
|
|
6186
6264
|
} else {
|
|
6187
6265
|
config.logger.warn(
|
|
6188
6266
|
`[apps] framework "${framework}" has no tsConfig — skipping tsconfig.json for "${app.name}"`
|
|
@@ -6236,18 +6314,20 @@ async function generateApps(config, report) {
|
|
|
6236
6314
|
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
6237
6315
|
result.error = err3 instanceof Error ? err3 : new Error(`apps generation failed: ${message}`);
|
|
6238
6316
|
result.summary = `apps generation failed: ${message}`;
|
|
6317
|
+
config.logger.error(result.summary);
|
|
6318
|
+
if (report) report.record("error", "apps", result.summary);
|
|
6239
6319
|
return result;
|
|
6240
6320
|
}
|
|
6241
6321
|
}
|
|
6242
6322
|
function relativeImportSpecifier(fromFile, toFile) {
|
|
6243
|
-
let rel =
|
|
6323
|
+
let rel = path34__default.relative(path34__default.dirname(fromFile), toFile).split(path34__default.sep).join("/").replace(/\.tsx?$/, ".js");
|
|
6244
6324
|
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
6245
6325
|
return rel;
|
|
6246
6326
|
}
|
|
6247
6327
|
function rewriteRelativeSpecifier(specifier, fromFile, toFile) {
|
|
6248
6328
|
if (!specifier.startsWith(".")) return specifier;
|
|
6249
|
-
const absolute =
|
|
6250
|
-
let rel =
|
|
6329
|
+
const absolute = path34__default.resolve(path34__default.dirname(fromFile), specifier);
|
|
6330
|
+
let rel = path34__default.relative(path34__default.dirname(toFile), absolute).split(path34__default.sep).join("/");
|
|
6251
6331
|
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
6252
6332
|
return rel;
|
|
6253
6333
|
}
|
|
@@ -6883,13 +6963,13 @@ function resolveNaming(kind, contextNaming, manifestNaming) {
|
|
|
6883
6963
|
async function writeStubFile(filePath, content, config, report) {
|
|
6884
6964
|
if (!isInScope(filePath, config)) {
|
|
6885
6965
|
config.logger.debug(
|
|
6886
|
-
`skipped (outside --only) ${
|
|
6966
|
+
`skipped (outside --only) ${path34__default.relative(config.workspaceRoot, filePath)}`
|
|
6887
6967
|
);
|
|
6888
6968
|
return "skipped";
|
|
6889
6969
|
}
|
|
6890
6970
|
try {
|
|
6891
|
-
await
|
|
6892
|
-
const relative =
|
|
6971
|
+
await fs27.stat(filePath);
|
|
6972
|
+
const relative = path34__default.relative(config.workspaceRoot, filePath);
|
|
6893
6973
|
config.logger.debug(`stub preserved ${relative}`);
|
|
6894
6974
|
if (report) {
|
|
6895
6975
|
report.record(
|
|
@@ -6904,7 +6984,9 @@ async function writeStubFile(filePath, content, config, report) {
|
|
|
6904
6984
|
throw err3;
|
|
6905
6985
|
}
|
|
6906
6986
|
}
|
|
6907
|
-
|
|
6987
|
+
if (!config.dryRun) {
|
|
6988
|
+
await fs27.mkdir(path34__default.dirname(filePath), { recursive: true });
|
|
6989
|
+
}
|
|
6908
6990
|
return safeWriteFileAtomic(filePath, content, config, report, false);
|
|
6909
6991
|
}
|
|
6910
6992
|
async function tryAnalyzeRelatedPort(moduleDir, name, kind, context, relatedPortNamingTemplate) {
|
|
@@ -6923,7 +7005,7 @@ async function tryAnalyzeRelatedPort(moduleDir, name, kind, context, relatedPort
|
|
|
6923
7005
|
`${derivedPortName}.ts`
|
|
6924
7006
|
];
|
|
6925
7007
|
for (const filename of possibleFilenames) {
|
|
6926
|
-
const portFilePath =
|
|
7008
|
+
const portFilePath = path34__default.join(moduleDir, "src", portSubdir, filename);
|
|
6927
7009
|
const analysis = analyzePortFile(portFilePath);
|
|
6928
7010
|
if (analysis) {
|
|
6929
7011
|
return analysis;
|
|
@@ -6976,7 +7058,7 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
6976
7058
|
`stubs.naming.${kind}`,
|
|
6977
7059
|
config
|
|
6978
7060
|
);
|
|
6979
|
-
const filePath =
|
|
7061
|
+
const filePath = path34__default.join(moduleDir, "src", subdir, filename);
|
|
6980
7062
|
let content;
|
|
6981
7063
|
if (kind === "adapter" || kind === "useCase") {
|
|
6982
7064
|
const relatedPortNaming = resolveNaming(
|
|
@@ -7005,7 +7087,7 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
7005
7087
|
contextNaming,
|
|
7006
7088
|
manifestNaming
|
|
7007
7089
|
);
|
|
7008
|
-
const outPortDir =
|
|
7090
|
+
const outPortDir = path34__default.join(
|
|
7009
7091
|
moduleDir,
|
|
7010
7092
|
"src",
|
|
7011
7093
|
"application",
|
|
@@ -7020,7 +7102,7 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
7020
7102
|
"stubs.naming.outPort",
|
|
7021
7103
|
config
|
|
7022
7104
|
);
|
|
7023
|
-
const outPortPath =
|
|
7105
|
+
const outPortPath = path34__default.join(outPortDir, outFile);
|
|
7024
7106
|
const analyzed = analyzePortFile(outPortPath);
|
|
7025
7107
|
return {
|
|
7026
7108
|
interfaceName: analyzed?.interfaceName ?? `${base}Port`,
|
|
@@ -7054,24 +7136,13 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
7054
7136
|
);
|
|
7055
7137
|
}
|
|
7056
7138
|
const status = await writeStubFile(filePath, content, config, report);
|
|
7057
|
-
|
|
7058
|
-
if (status === "updated") result.updated.push(filePath);
|
|
7059
|
-
if (status === "skipped" || status === "protected")
|
|
7060
|
-
result.skipped.push(filePath);
|
|
7061
|
-
if (status === "created" || status === "updated") result.totalOps += 1;
|
|
7139
|
+
recordWriteStatus(result, filePath, status);
|
|
7062
7140
|
}
|
|
7063
7141
|
}
|
|
7064
7142
|
return result;
|
|
7065
7143
|
}
|
|
7066
7144
|
var OHS_NOTE = "\n *\n * Open Host Service (open-host): this is this context's published language for consuming contexts — keep it stable.";
|
|
7067
7145
|
var ACL_NOTE = "\n *\n * Anti-Corruption Layer (acl): translate the upstream contract into this context's own domain model; do not leak provider types inward.";
|
|
7068
|
-
function recordStatus3(result, filePath, status) {
|
|
7069
|
-
if (status === "created") result.created.push(filePath);
|
|
7070
|
-
else if (status === "updated") result.updated.push(filePath);
|
|
7071
|
-
else if (status === "skipped" || status === "protected")
|
|
7072
|
-
result.skipped.push(filePath);
|
|
7073
|
-
if (status === "created" || status === "updated") result.totalOps += 1;
|
|
7074
|
-
}
|
|
7075
7146
|
function addAll(map, key, values) {
|
|
7076
7147
|
const set = map.get(key) ?? /* @__PURE__ */ new Set();
|
|
7077
7148
|
values.forEach((v) => set.add(v));
|
|
@@ -7137,27 +7208,29 @@ ${methodLines}
|
|
|
7137
7208
|
`;
|
|
7138
7209
|
}
|
|
7139
7210
|
async function emitPortAndAdapter(result, config, report, scope, spec) {
|
|
7140
|
-
const moduleRoot =
|
|
7211
|
+
const moduleRoot = path34__default.join(
|
|
7141
7212
|
config.workspaceRoot,
|
|
7142
7213
|
"packages",
|
|
7143
7214
|
spec.contextName
|
|
7144
7215
|
);
|
|
7145
|
-
const portDir =
|
|
7216
|
+
const portDir = path34__default.join(
|
|
7146
7217
|
moduleRoot,
|
|
7147
7218
|
"src",
|
|
7148
7219
|
"application",
|
|
7149
7220
|
"ports",
|
|
7150
7221
|
spec.portKind
|
|
7151
7222
|
);
|
|
7152
|
-
const portPath =
|
|
7223
|
+
const portPath = path34__default.join(
|
|
7153
7224
|
portDir,
|
|
7154
7225
|
`${spec.portBase}.${spec.portKind}-port.ts`
|
|
7155
7226
|
);
|
|
7156
7227
|
if (!isInScope(portPath, config)) {
|
|
7157
7228
|
return;
|
|
7158
7229
|
}
|
|
7159
|
-
|
|
7160
|
-
|
|
7230
|
+
if (!config.dryRun) {
|
|
7231
|
+
await fs27.mkdir(portDir, { recursive: true });
|
|
7232
|
+
}
|
|
7233
|
+
recordWriteStatus(
|
|
7161
7234
|
result,
|
|
7162
7235
|
portPath,
|
|
7163
7236
|
await safeWriteFileAtomic(
|
|
@@ -7180,15 +7253,17 @@ async function emitPortAndAdapter(result, config, report, scope, spec) {
|
|
|
7180
7253
|
);
|
|
7181
7254
|
return;
|
|
7182
7255
|
}
|
|
7183
|
-
const adapterDir =
|
|
7184
|
-
const adapterPath =
|
|
7256
|
+
const adapterDir = path34__default.join(moduleRoot, "src", "infrastructure", "adapters");
|
|
7257
|
+
const adapterPath = path34__default.join(adapterDir, `${spec.portBase}.adapter.ts`);
|
|
7185
7258
|
if (!isInScope(adapterPath, config)) {
|
|
7186
7259
|
return;
|
|
7187
7260
|
}
|
|
7188
|
-
|
|
7261
|
+
if (!config.dryRun) {
|
|
7262
|
+
await fs27.mkdir(adapterDir, { recursive: true });
|
|
7263
|
+
}
|
|
7189
7264
|
const adapterClassName = `${toPascalCase2(spec.portBase)}Adapter`;
|
|
7190
7265
|
const portSpecifier = relativeImportSpecifier(adapterPath, portPath);
|
|
7191
|
-
|
|
7266
|
+
recordWriteStatus(
|
|
7192
7267
|
result,
|
|
7193
7268
|
adapterPath,
|
|
7194
7269
|
await safeWriteFileAtomic(
|
|
@@ -7211,15 +7286,17 @@ function operationImports(ops) {
|
|
|
7211
7286
|
return ops.flatMap((op) => [`${op}Request`, `${op}Response`]);
|
|
7212
7287
|
}
|
|
7213
7288
|
async function writeSharedContract(result, config, report, relSegments, content) {
|
|
7214
|
-
const contractPath =
|
|
7289
|
+
const contractPath = path34__default.join(
|
|
7215
7290
|
config.workspaceRoot,
|
|
7216
7291
|
"packages",
|
|
7217
7292
|
"shared",
|
|
7218
7293
|
"src",
|
|
7219
7294
|
...relSegments
|
|
7220
7295
|
);
|
|
7221
|
-
|
|
7222
|
-
|
|
7296
|
+
if (!config.dryRun) {
|
|
7297
|
+
await fs27.mkdir(path34__default.dirname(contractPath), { recursive: true });
|
|
7298
|
+
}
|
|
7299
|
+
recordWriteStatus(
|
|
7223
7300
|
result,
|
|
7224
7301
|
contractPath,
|
|
7225
7302
|
await safeWriteFileAtomic(contractPath, content, config, report)
|
|
@@ -7369,7 +7446,7 @@ async function generateSharedKernel(config, report) {
|
|
|
7369
7446
|
(bc) => bc.name?.toLowerCase() === "shared"
|
|
7370
7447
|
);
|
|
7371
7448
|
if (!hasShared) return result;
|
|
7372
|
-
const kernelPath =
|
|
7449
|
+
const kernelPath = path34__default.join(
|
|
7373
7450
|
config.workspaceRoot,
|
|
7374
7451
|
"packages",
|
|
7375
7452
|
"shared",
|
|
@@ -7382,13 +7459,15 @@ async function generateSharedKernel(config, report) {
|
|
|
7382
7459
|
return result;
|
|
7383
7460
|
}
|
|
7384
7461
|
try {
|
|
7385
|
-
await
|
|
7462
|
+
await fs27.stat(kernelPath);
|
|
7386
7463
|
result.skipped.push(kernelPath);
|
|
7387
7464
|
return result;
|
|
7388
7465
|
} catch (err3) {
|
|
7389
7466
|
if (err3.code !== "ENOENT") throw err3;
|
|
7390
7467
|
}
|
|
7391
|
-
|
|
7468
|
+
if (!config.dryRun) {
|
|
7469
|
+
await fs27.mkdir(path34__default.dirname(kernelPath), { recursive: true });
|
|
7470
|
+
}
|
|
7392
7471
|
const status = await safeWriteFileAtomic(
|
|
7393
7472
|
kernelPath,
|
|
7394
7473
|
RESULT_KERNEL,
|
|
@@ -7396,12 +7475,7 @@ async function generateSharedKernel(config, report) {
|
|
|
7396
7475
|
report,
|
|
7397
7476
|
false
|
|
7398
7477
|
);
|
|
7399
|
-
|
|
7400
|
-
result.created.push(kernelPath);
|
|
7401
|
-
result.totalOps += 1;
|
|
7402
|
-
} else {
|
|
7403
|
-
result.skipped.push(kernelPath);
|
|
7404
|
-
}
|
|
7478
|
+
recordWriteStatus(result, kernelPath, status);
|
|
7405
7479
|
return result;
|
|
7406
7480
|
}
|
|
7407
7481
|
var execAsync = promisify(exec);
|
|
@@ -7435,14 +7509,27 @@ function mergeResult2(dest, src) {
|
|
|
7435
7509
|
dest.created.push(...src.created);
|
|
7436
7510
|
dest.updated.push(...src.updated);
|
|
7437
7511
|
dest.skipped.push(...src.skipped);
|
|
7512
|
+
dest.deleted.push(...src.deleted);
|
|
7513
|
+
dest.unchanged.push(...src.unchanged);
|
|
7438
7514
|
dest.totalOps += src.totalOps;
|
|
7515
|
+
if (src.error && !dest.error) {
|
|
7516
|
+
dest.error = src.error;
|
|
7517
|
+
dest.summary = src.summary;
|
|
7518
|
+
}
|
|
7439
7519
|
}
|
|
7440
7520
|
function mergeBarrelPasses(firstPass, secondPass) {
|
|
7441
7521
|
const combined = createEmptyResult();
|
|
7442
7522
|
const secondPaths = /* @__PURE__ */ new Set([
|
|
7443
7523
|
...secondPass.created,
|
|
7444
7524
|
...secondPass.updated,
|
|
7445
|
-
...secondPass.skipped
|
|
7525
|
+
...secondPass.skipped,
|
|
7526
|
+
...secondPass.deleted
|
|
7527
|
+
]);
|
|
7528
|
+
const secondAll = /* @__PURE__ */ new Set([...secondPaths, ...secondPass.unchanged]);
|
|
7529
|
+
const firstMutations = /* @__PURE__ */ new Set([
|
|
7530
|
+
...firstPass.created,
|
|
7531
|
+
...firstPass.updated,
|
|
7532
|
+
...firstPass.deleted
|
|
7446
7533
|
]);
|
|
7447
7534
|
for (const p of firstPass.created) {
|
|
7448
7535
|
if (!secondPaths.has(p)) combined.created.push(p);
|
|
@@ -7451,12 +7538,29 @@ function mergeBarrelPasses(firstPass, secondPass) {
|
|
|
7451
7538
|
if (!secondPaths.has(p)) combined.updated.push(p);
|
|
7452
7539
|
}
|
|
7453
7540
|
for (const p of firstPass.skipped) {
|
|
7454
|
-
if (!
|
|
7541
|
+
if (!secondAll.has(p)) combined.skipped.push(p);
|
|
7542
|
+
}
|
|
7543
|
+
for (const p of firstPass.deleted) {
|
|
7544
|
+
if (!secondPaths.has(p)) combined.deleted.push(p);
|
|
7545
|
+
}
|
|
7546
|
+
for (const p of firstPass.unchanged) {
|
|
7547
|
+
if (!secondAll.has(p)) combined.unchanged.push(p);
|
|
7455
7548
|
}
|
|
7456
7549
|
combined.created.push(...secondPass.created);
|
|
7457
7550
|
combined.updated.push(...secondPass.updated);
|
|
7458
7551
|
combined.skipped.push(...secondPass.skipped);
|
|
7459
|
-
combined.
|
|
7552
|
+
combined.deleted.push(...secondPass.deleted);
|
|
7553
|
+
for (const p of secondPass.unchanged) {
|
|
7554
|
+
if (!firstMutations.has(p)) combined.unchanged.push(p);
|
|
7555
|
+
}
|
|
7556
|
+
combined.totalOps = combined.created.length + combined.updated.length + combined.deleted.length;
|
|
7557
|
+
if (firstPass.error) {
|
|
7558
|
+
combined.error = firstPass.error;
|
|
7559
|
+
combined.summary = firstPass.summary;
|
|
7560
|
+
} else if (secondPass.error) {
|
|
7561
|
+
combined.error = secondPass.error;
|
|
7562
|
+
combined.summary = secondPass.summary;
|
|
7563
|
+
}
|
|
7460
7564
|
return combined;
|
|
7461
7565
|
}
|
|
7462
7566
|
|
|
@@ -7465,14 +7569,15 @@ function caseInsensitiveEnum(schema, dir = "lower") {
|
|
|
7465
7569
|
return external_exports.preprocess((value) => typeof value === "string" ? dir === "lower" ? value.trim().toLowerCase() : value.trim().toUpperCase() : value, schema);
|
|
7466
7570
|
}
|
|
7467
7571
|
var BoundedContextTypeSchema = boundedContextTypeSchema;
|
|
7468
|
-
var
|
|
7572
|
+
var PLANE_NAMES = [
|
|
7469
7573
|
"projection",
|
|
7470
7574
|
"probabilistic",
|
|
7471
7575
|
"infrastructure",
|
|
7472
7576
|
"shared-kernel",
|
|
7473
7577
|
"core",
|
|
7474
7578
|
"supporting"
|
|
7475
|
-
]
|
|
7579
|
+
];
|
|
7580
|
+
var PlaneTypeSchema = caseInsensitiveEnum(external_exports.enum(PLANE_NAMES));
|
|
7476
7581
|
var StatusTypeSchema = caseInsensitiveEnum(external_exports.enum(["active", "frozen", "deprecated", "experimental"]));
|
|
7477
7582
|
var RelationshipPatternSchema = caseInsensitiveEnum(external_exports.enum(["U/D", "ACL", "SK", "P", "OHS"]), "upper");
|
|
7478
7583
|
var RelationshipRoleSchema = caseInsensitiveEnum(external_exports.enum(["upstream", "downstream", "peer"]));
|
|
@@ -7776,21 +7881,21 @@ external_exports.object({
|
|
|
7776
7881
|
turboConfig: external_exports.record(external_exports.unknown()).optional()
|
|
7777
7882
|
});
|
|
7778
7883
|
function assertPathWithinArchitecture(workspaceRoot, relativePath) {
|
|
7779
|
-
const resolved =
|
|
7780
|
-
const archRoot =
|
|
7884
|
+
const resolved = path34__default.resolve(workspaceRoot, ".architecture", relativePath);
|
|
7885
|
+
const archRoot = path34__default.resolve(workspaceRoot, ".architecture");
|
|
7781
7886
|
try {
|
|
7782
7887
|
const realResolved = realpathSync(resolved);
|
|
7783
7888
|
const realArchRoot = realpathSync(archRoot);
|
|
7784
|
-
const archRootWithSep = realArchRoot +
|
|
7889
|
+
const archRootWithSep = realArchRoot + path34__default.sep;
|
|
7785
7890
|
if (realResolved !== realArchRoot && !realResolved.startsWith(archRootWithSep)) {
|
|
7786
7891
|
throw new Error(`Path traversal detected: "${relativePath}" resolves outside .architecture/`);
|
|
7787
7892
|
}
|
|
7788
7893
|
} catch (err3) {
|
|
7789
7894
|
if (err3 instanceof Error && "code" in err3 && err3.code === "ENOENT") {
|
|
7790
7895
|
let checkPath = archRoot;
|
|
7791
|
-
const pathSegments =
|
|
7896
|
+
const pathSegments = path34__default.relative(archRoot, resolved).split(path34__default.sep);
|
|
7792
7897
|
for (const segment of pathSegments) {
|
|
7793
|
-
checkPath =
|
|
7898
|
+
checkPath = path34__default.join(checkPath, segment);
|
|
7794
7899
|
try {
|
|
7795
7900
|
const stat = lstatSync(checkPath);
|
|
7796
7901
|
if (stat.isSymbolicLink()) {
|
|
@@ -7806,7 +7911,7 @@ function assertPathWithinArchitecture(workspaceRoot, relativePath) {
|
|
|
7806
7911
|
throw statErr;
|
|
7807
7912
|
}
|
|
7808
7913
|
}
|
|
7809
|
-
const archRootWithSep = archRoot +
|
|
7914
|
+
const archRootWithSep = archRoot + path34__default.sep;
|
|
7810
7915
|
if (resolved !== archRoot && !resolved.startsWith(archRootWithSep)) {
|
|
7811
7916
|
throw new Error(`Path traversal detected: "${relativePath}" resolves outside .architecture/`);
|
|
7812
7917
|
}
|
|
@@ -7816,7 +7921,7 @@ function assertPathWithinArchitecture(workspaceRoot, relativePath) {
|
|
|
7816
7921
|
}
|
|
7817
7922
|
}
|
|
7818
7923
|
async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
7819
|
-
const content = await
|
|
7924
|
+
const content = await fs27.readFile(manifestPath, "utf-8");
|
|
7820
7925
|
const parsed = yaml9.load(content);
|
|
7821
7926
|
if (parsed == null) {
|
|
7822
7927
|
throw new Error("Manifest file is empty");
|
|
@@ -7849,10 +7954,10 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
7849
7954
|
continue;
|
|
7850
7955
|
}
|
|
7851
7956
|
assertPathWithinArchitecture(workspaceRoot, indexEntry.file);
|
|
7852
|
-
const contextFilePath =
|
|
7957
|
+
const contextFilePath = path34__default.join(workspaceRoot, ".architecture", indexEntry.file);
|
|
7853
7958
|
let contextContent;
|
|
7854
7959
|
try {
|
|
7855
|
-
contextContent = await
|
|
7960
|
+
contextContent = await fs27.readFile(contextFilePath, "utf-8");
|
|
7856
7961
|
} catch (err3) {
|
|
7857
7962
|
if (err3 instanceof Error && "code" in err3 && err3.code === "ENOENT") {
|
|
7858
7963
|
throw new Error(`Context file not found: ${contextFilePath}`);
|
|
@@ -7884,10 +7989,10 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
7884
7989
|
continue;
|
|
7885
7990
|
}
|
|
7886
7991
|
assertPathWithinArchitecture(workspaceRoot, appEntry.file);
|
|
7887
|
-
const appFilePath =
|
|
7992
|
+
const appFilePath = path34__default.join(workspaceRoot, ".architecture", appEntry.file);
|
|
7888
7993
|
let appContent;
|
|
7889
7994
|
try {
|
|
7890
|
-
appContent = await
|
|
7995
|
+
appContent = await fs27.readFile(appFilePath, "utf-8");
|
|
7891
7996
|
} catch (err3) {
|
|
7892
7997
|
if (err3 instanceof Error && "code" in err3 && err3.code === "ENOENT") {
|
|
7893
7998
|
throw new Error(`App file not found: ${appFilePath}`);
|
|
@@ -7906,23 +8011,23 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
7906
8011
|
|
|
7907
8012
|
// src/sync-engine-init.ts
|
|
7908
8013
|
var __filename$1 = fileURLToPath(import.meta.url);
|
|
7909
|
-
var __dirname$1 =
|
|
8014
|
+
var __dirname$1 = path34__default.dirname(__filename$1);
|
|
7910
8015
|
async function findWorkspaceRoot(options) {
|
|
7911
8016
|
if (options.targetRoot) {
|
|
7912
8017
|
return options.targetRoot;
|
|
7913
8018
|
}
|
|
7914
8019
|
let currentDir = __dirname$1;
|
|
7915
|
-
while (currentDir !==
|
|
8020
|
+
while (currentDir !== path34__default.parse(currentDir).root) {
|
|
7916
8021
|
try {
|
|
7917
|
-
const pkgPath =
|
|
7918
|
-
const pkgContent = await
|
|
8022
|
+
const pkgPath = path34__default.join(currentDir, "package.json");
|
|
8023
|
+
const pkgContent = await fs27.readFile(pkgPath, "utf-8");
|
|
7919
8024
|
const pkg = JSON.parse(pkgContent);
|
|
7920
8025
|
if (pkg.workspaces && Array.isArray(pkg.workspaces)) {
|
|
7921
8026
|
return currentDir;
|
|
7922
8027
|
}
|
|
7923
8028
|
} catch {
|
|
7924
8029
|
}
|
|
7925
|
-
currentDir =
|
|
8030
|
+
currentDir = path34__default.dirname(currentDir);
|
|
7926
8031
|
}
|
|
7927
8032
|
throw new Error(
|
|
7928
8033
|
'Could not locate monorepo root. No package.json with "workspaces" field found.'
|
|
@@ -7933,7 +8038,7 @@ async function loadManifest(workspaceRoot, flags, options) {
|
|
|
7933
8038
|
return options.manifest;
|
|
7934
8039
|
}
|
|
7935
8040
|
const { logger: logger2, dryRun } = flags;
|
|
7936
|
-
const manifestPath =
|
|
8041
|
+
const manifestPath = path34__default.join(workspaceRoot, ".architecture/manifest.yaml");
|
|
7937
8042
|
logger2.debug(`[debug] __dirname (ESM): ${__dirname$1}`);
|
|
7938
8043
|
logger2.debug(`[debug] resolved workspaceRoot: ${workspaceRoot}`);
|
|
7939
8044
|
logger2.debug(`[debug] resolved manifestPath: ${manifestPath}`);
|
|
@@ -7987,6 +8092,23 @@ function validateManifest(manifest, flags) {
|
|
|
7987
8092
|
var execAsync2 = promisify(exec);
|
|
7988
8093
|
var SyncEngine = class {
|
|
7989
8094
|
report = new MigrationReport();
|
|
8095
|
+
// PR-B1 (RCA #4): per-run mutation journal — pre-images of every file sync
|
|
8096
|
+
// touches, replayed in reverse on failure (see journal.ts). The lifetime is
|
|
8097
|
+
// one RUN, not one instance: run() re-news it on entry, so a reused engine
|
|
8098
|
+
// can never replay a previous run's pre-images into a later rollback.
|
|
8099
|
+
journal = new SyncJournal();
|
|
8100
|
+
// B-1 (PR-B2 review): generators that failed-soft this run. Four generators
|
|
8101
|
+
// catch their own exceptions into `result.error` by contract (Wave-2e: skip
|
|
8102
|
+
// the package, do not abort the run) — but a swallowed failure plans zero
|
|
8103
|
+
// ops, so a run that could not even read a target still summarized as
|
|
8104
|
+
// `Total ops : 0` and the CLI exited 0: errors masqueraded as convergence,
|
|
8105
|
+
// silently breaking `--check`'s "exit 0 ⇒ converged" promise. Failures are
|
|
8106
|
+
// recorded at each production site (NOT off the merged rows — mergeResult
|
|
8107
|
+
// keeps only the first error, so row-level counting would under-report
|
|
8108
|
+
// multi-module failures), printed as FAILED rows under the summary, and
|
|
8109
|
+
// surfaced as `SyncRunSummary.errors` for cli.ts to turn into exit ≠ 0.
|
|
8110
|
+
// Per-run lifetime, same reset discipline as the journal.
|
|
8111
|
+
failures = [];
|
|
7990
8112
|
partialConfig;
|
|
7991
8113
|
fullConfig = null;
|
|
7992
8114
|
manifest = {};
|
|
@@ -8008,6 +8130,19 @@ var SyncEngine = class {
|
|
|
8008
8130
|
}
|
|
8009
8131
|
return this.fullConfig;
|
|
8010
8132
|
}
|
|
8133
|
+
/**
|
|
8134
|
+
* Record a failed-soft generator result (B-1). Called at every site that
|
|
8135
|
+
* receives a GeneratorResult, including the ones that never set `error`
|
|
8136
|
+
* today — the check is one truthy test, and a future generator adopting the
|
|
8137
|
+
* catch-into-result contract is then surfaced without anyone remembering
|
|
8138
|
+
* this seam. `row` matches the summary-table label so the FAILED line and
|
|
8139
|
+
* the table read as one report.
|
|
8140
|
+
*/
|
|
8141
|
+
noteFailure(row, result) {
|
|
8142
|
+
if (result.error) {
|
|
8143
|
+
this.failures.push({ row, message: result.error.message });
|
|
8144
|
+
}
|
|
8145
|
+
}
|
|
8011
8146
|
async ensureDirectories() {
|
|
8012
8147
|
const config = this.getConfig();
|
|
8013
8148
|
const result = createEmptyResult();
|
|
@@ -8022,20 +8157,12 @@ var SyncEngine = class {
|
|
|
8022
8157
|
);
|
|
8023
8158
|
continue;
|
|
8024
8159
|
}
|
|
8025
|
-
const moduleDir =
|
|
8160
|
+
const moduleDir = path34__default.join(this.workspaceRoot, "packages", mod.name);
|
|
8026
8161
|
logger2.info(
|
|
8027
8162
|
`Ensuring directories for module: ${mod.name} at ${moduleDir}`
|
|
8028
8163
|
);
|
|
8029
|
-
const layerResult = await ensureLayerFolders(
|
|
8030
|
-
|
|
8031
|
-
layers,
|
|
8032
|
-
config,
|
|
8033
|
-
this.report
|
|
8034
|
-
);
|
|
8035
|
-
result.created.push(...layerResult.created);
|
|
8036
|
-
result.skipped.push(...layerResult.skipped);
|
|
8037
|
-
result.updated.push(...layerResult.updated);
|
|
8038
|
-
result.totalOps += layerResult.totalOps;
|
|
8164
|
+
const layerResult = await ensureLayerFolders(moduleDir, layers, config);
|
|
8165
|
+
mergeResult2(result, layerResult);
|
|
8039
8166
|
}
|
|
8040
8167
|
return result;
|
|
8041
8168
|
}
|
|
@@ -8050,7 +8177,7 @@ var SyncEngine = class {
|
|
|
8050
8177
|
const stubs = createEmptyResult();
|
|
8051
8178
|
for (const module of modules) {
|
|
8052
8179
|
const moduleName = module.name;
|
|
8053
|
-
const moduleDir =
|
|
8180
|
+
const moduleDir = path34__default.join(this.workspaceRoot, "packages", moduleName);
|
|
8054
8181
|
if (moduleName.includes("..") || moduleName.includes("/") || moduleName.startsWith(".")) {
|
|
8055
8182
|
logger2.warn(
|
|
8056
8183
|
`Skipping invalid module name (potential path traversal): ${moduleName}`
|
|
@@ -8087,6 +8214,11 @@ var SyncEngine = class {
|
|
|
8087
8214
|
config,
|
|
8088
8215
|
this.report
|
|
8089
8216
|
);
|
|
8217
|
+
this.noteFailure("Barrels", barrelResult);
|
|
8218
|
+
this.noteFailure("package.json", pkgResult);
|
|
8219
|
+
this.noteFailure("tsconfig.json", tsResult);
|
|
8220
|
+
this.noteFailure("ESLint", eslintResult);
|
|
8221
|
+
this.noteFailure("Stubs", stubResult);
|
|
8090
8222
|
if (this.partialConfig.mode === "self-regen") {
|
|
8091
8223
|
await reapLegacyFolders(moduleDir, config, this.report);
|
|
8092
8224
|
}
|
|
@@ -8112,6 +8244,8 @@ var SyncEngine = class {
|
|
|
8112
8244
|
const { logger: logger2, dryRun, allowDirty, mode } = this.partialConfig;
|
|
8113
8245
|
const start = Date.now();
|
|
8114
8246
|
let lockFile = null;
|
|
8247
|
+
this.journal = new SyncJournal();
|
|
8248
|
+
this.failures = [];
|
|
8115
8249
|
logger2.info(
|
|
8116
8250
|
dryRun ? "[DRY-RUN MODE] Starting sync..." : "Starting sync..."
|
|
8117
8251
|
);
|
|
@@ -8160,7 +8294,8 @@ var SyncEngine = class {
|
|
|
8160
8294
|
this.fullConfig = {
|
|
8161
8295
|
...this.partialConfig,
|
|
8162
8296
|
workspaceRoot: this.workspaceRoot,
|
|
8163
|
-
manifest: this.manifest
|
|
8297
|
+
manifest: this.manifest,
|
|
8298
|
+
journal: this.journal
|
|
8164
8299
|
};
|
|
8165
8300
|
if (!dryRun && mode === "self-regen") {
|
|
8166
8301
|
lockFile = new LockFile(this.workspaceRoot);
|
|
@@ -8186,23 +8321,29 @@ var SyncEngine = class {
|
|
|
8186
8321
|
this.fullConfig,
|
|
8187
8322
|
this.report
|
|
8188
8323
|
);
|
|
8324
|
+
this.noteFailure("RootFiles", rootFilesResult);
|
|
8189
8325
|
const archFilesResult = await generateArchitectureFiles(
|
|
8190
8326
|
this.fullConfig,
|
|
8191
8327
|
this.report
|
|
8192
8328
|
);
|
|
8329
|
+
this.noteFailure("ArchFiles", archFilesResult);
|
|
8193
8330
|
const layerResult = await this.ensureDirectories();
|
|
8331
|
+
this.noteFailure("Layers", layerResult);
|
|
8194
8332
|
const coreResults = await this.generateCoreArtifacts();
|
|
8195
8333
|
const { pkgs, tsconfigs, eslint, stubs } = coreResults;
|
|
8196
8334
|
const firstPassBarrels = coreResults.barrels;
|
|
8197
8335
|
const appsResult = await generateApps(this.fullConfig, this.report);
|
|
8336
|
+
this.noteFailure("Apps", appsResult);
|
|
8198
8337
|
const crossContextResult = await generateCrossContext(
|
|
8199
8338
|
this.fullConfig,
|
|
8200
8339
|
this.report
|
|
8201
8340
|
);
|
|
8341
|
+
this.noteFailure("CrossContext", crossContextResult);
|
|
8202
8342
|
const sharedKernelResult = await generateSharedKernel(
|
|
8203
8343
|
this.fullConfig,
|
|
8204
8344
|
this.report
|
|
8205
8345
|
);
|
|
8346
|
+
this.noteFailure("SharedKernel", sharedKernelResult);
|
|
8206
8347
|
const secondPassBarrels = createEmptyResult();
|
|
8207
8348
|
const modules = this.fullConfig.manifest.bounded_contexts ?? [];
|
|
8208
8349
|
for (const module of modules) {
|
|
@@ -8210,16 +8351,47 @@ var SyncEngine = class {
|
|
|
8210
8351
|
if (!moduleName || moduleName.includes("..") || moduleName.includes("/") || moduleName.startsWith(".")) {
|
|
8211
8352
|
continue;
|
|
8212
8353
|
}
|
|
8213
|
-
const moduleDir =
|
|
8354
|
+
const moduleDir = path34__default.join(this.workspaceRoot, "packages", moduleName);
|
|
8214
8355
|
const pass2 = await generateBarrels(
|
|
8215
8356
|
moduleDir,
|
|
8216
8357
|
this.fullConfig,
|
|
8217
8358
|
this.report
|
|
8218
8359
|
);
|
|
8360
|
+
this.noteFailure("Barrels", pass2);
|
|
8219
8361
|
mergeResult2(secondPassBarrels, pass2);
|
|
8220
8362
|
}
|
|
8221
8363
|
const barrels = mergeBarrelPasses(firstPassBarrels, secondPassBarrels);
|
|
8222
|
-
const
|
|
8364
|
+
const rows = [
|
|
8365
|
+
["RootFiles", rootFilesResult],
|
|
8366
|
+
["ArchFiles", archFilesResult],
|
|
8367
|
+
["Layers", layerResult],
|
|
8368
|
+
["Barrels", barrels],
|
|
8369
|
+
["CrossContext", crossContextResult],
|
|
8370
|
+
["SharedKernel", sharedKernelResult],
|
|
8371
|
+
["package.json", pkgs],
|
|
8372
|
+
["tsconfig.json", tsconfigs],
|
|
8373
|
+
["ESLint", eslint],
|
|
8374
|
+
["Stubs", stubs],
|
|
8375
|
+
["Apps", appsResult]
|
|
8376
|
+
];
|
|
8377
|
+
const runSummary = {
|
|
8378
|
+
created: 0,
|
|
8379
|
+
updated: 0,
|
|
8380
|
+
deleted: 0,
|
|
8381
|
+
unchanged: 0,
|
|
8382
|
+
skipped: 0,
|
|
8383
|
+
totalOps: 0,
|
|
8384
|
+
errors: this.failures.length,
|
|
8385
|
+
durationMs: 0
|
|
8386
|
+
};
|
|
8387
|
+
for (const [, r] of rows) {
|
|
8388
|
+
runSummary.created += r.created.length;
|
|
8389
|
+
runSummary.updated += r.updated.length;
|
|
8390
|
+
runSummary.deleted += r.deleted.length;
|
|
8391
|
+
runSummary.unchanged += r.unchanged.length;
|
|
8392
|
+
runSummary.skipped += r.skipped.length;
|
|
8393
|
+
runSummary.totalOps += r.totalOps;
|
|
8394
|
+
}
|
|
8223
8395
|
if (mode === "self-regen") {
|
|
8224
8396
|
await runArchLinter(this.fullConfig);
|
|
8225
8397
|
await this.report.writeReport(this.fullConfig);
|
|
@@ -8227,62 +8399,70 @@ var SyncEngine = class {
|
|
|
8227
8399
|
logger2.info("Skipping arch-linter and report (external mode)");
|
|
8228
8400
|
}
|
|
8229
8401
|
const duration = Date.now() - start;
|
|
8230
|
-
|
|
8402
|
+
runSummary.durationMs = duration;
|
|
8403
|
+
if (this.failures.length === 0) {
|
|
8404
|
+
logger2.info("\nSync completed successfully.");
|
|
8405
|
+
} else {
|
|
8406
|
+
logger2.error(
|
|
8407
|
+
`
|
|
8408
|
+
Sync completed with ${this.failures.length} generator failure(s) — see the FAILED row(s) below.`
|
|
8409
|
+
);
|
|
8410
|
+
}
|
|
8231
8411
|
logger2.info(
|
|
8232
8412
|
`Processed ${this.manifest.bounded_contexts?.length ?? 0} modules in ${duration}ms`
|
|
8233
8413
|
);
|
|
8234
8414
|
logger2.info(`
|
|
8235
8415
|
=== Generator Summary ===`);
|
|
8236
|
-
|
|
8237
|
-
|
|
8238
|
-
|
|
8239
|
-
|
|
8240
|
-
|
|
8241
|
-
)
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
);
|
|
8245
|
-
|
|
8246
|
-
`• Barrels : ${barrels.created.length} created, ${barrels.updated.length} updated, ${barrels.skipped.length} skipped`
|
|
8247
|
-
);
|
|
8248
|
-
logger2.info(
|
|
8249
|
-
`• CrossContext : ${crossContextResult.created.length} created, ${crossContextResult.updated.length} updated, ${crossContextResult.skipped.length} skipped`
|
|
8250
|
-
);
|
|
8251
|
-
logger2.info(
|
|
8252
|
-
`• SharedKernel : ${sharedKernelResult.created.length} created, ${sharedKernelResult.updated.length} updated, ${sharedKernelResult.skipped.length} skipped`
|
|
8253
|
-
);
|
|
8254
|
-
logger2.info(
|
|
8255
|
-
`• package.json : ${pkgs.created.length} created, ${pkgs.updated.length} updated, ${pkgs.skipped.length} skipped`
|
|
8256
|
-
);
|
|
8257
|
-
logger2.info(
|
|
8258
|
-
`• tsconfig.json : ${tsconfigs.created.length} created, ${tsconfigs.updated.length} updated, ${tsconfigs.skipped.length} skipped`
|
|
8259
|
-
);
|
|
8260
|
-
logger2.info(
|
|
8261
|
-
`• ESLint : ${eslint.created.length} created, ${eslint.updated.length} updated, ${eslint.skipped.length} skipped`
|
|
8262
|
-
);
|
|
8263
|
-
logger2.info(
|
|
8264
|
-
`• Stubs : ${stubs.created.length} created, ${stubs.updated.length} updated, ${stubs.skipped.length} skipped`
|
|
8265
|
-
);
|
|
8266
|
-
logger2.info(
|
|
8267
|
-
`• Apps : ${appsResult.created.length} created, ${appsResult.updated.length} updated, ${appsResult.skipped.length} skipped`
|
|
8268
|
-
);
|
|
8269
|
-
logger2.info(`• Total ops : ${totalOps}`);
|
|
8416
|
+
for (const [label, r] of rows) {
|
|
8417
|
+
logger2.info(
|
|
8418
|
+
`• ${label} : ${r.created.length} created, ${r.updated.length} updated, ${r.deleted.length} deleted, ${r.unchanged.length} unchanged, ${r.skipped.length} skipped`
|
|
8419
|
+
);
|
|
8420
|
+
}
|
|
8421
|
+
for (const f of this.failures) {
|
|
8422
|
+
logger2.error(`• ${f.row} : FAILED — ${f.message}`);
|
|
8423
|
+
}
|
|
8424
|
+
logger2.info(`• Total ops : ${runSummary.totalOps}`);
|
|
8425
|
+
return runSummary;
|
|
8270
8426
|
} catch (err3) {
|
|
8271
8427
|
const message = err3 instanceof Error ? err3.message : "Unknown sync error";
|
|
8272
8428
|
logger2.error(`Sync failed: ${message}`);
|
|
8273
8429
|
if (!dryRun) {
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
} catch (rollbackErr) {
|
|
8430
|
+
if (this.journal.size === 0) {
|
|
8431
|
+
logger2.info(
|
|
8432
|
+
"No files were touched before the failure — nothing to roll back."
|
|
8433
|
+
);
|
|
8434
|
+
} else if (allowDirty) {
|
|
8280
8435
|
logger2.warn(
|
|
8281
|
-
`
|
|
8436
|
+
`Sync failed after touching ${this.journal.size} path(s) — NO rollback under --allow-dirty; the tree is left as-is:`
|
|
8437
|
+
);
|
|
8438
|
+
for (const line of this.journal.describeEntries(this.workspaceRoot)) {
|
|
8439
|
+
logger2.warn(` ${line}`);
|
|
8440
|
+
}
|
|
8441
|
+
} else {
|
|
8442
|
+
logger2.info(
|
|
8443
|
+
`Rolling back ${this.journal.size} journaled path(s) (inverse-ops; never git reset/clean)...`
|
|
8282
8444
|
);
|
|
8445
|
+
const outcome = await this.journal.rollback(
|
|
8446
|
+
logger2,
|
|
8447
|
+
this.workspaceRoot
|
|
8448
|
+
);
|
|
8449
|
+
if (outcome.failures.length === 0) {
|
|
8450
|
+
logger2.info(
|
|
8451
|
+
`Rollback completed: ${outcome.restored}/${outcome.attempted} path(s) restored.`
|
|
8452
|
+
);
|
|
8453
|
+
} else {
|
|
8454
|
+
for (const f of outcome.failures) {
|
|
8455
|
+
logger2.error(
|
|
8456
|
+
`Rollback failed for ${path34__default.relative(this.workspaceRoot, f.path)}: intended to ${f.intended} — ${f.error}`
|
|
8457
|
+
);
|
|
8458
|
+
}
|
|
8459
|
+
logger2.error(
|
|
8460
|
+
`Rollback incomplete: ${outcome.failures.length} of ${outcome.attempted} path(s) NOT restored — inspect the paths above.`
|
|
8461
|
+
);
|
|
8462
|
+
}
|
|
8283
8463
|
}
|
|
8284
|
-
process.exit(1);
|
|
8285
8464
|
}
|
|
8465
|
+
throw err3;
|
|
8286
8466
|
} finally {
|
|
8287
8467
|
if (lockFile) {
|
|
8288
8468
|
try {
|
|
@@ -8309,7 +8489,7 @@ function err2(error) {
|
|
|
8309
8489
|
var execAsync3 = promisify(exec);
|
|
8310
8490
|
async function loadManifest2(workspaceRoot) {
|
|
8311
8491
|
try {
|
|
8312
|
-
const manifestPath =
|
|
8492
|
+
const manifestPath = path34__default.join(
|
|
8313
8493
|
workspaceRoot,
|
|
8314
8494
|
".architecture/manifest.yaml"
|
|
8315
8495
|
);
|
|
@@ -8497,27 +8677,27 @@ var YamlSaveError = class extends Error {
|
|
|
8497
8677
|
filePath;
|
|
8498
8678
|
};
|
|
8499
8679
|
var YamlService = class {
|
|
8500
|
-
async loadManifest(
|
|
8680
|
+
async loadManifest(path38) {
|
|
8501
8681
|
try {
|
|
8502
|
-
const content = await readFile(
|
|
8682
|
+
const content = await readFile(path38, "utf-8");
|
|
8503
8683
|
const manifest = yaml9.load(content);
|
|
8504
8684
|
return ok2(manifest);
|
|
8505
8685
|
} catch (e) {
|
|
8506
8686
|
const error = e;
|
|
8507
8687
|
if (error.code === "ENOENT") {
|
|
8508
|
-
return err2(new YamlLoadError(`File not found: ${
|
|
8688
|
+
return err2(new YamlLoadError(`File not found: ${path38}`, path38));
|
|
8509
8689
|
}
|
|
8510
|
-
return err2(new YamlLoadError(error.message,
|
|
8690
|
+
return err2(new YamlLoadError(error.message, path38));
|
|
8511
8691
|
}
|
|
8512
8692
|
}
|
|
8513
|
-
saveManifest(manifest,
|
|
8514
|
-
const dir = dirname(
|
|
8515
|
-
const tempPath = `${
|
|
8693
|
+
saveManifest(manifest, path38) {
|
|
8694
|
+
const dir = dirname(path38);
|
|
8695
|
+
const tempPath = `${path38}.tmp`;
|
|
8516
8696
|
try {
|
|
8517
8697
|
mkdirSync(dir, { recursive: true });
|
|
8518
8698
|
const content = yaml9.dump(manifest, { indent: 2 });
|
|
8519
8699
|
writeFileSync(tempPath, content, "utf-8");
|
|
8520
|
-
renameSync(tempPath,
|
|
8700
|
+
renameSync(tempPath, path38);
|
|
8521
8701
|
return ok2(void 0);
|
|
8522
8702
|
} catch (e) {
|
|
8523
8703
|
const error = e;
|
|
@@ -8525,7 +8705,7 @@ var YamlService = class {
|
|
|
8525
8705
|
if (existsSync(tempPath)) unlinkSync(tempPath);
|
|
8526
8706
|
} catch {
|
|
8527
8707
|
}
|
|
8528
|
-
return err2(new YamlSaveError(error.message,
|
|
8708
|
+
return err2(new YamlSaveError(error.message, path38));
|
|
8529
8709
|
}
|
|
8530
8710
|
}
|
|
8531
8711
|
parse(content) {
|
|
@@ -8734,8 +8914,8 @@ function resolveTemplatesDir() {
|
|
|
8734
8914
|
if (process.env.HEXAGEN_TEMPLATES_DIR) {
|
|
8735
8915
|
return process.env.HEXAGEN_TEMPLATES_DIR;
|
|
8736
8916
|
}
|
|
8737
|
-
const cliDir =
|
|
8738
|
-
return
|
|
8917
|
+
const cliDir = path34__default.dirname(fileURLToPath(import.meta.url));
|
|
8918
|
+
return path34__default.resolve(cliDir, "templates");
|
|
8739
8919
|
}
|
|
8740
8920
|
|
|
8741
8921
|
// src/commands/arch/port.ts
|
|
@@ -9363,8 +9543,8 @@ var removeCommander = new Command("remove").description("Remove a port or bounde
|
|
|
9363
9543
|
function getManifestPath2(cwd) {
|
|
9364
9544
|
return join(cwd, ".architecture", "manifest.yaml");
|
|
9365
9545
|
}
|
|
9366
|
-
async function loadManifestFromPath(
|
|
9367
|
-
const result = await yamlService.loadManifest(
|
|
9546
|
+
async function loadManifestFromPath(path38) {
|
|
9547
|
+
const result = await yamlService.loadManifest(path38);
|
|
9368
9548
|
if (!result.success) {
|
|
9369
9549
|
return err2(result.error);
|
|
9370
9550
|
}
|
|
@@ -9782,7 +9962,7 @@ function isInstalled(config, templateId) {
|
|
|
9782
9962
|
return templateId in config.templates;
|
|
9783
9963
|
}
|
|
9784
9964
|
function conflictFilePath(filePath) {
|
|
9785
|
-
const ext =
|
|
9965
|
+
const ext = path34__default.extname(filePath);
|
|
9786
9966
|
return ext ? filePath.slice(0, -ext.length) + ".hexagen-update" + ext : filePath + ".hexagen-update";
|
|
9787
9967
|
}
|
|
9788
9968
|
|
|
@@ -9845,19 +10025,19 @@ function resolveDependencies(requested, registry) {
|
|
|
9845
10025
|
}
|
|
9846
10026
|
const sorted = [];
|
|
9847
10027
|
const state = /* @__PURE__ */ new Map();
|
|
9848
|
-
function visit(id,
|
|
10028
|
+
function visit(id, path38) {
|
|
9849
10029
|
const s = state.get(id);
|
|
9850
10030
|
if (s === "done")
|
|
9851
10031
|
return;
|
|
9852
10032
|
if (s === "visiting") {
|
|
9853
|
-
const cycleStart =
|
|
9854
|
-
throw new CyclicDependencyError([...
|
|
10033
|
+
const cycleStart = path38.indexOf(id);
|
|
10034
|
+
throw new CyclicDependencyError([...path38.slice(cycleStart), id]);
|
|
9855
10035
|
}
|
|
9856
10036
|
state.set(id, "visiting");
|
|
9857
10037
|
const manifest = registry.get(id);
|
|
9858
10038
|
for (const dep of manifest.requires) {
|
|
9859
10039
|
if (needed.has(dep))
|
|
9860
|
-
visit(dep, [...
|
|
10040
|
+
visit(dep, [...path38, id]);
|
|
9861
10041
|
}
|
|
9862
10042
|
state.set(id, "done");
|
|
9863
10043
|
sorted.push(id);
|
|
@@ -9985,9 +10165,9 @@ var ValidateTemplatesUseCase = class {
|
|
|
9985
10165
|
if (!isOutputEnabled(output, answers))
|
|
9986
10166
|
continue;
|
|
9987
10167
|
const rel = outputPath(output);
|
|
9988
|
-
const abs =
|
|
10168
|
+
const abs = path34__default.join(projectRoot, rel);
|
|
9989
10169
|
try {
|
|
9990
|
-
await
|
|
10170
|
+
await fs27.access(abs);
|
|
9991
10171
|
} catch {
|
|
9992
10172
|
missingFiles.push(rel);
|
|
9993
10173
|
}
|
|
@@ -10002,10 +10182,10 @@ var ValidateTemplatesUseCase = class {
|
|
|
10002
10182
|
for (const output of manifest.outputs) {
|
|
10003
10183
|
if (!isOutputEnabled(output, answers))
|
|
10004
10184
|
continue;
|
|
10005
|
-
const absConflict = conflictFilePath(
|
|
10185
|
+
const absConflict = conflictFilePath(path34__default.join(projectRoot, outputPath(output)));
|
|
10006
10186
|
try {
|
|
10007
|
-
await
|
|
10008
|
-
conflictFiles.push(
|
|
10187
|
+
await fs27.access(absConflict);
|
|
10188
|
+
conflictFiles.push(path34__default.relative(projectRoot, absConflict));
|
|
10009
10189
|
} catch {
|
|
10010
10190
|
}
|
|
10011
10191
|
}
|
|
@@ -10024,25 +10204,25 @@ var ValidateTemplatesUseCase = class {
|
|
|
10024
10204
|
return { results, totalWarnings, totalErrors };
|
|
10025
10205
|
}
|
|
10026
10206
|
};
|
|
10027
|
-
var PACKAGE_ROOT =
|
|
10207
|
+
var PACKAGE_ROOT = path34__default.resolve(path34__default.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
10028
10208
|
var FileSystemTemplateRegistry = class {
|
|
10029
10209
|
templatesDir;
|
|
10030
10210
|
cache = null;
|
|
10031
10211
|
constructor(templatesDir) {
|
|
10032
|
-
this.templatesDir = templatesDir ??
|
|
10212
|
+
this.templatesDir = templatesDir ?? path34__default.join(PACKAGE_ROOT, "templates");
|
|
10033
10213
|
}
|
|
10034
10214
|
async loadAll() {
|
|
10035
10215
|
if (this.cache)
|
|
10036
10216
|
return this.cache;
|
|
10037
10217
|
let entries;
|
|
10038
10218
|
try {
|
|
10039
|
-
entries = await
|
|
10219
|
+
entries = await fs27.readdir(this.templatesDir);
|
|
10040
10220
|
} catch {
|
|
10041
10221
|
return [];
|
|
10042
10222
|
}
|
|
10043
10223
|
const manifests = [];
|
|
10044
10224
|
for (const entry of entries) {
|
|
10045
|
-
const manifestPath =
|
|
10225
|
+
const manifestPath = path34__default.join(this.templatesDir, entry, "manifest.json");
|
|
10046
10226
|
const manifest = await this.readManifest(manifestPath);
|
|
10047
10227
|
if (manifest)
|
|
10048
10228
|
manifests.push(manifest);
|
|
@@ -10051,13 +10231,13 @@ var FileSystemTemplateRegistry = class {
|
|
|
10051
10231
|
return manifests;
|
|
10052
10232
|
}
|
|
10053
10233
|
async loadOne(id) {
|
|
10054
|
-
const manifestPath =
|
|
10234
|
+
const manifestPath = path34__default.join(this.templatesDir, id, "manifest.json");
|
|
10055
10235
|
return this.readManifest(manifestPath);
|
|
10056
10236
|
}
|
|
10057
10237
|
async readManifest(manifestPath) {
|
|
10058
10238
|
let raw;
|
|
10059
10239
|
try {
|
|
10060
|
-
raw = await
|
|
10240
|
+
raw = await fs27.readFile(manifestPath, "utf-8");
|
|
10061
10241
|
} catch {
|
|
10062
10242
|
return null;
|
|
10063
10243
|
}
|
|
@@ -10193,31 +10373,31 @@ ${prompt} (comma-separated numbers)`);
|
|
|
10193
10373
|
}
|
|
10194
10374
|
}
|
|
10195
10375
|
};
|
|
10196
|
-
var PACKAGE_ROOT2 =
|
|
10376
|
+
var PACKAGE_ROOT2 = path34__default.resolve(path34__default.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
10197
10377
|
var FileSystemFileEmitter = class {
|
|
10198
10378
|
templatesDir;
|
|
10199
10379
|
constructor(templatesDir) {
|
|
10200
|
-
this.templatesDir = templatesDir ??
|
|
10380
|
+
this.templatesDir = templatesDir ?? path34__default.join(PACKAGE_ROOT2, "templates");
|
|
10201
10381
|
}
|
|
10202
10382
|
async emit(manifest, answers, projectRoot, config) {
|
|
10203
10383
|
const warnings = [];
|
|
10204
10384
|
const generatedFiles = [];
|
|
10205
|
-
const templateFilesDir =
|
|
10206
|
-
const resolvedRoot =
|
|
10385
|
+
const templateFilesDir = path34__default.join(this.templatesDir, manifest.id, "files");
|
|
10386
|
+
const resolvedRoot = path34__default.resolve(projectRoot);
|
|
10207
10387
|
for (const out of manifest.outputs) {
|
|
10208
10388
|
if (!isOutputEnabled(out, answers))
|
|
10209
10389
|
continue;
|
|
10210
10390
|
const outputRelPath = outputPath(out);
|
|
10211
|
-
const destFile =
|
|
10212
|
-
if (!destFile.startsWith(resolvedRoot +
|
|
10391
|
+
const destFile = path34__default.resolve(projectRoot, outputRelPath);
|
|
10392
|
+
if (!destFile.startsWith(resolvedRoot + path34__default.sep) && destFile !== resolvedRoot) {
|
|
10213
10393
|
throw new Error(`Output path '${outputRelPath}' escapes the project root`);
|
|
10214
10394
|
}
|
|
10215
|
-
const sourceFile =
|
|
10395
|
+
const sourceFile = path34__default.join(templateFilesDir, outputRelPath);
|
|
10216
10396
|
let templateContent;
|
|
10217
10397
|
let sourceMode = 420;
|
|
10218
10398
|
try {
|
|
10219
|
-
const raw = await
|
|
10220
|
-
sourceMode = (await
|
|
10399
|
+
const raw = await fs27.readFile(sourceFile, "utf-8");
|
|
10400
|
+
sourceMode = (await fs27.stat(sourceFile)).mode & 511;
|
|
10221
10401
|
const { output, warnings: interpWarnings } = interpolate(raw, answers);
|
|
10222
10402
|
templateContent = output;
|
|
10223
10403
|
for (const key of interpWarnings) {
|
|
@@ -10232,7 +10412,7 @@ var FileSystemFileEmitter = class {
|
|
|
10232
10412
|
const templateHash = sha256(templateContent);
|
|
10233
10413
|
let existingContent = null;
|
|
10234
10414
|
try {
|
|
10235
|
-
existingContent = await
|
|
10415
|
+
existingContent = await fs27.readFile(destFile, "utf-8");
|
|
10236
10416
|
} catch {
|
|
10237
10417
|
}
|
|
10238
10418
|
if (existingContent !== null) {
|
|
@@ -10242,7 +10422,7 @@ var FileSystemFileEmitter = class {
|
|
|
10242
10422
|
if (!isAlreadyIdentical && !wasGeneratedByHexagen) {
|
|
10243
10423
|
const conflictDest = conflictFilePath(destFile);
|
|
10244
10424
|
await atomicWrite(conflictDest, templateContent, sourceMode);
|
|
10245
|
-
const rel =
|
|
10425
|
+
const rel = path34__default.relative(projectRoot, conflictDest);
|
|
10246
10426
|
warnings.push(`⚠️ Conflict: ${outputRelPath} has local changes.
|
|
10247
10427
|
New version written to ${rel}
|
|
10248
10428
|
Review and merge manually, then delete the conflict file.`);
|
|
@@ -10256,18 +10436,18 @@ var FileSystemFileEmitter = class {
|
|
|
10256
10436
|
}
|
|
10257
10437
|
};
|
|
10258
10438
|
async function atomicWrite(filePath, content, mode) {
|
|
10259
|
-
await
|
|
10439
|
+
await fs27.mkdir(path34__default.dirname(filePath), { recursive: true });
|
|
10260
10440
|
const tmp = `${filePath}.tmp.${Date.now()}`;
|
|
10261
10441
|
try {
|
|
10262
|
-
await
|
|
10442
|
+
await fs27.writeFile(tmp, content, "utf-8");
|
|
10263
10443
|
if (mode !== void 0 && (mode & 73) !== 0) {
|
|
10264
|
-
const created = (await
|
|
10444
|
+
const created = (await fs27.stat(tmp)).mode & 511;
|
|
10265
10445
|
const execBits = mode & 73 & ~process.umask();
|
|
10266
|
-
await
|
|
10446
|
+
await fs27.chmod(tmp, created | execBits);
|
|
10267
10447
|
}
|
|
10268
|
-
await
|
|
10448
|
+
await fs27.rename(tmp, filePath);
|
|
10269
10449
|
} catch (err3) {
|
|
10270
|
-
await
|
|
10450
|
+
await fs27.rm(tmp, { force: true }).catch(() => {
|
|
10271
10451
|
});
|
|
10272
10452
|
throw err3;
|
|
10273
10453
|
}
|
|
@@ -10277,9 +10457,9 @@ function sha256(content) {
|
|
|
10277
10457
|
}
|
|
10278
10458
|
var FileSystemTemplateConfigStore = class {
|
|
10279
10459
|
async load(projectRoot) {
|
|
10280
|
-
const configPath =
|
|
10460
|
+
const configPath = path34__default.join(projectRoot, TEMPLATE_CONFIG_FILE);
|
|
10281
10461
|
try {
|
|
10282
|
-
const raw = await
|
|
10462
|
+
const raw = await fs27.readFile(configPath, "utf-8");
|
|
10283
10463
|
return JSON.parse(raw);
|
|
10284
10464
|
} catch (err3) {
|
|
10285
10465
|
if (err3.code === "ENOENT")
|
|
@@ -10288,10 +10468,10 @@ var FileSystemTemplateConfigStore = class {
|
|
|
10288
10468
|
}
|
|
10289
10469
|
}
|
|
10290
10470
|
async save(projectRoot, config) {
|
|
10291
|
-
const configPath =
|
|
10471
|
+
const configPath = path34__default.join(projectRoot, TEMPLATE_CONFIG_FILE);
|
|
10292
10472
|
const tmp = `${configPath}.tmp.${Date.now()}`;
|
|
10293
|
-
await
|
|
10294
|
-
await
|
|
10473
|
+
await fs27.writeFile(tmp, JSON.stringify(config, null, 2), "utf-8");
|
|
10474
|
+
await fs27.rename(tmp, configPath);
|
|
10295
10475
|
}
|
|
10296
10476
|
};
|
|
10297
10477
|
|
|
@@ -10526,8 +10706,8 @@ Installed templates: ${installed}
|
|
|
10526
10706
|
function getManifestPath3(cwd) {
|
|
10527
10707
|
return join(cwd, ".architecture", "manifest.yaml");
|
|
10528
10708
|
}
|
|
10529
|
-
async function loadManifest4(
|
|
10530
|
-
const result = await yamlService.loadManifest(
|
|
10709
|
+
async function loadManifest4(path38) {
|
|
10710
|
+
const result = await yamlService.loadManifest(path38);
|
|
10531
10711
|
if (!result.success) {
|
|
10532
10712
|
throw result.error;
|
|
10533
10713
|
}
|
|
@@ -10725,35 +10905,35 @@ var FileSystemWorkspaceAdapter = class {
|
|
|
10725
10905
|
}
|
|
10726
10906
|
workspaceRoot;
|
|
10727
10907
|
listPackages() {
|
|
10728
|
-
const packagesDir =
|
|
10729
|
-
if (!
|
|
10908
|
+
const packagesDir = path34.join(this.workspaceRoot, "packages");
|
|
10909
|
+
if (!fs24.existsSync(packagesDir)) {
|
|
10730
10910
|
return [];
|
|
10731
10911
|
}
|
|
10732
|
-
return
|
|
10912
|
+
return fs24.readdirSync(packagesDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
|
|
10733
10913
|
}
|
|
10734
10914
|
listApps() {
|
|
10735
|
-
const appsDir =
|
|
10736
|
-
if (!
|
|
10915
|
+
const appsDir = path34.join(this.workspaceRoot, "apps");
|
|
10916
|
+
if (!fs24.existsSync(appsDir)) {
|
|
10737
10917
|
return [];
|
|
10738
10918
|
}
|
|
10739
|
-
return
|
|
10919
|
+
return fs24.readdirSync(appsDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
|
|
10740
10920
|
}
|
|
10741
10921
|
getSourceFiles(dir) {
|
|
10742
|
-
if (!
|
|
10922
|
+
if (!fs24.existsSync(dir)) {
|
|
10743
10923
|
return [];
|
|
10744
10924
|
}
|
|
10745
|
-
const entries =
|
|
10925
|
+
const entries = fs24.readdirSync(dir, { withFileTypes: true });
|
|
10746
10926
|
return entries.map((entry) => ({
|
|
10747
|
-
path:
|
|
10927
|
+
path: path34.join(dir, entry.name),
|
|
10748
10928
|
isDirectory: entry.isDirectory()
|
|
10749
10929
|
}));
|
|
10750
10930
|
}
|
|
10751
10931
|
fileExists(filePath) {
|
|
10752
|
-
return
|
|
10932
|
+
return fs24.existsSync(filePath);
|
|
10753
10933
|
}
|
|
10754
10934
|
readFile(filePath) {
|
|
10755
10935
|
try {
|
|
10756
|
-
return
|
|
10936
|
+
return fs24.readFileSync(filePath, "utf-8");
|
|
10757
10937
|
} catch {
|
|
10758
10938
|
return null;
|
|
10759
10939
|
}
|
|
@@ -11172,15 +11352,15 @@ async function updateBarrelExport(sourceFile, oldName, newName) {
|
|
|
11172
11352
|
}
|
|
11173
11353
|
async function updateManifestEntry(workspaceRoot, updateFn) {
|
|
11174
11354
|
try {
|
|
11175
|
-
const manifestPath =
|
|
11355
|
+
const manifestPath = path34__default.join(
|
|
11176
11356
|
workspaceRoot,
|
|
11177
11357
|
".architecture/manifest.yaml"
|
|
11178
11358
|
);
|
|
11179
|
-
const content = await
|
|
11359
|
+
const content = await fs27.readFile(manifestPath, "utf-8");
|
|
11180
11360
|
const manifest = yaml9.load(content);
|
|
11181
11361
|
updateFn(manifest);
|
|
11182
11362
|
const updatedContent = yaml9.dump(manifest, { indent: 2 });
|
|
11183
|
-
await
|
|
11363
|
+
await fs27.writeFile(manifestPath, updatedContent, "utf-8");
|
|
11184
11364
|
return ok2(void 0);
|
|
11185
11365
|
} catch (error) {
|
|
11186
11366
|
return err2(error);
|
|
@@ -11244,7 +11424,7 @@ var RenamePortPattern = class {
|
|
|
11244
11424
|
(f) => f.reason.includes("Declares")
|
|
11245
11425
|
);
|
|
11246
11426
|
for (const file of portFiles) {
|
|
11247
|
-
const filePath =
|
|
11427
|
+
const filePath = path34__default.join(this.workspaceRoot, file.path);
|
|
11248
11428
|
const sourceFile = this.project.addSourceFileAtPath(filePath);
|
|
11249
11429
|
const existingInterface = sourceFile.getInterface(request.newName);
|
|
11250
11430
|
if (existingInterface) {
|
|
@@ -11266,7 +11446,7 @@ var RenamePortPattern = class {
|
|
|
11266
11446
|
const warnings = [];
|
|
11267
11447
|
try {
|
|
11268
11448
|
for (const file of impact.filesToModify) {
|
|
11269
|
-
const filePath =
|
|
11449
|
+
const filePath = path34__default.join(this.workspaceRoot, file.path);
|
|
11270
11450
|
if (file.path.endsWith(".ts") || file.path.endsWith(".tsx")) {
|
|
11271
11451
|
try {
|
|
11272
11452
|
this.project.addSourceFileAtPath(filePath);
|
|
@@ -11369,7 +11549,7 @@ var RenamePortPattern = class {
|
|
|
11369
11549
|
*/
|
|
11370
11550
|
async renamePortFile(relativePath, oldName, newName) {
|
|
11371
11551
|
try {
|
|
11372
|
-
const filePath =
|
|
11552
|
+
const filePath = path34__default.join(this.workspaceRoot, relativePath);
|
|
11373
11553
|
const sourceFile = this.project.getSourceFile(filePath);
|
|
11374
11554
|
if (!sourceFile) {
|
|
11375
11555
|
return err2(new Error(`Source file not found: ${relativePath}`));
|
|
@@ -11382,17 +11562,17 @@ var RenamePortPattern = class {
|
|
|
11382
11562
|
if (typeAlias) {
|
|
11383
11563
|
typeAlias.rename(newName);
|
|
11384
11564
|
}
|
|
11385
|
-
const oldFileName =
|
|
11565
|
+
const oldFileName = path34__default.basename(relativePath);
|
|
11386
11566
|
const newFileName = oldFileName.replace(
|
|
11387
11567
|
toKebabCase(oldName),
|
|
11388
11568
|
toKebabCase(newName)
|
|
11389
11569
|
);
|
|
11390
11570
|
if (oldFileName !== newFileName) {
|
|
11391
|
-
const newFilePath =
|
|
11571
|
+
const newFilePath = path34__default.join(path34__default.dirname(filePath), newFileName);
|
|
11392
11572
|
await sourceFile.move(newFilePath);
|
|
11393
11573
|
return ok2([
|
|
11394
11574
|
relativePath,
|
|
11395
|
-
|
|
11575
|
+
path34__default.relative(this.workspaceRoot, newFilePath)
|
|
11396
11576
|
]);
|
|
11397
11577
|
}
|
|
11398
11578
|
return ok2([relativePath]);
|
|
@@ -11405,7 +11585,7 @@ var RenamePortPattern = class {
|
|
|
11405
11585
|
*/
|
|
11406
11586
|
async updateImports(relativePath, oldName, newName) {
|
|
11407
11587
|
try {
|
|
11408
|
-
const filePath =
|
|
11588
|
+
const filePath = path34__default.join(this.workspaceRoot, relativePath);
|
|
11409
11589
|
const sourceFile = this.project.getSourceFile(filePath);
|
|
11410
11590
|
if (!sourceFile) {
|
|
11411
11591
|
return ok2([]);
|
|
@@ -11421,7 +11601,7 @@ var RenamePortPattern = class {
|
|
|
11421
11601
|
*/
|
|
11422
11602
|
async updateBarrelExport(relativePath, oldName, newName) {
|
|
11423
11603
|
try {
|
|
11424
|
-
const filePath =
|
|
11604
|
+
const filePath = path34__default.join(this.workspaceRoot, relativePath);
|
|
11425
11605
|
const sourceFile = this.project.getSourceFile(filePath);
|
|
11426
11606
|
if (!sourceFile) {
|
|
11427
11607
|
return ok2([]);
|
|
@@ -11464,7 +11644,7 @@ var RenamePortPattern = class {
|
|
|
11464
11644
|
*/
|
|
11465
11645
|
async updateTestDouble(relativePath, oldName, newName) {
|
|
11466
11646
|
try {
|
|
11467
|
-
const filePath =
|
|
11647
|
+
const filePath = path34__default.join(this.workspaceRoot, relativePath);
|
|
11468
11648
|
const sourceFile = this.project.getSourceFile(filePath);
|
|
11469
11649
|
if (!sourceFile) {
|
|
11470
11650
|
return ok2([]);
|
|
@@ -11494,17 +11674,17 @@ var RenamePortPattern = class {
|
|
|
11494
11674
|
);
|
|
11495
11675
|
modified = modified || importsModified;
|
|
11496
11676
|
if (modified) {
|
|
11497
|
-
const oldFileName =
|
|
11677
|
+
const oldFileName = path34__default.basename(relativePath);
|
|
11498
11678
|
const newFileName = oldFileName.replace(
|
|
11499
11679
|
toKebabCase(oldName),
|
|
11500
11680
|
toKebabCase(newName)
|
|
11501
11681
|
);
|
|
11502
11682
|
if (oldFileName !== newFileName) {
|
|
11503
|
-
const newFilePath =
|
|
11683
|
+
const newFilePath = path34__default.join(path34__default.dirname(filePath), newFileName);
|
|
11504
11684
|
await sourceFile.move(newFilePath);
|
|
11505
11685
|
return ok2([
|
|
11506
11686
|
relativePath,
|
|
11507
|
-
|
|
11687
|
+
path34__default.relative(this.workspaceRoot, newFilePath)
|
|
11508
11688
|
]);
|
|
11509
11689
|
}
|
|
11510
11690
|
}
|
|
@@ -11577,7 +11757,7 @@ var RenameUseCasePattern = class {
|
|
|
11577
11757
|
const warnings = [];
|
|
11578
11758
|
try {
|
|
11579
11759
|
for (const file of impact.filesToModify) {
|
|
11580
|
-
const filePath =
|
|
11760
|
+
const filePath = path34__default.join(this.workspaceRoot, file.path);
|
|
11581
11761
|
if (file.path.endsWith(".ts") || file.path.endsWith(".tsx")) {
|
|
11582
11762
|
try {
|
|
11583
11763
|
this.project.addSourceFileAtPath(filePath);
|
|
@@ -11688,7 +11868,7 @@ var RenameUseCasePattern = class {
|
|
|
11688
11868
|
*/
|
|
11689
11869
|
async renameUseCaseFile(relativePath, oldName, newName) {
|
|
11690
11870
|
try {
|
|
11691
|
-
const filePath =
|
|
11871
|
+
const filePath = path34__default.join(this.workspaceRoot, relativePath);
|
|
11692
11872
|
const sourceFile = this.project.getSourceFile(filePath);
|
|
11693
11873
|
if (!sourceFile) {
|
|
11694
11874
|
return err2(new Error(`Source file not found: ${relativePath}`));
|
|
@@ -11697,17 +11877,17 @@ var RenameUseCasePattern = class {
|
|
|
11697
11877
|
if (classDecl) {
|
|
11698
11878
|
classDecl.rename(newName);
|
|
11699
11879
|
}
|
|
11700
|
-
const oldFileName =
|
|
11880
|
+
const oldFileName = path34__default.basename(relativePath);
|
|
11701
11881
|
const newFileName = oldFileName.replace(
|
|
11702
11882
|
toKebabCase(oldName),
|
|
11703
11883
|
toKebabCase(newName)
|
|
11704
11884
|
);
|
|
11705
11885
|
if (oldFileName !== newFileName) {
|
|
11706
|
-
const newFilePath =
|
|
11886
|
+
const newFilePath = path34__default.join(path34__default.dirname(filePath), newFileName);
|
|
11707
11887
|
await sourceFile.move(newFilePath);
|
|
11708
11888
|
return ok2([
|
|
11709
11889
|
relativePath,
|
|
11710
|
-
|
|
11890
|
+
path34__default.relative(this.workspaceRoot, newFilePath)
|
|
11711
11891
|
]);
|
|
11712
11892
|
}
|
|
11713
11893
|
return ok2([relativePath]);
|
|
@@ -11717,7 +11897,7 @@ var RenameUseCasePattern = class {
|
|
|
11717
11897
|
}
|
|
11718
11898
|
async updateImports(relativePath, oldName, newName) {
|
|
11719
11899
|
try {
|
|
11720
|
-
const filePath =
|
|
11900
|
+
const filePath = path34__default.join(this.workspaceRoot, relativePath);
|
|
11721
11901
|
const sourceFile = this.project.getSourceFile(filePath);
|
|
11722
11902
|
if (!sourceFile) {
|
|
11723
11903
|
return ok2([]);
|
|
@@ -11733,7 +11913,7 @@ var RenameUseCasePattern = class {
|
|
|
11733
11913
|
*/
|
|
11734
11914
|
async updateBarrelExport(relativePath, oldName, newName) {
|
|
11735
11915
|
try {
|
|
11736
|
-
const filePath =
|
|
11916
|
+
const filePath = path34__default.join(this.workspaceRoot, relativePath);
|
|
11737
11917
|
const sourceFile = this.project.getSourceFile(filePath);
|
|
11738
11918
|
if (!sourceFile) {
|
|
11739
11919
|
return ok2([]);
|
|
@@ -11770,24 +11950,24 @@ var RenameUseCasePattern = class {
|
|
|
11770
11950
|
*/
|
|
11771
11951
|
async updateTestFile(relativePath, oldName, newName) {
|
|
11772
11952
|
try {
|
|
11773
|
-
const filePath =
|
|
11953
|
+
const filePath = path34__default.join(this.workspaceRoot, relativePath);
|
|
11774
11954
|
const sourceFile = this.project.getSourceFile(filePath);
|
|
11775
11955
|
if (!sourceFile) {
|
|
11776
11956
|
return ok2([]);
|
|
11777
11957
|
}
|
|
11778
11958
|
const modified = await updateImports(sourceFile, oldName, newName);
|
|
11779
11959
|
if (modified) {
|
|
11780
|
-
const oldFileName =
|
|
11960
|
+
const oldFileName = path34__default.basename(relativePath);
|
|
11781
11961
|
const newFileName = oldFileName.replace(
|
|
11782
11962
|
toKebabCase(oldName),
|
|
11783
11963
|
toKebabCase(newName)
|
|
11784
11964
|
);
|
|
11785
11965
|
if (oldFileName !== newFileName) {
|
|
11786
|
-
const newFilePath =
|
|
11966
|
+
const newFilePath = path34__default.join(path34__default.dirname(filePath), newFileName);
|
|
11787
11967
|
await sourceFile.move(newFilePath);
|
|
11788
11968
|
return ok2([
|
|
11789
11969
|
relativePath,
|
|
11790
|
-
|
|
11970
|
+
path34__default.relative(this.workspaceRoot, newFilePath)
|
|
11791
11971
|
]);
|
|
11792
11972
|
}
|
|
11793
11973
|
}
|
|
@@ -11798,7 +11978,7 @@ var RenameUseCasePattern = class {
|
|
|
11798
11978
|
}
|
|
11799
11979
|
async updateCompositionRoot(relativePath, oldName, newName) {
|
|
11800
11980
|
try {
|
|
11801
|
-
const filePath =
|
|
11981
|
+
const filePath = path34__default.join(this.workspaceRoot, relativePath);
|
|
11802
11982
|
const sourceFile = this.project.getSourceFile(filePath);
|
|
11803
11983
|
if (!sourceFile) {
|
|
11804
11984
|
return ok2([]);
|
|
@@ -11868,7 +12048,7 @@ var RenameEntityPattern = class {
|
|
|
11868
12048
|
if (file.path.endsWith(".ts") || file.path.endsWith(".tsx")) {
|
|
11869
12049
|
try {
|
|
11870
12050
|
this.project.addSourceFileAtPath(
|
|
11871
|
-
|
|
12051
|
+
path34__default.join(this.workspaceRoot, file.path)
|
|
11872
12052
|
);
|
|
11873
12053
|
} catch {
|
|
11874
12054
|
}
|
|
@@ -11926,7 +12106,7 @@ var RenameEntityPattern = class {
|
|
|
11926
12106
|
async renameEntityFile(relativePath, oldName, newName) {
|
|
11927
12107
|
try {
|
|
11928
12108
|
const sourceFile = this.project.getSourceFile(
|
|
11929
|
-
|
|
12109
|
+
path34__default.join(this.workspaceRoot, relativePath)
|
|
11930
12110
|
);
|
|
11931
12111
|
if (!sourceFile) return err2(new Error(`File not found: ${relativePath}`));
|
|
11932
12112
|
const classDecl = sourceFile.getClass(oldName);
|
|
@@ -11943,7 +12123,7 @@ var RenameEntityPattern = class {
|
|
|
11943
12123
|
async updateReferences(relativePath, oldName, newName) {
|
|
11944
12124
|
try {
|
|
11945
12125
|
const sourceFile = this.project.getSourceFile(
|
|
11946
|
-
|
|
12126
|
+
path34__default.join(this.workspaceRoot, relativePath)
|
|
11947
12127
|
);
|
|
11948
12128
|
if (!sourceFile) return ok2([]);
|
|
11949
12129
|
let modified = false;
|
|
@@ -11962,11 +12142,11 @@ var RenameEntityPattern = class {
|
|
|
11962
12142
|
}
|
|
11963
12143
|
async updateManifest(oldName, newName) {
|
|
11964
12144
|
try {
|
|
11965
|
-
const manifestPath =
|
|
12145
|
+
const manifestPath = path34__default.join(
|
|
11966
12146
|
this.workspaceRoot,
|
|
11967
12147
|
".architecture/manifest.yaml"
|
|
11968
12148
|
);
|
|
11969
|
-
const content = await
|
|
12149
|
+
const content = await fs27.readFile(manifestPath, "utf-8");
|
|
11970
12150
|
const manifest = yaml9.load(content);
|
|
11971
12151
|
if (manifest.bounded_contexts) {
|
|
11972
12152
|
for (const context of manifest.bounded_contexts) {
|
|
@@ -11978,7 +12158,7 @@ var RenameEntityPattern = class {
|
|
|
11978
12158
|
}
|
|
11979
12159
|
}
|
|
11980
12160
|
}
|
|
11981
|
-
await
|
|
12161
|
+
await fs27.writeFile(
|
|
11982
12162
|
manifestPath,
|
|
11983
12163
|
yaml9.dump(manifest, { indent: 2 }),
|
|
11984
12164
|
"utf-8"
|
|
@@ -12662,7 +12842,7 @@ var manifestSplitCommander = new Command("split").description("Split monolithic
|
|
|
12662
12842
|
const dryRun = options.dryRun ?? false;
|
|
12663
12843
|
try {
|
|
12664
12844
|
const workspaceRoot = await findWorkspaceRoot({});
|
|
12665
|
-
const monolithicManifestPath =
|
|
12845
|
+
const monolithicManifestPath = path34__default.join(
|
|
12666
12846
|
workspaceRoot,
|
|
12667
12847
|
".architecture/manifest.yaml"
|
|
12668
12848
|
);
|
|
@@ -12671,7 +12851,7 @@ var manifestSplitCommander = new Command("split").description("Split monolithic
|
|
|
12671
12851
|
);
|
|
12672
12852
|
let manifestContent;
|
|
12673
12853
|
try {
|
|
12674
|
-
manifestContent = await
|
|
12854
|
+
manifestContent = await fs27.readFile(monolithicManifestPath, "utf-8");
|
|
12675
12855
|
} catch {
|
|
12676
12856
|
throw new Error(`Failed to read manifest.yaml. Does it exist?`);
|
|
12677
12857
|
}
|
|
@@ -12699,14 +12879,14 @@ Validation successful. Found ${contexts.length} bounded contexts.`
|
|
|
12699
12879
|
const planes = rawYaml.planes ?? {};
|
|
12700
12880
|
const planeLookup = buildPlaneLookup(planes);
|
|
12701
12881
|
console.log("Splitting manifest into the new directory structure...");
|
|
12702
|
-
const archDir =
|
|
12703
|
-
const contextsDir =
|
|
12704
|
-
const appsDir =
|
|
12705
|
-
const invariantsDir =
|
|
12882
|
+
const archDir = path34__default.join(workspaceRoot, ".architecture");
|
|
12883
|
+
const contextsDir = path34__default.join(archDir, "contexts");
|
|
12884
|
+
const appsDir = path34__default.join(archDir, "apps");
|
|
12885
|
+
const invariantsDir = path34__default.join(archDir, "invariants");
|
|
12706
12886
|
if (!dryRun) {
|
|
12707
|
-
await
|
|
12708
|
-
await
|
|
12709
|
-
await
|
|
12887
|
+
await fs27.mkdir(contextsDir, { recursive: true });
|
|
12888
|
+
await fs27.mkdir(appsDir, { recursive: true });
|
|
12889
|
+
await fs27.mkdir(invariantsDir, { recursive: true });
|
|
12710
12890
|
}
|
|
12711
12891
|
const CATEGORY_B_KEYS = /* @__PURE__ */ new Set(["monorepo", "generator"]);
|
|
12712
12892
|
const workspaceConfig = {};
|
|
@@ -12746,12 +12926,12 @@ Validation successful. Found ${contexts.length} bounded contexts.`
|
|
|
12746
12926
|
}
|
|
12747
12927
|
for (const ctx of contexts) {
|
|
12748
12928
|
const plane = planeLookup.get(ctx.name) ?? ctx.plane ?? "core";
|
|
12749
|
-
const ctxDir =
|
|
12929
|
+
const ctxDir = path34__default.join(contextsDir, plane, ctx.name);
|
|
12750
12930
|
const contextData = normalizeContextData(
|
|
12751
12931
|
extractContextData(ctx)
|
|
12752
12932
|
);
|
|
12753
12933
|
contextData.plane = plane;
|
|
12754
|
-
const ctxFilePath =
|
|
12934
|
+
const ctxFilePath = path34__default.join(ctxDir, "context.yaml");
|
|
12755
12935
|
const ctxYaml = yaml9.dump(contextData, {
|
|
12756
12936
|
noRefs: true,
|
|
12757
12937
|
sortKeys: false,
|
|
@@ -12760,8 +12940,8 @@ Validation successful. Found ${contexts.length} bounded contexts.`
|
|
|
12760
12940
|
if (dryRun) {
|
|
12761
12941
|
console.log(`[dry-run] Would create: ${ctxFilePath}`);
|
|
12762
12942
|
} else {
|
|
12763
|
-
await
|
|
12764
|
-
await
|
|
12943
|
+
await fs27.mkdir(ctxDir, { recursive: true });
|
|
12944
|
+
await fs27.writeFile(ctxFilePath, ctxYaml, "utf-8");
|
|
12765
12945
|
}
|
|
12766
12946
|
indexManifest.bounded_contexts.push({
|
|
12767
12947
|
name: ctx.name,
|
|
@@ -12777,7 +12957,7 @@ Validation successful. Found ${contexts.length} bounded contexts.`
|
|
|
12777
12957
|
if (typeof app === "object" && app !== null && "name" in app) {
|
|
12778
12958
|
const typedApp = app;
|
|
12779
12959
|
const appName = typedApp.name;
|
|
12780
|
-
const appFilePath =
|
|
12960
|
+
const appFilePath = path34__default.join(appsDir, `${appName}.app.yaml`);
|
|
12781
12961
|
const appYaml = yaml9.dump(app, {
|
|
12782
12962
|
noRefs: true,
|
|
12783
12963
|
sortKeys: false,
|
|
@@ -12786,7 +12966,7 @@ Validation successful. Found ${contexts.length} bounded contexts.`
|
|
|
12786
12966
|
if (dryRun) {
|
|
12787
12967
|
console.log(`[dry-run] Would create: ${appFilePath}`);
|
|
12788
12968
|
} else {
|
|
12789
|
-
await
|
|
12969
|
+
await fs27.writeFile(appFilePath, appYaml, "utf-8");
|
|
12790
12970
|
}
|
|
12791
12971
|
indexManifest.apps.push({
|
|
12792
12972
|
name: appName,
|
|
@@ -12794,7 +12974,7 @@ Validation successful. Found ${contexts.length} bounded contexts.`
|
|
|
12794
12974
|
});
|
|
12795
12975
|
}
|
|
12796
12976
|
}
|
|
12797
|
-
const workspaceConfigPath =
|
|
12977
|
+
const workspaceConfigPath = path34__default.join(archDir, "workspace.config.yaml");
|
|
12798
12978
|
const workspaceConfigYaml = yaml9.dump(workspaceConfig, {
|
|
12799
12979
|
noRefs: true,
|
|
12800
12980
|
sortKeys: false,
|
|
@@ -12805,7 +12985,7 @@ Validation successful. Found ${contexts.length} bounded contexts.`
|
|
|
12805
12985
|
console.log("\n--- Preview of workspace.config.yaml ---\n");
|
|
12806
12986
|
console.log(workspaceConfigYaml);
|
|
12807
12987
|
} else {
|
|
12808
|
-
await
|
|
12988
|
+
await fs27.writeFile(workspaceConfigPath, workspaceConfigYaml, "utf-8");
|
|
12809
12989
|
}
|
|
12810
12990
|
const indexYaml = yaml9.dump(indexManifest, {
|
|
12811
12991
|
noRefs: true,
|
|
@@ -12826,9 +13006,9 @@ Validation successful. Found ${contexts.length} bounded contexts.`
|
|
|
12826
13006
|
console.log(header + indexYaml);
|
|
12827
13007
|
} else {
|
|
12828
13008
|
const backupPath = monolithicManifestPath + ".pre-split-backup";
|
|
12829
|
-
await
|
|
13009
|
+
await fs27.copyFile(monolithicManifestPath, backupPath);
|
|
12830
13010
|
console.log(`Backup created at ${backupPath}`);
|
|
12831
|
-
await
|
|
13011
|
+
await fs27.writeFile(monolithicManifestPath, header + indexYaml, "utf-8");
|
|
12832
13012
|
}
|
|
12833
13013
|
console.log("\n✅ Manifest split completed successfully!");
|
|
12834
13014
|
if (dryRun) {
|
|
@@ -12875,45 +13055,53 @@ function createLogger() {
|
|
|
12875
13055
|
};
|
|
12876
13056
|
}
|
|
12877
13057
|
var logger = createLogger();
|
|
12878
|
-
function readVersion() {
|
|
12879
|
-
try {
|
|
12880
|
-
const pkgPath = join(
|
|
12881
|
-
dirname(fileURLToPath(import.meta.url)),
|
|
12882
|
-
"..",
|
|
12883
|
-
"package.json"
|
|
12884
|
-
);
|
|
12885
|
-
return JSON.parse(readFileSync(pkgPath, "utf8")).version ?? "0.0.0";
|
|
12886
|
-
} catch {
|
|
12887
|
-
return "0.0.0";
|
|
12888
|
-
}
|
|
12889
|
-
}
|
|
12890
13058
|
function buildProgram() {
|
|
12891
13059
|
const program2 = new Command();
|
|
12892
|
-
program2.name("hexagen").description("HexaGen Monaco — Generate and sync modular monorepos").version(
|
|
12893
|
-
program2.command("sync").description("Run the HexaGen sync engine to generate artifacts").option("--dry-run", "Preview changes without writing files").option(
|
|
13060
|
+
program2.name("hexagen").description("HexaGen Monaco — Generate and sync modular monorepos").version(resolveToolchainVersion());
|
|
13061
|
+
program2.command("sync").description("Run the HexaGen sync engine to generate artifacts").option("--dry-run", "Preview changes without writing files").option(
|
|
13062
|
+
"--check",
|
|
13063
|
+
"CI drift gate: implies --dry-run and exits non-zero iff any change would be made (created/updated/deleted). A converged tree exits 0."
|
|
13064
|
+
).option("--force", "Overwrite non-generated files in packages").option(
|
|
12894
13065
|
"--force-root",
|
|
12895
13066
|
"Overwrite protected root files (turbo.json, .gitignore)"
|
|
12896
13067
|
).option("--allow-dirty", "Skip git clean check (for development)").option("--strict", "Fail on architecture linter warnings").option(
|
|
12897
13068
|
"--only <pattern...>",
|
|
12898
13069
|
"Limit writes to workspace-relative paths/globs (e.g. packages/shared, 'packages/*/tsconfig.json'). Direct targets only — no dependency fan-out; run a full sync for cross-package changes."
|
|
13070
|
+
).option(
|
|
13071
|
+
"--report <path>",
|
|
13072
|
+
"Migration-report destination, resolved against the workspace root (absolute paths allowed; parent dirs are created). Real runs default to SYNC-MIGRATION-REPORT.md; --dry-run writes no report unless this is set."
|
|
12899
13073
|
).action(async (options) => {
|
|
13074
|
+
const check = options.check ?? false;
|
|
12900
13075
|
const flags = {
|
|
12901
|
-
dryRun: options.dryRun ?? false,
|
|
13076
|
+
dryRun: (options.dryRun || options.check) ?? false,
|
|
12902
13077
|
force: options.force ?? false,
|
|
12903
13078
|
forceRoot: options.forceRoot ?? false,
|
|
12904
13079
|
allowDirty: options.allowDirty ?? false,
|
|
12905
13080
|
strict: options.strict ?? false,
|
|
12906
13081
|
only: options.only,
|
|
13082
|
+
report: options.report,
|
|
12907
13083
|
mode: "self-regen",
|
|
12908
13084
|
logger
|
|
12909
13085
|
};
|
|
12910
13086
|
try {
|
|
12911
13087
|
const engine = new SyncEngine(flags);
|
|
12912
|
-
await engine.run();
|
|
13088
|
+
const summary = await engine.run();
|
|
13089
|
+
if (summary.errors > 0) {
|
|
13090
|
+
console.error(
|
|
13091
|
+
`Sync incomplete: ${summary.errors} generator failure(s) — see the FAILED row(s) above.`
|
|
13092
|
+
);
|
|
13093
|
+
process.exitCode = 1;
|
|
13094
|
+
}
|
|
13095
|
+
if (check && summary.totalOps > 0) {
|
|
13096
|
+
console.error(
|
|
13097
|
+
`Drift detected: ${summary.totalOps} pending change(s) (${summary.created} to create, ${summary.updated} to update, ${summary.deleted} to delete). Run \`hexagen sync\` to converge.`
|
|
13098
|
+
);
|
|
13099
|
+
process.exitCode = 1;
|
|
13100
|
+
}
|
|
12913
13101
|
} catch (err3) {
|
|
12914
13102
|
const message = err3 instanceof Error ? err3.message : "Unknown fatal error";
|
|
12915
13103
|
console.error(`Fatal sync error: ${message}`);
|
|
12916
|
-
process.
|
|
13104
|
+
process.exitCode = 1;
|
|
12917
13105
|
}
|
|
12918
13106
|
});
|
|
12919
13107
|
const archCommand = program2.command("arch").description("Manage architecture manifest.yaml");
|
|
@@ -12949,11 +13137,11 @@ function buildProgram() {
|
|
|
12949
13137
|
}
|
|
12950
13138
|
var program = buildProgram();
|
|
12951
13139
|
try {
|
|
12952
|
-
program.
|
|
13140
|
+
await program.parseAsync(process.argv);
|
|
12953
13141
|
} catch (err3) {
|
|
12954
13142
|
const message = err3 instanceof Error ? err3.message : "Unknown CLI error";
|
|
12955
13143
|
console.error(`CLI error: ${message}`);
|
|
12956
|
-
process.
|
|
13144
|
+
process.exitCode = 1;
|
|
12957
13145
|
}
|
|
12958
13146
|
//# sourceMappingURL=cli.js.map
|
|
12959
13147
|
//# sourceMappingURL=cli.js.map
|