统一移动壳宿主版本来源
移动壳入口 query 和 runtime 回包共用宿主版本常量 移动壳配置检查拒绝 HostBridge 版本散落硬编码 宿主壳方案和共享决策记录版本单一来源约束
This commit is contained in:
@@ -10,6 +10,8 @@ const bridgePath = new URL('../src/mobileHostBridge.ts', import.meta.url);
|
||||
const bridgeSource = fs.readFileSync(bridgePath, 'utf8');
|
||||
const mobileShellUrlPath = new URL('../src/mobileShellUrl.ts', import.meta.url);
|
||||
const mobileShellUrlSource = fs.readFileSync(mobileShellUrlPath, 'utf8');
|
||||
const mobileShellRuntimePath = new URL('../src/mobileShellRuntime.ts', import.meta.url);
|
||||
const mobileShellRuntimeSource = fs.readFileSync(mobileShellRuntimePath, 'utf8');
|
||||
const sharedContractPath = new URL(
|
||||
'../../../packages/shared/src/contracts/hostBridge.ts',
|
||||
import.meta.url,
|
||||
@@ -66,6 +68,17 @@ function extractStringArrayExport(source, exportName) {
|
||||
return entries;
|
||||
}
|
||||
|
||||
function extractStringConstExport(source, exportName) {
|
||||
const match = source.match(
|
||||
new RegExp(`export const ${exportName}\\s*=\\s*'([^']+)';`),
|
||||
);
|
||||
if (!match) {
|
||||
throw new Error(`unable to read ${exportName}`);
|
||||
}
|
||||
|
||||
return match[1];
|
||||
}
|
||||
|
||||
function collectProductionSourceFiles(entry) {
|
||||
const stats = fs.statSync(entry);
|
||||
if (stats.isDirectory()) {
|
||||
@@ -202,6 +215,14 @@ if (appConfig.version !== '0.1.0') {
|
||||
throw new Error('mobile shell app version must be 0.1.0');
|
||||
}
|
||||
|
||||
const mobileShellHostVersion = extractStringConstExport(
|
||||
mobileShellRuntimeSource,
|
||||
'MOBILE_SHELL_HOST_VERSION',
|
||||
);
|
||||
if (mobileShellHostVersion !== appConfig.version) {
|
||||
throw new Error('mobile shell HostBridge host version must match app.json version');
|
||||
}
|
||||
|
||||
if (appConfig.orientation !== 'default') {
|
||||
throw new Error('mobile shell must allow device orientation for landscape-capable H5 games');
|
||||
}
|
||||
@@ -459,6 +480,18 @@ if (!appSource.includes('capabilities: resolveMobileHostCapabilities()')) {
|
||||
throw new Error('mobile shell URL must use resolveMobileHostCapabilities()');
|
||||
}
|
||||
|
||||
if (!appSource.includes('hostVersion: MOBILE_SHELL_HOST_VERSION')) {
|
||||
throw new Error('mobile shell URL must use the shared mobile shell host version');
|
||||
}
|
||||
|
||||
if (!bridgeSource.includes('hostVersion: MOBILE_SHELL_HOST_VERSION')) {
|
||||
throw new Error('mobile shell runtime response must use the shared mobile shell host version');
|
||||
}
|
||||
|
||||
if (appSource.includes("hostVersion: '0.1.0'") || bridgeSource.includes("hostVersion: '0.1.0'")) {
|
||||
throw new Error('mobile shell HostBridge version must not be duplicated in app or bridge source');
|
||||
}
|
||||
|
||||
for (const capability of sdkBackedCapabilities) {
|
||||
if (appSource.includes(`'${capability}'`) || appSource.includes(`"${capability}"`)) {
|
||||
throw new Error(
|
||||
|
||||
Reference in New Issue
Block a user