catchword 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +314 -2
- package/bin/catchword.js +8 -0
- package/bin/falcon.js +5 -0
- package/dist/cli/adb.d.ts +6 -0
- package/dist/cli/adb.js +52 -0
- package/dist/cli/audit.d.ts +4 -0
- package/dist/cli/audit.js +91 -0
- package/dist/cli/build.d.ts +13 -0
- package/dist/cli/build.js +139 -0
- package/dist/cli/clean.d.ts +1 -0
- package/dist/cli/clean.js +15 -0
- package/dist/cli/create.d.ts +4 -0
- package/dist/cli/create.js +60 -0
- package/dist/cli/dev.d.ts +10 -0
- package/dist/cli/dev.js +23 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +243 -0
- package/dist/cli/native.d.ts +18 -0
- package/dist/cli/native.js +232 -0
- package/dist/cli/simulator.d.ts +8 -0
- package/dist/cli/simulator.js +77 -0
- package/dist/cli/upload.d.ts +9 -0
- package/dist/cli/upload.js +135 -0
- package/dist/cli/util.d.ts +8 -0
- package/dist/cli/util.js +43 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +90 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +51 -0
- package/dist/native/api.d.ts +46 -0
- package/dist/native/api.js +185 -0
- package/dist/native/build.d.ts +47 -0
- package/dist/native/build.js +407 -0
- package/dist/native/elf.d.ts +15 -0
- package/dist/native/elf.js +200 -0
- package/dist/native/types.d.ts +9 -0
- package/dist/native/types.js +91 -0
- package/dist/native/wsl.d.ts +7 -0
- package/dist/native/wsl.js +29 -0
- package/dist/plugin/app-entry.d.ts +6 -0
- package/dist/plugin/app-entry.js +115 -0
- package/dist/plugin/assets.d.ts +4 -0
- package/dist/plugin/assets.js +84 -0
- package/dist/plugin/config.d.ts +14 -0
- package/dist/plugin/config.js +80 -0
- package/dist/plugin/context.d.ts +58 -0
- package/dist/plugin/context.js +255 -0
- package/dist/plugin/fallback.d.ts +4 -0
- package/dist/plugin/fallback.js +81 -0
- package/dist/plugin/image-service.d.ts +17 -0
- package/dist/plugin/image-service.js +138 -0
- package/dist/plugin/jsapi.d.ts +6 -0
- package/dist/plugin/jsapi.js +82 -0
- package/dist/plugin/output.d.ts +4 -0
- package/dist/plugin/output.js +75 -0
- package/dist/plugin/preview.d.ts +34 -0
- package/dist/plugin/preview.js +459 -0
- package/dist/plugin/sanitize.d.ts +5 -0
- package/dist/plugin/sanitize.js +48 -0
- package/dist/plugin/security.d.ts +4 -0
- package/dist/plugin/security.js +18 -0
- package/dist/plugin/sfc.d.ts +6 -0
- package/dist/plugin/sfc.js +181 -0
- package/dist/plugin/shim.d.ts +4 -0
- package/dist/plugin/shim.js +68 -0
- package/dist/plugin/state.d.ts +31 -0
- package/dist/plugin/state.js +61 -0
- package/dist/plugin/string-table.d.ts +7 -0
- package/dist/plugin/string-table.js +324 -0
- package/dist/plugin/style.d.ts +15 -0
- package/dist/plugin/style.js +114 -0
- package/dist/plugin/template.d.ts +7 -0
- package/dist/plugin/template.js +39 -0
- package/dist/steps/manifest.d.ts +9 -0
- package/dist/steps/manifest.js +60 -0
- package/dist/steps/pack.d.ts +3 -0
- package/dist/steps/pack.js +46 -0
- package/dist/steps/qjsc.d.ts +9 -0
- package/dist/steps/qjsc.js +186 -0
- package/dist/steps/report.d.ts +2 -0
- package/dist/steps/report.js +50 -0
- package/dist/steps/security.d.ts +17 -0
- package/dist/steps/security.js +310 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.js +1 -0
- package/dist/util/class-tokenize.d.ts +2 -0
- package/dist/util/class-tokenize.js +56 -0
- package/dist/util/component-name.d.ts +6 -0
- package/dist/util/component-name.js +120 -0
- package/dist/util/fs.d.ts +14 -0
- package/dist/util/fs.js +70 -0
- package/dist/util/imports.d.ts +2 -0
- package/dist/util/imports.js +173 -0
- package/dist/util/log.d.ts +8 -0
- package/dist/util/log.js +24 -0
- package/package.json +61 -4
- package/template/README.md +38 -0
- package/template/catchword.config.ts +18 -0
- package/template/native/CMakeLists.txt +33 -0
- package/template/native/README.md +34 -0
- package/template/native/api.override.json +7 -0
- package/template/native/include/jsapi_demo.h +10 -0
- package/template/native/lib/README.md +10 -0
- package/template/native/sdk/README.md +6 -0
- package/template/native/src/bridge.cpp +9 -0
- package/template/native/src/jsapi_demo.cpp +11 -0
- package/template/package.json +38 -0
- package/template/src/app.js +45 -0
- package/template/src/app.json +11 -0
- package/template/src/base-page.js +150 -0
- package/template/src/components/HelloWorld.vue +20 -0
- package/template/src/mocks/$jsapi.test.js +5 -0
- package/template/src/mocks/test-module.js +5 -0
- package/template/src/pages/index/index.vue +41 -0
- package/template/src/pages/page/page.vue +63 -0
- package/template/src/shims.d.ts +21 -0
- package/template/src/styles/base.less +23 -0
- package/template/src/styles/mixin.less +32 -0
- package/template/src/styles/var.less +15 -0
- package/template/tsconfig.json +14 -0
- package/vendor/README.md +16 -0
- package/vendor/falcon-styler/.jscsrc +31 -0
- package/vendor/falcon-styler/LICENSE +21 -0
- package/vendor/falcon-styler/README.md +124 -0
- package/vendor/falcon-styler/index.js +273 -0
- package/vendor/falcon-styler/lib/shorthand-parser.js +78 -0
- package/vendor/falcon-styler/lib/util.js +30 -0
- package/vendor/falcon-styler/lib/validator.js +846 -0
- package/vendor/falcon-styler/package.json +32 -0
- package/vendor/licenses/falcon-styler.LICENSE +21 -0
- package/vendor/licenses/weex-template-compiler.README.md +3 -0
- package/vendor/package.json +5 -0
- package/vendor/qjsc/SHA256SUMS +11 -0
- package/vendor/qjsc/bin/darwin/arm64/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200412 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200906 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200412 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200906 +0 -0
- package/vendor/qjsc/bin/linux/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/win32/libgcc_s_dw2-1.dll +0 -0
- package/vendor/qjsc/bin/win32/pthreadGC-3.dll +0 -0
- package/vendor/qjsc/bin/win32/qjsc20200705.exe +0 -0
- package/vendor/web/falcon-js-web.js +863 -0
- package/vendor/web/falcon-jsapi-web.js +479 -0
- package/vendor/web/falcon-vue-render.js +11323 -0
- package/vendor/web/falcon-web-boot.js +4 -0
- package/vendor/web/falcon-web-hud.js +119 -0
- package/vendor/web/falcon-web-style.js +235 -0
- package/vendor/web/vue.runtime.common.dev.js +8467 -0
- package/vendor/web/vue.runtime.common.js +5 -0
- package/vendor/weex-template-compiler/README.md +3 -0
- package/vendor/weex-template-compiler/build.js +4824 -0
- package/vendor/weex-template-compiler/index.js +17 -0
- package/vendor/weex-template-compiler/package.json +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 falcon-vite contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,315 @@
|
|
|
1
|
-
#
|
|
1
|
+
# catchword
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
用 Vite 8重写的 Falcon 小程序构建工具。目标设备运行时仍是固件提供的
|
|
4
|
+
Vue 2.6.14 + Weex 渲染器,本工具负责把 `.vue` / `.ts` 工程编译成 `.falcon_` 目录、
|
|
5
|
+
QuickJS 字节码和 `.amr` 安装包。
|
|
6
|
+
|
|
7
|
+
本工具是非官方社区项目,与网易、有道官方无关;Falcon 仅指目标设备运行时。
|
|
8
|
+
|
|
9
|
+
## 命令
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
catchword build [options] # 默认命令,构建到 .falcon_
|
|
13
|
+
-c, --compress # oxc 压缩
|
|
14
|
+
-q, --qjsc # qjsc 预编译为 .js.bin
|
|
15
|
+
-p, --pack # 生成 manifest.json 并打 .amr
|
|
16
|
+
-m, --mock # api-mock 目录模拟 $jsapi
|
|
17
|
+
-e, --env <k=v ...> # 构建期常量
|
|
18
|
+
|
|
19
|
+
catchword dev|preview # 浏览器预览(Vite dev server)
|
|
20
|
+
--host --port --open # 默认只监听 127.0.0.1,局域网访问需 --host 0.0.0.0
|
|
21
|
+
|
|
22
|
+
catchword adb [amr] # adb push → miniapp_cli install → start → 清理
|
|
23
|
+
catchword upload [amr] # HTTP 推包到设备(默认 127.0.0.1:5556)
|
|
24
|
+
catchword simulator # 启动 appx 模拟器并监听源码变化
|
|
25
|
+
catchword create <name> [--preset native] # 从内置模板创建工程
|
|
26
|
+
catchword native api # 从 C++ 源码抽取原生契约到 api.json
|
|
27
|
+
catchword native types # 由 api.json 生成 TypeScript 声明
|
|
28
|
+
catchword native types --check # 只比对声明是否漂移(CI 用)
|
|
29
|
+
catchword native build -t x7 # 交叉编译 libjsapi_bridge_x7.so
|
|
30
|
+
catchword native verify -t x7 # 校验架构、GLIBC、依赖与导出符号
|
|
31
|
+
catchword native verify --strict # 将依赖/导出提示视为失败(CI 用)
|
|
32
|
+
catchword audit [--strict] # 审计产物中可被逆向提取的字符串/标识符/URL/源路径
|
|
33
|
+
catchword clean # 清理 .falcon_ / .falcon_tmp / .amr
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
全局选项:`-d, --dir <dir>`(工程目录,默认 `./`)、`-s, --silent`。
|
|
37
|
+
|
|
38
|
+
## 配置文件(catchword.config.ts)
|
|
39
|
+
|
|
40
|
+
工程根目录可以放一份 `catchword.config.ts`。
|
|
41
|
+
命令行参数、配置项、默认值按 CLI > 配置 > 默认 覆盖
|
|
42
|
+
|
|
43
|
+
旧项目仍可继续使用 `falcon.config.*` 文件名、`falcon` 命令,以及 `package.json` 顶层的 `falcon.*` 字段;新工程优先使用 `catchword.*`。
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { defineConfig } from 'catchword'
|
|
47
|
+
|
|
48
|
+
export default defineConfig({
|
|
49
|
+
build: {
|
|
50
|
+
compress: true,
|
|
51
|
+
qjsc: true,
|
|
52
|
+
pack: true,
|
|
53
|
+
mock: false,
|
|
54
|
+
env: ['DEBUG'],
|
|
55
|
+
define: { __APP_VERSION__: '1.2.3' }
|
|
56
|
+
},
|
|
57
|
+
device: {
|
|
58
|
+
name: 'x7',
|
|
59
|
+
logical: { width: 960, height: 266 },
|
|
60
|
+
panel: { width: 480, height: 960, rotation: 1 },
|
|
61
|
+
dpr: 2,
|
|
62
|
+
viewport: 960,
|
|
63
|
+
fontMetrics: 'builtin'
|
|
64
|
+
},
|
|
65
|
+
preview: {
|
|
66
|
+
host: '0.0.0.0',
|
|
67
|
+
port: 8081,
|
|
68
|
+
open: false,
|
|
69
|
+
mockDir: 'api-mock',
|
|
70
|
+
stage: true,
|
|
71
|
+
stageScale: 'fit'
|
|
72
|
+
},
|
|
73
|
+
simulator: { path: '/path/to/simulator', page: 'index' },
|
|
74
|
+
hooks: {
|
|
75
|
+
beforeBuild(ctx) {},
|
|
76
|
+
afterBuild(ctx, success) {}
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
也支持函数形式,拿到本次命令的 mode:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
export default defineConfig(({ mode }) => ({
|
|
85
|
+
build: { qjsc: mode === 'production' }
|
|
86
|
+
}))
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 设备画像与预览台架
|
|
90
|
+
|
|
91
|
+
`device` 决定浏览器预览里的 `$falcon.env.deviceWidth / deviceHeight / dpr`。
|
|
92
|
+
配置后 `window.__FALCON_PROFILE__` 会注入到预览页,渲染器的 viewport 与
|
|
93
|
+
`meta.setViewport` 都以它为准,不再取浏览器窗口大小:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
device: {
|
|
97
|
+
name: "x7",
|
|
98
|
+
logical: { width: 960, height: 266 },
|
|
99
|
+
panel: { width: 480, height: 960, rotation: 1 },
|
|
100
|
+
dpr: 2,
|
|
101
|
+
viewport: 960, // 可选:px2rem 的设计宽,默认沿用 750
|
|
102
|
+
fontMetrics: "builtin"
|
|
103
|
+
}
|
|
104
|
+
preview: { stage: true, stageScale: "fit" } // stage: false 退回整窗预览
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 预览中的原生 JSAPI
|
|
108
|
+
|
|
109
|
+
浏览器里没有 native 能力。`catchword dev` 用 `vendor/web/falcon-jsapi-web.js` 提供替身,
|
|
110
|
+
合并进 `$falcon.jsapi`,因此 `$jsapi/<name>` 和 `import bridge from "bridge"` 在预览与真机上
|
|
111
|
+
是同一套入口(dev 下 `bridge` 会被解析到这个替身)。
|
|
112
|
+
|
|
113
|
+
| 模块 | 预览里的行为 |
|
|
114
|
+
| ------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
|
|
115
|
+
| `Fetch` | 真实浏览器 `fetch`;`fetch()` 返回 `{ ok, status, body, text() }`,`downloadFile()` 落到 localStorage |
|
|
116
|
+
| `Dbase` / `Datas` | localStorage(键前缀 `falcon.dbase:`),同步读写,支持 `read/write/remove/exists/keys` |
|
|
117
|
+
| `Shell` | 只支持回放,未命中即抛错 |
|
|
118
|
+
| `Files` `Spell` `HttpServer` `Camera` `Video` `McFast` | 保留模块与方法,`available === false`,调用即抛错 |
|
|
119
|
+
|
|
120
|
+
- `Shell` 回放:`preview: { shell: { "cat /userdisk/packages.json": "[]" } }`,按整条命令或前缀命中。
|
|
121
|
+
- 其余原生模块在 mock 目录中用 `$jsapi.<name>.js` 提供实现,dev 下自动加载(不需要 `-m`)。
|
|
122
|
+
目录默认是工程根 `api-mock/`,可以用 `preview: { mockDir: "src/mocks" }` 改到源目录下:
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
// src/mocks/$jsapi.Camera.js
|
|
126
|
+
export default { start() {}, stop() {} }
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- `$jsapi/<name>` 取不到实现时在导入期抛错,并指明应该创建哪个 mock 文件;不会把 `undefined` 交给业务代码。
|
|
130
|
+
- 所有调用记进 `window.__FALCON_JSAPI_CALLS__`(module / method / args / time),可用于真机与预览的调用面对比。
|
|
131
|
+
- 预览启动时控制台会打印一行:哪些模块是真实现、哪些只是占位。
|
|
132
|
+
|
|
133
|
+
## 原生 JSAPI 工程
|
|
134
|
+
|
|
135
|
+
`catchword create <name> --preset native` 或 `catchword native init` 会在工程里生成 `native/`:
|
|
136
|
+
|
|
137
|
+
```text
|
|
138
|
+
native/
|
|
139
|
+
src/bridge.cpp # kModules 注册表
|
|
140
|
+
src/jsapi_<name>.cpp # 模块实现
|
|
141
|
+
include/
|
|
142
|
+
sdk/include/ # 设备 SDK 头文件
|
|
143
|
+
lib/ # 设备库副本,交叉编译时链接
|
|
144
|
+
api.json # 由源码生成,提交
|
|
145
|
+
api.d.ts # 由 api.json 生成,提交
|
|
146
|
+
api.override.json # 唯一手写的契约补充
|
|
147
|
+
libs/ # 编译产物,进入 .amr
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
对应配置:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
native: {
|
|
154
|
+
dir: "native",
|
|
155
|
+
targets: {
|
|
156
|
+
x7: {
|
|
157
|
+
buildDir: "native/build/x7",
|
|
158
|
+
out: "libs/libjsapi_bridge_x7.so",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
一条命令完成契约抽取、类型生成、交叉编译与校验:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
bun run native
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
CI 中用 `bun run native:check` 检查 `api.json` 和 `api.d.ts` 是否漂移。模块名需要与
|
|
171
|
+
`import "$jsapi/<Name>"`、`src/mocks/$jsapi.<Name>.js` 保持一致。
|
|
172
|
+
|
|
173
|
+
`catchword native verify` 会输出架构、GLIBC 上限、`DT_NEEDED`、`SONAME`、未解析符号和导出符号;
|
|
174
|
+
默认只提示,加 `--strict` 后把以下情况视为失败:
|
|
175
|
+
|
|
176
|
+
- 依赖了 `libstdc++.so.6` 等额外运行库;
|
|
177
|
+
- 依赖不在 `native.targets.<target>.allowedNeeded` 白名单中;
|
|
178
|
+
- 没有导出 `custom_init_jsapis`;
|
|
179
|
+
- 导出符号过多,通常说明没有加 `-fvisibility=hidden`。
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
native: {
|
|
183
|
+
targets: {
|
|
184
|
+
x7: {
|
|
185
|
+
allowedNeeded: ["libc.so.6", "libpthread.so.0", "libdl.so.2", "libm.so.6"],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## 在 vite.config 中使用
|
|
192
|
+
|
|
193
|
+
CLI 内部以 `configFile: false` 调用 Vite。也可以自己写配置:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { defineConfig } from 'vite'
|
|
197
|
+
import catchword from 'catchword'
|
|
198
|
+
|
|
199
|
+
export default defineConfig({
|
|
200
|
+
plugins: [catchword({ dir: __dirname })]
|
|
201
|
+
})
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
注意:设备构建与浏览器预览都由插件的 `config()` 决定,不需要再写 `build.rollupOptions`。
|
|
205
|
+
|
|
206
|
+
## 产物
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
.falcon_/
|
|
210
|
+
app.js(.bin) # 入口:App.meta / __AppClazz / __loadModuleDefault / __KEYFRAMES
|
|
211
|
+
<page>.js(.bin) # 每个页面一个入口,运行时按需 import
|
|
212
|
+
chunk-*.js(.bin) # 共享 chunk(如 defineComponent shim)
|
|
213
|
+
images/<md5>.png # 图片(默认不内联为 base64;`?base64` 显式内联)
|
|
214
|
+
assets/ # 媒体文件 / 工程根 assets 目录同步
|
|
215
|
+
services/ providers/ # app.json 中的服务与 provider
|
|
216
|
+
manifest.json # appName/appid/version/quickjs/meta/props/cert(size+md5)
|
|
217
|
+
<appid>.<version>.amr # zip 容器,写入工程根目录
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
`-q` 会把每个 `.js` 编译成 `.js.bin` 并删除原文件;`manifest.json` 在 qjsc 之后生成,
|
|
221
|
+
cert 覆盖最终文件。`.amr` 的容器格式与旧 CLI 一致,仍以真机 `miniapp_cli install` 返回
|
|
222
|
+
`{"ret": 0}` 为验收标准。`-p` 还会在 `.amr` 同目录生成 `<appid>.<version>.amr.sha256`
|
|
223
|
+
(`sha256sum -c` 格式),它不进入安装包。
|
|
224
|
+
|
|
225
|
+
## 安全构建
|
|
226
|
+
|
|
227
|
+
以下检查全部发生在开发机/CI 的构建阶段,不向设备运行时注入代码、守护进程或额外依赖:
|
|
228
|
+
|
|
229
|
+
- **源码路径**:非压缩构建会在 `renderChunk` 阶段剥离构建注释(保留 `@license` 等许可注释),
|
|
230
|
+
打包前再扫描产物;若仍出现工程绝对路径则失败。`-c` 压缩构建本身已不保留注释。
|
|
231
|
+
- **敏感字符串**:扫描所有文本产物(包括 `assets/`、`libs/` 和 qjsc 后的 `.js.bin`)中的
|
|
232
|
+
私钥、云厂商 AccessKey、GitHub/GitLab/npm/Stripe/OpenAI 等常见密钥格式,以及
|
|
233
|
+
`package.json` 的 `catchword.forbiddenStrings`。任何命中都会中止构建。
|
|
234
|
+
确认误报时可设置 `catchword.skipSecretScan: true`。
|
|
235
|
+
- **敏感文件**:`.env`、`.npmrc`、`.git*`、`.ssh` 等隐藏配置文件一旦出现在产物中即失败。
|
|
236
|
+
根目录 `assets/`、`libs/`、`jsworkers/` 同步到产物时会跳过隐藏文件、`.map` 和软链接。
|
|
237
|
+
- **manifest.cert**:打包前重新计算每个文件的大小与 MD5,并要求构建目录中除 `manifest.json`
|
|
238
|
+
自身外的每个文件都出现在 cert 中;生成清单后再被塞入的文件(例如 `.env`)会导致构建失败。
|
|
239
|
+
- **qjsc 二进制**:使用 `vendor/qjsc/SHA256SUMS` 校验将要执行的 qjsc 及其 DLL;
|
|
240
|
+
校验失败会中止构建。自定义/本地构建可设置 `catchword.skipQjscVerify: true`。
|
|
241
|
+
- **sourcemap**:产物中出现任何 `.map` 或内联 `sourceMappingURL=data:` 直接失败;
|
|
242
|
+
Vite 构建本身已关闭 sourcemap。
|
|
243
|
+
- **远程图片**:`?download` / `?base64` 的构建期下载有 30 秒超时和 32MB 上限,
|
|
244
|
+
失败会回退为原始 URL(与原有行为一致),避免构建被慢响应或超大响应拖死。
|
|
245
|
+
|
|
246
|
+
字符串表编码默认开启(`catchword.keepStrings: true` 可关闭)。编码表在模块加载时一次性解码并
|
|
247
|
+
原地替换,运行期 `__falconStr(i)` 只做数组下标,不需要每次调用重新解码;这是提高静态分析
|
|
248
|
+
成本的混淆措施,不是加密,密钥与解码器都在产物内。
|
|
249
|
+
|
|
250
|
+
直接使用 `catchwordVite()` 插件跑 `vite build` 时,插件会在 `closeBundle` 执行源码路径、敏感
|
|
251
|
+
文件、密钥与 sourcemap 检查;manifest、qjsc 与 `.amr` 仍由 `catchword build` 负责。
|
|
252
|
+
|
|
253
|
+
### 逆向分析与防护边界
|
|
254
|
+
|
|
255
|
+
QuickJS 字节码不保留原始语句和局部变量名,但 atom 字符串仍以明文存在。实际逆向流程通常是:
|
|
256
|
+
解 `.amr` → 对每个 `.js.bin` 提取 `[\x20-\x7e]{4,}` ASCII atom → 用 8 字符以上的标识符/
|
|
257
|
+
中文串与公开源码做 IDF 相似度 → 对比原生 `.so` 的导出符号与构建路径。
|
|
258
|
+
|
|
259
|
+
默认防护:
|
|
260
|
+
|
|
261
|
+
- 字符串表把长字符串、URL、UI 文案编码(`keepStrings: true` 会关闭);
|
|
262
|
+
- `App.meta` 只保留页面/服务 key,删除 `.vue`/`.ts` 源路径和 `options.alias/style`
|
|
263
|
+
(`keepMetaPaths: true` 恢复旧行为);
|
|
264
|
+
- 产物及字符串表原始值中出现源文件路径(如 `pages/...vue`)会直接失败;
|
|
265
|
+
- `@keyframes` 名称 token 化(`keepKeyframeNames: true` 可关闭);
|
|
266
|
+
- 类名 token 化、组件 `name`/SFC 元数据剥离、非压缩构建剥离注释;
|
|
267
|
+
- 原生库出现 `.symtab`、调试段或构建机路径时给出告警。
|
|
268
|
+
|
|
269
|
+
仍然可见、且属于运行时 ABI/路由的一部分:
|
|
270
|
+
|
|
271
|
+
- Vue/Weex 必需的属性名、样式键、生命周期名;
|
|
272
|
+
- 页面 key 与 `<page>.js.bin` 文件名;
|
|
273
|
+
- 字符串表可以被还原(这是混淆,不是加密);
|
|
274
|
+
- `.so` 的 `.dynsym` 导出(JSAPI 需要)。
|
|
275
|
+
|
|
276
|
+
发布建议:
|
|
277
|
+
|
|
278
|
+
1. 使用 `catchword build -c -q -p`;不要设置 `keepStrings`、`keepMetaPaths`、
|
|
279
|
+
`keepKeyframeNames`、`keepComponentNames`、`keepMetadata`。
|
|
280
|
+
2. 原生库发布前 `strip --strip-unneeded`(交叉编译可用 `llvm-strip`),编译加
|
|
281
|
+
`-fvisibility=hidden -ffile-prefix-map=<构建目录>=.`,并关闭调试信息。
|
|
282
|
+
3. 页面 key、组件/方法命名不要与公开仓库逐字一致;端点、密钥和业务规则放服务端。
|
|
283
|
+
4. 若代码源自 GPL/公开仓库,技术混淆不改变许可证义务。
|
|
284
|
+
|
|
285
|
+
Rolldown 的 `minify.mangleProps` 目前要求单一 JS 输出 chunk;多页面按需加载不满足该条件。
|
|
286
|
+
属性名混淆还必须保留 Vue/Weex 运行时键、样式键、生命周期、动态访问和持久化字段,风险较高,
|
|
287
|
+
因此未作为默认能力启用。
|
|
288
|
+
|
|
289
|
+
构建后可以运行 `catchword audit`,用与逆向工具相同的「可打印 ASCII atom → 标识符/URL/源路径」
|
|
290
|
+
方法审计自己的产物;它只读取 `.falcon_`,不会执行包内代码。
|
|
291
|
+
|
|
292
|
+
## QuickJS 版本
|
|
293
|
+
|
|
294
|
+
qjsc 二进制在 `vendor/qjsc/bin/`,按 `package.json` 的 `quickjs.version` 与 `bigNum` 选择:
|
|
295
|
+
|
|
296
|
+
| 平台 | 版本 |
|
|
297
|
+
| ------------ | ------------------------------------------------ |
|
|
298
|
+
| win32 | 20200705 |
|
|
299
|
+
| linux | 20200705 |
|
|
300
|
+
| darwin arm64 | 20200705 |
|
|
301
|
+
| darwin x64 | 20200412 / 20200705 / 20200906(含 bignum 变体) |
|
|
302
|
+
|
|
303
|
+
字节码必须与设备固件内的 QuickJS 版本匹配,不要随意升级。缺失的平台/版本会给出明确报错。
|
|
304
|
+
执行前会用 `vendor/qjsc/SHA256SUMS` 校验所选 qjsc 与同目录 DLL;新增/替换二进制时请同步更新该
|
|
305
|
+
清单,或在 `package.json` 设置 `catchword.skipQjscVerify: true` 跳过。
|
|
306
|
+
|
|
307
|
+
## 已知限制
|
|
308
|
+
|
|
309
|
+
- 浏览器预览是"重新实现平台的 Web 版",只覆盖 DOM 布局/页面栈/JSAPI 桩;媒体、输入法、
|
|
310
|
+
- 不支持 Vue 3.5 运行时。若要切换,需要把 Vue 3 + Weex renderer 移植进 `.amr`,
|
|
311
|
+
并接受与宿主 Vue 2.6 双运行时并存的内存成本。
|
|
312
|
+
- Windows 路径、qjsc 只做了本机与 fixture 验证;不同固件安装前请先在真机跑通。
|
|
313
|
+
- `App.meta` 路径清洗与 `@keyframes` token 化已在 fixture + qjsc 上验证;若特定固件依赖
|
|
314
|
+
`App.meta.options` 或动态设置动画名,可用 `keepMetaPaths` / `keepKeyframeNames` 关闭。
|
|
315
|
+
- `catchword audit` 只分析 `.falcon_` 构建目录,不解析 `.amr` 压缩包。
|
package/bin/catchword.js
ADDED
package/bin/falcon.js
ADDED
package/dist/cli/adb.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { createContext } from '../plugin/context.js';
|
|
3
|
+
import { log } from '../util/log.js';
|
|
4
|
+
import { parseJsonLine, run } from './util.js';
|
|
5
|
+
const TMP_PATH = '/data/tmp.amr';
|
|
6
|
+
export async function runAdb(opts) {
|
|
7
|
+
const ctx = createContext({ dir: opts.dir });
|
|
8
|
+
const amrPath = opts.appPath ?? ctx.amrPath;
|
|
9
|
+
if (!fs.existsSync(amrPath)) {
|
|
10
|
+
log.error(`本地 amr 包不存在: ${amrPath}\n请先执行构建`);
|
|
11
|
+
return -2;
|
|
12
|
+
}
|
|
13
|
+
const adbCheck = await run('adb', ['version']);
|
|
14
|
+
if (!adbCheck.ok) {
|
|
15
|
+
log.error('未找到 adb,请安装并加入 PATH');
|
|
16
|
+
return -1;
|
|
17
|
+
}
|
|
18
|
+
log.step('STEP1: push');
|
|
19
|
+
const push = await run('adb', ['push', amrPath, TMP_PATH]);
|
|
20
|
+
if (push.stdout)
|
|
21
|
+
log.info(push.stdout.trim());
|
|
22
|
+
if (!push.ok) {
|
|
23
|
+
log.error('push 失败');
|
|
24
|
+
return -4;
|
|
25
|
+
}
|
|
26
|
+
log.success('push 成功');
|
|
27
|
+
log.step('STEP2: install');
|
|
28
|
+
const install = await run('adb', ['shell', 'miniapp_cli', 'install', TMP_PATH]);
|
|
29
|
+
const installJson = parseJsonLine(install.stdout);
|
|
30
|
+
log.info(install.stdout.trim());
|
|
31
|
+
if (!install.ok || !installJson || installJson.ret !== 0) {
|
|
32
|
+
log.error('install 失败,请检查设备是否有 miniapp_cli');
|
|
33
|
+
return -6;
|
|
34
|
+
}
|
|
35
|
+
log.success('install 成功');
|
|
36
|
+
log.step('STEP3: start');
|
|
37
|
+
const startArgs = ['shell', 'miniapp_cli', 'start', String(installJson.appid)];
|
|
38
|
+
if (opts.page)
|
|
39
|
+
startArgs.push(opts.page);
|
|
40
|
+
const start = await run('adb', startArgs);
|
|
41
|
+
const startJson = parseJsonLine(start.stdout);
|
|
42
|
+
log.info(start.stdout.trim());
|
|
43
|
+
if (!start.ok || !startJson || startJson.ret !== 0) {
|
|
44
|
+
log.error('start 失败');
|
|
45
|
+
await run('adb', ['shell', 'rm', TMP_PATH]);
|
|
46
|
+
return -8;
|
|
47
|
+
}
|
|
48
|
+
log.success('start 成功');
|
|
49
|
+
await run('adb', ['shell', 'rm', TMP_PATH]);
|
|
50
|
+
log.success('安装完成');
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createContext } from '../plugin/context.js';
|
|
4
|
+
import { walkSync } from '../util/fs.js';
|
|
5
|
+
import { warnNativeLeaks } from '../steps/security.js';
|
|
6
|
+
import { log } from '../util/log.js';
|
|
7
|
+
const ASCII_RE = /[\x20-\x7e]{4,}/g;
|
|
8
|
+
const IDENT_RE = /[A-Za-z_$][A-Za-z0-9_$]{7,}/g;
|
|
9
|
+
const URL_RE = /(?:https?|wss?):\/\/[^\s'"<>]+/g;
|
|
10
|
+
const SOURCE_PATH_RE = /(?:pages|services|providers|components|src)\/[\w./@-]+\.(?:vue|ts|tsx|js|jsx|less|scss|css)/g;
|
|
11
|
+
const ENCODED_RE = /^[A-Za-z0-9+/]{40,}={0,2}$/;
|
|
12
|
+
function collect(file, name) {
|
|
13
|
+
const buf = fs.readFileSync(file);
|
|
14
|
+
const strings = new Set(buf.toString('latin1').match(ASCII_RE) ?? []);
|
|
15
|
+
const values = [...strings];
|
|
16
|
+
const encoded = values.filter((value) => ENCODED_RE.test(value)).length;
|
|
17
|
+
const identifiers = new Map();
|
|
18
|
+
const urls = new Set();
|
|
19
|
+
const sourcePaths = new Set();
|
|
20
|
+
for (const value of values) {
|
|
21
|
+
for (const match of value.match(IDENT_RE) ?? []) {
|
|
22
|
+
identifiers.set(match, (identifiers.get(match) ?? 0) + 1);
|
|
23
|
+
}
|
|
24
|
+
for (const match of value.match(URL_RE) ?? [])
|
|
25
|
+
urls.add(match);
|
|
26
|
+
for (const match of value.match(SOURCE_PATH_RE) ?? [])
|
|
27
|
+
sourcePaths.add(match);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
name,
|
|
31
|
+
bytes: buf.length,
|
|
32
|
+
strings: strings.size,
|
|
33
|
+
encoded,
|
|
34
|
+
urls: urls.size,
|
|
35
|
+
sourcePaths: sourcePaths.size,
|
|
36
|
+
identifiers: [...identifiers]
|
|
37
|
+
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
38
|
+
.slice(0, 12)
|
|
39
|
+
.map(([value]) => value)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export async function runAudit(dir, options = {}) {
|
|
43
|
+
const ctx = createContext({ dir });
|
|
44
|
+
if (!fs.existsSync(ctx.buildDir)) {
|
|
45
|
+
log.error(`构建目录不存在: ${ctx.buildDir}\n请先执行 catchword build`);
|
|
46
|
+
return -2;
|
|
47
|
+
}
|
|
48
|
+
const modules = new Map();
|
|
49
|
+
for (const file of walkSync(ctx.buildDir)) {
|
|
50
|
+
const ext = path.extname(file).toLowerCase();
|
|
51
|
+
if (ext !== '.bin' && ext !== '.js')
|
|
52
|
+
continue;
|
|
53
|
+
const rel = path.relative(ctx.buildDir, file).replace(/\\/g, '/');
|
|
54
|
+
const key = rel.replace(/\.bin$/, '');
|
|
55
|
+
if (ext === '.js' && modules.has(key))
|
|
56
|
+
continue;
|
|
57
|
+
modules.set(key, file);
|
|
58
|
+
}
|
|
59
|
+
const audits = [...modules.entries()]
|
|
60
|
+
.map(([name, file]) => collect(file, name))
|
|
61
|
+
.sort((a, b) => b.bytes - a.bytes);
|
|
62
|
+
log.step('逆向面审计');
|
|
63
|
+
for (const item of audits) {
|
|
64
|
+
log.info(` ${item.name.padEnd(28)} ${String(Math.round(item.bytes / 1024)).padStart(4)} KB` +
|
|
65
|
+
` 串 ${String(item.strings).padStart(4)}(编码块 ${String(item.encoded).padStart(3)})` +
|
|
66
|
+
` URL ${item.urls} 源路径 ${item.sourcePaths}` +
|
|
67
|
+
(item.identifiers.length ? ` top: ${item.identifiers.slice(0, 6).join(', ')}` : ''));
|
|
68
|
+
}
|
|
69
|
+
const total = audits.reduce((acc, item) => ({
|
|
70
|
+
strings: acc.strings + item.strings,
|
|
71
|
+
encoded: acc.encoded + item.encoded,
|
|
72
|
+
urls: acc.urls + item.urls,
|
|
73
|
+
sourcePaths: acc.sourcePaths + item.sourcePaths
|
|
74
|
+
}), { strings: 0, encoded: 0, urls: 0, sourcePaths: 0 });
|
|
75
|
+
log.info(` 合计: ${audits.length} 个模块, ${total.strings} 条可打印串` +
|
|
76
|
+
`(${total.encoded} 条疑似编码块), ${total.urls} 个 URL, ${total.sourcePaths} 个源文件路径`);
|
|
77
|
+
if (total.sourcePaths > 0) {
|
|
78
|
+
log.error('发现源文件路径:请检查 App.meta / SFC 元数据 / 自定义字符串,或保持默认清洗选项。');
|
|
79
|
+
}
|
|
80
|
+
if (total.urls > 0) {
|
|
81
|
+
log.warn('仍有明文 URL:确认字符串表未被 keepStrings 关闭,并考虑把端点/密钥移到服务端。');
|
|
82
|
+
}
|
|
83
|
+
if (total.strings - total.encoded > 0) {
|
|
84
|
+
log.info('提示: 剩余标识符通常是 Vue/Weex 属性名、样式键或生命周期名;' +
|
|
85
|
+
'属性名混淆受运行时 ABI 限制,不能安全地全局重命名。');
|
|
86
|
+
}
|
|
87
|
+
warnNativeLeaks(ctx);
|
|
88
|
+
if (options.strict === true && (total.sourcePaths > 0 || total.urls > 0))
|
|
89
|
+
return 1;
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FalconUserConfig } from '../types.js';
|
|
2
|
+
export interface BuildOptions {
|
|
3
|
+
nativeTarget?: string | boolean;
|
|
4
|
+
dir: string;
|
|
5
|
+
compress?: boolean;
|
|
6
|
+
qjsc?: boolean;
|
|
7
|
+
pack?: boolean;
|
|
8
|
+
mock?: boolean;
|
|
9
|
+
env?: string[];
|
|
10
|
+
silent?: boolean;
|
|
11
|
+
config?: FalconUserConfig;
|
|
12
|
+
}
|
|
13
|
+
export declare function runBuild(opts: BuildOptions): Promise<number>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { build as viteBuild } from 'vite';
|
|
3
|
+
import { createCatchwordPlugins } from '../index.js';
|
|
4
|
+
import { loadConfig } from '../config.js';
|
|
5
|
+
import { compileAll } from '../steps/qjsc.js';
|
|
6
|
+
import { generateManifest } from '../steps/manifest.js';
|
|
7
|
+
import { packAmr, writeSha256Sidecar } from '../steps/pack.js';
|
|
8
|
+
import { reportBuildSize } from '../steps/report.js';
|
|
9
|
+
import { assertNoBuildPathLeak, assertNoSensitiveFiles, assertNoSourceMaps, assertNoSourcePathLeak, scanSecrets, verifyManifestCert, warnNativeLeaks } from '../steps/security.js';
|
|
10
|
+
import { log } from '../util/log.js';
|
|
11
|
+
import { prepareBuild } from './util.js';
|
|
12
|
+
function toHookContext(ctx) {
|
|
13
|
+
return {
|
|
14
|
+
root: ctx.root,
|
|
15
|
+
srcDir: ctx.srcDir,
|
|
16
|
+
buildDir: ctx.buildDir,
|
|
17
|
+
pkg: ctx.pkg,
|
|
18
|
+
appJson: ctx.appJson,
|
|
19
|
+
appid: ctx.appid,
|
|
20
|
+
amrPath: ctx.amrPath,
|
|
21
|
+
config: ctx.config
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function warnInsecureRelease(ctx, options) {
|
|
25
|
+
if (options.pack !== true)
|
|
26
|
+
return;
|
|
27
|
+
const tool = ctx.toolOptions;
|
|
28
|
+
const tips = [];
|
|
29
|
+
if (options.minify !== true) {
|
|
30
|
+
tips.push('未启用 -c 压缩:局部函数名/标识符更完整');
|
|
31
|
+
}
|
|
32
|
+
if (tool.keepStrings === true) {
|
|
33
|
+
tips.push('catchword.keepStrings=true:字符串、URL、页面文案会以明文进入字节码');
|
|
34
|
+
}
|
|
35
|
+
if (tool.keepMetadata === true) {
|
|
36
|
+
tips.push('catchword.keepMetadata=true:SFC __file 等元数据会保留');
|
|
37
|
+
}
|
|
38
|
+
if (tool.keepComponentNames === true) {
|
|
39
|
+
tips.push('catchword.keepComponentNames=true:组件 name 会保留');
|
|
40
|
+
}
|
|
41
|
+
if (tool.tokenizeClassNames === false) {
|
|
42
|
+
tips.push('catchword.tokenizeClassNames=false:CSS 类名会保留');
|
|
43
|
+
}
|
|
44
|
+
if (tool.keepMetaPaths === true) {
|
|
45
|
+
tips.push('catchword.keepMetaPaths=true:App.meta 会带源文件路径');
|
|
46
|
+
}
|
|
47
|
+
if (tool.keepKeyframeNames === true) {
|
|
48
|
+
tips.push('catchword.keepKeyframeNames=true:@keyframes 名称会保留');
|
|
49
|
+
}
|
|
50
|
+
if (tips.length === 0)
|
|
51
|
+
return;
|
|
52
|
+
log.warn(`[catchword] 发布构建建议检查以下选项(推荐 catchword build -c -q -p):\n ${tips.join('\n ')}`);
|
|
53
|
+
}
|
|
54
|
+
export async function runBuild(opts) {
|
|
55
|
+
const config = opts.config ?? (await loadConfig(opts.dir, { mode: 'production' })).config;
|
|
56
|
+
const options = {
|
|
57
|
+
dir: opts.dir,
|
|
58
|
+
minify: opts.compress === true,
|
|
59
|
+
mock: opts.mock === true,
|
|
60
|
+
env: opts.env,
|
|
61
|
+
qjsc: opts.qjsc === true,
|
|
62
|
+
pack: opts.pack === true,
|
|
63
|
+
config
|
|
64
|
+
};
|
|
65
|
+
const { ctx, state, plugins } = createCatchwordPlugins(options);
|
|
66
|
+
if (opts.nativeTarget) {
|
|
67
|
+
const { runNativeBuild } = await import('../native/build.js');
|
|
68
|
+
const target = typeof opts.nativeTarget === 'string' ? opts.nativeTarget : 'x7';
|
|
69
|
+
const code = await runNativeBuild({ root: ctx.root, config, target });
|
|
70
|
+
if (code !== 0)
|
|
71
|
+
return code;
|
|
72
|
+
}
|
|
73
|
+
const hooks = config.hooks ?? {};
|
|
74
|
+
const hookCtx = toHookContext(ctx);
|
|
75
|
+
let success = false;
|
|
76
|
+
try {
|
|
77
|
+
if (hooks.beforeBuild)
|
|
78
|
+
await hooks.beforeBuild(hookCtx);
|
|
79
|
+
ctx.cliBuild = true;
|
|
80
|
+
prepareBuild(ctx);
|
|
81
|
+
log.info(`构建目录: ${ctx.root}`);
|
|
82
|
+
log.info(`产物目录: ${ctx.buildDir}`);
|
|
83
|
+
if (options.mock && options.pack) {
|
|
84
|
+
log.warn('[catchword] 打包产物包含 api-mock 模拟实现,请确认这不是发布构建');
|
|
85
|
+
}
|
|
86
|
+
warnInsecureRelease(ctx, options);
|
|
87
|
+
await viteBuild({
|
|
88
|
+
configFile: false,
|
|
89
|
+
root: ctx.root,
|
|
90
|
+
plugins,
|
|
91
|
+
logLevel: opts.silent ? 'silent' : 'info'
|
|
92
|
+
});
|
|
93
|
+
assertNoSourceMaps(ctx);
|
|
94
|
+
if (options.qjsc) {
|
|
95
|
+
await compileAll(ctx, state);
|
|
96
|
+
}
|
|
97
|
+
const cert = options.pack ? generateManifest(ctx) : null;
|
|
98
|
+
assertNoSensitiveFiles(ctx);
|
|
99
|
+
assertNoSourcePathLeak(ctx, state);
|
|
100
|
+
assertNoBuildPathLeak(ctx, state);
|
|
101
|
+
warnNativeLeaks(ctx);
|
|
102
|
+
if (cert) {
|
|
103
|
+
verifyManifestCert(ctx, cert);
|
|
104
|
+
scanSecrets(ctx, state);
|
|
105
|
+
try {
|
|
106
|
+
await packAmr(ctx);
|
|
107
|
+
writeSha256Sidecar(ctx.amrPath);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
for (const file of [ctx.amrPath, ctx.amrPath + '.tmp', ctx.amrPath + '.sha256']) {
|
|
111
|
+
try {
|
|
112
|
+
if (fs.existsSync(file))
|
|
113
|
+
fs.unlinkSync(file);
|
|
114
|
+
}
|
|
115
|
+
catch { }
|
|
116
|
+
}
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
scanSecrets(ctx, state);
|
|
122
|
+
}
|
|
123
|
+
if (!opts.silent)
|
|
124
|
+
reportBuildSize(ctx);
|
|
125
|
+
log.success(`应用构建成功: ${ctx.buildDir}`);
|
|
126
|
+
success = true;
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
if (hooks.afterBuild) {
|
|
131
|
+
try {
|
|
132
|
+
await hooks.afterBuild(hookCtx, success);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
log.warn(`afterBuild 钩子失败: ${String(error)}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runClean(dir: string): Promise<number>;
|