锁定微信壳页面包装层结构
原生壳门禁新增微信页面目录和页面文件清单反查 宿主壳方案文档同步微信页面包装层和微信能力清单 共享记忆补充三端壳结构和能力文档反查口径
This commit is contained in:
@@ -115,6 +115,18 @@ const expectedWechatShellFiles = [
|
||||
'webView.js',
|
||||
'webView.test.js',
|
||||
];
|
||||
const expectedWechatPageFilesByRoute = {
|
||||
'share-grid': ['index.js', 'index.json', 'index.wxml', 'index.wxss'],
|
||||
'subscribe-message': ['index.js', 'index.json', 'index.wxml', 'index.wxss'],
|
||||
'web-view': [
|
||||
'index.js',
|
||||
'index.json',
|
||||
'index.style.test.js',
|
||||
'index.wxml',
|
||||
'index.wxss',
|
||||
],
|
||||
'wechat-pay': ['index.js', 'index.json', 'index.wxml', 'index.wxss'],
|
||||
};
|
||||
const expectedMobileHostBridgeFiles = [
|
||||
'bridge.test.ts',
|
||||
'bridge.ts',
|
||||
@@ -186,6 +198,15 @@ const documentedShellLayerGroups = [
|
||||
(fileName) => !fileName.includes('.test.'),
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'wechat page wrapper files',
|
||||
files: Object.entries(expectedWechatPageFilesByRoute).flatMap(
|
||||
([route, files]) =>
|
||||
files
|
||||
.filter((fileName) => !fileName.includes('.test.'))
|
||||
.map((fileName) => `${route}/${fileName}`),
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'mobile host bridge files',
|
||||
files: expectedMobileHostBridgeFiles.filter(
|
||||
@@ -215,6 +236,7 @@ const capabilityListMarkers = {
|
||||
desktop: '桌面壳当前真实能力完整清单为',
|
||||
mobile: '移动壳当前通用真实能力完整清单为',
|
||||
mobileIosExtra: '移动壳 iOS 额外真实能力为',
|
||||
wechat: '微信小程序壳当前真实能力完整清单为',
|
||||
};
|
||||
const sharedHostBridgeContractPath =
|
||||
'packages/shared/src/contracts/hostBridge.ts';
|
||||
@@ -579,6 +601,28 @@ function assertSameList(actual, expected, label) {
|
||||
}
|
||||
}
|
||||
|
||||
function readDirectoryFileList(directory, label) {
|
||||
const files = [];
|
||||
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
||||
if (!entry.isFile()) {
|
||||
throw new Error(`${label} must not contain nested entries: ${entry.name}`);
|
||||
}
|
||||
files.push(entry.name);
|
||||
}
|
||||
return files.sort();
|
||||
}
|
||||
|
||||
function readDirectoryNameList(directory, label) {
|
||||
const directories = [];
|
||||
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory()) {
|
||||
throw new Error(`${label} must not contain root files: ${entry.name}`);
|
||||
}
|
||||
directories.push(entry.name);
|
||||
}
|
||||
return directories.sort();
|
||||
}
|
||||
|
||||
function assertShellLayerLayoutDocumented(source, label) {
|
||||
for (const group of documentedShellLayerGroups) {
|
||||
for (const fileName of group.files) {
|
||||
@@ -806,6 +850,11 @@ function assertNativeShellCapabilityPlan() {
|
||||
],
|
||||
'native shell documented method table',
|
||||
);
|
||||
assertSameList(
|
||||
extractDocumentCapabilityList(planSource, capabilityListMarkers.wechat),
|
||||
sharedWechatCapabilities,
|
||||
'wechat mini program documented capabilities',
|
||||
);
|
||||
assertSameList(
|
||||
extractDocumentCapabilityList(planSource, capabilityListMarkers.mobile),
|
||||
mobileCapabilities,
|
||||
@@ -976,35 +1025,39 @@ function assertWechatMiniProgramRouteParity() {
|
||||
}
|
||||
|
||||
function assertHostBridgeLayerLayout() {
|
||||
const wechatBridgeFiles = fs
|
||||
.readdirSync('miniprogram/host-bridge', { withFileTypes: true })
|
||||
.filter((entry) => entry.isFile())
|
||||
.map((entry) => entry.name)
|
||||
.sort();
|
||||
assertSameList(
|
||||
wechatBridgeFiles,
|
||||
readDirectoryFileList(
|
||||
'miniprogram/host-bridge',
|
||||
'wechat host bridge files',
|
||||
),
|
||||
expectedWechatHostBridgeFiles,
|
||||
'wechat host bridge files',
|
||||
);
|
||||
|
||||
const wechatShellLayerFiles = fs
|
||||
.readdirSync('miniprogram/shell', { withFileTypes: true })
|
||||
.filter((entry) => entry.isFile())
|
||||
.map((entry) => entry.name)
|
||||
.sort();
|
||||
assertSameList(
|
||||
wechatShellLayerFiles,
|
||||
readDirectoryFileList('miniprogram/shell', 'wechat shell files'),
|
||||
expectedWechatShellFiles,
|
||||
'wechat shell files',
|
||||
);
|
||||
|
||||
const wechatPagePaths = [
|
||||
'miniprogram/pages/web-view/index.js',
|
||||
'miniprogram/pages/wechat-pay/index.js',
|
||||
'miniprogram/pages/share-grid/index.js',
|
||||
'miniprogram/pages/subscribe-message/index.js',
|
||||
];
|
||||
for (const pagePath of wechatPagePaths) {
|
||||
assertSameList(
|
||||
readDirectoryNameList('miniprogram/pages', 'wechat page directories'),
|
||||
Object.keys(expectedWechatPageFilesByRoute).sort(),
|
||||
'wechat page directories',
|
||||
);
|
||||
|
||||
for (const [route, expectedFiles] of Object.entries(
|
||||
expectedWechatPageFilesByRoute,
|
||||
)) {
|
||||
assertSameList(
|
||||
readDirectoryFileList(
|
||||
`miniprogram/pages/${route}`,
|
||||
`wechat ${route} page wrapper files`,
|
||||
),
|
||||
expectedFiles,
|
||||
`wechat ${route} page wrapper files`,
|
||||
);
|
||||
const pagePath = `miniprogram/pages/${route}/index.js`;
|
||||
const source = fs.readFileSync(pagePath, 'utf8');
|
||||
if (!source.includes("require('../../shell/")) {
|
||||
throw new Error(`${pagePath} must import from miniprogram/shell`);
|
||||
|
||||
Reference in New Issue
Block a user