Dependency graph and subpackage boundary analyzer for WeChat Mini Programs, with WXML, JavaScript and WXSS parsers written in MoonBit
$ moon run cmd --target js -- --format text examples/shop-broken
error pages/me/index.wxml:1:1 [wxml-syntax-error] <view> is never closed.
warning packageGoods/detail/index.wxss:2:27 [local-wxss-resource] WXSS cannot load local file /images/logo.png on devices; ...
error pages/index/index.wxml:3:3 [unknown-template] Template 'bannr' is not defined in this file or in a file it imports.
warning pages/index/index.json $.usingComponents["coupon"] [unused-component] <coupon> is declared but never used ...
error packageOrder/confirm/index.json $.usingComponents["thumb"] [cross-subpackage-reference] subpackage order cannot use packageGoods/components/thumb/index ...
error pages/cart/index.js:1:26 [main-package-references-subpackage] The main package cannot use packageGoods/utils/sku.js ...
error packageActivity/landing/index.js:1:29 [independent-subpackage-dependency] Independent subpackage activity must not depend on utils/request.js ...
error pages/me/index.js:3:26 [navigate-to-tab-page] wx.navigateTo cannot open tabBar page pages/cart/index; use wx.switchTab.
error pages/me/index.js:6:25 [switch-tab-to-non-tab-page] wx.switchTab can only open tabBar pages; ...
error components/goods-card/index.js:5:28 [unknown-navigation-target] wx.navigateTo opens 'packageGoods/detial/index', which is not registered in app.json.
warning utils/cache.js:1:23 [require-cycle] Modules require each other: utils/cache.js -> utils/store.js. ...
info utils/legacy-share.js [unreferenced-file] Nothing references this file (36 bytes); ...
info utils/chart.js [move-to-subpackage] Only subpackage goods uses this file; moving it under packageGoods/ would take 94 bytes out of the main package.
Packages:
main 3.8 KiB of 2048.0 KiB 35 files
goods 0.8 KiB of 2048.0 KiB 10 files (0.1 KiB movable from main)
order 0.4 KiB of 2048.0 KiB 3 files
activity 0.1 KiB of 2048.0 KiB 2 files (independent)
8 errors, 3 warnings, 2 notes.cmd/ CLI:参数、Node.js 文件枚举与按需读取、输出与退出码
│
▼
routecheck 分析核心(纯 MoonBit,无 I/O,全部可用内存样例测试)
audit.mbt / preload.mbt / tab_assets.mbt app.json 结构校验
graph.mbt 工作队列遍历 app → 页面 → 组件 → 源文件,生成带位置的类型化依赖边
resolve.mbt 模块解析:相对 / 根路径 / miniprogram_npm 逐级查找、扩展名与 index 补全
rules.mbt 模板作用域、未用组件、分包边界、跳转语义、Tarjan 循环检测、可达性、体积与迁移建议
report.mbt JSON / 文本 / SARIF 2.1.0 / Graphviz DOT
│
├── wxml/ WXML 解析器:元素树、严格闭合检查与错误恢复、{{ }} 感知、<wxs> 原文跳过
├── jsscan/ JS 词法分析器(正则 / 除号判定、模板字符串嵌套、转义解码)+ 依赖与跳转提取
├── wxss/ WXSS 扫描器:@import 与 url(),跳过注释和字符串
└── scan/ 共享游标:字符位置、行列号、BOM 处理moon add jiabin777on-hue/routecheck然后在 moon.pkg 的 import 中加入需要的包,例如 "jiabin777on-hue/routecheck/wxml"。moon run cmd --target js -- examples/shop # JSON 报告
moon run cmd --target js -- --format text examples/shop-broken # 终端阅读
moon run cmd --target js -- --format sarif <目录> > routecheck.sarif
moon run cmd --target js -- --format dot <目录> | dot -Tsvg > deps.svg
moon run cmd --target js -- --strict --max-package-kb 1800 <目录>| 选项 | 说明 |
|---|---|
| --format json\|text\|sarif\|dot | 默认 json。sarif 可直接上传到 GitHub Code Scanning;dot 按包分簇输出依赖图,违规边标红,异步边为虚线。 |
| --strict | warning 也视为失败。 |
| --sarif-base <dir> | SARIF 中的路径改为相对 <dir>(通常是仓库根目录),而不是小程序根目录,便于 Code Scanning 定位源码。 |
| --max-package-kb <n> | 单包上限,默认 2048。 |
| --max-total-kb <n> | 总体积上限,默认 20480。 |
{
"summary": { "errors": 8, "warnings": 3, "infos": 2, "files": 51, "edges": 28 },
"packages": [{ "name": "goods", "root": "packageGoods", "independent": false, "files": 10, "bytes": 841, "movableBytes": 94 }],
"findings": [{ "code": "main-package-references-subpackage", "severity": "error", "file": "pages/cart/index.js", "line": 1, "column": 26, "detail": "..." }],
"moves": [{ "file": "utils/chart.js", "to": "packageGoods/utils/chart.js", "package": "goods", "bytes": 94, "conflict": false,
"rewrites": [{ "file": "packageGoods/detail/index.js", "line": 3, "column": 27, "specifier": "../../utils/chart", "replacement": "../utils/chart" }] }]
}permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v5
- uses: jiabin777on-hue/miniapp-routecheck@v0.3.0
with:
path: .moon test --target js # 64 个测试:三个解析器、解析器边界情况、每类规则(含插件、Worker)、迁移清单、Tarjan、4 个文档测试
moon test --target wasm-gc # 同一套测试在 wasm-gc 上运行(CI 还会跑 native)
node --test test/cli.test.cjs # 13 个端到端测试:样例、SARIF(含 --sarif-base)、DOT、--strict、体积限额、编码、编译插件、参数| 项目 | 文件 | 诊断 | 说明 |
|---|---|---|---|
| Tencent/weui-wxss dist/ | 307 | 0 error,0 warning | 全部 126 条 info 为未被引用的样式文件(WeUI 按需引入的组件样式)。 |
| wechat-miniprogram/miniprogram-demo | 3283 | 50 error,30 warning | 官方示例,TypeScript + Less,11 个分包,含独立分包、Skyline 与 useExtendedLib。 |
git clone --depth 1 --recurse-submodules https://github.com/wechat-miniprogram/miniprogram-demo
moon run cmd --target js -- --format text miniprogram-demopub(all) struct Options {
max_package_bytes : Int
max_total_bytes : Int
}Install
Download zipDependency graph and subpackage boundary analyzer for WeChat Mini Programs, with WXML, JavaScript and WXSS parsers written in MoonBit