feat: 打通 HBuilderX CLI 构建 + 修复文章闭环静态盲区
构建: - 新增 tools/build.js:junction HBuilderX 工具链,CLI 构建 h5/mp-weixin - vue 指向补丁版 @dcloudio/uni-h5-vue(官方 npm vue 不导出 isInSSRComponentSetup) - 设 HX_APP_ROOT 避免退化成 H5 空壳产物;产物完整性校验 校验工具: - 新增 check-cloud-methods.js:acorn 解析云对象方法,比对 94 处调用点 - 新增 check-android-contract.js:Kotlin 侧云对象契约校验 - audit-project.js 修 downloadFile 误报(注释未剥离);tools/ 排除出扫描 - package.json 声明此前隐式依赖的 acorn 功能: - 补 uni-cms-articles.getPublishedArticles(安卓端依赖但此前不存在) - 修 u-parse <audio> 引用已移除组件导致 H5 构建失败
This commit is contained in:
+17
-3
@@ -15,7 +15,9 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const ROOT = path.resolve(__dirname, '..');
|
||||
const IGNORE_DIRS = new Set(['.git', 'node_modules', 'unpackage', '.hbuilderx', '.trae', 'git']);
|
||||
// tools/ 是检查器自身,内部必然包含 importObject 等模式字符串,
|
||||
// 当成业务代码审计只会产生假阳性;.zcode/ 是工具链运行产物。
|
||||
const IGNORE_DIRS = new Set(['.git', 'node_modules', 'unpackage', '.hbuilderx', '.trae', 'git', 'tools', '.zcode']);
|
||||
const SOURCE_EXT = new Set(['.vue', '.js', '.ts', '.json', '.scss', '.css', '.md', '.html']);
|
||||
const JSON_OUT = process.argv.includes('--json');
|
||||
|
||||
@@ -504,6 +506,17 @@ function sectionSecrets(files) {
|
||||
const WRITE_METHOD_RE = /\basync\s+([A-Za-z_$][\w$]*)\s*\(/g;
|
||||
const READONLY_HINTS = /^(get|list|query|search|count|is[A-Z]|_)/;
|
||||
|
||||
/**
|
||||
* 把行注释内容替换为等量空格:长度不变,字节偏移不变,
|
||||
* 因此 lineAt(src, idx) 与 src.slice 仍指向同一位置。
|
||||
*
|
||||
* 不做这层剥离时,被注释掉的 `async foo() {}` 会被 WRITE_METHOD_RE 当成
|
||||
* 活方法,产生「未校验登录态」的假警报(ext-storage-co.downloadFile 就是)。
|
||||
*/
|
||||
function blankLineComments(src) {
|
||||
return src.replace(/^([ \t]*)\/\/.*$/gm, (line) => ' '.repeat(line.length));
|
||||
}
|
||||
|
||||
/**
|
||||
* 云对象方法按"是否写库"与"是否校验登录"分类。
|
||||
* 写方法缺少 checkToken 即为越权风险;读方法缺少则提示可能泄露数据。
|
||||
@@ -513,12 +526,13 @@ function sectionCloudAuth(files, cloudfns) {
|
||||
for (const [name, decl] of cloudfns) {
|
||||
if (decl.isVendor || decl.methods === null) continue;
|
||||
|
||||
let src;
|
||||
let raw;
|
||||
try {
|
||||
src = fs.readFileSync(path.join(ROOT, decl.file), 'utf8');
|
||||
raw = fs.readFileSync(path.join(ROOT, decl.file), 'utf8');
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
const src = blankLineComments(raw);
|
||||
|
||||
// 逐个方法切分,判断方法体内是否有写操作且无鉴权
|
||||
const marks = [];
|
||||
|
||||
Reference in New Issue
Block a user