@iyowei/sweep-node-modules-cli 0.2.1 → 0.3.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/README.md CHANGED
@@ -17,7 +17,7 @@ A workspace-level cleaner for `node_modules`: scan several root directories in o
17
17
  - **Dual runtime** for the actual work: bun when available, node otherwise (identical behavior; bun starts faster).
18
18
  - Modern runtime APIs only: any recent bun; for node, a version that runs TypeScript natively (the same version floor applies to the source install and the package install; version snapshot and test records in [ADR 0006](../../docs/adrs/0006-dual-runtime-bun-first.md)).
19
19
  - Zero third-party runtime dependencies (built-in runtime capabilities only).
20
- - Runs on Windows, macOS, and Linux (see [ADR 0007](../../docs/adrs/0007-platform-portability.md)).
20
+ - Runs on macOS and Linux today; Windows launchers are shipped but not yet verified on a real Windows machine (see the evidence gap in [ADR 0007](../../docs/adrs/0007-platform-portability.md)).
21
21
 
22
22
  ## Installation
23
23
 
@@ -80,7 +80,7 @@ $bin = "$env:USERPROFILE\tools\sweep-node-modules\packages\sweep-node-modules-cl
80
80
 
81
81
  > Or skip the command line: add the `bin` directory to your user `Path` under System Properties → Environment Variables.
82
82
 
83
- - **Requires**: bun or node, either works (the launcher is a shell / cmd script run by the OS; it does not depend on node); **node-only environments**: run one build first (`bun install && bun run build`) — node does not read the repo's path mappings, so an uncovered checkout cannot resolve the API package's artifacts
83
+ - **Requires**: bun or node, either works (the launcher is a shell / cmd script run by the OS; it does not depend on node); **node-only runtime**: the checkout must be built first, and building needs bun (`bun install && bun run build`) — node does not read the repo's path mappings, so an uncovered checkout cannot resolve the API package's artifacts
84
84
  - The most direct entry point; afterwards just run `sweep-nm` (on Windows via `packages\sweep-node-modules-cli\bin\sweep-nm.cmd`)
85
85
 
86
86
  ## Usage
@@ -92,7 +92,7 @@ sweep-nm
92
92
  # once the list checks out, delete for real
93
93
  sweep-nm --yes
94
94
 
95
- # also delete "suspected install trees" (package manager / version manager / editor extension trees; skipped by default)
95
+ # also delete "suspected install trees" (package manager / version manager / editor trees, hidden home-dir dirs, system-data-root names; skipped by default)
96
96
  sweep-nm --yes --force
97
97
 
98
98
  # add exclusions on the fly (repeatable)
@@ -106,20 +106,24 @@ sweep-nm config
106
106
 
107
107
  # init wizard: generate a config file interactively
108
108
  sweep-nm init
109
+
110
+ # full option list (also -h)
111
+ sweep-nm --help
109
112
  ```
110
113
 
111
114
  The end of the header line reports the runtime actually in use for this run (e.g. `bun 1.4.2`); it appears on interactive terminals only, keeping non-TTY output noise-free.
112
115
 
116
+ ## Exit codes
117
+
118
+ `0` means success (preview and empty results included); `1` means anything else (deletion failure / batch abort / unattempted targets / broken or missing config / bad arguments / a run refused for lack of a config).
119
+
113
120
  ## Configuration
114
121
 
115
122
  The config file lives at a platform-appropriate path: `%APPDATA%\sweep-node-modules\config.json` on Windows, `~/.config/sweep-node-modules/config.json` everywhere else. Override it with `--config` or the `SWEEP_NM_CONFIG` environment variable; `sweep-nm config` reports the path and file status actually in effect for the current run. **The write side requires real paths**: if the config path or any of its ancestors involves a symlink (system links such as `/tmp` and `/var` included), `sweep-nm init` refuses to write before touching disk and points at the link; follow the prompt to rewrite the path in real form (e.g. `/private/tmp/x`) and it goes through.
116
123
 
117
124
  ```json
118
125
  {
119
- "roots": [
120
- "/Users/iyowei/workspace/development",
121
- "/Users/iyowei/self/development"
122
- ],
126
+ "roots": ["/Users/you/workspace", "/Users/you/projects"],
123
127
  "exclude": ["my-kits"],
124
128
  "include": []
125
129
  }
