@hexagen-monaco/sync 0.5.2 → 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 +1610 -620
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +24 -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 +17 -4
- package/dist/fs-utils.d.ts.map +1 -1
- package/dist/generators/apps-framework-templates.d.ts +2 -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 +5 -0
- package/dist/generators/cross-context.d.ts.map +1 -0
- package/dist/generators/eslint.d.ts +3 -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/port-analyzer.d.ts +38 -4
- package/dist/generators/port-analyzer.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 +4 -4
- 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 +23 -0
- package/dist/generators/shared-kernel.d.ts.map +1 -0
- package/dist/generators/stubs.d.ts +13 -0
- package/dist/generators/stubs.d.ts.map +1 -1
- package/dist/generators/tsconfig.d.ts.map +1 -1
- package/dist/index.js +1441 -470
- 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/scope-filter.d.ts +35 -0
- package/dist/scope-filter.d.ts.map +1 -0
- 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/templates/adobe-creative-production/manifest.json +2 -0
- package/dist/templates/adobe-express/manifest.json +2 -0
- package/dist/templates/adobe-firefly-composite/manifest.json +2 -0
- package/dist/templates/adobe-firefly-content-tagging/manifest.json +2 -0
- package/dist/templates/adobe-firefly-core/manifest.json +2 -0
- package/dist/templates/adobe-firefly-custom-models/manifest.json +2 -0
- package/dist/templates/adobe-firefly-generate/manifest.json +2 -0
- package/dist/templates/adobe-firefly-media/manifest.json +2 -0
- package/dist/templates/adobe-firefly-storage-azure/manifest.json +2 -0
- package/dist/templates/adobe-firefly-storage-gcs/manifest.json +2 -0
- package/dist/templates/adobe-firefly-storage-s3/manifest.json +2 -0
- package/dist/templates/adobe-firefly-upscale/manifest.json +2 -0
- package/dist/templates/adobe-illustrator/manifest.json +2 -0
- package/dist/templates/adobe-ims-spa/manifest.json +2 -0
- package/dist/templates/adobe-indesign/manifest.json +2 -0
- package/dist/templates/adobe-lightroom/manifest.json +2 -0
- package/dist/templates/adobe-photoshop/manifest.json +2 -0
- package/dist/templates/adobe-substance-3d/manifest.json +2 -0
- package/dist/templates/auth-mock/manifest.json +2 -0
- package/dist/templates/bedrock-agentcore-runtime/manifest.json +10 -2
- package/dist/templates/bedrock-agentcore-services/manifest.json +38 -9
- package/dist/templates/better-auth/manifest.json +2 -0
- package/dist/templates/bullmq/manifest.json +2 -0
- package/dist/templates/ci-github-actions/README.md +7 -0
- package/dist/templates/ci-github-actions/files/.github/dependabot.yml +16 -4
- package/dist/templates/ci-github-actions/files/.github/workflows/ci.yml +7 -3
- package/dist/templates/ci-github-actions/files/.github/workflows/preview.yml +20 -2
- package/dist/templates/ci-github-actions/manifest.json +26 -6
- package/dist/templates/clerk/manifest.json +2 -0
- package/dist/templates/design-system/manifest.json +14 -3
- package/dist/templates/docker/manifest.json +2 -0
- package/dist/templates/error-handling/manifest.json +2 -0
- package/dist/templates/eslint-no-console/manifest.json +2 -0
- package/dist/templates/github-oauth/manifest.json +2 -0
- package/dist/templates/google-oauth/manifest.json +2 -0
- package/dist/templates/langgraph/manifest.json +62 -15
- package/dist/templates/llm-adapter/manifest.json +2 -0
- package/dist/templates/magic-link/manifest.json +2 -0
- package/dist/templates/mcp-server/README.md +49 -0
- package/dist/templates/mcp-server/files/.env.mcp.example +6 -0
- package/dist/templates/mcp-server/files/.mcp.json.example +8 -0
- package/dist/templates/mcp-server/files/bin/cli.ts +15 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/prompts/example.prompt.ts +32 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/registry/register-all.ts +11 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/registry/tool-registry.test.ts +67 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/registry/tool-registry.ts +45 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/resources/example.resource.ts +28 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/sdk.ts +41 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/server.ts +52 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/tools/example.tool.test.ts +31 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/tools/example.tool.ts +74 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/transport/register-transports.ts +15 -0
- package/dist/templates/mcp-server/files/src/infrastructure/mcp/transport/stdio.ts +14 -0
- package/dist/templates/mcp-server/manifest.json +68 -0
- package/dist/templates/mcp-server-http/README.md +98 -0
- package/dist/templates/mcp-server-http/files/.env.mcp-http.example +22 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/auth/bearer.test.ts +54 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/auth/bearer.ts +49 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/auth/oauth.test.ts +50 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/auth/oauth.ts +53 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/guard.test.ts +75 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/guard.ts +26 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/transport/http.ts +94 -0
- package/dist/templates/mcp-server-http/files/src/infrastructure/mcp/transport/register-transports.ts +15 -0
- package/dist/templates/mcp-server-http/manifest.json +56 -0
- package/dist/templates/microsoft-entra/manifest.json +2 -0
- package/dist/templates/nextauth/manifest.json +2 -0
- package/dist/templates/observability/manifest.json +10 -2
- package/dist/templates/rate-limiting/manifest.json +2 -0
- package/dist/templates/shared-types/manifest.json +2 -0
- package/dist/templates/supabase/manifest.json +2 -0
- package/dist/templates/supabase-auth/manifest.json +2 -0
- package/dist/toolchain-version.d.ts +14 -0
- package/dist/toolchain-version.d.ts.map +1 -0
- package/dist/types/manifest/apps.d.ts +12 -1
- package/dist/types/manifest/apps.d.ts.map +1 -1
- 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/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import path7 from 'path';
|
|
2
|
+
import fs4, { realpathSync, lstatSync, createWriteStream } from 'fs';
|
|
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
7
|
import crypto from 'crypto';
|
|
8
|
-
import { Project, MethodSignature } from 'ts-morph';
|
|
9
8
|
import { fileURLToPath } from 'url';
|
|
9
|
+
import { Project, MethodSignature } from 'ts-morph';
|
|
10
10
|
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
12
12
|
var __export = (target, all) => {
|
|
@@ -19,26 +19,132 @@ var MigrationReport = class {
|
|
|
19
19
|
this.entries.push({ type, target, message });
|
|
20
20
|
}
|
|
21
21
|
async writeReport(config) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
if (config.dryRun && !config.report) {
|
|
23
|
+
const counts = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const e of this.entries) {
|
|
25
|
+
counts.set(e.type, (counts.get(e.type) ?? 0) + 1);
|
|
26
|
+
}
|
|
27
|
+
const breakdown = [...counts.entries()].map(([type, n]) => `${n} ${type}`).join(", ");
|
|
28
|
+
config.logger.info(
|
|
29
|
+
`[DRY-RUN] skipping migration report file (${this.entries.length} entries${breakdown ? `: ${breakdown}` : ""}) — pass --report <path> to write it anyway`
|
|
30
|
+
);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const reportPath = config.report ? path7.resolve(config.workspaceRoot, config.report) : path7.join(config.workspaceRoot, "SYNC-MIGRATION-REPORT.md");
|
|
34
|
+
await fs5.mkdir(path7.dirname(reportPath), { recursive: true });
|
|
35
|
+
let preContent = null;
|
|
36
|
+
try {
|
|
37
|
+
preContent = await fs5.readFile(reportPath, "utf8");
|
|
38
|
+
} catch (e) {
|
|
39
|
+
if (!(e instanceof Error && "code" in e && e.code === "ENOENT"))
|
|
40
|
+
throw e;
|
|
41
|
+
}
|
|
42
|
+
config.journal?.recordWrite(reportPath, preContent);
|
|
26
43
|
const stream = createWriteStream(reportPath, { flags: "w" });
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
stream.write(
|
|
30
|
-
|
|
44
|
+
await new Promise((resolve, reject) => {
|
|
45
|
+
stream.on("error", reject);
|
|
46
|
+
stream.write("# Sync Migration Report\n\n");
|
|
47
|
+
for (const e of this.entries) {
|
|
48
|
+
stream.write(
|
|
49
|
+
`- ${e.type.toUpperCase()}: ${e.target}${e.message ? ` – ${e.message}` : ""}
|
|
31
50
|
`
|
|
32
|
-
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
stream.end(resolve);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var SyncJournal = class {
|
|
58
|
+
entries = [];
|
|
59
|
+
/**
|
|
60
|
+
* Record a write BEFORE it is attempted. `preContent: null` means the file
|
|
61
|
+
* did not exist (a create); a string is the full pre-image of an overwrite.
|
|
62
|
+
* Over-recording is safe: rolling back a write that never happened either
|
|
63
|
+
* restores identical content or unlinks a file that is not there (ENOENT
|
|
64
|
+
* tolerated below). Under-recording loses user data — so mutation sites
|
|
65
|
+
* record first, mutate second.
|
|
66
|
+
*/
|
|
67
|
+
recordWrite(filePath, preContent) {
|
|
68
|
+
this.entries.push({
|
|
69
|
+
path: filePath,
|
|
70
|
+
kind: preContent === null ? "created" : "overwritten",
|
|
71
|
+
preContent
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/** Record a deletion BEFORE the unlink, with the full pre-image. */
|
|
75
|
+
recordDelete(filePath, preContent) {
|
|
76
|
+
this.entries.push({ path: filePath, kind: "deleted", preContent });
|
|
77
|
+
}
|
|
78
|
+
get size() {
|
|
79
|
+
return this.entries.length;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Human-readable journal lines (workspace-relative), oldest first — printed
|
|
83
|
+
* verbatim when a failed run must NOT roll back (--allow-dirty).
|
|
84
|
+
*/
|
|
85
|
+
describeEntries(workspaceRoot) {
|
|
86
|
+
return this.entries.map(
|
|
87
|
+
(e) => `${e.kind} ${path7.relative(workspaceRoot, e.path)}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Replay the journal in REVERSE order: restore pre-images, unlink created
|
|
92
|
+
* files. Reverse order makes repeated writes to the same path converge on
|
|
93
|
+
* the OLDEST pre-image (pass-1 barrel pre-image is restored last), i.e. the
|
|
94
|
+
* true pre-sync state.
|
|
95
|
+
*
|
|
96
|
+
* Per-entry best-effort: a failing inverse op is collected and replay
|
|
97
|
+
* CONTINUES — restoring nine of ten files beats aborting at the first
|
|
98
|
+
* error. The caller prints the failures; nothing here (or anywhere) falls
|
|
99
|
+
* back to a git-wide reset/clean.
|
|
100
|
+
*
|
|
101
|
+
* Restores use a plain writeFile, not the atomic tmp+rename protocol: the
|
|
102
|
+
* rollback may be running on the same broken substrate that failed the
|
|
103
|
+
* sync, and the simplest possible write maximizes the odds of getting the
|
|
104
|
+
* user's bytes back on disk.
|
|
105
|
+
*/
|
|
106
|
+
async rollback(logger, workspaceRoot) {
|
|
107
|
+
const outcome = {
|
|
108
|
+
attempted: this.entries.length,
|
|
109
|
+
restored: 0,
|
|
110
|
+
failures: []
|
|
111
|
+
};
|
|
112
|
+
for (const entry of [...this.entries].reverse()) {
|
|
113
|
+
const relative = path7.relative(workspaceRoot, entry.path);
|
|
114
|
+
try {
|
|
115
|
+
if (entry.preContent === null) {
|
|
116
|
+
try {
|
|
117
|
+
await fs5.unlink(entry.path);
|
|
118
|
+
} catch (err3) {
|
|
119
|
+
if (!(err3 instanceof Error && "code" in err3 && err3.code === "ENOENT")) {
|
|
120
|
+
throw err3;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
logger.info(`rolled back (removed) ${relative}`);
|
|
124
|
+
} else {
|
|
125
|
+
await fs5.mkdir(path7.dirname(entry.path), { recursive: true });
|
|
126
|
+
await fs5.writeFile(entry.path, entry.preContent, {
|
|
127
|
+
encoding: "utf8"
|
|
128
|
+
});
|
|
129
|
+
logger.info(`rolled back (restored) ${relative}`);
|
|
130
|
+
}
|
|
131
|
+
outcome.restored += 1;
|
|
132
|
+
} catch (err3) {
|
|
133
|
+
outcome.failures.push({
|
|
134
|
+
path: entry.path,
|
|
135
|
+
intended: entry.preContent === null ? "remove created file" : "restore pre-image",
|
|
136
|
+
error: err3 instanceof Error ? err3.message : String(err3)
|
|
137
|
+
});
|
|
138
|
+
}
|
|
33
139
|
}
|
|
34
|
-
|
|
140
|
+
return outcome;
|
|
35
141
|
}
|
|
36
142
|
};
|
|
37
143
|
var LOCK_FILE = ".architecture/.sync.lock";
|
|
38
144
|
var LockFile = class {
|
|
39
|
-
constructor(workspaceRoot, fsImpl =
|
|
145
|
+
constructor(workspaceRoot, fsImpl = fs5, logger = console) {
|
|
40
146
|
this.workspaceRoot = workspaceRoot;
|
|
41
|
-
this.lockPath =
|
|
147
|
+
this.lockPath = path7.join(workspaceRoot, LOCK_FILE);
|
|
42
148
|
this.fsImpl = fsImpl;
|
|
43
149
|
this.logger = logger;
|
|
44
150
|
}
|
|
@@ -105,11 +211,11 @@ var LockFile = class {
|
|
|
105
211
|
};
|
|
106
212
|
var BIN_NAME = process.platform === "win32" ? "hexagen-lint.cmd" : "hexagen-lint";
|
|
107
213
|
function resolveArchLinterBin(startDir) {
|
|
108
|
-
let dir =
|
|
214
|
+
let dir = path7.resolve(startDir);
|
|
109
215
|
for (; ; ) {
|
|
110
|
-
const candidate =
|
|
111
|
-
if (
|
|
112
|
-
const parent =
|
|
216
|
+
const candidate = path7.join(dir, "node_modules", ".bin", BIN_NAME);
|
|
217
|
+
if (fs4.existsSync(candidate)) return candidate;
|
|
218
|
+
const parent = path7.dirname(dir);
|
|
113
219
|
if (parent === dir) return null;
|
|
114
220
|
dir = parent;
|
|
115
221
|
}
|
|
@@ -155,9 +261,64 @@ function createEmptyResult() {
|
|
|
155
261
|
created: [],
|
|
156
262
|
skipped: [],
|
|
157
263
|
updated: [],
|
|
264
|
+
deleted: [],
|
|
265
|
+
unchanged: [],
|
|
158
266
|
totalOps: 0
|
|
159
267
|
};
|
|
160
268
|
}
|
|
269
|
+
function recordWriteStatus(result, filePath, status) {
|
|
270
|
+
if (status === "created") {
|
|
271
|
+
result.created.push(filePath);
|
|
272
|
+
result.totalOps += 1;
|
|
273
|
+
} else if (status === "updated") {
|
|
274
|
+
result.updated.push(filePath);
|
|
275
|
+
result.totalOps += 1;
|
|
276
|
+
} else if (status === "unchanged") {
|
|
277
|
+
result.unchanged.push(filePath);
|
|
278
|
+
} else {
|
|
279
|
+
result.skipped.push(filePath);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/scope-filter.ts
|
|
284
|
+
var GLOB_META = /[*?]/;
|
|
285
|
+
function normalize(p) {
|
|
286
|
+
return p.replace(/\\/g, "/").replace(/^\.?\//, "").replace(/\/+$/, "");
|
|
287
|
+
}
|
|
288
|
+
function globToRegExp(glob) {
|
|
289
|
+
let re = "";
|
|
290
|
+
for (let i = 0; i < glob.length; i++) {
|
|
291
|
+
const c = glob[i];
|
|
292
|
+
if (c === "*") {
|
|
293
|
+
if (glob[i + 1] === "*") {
|
|
294
|
+
re += ".*";
|
|
295
|
+
i++;
|
|
296
|
+
} else {
|
|
297
|
+
re += "[^/]*";
|
|
298
|
+
}
|
|
299
|
+
} else if (c === "?") {
|
|
300
|
+
re += "[^/]";
|
|
301
|
+
} else if ("\\^$.|+()[]{}".includes(c)) {
|
|
302
|
+
re += `\\${c}`;
|
|
303
|
+
} else {
|
|
304
|
+
re += c;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return new RegExp(`^${re}$`);
|
|
308
|
+
}
|
|
309
|
+
function matchesScope(relativePath, patterns) {
|
|
310
|
+
const rel = normalize(relativePath);
|
|
311
|
+
return patterns.some((raw) => {
|
|
312
|
+
const pat = normalize(raw);
|
|
313
|
+
if (pat === "") return false;
|
|
314
|
+
if (!GLOB_META.test(pat)) {
|
|
315
|
+
return rel === pat || rel.startsWith(`${pat}/`);
|
|
316
|
+
}
|
|
317
|
+
return globToRegExp(pat).test(rel);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// src/fs-utils.ts
|
|
161
322
|
var GENERATED_MARKER = "// @generated by @hexagen/sync";
|
|
162
323
|
var protectedFiles = /* @__PURE__ */ new Set([
|
|
163
324
|
".gitignore",
|
|
@@ -184,20 +345,29 @@ function isGeneratedFile(content) {
|
|
|
184
345
|
return content.includes(GENERATED_MARKER);
|
|
185
346
|
}
|
|
186
347
|
function isProtectedRoot(filePath, config) {
|
|
187
|
-
const relative =
|
|
348
|
+
const relative = path7.relative(config.workspaceRoot, filePath);
|
|
188
349
|
const isRootLevel = !relative.startsWith("packages/") && !relative.startsWith("tools/") && !relative.startsWith("apps/");
|
|
189
350
|
return isRootLevel && Array.from(protectedFiles).some(
|
|
190
351
|
(f) => relative.endsWith(f) || relative.includes(f)
|
|
191
352
|
);
|
|
192
353
|
}
|
|
354
|
+
function isInScope(filePath, config) {
|
|
355
|
+
if (!config.only || config.only.length === 0) return true;
|
|
356
|
+
const relativePath = path7.relative(config.workspaceRoot, filePath);
|
|
357
|
+
return matchesScope(relativePath, config.only);
|
|
358
|
+
}
|
|
193
359
|
async function safeWriteFileAtomic(filePath, content, config, report, skipGeneratedCheck = false) {
|
|
194
360
|
const { dryRun, forceRoot, logger, workspaceRoot } = config;
|
|
195
|
-
const relativePath =
|
|
361
|
+
const relativePath = path7.relative(workspaceRoot, filePath);
|
|
362
|
+
if (!isInScope(filePath, config)) {
|
|
363
|
+
logger.debug(`skipped (outside --only) ${relativePath}`);
|
|
364
|
+
return "skipped";
|
|
365
|
+
}
|
|
196
366
|
let exists = false;
|
|
197
367
|
let currentContent = "";
|
|
198
368
|
let currentHash = "";
|
|
199
369
|
try {
|
|
200
|
-
currentContent = await
|
|
370
|
+
currentContent = await fs5.readFile(filePath, "utf8");
|
|
201
371
|
currentHash = contentHash(currentContent);
|
|
202
372
|
exists = true;
|
|
203
373
|
} catch (e) {
|
|
@@ -209,36 +379,39 @@ async function safeWriteFileAtomic(filePath, content, config, report, skipGenera
|
|
|
209
379
|
logger.debug(`unchanged ${relativePath}`);
|
|
210
380
|
return "unchanged";
|
|
211
381
|
}
|
|
212
|
-
if (dryRun) {
|
|
213
|
-
const action = exists ? "update" : "create";
|
|
214
|
-
logger.info(`[DRY-RUN] would ${action} ${relativePath}`);
|
|
215
|
-
return exists ? "updated" : "created";
|
|
216
|
-
}
|
|
217
382
|
if (isProtectedRoot(filePath, config) && !forceRoot) {
|
|
218
|
-
|
|
383
|
+
const verb = dryRun ? "[DRY-RUN] would skip" : "skipped";
|
|
384
|
+
logger.warn(`${verb} (root protected, use --force-root) ${relativePath}`);
|
|
219
385
|
if (report) report.record("blocked", filePath, "Root file protected");
|
|
220
386
|
return "protected";
|
|
221
387
|
}
|
|
222
388
|
if (exists && !forceRoot && !skipGeneratedCheck && !isGeneratedFile(currentContent)) {
|
|
389
|
+
const verb = dryRun ? "[DRY-RUN] would skip" : "skipped";
|
|
223
390
|
logger.warn(
|
|
224
|
-
|
|
391
|
+
`${verb} (hand-written, use --force-root to overwrite) ${relativePath}`
|
|
225
392
|
);
|
|
226
393
|
return "skipped";
|
|
227
394
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
395
|
+
if (dryRun) {
|
|
396
|
+
const action = exists ? "update" : "create";
|
|
397
|
+
logger.info(`[DRY-RUN] would ${action} ${relativePath}`);
|
|
398
|
+
return exists ? "updated" : "created";
|
|
399
|
+
}
|
|
400
|
+
config.journal?.recordWrite(filePath, exists ? currentContent : null);
|
|
401
|
+
await fs5.mkdir(path7.dirname(filePath), { recursive: true });
|
|
402
|
+
const tmpName = `.${path7.basename(filePath)}.${crypto.randomUUID()}.tmp`;
|
|
403
|
+
const tmpPath = path7.join(path7.dirname(filePath), tmpName);
|
|
404
|
+
await fs5.writeFile(tmpPath, content, { encoding: "utf8" });
|
|
232
405
|
try {
|
|
233
|
-
await
|
|
406
|
+
await fs5.rename(tmpPath, filePath);
|
|
234
407
|
const status = exists ? "updated" : "created";
|
|
235
408
|
logger.info(`${status} ${relativePath}`);
|
|
236
409
|
return status;
|
|
237
410
|
} catch (err3) {
|
|
238
411
|
if (err3 instanceof Error && "code" in err3 && err3.code === "EXDEV") {
|
|
239
412
|
try {
|
|
240
|
-
await
|
|
241
|
-
await
|
|
413
|
+
await fs5.copyFile(tmpPath, filePath);
|
|
414
|
+
await fs5.unlink(tmpPath);
|
|
242
415
|
const status = exists ? "updated" : "created";
|
|
243
416
|
logger.info(`${status} ${relativePath}`);
|
|
244
417
|
return status;
|
|
@@ -246,7 +419,7 @@ async function safeWriteFileAtomic(filePath, content, config, report, skipGenera
|
|
|
246
419
|
logger.warn(`EXDEV fallback failed for ${relativePath}: ${copyErr}`);
|
|
247
420
|
}
|
|
248
421
|
}
|
|
249
|
-
await
|
|
422
|
+
await fs5.unlink(tmpPath).catch(() => {
|
|
250
423
|
});
|
|
251
424
|
throw err3;
|
|
252
425
|
}
|
|
@@ -262,48 +435,45 @@ async function safeWriteFile(filePath, content, config, skipGeneratedCheck = fal
|
|
|
262
435
|
}
|
|
263
436
|
|
|
264
437
|
// src/generators/layer-folders.ts
|
|
265
|
-
|
|
266
|
-
async function loadYamlSafe(filePath) {
|
|
438
|
+
async function directoryExists(dirPath) {
|
|
267
439
|
try {
|
|
268
|
-
const
|
|
269
|
-
return
|
|
440
|
+
const stats = await fs5.stat(dirPath);
|
|
441
|
+
return stats.isDirectory();
|
|
270
442
|
} catch (e) {
|
|
271
443
|
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
|
|
272
|
-
return
|
|
444
|
+
return false;
|
|
273
445
|
}
|
|
274
446
|
throw e;
|
|
275
447
|
}
|
|
276
448
|
}
|
|
277
|
-
async function
|
|
278
|
-
const
|
|
449
|
+
async function ensureDirectoryCounted(dirPath, config, result) {
|
|
450
|
+
const existed = await directoryExists(dirPath);
|
|
451
|
+
if (existed) return;
|
|
452
|
+
const relativePath = path7.relative(config.workspaceRoot, dirPath);
|
|
453
|
+
if (config.dryRun) {
|
|
454
|
+
config.logger.info(`[DRY-RUN] would create directory ${relativePath}`);
|
|
455
|
+
} else {
|
|
456
|
+
await fs5.mkdir(dirPath, { recursive: true });
|
|
457
|
+
config.logger.info(`created directory ${relativePath}`);
|
|
458
|
+
}
|
|
459
|
+
result.created.push(dirPath);
|
|
460
|
+
result.totalOps += 1;
|
|
461
|
+
}
|
|
462
|
+
async function loadYamlSafe(filePath) {
|
|
279
463
|
try {
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
if (entry.name === "index.ts" || entry.name.startsWith(".")) continue;
|
|
283
|
-
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
284
|
-
const base = entry.name.replace(/\.ts$/, "");
|
|
285
|
-
exportLines.push(`export * from './${base}.js';`);
|
|
286
|
-
} else if (entry.isDirectory()) {
|
|
287
|
-
exportLines.push(`export * from './${entry.name}/index.js';`);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
464
|
+
const content = await fs5.readFile(filePath, "utf8");
|
|
465
|
+
return yaml3.load(content);
|
|
290
466
|
} catch (e) {
|
|
291
|
-
if (e instanceof Error && "code" in e && e.code === "ENOENT")
|
|
292
|
-
|
|
467
|
+
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
|
|
468
|
+
return null;
|
|
293
469
|
}
|
|
470
|
+
throw e;
|
|
294
471
|
}
|
|
295
|
-
return exportLines.length > 0 ? `${GENERATED_MARKER2}
|
|
296
|
-
|
|
297
|
-
${exportLines.join("\n")}
|
|
298
|
-
` : `${GENERATED_MARKER2}
|
|
299
|
-
|
|
300
|
-
// No exports yet
|
|
301
|
-
`;
|
|
302
472
|
}
|
|
303
|
-
async function ensureLayerFolders(moduleDir, layers, config
|
|
473
|
+
async function ensureLayerFolders(moduleDir, layers, config) {
|
|
304
474
|
const result = createEmptyResult();
|
|
305
475
|
const { logger } = config;
|
|
306
|
-
const layerRulesPath =
|
|
476
|
+
const layerRulesPath = path7.join(
|
|
307
477
|
config.workspaceRoot,
|
|
308
478
|
".architecture",
|
|
309
479
|
"invariants",
|
|
@@ -314,58 +484,18 @@ async function ensureLayerFolders(moduleDir, layers, config, report) {
|
|
|
314
484
|
logger.warn("layer-rules.yaml not found — skipping layer rule enforcement");
|
|
315
485
|
}
|
|
316
486
|
for (const [, layerConfig] of Object.entries(layers)) {
|
|
317
|
-
const layerPath =
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
result.created.push(layerPath);
|
|
321
|
-
result.totalOps += 1;
|
|
322
|
-
} catch (e) {
|
|
323
|
-
if (e instanceof Error && "code" in e && e.code === "EEXIST") {
|
|
324
|
-
result.skipped.push(layerPath);
|
|
325
|
-
} else {
|
|
326
|
-
throw e;
|
|
327
|
-
}
|
|
487
|
+
const layerPath = path7.join(moduleDir, layerConfig.folder);
|
|
488
|
+
if (!isInScope(layerPath, config) && !isInScope(path7.join(layerPath, "index.ts"), config)) {
|
|
489
|
+
continue;
|
|
328
490
|
}
|
|
329
|
-
|
|
330
|
-
const barrelContent = await generateBarrelContent(layerPath);
|
|
331
|
-
const barrelStatus = await safeWriteFileAtomic(
|
|
332
|
-
barrelPath,
|
|
333
|
-
barrelContent,
|
|
334
|
-
config,
|
|
335
|
-
report
|
|
336
|
-
);
|
|
337
|
-
if (barrelStatus === "created") result.created.push(barrelPath);
|
|
338
|
-
if (barrelStatus === "updated") result.updated.push(barrelPath);
|
|
339
|
-
if (barrelStatus === "skipped" || barrelStatus === "protected")
|
|
340
|
-
result.skipped.push(barrelPath);
|
|
341
|
-
result.totalOps += barrelStatus === "created" || barrelStatus === "updated" ? 1 : 0;
|
|
491
|
+
await ensureDirectoryCounted(layerPath, config, result);
|
|
342
492
|
const subfolders = layerConfig.subfolders ?? [];
|
|
343
493
|
for (const sub of subfolders) {
|
|
344
|
-
const subPath =
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
result.created.push(subPath);
|
|
348
|
-
result.totalOps += 1;
|
|
349
|
-
} catch (e) {
|
|
350
|
-
if (e instanceof Error && "code" in e && e.code === "EEXIST") {
|
|
351
|
-
result.skipped.push(subPath);
|
|
352
|
-
} else {
|
|
353
|
-
throw e;
|
|
354
|
-
}
|
|
494
|
+
const subPath = path7.join(layerPath, sub);
|
|
495
|
+
if (!isInScope(subPath, config) && !isInScope(path7.join(subPath, "index.ts"), config)) {
|
|
496
|
+
continue;
|
|
355
497
|
}
|
|
356
|
-
|
|
357
|
-
const subBarrelContent = await generateBarrelContent(subPath);
|
|
358
|
-
const subBarrelStatus = await safeWriteFileAtomic(
|
|
359
|
-
subBarrelPath,
|
|
360
|
-
subBarrelContent,
|
|
361
|
-
config,
|
|
362
|
-
report
|
|
363
|
-
);
|
|
364
|
-
if (subBarrelStatus === "created") result.created.push(subBarrelPath);
|
|
365
|
-
if (subBarrelStatus === "updated") result.updated.push(subBarrelPath);
|
|
366
|
-
if (subBarrelStatus === "skipped" || subBarrelStatus === "protected")
|
|
367
|
-
result.skipped.push(subBarrelPath);
|
|
368
|
-
result.totalOps += subBarrelStatus === "created" || subBarrelStatus === "updated" ? 1 : 0;
|
|
498
|
+
await ensureDirectoryCounted(subPath, config, result);
|
|
369
499
|
}
|
|
370
500
|
}
|
|
371
501
|
return result;
|
|
@@ -386,10 +516,10 @@ var BARREL_EXCLUSIONS = /* @__PURE__ */ new Set([
|
|
|
386
516
|
function isExcludedDirectory(name) {
|
|
387
517
|
return BARREL_EXCLUSIONS.has(name) || name.startsWith(".");
|
|
388
518
|
}
|
|
389
|
-
var
|
|
519
|
+
var GENERATED_MARKER2 = "// @generated by @hexagen/sync";
|
|
390
520
|
var LEGACY_GENERATED_MARKER = "— generated by sync.ts";
|
|
391
521
|
function isGeneratedFile2(content) {
|
|
392
|
-
return content.includes(
|
|
522
|
+
return content.includes(GENERATED_MARKER2) || content.includes(LEGACY_GENERATED_MARKER);
|
|
393
523
|
}
|
|
394
524
|
function contentHash2(content) {
|
|
395
525
|
return crypto.createHash("sha256").update(content).digest("hex");
|
|
@@ -397,18 +527,18 @@ function contentHash2(content) {
|
|
|
397
527
|
function detectCircularExports(exportGraph) {
|
|
398
528
|
const visited = /* @__PURE__ */ new Set();
|
|
399
529
|
const recursionStack = /* @__PURE__ */ new Set();
|
|
400
|
-
const
|
|
530
|
+
const path25 = [];
|
|
401
531
|
function dfs(node) {
|
|
402
532
|
if (recursionStack.has(node)) {
|
|
403
|
-
const cycleStart =
|
|
404
|
-
return [...
|
|
533
|
+
const cycleStart = path25.indexOf(node);
|
|
534
|
+
return [...path25.slice(cycleStart), node];
|
|
405
535
|
}
|
|
406
536
|
if (visited.has(node)) {
|
|
407
537
|
return null;
|
|
408
538
|
}
|
|
409
539
|
visited.add(node);
|
|
410
540
|
recursionStack.add(node);
|
|
411
|
-
|
|
541
|
+
path25.push(node);
|
|
412
542
|
const exports$1 = exportGraph.get(node) ?? [];
|
|
413
543
|
for (const exportPath of exports$1) {
|
|
414
544
|
const cycle = dfs(exportPath);
|
|
@@ -416,7 +546,7 @@ function detectCircularExports(exportGraph) {
|
|
|
416
546
|
return cycle;
|
|
417
547
|
}
|
|
418
548
|
}
|
|
419
|
-
|
|
549
|
+
path25.pop();
|
|
420
550
|
recursionStack.delete(node);
|
|
421
551
|
return null;
|
|
422
552
|
}
|
|
@@ -428,15 +558,15 @@ function detectCircularExports(exportGraph) {
|
|
|
428
558
|
}
|
|
429
559
|
return { hasCircular: false, cycle: null };
|
|
430
560
|
}
|
|
431
|
-
function
|
|
561
|
+
function generateBarrelContent(entries) {
|
|
432
562
|
if (entries.length === 0) {
|
|
433
563
|
return null;
|
|
434
564
|
}
|
|
435
565
|
const exportLines = entries.sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
|
|
436
|
-
const
|
|
437
|
-
return `export * from "${
|
|
566
|
+
const path25 = entry.isDirectory ? `./${entry.name}/index.js` : `./${entry.name}.js`;
|
|
567
|
+
return `export * from "${path25}";`;
|
|
438
568
|
});
|
|
439
|
-
return `${
|
|
569
|
+
return `${GENERATED_MARKER2}
|
|
440
570
|
|
|
441
571
|
${exportLines.join("\n")}
|
|
442
572
|
`;
|
|
@@ -456,25 +586,47 @@ var CircularExportError = class extends Error {
|
|
|
456
586
|
};
|
|
457
587
|
async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
458
588
|
const result = createEmptyResult();
|
|
459
|
-
const srcDir =
|
|
589
|
+
const srcDir = path7.join(moduleDir, "src");
|
|
460
590
|
const layers = ["domain", "application", "infrastructure"];
|
|
461
591
|
const pendingWrites = [];
|
|
462
592
|
const preserved = [];
|
|
463
593
|
const exportGraph = /* @__PURE__ */ new Map();
|
|
594
|
+
const layersWithContent = [];
|
|
464
595
|
for (const layer of layers) {
|
|
465
|
-
const layerDir =
|
|
596
|
+
const layerDir = path7.join(srcDir, layer);
|
|
466
597
|
try {
|
|
467
|
-
await
|
|
598
|
+
await fs5.access(layerDir);
|
|
468
599
|
} catch {
|
|
469
600
|
continue;
|
|
470
601
|
}
|
|
471
|
-
await walkDirectory(
|
|
602
|
+
const layerExports = await walkDirectory(
|
|
472
603
|
layerDir,
|
|
473
604
|
pendingWrites,
|
|
474
605
|
preserved,
|
|
475
606
|
exportGraph,
|
|
476
607
|
config
|
|
477
608
|
);
|
|
609
|
+
if (layerExports.length > 0) layersWithContent.push(layer);
|
|
610
|
+
}
|
|
611
|
+
if (config.mode === "external" && layersWithContent.length > 0) {
|
|
612
|
+
const rootBarrelPath = path7.join(srcDir, "index.ts");
|
|
613
|
+
if (await shouldGenerateBarrel(rootBarrelPath, preserved, config.logger)) {
|
|
614
|
+
const content = generateBarrelContent(
|
|
615
|
+
layersWithContent.map((name) => ({ name, isDirectory: true }))
|
|
616
|
+
);
|
|
617
|
+
const existing = await readFileIfExists(rootBarrelPath);
|
|
618
|
+
if (content !== null && !(existing && contentHash2(existing) === contentHash2(content))) {
|
|
619
|
+
pendingWrites.push({
|
|
620
|
+
filePath: rootBarrelPath,
|
|
621
|
+
content,
|
|
622
|
+
isNew: !existing
|
|
623
|
+
});
|
|
624
|
+
exportGraph.set(
|
|
625
|
+
rootBarrelPath,
|
|
626
|
+
layersWithContent.map((name) => path7.join(srcDir, name, "index.ts"))
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
478
630
|
}
|
|
479
631
|
const circularCheck = detectCircularExports(exportGraph);
|
|
480
632
|
if (circularCheck.hasCircular && circularCheck.cycle) {
|
|
@@ -482,9 +634,19 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
|
482
634
|
}
|
|
483
635
|
for (const pending of pendingWrites) {
|
|
484
636
|
if (pending.content === "") {
|
|
637
|
+
if (config.dryRun) {
|
|
638
|
+
config.logger.info(
|
|
639
|
+
`[DRY-RUN] would delete empty barrel ${pending.filePath}`
|
|
640
|
+
);
|
|
641
|
+
result.deleted.push(pending.filePath);
|
|
642
|
+
result.totalOps++;
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
485
645
|
try {
|
|
486
|
-
await
|
|
487
|
-
|
|
646
|
+
const preContent = await fs5.readFile(pending.filePath, "utf8");
|
|
647
|
+
config.journal?.recordDelete(pending.filePath, preContent);
|
|
648
|
+
await fs5.unlink(pending.filePath);
|
|
649
|
+
result.deleted.push(pending.filePath);
|
|
488
650
|
result.totalOps++;
|
|
489
651
|
continue;
|
|
490
652
|
} catch (err3) {
|
|
@@ -500,15 +662,7 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
|
500
662
|
config,
|
|
501
663
|
report
|
|
502
664
|
);
|
|
503
|
-
|
|
504
|
-
result.created.push(pending.filePath);
|
|
505
|
-
result.totalOps++;
|
|
506
|
-
} else if (status === "updated") {
|
|
507
|
-
result.updated.push(pending.filePath);
|
|
508
|
-
result.totalOps++;
|
|
509
|
-
} else if (status === "skipped" || status === "protected") {
|
|
510
|
-
result.skipped.push(pending.filePath);
|
|
511
|
-
}
|
|
665
|
+
recordWriteStatus(result, pending.filePath, status);
|
|
512
666
|
}
|
|
513
667
|
result.skipped.push(...preserved);
|
|
514
668
|
return result;
|
|
@@ -518,7 +672,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
518
672
|
const exportEntries = [];
|
|
519
673
|
let entries;
|
|
520
674
|
try {
|
|
521
|
-
entries = await
|
|
675
|
+
entries = await fs5.readdir(dirPath, { withFileTypes: true });
|
|
522
676
|
} catch {
|
|
523
677
|
return exportEntries;
|
|
524
678
|
}
|
|
@@ -535,7 +689,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
535
689
|
}
|
|
536
690
|
}
|
|
537
691
|
for (const dir of directories) {
|
|
538
|
-
const subDirPath =
|
|
692
|
+
const subDirPath = path7.join(dirPath, dir);
|
|
539
693
|
const subExports = await walkDirectory(
|
|
540
694
|
subDirPath,
|
|
541
695
|
pendingWrites,
|
|
@@ -543,7 +697,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
543
697
|
exportGraph,
|
|
544
698
|
config
|
|
545
699
|
);
|
|
546
|
-
const subBarrelPath =
|
|
700
|
+
const subBarrelPath = path7.join(subDirPath, "index.ts");
|
|
547
701
|
const isQueuedForDeletion = pendingWrites.some(
|
|
548
702
|
(p) => p.filePath === subBarrelPath && p.content === ""
|
|
549
703
|
);
|
|
@@ -555,9 +709,9 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
555
709
|
exportEntries.push({ name: file, isDirectory: false });
|
|
556
710
|
}
|
|
557
711
|
if (exportEntries.length === 0) {
|
|
558
|
-
const barrelPath2 =
|
|
712
|
+
const barrelPath2 = path7.join(dirPath, "index.ts");
|
|
559
713
|
const existingBarrel = await readFileIfExists(barrelPath2);
|
|
560
|
-
const dirName =
|
|
714
|
+
const dirName = path7.basename(dirPath);
|
|
561
715
|
const isLayerDir = ["domain", "application", "infrastructure"].includes(
|
|
562
716
|
dirName
|
|
563
717
|
);
|
|
@@ -572,7 +726,7 @@ async function walkDirectory(dirPath, pendingWrites, preserved, exportGraph, con
|
|
|
572
726
|
isNew: false
|
|
573
727
|
});
|
|
574
728
|
} else if (isEmptyStub && isLayerDir) {
|
|
575
|
-
const newContent = `${
|
|
729
|
+
const newContent = `${GENERATED_MARKER2}
|
|
576
730
|
|
|
577
731
|
export {};
|
|
578
732
|
`;
|
|
@@ -584,7 +738,7 @@ export {};
|
|
|
584
738
|
});
|
|
585
739
|
}
|
|
586
740
|
} else if (!existingBarrel.includes("export {}") && isLayerDir) {
|
|
587
|
-
const newContent = `${
|
|
741
|
+
const newContent = `${GENERATED_MARKER2}
|
|
588
742
|
|
|
589
743
|
export {};
|
|
590
744
|
`;
|
|
@@ -595,7 +749,7 @@ export {};
|
|
|
595
749
|
});
|
|
596
750
|
}
|
|
597
751
|
} else if (isLayerDir) {
|
|
598
|
-
const newContent = `${
|
|
752
|
+
const newContent = `${GENERATED_MARKER2}
|
|
599
753
|
|
|
600
754
|
export {};
|
|
601
755
|
`;
|
|
@@ -607,14 +761,14 @@ export {};
|
|
|
607
761
|
}
|
|
608
762
|
return [];
|
|
609
763
|
}
|
|
610
|
-
const barrelPath =
|
|
764
|
+
const barrelPath = path7.join(dirPath, "index.ts");
|
|
611
765
|
const shouldCreateBarrel = await shouldGenerateBarrel(
|
|
612
766
|
barrelPath,
|
|
613
767
|
preserved,
|
|
614
768
|
logger
|
|
615
769
|
);
|
|
616
770
|
if (shouldCreateBarrel) {
|
|
617
|
-
const content =
|
|
771
|
+
const content = generateBarrelContent(exportEntries);
|
|
618
772
|
if (content === null) {
|
|
619
773
|
return [];
|
|
620
774
|
}
|
|
@@ -627,14 +781,14 @@ export {};
|
|
|
627
781
|
content,
|
|
628
782
|
isNew: !existingContent
|
|
629
783
|
});
|
|
630
|
-
const exportPaths = exportEntries.filter((e) => e.isDirectory).map((e) =>
|
|
784
|
+
const exportPaths = exportEntries.filter((e) => e.isDirectory).map((e) => path7.join(dirPath, e.name, "index.ts"));
|
|
631
785
|
exportGraph.set(barrelPath, exportPaths);
|
|
632
786
|
}
|
|
633
787
|
return exportEntries;
|
|
634
788
|
}
|
|
635
789
|
async function hasBarrel(dirPath) {
|
|
636
790
|
try {
|
|
637
|
-
await
|
|
791
|
+
await fs5.access(path7.join(dirPath, "index.ts"));
|
|
638
792
|
return true;
|
|
639
793
|
} catch {
|
|
640
794
|
return false;
|
|
@@ -654,7 +808,7 @@ async function shouldGenerateBarrel(barrelPath, preserved, logger) {
|
|
|
654
808
|
}
|
|
655
809
|
async function readFileIfExists(filePath) {
|
|
656
810
|
try {
|
|
657
|
-
return await
|
|
811
|
+
return await fs5.readFile(filePath, "utf8");
|
|
658
812
|
} catch (err3) {
|
|
659
813
|
if (err3 && typeof err3 === "object" && "code" in err3 && err3.code === "ENOENT") {
|
|
660
814
|
return null;
|
|
@@ -699,7 +853,12 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
|
|
|
699
853
|
const moduleOverrides = context?.packageJson ?? {};
|
|
700
854
|
const scope = config.manifest ? resolveScope(config.manifest) : "generated-project";
|
|
701
855
|
const dependsOnDeps = context ? expandDependsOn(context, scope) : {};
|
|
702
|
-
const pkgPath =
|
|
856
|
+
const pkgPath = path7.join(modulePath, "package.json");
|
|
857
|
+
const dependencies = {
|
|
858
|
+
...dependsOnDeps,
|
|
859
|
+
...defaults.dependencies ?? {},
|
|
860
|
+
...moduleOverrides.dependencies ?? {}
|
|
861
|
+
};
|
|
703
862
|
const desiredPkg = {
|
|
704
863
|
name: `@${scope}/${moduleName}`,
|
|
705
864
|
version: "0.1.0",
|
|
@@ -720,11 +879,17 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
|
|
|
720
879
|
...defaults.scripts ?? {},
|
|
721
880
|
...moduleOverrides.scripts ?? {}
|
|
722
881
|
},
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
882
|
+
// Emitted only when non-empty (PR-B2, capstone 6f): Yarn 4 deletes an
|
|
883
|
+
// empty `"dependencies": {}` from workspace manifests during install, so
|
|
884
|
+
// emitting one creates a permanent install↔sync churn loop — install
|
|
885
|
+
// strips the key, the next sync re-injects it (`dependencies` is
|
|
886
|
+
// protected, but a protected key MISSING from the current file is
|
|
887
|
+
// re-added), and the tree never converges across the consumer's
|
|
888
|
+
// sync → install → sync workflow. A dependency-less package carries no
|
|
889
|
+
// block at all, matching yarn's normalized form. Existing trees that
|
|
890
|
+
// still carry `{}` on disk stay untouched via the protected-key merge.
|
|
891
|
+
// devDependencies/scripts can't go empty (both have built-in entries).
|
|
892
|
+
...Object.keys(dependencies).length > 0 ? { dependencies } : {},
|
|
728
893
|
devDependencies: {
|
|
729
894
|
typescript: "^5.0.0",
|
|
730
895
|
...defaults.devDependencies ?? {},
|
|
@@ -733,7 +898,7 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
|
|
|
733
898
|
};
|
|
734
899
|
let currentPkg = {};
|
|
735
900
|
try {
|
|
736
|
-
const currentContent = await
|
|
901
|
+
const currentContent = await fs5.readFile(pkgPath, "utf8");
|
|
737
902
|
currentPkg = JSON.parse(currentContent);
|
|
738
903
|
} catch (e) {
|
|
739
904
|
if (!(e instanceof Error && "code" in e && e.code === "ENOENT")) {
|
|
@@ -773,11 +938,7 @@ async function generatePackageJson(modulePath, moduleName, config, report) {
|
|
|
773
938
|
report,
|
|
774
939
|
true
|
|
775
940
|
);
|
|
776
|
-
|
|
777
|
-
if (status === "updated") result.updated.push(pkgPath);
|
|
778
|
-
if (status === "skipped" || status === "protected")
|
|
779
|
-
result.skipped.push(pkgPath);
|
|
780
|
-
result.totalOps += status === "created" || status === "updated" ? 1 : 0;
|
|
941
|
+
recordWriteStatus(result, pkgPath, status);
|
|
781
942
|
return result;
|
|
782
943
|
}
|
|
783
944
|
var BUILTIN_FALLBACK_TEMPLATE = {
|
|
@@ -847,7 +1008,7 @@ function buildTemplate(base, context, scope) {
|
|
|
847
1008
|
}
|
|
848
1009
|
async function generateTsconfig(moduleDir, moduleName, config, report) {
|
|
849
1010
|
const result = createEmptyResult();
|
|
850
|
-
const filePath =
|
|
1011
|
+
const filePath = path7.join(moduleDir, "tsconfig.json");
|
|
851
1012
|
try {
|
|
852
1013
|
const base = resolveWorkspaceTemplate(config.manifest);
|
|
853
1014
|
const context = config.manifest.bounded_contexts?.find(
|
|
@@ -862,16 +1023,14 @@ async function generateTsconfig(moduleDir, moduleName, config, report) {
|
|
|
862
1023
|
config,
|
|
863
1024
|
report
|
|
864
1025
|
);
|
|
865
|
-
|
|
866
|
-
if (status === "updated") result.updated.push(filePath);
|
|
867
|
-
if (status === "skipped" || status === "protected")
|
|
868
|
-
result.skipped.push(filePath);
|
|
869
|
-
result.totalOps += status === "created" || status === "updated" ? 1 : 0;
|
|
1026
|
+
recordWriteStatus(result, filePath, status);
|
|
870
1027
|
return result;
|
|
871
1028
|
} catch (err3) {
|
|
872
1029
|
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
873
1030
|
result.error = err3 instanceof Error ? err3 : new Error(`tsconfig generation failed for ${moduleName}: ${message}`);
|
|
874
1031
|
result.summary = `tsconfig generation failed for ${moduleName}: ${message}`;
|
|
1032
|
+
config.logger.error(result.summary);
|
|
1033
|
+
if (report) report.record("error", filePath, result.summary);
|
|
875
1034
|
return result;
|
|
876
1035
|
}
|
|
877
1036
|
}
|
|
@@ -879,15 +1038,15 @@ async function reapLegacyFolders(moduleDir, config, report) {
|
|
|
879
1038
|
const { dryRun, logger } = config;
|
|
880
1039
|
const legacyLayers = ["domain", "application", "infrastructure"];
|
|
881
1040
|
for (const layer of legacyLayers) {
|
|
882
|
-
const layerPath =
|
|
883
|
-
const relativePath =
|
|
1041
|
+
const layerPath = path7.join(moduleDir, layer);
|
|
1042
|
+
const relativePath = path7.relative(config.workspaceRoot, layerPath);
|
|
884
1043
|
try {
|
|
885
|
-
const entries = await
|
|
1044
|
+
const entries = await fs5.readdir(layerPath);
|
|
886
1045
|
if (entries.length === 0) {
|
|
887
1046
|
if (dryRun) {
|
|
888
1047
|
logger.info(`[DRY-RUN] would delete empty folder ${relativePath}`);
|
|
889
1048
|
} else {
|
|
890
|
-
await
|
|
1049
|
+
await fs5.rmdir(layerPath);
|
|
891
1050
|
logger.info(`deleted empty folder ${relativePath}`);
|
|
892
1051
|
if (report) report.record("deleted", layerPath);
|
|
893
1052
|
}
|
|
@@ -1377,8 +1536,8 @@ function getErrorMap() {
|
|
|
1377
1536
|
|
|
1378
1537
|
// ../../node_modules/zod/v3/helpers/parseUtil.js
|
|
1379
1538
|
var makeIssue = (params) => {
|
|
1380
|
-
const { data, path:
|
|
1381
|
-
const fullPath = [...
|
|
1539
|
+
const { data, path: path25, errorMaps, issueData } = params;
|
|
1540
|
+
const fullPath = [...path25, ...issueData.path || []];
|
|
1382
1541
|
const fullIssue = {
|
|
1383
1542
|
...issueData,
|
|
1384
1543
|
path: fullPath
|
|
@@ -1494,11 +1653,11 @@ var errorUtil;
|
|
|
1494
1653
|
|
|
1495
1654
|
// ../../node_modules/zod/v3/types.js
|
|
1496
1655
|
var ParseInputLazyPath = class {
|
|
1497
|
-
constructor(parent, value,
|
|
1656
|
+
constructor(parent, value, path25, key) {
|
|
1498
1657
|
this._cachedPath = [];
|
|
1499
1658
|
this.parent = parent;
|
|
1500
1659
|
this.data = value;
|
|
1501
|
-
this._path =
|
|
1660
|
+
this._path = path25;
|
|
1502
1661
|
this._key = key;
|
|
1503
1662
|
}
|
|
1504
1663
|
get path() {
|
|
@@ -5009,6 +5168,7 @@ var BUILTIN_PACKAGE_JSON_TEMPLATE = `{
|
|
|
5009
5168
|
"sync": "hexagen sync",
|
|
5010
5169
|
"sync:dry": "hexagen sync --dry-run",
|
|
5011
5170
|
"sync:force": "hexagen sync --force",
|
|
5171
|
+
"sync:check": "hexagen sync --check",
|
|
5012
5172
|
"lint:arch": "hexagen arch validate",
|
|
5013
5173
|
"templates:add": "hexagen add",
|
|
5014
5174
|
"templates:validate": "hexagen validate-templates",
|
|
@@ -5019,8 +5179,8 @@ var BUILTIN_PACKAGE_JSON_TEMPLATE = `{
|
|
|
5019
5179
|
"typescript": "^5.5.4",
|
|
5020
5180
|
"eslint": "^9.0.0",
|
|
5021
5181
|
"prettier": "^3.0.0",
|
|
5022
|
-
"@hexagen-monaco/sync": "^
|
|
5023
|
-
"@hexagen-monaco/arch-linter": "^
|
|
5182
|
+
"@hexagen-monaco/sync": "^{toolchainVersion}",
|
|
5183
|
+
"@hexagen-monaco/arch-linter": "^{toolchainVersion}"
|
|
5024
5184
|
}
|
|
5025
5185
|
}`;
|
|
5026
5186
|
var BUILTIN_TSCONFIG_BASE_TEMPLATE = `{
|
|
@@ -5029,6 +5189,7 @@ var BUILTIN_TSCONFIG_BASE_TEMPLATE = `{
|
|
|
5029
5189
|
"module": "ESNext",
|
|
5030
5190
|
"moduleResolution": "bundler",
|
|
5031
5191
|
"strict": true,
|
|
5192
|
+
"skipLibCheck": true,
|
|
5032
5193
|
"composite": true,
|
|
5033
5194
|
"declaration": true,
|
|
5034
5195
|
"emitDeclarationOnly": true,
|
|
@@ -5060,6 +5221,9 @@ var BUILTIN_TURBO_TEMPLATE = `{
|
|
|
5060
5221
|
]
|
|
5061
5222
|
},
|
|
5062
5223
|
"typecheck": {
|
|
5224
|
+
"dependsOn": [
|
|
5225
|
+
"^build"
|
|
5226
|
+
],
|
|
5063
5227
|
"outputs": [],
|
|
5064
5228
|
"cache": true
|
|
5065
5229
|
},
|
|
@@ -5080,7 +5244,13 @@ node_modules/
|
|
|
5080
5244
|
dist/
|
|
5081
5245
|
.turbo/
|
|
5082
5246
|
.next/
|
|
5083
|
-
|
|
5247
|
+
.nitro/
|
|
5248
|
+
.output/
|
|
5249
|
+
|
|
5250
|
+
# Next.js static export — anchored to apps so a bare \`out/\` can't shadow a
|
|
5251
|
+
# bounded context's hexagonal \`src/application/ports/out/\` source (which a
|
|
5252
|
+
# pattern without a leading path matches at any depth).
|
|
5253
|
+
apps/*/out/
|
|
5084
5254
|
|
|
5085
5255
|
# Test / coverage
|
|
5086
5256
|
coverage/
|
|
@@ -5122,15 +5292,33 @@ adding \`--immutable\` to the \`yarn install\` step in
|
|
|
5122
5292
|
Its pre-lockfile guidance goes stale once \`yarn.lock\` is committed. (Run
|
|
5123
5293
|
\`hexagen sync\` won't bring it back — it's a protected root file.)
|
|
5124
5294
|
`;
|
|
5295
|
+
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-]+)*))?$/;
|
|
5296
|
+
function assertValidToolchainVersion(version, source) {
|
|
5297
|
+
const invalid = !SEMVER_2_0_0.test(version) || /^0\.0\.0(?:$|[-+])/.test(version);
|
|
5298
|
+
if (invalid) {
|
|
5299
|
+
throw new Error(
|
|
5300
|
+
`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).`
|
|
5301
|
+
);
|
|
5302
|
+
}
|
|
5303
|
+
return version;
|
|
5304
|
+
}
|
|
5305
|
+
function resolveToolchainVersion() {
|
|
5306
|
+
{
|
|
5307
|
+
return assertValidToolchainVersion(
|
|
5308
|
+
"0.7.0",
|
|
5309
|
+
"build-injected __HEXAGEN_TOOLCHAIN_VERSION__"
|
|
5310
|
+
);
|
|
5311
|
+
}
|
|
5312
|
+
}
|
|
5125
5313
|
|
|
5126
5314
|
// src/generators/root-files.ts
|
|
5127
|
-
function buildVars(manifest) {
|
|
5315
|
+
function buildVars(manifest, toolchainVersion) {
|
|
5128
5316
|
const system = typeof manifest.system === "string" && manifest.system.length > 0 ? manifest.system : "generated-project";
|
|
5129
5317
|
const scope = resolveScope(manifest);
|
|
5130
5318
|
const packageManager = typeof manifest.monorepo?.packageManager === "string" && manifest.monorepo.packageManager.length > 0 ? manifest.monorepo.packageManager : "yarn@4.12.0";
|
|
5131
5319
|
const workspacesArray = Array.isArray(manifest.monorepo?.workspaces) && manifest.monorepo.workspaces.length > 0 ? manifest.monorepo.workspaces : ["apps/*", "packages/*"];
|
|
5132
5320
|
const workspaces = "[\n" + workspacesArray.map((w) => ` ${JSON.stringify(w)}`).join(",\n") + "\n ]";
|
|
5133
|
-
return { system, scope, packageManager, workspaces };
|
|
5321
|
+
return { system, scope, packageManager, workspaces, toolchainVersion };
|
|
5134
5322
|
}
|
|
5135
5323
|
function resolveTemplate(manifestTemplate, builtin) {
|
|
5136
5324
|
if (typeof manifestTemplate === "string" && manifestTemplate.length > 0) {
|
|
@@ -5156,17 +5344,14 @@ async function writeRootFile(filePath, content, config, report, result) {
|
|
|
5156
5344
|
report,
|
|
5157
5345
|
true
|
|
5158
5346
|
);
|
|
5159
|
-
|
|
5160
|
-
if (status === "updated") result.updated.push(filePath);
|
|
5161
|
-
if (status === "skipped" || status === "protected")
|
|
5162
|
-
result.skipped.push(filePath);
|
|
5163
|
-
if (status === "created" || status === "updated") result.totalOps += 1;
|
|
5347
|
+
recordWriteStatus(result, filePath, status);
|
|
5164
5348
|
}
|
|
5165
5349
|
async function generateRootFiles(config, report) {
|
|
5166
5350
|
const result = createEmptyResult();
|
|
5351
|
+
const toolchainVersion = resolveToolchainVersion();
|
|
5167
5352
|
try {
|
|
5168
5353
|
const rootFiles = config.manifest.monorepo?.rootFiles;
|
|
5169
|
-
const vars = buildVars(config.manifest);
|
|
5354
|
+
const vars = buildVars(config.manifest, toolchainVersion);
|
|
5170
5355
|
const packageJsonTemplate = resolveTemplate(
|
|
5171
5356
|
rootFiles?.packageJson?.template,
|
|
5172
5357
|
BUILTIN_PACKAGE_JSON_TEMPLATE
|
|
@@ -5178,7 +5363,7 @@ async function generateRootFiles(config, report) {
|
|
|
5178
5363
|
"package.json"
|
|
5179
5364
|
);
|
|
5180
5365
|
await writeRootFile(
|
|
5181
|
-
|
|
5366
|
+
path7.join(config.workspaceRoot, "package.json"),
|
|
5182
5367
|
packageJsonContent,
|
|
5183
5368
|
config,
|
|
5184
5369
|
report,
|
|
@@ -5195,7 +5380,7 @@ async function generateRootFiles(config, report) {
|
|
|
5195
5380
|
"tsconfig.base.json"
|
|
5196
5381
|
);
|
|
5197
5382
|
await writeRootFile(
|
|
5198
|
-
|
|
5383
|
+
path7.join(config.workspaceRoot, "tsconfig.base.json"),
|
|
5199
5384
|
tsconfigContent,
|
|
5200
5385
|
config,
|
|
5201
5386
|
report,
|
|
@@ -5212,7 +5397,7 @@ async function generateRootFiles(config, report) {
|
|
|
5212
5397
|
"turbo.json"
|
|
5213
5398
|
);
|
|
5214
5399
|
await writeRootFile(
|
|
5215
|
-
|
|
5400
|
+
path7.join(config.workspaceRoot, "turbo.json"),
|
|
5216
5401
|
turboContent,
|
|
5217
5402
|
config,
|
|
5218
5403
|
report,
|
|
@@ -5223,7 +5408,7 @@ async function generateRootFiles(config, report) {
|
|
|
5223
5408
|
BUILTIN_GITIGNORE_TEMPLATE
|
|
5224
5409
|
);
|
|
5225
5410
|
await writeRootFile(
|
|
5226
|
-
|
|
5411
|
+
path7.join(config.workspaceRoot, ".gitignore"),
|
|
5227
5412
|
interpolateAndWarn(gitignoreTemplate, vars, config, ".gitignore"),
|
|
5228
5413
|
config,
|
|
5229
5414
|
report,
|
|
@@ -5234,7 +5419,7 @@ async function generateRootFiles(config, report) {
|
|
|
5234
5419
|
BUILTIN_YARNRC_TEMPLATE
|
|
5235
5420
|
);
|
|
5236
5421
|
await writeRootFile(
|
|
5237
|
-
|
|
5422
|
+
path7.join(config.workspaceRoot, ".yarnrc.yml"),
|
|
5238
5423
|
interpolateAndWarn(yarnrcTemplate, vars, config, ".yarnrc.yml"),
|
|
5239
5424
|
config,
|
|
5240
5425
|
report,
|
|
@@ -5245,7 +5430,7 @@ async function generateRootFiles(config, report) {
|
|
|
5245
5430
|
BUILTIN_SETUP_MD_TEMPLATE
|
|
5246
5431
|
);
|
|
5247
5432
|
await writeRootFile(
|
|
5248
|
-
|
|
5433
|
+
path7.join(config.workspaceRoot, "SETUP.md"),
|
|
5249
5434
|
interpolateAndWarn(setupTemplate, vars, config, "SETUP.md"),
|
|
5250
5435
|
config,
|
|
5251
5436
|
report,
|
|
@@ -5256,6 +5441,8 @@ async function generateRootFiles(config, report) {
|
|
|
5256
5441
|
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
5257
5442
|
result.error = err3 instanceof Error ? err3 : new Error(`root-files generation failed: ${message}`);
|
|
5258
5443
|
result.summary = `root-files generation failed: ${message}`;
|
|
5444
|
+
config.logger.error(result.summary);
|
|
5445
|
+
if (report) report.record("error", "root-files", result.summary);
|
|
5259
5446
|
return result;
|
|
5260
5447
|
}
|
|
5261
5448
|
}
|
|
@@ -5471,23 +5658,21 @@ function interpolateWithLogging(label, template, vars, config) {
|
|
|
5471
5658
|
}
|
|
5472
5659
|
return output;
|
|
5473
5660
|
}
|
|
5474
|
-
function recordStatus(result, filePath, status) {
|
|
5475
|
-
if (status === "created") result.created.push(filePath);
|
|
5476
|
-
else if (status === "updated") result.updated.push(filePath);
|
|
5477
|
-
else if (status === "skipped" || status === "protected")
|
|
5478
|
-
result.skipped.push(filePath);
|
|
5479
|
-
if (status === "created" || status === "updated") result.totalOps += 1;
|
|
5480
|
-
}
|
|
5481
5661
|
async function writeManifestIfFreshExternal(config, result, report) {
|
|
5482
5662
|
if (config.mode !== "external") {
|
|
5483
5663
|
return;
|
|
5484
5664
|
}
|
|
5485
|
-
const archDir =
|
|
5486
|
-
const manifestPath =
|
|
5487
|
-
const relative =
|
|
5665
|
+
const archDir = path7.join(config.workspaceRoot, ".architecture");
|
|
5666
|
+
const manifestPath = path7.join(archDir, "manifest.yaml");
|
|
5667
|
+
const relative = path7.relative(config.workspaceRoot, manifestPath);
|
|
5668
|
+
if (!isInScope(manifestPath, config)) {
|
|
5669
|
+
config.logger.debug(`skipped (outside --only) ${relative}`);
|
|
5670
|
+
result.skipped.push(manifestPath);
|
|
5671
|
+
return;
|
|
5672
|
+
}
|
|
5488
5673
|
let exists = false;
|
|
5489
5674
|
try {
|
|
5490
|
-
await
|
|
5675
|
+
await fs5.access(manifestPath);
|
|
5491
5676
|
exists = true;
|
|
5492
5677
|
} catch {
|
|
5493
5678
|
exists = false;
|
|
@@ -5506,8 +5691,9 @@ async function writeManifestIfFreshExternal(config, result, report) {
|
|
|
5506
5691
|
return;
|
|
5507
5692
|
}
|
|
5508
5693
|
const content = yaml3.dump(config.manifest);
|
|
5509
|
-
|
|
5510
|
-
await
|
|
5694
|
+
config.journal?.recordWrite(manifestPath, null);
|
|
5695
|
+
await fs5.mkdir(archDir, { recursive: true });
|
|
5696
|
+
await fs5.writeFile(manifestPath, content, { encoding: "utf8" });
|
|
5511
5697
|
config.logger.info(`created ${relative}`);
|
|
5512
5698
|
if (report)
|
|
5513
5699
|
report.record(
|
|
@@ -5521,12 +5707,12 @@ async function writeManifestIfFreshExternal(config, result, report) {
|
|
|
5521
5707
|
async function generateArchitectureFiles(config, report) {
|
|
5522
5708
|
const result = createEmptyResult();
|
|
5523
5709
|
const manifest = config.manifest;
|
|
5524
|
-
const archRoot =
|
|
5710
|
+
const archRoot = path7.join(config.workspaceRoot, ".architecture");
|
|
5525
5711
|
const archInvariants = manifest.monorepo?.archInvariants;
|
|
5526
5712
|
const vars = buildInterpolationVars(manifest);
|
|
5527
5713
|
const workspaceTemplate = vars.workspaceTemplate ?? "modular-monolith";
|
|
5528
5714
|
await writeManifestIfFreshExternal(config, result, report);
|
|
5529
|
-
const layerRulesPath =
|
|
5715
|
+
const layerRulesPath = path7.join(archRoot, "invariants", "layer-rules.yaml");
|
|
5530
5716
|
const layerRulesTemplate = resolveTemplate2(
|
|
5531
5717
|
archInvariants?.layerRules,
|
|
5532
5718
|
builtInLayerRules(workspaceTemplate)
|
|
@@ -5544,8 +5730,8 @@ async function generateArchitectureFiles(config, report) {
|
|
|
5544
5730
|
report,
|
|
5545
5731
|
true
|
|
5546
5732
|
);
|
|
5547
|
-
|
|
5548
|
-
const linterConfigPath =
|
|
5733
|
+
recordWriteStatus(result, layerRulesPath, layerRulesStatus);
|
|
5734
|
+
const linterConfigPath = path7.join(
|
|
5549
5735
|
archRoot,
|
|
5550
5736
|
"invariants",
|
|
5551
5737
|
"linter-config.yaml"
|
|
@@ -5567,8 +5753,8 @@ async function generateArchitectureFiles(config, report) {
|
|
|
5567
5753
|
report,
|
|
5568
5754
|
true
|
|
5569
5755
|
);
|
|
5570
|
-
|
|
5571
|
-
const generatorConfigPath =
|
|
5756
|
+
recordWriteStatus(result, linterConfigPath, linterConfigStatus);
|
|
5757
|
+
const generatorConfigPath = path7.join(archRoot, "generator.config.yaml");
|
|
5572
5758
|
const generatorConfigTemplate = resolveTemplate2(
|
|
5573
5759
|
archInvariants?.generatorConfig,
|
|
5574
5760
|
GENERATOR_CONFIG_TEMPLATE
|
|
@@ -5586,7 +5772,7 @@ async function generateArchitectureFiles(config, report) {
|
|
|
5586
5772
|
report,
|
|
5587
5773
|
true
|
|
5588
5774
|
);
|
|
5589
|
-
|
|
5775
|
+
recordWriteStatus(result, generatorConfigPath, generatorConfigStatus);
|
|
5590
5776
|
return result;
|
|
5591
5777
|
}
|
|
5592
5778
|
|
|
@@ -5690,7 +5876,6 @@ var PLAIN_TS_PACKAGE_JSON_TEMPLATE = `{
|
|
|
5690
5876
|
"lint": "eslint src --ext .ts,.tsx",
|
|
5691
5877
|
"typecheck": "tsc --noEmit"
|
|
5692
5878
|
},
|
|
5693
|
-
"dependencies": {},
|
|
5694
5879
|
"devDependencies": {
|
|
5695
5880
|
"typescript": "^5.5.4",
|
|
5696
5881
|
"eslint": "^9.0.0",
|
|
@@ -5716,6 +5901,50 @@ export function main(): void {
|
|
|
5716
5901
|
// Application bootstrap for {appName}
|
|
5717
5902
|
}
|
|
5718
5903
|
`;
|
|
5904
|
+
var NITRO_PACKAGE_JSON_TEMPLATE = `{
|
|
5905
|
+
"name": "@{scope}/{appName}",
|
|
5906
|
+
"version": "0.0.0",
|
|
5907
|
+
"private": true,
|
|
5908
|
+
"type": "module",
|
|
5909
|
+
"scripts": {
|
|
5910
|
+
"build": "nitro build",
|
|
5911
|
+
"dev": "nitro dev",
|
|
5912
|
+
"preview": "node .output/server/index.mjs",
|
|
5913
|
+
"prepare": "nitro prepare",
|
|
5914
|
+
"lint": "eslint server --ext .ts",
|
|
5915
|
+
"typecheck": "nitro prepare && tsc --noEmit"
|
|
5916
|
+
},
|
|
5917
|
+
"dependencies": {
|
|
5918
|
+
"nitropack": "^2.13.0"
|
|
5919
|
+
},
|
|
5920
|
+
"devDependencies": {
|
|
5921
|
+
"typescript": "^5.5.4",
|
|
5922
|
+
"eslint": "^9.0.0",
|
|
5923
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
5924
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0"
|
|
5925
|
+
}
|
|
5926
|
+
}
|
|
5927
|
+
`;
|
|
5928
|
+
var NITRO_TSCONFIG = {
|
|
5929
|
+
extends: "./.nitro/types/tsconfig.json",
|
|
5930
|
+
compilerOptions: {
|
|
5931
|
+
moduleResolution: "bundler",
|
|
5932
|
+
strict: true,
|
|
5933
|
+
skipLibCheck: true
|
|
5934
|
+
}
|
|
5935
|
+
};
|
|
5936
|
+
var NITRO_CONFIG_TEMPLATE = `import { defineNitroConfig } from "nitropack/config";
|
|
5937
|
+
|
|
5938
|
+
// https://nitro.build/config
|
|
5939
|
+
export default defineNitroConfig({
|
|
5940
|
+
srcDir: "server",
|
|
5941
|
+
compatibilityDate: "2025-01-01",
|
|
5942
|
+
});
|
|
5943
|
+
`;
|
|
5944
|
+
var NITRO_ROUTE_TEMPLATE = `// Auto-generated Nitro route — GET /
|
|
5945
|
+
// \`defineEventHandler\` is auto-imported by Nitro (see ./.nitro/types).
|
|
5946
|
+
export default defineEventHandler(() => ({ status: "ok", app: "{appName}" }));
|
|
5947
|
+
`;
|
|
5719
5948
|
var BUILTIN_FRAMEWORK_TEMPLATES = {
|
|
5720
5949
|
"next.js": {
|
|
5721
5950
|
packageJson: { template: NEXTJS_PACKAGE_JSON_TEMPLATE },
|
|
@@ -5740,8 +5969,103 @@ var BUILTIN_FRAMEWORK_TEMPLATES = {
|
|
|
5740
5969
|
path: "src/index.ts",
|
|
5741
5970
|
template: PLAIN_TS_ENTRY_TEMPLATE
|
|
5742
5971
|
}
|
|
5972
|
+
},
|
|
5973
|
+
nitro: {
|
|
5974
|
+
packageJson: { template: NITRO_PACKAGE_JSON_TEMPLATE },
|
|
5975
|
+
tsConfig: NITRO_TSCONFIG,
|
|
5976
|
+
entryPoint: {
|
|
5977
|
+
path: "server/routes/index.ts",
|
|
5978
|
+
template: NITRO_ROUTE_TEMPLATE
|
|
5979
|
+
},
|
|
5980
|
+
extraFiles: [{ path: "nitro.config.ts", template: NITRO_CONFIG_TEMPLATE }]
|
|
5743
5981
|
}
|
|
5744
5982
|
};
|
|
5983
|
+
var GENERATED_MARKER_LINE = "// @generated by @hexagen/sync";
|
|
5984
|
+
var BUILTIN_FALLBACK_TEMPLATE2 = `import eslint from '@eslint/js';
|
|
5985
|
+
import tseslint from 'typescript-eslint';
|
|
5986
|
+
|
|
5987
|
+
export default tseslint.config(
|
|
5988
|
+
eslint.configs.recommended,
|
|
5989
|
+
...tseslint.configs.recommended,
|
|
5990
|
+
{
|
|
5991
|
+
rules: {
|
|
5992
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
5993
|
+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
5994
|
+
},
|
|
5995
|
+
},
|
|
5996
|
+
{
|
|
5997
|
+
ignores: ['dist/**', 'node_modules/**'],
|
|
5998
|
+
},
|
|
5999
|
+
);
|
|
6000
|
+
`;
|
|
6001
|
+
function resolveTemplate3(manifest, moduleName, usePerContextOverride) {
|
|
6002
|
+
const contextOverride = usePerContextOverride ? manifest.bounded_contexts?.find((c) => c.name === moduleName)?.generator?.eslint : void 0;
|
|
6003
|
+
if (contextOverride?.template !== void 0) {
|
|
6004
|
+
return { template: contextOverride.template, source: "per-context" };
|
|
6005
|
+
}
|
|
6006
|
+
const rootLevel = manifest.workspaceDefaults?.eslint;
|
|
6007
|
+
if (rootLevel?.template !== void 0) {
|
|
6008
|
+
return { template: rootLevel.template, source: "workspace" };
|
|
6009
|
+
}
|
|
6010
|
+
const monorepoLevel = manifest.monorepo?.workspaceDefaults?.eslint;
|
|
6011
|
+
if (monorepoLevel?.template !== void 0) {
|
|
6012
|
+
return { template: monorepoLevel.template, source: "workspace" };
|
|
6013
|
+
}
|
|
6014
|
+
return { template: BUILTIN_FALLBACK_TEMPLATE2, source: "fallback" };
|
|
6015
|
+
}
|
|
6016
|
+
function withGeneratedMarker(content) {
|
|
6017
|
+
if (content.startsWith(GENERATED_MARKER_LINE)) {
|
|
6018
|
+
return content;
|
|
6019
|
+
}
|
|
6020
|
+
return `${GENERATED_MARKER_LINE}
|
|
6021
|
+
${content}`;
|
|
6022
|
+
}
|
|
6023
|
+
async function generateEslintConfig(moduleDir, moduleName, config, report, options = {}) {
|
|
6024
|
+
const result = createEmptyResult();
|
|
6025
|
+
const filePath = path7.join(moduleDir, "eslint.config.js");
|
|
6026
|
+
try {
|
|
6027
|
+
const { template, source } = resolveTemplate3(
|
|
6028
|
+
config.manifest,
|
|
6029
|
+
moduleName,
|
|
6030
|
+
options.usePerContextOverride ?? true
|
|
6031
|
+
);
|
|
6032
|
+
if (typeof template !== "string" || template.length === 0) {
|
|
6033
|
+
const message = `No eslint template resolved for ${moduleName} (source: ${source}); skipping`;
|
|
6034
|
+
config.logger.error(message);
|
|
6035
|
+
if (report) report.record("error", filePath, message);
|
|
6036
|
+
result.skipped.push(filePath);
|
|
6037
|
+
result.summary = message;
|
|
6038
|
+
return result;
|
|
6039
|
+
}
|
|
6040
|
+
const scope = resolveScope(config.manifest);
|
|
6041
|
+
const { output: interpolated, warnings } = interpolate(template, {
|
|
6042
|
+
packageName: moduleName,
|
|
6043
|
+
scope
|
|
6044
|
+
});
|
|
6045
|
+
for (const missingVar of warnings) {
|
|
6046
|
+
const message = `Missing interpolation variable "${missingVar}" in eslint template for ${moduleName} (source: ${source}); placeholder left verbatim`;
|
|
6047
|
+
config.logger.warn(message);
|
|
6048
|
+
if (report) report.record("warning", filePath, message);
|
|
6049
|
+
}
|
|
6050
|
+
const content = withGeneratedMarker(interpolated);
|
|
6051
|
+
const status = await safeWriteFileAtomic(
|
|
6052
|
+
filePath,
|
|
6053
|
+
content,
|
|
6054
|
+
config,
|
|
6055
|
+
report,
|
|
6056
|
+
false
|
|
6057
|
+
);
|
|
6058
|
+
recordWriteStatus(result, filePath, status);
|
|
6059
|
+
return result;
|
|
6060
|
+
} catch (err3) {
|
|
6061
|
+
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
6062
|
+
result.error = err3 instanceof Error ? err3 : new Error(`eslint generation failed for ${moduleName}: ${message}`);
|
|
6063
|
+
result.summary = `eslint generation failed for ${moduleName}: ${message}`;
|
|
6064
|
+
config.logger.error(result.summary);
|
|
6065
|
+
if (report) report.record("error", filePath, result.summary);
|
|
6066
|
+
return result;
|
|
6067
|
+
}
|
|
6068
|
+
}
|
|
5745
6069
|
|
|
5746
6070
|
// src/generators/apps.ts
|
|
5747
6071
|
function resolveFrameworkConfig(framework, manifestConfig) {
|
|
@@ -5752,7 +6076,8 @@ function resolveFrameworkConfig(framework, manifestConfig) {
|
|
|
5752
6076
|
return {
|
|
5753
6077
|
packageJson: manifestConfig.packageJson ?? builtin.packageJson,
|
|
5754
6078
|
tsConfig: manifestConfig.tsConfig ?? builtin.tsConfig,
|
|
5755
|
-
entryPoint: manifestConfig.entryPoint ?? builtin.entryPoint
|
|
6079
|
+
entryPoint: manifestConfig.entryPoint ?? builtin.entryPoint,
|
|
6080
|
+
extraFiles: manifestConfig.extraFiles ?? builtin.extraFiles
|
|
5756
6081
|
};
|
|
5757
6082
|
}
|
|
5758
6083
|
function interpolateWithLogging2(template, vars, context, config) {
|
|
@@ -5765,16 +6090,58 @@ function interpolateWithLogging2(template, vars, context, config) {
|
|
|
5765
6090
|
}
|
|
5766
6091
|
return output;
|
|
5767
6092
|
}
|
|
5768
|
-
function
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
result.
|
|
6093
|
+
function mergeResult(result, sub) {
|
|
6094
|
+
result.created.push(...sub.created);
|
|
6095
|
+
result.updated.push(...sub.updated);
|
|
6096
|
+
result.skipped.push(...sub.skipped);
|
|
6097
|
+
result.deleted.push(...sub.deleted);
|
|
6098
|
+
result.unchanged.push(...sub.unchanged);
|
|
6099
|
+
result.totalOps += sub.totalOps;
|
|
6100
|
+
if (sub.error && !result.error) {
|
|
6101
|
+
result.error = sub.error;
|
|
6102
|
+
result.summary = sub.summary;
|
|
6103
|
+
}
|
|
6104
|
+
}
|
|
6105
|
+
async function emitAppFile(appDir, relPath, template, vars, config, report, result, appName) {
|
|
6106
|
+
const content = interpolateWithLogging2(
|
|
6107
|
+
template,
|
|
6108
|
+
vars,
|
|
6109
|
+
`apps/${appName}/${relPath}`,
|
|
6110
|
+
config
|
|
6111
|
+
);
|
|
6112
|
+
const target = path7.resolve(appDir, relPath);
|
|
6113
|
+
const relative = path7.relative(appDir, target);
|
|
6114
|
+
if (relative === "" || relative.startsWith("..") || path7.isAbsolute(relative)) {
|
|
6115
|
+
config.logger.warn(
|
|
6116
|
+
`[apps] skipping file with unsafe path (escapes apps/${appName}): ${relPath}`
|
|
6117
|
+
);
|
|
6118
|
+
if (report) {
|
|
6119
|
+
report.record(
|
|
6120
|
+
"blocked",
|
|
6121
|
+
appName,
|
|
6122
|
+
`Unsafe file path (potential path traversal): ${relPath}`
|
|
6123
|
+
);
|
|
6124
|
+
}
|
|
6125
|
+
return "unsafe";
|
|
6126
|
+
}
|
|
6127
|
+
if (!config.dryRun && isInScope(target, config)) {
|
|
6128
|
+
try {
|
|
6129
|
+
await fs5.mkdir(path7.dirname(target), { recursive: true });
|
|
6130
|
+
} catch (err3) {
|
|
6131
|
+
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
6132
|
+
config.logger.error(
|
|
6133
|
+
`[apps] failed to create dir for "${appName}" file ${relPath}: ${message}`
|
|
6134
|
+
);
|
|
6135
|
+
if (report) report.record("blocked", appName, message);
|
|
6136
|
+
return "error";
|
|
6137
|
+
}
|
|
5777
6138
|
}
|
|
6139
|
+
recordWriteStatus(
|
|
6140
|
+
result,
|
|
6141
|
+
target,
|
|
6142
|
+
await safeWriteFileAtomic(target, content, config, report)
|
|
6143
|
+
);
|
|
6144
|
+
return "ok";
|
|
5778
6145
|
}
|
|
5779
6146
|
async function generateApps(config, report) {
|
|
5780
6147
|
const result = createEmptyResult();
|
|
@@ -5795,6 +6162,19 @@ async function generateApps(config, report) {
|
|
|
5795
6162
|
config.logger.warn(`[apps] skipping entry with missing or empty name`);
|
|
5796
6163
|
continue;
|
|
5797
6164
|
}
|
|
6165
|
+
if (app.name.includes("..") || app.name.includes("/") || app.name.includes("\\") || app.name.startsWith(".")) {
|
|
6166
|
+
config.logger.warn(
|
|
6167
|
+
`[apps] skipping app with unsafe name (potential path traversal): ${app.name}`
|
|
6168
|
+
);
|
|
6169
|
+
if (report) {
|
|
6170
|
+
report.record(
|
|
6171
|
+
"blocked",
|
|
6172
|
+
app.name,
|
|
6173
|
+
"Unsafe app name (potential path traversal)"
|
|
6174
|
+
);
|
|
6175
|
+
}
|
|
6176
|
+
continue;
|
|
6177
|
+
}
|
|
5798
6178
|
if (seen.has(app.name)) {
|
|
5799
6179
|
config.logger.warn(
|
|
5800
6180
|
`[apps] duplicate app name "${app.name}" — keeping first occurrence, skipping this duplicate`
|
|
@@ -5837,18 +6217,20 @@ async function generateApps(config, report) {
|
|
|
5837
6217
|
version: app.version ?? "",
|
|
5838
6218
|
depends_on: (app.depends_on ?? []).join(", ")
|
|
5839
6219
|
};
|
|
5840
|
-
const appDir =
|
|
5841
|
-
const srcDir =
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
6220
|
+
const appDir = path7.join(config.workspaceRoot, "apps", app.name);
|
|
6221
|
+
const srcDir = path7.join(appDir, "src");
|
|
6222
|
+
if (!config.dryRun && isInScope(appDir, config)) {
|
|
6223
|
+
try {
|
|
6224
|
+
await fs5.mkdir(appDir, { recursive: true });
|
|
6225
|
+
await fs5.mkdir(srcDir, { recursive: true });
|
|
6226
|
+
} catch (err3) {
|
|
6227
|
+
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
6228
|
+
config.logger.error(
|
|
6229
|
+
`[apps] failed to create directory for "${app.name}": ${message}`
|
|
6230
|
+
);
|
|
6231
|
+
if (report) report.record("blocked", app.name, message);
|
|
6232
|
+
continue;
|
|
6233
|
+
}
|
|
5852
6234
|
}
|
|
5853
6235
|
const pkgTemplate = frameworkConfig.packageJson?.template;
|
|
5854
6236
|
if (pkgTemplate) {
|
|
@@ -5858,14 +6240,14 @@ async function generateApps(config, report) {
|
|
|
5858
6240
|
`apps/${app.name}/package.json`,
|
|
5859
6241
|
config
|
|
5860
6242
|
);
|
|
5861
|
-
const pkgPath =
|
|
6243
|
+
const pkgPath = path7.join(appDir, "package.json");
|
|
5862
6244
|
const status = await safeWriteFileAtomic(
|
|
5863
6245
|
pkgPath,
|
|
5864
6246
|
pkgContent,
|
|
5865
6247
|
config,
|
|
5866
6248
|
report
|
|
5867
6249
|
);
|
|
5868
|
-
|
|
6250
|
+
recordWriteStatus(result, pkgPath, status);
|
|
5869
6251
|
} else {
|
|
5870
6252
|
config.logger.warn(
|
|
5871
6253
|
`[apps] framework "${framework}" has no package.json template — skipping package.json for "${app.name}"`
|
|
@@ -5874,14 +6256,14 @@ async function generateApps(config, report) {
|
|
|
5874
6256
|
const tsConfig = frameworkConfig.tsConfig;
|
|
5875
6257
|
if (tsConfig) {
|
|
5876
6258
|
const tsContent = JSON.stringify(tsConfig, null, 2) + "\n";
|
|
5877
|
-
const tsPath =
|
|
6259
|
+
const tsPath = path7.join(appDir, "tsconfig.json");
|
|
5878
6260
|
const status = await safeWriteFileAtomic(
|
|
5879
6261
|
tsPath,
|
|
5880
6262
|
tsContent,
|
|
5881
6263
|
config,
|
|
5882
6264
|
report
|
|
5883
6265
|
);
|
|
5884
|
-
|
|
6266
|
+
recordWriteStatus(result, tsPath, status);
|
|
5885
6267
|
} else {
|
|
5886
6268
|
config.logger.warn(
|
|
5887
6269
|
`[apps] framework "${framework}" has no tsConfig — skipping tsconfig.json for "${app.name}"`
|
|
@@ -5889,130 +6271,120 @@ async function generateApps(config, report) {
|
|
|
5889
6271
|
}
|
|
5890
6272
|
const entry = frameworkConfig.entryPoint;
|
|
5891
6273
|
if (entry?.path && entry.template !== void 0) {
|
|
5892
|
-
const
|
|
6274
|
+
const status = await emitAppFile(
|
|
6275
|
+
appDir,
|
|
6276
|
+
entry.path,
|
|
5893
6277
|
entry.template,
|
|
5894
6278
|
vars,
|
|
5895
|
-
`apps/${app.name}/${entry.path}`,
|
|
5896
|
-
config
|
|
5897
|
-
);
|
|
5898
|
-
const entryPath = path6.join(appDir, entry.path);
|
|
5899
|
-
try {
|
|
5900
|
-
await fs3.mkdir(path6.dirname(entryPath), { recursive: true });
|
|
5901
|
-
} catch (err3) {
|
|
5902
|
-
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
5903
|
-
config.logger.error(
|
|
5904
|
-
`[apps] failed to create entry-point dir for "${app.name}": ${message}`
|
|
5905
|
-
);
|
|
5906
|
-
if (report) report.record("blocked", app.name, message);
|
|
5907
|
-
continue;
|
|
5908
|
-
}
|
|
5909
|
-
const status = await safeWriteFileAtomic(
|
|
5910
|
-
entryPath,
|
|
5911
|
-
entryContent,
|
|
5912
6279
|
config,
|
|
5913
|
-
report
|
|
6280
|
+
report,
|
|
6281
|
+
result,
|
|
6282
|
+
app.name
|
|
5914
6283
|
);
|
|
5915
|
-
|
|
6284
|
+
if (status !== "ok") continue;
|
|
5916
6285
|
} else {
|
|
5917
6286
|
config.logger.warn(
|
|
5918
6287
|
`[apps] framework "${framework}" has no entryPoint template — skipping entry file for "${app.name}"`
|
|
5919
6288
|
);
|
|
5920
6289
|
}
|
|
6290
|
+
for (const extra of frameworkConfig.extraFiles ?? []) {
|
|
6291
|
+
if (!extra?.path || extra.template === void 0) continue;
|
|
6292
|
+
await emitAppFile(
|
|
6293
|
+
appDir,
|
|
6294
|
+
extra.path,
|
|
6295
|
+
extra.template,
|
|
6296
|
+
vars,
|
|
6297
|
+
config,
|
|
6298
|
+
report,
|
|
6299
|
+
result,
|
|
6300
|
+
app.name
|
|
6301
|
+
);
|
|
6302
|
+
}
|
|
6303
|
+
const eslintResult = await generateEslintConfig(
|
|
6304
|
+
appDir,
|
|
6305
|
+
app.name,
|
|
6306
|
+
config,
|
|
6307
|
+
report,
|
|
6308
|
+
{ usePerContextOverride: false }
|
|
6309
|
+
);
|
|
6310
|
+
mergeResult(result, eslintResult);
|
|
6311
|
+
}
|
|
6312
|
+
if (!result.error) {
|
|
6313
|
+
result.summary = `apps: ${result.created.length} created, ${result.updated.length} updated, ${result.skipped.length} skipped`;
|
|
5921
6314
|
}
|
|
5922
|
-
result.summary = `apps: ${result.created.length} created, ${result.updated.length} updated, ${result.skipped.length} skipped`;
|
|
5923
6315
|
return result;
|
|
5924
6316
|
} catch (err3) {
|
|
5925
6317
|
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
5926
6318
|
result.error = err3 instanceof Error ? err3 : new Error(`apps generation failed: ${message}`);
|
|
5927
6319
|
result.summary = `apps generation failed: ${message}`;
|
|
6320
|
+
config.logger.error(result.summary);
|
|
6321
|
+
if (report) report.record("error", "apps", result.summary);
|
|
5928
6322
|
return result;
|
|
5929
6323
|
}
|
|
5930
6324
|
}
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
export default tseslint.config(
|
|
5936
|
-
eslint.configs.recommended,
|
|
5937
|
-
...tseslint.configs.recommended,
|
|
5938
|
-
{
|
|
5939
|
-
rules: {
|
|
5940
|
-
'@typescript-eslint/no-explicit-any': 'warn',
|
|
5941
|
-
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
5942
|
-
},
|
|
5943
|
-
},
|
|
5944
|
-
{
|
|
5945
|
-
ignores: ['dist/**', 'node_modules/**'],
|
|
5946
|
-
},
|
|
5947
|
-
);
|
|
5948
|
-
`;
|
|
5949
|
-
function resolveTemplate3(manifest, moduleName) {
|
|
5950
|
-
const contextOverride = manifest.bounded_contexts?.find((c) => c.name === moduleName)?.generator?.eslint;
|
|
5951
|
-
if (contextOverride?.template !== void 0) {
|
|
5952
|
-
return { template: contextOverride.template, source: "per-context" };
|
|
5953
|
-
}
|
|
5954
|
-
const rootLevel = manifest.workspaceDefaults?.eslint;
|
|
5955
|
-
if (rootLevel?.template !== void 0) {
|
|
5956
|
-
return { template: rootLevel.template, source: "workspace" };
|
|
5957
|
-
}
|
|
5958
|
-
const monorepoLevel = manifest.monorepo?.workspaceDefaults?.eslint;
|
|
5959
|
-
if (monorepoLevel?.template !== void 0) {
|
|
5960
|
-
return { template: monorepoLevel.template, source: "workspace" };
|
|
5961
|
-
}
|
|
5962
|
-
return { template: BUILTIN_FALLBACK_TEMPLATE2, source: "fallback" };
|
|
6325
|
+
function relativeImportSpecifier(fromFile, toFile) {
|
|
6326
|
+
let rel = path7.relative(path7.dirname(fromFile), toFile).split(path7.sep).join("/").replace(/\.tsx?$/, ".js");
|
|
6327
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
6328
|
+
return rel;
|
|
5963
6329
|
}
|
|
5964
|
-
function
|
|
5965
|
-
if (
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
6330
|
+
function rewriteRelativeSpecifier(specifier, fromFile, toFile) {
|
|
6331
|
+
if (!specifier.startsWith(".")) return specifier;
|
|
6332
|
+
const absolute = path7.resolve(path7.dirname(fromFile), specifier);
|
|
6333
|
+
let rel = path7.relative(path7.dirname(toFile), absolute).split(path7.sep).join("/");
|
|
6334
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
6335
|
+
return rel;
|
|
5970
6336
|
}
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6337
|
+
var RESERVED_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
6338
|
+
"break",
|
|
6339
|
+
"case",
|
|
6340
|
+
"catch",
|
|
6341
|
+
"class",
|
|
6342
|
+
"const",
|
|
6343
|
+
"continue",
|
|
6344
|
+
"debugger",
|
|
6345
|
+
"default",
|
|
6346
|
+
"delete",
|
|
6347
|
+
"do",
|
|
6348
|
+
"else",
|
|
6349
|
+
"enum",
|
|
6350
|
+
"export",
|
|
6351
|
+
"extends",
|
|
6352
|
+
"false",
|
|
6353
|
+
"finally",
|
|
6354
|
+
"for",
|
|
6355
|
+
"function",
|
|
6356
|
+
"if",
|
|
6357
|
+
"import",
|
|
6358
|
+
"in",
|
|
6359
|
+
"instanceof",
|
|
6360
|
+
"new",
|
|
6361
|
+
"null",
|
|
6362
|
+
"return",
|
|
6363
|
+
"super",
|
|
6364
|
+
"switch",
|
|
6365
|
+
"this",
|
|
6366
|
+
"throw",
|
|
6367
|
+
"true",
|
|
6368
|
+
"try",
|
|
6369
|
+
"typeof",
|
|
6370
|
+
"var",
|
|
6371
|
+
"void",
|
|
6372
|
+
"while",
|
|
6373
|
+
"with",
|
|
6374
|
+
"yield",
|
|
6375
|
+
"let",
|
|
6376
|
+
"static",
|
|
6377
|
+
"implements",
|
|
6378
|
+
"interface",
|
|
6379
|
+
"package",
|
|
6380
|
+
"private",
|
|
6381
|
+
"protected",
|
|
6382
|
+
"public",
|
|
6383
|
+
"await"
|
|
6384
|
+
]);
|
|
6385
|
+
function safeParamName(name) {
|
|
6386
|
+
const candidate = name.length === 0 ? "dep" : name;
|
|
6387
|
+
return RESERVED_IDENTIFIERS.has(candidate) ? `${candidate}_` : candidate;
|
|
6016
6388
|
}
|
|
6017
6389
|
function analyzePortFile(portFilePath) {
|
|
6018
6390
|
try {
|
|
@@ -6089,13 +6461,22 @@ function extractImports(importDecls) {
|
|
|
6089
6461
|
}
|
|
6090
6462
|
return imports;
|
|
6091
6463
|
}
|
|
6092
|
-
function generateAdapterFromPort(analysis, adapterName) {
|
|
6464
|
+
function generateAdapterFromPort(analysis, adapterName, portImportSpecifier, outputFilePath) {
|
|
6093
6465
|
const { interfaceName, methods, imports } = analysis;
|
|
6094
|
-
const
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6466
|
+
const portImport = portImportSpecifier ? `import type { ${interfaceName} } from '${portImportSpecifier}';` : "";
|
|
6467
|
+
const importStatements = [
|
|
6468
|
+
portImport,
|
|
6469
|
+
...imports.map((imp) => {
|
|
6470
|
+
const specifier = outputFilePath ? rewriteRelativeSpecifier(
|
|
6471
|
+
imp.moduleSpecifier,
|
|
6472
|
+
analysis.filePath,
|
|
6473
|
+
outputFilePath
|
|
6474
|
+
) : imp.moduleSpecifier;
|
|
6475
|
+
const typeOnly = imp.isTypeOnly ? "type " : "";
|
|
6476
|
+
const names = imp.namedImports.join(", ");
|
|
6477
|
+
return `import ${typeOnly}{ ${names} } from '${specifier}';`;
|
|
6478
|
+
})
|
|
6479
|
+
].filter(Boolean).join("\n");
|
|
6099
6480
|
const methodImpls = methods.map((method) => {
|
|
6100
6481
|
const params = method.parameters.map((p) => `${p.name}${p.isOptional ? "?" : ""}: ${p.type}`).join(", ");
|
|
6101
6482
|
const asyncKeyword = method.isAsync ? "async " : "";
|
|
@@ -6123,16 +6504,48 @@ ${methodImpls}
|
|
|
6123
6504
|
}
|
|
6124
6505
|
`;
|
|
6125
6506
|
}
|
|
6126
|
-
function generateUseCaseFromPort(analysis, useCaseName, outPorts) {
|
|
6507
|
+
function generateUseCaseFromPort(analysis, useCaseName, outPorts, portImportSpecifier, outputFilePath) {
|
|
6127
6508
|
const { interfaceName, methods, imports } = analysis;
|
|
6128
|
-
const
|
|
6509
|
+
const importLines = [];
|
|
6510
|
+
const taken = /* @__PURE__ */ new Set();
|
|
6511
|
+
const importType = (name, specifier) => {
|
|
6512
|
+
let local = name;
|
|
6513
|
+
let n = 2;
|
|
6514
|
+
while (taken.has(local)) local = `${name}_${n++}`;
|
|
6515
|
+
taken.add(local);
|
|
6516
|
+
importLines.push(
|
|
6517
|
+
local === name ? `import type { ${name} } from '${specifier}';` : `import type { ${name} as ${local} } from '${specifier}';`
|
|
6518
|
+
);
|
|
6519
|
+
return local;
|
|
6520
|
+
};
|
|
6521
|
+
const implementsName = portImportSpecifier ? importType(interfaceName, portImportSpecifier) : interfaceName;
|
|
6522
|
+
const seenDeps = /* @__PURE__ */ new Map();
|
|
6523
|
+
const usedParams = /* @__PURE__ */ new Set();
|
|
6524
|
+
const constructorEntries = [];
|
|
6525
|
+
for (const p of outPorts) {
|
|
6526
|
+
const depKey = `${p.interfaceName}|${p.importSpecifier}`;
|
|
6527
|
+
if (seenDeps.has(depKey)) continue;
|
|
6528
|
+
const localType = importType(p.interfaceName, p.importSpecifier);
|
|
6529
|
+
seenDeps.set(depKey, localType);
|
|
6530
|
+
let param = safeParamName(p.paramName);
|
|
6531
|
+
const paramBase = param;
|
|
6532
|
+
let n = 2;
|
|
6533
|
+
while (usedParams.has(param)) param = `${paramBase}${n++}`;
|
|
6534
|
+
usedParams.add(param);
|
|
6535
|
+
constructorEntries.push(`private readonly ${param}: ${localType}`);
|
|
6536
|
+
}
|
|
6537
|
+
for (const imp of imports) {
|
|
6538
|
+
const specifier = outputFilePath ? rewriteRelativeSpecifier(
|
|
6539
|
+
imp.moduleSpecifier,
|
|
6540
|
+
analysis.filePath,
|
|
6541
|
+
outputFilePath
|
|
6542
|
+
) : imp.moduleSpecifier;
|
|
6129
6543
|
const typeOnly = imp.isTypeOnly ? "type " : "";
|
|
6130
|
-
const
|
|
6131
|
-
|
|
6132
|
-
}
|
|
6133
|
-
const
|
|
6134
|
-
|
|
6135
|
-
).join(",\n ");
|
|
6544
|
+
const line = `import ${typeOnly}{ ${imp.namedImports.join(", ")} } from '${specifier}';`;
|
|
6545
|
+
if (!importLines.includes(line)) importLines.push(line);
|
|
6546
|
+
}
|
|
6547
|
+
const importStatements = importLines.join("\n");
|
|
6548
|
+
const constructorParams = constructorEntries.join(",\n ");
|
|
6136
6549
|
const methodImpls = methods.map((method) => {
|
|
6137
6550
|
const params = method.parameters.map((p) => `${p.name}${p.isOptional ? "?" : ""}: ${p.type}`).join(", ");
|
|
6138
6551
|
const asyncKeyword = method.isAsync ? "async " : "";
|
|
@@ -6145,12 +6558,12 @@ function generateUseCaseFromPort(analysis, useCaseName, outPorts) {
|
|
|
6145
6558
|
throw new Error('Not implemented: ${method.name}');
|
|
6146
6559
|
}`;
|
|
6147
6560
|
}).join("\n\n");
|
|
6148
|
-
const constructorBlock =
|
|
6561
|
+
const constructorBlock = constructorEntries.length > 0 ? ` constructor(
|
|
6149
6562
|
${constructorParams}
|
|
6150
6563
|
) {}` : "";
|
|
6151
6564
|
return `// @generated use-case stub — edit freely
|
|
6152
6565
|
/**
|
|
6153
|
-
* ${useCaseName} implements ${
|
|
6566
|
+
* ${useCaseName} implements ${implementsName}
|
|
6154
6567
|
*
|
|
6155
6568
|
* This use case was generated from the port interface.
|
|
6156
6569
|
* Replace TODO implementations with actual business logic.
|
|
@@ -6158,7 +6571,7 @@ function generateUseCaseFromPort(analysis, useCaseName, outPorts) {
|
|
|
6158
6571
|
|
|
6159
6572
|
${importStatements}
|
|
6160
6573
|
|
|
6161
|
-
export class ${useCaseName} implements ${
|
|
6574
|
+
export class ${useCaseName} implements ${implementsName} {
|
|
6162
6575
|
${constructorBlock}
|
|
6163
6576
|
|
|
6164
6577
|
${methodImpls}
|
|
@@ -6551,9 +6964,15 @@ function resolveNaming(kind, contextNaming, manifestNaming) {
|
|
|
6551
6964
|
return contextNaming?.[kind] ?? manifestNaming?.[kind] ?? DEFAULT_NAMING[kind];
|
|
6552
6965
|
}
|
|
6553
6966
|
async function writeStubFile(filePath, content, config, report) {
|
|
6967
|
+
if (!isInScope(filePath, config)) {
|
|
6968
|
+
config.logger.debug(
|
|
6969
|
+
`skipped (outside --only) ${path7.relative(config.workspaceRoot, filePath)}`
|
|
6970
|
+
);
|
|
6971
|
+
return "skipped";
|
|
6972
|
+
}
|
|
6554
6973
|
try {
|
|
6555
|
-
await
|
|
6556
|
-
const relative =
|
|
6974
|
+
await fs5.stat(filePath);
|
|
6975
|
+
const relative = path7.relative(config.workspaceRoot, filePath);
|
|
6557
6976
|
config.logger.debug(`stub preserved ${relative}`);
|
|
6558
6977
|
if (report) {
|
|
6559
6978
|
report.record(
|
|
@@ -6568,15 +6987,19 @@ async function writeStubFile(filePath, content, config, report) {
|
|
|
6568
6987
|
throw err3;
|
|
6569
6988
|
}
|
|
6570
6989
|
}
|
|
6571
|
-
|
|
6990
|
+
if (!config.dryRun) {
|
|
6991
|
+
await fs5.mkdir(path7.dirname(filePath), { recursive: true });
|
|
6992
|
+
}
|
|
6572
6993
|
return safeWriteFileAtomic(filePath, content, config, report, false);
|
|
6573
6994
|
}
|
|
6574
|
-
async function tryAnalyzeRelatedPort(moduleDir, name, kind, context) {
|
|
6995
|
+
async function tryAnalyzeRelatedPort(moduleDir, name, kind, context, relatedPortNamingTemplate) {
|
|
6575
6996
|
const portType = kind === "adapter" ? "out" : "in";
|
|
6576
6997
|
const portSubdir = `application/ports/${portType}`;
|
|
6577
6998
|
const derivedPortName = name.replace(/Adapter$|UseCase$/, "Port");
|
|
6578
6999
|
const declaredPorts = portType === "in" ? context.layers?.application?.ports?.in || [] : context.layers?.application?.ports?.out || [];
|
|
6579
|
-
if (!declaredPorts.some(
|
|
7000
|
+
if (!declaredPorts.some(
|
|
7001
|
+
(p) => normalizeStubName(portName(p), relatedPortNamingTemplate) === derivedPortName
|
|
7002
|
+
)) {
|
|
6580
7003
|
return null;
|
|
6581
7004
|
}
|
|
6582
7005
|
const possibleFilenames = [
|
|
@@ -6585,7 +7008,7 @@ async function tryAnalyzeRelatedPort(moduleDir, name, kind, context) {
|
|
|
6585
7008
|
`${derivedPortName}.ts`
|
|
6586
7009
|
];
|
|
6587
7010
|
for (const filename of possibleFilenames) {
|
|
6588
|
-
const portFilePath =
|
|
7011
|
+
const portFilePath = path7.join(moduleDir, "src", portSubdir, filename);
|
|
6589
7012
|
const analysis = analyzePortFile(portFilePath);
|
|
6590
7013
|
if (analysis) {
|
|
6591
7014
|
return analysis;
|
|
@@ -6593,6 +7016,15 @@ async function tryAnalyzeRelatedPort(moduleDir, name, kind, context) {
|
|
|
6593
7016
|
}
|
|
6594
7017
|
return null;
|
|
6595
7018
|
}
|
|
7019
|
+
function normalizeStubName(rawName, namingTemplate) {
|
|
7020
|
+
const placeholder = "{name}";
|
|
7021
|
+
const idx = namingTemplate.lastIndexOf(placeholder);
|
|
7022
|
+
const ext = idx >= 0 ? namingTemplate.slice(idx + placeholder.length) : "";
|
|
7023
|
+
const base = ext && rawName.endsWith(ext) ? rawName.slice(0, -ext.length) : rawName;
|
|
7024
|
+
const pascal = base.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
7025
|
+
if (pascal.length === 0) return "Stub";
|
|
7026
|
+
return /^[0-9]/.test(pascal) ? `Stub${pascal}` : pascal;
|
|
7027
|
+
}
|
|
6596
7028
|
async function generateStubs(moduleDir, moduleName, config, report) {
|
|
6597
7029
|
const result = createEmptyResult();
|
|
6598
7030
|
const stubs = config.manifest.generator?.sync?.stubs;
|
|
@@ -6621,27 +7053,73 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
6621
7053
|
for (const { kind, subdir, names } of plan) {
|
|
6622
7054
|
const contentTemplate = resolveTemplate4(kind, manifestTemplates);
|
|
6623
7055
|
const namingTemplate = resolveNaming(kind, contextNaming, manifestNaming);
|
|
6624
|
-
for (const
|
|
7056
|
+
for (const rawName of names) {
|
|
7057
|
+
const name = normalizeStubName(rawName, namingTemplate);
|
|
6625
7058
|
const filename = interpolateWithLog(
|
|
6626
7059
|
namingTemplate,
|
|
6627
7060
|
name,
|
|
6628
7061
|
`stubs.naming.${kind}`,
|
|
6629
7062
|
config
|
|
6630
7063
|
);
|
|
7064
|
+
const filePath = path7.join(moduleDir, "src", subdir, filename);
|
|
6631
7065
|
let content;
|
|
6632
7066
|
if (kind === "adapter" || kind === "useCase") {
|
|
7067
|
+
const relatedPortNaming = resolveNaming(
|
|
7068
|
+
kind === "adapter" ? "outPort" : "inPort",
|
|
7069
|
+
contextNaming,
|
|
7070
|
+
manifestNaming
|
|
7071
|
+
);
|
|
6633
7072
|
const portAnalysis = await tryAnalyzeRelatedPort(
|
|
6634
7073
|
moduleDir,
|
|
6635
7074
|
name,
|
|
6636
7075
|
kind,
|
|
6637
|
-
context
|
|
7076
|
+
context,
|
|
7077
|
+
relatedPortNaming
|
|
6638
7078
|
);
|
|
6639
7079
|
if (portAnalysis) {
|
|
6640
7080
|
if (kind === "adapter") {
|
|
6641
|
-
content = generateAdapterFromPort(
|
|
7081
|
+
content = generateAdapterFromPort(
|
|
7082
|
+
portAnalysis,
|
|
7083
|
+
name,
|
|
7084
|
+
relativeImportSpecifier(filePath, portAnalysis.filePath),
|
|
7085
|
+
filePath
|
|
7086
|
+
);
|
|
6642
7087
|
} else {
|
|
6643
|
-
const
|
|
6644
|
-
|
|
7088
|
+
const outPortNaming = resolveNaming(
|
|
7089
|
+
"outPort",
|
|
7090
|
+
contextNaming,
|
|
7091
|
+
manifestNaming
|
|
7092
|
+
);
|
|
7093
|
+
const outPortDir = path7.join(
|
|
7094
|
+
moduleDir,
|
|
7095
|
+
"src",
|
|
7096
|
+
"application",
|
|
7097
|
+
"ports",
|
|
7098
|
+
"out"
|
|
7099
|
+
);
|
|
7100
|
+
const outPorts = (context.layers?.application?.ports?.out ?? []).map((p) => {
|
|
7101
|
+
const base = normalizeStubName(portName(p), outPortNaming);
|
|
7102
|
+
const outFile = interpolateWithLog(
|
|
7103
|
+
outPortNaming,
|
|
7104
|
+
base,
|
|
7105
|
+
"stubs.naming.outPort",
|
|
7106
|
+
config
|
|
7107
|
+
);
|
|
7108
|
+
const outPortPath = path7.join(outPortDir, outFile);
|
|
7109
|
+
const analyzed = analyzePortFile(outPortPath);
|
|
7110
|
+
return {
|
|
7111
|
+
interfaceName: analyzed?.interfaceName ?? `${base}Port`,
|
|
7112
|
+
paramName: base.charAt(0).toLowerCase() + base.slice(1),
|
|
7113
|
+
importSpecifier: relativeImportSpecifier(filePath, outPortPath)
|
|
7114
|
+
};
|
|
7115
|
+
});
|
|
7116
|
+
content = generateUseCaseFromPort(
|
|
7117
|
+
portAnalysis,
|
|
7118
|
+
name,
|
|
7119
|
+
outPorts,
|
|
7120
|
+
relativeImportSpecifier(filePath, portAnalysis.filePath),
|
|
7121
|
+
filePath
|
|
7122
|
+
);
|
|
6645
7123
|
}
|
|
6646
7124
|
config.logger.debug(`Generated ${kind} '${name}' from port analysis`);
|
|
6647
7125
|
} else {
|
|
@@ -6660,17 +7138,349 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
6660
7138
|
config
|
|
6661
7139
|
);
|
|
6662
7140
|
}
|
|
6663
|
-
const filePath = path6.join(moduleDir, "src", subdir, filename);
|
|
6664
7141
|
const status = await writeStubFile(filePath, content, config, report);
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
7142
|
+
recordWriteStatus(result, filePath, status);
|
|
7143
|
+
}
|
|
7144
|
+
}
|
|
7145
|
+
return result;
|
|
7146
|
+
}
|
|
7147
|
+
var OHS_NOTE = "\n *\n * Open Host Service (open-host): this is this context's published language for consuming contexts — keep it stable.";
|
|
7148
|
+
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.";
|
|
7149
|
+
function addAll(map, key, values) {
|
|
7150
|
+
const set = map.get(key) ?? /* @__PURE__ */ new Set();
|
|
7151
|
+
values.forEach((v) => set.add(v));
|
|
7152
|
+
map.set(key, set);
|
|
7153
|
+
}
|
|
7154
|
+
function toPascalCase2(stem) {
|
|
7155
|
+
return stem.split(/[-.]/).filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
7156
|
+
}
|
|
7157
|
+
function toCamelCase(pascal) {
|
|
7158
|
+
return pascal.length > 0 ? pascal.charAt(0).toLowerCase() + pascal.slice(1) : pascal;
|
|
7159
|
+
}
|
|
7160
|
+
function isSafePathSegment(name) {
|
|
7161
|
+
return name.length > 0 && !name.includes("..") && !name.includes("/") && !name.includes("\\") && !name.startsWith(".");
|
|
7162
|
+
}
|
|
7163
|
+
function isValidTsIdentifier(name) {
|
|
7164
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
|
|
7165
|
+
}
|
|
7166
|
+
function eventContractContent(name) {
|
|
7167
|
+
return `// @generated cross-context event contract — edit freely
|
|
7168
|
+
/**
|
|
7169
|
+
* ${name} is a domain event published across an event-bus boundary.
|
|
7170
|
+
* Both the publishing and subscribing contexts depend on this shared contract.
|
|
7171
|
+
*/
|
|
7172
|
+
export interface ${name} {
|
|
7173
|
+
// TODO: define the event payload
|
|
7174
|
+
readonly occurredAt: string;
|
|
7175
|
+
}
|
|
7176
|
+
`;
|
|
7177
|
+
}
|
|
7178
|
+
function dtoContent(op) {
|
|
7179
|
+
return `// @generated cross-context DTO — edit freely
|
|
7180
|
+
/**
|
|
7181
|
+
* Request/response payloads for the ${op} operation, exchanged across the
|
|
7182
|
+
* network boundary. Both the calling (client) and serving (controller) contexts
|
|
7183
|
+
* depend on these shared contracts.
|
|
7184
|
+
*/
|
|
7185
|
+
export interface ${op}Request {
|
|
7186
|
+
// TODO: define the request fields
|
|
7187
|
+
readonly _placeholder?: never;
|
|
7188
|
+
}
|
|
7189
|
+
|
|
7190
|
+
export interface ${op}Response {
|
|
7191
|
+
// TODO: define the response fields
|
|
7192
|
+
readonly _placeholder?: never;
|
|
7193
|
+
}
|
|
7194
|
+
`;
|
|
7195
|
+
}
|
|
7196
|
+
function portContent(scope, interfaceName, methods, importedTypes, doc) {
|
|
7197
|
+
const uniqueImports = [...new Set(importedTypes)].sort();
|
|
7198
|
+
const importLine = uniqueImports.length > 0 ? `import type { ${uniqueImports.join(", ")} } from "@${scope}/shared";
|
|
7199
|
+
|
|
7200
|
+
` : "";
|
|
7201
|
+
const methodLines = methods.map(
|
|
7202
|
+
(m) => ` ${m.name}(${m.paramName}: ${m.paramType}): Promise<${m.returnType}>;`
|
|
7203
|
+
).join("\n");
|
|
7204
|
+
return `// @generated cross-context port — edit freely
|
|
7205
|
+
${importLine}/**
|
|
7206
|
+
* ${doc}
|
|
7207
|
+
*/
|
|
7208
|
+
export interface ${interfaceName} {
|
|
7209
|
+
${methodLines}
|
|
7210
|
+
}
|
|
7211
|
+
`;
|
|
7212
|
+
}
|
|
7213
|
+
async function emitPortAndAdapter(result, config, report, scope, spec) {
|
|
7214
|
+
const moduleRoot = path7.join(
|
|
7215
|
+
config.workspaceRoot,
|
|
7216
|
+
"packages",
|
|
7217
|
+
spec.contextName
|
|
7218
|
+
);
|
|
7219
|
+
const portDir = path7.join(
|
|
7220
|
+
moduleRoot,
|
|
7221
|
+
"src",
|
|
7222
|
+
"application",
|
|
7223
|
+
"ports",
|
|
7224
|
+
spec.portKind
|
|
7225
|
+
);
|
|
7226
|
+
const portPath = path7.join(
|
|
7227
|
+
portDir,
|
|
7228
|
+
`${spec.portBase}.${spec.portKind}-port.ts`
|
|
7229
|
+
);
|
|
7230
|
+
if (!isInScope(portPath, config)) {
|
|
7231
|
+
return;
|
|
7232
|
+
}
|
|
7233
|
+
if (!config.dryRun) {
|
|
7234
|
+
await fs5.mkdir(portDir, { recursive: true });
|
|
7235
|
+
}
|
|
7236
|
+
recordWriteStatus(
|
|
7237
|
+
result,
|
|
7238
|
+
portPath,
|
|
7239
|
+
await safeWriteFileAtomic(
|
|
7240
|
+
portPath,
|
|
7241
|
+
portContent(
|
|
7242
|
+
scope,
|
|
7243
|
+
spec.interfaceName,
|
|
7244
|
+
spec.methods,
|
|
7245
|
+
spec.importedTypes,
|
|
7246
|
+
spec.doc
|
|
7247
|
+
),
|
|
7248
|
+
config,
|
|
7249
|
+
report
|
|
7250
|
+
)
|
|
7251
|
+
);
|
|
7252
|
+
const analysis = analyzePortFile(portPath);
|
|
7253
|
+
if (!analysis) {
|
|
7254
|
+
config.logger.warn(
|
|
7255
|
+
`[cross-context] could not analyze ${portPath}; skipping adapter`
|
|
7256
|
+
);
|
|
7257
|
+
return;
|
|
7258
|
+
}
|
|
7259
|
+
const adapterDir = path7.join(moduleRoot, "src", "infrastructure", "adapters");
|
|
7260
|
+
const adapterPath = path7.join(adapterDir, `${spec.portBase}.adapter.ts`);
|
|
7261
|
+
if (!isInScope(adapterPath, config)) {
|
|
7262
|
+
return;
|
|
7263
|
+
}
|
|
7264
|
+
if (!config.dryRun) {
|
|
7265
|
+
await fs5.mkdir(adapterDir, { recursive: true });
|
|
7266
|
+
}
|
|
7267
|
+
const adapterClassName = `${toPascalCase2(spec.portBase)}Adapter`;
|
|
7268
|
+
const portSpecifier = relativeImportSpecifier(adapterPath, portPath);
|
|
7269
|
+
recordWriteStatus(
|
|
7270
|
+
result,
|
|
7271
|
+
adapterPath,
|
|
7272
|
+
await safeWriteFileAtomic(
|
|
7273
|
+
adapterPath,
|
|
7274
|
+
generateAdapterFromPort(analysis, adapterClassName, portSpecifier),
|
|
7275
|
+
config,
|
|
7276
|
+
report
|
|
7277
|
+
)
|
|
7278
|
+
);
|
|
7279
|
+
}
|
|
7280
|
+
function operationMethods(ops) {
|
|
7281
|
+
return ops.map((op) => ({
|
|
7282
|
+
name: toCamelCase(op),
|
|
7283
|
+
paramName: "request",
|
|
7284
|
+
paramType: `${op}Request`,
|
|
7285
|
+
returnType: `${op}Response`
|
|
7286
|
+
}));
|
|
7287
|
+
}
|
|
7288
|
+
function operationImports(ops) {
|
|
7289
|
+
return ops.flatMap((op) => [`${op}Request`, `${op}Response`]);
|
|
7290
|
+
}
|
|
7291
|
+
async function writeSharedContract(result, config, report, relSegments, content) {
|
|
7292
|
+
const contractPath = path7.join(
|
|
7293
|
+
config.workspaceRoot,
|
|
7294
|
+
"packages",
|
|
7295
|
+
"shared",
|
|
7296
|
+
"src",
|
|
7297
|
+
...relSegments
|
|
7298
|
+
);
|
|
7299
|
+
if (!config.dryRun) {
|
|
7300
|
+
await fs5.mkdir(path7.dirname(contractPath), { recursive: true });
|
|
7301
|
+
}
|
|
7302
|
+
recordWriteStatus(
|
|
7303
|
+
result,
|
|
7304
|
+
contractPath,
|
|
7305
|
+
await safeWriteFileAtomic(contractPath, content, config, report)
|
|
7306
|
+
);
|
|
7307
|
+
}
|
|
7308
|
+
async function generateCrossContext(config, report) {
|
|
7309
|
+
const result = createEmptyResult();
|
|
7310
|
+
const edges = config.manifest.cross_context;
|
|
7311
|
+
if (!Array.isArray(edges) || edges.length === 0) return result;
|
|
7312
|
+
const scope = resolveScope(config.manifest);
|
|
7313
|
+
const allEvents = /* @__PURE__ */ new Set();
|
|
7314
|
+
const publisherEvents = /* @__PURE__ */ new Map();
|
|
7315
|
+
const subscriberEvents = /* @__PURE__ */ new Map();
|
|
7316
|
+
const allOperations = /* @__PURE__ */ new Set();
|
|
7317
|
+
const controllerOps = /* @__PURE__ */ new Map();
|
|
7318
|
+
const clientOps = /* @__PURE__ */ new Map();
|
|
7319
|
+
const ohsProviders = /* @__PURE__ */ new Set();
|
|
7320
|
+
const aclConsumers = /* @__PURE__ */ new Set();
|
|
7321
|
+
for (const edge of edges) {
|
|
7322
|
+
if (edge.provider && !isSafePathSegment(edge.provider) || edge.consumer && !isSafePathSegment(edge.consumer)) {
|
|
7323
|
+
config.logger.warn(
|
|
7324
|
+
`[cross-context] skipping edge with unsafe context name: ${edge.consumer} -> ${edge.provider}`
|
|
7325
|
+
);
|
|
7326
|
+
continue;
|
|
6670
7327
|
}
|
|
7328
|
+
if (edge.integrationPattern === "open-host" && edge.provider)
|
|
7329
|
+
ohsProviders.add(edge.provider);
|
|
7330
|
+
if (edge.integrationPattern === "acl" && edge.consumer)
|
|
7331
|
+
aclConsumers.add(edge.consumer);
|
|
7332
|
+
if (edge.transport === "network") {
|
|
7333
|
+
const operations = (edge.operations ?? []).filter(
|
|
7334
|
+
(o) => typeof o === "string" && isValidTsIdentifier(o)
|
|
7335
|
+
);
|
|
7336
|
+
operations.forEach((o) => allOperations.add(o));
|
|
7337
|
+
if (edge.provider) addAll(controllerOps, edge.provider, operations);
|
|
7338
|
+
if (edge.consumer) addAll(clientOps, edge.consumer, operations);
|
|
7339
|
+
} else {
|
|
7340
|
+
const events = (edge.events ?? []).filter(
|
|
7341
|
+
(e) => typeof e === "string" && isValidTsIdentifier(e)
|
|
7342
|
+
);
|
|
7343
|
+
events.forEach((e) => allEvents.add(e));
|
|
7344
|
+
if (edge.provider) addAll(publisherEvents, edge.provider, events);
|
|
7345
|
+
if (edge.consumer) addAll(subscriberEvents, edge.consumer, events);
|
|
7346
|
+
}
|
|
7347
|
+
}
|
|
7348
|
+
for (const event of [...allEvents].sort()) {
|
|
7349
|
+
await writeSharedContract(
|
|
7350
|
+
result,
|
|
7351
|
+
config,
|
|
7352
|
+
report,
|
|
7353
|
+
["domain", "events", `${event}.event.ts`],
|
|
7354
|
+
eventContractContent(event)
|
|
7355
|
+
);
|
|
7356
|
+
}
|
|
7357
|
+
for (const provider of [...publisherEvents.keys()].sort()) {
|
|
7358
|
+
const events = [...publisherEvents.get(provider) ?? []].sort();
|
|
7359
|
+
await emitPortAndAdapter(result, config, report, scope, {
|
|
7360
|
+
contextName: provider,
|
|
7361
|
+
portKind: "out",
|
|
7362
|
+
portBase: "message-publisher",
|
|
7363
|
+
interfaceName: "MessagePublisherPort",
|
|
7364
|
+
methods: [
|
|
7365
|
+
{
|
|
7366
|
+
name: "publish",
|
|
7367
|
+
paramName: "event",
|
|
7368
|
+
paramType: events.join(" | ") || "unknown",
|
|
7369
|
+
returnType: "void"
|
|
7370
|
+
}
|
|
7371
|
+
],
|
|
7372
|
+
importedTypes: events,
|
|
7373
|
+
doc: "Publishes this context's domain events across the event-bus boundary." + (ohsProviders.has(provider) ? OHS_NOTE : "")
|
|
7374
|
+
});
|
|
7375
|
+
}
|
|
7376
|
+
for (const consumer of [...subscriberEvents.keys()].sort()) {
|
|
7377
|
+
const events = [...subscriberEvents.get(consumer) ?? []].sort();
|
|
7378
|
+
await emitPortAndAdapter(result, config, report, scope, {
|
|
7379
|
+
contextName: consumer,
|
|
7380
|
+
portKind: "in",
|
|
7381
|
+
portBase: "event-listener",
|
|
7382
|
+
interfaceName: "EventListenerPort",
|
|
7383
|
+
methods: [
|
|
7384
|
+
{
|
|
7385
|
+
name: "handle",
|
|
7386
|
+
paramName: "event",
|
|
7387
|
+
paramType: events.join(" | ") || "unknown",
|
|
7388
|
+
returnType: "void"
|
|
7389
|
+
}
|
|
7390
|
+
],
|
|
7391
|
+
importedTypes: events,
|
|
7392
|
+
doc: "Handles cross-context events this context subscribes to." + (aclConsumers.has(consumer) ? ACL_NOTE : "")
|
|
7393
|
+
});
|
|
7394
|
+
}
|
|
7395
|
+
for (const op of [...allOperations].sort()) {
|
|
7396
|
+
await writeSharedContract(
|
|
7397
|
+
result,
|
|
7398
|
+
config,
|
|
7399
|
+
report,
|
|
7400
|
+
["domain", "dtos", `${op}.dto.ts`],
|
|
7401
|
+
dtoContent(op)
|
|
7402
|
+
);
|
|
7403
|
+
}
|
|
7404
|
+
for (const provider of [...controllerOps.keys()].sort()) {
|
|
7405
|
+
const ops = [...controllerOps.get(provider) ?? []].sort();
|
|
7406
|
+
await emitPortAndAdapter(result, config, report, scope, {
|
|
7407
|
+
contextName: provider,
|
|
7408
|
+
portKind: "in",
|
|
7409
|
+
portBase: "rest-controller",
|
|
7410
|
+
interfaceName: "RestControllerPort",
|
|
7411
|
+
methods: operationMethods(ops),
|
|
7412
|
+
importedTypes: operationImports(ops),
|
|
7413
|
+
doc: "Serves this context's operations over the network boundary." + (ohsProviders.has(provider) ? OHS_NOTE : "")
|
|
7414
|
+
});
|
|
7415
|
+
}
|
|
7416
|
+
for (const consumer of [...clientOps.keys()].sort()) {
|
|
7417
|
+
const ops = [...clientOps.get(consumer) ?? []].sort();
|
|
7418
|
+
await emitPortAndAdapter(result, config, report, scope, {
|
|
7419
|
+
contextName: consumer,
|
|
7420
|
+
portKind: "out",
|
|
7421
|
+
portBase: "external-service-client",
|
|
7422
|
+
interfaceName: "ExternalServiceClientPort",
|
|
7423
|
+
methods: operationMethods(ops),
|
|
7424
|
+
importedTypes: operationImports(ops),
|
|
7425
|
+
doc: "Calls operations on the contexts this context depends on over the network." + (aclConsumers.has(consumer) ? ACL_NOTE : "")
|
|
7426
|
+
});
|
|
6671
7427
|
}
|
|
6672
7428
|
return result;
|
|
6673
7429
|
}
|
|
7430
|
+
var RESULT_KERNEL = `// @generated by @hexagen/sync — shared Result kernel (edit freely)
|
|
7431
|
+
/**
|
|
7432
|
+
* Result is the explicit success/failure type generated use-cases return.
|
|
7433
|
+
* Mirrors @hexagen/shared's Result. Created once, then preserved on re-sync.
|
|
7434
|
+
*/
|
|
7435
|
+
export type Result<T, E = unknown> =
|
|
7436
|
+
| { success: true; value: T }
|
|
7437
|
+
| { success: false; error: E };
|
|
7438
|
+
|
|
7439
|
+
export const ok = <T>(value: T): Result<T, never> => ({ success: true, value });
|
|
7440
|
+
export const err = <E>(error: E): Result<never, E> => ({
|
|
7441
|
+
success: false,
|
|
7442
|
+
error,
|
|
7443
|
+
});
|
|
7444
|
+
`;
|
|
7445
|
+
async function generateSharedKernel(config, report) {
|
|
7446
|
+
const result = createEmptyResult();
|
|
7447
|
+
if (config.mode !== "external") return result;
|
|
7448
|
+
const hasShared = (config.manifest.bounded_contexts ?? []).some(
|
|
7449
|
+
(bc) => bc.name?.toLowerCase() === "shared"
|
|
7450
|
+
);
|
|
7451
|
+
if (!hasShared) return result;
|
|
7452
|
+
const kernelPath = path7.join(
|
|
7453
|
+
config.workspaceRoot,
|
|
7454
|
+
"packages",
|
|
7455
|
+
"shared",
|
|
7456
|
+
"src",
|
|
7457
|
+
"domain",
|
|
7458
|
+
"result.ts"
|
|
7459
|
+
);
|
|
7460
|
+
if (!isInScope(kernelPath, config)) {
|
|
7461
|
+
result.skipped.push(kernelPath);
|
|
7462
|
+
return result;
|
|
7463
|
+
}
|
|
7464
|
+
try {
|
|
7465
|
+
await fs5.stat(kernelPath);
|
|
7466
|
+
result.skipped.push(kernelPath);
|
|
7467
|
+
return result;
|
|
7468
|
+
} catch (err3) {
|
|
7469
|
+
if (err3.code !== "ENOENT") throw err3;
|
|
7470
|
+
}
|
|
7471
|
+
if (!config.dryRun) {
|
|
7472
|
+
await fs5.mkdir(path7.dirname(kernelPath), { recursive: true });
|
|
7473
|
+
}
|
|
7474
|
+
const status = await safeWriteFileAtomic(
|
|
7475
|
+
kernelPath,
|
|
7476
|
+
RESULT_KERNEL,
|
|
7477
|
+
config,
|
|
7478
|
+
report,
|
|
7479
|
+
false
|
|
7480
|
+
);
|
|
7481
|
+
recordWriteStatus(result, kernelPath, status);
|
|
7482
|
+
return result;
|
|
7483
|
+
}
|
|
6674
7484
|
var execAsync = promisify(exec);
|
|
6675
7485
|
var MAX_BUFFER = 1024 * 1024 * 10;
|
|
6676
7486
|
async function ensureDependenciesBuilt(config) {
|
|
@@ -6698,18 +7508,31 @@ async function ensureDependenciesBuilt(config) {
|
|
|
6698
7508
|
}
|
|
6699
7509
|
|
|
6700
7510
|
// src/sync-engine-helpers.ts
|
|
6701
|
-
function
|
|
7511
|
+
function mergeResult2(dest, src) {
|
|
6702
7512
|
dest.created.push(...src.created);
|
|
6703
7513
|
dest.updated.push(...src.updated);
|
|
6704
7514
|
dest.skipped.push(...src.skipped);
|
|
7515
|
+
dest.deleted.push(...src.deleted);
|
|
7516
|
+
dest.unchanged.push(...src.unchanged);
|
|
6705
7517
|
dest.totalOps += src.totalOps;
|
|
7518
|
+
if (src.error && !dest.error) {
|
|
7519
|
+
dest.error = src.error;
|
|
7520
|
+
dest.summary = src.summary;
|
|
7521
|
+
}
|
|
6706
7522
|
}
|
|
6707
7523
|
function mergeBarrelPasses(firstPass, secondPass) {
|
|
6708
7524
|
const combined = createEmptyResult();
|
|
6709
7525
|
const secondPaths = /* @__PURE__ */ new Set([
|
|
6710
7526
|
...secondPass.created,
|
|
6711
7527
|
...secondPass.updated,
|
|
6712
|
-
...secondPass.skipped
|
|
7528
|
+
...secondPass.skipped,
|
|
7529
|
+
...secondPass.deleted
|
|
7530
|
+
]);
|
|
7531
|
+
const secondAll = /* @__PURE__ */ new Set([...secondPaths, ...secondPass.unchanged]);
|
|
7532
|
+
const firstMutations = /* @__PURE__ */ new Set([
|
|
7533
|
+
...firstPass.created,
|
|
7534
|
+
...firstPass.updated,
|
|
7535
|
+
...firstPass.deleted
|
|
6713
7536
|
]);
|
|
6714
7537
|
for (const p of firstPass.created) {
|
|
6715
7538
|
if (!secondPaths.has(p)) combined.created.push(p);
|
|
@@ -6718,12 +7541,29 @@ function mergeBarrelPasses(firstPass, secondPass) {
|
|
|
6718
7541
|
if (!secondPaths.has(p)) combined.updated.push(p);
|
|
6719
7542
|
}
|
|
6720
7543
|
for (const p of firstPass.skipped) {
|
|
6721
|
-
if (!
|
|
7544
|
+
if (!secondAll.has(p)) combined.skipped.push(p);
|
|
7545
|
+
}
|
|
7546
|
+
for (const p of firstPass.deleted) {
|
|
7547
|
+
if (!secondPaths.has(p)) combined.deleted.push(p);
|
|
7548
|
+
}
|
|
7549
|
+
for (const p of firstPass.unchanged) {
|
|
7550
|
+
if (!secondAll.has(p)) combined.unchanged.push(p);
|
|
6722
7551
|
}
|
|
6723
7552
|
combined.created.push(...secondPass.created);
|
|
6724
7553
|
combined.updated.push(...secondPass.updated);
|
|
6725
7554
|
combined.skipped.push(...secondPass.skipped);
|
|
6726
|
-
combined.
|
|
7555
|
+
combined.deleted.push(...secondPass.deleted);
|
|
7556
|
+
for (const p of secondPass.unchanged) {
|
|
7557
|
+
if (!firstMutations.has(p)) combined.unchanged.push(p);
|
|
7558
|
+
}
|
|
7559
|
+
combined.totalOps = combined.created.length + combined.updated.length + combined.deleted.length;
|
|
7560
|
+
if (firstPass.error) {
|
|
7561
|
+
combined.error = firstPass.error;
|
|
7562
|
+
combined.summary = firstPass.summary;
|
|
7563
|
+
} else if (secondPass.error) {
|
|
7564
|
+
combined.error = secondPass.error;
|
|
7565
|
+
combined.summary = secondPass.summary;
|
|
7566
|
+
}
|
|
6727
7567
|
return combined;
|
|
6728
7568
|
}
|
|
6729
7569
|
|
|
@@ -6732,14 +7572,15 @@ function caseInsensitiveEnum(schema, dir = "lower") {
|
|
|
6732
7572
|
return external_exports.preprocess((value) => typeof value === "string" ? dir === "lower" ? value.trim().toLowerCase() : value.trim().toUpperCase() : value, schema);
|
|
6733
7573
|
}
|
|
6734
7574
|
var BoundedContextTypeSchema = boundedContextTypeSchema;
|
|
6735
|
-
var
|
|
7575
|
+
var PLANE_NAMES = [
|
|
6736
7576
|
"projection",
|
|
6737
7577
|
"probabilistic",
|
|
6738
7578
|
"infrastructure",
|
|
6739
7579
|
"shared-kernel",
|
|
6740
7580
|
"core",
|
|
6741
7581
|
"supporting"
|
|
6742
|
-
]
|
|
7582
|
+
];
|
|
7583
|
+
var PlaneTypeSchema = caseInsensitiveEnum(external_exports.enum(PLANE_NAMES));
|
|
6743
7584
|
var StatusTypeSchema = caseInsensitiveEnum(external_exports.enum(["active", "frozen", "deprecated", "experimental"]));
|
|
6744
7585
|
var RelationshipPatternSchema = caseInsensitiveEnum(external_exports.enum(["U/D", "ACL", "SK", "P", "OHS"]), "upper");
|
|
6745
7586
|
var RelationshipRoleSchema = caseInsensitiveEnum(external_exports.enum(["upstream", "downstream", "peer"]));
|
|
@@ -6850,12 +7691,23 @@ var IndexManifestSchema = external_exports.object({
|
|
|
6850
7691
|
message: "Context plane does not match file path subdirectory",
|
|
6851
7692
|
path: ["bounded_contexts"]
|
|
6852
7693
|
});
|
|
7694
|
+
var CrossContextEdgeSchema = external_exports.object({
|
|
7695
|
+
consumer: external_exports.string(),
|
|
7696
|
+
provider: external_exports.string(),
|
|
7697
|
+
transport: external_exports.enum(["event-bus", "network"]),
|
|
7698
|
+
events: external_exports.array(external_exports.string()).optional(),
|
|
7699
|
+
operations: external_exports.array(external_exports.string()).optional(),
|
|
7700
|
+
integrationPattern: external_exports.enum(["open-host", "acl"]).optional()
|
|
7701
|
+
});
|
|
6853
7702
|
var ManifestSchema = external_exports.object({
|
|
6854
7703
|
version: external_exports.string().optional(),
|
|
6855
7704
|
description: external_exports.string().optional(),
|
|
6856
7705
|
system: external_exports.string().optional(),
|
|
6857
7706
|
scope: external_exports.string().optional(),
|
|
6858
7707
|
architecture: external_exports.string().optional(),
|
|
7708
|
+
// The wizard records the chosen workspace template (e.g. "strict-enterprise")
|
|
7709
|
+
// alongside `architecture`; persisted into .architecture/manifest.yaml.
|
|
7710
|
+
workspaceTemplate: external_exports.string().optional(),
|
|
6859
7711
|
planes: external_exports.record(external_exports.array(external_exports.string())).optional(),
|
|
6860
7712
|
monorepo: external_exports.record(external_exports.unknown()).optional(),
|
|
6861
7713
|
generator: external_exports.record(external_exports.unknown()).optional(),
|
|
@@ -6870,6 +7722,7 @@ var ManifestSchema = external_exports.object({
|
|
|
6870
7722
|
})).optional(),
|
|
6871
7723
|
bounded_contexts: external_exports.array(BoundedContextSchema),
|
|
6872
7724
|
apps: external_exports.array(AppSchema).optional(),
|
|
7725
|
+
cross_context: external_exports.array(CrossContextEdgeSchema).optional(),
|
|
6873
7726
|
context_mappings: external_exports.array(external_exports.object({
|
|
6874
7727
|
upstream: external_exports.string(),
|
|
6875
7728
|
downstream: external_exports.string(),
|
|
@@ -6938,7 +7791,15 @@ var BoundedContextSchema2 = external_exports.object({
|
|
|
6938
7791
|
id: external_exports.string(),
|
|
6939
7792
|
name: external_exports.string().min(1, "Please enter a name for this bounded context (e.g., 'UserService', 'OrderProcessing')"),
|
|
6940
7793
|
description: external_exports.string().optional(),
|
|
6941
|
-
|
|
7794
|
+
// ADR-0041: `infrastructureTarget` (API backend) and `uiFramework` (below)
|
|
7795
|
+
// are PROJECT-LEVEL choices managed by the wizard's Applications step, which
|
|
7796
|
+
// fans a single selection out to every context. They persist per-context (the
|
|
7797
|
+
// source of truth `deriveApps` reads), but are NOT direct per-context input —
|
|
7798
|
+
// do not re-add per-context UI/API editing without revisiting ADR-0041.
|
|
7799
|
+
// `"none"` = the project opts out of a separate API backend (UI-only, e.g. a
|
|
7800
|
+
// Next.js app with built-in routes); `deriveApps` then emits no `api` app.
|
|
7801
|
+
// Distinct from `undefined` (legacy/unset → defaults to the preset).
|
|
7802
|
+
infrastructureTarget: external_exports.enum(["nestjs", "express", "serverless", "plain-ts", "nitro", "none"]).optional(),
|
|
6942
7803
|
coreDomainEntities: external_exports.array(external_exports.string()).default([]),
|
|
6943
7804
|
valueObjects: external_exports.array(external_exports.string()).default([]),
|
|
6944
7805
|
domainEvents: external_exports.array(external_exports.string()).default([]),
|
|
@@ -7023,21 +7884,21 @@ external_exports.object({
|
|
|
7023
7884
|
turboConfig: external_exports.record(external_exports.unknown()).optional()
|
|
7024
7885
|
});
|
|
7025
7886
|
function assertPathWithinArchitecture(workspaceRoot, relativePath) {
|
|
7026
|
-
const resolved =
|
|
7027
|
-
const archRoot =
|
|
7887
|
+
const resolved = path7.resolve(workspaceRoot, ".architecture", relativePath);
|
|
7888
|
+
const archRoot = path7.resolve(workspaceRoot, ".architecture");
|
|
7028
7889
|
try {
|
|
7029
7890
|
const realResolved = realpathSync(resolved);
|
|
7030
7891
|
const realArchRoot = realpathSync(archRoot);
|
|
7031
|
-
const archRootWithSep = realArchRoot +
|
|
7892
|
+
const archRootWithSep = realArchRoot + path7.sep;
|
|
7032
7893
|
if (realResolved !== realArchRoot && !realResolved.startsWith(archRootWithSep)) {
|
|
7033
7894
|
throw new Error(`Path traversal detected: "${relativePath}" resolves outside .architecture/`);
|
|
7034
7895
|
}
|
|
7035
7896
|
} catch (err3) {
|
|
7036
7897
|
if (err3 instanceof Error && "code" in err3 && err3.code === "ENOENT") {
|
|
7037
7898
|
let checkPath = archRoot;
|
|
7038
|
-
const pathSegments =
|
|
7899
|
+
const pathSegments = path7.relative(archRoot, resolved).split(path7.sep);
|
|
7039
7900
|
for (const segment of pathSegments) {
|
|
7040
|
-
checkPath =
|
|
7901
|
+
checkPath = path7.join(checkPath, segment);
|
|
7041
7902
|
try {
|
|
7042
7903
|
const stat = lstatSync(checkPath);
|
|
7043
7904
|
if (stat.isSymbolicLink()) {
|
|
@@ -7053,7 +7914,7 @@ function assertPathWithinArchitecture(workspaceRoot, relativePath) {
|
|
|
7053
7914
|
throw statErr;
|
|
7054
7915
|
}
|
|
7055
7916
|
}
|
|
7056
|
-
const archRootWithSep = archRoot +
|
|
7917
|
+
const archRootWithSep = archRoot + path7.sep;
|
|
7057
7918
|
if (resolved !== archRoot && !resolved.startsWith(archRootWithSep)) {
|
|
7058
7919
|
throw new Error(`Path traversal detected: "${relativePath}" resolves outside .architecture/`);
|
|
7059
7920
|
}
|
|
@@ -7063,7 +7924,7 @@ function assertPathWithinArchitecture(workspaceRoot, relativePath) {
|
|
|
7063
7924
|
}
|
|
7064
7925
|
}
|
|
7065
7926
|
async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
7066
|
-
const content = await
|
|
7927
|
+
const content = await fs5.readFile(manifestPath, "utf-8");
|
|
7067
7928
|
const parsed = yaml3.load(content);
|
|
7068
7929
|
if (parsed == null) {
|
|
7069
7930
|
throw new Error("Manifest file is empty");
|
|
@@ -7096,10 +7957,10 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
7096
7957
|
continue;
|
|
7097
7958
|
}
|
|
7098
7959
|
assertPathWithinArchitecture(workspaceRoot, indexEntry.file);
|
|
7099
|
-
const contextFilePath =
|
|
7960
|
+
const contextFilePath = path7.join(workspaceRoot, ".architecture", indexEntry.file);
|
|
7100
7961
|
let contextContent;
|
|
7101
7962
|
try {
|
|
7102
|
-
contextContent = await
|
|
7963
|
+
contextContent = await fs5.readFile(contextFilePath, "utf-8");
|
|
7103
7964
|
} catch (err3) {
|
|
7104
7965
|
if (err3 instanceof Error && "code" in err3 && err3.code === "ENOENT") {
|
|
7105
7966
|
throw new Error(`Context file not found: ${contextFilePath}`);
|
|
@@ -7131,10 +7992,10 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
7131
7992
|
continue;
|
|
7132
7993
|
}
|
|
7133
7994
|
assertPathWithinArchitecture(workspaceRoot, appEntry.file);
|
|
7134
|
-
const appFilePath =
|
|
7995
|
+
const appFilePath = path7.join(workspaceRoot, ".architecture", appEntry.file);
|
|
7135
7996
|
let appContent;
|
|
7136
7997
|
try {
|
|
7137
|
-
appContent = await
|
|
7998
|
+
appContent = await fs5.readFile(appFilePath, "utf-8");
|
|
7138
7999
|
} catch (err3) {
|
|
7139
8000
|
if (err3 instanceof Error && "code" in err3 && err3.code === "ENOENT") {
|
|
7140
8001
|
throw new Error(`App file not found: ${appFilePath}`);
|
|
@@ -7153,23 +8014,23 @@ async function mergeSplitManifest(workspaceRoot, manifestPath) {
|
|
|
7153
8014
|
|
|
7154
8015
|
// src/sync-engine-init.ts
|
|
7155
8016
|
var __filename$1 = fileURLToPath(import.meta.url);
|
|
7156
|
-
var __dirname$1 =
|
|
8017
|
+
var __dirname$1 = path7.dirname(__filename$1);
|
|
7157
8018
|
async function findWorkspaceRoot(options) {
|
|
7158
8019
|
if (options.targetRoot) {
|
|
7159
8020
|
return options.targetRoot;
|
|
7160
8021
|
}
|
|
7161
8022
|
let currentDir = __dirname$1;
|
|
7162
|
-
while (currentDir !==
|
|
8023
|
+
while (currentDir !== path7.parse(currentDir).root) {
|
|
7163
8024
|
try {
|
|
7164
|
-
const pkgPath =
|
|
7165
|
-
const pkgContent = await
|
|
8025
|
+
const pkgPath = path7.join(currentDir, "package.json");
|
|
8026
|
+
const pkgContent = await fs5.readFile(pkgPath, "utf-8");
|
|
7166
8027
|
const pkg = JSON.parse(pkgContent);
|
|
7167
8028
|
if (pkg.workspaces && Array.isArray(pkg.workspaces)) {
|
|
7168
8029
|
return currentDir;
|
|
7169
8030
|
}
|
|
7170
8031
|
} catch {
|
|
7171
8032
|
}
|
|
7172
|
-
currentDir =
|
|
8033
|
+
currentDir = path7.dirname(currentDir);
|
|
7173
8034
|
}
|
|
7174
8035
|
throw new Error(
|
|
7175
8036
|
'Could not locate monorepo root. No package.json with "workspaces" field found.'
|
|
@@ -7180,7 +8041,7 @@ async function loadManifest(workspaceRoot, flags, options) {
|
|
|
7180
8041
|
return options.manifest;
|
|
7181
8042
|
}
|
|
7182
8043
|
const { logger, dryRun } = flags;
|
|
7183
|
-
const manifestPath =
|
|
8044
|
+
const manifestPath = path7.join(workspaceRoot, ".architecture/manifest.yaml");
|
|
7184
8045
|
logger.debug(`[debug] __dirname (ESM): ${__dirname$1}`);
|
|
7185
8046
|
logger.debug(`[debug] resolved workspaceRoot: ${workspaceRoot}`);
|
|
7186
8047
|
logger.debug(`[debug] resolved manifestPath: ${manifestPath}`);
|
|
@@ -7234,6 +8095,23 @@ function validateManifest(manifest, flags) {
|
|
|
7234
8095
|
var execAsync2 = promisify(exec);
|
|
7235
8096
|
var SyncEngine = class {
|
|
7236
8097
|
report = new MigrationReport();
|
|
8098
|
+
// PR-B1 (RCA #4): per-run mutation journal — pre-images of every file sync
|
|
8099
|
+
// touches, replayed in reverse on failure (see journal.ts). The lifetime is
|
|
8100
|
+
// one RUN, not one instance: run() re-news it on entry, so a reused engine
|
|
8101
|
+
// can never replay a previous run's pre-images into a later rollback.
|
|
8102
|
+
journal = new SyncJournal();
|
|
8103
|
+
// B-1 (PR-B2 review): generators that failed-soft this run. Four generators
|
|
8104
|
+
// catch their own exceptions into `result.error` by contract (Wave-2e: skip
|
|
8105
|
+
// the package, do not abort the run) — but a swallowed failure plans zero
|
|
8106
|
+
// ops, so a run that could not even read a target still summarized as
|
|
8107
|
+
// `Total ops : 0` and the CLI exited 0: errors masqueraded as convergence,
|
|
8108
|
+
// silently breaking `--check`'s "exit 0 ⇒ converged" promise. Failures are
|
|
8109
|
+
// recorded at each production site (NOT off the merged rows — mergeResult
|
|
8110
|
+
// keeps only the first error, so row-level counting would under-report
|
|
8111
|
+
// multi-module failures), printed as FAILED rows under the summary, and
|
|
8112
|
+
// surfaced as `SyncRunSummary.errors` for cli.ts to turn into exit ≠ 0.
|
|
8113
|
+
// Per-run lifetime, same reset discipline as the journal.
|
|
8114
|
+
failures = [];
|
|
7237
8115
|
partialConfig;
|
|
7238
8116
|
fullConfig = null;
|
|
7239
8117
|
manifest = {};
|
|
@@ -7255,6 +8133,19 @@ var SyncEngine = class {
|
|
|
7255
8133
|
}
|
|
7256
8134
|
return this.fullConfig;
|
|
7257
8135
|
}
|
|
8136
|
+
/**
|
|
8137
|
+
* Record a failed-soft generator result (B-1). Called at every site that
|
|
8138
|
+
* receives a GeneratorResult, including the ones that never set `error`
|
|
8139
|
+
* today — the check is one truthy test, and a future generator adopting the
|
|
8140
|
+
* catch-into-result contract is then surfaced without anyone remembering
|
|
8141
|
+
* this seam. `row` matches the summary-table label so the FAILED line and
|
|
8142
|
+
* the table read as one report.
|
|
8143
|
+
*/
|
|
8144
|
+
noteFailure(row, result) {
|
|
8145
|
+
if (result.error) {
|
|
8146
|
+
this.failures.push({ row, message: result.error.message });
|
|
8147
|
+
}
|
|
8148
|
+
}
|
|
7258
8149
|
async ensureDirectories() {
|
|
7259
8150
|
const config = this.getConfig();
|
|
7260
8151
|
const result = createEmptyResult();
|
|
@@ -7269,20 +8160,12 @@ var SyncEngine = class {
|
|
|
7269
8160
|
);
|
|
7270
8161
|
continue;
|
|
7271
8162
|
}
|
|
7272
|
-
const moduleDir =
|
|
8163
|
+
const moduleDir = path7.join(this.workspaceRoot, "packages", mod.name);
|
|
7273
8164
|
logger.info(
|
|
7274
8165
|
`Ensuring directories for module: ${mod.name} at ${moduleDir}`
|
|
7275
8166
|
);
|
|
7276
|
-
const layerResult = await ensureLayerFolders(
|
|
7277
|
-
|
|
7278
|
-
layers,
|
|
7279
|
-
config,
|
|
7280
|
-
this.report
|
|
7281
|
-
);
|
|
7282
|
-
result.created.push(...layerResult.created);
|
|
7283
|
-
result.skipped.push(...layerResult.skipped);
|
|
7284
|
-
result.updated.push(...layerResult.updated);
|
|
7285
|
-
result.totalOps += layerResult.totalOps;
|
|
8167
|
+
const layerResult = await ensureLayerFolders(moduleDir, layers, config);
|
|
8168
|
+
mergeResult2(result, layerResult);
|
|
7286
8169
|
}
|
|
7287
8170
|
return result;
|
|
7288
8171
|
}
|
|
@@ -7297,7 +8180,7 @@ var SyncEngine = class {
|
|
|
7297
8180
|
const stubs = createEmptyResult();
|
|
7298
8181
|
for (const module of modules) {
|
|
7299
8182
|
const moduleName = module.name;
|
|
7300
|
-
const moduleDir =
|
|
8183
|
+
const moduleDir = path7.join(this.workspaceRoot, "packages", moduleName);
|
|
7301
8184
|
if (moduleName.includes("..") || moduleName.includes("/") || moduleName.startsWith(".")) {
|
|
7302
8185
|
logger.warn(
|
|
7303
8186
|
`Skipping invalid module name (potential path traversal): ${moduleName}`
|
|
@@ -7334,14 +8217,19 @@ var SyncEngine = class {
|
|
|
7334
8217
|
config,
|
|
7335
8218
|
this.report
|
|
7336
8219
|
);
|
|
8220
|
+
this.noteFailure("Barrels", barrelResult);
|
|
8221
|
+
this.noteFailure("package.json", pkgResult);
|
|
8222
|
+
this.noteFailure("tsconfig.json", tsResult);
|
|
8223
|
+
this.noteFailure("ESLint", eslintResult);
|
|
8224
|
+
this.noteFailure("Stubs", stubResult);
|
|
7337
8225
|
if (this.partialConfig.mode === "self-regen") {
|
|
7338
8226
|
await reapLegacyFolders(moduleDir, config, this.report);
|
|
7339
8227
|
}
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
8228
|
+
mergeResult2(barrels, barrelResult);
|
|
8229
|
+
mergeResult2(pkgs, pkgResult);
|
|
8230
|
+
mergeResult2(tsconfigs, tsResult);
|
|
8231
|
+
mergeResult2(eslint, eslintResult);
|
|
8232
|
+
mergeResult2(stubs, stubResult);
|
|
7345
8233
|
}
|
|
7346
8234
|
return {
|
|
7347
8235
|
rootFiles: createEmptyResult(),
|
|
@@ -7359,6 +8247,8 @@ var SyncEngine = class {
|
|
|
7359
8247
|
const { logger, dryRun, allowDirty, mode } = this.partialConfig;
|
|
7360
8248
|
const start = Date.now();
|
|
7361
8249
|
let lockFile = null;
|
|
8250
|
+
this.journal = new SyncJournal();
|
|
8251
|
+
this.failures = [];
|
|
7362
8252
|
logger.info(
|
|
7363
8253
|
dryRun ? "[DRY-RUN MODE] Starting sync..." : "Starting sync..."
|
|
7364
8254
|
);
|
|
@@ -7407,7 +8297,8 @@ var SyncEngine = class {
|
|
|
7407
8297
|
this.fullConfig = {
|
|
7408
8298
|
...this.partialConfig,
|
|
7409
8299
|
workspaceRoot: this.workspaceRoot,
|
|
7410
|
-
manifest: this.manifest
|
|
8300
|
+
manifest: this.manifest,
|
|
8301
|
+
journal: this.journal
|
|
7411
8302
|
};
|
|
7412
8303
|
if (!dryRun && mode === "self-regen") {
|
|
7413
8304
|
lockFile = new LockFile(this.workspaceRoot);
|
|
@@ -7433,15 +8324,29 @@ var SyncEngine = class {
|
|
|
7433
8324
|
this.fullConfig,
|
|
7434
8325
|
this.report
|
|
7435
8326
|
);
|
|
8327
|
+
this.noteFailure("RootFiles", rootFilesResult);
|
|
7436
8328
|
const archFilesResult = await generateArchitectureFiles(
|
|
7437
8329
|
this.fullConfig,
|
|
7438
8330
|
this.report
|
|
7439
8331
|
);
|
|
8332
|
+
this.noteFailure("ArchFiles", archFilesResult);
|
|
7440
8333
|
const layerResult = await this.ensureDirectories();
|
|
8334
|
+
this.noteFailure("Layers", layerResult);
|
|
7441
8335
|
const coreResults = await this.generateCoreArtifacts();
|
|
7442
8336
|
const { pkgs, tsconfigs, eslint, stubs } = coreResults;
|
|
7443
8337
|
const firstPassBarrels = coreResults.barrels;
|
|
7444
8338
|
const appsResult = await generateApps(this.fullConfig, this.report);
|
|
8339
|
+
this.noteFailure("Apps", appsResult);
|
|
8340
|
+
const crossContextResult = await generateCrossContext(
|
|
8341
|
+
this.fullConfig,
|
|
8342
|
+
this.report
|
|
8343
|
+
);
|
|
8344
|
+
this.noteFailure("CrossContext", crossContextResult);
|
|
8345
|
+
const sharedKernelResult = await generateSharedKernel(
|
|
8346
|
+
this.fullConfig,
|
|
8347
|
+
this.report
|
|
8348
|
+
);
|
|
8349
|
+
this.noteFailure("SharedKernel", sharedKernelResult);
|
|
7445
8350
|
const secondPassBarrels = createEmptyResult();
|
|
7446
8351
|
const modules = this.fullConfig.manifest.bounded_contexts ?? [];
|
|
7447
8352
|
for (const module of modules) {
|
|
@@ -7449,16 +8354,47 @@ var SyncEngine = class {
|
|
|
7449
8354
|
if (!moduleName || moduleName.includes("..") || moduleName.includes("/") || moduleName.startsWith(".")) {
|
|
7450
8355
|
continue;
|
|
7451
8356
|
}
|
|
7452
|
-
const moduleDir =
|
|
8357
|
+
const moduleDir = path7.join(this.workspaceRoot, "packages", moduleName);
|
|
7453
8358
|
const pass2 = await generateBarrels(
|
|
7454
8359
|
moduleDir,
|
|
7455
8360
|
this.fullConfig,
|
|
7456
8361
|
this.report
|
|
7457
8362
|
);
|
|
7458
|
-
|
|
8363
|
+
this.noteFailure("Barrels", pass2);
|
|
8364
|
+
mergeResult2(secondPassBarrels, pass2);
|
|
7459
8365
|
}
|
|
7460
8366
|
const barrels = mergeBarrelPasses(firstPassBarrels, secondPassBarrels);
|
|
7461
|
-
const
|
|
8367
|
+
const rows = [
|
|
8368
|
+
["RootFiles", rootFilesResult],
|
|
8369
|
+
["ArchFiles", archFilesResult],
|
|
8370
|
+
["Layers", layerResult],
|
|
8371
|
+
["Barrels", barrels],
|
|
8372
|
+
["CrossContext", crossContextResult],
|
|
8373
|
+
["SharedKernel", sharedKernelResult],
|
|
8374
|
+
["package.json", pkgs],
|
|
8375
|
+
["tsconfig.json", tsconfigs],
|
|
8376
|
+
["ESLint", eslint],
|
|
8377
|
+
["Stubs", stubs],
|
|
8378
|
+
["Apps", appsResult]
|
|
8379
|
+
];
|
|
8380
|
+
const runSummary = {
|
|
8381
|
+
created: 0,
|
|
8382
|
+
updated: 0,
|
|
8383
|
+
deleted: 0,
|
|
8384
|
+
unchanged: 0,
|
|
8385
|
+
skipped: 0,
|
|
8386
|
+
totalOps: 0,
|
|
8387
|
+
errors: this.failures.length,
|
|
8388
|
+
durationMs: 0
|
|
8389
|
+
};
|
|
8390
|
+
for (const [, r] of rows) {
|
|
8391
|
+
runSummary.created += r.created.length;
|
|
8392
|
+
runSummary.updated += r.updated.length;
|
|
8393
|
+
runSummary.deleted += r.deleted.length;
|
|
8394
|
+
runSummary.unchanged += r.unchanged.length;
|
|
8395
|
+
runSummary.skipped += r.skipped.length;
|
|
8396
|
+
runSummary.totalOps += r.totalOps;
|
|
8397
|
+
}
|
|
7462
8398
|
if (mode === "self-regen") {
|
|
7463
8399
|
await runArchLinter(this.fullConfig);
|
|
7464
8400
|
await this.report.writeReport(this.fullConfig);
|
|
@@ -7466,56 +8402,70 @@ var SyncEngine = class {
|
|
|
7466
8402
|
logger.info("Skipping arch-linter and report (external mode)");
|
|
7467
8403
|
}
|
|
7468
8404
|
const duration = Date.now() - start;
|
|
7469
|
-
|
|
8405
|
+
runSummary.durationMs = duration;
|
|
8406
|
+
if (this.failures.length === 0) {
|
|
8407
|
+
logger.info("\nSync completed successfully.");
|
|
8408
|
+
} else {
|
|
8409
|
+
logger.error(
|
|
8410
|
+
`
|
|
8411
|
+
Sync completed with ${this.failures.length} generator failure(s) — see the FAILED row(s) below.`
|
|
8412
|
+
);
|
|
8413
|
+
}
|
|
7470
8414
|
logger.info(
|
|
7471
8415
|
`Processed ${this.manifest.bounded_contexts?.length ?? 0} modules in ${duration}ms`
|
|
7472
8416
|
);
|
|
7473
8417
|
logger.info(`
|
|
7474
8418
|
=== Generator Summary ===`);
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
)
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
);
|
|
7484
|
-
|
|
7485
|
-
`• Barrels : ${barrels.created.length} created, ${barrels.updated.length} updated, ${barrels.skipped.length} skipped`
|
|
7486
|
-
);
|
|
7487
|
-
logger.info(
|
|
7488
|
-
`• package.json : ${pkgs.created.length} created, ${pkgs.updated.length} updated, ${pkgs.skipped.length} skipped`
|
|
7489
|
-
);
|
|
7490
|
-
logger.info(
|
|
7491
|
-
`• tsconfig.json : ${tsconfigs.created.length} created, ${tsconfigs.updated.length} updated, ${tsconfigs.skipped.length} skipped`
|
|
7492
|
-
);
|
|
7493
|
-
logger.info(
|
|
7494
|
-
`• ESLint : ${eslint.created.length} created, ${eslint.updated.length} updated, ${eslint.skipped.length} skipped`
|
|
7495
|
-
);
|
|
7496
|
-
logger.info(
|
|
7497
|
-
`• Stubs : ${stubs.created.length} created, ${stubs.updated.length} updated, ${stubs.skipped.length} skipped`
|
|
7498
|
-
);
|
|
7499
|
-
logger.info(
|
|
7500
|
-
`• Apps : ${appsResult.created.length} created, ${appsResult.updated.length} updated, ${appsResult.skipped.length} skipped`
|
|
7501
|
-
);
|
|
7502
|
-
logger.info(`• Total ops : ${totalOps}`);
|
|
8419
|
+
for (const [label, r] of rows) {
|
|
8420
|
+
logger.info(
|
|
8421
|
+
`• ${label} : ${r.created.length} created, ${r.updated.length} updated, ${r.deleted.length} deleted, ${r.unchanged.length} unchanged, ${r.skipped.length} skipped`
|
|
8422
|
+
);
|
|
8423
|
+
}
|
|
8424
|
+
for (const f of this.failures) {
|
|
8425
|
+
logger.error(`• ${f.row} : FAILED — ${f.message}`);
|
|
8426
|
+
}
|
|
8427
|
+
logger.info(`• Total ops : ${runSummary.totalOps}`);
|
|
8428
|
+
return runSummary;
|
|
7503
8429
|
} catch (err3) {
|
|
7504
8430
|
const message = err3 instanceof Error ? err3.message : "Unknown sync error";
|
|
7505
8431
|
logger.error(`Sync failed: ${message}`);
|
|
7506
8432
|
if (!dryRun) {
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
} catch (rollbackErr) {
|
|
8433
|
+
if (this.journal.size === 0) {
|
|
8434
|
+
logger.info(
|
|
8435
|
+
"No files were touched before the failure — nothing to roll back."
|
|
8436
|
+
);
|
|
8437
|
+
} else if (allowDirty) {
|
|
7513
8438
|
logger.warn(
|
|
7514
|
-
`
|
|
8439
|
+
`Sync failed after touching ${this.journal.size} path(s) — NO rollback under --allow-dirty; the tree is left as-is:`
|
|
7515
8440
|
);
|
|
8441
|
+
for (const line of this.journal.describeEntries(this.workspaceRoot)) {
|
|
8442
|
+
logger.warn(` ${line}`);
|
|
8443
|
+
}
|
|
8444
|
+
} else {
|
|
8445
|
+
logger.info(
|
|
8446
|
+
`Rolling back ${this.journal.size} journaled path(s) (inverse-ops; never git reset/clean)...`
|
|
8447
|
+
);
|
|
8448
|
+
const outcome = await this.journal.rollback(
|
|
8449
|
+
logger,
|
|
8450
|
+
this.workspaceRoot
|
|
8451
|
+
);
|
|
8452
|
+
if (outcome.failures.length === 0) {
|
|
8453
|
+
logger.info(
|
|
8454
|
+
`Rollback completed: ${outcome.restored}/${outcome.attempted} path(s) restored.`
|
|
8455
|
+
);
|
|
8456
|
+
} else {
|
|
8457
|
+
for (const f of outcome.failures) {
|
|
8458
|
+
logger.error(
|
|
8459
|
+
`Rollback failed for ${path7.relative(this.workspaceRoot, f.path)}: intended to ${f.intended} — ${f.error}`
|
|
8460
|
+
);
|
|
8461
|
+
}
|
|
8462
|
+
logger.error(
|
|
8463
|
+
`Rollback incomplete: ${outcome.failures.length} of ${outcome.attempted} path(s) NOT restored — inspect the paths above.`
|
|
8464
|
+
);
|
|
8465
|
+
}
|
|
7516
8466
|
}
|
|
7517
|
-
process.exit(1);
|
|
7518
8467
|
}
|
|
8468
|
+
throw err3;
|
|
7519
8469
|
} finally {
|
|
7520
8470
|
if (lockFile) {
|
|
7521
8471
|
try {
|
|
@@ -7606,6 +8556,27 @@ function parseArgs(rawArgs) {
|
|
|
7606
8556
|
case "--allow-dirty":
|
|
7607
8557
|
flags.allowDirty = true;
|
|
7608
8558
|
break;
|
|
8559
|
+
// Lenient on a missing value (warn + skip) where the commander front
|
|
8560
|
+
// door hard-errors on `--report <path>` — deliberate divergence:
|
|
8561
|
+
// parseArgs serves programmatic/test callers that shouldn't die on a
|
|
8562
|
+
// malformed optional flag (review #315).
|
|
8563
|
+
case "--report": {
|
|
8564
|
+
const next = args[i + 1];
|
|
8565
|
+
if (next !== void 0 && !next.startsWith("-")) {
|
|
8566
|
+
flags.report = args[++i];
|
|
8567
|
+
} else {
|
|
8568
|
+
flags.logger.warn("--report requires a path argument — ignored");
|
|
8569
|
+
}
|
|
8570
|
+
break;
|
|
8571
|
+
}
|
|
8572
|
+
case "--only": {
|
|
8573
|
+
const patterns = [];
|
|
8574
|
+
while (i + 1 < args.length && !args[i + 1].startsWith("-")) {
|
|
8575
|
+
patterns.push(args[++i]);
|
|
8576
|
+
}
|
|
8577
|
+
flags.only = [...flags.only ?? [], ...patterns];
|
|
8578
|
+
break;
|
|
8579
|
+
}
|
|
7609
8580
|
default:
|
|
7610
8581
|
if (arg.startsWith("-")) {
|
|
7611
8582
|
flags.logger.warn(`Unknown flag ignored: ${arg}`);
|
|
@@ -7623,7 +8594,7 @@ function ok2(value) {
|
|
|
7623
8594
|
function err2(error) {
|
|
7624
8595
|
return { success: false, error };
|
|
7625
8596
|
}
|
|
7626
|
-
var CONFIG_FILE =
|
|
8597
|
+
var CONFIG_FILE = path7.join(
|
|
7627
8598
|
process.cwd(),
|
|
7628
8599
|
".architecture/generator.config.yaml"
|
|
7629
8600
|
);
|
|
@@ -7634,7 +8605,7 @@ function isFailureMode(v) {
|
|
|
7634
8605
|
return v === "abort" || v === "abort-and-cleanup" || v === "warn-and-continue";
|
|
7635
8606
|
}
|
|
7636
8607
|
var YamlConfigAdapter = class {
|
|
7637
|
-
constructor(configFile = CONFIG_FILE, fsImpl =
|
|
8608
|
+
constructor(configFile = CONFIG_FILE, fsImpl = fs5, logger = console) {
|
|
7638
8609
|
this.configFile = configFile;
|
|
7639
8610
|
this.fsImpl = fsImpl;
|
|
7640
8611
|
this.logger = logger;
|
|
@@ -7790,7 +8761,7 @@ var YamlConfigAdapter = class {
|
|
|
7790
8761
|
const updated = { ...current, ...sanitized };
|
|
7791
8762
|
const yamlDoc = this.toYamlDoc(updated);
|
|
7792
8763
|
const content = yaml3.dump(yamlDoc, { indent: 2, lineWidth: -1 });
|
|
7793
|
-
await this.fsImpl.mkdir(
|
|
8764
|
+
await this.fsImpl.mkdir(path7.dirname(this.configFile), { recursive: true });
|
|
7794
8765
|
const tmpPath = `${this.configFile}.tmp`;
|
|
7795
8766
|
await this.fsImpl.writeFile(tmpPath, content, {
|
|
7796
8767
|
encoding: "utf8",
|
|
@@ -8000,7 +8971,7 @@ var InMemoryConfigDouble = class _InMemoryConfigDouble {
|
|
|
8000
8971
|
var execAsync3 = promisify(exec);
|
|
8001
8972
|
async function loadManifest2(workspaceRoot) {
|
|
8002
8973
|
try {
|
|
8003
|
-
const manifestPath =
|
|
8974
|
+
const manifestPath = path7.join(
|
|
8004
8975
|
workspaceRoot,
|
|
8005
8976
|
".architecture/manifest.yaml"
|
|
8006
8977
|
);
|
|
@@ -8041,18 +9012,18 @@ async function validateManifest2(workspaceRoot) {
|
|
|
8041
9012
|
}
|
|
8042
9013
|
async function saveManifest(workspaceRoot, manifest) {
|
|
8043
9014
|
try {
|
|
8044
|
-
const manifestPath =
|
|
9015
|
+
const manifestPath = path7.join(
|
|
8045
9016
|
workspaceRoot,
|
|
8046
9017
|
".architecture/manifest.yaml"
|
|
8047
9018
|
);
|
|
8048
9019
|
const content = yaml3.dump(manifest, { indent: 2 });
|
|
8049
|
-
await
|
|
9020
|
+
await fs5.writeFile(manifestPath, content, "utf-8");
|
|
8050
9021
|
return ok2(void 0);
|
|
8051
9022
|
} catch (errObj) {
|
|
8052
9023
|
return err2(errObj);
|
|
8053
9024
|
}
|
|
8054
9025
|
}
|
|
8055
9026
|
|
|
8056
|
-
export { DEFAULT_NAMING, DEFAULT_TEMPLATES, InMemoryConfigDouble, SyncEngine, YamlConfigAdapter, createEmptyResult, err2 as err, isGeneratedFile, isIndexManifest, isProtectedRoot, loadManifest2 as loadManifest, mergeSplitManifest, ok2 as ok, parseArgs, portName, protectedFiles, safeWriteFile, safeWriteFileAtomic, saveManifest, validateManifest2 as validateManifest };
|
|
9027
|
+
export { DEFAULT_NAMING, DEFAULT_TEMPLATES, InMemoryConfigDouble, SyncEngine, YamlConfigAdapter, createEmptyResult, err2 as err, isGeneratedFile, isInScope, isIndexManifest, isProtectedRoot, loadManifest2 as loadManifest, mergeSplitManifest, ok2 as ok, parseArgs, portName, protectedFiles, recordWriteStatus, safeWriteFile, safeWriteFileAtomic, saveManifest, validateManifest2 as validateManifest };
|
|
8057
9028
|
//# sourceMappingURL=index.js.map
|
|
8058
9029
|
//# sourceMappingURL=index.js.map
|