@sixbell-telco/sdk-tools 0.0.0-stage → 0.1.0
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/CHANGELOG.md +32 -0
- package/README.md +277 -2
- package/data/security-floors.json +47 -0
- package/package.json +43 -4
- package/recipes/README.md +53 -0
- package/recipes/crud-list.md +21 -0
- package/recipes/custom-component.md +35 -0
- package/recipes/detail-page.md +19 -0
- package/recipes/form-dialog.md +17 -0
- package/recipes/parts/crud-list/i18n.json +83 -0
- package/recipes/parts/crud-list/src/app/features/__name__/__name__.routes.ts.tpl +30 -0
- package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.html.tpl +102 -0
- package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.spec.ts.tpl +101 -0
- package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.ts.tpl +143 -0
- package/recipes/parts/detail-page/i18n.json +32 -0
- package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.html.tpl +35 -0
- package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.spec.ts.tpl +58 -0
- package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.ts.tpl +68 -0
- package/recipes/parts/entity/i18n.json +5 -0
- package/recipes/parts/entity/src/app/features/__name__/__name__.model.ts.tpl +9 -0
- package/recipes/parts/entity/src/app/features/__name__/__name__.service.spec.ts.tpl +29 -0
- package/recipes/parts/entity/src/app/features/__name__/__name__.service.ts.tpl +33 -0
- package/recipes/parts/form-dialog/i18n.json +35 -0
- package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.html.tpl +33 -0
- package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.spec.ts.tpl +69 -0
- package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.ts.tpl +73 -0
- package/src/add/add.mjs +251 -0
- package/src/check/config.mjs +112 -0
- package/src/check/exceptions.mjs +103 -0
- package/src/check/federation.mjs +224 -0
- package/src/check/finding.mjs +23 -0
- package/src/check/harness.mjs +146 -0
- package/src/check/i18n.mjs +218 -0
- package/src/check/integration.mjs +566 -0
- package/src/check/security.mjs +165 -0
- package/src/check/steps.mjs +37 -0
- package/src/check/styles.mjs +347 -0
- package/src/check/wiring.mjs +198 -0
- package/src/check.mjs +333 -0
- package/src/cli.mjs +551 -0
- package/src/docs/docs.mjs +154 -0
- package/src/doctor/doctor.mjs +492 -0
- package/src/format.mjs +102 -0
- package/src/info/info.mjs +149 -0
- package/src/init/init.mjs +490 -0
- package/src/init/merge.mjs +191 -0
- package/src/init/template.mjs +292 -0
- package/src/mcp/catalog.mjs +248 -0
- package/src/mcp/glossary.mjs +75 -0
- package/src/mcp/manifest.mjs +53 -0
- package/src/mcp/recipes.mjs +198 -0
- package/src/mcp/server.mjs +249 -0
- package/src/mcp/upgrade-guide.mjs +116 -0
- package/src/mcp/usage.mjs +48 -0
- package/src/project/project.mjs +220 -0
- package/src/types.d.ts +448 -0
- package/src/upgrade/lockstep.mjs +153 -0
- package/src/upgrade/upgrade.mjs +623 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdk-tools.exceptions.json` at the app root: approved exceptions (through PR review) to `check`
|
|
3
|
+
* findings. Schema: an array (or `{ "exceptions": [...] }`) of { rule, path, reason, owner?, until? }.
|
|
4
|
+
* A matched finding moves to `excepted` and is not counted; an entry past its `until` date excepts
|
|
5
|
+
* nothing and is itself a finding (exceptions/expired), and so is a malformed entry (exceptions/invalid).
|
|
6
|
+
*/
|
|
7
|
+
import { readText } from '../project/project.mjs';
|
|
8
|
+
import { finding } from './finding.mjs';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import('../types.js').Finding} Finding
|
|
12
|
+
* @typedef {import('../types.js').ExceptionEntry} ExceptionEntry
|
|
13
|
+
* @typedef {import('../types.js').ExceptedFinding} ExceptedFinding
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const EXCEPTIONS_FILE = 'sdk-tools.exceptions.json';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A path glob as a regular expression: `**` any depth, `*` within one segment, `?` one character.
|
|
20
|
+
* @param {string} glob
|
|
21
|
+
*/
|
|
22
|
+
export function globToRegExp(glob) {
|
|
23
|
+
let source = '';
|
|
24
|
+
for (let index = 0; index < glob.length; index += 1) {
|
|
25
|
+
const char = glob[index];
|
|
26
|
+
if (char === '*' && glob[index + 1] === '*') {
|
|
27
|
+
const slash = glob[index + 2] === '/';
|
|
28
|
+
source += slash ? '(?:.*/)?' : '.*';
|
|
29
|
+
index += slash ? 2 : 1;
|
|
30
|
+
} else if (char === '*') source += '[^/]*';
|
|
31
|
+
else if (char === '?') source += '[^/]';
|
|
32
|
+
else source += char.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
33
|
+
}
|
|
34
|
+
return new RegExp(`^${source}$`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Applies the app's exceptions to `findings`.
|
|
39
|
+
* @param {string} root
|
|
40
|
+
* @param {Finding[]} findings
|
|
41
|
+
* @param {string} [today] YYYY-MM-DD
|
|
42
|
+
* @returns {{ findings: Finding[], excepted: ExceptedFinding[] }}
|
|
43
|
+
*/
|
|
44
|
+
export function applyExceptions(root, findings, today = new Date().toISOString().slice(0, 10)) {
|
|
45
|
+
const text = readText(root, EXCEPTIONS_FILE);
|
|
46
|
+
if (text === null) return { findings, excepted: [] };
|
|
47
|
+
/** @type {unknown} */
|
|
48
|
+
let parsed;
|
|
49
|
+
try {
|
|
50
|
+
parsed = JSON.parse(text);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return {
|
|
53
|
+
findings: [...findings, finding('exceptions/invalid', EXCEPTIONS_FILE, `Invalid JSON: ${/** @type {Error} */ (error).message}`)],
|
|
54
|
+
excepted: [],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const list = Array.isArray(parsed) ? parsed : /** @type {{ exceptions?: unknown }} */ (parsed)?.exceptions;
|
|
58
|
+
if (!Array.isArray(list))
|
|
59
|
+
return {
|
|
60
|
+
findings: [...findings, finding('exceptions/invalid', EXCEPTIONS_FILE, 'Expected an array of { rule, path, reason, owner?, until? }.')],
|
|
61
|
+
excepted: [],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** @type {Finding[]} */
|
|
65
|
+
const problems = [];
|
|
66
|
+
/** @type {{ entry: ExceptionEntry, pattern: RegExp }[]} */
|
|
67
|
+
const active = [];
|
|
68
|
+
for (const [index, raw] of list.entries()) {
|
|
69
|
+
const entry = /** @type {Partial<ExceptionEntry>} */ (raw ?? {});
|
|
70
|
+
if (typeof entry.rule !== 'string' || typeof entry.path !== 'string' || typeof entry.reason !== 'string' || !entry.reason.trim()) {
|
|
71
|
+
problems.push(finding('exceptions/invalid', EXCEPTIONS_FILE, `Entry ${index} needs rule, path and a non-empty reason.`));
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (entry.until !== undefined && (typeof entry.until !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(entry.until))) {
|
|
75
|
+
problems.push(
|
|
76
|
+
finding('exceptions/invalid', EXCEPTIONS_FILE, `Entry ${index} (${entry.rule} ${entry.path}): until must be a date, YYYY-MM-DD.`),
|
|
77
|
+
);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (entry.until && entry.until < today) {
|
|
81
|
+
problems.push(
|
|
82
|
+
finding(
|
|
83
|
+
'exceptions/expired',
|
|
84
|
+
EXCEPTIONS_FILE,
|
|
85
|
+
`The exception for ${entry.rule} on ${entry.path} expired on ${entry.until}${entry.owner ? ` (owner ${entry.owner})` : ''}: fix the findings or renew it through review.`,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
active.push({ entry: /** @type {ExceptionEntry} */ (entry), pattern: globToRegExp(entry.path) });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** @type {Finding[]} */
|
|
94
|
+
const kept = [];
|
|
95
|
+
/** @type {ExceptedFinding[]} */
|
|
96
|
+
const excepted = [];
|
|
97
|
+
for (const item of findings) {
|
|
98
|
+
const match = active.find(({ entry, pattern }) => (entry.rule === item.rule || entry.rule === item.id) && pattern.test(item.file));
|
|
99
|
+
if (match) excepted.push({ ...item, exception: match.entry });
|
|
100
|
+
else kept.push(item);
|
|
101
|
+
}
|
|
102
|
+
return { findings: [...kept, ...problems], excepted };
|
|
103
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Federation step: the child's remote shell and exposes, the host's remotes, and dayjs sharing.
|
|
3
|
+
* Ids: MFE_CHILD_003..007, MFE_CHILD_FEDERATION_001..004, MFE_HOST_RUNTIME_002..005,
|
|
4
|
+
* MFE_FEDERATION_DAYJS_001/002.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
|
|
9
|
+
import { readJson, readText, walk } from '../project/project.mjs';
|
|
10
|
+
import { finding } from './finding.mjs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {import('../types.js').Finding} Finding
|
|
14
|
+
* @typedef {import('../types.js').ProjectInfo} ProjectInfo
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const REMOTE_SHELL = 'MfeShadowShellComponent';
|
|
18
|
+
const MAIN_LAYOUT = 'MainLayoutComponent';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* MFE_CHILD_FEDERATION_001..003 for one expose's shell source.
|
|
22
|
+
* @param {string} source
|
|
23
|
+
* @param {string} key
|
|
24
|
+
* @param {string} file
|
|
25
|
+
* @returns {Finding[]}
|
|
26
|
+
*/
|
|
27
|
+
function exposeShellFindings(source, key, file) {
|
|
28
|
+
/** @type {Finding[]} */
|
|
29
|
+
const findings = [];
|
|
30
|
+
if (!source.includes(REMOTE_SHELL))
|
|
31
|
+
findings.push(
|
|
32
|
+
finding('MFE_CHILD_FEDERATION_001', file, `Expose ${key} must wrap its feature routes with ${REMOTE_SHELL} from @sixbell-telco/sdk/utils/mfe.`),
|
|
33
|
+
);
|
|
34
|
+
if (source.includes(MAIN_LAYOUT))
|
|
35
|
+
findings.push(finding('MFE_CHILD_FEDERATION_002', file, `Expose ${key} must not import ${MAIN_LAYOUT}: the host renders the layout.`));
|
|
36
|
+
if (source.includes(REMOTE_SHELL) && !/children\s*:/.test(source))
|
|
37
|
+
findings.push(finding('MFE_CHILD_FEDERATION_003', file, `Expose ${key} shell must declare its child routes (children: [...]).`));
|
|
38
|
+
return findings;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {ProjectInfo} project
|
|
43
|
+
* @returns {Finding[]}
|
|
44
|
+
*/
|
|
45
|
+
function childFederation(project) {
|
|
46
|
+
const { root, federation } = project;
|
|
47
|
+
/** @type {Finding[]} */
|
|
48
|
+
const findings = [];
|
|
49
|
+
if (!federation)
|
|
50
|
+
return [
|
|
51
|
+
finding('MFE_CHILD_006', 'federation.config.js', 'A child needs federation.config.js with its exposes (sdk-tools init --child creates it).'),
|
|
52
|
+
];
|
|
53
|
+
const exposes = Object.entries(federation.exposes);
|
|
54
|
+
/** @param {string} file */
|
|
55
|
+
const featureRoutes = (file) => /features\/.*\.routes\.ts$/.test(file);
|
|
56
|
+
const direct = exposes.filter(([, file]) => featureRoutes(file)).map(([key]) => key);
|
|
57
|
+
if (direct.length)
|
|
58
|
+
findings.push(
|
|
59
|
+
finding(
|
|
60
|
+
'MFE_CHILD_007',
|
|
61
|
+
'federation.config.js',
|
|
62
|
+
`Exposes ${direct.join(', ')} must point at the remote shell routes (src/app/<name>-shell.routes.ts), not straight at feature routes.`,
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
for (const [key, file] of exposes.filter(([, file]) => !featureRoutes(file))) {
|
|
66
|
+
const relativeFile = file.replace(/^\.\//, '');
|
|
67
|
+
const source = readText(root, relativeFile);
|
|
68
|
+
if (source === null)
|
|
69
|
+
findings.push(finding('MFE_CHILD_FEDERATION_004', 'federation.config.js', `Expose ${key} points at ${file}, which does not exist.`));
|
|
70
|
+
// An exposed component (not a route tree) mounts without the remote shell.
|
|
71
|
+
else if (/routes?\.ts$/.test(relativeFile)) findings.push(...exposeShellFindings(source, key, relativeFile));
|
|
72
|
+
}
|
|
73
|
+
const configured = readJson(root, 'mfe-foundation.config.json')?.exposes;
|
|
74
|
+
if (Array.isArray(configured)) {
|
|
75
|
+
for (const { key } of configured) {
|
|
76
|
+
if (key && !(key in federation.exposes))
|
|
77
|
+
findings.push(
|
|
78
|
+
finding(
|
|
79
|
+
'MFE_CHILD_FEDERATION_001',
|
|
80
|
+
'federation.config.js',
|
|
81
|
+
`mfe-foundation.config.json declares expose "${key}" but federation.config.js omits it.`,
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Template children mount the shell in src/app/<name>-shell.routes.ts; older ones under src/app/remote/.
|
|
88
|
+
const shellFiles = [
|
|
89
|
+
...walk(root, 'src/app', (file) => /^src\/app\/[^/]+-shell\.routes\.ts$/.test(file)),
|
|
90
|
+
...walk(root, 'src/app/remote', (file) => file.endsWith('.ts') && !file.endsWith('.spec.ts')),
|
|
91
|
+
...exposes.map(([, file]) => file.replace(/^\.\//, '')),
|
|
92
|
+
];
|
|
93
|
+
const hasShell = shellFiles.some((file) => {
|
|
94
|
+
const source = readText(root, file) ?? '';
|
|
95
|
+
return source.includes('ViewEncapsulation.ShadowDom') || (source.includes(REMOTE_SHELL) && source.includes('@sixbell-telco/sdk/utils/mfe'));
|
|
96
|
+
});
|
|
97
|
+
if (!hasShell && !findings.some((item) => item.rule === 'MFE_CHILD_FEDERATION_001' || item.rule === 'MFE_CHILD_007'))
|
|
98
|
+
findings.push(
|
|
99
|
+
finding(
|
|
100
|
+
'MFE_CHILD_003',
|
|
101
|
+
'src/app',
|
|
102
|
+
`A child exposes a remote shell (src/app/<name>-shell.routes.ts) that renders ${REMOTE_SHELL} from @sixbell-telco/sdk/utils/mfe.`,
|
|
103
|
+
),
|
|
104
|
+
);
|
|
105
|
+
if (!project.packageJson?.scripts?.build?.includes('write-stylesheet-href'))
|
|
106
|
+
findings.push(
|
|
107
|
+
finding(
|
|
108
|
+
'MFE_CHILD_004',
|
|
109
|
+
'package.json',
|
|
110
|
+
'The "build" script must run node scripts/write-stylesheet-href.mjs after ng build, so the remote shell finds its stylesheet.',
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
if (!existsSync(join(root, 'scripts/write-stylesheet-href.mjs')))
|
|
114
|
+
findings.push(
|
|
115
|
+
finding(
|
|
116
|
+
'MFE_CHILD_005',
|
|
117
|
+
'scripts/write-stylesheet-href.mjs',
|
|
118
|
+
'The remote shell needs scripts/write-stylesheet-href.mjs (copy it from the child template).',
|
|
119
|
+
),
|
|
120
|
+
);
|
|
121
|
+
return findings;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @param {ProjectInfo} project
|
|
126
|
+
* @returns {Finding[]}
|
|
127
|
+
*/
|
|
128
|
+
function hostFederation(project) {
|
|
129
|
+
const { root, federation } = project;
|
|
130
|
+
/** @type {Finding[]} */
|
|
131
|
+
const findings = [];
|
|
132
|
+
if (existsSync(join(root, 'src/assets/configuration/mfe_config.json')))
|
|
133
|
+
findings.push(
|
|
134
|
+
finding('MFE_HOST_RUNTIME_002', 'src/assets/configuration/mfe_config.json', 'A host does not ship the child-only mfe_config.json: delete it.'),
|
|
135
|
+
);
|
|
136
|
+
for (const file of walk(root, 'src/app', (name) => name.endsWith('.ts') && !name.endsWith('.spec.ts'))) {
|
|
137
|
+
if (/\bconfigurationGuard\b/.test(readText(root, file) ?? ''))
|
|
138
|
+
findings.push(finding('MFE_HOST_RUNTIME_003', file, 'A host does not use the child-only configurationGuard.'));
|
|
139
|
+
}
|
|
140
|
+
if (federation && Object.keys(federation.exposes).length)
|
|
141
|
+
findings.push(
|
|
142
|
+
finding(
|
|
143
|
+
'MFE_HOST_RUNTIME_004',
|
|
144
|
+
'federation.config.js',
|
|
145
|
+
'A host does not declare exposes in federation.config.js: only children expose routes.',
|
|
146
|
+
),
|
|
147
|
+
);
|
|
148
|
+
const manifest = readJson(root, 'src/assets/federation/federation.manifest.json');
|
|
149
|
+
const routing = walk(root, 'src/app', (file) => file.endsWith('.ts') && !file.endsWith('.spec.ts'))
|
|
150
|
+
.map((file) => readText(root, file) ?? '')
|
|
151
|
+
.filter((source) => source.includes('loadRemoteModule'))
|
|
152
|
+
.join('\n');
|
|
153
|
+
if (manifest && typeof manifest === 'object') {
|
|
154
|
+
for (const name of Object.keys(manifest)) {
|
|
155
|
+
const quoted = `['"\`]${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}['"\`]`;
|
|
156
|
+
if (!new RegExp(`loadRemoteModule\\s*\\(\\s*${quoted}|remoteName\\s*:\\s*${quoted}`).test(routing))
|
|
157
|
+
findings.push(
|
|
158
|
+
finding(
|
|
159
|
+
'MFE_HOST_RUNTIME_005',
|
|
160
|
+
'src/assets/federation/federation.manifest.json',
|
|
161
|
+
`Remote "${name}" is in the federation manifest but no route loads it with loadRemoteModule.`,
|
|
162
|
+
),
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return findings;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Whether the skip list covers dayjs.
|
|
171
|
+
* @param {ProjectInfo['federation']} federation
|
|
172
|
+
*/
|
|
173
|
+
function skipsDayjs(federation) {
|
|
174
|
+
if (!federation) return false;
|
|
175
|
+
if (federation.skip.some((entry) => entry === 'dayjs' || entry === 'dayjs/')) return true;
|
|
176
|
+
const skipBlock = /\bskip\s*:\s*\[[\s\S]*?\]/.exec(federation.source)?.[0] ?? '';
|
|
177
|
+
return /===?\s*['"`]dayjs['"`]|startsWith\(\s*['"`]dayjs/.test(skipBlock) || /\/\^?dayjs/.test(skipBlock);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* MFE_FEDERATION_DAYJS_001/002: dayjs has no "exports" map, so a shared dayjs needs its plugin
|
|
182
|
+
* subpaths shared, and a locale import needs dayjs skipped (or its locales mapped).
|
|
183
|
+
* @param {ProjectInfo} project
|
|
184
|
+
* @returns {Finding[]}
|
|
185
|
+
*/
|
|
186
|
+
function dayjsSharing(project) {
|
|
187
|
+
const { root, federation } = project;
|
|
188
|
+
if (!federation || !project.packageJson?.dependencies?.dayjs || skipsDayjs(federation)) return [];
|
|
189
|
+
/** @type {Finding[]} */
|
|
190
|
+
const findings = [];
|
|
191
|
+
const sharesPlugins = /dayjs\/plugin/.test(federation.source) && /readdirSync/.test(federation.source);
|
|
192
|
+
if (!sharesPlugins)
|
|
193
|
+
findings.push(
|
|
194
|
+
finding(
|
|
195
|
+
'MFE_FEDERATION_DAYJS_001',
|
|
196
|
+
'federation.config.js',
|
|
197
|
+
'federation.config.js shares dayjs without its plugin subpaths (dayjs has no "exports" map), so dayjs/plugin/* imports fail with "Unable to resolve specifier". Copy shareDayjsPlugins from the template federation.config.js, or skip dayjs.',
|
|
198
|
+
),
|
|
199
|
+
);
|
|
200
|
+
if (!/dayjs\/(?:esm\/)?locale\//.test(federation.source)) {
|
|
201
|
+
const importers = walk(root, 'src', (file) => /\.(?:ts|js|mjs)$/.test(file) && !file.endsWith('.spec.ts')).filter((file) =>
|
|
202
|
+
/['"`]dayjs\/(?:esm\/)?locale\//.test(readText(root, file) ?? ''),
|
|
203
|
+
);
|
|
204
|
+
if (importers.length)
|
|
205
|
+
findings.push(
|
|
206
|
+
finding(
|
|
207
|
+
'MFE_FEDERATION_DAYJS_002',
|
|
208
|
+
'federation.config.js',
|
|
209
|
+
`${importers.join(', ')} import a dayjs locale while federation.config.js shares dayjs without its locales, which fail with "Unable to resolve specifier". Add 'dayjs' to skip, or map dayjs/locale/* in federation.config.js.`,
|
|
210
|
+
),
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return findings;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @param {ProjectInfo} project
|
|
218
|
+
* @returns {Finding[]}
|
|
219
|
+
*/
|
|
220
|
+
export function federationStep(project) {
|
|
221
|
+
if (project.role === 'child') return [...childFederation(project), ...dayjsSharing(project)];
|
|
222
|
+
if (project.role === 'host') return [...hostFederation(project), ...dayjsSharing(project)];
|
|
223
|
+
return [];
|
|
224
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** @typedef {import('../types.js').Finding} Finding */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A project-level finding. `rule` is the stable id (the mfe-tools id, such as MFE_CHILD_003).
|
|
5
|
+
* @param {string} rule
|
|
6
|
+
* @param {string} file
|
|
7
|
+
* @param {string} message
|
|
8
|
+
* @param {{ severity?: Finding['severity'], line?: number, column?: number }} [at]
|
|
9
|
+
* @returns {Finding}
|
|
10
|
+
*/
|
|
11
|
+
export function finding(rule, file, message, { severity = 'error', line = 0, column = 0 } = {}) {
|
|
12
|
+
return { rule, severity, file, line, column, message };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 1-based line and column of `offset` in `text`.
|
|
17
|
+
* @param {string} text
|
|
18
|
+
* @param {number} offset
|
|
19
|
+
*/
|
|
20
|
+
export function position(text, offset) {
|
|
21
|
+
const before = text.slice(0, offset).split('\n');
|
|
22
|
+
return { line: before.length, column: (before.at(-1)?.length ?? 0) + 1 };
|
|
23
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Harness and shell step: the kit shell (st-app-layout, provideLayout) in hosts and in a child's
|
|
3
|
+
* standalone dev harness, which must not nest the remote shell.
|
|
4
|
+
* Ids: MFE_CHILD_009..011, MFE_CHILD_HARNESS_001/002, MFE_CHILD_ROUTE_001, MFE_LAYOUT_001..003,
|
|
5
|
+
* MFE_LAYOUT_005, MFE_LAYOUT_006, MFE_LAYOUT_008.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
import { readText, walk } from '../project/project.mjs';
|
|
11
|
+
import { finding } from './finding.mjs';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {import('../types.js').Finding} Finding
|
|
15
|
+
* @typedef {import('../types.js').ProjectInfo} ProjectInfo
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const MAIN_LAYOUT_TS = 'src/app/core/layouts/main-layout/main-layout.component.ts';
|
|
19
|
+
const MAIN_LAYOUT_HTML = 'src/app/core/layouts/main-layout/main-layout.component.html';
|
|
20
|
+
const APP_CONFIG = 'src/app/app.config.ts';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The child's standalone harness routes (app.routes.ts): MainLayoutComponent at the root, never the
|
|
24
|
+
* remote shell or a remote route tree inside it.
|
|
25
|
+
* @param {string} source
|
|
26
|
+
* @param {string} file
|
|
27
|
+
* @returns {Finding[]}
|
|
28
|
+
*/
|
|
29
|
+
function harnessRouteFindings(source, file) {
|
|
30
|
+
/** @type {Finding[]} */
|
|
31
|
+
const findings = [];
|
|
32
|
+
if (!/\bMainLayoutComponent\b/.test(source))
|
|
33
|
+
findings.push(
|
|
34
|
+
finding('MFE_CHILD_HARNESS_001', file, 'The standalone harness routes must render MainLayoutComponent at the root, around the feature routes.'),
|
|
35
|
+
);
|
|
36
|
+
if (source.includes('MfeShadowShellComponent'))
|
|
37
|
+
findings.push(
|
|
38
|
+
finding(
|
|
39
|
+
'MFE_CHILD_HARNESS_002',
|
|
40
|
+
file,
|
|
41
|
+
'The standalone harness must not nest MfeShadowShellComponent: the remote shell is only for the federated expose.',
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
else if (/-shell\.routes['"]|\bREMOTE_ROUTES\b|_SHELL_ROUTES\b|\bloadRemoteModule\b/.test(source))
|
|
45
|
+
findings.push(
|
|
46
|
+
finding('MFE_CHILD_ROUTE_001', file, 'The standalone harness must mount the feature routes, not the federated remote shell route tree.'),
|
|
47
|
+
);
|
|
48
|
+
return findings;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Shell rules for hosts and for a child's dev harness (st-app-layout itself is MFE_CHILD_011 in a child).
|
|
53
|
+
* @param {ProjectInfo} project
|
|
54
|
+
* @returns {Finding[]}
|
|
55
|
+
*/
|
|
56
|
+
function kitShell(project) {
|
|
57
|
+
const { root, role } = project;
|
|
58
|
+
/** @type {Finding[]} */
|
|
59
|
+
const findings = [];
|
|
60
|
+
const html = readText(root, MAIN_LAYOUT_HTML) ?? '';
|
|
61
|
+
const ts = readText(root, MAIN_LAYOUT_TS) ?? '';
|
|
62
|
+
if (role === 'host' && (!html.includes('<st-app-layout') || !ts.includes('@sixbell-telco/sdk/layouts')))
|
|
63
|
+
findings.push(
|
|
64
|
+
finding(
|
|
65
|
+
'MFE_LAYOUT_001',
|
|
66
|
+
MAIN_LAYOUT_HTML,
|
|
67
|
+
'The shell renders <st-app-layout [items]> from @sixbell-telco/sdk/layouts around <router-outlet />.',
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
const appConfig = readText(root, APP_CONFIG);
|
|
71
|
+
if (appConfig !== null) {
|
|
72
|
+
if (!/provideLayout\s*\(/.test(appConfig))
|
|
73
|
+
findings.push(finding('MFE_LAYOUT_002', APP_CONFIG, 'Register provideLayout({ defaultLayout }) from @sixbell-telco/sdk/layouts.'));
|
|
74
|
+
const sdkAccount = /import\s*\{[^}]*\bprovideLayoutAccount\b[^}]*\}\s*from\s*['"]@sixbell-telco\/sdk\/layouts['"]/.test(appConfig);
|
|
75
|
+
const wrapper = /(?:^|[^\w$])(provide\w*LayoutAccount)\s*\(/.exec(appConfig)?.[1];
|
|
76
|
+
const provider = readText(root, 'src/app/core/providers/layout-account.provider.ts') ?? '';
|
|
77
|
+
const wrapped = Boolean(
|
|
78
|
+
wrapper && new RegExp(`export\\s+function\\s+${wrapper}\\b`).test(provider) && /(?:^|[^\w$])provideLayoutAccount\s*\(/.test(provider),
|
|
79
|
+
);
|
|
80
|
+
if (!sdkAccount && !wrapped)
|
|
81
|
+
findings.push(
|
|
82
|
+
finding(
|
|
83
|
+
'MFE_LAYOUT_003',
|
|
84
|
+
APP_CONFIG,
|
|
85
|
+
'Register the account for the kit account menu with provideLayoutAccount from @sixbell-telco/sdk/layouts.',
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (existsSync(join(root, 'src/app/core/services/layout/layout.service.ts')))
|
|
90
|
+
findings.push(
|
|
91
|
+
finding(
|
|
92
|
+
'MFE_LAYOUT_005',
|
|
93
|
+
'src/app/core/services/layout/layout.service.ts',
|
|
94
|
+
'Local LayoutService: use LayoutService and provideLayout from @sixbell-telco/sdk/layouts, and delete it.',
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
const localOptions = walk(root, 'src/app', (file) => file.endsWith('.ts') && !file.endsWith('.spec.ts')).find((file) =>
|
|
98
|
+
/export const LAYOUT_OPTIONS\b/.test(readText(root, file) ?? ''),
|
|
99
|
+
);
|
|
100
|
+
if (localOptions)
|
|
101
|
+
findings.push(
|
|
102
|
+
finding(
|
|
103
|
+
'MFE_LAYOUT_006',
|
|
104
|
+
localOptions,
|
|
105
|
+
'Local LAYOUT_OPTIONS: the kit owns the layout catalog (LAYOUT_OPTIONS from @sixbell-telco/sdk/layouts).',
|
|
106
|
+
),
|
|
107
|
+
);
|
|
108
|
+
const defaultLayout = /defaultLayout:\s*['"]([^'"]+)['"]/.exec(readText(root, 'src/environments/environment.ts') ?? '')?.[1];
|
|
109
|
+
if (defaultLayout && !defaultLayout.startsWith('{{') && !['classic', 'modern'].includes(defaultLayout))
|
|
110
|
+
findings.push(finding('MFE_LAYOUT_008', 'src/environments/environment.ts', `defaultLayout is "${defaultLayout}": use classic or modern.`));
|
|
111
|
+
return findings;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @param {ProjectInfo} project
|
|
116
|
+
* @returns {Finding[]}
|
|
117
|
+
*/
|
|
118
|
+
function childHarness(project) {
|
|
119
|
+
const { root } = project;
|
|
120
|
+
/** @type {Finding[]} */
|
|
121
|
+
const findings = [];
|
|
122
|
+
if (!existsSync(join(root, MAIN_LAYOUT_TS)))
|
|
123
|
+
findings.push(
|
|
124
|
+
finding('MFE_CHILD_009', MAIN_LAYOUT_TS, 'The standalone dev harness needs MainLayoutComponent (copy it from the child template).'),
|
|
125
|
+
);
|
|
126
|
+
const html = readText(root, MAIN_LAYOUT_HTML);
|
|
127
|
+
if (html !== null && !html.includes('<router-outlet'))
|
|
128
|
+
findings.push(finding('MFE_CHILD_010', MAIN_LAYOUT_HTML, 'The dev harness layout must render <router-outlet />.'));
|
|
129
|
+
if (html !== null && !html.includes('<st-app-layout'))
|
|
130
|
+
findings.push(
|
|
131
|
+
finding('MFE_CHILD_011', MAIN_LAYOUT_HTML, 'The dev harness renders the kit <st-app-layout [items]> with the static menu, like the host.'),
|
|
132
|
+
);
|
|
133
|
+
const routes = ['src/app/app.routes.ts', 'src/app/app.routes.child.ts'].find((file) => existsSync(join(root, file)));
|
|
134
|
+
if (routes) findings.push(...harnessRouteFindings(readText(root, routes) ?? '', routes));
|
|
135
|
+
return findings;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @param {ProjectInfo} project
|
|
140
|
+
* @returns {Finding[]}
|
|
141
|
+
*/
|
|
142
|
+
export function harnessStep(project) {
|
|
143
|
+
if (project.role === 'child') return [...childHarness(project), ...kitShell(project)];
|
|
144
|
+
if (project.role === 'host') return kitShell(project);
|
|
145
|
+
return [];
|
|
146
|
+
}
|