@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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.55.8",
4
+ "version": "3.55.10",
5
5
  "description": "Runtime framework and CLI for API services, frontends, and multi-repo workspaces",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -7,6 +7,7 @@ import { resolveProjectContext } from '../helpers/project-context.mjs'
7
7
  import { readCliPackageJson } from '../helpers/project-root.mjs'
8
8
  import { ensureTmpSchemaVersion } from '../helpers/tmp-schema-version.mjs'
9
9
  import { ProjectScopeKindEnum } from '../helpers/cli-enums.mjs'
10
+ import { formatSlotMismatch } from '../helpers/workspace-resolve.mjs'
10
11
 
11
12
  function line(label, value) {
12
13
  console.log(` ${label.padEnd(20)}${value}`)
@@ -73,6 +74,18 @@ export function registerProjectInfoCommand(cli, { cliName = CLI_PRIMARY_NAME } =
73
74
  console.log(chalk.bold.cyan('\n Workspace link'))
74
75
  line('name', `${ctx.selfEntry.name} [${ctx.selfEntry.type}]`)
75
76
  line('slot', ctx.selfEntry.slot)
77
+ } else if (ctx.selfMismatch) {
78
+ console.log(chalk.bold.red('\n Slot mismatch (this project)'))
79
+ console.log(` ${chalk.red('✗')} ${formatSlotMismatch(ctx.selfMismatch)}`)
80
+ console.log(chalk.gray(` tmp: ${ctx.selfMismatch.tmp}`))
81
+ }
82
+
83
+ if (ctx.slotMismatches?.length > 0) {
84
+ console.log(chalk.bold.red(`\n Slot mismatches (${ctx.slotMismatches.length})`))
85
+ for (const mismatch of ctx.slotMismatches) {
86
+ console.log(` ${chalk.red('✗')} ${formatSlotMismatch(mismatch)}`)
87
+ console.log(chalk.gray(` ${mismatch.projectPath}`))
88
+ }
76
89
  }
77
90
 
78
91
  if (ctx.workspaceEntries.length > 0 && ctx.kind === ProjectScopeKindEnum.WORKSPACE_ROOT) {
@@ -2,30 +2,75 @@ import chalk from 'chalk'
2
2
 
3
3
  import { printCommandFooter, printCommandHeader } from '../helpers/banner.mjs'
4
4
  import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
5
+ import { t } from '../helpers/cli-i18n.mjs'
5
6
  import { readCliPackageJson } from '../helpers/project-root.mjs'
6
- import { readRegistry, resolveXrystalHome, syncRegistryFromPath } from '../helpers/xrystal-registry.mjs'
7
+ import { groupProjectsBySlot, REGISTRY_SLOT_ORDER } from '../helpers/registry-display.mjs'
8
+ import { formatSlotMismatch, scanWorkspaceProjects } from '../helpers/workspace-resolve.mjs'
9
+ import { readRegistry, resolveUserHome, syncRegistryFromPath } from '../helpers/xrystal-registry.mjs'
10
+
11
+ function printProjectLine(project, { indent = ' ' } = {}) {
12
+ const cluster = project.cluster ? chalk.yellow(` cluster=${project.cluster}`) : ''
13
+ console.log(`${indent}• ${project.name} [${project.type}] → ${project.path}${cluster}`)
14
+ }
15
+
16
+ function printWorkspaceSlotMismatches(workspacePath) {
17
+ const { mismatches } = scanWorkspaceProjects(workspacePath)
18
+ if (mismatches.length === 0) return
19
+
20
+ console.log(chalk.red.bold(` ${t('registry.slotMismatches')}`))
21
+ for (const slot of REGISTRY_SLOT_ORDER) {
22
+ const items = mismatches.filter((m) => m.slot === slot)
23
+ if (items.length === 0) continue
24
+ console.log(chalk.red(` ${slot}`))
25
+ for (const mismatch of items) {
26
+ console.log(chalk.red(` ✗ ${formatSlotMismatch(mismatch)}`))
27
+ }
28
+ }
29
+ }
30
+
31
+ function printWorkspaceProjects(projects) {
32
+ if (projects.length === 0) {
33
+ console.log(chalk.gray(` ${t('registry.noProjects')}`))
34
+ return
35
+ }
36
+
37
+ const { groups, other } = groupProjectsBySlot(projects)
38
+
39
+ for (const slot of REGISTRY_SLOT_ORDER) {
40
+ const items = groups[slot]
41
+ console.log(chalk.bold(` ${slot}`))
42
+ if (items.length === 0) {
43
+ console.log(chalk.gray(` ${t('registry.slotEmpty')}`))
44
+ continue
45
+ }
46
+ for (const project of items) {
47
+ printProjectLine(project)
48
+ }
49
+ }
50
+
51
+ if (other.length > 0) {
52
+ console.log(chalk.bold(` ${t('registry.other')}`))
53
+ for (const project of other) {
54
+ printProjectLine(project)
55
+ }
56
+ }
57
+ }
7
58
 
8
59
  function printProjectsRegistry() {
9
60
  const registry = readRegistry()
10
- console.log(chalk.gray(` home: ${resolveXrystalHome()}`))
61
+ console.log(chalk.gray(` home: ${resolveUserHome()}`))
11
62
  console.log(chalk.gray(` workspaces: ${registry.workspaces.length}`))
12
63
 
13
64
  if (registry.workspaces.length === 0) {
14
- console.log(chalk.yellow('\n no workspaces registered — run xry create demo --workspace then xry workspaces sync\n'))
65
+ console.log(chalk.yellow(`\n ${t('registry.noWorkspaces')}\n`))
15
66
  return
16
67
  }
17
68
 
18
69
  for (const ws of registry.workspaces) {
19
70
  console.log(chalk.cyan(`\n${ws.name}`))
20
71
  console.log(chalk.gray(` path: ${ws.path}`))
21
- if (ws.projects.length === 0) {
22
- console.log(chalk.gray(' projects: (none linked yet)'))
23
- continue
24
- }
25
- for (const project of ws.projects) {
26
- const cluster = project.cluster ? chalk.yellow(` cluster=${project.cluster}`) : ''
27
- console.log(` • ${project.name} [${project.type}] → ${project.path}${cluster}`)
28
- }
72
+ printWorkspaceProjects(ws.projects)
73
+ printWorkspaceSlotMismatches(ws.path)
29
74
  }
30
75
  console.log('')
31
76
  }
@@ -10,12 +10,22 @@ import { runWorkspaceSelfHeal } from '../helpers/workspace-heal.mjs'
10
10
  import { printSyncProjectResult, syncOneProject } from '../helpers/sync-project.mjs'
11
11
  import { ensureSyncProjectTmp, previewSyncProjectTmp } from '../helpers/sync-tmp.mjs'
12
12
  import { formatSyncHelp } from '../helpers/cli-help.mjs'
13
+ import { findWorkspaceRoot, resolveWorkspaceOuterTmp } from '../helpers/workspace-resolve.mjs'
13
14
 
14
15
  /** Sync tsconfig + @xrystal/core pin from tmp.yml layout. */
15
16
  export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
16
17
  const run = (options) => {
17
18
  const coreVersion = readCliPackageJson().version
18
19
 
20
+ // Heal outer tmp structure before discovery — broken folder-structure must not block sync.
21
+ const earlyWorkspaceRoot = findWorkspaceRoot(process.cwd())
22
+ let workspaceHeal = null
23
+ if (earlyWorkspaceRoot && !options.dryRun) {
24
+ workspaceHeal = runWorkspaceSelfHeal(earlyWorkspaceRoot, {
25
+ forceRegistry: Boolean(options.all || options.workspace),
26
+ })
27
+ }
28
+
19
29
  let scope
20
30
  try {
21
31
  scope = resolveSyncScope(process.cwd(), { ...options, cliName })
@@ -26,16 +36,20 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
26
36
 
27
37
  printCommandHeader({ cliName, command: 'sync', version: coreVersion })
28
38
 
29
- let workspaceHeal = null
30
- if (scope.workspaceRoot && !options.dryRun) {
39
+ if (scope.workspaceRoot && !options.dryRun && !workspaceHeal) {
31
40
  workspaceHeal = runWorkspaceSelfHeal(scope.workspaceRoot, {
32
41
  forceRegistry: scope.mode === 'workspace-all',
33
42
  })
43
+ }
44
+ if (workspaceHeal) {
34
45
  if (workspaceHeal.slotDirsCreated.length) {
35
46
  console.log(chalk.green(` layout: created ${workspaceHeal.slotDirsCreated.join(', ')}/`))
36
47
  }
37
- if (workspaceHeal.tmpOptionsPatched) {
38
- console.log(chalk.green(' outer tmp: added global.options.fileWatchIntervalMs'))
48
+ if (workspaceHeal.outerTmpHeal?.changed) {
49
+ console.log(chalk.green(` outer tmp healed: ${workspaceHeal.outerTmpHeal.notes.join(', ')}`))
50
+ }
51
+ if (workspaceHeal.schemaPatched) {
52
+ console.log(chalk.green(' outer tmp end.version healed (schema)'))
39
53
  }
40
54
  }
41
55
  if (scope.warnAllIgnored) {
@@ -47,9 +61,9 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
47
61
  }
48
62
  console.log(chalk.gray(` projects: ${scope.entries.length}`))
49
63
 
50
- if (scope.mode === 'workspace-all' && scope.workspaceRoot) {
51
- const wsTmp = path.join(scope.workspaceRoot, 'tmp.yml')
52
- if (!options.dryRun) {
64
+ if (scope.mode === 'workspace-all' && scope.workspaceRoot && !options.dryRun) {
65
+ const wsTmp = resolveWorkspaceOuterTmp(scope.workspaceRoot)
66
+ if (wsTmp) {
53
67
  const wsSchema = ensureTmpSchemaVersion(wsTmp)
54
68
  if (wsSchema.patched) {
55
69
  console.log(chalk.green(` outer tmp end.version → ${wsSchema.schemaVersion} (schema)`))
@@ -4,7 +4,7 @@ import { printCommandFooter, printCommandHeader } from '../helpers/banner.mjs'
4
4
  import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
5
5
  import { readCliPackageJson } from '../helpers/project-root.mjs'
6
6
  import { collectWatchTargets } from '../helpers/xrystal-watch-daemon.mjs'
7
- import { readRegistry, resolveXrystalHome } from '../helpers/xrystal-registry.mjs'
7
+ import { readRegistry, resolveUserHome } from '../helpers/xrystal-registry.mjs'
8
8
  import {
9
9
  ensureWatchDaemon,
10
10
  startWatchDaemon,
@@ -67,7 +67,7 @@ export function registerWatchCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
67
67
  printCommandHeader({ cliName, command: 'watch status', version })
68
68
 
69
69
  const status = watchDaemonStatus()
70
- console.log(chalk.gray(` home: ${resolveXrystalHome()}`))
70
+ console.log(chalk.gray(` home: ${resolveUserHome()}`))
71
71
  console.log(status.running
72
72
  ? chalk.green(` running pid ${status.pid}`)
73
73
  : chalk.yellow(' not running'))
@@ -1,4 +1,4 @@
1
1
  source/utils/helpers/tmp/tmp-schema.ts
2
- source/utils/helpers/xrystal-home/registry.ts
2
+ source/utils/helpers/user-home/registry.ts
3
3
  source/utils/helpers/workspace/index.ts
4
4
  source/utils/helpers/tmp/seed-from-tmp.ts
@@ -75,6 +75,7 @@ var GlobalTypeEnum;
75
75
  GlobalTypeEnum2["WORKSPACE"] = "workspace";
76
76
  GlobalTypeEnum2["API_SERVICE"] = "api-service";
77
77
  GlobalTypeEnum2["FRONTEND"] = "frontend";
78
+ GlobalTypeEnum2["CORE_LIBRARY"] = "core-library";
78
79
  })(GlobalTypeEnum ||= {});
79
80
  var RuntimeEnum;
80
81
  ((RuntimeEnum2) => {
@@ -222,6 +223,8 @@ function normalizeGlobalType(value) {
222
223
  return "api-service" /* API_SERVICE */;
223
224
  if (raw === "frontend" /* FRONTEND */)
224
225
  return "frontend" /* FRONTEND */;
226
+ if (raw === "core-library" /* CORE_LIBRARY */)
227
+ return "core-library" /* CORE_LIBRARY */;
225
228
  throw new Error(`${defaults_default.packageName}: configs.global.type must be one of ${Object.values(GlobalTypeEnum).join("|")} (got "${String(value)}")`);
226
229
  }
227
230
  function normalizeRuntime(value) {
@@ -279,6 +282,13 @@ function readTmpGlobalPathsBlock(configs) {
279
282
  }
280
283
  };
281
284
  }
285
+ function buildTmpRelPath(rootFolder, tmpFileName) {
286
+ const root = stripDotSlash(rootFolder);
287
+ const tmp = stripDotSlash(tmpFileName) || "tmp.yml";
288
+ if (!root || root === ".")
289
+ return tmp;
290
+ return `${root}/${tmp}`.replace(/\/+/g, "/");
291
+ }
282
292
  function resolveMergedPaths(configs) {
283
293
  const paths = readTmpGlobalPathsBlock(configs);
284
294
  const root = stripDotSlash(normalizeRootFolder2(paths.root));
@@ -289,7 +299,7 @@ function resolveMergedPaths(configs) {
289
299
  root,
290
300
  source,
291
301
  special,
292
- tmpRelPath: `${root}/${tmpName}`.replace(/\/+/g, "/")
302
+ tmpRelPath: buildTmpRelPath(root, tmpName)
293
303
  };
294
304
  }
295
305
  function readWorkspaceGlobalBlock(global) {
@@ -308,6 +318,21 @@ function readWorkspaceGlobalBlock(global) {
308
318
  options: optionsRaw ? { fileWatchIntervalMs: readWatchIntervalValue(optionsRaw.fileWatchIntervalMs) } : undefined
309
319
  };
310
320
  }
321
+ function readCoreLibraryGlobalBlock(global, configs) {
322
+ const varsRaw = isRecord2(global.vars) ? global.vars : {};
323
+ const runtimeRaw = typeof global.runtime === "string" ? global.runtime.trim() : "";
324
+ return {
325
+ type: "core-library" /* CORE_LIBRARY */,
326
+ runtime: runtimeRaw ? normalizeRuntime(runtimeRaw) : "bun" /* BUN */,
327
+ framework: typeof global.framework === "string" ? global.framework.trim() : "",
328
+ paths: readTmpGlobalPathsBlock(configs),
329
+ vars: { ...varsRaw },
330
+ build: isRecord2(global.build) ? { ...global.build } : undefined,
331
+ options: isRecord2(global.options) ? {
332
+ fileWatchIntervalMs: readWatchIntervalValue(global.options.fileWatchIntervalMs)
333
+ } : undefined
334
+ };
335
+ }
311
336
  function readTmpGlobalBlock(configs) {
312
337
  const global = isRecord2(configs?.global) ? configs.global : {};
313
338
  const varsRaw = isRecord2(global.vars) ? global.vars : {};
@@ -316,6 +341,9 @@ function readTmpGlobalBlock(configs) {
316
341
  if (type === "workspace" /* WORKSPACE */) {
317
342
  return readWorkspaceGlobalBlock(global);
318
343
  }
344
+ if (type === "core-library" /* CORE_LIBRARY */) {
345
+ return readCoreLibraryGlobalBlock(global, configs);
346
+ }
319
347
  if (typeof global.framework !== "string" || !global.framework.trim()) {
320
348
  throw new Error(`${defaults_default.packageName}: configs.global.framework is required`);
321
349
  }
@@ -400,12 +428,14 @@ function resolveTmpRuntimeConfigs(tmp) {
400
428
  const global = readTmpGlobalBlock(configs);
401
429
  const depends = readTmpDependsBlock(configs);
402
430
  if (global.type === "workspace" /* WORKSPACE */) {
431
+ const root = stripDotSlash(normalizeRootFolder2(global.paths.root ?? ".")) || ".";
432
+ const tmpName = stripDotSlash(global.paths.tmp ?? "tmp.yml") || "tmp.yml";
403
433
  return {
404
434
  global: { ...global, build: {} },
405
435
  depends: buildNormalizedDepends(depends),
406
436
  deploymentName: resolveTmpDeploymentName(tmp),
407
- rootFolderPath: ".",
408
- tmpRelPath: global.paths.tmp ?? "tmp.yml"
437
+ rootFolderPath: root,
438
+ tmpRelPath: buildTmpRelPath(root, tmpName)
409
439
  };
410
440
  }
411
441
  const merged = resolveMergedPaths(configs);
@@ -428,17 +458,19 @@ function normalizeTmpDocument(tmp) {
428
458
  };
429
459
  }
430
460
  function resolveProjectRootFromTmpPath(tmpFilePath, configs) {
431
- const merged = resolveMergedPaths(configs);
461
+ const runtime = resolveTmpRuntimeConfigs(isRecord2(configs?.global) ? { configs } : { configs: configs ?? {} });
432
462
  const abs = tmpFilePath.replace(/\\/g, "/");
433
- const rel = merged.tmpRelPath;
434
- if (abs.endsWith(`/${rel}`)) {
435
- return abs.slice(0, -(rel.length + 1));
463
+ const rel = runtime.tmpRelPath;
464
+ if (abs === rel || abs.endsWith(`/${rel}`)) {
465
+ const root = abs === rel ? "" : abs.slice(0, -(rel.length + 1));
466
+ return root || ".";
436
467
  }
437
468
  throw new Error(`${defaults_default.packageName}: tmp path ${tmpFilePath} does not match configs.global.paths (${rel})`);
438
469
  }
439
470
  function resolveTmpAbsPath(projectRoot, configs) {
440
- const merged = resolveMergedPaths(configs);
441
- return `${projectRoot.replace(/\\/g, "/").replace(/\/$/, "")}/${merged.tmpRelPath}`;
471
+ const runtime = resolveTmpRuntimeConfigs(isRecord2(configs?.global) ? { configs } : { configs: configs ?? {} });
472
+ const base = projectRoot.replace(/\\/g, "/").replace(/\/$/, "");
473
+ return `${base}/${runtime.tmpRelPath}`;
442
474
  }
443
475
  export {
444
476
  resolveTmpRuntimeConfigs,
@@ -459,6 +491,7 @@ export {
459
491
  normalizeGlobalType,
460
492
  normalizeBundler,
461
493
  buildTmpVarContext,
494
+ buildTmpRelPath,
462
495
  assertNoLegacyTmpKeys,
463
496
  applyTmpGlobalVars
464
497
  };
@@ -1,4 +1,4 @@
1
- // source/utils/helpers/xrystal-home/registry.ts
1
+ // source/utils/helpers/user-home/registry.ts
2
2
  import fs3 from "node:fs";
3
3
  import os from "node:os";
4
4
  import path5 from "node:path";
@@ -278,11 +278,31 @@ function parseFolderStructure(text) {
278
278
  ["mobile" /* MOBILE */]: readSlot("mobile" /* MOBILE */)
279
279
  };
280
280
  }
281
+ function allowedGlobalTypesForSlot(slot) {
282
+ if (slot === "api" /* API */)
283
+ return ["api-service" /* API_SERVICE */];
284
+ if (slot === "web" /* WEB */ || slot === "mobile" /* MOBILE */) {
285
+ return ["frontend" /* FRONTEND */];
286
+ }
287
+ return [];
288
+ }
281
289
  function workspaceDiscoverySlots(fsMap) {
282
290
  return [
283
- { slot: "api" /* API */, folder: fsMap["api" /* API */], frontendOnly: false },
284
- { slot: "web" /* WEB */, folder: fsMap["web" /* WEB */], frontendOnly: true },
285
- { slot: "mobile" /* MOBILE */, folder: fsMap["mobile" /* MOBILE */], frontendOnly: true }
291
+ {
292
+ slot: "api" /* API */,
293
+ folder: fsMap["api" /* API */],
294
+ allowedTypes: allowedGlobalTypesForSlot("api" /* API */)
295
+ },
296
+ {
297
+ slot: "web" /* WEB */,
298
+ folder: fsMap["web" /* WEB */],
299
+ allowedTypes: allowedGlobalTypesForSlot("web" /* WEB */)
300
+ },
301
+ {
302
+ slot: "mobile" /* MOBILE */,
303
+ folder: fsMap["mobile" /* MOBILE */],
304
+ allowedTypes: allowedGlobalTypesForSlot("mobile" /* MOBILE */)
305
+ }
286
306
  ];
287
307
  }
288
308
  function entryName(meta) {
@@ -303,13 +323,38 @@ function entryType(meta, slot) {
303
323
  return null;
304
324
  }
305
325
  function findWorkspaceRoot(startDir = process.cwd()) {
306
- let cur = path4.resolve(startDir);
326
+ return findWorkspaceAnchor(startDir)?.root ?? null;
327
+ }
328
+ function resolveWorkspaceOuterTmp(workspaceRoot) {
329
+ const root = path4.resolve(workspaceRoot);
330
+ const anchor = findWorkspaceAnchor(root);
331
+ if (!anchor)
332
+ return null;
333
+ if (path4.resolve(anchor.root) !== root)
334
+ return null;
335
+ return anchor.tmpPath;
336
+ }
337
+ function findWorkspaceAnchor(startDir = process.cwd()) {
338
+ const start = path4.resolve(startDir);
339
+ let cur = start;
307
340
  for (;; ) {
308
- const candidate = path4.join(cur, TMP_FILE);
309
- if (fs2.existsSync(candidate)) {
310
- const meta = readTmpFile(candidate);
311
- if (meta.globalType === "workspace" /* WORKSPACE */)
312
- return cur;
341
+ for (const candidate of listShallowTmpCandidates(cur)) {
342
+ let meta;
343
+ try {
344
+ meta = readTmpFile(candidate);
345
+ } catch {
346
+ continue;
347
+ }
348
+ if (meta.globalType !== "workspace" /* WORKSPACE */)
349
+ continue;
350
+ try {
351
+ const root = path4.resolve(resolveRepoRootFromTmpMeta(candidate, meta));
352
+ if (start === root || start.startsWith(`${root}${path4.sep}`)) {
353
+ return { root, tmpPath: path4.resolve(candidate), meta };
354
+ }
355
+ } catch {
356
+ continue;
357
+ }
313
358
  }
314
359
  const parent = path4.dirname(cur);
315
360
  if (parent === cur)
@@ -318,6 +363,29 @@ function findWorkspaceRoot(startDir = process.cwd()) {
318
363
  }
319
364
  return null;
320
365
  }
366
+ function listShallowTmpCandidates(dir) {
367
+ const out = [];
368
+ const direct = path4.join(dir, TMP_FILE);
369
+ if (fs2.existsSync(direct))
370
+ out.push(direct);
371
+ let entries;
372
+ try {
373
+ entries = fs2.readdirSync(dir, { withFileTypes: true });
374
+ } catch {
375
+ return out;
376
+ }
377
+ for (const entry of entries) {
378
+ const full = path4.join(dir, entry.name);
379
+ if (!isTraversableDir(entry, full))
380
+ continue;
381
+ if (SKIP_DIRS.has(entry.name) || entry.name.startsWith("."))
382
+ continue;
383
+ const nested = path4.join(full, TMP_FILE);
384
+ if (fs2.existsSync(nested))
385
+ out.push(nested);
386
+ }
387
+ return out;
388
+ }
321
389
  function isTraversableDir(entry, fullPath) {
322
390
  if (entry.isDirectory())
323
391
  return true;
@@ -358,39 +426,70 @@ function walkTmpUnder(rootDir) {
358
426
  return found;
359
427
  }
360
428
  function stripDotSlash(value) {
361
- return value.replace(/^\.\//, "");
362
- }
363
- function repoRootFromTmp(tmpPath, meta) {
364
- const abs = tmpPath.replace(/\\/g, "/");
365
- const rootFolder = stripDotSlash(meta.pathsRoot ?? "./x");
366
- const tmpName = stripDotSlash(meta.pathsTmp ?? "tmp.yml");
367
- const rel = `${rootFolder}/${tmpName}`.replace(/\/+/g, "/");
368
- if (abs.endsWith(`/${rel}`)) {
369
- return abs.slice(0, -(rel.length + 1));
429
+ return value.replace(/^\.\//, "").replace(/\/$/, "");
430
+ }
431
+ function buildRepoTmpRelPath(meta) {
432
+ const isWorkspace = meta.globalType === "workspace" /* WORKSPACE */;
433
+ const rootFolder = stripDotSlash(meta.pathsRoot?.trim() || (isWorkspace ? "." : packageDefaults.packageRootFolder));
434
+ const tmpName = stripDotSlash(meta.pathsTmp?.trim() || TMP_FILE) || TMP_FILE;
435
+ if (!rootFolder || rootFolder === ".")
436
+ return tmpName;
437
+ return `${rootFolder}/${tmpName}`.replace(/\/+/g, "/");
438
+ }
439
+ function resolveRepoRootFromTmpMeta(tmpPath, meta) {
440
+ const abs = path4.resolve(tmpPath).replace(/\\/g, "/");
441
+ const rel = buildRepoTmpRelPath(meta);
442
+ if (abs === rel || abs.endsWith(`/${rel}`)) {
443
+ const root = abs === rel ? "" : abs.slice(0, -(rel.length + 1));
444
+ return root || path4.dirname(abs);
370
445
  }
371
446
  throw new Error(`tmp path mismatch: expected */${rel}, got ${abs}`);
372
447
  }
373
- function findEntries(workspaceRoot) {
374
- const wsMeta = readTmpFile(path4.join(workspaceRoot, TMP_FILE));
448
+ function scanWorkspaceProjects(workspaceRoot) {
449
+ const outerTmp = resolveWorkspaceOuterTmp(workspaceRoot);
450
+ const wsMeta = readTmpFile(outerTmp ?? path4.join(workspaceRoot, TMP_FILE));
375
451
  const fsMap = wsMeta.folderStructure;
376
452
  const entries = [];
453
+ const mismatches = [];
377
454
  const seen = new Set;
378
- for (const { slot, folder: folderRel, frontendOnly } of workspaceDiscoverySlots(fsMap)) {
455
+ const seenMismatch = new Set;
456
+ const outerResolved = outerTmp ? path4.resolve(outerTmp) : null;
457
+ for (const { slot, folder: folderRel, allowedTypes } of workspaceDiscoverySlots(fsMap)) {
379
458
  const folder = path4.join(workspaceRoot, folderRel);
380
459
  for (const tmpPath of walkTmpUnder(folder)) {
381
- if (path4.resolve(tmpPath) === path4.join(workspaceRoot, TMP_FILE))
460
+ if (outerResolved && path4.resolve(tmpPath) === outerResolved)
382
461
  continue;
383
462
  const meta = readTmpFile(tmpPath);
384
463
  const kind = entryType(meta, slot);
385
464
  if (kind === "workspace" /* WORKSPACE */)
386
465
  continue;
387
- if (frontendOnly && kind !== "frontend" /* FRONTEND */)
388
- continue;
389
- if (kind !== "api-service" /* API_SERVICE */ && kind !== "frontend" /* FRONTEND */)
390
- continue;
391
466
  const name = entryName(meta);
467
+ const explicitType = (meta.globalType ?? "").trim() || null;
468
+ const projectPath = (() => {
469
+ try {
470
+ return resolveRepoRootFromTmpMeta(tmpPath, meta);
471
+ } catch {
472
+ return path4.dirname(tmpPath);
473
+ }
474
+ })();
392
475
  if (!name)
393
476
  continue;
477
+ if (kind == null || !allowedTypes.includes(kind)) {
478
+ const mismatchKey = `${slot}:${tmpPath}`;
479
+ if (!seenMismatch.has(mismatchKey)) {
480
+ seenMismatch.add(mismatchKey);
481
+ mismatches.push({
482
+ slot,
483
+ slotFolder: folderRel,
484
+ projectName: name,
485
+ globalType: explicitType,
486
+ expectedTypes: allowedTypes,
487
+ tmp: tmpPath,
488
+ projectPath
489
+ });
490
+ }
491
+ continue;
492
+ }
394
493
  const key = `${kind}:${name}`;
395
494
  if (seen.has(key))
396
495
  continue;
@@ -398,29 +497,37 @@ function findEntries(workspaceRoot) {
398
497
  entries.push({
399
498
  name,
400
499
  type: kind,
401
- path: repoRootFromTmp(tmpPath, meta),
500
+ path: projectPath,
402
501
  tmp: tmpPath,
403
502
  slot,
404
503
  cluster: meta.clusterDeployment ?? meta.projectName
405
504
  });
406
505
  }
407
506
  }
408
- return entries.sort((a, b) => a.type === b.type ? a.name.localeCompare(b.name) : a.type.localeCompare(b.type));
507
+ const sortEntries = (a, b) => a.type === b.type ? a.name.localeCompare(b.name) : a.type.localeCompare(b.type);
508
+ mismatches.sort((a, b) => a.slot.localeCompare(b.slot) || a.projectName.localeCompare(b.projectName) || a.tmp.localeCompare(b.tmp));
509
+ return {
510
+ entries: entries.sort(sortEntries),
511
+ mismatches
512
+ };
513
+ }
514
+ function findEntries(workspaceRoot) {
515
+ return scanWorkspaceProjects(workspaceRoot).entries;
409
516
  }
410
517
 
411
- // source/utils/helpers/xrystal-home/registry.ts
412
- var XRYSTAL_HOME_DIR = ".xrystal";
413
- function resolveXrystalHome() {
414
- const override = process.env.XRYSTAL_HOME?.trim();
518
+ // source/utils/helpers/user-home/registry.ts
519
+ var USER_HOME_DIR = ".xrystal";
520
+ function resolveUserHome() {
521
+ const override = process.env.XRY_HOME?.trim() || process.env.XRYSTAL_HOME?.trim();
415
522
  if (override)
416
523
  return path5.resolve(override);
417
- return path5.join(os.homedir(), XRYSTAL_HOME_DIR);
524
+ return path5.join(os.homedir(), USER_HOME_DIR);
418
525
  }
419
526
  function registryFilePath() {
420
- return path5.join(resolveXrystalHome(), "registry.json");
527
+ return path5.join(resolveUserHome(), "registry.json");
421
528
  }
422
- function ensureXrystalHome() {
423
- const home = resolveXrystalHome();
529
+ function ensureUserHome() {
530
+ const home = resolveUserHome();
424
531
  fs3.mkdirSync(path5.join(home, "workspaces"), { recursive: true });
425
532
  return home;
426
533
  }
@@ -453,7 +560,7 @@ function scanWorkspace(workspacePath, workspaceName) {
453
560
  };
454
561
  }
455
562
  function readRegistry() {
456
- ensureXrystalHome();
563
+ ensureUserHome();
457
564
  const file = registryFilePath();
458
565
  if (!fs3.existsSync(file)) {
459
566
  return { version: 1, updatedAt: new Date().toISOString(), workspaces: [] };
@@ -461,12 +568,12 @@ function readRegistry() {
461
568
  return JSON.parse(fs3.readFileSync(file, "utf8"));
462
569
  }
463
570
  function writeRegistry(registry) {
464
- ensureXrystalHome();
571
+ ensureUserHome();
465
572
  registry.updatedAt = new Date().toISOString();
466
573
  fs3.writeFileSync(registryFilePath(), `${JSON.stringify(registry, null, 2)}
467
574
  `);
468
575
  for (const ws of registry.workspaces) {
469
- const wsDir = path5.join(resolveXrystalHome(), "workspaces", ws.name);
576
+ const wsDir = path5.join(resolveUserHome(), "workspaces", ws.name);
470
577
  fs3.mkdirSync(wsDir, { recursive: true });
471
578
  fs3.writeFileSync(path5.join(wsDir, "workspace.json"), `${JSON.stringify(ws, null, 2)}
472
579
  `);
@@ -533,12 +640,12 @@ export {
533
640
  upsertWorkspace,
534
641
  syncRegistryFromPath,
535
642
  scanWorkspace,
536
- resolveXrystalHome,
643
+ resolveUserHome,
537
644
  registryFilePath,
538
645
  readRegistry,
539
646
  listRegistryProjects,
540
647
  healRegistryAtPath,
541
648
  entryToRegistryProject,
542
- ensureXrystalHome,
543
- XRYSTAL_HOME_DIR
649
+ ensureUserHome,
650
+ USER_HOME_DIR
544
651
  };