fix(miniprogram): restore secondary pages on real devices

This commit is contained in:
2026-08-13 11:32:21 +08:00
parent 58787e738a
commit 39a2e53e61
17 changed files with 192 additions and 23 deletions
+47
View File
@@ -0,0 +1,47 @@
import { existsSync, readFileSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path';
const projectRoot = resolve(import.meta.dirname, '..');
const miniRoot = join(projectRoot, 'miniprogram');
const app = JSON.parse(readFileSync(join(miniRoot, 'app.json'), 'utf8'));
const allowedTags = new Set([
'block',
'button',
'checkbox',
'checkbox-group',
'image',
'input',
'label',
'picker',
'switch',
'text',
'textarea',
'view',
]);
const failures = [];
for (const page of app.pages) {
const base = join(miniRoot, page);
for (const extension of ['.ts', '.json', '.wxml', '.wxss']) {
if (!existsSync(`${base}${extension}`)) failures.push(`${page}${extension} 缺失`);
}
const wxml = readFileSync(`${base}.wxml`, 'utf8');
if (!wxml.trim()) failures.push(`${page}.wxml 为空`);
for (const match of wxml.matchAll(/<\/?([A-Za-z][A-Za-z0-9-]*)/g)) {
if (!allowedTags.has(match[1])) failures.push(`${page}.wxml 使用不支持标签 <${match[1]}>`);
}
const source = readFileSync(`${base}.ts`, 'utf8');
for (const match of source.matchAll(
/wx\.(?:navigateTo|redirectTo)\(\{\s*url:\s*[`'"]([^`'"]+)/g,
)) {
const target = match[1].split('?')[0].replace(/^\//, '');
if (target.includes('${')) continue;
if (!app.pages.includes(target)) failures.push(`${page}.ts 路由未注册:${target}`);
}
}
if (failures.length) {
console.error(failures.join('\n'));
process.exit(1);
}
console.log(`小程序页面完整性检查通过:${app.pages.length} 个页面`);
@@ -0,0 +1,29 @@
import { readFileSync, readdirSync, statSync } from 'node:fs';
import { join, relative } from 'node:path';
const root = new URL('../miniprogram/', import.meta.url);
const sourceRoot = decodeURIComponent(root.pathname).replace(/^\/(?:([A-Za-z]:))/, '$1');
const failures = [];
function walk(directory) {
for (const name of readdirSync(directory)) {
const path = join(directory, name);
if (statSync(path).isDirectory()) walk(path);
else if (path.endsWith('.ts') && !path.endsWith('.spec.ts')) inspect(path);
}
}
function inspect(path) {
const source = readFileSync(path, 'utf8');
const imports = source.matchAll(
/import\s+(?!type\b)[\s\S]*?from\s+['"](@lehuo\/contracts)['"];?/g,
);
for (const match of imports) failures.push(relative(sourceRoot, path));
}
walk(sourceRoot);
if (failures.length) {
console.error(`小程序存在未打包的运行时 workspace 依赖:\n${[...new Set(failures)].join('\n')}`);
process.exit(1);
}
console.log('小程序运行时依赖检查通过');