@xrystal/core 3.55.9 → 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.
- package/package.json +1 -1
- package/x/bin/commands/sync.mjs +21 -7
- package/x/bin/helpers/.generated/tmp-schema.mjs +21 -0
- package/x/bin/helpers/.generated/workspace.mjs +180 -20
- package/x/bin/helpers/cli-enums.mjs +1 -0
- package/x/bin/helpers/project-context.mjs +5 -0
- package/x/bin/helpers/workspace-heal.mjs +21 -5
- package/x/bin/helpers/workspace-resolve.mjs +1 -0
- package/x/bin/helpers/workspace-tmp.mjs +11 -7
- package/x/dist/utils/helpers/tmp/loader-boot-plan.js +7 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +22 -0
- package/x/dist/utils/helpers/workspace/index.d.ts +15 -1
- package/x/dist/utils/helpers/workspace/index.js +200 -19
- package/x/dist/utils/models/enums/index.d.ts +4 -2
- package/x/dist/utils/models/enums/index.js +3 -1
- package/x/tmp.yml +2 -3
package/package.json
CHANGED
package/x/bin/commands/sync.mjs
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
38
|
-
console.log(chalk.green(
|
|
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 =
|
|
52
|
-
if (
|
|
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)`))
|
|
@@ -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) {
|
|
@@ -315,6 +318,21 @@ function readWorkspaceGlobalBlock(global) {
|
|
|
315
318
|
options: optionsRaw ? { fileWatchIntervalMs: readWatchIntervalValue(optionsRaw.fileWatchIntervalMs) } : undefined
|
|
316
319
|
};
|
|
317
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
|
+
}
|
|
318
336
|
function readTmpGlobalBlock(configs) {
|
|
319
337
|
const global = isRecord2(configs?.global) ? configs.global : {};
|
|
320
338
|
const varsRaw = isRecord2(global.vars) ? global.vars : {};
|
|
@@ -323,6 +341,9 @@ function readTmpGlobalBlock(configs) {
|
|
|
323
341
|
if (type === "workspace" /* WORKSPACE */) {
|
|
324
342
|
return readWorkspaceGlobalBlock(global);
|
|
325
343
|
}
|
|
344
|
+
if (type === "core-library" /* CORE_LIBRARY */) {
|
|
345
|
+
return readCoreLibraryGlobalBlock(global, configs);
|
|
346
|
+
}
|
|
326
347
|
if (typeof global.framework !== "string" || !global.framework.trim()) {
|
|
327
348
|
throw new Error(`${defaults_default.packageName}: configs.global.framework is required`);
|
|
328
349
|
}
|
|
@@ -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.
|
|
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"));
|
|
@@ -343,8 +347,10 @@ function findWorkspaceAnchor(startDir = process.cwd()) {
|
|
|
343
347
|
try {
|
|
344
348
|
meta = readTmpFile(candidate);
|
|
345
349
|
} catch {
|
|
346
|
-
|
|
350
|
+
meta = readBrokenWorkspaceTmpMeta(candidate);
|
|
347
351
|
}
|
|
352
|
+
if (!meta)
|
|
353
|
+
continue;
|
|
348
354
|
if (meta.globalType !== "workspace" /* WORKSPACE */)
|
|
349
355
|
continue;
|
|
350
356
|
try {
|
|
@@ -363,6 +369,50 @@ function findWorkspaceAnchor(startDir = process.cwd()) {
|
|
|
363
369
|
}
|
|
364
370
|
return null;
|
|
365
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
|
+
}
|
|
366
416
|
function listShallowTmpCandidates(dir) {
|
|
367
417
|
const out = [];
|
|
368
418
|
const direct = path4.join(dir, TMP_FILE);
|
|
@@ -447,7 +497,7 @@ function resolveRepoRootFromTmpMeta(tmpPath, meta) {
|
|
|
447
497
|
}
|
|
448
498
|
function scanWorkspaceProjects(workspaceRoot) {
|
|
449
499
|
const outerTmp = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
450
|
-
const wsMeta =
|
|
500
|
+
const wsMeta = readWorkspaceTmpMeta(outerTmp ?? path4.join(workspaceRoot, TMP_FILE));
|
|
451
501
|
const fsMap = wsMeta.folderStructure;
|
|
452
502
|
const entries = [];
|
|
453
503
|
const mismatches = [];
|
|
@@ -490,6 +540,8 @@ function scanWorkspaceProjects(workspaceRoot) {
|
|
|
490
540
|
}
|
|
491
541
|
continue;
|
|
492
542
|
}
|
|
543
|
+
if (kind !== "api-service" /* API_SERVICE */ && kind !== "frontend" /* FRONTEND */)
|
|
544
|
+
continue;
|
|
493
545
|
const key = `${kind}:${name}`;
|
|
494
546
|
if (seen.has(key))
|
|
495
547
|
continue;
|
|
@@ -551,22 +603,127 @@ function ensureWorkspaceSlotDirs(workspaceRoot) {
|
|
|
551
603
|
}
|
|
552
604
|
return created;
|
|
553
605
|
}
|
|
554
|
-
function
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
|
|
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 = [];
|
|
561
623
|
const defaultMs = packageDefaults.tmpWatchDefaults.intervalMs;
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
if (
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
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;
|
|
570
727
|
}
|
|
571
728
|
var readWorkspaceCoreTmp = readWorkspaceGlobalTmp;
|
|
572
729
|
function workspaceTmpTemplate(projectName) {
|
|
@@ -581,7 +738,7 @@ configs:
|
|
|
581
738
|
tmp: tmp.yml
|
|
582
739
|
options:
|
|
583
740
|
fileWatchIntervalMs: 500
|
|
584
|
-
|
|
741
|
+
slots:
|
|
585
742
|
api: api
|
|
586
743
|
web: web
|
|
587
744
|
mobile: mobile
|
|
@@ -600,11 +757,14 @@ export {
|
|
|
600
757
|
resolveWorkspaceOuterTmp,
|
|
601
758
|
resolveRepoRootFromTmpMeta,
|
|
602
759
|
resolveEntryPath,
|
|
760
|
+
readWorkspaceTmpMeta,
|
|
603
761
|
readWorkspaceGlobalTmp,
|
|
604
762
|
readWorkspaceCoreTmp,
|
|
605
763
|
readTmpFile,
|
|
764
|
+
readBrokenWorkspaceTmpMeta,
|
|
606
765
|
parseFolderStructure,
|
|
607
766
|
normalizeGlobalType,
|
|
767
|
+
healWorkspaceOuterTmpStructure,
|
|
608
768
|
healWorkspaceOuterTmpOptions,
|
|
609
769
|
formatSlotMismatch,
|
|
610
770
|
findWorkspaceRoot,
|
|
@@ -56,8 +56,13 @@ export function resolveProjectContext(startDir = process.cwd()) {
|
|
|
56
56
|
package: readProjectPackageJson(coreRoot),
|
|
57
57
|
core: { cli: cliVersion, declared: cliVersion, installed: cliVersion, isGlobalLibrary: true },
|
|
58
58
|
workspaceEntries: [],
|
|
59
|
+
slotMismatches: [],
|
|
60
|
+
selfEntry: null,
|
|
61
|
+
selfMismatch: null,
|
|
62
|
+
schemaVersionExpected: TMP_SCHEMA_VERSION,
|
|
59
63
|
hints: [
|
|
60
64
|
'Global runtime library — publish via xry tag',
|
|
65
|
+
'tmp global.type: core-library (not workspace / not api-service)',
|
|
61
66
|
'Consumers: bun add @xrystal/core && xry tmp in their repo',
|
|
62
67
|
],
|
|
63
68
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ensureWorkspaceSlotDirs,
|
|
3
|
-
|
|
3
|
+
healWorkspaceOuterTmpStructure,
|
|
4
|
+
resolveWorkspaceOuterTmp,
|
|
4
5
|
} from './workspace-resolve.mjs'
|
|
5
6
|
import { healRegistryAtPath } from './xrystal-registry.mjs'
|
|
6
7
|
import { ensureOuterWorkspaceTmp } from './workspace-tmp.mjs'
|
|
7
8
|
import { ensureWatchDaemon } from './xrystal-watch-spawn.mjs'
|
|
9
|
+
import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
|
-
* Workspace self-heal:
|
|
12
|
+
* Workspace self-heal: outer tmp structure, slot dirs, ~/.xrystal registry.
|
|
11
13
|
* Runs automatically on sync / project context — no explicit CLI flag required.
|
|
12
14
|
*/
|
|
13
15
|
export function runWorkspaceSelfHeal(workspaceRoot, {
|
|
@@ -16,12 +18,20 @@ export function runWorkspaceSelfHeal(workspaceRoot, {
|
|
|
16
18
|
forceRegistry = false,
|
|
17
19
|
ensureDaemon = true,
|
|
18
20
|
} = {}) {
|
|
21
|
+
let ensuredPath = null
|
|
19
22
|
if (ensureTmp) {
|
|
20
|
-
ensureOuterWorkspaceTmp(workspaceRoot)
|
|
23
|
+
ensuredPath = ensureOuterWorkspaceTmp(workspaceRoot).tmpFilePath
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Structural heal must run even when discovery could not resolve outer tmp yet.
|
|
27
|
+
const outerTmpHeal = healWorkspaceOuterTmpStructure(workspaceRoot)
|
|
28
|
+
const outerTmpPath = resolveWorkspaceOuterTmp(workspaceRoot) ?? ensuredPath
|
|
29
|
+
let schemaPatched = false
|
|
30
|
+
if (outerTmpPath) {
|
|
31
|
+
schemaPatched = ensureTmpSchemaVersion(outerTmpPath).patched
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
const slotDirsCreated = ensureWorkspaceSlotDirs(workspaceRoot)
|
|
24
|
-
const tmpOptionsPatched = healWorkspaceOuterTmpOptions(workspaceRoot)
|
|
25
35
|
|
|
26
36
|
let registryChanged = false
|
|
27
37
|
if (healRegistry) {
|
|
@@ -32,5 +42,11 @@ export function runWorkspaceSelfHeal(workspaceRoot, {
|
|
|
32
42
|
ensureWatchDaemon({ quiet: true })
|
|
33
43
|
}
|
|
34
44
|
|
|
35
|
-
return {
|
|
45
|
+
return {
|
|
46
|
+
slotDirsCreated,
|
|
47
|
+
outerTmpHeal,
|
|
48
|
+
tmpOptionsPatched: outerTmpHeal.changed,
|
|
49
|
+
schemaPatched,
|
|
50
|
+
registryChanged,
|
|
51
|
+
}
|
|
36
52
|
}
|
|
@@ -11,18 +11,22 @@ import { runWorkspaceSelfHeal } from './workspace-heal.mjs'
|
|
|
11
11
|
|
|
12
12
|
export function ensureOuterWorkspaceTmp(workspaceRoot, { projectName } = {}) {
|
|
13
13
|
const resolved = path.resolve(workspaceRoot)
|
|
14
|
-
|
|
15
|
-
let tmpPath = existing
|
|
14
|
+
let tmpPath = resolveWorkspaceOuterTmp(resolved)
|
|
16
15
|
let created = false
|
|
17
16
|
|
|
18
17
|
if (!tmpPath) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const fallback = path.join(resolved, 'tmp.yml')
|
|
19
|
+
if (fs.existsSync(fallback)) {
|
|
20
|
+
// Broken outer tmp (e.g. legacy admin slot) — keep file for structural heal.
|
|
21
|
+
tmpPath = fallback
|
|
22
|
+
} else {
|
|
23
|
+
tmpPath = fallback
|
|
24
|
+
const name = projectName ?? workspaceProjectName(resolved)
|
|
25
|
+
fs.writeFileSync(tmpPath, workspaceTmpTemplate(name))
|
|
26
|
+
created = true
|
|
27
|
+
}
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
const schema = ensureTmpSchemaVersion(tmpPath)
|
|
26
|
-
runWorkspaceSelfHeal(resolved, { ensureTmp: false })
|
|
27
31
|
return { tmpFilePath: tmpPath, created, schema, workspaceRoot: resolved }
|
|
28
32
|
}
|
|
@@ -29,6 +29,13 @@ export function resolveLoaderBootPlan(configs) {
|
|
|
29
29
|
infra: { ...WORKSPACE_INFRA_DEFAULTS },
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
if (type === GlobalTypeEnum.CORE_LIBRARY) {
|
|
33
|
+
return {
|
|
34
|
+
profile: LoaderBootProfileEnum.MINIMAL,
|
|
35
|
+
projectType: type,
|
|
36
|
+
infra: createInfraLoaderFlags(),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
32
39
|
if (type === GlobalTypeEnum.API_SERVICE) {
|
|
33
40
|
return {
|
|
34
41
|
profile: LoaderBootProfileEnum.API_SERVICE,
|
|
@@ -24,6 +24,8 @@ export function normalizeGlobalType(value) {
|
|
|
24
24
|
return GlobalTypeEnum.API_SERVICE;
|
|
25
25
|
if (raw === GlobalTypeEnum.FRONTEND)
|
|
26
26
|
return GlobalTypeEnum.FRONTEND;
|
|
27
|
+
if (raw === GlobalTypeEnum.CORE_LIBRARY)
|
|
28
|
+
return GlobalTypeEnum.CORE_LIBRARY;
|
|
27
29
|
throw new Error(`${defaults.packageName}: configs.global.type must be one of ${Object.values(GlobalTypeEnum).join('|')} (got "${String(value)}")`);
|
|
28
30
|
}
|
|
29
31
|
export function normalizeRuntime(value) {
|
|
@@ -120,6 +122,23 @@ function readWorkspaceGlobalBlock(global) {
|
|
|
120
122
|
: undefined,
|
|
121
123
|
};
|
|
122
124
|
}
|
|
125
|
+
function readCoreLibraryGlobalBlock(global, configs) {
|
|
126
|
+
const varsRaw = isRecord(global.vars) ? global.vars : {};
|
|
127
|
+
const runtimeRaw = typeof global.runtime === 'string' ? global.runtime.trim() : '';
|
|
128
|
+
return {
|
|
129
|
+
type: GlobalTypeEnum.CORE_LIBRARY,
|
|
130
|
+
runtime: runtimeRaw ? normalizeRuntime(runtimeRaw) : RuntimeEnum.BUN,
|
|
131
|
+
framework: typeof global.framework === 'string' ? global.framework.trim() : '',
|
|
132
|
+
paths: readTmpGlobalPathsBlock(configs),
|
|
133
|
+
vars: { ...varsRaw },
|
|
134
|
+
build: isRecord(global.build) ? { ...global.build } : undefined,
|
|
135
|
+
options: isRecord(global.options)
|
|
136
|
+
? {
|
|
137
|
+
fileWatchIntervalMs: readWatchIntervalValue(global.options.fileWatchIntervalMs),
|
|
138
|
+
}
|
|
139
|
+
: undefined,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
123
142
|
export function readTmpGlobalBlock(configs) {
|
|
124
143
|
const global = isRecord(configs?.global) ? configs.global : {};
|
|
125
144
|
const varsRaw = isRecord(global.vars) ? global.vars : {};
|
|
@@ -128,6 +147,9 @@ export function readTmpGlobalBlock(configs) {
|
|
|
128
147
|
if (type === GlobalTypeEnum.WORKSPACE) {
|
|
129
148
|
return readWorkspaceGlobalBlock(global);
|
|
130
149
|
}
|
|
150
|
+
if (type === GlobalTypeEnum.CORE_LIBRARY) {
|
|
151
|
+
return readCoreLibraryGlobalBlock(global, configs);
|
|
152
|
+
}
|
|
131
153
|
if (typeof global.framework !== 'string' || !global.framework.trim()) {
|
|
132
154
|
throw new Error(`${defaults.packageName}: configs.global.framework is required`);
|
|
133
155
|
}
|
|
@@ -58,6 +58,9 @@ export type WorkspaceAnchor = {
|
|
|
58
58
|
* always derived from that file's configs.global.paths — never hardcoded.
|
|
59
59
|
*/
|
|
60
60
|
export declare function findWorkspaceAnchor(startDir?: string): WorkspaceAnchor | null;
|
|
61
|
+
/** Best-effort workspace meta when folder-structure is broken (e.g. legacy admin slot). */
|
|
62
|
+
export declare function readBrokenWorkspaceTmpMeta(filePath: string): TmpMeta | null;
|
|
63
|
+
export declare function readWorkspaceTmpMeta(filePath: string): TmpMeta;
|
|
61
64
|
/** Relative tmp path from project root, driven only by configs.global.paths. */
|
|
62
65
|
export declare function buildRepoTmpRelPath(meta: Pick<TmpMeta, 'pathsRoot' | 'pathsTmp' | 'globalType'>): string;
|
|
63
66
|
/** Project/workspace root = tmp file location minus paths.root/paths.tmp. */
|
|
@@ -75,7 +78,18 @@ export declare function readWorkspaceGlobalTmp(workspaceRoot: string): {
|
|
|
75
78
|
};
|
|
76
79
|
/** Ensure api/web/mobile (or custom folder-structure paths) exist on disk. */
|
|
77
80
|
export declare function ensureWorkspaceSlotDirs(workspaceRoot: string): string[];
|
|
78
|
-
|
|
81
|
+
export type OuterTmpHealResult = {
|
|
82
|
+
changed: boolean;
|
|
83
|
+
notes: string[];
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Heal outer workspace tmp structure on sync/project:
|
|
87
|
+
* slots (api/web/mobile), global.paths, options.fileWatchIntervalMs, end.version.
|
|
88
|
+
* Migrates legacy configs.folder-structure → configs.slots.
|
|
89
|
+
* Does not overwrite existing custom slot folder names.
|
|
90
|
+
*/
|
|
91
|
+
export declare function healWorkspaceOuterTmpStructure(workspaceRoot: string): OuterTmpHealResult;
|
|
92
|
+
/** @deprecated use healWorkspaceOuterTmpStructure */
|
|
79
93
|
export declare function healWorkspaceOuterTmpOptions(workspaceRoot: string): boolean;
|
|
80
94
|
/** @deprecated */ export declare const readWorkspaceCoreTmp: typeof readWorkspaceGlobalTmp;
|
|
81
95
|
export declare function workspaceTmpTemplate(projectName: string): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import yaml from 'yaml';
|
|
3
4
|
import { GlobalTypeEnum, WorkspaceSlotEnum } from '../../../utils/models/enums/index.js';
|
|
4
5
|
import { packageDefaults } from '../../../utils/constants/index.js';
|
|
5
6
|
import { normalizeGlobalType } from '../../../utils/helpers/tmp/tmp-schema.js';
|
|
@@ -43,9 +44,12 @@ export function readTmpFile(filePath) {
|
|
|
43
44
|
return out;
|
|
44
45
|
}
|
|
45
46
|
export function parseFolderStructure(text) {
|
|
46
|
-
|
|
47
|
+
// Canonical key: configs.slots — legacy alias: configs.folder-structure
|
|
48
|
+
const fsBlock = text.match(/(?:^|\n)[ \t]*slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
49
|
+
?? text.match(/(?:^|\n)[ \t]*folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
50
|
+
?? '';
|
|
47
51
|
if (/^[ \t]+admin:/m.test(fsBlock)) {
|
|
48
|
-
throw new Error('configs.
|
|
52
|
+
throw new Error('configs.slots.admin removed — put admin panels under web/ (e.g. web/admin-ui)');
|
|
49
53
|
}
|
|
50
54
|
const readSlot = (key) => {
|
|
51
55
|
const scalar = fsBlock.match(new RegExp(`^[ \\t]+${key}:\\s*(.+?)(?:\\s+#.*)?$`, 'm'));
|
|
@@ -138,8 +142,10 @@ export function findWorkspaceAnchor(startDir = process.cwd()) {
|
|
|
138
142
|
meta = readTmpFile(candidate);
|
|
139
143
|
}
|
|
140
144
|
catch {
|
|
141
|
-
|
|
145
|
+
meta = readBrokenWorkspaceTmpMeta(candidate);
|
|
142
146
|
}
|
|
147
|
+
if (!meta)
|
|
148
|
+
continue;
|
|
143
149
|
if (meta.globalType !== GlobalTypeEnum.WORKSPACE)
|
|
144
150
|
continue;
|
|
145
151
|
try {
|
|
@@ -159,6 +165,57 @@ export function findWorkspaceAnchor(startDir = process.cwd()) {
|
|
|
159
165
|
}
|
|
160
166
|
return null;
|
|
161
167
|
}
|
|
168
|
+
/** Best-effort workspace meta when folder-structure is broken (e.g. legacy admin slot). */
|
|
169
|
+
export function readBrokenWorkspaceTmpMeta(filePath) {
|
|
170
|
+
if (!fs.existsSync(filePath))
|
|
171
|
+
return null;
|
|
172
|
+
let text;
|
|
173
|
+
try {
|
|
174
|
+
text = fs.readFileSync(filePath, 'utf8');
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const typeMatch = text.match(/global:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+type:\s*(.+?)\s*(?:#.*)?$/m);
|
|
180
|
+
if (!typeMatch || parseScalar(typeMatch[1]) !== GlobalTypeEnum.WORKSPACE)
|
|
181
|
+
return null;
|
|
182
|
+
const out = {
|
|
183
|
+
path: filePath,
|
|
184
|
+
globalType: GlobalTypeEnum.WORKSPACE,
|
|
185
|
+
folderStructure: { ...DEFAULT_FOLDER_STRUCTURE },
|
|
186
|
+
};
|
|
187
|
+
const projectMatch = text.match(/^project:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+name:\s*(.+?)\s*(?:#.*)?$/m)
|
|
188
|
+
?? text.match(/^project:\s*\n[ \t]+name:\s*(.+?)\s*(?:#.*)?$/m);
|
|
189
|
+
if (projectMatch)
|
|
190
|
+
out.projectName = parseScalar(projectMatch[1]);
|
|
191
|
+
const rootBlock = text.match(/paths:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+root:\s*(.+?)\s*(?:#.*)?$/m);
|
|
192
|
+
if (rootBlock)
|
|
193
|
+
out.pathsRoot = parseScalar(rootBlock[1]);
|
|
194
|
+
const tmpBlock = text.match(/paths:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+tmp:\s*(.+?)\s*(?:#.*)?$/m);
|
|
195
|
+
if (tmpBlock)
|
|
196
|
+
out.pathsTmp = parseScalar(tmpBlock[1]);
|
|
197
|
+
// Preserve known good slot folder names even when admin is present.
|
|
198
|
+
const fsBlock = text.match(/(?:^|\n)[ \t]*slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
199
|
+
?? text.match(/(?:^|\n)[ \t]*folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
200
|
+
?? '';
|
|
201
|
+
for (const slot of [WorkspaceSlotEnum.API, WorkspaceSlotEnum.WEB, WorkspaceSlotEnum.MOBILE]) {
|
|
202
|
+
const scalar = fsBlock.match(new RegExp(`^[ \\t]+${slot}:\\s*(.+?)(?:\\s+#.*)?$`, 'm'));
|
|
203
|
+
if (scalar)
|
|
204
|
+
out.folderStructure[slot] = parseScalar(scalar[1]);
|
|
205
|
+
}
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
export function readWorkspaceTmpMeta(filePath) {
|
|
209
|
+
try {
|
|
210
|
+
return readTmpFile(filePath);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
const broken = readBrokenWorkspaceTmpMeta(filePath);
|
|
214
|
+
if (broken)
|
|
215
|
+
return broken;
|
|
216
|
+
throw new Error(`Unable to read workspace tmp: ${filePath}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
162
219
|
/** tmp.yml directly under dir, or one level down (paths.root folder). */
|
|
163
220
|
function listShallowTmpCandidates(dir) {
|
|
164
221
|
const out = [];
|
|
@@ -249,7 +306,7 @@ export function resolveRepoRootFromTmpMeta(tmpPath, meta) {
|
|
|
249
306
|
}
|
|
250
307
|
export function scanWorkspaceProjects(workspaceRoot) {
|
|
251
308
|
const outerTmp = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
252
|
-
const wsMeta =
|
|
309
|
+
const wsMeta = readWorkspaceTmpMeta(outerTmp ?? path.join(workspaceRoot, TMP_FILE));
|
|
253
310
|
const fsMap = wsMeta.folderStructure;
|
|
254
311
|
const entries = [];
|
|
255
312
|
const mismatches = [];
|
|
@@ -293,6 +350,8 @@ export function scanWorkspaceProjects(workspaceRoot) {
|
|
|
293
350
|
}
|
|
294
351
|
continue;
|
|
295
352
|
}
|
|
353
|
+
if (kind !== GlobalTypeEnum.API_SERVICE && kind !== GlobalTypeEnum.FRONTEND)
|
|
354
|
+
continue;
|
|
296
355
|
const key = `${kind}:${name}`;
|
|
297
356
|
if (seen.has(key))
|
|
298
357
|
continue;
|
|
@@ -358,21 +417,143 @@ export function ensureWorkspaceSlotDirs(workspaceRoot) {
|
|
|
358
417
|
}
|
|
359
418
|
return created;
|
|
360
419
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
420
|
+
function isPlainObject(value) {
|
|
421
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Heal outer workspace tmp structure on sync/project:
|
|
425
|
+
* slots (api/web/mobile), global.paths, options.fileWatchIntervalMs, end.version.
|
|
426
|
+
* Migrates legacy configs.folder-structure → configs.slots.
|
|
427
|
+
* Does not overwrite existing custom slot folder names.
|
|
428
|
+
*/
|
|
429
|
+
export function healWorkspaceOuterTmpStructure(workspaceRoot) {
|
|
430
|
+
const resolvedRoot = path.resolve(workspaceRoot);
|
|
431
|
+
const tmpPath = resolveWorkspaceOuterTmp(resolvedRoot)
|
|
432
|
+
?? (fs.existsSync(path.join(resolvedRoot, TMP_FILE)) ? path.join(resolvedRoot, TMP_FILE) : null);
|
|
433
|
+
if (!tmpPath || !fs.existsSync(tmpPath))
|
|
434
|
+
return { changed: false, notes: [] };
|
|
435
|
+
const raw = fs.readFileSync(tmpPath, 'utf8');
|
|
436
|
+
let doc;
|
|
437
|
+
try {
|
|
438
|
+
const parsed = yaml.parse(raw);
|
|
439
|
+
doc = isPlainObject(parsed) ? parsed : {};
|
|
440
|
+
}
|
|
441
|
+
catch {
|
|
442
|
+
return { changed: false, notes: [] };
|
|
443
|
+
}
|
|
444
|
+
const notes = [];
|
|
369
445
|
const defaultMs = packageDefaults.tmpWatchDefaults.intervalMs;
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
446
|
+
const schemaVersion = packageDefaults.tmpSchemaVersion ?? 1;
|
|
447
|
+
if (!isPlainObject(doc.project)) {
|
|
448
|
+
doc.project = { name: path.basename(workspaceRoot) };
|
|
449
|
+
notes.push('project');
|
|
450
|
+
}
|
|
451
|
+
else if (typeof doc.project.name !== 'string' || !doc.project.name.trim()) {
|
|
452
|
+
doc.project.name = path.basename(workspaceRoot);
|
|
453
|
+
notes.push('project.name');
|
|
454
|
+
}
|
|
455
|
+
if (!isPlainObject(doc.configs)) {
|
|
456
|
+
doc.configs = {};
|
|
457
|
+
notes.push('configs');
|
|
458
|
+
}
|
|
459
|
+
const configs = doc.configs;
|
|
460
|
+
if (!isPlainObject(configs.global)) {
|
|
461
|
+
configs.global = {};
|
|
462
|
+
notes.push('configs.global');
|
|
463
|
+
}
|
|
464
|
+
const global = configs.global;
|
|
465
|
+
if (global.type !== GlobalTypeEnum.WORKSPACE) {
|
|
466
|
+
global.type = GlobalTypeEnum.WORKSPACE;
|
|
467
|
+
notes.push('global.type');
|
|
468
|
+
}
|
|
469
|
+
if (!isPlainObject(global.paths)) {
|
|
470
|
+
global.paths = { root: '.', tmp: 'tmp.yml' };
|
|
471
|
+
notes.push('global.paths');
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
const paths = global.paths;
|
|
475
|
+
if (typeof paths.root !== 'string' || !paths.root.trim()) {
|
|
476
|
+
paths.root = '.';
|
|
477
|
+
notes.push('global.paths.root');
|
|
478
|
+
}
|
|
479
|
+
if (typeof paths.tmp !== 'string' || !paths.tmp.trim()) {
|
|
480
|
+
paths.tmp = 'tmp.yml';
|
|
481
|
+
notes.push('global.paths.tmp');
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (!isPlainObject(global.options)) {
|
|
485
|
+
global.options = { fileWatchIntervalMs: defaultMs };
|
|
486
|
+
notes.push('global.options');
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
const options = global.options;
|
|
490
|
+
if (options.fileWatchIntervalMs == null || options.fileWatchIntervalMs === '') {
|
|
491
|
+
options.fileWatchIntervalMs = defaultMs;
|
|
492
|
+
notes.push('global.options.fileWatchIntervalMs');
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
const slotsKey = 'slots';
|
|
496
|
+
const legacyKey = 'folder-structure';
|
|
497
|
+
let slotsMap;
|
|
498
|
+
if (isPlainObject(configs[slotsKey])) {
|
|
499
|
+
slotsMap = configs[slotsKey];
|
|
500
|
+
}
|
|
501
|
+
else if (isPlainObject(configs[legacyKey])) {
|
|
502
|
+
slotsMap = { ...configs[legacyKey] };
|
|
503
|
+
configs[slotsKey] = slotsMap;
|
|
504
|
+
delete configs[legacyKey];
|
|
505
|
+
notes.push('folder-structure → slots');
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
slotsMap = { ...DEFAULT_FOLDER_STRUCTURE };
|
|
509
|
+
configs[slotsKey] = slotsMap;
|
|
510
|
+
notes.push('slots');
|
|
511
|
+
}
|
|
512
|
+
if ('admin' in slotsMap) {
|
|
513
|
+
delete slotsMap.admin;
|
|
514
|
+
notes.push('slots.admin removed');
|
|
515
|
+
}
|
|
516
|
+
for (const slot of [
|
|
517
|
+
WorkspaceSlotEnum.API,
|
|
518
|
+
WorkspaceSlotEnum.WEB,
|
|
519
|
+
WorkspaceSlotEnum.MOBILE,
|
|
520
|
+
]) {
|
|
521
|
+
const value = slotsMap[slot];
|
|
522
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
523
|
+
slotsMap[slot] = DEFAULT_FOLDER_STRUCTURE[slot];
|
|
524
|
+
notes.push(`slots.${slot}`);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
// Drop leftover legacy key if both somehow exist
|
|
528
|
+
if (legacyKey in configs && slotsKey in configs) {
|
|
529
|
+
delete configs[legacyKey];
|
|
530
|
+
if (!notes.includes('folder-structure → slots')) {
|
|
531
|
+
notes.push('folder-structure removed');
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (!isPlainObject(doc.end)) {
|
|
535
|
+
doc.end = { version: schemaVersion };
|
|
536
|
+
notes.push('end');
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
const end = doc.end;
|
|
540
|
+
if (end.version == null || end.version === '') {
|
|
541
|
+
end.version = schemaVersion;
|
|
542
|
+
notes.push('end.version');
|
|
543
|
+
}
|
|
544
|
+
else if (typeof end.version === 'string' && /^\d+$/.test(end.version.trim())) {
|
|
545
|
+
end.version = Number(end.version);
|
|
546
|
+
notes.push('end.version type');
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (notes.length === 0)
|
|
550
|
+
return { changed: false, notes: [] };
|
|
551
|
+
fs.writeFileSync(tmpPath, `${yaml.stringify(doc).trimEnd()}\n`);
|
|
552
|
+
return { changed: true, notes };
|
|
553
|
+
}
|
|
554
|
+
/** @deprecated use healWorkspaceOuterTmpStructure */
|
|
555
|
+
export function healWorkspaceOuterTmpOptions(workspaceRoot) {
|
|
556
|
+
return healWorkspaceOuterTmpStructure(workspaceRoot).changed;
|
|
376
557
|
}
|
|
377
558
|
/** @deprecated */ export const readWorkspaceCoreTmp = readWorkspaceGlobalTmp;
|
|
378
559
|
export function workspaceTmpTemplate(projectName) {
|
|
@@ -387,7 +568,7 @@ configs:
|
|
|
387
568
|
tmp: tmp.yml
|
|
388
569
|
options:
|
|
389
570
|
fileWatchIntervalMs: 500
|
|
390
|
-
|
|
571
|
+
slots:
|
|
391
572
|
api: api
|
|
392
573
|
web: web
|
|
393
574
|
mobile: mobile
|
|
@@ -24,7 +24,9 @@ export declare enum FrameworkEnum {
|
|
|
24
24
|
export declare enum GlobalTypeEnum {
|
|
25
25
|
WORKSPACE = "workspace",
|
|
26
26
|
API_SERVICE = "api-service",
|
|
27
|
-
FRONTEND = "frontend"
|
|
27
|
+
FRONTEND = "frontend",
|
|
28
|
+
/** @xrystal/core package source — layout/build only, not a runnable service or workspace. */
|
|
29
|
+
CORE_LIBRARY = "core-library"
|
|
28
30
|
}
|
|
29
31
|
/** Runtime loader boot profile derived from tmp global.type (+ minimal fallback). */
|
|
30
32
|
export declare enum LoaderBootProfileEnum {
|
|
@@ -46,7 +48,7 @@ export declare enum ProjectScopeKindEnum {
|
|
|
46
48
|
WORKSPACE_SERVICE = "workspace-service",
|
|
47
49
|
STANDALONE_SERVICE = "standalone-service"
|
|
48
50
|
}
|
|
49
|
-
/** Workspace
|
|
51
|
+
/** Workspace slots (outer tmp.yml configs.slots — legacy: folder-structure). */
|
|
50
52
|
export declare enum WorkspaceSlotEnum {
|
|
51
53
|
API = "api",
|
|
52
54
|
WEB = "web",
|
|
@@ -29,6 +29,8 @@ export var GlobalTypeEnum;
|
|
|
29
29
|
GlobalTypeEnum["WORKSPACE"] = "workspace";
|
|
30
30
|
GlobalTypeEnum["API_SERVICE"] = "api-service";
|
|
31
31
|
GlobalTypeEnum["FRONTEND"] = "frontend";
|
|
32
|
+
/** @xrystal/core package source — layout/build only, not a runnable service or workspace. */
|
|
33
|
+
GlobalTypeEnum["CORE_LIBRARY"] = "core-library";
|
|
32
34
|
})(GlobalTypeEnum || (GlobalTypeEnum = {}));
|
|
33
35
|
/** Runtime loader boot profile derived from tmp global.type (+ minimal fallback). */
|
|
34
36
|
export var LoaderBootProfileEnum;
|
|
@@ -53,7 +55,7 @@ export var ProjectScopeKindEnum;
|
|
|
53
55
|
ProjectScopeKindEnum["WORKSPACE_SERVICE"] = "workspace-service";
|
|
54
56
|
ProjectScopeKindEnum["STANDALONE_SERVICE"] = "standalone-service";
|
|
55
57
|
})(ProjectScopeKindEnum || (ProjectScopeKindEnum = {}));
|
|
56
|
-
/** Workspace
|
|
58
|
+
/** Workspace slots (outer tmp.yml configs.slots — legacy: folder-structure). */
|
|
57
59
|
export var WorkspaceSlotEnum;
|
|
58
60
|
(function (WorkspaceSlotEnum) {
|
|
59
61
|
WorkspaceSlotEnum["API"] = "api";
|