背景:
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 等关键字段变更
75 lines
3.6 KiB
Plaintext
75 lines
3.6 KiB
Plaintext
{
|
|
// ============================================================================
|
|
// 鸿蒙元服务 entry 模块的必需 HAR 依赖白名单
|
|
//
|
|
// 背景:
|
|
// mp-harmony 项目把 uniapp 编译产物拆成了 6 个鸿蒙模块:
|
|
// - entry (主入口 HAP, 由 DevEco 编译)
|
|
// - components_diy (50+ diy-* 组件的 pack.js, shared HAR)
|
|
// - pages_goods (商品分类/详情/列表/购物车, shared HAR)
|
|
// - pages_order (订单相关页面, shared HAR)
|
|
// - pages_promotion (分销/积分/商户等营销页面, shared HAR)
|
|
// - pages_tool (会员/支付/客服/工具页, shared HAR)
|
|
//
|
|
// entry 的 module.json 默认只会声明 oh-package.json5 里 dependencies 中的 HAR
|
|
// 作为 module dependencies。如果这里不显式声明, 鸿蒙运行时会找不到
|
|
// components-diy/diy-group.pack.js 等子包 chunk,
|
|
// DIY 首页 / 商品分类 / 订单 / 营销页 全部被 componentPlaceholder fallback 成 <view>,
|
|
// 表现为: 首页 DIY 内容不显示, 12s splash 兜底超时, TabBar 点击无反应。
|
|
//
|
|
// 必须:
|
|
// entry/oh-package.json5 的 dependencies 必须保留以下 5 个 file: 依赖。
|
|
// 不要轻易删除, 删除前请先和 ascf 子包负责人对齐。
|
|
//
|
|
// 验证:
|
|
// 执行 `node scripts/check-har-deps.js` 校验当前 module.json 是否包含这些依赖。
|
|
// ============================================================================
|
|
requiredHarDeps: [
|
|
"components_diy",
|
|
"pages_goods",
|
|
"pages_order",
|
|
"pages_promotion",
|
|
"pages_tool",
|
|
],
|
|
|
|
// oh-package.json5 里依赖声明的预期 source 字符串
|
|
// (DevEco/ohpm 解析后会规范化, 这里保留原始声明便于核对)
|
|
expectedDependencySources: {
|
|
components_diy: "file:../ascf/ascf_build/components_diy",
|
|
pages_goods: "file:../ascf/ascf_build/pages_goods",
|
|
pages_order: "file:../ascf/ascf_build/pages_order",
|
|
pages_promotion: "file:../ascf/ascf_build/pages_promotion",
|
|
pages_tool: "file:../ascf/ascf_build/pages_tool",
|
|
},
|
|
|
|
// 校验脚本要扫描的产物路径 (相对 entry 目录)
|
|
buildArtifacts: {
|
|
moduleJson: "build/default/intermediates/package/default/module.json",
|
|
},
|
|
|
|
// oh_modules 子包内 rawfile 根目录映射 (用于 --rawfile 检查)
|
|
// 子包 HAR 通过 ohpm 同步后落在 entry/oh_modules/<pkg>/src/main/resources/rawfile/<root>/
|
|
// HAR 资源在运行时由鸿蒙端通过 HAR 共享机制加载, 不是 entry 的 rawfile 路径
|
|
ohModulesRoots: {
|
|
components_diy: {
|
|
pkg: "components_diy",
|
|
root: "components-diy",
|
|
},
|
|
pages_goods: { pkg: "pages_goods", root: "pages_goods" },
|
|
pages_order: { pkg: "pages_order", root: "pages_order" },
|
|
pages_promotion:{ pkg: "pages_promotion",root: "pages_promotion" },
|
|
pages_tool: { pkg: "pages_tool", root: "pages_tool" },
|
|
},
|
|
|
|
// 每个子包在 ascf_build 中的 src/main/module.json5 路径 (相对 mp-harmony 目录)
|
|
// 用于校验 module.name 字段是否被 vue.config.js 重新生成时清空
|
|
// 现象: pages_tool 的 module.json5 的 module.name 被覆盖成 "",
|
|
// 导致 hvigor schema 校验失败, build 阶段直接退出。
|
|
subpackageModuleJson5: {
|
|
components_diy: "./ascf/ascf_build/components_diy/src/main/module.json5",
|
|
pages_goods: "./ascf/ascf_build/pages_goods/src/main/module.json5",
|
|
pages_order: "./ascf/ascf_build/pages_order/src/main/module.json5",
|
|
pages_promotion: "./ascf/ascf_build/pages_promotion/src/main/module.json5",
|
|
pages_tool: "./ascf/ascf_build/pages_tool/src/main/module.json5",
|
|
},
|
|
} |