@tmsfe/tmskit 0.0.70 → 0.0.71
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/dist/index.cjs.js +48 -32
- package/package.json +1 -1
- package/src/core/buildAppJson.js +38 -35
package/dist/index.cjs.js
CHANGED
|
@@ -1548,18 +1548,40 @@ function mergeSubPackages(existingPackages, newPackages) {
|
|
|
1548
1548
|
return resultPackages;
|
|
1549
1549
|
}
|
|
1550
1550
|
|
|
1551
|
+
/**
|
|
1552
|
+
* 收集当前 appJson 中所有有效的页面路径和分包标识
|
|
1553
|
+
*/
|
|
1554
|
+
function collectValidPaths(appJson) {
|
|
1555
|
+
const subpackages = appJson.subpackages || [];
|
|
1556
|
+
const pages = new Set(appJson.pages || []);
|
|
1557
|
+
const roots = new Set();
|
|
1558
|
+
const names = new Set();
|
|
1559
|
+
subpackages.forEach(sub => {
|
|
1560
|
+
if (sub.root) roots.add(sub.root);
|
|
1561
|
+
if (sub.name) names.add(sub.name);
|
|
1562
|
+
(sub.pages || []).forEach(page => {
|
|
1563
|
+
pages.add(`${sub.root}/${page}`);
|
|
1564
|
+
});
|
|
1565
|
+
});
|
|
1566
|
+
return {
|
|
1567
|
+
pages,
|
|
1568
|
+
roots,
|
|
1569
|
+
names
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1551
1573
|
/**
|
|
1552
1574
|
* 清理 preloadRule 中引用了不存在分包的条目
|
|
1553
1575
|
*/
|
|
1554
|
-
function cleanPreloadRule(appJson
|
|
1576
|
+
function cleanPreloadRule(appJson, {
|
|
1577
|
+
roots,
|
|
1578
|
+
names
|
|
1579
|
+
}) {
|
|
1555
1580
|
if (!appJson.preloadRule) return;
|
|
1556
|
-
const subpackages = appJson.subpackages || [];
|
|
1557
|
-
const existingSubpackageNames = new Set(subpackages.map(sub => sub.name).filter(Boolean));
|
|
1558
|
-
const existingSubpackageRoots = new Set(subpackages.map(sub => sub.root).filter(Boolean));
|
|
1559
1581
|
Object.keys(appJson.preloadRule).forEach(pageKey => {
|
|
1560
1582
|
const rule = appJson.preloadRule[pageKey];
|
|
1561
1583
|
if (rule.packages) {
|
|
1562
|
-
rule.packages = rule.packages.filter(pkg =>
|
|
1584
|
+
rule.packages = rule.packages.filter(pkg => names.has(pkg) || roots.has(pkg));
|
|
1563
1585
|
if (rule.packages.length === 0) {
|
|
1564
1586
|
delete appJson.preloadRule[pageKey];
|
|
1565
1587
|
}
|
|
@@ -1573,19 +1595,14 @@ function cleanPreloadRule(appJson) {
|
|
|
1573
1595
|
/**
|
|
1574
1596
|
* 清理 entranceDeclare 中引用了不存在页面的条目
|
|
1575
1597
|
*/
|
|
1576
|
-
function cleanEntranceDeclare(appJson
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
(appJson.subpackages || []).forEach(sub => {
|
|
1580
|
-
(sub.pages || []).forEach(page => {
|
|
1581
|
-
allValidPages.add(`${sub.root}/${page}`);
|
|
1582
|
-
});
|
|
1583
|
-
});
|
|
1598
|
+
function cleanEntranceDeclare(appJson, {
|
|
1599
|
+
pages
|
|
1600
|
+
}) {
|
|
1584
1601
|
if (!appJson.entranceDeclare) return;
|
|
1585
1602
|
Object.keys(appJson.entranceDeclare).forEach(key => {
|
|
1586
1603
|
const entry = appJson.entranceDeclare[key];
|
|
1587
|
-
if (entry && entry.path && !
|
|
1588
|
-
info$g(`[
|
|
1604
|
+
if (entry && entry.path && !pages.has(entry.path)) {
|
|
1605
|
+
info$g(`[buildAppJson] 移除 entranceDeclare.${key},页面 ${entry.path} 不存在`);
|
|
1589
1606
|
delete appJson.entranceDeclare[key];
|
|
1590
1607
|
}
|
|
1591
1608
|
});
|
|
@@ -1596,19 +1613,19 @@ function cleanEntranceDeclare(appJson) {
|
|
|
1596
1613
|
|
|
1597
1614
|
/**
|
|
1598
1615
|
* 清理 agent.skills 中引用了不存在分包路径的技能
|
|
1616
|
+
* skill.path 必须以某个有效分包 root 为前缀才保留
|
|
1599
1617
|
*/
|
|
1600
|
-
function cleanAgentConfig(appJson
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1618
|
+
function cleanAgentConfig(appJson, {
|
|
1619
|
+
roots
|
|
1620
|
+
}) {
|
|
1621
|
+
if (!appJson.agent || !Array.isArray(appJson.agent.skills)) return;
|
|
1604
1622
|
appJson.agent.skills = appJson.agent.skills.filter(skill => {
|
|
1605
1623
|
if (!skill.path) return true;
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
return false;
|
|
1624
|
+
const isValid = Array.from(roots).some(root => skill.path === root || skill.path.startsWith(`${root}/`));
|
|
1625
|
+
if (!isValid) {
|
|
1626
|
+
info$g(`[buildAppJson] 移除 agent.skills "${skill.name}",路径 ${skill.path} 对应的分包不存在`);
|
|
1627
|
+
}
|
|
1628
|
+
return isValid;
|
|
1612
1629
|
});
|
|
1613
1630
|
if (appJson.agent.skills.length === 0) {
|
|
1614
1631
|
delete appJson.agent;
|
|
@@ -1641,12 +1658,11 @@ async function buildOutputAppJson$3(tmsConfig, modules) {
|
|
|
1641
1658
|
// 更新主包,需在subpackages处理完成后执行, pages/
|
|
1642
1659
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
1643
1660
|
|
|
1644
|
-
//
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
}
|
|
1661
|
+
// 清理引用了不存在分包/页面的无效配置
|
|
1662
|
+
const validPaths = collectValidPaths(appJson);
|
|
1663
|
+
cleanPreloadRule(appJson, validPaths);
|
|
1664
|
+
cleanEntranceDeclare(appJson, validPaths);
|
|
1665
|
+
cleanAgentConfig(appJson, validPaths);
|
|
1650
1666
|
|
|
1651
1667
|
// 模板渲染:先将 app.json 转为字符串,然后通过 preprocess 渲染
|
|
1652
1668
|
const appJsonStr = JSON.stringify(appJson, null, 2);
|
|
@@ -4483,7 +4499,7 @@ var entry = [{
|
|
|
4483
4499
|
|
|
4484
4500
|
var require$$12 = {
|
|
4485
4501
|
name: "@tmsfe/tmskit",
|
|
4486
|
-
version: "0.0.
|
|
4502
|
+
version: "0.0.71",
|
|
4487
4503
|
description: "tmskit",
|
|
4488
4504
|
main: "dist/index.cjs",
|
|
4489
4505
|
bin: {
|
package/package.json
CHANGED
package/src/core/buildAppJson.js
CHANGED
|
@@ -168,20 +168,36 @@ function mergeSubPackages(existingPackages, newPackages) {
|
|
|
168
168
|
return resultPackages;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
/**
|
|
172
|
+
* 收集当前 appJson 中所有有效的页面路径和分包标识
|
|
173
|
+
*/
|
|
174
|
+
function collectValidPaths(appJson) {
|
|
175
|
+
const subpackages = appJson.subpackages || [];
|
|
176
|
+
const pages = new Set(appJson.pages || []);
|
|
177
|
+
const roots = new Set();
|
|
178
|
+
const names = new Set();
|
|
179
|
+
|
|
180
|
+
subpackages.forEach((sub) => {
|
|
181
|
+
if (sub.root) roots.add(sub.root);
|
|
182
|
+
if (sub.name) names.add(sub.name);
|
|
183
|
+
(sub.pages || []).forEach((page) => {
|
|
184
|
+
pages.add(`${sub.root}/${page}`);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
return { pages, roots, names };
|
|
189
|
+
}
|
|
190
|
+
|
|
171
191
|
/**
|
|
172
192
|
* 清理 preloadRule 中引用了不存在分包的条目
|
|
173
193
|
*/
|
|
174
|
-
function cleanPreloadRule(appJson) {
|
|
194
|
+
function cleanPreloadRule(appJson, { roots, names }) {
|
|
175
195
|
if (!appJson.preloadRule) return;
|
|
176
196
|
|
|
177
|
-
const subpackages = appJson.subpackages || [];
|
|
178
|
-
const existingSubpackageNames = new Set(subpackages.map(sub => sub.name).filter(Boolean));
|
|
179
|
-
const existingSubpackageRoots = new Set(subpackages.map(sub => sub.root).filter(Boolean));
|
|
180
|
-
|
|
181
197
|
Object.keys(appJson.preloadRule).forEach((pageKey) => {
|
|
182
198
|
const rule = appJson.preloadRule[pageKey];
|
|
183
199
|
if (rule.packages) {
|
|
184
|
-
rule.packages = rule.packages.filter(pkg =>
|
|
200
|
+
rule.packages = rule.packages.filter(pkg => names.has(pkg) || roots.has(pkg));
|
|
185
201
|
if (rule.packages.length === 0) {
|
|
186
202
|
delete appJson.preloadRule[pageKey];
|
|
187
203
|
}
|
|
@@ -193,25 +209,16 @@ function cleanPreloadRule(appJson) {
|
|
|
193
209
|
}
|
|
194
210
|
}
|
|
195
211
|
|
|
196
|
-
|
|
197
212
|
/**
|
|
198
213
|
* 清理 entranceDeclare 中引用了不存在页面的条目
|
|
199
214
|
*/
|
|
200
|
-
function cleanEntranceDeclare(appJson) {
|
|
201
|
-
// 收集所有有效页面路径(主包 pages + 分包 pages)
|
|
202
|
-
const allValidPages = new Set(appJson.pages || []);
|
|
203
|
-
(appJson.subpackages || []).forEach((sub) => {
|
|
204
|
-
(sub.pages || []).forEach((page) => {
|
|
205
|
-
allValidPages.add(`${sub.root}/${page}`);
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
215
|
+
function cleanEntranceDeclare(appJson, { pages }) {
|
|
209
216
|
if (!appJson.entranceDeclare) return;
|
|
210
217
|
|
|
211
218
|
Object.keys(appJson.entranceDeclare).forEach((key) => {
|
|
212
219
|
const entry = appJson.entranceDeclare[key];
|
|
213
|
-
if (entry && entry.path && !
|
|
214
|
-
info(`[
|
|
220
|
+
if (entry && entry.path && !pages.has(entry.path)) {
|
|
221
|
+
info(`[buildAppJson] 移除 entranceDeclare.${key},页面 ${entry.path} 不存在`);
|
|
215
222
|
delete appJson.entranceDeclare[key];
|
|
216
223
|
}
|
|
217
224
|
});
|
|
@@ -223,21 +230,18 @@ function cleanEntranceDeclare(appJson) {
|
|
|
223
230
|
|
|
224
231
|
/**
|
|
225
232
|
* 清理 agent.skills 中引用了不存在分包路径的技能
|
|
233
|
+
* skill.path 必须以某个有效分包 root 为前缀才保留
|
|
226
234
|
*/
|
|
227
|
-
function cleanAgentConfig(appJson) {
|
|
228
|
-
if (!appJson.agent || !appJson.agent.skills) return;
|
|
229
|
-
|
|
230
|
-
const subpackages = appJson.subpackages || [];
|
|
231
|
-
const allValidRoots = new Set(subpackages.map(sub => sub.root).filter(Boolean));
|
|
235
|
+
function cleanAgentConfig(appJson, { roots }) {
|
|
236
|
+
if (!appJson.agent || !Array.isArray(appJson.agent.skills)) return;
|
|
232
237
|
|
|
233
238
|
appJson.agent.skills = appJson.agent.skills.filter((skill) => {
|
|
234
239
|
if (!skill.path) return true;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return false;
|
|
240
|
+
const isValid = Array.from(roots).some(root => skill.path === root || skill.path.startsWith(`${root}/`));
|
|
241
|
+
if (!isValid) {
|
|
242
|
+
info(`[buildAppJson] 移除 agent.skills "${skill.name}",路径 ${skill.path} 对应的分包不存在`);
|
|
243
|
+
}
|
|
244
|
+
return isValid;
|
|
241
245
|
});
|
|
242
246
|
|
|
243
247
|
if (appJson.agent.skills.length === 0) {
|
|
@@ -270,12 +274,11 @@ async function buildOutputAppJson(tmsConfig, modules) {
|
|
|
270
274
|
// 更新主包,需在subpackages处理完成后执行, pages/
|
|
271
275
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
272
276
|
|
|
273
|
-
//
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
277
|
+
// 清理引用了不存在分包/页面的无效配置
|
|
278
|
+
const validPaths = collectValidPaths(appJson);
|
|
279
|
+
cleanPreloadRule(appJson, validPaths);
|
|
280
|
+
cleanEntranceDeclare(appJson, validPaths);
|
|
281
|
+
cleanAgentConfig(appJson, validPaths);
|
|
279
282
|
|
|
280
283
|
// 模板渲染:先将 app.json 转为字符串,然后通过 preprocess 渲染
|
|
281
284
|
const appJsonStr = JSON.stringify(appJson, null, 2);
|