@xrystal/core 3.55.9 → 3.55.11
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 +33 -9
- package/x/bin/helpers/.generated/tmp-schema.mjs +21 -0
- package/x/bin/helpers/.generated/user-home-registry.mjs +56 -4
- package/x/bin/helpers/.generated/workspace.mjs +195 -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 +228 -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, readTmpFile, 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)`))
|
|
@@ -59,8 +73,18 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
59
73
|
|
|
60
74
|
if (scope.entries.length === 0) {
|
|
61
75
|
console.log(chalk.yellow('\n no projects to sync'))
|
|
62
|
-
if (scope.mode === 'workspace-all') {
|
|
63
|
-
|
|
76
|
+
if (scope.mode === 'workspace-all' && scope.workspaceRoot) {
|
|
77
|
+
let slotHint = 'api/ web/ mobile/'
|
|
78
|
+
try {
|
|
79
|
+
const wsTmp = resolveWorkspaceOuterTmp(scope.workspaceRoot)
|
|
80
|
+
if (wsTmp) {
|
|
81
|
+
const folders = Object.values(readTmpFile(wsTmp).folderStructure)
|
|
82
|
+
if (folders.length) slotHint = folders.map((f) => `${f}/`).join(' ')
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
// keep default hint
|
|
86
|
+
}
|
|
87
|
+
console.log(chalk.gray(` link services under ${slotHint} then re-run`))
|
|
64
88
|
}
|
|
65
89
|
printCommandFooter({ version: coreVersion })
|
|
66
90
|
return
|
|
@@ -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
|
}
|
|
@@ -6,6 +6,7 @@ import path5 from "node:path";
|
|
|
6
6
|
// source/utils/helpers/workspace/index.ts
|
|
7
7
|
import fs2 from "node:fs";
|
|
8
8
|
import path4 from "node:path";
|
|
9
|
+
import yaml2 from "yaml";
|
|
9
10
|
|
|
10
11
|
// source/utils/models/enums/index.ts
|
|
11
12
|
var GlobalTypeEnum;
|
|
@@ -13,6 +14,7 @@ var GlobalTypeEnum;
|
|
|
13
14
|
GlobalTypeEnum2["WORKSPACE"] = "workspace";
|
|
14
15
|
GlobalTypeEnum2["API_SERVICE"] = "api-service";
|
|
15
16
|
GlobalTypeEnum2["FRONTEND"] = "frontend";
|
|
17
|
+
GlobalTypeEnum2["CORE_LIBRARY"] = "core-library";
|
|
16
18
|
})(GlobalTypeEnum ||= {});
|
|
17
19
|
|
|
18
20
|
// source/utils/constants/index.ts
|
|
@@ -220,6 +222,8 @@ function normalizeGlobalType(value) {
|
|
|
220
222
|
return "api-service" /* API_SERVICE */;
|
|
221
223
|
if (raw === "frontend" /* FRONTEND */)
|
|
222
224
|
return "frontend" /* FRONTEND */;
|
|
225
|
+
if (raw === "core-library" /* CORE_LIBRARY */)
|
|
226
|
+
return "core-library" /* CORE_LIBRARY */;
|
|
223
227
|
throw new Error(`${defaults_default.packageName}: configs.global.type must be one of ${Object.values(GlobalTypeEnum).join("|")} (got "${String(value)}")`);
|
|
224
228
|
}
|
|
225
229
|
|
|
@@ -262,9 +266,9 @@ function readTmpFile(filePath) {
|
|
|
262
266
|
return out;
|
|
263
267
|
}
|
|
264
268
|
function parseFolderStructure(text) {
|
|
265
|
-
const fsBlock = text.match(/folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? "";
|
|
269
|
+
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] ?? text.match(/(?:^|\n)slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? text.match(/(?:^|\n)folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? "";
|
|
266
270
|
if (/^[ \t]+admin:/m.test(fsBlock)) {
|
|
267
|
-
throw new Error("configs.
|
|
271
|
+
throw new Error("configs.slots.admin removed — put admin panels under web/ (e.g. web/admin-ui)");
|
|
268
272
|
}
|
|
269
273
|
const readSlot = (key) => {
|
|
270
274
|
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] ?? text.match(/(?:^|\n)slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? text.match(/(?:^|\n)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;
|
|
@@ -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] ?? text.match(/(?:^|\n)slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? text.match(/(?:^|\n)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] ?? text.match(/(?:^|\n)slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? text.match(/(?:^|\n)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,142 @@ 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
|
+
const topLevelSlots = isPlainObject(doc[slotsKey]) ? doc[slotsKey] : isPlainObject(doc[legacyKey]) ? doc[legacyKey] : null;
|
|
673
|
+
let slotsMap;
|
|
674
|
+
if (isPlainObject(configs[slotsKey])) {
|
|
675
|
+
slotsMap = configs[slotsKey];
|
|
676
|
+
} else if (isPlainObject(configs[legacyKey])) {
|
|
677
|
+
slotsMap = { ...configs[legacyKey] };
|
|
678
|
+
configs[slotsKey] = slotsMap;
|
|
679
|
+
delete configs[legacyKey];
|
|
680
|
+
notes.push("folder-structure → slots");
|
|
681
|
+
} else {
|
|
682
|
+
slotsMap = topLevelSlots ? {} : { ...DEFAULT_FOLDER_STRUCTURE };
|
|
683
|
+
configs[slotsKey] = slotsMap;
|
|
684
|
+
notes.push(topLevelSlots ? "top-level slots → configs.slots" : "slots");
|
|
685
|
+
}
|
|
686
|
+
if (topLevelSlots) {
|
|
687
|
+
for (const [key, value] of Object.entries(topLevelSlots)) {
|
|
688
|
+
if (typeof value === "string" && value.trim()) {
|
|
689
|
+
slotsMap[key] = value.trim();
|
|
690
|
+
} else if (value !== undefined) {
|
|
691
|
+
slotsMap[key] = value;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
delete doc[slotsKey];
|
|
695
|
+
delete doc[legacyKey];
|
|
696
|
+
if (!notes.includes("top-level slots → configs.slots")) {
|
|
697
|
+
notes.push("top-level slots → configs.slots");
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if ("admin" in slotsMap) {
|
|
701
|
+
delete slotsMap.admin;
|
|
702
|
+
notes.push("slots.admin removed");
|
|
703
|
+
}
|
|
704
|
+
for (const slot of [
|
|
705
|
+
"api" /* API */,
|
|
706
|
+
"web" /* WEB */,
|
|
707
|
+
"mobile" /* MOBILE */
|
|
708
|
+
]) {
|
|
709
|
+
const value = slotsMap[slot];
|
|
710
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
711
|
+
slotsMap[slot] = DEFAULT_FOLDER_STRUCTURE[slot];
|
|
712
|
+
notes.push(`slots.${slot}`);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
if (legacyKey in configs && slotsKey in configs) {
|
|
716
|
+
delete configs[legacyKey];
|
|
717
|
+
if (!notes.includes("folder-structure → slots")) {
|
|
718
|
+
notes.push("folder-structure removed");
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (!isPlainObject(doc.end)) {
|
|
722
|
+
doc.end = { version: schemaVersion };
|
|
723
|
+
notes.push("end");
|
|
724
|
+
} else {
|
|
725
|
+
const end = doc.end;
|
|
726
|
+
if (end.version == null || end.version === "") {
|
|
727
|
+
end.version = schemaVersion;
|
|
728
|
+
notes.push("end.version");
|
|
729
|
+
} else if (typeof end.version === "string" && /^\d+$/.test(end.version.trim())) {
|
|
730
|
+
end.version = Number(end.version);
|
|
731
|
+
notes.push("end.version type");
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (notes.length === 0)
|
|
735
|
+
return { changed: false, notes: [] };
|
|
736
|
+
fs2.writeFileSync(tmpPath, `${yaml2.stringify(doc).trimEnd()}
|
|
737
|
+
`);
|
|
738
|
+
return { changed: true, notes };
|
|
739
|
+
}
|
|
740
|
+
function healWorkspaceOuterTmpOptions(workspaceRoot) {
|
|
741
|
+
return healWorkspaceOuterTmpStructure(workspaceRoot).changed;
|
|
570
742
|
}
|
|
571
743
|
var readWorkspaceCoreTmp = readWorkspaceGlobalTmp;
|
|
572
744
|
function workspaceTmpTemplate(projectName) {
|
|
@@ -581,7 +753,7 @@ configs:
|
|
|
581
753
|
tmp: tmp.yml
|
|
582
754
|
options:
|
|
583
755
|
fileWatchIntervalMs: 500
|
|
584
|
-
|
|
756
|
+
slots:
|
|
585
757
|
api: api
|
|
586
758
|
web: web
|
|
587
759
|
mobile: mobile
|
|
@@ -600,11 +772,14 @@ export {
|
|
|
600
772
|
resolveWorkspaceOuterTmp,
|
|
601
773
|
resolveRepoRootFromTmpMeta,
|
|
602
774
|
resolveEntryPath,
|
|
775
|
+
readWorkspaceTmpMeta,
|
|
603
776
|
readWorkspaceGlobalTmp,
|
|
604
777
|
readWorkspaceCoreTmp,
|
|
605
778
|
readTmpFile,
|
|
779
|
+
readBrokenWorkspaceTmpMeta,
|
|
606
780
|
parseFolderStructure,
|
|
607
781
|
normalizeGlobalType,
|
|
782
|
+
healWorkspaceOuterTmpStructure,
|
|
608
783
|
healWorkspaceOuterTmpOptions,
|
|
609
784
|
formatSlotMismatch,
|
|
610
785
|
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,14 @@ export function readTmpFile(filePath) {
|
|
|
43
44
|
return out;
|
|
44
45
|
}
|
|
45
46
|
export function parseFolderStructure(text) {
|
|
46
|
-
|
|
47
|
+
// Prefer indented configs.slots / configs.folder-structure over accidental top-level keys.
|
|
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
|
+
?? text.match(/(?:^|\n)slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
51
|
+
?? text.match(/(?:^|\n)folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
52
|
+
?? '';
|
|
47
53
|
if (/^[ \t]+admin:/m.test(fsBlock)) {
|
|
48
|
-
throw new Error('configs.
|
|
54
|
+
throw new Error('configs.slots.admin removed — put admin panels under web/ (e.g. web/admin-ui)');
|
|
49
55
|
}
|
|
50
56
|
const readSlot = (key) => {
|
|
51
57
|
const scalar = fsBlock.match(new RegExp(`^[ \\t]+${key}:\\s*(.+?)(?:\\s+#.*)?$`, 'm'));
|
|
@@ -138,8 +144,10 @@ export function findWorkspaceAnchor(startDir = process.cwd()) {
|
|
|
138
144
|
meta = readTmpFile(candidate);
|
|
139
145
|
}
|
|
140
146
|
catch {
|
|
141
|
-
|
|
147
|
+
meta = readBrokenWorkspaceTmpMeta(candidate);
|
|
142
148
|
}
|
|
149
|
+
if (!meta)
|
|
150
|
+
continue;
|
|
143
151
|
if (meta.globalType !== GlobalTypeEnum.WORKSPACE)
|
|
144
152
|
continue;
|
|
145
153
|
try {
|
|
@@ -159,6 +167,60 @@ export function findWorkspaceAnchor(startDir = process.cwd()) {
|
|
|
159
167
|
}
|
|
160
168
|
return null;
|
|
161
169
|
}
|
|
170
|
+
/** Best-effort workspace meta when folder-structure is broken (e.g. legacy admin slot). */
|
|
171
|
+
export function readBrokenWorkspaceTmpMeta(filePath) {
|
|
172
|
+
if (!fs.existsSync(filePath))
|
|
173
|
+
return null;
|
|
174
|
+
let text;
|
|
175
|
+
try {
|
|
176
|
+
text = fs.readFileSync(filePath, 'utf8');
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
const typeMatch = text.match(/global:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+type:\s*(.+?)\s*(?:#.*)?$/m);
|
|
182
|
+
if (!typeMatch || parseScalar(typeMatch[1]) !== GlobalTypeEnum.WORKSPACE)
|
|
183
|
+
return null;
|
|
184
|
+
const out = {
|
|
185
|
+
path: filePath,
|
|
186
|
+
globalType: GlobalTypeEnum.WORKSPACE,
|
|
187
|
+
folderStructure: { ...DEFAULT_FOLDER_STRUCTURE },
|
|
188
|
+
};
|
|
189
|
+
const projectMatch = text.match(/^project:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+name:\s*(.+?)\s*(?:#.*)?$/m)
|
|
190
|
+
?? text.match(/^project:\s*\n[ \t]+name:\s*(.+?)\s*(?:#.*)?$/m);
|
|
191
|
+
if (projectMatch)
|
|
192
|
+
out.projectName = parseScalar(projectMatch[1]);
|
|
193
|
+
const rootBlock = text.match(/paths:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+root:\s*(.+?)\s*(?:#.*)?$/m);
|
|
194
|
+
if (rootBlock)
|
|
195
|
+
out.pathsRoot = parseScalar(rootBlock[1]);
|
|
196
|
+
const tmpBlock = text.match(/paths:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+tmp:\s*(.+?)\s*(?:#.*)?$/m);
|
|
197
|
+
if (tmpBlock)
|
|
198
|
+
out.pathsTmp = parseScalar(tmpBlock[1]);
|
|
199
|
+
// Preserve known good slot folder names even when admin is present.
|
|
200
|
+
// Prefer indented configs.slots over accidental top-level keys.
|
|
201
|
+
const fsBlock = text.match(/(?:^|\n)[ \t]+slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
202
|
+
?? text.match(/(?:^|\n)[ \t]+folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
203
|
+
?? text.match(/(?:^|\n)slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
204
|
+
?? text.match(/(?:^|\n)folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
205
|
+
?? '';
|
|
206
|
+
for (const slot of [WorkspaceSlotEnum.API, WorkspaceSlotEnum.WEB, WorkspaceSlotEnum.MOBILE]) {
|
|
207
|
+
const scalar = fsBlock.match(new RegExp(`^[ \\t]+${slot}:\\s*(.+?)(?:\\s+#.*)?$`, 'm'));
|
|
208
|
+
if (scalar)
|
|
209
|
+
out.folderStructure[slot] = parseScalar(scalar[1]);
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
export function readWorkspaceTmpMeta(filePath) {
|
|
214
|
+
try {
|
|
215
|
+
return readTmpFile(filePath);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
const broken = readBrokenWorkspaceTmpMeta(filePath);
|
|
219
|
+
if (broken)
|
|
220
|
+
return broken;
|
|
221
|
+
throw new Error(`Unable to read workspace tmp: ${filePath}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
162
224
|
/** tmp.yml directly under dir, or one level down (paths.root folder). */
|
|
163
225
|
function listShallowTmpCandidates(dir) {
|
|
164
226
|
const out = [];
|
|
@@ -249,7 +311,7 @@ export function resolveRepoRootFromTmpMeta(tmpPath, meta) {
|
|
|
249
311
|
}
|
|
250
312
|
export function scanWorkspaceProjects(workspaceRoot) {
|
|
251
313
|
const outerTmp = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
252
|
-
const wsMeta =
|
|
314
|
+
const wsMeta = readWorkspaceTmpMeta(outerTmp ?? path.join(workspaceRoot, TMP_FILE));
|
|
253
315
|
const fsMap = wsMeta.folderStructure;
|
|
254
316
|
const entries = [];
|
|
255
317
|
const mismatches = [];
|
|
@@ -293,6 +355,8 @@ export function scanWorkspaceProjects(workspaceRoot) {
|
|
|
293
355
|
}
|
|
294
356
|
continue;
|
|
295
357
|
}
|
|
358
|
+
if (kind !== GlobalTypeEnum.API_SERVICE && kind !== GlobalTypeEnum.FRONTEND)
|
|
359
|
+
continue;
|
|
296
360
|
const key = `${kind}:${name}`;
|
|
297
361
|
if (seen.has(key))
|
|
298
362
|
continue;
|
|
@@ -358,21 +422,166 @@ export function ensureWorkspaceSlotDirs(workspaceRoot) {
|
|
|
358
422
|
}
|
|
359
423
|
return created;
|
|
360
424
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
425
|
+
function isPlainObject(value) {
|
|
426
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Heal outer workspace tmp structure on sync/project:
|
|
430
|
+
* slots (api/web/mobile), global.paths, options.fileWatchIntervalMs, end.version.
|
|
431
|
+
* Migrates legacy configs.folder-structure → configs.slots.
|
|
432
|
+
* Does not overwrite existing custom slot folder names.
|
|
433
|
+
*/
|
|
434
|
+
export function healWorkspaceOuterTmpStructure(workspaceRoot) {
|
|
435
|
+
const resolvedRoot = path.resolve(workspaceRoot);
|
|
436
|
+
const tmpPath = resolveWorkspaceOuterTmp(resolvedRoot)
|
|
437
|
+
?? (fs.existsSync(path.join(resolvedRoot, TMP_FILE)) ? path.join(resolvedRoot, TMP_FILE) : null);
|
|
438
|
+
if (!tmpPath || !fs.existsSync(tmpPath))
|
|
439
|
+
return { changed: false, notes: [] };
|
|
440
|
+
const raw = fs.readFileSync(tmpPath, 'utf8');
|
|
441
|
+
let doc;
|
|
442
|
+
try {
|
|
443
|
+
const parsed = yaml.parse(raw);
|
|
444
|
+
doc = isPlainObject(parsed) ? parsed : {};
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
return { changed: false, notes: [] };
|
|
448
|
+
}
|
|
449
|
+
const notes = [];
|
|
369
450
|
const defaultMs = packageDefaults.tmpWatchDefaults.intervalMs;
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
451
|
+
const schemaVersion = packageDefaults.tmpSchemaVersion ?? 1;
|
|
452
|
+
if (!isPlainObject(doc.project)) {
|
|
453
|
+
doc.project = { name: path.basename(workspaceRoot) };
|
|
454
|
+
notes.push('project');
|
|
455
|
+
}
|
|
456
|
+
else if (typeof doc.project.name !== 'string' || !doc.project.name.trim()) {
|
|
457
|
+
doc.project.name = path.basename(workspaceRoot);
|
|
458
|
+
notes.push('project.name');
|
|
459
|
+
}
|
|
460
|
+
if (!isPlainObject(doc.configs)) {
|
|
461
|
+
doc.configs = {};
|
|
462
|
+
notes.push('configs');
|
|
463
|
+
}
|
|
464
|
+
const configs = doc.configs;
|
|
465
|
+
if (!isPlainObject(configs.global)) {
|
|
466
|
+
configs.global = {};
|
|
467
|
+
notes.push('configs.global');
|
|
468
|
+
}
|
|
469
|
+
const global = configs.global;
|
|
470
|
+
if (global.type !== GlobalTypeEnum.WORKSPACE) {
|
|
471
|
+
global.type = GlobalTypeEnum.WORKSPACE;
|
|
472
|
+
notes.push('global.type');
|
|
473
|
+
}
|
|
474
|
+
if (!isPlainObject(global.paths)) {
|
|
475
|
+
global.paths = { root: '.', tmp: 'tmp.yml' };
|
|
476
|
+
notes.push('global.paths');
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
const paths = global.paths;
|
|
480
|
+
if (typeof paths.root !== 'string' || !paths.root.trim()) {
|
|
481
|
+
paths.root = '.';
|
|
482
|
+
notes.push('global.paths.root');
|
|
483
|
+
}
|
|
484
|
+
if (typeof paths.tmp !== 'string' || !paths.tmp.trim()) {
|
|
485
|
+
paths.tmp = 'tmp.yml';
|
|
486
|
+
notes.push('global.paths.tmp');
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (!isPlainObject(global.options)) {
|
|
490
|
+
global.options = { fileWatchIntervalMs: defaultMs };
|
|
491
|
+
notes.push('global.options');
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
const options = global.options;
|
|
495
|
+
if (options.fileWatchIntervalMs == null || options.fileWatchIntervalMs === '') {
|
|
496
|
+
options.fileWatchIntervalMs = defaultMs;
|
|
497
|
+
notes.push('global.options.fileWatchIntervalMs');
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const slotsKey = 'slots';
|
|
501
|
+
const legacyKey = 'folder-structure';
|
|
502
|
+
// Accidental top-level slots / folder-structure (outside configs) — migrate, don't ignore.
|
|
503
|
+
const topLevelSlots = isPlainObject(doc[slotsKey])
|
|
504
|
+
? doc[slotsKey]
|
|
505
|
+
: isPlainObject(doc[legacyKey])
|
|
506
|
+
? doc[legacyKey]
|
|
507
|
+
: null;
|
|
508
|
+
let slotsMap;
|
|
509
|
+
if (isPlainObject(configs[slotsKey])) {
|
|
510
|
+
slotsMap = configs[slotsKey];
|
|
511
|
+
}
|
|
512
|
+
else if (isPlainObject(configs[legacyKey])) {
|
|
513
|
+
slotsMap = { ...configs[legacyKey] };
|
|
514
|
+
configs[slotsKey] = slotsMap;
|
|
515
|
+
delete configs[legacyKey];
|
|
516
|
+
notes.push('folder-structure → slots');
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
// Defaults when nothing on disk; empty map when migrating top-level custom names.
|
|
520
|
+
slotsMap = topLevelSlots ? {} : { ...DEFAULT_FOLDER_STRUCTURE };
|
|
521
|
+
configs[slotsKey] = slotsMap;
|
|
522
|
+
notes.push(topLevelSlots ? 'top-level slots → configs.slots' : 'slots');
|
|
523
|
+
}
|
|
524
|
+
// Overlay / migrate top-level custom names into configs.slots, then drop the orphan key.
|
|
525
|
+
if (topLevelSlots) {
|
|
526
|
+
for (const [key, value] of Object.entries(topLevelSlots)) {
|
|
527
|
+
if (typeof value === 'string' && value.trim()) {
|
|
528
|
+
slotsMap[key] = value.trim();
|
|
529
|
+
}
|
|
530
|
+
else if (value !== undefined) {
|
|
531
|
+
slotsMap[key] = value;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
delete doc[slotsKey];
|
|
535
|
+
delete doc[legacyKey];
|
|
536
|
+
if (!notes.includes('top-level slots → configs.slots')) {
|
|
537
|
+
notes.push('top-level slots → configs.slots');
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if ('admin' in slotsMap) {
|
|
541
|
+
delete slotsMap.admin;
|
|
542
|
+
notes.push('slots.admin removed');
|
|
543
|
+
}
|
|
544
|
+
for (const slot of [
|
|
545
|
+
WorkspaceSlotEnum.API,
|
|
546
|
+
WorkspaceSlotEnum.WEB,
|
|
547
|
+
WorkspaceSlotEnum.MOBILE,
|
|
548
|
+
]) {
|
|
549
|
+
const value = slotsMap[slot];
|
|
550
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
551
|
+
slotsMap[slot] = DEFAULT_FOLDER_STRUCTURE[slot];
|
|
552
|
+
notes.push(`slots.${slot}`);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
// Drop leftover legacy key if both somehow exist
|
|
556
|
+
if (legacyKey in configs && slotsKey in configs) {
|
|
557
|
+
delete configs[legacyKey];
|
|
558
|
+
if (!notes.includes('folder-structure → slots')) {
|
|
559
|
+
notes.push('folder-structure removed');
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if (!isPlainObject(doc.end)) {
|
|
563
|
+
doc.end = { version: schemaVersion };
|
|
564
|
+
notes.push('end');
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
const end = doc.end;
|
|
568
|
+
if (end.version == null || end.version === '') {
|
|
569
|
+
end.version = schemaVersion;
|
|
570
|
+
notes.push('end.version');
|
|
571
|
+
}
|
|
572
|
+
else if (typeof end.version === 'string' && /^\d+$/.test(end.version.trim())) {
|
|
573
|
+
end.version = Number(end.version);
|
|
574
|
+
notes.push('end.version type');
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
if (notes.length === 0)
|
|
578
|
+
return { changed: false, notes: [] };
|
|
579
|
+
fs.writeFileSync(tmpPath, `${yaml.stringify(doc).trimEnd()}\n`);
|
|
580
|
+
return { changed: true, notes };
|
|
581
|
+
}
|
|
582
|
+
/** @deprecated use healWorkspaceOuterTmpStructure */
|
|
583
|
+
export function healWorkspaceOuterTmpOptions(workspaceRoot) {
|
|
584
|
+
return healWorkspaceOuterTmpStructure(workspaceRoot).changed;
|
|
376
585
|
}
|
|
377
586
|
/** @deprecated */ export const readWorkspaceCoreTmp = readWorkspaceGlobalTmp;
|
|
378
587
|
export function workspaceTmpTemplate(projectName) {
|
|
@@ -387,7 +596,7 @@ configs:
|
|
|
387
596
|
tmp: tmp.yml
|
|
388
597
|
options:
|
|
389
598
|
fileWatchIntervalMs: 500
|
|
390
|
-
|
|
599
|
+
slots:
|
|
391
600
|
api: api
|
|
392
601
|
web: web
|
|
393
602
|
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";
|