@hexagen-monaco/sync 0.15.0 → 0.16.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/__tests__/drift-files.test.d.ts +2 -0
- package/dist/__tests__/drift-files.test.d.ts.map +1 -0
- package/dist/cli.js +656 -525
- package/dist/cli.js.map +1 -1
- package/dist/commands/sync/check-json-files.test.d.ts +2 -0
- package/dist/commands/sync/check-json-files.test.d.ts.map +1 -0
- package/dist/commands/sync/check-json.d.ts +25 -5
- package/dist/commands/sync/check-json.d.ts.map +1 -1
- package/dist/generators/port-analyzer.d.ts +2 -0
- package/dist/generators/port-analyzer.d.ts.map +1 -1
- package/dist/index.js +235 -120
- package/dist/index.js.map +1 -1
- package/dist/preflight.d.ts +4 -1
- package/dist/preflight.d.ts.map +1 -1
- package/dist/results.d.ts +40 -0
- package/dist/results.d.ts.map +1 -1
- package/dist/sync-engine.d.ts +1 -0
- package/dist/sync-engine.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path8 from 'path';
|
|
2
2
|
import fs4, { realpathSync, lstatSync, createWriteStream } from 'fs';
|
|
3
3
|
import fs5 from 'fs/promises';
|
|
4
4
|
import { promisify } from 'util';
|
|
5
5
|
import { exec } from 'child_process';
|
|
6
6
|
import yaml3 from 'js-yaml';
|
|
7
|
-
import crypto from 'crypto';
|
|
7
|
+
import crypto, { createHash } from 'crypto';
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
import { fileURLToPath } from 'url';
|
|
10
10
|
import { Project, MethodSignature } from 'ts-morph';
|
|
@@ -27,8 +27,8 @@ var MigrationReport = class {
|
|
|
27
27
|
);
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
const reportPath = config.report ?
|
|
31
|
-
await fs5.mkdir(
|
|
30
|
+
const reportPath = config.report ? path8.resolve(config.workspaceRoot, config.report) : path8.join(config.workspaceRoot, "SYNC-MIGRATION-REPORT.md");
|
|
31
|
+
await fs5.mkdir(path8.dirname(reportPath), { recursive: true });
|
|
32
32
|
let preContent = null;
|
|
33
33
|
try {
|
|
34
34
|
preContent = await fs5.readFile(reportPath, "utf8");
|
|
@@ -81,7 +81,7 @@ var SyncJournal = class {
|
|
|
81
81
|
*/
|
|
82
82
|
describeEntries(workspaceRoot) {
|
|
83
83
|
return this.entries.map(
|
|
84
|
-
(e) => `${e.kind} ${
|
|
84
|
+
(e) => `${e.kind} ${path8.relative(workspaceRoot, e.path)}`
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
@@ -107,7 +107,7 @@ var SyncJournal = class {
|
|
|
107
107
|
failures: []
|
|
108
108
|
};
|
|
109
109
|
for (const entry of [...this.entries].reverse()) {
|
|
110
|
-
const relative =
|
|
110
|
+
const relative = path8.relative(workspaceRoot, entry.path);
|
|
111
111
|
try {
|
|
112
112
|
if (entry.preContent === null) {
|
|
113
113
|
try {
|
|
@@ -119,7 +119,7 @@ var SyncJournal = class {
|
|
|
119
119
|
}
|
|
120
120
|
logger.info(`rolled back (removed) ${relative}`);
|
|
121
121
|
} else {
|
|
122
|
-
await fs5.mkdir(
|
|
122
|
+
await fs5.mkdir(path8.dirname(entry.path), { recursive: true });
|
|
123
123
|
await fs5.writeFile(entry.path, entry.preContent, {
|
|
124
124
|
encoding: "utf8"
|
|
125
125
|
});
|
|
@@ -141,7 +141,7 @@ var LOCK_FILE = ".architecture/.sync.lock";
|
|
|
141
141
|
var LockFile = class {
|
|
142
142
|
constructor(workspaceRoot, fsImpl = fs5, logger = console) {
|
|
143
143
|
this.workspaceRoot = workspaceRoot;
|
|
144
|
-
this.lockPath =
|
|
144
|
+
this.lockPath = path8.join(workspaceRoot, LOCK_FILE);
|
|
145
145
|
this.fsImpl = fsImpl;
|
|
146
146
|
this.logger = logger;
|
|
147
147
|
}
|
|
@@ -229,22 +229,22 @@ function binEntryOf(pkgJsonPath) {
|
|
|
229
229
|
}
|
|
230
230
|
function resolveFromPackage(dir) {
|
|
231
231
|
for (const pkgName of PACKAGE_NAMES) {
|
|
232
|
-
const pkgDir =
|
|
233
|
-
const entry = binEntryOf(
|
|
232
|
+
const pkgDir = path8.join(dir, "node_modules", ...pkgName.split("/"));
|
|
233
|
+
const entry = binEntryOf(path8.join(pkgDir, "package.json"));
|
|
234
234
|
if (entry === null) continue;
|
|
235
|
-
const binPath =
|
|
235
|
+
const binPath = path8.join(pkgDir, entry);
|
|
236
236
|
if (fs4.existsSync(binPath)) return binPath;
|
|
237
237
|
}
|
|
238
238
|
return null;
|
|
239
239
|
}
|
|
240
240
|
function resolveArchLinterBin(startDir) {
|
|
241
|
-
let dir =
|
|
241
|
+
let dir = path8.resolve(startDir);
|
|
242
242
|
for (; ; ) {
|
|
243
|
-
const candidate =
|
|
243
|
+
const candidate = path8.join(dir, "node_modules", ".bin", BIN_NAME);
|
|
244
244
|
if (fs4.existsSync(candidate)) return candidate;
|
|
245
245
|
const fromPackage = resolveFromPackage(dir);
|
|
246
246
|
if (fromPackage !== null) return fromPackage;
|
|
247
|
-
const parent =
|
|
247
|
+
const parent = path8.dirname(dir);
|
|
248
248
|
if (parent === dir) return null;
|
|
249
249
|
dir = parent;
|
|
250
250
|
}
|
|
@@ -308,8 +308,6 @@ ${message}`);
|
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
|
-
|
|
312
|
-
// src/results.ts
|
|
313
311
|
function createEmptyResult() {
|
|
314
312
|
return {
|
|
315
313
|
created: [],
|
|
@@ -333,6 +331,61 @@ function recordWriteStatus(result, filePath, status) {
|
|
|
333
331
|
result.skipped.push(filePath);
|
|
334
332
|
}
|
|
335
333
|
}
|
|
334
|
+
function driftReason(action) {
|
|
335
|
+
if (action === "create") {
|
|
336
|
+
return "missing on disk; sync would create it";
|
|
337
|
+
}
|
|
338
|
+
if (action === "update") {
|
|
339
|
+
return "content differs from generated output";
|
|
340
|
+
}
|
|
341
|
+
return "no longer generated; sync would remove it";
|
|
342
|
+
}
|
|
343
|
+
function normalizeRelativePath(filePath, workspaceRoot) {
|
|
344
|
+
const relative = path8.isAbsolute(filePath) ? path8.relative(workspaceRoot, filePath) : filePath;
|
|
345
|
+
return relative.replaceAll("\\", "/");
|
|
346
|
+
}
|
|
347
|
+
function compareStrings(a, b) {
|
|
348
|
+
if (a < b) return -1;
|
|
349
|
+
if (a > b) return 1;
|
|
350
|
+
return 0;
|
|
351
|
+
}
|
|
352
|
+
function compareDriftFiles(a, b) {
|
|
353
|
+
const byPath = compareStrings(a.path, b.path);
|
|
354
|
+
if (byPath !== 0) return byPath;
|
|
355
|
+
const byAction = compareStrings(a.action, b.action);
|
|
356
|
+
if (byAction !== 0) return byAction;
|
|
357
|
+
return compareStrings(a.generator, b.generator);
|
|
358
|
+
}
|
|
359
|
+
function collectDriftFilesForRow(generator, result, workspaceRoot, seen, files) {
|
|
360
|
+
const buckets = [
|
|
361
|
+
["create", result.created],
|
|
362
|
+
["update", result.updated],
|
|
363
|
+
["delete", result.deleted]
|
|
364
|
+
];
|
|
365
|
+
for (const [action, paths] of buckets) {
|
|
366
|
+
for (const p of paths) {
|
|
367
|
+
const relPath = normalizeRelativePath(p, workspaceRoot);
|
|
368
|
+
const key = `${relPath}\0${action}\0${generator}`;
|
|
369
|
+
if (seen.has(key)) continue;
|
|
370
|
+
seen.add(key);
|
|
371
|
+
files.push({
|
|
372
|
+
path: relPath,
|
|
373
|
+
action,
|
|
374
|
+
generator,
|
|
375
|
+
reason: driftReason(action)
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function buildDriftFiles(rows, workspaceRoot) {
|
|
381
|
+
const seen = /* @__PURE__ */ new Set();
|
|
382
|
+
const files = [];
|
|
383
|
+
for (const [generator, result] of rows) {
|
|
384
|
+
collectDriftFilesForRow(generator, result, workspaceRoot, seen, files);
|
|
385
|
+
}
|
|
386
|
+
files.sort(compareDriftFiles);
|
|
387
|
+
return files;
|
|
388
|
+
}
|
|
336
389
|
|
|
337
390
|
// src/scope-filter.ts
|
|
338
391
|
var GLOB_META = /[*?]/;
|
|
@@ -400,7 +453,7 @@ function isGeneratedFile(content) {
|
|
|
400
453
|
return content.includes(GENERATED_MARKER);
|
|
401
454
|
}
|
|
402
455
|
function isProtectedRoot(filePath, config) {
|
|
403
|
-
const relative =
|
|
456
|
+
const relative = path8.relative(config.workspaceRoot, filePath).replace(/\\/g, "/");
|
|
404
457
|
const isRootLevel = !relative.startsWith("packages/") && !relative.startsWith("tools/") && !relative.startsWith("apps/");
|
|
405
458
|
return isRootLevel && Array.from(protectedFiles).some(
|
|
406
459
|
(f) => relative.endsWith(f) || relative.includes(f)
|
|
@@ -408,12 +461,12 @@ function isProtectedRoot(filePath, config) {
|
|
|
408
461
|
}
|
|
409
462
|
function isInScope(filePath, config) {
|
|
410
463
|
if (!config.only || config.only.length === 0) return true;
|
|
411
|
-
const relativePath =
|
|
464
|
+
const relativePath = path8.relative(config.workspaceRoot, filePath);
|
|
412
465
|
return matchesScope(relativePath, config.only);
|
|
413
466
|
}
|
|
414
467
|
async function safeWriteFileAtomic(filePath, content, config, report, skipGeneratedCheck = false) {
|
|
415
468
|
const { dryRun, forceRoot, logger, workspaceRoot } = config;
|
|
416
|
-
const relativePath =
|
|
469
|
+
const relativePath = path8.relative(workspaceRoot, filePath);
|
|
417
470
|
if (!isInScope(filePath, config)) {
|
|
418
471
|
logger.debug(`skipped (outside --only) ${relativePath}`);
|
|
419
472
|
return "skipped";
|
|
@@ -453,9 +506,9 @@ async function safeWriteFileAtomic(filePath, content, config, report, skipGenera
|
|
|
453
506
|
return exists ? "updated" : "created";
|
|
454
507
|
}
|
|
455
508
|
config.journal?.recordWrite(filePath, exists ? currentContent : null);
|
|
456
|
-
await fs5.mkdir(
|
|
457
|
-
const tmpName = `.${
|
|
458
|
-
const tmpPath =
|
|
509
|
+
await fs5.mkdir(path8.dirname(filePath), { recursive: true });
|
|
510
|
+
const tmpName = `.${path8.basename(filePath)}.${crypto.randomUUID()}.tmp`;
|
|
511
|
+
const tmpPath = path8.join(path8.dirname(filePath), tmpName);
|
|
459
512
|
await fs5.writeFile(tmpPath, content, { encoding: "utf8" });
|
|
460
513
|
try {
|
|
461
514
|
await fs5.rename(tmpPath, filePath);
|
|
@@ -553,7 +606,7 @@ async function directoryExists(dirPath) {
|
|
|
553
606
|
async function ensureDirectoryCounted(dirPath, config, result) {
|
|
554
607
|
const existed = await directoryExists(dirPath);
|
|
555
608
|
if (existed) return;
|
|
556
|
-
const relativePath =
|
|
609
|
+
const relativePath = path8.relative(config.workspaceRoot, dirPath);
|
|
557
610
|
if (config.dryRun) {
|
|
558
611
|
config.logger.info(`[DRY-RUN] would create directory ${relativePath}`);
|
|
559
612
|
} else {
|
|
@@ -564,7 +617,7 @@ async function ensureDirectoryCounted(dirPath, config, result) {
|
|
|
564
617
|
result.totalOps += 1;
|
|
565
618
|
}
|
|
566
619
|
async function ensureGitkeepCounted(dirPath, config, result) {
|
|
567
|
-
const keepPath =
|
|
620
|
+
const keepPath = path8.join(dirPath, ".gitkeep");
|
|
568
621
|
let entries = null;
|
|
569
622
|
if (await directoryExists(dirPath)) {
|
|
570
623
|
entries = await fs5.readdir(dirPath);
|
|
@@ -604,7 +657,7 @@ async function loadYamlSafe(filePath) {
|
|
|
604
657
|
async function ensureLayerFolders(moduleDir, layers, config, contextLayers) {
|
|
605
658
|
const result = createEmptyResult();
|
|
606
659
|
const { logger } = config;
|
|
607
|
-
const layerRulesPath =
|
|
660
|
+
const layerRulesPath = path8.join(
|
|
608
661
|
config.workspaceRoot,
|
|
609
662
|
".architecture",
|
|
610
663
|
"invariants",
|
|
@@ -618,8 +671,8 @@ async function ensureLayerFolders(moduleDir, layers, config, contextLayers) {
|
|
|
618
671
|
if (!layerDeclaresContent(layerName, contextLayers)) {
|
|
619
672
|
continue;
|
|
620
673
|
}
|
|
621
|
-
const layerPath =
|
|
622
|
-
if (!isInScope(layerPath, config) && !isInScope(
|
|
674
|
+
const layerPath = path8.join(moduleDir, resolveLayerDir(layers, layerName));
|
|
675
|
+
if (!isInScope(layerPath, config) && !isInScope(path8.join(layerPath, "index.ts"), config)) {
|
|
623
676
|
continue;
|
|
624
677
|
}
|
|
625
678
|
await ensureDirectoryCounted(layerPath, config, result);
|
|
@@ -635,8 +688,8 @@ async function ensureLayerFolders(moduleDir, layers, config, contextLayers) {
|
|
|
635
688
|
);
|
|
636
689
|
continue;
|
|
637
690
|
}
|
|
638
|
-
const subPath =
|
|
639
|
-
if (!isInScope(subPath, config) && !isInScope(
|
|
691
|
+
const subPath = path8.join(layerPath, normalizedSub);
|
|
692
|
+
if (!isInScope(subPath, config) && !isInScope(path8.join(subPath, "index.ts"), config)) {
|
|
640
693
|
continue;
|
|
641
694
|
}
|
|
642
695
|
await ensureDirectoryCounted(subPath, config, result);
|
|
@@ -672,18 +725,18 @@ function contentHash2(content) {
|
|
|
672
725
|
function detectCircularExports(exportGraph) {
|
|
673
726
|
const visited = /* @__PURE__ */ new Set();
|
|
674
727
|
const recursionStack = /* @__PURE__ */ new Set();
|
|
675
|
-
const
|
|
728
|
+
const path26 = [];
|
|
676
729
|
function dfs(node) {
|
|
677
730
|
if (recursionStack.has(node)) {
|
|
678
|
-
const cycleStart =
|
|
679
|
-
return [...
|
|
731
|
+
const cycleStart = path26.indexOf(node);
|
|
732
|
+
return [...path26.slice(cycleStart), node];
|
|
680
733
|
}
|
|
681
734
|
if (visited.has(node)) {
|
|
682
735
|
return null;
|
|
683
736
|
}
|
|
684
737
|
visited.add(node);
|
|
685
738
|
recursionStack.add(node);
|
|
686
|
-
|
|
739
|
+
path26.push(node);
|
|
687
740
|
const exports$1 = exportGraph.get(node) ?? [];
|
|
688
741
|
for (const exportPath of exports$1) {
|
|
689
742
|
const cycle = dfs(exportPath);
|
|
@@ -691,7 +744,7 @@ function detectCircularExports(exportGraph) {
|
|
|
691
744
|
return cycle;
|
|
692
745
|
}
|
|
693
746
|
}
|
|
694
|
-
|
|
747
|
+
path26.pop();
|
|
695
748
|
recursionStack.delete(node);
|
|
696
749
|
return null;
|
|
697
750
|
}
|
|
@@ -708,8 +761,8 @@ function generateBarrelContent(entries) {
|
|
|
708
761
|
return null;
|
|
709
762
|
}
|
|
710
763
|
const exportLines = entries.sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
|
|
711
|
-
const
|
|
712
|
-
return `export * from "${
|
|
764
|
+
const path26 = entry.isDirectory ? `./${entry.name}/index.js` : `./${entry.name}.js`;
|
|
765
|
+
return `export * from "${path26}";`;
|
|
713
766
|
});
|
|
714
767
|
return `${GENERATED_MARKER2}
|
|
715
768
|
|
|
@@ -731,14 +784,14 @@ var CircularExportError = class extends Error {
|
|
|
731
784
|
};
|
|
732
785
|
async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
733
786
|
const result = createEmptyResult();
|
|
734
|
-
const srcDir =
|
|
787
|
+
const srcDir = path8.join(moduleDir, "src");
|
|
735
788
|
const layers = ["domain", "application", "infrastructure"];
|
|
736
789
|
const pendingWrites = [];
|
|
737
790
|
const preserved = [];
|
|
738
791
|
const exportGraph = /* @__PURE__ */ new Map();
|
|
739
792
|
const layersWithContent = [];
|
|
740
793
|
for (const layer of layers) {
|
|
741
|
-
const layerDir =
|
|
794
|
+
const layerDir = path8.join(srcDir, layer);
|
|
742
795
|
try {
|
|
743
796
|
await fs5.access(layerDir);
|
|
744
797
|
} catch {
|
|
@@ -754,7 +807,7 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
|
754
807
|
if (layerExports.length > 0) layersWithContent.push(layer);
|
|
755
808
|
}
|
|
756
809
|
if (config.mode === "external" && layersWithContent.length > 0) {
|
|
757
|
-
const rootBarrelPath =
|
|
810
|
+
const rootBarrelPath = path8.join(srcDir, "index.ts");
|
|
758
811
|
if (await shouldGenerateBarrel(rootBarrelPath, preserved, config.logger)) {
|
|
759
812
|
const content = generateBarrelContent(
|
|
760
813
|
layersWithContent.map((name) => ({ name, isDirectory: true }))
|
|
@@ -768,7 +821,7 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
|
768
821
|
});
|
|
769
822
|
exportGraph.set(
|
|
770
823
|
rootBarrelPath,
|
|
771
|
-
layersWithContent.map((name) =>
|
|
824
|
+
layersWithContent.map((name) => path8.join(srcDir, name, "index.ts"))
|
|
772
825
|
);
|
|
773
826
|
}
|
|
774
827
|
}
|
|
@@ -834,7 +887,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
834
887
|
}
|
|
835
888
|
}
|
|
836
889
|
for (const dir of directories) {
|
|
837
|
-
const subDirPath =
|
|
890
|
+
const subDirPath = path8.join(dirPath, dir);
|
|
838
891
|
const subExports = await walkDirectory(
|
|
839
892
|
subDirPath,
|
|
840
893
|
pendingWrites,
|
|
@@ -842,7 +895,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
842
895
|
exportGraph,
|
|
843
896
|
config
|
|
844
897
|
);
|
|
845
|
-
const subBarrelPath =
|
|
898
|
+
const subBarrelPath = path8.join(subDirPath, "index.ts");
|
|
846
899
|
const isQueuedForDeletion = pendingWrites.some(
|
|
847
900
|
(p) => p.filePath === subBarrelPath && p.content === ""
|
|
848
901
|
);
|
|
@@ -854,7 +907,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
854
907
|
exportEntries.push({ name: file, isDirectory: false });
|
|
855
908
|
}
|
|
856
909
|
if (exportEntries.length === 0) {
|
|
857
|
-
const barrelPath2 =
|
|
910
|
+
const barrelPath2 = path8.join(dirPath, "index.ts");
|
|
858
911
|
const existingBarrel = await readFileIfExists(barrelPath2);
|
|
859
912
|
if (existingBarrel) {
|
|
860
913
|
const isGenerated = isGeneratedFile2(existingBarrel);
|
|
@@ -871,7 +924,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
871
924
|
}
|
|
872
925
|
return [];
|
|
873
926
|
}
|
|
874
|
-
const barrelPath =
|
|
927
|
+
const barrelPath = path8.join(dirPath, "index.ts");
|
|
875
928
|
const shouldCreateBarrel = await shouldGenerateBarrel(
|
|
876
929
|
barrelPath,
|
|
877
930
|
preserved,
|
|
@@ -891,14 +944,14 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
891
944
|
content,
|
|
892
945
|
isNew: !existingContent
|
|
893
946
|
});
|
|
894
|
-
const exportPaths = exportEntries.filter((e) => e.isDirectory).map((e) =>
|
|
947
|
+
const exportPaths = exportEntries.filter((e) => e.isDirectory).map((e) => path8.join(dirPath, e.name, "index.ts"));
|
|
895
948
|
exportGraph.set(barrelPath, exportPaths);
|
|
896
949
|
}
|
|
897
950
|
return exportEntries;
|
|
898
951
|
}
|
|
899
952
|
async function hasBarrel(dirPath) {
|
|
900
953
|
try {
|
|
901
|
-
await fs5.access(
|
|
954
|
+
await fs5.access(path8.join(dirPath, "index.ts"));
|
|
902
955
|
return true;
|
|
903
956
|
} catch {
|
|
904
957
|
return false;
|
|
@@ -963,7 +1016,7 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
|
|
|
963
1016
|
const moduleOverrides = context?.packageJson ?? {};
|
|
964
1017
|
const scope = config.manifest ? resolveScope(config.manifest) : "generated-project";
|
|
965
1018
|
const dependsOnDeps = context ? expandDependsOn(context, scope) : {};
|
|
966
|
-
const pkgPath =
|
|
1019
|
+
const pkgPath = path8.join(modulePath, "package.json");
|
|
967
1020
|
const dependencies = {
|
|
968
1021
|
...dependsOnDeps,
|
|
969
1022
|
...defaults.dependencies ?? {},
|
|
@@ -1057,7 +1110,7 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
|
|
|
1057
1110
|
);
|
|
1058
1111
|
recordWriteStatus(result, pkgPath, status);
|
|
1059
1112
|
if (config.mode === "external") {
|
|
1060
|
-
const vitestConfigPath =
|
|
1113
|
+
const vitestConfigPath = path8.join(modulePath, "vitest.config.ts");
|
|
1061
1114
|
if (isInScope(vitestConfigPath, config)) {
|
|
1062
1115
|
let vitestConfigExists = false;
|
|
1063
1116
|
try {
|
|
@@ -1158,7 +1211,7 @@ function buildTemplate(base, context, scope) {
|
|
|
1158
1211
|
}
|
|
1159
1212
|
async function generateTsconfig(moduleDir, moduleName, config, report) {
|
|
1160
1213
|
const result = createEmptyResult();
|
|
1161
|
-
const filePath =
|
|
1214
|
+
const filePath = path8.join(moduleDir, "tsconfig.json");
|
|
1162
1215
|
try {
|
|
1163
1216
|
const base = resolveWorkspaceTemplate(config.manifest);
|
|
1164
1217
|
const context = config.manifest.bounded_contexts?.find(
|
|
@@ -1190,7 +1243,7 @@ export {};
|
|
|
1190
1243
|
`;
|
|
1191
1244
|
async function ensurePackageSrcIndex(moduleDir, config, report) {
|
|
1192
1245
|
const result = createEmptyResult();
|
|
1193
|
-
const filePath =
|
|
1246
|
+
const filePath = path8.join(moduleDir, "src", "index.ts");
|
|
1194
1247
|
if (!isInScope(filePath, config)) {
|
|
1195
1248
|
result.skipped.push(filePath);
|
|
1196
1249
|
return result;
|
|
@@ -1203,7 +1256,7 @@ async function ensurePackageSrcIndex(moduleDir, config, report) {
|
|
|
1203
1256
|
if (err3.code !== "ENOENT") throw err3;
|
|
1204
1257
|
}
|
|
1205
1258
|
if (!config.dryRun) {
|
|
1206
|
-
await fs5.mkdir(
|
|
1259
|
+
await fs5.mkdir(path8.dirname(filePath), { recursive: true });
|
|
1207
1260
|
}
|
|
1208
1261
|
const status = await safeWriteFileAtomic(
|
|
1209
1262
|
filePath,
|
|
@@ -1219,8 +1272,8 @@ async function reapLegacyFolders(moduleDir, config, report) {
|
|
|
1219
1272
|
const { dryRun, logger } = config;
|
|
1220
1273
|
const legacyLayers = ["domain", "application", "infrastructure"];
|
|
1221
1274
|
for (const layer of legacyLayers) {
|
|
1222
|
-
const layerPath =
|
|
1223
|
-
const relativePath =
|
|
1275
|
+
const layerPath = path8.join(moduleDir, layer);
|
|
1276
|
+
const relativePath = path8.relative(config.workspaceRoot, layerPath);
|
|
1224
1277
|
try {
|
|
1225
1278
|
const entries = await fs5.readdir(layerPath);
|
|
1226
1279
|
if (entries.length === 0) {
|
|
@@ -1694,7 +1747,7 @@ function assertValidToolchainVersion(version, source) {
|
|
|
1694
1747
|
function resolveToolchainVersion() {
|
|
1695
1748
|
{
|
|
1696
1749
|
return assertValidToolchainVersion(
|
|
1697
|
-
"0.
|
|
1750
|
+
"0.16.0",
|
|
1698
1751
|
"build-injected __HEXAGEN_TOOLCHAIN_VERSION__"
|
|
1699
1752
|
);
|
|
1700
1753
|
}
|
|
@@ -1879,7 +1932,7 @@ async function generateRootFiles(config, report) {
|
|
|
1879
1932
|
);
|
|
1880
1933
|
}
|
|
1881
1934
|
await writeRootFile(
|
|
1882
|
-
|
|
1935
|
+
path8.join(config.workspaceRoot, "package.json"),
|
|
1883
1936
|
packageJsonContent,
|
|
1884
1937
|
config,
|
|
1885
1938
|
report,
|
|
@@ -1900,7 +1953,7 @@ async function generateRootFiles(config, report) {
|
|
|
1900
1953
|
tsconfigContent = reindentJson(tsconfigContent, prettierOptions.tabWidth);
|
|
1901
1954
|
}
|
|
1902
1955
|
await writeRootFile(
|
|
1903
|
-
|
|
1956
|
+
path8.join(config.workspaceRoot, "tsconfig.base.json"),
|
|
1904
1957
|
tsconfigContent,
|
|
1905
1958
|
config,
|
|
1906
1959
|
report,
|
|
@@ -1928,7 +1981,7 @@ async function generateRootFiles(config, report) {
|
|
|
1928
1981
|
);
|
|
1929
1982
|
}
|
|
1930
1983
|
await writeRootFile(
|
|
1931
|
-
|
|
1984
|
+
path8.join(config.workspaceRoot, "turbo.json"),
|
|
1932
1985
|
turboContent,
|
|
1933
1986
|
config,
|
|
1934
1987
|
report,
|
|
@@ -1939,7 +1992,7 @@ async function generateRootFiles(config, report) {
|
|
|
1939
1992
|
BUILTIN_GITIGNORE_TEMPLATE
|
|
1940
1993
|
);
|
|
1941
1994
|
await writeRootFile(
|
|
1942
|
-
|
|
1995
|
+
path8.join(config.workspaceRoot, ".gitignore"),
|
|
1943
1996
|
interpolateAndWarn(gitignoreTemplate, vars, config, ".gitignore"),
|
|
1944
1997
|
config,
|
|
1945
1998
|
report,
|
|
@@ -1950,7 +2003,7 @@ async function generateRootFiles(config, report) {
|
|
|
1950
2003
|
BUILTIN_YARNRC_TEMPLATE
|
|
1951
2004
|
);
|
|
1952
2005
|
await writeRootFile(
|
|
1953
|
-
|
|
2006
|
+
path8.join(config.workspaceRoot, ".yarnrc.yml"),
|
|
1954
2007
|
interpolateAndWarn(yarnrcTemplate, vars, config, ".yarnrc.yml"),
|
|
1955
2008
|
config,
|
|
1956
2009
|
report,
|
|
@@ -1961,14 +2014,14 @@ async function generateRootFiles(config, report) {
|
|
|
1961
2014
|
BUILTIN_SETUP_MD_TEMPLATE
|
|
1962
2015
|
);
|
|
1963
2016
|
await writeRootFile(
|
|
1964
|
-
|
|
2017
|
+
path8.join(config.workspaceRoot, "SETUP.md"),
|
|
1965
2018
|
interpolateAndWarn(setupTemplate, vars, config, "SETUP.md"),
|
|
1966
2019
|
config,
|
|
1967
2020
|
report,
|
|
1968
2021
|
result
|
|
1969
2022
|
);
|
|
1970
2023
|
await writeRootFile(
|
|
1971
|
-
|
|
2024
|
+
path8.join(config.workspaceRoot, ".prettierrc.json"),
|
|
1972
2025
|
prettierrcContent,
|
|
1973
2026
|
config,
|
|
1974
2027
|
report,
|
|
@@ -2654,9 +2707,9 @@ async function writeManifestIfFreshExternal(config, result, report) {
|
|
|
2654
2707
|
if (config.mode !== "external") {
|
|
2655
2708
|
return;
|
|
2656
2709
|
}
|
|
2657
|
-
const archDir =
|
|
2658
|
-
const manifestPath =
|
|
2659
|
-
const relative =
|
|
2710
|
+
const archDir = path8.join(config.workspaceRoot, ".architecture");
|
|
2711
|
+
const manifestPath = path8.join(archDir, "manifest.yaml");
|
|
2712
|
+
const relative = path8.relative(config.workspaceRoot, manifestPath);
|
|
2660
2713
|
if (!isInScope(manifestPath, config)) {
|
|
2661
2714
|
config.logger.debug(`skipped (outside --only) ${relative}`);
|
|
2662
2715
|
result.skipped.push(manifestPath);
|
|
@@ -2699,7 +2752,7 @@ async function writeManifestIfFreshExternal(config, result, report) {
|
|
|
2699
2752
|
async function generateArchitectureFiles(config, report) {
|
|
2700
2753
|
const result = createEmptyResult();
|
|
2701
2754
|
const manifest = config.manifest;
|
|
2702
|
-
const archRoot =
|
|
2755
|
+
const archRoot = path8.join(config.workspaceRoot, ".architecture");
|
|
2703
2756
|
const archInvariants = manifest.monorepo?.archInvariants;
|
|
2704
2757
|
const { vars, ownershipCollisions } = buildInterpolationVars(manifest);
|
|
2705
2758
|
const workspaceTemplate = vars.workspaceTemplate ?? "modular-monolith";
|
|
@@ -2709,7 +2762,7 @@ async function generateArchitectureFiles(config, report) {
|
|
|
2709
2762
|
);
|
|
2710
2763
|
}
|
|
2711
2764
|
await writeManifestIfFreshExternal(config, result, report);
|
|
2712
|
-
const layerRulesPath =
|
|
2765
|
+
const layerRulesPath = path8.join(archRoot, "invariants", "layer-rules.yaml");
|
|
2713
2766
|
const layerRulesTemplate = resolveTemplate2(
|
|
2714
2767
|
archInvariants?.layerRules,
|
|
2715
2768
|
builtInLayerRules(workspaceTemplate)
|
|
@@ -2728,7 +2781,7 @@ async function generateArchitectureFiles(config, report) {
|
|
|
2728
2781
|
true
|
|
2729
2782
|
);
|
|
2730
2783
|
recordWriteStatus(result, layerRulesPath, layerRulesStatus);
|
|
2731
|
-
const linterConfigPath =
|
|
2784
|
+
const linterConfigPath = path8.join(
|
|
2732
2785
|
archRoot,
|
|
2733
2786
|
"invariants",
|
|
2734
2787
|
"linter-config.yaml"
|
|
@@ -2751,7 +2804,7 @@ async function generateArchitectureFiles(config, report) {
|
|
|
2751
2804
|
true
|
|
2752
2805
|
);
|
|
2753
2806
|
recordWriteStatus(result, linterConfigPath, linterConfigStatus);
|
|
2754
|
-
const generatorConfigPath =
|
|
2807
|
+
const generatorConfigPath = path8.join(archRoot, "generator.config.yaml");
|
|
2755
2808
|
const generatorConfigTemplate = resolveTemplate2(
|
|
2756
2809
|
archInvariants?.generatorConfig,
|
|
2757
2810
|
GENERATOR_CONFIG_TEMPLATE
|
|
@@ -3689,7 +3742,7 @@ ${content}`;
|
|
|
3689
3742
|
}
|
|
3690
3743
|
async function generateEslintConfig(moduleDir, moduleName, config, report, options = {}) {
|
|
3691
3744
|
const result = createEmptyResult();
|
|
3692
|
-
const filePath =
|
|
3745
|
+
const filePath = path8.join(moduleDir, "eslint.config.js");
|
|
3693
3746
|
try {
|
|
3694
3747
|
const { template, source } = resolveTemplate3(
|
|
3695
3748
|
config.manifest,
|
|
@@ -3777,9 +3830,9 @@ async function emitAppFile(appDir, relPath, template, vars, config, report, resu
|
|
|
3777
3830
|
`apps/${appName}/${relPath}`,
|
|
3778
3831
|
config
|
|
3779
3832
|
);
|
|
3780
|
-
const target =
|
|
3781
|
-
const relative =
|
|
3782
|
-
if (relative === "" || relative.startsWith("..") ||
|
|
3833
|
+
const target = path8.resolve(appDir, relPath);
|
|
3834
|
+
const relative = path8.relative(appDir, target);
|
|
3835
|
+
if (relative === "" || relative.startsWith("..") || path8.isAbsolute(relative)) {
|
|
3783
3836
|
config.logger.warn(
|
|
3784
3837
|
`[apps] skipping file with unsafe path (escapes apps/${appName}): ${relPath}`
|
|
3785
3838
|
);
|
|
@@ -3794,7 +3847,7 @@ async function emitAppFile(appDir, relPath, template, vars, config, report, resu
|
|
|
3794
3847
|
}
|
|
3795
3848
|
if (!config.dryRun && isInScope(target, config)) {
|
|
3796
3849
|
try {
|
|
3797
|
-
await fs5.mkdir(
|
|
3850
|
+
await fs5.mkdir(path8.dirname(target), { recursive: true });
|
|
3798
3851
|
} catch (err3) {
|
|
3799
3852
|
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
3800
3853
|
config.logger.error(
|
|
@@ -3885,8 +3938,8 @@ async function generateApps(config, report) {
|
|
|
3885
3938
|
version: app.version ?? "",
|
|
3886
3939
|
depends_on: (app.depends_on ?? []).join(", ")
|
|
3887
3940
|
};
|
|
3888
|
-
const appDir =
|
|
3889
|
-
const srcDir =
|
|
3941
|
+
const appDir = path8.join(config.workspaceRoot, "apps", app.name);
|
|
3942
|
+
const srcDir = path8.join(appDir, "src");
|
|
3890
3943
|
if (!config.dryRun && isInScope(appDir, config)) {
|
|
3891
3944
|
try {
|
|
3892
3945
|
await fs5.mkdir(appDir, { recursive: true });
|
|
@@ -3908,7 +3961,7 @@ async function generateApps(config, report) {
|
|
|
3908
3961
|
`apps/${app.name}/package.json`,
|
|
3909
3962
|
config
|
|
3910
3963
|
);
|
|
3911
|
-
const pkgPath =
|
|
3964
|
+
const pkgPath = path8.join(appDir, "package.json");
|
|
3912
3965
|
const status = await safeWriteFileAtomic(
|
|
3913
3966
|
pkgPath,
|
|
3914
3967
|
pkgContent,
|
|
@@ -3924,7 +3977,7 @@ async function generateApps(config, report) {
|
|
|
3924
3977
|
const tsConfig = frameworkConfig.tsConfig;
|
|
3925
3978
|
if (tsConfig) {
|
|
3926
3979
|
const tsContent = JSON.stringify(tsConfig, null, 2) + "\n";
|
|
3927
|
-
const tsPath =
|
|
3980
|
+
const tsPath = path8.join(appDir, "tsconfig.json");
|
|
3928
3981
|
const status = await safeWriteFileAtomic(
|
|
3929
3982
|
tsPath,
|
|
3930
3983
|
tsContent,
|
|
@@ -3991,14 +4044,14 @@ async function generateApps(config, report) {
|
|
|
3991
4044
|
}
|
|
3992
4045
|
}
|
|
3993
4046
|
function relativeImportSpecifier(fromFile, toFile) {
|
|
3994
|
-
let rel =
|
|
4047
|
+
let rel = path8.relative(path8.dirname(fromFile), toFile).split(path8.sep).join("/").replace(/\.tsx?$/, ".js");
|
|
3995
4048
|
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
3996
4049
|
return rel;
|
|
3997
4050
|
}
|
|
3998
4051
|
function rewriteRelativeSpecifier(specifier, fromFile, toFile) {
|
|
3999
4052
|
if (!specifier.startsWith(".")) return specifier;
|
|
4000
|
-
const absolute =
|
|
4001
|
-
let rel =
|
|
4053
|
+
const absolute = path8.resolve(path8.dirname(fromFile), specifier);
|
|
4054
|
+
let rel = path8.relative(path8.dirname(toFile), absolute).split(path8.sep).join("/");
|
|
4002
4055
|
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
4003
4056
|
return rel;
|
|
4004
4057
|
}
|
|
@@ -4054,7 +4107,28 @@ function safeParamName(name) {
|
|
|
4054
4107
|
const candidate = name.length === 0 ? "dep" : name;
|
|
4055
4108
|
return RESERVED_IDENTIFIERS.has(candidate) ? `${candidate}_` : candidate;
|
|
4056
4109
|
}
|
|
4110
|
+
var analysisMemo = /* @__PURE__ */ new Map();
|
|
4111
|
+
function resetPortAnalysisMemo() {
|
|
4112
|
+
analysisMemo.clear();
|
|
4113
|
+
}
|
|
4057
4114
|
function analyzePortFile(portFilePath) {
|
|
4115
|
+
const absolute = path8.resolve(portFilePath);
|
|
4116
|
+
let contents;
|
|
4117
|
+
try {
|
|
4118
|
+
contents = fs4.readFileSync(absolute, "utf8");
|
|
4119
|
+
} catch {
|
|
4120
|
+
return null;
|
|
4121
|
+
}
|
|
4122
|
+
const fingerprint = createHash("sha256").update(contents).digest("hex");
|
|
4123
|
+
const key = `${absolute}:${fingerprint}`;
|
|
4124
|
+
if (analysisMemo.has(key)) {
|
|
4125
|
+
return analysisMemo.get(key) ?? null;
|
|
4126
|
+
}
|
|
4127
|
+
const result = analyzePortFileUncached(absolute, contents);
|
|
4128
|
+
analysisMemo.set(key, result);
|
|
4129
|
+
return result;
|
|
4130
|
+
}
|
|
4131
|
+
function analyzePortFileUncached(portFilePath, contents) {
|
|
4058
4132
|
try {
|
|
4059
4133
|
const project = new Project({
|
|
4060
4134
|
skipAddingFilesFromTsConfig: true,
|
|
@@ -4065,7 +4139,9 @@ function analyzePortFile(portFilePath) {
|
|
|
4065
4139
|
// ESNext
|
|
4066
4140
|
}
|
|
4067
4141
|
});
|
|
4068
|
-
const sourceFile = project.
|
|
4142
|
+
const sourceFile = project.createSourceFile(portFilePath, contents, {
|
|
4143
|
+
overwrite: true
|
|
4144
|
+
});
|
|
4069
4145
|
const interfaces = sourceFile.getInterfaces().filter((i) => i.isExported());
|
|
4070
4146
|
if (interfaces.length === 0) {
|
|
4071
4147
|
return null;
|
|
@@ -4637,13 +4713,13 @@ function resolveNaming(kind, contextNaming, manifestNaming) {
|
|
|
4637
4713
|
async function writeStubFile(filePath, content, config, report) {
|
|
4638
4714
|
if (!isInScope(filePath, config)) {
|
|
4639
4715
|
config.logger.debug(
|
|
4640
|
-
`skipped (outside --only) ${
|
|
4716
|
+
`skipped (outside --only) ${path8.relative(config.workspaceRoot, filePath)}`
|
|
4641
4717
|
);
|
|
4642
4718
|
return "skipped";
|
|
4643
4719
|
}
|
|
4644
4720
|
try {
|
|
4645
4721
|
await fs5.stat(filePath);
|
|
4646
|
-
const relative =
|
|
4722
|
+
const relative = path8.relative(config.workspaceRoot, filePath);
|
|
4647
4723
|
config.logger.debug(`stub preserved ${relative}`);
|
|
4648
4724
|
if (report) {
|
|
4649
4725
|
report.record(
|
|
@@ -4659,7 +4735,7 @@ async function writeStubFile(filePath, content, config, report) {
|
|
|
4659
4735
|
}
|
|
4660
4736
|
}
|
|
4661
4737
|
if (!config.dryRun) {
|
|
4662
|
-
await fs5.mkdir(
|
|
4738
|
+
await fs5.mkdir(path8.dirname(filePath), { recursive: true });
|
|
4663
4739
|
}
|
|
4664
4740
|
return safeWriteFileAtomic(filePath, content, config, report, false);
|
|
4665
4741
|
}
|
|
@@ -4682,7 +4758,7 @@ async function tryAnalyzeRelatedPort(moduleDir, name, kind, context, relatedPort
|
|
|
4682
4758
|
`${derivedPortName}.ts`
|
|
4683
4759
|
];
|
|
4684
4760
|
for (const filename of possibleFilenames) {
|
|
4685
|
-
const portFilePath =
|
|
4761
|
+
const portFilePath = path8.join(moduleDir, portSubdir, filename);
|
|
4686
4762
|
const analysis = analyzePortFile(portFilePath);
|
|
4687
4763
|
if (analysis) {
|
|
4688
4764
|
return analysis;
|
|
@@ -4738,7 +4814,7 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
4738
4814
|
`stubs.naming.${kind}`,
|
|
4739
4815
|
interpolation
|
|
4740
4816
|
);
|
|
4741
|
-
const filePath =
|
|
4817
|
+
const filePath = path8.join(moduleDir, subdir, filename);
|
|
4742
4818
|
let content;
|
|
4743
4819
|
if (kind === "adapter" || kind === "useCase") {
|
|
4744
4820
|
const relatedPortNaming = resolveNaming(
|
|
@@ -4768,7 +4844,7 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
4768
4844
|
contextNaming,
|
|
4769
4845
|
manifestNaming
|
|
4770
4846
|
);
|
|
4771
|
-
const outPortDir =
|
|
4847
|
+
const outPortDir = path8.join(
|
|
4772
4848
|
moduleDir,
|
|
4773
4849
|
resolveEmissionDir(layersConfig, "application/ports/out")
|
|
4774
4850
|
);
|
|
@@ -4780,7 +4856,7 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
4780
4856
|
"stubs.naming.outPort",
|
|
4781
4857
|
interpolation
|
|
4782
4858
|
);
|
|
4783
|
-
const outPortPath =
|
|
4859
|
+
const outPortPath = path8.join(outPortDir, outFile);
|
|
4784
4860
|
const analyzed = analyzePortFile(outPortPath);
|
|
4785
4861
|
return {
|
|
4786
4862
|
interfaceName: analyzed?.interfaceName ?? `${base}Port`,
|
|
@@ -4883,19 +4959,19 @@ ${methodLines}
|
|
|
4883
4959
|
`;
|
|
4884
4960
|
}
|
|
4885
4961
|
async function emitPortAndAdapter(result, config, report, scope, spec) {
|
|
4886
|
-
const moduleRoot =
|
|
4962
|
+
const moduleRoot = path8.join(
|
|
4887
4963
|
config.workspaceRoot,
|
|
4888
4964
|
"packages",
|
|
4889
4965
|
spec.contextName
|
|
4890
4966
|
);
|
|
4891
|
-
const portDir =
|
|
4967
|
+
const portDir = path8.join(
|
|
4892
4968
|
moduleRoot,
|
|
4893
4969
|
"src",
|
|
4894
4970
|
"application",
|
|
4895
4971
|
"ports",
|
|
4896
4972
|
spec.portKind
|
|
4897
4973
|
);
|
|
4898
|
-
const portPath =
|
|
4974
|
+
const portPath = path8.join(
|
|
4899
4975
|
portDir,
|
|
4900
4976
|
`${spec.portBase}.${spec.portKind}-port.ts`
|
|
4901
4977
|
);
|
|
@@ -4928,8 +5004,8 @@ async function emitPortAndAdapter(result, config, report, scope, spec) {
|
|
|
4928
5004
|
);
|
|
4929
5005
|
return;
|
|
4930
5006
|
}
|
|
4931
|
-
const adapterDir =
|
|
4932
|
-
const adapterPath =
|
|
5007
|
+
const adapterDir = path8.join(moduleRoot, "src", "infrastructure", "adapters");
|
|
5008
|
+
const adapterPath = path8.join(adapterDir, `${spec.portBase}.adapter.ts`);
|
|
4933
5009
|
if (!isInScope(adapterPath, config)) {
|
|
4934
5010
|
return;
|
|
4935
5011
|
}
|
|
@@ -4961,7 +5037,7 @@ function operationImports(ops) {
|
|
|
4961
5037
|
return ops.flatMap((op) => [`${op}Request`, `${op}Response`]);
|
|
4962
5038
|
}
|
|
4963
5039
|
async function writeSharedContract(result, config, report, relSegments, content) {
|
|
4964
|
-
const contractPath =
|
|
5040
|
+
const contractPath = path8.join(
|
|
4965
5041
|
config.workspaceRoot,
|
|
4966
5042
|
"packages",
|
|
4967
5043
|
"shared",
|
|
@@ -4969,7 +5045,7 @@ async function writeSharedContract(result, config, report, relSegments, content)
|
|
|
4969
5045
|
...relSegments
|
|
4970
5046
|
);
|
|
4971
5047
|
if (!config.dryRun) {
|
|
4972
|
-
await fs5.mkdir(
|
|
5048
|
+
await fs5.mkdir(path8.dirname(contractPath), { recursive: true });
|
|
4973
5049
|
}
|
|
4974
5050
|
recordWriteStatus(
|
|
4975
5051
|
result,
|
|
@@ -5121,7 +5197,7 @@ async function generateSharedKernel(config, report) {
|
|
|
5121
5197
|
(bc) => bc.name?.toLowerCase() === "shared"
|
|
5122
5198
|
);
|
|
5123
5199
|
if (!hasShared) return result;
|
|
5124
|
-
const kernelPath =
|
|
5200
|
+
const kernelPath = path8.join(
|
|
5125
5201
|
config.workspaceRoot,
|
|
5126
5202
|
"packages",
|
|
5127
5203
|
"shared",
|
|
@@ -5141,7 +5217,7 @@ async function generateSharedKernel(config, report) {
|
|
|
5141
5217
|
if (err3.code !== "ENOENT") throw err3;
|
|
5142
5218
|
}
|
|
5143
5219
|
if (!config.dryRun) {
|
|
5144
|
-
await fs5.mkdir(
|
|
5220
|
+
await fs5.mkdir(path8.dirname(kernelPath), { recursive: true });
|
|
5145
5221
|
}
|
|
5146
5222
|
const status = await safeWriteFileAtomic(
|
|
5147
5223
|
kernelPath,
|
|
@@ -5155,12 +5231,18 @@ async function generateSharedKernel(config, report) {
|
|
|
5155
5231
|
}
|
|
5156
5232
|
var execAsync = promisify(exec);
|
|
5157
5233
|
var MAX_BUFFER = 1024 * 1024 * 10;
|
|
5158
|
-
async function ensureDependenciesBuilt(config) {
|
|
5234
|
+
async function ensureDependenciesBuilt(config, options = {}) {
|
|
5159
5235
|
const { logger, dryRun } = config;
|
|
5160
5236
|
if (dryRun) {
|
|
5161
5237
|
logger.info("Pre‑flight: skipping build in dry-run mode");
|
|
5162
5238
|
return;
|
|
5163
5239
|
}
|
|
5240
|
+
if (options.skip) {
|
|
5241
|
+
logger.info(
|
|
5242
|
+
"Preflight: build skipped (--no-preflight); the build is left to the gate"
|
|
5243
|
+
);
|
|
5244
|
+
return;
|
|
5245
|
+
}
|
|
5164
5246
|
logger.info("Pre‑flight: ensuring package dependencies are up‑to‑date...");
|
|
5165
5247
|
try {
|
|
5166
5248
|
const { stdout, stderr } = await execAsync("npx turbo run build", {
|
|
@@ -5239,21 +5321,21 @@ function mergeBarrelPasses(firstPass, secondPass) {
|
|
|
5239
5321
|
return combined;
|
|
5240
5322
|
}
|
|
5241
5323
|
function assertPathWithinArchitecture(workspaceRoot, relativePath) {
|
|
5242
|
-
const resolved =
|
|
5243
|
-
const archRoot =
|
|
5324
|
+
const resolved = path8.resolve(workspaceRoot, ".architecture", relativePath);
|
|
5325
|
+
const archRoot = path8.resolve(workspaceRoot, ".architecture");
|
|
5244
5326
|
try {
|
|
5245
5327
|
const realResolved = realpathSync(resolved);
|
|
5246
5328
|
const realArchRoot = realpathSync(archRoot);
|
|
5247
|
-
const archRootWithSep = realArchRoot +
|
|
5329
|
+
const archRootWithSep = realArchRoot + path8.sep;
|
|
5248
5330
|
if (realResolved !== realArchRoot && !realResolved.startsWith(archRootWithSep)) {
|
|
5249
5331
|
throw new Error(`Path traversal detected: "${relativePath}" resolves outside .architecture/`);
|
|
5250
5332
|
}
|
|
5251
5333
|
} catch (err3) {
|
|
5252
5334
|
if (err3 instanceof Error && "code" in err3 && err3.code === "ENOENT") {
|
|
5253
5335
|
let checkPath = archRoot;
|
|
5254
|
-
const pathSegments =
|
|
5336
|
+
const pathSegments = path8.relative(archRoot, resolved).split(path8.sep);
|
|
5255
5337
|
for (const segment of pathSegments) {
|
|
5256
|
-
checkPath =
|
|
5338
|
+
checkPath = path8.join(checkPath, segment);
|
|
5257
5339
|
try {
|
|
5258
5340
|
const stat = lstatSync(checkPath);
|
|
5259
5341
|
if (stat.isSymbolicLink()) {
|
|
@@ -5269,7 +5351,7 @@ function assertPathWithinArchitecture(workspaceRoot, relativePath) {
|
|
|
5269
5351
|
throw statErr;
|
|
5270
5352
|
}
|
|
5271
5353
|
}
|
|
5272
|
-
const archRootWithSep = archRoot +
|
|
5354
|
+
const archRootWithSep = archRoot + path8.sep;
|
|
5273
5355
|
if (resolved !== archRoot && !resolved.startsWith(archRootWithSep)) {
|
|
5274
5356
|
throw new Error(`Path traversal detected: "${relativePath}" resolves outside .architecture/`);
|
|
5275
5357
|
}
|
|
@@ -5308,7 +5390,7 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
5308
5390
|
};
|
|
5309
5391
|
if (typeof index.workspace_config === "string") {
|
|
5310
5392
|
assertPathWithinArchitecture(workspaceRoot, index.workspace_config);
|
|
5311
|
-
const sideCarPath =
|
|
5393
|
+
const sideCarPath = path8.join(workspaceRoot, ".architecture", index.workspace_config);
|
|
5312
5394
|
let sideCarContent;
|
|
5313
5395
|
try {
|
|
5314
5396
|
sideCarContent = await fs5.readFile(sideCarPath, "utf-8");
|
|
@@ -5334,7 +5416,7 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
5334
5416
|
for (const entry of indexContexts) {
|
|
5335
5417
|
const indexEntry = entry;
|
|
5336
5418
|
assertPathWithinArchitecture(workspaceRoot, indexEntry.file);
|
|
5337
|
-
const contextFilePath =
|
|
5419
|
+
const contextFilePath = path8.join(workspaceRoot, ".architecture", indexEntry.file);
|
|
5338
5420
|
let contextContent;
|
|
5339
5421
|
try {
|
|
5340
5422
|
contextContent = await fs5.readFile(contextFilePath, "utf-8");
|
|
@@ -5369,7 +5451,7 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
5369
5451
|
continue;
|
|
5370
5452
|
}
|
|
5371
5453
|
assertPathWithinArchitecture(workspaceRoot, appEntry.file);
|
|
5372
|
-
const appFilePath =
|
|
5454
|
+
const appFilePath = path8.join(workspaceRoot, ".architecture", appEntry.file);
|
|
5373
5455
|
let appContent;
|
|
5374
5456
|
try {
|
|
5375
5457
|
appContent = await fs5.readFile(appFilePath, "utf-8");
|
|
@@ -5391,14 +5473,14 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
5391
5473
|
|
|
5392
5474
|
// src/sync-engine-init.ts
|
|
5393
5475
|
var __filename$1 = fileURLToPath(import.meta.url);
|
|
5394
|
-
var __dirname$1 =
|
|
5476
|
+
var __dirname$1 = path8.dirname(__filename$1);
|
|
5395
5477
|
function isENOENT(err3) {
|
|
5396
5478
|
return err3 instanceof Error && "code" in err3 && err3.code === "ENOENT";
|
|
5397
5479
|
}
|
|
5398
5480
|
async function findRootFrom(startDir, problems) {
|
|
5399
5481
|
let currentDir = startDir;
|
|
5400
|
-
while (currentDir !==
|
|
5401
|
-
const pkgPath =
|
|
5482
|
+
while (currentDir !== path8.parse(currentDir).root) {
|
|
5483
|
+
const pkgPath = path8.join(currentDir, "package.json");
|
|
5402
5484
|
try {
|
|
5403
5485
|
const pkgContent = await fs5.readFile(pkgPath, "utf-8");
|
|
5404
5486
|
const pkg = JSON.parse(pkgContent);
|
|
@@ -5411,7 +5493,7 @@ async function findRootFrom(startDir, problems) {
|
|
|
5411
5493
|
problems.push(new Error(`${pkgPath}: ${reason}`));
|
|
5412
5494
|
}
|
|
5413
5495
|
}
|
|
5414
|
-
currentDir =
|
|
5496
|
+
currentDir = path8.dirname(currentDir);
|
|
5415
5497
|
}
|
|
5416
5498
|
return null;
|
|
5417
5499
|
}
|
|
@@ -5436,7 +5518,7 @@ async function loadManifest(workspaceRoot, flags, options) {
|
|
|
5436
5518
|
return { manifest: options.manifest, manifestMissing: false };
|
|
5437
5519
|
}
|
|
5438
5520
|
const { logger, dryRun } = flags;
|
|
5439
|
-
const manifestPath =
|
|
5521
|
+
const manifestPath = path8.join(workspaceRoot, ".architecture/manifest.yaml");
|
|
5440
5522
|
logger.debug(`[debug] __dirname (ESM): ${__dirname$1}`);
|
|
5441
5523
|
logger.debug(`[debug] resolved workspaceRoot: ${workspaceRoot}`);
|
|
5442
5524
|
logger.debug(`[debug] resolved manifestPath: ${manifestPath}`);
|
|
@@ -5559,7 +5641,7 @@ var SyncEngine = class {
|
|
|
5559
5641
|
);
|
|
5560
5642
|
continue;
|
|
5561
5643
|
}
|
|
5562
|
-
const moduleDir =
|
|
5644
|
+
const moduleDir = path8.join(this.workspaceRoot, "packages", mod.name);
|
|
5563
5645
|
logger.info(
|
|
5564
5646
|
`Ensuring directories for module: ${mod.name} at ${moduleDir}`
|
|
5565
5647
|
);
|
|
@@ -5584,7 +5666,7 @@ var SyncEngine = class {
|
|
|
5584
5666
|
const stubs = createEmptyResult();
|
|
5585
5667
|
for (const module of modules) {
|
|
5586
5668
|
const moduleName = module.name;
|
|
5587
|
-
const moduleDir =
|
|
5669
|
+
const moduleDir = path8.join(this.workspaceRoot, "packages", moduleName);
|
|
5588
5670
|
if (moduleName.includes("..") || moduleName.includes("/") || moduleName.startsWith(".")) {
|
|
5589
5671
|
logger.warn(
|
|
5590
5672
|
`Skipping invalid module name (potential path traversal): ${moduleName}`
|
|
@@ -5655,8 +5737,12 @@ var SyncEngine = class {
|
|
|
5655
5737
|
};
|
|
5656
5738
|
}
|
|
5657
5739
|
async run() {
|
|
5740
|
+
resetPortAnalysisMemo();
|
|
5658
5741
|
const { logger, dryRun, allowDirty, mode } = this.partialConfig;
|
|
5659
5742
|
const start = Date.now();
|
|
5743
|
+
let gitStatusMs = null;
|
|
5744
|
+
let preflightMs = null;
|
|
5745
|
+
let linterMs = null;
|
|
5660
5746
|
let lockFile = null;
|
|
5661
5747
|
this.journal = new SyncJournal();
|
|
5662
5748
|
this.failures = [];
|
|
@@ -5666,12 +5752,14 @@ var SyncEngine = class {
|
|
|
5666
5752
|
);
|
|
5667
5753
|
if (mode === "self-regen" && !allowDirty) {
|
|
5668
5754
|
try {
|
|
5755
|
+
const gitStart = Date.now();
|
|
5669
5756
|
const { stdout: gitStatus } = await execAsync2(
|
|
5670
5757
|
"git status --porcelain",
|
|
5671
5758
|
{
|
|
5672
5759
|
cwd: this.options?.targetRoot ?? process.cwd()
|
|
5673
5760
|
}
|
|
5674
5761
|
);
|
|
5762
|
+
gitStatusMs = Date.now() - gitStart;
|
|
5675
5763
|
if (gitStatus && gitStatus.trim().length > 0) {
|
|
5676
5764
|
logger.error(
|
|
5677
5765
|
"Git working tree is dirty. Commit or stash changes, or use --allow-dirty to proceed."
|
|
@@ -5732,10 +5820,15 @@ var SyncEngine = class {
|
|
|
5732
5820
|
}
|
|
5733
5821
|
}
|
|
5734
5822
|
if (mode === "self-regen") {
|
|
5735
|
-
|
|
5823
|
+
const preflightStart = Date.now();
|
|
5824
|
+
await ensureDependenciesBuilt(this.fullConfig, {
|
|
5825
|
+
skip: this.options?.noPreflight
|
|
5826
|
+
});
|
|
5827
|
+
preflightMs = Date.now() - preflightStart;
|
|
5736
5828
|
} else {
|
|
5737
5829
|
logger.info("Skipping preflight build (external mode)");
|
|
5738
5830
|
}
|
|
5831
|
+
const generatorsStart = Date.now();
|
|
5739
5832
|
const rootFilesResult = await generateRootFiles(
|
|
5740
5833
|
this.fullConfig,
|
|
5741
5834
|
this.report
|
|
@@ -5770,7 +5863,7 @@ var SyncEngine = class {
|
|
|
5770
5863
|
if (!moduleName || moduleName.includes("..") || moduleName.includes("/") || moduleName.startsWith(".")) {
|
|
5771
5864
|
continue;
|
|
5772
5865
|
}
|
|
5773
|
-
const moduleDir =
|
|
5866
|
+
const moduleDir = path8.join(this.workspaceRoot, "packages", moduleName);
|
|
5774
5867
|
const pass2 = await generateBarrels(
|
|
5775
5868
|
moduleDir,
|
|
5776
5869
|
this.fullConfig,
|
|
@@ -5780,6 +5873,7 @@ var SyncEngine = class {
|
|
|
5780
5873
|
mergeResult2(secondPassBarrels, pass2);
|
|
5781
5874
|
}
|
|
5782
5875
|
const barrels = mergeBarrelPasses(firstPassBarrels, secondPassBarrels);
|
|
5876
|
+
const generatorsMs = Date.now() - generatorsStart;
|
|
5783
5877
|
const rows = [
|
|
5784
5878
|
["RootFiles", rootFilesResult],
|
|
5785
5879
|
["ArchFiles", archFilesResult],
|
|
@@ -5812,14 +5906,23 @@ var SyncEngine = class {
|
|
|
5812
5906
|
runSummary.skipped += r.skipped.length;
|
|
5813
5907
|
runSummary.totalOps += r.totalOps;
|
|
5814
5908
|
}
|
|
5909
|
+
runSummary.files = buildDriftFiles(rows, this.workspaceRoot);
|
|
5815
5910
|
if (mode === "self-regen") {
|
|
5911
|
+
const linterStart = Date.now();
|
|
5816
5912
|
await runArchLinter(this.fullConfig);
|
|
5913
|
+
linterMs = Date.now() - linterStart;
|
|
5817
5914
|
await this.report.writeReport(this.fullConfig);
|
|
5818
5915
|
} else {
|
|
5819
5916
|
logger.info("Skipping arch-linter and report (external mode)");
|
|
5820
5917
|
}
|
|
5821
5918
|
const duration = Date.now() - start;
|
|
5822
5919
|
runSummary.durationMs = duration;
|
|
5920
|
+
runSummary.phaseTimingsMs = {
|
|
5921
|
+
gitStatus: gitStatusMs,
|
|
5922
|
+
preflight: preflightMs,
|
|
5923
|
+
generators: generatorsMs,
|
|
5924
|
+
linter: linterMs
|
|
5925
|
+
};
|
|
5823
5926
|
if (this.failures.length === 0) {
|
|
5824
5927
|
logger.info("\nSync completed successfully.");
|
|
5825
5928
|
} else {
|
|
@@ -5842,6 +5945,18 @@ Sync completed with ${this.failures.length} generator failure(s) — see the FAI
|
|
|
5842
5945
|
logger.error(`• ${f.row} : FAILED — ${f.message}`);
|
|
5843
5946
|
}
|
|
5844
5947
|
logger.info(`• Total ops : ${runSummary.totalOps}`);
|
|
5948
|
+
logger.info(`
|
|
5949
|
+
=== Phase Timings ===`);
|
|
5950
|
+
const phaseTimingRows = [
|
|
5951
|
+
["git status", gitStatusMs],
|
|
5952
|
+
["preflight", preflightMs],
|
|
5953
|
+
["generators", generatorsMs],
|
|
5954
|
+
["linter", linterMs]
|
|
5955
|
+
];
|
|
5956
|
+
for (const [label, value] of phaseTimingRows) {
|
|
5957
|
+
const formatted = value === null ? "skipped" : `${value}ms`;
|
|
5958
|
+
logger.info(`• ${label} : ${formatted}`);
|
|
5959
|
+
}
|
|
5845
5960
|
return runSummary;
|
|
5846
5961
|
} catch (err3) {
|
|
5847
5962
|
const message = err3 instanceof Error ? err3.message : "Unknown sync error";
|
|
@@ -5873,7 +5988,7 @@ Sync completed with ${this.failures.length} generator failure(s) — see the FAI
|
|
|
5873
5988
|
} else {
|
|
5874
5989
|
for (const f of outcome.failures) {
|
|
5875
5990
|
logger.error(
|
|
5876
|
-
`Rollback failed for ${
|
|
5991
|
+
`Rollback failed for ${path8.relative(this.workspaceRoot, f.path)}: intended to ${f.intended} — ${f.error}`
|
|
5877
5992
|
);
|
|
5878
5993
|
}
|
|
5879
5994
|
logger.error(
|
|
@@ -6014,7 +6129,7 @@ function err2(error) {
|
|
|
6014
6129
|
var execAsync3 = promisify(exec);
|
|
6015
6130
|
async function loadManifest2(workspaceRoot) {
|
|
6016
6131
|
try {
|
|
6017
|
-
const manifestPath =
|
|
6132
|
+
const manifestPath = path8.join(
|
|
6018
6133
|
workspaceRoot,
|
|
6019
6134
|
".architecture/manifest.yaml"
|
|
6020
6135
|
);
|
|
@@ -6055,7 +6170,7 @@ async function validateManifest2(workspaceRoot) {
|
|
|
6055
6170
|
}
|
|
6056
6171
|
async function saveManifest(workspaceRoot, manifest) {
|
|
6057
6172
|
try {
|
|
6058
|
-
const manifestPath =
|
|
6173
|
+
const manifestPath = path8.join(
|
|
6059
6174
|
workspaceRoot,
|
|
6060
6175
|
".architecture/manifest.yaml"
|
|
6061
6176
|
);
|
|
@@ -6067,6 +6182,6 @@ async function saveManifest(workspaceRoot, manifest) {
|
|
|
6067
6182
|
}
|
|
6068
6183
|
}
|
|
6069
6184
|
|
|
6070
|
-
export { DEFAULT_NAMING, DEFAULT_TEMPLATES, SyncEngine, createEmptyResult, err2 as err, isIndexManifest, loadManifest2 as loadManifest, mergeSplitManifest, ok2 as ok, parseArgs, portName, recordWriteStatus, sanitizeScope, saveManifest, validateManifest2 as validateManifest };
|
|
6185
|
+
export { DEFAULT_NAMING, DEFAULT_TEMPLATES, SyncEngine, buildDriftFiles, createEmptyResult, err2 as err, isIndexManifest, loadManifest2 as loadManifest, mergeSplitManifest, ok2 as ok, parseArgs, portName, recordWriteStatus, sanitizeScope, saveManifest, validateManifest2 as validateManifest };
|
|
6071
6186
|
//# sourceMappingURL=index.js.map
|
|
6072
6187
|
//# sourceMappingURL=index.js.map
|