@hexagen-monaco/sync 0.5.2 → 0.6.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 +1191 -389
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/fs-utils.d.ts +13 -0
- 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.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.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/root-file-templates.d.ts +3 -3
- package/dist/generators/root-file-templates.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/index.js +950 -172
- package/dist/index.js.map +1 -1
- package/dist/scope-filter.d.ts +35 -0
- package/dist/scope-filter.d.ts.map +1 -0
- 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/types/manifest/apps.d.ts +12 -1
- package/dist/types/manifest/apps.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -158,6 +158,46 @@ function createEmptyResult() {
|
|
|
158
158
|
totalOps: 0
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
|
+
|
|
162
|
+
// src/scope-filter.ts
|
|
163
|
+
var GLOB_META = /[*?]/;
|
|
164
|
+
function normalize(p) {
|
|
165
|
+
return p.replace(/\\/g, "/").replace(/^\.?\//, "").replace(/\/+$/, "");
|
|
166
|
+
}
|
|
167
|
+
function globToRegExp(glob) {
|
|
168
|
+
let re = "";
|
|
169
|
+
for (let i = 0; i < glob.length; i++) {
|
|
170
|
+
const c = glob[i];
|
|
171
|
+
if (c === "*") {
|
|
172
|
+
if (glob[i + 1] === "*") {
|
|
173
|
+
re += ".*";
|
|
174
|
+
i++;
|
|
175
|
+
} else {
|
|
176
|
+
re += "[^/]*";
|
|
177
|
+
}
|
|
178
|
+
} else if (c === "?") {
|
|
179
|
+
re += "[^/]";
|
|
180
|
+
} else if ("\\^$.|+()[]{}".includes(c)) {
|
|
181
|
+
re += `\\${c}`;
|
|
182
|
+
} else {
|
|
183
|
+
re += c;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return new RegExp(`^${re}$`);
|
|
187
|
+
}
|
|
188
|
+
function matchesScope(relativePath, patterns) {
|
|
189
|
+
const rel = normalize(relativePath);
|
|
190
|
+
return patterns.some((raw) => {
|
|
191
|
+
const pat = normalize(raw);
|
|
192
|
+
if (pat === "") return false;
|
|
193
|
+
if (!GLOB_META.test(pat)) {
|
|
194
|
+
return rel === pat || rel.startsWith(`${pat}/`);
|
|
195
|
+
}
|
|
196
|
+
return globToRegExp(pat).test(rel);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/fs-utils.ts
|
|
161
201
|
var GENERATED_MARKER = "// @generated by @hexagen/sync";
|
|
162
202
|
var protectedFiles = /* @__PURE__ */ new Set([
|
|
163
203
|
".gitignore",
|
|
@@ -190,9 +230,18 @@ function isProtectedRoot(filePath, config) {
|
|
|
190
230
|
(f) => relative.endsWith(f) || relative.includes(f)
|
|
191
231
|
);
|
|
192
232
|
}
|
|
233
|
+
function isInScope(filePath, config) {
|
|
234
|
+
if (!config.only || config.only.length === 0) return true;
|
|
235
|
+
const relativePath = path6.relative(config.workspaceRoot, filePath);
|
|
236
|
+
return matchesScope(relativePath, config.only);
|
|
237
|
+
}
|
|
193
238
|
async function safeWriteFileAtomic(filePath, content, config, report, skipGeneratedCheck = false) {
|
|
194
239
|
const { dryRun, forceRoot, logger, workspaceRoot } = config;
|
|
195
240
|
const relativePath = path6.relative(workspaceRoot, filePath);
|
|
241
|
+
if (!isInScope(filePath, config)) {
|
|
242
|
+
logger.debug(`skipped (outside --only) ${relativePath}`);
|
|
243
|
+
return "skipped";
|
|
244
|
+
}
|
|
196
245
|
let exists = false;
|
|
197
246
|
let currentContent = "";
|
|
198
247
|
let currentHash = "";
|
|
@@ -209,22 +258,24 @@ async function safeWriteFileAtomic(filePath, content, config, report, skipGenera
|
|
|
209
258
|
logger.debug(`unchanged ${relativePath}`);
|
|
210
259
|
return "unchanged";
|
|
211
260
|
}
|
|
212
|
-
if (dryRun) {
|
|
213
|
-
const action = exists ? "update" : "create";
|
|
214
|
-
logger.info(`[DRY-RUN] would ${action} ${relativePath}`);
|
|
215
|
-
return exists ? "updated" : "created";
|
|
216
|
-
}
|
|
217
261
|
if (isProtectedRoot(filePath, config) && !forceRoot) {
|
|
218
|
-
|
|
262
|
+
const verb = dryRun ? "[DRY-RUN] would skip" : "skipped";
|
|
263
|
+
logger.warn(`${verb} (root protected, use --force-root) ${relativePath}`);
|
|
219
264
|
if (report) report.record("blocked", filePath, "Root file protected");
|
|
220
265
|
return "protected";
|
|
221
266
|
}
|
|
222
267
|
if (exists && !forceRoot && !skipGeneratedCheck && !isGeneratedFile(currentContent)) {
|
|
268
|
+
const verb = dryRun ? "[DRY-RUN] would skip" : "skipped";
|
|
223
269
|
logger.warn(
|
|
224
|
-
|
|
270
|
+
`${verb} (hand-written, use --force-root to overwrite) ${relativePath}`
|
|
225
271
|
);
|
|
226
272
|
return "skipped";
|
|
227
273
|
}
|
|
274
|
+
if (dryRun) {
|
|
275
|
+
const action = exists ? "update" : "create";
|
|
276
|
+
logger.info(`[DRY-RUN] would ${action} ${relativePath}`);
|
|
277
|
+
return exists ? "updated" : "created";
|
|
278
|
+
}
|
|
228
279
|
await fs3.mkdir(path6.dirname(filePath), { recursive: true });
|
|
229
280
|
const tmpName = `.${path6.basename(filePath)}.${crypto.randomUUID()}.tmp`;
|
|
230
281
|
const tmpPath = path6.join(path6.dirname(filePath), tmpName);
|
|
@@ -315,6 +366,10 @@ async function ensureLayerFolders(moduleDir, layers, config, report) {
|
|
|
315
366
|
}
|
|
316
367
|
for (const [, layerConfig] of Object.entries(layers)) {
|
|
317
368
|
const layerPath = path6.join(moduleDir, layerConfig.folder);
|
|
369
|
+
const barrelPath = path6.join(layerPath, "index.ts");
|
|
370
|
+
if (!isInScope(barrelPath, config)) {
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
318
373
|
try {
|
|
319
374
|
await fs3.mkdir(layerPath, { recursive: true });
|
|
320
375
|
result.created.push(layerPath);
|
|
@@ -326,7 +381,6 @@ async function ensureLayerFolders(moduleDir, layers, config, report) {
|
|
|
326
381
|
throw e;
|
|
327
382
|
}
|
|
328
383
|
}
|
|
329
|
-
const barrelPath = path6.join(layerPath, "index.ts");
|
|
330
384
|
const barrelContent = await generateBarrelContent(layerPath);
|
|
331
385
|
const barrelStatus = await safeWriteFileAtomic(
|
|
332
386
|
barrelPath,
|
|
@@ -342,6 +396,10 @@ async function ensureLayerFolders(moduleDir, layers, config, report) {
|
|
|
342
396
|
const subfolders = layerConfig.subfolders ?? [];
|
|
343
397
|
for (const sub of subfolders) {
|
|
344
398
|
const subPath = path6.join(layerPath, sub);
|
|
399
|
+
const subBarrelPath = path6.join(subPath, "index.ts");
|
|
400
|
+
if (!isInScope(subBarrelPath, config)) {
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
345
403
|
try {
|
|
346
404
|
await fs3.mkdir(subPath, { recursive: true });
|
|
347
405
|
result.created.push(subPath);
|
|
@@ -353,7 +411,6 @@ async function ensureLayerFolders(moduleDir, layers, config, report) {
|
|
|
353
411
|
throw e;
|
|
354
412
|
}
|
|
355
413
|
}
|
|
356
|
-
const subBarrelPath = path6.join(subPath, "index.ts");
|
|
357
414
|
const subBarrelContent = await generateBarrelContent(subPath);
|
|
358
415
|
const subBarrelStatus = await safeWriteFileAtomic(
|
|
359
416
|
subBarrelPath,
|
|
@@ -397,18 +454,18 @@ function contentHash2(content) {
|
|
|
397
454
|
function detectCircularExports(exportGraph) {
|
|
398
455
|
const visited = /* @__PURE__ */ new Set();
|
|
399
456
|
const recursionStack = /* @__PURE__ */ new Set();
|
|
400
|
-
const
|
|
457
|
+
const path24 = [];
|
|
401
458
|
function dfs(node) {
|
|
402
459
|
if (recursionStack.has(node)) {
|
|
403
|
-
const cycleStart =
|
|
404
|
-
return [...
|
|
460
|
+
const cycleStart = path24.indexOf(node);
|
|
461
|
+
return [...path24.slice(cycleStart), node];
|
|
405
462
|
}
|
|
406
463
|
if (visited.has(node)) {
|
|
407
464
|
return null;
|
|
408
465
|
}
|
|
409
466
|
visited.add(node);
|
|
410
467
|
recursionStack.add(node);
|
|
411
|
-
|
|
468
|
+
path24.push(node);
|
|
412
469
|
const exports$1 = exportGraph.get(node) ?? [];
|
|
413
470
|
for (const exportPath of exports$1) {
|
|
414
471
|
const cycle = dfs(exportPath);
|
|
@@ -416,7 +473,7 @@ function detectCircularExports(exportGraph) {
|
|
|
416
473
|
return cycle;
|
|
417
474
|
}
|
|
418
475
|
}
|
|
419
|
-
|
|
476
|
+
path24.pop();
|
|
420
477
|
recursionStack.delete(node);
|
|
421
478
|
return null;
|
|
422
479
|
}
|
|
@@ -433,8 +490,8 @@ function generateBarrelContent2(entries) {
|
|
|
433
490
|
return null;
|
|
434
491
|
}
|
|
435
492
|
const exportLines = entries.sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
|
|
436
|
-
const
|
|
437
|
-
return `export * from "${
|
|
493
|
+
const path24 = entry.isDirectory ? `./${entry.name}/index.js` : `./${entry.name}.js`;
|
|
494
|
+
return `export * from "${path24}";`;
|
|
438
495
|
});
|
|
439
496
|
return `${GENERATED_MARKER3}
|
|
440
497
|
|
|
@@ -461,6 +518,7 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
|
461
518
|
const pendingWrites = [];
|
|
462
519
|
const preserved = [];
|
|
463
520
|
const exportGraph = /* @__PURE__ */ new Map();
|
|
521
|
+
const layersWithContent = [];
|
|
464
522
|
for (const layer of layers) {
|
|
465
523
|
const layerDir = path6.join(srcDir, layer);
|
|
466
524
|
try {
|
|
@@ -468,13 +526,34 @@ async function generateRecursiveBarrels(moduleDir, config, report) {
|
|
|
468
526
|
} catch {
|
|
469
527
|
continue;
|
|
470
528
|
}
|
|
471
|
-
await walkDirectory(
|
|
529
|
+
const layerExports = await walkDirectory(
|
|
472
530
|
layerDir,
|
|
473
531
|
pendingWrites,
|
|
474
532
|
preserved,
|
|
475
533
|
exportGraph,
|
|
476
534
|
config
|
|
477
535
|
);
|
|
536
|
+
if (layerExports.length > 0) layersWithContent.push(layer);
|
|
537
|
+
}
|
|
538
|
+
if (config.mode === "external" && layersWithContent.length > 0) {
|
|
539
|
+
const rootBarrelPath = path6.join(srcDir, "index.ts");
|
|
540
|
+
if (await shouldGenerateBarrel(rootBarrelPath, preserved, config.logger)) {
|
|
541
|
+
const content = generateBarrelContent2(
|
|
542
|
+
layersWithContent.map((name) => ({ name, isDirectory: true }))
|
|
543
|
+
);
|
|
544
|
+
const existing = await readFileIfExists(rootBarrelPath);
|
|
545
|
+
if (content !== null && !(existing && contentHash2(existing) === contentHash2(content))) {
|
|
546
|
+
pendingWrites.push({
|
|
547
|
+
filePath: rootBarrelPath,
|
|
548
|
+
content,
|
|
549
|
+
isNew: !existing
|
|
550
|
+
});
|
|
551
|
+
exportGraph.set(
|
|
552
|
+
rootBarrelPath,
|
|
553
|
+
layersWithContent.map((name) => path6.join(srcDir, name, "index.ts"))
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
478
557
|
}
|
|
479
558
|
const circularCheck = detectCircularExports(exportGraph);
|
|
480
559
|
if (circularCheck.hasCircular && circularCheck.cycle) {
|
|
@@ -1377,8 +1456,8 @@ function getErrorMap() {
|
|
|
1377
1456
|
|
|
1378
1457
|
// ../../node_modules/zod/v3/helpers/parseUtil.js
|
|
1379
1458
|
var makeIssue = (params) => {
|
|
1380
|
-
const { data, path:
|
|
1381
|
-
const fullPath = [...
|
|
1459
|
+
const { data, path: path24, errorMaps, issueData } = params;
|
|
1460
|
+
const fullPath = [...path24, ...issueData.path || []];
|
|
1382
1461
|
const fullIssue = {
|
|
1383
1462
|
...issueData,
|
|
1384
1463
|
path: fullPath
|
|
@@ -1494,11 +1573,11 @@ var errorUtil;
|
|
|
1494
1573
|
|
|
1495
1574
|
// ../../node_modules/zod/v3/types.js
|
|
1496
1575
|
var ParseInputLazyPath = class {
|
|
1497
|
-
constructor(parent, value,
|
|
1576
|
+
constructor(parent, value, path24, key) {
|
|
1498
1577
|
this._cachedPath = [];
|
|
1499
1578
|
this.parent = parent;
|
|
1500
1579
|
this.data = value;
|
|
1501
|
-
this._path =
|
|
1580
|
+
this._path = path24;
|
|
1502
1581
|
this._key = key;
|
|
1503
1582
|
}
|
|
1504
1583
|
get path() {
|
|
@@ -5029,6 +5108,7 @@ var BUILTIN_TSCONFIG_BASE_TEMPLATE = `{
|
|
|
5029
5108
|
"module": "ESNext",
|
|
5030
5109
|
"moduleResolution": "bundler",
|
|
5031
5110
|
"strict": true,
|
|
5111
|
+
"skipLibCheck": true,
|
|
5032
5112
|
"composite": true,
|
|
5033
5113
|
"declaration": true,
|
|
5034
5114
|
"emitDeclarationOnly": true,
|
|
@@ -5060,6 +5140,9 @@ var BUILTIN_TURBO_TEMPLATE = `{
|
|
|
5060
5140
|
]
|
|
5061
5141
|
},
|
|
5062
5142
|
"typecheck": {
|
|
5143
|
+
"dependsOn": [
|
|
5144
|
+
"^build"
|
|
5145
|
+
],
|
|
5063
5146
|
"outputs": [],
|
|
5064
5147
|
"cache": true
|
|
5065
5148
|
},
|
|
@@ -5080,7 +5163,13 @@ node_modules/
|
|
|
5080
5163
|
dist/
|
|
5081
5164
|
.turbo/
|
|
5082
5165
|
.next/
|
|
5083
|
-
|
|
5166
|
+
.nitro/
|
|
5167
|
+
.output/
|
|
5168
|
+
|
|
5169
|
+
# Next.js static export — anchored to apps so a bare \`out/\` can't shadow a
|
|
5170
|
+
# bounded context's hexagonal \`src/application/ports/out/\` source (which a
|
|
5171
|
+
# pattern without a leading path matches at any depth).
|
|
5172
|
+
apps/*/out/
|
|
5084
5173
|
|
|
5085
5174
|
# Test / coverage
|
|
5086
5175
|
coverage/
|
|
@@ -5485,6 +5574,11 @@ async function writeManifestIfFreshExternal(config, result, report) {
|
|
|
5485
5574
|
const archDir = path6.join(config.workspaceRoot, ".architecture");
|
|
5486
5575
|
const manifestPath = path6.join(archDir, "manifest.yaml");
|
|
5487
5576
|
const relative = path6.relative(config.workspaceRoot, manifestPath);
|
|
5577
|
+
if (!isInScope(manifestPath, config)) {
|
|
5578
|
+
config.logger.debug(`skipped (outside --only) ${relative}`);
|
|
5579
|
+
result.skipped.push(manifestPath);
|
|
5580
|
+
return;
|
|
5581
|
+
}
|
|
5488
5582
|
let exists = false;
|
|
5489
5583
|
try {
|
|
5490
5584
|
await fs3.access(manifestPath);
|
|
@@ -5716,6 +5810,50 @@ export function main(): void {
|
|
|
5716
5810
|
// Application bootstrap for {appName}
|
|
5717
5811
|
}
|
|
5718
5812
|
`;
|
|
5813
|
+
var NITRO_PACKAGE_JSON_TEMPLATE = `{
|
|
5814
|
+
"name": "@{scope}/{appName}",
|
|
5815
|
+
"version": "0.0.0",
|
|
5816
|
+
"private": true,
|
|
5817
|
+
"type": "module",
|
|
5818
|
+
"scripts": {
|
|
5819
|
+
"build": "nitro build",
|
|
5820
|
+
"dev": "nitro dev",
|
|
5821
|
+
"preview": "node .output/server/index.mjs",
|
|
5822
|
+
"prepare": "nitro prepare",
|
|
5823
|
+
"lint": "eslint server --ext .ts",
|
|
5824
|
+
"typecheck": "nitro prepare && tsc --noEmit"
|
|
5825
|
+
},
|
|
5826
|
+
"dependencies": {
|
|
5827
|
+
"nitropack": "^2.13.0"
|
|
5828
|
+
},
|
|
5829
|
+
"devDependencies": {
|
|
5830
|
+
"typescript": "^5.5.4",
|
|
5831
|
+
"eslint": "^9.0.0",
|
|
5832
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
5833
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0"
|
|
5834
|
+
}
|
|
5835
|
+
}
|
|
5836
|
+
`;
|
|
5837
|
+
var NITRO_TSCONFIG = {
|
|
5838
|
+
extends: "./.nitro/types/tsconfig.json",
|
|
5839
|
+
compilerOptions: {
|
|
5840
|
+
moduleResolution: "bundler",
|
|
5841
|
+
strict: true,
|
|
5842
|
+
skipLibCheck: true
|
|
5843
|
+
}
|
|
5844
|
+
};
|
|
5845
|
+
var NITRO_CONFIG_TEMPLATE = `import { defineNitroConfig } from "nitropack/config";
|
|
5846
|
+
|
|
5847
|
+
// https://nitro.build/config
|
|
5848
|
+
export default defineNitroConfig({
|
|
5849
|
+
srcDir: "server",
|
|
5850
|
+
compatibilityDate: "2025-01-01",
|
|
5851
|
+
});
|
|
5852
|
+
`;
|
|
5853
|
+
var NITRO_ROUTE_TEMPLATE = `// Auto-generated Nitro route — GET /
|
|
5854
|
+
// \`defineEventHandler\` is auto-imported by Nitro (see ./.nitro/types).
|
|
5855
|
+
export default defineEventHandler(() => ({ status: "ok", app: "{appName}" }));
|
|
5856
|
+
`;
|
|
5719
5857
|
var BUILTIN_FRAMEWORK_TEMPLATES = {
|
|
5720
5858
|
"next.js": {
|
|
5721
5859
|
packageJson: { template: NEXTJS_PACKAGE_JSON_TEMPLATE },
|
|
@@ -5740,8 +5878,107 @@ var BUILTIN_FRAMEWORK_TEMPLATES = {
|
|
|
5740
5878
|
path: "src/index.ts",
|
|
5741
5879
|
template: PLAIN_TS_ENTRY_TEMPLATE
|
|
5742
5880
|
}
|
|
5881
|
+
},
|
|
5882
|
+
nitro: {
|
|
5883
|
+
packageJson: { template: NITRO_PACKAGE_JSON_TEMPLATE },
|
|
5884
|
+
tsConfig: NITRO_TSCONFIG,
|
|
5885
|
+
entryPoint: {
|
|
5886
|
+
path: "server/routes/index.ts",
|
|
5887
|
+
template: NITRO_ROUTE_TEMPLATE
|
|
5888
|
+
},
|
|
5889
|
+
extraFiles: [{ path: "nitro.config.ts", template: NITRO_CONFIG_TEMPLATE }]
|
|
5743
5890
|
}
|
|
5744
5891
|
};
|
|
5892
|
+
var GENERATED_MARKER_LINE = "// @generated by @hexagen/sync";
|
|
5893
|
+
var BUILTIN_FALLBACK_TEMPLATE2 = `import eslint from '@eslint/js';
|
|
5894
|
+
import tseslint from 'typescript-eslint';
|
|
5895
|
+
|
|
5896
|
+
export default tseslint.config(
|
|
5897
|
+
eslint.configs.recommended,
|
|
5898
|
+
...tseslint.configs.recommended,
|
|
5899
|
+
{
|
|
5900
|
+
rules: {
|
|
5901
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
5902
|
+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
5903
|
+
},
|
|
5904
|
+
},
|
|
5905
|
+
{
|
|
5906
|
+
ignores: ['dist/**', 'node_modules/**'],
|
|
5907
|
+
},
|
|
5908
|
+
);
|
|
5909
|
+
`;
|
|
5910
|
+
function resolveTemplate3(manifest, moduleName, usePerContextOverride) {
|
|
5911
|
+
const contextOverride = usePerContextOverride ? manifest.bounded_contexts?.find((c) => c.name === moduleName)?.generator?.eslint : void 0;
|
|
5912
|
+
if (contextOverride?.template !== void 0) {
|
|
5913
|
+
return { template: contextOverride.template, source: "per-context" };
|
|
5914
|
+
}
|
|
5915
|
+
const rootLevel = manifest.workspaceDefaults?.eslint;
|
|
5916
|
+
if (rootLevel?.template !== void 0) {
|
|
5917
|
+
return { template: rootLevel.template, source: "workspace" };
|
|
5918
|
+
}
|
|
5919
|
+
const monorepoLevel = manifest.monorepo?.workspaceDefaults?.eslint;
|
|
5920
|
+
if (monorepoLevel?.template !== void 0) {
|
|
5921
|
+
return { template: monorepoLevel.template, source: "workspace" };
|
|
5922
|
+
}
|
|
5923
|
+
return { template: BUILTIN_FALLBACK_TEMPLATE2, source: "fallback" };
|
|
5924
|
+
}
|
|
5925
|
+
function withGeneratedMarker(content) {
|
|
5926
|
+
if (content.startsWith(GENERATED_MARKER_LINE)) {
|
|
5927
|
+
return content;
|
|
5928
|
+
}
|
|
5929
|
+
return `${GENERATED_MARKER_LINE}
|
|
5930
|
+
${content}`;
|
|
5931
|
+
}
|
|
5932
|
+
async function generateEslintConfig(moduleDir, moduleName, config, report, options = {}) {
|
|
5933
|
+
const result = createEmptyResult();
|
|
5934
|
+
const filePath = path6.join(moduleDir, "eslint.config.js");
|
|
5935
|
+
try {
|
|
5936
|
+
const { template, source } = resolveTemplate3(
|
|
5937
|
+
config.manifest,
|
|
5938
|
+
moduleName,
|
|
5939
|
+
options.usePerContextOverride ?? true
|
|
5940
|
+
);
|
|
5941
|
+
if (typeof template !== "string" || template.length === 0) {
|
|
5942
|
+
const message = `No eslint template resolved for ${moduleName} (source: ${source}); skipping`;
|
|
5943
|
+
config.logger.error(message);
|
|
5944
|
+
if (report) report.record("error", filePath, message);
|
|
5945
|
+
result.skipped.push(filePath);
|
|
5946
|
+
result.summary = message;
|
|
5947
|
+
return result;
|
|
5948
|
+
}
|
|
5949
|
+
const scope = resolveScope(config.manifest);
|
|
5950
|
+
const { output: interpolated, warnings } = interpolate(template, {
|
|
5951
|
+
packageName: moduleName,
|
|
5952
|
+
scope
|
|
5953
|
+
});
|
|
5954
|
+
for (const missingVar of warnings) {
|
|
5955
|
+
const message = `Missing interpolation variable "${missingVar}" in eslint template for ${moduleName} (source: ${source}); placeholder left verbatim`;
|
|
5956
|
+
config.logger.warn(message);
|
|
5957
|
+
if (report) report.record("warning", filePath, message);
|
|
5958
|
+
}
|
|
5959
|
+
const content = withGeneratedMarker(interpolated);
|
|
5960
|
+
const status = await safeWriteFileAtomic(
|
|
5961
|
+
filePath,
|
|
5962
|
+
content,
|
|
5963
|
+
config,
|
|
5964
|
+
report,
|
|
5965
|
+
false
|
|
5966
|
+
);
|
|
5967
|
+
if (status === "created") result.created.push(filePath);
|
|
5968
|
+
if (status === "updated") result.updated.push(filePath);
|
|
5969
|
+
if (status === "skipped" || status === "protected")
|
|
5970
|
+
result.skipped.push(filePath);
|
|
5971
|
+
result.totalOps += status === "created" || status === "updated" ? 1 : 0;
|
|
5972
|
+
return result;
|
|
5973
|
+
} catch (err3) {
|
|
5974
|
+
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
5975
|
+
result.error = err3 instanceof Error ? err3 : new Error(`eslint generation failed for ${moduleName}: ${message}`);
|
|
5976
|
+
result.summary = `eslint generation failed for ${moduleName}: ${message}`;
|
|
5977
|
+
config.logger.error(result.summary);
|
|
5978
|
+
if (report) report.record("error", filePath, result.summary);
|
|
5979
|
+
return result;
|
|
5980
|
+
}
|
|
5981
|
+
}
|
|
5745
5982
|
|
|
5746
5983
|
// src/generators/apps.ts
|
|
5747
5984
|
function resolveFrameworkConfig(framework, manifestConfig) {
|
|
@@ -5752,7 +5989,8 @@ function resolveFrameworkConfig(framework, manifestConfig) {
|
|
|
5752
5989
|
return {
|
|
5753
5990
|
packageJson: manifestConfig.packageJson ?? builtin.packageJson,
|
|
5754
5991
|
tsConfig: manifestConfig.tsConfig ?? builtin.tsConfig,
|
|
5755
|
-
entryPoint: manifestConfig.entryPoint ?? builtin.entryPoint
|
|
5992
|
+
entryPoint: manifestConfig.entryPoint ?? builtin.entryPoint,
|
|
5993
|
+
extraFiles: manifestConfig.extraFiles ?? builtin.extraFiles
|
|
5756
5994
|
};
|
|
5757
5995
|
}
|
|
5758
5996
|
function interpolateWithLogging2(template, vars, context, config) {
|
|
@@ -5776,6 +6014,57 @@ function recordStatus2(result, filePath, status) {
|
|
|
5776
6014
|
result.skipped.push(filePath);
|
|
5777
6015
|
}
|
|
5778
6016
|
}
|
|
6017
|
+
function mergeResult(result, sub) {
|
|
6018
|
+
result.created.push(...sub.created);
|
|
6019
|
+
result.updated.push(...sub.updated);
|
|
6020
|
+
result.skipped.push(...sub.skipped);
|
|
6021
|
+
result.totalOps += sub.totalOps;
|
|
6022
|
+
if (sub.error && !result.error) {
|
|
6023
|
+
result.error = sub.error;
|
|
6024
|
+
result.summary = sub.summary;
|
|
6025
|
+
}
|
|
6026
|
+
}
|
|
6027
|
+
async function emitAppFile(appDir, relPath, template, vars, config, report, result, appName) {
|
|
6028
|
+
const content = interpolateWithLogging2(
|
|
6029
|
+
template,
|
|
6030
|
+
vars,
|
|
6031
|
+
`apps/${appName}/${relPath}`,
|
|
6032
|
+
config
|
|
6033
|
+
);
|
|
6034
|
+
const target = path6.resolve(appDir, relPath);
|
|
6035
|
+
const relative = path6.relative(appDir, target);
|
|
6036
|
+
if (relative === "" || relative.startsWith("..") || path6.isAbsolute(relative)) {
|
|
6037
|
+
config.logger.warn(
|
|
6038
|
+
`[apps] skipping file with unsafe path (escapes apps/${appName}): ${relPath}`
|
|
6039
|
+
);
|
|
6040
|
+
if (report) {
|
|
6041
|
+
report.record(
|
|
6042
|
+
"blocked",
|
|
6043
|
+
appName,
|
|
6044
|
+
`Unsafe file path (potential path traversal): ${relPath}`
|
|
6045
|
+
);
|
|
6046
|
+
}
|
|
6047
|
+
return "unsafe";
|
|
6048
|
+
}
|
|
6049
|
+
if (isInScope(target, config)) {
|
|
6050
|
+
try {
|
|
6051
|
+
await fs3.mkdir(path6.dirname(target), { recursive: true });
|
|
6052
|
+
} catch (err3) {
|
|
6053
|
+
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
6054
|
+
config.logger.error(
|
|
6055
|
+
`[apps] failed to create dir for "${appName}" file ${relPath}: ${message}`
|
|
6056
|
+
);
|
|
6057
|
+
if (report) report.record("blocked", appName, message);
|
|
6058
|
+
return "error";
|
|
6059
|
+
}
|
|
6060
|
+
}
|
|
6061
|
+
recordStatus2(
|
|
6062
|
+
result,
|
|
6063
|
+
target,
|
|
6064
|
+
await safeWriteFileAtomic(target, content, config, report)
|
|
6065
|
+
);
|
|
6066
|
+
return "ok";
|
|
6067
|
+
}
|
|
5779
6068
|
async function generateApps(config, report) {
|
|
5780
6069
|
const result = createEmptyResult();
|
|
5781
6070
|
try {
|
|
@@ -5795,6 +6084,19 @@ async function generateApps(config, report) {
|
|
|
5795
6084
|
config.logger.warn(`[apps] skipping entry with missing or empty name`);
|
|
5796
6085
|
continue;
|
|
5797
6086
|
}
|
|
6087
|
+
if (app.name.includes("..") || app.name.includes("/") || app.name.includes("\\") || app.name.startsWith(".")) {
|
|
6088
|
+
config.logger.warn(
|
|
6089
|
+
`[apps] skipping app with unsafe name (potential path traversal): ${app.name}`
|
|
6090
|
+
);
|
|
6091
|
+
if (report) {
|
|
6092
|
+
report.record(
|
|
6093
|
+
"blocked",
|
|
6094
|
+
app.name,
|
|
6095
|
+
"Unsafe app name (potential path traversal)"
|
|
6096
|
+
);
|
|
6097
|
+
}
|
|
6098
|
+
continue;
|
|
6099
|
+
}
|
|
5798
6100
|
if (seen.has(app.name)) {
|
|
5799
6101
|
config.logger.warn(
|
|
5800
6102
|
`[apps] duplicate app name "${app.name}" — keeping first occurrence, skipping this duplicate`
|
|
@@ -5839,16 +6141,18 @@ async function generateApps(config, report) {
|
|
|
5839
6141
|
};
|
|
5840
6142
|
const appDir = path6.join(config.workspaceRoot, "apps", app.name);
|
|
5841
6143
|
const srcDir = path6.join(appDir, "src");
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
6144
|
+
if (isInScope(appDir, config)) {
|
|
6145
|
+
try {
|
|
6146
|
+
await fs3.mkdir(appDir, { recursive: true });
|
|
6147
|
+
await fs3.mkdir(srcDir, { recursive: true });
|
|
6148
|
+
} catch (err3) {
|
|
6149
|
+
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
6150
|
+
config.logger.error(
|
|
6151
|
+
`[apps] failed to create directory for "${app.name}": ${message}`
|
|
6152
|
+
);
|
|
6153
|
+
if (report) report.record("blocked", app.name, message);
|
|
6154
|
+
continue;
|
|
6155
|
+
}
|
|
5852
6156
|
}
|
|
5853
6157
|
const pkgTemplate = frameworkConfig.packageJson?.template;
|
|
5854
6158
|
if (pkgTemplate) {
|
|
@@ -5889,37 +6193,47 @@ async function generateApps(config, report) {
|
|
|
5889
6193
|
}
|
|
5890
6194
|
const entry = frameworkConfig.entryPoint;
|
|
5891
6195
|
if (entry?.path && entry.template !== void 0) {
|
|
5892
|
-
const
|
|
6196
|
+
const status = await emitAppFile(
|
|
6197
|
+
appDir,
|
|
6198
|
+
entry.path,
|
|
5893
6199
|
entry.template,
|
|
5894
6200
|
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
6201
|
config,
|
|
5913
|
-
report
|
|
6202
|
+
report,
|
|
6203
|
+
result,
|
|
6204
|
+
app.name
|
|
5914
6205
|
);
|
|
5915
|
-
|
|
6206
|
+
if (status !== "ok") continue;
|
|
5916
6207
|
} else {
|
|
5917
6208
|
config.logger.warn(
|
|
5918
6209
|
`[apps] framework "${framework}" has no entryPoint template — skipping entry file for "${app.name}"`
|
|
5919
6210
|
);
|
|
5920
6211
|
}
|
|
6212
|
+
for (const extra of frameworkConfig.extraFiles ?? []) {
|
|
6213
|
+
if (!extra?.path || extra.template === void 0) continue;
|
|
6214
|
+
await emitAppFile(
|
|
6215
|
+
appDir,
|
|
6216
|
+
extra.path,
|
|
6217
|
+
extra.template,
|
|
6218
|
+
vars,
|
|
6219
|
+
config,
|
|
6220
|
+
report,
|
|
6221
|
+
result,
|
|
6222
|
+
app.name
|
|
6223
|
+
);
|
|
6224
|
+
}
|
|
6225
|
+
const eslintResult = await generateEslintConfig(
|
|
6226
|
+
appDir,
|
|
6227
|
+
app.name,
|
|
6228
|
+
config,
|
|
6229
|
+
report,
|
|
6230
|
+
{ usePerContextOverride: false }
|
|
6231
|
+
);
|
|
6232
|
+
mergeResult(result, eslintResult);
|
|
6233
|
+
}
|
|
6234
|
+
if (!result.error) {
|
|
6235
|
+
result.summary = `apps: ${result.created.length} created, ${result.updated.length} updated, ${result.skipped.length} skipped`;
|
|
5921
6236
|
}
|
|
5922
|
-
result.summary = `apps: ${result.created.length} created, ${result.updated.length} updated, ${result.skipped.length} skipped`;
|
|
5923
6237
|
return result;
|
|
5924
6238
|
} catch (err3) {
|
|
5925
6239
|
const message = err3 instanceof Error ? err3.message : String(err3);
|
|
@@ -5928,91 +6242,69 @@ async function generateApps(config, report) {
|
|
|
5928
6242
|
return result;
|
|
5929
6243
|
}
|
|
5930
6244
|
}
|
|
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" };
|
|
6245
|
+
function relativeImportSpecifier(fromFile, toFile) {
|
|
6246
|
+
let rel = path6.relative(path6.dirname(fromFile), toFile).split(path6.sep).join("/").replace(/\.tsx?$/, ".js");
|
|
6247
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
6248
|
+
return rel;
|
|
5963
6249
|
}
|
|
5964
|
-
function
|
|
5965
|
-
if (
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
6250
|
+
function rewriteRelativeSpecifier(specifier, fromFile, toFile) {
|
|
6251
|
+
if (!specifier.startsWith(".")) return specifier;
|
|
6252
|
+
const absolute = path6.resolve(path6.dirname(fromFile), specifier);
|
|
6253
|
+
let rel = path6.relative(path6.dirname(toFile), absolute).split(path6.sep).join("/");
|
|
6254
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
6255
|
+
return rel;
|
|
5970
6256
|
}
|
|
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
|
-
|
|
6257
|
+
var RESERVED_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
6258
|
+
"break",
|
|
6259
|
+
"case",
|
|
6260
|
+
"catch",
|
|
6261
|
+
"class",
|
|
6262
|
+
"const",
|
|
6263
|
+
"continue",
|
|
6264
|
+
"debugger",
|
|
6265
|
+
"default",
|
|
6266
|
+
"delete",
|
|
6267
|
+
"do",
|
|
6268
|
+
"else",
|
|
6269
|
+
"enum",
|
|
6270
|
+
"export",
|
|
6271
|
+
"extends",
|
|
6272
|
+
"false",
|
|
6273
|
+
"finally",
|
|
6274
|
+
"for",
|
|
6275
|
+
"function",
|
|
6276
|
+
"if",
|
|
6277
|
+
"import",
|
|
6278
|
+
"in",
|
|
6279
|
+
"instanceof",
|
|
6280
|
+
"new",
|
|
6281
|
+
"null",
|
|
6282
|
+
"return",
|
|
6283
|
+
"super",
|
|
6284
|
+
"switch",
|
|
6285
|
+
"this",
|
|
6286
|
+
"throw",
|
|
6287
|
+
"true",
|
|
6288
|
+
"try",
|
|
6289
|
+
"typeof",
|
|
6290
|
+
"var",
|
|
6291
|
+
"void",
|
|
6292
|
+
"while",
|
|
6293
|
+
"with",
|
|
6294
|
+
"yield",
|
|
6295
|
+
"let",
|
|
6296
|
+
"static",
|
|
6297
|
+
"implements",
|
|
6298
|
+
"interface",
|
|
6299
|
+
"package",
|
|
6300
|
+
"private",
|
|
6301
|
+
"protected",
|
|
6302
|
+
"public",
|
|
6303
|
+
"await"
|
|
6304
|
+
]);
|
|
6305
|
+
function safeParamName(name) {
|
|
6306
|
+
const candidate = name.length === 0 ? "dep" : name;
|
|
6307
|
+
return RESERVED_IDENTIFIERS.has(candidate) ? `${candidate}_` : candidate;
|
|
6016
6308
|
}
|
|
6017
6309
|
function analyzePortFile(portFilePath) {
|
|
6018
6310
|
try {
|
|
@@ -6089,13 +6381,22 @@ function extractImports(importDecls) {
|
|
|
6089
6381
|
}
|
|
6090
6382
|
return imports;
|
|
6091
6383
|
}
|
|
6092
|
-
function generateAdapterFromPort(analysis, adapterName) {
|
|
6384
|
+
function generateAdapterFromPort(analysis, adapterName, portImportSpecifier, outputFilePath) {
|
|
6093
6385
|
const { interfaceName, methods, imports } = analysis;
|
|
6094
|
-
const
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6386
|
+
const portImport = portImportSpecifier ? `import type { ${interfaceName} } from '${portImportSpecifier}';` : "";
|
|
6387
|
+
const importStatements = [
|
|
6388
|
+
portImport,
|
|
6389
|
+
...imports.map((imp) => {
|
|
6390
|
+
const specifier = outputFilePath ? rewriteRelativeSpecifier(
|
|
6391
|
+
imp.moduleSpecifier,
|
|
6392
|
+
analysis.filePath,
|
|
6393
|
+
outputFilePath
|
|
6394
|
+
) : imp.moduleSpecifier;
|
|
6395
|
+
const typeOnly = imp.isTypeOnly ? "type " : "";
|
|
6396
|
+
const names = imp.namedImports.join(", ");
|
|
6397
|
+
return `import ${typeOnly}{ ${names} } from '${specifier}';`;
|
|
6398
|
+
})
|
|
6399
|
+
].filter(Boolean).join("\n");
|
|
6099
6400
|
const methodImpls = methods.map((method) => {
|
|
6100
6401
|
const params = method.parameters.map((p) => `${p.name}${p.isOptional ? "?" : ""}: ${p.type}`).join(", ");
|
|
6101
6402
|
const asyncKeyword = method.isAsync ? "async " : "";
|
|
@@ -6123,16 +6424,48 @@ ${methodImpls}
|
|
|
6123
6424
|
}
|
|
6124
6425
|
`;
|
|
6125
6426
|
}
|
|
6126
|
-
function generateUseCaseFromPort(analysis, useCaseName, outPorts) {
|
|
6427
|
+
function generateUseCaseFromPort(analysis, useCaseName, outPorts, portImportSpecifier, outputFilePath) {
|
|
6127
6428
|
const { interfaceName, methods, imports } = analysis;
|
|
6128
|
-
const
|
|
6429
|
+
const importLines = [];
|
|
6430
|
+
const taken = /* @__PURE__ */ new Set();
|
|
6431
|
+
const importType = (name, specifier) => {
|
|
6432
|
+
let local = name;
|
|
6433
|
+
let n = 2;
|
|
6434
|
+
while (taken.has(local)) local = `${name}_${n++}`;
|
|
6435
|
+
taken.add(local);
|
|
6436
|
+
importLines.push(
|
|
6437
|
+
local === name ? `import type { ${name} } from '${specifier}';` : `import type { ${name} as ${local} } from '${specifier}';`
|
|
6438
|
+
);
|
|
6439
|
+
return local;
|
|
6440
|
+
};
|
|
6441
|
+
const implementsName = portImportSpecifier ? importType(interfaceName, portImportSpecifier) : interfaceName;
|
|
6442
|
+
const seenDeps = /* @__PURE__ */ new Map();
|
|
6443
|
+
const usedParams = /* @__PURE__ */ new Set();
|
|
6444
|
+
const constructorEntries = [];
|
|
6445
|
+
for (const p of outPorts) {
|
|
6446
|
+
const depKey = `${p.interfaceName}|${p.importSpecifier}`;
|
|
6447
|
+
if (seenDeps.has(depKey)) continue;
|
|
6448
|
+
const localType = importType(p.interfaceName, p.importSpecifier);
|
|
6449
|
+
seenDeps.set(depKey, localType);
|
|
6450
|
+
let param = safeParamName(p.paramName);
|
|
6451
|
+
const paramBase = param;
|
|
6452
|
+
let n = 2;
|
|
6453
|
+
while (usedParams.has(param)) param = `${paramBase}${n++}`;
|
|
6454
|
+
usedParams.add(param);
|
|
6455
|
+
constructorEntries.push(`private readonly ${param}: ${localType}`);
|
|
6456
|
+
}
|
|
6457
|
+
for (const imp of imports) {
|
|
6458
|
+
const specifier = outputFilePath ? rewriteRelativeSpecifier(
|
|
6459
|
+
imp.moduleSpecifier,
|
|
6460
|
+
analysis.filePath,
|
|
6461
|
+
outputFilePath
|
|
6462
|
+
) : imp.moduleSpecifier;
|
|
6129
6463
|
const typeOnly = imp.isTypeOnly ? "type " : "";
|
|
6130
|
-
const
|
|
6131
|
-
|
|
6132
|
-
}
|
|
6133
|
-
const
|
|
6134
|
-
|
|
6135
|
-
).join(",\n ");
|
|
6464
|
+
const line = `import ${typeOnly}{ ${imp.namedImports.join(", ")} } from '${specifier}';`;
|
|
6465
|
+
if (!importLines.includes(line)) importLines.push(line);
|
|
6466
|
+
}
|
|
6467
|
+
const importStatements = importLines.join("\n");
|
|
6468
|
+
const constructorParams = constructorEntries.join(",\n ");
|
|
6136
6469
|
const methodImpls = methods.map((method) => {
|
|
6137
6470
|
const params = method.parameters.map((p) => `${p.name}${p.isOptional ? "?" : ""}: ${p.type}`).join(", ");
|
|
6138
6471
|
const asyncKeyword = method.isAsync ? "async " : "";
|
|
@@ -6145,12 +6478,12 @@ function generateUseCaseFromPort(analysis, useCaseName, outPorts) {
|
|
|
6145
6478
|
throw new Error('Not implemented: ${method.name}');
|
|
6146
6479
|
}`;
|
|
6147
6480
|
}).join("\n\n");
|
|
6148
|
-
const constructorBlock =
|
|
6481
|
+
const constructorBlock = constructorEntries.length > 0 ? ` constructor(
|
|
6149
6482
|
${constructorParams}
|
|
6150
6483
|
) {}` : "";
|
|
6151
6484
|
return `// @generated use-case stub — edit freely
|
|
6152
6485
|
/**
|
|
6153
|
-
* ${useCaseName} implements ${
|
|
6486
|
+
* ${useCaseName} implements ${implementsName}
|
|
6154
6487
|
*
|
|
6155
6488
|
* This use case was generated from the port interface.
|
|
6156
6489
|
* Replace TODO implementations with actual business logic.
|
|
@@ -6158,7 +6491,7 @@ function generateUseCaseFromPort(analysis, useCaseName, outPorts) {
|
|
|
6158
6491
|
|
|
6159
6492
|
${importStatements}
|
|
6160
6493
|
|
|
6161
|
-
export class ${useCaseName} implements ${
|
|
6494
|
+
export class ${useCaseName} implements ${implementsName} {
|
|
6162
6495
|
${constructorBlock}
|
|
6163
6496
|
|
|
6164
6497
|
${methodImpls}
|
|
@@ -6551,6 +6884,12 @@ function resolveNaming(kind, contextNaming, manifestNaming) {
|
|
|
6551
6884
|
return contextNaming?.[kind] ?? manifestNaming?.[kind] ?? DEFAULT_NAMING[kind];
|
|
6552
6885
|
}
|
|
6553
6886
|
async function writeStubFile(filePath, content, config, report) {
|
|
6887
|
+
if (!isInScope(filePath, config)) {
|
|
6888
|
+
config.logger.debug(
|
|
6889
|
+
`skipped (outside --only) ${path6.relative(config.workspaceRoot, filePath)}`
|
|
6890
|
+
);
|
|
6891
|
+
return "skipped";
|
|
6892
|
+
}
|
|
6554
6893
|
try {
|
|
6555
6894
|
await fs3.stat(filePath);
|
|
6556
6895
|
const relative = path6.relative(config.workspaceRoot, filePath);
|
|
@@ -6571,12 +6910,14 @@ async function writeStubFile(filePath, content, config, report) {
|
|
|
6571
6910
|
await fs3.mkdir(path6.dirname(filePath), { recursive: true });
|
|
6572
6911
|
return safeWriteFileAtomic(filePath, content, config, report, false);
|
|
6573
6912
|
}
|
|
6574
|
-
async function tryAnalyzeRelatedPort(moduleDir, name, kind, context) {
|
|
6913
|
+
async function tryAnalyzeRelatedPort(moduleDir, name, kind, context, relatedPortNamingTemplate) {
|
|
6575
6914
|
const portType = kind === "adapter" ? "out" : "in";
|
|
6576
6915
|
const portSubdir = `application/ports/${portType}`;
|
|
6577
6916
|
const derivedPortName = name.replace(/Adapter$|UseCase$/, "Port");
|
|
6578
6917
|
const declaredPorts = portType === "in" ? context.layers?.application?.ports?.in || [] : context.layers?.application?.ports?.out || [];
|
|
6579
|
-
if (!declaredPorts.some(
|
|
6918
|
+
if (!declaredPorts.some(
|
|
6919
|
+
(p) => normalizeStubName(portName(p), relatedPortNamingTemplate) === derivedPortName
|
|
6920
|
+
)) {
|
|
6580
6921
|
return null;
|
|
6581
6922
|
}
|
|
6582
6923
|
const possibleFilenames = [
|
|
@@ -6593,6 +6934,15 @@ async function tryAnalyzeRelatedPort(moduleDir, name, kind, context) {
|
|
|
6593
6934
|
}
|
|
6594
6935
|
return null;
|
|
6595
6936
|
}
|
|
6937
|
+
function normalizeStubName(rawName, namingTemplate) {
|
|
6938
|
+
const placeholder = "{name}";
|
|
6939
|
+
const idx = namingTemplate.lastIndexOf(placeholder);
|
|
6940
|
+
const ext = idx >= 0 ? namingTemplate.slice(idx + placeholder.length) : "";
|
|
6941
|
+
const base = ext && rawName.endsWith(ext) ? rawName.slice(0, -ext.length) : rawName;
|
|
6942
|
+
const pascal = base.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
6943
|
+
if (pascal.length === 0) return "Stub";
|
|
6944
|
+
return /^[0-9]/.test(pascal) ? `Stub${pascal}` : pascal;
|
|
6945
|
+
}
|
|
6596
6946
|
async function generateStubs(moduleDir, moduleName, config, report) {
|
|
6597
6947
|
const result = createEmptyResult();
|
|
6598
6948
|
const stubs = config.manifest.generator?.sync?.stubs;
|
|
@@ -6621,27 +6971,73 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
6621
6971
|
for (const { kind, subdir, names } of plan) {
|
|
6622
6972
|
const contentTemplate = resolveTemplate4(kind, manifestTemplates);
|
|
6623
6973
|
const namingTemplate = resolveNaming(kind, contextNaming, manifestNaming);
|
|
6624
|
-
for (const
|
|
6974
|
+
for (const rawName of names) {
|
|
6975
|
+
const name = normalizeStubName(rawName, namingTemplate);
|
|
6625
6976
|
const filename = interpolateWithLog(
|
|
6626
6977
|
namingTemplate,
|
|
6627
6978
|
name,
|
|
6628
6979
|
`stubs.naming.${kind}`,
|
|
6629
6980
|
config
|
|
6630
6981
|
);
|
|
6982
|
+
const filePath = path6.join(moduleDir, "src", subdir, filename);
|
|
6631
6983
|
let content;
|
|
6632
6984
|
if (kind === "adapter" || kind === "useCase") {
|
|
6985
|
+
const relatedPortNaming = resolveNaming(
|
|
6986
|
+
kind === "adapter" ? "outPort" : "inPort",
|
|
6987
|
+
contextNaming,
|
|
6988
|
+
manifestNaming
|
|
6989
|
+
);
|
|
6633
6990
|
const portAnalysis = await tryAnalyzeRelatedPort(
|
|
6634
6991
|
moduleDir,
|
|
6635
6992
|
name,
|
|
6636
6993
|
kind,
|
|
6637
|
-
context
|
|
6994
|
+
context,
|
|
6995
|
+
relatedPortNaming
|
|
6638
6996
|
);
|
|
6639
6997
|
if (portAnalysis) {
|
|
6640
6998
|
if (kind === "adapter") {
|
|
6641
|
-
content = generateAdapterFromPort(
|
|
6999
|
+
content = generateAdapterFromPort(
|
|
7000
|
+
portAnalysis,
|
|
7001
|
+
name,
|
|
7002
|
+
relativeImportSpecifier(filePath, portAnalysis.filePath),
|
|
7003
|
+
filePath
|
|
7004
|
+
);
|
|
6642
7005
|
} else {
|
|
6643
|
-
const
|
|
6644
|
-
|
|
7006
|
+
const outPortNaming = resolveNaming(
|
|
7007
|
+
"outPort",
|
|
7008
|
+
contextNaming,
|
|
7009
|
+
manifestNaming
|
|
7010
|
+
);
|
|
7011
|
+
const outPortDir = path6.join(
|
|
7012
|
+
moduleDir,
|
|
7013
|
+
"src",
|
|
7014
|
+
"application",
|
|
7015
|
+
"ports",
|
|
7016
|
+
"out"
|
|
7017
|
+
);
|
|
7018
|
+
const outPorts = (context.layers?.application?.ports?.out ?? []).map((p) => {
|
|
7019
|
+
const base = normalizeStubName(portName(p), outPortNaming);
|
|
7020
|
+
const outFile = interpolateWithLog(
|
|
7021
|
+
outPortNaming,
|
|
7022
|
+
base,
|
|
7023
|
+
"stubs.naming.outPort",
|
|
7024
|
+
config
|
|
7025
|
+
);
|
|
7026
|
+
const outPortPath = path6.join(outPortDir, outFile);
|
|
7027
|
+
const analyzed = analyzePortFile(outPortPath);
|
|
7028
|
+
return {
|
|
7029
|
+
interfaceName: analyzed?.interfaceName ?? `${base}Port`,
|
|
7030
|
+
paramName: base.charAt(0).toLowerCase() + base.slice(1),
|
|
7031
|
+
importSpecifier: relativeImportSpecifier(filePath, outPortPath)
|
|
7032
|
+
};
|
|
7033
|
+
});
|
|
7034
|
+
content = generateUseCaseFromPort(
|
|
7035
|
+
portAnalysis,
|
|
7036
|
+
name,
|
|
7037
|
+
outPorts,
|
|
7038
|
+
relativeImportSpecifier(filePath, portAnalysis.filePath),
|
|
7039
|
+
filePath
|
|
7040
|
+
);
|
|
6645
7041
|
}
|
|
6646
7042
|
config.logger.debug(`Generated ${kind} '${name}' from port analysis`);
|
|
6647
7043
|
} else {
|
|
@@ -6660,7 +7056,6 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
6660
7056
|
config
|
|
6661
7057
|
);
|
|
6662
7058
|
}
|
|
6663
|
-
const filePath = path6.join(moduleDir, "src", subdir, filename);
|
|
6664
7059
|
const status = await writeStubFile(filePath, content, config, report);
|
|
6665
7060
|
if (status === "created") result.created.push(filePath);
|
|
6666
7061
|
if (status === "updated") result.updated.push(filePath);
|
|
@@ -6671,6 +7066,347 @@ async function generateStubs(moduleDir, moduleName, config, report) {
|
|
|
6671
7066
|
}
|
|
6672
7067
|
return result;
|
|
6673
7068
|
}
|
|
7069
|
+
var OHS_NOTE = "\n *\n * Open Host Service (open-host): this is this context's published language for consuming contexts — keep it stable.";
|
|
7070
|
+
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.";
|
|
7071
|
+
function recordStatus3(result, filePath, status) {
|
|
7072
|
+
if (status === "created") result.created.push(filePath);
|
|
7073
|
+
else if (status === "updated") result.updated.push(filePath);
|
|
7074
|
+
else if (status === "skipped" || status === "protected")
|
|
7075
|
+
result.skipped.push(filePath);
|
|
7076
|
+
if (status === "created" || status === "updated") result.totalOps += 1;
|
|
7077
|
+
}
|
|
7078
|
+
function addAll(map, key, values) {
|
|
7079
|
+
const set = map.get(key) ?? /* @__PURE__ */ new Set();
|
|
7080
|
+
values.forEach((v) => set.add(v));
|
|
7081
|
+
map.set(key, set);
|
|
7082
|
+
}
|
|
7083
|
+
function toPascalCase2(stem) {
|
|
7084
|
+
return stem.split(/[-.]/).filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
7085
|
+
}
|
|
7086
|
+
function toCamelCase(pascal) {
|
|
7087
|
+
return pascal.length > 0 ? pascal.charAt(0).toLowerCase() + pascal.slice(1) : pascal;
|
|
7088
|
+
}
|
|
7089
|
+
function isSafePathSegment(name) {
|
|
7090
|
+
return name.length > 0 && !name.includes("..") && !name.includes("/") && !name.includes("\\") && !name.startsWith(".");
|
|
7091
|
+
}
|
|
7092
|
+
function isValidTsIdentifier(name) {
|
|
7093
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
|
|
7094
|
+
}
|
|
7095
|
+
function eventContractContent(name) {
|
|
7096
|
+
return `// @generated cross-context event contract — edit freely
|
|
7097
|
+
/**
|
|
7098
|
+
* ${name} is a domain event published across an event-bus boundary.
|
|
7099
|
+
* Both the publishing and subscribing contexts depend on this shared contract.
|
|
7100
|
+
*/
|
|
7101
|
+
export interface ${name} {
|
|
7102
|
+
// TODO: define the event payload
|
|
7103
|
+
readonly occurredAt: string;
|
|
7104
|
+
}
|
|
7105
|
+
`;
|
|
7106
|
+
}
|
|
7107
|
+
function dtoContent(op) {
|
|
7108
|
+
return `// @generated cross-context DTO — edit freely
|
|
7109
|
+
/**
|
|
7110
|
+
* Request/response payloads for the ${op} operation, exchanged across the
|
|
7111
|
+
* network boundary. Both the calling (client) and serving (controller) contexts
|
|
7112
|
+
* depend on these shared contracts.
|
|
7113
|
+
*/
|
|
7114
|
+
export interface ${op}Request {
|
|
7115
|
+
// TODO: define the request fields
|
|
7116
|
+
readonly _placeholder?: never;
|
|
7117
|
+
}
|
|
7118
|
+
|
|
7119
|
+
export interface ${op}Response {
|
|
7120
|
+
// TODO: define the response fields
|
|
7121
|
+
readonly _placeholder?: never;
|
|
7122
|
+
}
|
|
7123
|
+
`;
|
|
7124
|
+
}
|
|
7125
|
+
function portContent(scope, interfaceName, methods, importedTypes, doc) {
|
|
7126
|
+
const uniqueImports = [...new Set(importedTypes)].sort();
|
|
7127
|
+
const importLine = uniqueImports.length > 0 ? `import type { ${uniqueImports.join(", ")} } from "@${scope}/shared";
|
|
7128
|
+
|
|
7129
|
+
` : "";
|
|
7130
|
+
const methodLines = methods.map(
|
|
7131
|
+
(m) => ` ${m.name}(${m.paramName}: ${m.paramType}): Promise<${m.returnType}>;`
|
|
7132
|
+
).join("\n");
|
|
7133
|
+
return `// @generated cross-context port — edit freely
|
|
7134
|
+
${importLine}/**
|
|
7135
|
+
* ${doc}
|
|
7136
|
+
*/
|
|
7137
|
+
export interface ${interfaceName} {
|
|
7138
|
+
${methodLines}
|
|
7139
|
+
}
|
|
7140
|
+
`;
|
|
7141
|
+
}
|
|
7142
|
+
async function emitPortAndAdapter(result, config, report, scope, spec) {
|
|
7143
|
+
const moduleRoot = path6.join(
|
|
7144
|
+
config.workspaceRoot,
|
|
7145
|
+
"packages",
|
|
7146
|
+
spec.contextName
|
|
7147
|
+
);
|
|
7148
|
+
const portDir = path6.join(
|
|
7149
|
+
moduleRoot,
|
|
7150
|
+
"src",
|
|
7151
|
+
"application",
|
|
7152
|
+
"ports",
|
|
7153
|
+
spec.portKind
|
|
7154
|
+
);
|
|
7155
|
+
const portPath = path6.join(
|
|
7156
|
+
portDir,
|
|
7157
|
+
`${spec.portBase}.${spec.portKind}-port.ts`
|
|
7158
|
+
);
|
|
7159
|
+
if (!isInScope(portPath, config)) {
|
|
7160
|
+
return;
|
|
7161
|
+
}
|
|
7162
|
+
await fs3.mkdir(portDir, { recursive: true });
|
|
7163
|
+
recordStatus3(
|
|
7164
|
+
result,
|
|
7165
|
+
portPath,
|
|
7166
|
+
await safeWriteFileAtomic(
|
|
7167
|
+
portPath,
|
|
7168
|
+
portContent(
|
|
7169
|
+
scope,
|
|
7170
|
+
spec.interfaceName,
|
|
7171
|
+
spec.methods,
|
|
7172
|
+
spec.importedTypes,
|
|
7173
|
+
spec.doc
|
|
7174
|
+
),
|
|
7175
|
+
config,
|
|
7176
|
+
report
|
|
7177
|
+
)
|
|
7178
|
+
);
|
|
7179
|
+
const analysis = analyzePortFile(portPath);
|
|
7180
|
+
if (!analysis) {
|
|
7181
|
+
config.logger.warn(
|
|
7182
|
+
`[cross-context] could not analyze ${portPath}; skipping adapter`
|
|
7183
|
+
);
|
|
7184
|
+
return;
|
|
7185
|
+
}
|
|
7186
|
+
const adapterDir = path6.join(moduleRoot, "src", "infrastructure", "adapters");
|
|
7187
|
+
const adapterPath = path6.join(adapterDir, `${spec.portBase}.adapter.ts`);
|
|
7188
|
+
if (!isInScope(adapterPath, config)) {
|
|
7189
|
+
return;
|
|
7190
|
+
}
|
|
7191
|
+
await fs3.mkdir(adapterDir, { recursive: true });
|
|
7192
|
+
const adapterClassName = `${toPascalCase2(spec.portBase)}Adapter`;
|
|
7193
|
+
const portSpecifier = relativeImportSpecifier(adapterPath, portPath);
|
|
7194
|
+
recordStatus3(
|
|
7195
|
+
result,
|
|
7196
|
+
adapterPath,
|
|
7197
|
+
await safeWriteFileAtomic(
|
|
7198
|
+
adapterPath,
|
|
7199
|
+
generateAdapterFromPort(analysis, adapterClassName, portSpecifier),
|
|
7200
|
+
config,
|
|
7201
|
+
report
|
|
7202
|
+
)
|
|
7203
|
+
);
|
|
7204
|
+
}
|
|
7205
|
+
function operationMethods(ops) {
|
|
7206
|
+
return ops.map((op) => ({
|
|
7207
|
+
name: toCamelCase(op),
|
|
7208
|
+
paramName: "request",
|
|
7209
|
+
paramType: `${op}Request`,
|
|
7210
|
+
returnType: `${op}Response`
|
|
7211
|
+
}));
|
|
7212
|
+
}
|
|
7213
|
+
function operationImports(ops) {
|
|
7214
|
+
return ops.flatMap((op) => [`${op}Request`, `${op}Response`]);
|
|
7215
|
+
}
|
|
7216
|
+
async function writeSharedContract(result, config, report, relSegments, content) {
|
|
7217
|
+
const contractPath = path6.join(
|
|
7218
|
+
config.workspaceRoot,
|
|
7219
|
+
"packages",
|
|
7220
|
+
"shared",
|
|
7221
|
+
"src",
|
|
7222
|
+
...relSegments
|
|
7223
|
+
);
|
|
7224
|
+
await fs3.mkdir(path6.dirname(contractPath), { recursive: true });
|
|
7225
|
+
recordStatus3(
|
|
7226
|
+
result,
|
|
7227
|
+
contractPath,
|
|
7228
|
+
await safeWriteFileAtomic(contractPath, content, config, report)
|
|
7229
|
+
);
|
|
7230
|
+
}
|
|
7231
|
+
async function generateCrossContext(config, report) {
|
|
7232
|
+
const result = createEmptyResult();
|
|
7233
|
+
const edges = config.manifest.cross_context;
|
|
7234
|
+
if (!Array.isArray(edges) || edges.length === 0) return result;
|
|
7235
|
+
const scope = resolveScope(config.manifest);
|
|
7236
|
+
const allEvents = /* @__PURE__ */ new Set();
|
|
7237
|
+
const publisherEvents = /* @__PURE__ */ new Map();
|
|
7238
|
+
const subscriberEvents = /* @__PURE__ */ new Map();
|
|
7239
|
+
const allOperations = /* @__PURE__ */ new Set();
|
|
7240
|
+
const controllerOps = /* @__PURE__ */ new Map();
|
|
7241
|
+
const clientOps = /* @__PURE__ */ new Map();
|
|
7242
|
+
const ohsProviders = /* @__PURE__ */ new Set();
|
|
7243
|
+
const aclConsumers = /* @__PURE__ */ new Set();
|
|
7244
|
+
for (const edge of edges) {
|
|
7245
|
+
if (edge.provider && !isSafePathSegment(edge.provider) || edge.consumer && !isSafePathSegment(edge.consumer)) {
|
|
7246
|
+
config.logger.warn(
|
|
7247
|
+
`[cross-context] skipping edge with unsafe context name: ${edge.consumer} -> ${edge.provider}`
|
|
7248
|
+
);
|
|
7249
|
+
continue;
|
|
7250
|
+
}
|
|
7251
|
+
if (edge.integrationPattern === "open-host" && edge.provider)
|
|
7252
|
+
ohsProviders.add(edge.provider);
|
|
7253
|
+
if (edge.integrationPattern === "acl" && edge.consumer)
|
|
7254
|
+
aclConsumers.add(edge.consumer);
|
|
7255
|
+
if (edge.transport === "network") {
|
|
7256
|
+
const operations = (edge.operations ?? []).filter(
|
|
7257
|
+
(o) => typeof o === "string" && isValidTsIdentifier(o)
|
|
7258
|
+
);
|
|
7259
|
+
operations.forEach((o) => allOperations.add(o));
|
|
7260
|
+
if (edge.provider) addAll(controllerOps, edge.provider, operations);
|
|
7261
|
+
if (edge.consumer) addAll(clientOps, edge.consumer, operations);
|
|
7262
|
+
} else {
|
|
7263
|
+
const events = (edge.events ?? []).filter(
|
|
7264
|
+
(e) => typeof e === "string" && isValidTsIdentifier(e)
|
|
7265
|
+
);
|
|
7266
|
+
events.forEach((e) => allEvents.add(e));
|
|
7267
|
+
if (edge.provider) addAll(publisherEvents, edge.provider, events);
|
|
7268
|
+
if (edge.consumer) addAll(subscriberEvents, edge.consumer, events);
|
|
7269
|
+
}
|
|
7270
|
+
}
|
|
7271
|
+
for (const event of [...allEvents].sort()) {
|
|
7272
|
+
await writeSharedContract(
|
|
7273
|
+
result,
|
|
7274
|
+
config,
|
|
7275
|
+
report,
|
|
7276
|
+
["domain", "events", `${event}.event.ts`],
|
|
7277
|
+
eventContractContent(event)
|
|
7278
|
+
);
|
|
7279
|
+
}
|
|
7280
|
+
for (const provider of [...publisherEvents.keys()].sort()) {
|
|
7281
|
+
const events = [...publisherEvents.get(provider) ?? []].sort();
|
|
7282
|
+
await emitPortAndAdapter(result, config, report, scope, {
|
|
7283
|
+
contextName: provider,
|
|
7284
|
+
portKind: "out",
|
|
7285
|
+
portBase: "message-publisher",
|
|
7286
|
+
interfaceName: "MessagePublisherPort",
|
|
7287
|
+
methods: [
|
|
7288
|
+
{
|
|
7289
|
+
name: "publish",
|
|
7290
|
+
paramName: "event",
|
|
7291
|
+
paramType: events.join(" | ") || "unknown",
|
|
7292
|
+
returnType: "void"
|
|
7293
|
+
}
|
|
7294
|
+
],
|
|
7295
|
+
importedTypes: events,
|
|
7296
|
+
doc: "Publishes this context's domain events across the event-bus boundary." + (ohsProviders.has(provider) ? OHS_NOTE : "")
|
|
7297
|
+
});
|
|
7298
|
+
}
|
|
7299
|
+
for (const consumer of [...subscriberEvents.keys()].sort()) {
|
|
7300
|
+
const events = [...subscriberEvents.get(consumer) ?? []].sort();
|
|
7301
|
+
await emitPortAndAdapter(result, config, report, scope, {
|
|
7302
|
+
contextName: consumer,
|
|
7303
|
+
portKind: "in",
|
|
7304
|
+
portBase: "event-listener",
|
|
7305
|
+
interfaceName: "EventListenerPort",
|
|
7306
|
+
methods: [
|
|
7307
|
+
{
|
|
7308
|
+
name: "handle",
|
|
7309
|
+
paramName: "event",
|
|
7310
|
+
paramType: events.join(" | ") || "unknown",
|
|
7311
|
+
returnType: "void"
|
|
7312
|
+
}
|
|
7313
|
+
],
|
|
7314
|
+
importedTypes: events,
|
|
7315
|
+
doc: "Handles cross-context events this context subscribes to." + (aclConsumers.has(consumer) ? ACL_NOTE : "")
|
|
7316
|
+
});
|
|
7317
|
+
}
|
|
7318
|
+
for (const op of [...allOperations].sort()) {
|
|
7319
|
+
await writeSharedContract(
|
|
7320
|
+
result,
|
|
7321
|
+
config,
|
|
7322
|
+
report,
|
|
7323
|
+
["domain", "dtos", `${op}.dto.ts`],
|
|
7324
|
+
dtoContent(op)
|
|
7325
|
+
);
|
|
7326
|
+
}
|
|
7327
|
+
for (const provider of [...controllerOps.keys()].sort()) {
|
|
7328
|
+
const ops = [...controllerOps.get(provider) ?? []].sort();
|
|
7329
|
+
await emitPortAndAdapter(result, config, report, scope, {
|
|
7330
|
+
contextName: provider,
|
|
7331
|
+
portKind: "in",
|
|
7332
|
+
portBase: "rest-controller",
|
|
7333
|
+
interfaceName: "RestControllerPort",
|
|
7334
|
+
methods: operationMethods(ops),
|
|
7335
|
+
importedTypes: operationImports(ops),
|
|
7336
|
+
doc: "Serves this context's operations over the network boundary." + (ohsProviders.has(provider) ? OHS_NOTE : "")
|
|
7337
|
+
});
|
|
7338
|
+
}
|
|
7339
|
+
for (const consumer of [...clientOps.keys()].sort()) {
|
|
7340
|
+
const ops = [...clientOps.get(consumer) ?? []].sort();
|
|
7341
|
+
await emitPortAndAdapter(result, config, report, scope, {
|
|
7342
|
+
contextName: consumer,
|
|
7343
|
+
portKind: "out",
|
|
7344
|
+
portBase: "external-service-client",
|
|
7345
|
+
interfaceName: "ExternalServiceClientPort",
|
|
7346
|
+
methods: operationMethods(ops),
|
|
7347
|
+
importedTypes: operationImports(ops),
|
|
7348
|
+
doc: "Calls operations on the contexts this context depends on over the network." + (aclConsumers.has(consumer) ? ACL_NOTE : "")
|
|
7349
|
+
});
|
|
7350
|
+
}
|
|
7351
|
+
return result;
|
|
7352
|
+
}
|
|
7353
|
+
var RESULT_KERNEL = `// @generated by @hexagen/sync — shared Result kernel (edit freely)
|
|
7354
|
+
/**
|
|
7355
|
+
* Result is the explicit success/failure type generated use-cases return.
|
|
7356
|
+
* Mirrors @hexagen/shared's Result. Created once, then preserved on re-sync.
|
|
7357
|
+
*/
|
|
7358
|
+
export type Result<T, E = unknown> =
|
|
7359
|
+
| { success: true; value: T }
|
|
7360
|
+
| { success: false; error: E };
|
|
7361
|
+
|
|
7362
|
+
export const ok = <T>(value: T): Result<T, never> => ({ success: true, value });
|
|
7363
|
+
export const err = <E>(error: E): Result<never, E> => ({
|
|
7364
|
+
success: false,
|
|
7365
|
+
error,
|
|
7366
|
+
});
|
|
7367
|
+
`;
|
|
7368
|
+
async function generateSharedKernel(config, report) {
|
|
7369
|
+
const result = createEmptyResult();
|
|
7370
|
+
if (config.mode !== "external") return result;
|
|
7371
|
+
const hasShared = (config.manifest.bounded_contexts ?? []).some(
|
|
7372
|
+
(bc) => bc.name?.toLowerCase() === "shared"
|
|
7373
|
+
);
|
|
7374
|
+
if (!hasShared) return result;
|
|
7375
|
+
const kernelPath = path6.join(
|
|
7376
|
+
config.workspaceRoot,
|
|
7377
|
+
"packages",
|
|
7378
|
+
"shared",
|
|
7379
|
+
"src",
|
|
7380
|
+
"domain",
|
|
7381
|
+
"result.ts"
|
|
7382
|
+
);
|
|
7383
|
+
if (!isInScope(kernelPath, config)) {
|
|
7384
|
+
result.skipped.push(kernelPath);
|
|
7385
|
+
return result;
|
|
7386
|
+
}
|
|
7387
|
+
try {
|
|
7388
|
+
await fs3.stat(kernelPath);
|
|
7389
|
+
result.skipped.push(kernelPath);
|
|
7390
|
+
return result;
|
|
7391
|
+
} catch (err3) {
|
|
7392
|
+
if (err3.code !== "ENOENT") throw err3;
|
|
7393
|
+
}
|
|
7394
|
+
await fs3.mkdir(path6.dirname(kernelPath), { recursive: true });
|
|
7395
|
+
const status = await safeWriteFileAtomic(
|
|
7396
|
+
kernelPath,
|
|
7397
|
+
RESULT_KERNEL,
|
|
7398
|
+
config,
|
|
7399
|
+
report,
|
|
7400
|
+
false
|
|
7401
|
+
);
|
|
7402
|
+
if (status === "created" || status === "updated") {
|
|
7403
|
+
result.created.push(kernelPath);
|
|
7404
|
+
result.totalOps += 1;
|
|
7405
|
+
} else {
|
|
7406
|
+
result.skipped.push(kernelPath);
|
|
7407
|
+
}
|
|
7408
|
+
return result;
|
|
7409
|
+
}
|
|
6674
7410
|
var execAsync = promisify(exec);
|
|
6675
7411
|
var MAX_BUFFER = 1024 * 1024 * 10;
|
|
6676
7412
|
async function ensureDependenciesBuilt(config) {
|
|
@@ -6698,7 +7434,7 @@ async function ensureDependenciesBuilt(config) {
|
|
|
6698
7434
|
}
|
|
6699
7435
|
|
|
6700
7436
|
// src/sync-engine-helpers.ts
|
|
6701
|
-
function
|
|
7437
|
+
function mergeResult2(dest, src) {
|
|
6702
7438
|
dest.created.push(...src.created);
|
|
6703
7439
|
dest.updated.push(...src.updated);
|
|
6704
7440
|
dest.skipped.push(...src.skipped);
|
|
@@ -6850,12 +7586,23 @@ var IndexManifestSchema = external_exports.object({
|
|
|
6850
7586
|
message: "Context plane does not match file path subdirectory",
|
|
6851
7587
|
path: ["bounded_contexts"]
|
|
6852
7588
|
});
|
|
7589
|
+
var CrossContextEdgeSchema = external_exports.object({
|
|
7590
|
+
consumer: external_exports.string(),
|
|
7591
|
+
provider: external_exports.string(),
|
|
7592
|
+
transport: external_exports.enum(["event-bus", "network"]),
|
|
7593
|
+
events: external_exports.array(external_exports.string()).optional(),
|
|
7594
|
+
operations: external_exports.array(external_exports.string()).optional(),
|
|
7595
|
+
integrationPattern: external_exports.enum(["open-host", "acl"]).optional()
|
|
7596
|
+
});
|
|
6853
7597
|
var ManifestSchema = external_exports.object({
|
|
6854
7598
|
version: external_exports.string().optional(),
|
|
6855
7599
|
description: external_exports.string().optional(),
|
|
6856
7600
|
system: external_exports.string().optional(),
|
|
6857
7601
|
scope: external_exports.string().optional(),
|
|
6858
7602
|
architecture: external_exports.string().optional(),
|
|
7603
|
+
// The wizard records the chosen workspace template (e.g. "strict-enterprise")
|
|
7604
|
+
// alongside `architecture`; persisted into .architecture/manifest.yaml.
|
|
7605
|
+
workspaceTemplate: external_exports.string().optional(),
|
|
6859
7606
|
planes: external_exports.record(external_exports.array(external_exports.string())).optional(),
|
|
6860
7607
|
monorepo: external_exports.record(external_exports.unknown()).optional(),
|
|
6861
7608
|
generator: external_exports.record(external_exports.unknown()).optional(),
|
|
@@ -6870,6 +7617,7 @@ var ManifestSchema = external_exports.object({
|
|
|
6870
7617
|
})).optional(),
|
|
6871
7618
|
bounded_contexts: external_exports.array(BoundedContextSchema),
|
|
6872
7619
|
apps: external_exports.array(AppSchema).optional(),
|
|
7620
|
+
cross_context: external_exports.array(CrossContextEdgeSchema).optional(),
|
|
6873
7621
|
context_mappings: external_exports.array(external_exports.object({
|
|
6874
7622
|
upstream: external_exports.string(),
|
|
6875
7623
|
downstream: external_exports.string(),
|
|
@@ -6938,7 +7686,15 @@ var BoundedContextSchema2 = external_exports.object({
|
|
|
6938
7686
|
id: external_exports.string(),
|
|
6939
7687
|
name: external_exports.string().min(1, "Please enter a name for this bounded context (e.g., 'UserService', 'OrderProcessing')"),
|
|
6940
7688
|
description: external_exports.string().optional(),
|
|
6941
|
-
|
|
7689
|
+
// ADR-0041: `infrastructureTarget` (API backend) and `uiFramework` (below)
|
|
7690
|
+
// are PROJECT-LEVEL choices managed by the wizard's Applications step, which
|
|
7691
|
+
// fans a single selection out to every context. They persist per-context (the
|
|
7692
|
+
// source of truth `deriveApps` reads), but are NOT direct per-context input —
|
|
7693
|
+
// do not re-add per-context UI/API editing without revisiting ADR-0041.
|
|
7694
|
+
// `"none"` = the project opts out of a separate API backend (UI-only, e.g. a
|
|
7695
|
+
// Next.js app with built-in routes); `deriveApps` then emits no `api` app.
|
|
7696
|
+
// Distinct from `undefined` (legacy/unset → defaults to the preset).
|
|
7697
|
+
infrastructureTarget: external_exports.enum(["nestjs", "express", "serverless", "plain-ts", "nitro", "none"]).optional(),
|
|
6942
7698
|
coreDomainEntities: external_exports.array(external_exports.string()).default([]),
|
|
6943
7699
|
valueObjects: external_exports.array(external_exports.string()).default([]),
|
|
6944
7700
|
domainEvents: external_exports.array(external_exports.string()).default([]),
|
|
@@ -7337,11 +8093,11 @@ var SyncEngine = class {
|
|
|
7337
8093
|
if (this.partialConfig.mode === "self-regen") {
|
|
7338
8094
|
await reapLegacyFolders(moduleDir, config, this.report);
|
|
7339
8095
|
}
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
8096
|
+
mergeResult2(barrels, barrelResult);
|
|
8097
|
+
mergeResult2(pkgs, pkgResult);
|
|
8098
|
+
mergeResult2(tsconfigs, tsResult);
|
|
8099
|
+
mergeResult2(eslint, eslintResult);
|
|
8100
|
+
mergeResult2(stubs, stubResult);
|
|
7345
8101
|
}
|
|
7346
8102
|
return {
|
|
7347
8103
|
rootFiles: createEmptyResult(),
|
|
@@ -7442,6 +8198,14 @@ var SyncEngine = class {
|
|
|
7442
8198
|
const { pkgs, tsconfigs, eslint, stubs } = coreResults;
|
|
7443
8199
|
const firstPassBarrels = coreResults.barrels;
|
|
7444
8200
|
const appsResult = await generateApps(this.fullConfig, this.report);
|
|
8201
|
+
const crossContextResult = await generateCrossContext(
|
|
8202
|
+
this.fullConfig,
|
|
8203
|
+
this.report
|
|
8204
|
+
);
|
|
8205
|
+
const sharedKernelResult = await generateSharedKernel(
|
|
8206
|
+
this.fullConfig,
|
|
8207
|
+
this.report
|
|
8208
|
+
);
|
|
7445
8209
|
const secondPassBarrels = createEmptyResult();
|
|
7446
8210
|
const modules = this.fullConfig.manifest.bounded_contexts ?? [];
|
|
7447
8211
|
for (const module of modules) {
|
|
@@ -7455,10 +8219,10 @@ var SyncEngine = class {
|
|
|
7455
8219
|
this.fullConfig,
|
|
7456
8220
|
this.report
|
|
7457
8221
|
);
|
|
7458
|
-
|
|
8222
|
+
mergeResult2(secondPassBarrels, pass2);
|
|
7459
8223
|
}
|
|
7460
8224
|
const barrels = mergeBarrelPasses(firstPassBarrels, secondPassBarrels);
|
|
7461
|
-
const totalOps = rootFilesResult.totalOps + archFilesResult.totalOps + layerResult.totalOps + barrels.totalOps + pkgs.totalOps + tsconfigs.totalOps + eslint.totalOps + stubs.totalOps + appsResult.totalOps;
|
|
8225
|
+
const totalOps = rootFilesResult.totalOps + archFilesResult.totalOps + layerResult.totalOps + barrels.totalOps + pkgs.totalOps + tsconfigs.totalOps + eslint.totalOps + stubs.totalOps + appsResult.totalOps + crossContextResult.totalOps + sharedKernelResult.totalOps;
|
|
7462
8226
|
if (mode === "self-regen") {
|
|
7463
8227
|
await runArchLinter(this.fullConfig);
|
|
7464
8228
|
await this.report.writeReport(this.fullConfig);
|
|
@@ -7484,6 +8248,12 @@ var SyncEngine = class {
|
|
|
7484
8248
|
logger.info(
|
|
7485
8249
|
`• Barrels : ${barrels.created.length} created, ${barrels.updated.length} updated, ${barrels.skipped.length} skipped`
|
|
7486
8250
|
);
|
|
8251
|
+
logger.info(
|
|
8252
|
+
`• CrossContext : ${crossContextResult.created.length} created, ${crossContextResult.updated.length} updated, ${crossContextResult.skipped.length} skipped`
|
|
8253
|
+
);
|
|
8254
|
+
logger.info(
|
|
8255
|
+
`• SharedKernel : ${sharedKernelResult.created.length} created, ${sharedKernelResult.updated.length} updated, ${sharedKernelResult.skipped.length} skipped`
|
|
8256
|
+
);
|
|
7487
8257
|
logger.info(
|
|
7488
8258
|
`• package.json : ${pkgs.created.length} created, ${pkgs.updated.length} updated, ${pkgs.skipped.length} skipped`
|
|
7489
8259
|
);
|
|
@@ -7606,6 +8376,14 @@ function parseArgs(rawArgs) {
|
|
|
7606
8376
|
case "--allow-dirty":
|
|
7607
8377
|
flags.allowDirty = true;
|
|
7608
8378
|
break;
|
|
8379
|
+
case "--only": {
|
|
8380
|
+
const patterns = [];
|
|
8381
|
+
while (i + 1 < args.length && !args[i + 1].startsWith("-")) {
|
|
8382
|
+
patterns.push(args[++i]);
|
|
8383
|
+
}
|
|
8384
|
+
flags.only = [...flags.only ?? [], ...patterns];
|
|
8385
|
+
break;
|
|
8386
|
+
}
|
|
7609
8387
|
default:
|
|
7610
8388
|
if (arg.startsWith("-")) {
|
|
7611
8389
|
flags.logger.warn(`Unknown flag ignored: ${arg}`);
|
|
@@ -8053,6 +8831,6 @@ async function saveManifest(workspaceRoot, manifest) {
|
|
|
8053
8831
|
}
|
|
8054
8832
|
}
|
|
8055
8833
|
|
|
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 };
|
|
8834
|
+
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, safeWriteFile, safeWriteFileAtomic, saveManifest, validateManifest2 as validateManifest };
|
|
8057
8835
|
//# sourceMappingURL=index.js.map
|
|
8058
8836
|
//# sourceMappingURL=index.js.map
|