@xrystal/core 3.55.7 → 3.55.9
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/project-info.mjs +13 -0
- package/x/bin/commands/projects.mjs +56 -11
- package/x/bin/commands/telepresence.mjs +3 -0
- package/x/bin/commands/watch.mjs +2 -2
- package/x/bin/helpers/.generated/.generated-from +1 -1
- package/x/bin/helpers/.generated/tmp-schema.mjs +21 -9
- package/x/bin/helpers/.generated/{xrystal-home-registry.mjs → user-home-registry.mjs} +150 -43
- package/x/bin/helpers/.generated/workspace.mjs +162 -34
- package/x/bin/helpers/cli-i18n.mjs +14 -0
- package/x/bin/helpers/create-target.mjs +5 -1
- package/x/bin/helpers/project-artifacts.mjs +2 -2
- package/x/bin/helpers/project-context.mjs +11 -4
- package/x/bin/helpers/registry-display.mjs +30 -0
- package/x/bin/helpers/workspace-resolve.mjs +7 -0
- package/x/bin/helpers/workspace-tmp.mjs +9 -3
- package/x/bin/helpers/xrystal-config.mjs +4 -4
- package/x/bin/helpers/xrystal-registry.mjs +4 -4
- package/x/bin/helpers/xrystal-watch-daemon.mjs +3 -3
- package/x/bin/helpers/xrystal-watch-service.mjs +2 -2
- package/x/bin/helpers/xrystal-watch-spawn.mjs +3 -3
- package/x/dist/utils/helpers/tmp/index.d.ts +1 -1
- package/x/dist/utils/helpers/tmp/index.js +1 -1
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +2 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +21 -9
- package/x/dist/utils/helpers/{xrystal-home → user-home}/registry.d.ts +11 -10
- package/x/dist/utils/helpers/{xrystal-home → user-home}/registry.js +11 -10
- package/x/dist/utils/helpers/workspace/index.d.ts +33 -1
- package/x/dist/utils/helpers/workspace/index.js +169 -33
|
@@ -81,6 +81,14 @@ export function readTmpGlobalPathsBlock(configs) {
|
|
|
81
81
|
},
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
+
/** Join paths.root + paths.tmp → relative path from project/workspace root (dynamic). */
|
|
85
|
+
export function buildTmpRelPath(rootFolder, tmpFileName) {
|
|
86
|
+
const root = stripDotSlash(rootFolder);
|
|
87
|
+
const tmp = stripDotSlash(tmpFileName) || 'tmp.yml';
|
|
88
|
+
if (!root || root === '.')
|
|
89
|
+
return tmp;
|
|
90
|
+
return `${root}/${tmp}`.replace(/\/+/g, '/');
|
|
91
|
+
}
|
|
84
92
|
export function resolveMergedPaths(configs) {
|
|
85
93
|
const paths = readTmpGlobalPathsBlock(configs);
|
|
86
94
|
const root = stripDotSlash(normalizeRootFolder(paths.root));
|
|
@@ -91,7 +99,7 @@ export function resolveMergedPaths(configs) {
|
|
|
91
99
|
root,
|
|
92
100
|
source,
|
|
93
101
|
special,
|
|
94
|
-
tmpRelPath:
|
|
102
|
+
tmpRelPath: buildTmpRelPath(root, tmpName),
|
|
95
103
|
};
|
|
96
104
|
}
|
|
97
105
|
function readWorkspaceGlobalBlock(global) {
|
|
@@ -208,12 +216,14 @@ export function resolveTmpRuntimeConfigs(tmp) {
|
|
|
208
216
|
const global = readTmpGlobalBlock(configs);
|
|
209
217
|
const depends = readTmpDependsBlock(configs);
|
|
210
218
|
if (global.type === GlobalTypeEnum.WORKSPACE) {
|
|
219
|
+
const root = stripDotSlash(normalizeRootFolder(global.paths.root ?? '.')) || '.';
|
|
220
|
+
const tmpName = stripDotSlash(global.paths.tmp ?? 'tmp.yml') || 'tmp.yml';
|
|
211
221
|
return {
|
|
212
222
|
global: { ...global, build: {} },
|
|
213
223
|
depends: buildNormalizedDepends(depends),
|
|
214
224
|
deploymentName: resolveTmpDeploymentName(tmp),
|
|
215
|
-
rootFolderPath:
|
|
216
|
-
tmpRelPath:
|
|
225
|
+
rootFolderPath: root,
|
|
226
|
+
tmpRelPath: buildTmpRelPath(root, tmpName),
|
|
217
227
|
};
|
|
218
228
|
}
|
|
219
229
|
const merged = resolveMergedPaths(configs);
|
|
@@ -236,15 +246,17 @@ export function normalizeTmpDocument(tmp) {
|
|
|
236
246
|
};
|
|
237
247
|
}
|
|
238
248
|
export function resolveProjectRootFromTmpPath(tmpFilePath, configs) {
|
|
239
|
-
const
|
|
249
|
+
const runtime = resolveTmpRuntimeConfigs(isRecord(configs?.global) ? { configs } : { configs: configs ?? {} });
|
|
240
250
|
const abs = tmpFilePath.replace(/\\/g, '/');
|
|
241
|
-
const rel =
|
|
242
|
-
if (abs.endsWith(`/${rel}`)) {
|
|
243
|
-
|
|
251
|
+
const rel = runtime.tmpRelPath;
|
|
252
|
+
if (abs === rel || abs.endsWith(`/${rel}`)) {
|
|
253
|
+
const root = abs === rel ? '' : abs.slice(0, -(rel.length + 1));
|
|
254
|
+
return root || '.';
|
|
244
255
|
}
|
|
245
256
|
throw new Error(`${defaults.packageName}: tmp path ${tmpFilePath} does not match configs.global.paths (${rel})`);
|
|
246
257
|
}
|
|
247
258
|
export function resolveTmpAbsPath(projectRoot, configs) {
|
|
248
|
-
const
|
|
249
|
-
|
|
259
|
+
const runtime = resolveTmpRuntimeConfigs(isRecord(configs?.global) ? { configs } : { configs: configs ?? {} });
|
|
260
|
+
const base = projectRoot.replace(/\\/g, '/').replace(/\/$/, '');
|
|
261
|
+
return `${base}/${runtime.tmpRelPath}`;
|
|
250
262
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type WorkspaceEntry } from '../../../utils/helpers/workspace';
|
|
2
|
-
|
|
2
|
+
/** Directory name under the user home (e.g. ~/.xrystal). */
|
|
3
|
+
export declare const USER_HOME_DIR = ".xrystal";
|
|
3
4
|
export type RegistryProject = {
|
|
4
5
|
name: string;
|
|
5
6
|
type: string;
|
|
@@ -13,27 +14,27 @@ export type RegistryWorkspace = {
|
|
|
13
14
|
projects: RegistryProject[];
|
|
14
15
|
updatedAt: string;
|
|
15
16
|
};
|
|
16
|
-
export type
|
|
17
|
+
export type UserHomeRegistry = {
|
|
17
18
|
version: 1;
|
|
18
19
|
updatedAt: string;
|
|
19
20
|
workspaces: RegistryWorkspace[];
|
|
20
21
|
};
|
|
21
|
-
export declare function
|
|
22
|
+
export declare function resolveUserHome(): string;
|
|
22
23
|
export declare function registryFilePath(): string;
|
|
23
|
-
export declare function
|
|
24
|
+
export declare function ensureUserHome(): string;
|
|
24
25
|
export declare function entryToRegistryProject(entry: WorkspaceEntry): RegistryProject;
|
|
25
26
|
export declare function scanWorkspace(workspacePath: string, workspaceName?: string): RegistryWorkspace;
|
|
26
|
-
export declare function readRegistry():
|
|
27
|
-
export declare function writeRegistry(registry:
|
|
28
|
-
export declare function upsertWorkspace(registry:
|
|
29
|
-
export declare function syncRegistryFromPath(startDir?: string):
|
|
27
|
+
export declare function readRegistry(): UserHomeRegistry;
|
|
28
|
+
export declare function writeRegistry(registry: UserHomeRegistry): void;
|
|
29
|
+
export declare function upsertWorkspace(registry: UserHomeRegistry, workspace: RegistryWorkspace): UserHomeRegistry;
|
|
30
|
+
export declare function syncRegistryFromPath(startDir?: string): UserHomeRegistry;
|
|
30
31
|
/** Rescan workspace, prune dead registry rows, write when drift detected. */
|
|
31
32
|
export declare function healRegistryAtPath(workspaceRoot: string, { force }?: {
|
|
32
33
|
force?: boolean;
|
|
33
34
|
}): {
|
|
34
35
|
changed: boolean;
|
|
35
|
-
registry:
|
|
36
|
+
registry: UserHomeRegistry;
|
|
36
37
|
};
|
|
37
|
-
export declare function listRegistryProjects(registry?:
|
|
38
|
+
export declare function listRegistryProjects(registry?: UserHomeRegistry): Array<RegistryProject & {
|
|
38
39
|
workspace: string;
|
|
39
40
|
}>;
|
|
@@ -2,18 +2,19 @@ import fs from 'node:fs';
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { findEntries, findWorkspaceRoot } from '../../../utils/helpers/workspace/index.js';
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
5
|
+
/** Directory name under the user home (e.g. ~/.xrystal). */
|
|
6
|
+
export const USER_HOME_DIR = '.xrystal';
|
|
7
|
+
export function resolveUserHome() {
|
|
8
|
+
const override = process.env.XRY_HOME?.trim() || process.env.XRYSTAL_HOME?.trim();
|
|
8
9
|
if (override)
|
|
9
10
|
return path.resolve(override);
|
|
10
|
-
return path.join(os.homedir(),
|
|
11
|
+
return path.join(os.homedir(), USER_HOME_DIR);
|
|
11
12
|
}
|
|
12
13
|
export function registryFilePath() {
|
|
13
|
-
return path.join(
|
|
14
|
+
return path.join(resolveUserHome(), 'registry.json');
|
|
14
15
|
}
|
|
15
|
-
export function
|
|
16
|
-
const home =
|
|
16
|
+
export function ensureUserHome() {
|
|
17
|
+
const home = resolveUserHome();
|
|
17
18
|
fs.mkdirSync(path.join(home, 'workspaces'), { recursive: true });
|
|
18
19
|
return home;
|
|
19
20
|
}
|
|
@@ -47,7 +48,7 @@ export function scanWorkspace(workspacePath, workspaceName) {
|
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
export function readRegistry() {
|
|
50
|
-
|
|
51
|
+
ensureUserHome();
|
|
51
52
|
const file = registryFilePath();
|
|
52
53
|
if (!fs.existsSync(file)) {
|
|
53
54
|
return { version: 1, updatedAt: new Date().toISOString(), workspaces: [] };
|
|
@@ -55,11 +56,11 @@ export function readRegistry() {
|
|
|
55
56
|
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
56
57
|
}
|
|
57
58
|
export function writeRegistry(registry) {
|
|
58
|
-
|
|
59
|
+
ensureUserHome();
|
|
59
60
|
registry.updatedAt = new Date().toISOString();
|
|
60
61
|
fs.writeFileSync(registryFilePath(), `${JSON.stringify(registry, null, 2)}\n`);
|
|
61
62
|
for (const ws of registry.workspaces) {
|
|
62
|
-
const wsDir = path.join(
|
|
63
|
+
const wsDir = path.join(resolveUserHome(), 'workspaces', ws.name);
|
|
63
64
|
fs.mkdirSync(wsDir, { recursive: true });
|
|
64
65
|
fs.writeFileSync(path.join(wsDir, 'workspace.json'), `${JSON.stringify(ws, null, 2)}\n`);
|
|
65
66
|
for (const project of ws.projects) {
|
|
@@ -27,13 +27,45 @@ export declare function parseFolderStructure(text: string): FolderStructure;
|
|
|
27
27
|
type DiscoverySlot = {
|
|
28
28
|
slot: WorkspaceSlot;
|
|
29
29
|
folder: string;
|
|
30
|
-
|
|
30
|
+
allowedTypes: GlobalTypeEnum[];
|
|
31
31
|
};
|
|
32
|
+
export declare function allowedGlobalTypesForSlot(slot: WorkspaceSlot): GlobalTypeEnum[];
|
|
32
33
|
export declare function workspaceDiscoverySlots(fsMap: FolderStructure): DiscoverySlot[];
|
|
34
|
+
export type SlotTypeMismatch = {
|
|
35
|
+
slot: WorkspaceSlot;
|
|
36
|
+
slotFolder: string;
|
|
37
|
+
projectName: string;
|
|
38
|
+
globalType: string | null;
|
|
39
|
+
expectedTypes: GlobalTypeEnum[];
|
|
40
|
+
tmp: string;
|
|
41
|
+
projectPath: string;
|
|
42
|
+
};
|
|
43
|
+
export declare function formatSlotMismatch(mismatch: SlotTypeMismatch): string;
|
|
33
44
|
export { normalizeGlobalType } from '../../../utils/helpers/tmp/tmp-schema';
|
|
34
45
|
export declare function entryName(meta: TmpMeta): string | null;
|
|
35
46
|
export declare function entryType(meta: TmpMeta, slot: WorkspaceSlot): GlobalTypeEnum | null;
|
|
36
47
|
export declare function findWorkspaceRoot(startDir?: string): string | null;
|
|
48
|
+
/** Outer workspace tmp path for a known workspace root (honours configs.global.paths). */
|
|
49
|
+
export declare function resolveWorkspaceOuterTmp(workspaceRoot: string): string | null;
|
|
50
|
+
export type WorkspaceAnchor = {
|
|
51
|
+
root: string;
|
|
52
|
+
tmpPath: string;
|
|
53
|
+
meta: TmpMeta;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Walk up from cwd; at each level look for workspace tmp at `./tmp.yml` or
|
|
57
|
+
* `./<paths.root>/tmp.yml` (any one-level folder). Project/workspace root is
|
|
58
|
+
* always derived from that file's configs.global.paths — never hardcoded.
|
|
59
|
+
*/
|
|
60
|
+
export declare function findWorkspaceAnchor(startDir?: string): WorkspaceAnchor | null;
|
|
61
|
+
/** Relative tmp path from project root, driven only by configs.global.paths. */
|
|
62
|
+
export declare function buildRepoTmpRelPath(meta: Pick<TmpMeta, 'pathsRoot' | 'pathsTmp' | 'globalType'>): string;
|
|
63
|
+
/** Project/workspace root = tmp file location minus paths.root/paths.tmp. */
|
|
64
|
+
export declare function resolveRepoRootFromTmpMeta(tmpPath: string, meta: Pick<TmpMeta, 'pathsRoot' | 'pathsTmp' | 'globalType'>): string;
|
|
65
|
+
export declare function scanWorkspaceProjects(workspaceRoot: string): {
|
|
66
|
+
entries: WorkspaceEntry[];
|
|
67
|
+
mismatches: SlotTypeMismatch[];
|
|
68
|
+
};
|
|
37
69
|
export declare function findEntries(workspaceRoot: string): WorkspaceEntry[];
|
|
38
70
|
export declare function findApiServices(workspaceRoot: string): WorkspaceEntry[];
|
|
39
71
|
export declare function resolveEntryPath(workspaceRoot: string, name: string): string | null;
|
|
@@ -59,13 +59,38 @@ export function parseFolderStructure(text) {
|
|
|
59
59
|
[WorkspaceSlotEnum.MOBILE]: readSlot(WorkspaceSlotEnum.MOBILE),
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
+
export function allowedGlobalTypesForSlot(slot) {
|
|
63
|
+
if (slot === WorkspaceSlotEnum.API)
|
|
64
|
+
return [GlobalTypeEnum.API_SERVICE];
|
|
65
|
+
if (slot === WorkspaceSlotEnum.WEB || slot === WorkspaceSlotEnum.MOBILE) {
|
|
66
|
+
return [GlobalTypeEnum.FRONTEND];
|
|
67
|
+
}
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
62
70
|
export function workspaceDiscoverySlots(fsMap) {
|
|
63
71
|
return [
|
|
64
|
-
{
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
{
|
|
73
|
+
slot: WorkspaceSlotEnum.API,
|
|
74
|
+
folder: fsMap[WorkspaceSlotEnum.API],
|
|
75
|
+
allowedTypes: allowedGlobalTypesForSlot(WorkspaceSlotEnum.API),
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
slot: WorkspaceSlotEnum.WEB,
|
|
79
|
+
folder: fsMap[WorkspaceSlotEnum.WEB],
|
|
80
|
+
allowedTypes: allowedGlobalTypesForSlot(WorkspaceSlotEnum.WEB),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
slot: WorkspaceSlotEnum.MOBILE,
|
|
84
|
+
folder: fsMap[WorkspaceSlotEnum.MOBILE],
|
|
85
|
+
allowedTypes: allowedGlobalTypesForSlot(WorkspaceSlotEnum.MOBILE),
|
|
86
|
+
},
|
|
67
87
|
];
|
|
68
88
|
}
|
|
89
|
+
export function formatSlotMismatch(mismatch) {
|
|
90
|
+
const expected = mismatch.expectedTypes.join(' | ');
|
|
91
|
+
const got = mismatch.globalType?.trim() || '(missing global.type)';
|
|
92
|
+
return `${mismatch.projectName}: ${got} in ${mismatch.slot}/ slot — expected ${expected}`;
|
|
93
|
+
}
|
|
69
94
|
export { normalizeGlobalType } from '../../../utils/helpers/tmp/tmp-schema.js';
|
|
70
95
|
export function entryName(meta) {
|
|
71
96
|
const project = (meta.projectName ?? '').trim();
|
|
@@ -86,13 +111,46 @@ export function entryType(meta, slot) {
|
|
|
86
111
|
return null;
|
|
87
112
|
}
|
|
88
113
|
export function findWorkspaceRoot(startDir = process.cwd()) {
|
|
89
|
-
|
|
114
|
+
return findWorkspaceAnchor(startDir)?.root ?? null;
|
|
115
|
+
}
|
|
116
|
+
/** Outer workspace tmp path for a known workspace root (honours configs.global.paths). */
|
|
117
|
+
export function resolveWorkspaceOuterTmp(workspaceRoot) {
|
|
118
|
+
const root = path.resolve(workspaceRoot);
|
|
119
|
+
const anchor = findWorkspaceAnchor(root);
|
|
120
|
+
if (!anchor)
|
|
121
|
+
return null;
|
|
122
|
+
if (path.resolve(anchor.root) !== root)
|
|
123
|
+
return null;
|
|
124
|
+
return anchor.tmpPath;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Walk up from cwd; at each level look for workspace tmp at `./tmp.yml` or
|
|
128
|
+
* `./<paths.root>/tmp.yml` (any one-level folder). Project/workspace root is
|
|
129
|
+
* always derived from that file's configs.global.paths — never hardcoded.
|
|
130
|
+
*/
|
|
131
|
+
export function findWorkspaceAnchor(startDir = process.cwd()) {
|
|
132
|
+
const start = path.resolve(startDir);
|
|
133
|
+
let cur = start;
|
|
90
134
|
for (;;) {
|
|
91
|
-
const candidate
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
135
|
+
for (const candidate of listShallowTmpCandidates(cur)) {
|
|
136
|
+
let meta;
|
|
137
|
+
try {
|
|
138
|
+
meta = readTmpFile(candidate);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (meta.globalType !== GlobalTypeEnum.WORKSPACE)
|
|
144
|
+
continue;
|
|
145
|
+
try {
|
|
146
|
+
const root = path.resolve(resolveRepoRootFromTmpMeta(candidate, meta));
|
|
147
|
+
if (start === root || start.startsWith(`${root}${path.sep}`)) {
|
|
148
|
+
return { root, tmpPath: path.resolve(candidate), meta };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
96
154
|
}
|
|
97
155
|
const parent = path.dirname(cur);
|
|
98
156
|
if (parent === cur)
|
|
@@ -101,6 +159,31 @@ export function findWorkspaceRoot(startDir = process.cwd()) {
|
|
|
101
159
|
}
|
|
102
160
|
return null;
|
|
103
161
|
}
|
|
162
|
+
/** tmp.yml directly under dir, or one level down (paths.root folder). */
|
|
163
|
+
function listShallowTmpCandidates(dir) {
|
|
164
|
+
const out = [];
|
|
165
|
+
const direct = path.join(dir, TMP_FILE);
|
|
166
|
+
if (fs.existsSync(direct))
|
|
167
|
+
out.push(direct);
|
|
168
|
+
let entries;
|
|
169
|
+
try {
|
|
170
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
for (const entry of entries) {
|
|
176
|
+
const full = path.join(dir, entry.name);
|
|
177
|
+
if (!isTraversableDir(entry, full))
|
|
178
|
+
continue;
|
|
179
|
+
if (SKIP_DIRS.has(entry.name) || entry.name.startsWith('.'))
|
|
180
|
+
continue;
|
|
181
|
+
const nested = path.join(full, TMP_FILE);
|
|
182
|
+
if (fs.existsSync(nested))
|
|
183
|
+
out.push(nested);
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
104
187
|
function isTraversableDir(entry, fullPath) {
|
|
105
188
|
if (entry.isDirectory())
|
|
106
189
|
return true;
|
|
@@ -143,39 +226,73 @@ function walkTmpUnder(rootDir) {
|
|
|
143
226
|
return found;
|
|
144
227
|
}
|
|
145
228
|
function stripDotSlash(value) {
|
|
146
|
-
return value.replace(/^\.\//, '');
|
|
229
|
+
return value.replace(/^\.\//, '').replace(/\/$/, '');
|
|
147
230
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
if (
|
|
154
|
-
return
|
|
231
|
+
/** Relative tmp path from project root, driven only by configs.global.paths. */
|
|
232
|
+
export function buildRepoTmpRelPath(meta) {
|
|
233
|
+
const isWorkspace = meta.globalType === GlobalTypeEnum.WORKSPACE;
|
|
234
|
+
const rootFolder = stripDotSlash(meta.pathsRoot?.trim() || (isWorkspace ? '.' : packageDefaults.packageRootFolder));
|
|
235
|
+
const tmpName = stripDotSlash(meta.pathsTmp?.trim() || TMP_FILE) || TMP_FILE;
|
|
236
|
+
if (!rootFolder || rootFolder === '.')
|
|
237
|
+
return tmpName;
|
|
238
|
+
return `${rootFolder}/${tmpName}`.replace(/\/+/g, '/');
|
|
239
|
+
}
|
|
240
|
+
/** Project/workspace root = tmp file location minus paths.root/paths.tmp. */
|
|
241
|
+
export function resolveRepoRootFromTmpMeta(tmpPath, meta) {
|
|
242
|
+
const abs = path.resolve(tmpPath).replace(/\\/g, '/');
|
|
243
|
+
const rel = buildRepoTmpRelPath(meta);
|
|
244
|
+
if (abs === rel || abs.endsWith(`/${rel}`)) {
|
|
245
|
+
const root = abs === rel ? '' : abs.slice(0, -(rel.length + 1));
|
|
246
|
+
return root || path.dirname(abs);
|
|
155
247
|
}
|
|
156
248
|
throw new Error(`tmp path mismatch: expected */${rel}, got ${abs}`);
|
|
157
249
|
}
|
|
158
|
-
export function
|
|
159
|
-
const
|
|
250
|
+
export function scanWorkspaceProjects(workspaceRoot) {
|
|
251
|
+
const outerTmp = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
252
|
+
const wsMeta = readTmpFile(outerTmp ?? path.join(workspaceRoot, TMP_FILE));
|
|
160
253
|
const fsMap = wsMeta.folderStructure;
|
|
161
254
|
const entries = [];
|
|
255
|
+
const mismatches = [];
|
|
162
256
|
const seen = new Set();
|
|
163
|
-
|
|
257
|
+
const seenMismatch = new Set();
|
|
258
|
+
const outerResolved = outerTmp ? path.resolve(outerTmp) : null;
|
|
259
|
+
for (const { slot, folder: folderRel, allowedTypes } of workspaceDiscoverySlots(fsMap)) {
|
|
164
260
|
const folder = path.join(workspaceRoot, folderRel);
|
|
165
261
|
for (const tmpPath of walkTmpUnder(folder)) {
|
|
166
|
-
if (path.resolve(tmpPath) ===
|
|
262
|
+
if (outerResolved && path.resolve(tmpPath) === outerResolved)
|
|
167
263
|
continue;
|
|
168
264
|
const meta = readTmpFile(tmpPath);
|
|
169
265
|
const kind = entryType(meta, slot);
|
|
170
266
|
if (kind === GlobalTypeEnum.WORKSPACE)
|
|
171
267
|
continue;
|
|
172
|
-
if (frontendOnly && kind !== GlobalTypeEnum.FRONTEND)
|
|
173
|
-
continue;
|
|
174
|
-
if (kind !== GlobalTypeEnum.API_SERVICE && kind !== GlobalTypeEnum.FRONTEND)
|
|
175
|
-
continue;
|
|
176
268
|
const name = entryName(meta);
|
|
269
|
+
const explicitType = (meta.globalType ?? '').trim() || null;
|
|
270
|
+
const projectPath = (() => {
|
|
271
|
+
try {
|
|
272
|
+
return resolveRepoRootFromTmpMeta(tmpPath, meta);
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
return path.dirname(tmpPath);
|
|
276
|
+
}
|
|
277
|
+
})();
|
|
177
278
|
if (!name)
|
|
178
279
|
continue;
|
|
280
|
+
if (kind == null || !allowedTypes.includes(kind)) {
|
|
281
|
+
const mismatchKey = `${slot}:${tmpPath}`;
|
|
282
|
+
if (!seenMismatch.has(mismatchKey)) {
|
|
283
|
+
seenMismatch.add(mismatchKey);
|
|
284
|
+
mismatches.push({
|
|
285
|
+
slot,
|
|
286
|
+
slotFolder: folderRel,
|
|
287
|
+
projectName: name,
|
|
288
|
+
globalType: explicitType,
|
|
289
|
+
expectedTypes: allowedTypes,
|
|
290
|
+
tmp: tmpPath,
|
|
291
|
+
projectPath,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
179
296
|
const key = `${kind}:${name}`;
|
|
180
297
|
if (seen.has(key))
|
|
181
298
|
continue;
|
|
@@ -183,14 +300,24 @@ export function findEntries(workspaceRoot) {
|
|
|
183
300
|
entries.push({
|
|
184
301
|
name,
|
|
185
302
|
type: kind,
|
|
186
|
-
path:
|
|
303
|
+
path: projectPath,
|
|
187
304
|
tmp: tmpPath,
|
|
188
305
|
slot,
|
|
189
306
|
cluster: meta.clusterDeployment ?? meta.projectName,
|
|
190
307
|
});
|
|
191
308
|
}
|
|
192
309
|
}
|
|
193
|
-
|
|
310
|
+
const sortEntries = (a, b) => (a.type === b.type ? a.name.localeCompare(b.name) : a.type.localeCompare(b.type));
|
|
311
|
+
mismatches.sort((a, b) => (a.slot.localeCompare(b.slot)
|
|
312
|
+
|| a.projectName.localeCompare(b.projectName)
|
|
313
|
+
|| a.tmp.localeCompare(b.tmp)));
|
|
314
|
+
return {
|
|
315
|
+
entries: entries.sort(sortEntries),
|
|
316
|
+
mismatches,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
export function findEntries(workspaceRoot) {
|
|
320
|
+
return scanWorkspaceProjects(workspaceRoot).entries;
|
|
194
321
|
}
|
|
195
322
|
export function findApiServices(workspaceRoot) {
|
|
196
323
|
return findEntries(workspaceRoot).filter((e) => e.type === GlobalTypeEnum.API_SERVICE);
|
|
@@ -200,19 +327,25 @@ export function resolveEntryPath(workspaceRoot, name) {
|
|
|
200
327
|
return hit?.path ?? null;
|
|
201
328
|
}
|
|
202
329
|
export function workspaceProjectName(workspaceRoot) {
|
|
203
|
-
const
|
|
330
|
+
const tmpPath = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
331
|
+
if (!tmpPath)
|
|
332
|
+
return path.basename(workspaceRoot);
|
|
333
|
+
const meta = readTmpFile(tmpPath);
|
|
204
334
|
return meta.projectName?.trim() || path.basename(workspaceRoot);
|
|
205
335
|
}
|
|
206
336
|
export function readWorkspaceGlobalTmp(workspaceRoot) {
|
|
207
|
-
const
|
|
337
|
+
const tmpPath = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
338
|
+
if (!tmpPath)
|
|
339
|
+
return {};
|
|
340
|
+
const text = fs.readFileSync(tmpPath, 'utf8');
|
|
208
341
|
const match = text.match(/options:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+fileWatchIntervalMs:\s*(\d+)/m)
|
|
209
342
|
?? text.match(/fileWatchIntervalMs:\s*(\d+)/);
|
|
210
343
|
return match ? { fileWatchIntervalMs: Number(match[1]) } : {};
|
|
211
344
|
}
|
|
212
345
|
/** Ensure api/web/mobile (or custom folder-structure paths) exist on disk. */
|
|
213
346
|
export function ensureWorkspaceSlotDirs(workspaceRoot) {
|
|
214
|
-
const tmpPath =
|
|
215
|
-
if (!
|
|
347
|
+
const tmpPath = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
348
|
+
if (!tmpPath)
|
|
216
349
|
return [];
|
|
217
350
|
const meta = readTmpFile(tmpPath);
|
|
218
351
|
const created = [];
|
|
@@ -227,8 +360,8 @@ export function ensureWorkspaceSlotDirs(workspaceRoot) {
|
|
|
227
360
|
}
|
|
228
361
|
/** Patch outer workspace tmp when global.options.fileWatchIntervalMs is missing. */
|
|
229
362
|
export function healWorkspaceOuterTmpOptions(workspaceRoot) {
|
|
230
|
-
const tmpPath =
|
|
231
|
-
if (!
|
|
363
|
+
const tmpPath = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
364
|
+
if (!tmpPath)
|
|
232
365
|
return false;
|
|
233
366
|
const text = fs.readFileSync(tmpPath, 'utf8');
|
|
234
367
|
if (/fileWatchIntervalMs:\s*\d+/m.test(text))
|
|
@@ -249,6 +382,9 @@ export function workspaceTmpTemplate(projectName) {
|
|
|
249
382
|
configs:
|
|
250
383
|
global:
|
|
251
384
|
type: workspace
|
|
385
|
+
paths:
|
|
386
|
+
root: .
|
|
387
|
+
tmp: tmp.yml
|
|
252
388
|
options:
|
|
253
389
|
fileWatchIntervalMs: 500
|
|
254
390
|
folder-structure:
|