@@ -127,7 +131,7 @@ The config file lives at a platform-appropriate path: `%APPDATA%\sweep-node-modu
127
131
 
128
132
  - `roots`: the scan roots, any number of them; duplicate or nested roots are deduplicated by real path. **The delete side requires real paths**: no symlink may sit on a root or any of its ancestors (system links such as `/tmp` and `/var` included); if one is hit, `--yes` rejects the whole batch and tells you to rewrite the path in real form (e.g. `/private/tmp/x`), which clears it. Scanning is not subject to this: a root that is itself a symlink still gets scanned.
129
133
  - `exclude`: the exclusion list; a name match at any directory level between a root and a `node_modules` skips it (more exclusions, less deletion: the safe direction). **Omit this field and a built-in default list applies** (package manager / version manager install trees, editor extension directories, system and application data roots; the list and its rationale are in the [design doc](../../docs/designs/config-and-initialization.md), section "Default exclusions"). These names never warn when they match nothing, since they vary by platform. Write the field explicitly (an empty array counts) and your own list takes over completely.
130
- - **Suspected install trees stay out of the delete batch by default**: targets that look like install trees (e.g. `~/.bun/install/global/node_modules`, `<version dir>/lib/node_modules`, editor extension directories) are flagged in the list as `疑似安装树: <reason>` (suspected install tree, plus the reason) and keep their `node_modules` suffix; `--yes` does not delete them (reported as a failure, with an explanation of the skip). Cleaning them takes an explicit `--force`, which releases only this batch of targets and relaxes no deletion guard.
134
+ - **Suspected install trees stay out of the delete batch by default**: targets that look like install trees (e.g. `~/.bun/install/global/node_modules`, `<version dir>/lib/node_modules`, editor extension directories, any `node_modules` under a hidden directory in the home dir, or under a system-data-root name such as `Library` / `.local` / `.config` / `.cache`) are flagged in the list as `疑似安装树: <reason>` (suspected install tree, plus the reason) and keep their `node_modules` suffix; `--yes` does not delete them (reported as a failure, with an explanation of the skip). Cleaning them takes an explicit `--force`, which releases only this batch of targets and relaxes no deletion guard.
131
135
  - **Cross-device targets stay out of the delete batch by default**: when a target and its owning root are not on the same filesystem (a cloud drive, network share, or container volume is mounted under the root and the entry lands on that volume), it is likewise not deleted; the list line notes the form at its end, `跨设备: 根与目标之间有挂载点` (a mount point lies between root and target) or `跨设备: 目标本体即挂载点` (the target itself is the mount point). For the first form, add that mount point as its own root and it cleans as usual; for the second, unmount the volume first; `--force` does not release this category.
132
136
  - `include`: the inclusion list (a whitelist); only matches are included, matched the same way as `exclude`. Omitted or empty means no filtering (more inclusions, more deletion); when a name matches both lists, `exclude` wins. A misspelled name would leave the result empty, so unmatched names warn on stderr.
133
137
  - `node_modules` and `.git` are always stripped from either list: the former is the tool's very target (under `exclude` it would rule out the only thing this tool does, under `include` it can never match), the latter is a directory the scan always skips. If stripping leaves `include` empty, that means no filtering, not "scan only `node_modules`".
@@ -143,9 +147,9 @@ Deletion is the only irreversible action this tool performs, and a whole discipl
143
147
 
144
148
  **Nothing happens by default.** Preview is the default mode, and deletion requires an explicit `--yes`. With no config file, `--yes` is hard-rejected and nothing is deleted. On the run right after the wizard writes a config, preview is forced even if `--yes` was passed. `--force` releases only suspected install trees; it relaxes no deletion guard.
145
149
 
146
- **What gets deleted is decided by both name and location.** Only directories named exactly `node_modules` are eligible, and only under the roots you declared; whether a target sits under a root is judged by path hierarchy rather than string prefixes, so `..` traversal and lookalike paths are rejected outright. Targets whose size cannot be measured are never deleted: keep rather than guess. Two categories are held back by default: suspected install trees (reinstalling them is painful or impossible; released only by an explicit `--force`) and cross-device targets that live on a different filesystem (`--force` does not release these either). A built-in default exclusion list (install-tree and system-data-root names from package managers, version managers, and editors) keeps the scan away from those trees.
150
+ **What gets deleted is decided by both name and location.** Only directories named exactly `node_modules` are eligible, and only under the roots you declared; whether a target sits under a root is judged by path hierarchy rather than string prefixes, so `..` traversal and lookalike paths are rejected outright. Targets whose size cannot be measured are never deleted: keep rather than guess. Two categories are held back by default: suspected install trees (reinstalling them is painful or impossible; released only by an explicit `--force`) and cross-device targets that live on a different filesystem (`--force` does not release these either). A built-in default exclusion list (install-tree and system-data-root names from package managers, version managers, and editors, plus data-root names such as `Library` / `.local` / `.config` / `.cache` / `.claude`) keeps the scan away from those trees.
147
151
 
148
- **One failure stops the whole batch, and every path is re-checked first.** If a single target fails a check, the entire batch is abandoned with zero deletions, rather than letting the rest through; right before removal, the path from the root down to the target's parent is re-verified component by component, and a swap mid-way stops the batch. If a configured root, or any of its ancestors, has been swapped for a symlink, the delete batch is rejected with rewrite instructions; system links such as `/tmp` and `/var` count too, and rewriting to the real path clears it.
152
+ **One failure stops the whole batch, and every path is re-checked first.** If a single target fails the pre-flight check, the entire batch is abandoned with zero deletions, rather than letting the rest through; right before removal, the path from the root down to the target's parent is re-verified component by component; a mid-way swap then stops the batch from dispatching further deletions (targets already dispatched run to completion and are reported as they are). If a configured root, or any of its ancestors, has been swapped for a symlink, the delete batch is rejected with rewrite instructions; system links such as `/tmp` and `/var` count too, and rewriting to the real path clears it.
149
153
 
150
154
  **Symlinks: the threshold follows reversibility.** For the same config, the read-only scan follows a symlinked root and still lists results, the irreversible delete rejects the batch, and `init` refuses to write a single byte through a link. The split is deliberate: a link's origin cannot be judged, so the irreversible step does not get the benefit of the doubt.
151
155
 
package/README.zh-CN.md CHANGED
@@ -17,7 +17,7 @@
17
17
  - 业务逻辑**双运行时**: 有 bun 走 bun, 否则 node (功能一致, bun 启动更快)。
18
18
  - 取最新一代运行时 API: bun 任意近期版本; node 需原生支持 TypeScript 直跑的版本 (源码方式与包方式取同一版本下限; 版本快照与实测记录见 [ADR 0006](../../docs/adrs/0006-dual-runtime-bun-first.md))。
19
19
  - 零第三方运行时依赖 (只用运行时内置能力)。
20
- - 平台: Windows / macOS / Linux 三平台均可运行 (见 [ADR 0007](../../docs/adrs/0007-platform-portability.md))。
20
+ - 平台: 当前实际验证于 macOS 与 Linux; Windows 启动器已随包分发, 但未经真机验证 (证据缺口见 [ADR 0007](../../docs/adrs/0007-platform-portability.md))。
21
21
 
22
22
  ## 安装
23
23
 
@@ -80,7 +80,7 @@ $bin = "$env:USERPROFILE\tools\sweep-node-modules\packages\sweep-node-modules-cl
80
80
 
81
81
  > 也可以不经命令行: 在「系统属性 → 环境变量」里把该 `bin` 目录加到用户变量 `Path` 中。
82
82
 
83
- - **需要**: bun 或 node 任一 (启动器是 shell / cmd 脚本, 由系统执行, 不依赖 node); **仅 node 的环境**: 需先完成一次构建 (构建链以 bun 为工具: `bun install && bun run build`)——node 不解析仓库内的路径映射, 未经构建的检出态会找不到 API 包产物
83
+ - **需要**: bun 或 node 任一 (启动器是 shell / cmd 脚本, 由系统执行, 不依赖 node); **仅 node 运行时**: 检出态须先构建一次, 且构建本身需要 bun (`bun install && bun run build`): node 不解析仓库内的路径映射, 未经构建的检出态会找不到 API 包产物
84
84
  - 特点: 入口最直接; 之后直接敲 `sweep-nm` (Windows 经 `packages\sweep-node-modules-cli\bin\sweep-nm.cmd`)
85
85
 
86
86
  ## 使用
@@ -92,7 +92,7 @@ sweep-nm
92
92
  # 复核无误后执行删除
93
93
  sweep-nm --yes
94
94
 
95
- # 连同「疑似安装树」一并删除 (包管理器 / 版本管理器 / 编辑器扩展等安装树, 默认跳过)
95
+ # 连同「疑似安装树」一并删除 (包管理器 / 版本管理器 / 编辑器扩展、家目录隐藏目录、系统数据根名; 默认跳过)
96
96
  sweep-nm --yes --force
97
97
 
98
98
  # 临时追加排除(可重复)
@@ -106,20 +106,24 @@ sweep-nm config
106
106
 
107
107
  # 初始化向导: 交互式生成配置文件
108
108
  sweep-nm init
109
+
110
+ # 完整选项表 (亦可 -h)
111
+ sweep-nm --help
109
112
  ```
