### 问题描述 `@tarojs/helper` 的 `emptyDirectory(dirPath, opts)` 支持用 `excludes` 排除某些文件/目录,但递归处理子目录时调用的是: ```ts emptyDirectory(curPath) ``` 没有把 `opts` 传下去。因此在子目录里的被排除文件仍然会被删除。 ### 复现步骤 1. 建目录:`root/a/keep.txt`、`root/a/del.txt`、`root/top.txt` 2. 调用 `emptyDirectory(root, { excludes: ['keep.txt'] })` 3. 检查 `root/a/keep.txt` ### 期望行为 `excludes` 应该对整个目录树生效,`root/a/keep.txt` 保留,`del.txt` 和 `top.txt` 删除。 ### 实际行为 `root/a/keep.txt` 也被删除,只剩空目录。 本地用一个和 `utils.ts` 完全相同的 `emptyDirectory` 实现复现: ```text exists a/keep.txt: false exists a/del.txt: false exists top.txt: false ``` ### 代码位置 `packages/taro-helper/src/utils.ts:369-393`: ```ts if (canRemove) { emptyDirectory(curPath) fs.rmdirSync(curPath) } ``` `opts` 在递归调用里丢失。只把 `opts` 传下去还不够:CodeRabbit 指出文件删除分支仍会绕过 `excludes`,保留嵌套排除项还会让祖先目录非空、原有“吞异常重试”可能死循环;全局正则还有 `lastIndex` 状态问题。 修复 PR:https://github.com/NervJS/taro/pull/19746(文件级 excludes、保留祖先目录、有界重试、重置 lastIndex,并补测试)。 ### 环境 - Taro 4.3.3(main) - Windows - Node 24 - `@tarojs/helper` 的 `emptyDirectory` ### 补充 #12788 是希望 `needClearOutput` 支持 excludes 的特性请求;这里不是同一个问题,而是 excludes 在嵌套目录下不生效。
Activity