@flun/node-mobile-app 3.1.1 → 3.1.2

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/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # 变更日志
2
+ ## [3.1.2] - 2026-10-15 21:05
3
+ ### 修复
4
+ - 修复了 "src\optimize-node-modules.js" 中 prunePlatform 函数一些边界问题;
5
+
2
6
  ## [3.1.1] - 2026-10-15 20:29
3
7
  ### 更新
4
8
  - 同步更新了一些依赖包;
@@ -11,34 +15,4 @@
11
15
  - **`clearItem` 单文件分支漏判 js(重要)**:目录分支已有「跳过 js」判断,单文件分支遗漏,导致资源目录中的**单个 js 文件**被清空为 0 字节,合并阶段读到空文件、产物损坏;现补充 js 判断,js 一律保留给合并阶段;
12
16
  - **合并阶段日志标题**:由「处理 JS 资源(用到则合并,未用到则提前清除)」改为「处理保留的资源 JS(被引用则合并,否则删除)」,与新流程呼应;
13
17
  - **Gradle 原生编译报 postinstall 失败(重要)**:Gradle 编译原生模块时执行 `npm rebuild`,会触发各包 postinstall;而合并阶段已删除脚本文件,导致 `Cannot find module ... copy-files.js`、构建失败;现合并阶段同步**删除 `package.json` 的 `scripts` 字段**(运行时无安装期,scripts 无用),rebuild 不再触发;
14
- - **`--debug` 下 `quiet` 命令仍被静默**:`run` 的 quiet 分支未判断 debug,导致 `--debug` 时 `gradlew` / `xcodebuild` 等命令输出仍被吞;现改为「debug 时忽略 quiet,全量输出」(不影响默认模式下 test 的精简行为);
15
-
16
- ## [3.0.0] - 2026-10-13 21:19
17
- ### 新增
18
- - **node_modules 优化系统(默认开启)**:构建时自动执行六阶段优化,大幅减少打包文件数、加速启动。不改变项目源码,对任意 Node.js 项目通用;
19
- - **阶段 1 合并 JS**:按包入口 bundle,多个 JS 文件合并为单文件(`bundled/` 目录下的 `.cjs` / `.mjs`);CJS 保持 CJS、ESM 保持 ESM;
20
- - **阶段 2 清空资源**:扫描各包 `postinstall` 引用的目录/文件,保留目录结构、清空内容;被 import/require 的保留不删;
21
- - **阶段 3 清平台二进制**:按目标平台 + `abiFilters` 逐文件判定,删除非本机二进制(三层识别:目录名、文件后缀、文件头魔数);
22
- - **阶段 4 清开发文件**:删除 `.md` / `.map` / `.d.ts` / `.h` / `.c` 等非运行文件;**原生模块包(含 `binding.gyp`)内的编译必需文件保留**,确保原生编译通过;
23
- - **阶段 5 清中间产物**;**阶段 6 清不参与运行的文件和空目录**;
24
- - **优化缓存(快照 + 指纹)**:`.deps-snapshot.json` 记录依赖、目标平台、架构、运行时 Node 主版本、优化代码指纹、上次构建是否完成;
25
- - 构建时自动判断并执行三种动作:**重装依赖并优化** / **仅优化** / **跳过**,日志说明当次动作与原因;
26
- - 运行时 Node 主版本从 `libnode/include/node/node_version.h` 读取(读不到则报错退出);
27
- - **模板指纹**:`template/` 目录内容纳入缓存指纹,模板改动自动触发重编;
28
- - **`--debug` 调试开关**:`npx node-mobile-app build --debug` / `test --debug` 显示优化各阶段明细与各命令完整输出;
29
- - **优化逃生舱口**(`mobileAppConfig.js`):`optimize: { enabled: false }` 整体关闭优化;`optimize: { exclude: ['包名'] }` 精确排除特定包;
30
- - **构建进度提示**:默认模式在打包阶段显示「打包进行中...」,避免长时间无输出被误认为卡死;`--debug` 下输出已完整,无需此提示;
31
-
32
- ### 修复
33
- - **`bundled` 目录在 APK 中丢失(重要)**:aapt2 默认过滤 `<dir>_*`,原产物目录名以下划线开头,被打包时整体丢弃,应用启动报 `Node assets copy failed`;产物目录改用 `bundled`,绕开该过滤;
34
- - **scripts 引用保护过宽**:原逻辑保护 `package.json` `scripts` 引用的所有 js(含 test / lint),但移动端无安装期、这些脚本永不执行;移除该保护,测试脚本等被正常清理;
35
- - **`run` 输出策略**:`run` 默认实时输出(inherit);新增 `quiet` 参数——捕获输出、成功静默、失败才打印,用于 `gradlew` / `xcodebuild` 等命令;
36
- - **`clean` 清理不完整**:原只清 `node-mobile-app-build` 与插件 `.cxx`,现补上插件 `android/build`,确保清环境彻底;
37
-
38
- ### 升级注意事项
39
- - **3.0.0 起 node_modules 优化默认开启**,无需配置即享优化收益;
40
- - **升级后首次构建**会重装依赖并执行优化,比平时慢;后续构建命中缓存后无额外开销;
41
- - 若**构建或运行异常**,按以下顺序排查:
42
- 1. 在 `mobileAppConfig.js` 中设置 `optimize: { enabled: false }` 关闭优化,验证是否为优化引起;
43
- 2. 若确认是某个包合并后异常,用 `optimize: { exclude: ['包名'] }` 排除优化时异常或不想优化的包;
44
- 3. 若需彻底重来,删除 `node-mobile-app-build` 目录后重新构建。
18
+ - **`--debug` 下 `quiet` 命令仍被静默**:`run` 的 quiet 分支未判断 debug,导致 `--debug` 时 `gradlew` / `xcodebuild` 等命令输出仍被吞;现改为「debug 时忽略 quiet,全量输出」(不影响默认模式下 test 的精简行为);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flun/node-mobile-app",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "description": "将 Node.js 项目一键打包为 Android / iOS 移动应用,运行时由 @flun/nodejs-mobile-react-native 提供,无需修改你的 Node 代码;",
5
5
  "author": "flun <open@flun.top>",
