@xrystal/core 3.55.8 → 3.55.10

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.
Files changed (35) hide show
  1. package/package.json +1 -1
  2. package/x/bin/commands/project-info.mjs +13 -0
  3. package/x/bin/commands/projects.mjs +56 -11
  4. package/x/bin/commands/sync.mjs +21 -7
  5. package/x/bin/commands/watch.mjs +2 -2
  6. package/x/bin/helpers/.generated/.generated-from +1 -1
  7. package/x/bin/helpers/.generated/tmp-schema.mjs +42 -9
  8. package/x/bin/helpers/.generated/{xrystal-home-registry.mjs → user-home-registry.mjs} +150 -43
  9. package/x/bin/helpers/.generated/workspace.mjs +338 -50
  10. package/x/bin/helpers/cli-enums.mjs +1 -0
  11. package/x/bin/helpers/cli-i18n.mjs +14 -0
  12. package/x/bin/helpers/create-target.mjs +5 -1
  13. package/x/bin/helpers/project-artifacts.mjs +2 -2
  14. package/x/bin/helpers/project-context.mjs +16 -4
  15. package/x/bin/helpers/registry-display.mjs +30 -0
  16. package/x/bin/helpers/workspace-heal.mjs +21 -5
  17. package/x/bin/helpers/workspace-resolve.mjs +8 -0
  18. package/x/bin/helpers/workspace-tmp.mjs +17 -7
  19. package/x/bin/helpers/xrystal-config.mjs +4 -4
  20. package/x/bin/helpers/xrystal-registry.mjs +4 -4
  21. package/x/bin/helpers/xrystal-watch-daemon.mjs +3 -3
  22. package/x/bin/helpers/xrystal-watch-service.mjs +2 -2
  23. package/x/bin/helpers/xrystal-watch-spawn.mjs +3 -3
  24. package/x/dist/utils/helpers/tmp/index.d.ts +1 -1
  25. package/x/dist/utils/helpers/tmp/index.js +1 -1
  26. package/x/dist/utils/helpers/tmp/loader-boot-plan.js +7 -0
  27. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +2 -0
  28. package/x/dist/utils/helpers/tmp/tmp-schema.js +43 -9
  29. package/x/dist/utils/helpers/{xrystal-home → user-home}/registry.d.ts +11 -10
  30. package/x/dist/utils/helpers/{xrystal-home → user-home}/registry.js +11 -10
  31. package/x/dist/utils/helpers/workspace/index.d.ts +48 -2
  32. package/x/dist/utils/helpers/workspace/index.js +365 -48
  33. package/x/dist/utils/models/enums/index.d.ts +4 -2
  34. package/x/dist/utils/models/enums/index.js +3 -1
  35. package/x/tmp.yml +2 -3
@@ -1,6 +1,7 @@
1
1
  // source/utils/helpers/workspace/index.ts
2
2
  import fs2 from "node:fs";
3
3
  import path4 from "node:path";
4
+ import yaml2 from "yaml";
4
5
 
5
6
  // source/utils/models/enums/index.ts
6
7
  var GlobalTypeEnum;
@@ -8,6 +9,7 @@ var GlobalTypeEnum;
8
9
  GlobalTypeEnum2["WORKSPACE"] = "workspace";
9
10
  GlobalTypeEnum2["API_SERVICE"] = "api-service";
10
11
  GlobalTypeEnum2["FRONTEND"] = "frontend";
12
+ GlobalTypeEnum2["CORE_LIBRARY"] = "core-library";
11
13
  })(GlobalTypeEnum ||= {});
12
14
 
13
15
  // source/utils/constants/index.ts
@@ -215,6 +217,8 @@ function normalizeGlobalType(value) {
215
217
  return "api-service" /* API_SERVICE */;
216
218
  if (raw === "frontend" /* FRONTEND */)
217
219
  return "frontend" /* FRONTEND */;
220
+ if (raw === "core-library" /* CORE_LIBRARY */)
221
+ return "core-library" /* CORE_LIBRARY */;
218
222
  throw new Error(`${defaults_default.packageName}: configs.global.type must be one of ${Object.values(GlobalTypeEnum).join("|")} (got "${String(value)}")`);
219
223
  }
220
224
 
@@ -257,9 +261,9 @@ function readTmpFile(filePath) {
257
261
  return out;
258
262
  }
