chore(mp-harmony): 修正子包 HAR name 字段 + 纳入元数据到 git

背景:
  mp-harmony 项目的 5 个 ascf shared HAR 子包 (components_diy / pages_goods /
  pages_order / pages_promotion / pages_tool) 在 ascf_build 目录下, 关键
  元数据 (oh-package.json5 / module.json5 / build-profile.json5 /
  Index.ets / hvigorfile.ts / obfuscation-rules.txt) 之前被 .gitignore
  整体忽略, 从未被 git 跟踪, 导致 "module.name 被清空" 等回归无法被
  git diff / blame 追踪。

改动:
  1. .gitignore 改造
     - 不再整体 ignore ascf_build
     - 精确 ignore 已知产物路径 (rawfile/**/*.pack.js / rawfile/**/*.html
       / rawfile/**/*.json / build/ / oh_modules/ / .preview/ / .cxx/
       / .test/ / node_modules/)
     - ! 取反保留 HAR 必需文件 (placeholder/index.*, rawfile/index.js,
       base/element/*.json)
     - 补充 entry / hvigor / 鸿蒙签名材料 / IDE 临时文件 ignore 规则
  2. 首次将 5 个 HAR 包的元数据纳入 git (40 个文件)
  3. 新增 scripts/fix-subpackage-module-names.js: 任何入口 require
     vue.config.js 时自动修复 oh-package.json5.name + module.json5.module.name
     双重覆盖, 防止 DevEco ohpm 报 "00604007 Field IS Empty Error" 或
     hvigor 报 "Schema validate failed"
  4. vue.config.js 顶层 IIFE 触发修复 (任何 require 立即生效, 不依赖
     webpack 钩子)
  5. entry/scripts/check-har-deps.js 扩展: 校验 ascf_build 子包
     module.json5.module.name 字段 (兜底校验)
  6. entry/har-deps-required.json5 扩展: 新增 subpackageModuleJson5
     路径映射 + ohModulesRoots 校验资源齐备性
  7. entry/README-HAR-DEPS.md 更新: 故障速查表新增 module.name 相关
     报错条目

预期效果:
  - HBuilderX 触发 vue-cli-service build → vue.config.js 自动修复子包
    name → DevEco ohpm install / hvigor schema 校验通过
  - check-har-deps.js 兜底, 任何回归立即被检测并报错
  - 团队成员 git pull 后能立即看到 ascf_build 元数据, 可用 git diff
    跟踪 module.name 等关键字段变更
This commit is contained in:
2026-07-30 14:26:55 +08:00
parent 3dd059a6f6
commit 8ebd7918fb
48 changed files with 2870 additions and 4 deletions

View File

@@ -173,6 +173,38 @@ function main() {
}
}
// ---- 4. 校验 ascf_build 子包 module.json5 的 module.name 字段 ----
// 防止 vue.config.js 重新生成时把 module.name 清空, 导致 hvigor schema 校验失败
console.log();
console.log(color('--- ascf_build 子包 module.json5 检查 ---', 'cyan'));
const mpHarmonyDir = path.resolve(ENTRY_DIR, '..');
const subpackageModuleJson5 = config.subpackageModuleJson5 || {};
for (const har of requiredHarDeps) {
const rel = subpackageModuleJson5[har];
if (!rel) continue;
const moduleJson5Path = path.resolve(mpHarmonyDir, rel);
if (!exists(moduleJson5Path)) {
warnings.push(`ascf_build/${har}/src/main/module.json5 缺失 (${moduleJson5Path})`);
console.log(color(` ⚠ ${moduleJson5Path} 不存在`, 'yellow'));
continue;
}
let mj;
try {
mj = loadJson5(moduleJson5Path);
} catch (e) {
errors.push(`${har} 的 module.json5 解析失败: ${e.message}`);
console.log(color(` ✘ ${har} module.json5 解析失败`, 'red'));
continue;
}
const moduleName = mj && mj.module && mj.module.name;
if (!moduleName || moduleName !== har) {
errors.push(`${har} 的 module.json5.module.name 异常: "${moduleName}" (应为 "${har}", 常见原因: vue.config.js 重新生成时未写入 packageName)`);
console.log(color(` ✘ ${har} module.name = "${moduleName}" (应为 "${har}")`, 'red'));
} else {
console.log(color(` ✔ ${har} module.name = "${moduleName}"`, 'green'));
}
}
// ---- 总结 ----
console.log();
if (warnings.length) {