6
6
  "keywords": [
@@ -45,10 +45,10 @@
45
45
  "@eslint/js": "^10.0.1",
46
46
  "@flun/nodejs-mobile-react-native": "^2.0.8",
47
47
  "@react-native/babel-preset": "^0.88.0",
48
+ "@react-native/metro-config": "^0.88.0",
48
49
  "@react-native-community/cli": "^20.2.0",
49
50
  "@react-native-community/cli-platform-android": "^20.2.0",
50
51
  "@react-native-community/cli-platform-ios": "^20.2.0",
51
- "@react-native/metro-config": "^0.88.0",
52
52
  "@types/react": "^19.3.0",
53
53
  "@typescript-eslint/eslint-plugin": "^8.71.2",
54
54
  "@typescript-eslint/parser": "^8.71.2",
@@ -406,11 +406,16 @@ const require = createRequire(import.meta.url), subpath = (...parts) => './' + p
406
406
  prunePlatform = async (nmDir, myPlat, myArch) => {
407
407
  let removed = 0;
408
408
  const readHead = file => {
409
+ let fd;
409
410
  try {
410
- const fd = fs.openSync(file, 'r'), buf = Buffer.alloc(512), n = fs.readSync(fd, buf, 0, 512, 0);
411
- fs.closeSync(fd);
412
- return n > 0 ? buf.slice(0, n) : null;
413
- } catch { return null; }
411
+ fd = fs.openSync(file, 'r');
412
+ const buf = Buffer.alloc(512), n = fs.readSync(fd, buf, 0, 512, 0);
413
+ return n > 0 ? buf.subarray(0, n) : null;
414
+ } catch {
415
+ return null;
416
+ } finally {
417
+ if (fd !== undefined) fs.closeSync(fd);
418
+ }
414
419
  },
415
420
  sniffPlat = buf => {
416
421
  if (!buf || buf.length < 4) return null;