259
263
  function parseFolderStructure(text) {
260
- const fsBlock = text.match(/folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? "";
264
+ const fsBlock = text.match(/(?:^|\n)[ \t]*slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? text.match(/(?:^|\n)[ \t]*folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? "";
261
265
  if (/^[ \t]+admin:/m.test(fsBlock)) {
262
- throw new Error("configs.folder-structure.admin removed — put admin panels under web/ (e.g. web/admin-ui)");
266
+ throw new Error("configs.slots.admin removed — put admin panels under web/ (e.g. web/admin-ui)");
263
267
  }
264
268
  const readSlot = (key) => {
265
269
  const scalar = fsBlock.match(new RegExp(`^[ \\t]+${key}:\\s*(.+?)(?:\\s+#.*)?$`, "m"));
@@ -273,13 +277,38 @@ function parseFolderStructure(text) {
273
277
  ["mobile" /* MOBILE */]: readSlot("mobile" /* MOBILE */)
274
278
  };
275
279
  }
280
+ function allowedGlobalTypesForSlot(slot) {
281
+ if (slot === "api" /* API */)
282
+ return ["api-service" /* API_SERVICE */];
283
+ if (slot === "web" /* WEB */ || slot === "mobile" /* MOBILE */) {
284
+ return ["frontend" /* FRONTEND */];
285
+ }
286
+ return [];
287
+ }
276
288
  function workspaceDiscoverySlots(fsMap) {
277
289
  return [
278
- { slot: "api" /* API */, folder: fsMap["api" /* API */], frontendOnly: false },
279
- { slot: "web" /* WEB */, folder: fsMap["web" /* WEB */], frontendOnly: true },
280
- { slot: "mobile" /* MOBILE */, folder: fsMap["mobile" /* MOBILE */], frontendOnly: true }
290
+ {
291
+ slot: "api" /* API */,
292
+ folder: fsMap["api" /* API */],
293
+ allowedTypes: allowedGlobalTypesForSlot("api" /* API */)
294
+ },
295
+ {
296
+ slot: "web" /* WEB */,
297
+ folder: fsMap["web" /* WEB */],
298
+ allowedTypes: allowedGlobalTypesForSlot("web" /* WEB */)
299
+ },
300
+ {
301
+ slot: "mobile" /* MOBILE */,
302
+ folder: fsMap["mobile" /* MOBILE */],
303
+ allowedTypes: allowedGlobalTypesForSlot("mobile" /* MOBILE */)
304
+ }
281
305
  ];
282
306
  }
307
+ function formatSlotMismatch(mismatch) {
308
+ const expected = mismatch.expectedTypes.join(" | ");
309
+ const got = mismatch.globalType?.trim() || "(missing global.type)";
310
+ return `${mismatch.projectName}: ${got} in ${mismatch.slot}/ slot — expected ${expected}`;
311
+ }
283
312
  function entryName(meta) {
284
313
  const project = (meta.projectName ?? "").trim();
285
314
  return project || null;
@@ -298,13 +327,40 @@ function entryType(meta, slot) {
298
327
  return null;
299
328
  }
300
329
  function findWorkspaceRoot(startDir = process.cwd()) {
301
- let cur = path4.resolve(startDir);
330
+ return findWorkspaceAnchor(startDir)?.root ?? null;
331
+ }
332
+ function resolveWorkspaceOuterTmp(workspaceRoot) {
333
+ const root = path4.resolve(workspaceRoot);
334
+ const anchor = findWorkspaceAnchor(root);
335
+ if (!anchor)
336
+ return null;
337
+ if (path4.resolve(anchor.root) !== root)
338
+ return null;
339
+ return anchor.tmpPath;
340
+ }
341
+ function findWorkspaceAnchor(startDir = process.cwd()) {
342
+ const start = path4.resolve(startDir);
343
+ let cur = start;
302
344
  for (;; ) {
303
- const candidate = path4.join(cur, TMP_FILE);
304
- if (fs2.existsSync(candidate)) {
305
- const meta = readTmpFile(candidate);
306
- if (meta.globalType === "workspace" /* WORKSPACE */)
307
- return cur;
345
+ for (const candidate of listShallowTmpCandidates(cur)) {
346
+ let meta;
347
+ try {
348
+ meta = readTmpFile(candidate);
349
+ } catch {
350
+ meta = readBrokenWorkspaceTmpMeta(candidate);
351
+ }
352
+ if (!meta)
353
+ continue;
354
+ if (meta.globalType !== "workspace" /* WORKSPACE */)
355
+ continue;
356
+ try {
357
+ const root = path4.resolve(resolveRepoRootFromTmpMeta(candidate, meta));
358
+ if (start === root || start.startsWith(`${root}${path4.sep}`)) {
359
+ return { root, tmpPath: path4.resolve(candidate), meta };
360
+ }
361
+ } catch {
362
+ continue;
363
+ }
308
364
  }
309
365
  const parent = path4.dirname(cur);
310
366
  if (parent === cur)
@@ -313,6 +369,73 @@ function findWorkspaceRoot(startDir = process.cwd()) {
313
369
  }
314
370
  return null;
315
371
  }
372
+ function readBrokenWorkspaceTmpMeta(filePath) {
373
+ if (!fs2.existsSync(filePath))
374
+ return null;
375
+ let text;
376
+ try {
377
+ text = fs2.readFileSync(filePath, "utf8");
378
+ } catch {
379
+ return null;
380
+ }
381
+ const typeMatch = text.match(/global:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+type:\s*(.+?)\s*(?:#.*)?$/m);
382
+ if (!typeMatch || parseScalar(typeMatch[1]) !== "workspace" /* WORKSPACE */)
383
+ return null;
384
+ const out = {
385
+ path: filePath,
386
+ globalType: "workspace" /* WORKSPACE */,
387
+ folderStructure: { ...DEFAULT_FOLDER_STRUCTURE }
388
+ };
389
+ const projectMatch = text.match(/^project:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+name:\s*(.+?)\s*(?:#.*)?$/m) ?? text.match(/^project:\s*\n[ \t]+name:\s*(.+?)\s*(?:#.*)?$/m);
390
+ if (projectMatch)
391
+ out.projectName = parseScalar(projectMatch[1]);
392
+ const rootBlock = text.match(/paths:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+root:\s*(.+?)\s*(?:#.*)?$/m);
393
+ if (rootBlock)
394
+ out.pathsRoot = parseScalar(rootBlock[1]);
395
+ const tmpBlock = text.match(/paths:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+tmp:\s*(.+?)\s*(?:#.*)?$/m);
396
+ if (tmpBlock)
397
+ out.pathsTmp = parseScalar(tmpBlock[1]);
398
+ const fsBlock = text.match(/(?:^|\n)[ \t]*slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? text.match(/(?:^|\n)[ \t]*folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? "";
399
+ for (const slot of ["api" /* API */, "web" /* WEB */, "mobile" /* MOBILE */]) {
400
+ const scalar = fsBlock.match(new RegExp(`^[ \\t]+${slot}:\\s*(.+?)(?:\\s+#.*)?$`, "m"));
401
+ if (scalar)
402
+ out.folderStructure[slot] = parseScalar(scalar[1]);
403
+ }
404
+ return out;
405
+ }
406
+ function readWorkspaceTmpMeta(filePath) {
407
+ try {
408
+ return readTmpFile(filePath);
409
+ } catch {
410
+ const broken = readBrokenWorkspaceTmpMeta(filePath);
411
+ if (broken)
412
+ return broken;
413
+ throw new Error(`Unable to read workspace tmp: ${filePath}`);
414
+ }
415
+ }
416
+ function listShallowTmpCandidates(dir) {
417
+ const out = [];
418
+ const direct = path4.join(dir, TMP_FILE);
419
+ if (fs2.existsSync(direct))
420
+ out.push(direct);
421
+ let entries;
422
+ try {
423
+ entries = fs2.readdirSync(dir, { withFileTypes: true });
424
+ } catch {
425
+ return out;
426
+ }
427
+ for (const entry of entries) {
428
+ const full = path4.join(dir, entry.name);
429
+ if (!isTraversableDir(entry, full))
430
+ continue;
431
+ if (SKIP_DIRS.has(entry.name) || entry.name.startsWith("."))
432
+ continue;
433
+ const nested = path4.join(full, TMP_FILE);
434
+ if (fs2.existsSync(nested))
435
+ out.push(nested);
436
+ }
437
+ return out;
438
+ }
316
439
  function isTraversableDir(entry, fullPath) {
317
440
  if (entry.isDirectory())
318
441
  return true;
@@ -353,39 +476,72 @@ function walkTmpUnder(rootDir) {
353
476
  return found;
354
477
  }
355
478
  function stripDotSlash(value) {
356
- return value.replace(/^\.\//, "");
357
- }
358
- function repoRootFromTmp(tmpPath, meta) {
359
- const abs = tmpPath.replace(/\\/g, "/");
360
- const rootFolder = stripDotSlash(meta.pathsRoot ?? "./x");
361
- const tmpName = stripDotSlash(meta.pathsTmp ?? "tmp.yml");
362
- const rel = `${rootFolder}/${tmpName}`.replace(/\/+/g, "/");
363
- if (abs.endsWith(`/${rel}`)) {
364
- return abs.slice(0, -(rel.length + 1));
479
+ return value.replace(/^\.\//, "").replace(/\/$/, "");
480
+ }
481
+ function buildRepoTmpRelPath(meta) {
482
+ const isWorkspace = meta.globalType === "workspace" /* WORKSPACE */;
483
+ const rootFolder = stripDotSlash(meta.pathsRoot?.trim() || (isWorkspace ? "." : packageDefaults.packageRootFolder));
484
+ const tmpName = stripDotSlash(meta.pathsTmp?.trim() || TMP_FILE) || TMP_FILE;
485
+ if (!rootFolder || rootFolder === ".")
486
+ return tmpName;
487
+ return `${rootFolder}/${tmpName}`.replace(/\/+/g, "/");
488
+ }
489
+ function resolveRepoRootFromTmpMeta(tmpPath, meta) {
490
+ const abs = path4.resolve(tmpPath).replace(/\\/g, "/");
491
+ const rel = buildRepoTmpRelPath(meta);
492
+ if (abs === rel || abs.endsWith(`/${rel}`)) {
493
+ const root = abs === rel ? "" : abs.slice(0, -(rel.length + 1));
494
+ return root || path4.dirname(abs);
365
495
  }
366
496
  throw new Error(`tmp path mismatch: expected */${rel}, got ${abs}`);
367
497
  }
368
- function findEntries(workspaceRoot) {
369
- const wsMeta = readTmpFile(path4.join(workspaceRoot, TMP_FILE));
498
+ function scanWorkspaceProjects(workspaceRoot) {
499
+ const outerTmp = resolveWorkspaceOuterTmp(workspaceRoot);
500
+ const wsMeta = readWorkspaceTmpMeta(outerTmp ?? path4.join(workspaceRoot, TMP_FILE));
370
501
  const fsMap = wsMeta.folderStructure;
371
502
  const entries = [];
503
+ const mismatches = [];
372
504
  const seen = new Set;
373
- for (const { slot, folder: folderRel, frontendOnly } of workspaceDiscoverySlots(fsMap)) {
505
+ const seenMismatch = new Set;
506
+ const outerResolved = outerTmp ? path4.resolve(outerTmp) : null;
507
+ for (const { slot, folder: folderRel, allowedTypes } of workspaceDiscoverySlots(fsMap)) {
374
508
  const folder = path4.join(workspaceRoot, folderRel);
375
509
  for (const tmpPath of walkTmpUnder(folder)) {
376
- if (path4.resolve(tmpPath) === path4.join(workspaceRoot, TMP_FILE))
510
+ if (outerResolved && path4.resolve(tmpPath) === outerResolved)
377
511
  continue;
378
512
  const meta = readTmpFile(tmpPath);
379
513
  const kind = entryType(meta, slot);
380
514
  if (kind === "workspace" /* WORKSPACE */)
381
515
  continue;
382
- if (frontendOnly && kind !== "frontend" /* FRONTEND */)
383
- continue;
384
- if (kind !== "api-service" /* API_SERVICE */ && kind !== "frontend" /* FRONTEND */)
385
- continue;
386
516
  const name = entryName(meta);
517
+ const explicitType = (meta.globalType ?? "").trim() || null;
518
+ const projectPath = (() => {
519
+ try {
520
+ return resolveRepoRootFromTmpMeta(tmpPath, meta);
521
+ } catch {
522
+ return path4.dirname(tmpPath);
523
+ }
524
+ })();
387
525
  if (!name)
388
526
  continue;
527
+ if (kind == null || !allowedTypes.includes(kind)) {
528
+ const mismatchKey = `${slot}:${tmpPath}`;
529
+ if (!seenMismatch.has(mismatchKey)) {
530
+ seenMismatch.add(mismatchKey);
531
+ mismatches.push({
532
+ slot,
533
+ slotFolder: folderRel,
534
+ projectName: name,
535
+ globalType: explicitType,
536
+ expectedTypes: allowedTypes,
537
+ tmp: tmpPath,
538
+ projectPath
539
+ });
540
+ }
541
+ continue;
542
+ }
543
+ if (kind !== "api-service" /* API_SERVICE */ && kind !== "frontend" /* FRONTEND */)
544
+ continue;
389
545
  const key = `${kind}:${name}`;
390
546
  if (seen.has(key))
391
547
  continue;
@@ -393,14 +549,22 @@ function findEntries(workspaceRoot) {
393
549
  entries.push({
394
550
  name,
395
551
  type: kind,
396
- path: repoRootFromTmp(tmpPath, meta),
552
+ path: projectPath,
397
553
  tmp: tmpPath,
398
554
  slot,
399
555
  cluster: meta.clusterDeployment ?? meta.projectName
400
556
  });
401
557
  }
402
558
  }
403
- return entries.sort((a, b) => a.type === b.type ? a.name.localeCompare(b.name) : a.type.localeCompare(b.type));
559
+ const sortEntries = (a, b) => a.type === b.type ? a.name.localeCompare(b.name) : a.type.localeCompare(b.type);
560
+ mismatches.sort((a, b) => a.slot.localeCompare(b.slot) || a.projectName.localeCompare(b.projectName) || a.tmp.localeCompare(b.tmp));
561
+ return {
562
+ entries: entries.sort(sortEntries),
563
+ mismatches
564
+ };
565
+ }
566
+ function findEntries(workspaceRoot) {
567
+ return scanWorkspaceProjects(workspaceRoot).entries;
404
568
  }
405
569
  function findApiServices(workspaceRoot) {
406
570
  return findEntries(workspaceRoot).filter((e) => e.type === "api-service" /* API_SERVICE */);
@@ -410,17 +574,23 @@ function resolveEntryPath(workspaceRoot, name) {
410
574
  return hit?.path ?? null;
411
575
  }
412
576
  function workspaceProjectName(workspaceRoot) {
413
- const meta = readTmpFile(path4.join(workspaceRoot, TMP_FILE));
577
+ const tmpPath = resolveWorkspaceOuterTmp(workspaceRoot);
578
+ if (!tmpPath)
579
+ return path4.basename(workspaceRoot);
580
+ const meta = readTmpFile(tmpPath);
414
581
  return meta.projectName?.trim() || path4.basename(workspaceRoot);
415
582
  }
416
583
  function readWorkspaceGlobalTmp(workspaceRoot) {
417
- const text = fs2.readFileSync(path4.join(workspaceRoot, TMP_FILE), "utf8");
584
+ const tmpPath = resolveWorkspaceOuterTmp(workspaceRoot);
585
+ if (!tmpPath)
586
+ return {};
587
+ const text = fs2.readFileSync(tmpPath, "utf8");
418
588
  const match = text.match(/options:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+fileWatchIntervalMs:\s*(\d+)/m) ?? text.match(/fileWatchIntervalMs:\s*(\d+)/);
419
589
  return match ? { fileWatchIntervalMs: Number(match[1]) } : {};
420
590
  }
421
591
  function ensureWorkspaceSlotDirs(workspaceRoot) {
422
- const tmpPath = path4.join(workspaceRoot, TMP_FILE);
423
- if (!fs2.existsSync(tmpPath))
592
+ const tmpPath = resolveWorkspaceOuterTmp(workspaceRoot);
593
+ if (!tmpPath)
424
594
  return [];
425
595
  const meta = readTmpFile(tmpPath);
426
596
  const created = [];
@@ -433,22 +603,127 @@ function ensureWorkspaceSlotDirs(workspaceRoot) {
433
603
  }
434
604
  return created;
435
605
  }
436
- function healWorkspaceOuterTmpOptions(workspaceRoot) {
437
- const tmpPath = path4.join(workspaceRoot, TMP_FILE);
438
- if (!fs2.existsSync(tmpPath))
439
- return false;
440
- const text = fs2.readFileSync(tmpPath, "utf8");
441
- if (/fileWatchIntervalMs:\s*\d+/m.test(text))
442
- return false;
606
+ function isPlainObject(value) {
607
+ return typeof value === "object" && value !== null && !Array.isArray(value);
608
+ }
609
+ function healWorkspaceOuterTmpStructure(workspaceRoot) {
610
+ const resolvedRoot = path4.resolve(workspaceRoot);
611
+ const tmpPath = resolveWorkspaceOuterTmp(resolvedRoot) ?? (fs2.existsSync(path4.join(resolvedRoot, TMP_FILE)) ? path4.join(resolvedRoot, TMP_FILE) : null);
612
+ if (!tmpPath || !fs2.existsSync(tmpPath))
613
+ return { changed: false, notes: [] };
614
+ const raw = fs2.readFileSync(tmpPath, "utf8");
615
+ let doc;
616
+ try {
617
+ const parsed = yaml2.parse(raw);
618
+ doc = isPlainObject(parsed) ? parsed : {};
619
+ } catch {
620
+ return { changed: false, notes: [] };
621
+ }
622
+ const notes = [];
443
623
  const defaultMs = packageDefaults.tmpWatchDefaults.intervalMs;
444
- const insertBlock = ` options:
445
- fileWatchIntervalMs: ${defaultMs}
446
- `;
447
- const patched = text.replace(/(configs:\s*\n\s+global:\s*\n\s+type:\s*workspace\s*\n)/m, `$1${insertBlock}`);
448
- if (patched === text)
449
- return false;
450
- fs2.writeFileSync(tmpPath, patched);
451
- return true;
624
+ const schemaVersion = packageDefaults.tmpSchemaVersion ?? 1;
625
+ if (!isPlainObject(doc.project)) {
626
+ doc.project = { name: path4.basename(workspaceRoot) };
627
+ notes.push("project");
628
+ } else if (typeof doc.project.name !== "string" || !doc.project.name.trim()) {
629
+ doc.project.name = path4.basename(workspaceRoot);
630
+ notes.push("project.name");
631
+ }
632
+ if (!isPlainObject(doc.configs)) {
633
+ doc.configs = {};
634
+ notes.push("configs");
635
+ }
636
+ const configs = doc.configs;
637
+ if (!isPlainObject(configs.global)) {
638
+ configs.global = {};
639
+ notes.push("configs.global");
640
+ }
641
+ const global = configs.global;
642
+ if (global.type !== "workspace" /* WORKSPACE */) {
643
+ global.type = "workspace" /* WORKSPACE */;
644
+ notes.push("global.type");
645
+ }
646
+ if (!isPlainObject(global.paths)) {
647
+ global.paths = { root: ".", tmp: "tmp.yml" };
648
+ notes.push("global.paths");
649
+ } else {
650
+ const paths = global.paths;
651
+ if (typeof paths.root !== "string" || !paths.root.trim()) {
652
+ paths.root = ".";
653
+ notes.push("global.paths.root");
654
+ }
655
+ if (typeof paths.tmp !== "string" || !paths.tmp.trim()) {
656
+ paths.tmp = "tmp.yml";
657
+ notes.push("global.paths.tmp");
658
+ }
659
+ }
660
+ if (!isPlainObject(global.options)) {
661
+ global.options = { fileWatchIntervalMs: defaultMs };
662
+ notes.push("global.options");
663
+ } else {
664
+ const options = global.options;
665
+ if (options.fileWatchIntervalMs == null || options.fileWatchIntervalMs === "") {
666
+ options.fileWatchIntervalMs = defaultMs;
667
+ notes.push("global.options.fileWatchIntervalMs");
668
+ }
669
+ }
670
+ const slotsKey = "slots";
671
+ const legacyKey = "folder-structure";
672
+ let slotsMap;
673
+ if (isPlainObject(configs[slotsKey])) {
674
+ slotsMap = configs[slotsKey];
675
+ } else if (isPlainObject(configs[legacyKey])) {
676
+ slotsMap = { ...configs[legacyKey] };
677
+ configs[slotsKey] = slotsMap;
678
+ delete configs[legacyKey];
679
+ notes.push("folder-structure → slots");
680
+ } else {
681
+ slotsMap = { ...DEFAULT_FOLDER_STRUCTURE };
682
+ configs[slotsKey] = slotsMap;
683
+ notes.push("slots");
684
+ }
685
+ if ("admin" in slotsMap) {
686
+ delete slotsMap.admin;
687
+ notes.push("slots.admin removed");
688
+ }
689
+ for (const slot of [
690
+ "api" /* API */,
691
+ "web" /* WEB */,
692
+ "mobile" /* MOBILE */
693
+ ]) {
694
+ const value = slotsMap[slot];
695
+ if (typeof value !== "string" || !value.trim()) {
696
+ slotsMap[slot] = DEFAULT_FOLDER_STRUCTURE[slot];
697
+ notes.push(`slots.${slot}`);
698
+ }
699
+ }
700
+ if (legacyKey in configs && slotsKey in configs) {
701
+ delete configs[legacyKey];
702
+ if (!notes.includes("folder-structure → slots")) {
703
+ notes.push("folder-structure removed");
704
+ }
705
+ }
706
+ if (!isPlainObject(doc.end)) {
707
+ doc.end = { version: schemaVersion };
708
+ notes.push("end");
709
+ } else {
710
+ const end = doc.end;
711
+ if (end.version == null || end.version === "") {
712
+ end.version = schemaVersion;
713
+ notes.push("end.version");
714
+ } else if (typeof end.version === "string" && /^\d+$/.test(end.version.trim())) {
715
+ end.version = Number(end.version);
716
+ notes.push("end.version type");
717
+ }
718
+ }
719
+ if (notes.length === 0)
720
+ return { changed: false, notes: [] };
721
+ fs2.writeFileSync(tmpPath, `${yaml2.stringify(doc).trimEnd()}
722
+ `);
723
+ return { changed: true, notes };
724
+ }
725
+ function healWorkspaceOuterTmpOptions(workspaceRoot) {
726
+ return healWorkspaceOuterTmpStructure(workspaceRoot).changed;
452
727
  }
453
728
  var readWorkspaceCoreTmp = readWorkspaceGlobalTmp;
454
729
  function workspaceTmpTemplate(projectName) {
@@ -458,9 +733,12 @@ function workspaceTmpTemplate(projectName) {
458
733
  configs:
459
734
  global:
460
735
  type: workspace
736
+ paths:
737
+ root: .
738
+ tmp: tmp.yml
461
739
  options:
462
740
  fileWatchIntervalMs: 500
463
- folder-structure:
741
+ slots:
464
742
  api: api
465
743
  web: web
466
744
  mobile: mobile
@@ -475,19 +753,29 @@ export {
475
753
  workspaceTmpTemplate,
476
754
  workspaceProjectName,
477
755
  workspaceDiscoverySlots,
756
+ scanWorkspaceProjects,
757
+ resolveWorkspaceOuterTmp,
758
+ resolveRepoRootFromTmpMeta,
478
759
  resolveEntryPath,
760
+ readWorkspaceTmpMeta,
479
761
  readWorkspaceGlobalTmp,
480
762
  readWorkspaceCoreTmp,
481
763
  readTmpFile,
764
+ readBrokenWorkspaceTmpMeta,
482
765
  parseFolderStructure,
483
766
  normalizeGlobalType,
767
+ healWorkspaceOuterTmpStructure,
484
768
  healWorkspaceOuterTmpOptions,
769
+ formatSlotMismatch,
485
770
  findWorkspaceRoot,
771
+ findWorkspaceAnchor,
486
772
  findEntries,
487
773
  findApiServices,
488
774
  entryType,
489
775
  entryName,
490
776
  ensureWorkspaceSlotDirs,
777
+ buildRepoTmpRelPath,
778
+ allowedGlobalTypesForSlot,
491
779
  TMP_FILE,
492
780
  SKIP_DIRS,
493
781
  DEFAULT_FOLDER_STRUCTURE
@@ -4,6 +4,7 @@ export const GlobalTypeEnum = {
4
4
  WORKSPACE: 'workspace',
5
5
  API_SERVICE: 'api-service',
6
6
  FRONTEND: 'frontend',
7
+ CORE_LIBRARY: 'core-library',
7
8
  }
8
9
 
9
10
  export const ProjectScopeKindEnum = {
@@ -67,6 +67,13 @@ const MESSAGES = {
67
67
  { ctx: 'Global registry only', cmd: 'workspaces sync', effect: 'rescan ~/.xrystal from cwd' },
68
68
  ],
69
69
  syncScopeHint: 'shows which row applies to your cwd',
70
+ registry: {
71
+ noWorkspaces: 'no workspaces registered — run xry create demo --workspace then xry workspaces sync',
72
+ noProjects: 'projects: (none linked yet)',
73
+ slotEmpty: '(empty)',
74
+ slotMismatches: 'slot mismatches (wrong global.type for folder slot)',
75
+ other: 'other',
76
+ },
70
77
  },
71
78
  [CliLangEnum.TR]: {
72
79
  langTip: 'Dil: xry config lang tr (~/.xrystal/config.json)',
@@ -129,6 +136,13 @@ const MESSAGES = {
129
136
  { ctx: 'Sadece global registry', cmd: 'workspaces sync', effect: '~/.xrystal yeniden tara' },
130
137
  ],
131
138
  syncScopeHint: 'hangi satırın cwd\'ne uyduğunu gösterir',
139
+ registry: {
140
+ noWorkspaces: 'kayıtlı workspace yok — xry create demo --workspace sonra xry workspaces sync',
141
+ noProjects: 'projeler: (henüz link yok)',
142
+ slotEmpty: '(boş)',
143
+ slotMismatches: 'slot uyumsuzlukları (global.type bu klasör slotuna uymuyor)',
144
+ other: 'diğer',
145
+ },
132
146
  },
133
147
  }
134
148
 
@@ -5,6 +5,7 @@ import {
5
5
  DEFAULT_FOLDER_STRUCTURE,
6
6
  findWorkspaceRoot,
7
7
  readTmpFile,
8
+ resolveWorkspaceOuterTmp,
8
9
  } from './workspace-resolve.mjs'
9
10
  import { WorkspaceSlotEnum } from './cli-enums.mjs'
10
11
 
@@ -51,7 +52,10 @@ export function resolveCreateTarget(projectName, targetDir, { slot = WorkspaceSl
51
52
 
52
53
  if (workspaceRoot) {
53
54
  const wsRoot = resolveReal(workspaceRoot)
54
- const wsTmp = path.join(wsRoot, 'tmp.yml')
55
+ const wsTmp = resolveWorkspaceOuterTmp(wsRoot)
56
+ if (!wsTmp) {
57
+ throw new Error(`Workspace outer tmp.yml not found under ${wsRoot}`)
58
+ }
55
59
  const fsMap = readTmpFile(wsTmp).folderStructure
56
60
  const slotFolder = fsMap[slot] ?? DEFAULT_FOLDER_STRUCTURE[slot]
57
61
  const slotRoot = path.join(wsRoot, slotFolder)
@@ -20,8 +20,8 @@ function cliGeneratedModules() {
20
20
  outfile: path.join(CLI_GENERATED_DIR, 'tmp-schema.mjs'),
21
21
  },
22
22
  {
23
- source: `${main}/utils/helpers/xrystal-home/registry.ts`,
24
- outfile: path.join(CLI_GENERATED_DIR, 'xrystal-home-registry.mjs'),
23
+ source: `${main}/utils/helpers/user-home/registry.ts`,
24
+ outfile: path.join(CLI_GENERATED_DIR, 'user-home-registry.mjs'),
25
25
  },
26
26
  {
27
27
  source: `${main}/utils/helpers/workspace/index.ts`,
@@ -4,7 +4,7 @@ import yaml from 'yaml'
4
4
 
5
5
  import { packageDefaults } from './package-defaults.mjs'
6
6
  import { isCorePackageRoot } from './tmp-layout.mjs'
7
- import { findEntries, findWorkspaceRoot, workspaceProjectName } from './workspace-resolve.mjs'
7
+ import { findWorkspaceRoot, resolveWorkspaceOuterTmp, scanWorkspaceProjects, workspaceProjectName } from './workspace-resolve.mjs'
8
8
  import { getInstalledCoreVersion, readCliPackageJson, readProjectPackageJson, resolveProjectRoot } from './project-root.mjs'
9
9
  import { readTmpSchemaVersion, TMP_SCHEMA_VERSION } from './tmp-schema-version.mjs'
10
10
  import { GlobalTypeEnum, ProjectScopeKindEnum } from './cli-enums.mjs'
@@ -30,8 +30,7 @@ function readTmpMeta(tmpFilePath) {
30
30
  function findOuterWorkspaceTmp(startDir) {
31
31
  const wsRoot = findWorkspaceRoot(startDir)
32
32
  if (!wsRoot) return null
33
- const outer = path.join(wsRoot, 'tmp.yml')
34
- return fs.existsSync(outer) ? outer : null
33
+ return resolveWorkspaceOuterTmp(wsRoot)
35
34
  }
36
35
 
37
36
  export function resolveProjectContext(startDir = process.cwd()) {
@@ -57,8 +56,13 @@ export function resolveProjectContext(startDir = process.cwd()) {
57
56
  package: readProjectPackageJson(coreRoot),
58
57
  core: { cli: cliVersion, declared: cliVersion, installed: cliVersion, isGlobalLibrary: true },
59
58
  workspaceEntries: [],
59
+ slotMismatches: [],
60
+ selfEntry: null,
61
+ selfMismatch: null,
62
+ schemaVersionExpected: TMP_SCHEMA_VERSION,
60
63
  hints: [
61
64
  'Global runtime library — publish via xry tag',
65
+ 'tmp global.type: core-library (not workspace / not api-service)',
62
66
  'Consumers: bun add @xrystal/core && xry tmp in their repo',
63
67
  ],
64
68
  }
@@ -110,10 +114,16 @@ export function resolveProjectContext(startDir = process.cwd()) {
110
114
  }
111
115
  }
112
116
 
113
- const workspaceEntries = workspaceRoot ? findEntries(workspaceRoot) : []
117
+ const workspaceScan = workspaceRoot ? scanWorkspaceProjects(workspaceRoot) : { entries: [], mismatches: [] }
118
+ const workspaceEntries = workspaceScan.entries
119
+ const slotMismatches = workspaceScan.mismatches
114
120
  const selfEntry = workspaceEntries.find((e) => path.resolve(e.path) === path.resolve(projectRoot))
121
+ const selfMismatch = slotMismatches.find((m) => path.resolve(m.projectPath) === path.resolve(projectRoot))
115
122
 
116
123
  const hints = []
124
+ if (slotMismatches.length > 0) {
125
+ hints.push('Fix slot/type mismatches — api slot → api-service · web/mobile → frontend')
126
+ }
117
127
  if (kind === ProjectScopeKindEnum.WORKSPACE_ROOT) {
118
128
  hints.push('Outer tmp: ./tmp.yml · inner tmp: each api|web|mobile project (admin → web/)')
119
129
  hints.push('xry sync — all linked projects + ~/.xrystal registry')
@@ -142,6 +152,8 @@ export function resolveProjectContext(startDir = process.cwd()) {
142
152
  innerTmp: innerMeta,
143
153
  tmp: innerMeta ?? outerMeta,
144
154
  selfEntry: selfEntry ?? null,
155
+ selfMismatch: selfMismatch ?? null,
156
+ slotMismatches,
145
157
  package: pkg,
146
158
  core: {
147
159
  cli: cliVersion,