110
113
 
111
114
  清单顶栏尾部会标注本次实际使用的运行时 (如 `bun 1.4.2`), 仅交互终端显示 (非 TTY 不增噪音)。
112
115
 
116
+ ## 退出码
117
+
118
+ `0` 表示成功 (含预览与空结果); 其余一律 `1` (删除失败 / 整批中止 / 未处理目标 / 配置损坏或不存在 / 参数错误 / 无配置下的执行拒绝)。
119
+
113
120
  ## 配置
114
121
 
115
122
  配置文件位置 (平台自适应): Windows 为 `%APPDATA%\sweep-node-modules\config.json`, 其余为 `~/.config/sweep-node-modules/config.json`; 可用 `--config` 或环境变量 `SWEEP_NM_CONFIG` 覆盖, 本次实际生效的路径与文件状态用 `sweep-nm config` 查看。**写入侧须为真实路径形态**: 配置路径及其祖先链有符号链接介入 (系统链接 `/tmp`、`/var` 也在内) 时, `sweep-nm init` 落盘前会拒写并给出链接定位, 按提示改写成真实路径形态 (如 `/private/tmp/x`) 即放行。
116
123
 
117
124
  ```json
118
125
  {
119
- "roots": [
120
- "/Users/iyowei/workspace/development",
121
- "/Users/iyowei/self/development"
122
- ],
126
+ "roots": ["/Users/you/workspace", "/Users/you/projects"],
123
127
  "exclude": ["my-kits"],
124
128
  "include": []
125
129
  }
@@ -127,7 +131,7 @@ sweep-nm init
127
131
 
128
132
  - `roots`: 扫描根目录, 任意多个; 重复或嵌套的根按真实路径去重。**删除侧须为真实路径形态**: 根及其祖先链不得有符号链接介入 (系统链接 `/tmp`、`/var` 也在内), 命中则 `--yes` 整批拒绝并按提示改写成真实路径 (如 `/private/tmp/x`) 即放行; 扫描侧不受此限 (根为符号链接照常扫描)。
129
133
  - `exclude`: 排除名单; 从根到 `node_modules` 的任意一级目录名命中即跳过 (多排除 = 少删, 安全方向)。**不写该字段时取内置默认名单** (包管理器 / 版本管理器的安装树、编辑器扩展目录、系统与应用数据根, 词表与理由见[设计文档](../../docs/designs/config-and-initialization.md)「默认排除名单」; 这批名字零命中不告警, 它们依平台而异); 显式写出该字段 (含写空数组) 即以你自己的名单为准。
130
- - **疑似安装树默认不进删除批**: 安装树形态的目标 (如 `~/.bun/install/global/node_modules`、`<版本目录>/lib/node_modules`、编辑器扩展目录) 在清单里带 `疑似安装树: <理由>` 标记且保留 `node_modules` 后缀, `--yes` 不删它们 (计失败并给跳过说明); 要清理须显式加 `--force`, 它只放行这一批目标, 不放宽删除安全闸。
134
+ - **疑似安装树默认不进删除批**: 安装树形态的目标 (如 `~/.bun/install/global/node_modules`、`<版本目录>/lib/node_modules`、编辑器扩展目录、家目录任意隐藏目录下的 `node_modules`, 或 `Library` / `.local` / `.config` / `.cache` 等系统数据根名下的) 在清单里带 `疑似安装树: <理由>` 标记且保留 `node_modules` 后缀, `--yes` 不删它们 (计失败并给跳过说明); 要清理须显式加 `--force`, 它只放行这一批目标, 不放宽删除安全闸。
131
135
  - **跨设备目标默认不进删除批**: 目标与所属根不在同一文件系统时 (根之下挂了云盘 / 网络盘 / 容器卷, 条目落在那一卷上) 同样不删, 清单行尾标注 `跨设备: 根与目标之间有挂载点` 或 `跨设备: 目标本体即挂载点`; 前者把该挂载点加进 `roots` 即可照常清理, 后者 (目标本体就是挂载点) 只能先卸载该卷; `--force` 不放行这一类。
132
136
  - `include`: 包含名单 (白名单); 命中才纳入, 口径与 `exclude` 同款; 缺省或空数组 = 不过滤 (多包含 = 多删); 与 `exclude` 同时命中时 `exclude` 优先。写错名字会让结果直接为空, 故未命中的名字会在 stderr 警示。
133
137
  - 两份名单里的 `node_modules` 与 `.git` 一律被剔除: 前者是本工具的目标 (列入排除等于排掉唯一目标, 列入包含则永久零命中), 后者是扫描恒定跳过的目录; 剔除后 `include` 为空数组 = 不过滤 (不是「只扫 node_modules」)。
@@ -143,9 +147,9 @@ sweep-nm init
143
147
 
144
148
  **默认什么都不做。** 预览是默认态, 删除要显式加 `--yes`; 没有配置文件时 `--yes` 被硬拒绝, 零删除; 向导刚写入配置的那一轮强制预览, 即便带了 `--yes` 也只预览。`--force` 只放行「疑似安装树」这一批目标, 不放宽任何删除安全闸。
145
149
 
146
- **删什么, 由名字与归属双重判定。** 只认名字恰为 `node_modules` 的目录, 且必须落在声明的扫描根之下; 归属按路径层级判定, 不是字符串前缀, 上溯与冒名路径一概拒绝。体积测不到的目标一律不删: 宁可留着, 不猜。两类目标默认拦下: 删了装不回来的「疑似安装树」 (要清理须显式加 `--force`), 与落在另一文件系统上的跨设备目标 (`--force` 同样不放行); 另有一份缺省排除名单 (包管理器 / 版本管理器 / 编辑器扩展与系统数据根的名字) 挨着就不扫。
150
+ **删什么, 由名字与归属双重判定。** 只认名字恰为 `node_modules` 的目录, 且必须落在声明的扫描根之下; 归属按路径层级判定, 不是字符串前缀, 上溯与冒名路径一概拒绝。体积测不到的目标一律不删: 宁可留着, 不猜。两类目标默认拦下: 删了装不回来的「疑似安装树」 (要清理须显式加 `--force`), 与落在另一文件系统上的跨设备目标 (`--force` 同样不放行); 另有一份缺省排除名单 (包管理器 / 版本管理器 / 编辑器扩展与 `Library` / `.local` / `.config` / `.cache` / `.claude` 等系统数据根的名字) 挨着就不扫。
147
151
 
148
- **一处不过, 整批不删; 动手前逐级复核。** 任一目标没通过检查, 整批一个都不删, 而不是逐条放行; 删除前自根至目标父目录逐级复核, 半路被掉包就整批停手。配置根或其祖先被换成符号链接时, 删除整批拒绝, 拒绝文案自带改写方向; 系统固有链接 (`/tmp`、`/var` 这类) 同样命中, 改写成真实路径形态即放行。
152
+ **一处不过, 整批不删; 动手前逐级复核。** 任一目标未通过预检, 整批一个都不删, 而不是逐条放行; 删除前自根至目标父目录逐级复核, 半路被掉包则停止派发新条 (已在飞的条目跑完并如实报告)。配置根或其祖先被换成符号链接时, 删除整批拒绝, 拒绝文案自带改写方向; 系统固有链接 (`/tmp`、`/var` 这类) 同样命中, 改写成真实路径形态即放行。
149
153
 
150
154
  **符号链接: 门槛跟着可逆性走。** 同一份配置, 只读的扫描面照常跟进 (根为符号链接照常出清单), 不可逆的删除面整批拒绝, 写入面 (`init` 落盘) 有链接介入就一个字节不落。这个分叉是有意的: 链接的来路判不了, 就不放行不可逆的那一步。
151
155
 
package/bin/sweep-nm.mjs CHANGED
@@ -13,7 +13,8 @@
13
13
  * 先试 cwd 再扫 PATH), 而本工具的调用现场恰是「在被扫目录里执行」, 目录内放一个同名
14
14
  * bun.exe / bun.com 即可顶替真实运行时进入执行链。故 win32 下先按 PATH 解析出绝对路径
15
15
  * (空条目与相对条目都会把解析引回当前目录, 一并跳过) 再探测与执行, 解析面与执行面都不再
16
- * 触发任何搜索序; POSIX 侧 Node 走 execvp 只搜 PATH, 维持裸名原样。
16
+ * 触发任何搜索序; POSIX 侧同法收紧 (空与相对条目在 POSIX 下同样意为当前目录), 并保持
17
+ * execvp「首候选不可执行时继续搜索」的语义 (逐候选探测)。
17
18
  *
18
19
  * 产物自证 (审计项「发行面 dist/cli.js 与源码和提交无身份绑定」的运行时防线): 决定跑
19
20
  * dist/cli.js 之前必须与随附的 dist/manifest.json 对账 (形状版本受支持, 且清单记的 cliSha256
@@ -28,7 +29,7 @@
28
29
  import { spawnSync } from 'node:child_process';
29
30
  import { createHash } from 'node:crypto';
30
31
  import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
31
- import { dirname, join, win32 } from 'node:path';
32
+ import { dirname, join, posix, win32 } from 'node:path';
32
33
  import { fileURLToPath } from 'node:url';
33
34
 
34
35
  /** 产物与清单的文件名 (与 scripts/release-artifact.ts 的 CLI_FILE / MANIFEST_FILE 同值) */
@@ -77,10 +78,28 @@ export const resolveWin32Executable = (name, pathEnv, fileProbe) => {
77
78
  return null;
78
79
  };
79
80
 
81
+ /**
82
+ * 在 PATH 中解析命令的全部候选绝对路径 (POSIX 语义, 保持 PATH 顺序), 跳过空条目与相对
83
+ * 条目 (两者在 POSIX 下都按当前目录解析, 属本工具要摘掉的解析面; 与 win32 分支同一理由,
84
+ * 见文件头「运行时解析防劫持」)。返回数组而非首命中: 同名文件可能不可执行, execvp 在
85
+ * 该情形会继续搜索, 候选交由调用方逐个探测以保持同一语义。注入 pathEnv / fileProbe 供
86
+ * 测试在任意宿主上覆盖本函数。
87
+ */
88
+ export const resolvePosixExecutables = (name, pathEnv, fileProbe) => {
89
+ const found = [];
90
+ for (const dir of pathEnv.split(':')) {
91
+ if (dir === '' || !dir.startsWith('/')) continue;
92
+ const candidate = posix.join(dir, name);
93
+ if (fileProbe(candidate)) found.push(candidate);
94
+ }
95
+ return found;
96
+ };
97
+
80
98
  /**
81
99
  * 挑选运行时: Bun 优先, 其次 Node; 皆无则 null (由调用处报错退出)。
82
- * win32 下先按 PATH 解析绝对路径再探测 (理由见文件头「运行时解析防劫持」), POSIX 下维持
83
- * 裸名 (execvp 只搜 PATH); 各参数显式传入供测试注入, 生产调用不传。
100
+ * 两个平台都先按 PATH 解析绝对路径再探测 (理由见文件头「运行时解析防劫持」): win32 取
101
+ * 首个解析命中, POSIX 按 PATH 顺序逐个候选探测 (保持 execvp 的继续搜索语义); 各参数
102
+ * 显式传入供测试注入, 生产调用不传。
84
103
  */
85
104
  export const pickRuntime = ({
86
105
  platform = process.platform,
@@ -89,11 +108,14 @@ export const pickRuntime = ({
89
108
  probe = available,
90
109
  } = {}) => {
91
110
  for (const name of ['bun', 'node']) {
92
- const resolved =
93
- platform === 'win32'
94
- ? resolveWin32Executable(name, pathEnv, fileProbe)
95
- : name;
96
- if (resolved !== null && probe(resolved)) return resolved;
111
+ if (platform === 'win32') {
112
+ const resolved = resolveWin32Executable(name, pathEnv, fileProbe);
113
+ if (resolved !== null && probe(resolved)) return resolved;
114
+ continue;
115
+ }
116
+ for (const candidate of resolvePosixExecutables(name, pathEnv, fileProbe)) {
117
+ if (probe(candidate)) return candidate;
118
+ }
97
119
  }
98
120
  return null;
99
121
  };
@@ -163,7 +185,7 @@ const main = () => {
163
185
  // 处置指引按宿主分流: 仓库检出态 (有源码) 可走源码入口或重构建; 包态 (无源码) 只能重装本包
164
186
  const advice = existsSync(join(root, 'src', 'cli.ts'))
165
187
  ? '用源码入口跑 (bun src/cli.ts 或 node src/cli.ts), 或重新构建 (bun run build)'
166
- : '重装本包换一份完好分发 (npm install -g @iyowei/sweep-node-modules); 重装无效则说明该版本包有缺陷, 需发布者重新构建后再发';
188
+ : '重装本包换一份完好分发 (npm install -g @iyowei/sweep-node-modules-cli); 重装无效则说明该版本包有缺陷, 需发布者重新构建后再发';
167
189
  process.stderr.write(
168
190
  `sweep-nm: ${problem}, 已拒绝执行该产物 (无法证明它与构建清单同源)。\n` +
169
191
  ` 处置: ${advice}。\n`,
package/dist/cli.js CHANGED
@@ -1210,6 +1210,11 @@ function createDuSizer(bin = findDu()) {
1210
1210
  const failures = new Map;
1211
1211
  let intact = true;
1212
1212
  if (safeTargets.length > 0) {
1213
+ if (options?.signal?.aborted) {
1214
+ throw new SweepError("CANCELLED", "体积统计在批量统计前被取消", {
1215
+ phase: "measure"
1216
+ });
1217
+ }
1213
1218
  const { stdout, stderr } = await runDu(bin, safeTargets);
1214
1219
  const assessment = assessDuOutput(stdout, safeTargets);
1215
1220
  intact = assessment.intact;
@@ -1822,6 +1827,7 @@ function helpText(color) {
1822
1827
  row("sweep-nm config", "查看实际生效的配置: 来源 + 路径 + 文件状态"),
1823
1828
  row("sweep-nm init", "初始化向导: 交互生成配置文件"),
1824
1829
  row("sweep-nm --help", "帮助"),
1830
+ row("sweep-nm -h", "--help 的别名"),
1825
1831
  "",
1826
1832
  "说明:",
1827
1833
  " --exclude 按目录名精确匹配 (区分大小写), 从根到命中点的任意一级命中即跳过",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "commit": "649c1f4128c950d192f7225458f54cd8071a4e2d",
3
+ "commit": "3218787a30a10755c1440ffc9954d4d253506da0",
4
4
  "dirty": false,
5
- "cliSha256": "2582a554e1cd9c141f86485dbb1d361a9243d9b71b2dc816b29fb1b2e3cfbc82",
6
- "builtAt": "2026-09-29T15:02:19.360Z"
5
+ "cliSha256": "a1c13d3aa735d1f4cab2cd7475d88e7f7fa6acd662fa08466c18f690e34c0a48",
6
+ "builtAt": "2026-09-30T07:09:11.780Z"
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iyowei/sweep-node-modules-cli",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "CLI to find and delete node_modules across projects: scan multiple workspace roots (monorepo friendly), bulk-remove them to free up disk space, preview first and delete after confirmation. 工作区级 node_modules 批量清理工具。",
5
5
  "keywords": [
6
6
  "cli",
@@ -57,7 +57,7 @@
57
57
  "registry": "https://registry.npmjs.org/"
58
58
  },
59
59
  "devDependencies": {
60
- "@iyowei/sweep-node-modules": "0.5.0"
60
+ "@iyowei/sweep-node-modules": "0.5.1"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "bun build src/cli.ts --target=node --outfile=dist/cli.js && bun scripts/write-dist-manifest.ts",