@iyowei/sweep-node-modules-cli 0.1.0 → 0.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/LICENSE +1 -1
- package/README.md +10 -6
- package/README.zh-CN.md +10 -6
- package/dist/cli.js +24 -13
- package/dist/manifest.json +3 -3
- package/package.json +3 -3
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
# sweep-node-modules
|
|
1
|
+
# sweep-node-modules-cli
|
|
2
2
|
|
|
3
3
|
[](https://github.com/iyowei/sweep-node-modules/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@iyowei/sweep-node-modules-cli)
|
|
5
|
+
[](https://www.npmjs.com/package/@iyowei/sweep-node-modules-cli)
|
|
6
|
+

|
|
7
|
+

|
|
4
8
|
|
|
5
9
|
**English** | [中文](README.zh-CN.md)
|
|
6
10
|
|
|
@@ -55,10 +59,10 @@ bun install -g @iyowei/sweep-node-modules-cli
|
|
|
55
59
|
# clone, then cd into the repo root (adjust the path to your clone location)
|
|
56
60
|
cd "<your clone>/sweep-node-modules"
|
|
57
61
|
|
|
58
|
-
chmod +x packages/cli/bin/sweep-nm
|
|
62
|
+
chmod +x packages/sweep-node-modules-cli/bin/sweep-nm
|
|
59
63
|
|
|
60
64
|
# symlink it into ~/.local/bin (usually already on PATH); the launcher picks the runtime
|
|
61
|
-
ln -sf "$PWD/packages/cli/bin/sweep-nm" ~/.local/
|
|
65
|
+
ln -sf "$PWD/packages/sweep-node-modules-cli/bin/sweep-nm" ~/.local/bin/sweep-nm
|
|
62
66
|
```
|
|
63
67
|
|
|
64
68
|
**Windows** (PowerShell):
|
|
@@ -66,7 +70,7 @@ ln -sf "$PWD/packages/cli/bin/sweep-nm" ~/.local/packages/cli/bin/sweep-nm
|
|
|
66
70
|
```powershell
|
|
67
71
|
# add the repo's bin directory to your user PATH; one-time, effective after reopening the terminal
|
|
68
72
|
# adjust the path to your actual clone location (the launcher locates src relative to itself, so the script cannot be copied out on its own)
|
|
69
|
-
$bin = "$env:USERPROFILE\tools\sweep-node-modules\packages\cli\bin"
|
|
73
|
+
$bin = "$env:USERPROFILE\tools\sweep-node-modules\packages\sweep-node-modules-cli\bin"
|
|
70
74
|
[Environment]::SetEnvironmentVariable(
|
|
71
75
|
'Path',
|
|
72
76
|
[Environment]::GetEnvironmentVariable('Path', 'User') + ";$bin",
|
|
@@ -77,9 +81,9 @@ $bin = "$env:USERPROFILE\tools\sweep-node-modules\packages\cli\bin"
|
|
|
77
81
|
> Or skip the command line: add the `bin` directory to your user `Path` under System Properties → Environment Variables.
|
|
78
82
|
|
|
79
83
|
- **Requires**: bun or node, either works (the launcher is a shell / cmd script run by the OS; it does not depend on node)
|
|
80
|
-
- The most direct entry point; afterwards just run `sweep-nm` (on Windows via `packages\cli\bin\sweep-nm.cmd`)
|
|
84
|
+
- The most direct entry point; afterwards just run `sweep-nm` (on Windows via `packages\sweep-node-modules-cli\bin\sweep-nm.cmd`)
|
|
81
85
|
|
|
82
|
-
> The tool also ships an API package, `@iyowei/sweep-node-modules
|
|
86
|
+
> The tool also ships an API package, [`@iyowei/sweep-node-modules`](https://www.npmjs.com/package/@iyowei/sweep-node-modules), for use in your own programs or scripts (usage is documented in that package).
|
|
83
87
|
|
|
84
88
|
## Usage
|
|
85
89
|
|
package/README.zh-CN.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
# sweep-node-modules
|
|
1
|
+
# sweep-node-modules-cli
|
|
2
2
|
|
|
3
3
|
[](https://github.com/iyowei/sweep-node-modules/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@iyowei/sweep-node-modules-cli)
|
|
5
|
+
[](https://www.npmjs.com/package/@iyowei/sweep-node-modules-cli)
|
|
6
|
+

|
|
7
|
+

|
|
4
8
|
|
|
5
9
|
[English](README.md) | **中文**
|
|
6
10
|
|
|
@@ -55,10 +59,10 @@ bun install -g @iyowei/sweep-node-modules-cli
|
|
|
55
59
|
# 克隆后进入仓库根 (路径按你的实际位置调整)
|
|
56
60
|
cd "<克隆位置>/sweep-node-modules"
|
|
57
61
|
|
|
58
|
-
chmod +x packages/cli/bin/sweep-nm
|
|
62
|
+
chmod +x packages/sweep-node-modules-cli/bin/sweep-nm
|
|
59
63
|
|
|
60
64
|
# 软链进 ~/.local/bin (通常已在 PATH 中), 启动器会挑选运行时
|
|
61
|
-
ln -sf "$PWD/packages/cli/bin/sweep-nm" ~/.local/
|
|
65
|
+
ln -sf "$PWD/packages/sweep-node-modules-cli/bin/sweep-nm" ~/.local/bin/sweep-nm
|
|
62
66
|
```
|
|
63
67
|
|
|
64
68
|
**Windows** (PowerShell):
|
|
@@ -66,7 +70,7 @@ ln -sf "$PWD/packages/cli/bin/sweep-nm" ~/.local/packages/cli/bin/sweep-nm
|
|
|
66
70
|
```powershell
|
|
67
71
|
# 把仓库的 bin 目录加入用户 PATH, 只需一次, 重开终端后生效
|
|
68
72
|
# 路径按你的实际克隆位置调整 (启动器靠自身位置定位 src, 故不能把脚本单独复制走)
|
|
69
|
-
$bin = "$env:USERPROFILE\tools\sweep-node-modules\packages\cli\bin"
|
|
73
|
+
$bin = "$env:USERPROFILE\tools\sweep-node-modules\packages\sweep-node-modules-cli\bin"
|
|
70
74
|
[Environment]::SetEnvironmentVariable(
|
|
71
75
|
'Path',
|
|
72
76
|
[Environment]::GetEnvironmentVariable('Path', 'User') + ";$bin",
|
|
@@ -77,9 +81,9 @@ $bin = "$env:USERPROFILE\tools\sweep-node-modules\packages\cli\bin"
|
|
|
77
81
|
> 也可以不经命令行: 在「系统属性 → 环境变量」里把该 `bin` 目录加到用户变量 `Path` 中。
|
|
78
82
|
|
|
79
83
|
- **需要**: bun 或 node 任一 (启动器是 shell / cmd 脚本, 由系统执行, 不依赖 node)
|
|
80
|
-
- 特点: 入口最直接; 之后直接敲 `sweep-nm` (Windows 经 `packages\cli\bin\sweep-nm.cmd`)
|
|
84
|
+
- 特点: 入口最直接; 之后直接敲 `sweep-nm` (Windows 经 `packages\sweep-node-modules-cli\bin\sweep-nm.cmd`)
|
|
81
85
|
|
|
82
|
-
> 本工具同时提供可编程 API 包 `@iyowei/sweep-node-modules
|
|
86
|
+
> 本工具同时提供可编程 API 包 [`@iyowei/sweep-node-modules`](https://www.npmjs.com/package/@iyowei/sweep-node-modules), 供在程序或脚本中调用 (用法见该包文档)。
|
|
83
87
|
|
|
84
88
|
## 使用
|
|
85
89
|
|
package/dist/cli.js
CHANGED
|
@@ -3,10 +3,10 @@ import { lstat as lstat3, mkdir, realpath as realpath3 } from "node:fs/promises"
|
|
|
3
3
|
import { homedir as homedir5 } from "node:os";
|
|
4
4
|
import { basename, dirname } from "node:path";
|
|
5
5
|
|
|
6
|
-
// ../
|
|
6
|
+
// ../sweep-node-modules/src/classify.ts
|
|
7
7
|
import { homedir as homedir3 } from "node:os";
|
|
8
8
|
|
|
9
|
-
// ../
|
|
9
|
+
// ../sweep-node-modules/src/config.ts
|
|
10
10
|
import { readFile } from "node:fs/promises";
|
|
11
11
|
import { homedir } from "node:os";
|
|
12
12
|
import { posix, win32 } from "node:path";
|
|
@@ -130,7 +130,7 @@ function mergeNames(configNames, cliNames) {
|
|
|
130
130
|
return [...new Set([...configNames, ...cliNames])].filter((name) => name !== "node_modules" && name !== ".git");
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
// ../
|
|
133
|
+
// ../sweep-node-modules/src/guard.ts
|
|
134
134
|
import { lstat, realpath, stat } from "node:fs/promises";
|
|
135
135
|
import { homedir as homedir2 } from "node:os";
|
|
136
136
|
import { posix as posix2, win32 as win322 } from "node:path";
|
|
@@ -319,7 +319,7 @@ async function findCrossDeviceTargets(targets, options) {
|
|
|
319
319
|
return found;
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
-
// ../
|
|
322
|
+
// ../sweep-node-modules/src/classify.ts
|
|
323
323
|
var fold2 = (text, style) => style.caseInsensitive ? text.toLowerCase() : text;
|
|
324
324
|
var INSTALL_TREE_SEGMENTS = new Set([...DEFAULT_EXCLUDE, "extensions", "_npx"].map((name) => name.toLowerCase()));
|
|
325
325
|
function classifyTarget(target, options = {}) {
|
|
@@ -351,7 +351,7 @@ function classifyTarget(target, options = {}) {
|
|
|
351
351
|
}
|
|
352
352
|
return { kind: "project" };
|
|
353
353
|
}
|
|
354
|
-
// ../
|
|
354
|
+
// ../sweep-node-modules/src/delete.ts
|
|
355
355
|
import { lstat as lstat2, rm } from "node:fs/promises";
|
|
356
356
|
import { isAbsolute, join, relative, sep } from "node:path";
|
|
357
357
|
var ERROR_HINTS = {
|
|
@@ -493,7 +493,7 @@ async function removeTargets(targets, options) {
|
|
|
493
493
|
}
|
|
494
494
|
return result;
|
|
495
495
|
}
|
|
496
|
-
// ../
|
|
496
|
+
// ../sweep-node-modules/src/runtime.ts
|
|
497
497
|
import { readFile as readFile2, writeFile } from "node:fs/promises";
|
|
498
498
|
var isBun = typeof Bun !== "undefined";
|
|
499
499
|
var versions = process.versions;
|
|
@@ -506,7 +506,7 @@ async function writeTextFile(path, text) {
|
|
|
506
506
|
}
|
|
507
507
|
await writeFile(path, text, "utf8");
|
|
508
508
|
}
|
|
509
|
-
// ../
|
|
509
|
+
// ../sweep-node-modules/src/scan-parallel.ts
|
|
510
510
|
import { readdir, realpath as realpath2, stat as stat2 } from "node:fs/promises";
|
|
511
511
|
import { join as join2 } from "node:path";
|
|
512
512
|
var NODE_MODULES = "node_modules";
|
|
@@ -676,12 +676,13 @@ function createParallelScanner() {
|
|
|
676
676
|
}
|
|
677
677
|
};
|
|
678
678
|
}
|
|
679
|
-
// ../
|
|
679
|
+
// ../sweep-node-modules/src/size-du.ts
|
|
680
680
|
import { spawn } from "node:child_process";
|
|
681
681
|
import { accessSync, constants } from "node:fs";
|
|
682
682
|
var DU_PROBES = ["/usr/bin/du", "/bin/du"];
|
|
683
683
|
var hasControlChar = (target) => target.includes(`
|
|
684
684
|
`) || target.includes("\r");
|
|
685
|
+
var PROG_PREFIX_RE = /^(?:\/[^\s:]*)?[a-z][a-z0-9_-]*:\s+/;
|
|
685
686
|
function findDu(platform = process.platform) {
|
|
686
687
|
if (platform === "win32")
|
|
687
688
|
return null;
|
|
@@ -769,7 +770,15 @@ function describeDuFailure(detail) {
|
|
|
769
770
|
return { reason: `读取失败 (${detail})`, missing: false };
|
|
770
771
|
}
|
|
771
772
|
function parseDuErrorLine(line) {
|
|
772
|
-
const
|
|
773
|
+
const body = line.replace(PROG_PREFIX_RE, "");
|
|
774
|
+
const gnu = /^cannot\s+(?:access|read directory|stat|open)\s+'(.*)':\s+(.+)$/.exec(body);
|
|
775
|
+
if (gnu !== null) {
|
|
776
|
+
const path = gnu[1];
|
|
777
|
+
const detail = gnu[2];
|
|
778
|
+
if (path !== undefined && detail !== undefined)
|
|
779
|
+
return { path, detail };
|
|
780
|
+
}
|
|
781
|
+
const match = /^(.+):\s+(.+)$/.exec(body);
|
|
773
782
|
if (match === null)
|
|
774
783
|
return null;
|
|
775
784
|
const path = match[1];
|
|
@@ -818,7 +827,7 @@ function createDuSizer(bin = findDu()) {
|
|
|
818
827
|
continue;
|
|
819
828
|
const errorLine = parseDuErrorLine(line);
|
|
820
829
|
if (errorLine === null) {
|
|
821
|
-
warnings.push(`体积统计失败 (未归因): ${line.trim()}`);
|
|
830
|
+
warnings.push(`体积统计失败 (未归因): ${line.replace(PROG_PREFIX_RE, "").trim()}`);
|
|
822
831
|
continue;
|
|
823
832
|
}
|
|
824
833
|
const failure = describeDuFailure(errorLine.detail);
|
|
@@ -828,6 +837,8 @@ function createDuSizer(bin = findDu()) {
|
|
|
828
837
|
}
|
|
829
838
|
failures.set(errorLine.path, failure);
|
|
830
839
|
}
|
|
840
|
+
for (const path of failures.keys())
|
|
841
|
+
sizes.delete(path);
|
|
831
842
|
}
|
|
832
843
|
for (const target of sorted) {
|
|
833
844
|
if (hasControlChar(target)) {
|
|
@@ -859,7 +870,7 @@ function createDuSizer(bin = findDu()) {
|
|
|
859
870
|
};
|
|
860
871
|
}
|
|
861
872
|
|
|
862
|
-
// ../
|
|
873
|
+
// ../sweep-node-modules/src/size-js.ts
|
|
863
874
|
import { readdir as readdir2, stat as stat3 } from "node:fs/promises";
|
|
864
875
|
import { join as join3 } from "node:path";
|
|
865
876
|
function describeFailure(code) {
|
|
@@ -932,11 +943,11 @@ function createJsSizer() {
|
|
|
932
943
|
};
|
|
933
944
|
}
|
|
934
945
|
|
|
935
|
-
// ../
|
|
946
|
+
// ../sweep-node-modules/src/size.ts
|
|
936
947
|
function createSizer() {
|
|
937
948
|
return findDu() !== null ? createDuSizer() : createJsSizer();
|
|
938
949
|
}
|
|
939
|
-
// ../
|
|
950
|
+
// ../sweep-node-modules/src/skip.ts
|
|
940
951
|
var SUSPECT_HINT = "已跳过 (加 --force 一并清理)";
|
|
941
952
|
var CROSS_DEVICE_NOTES = {
|
|
942
953
|
"on-path": "跨设备: 根与目标之间有挂载点",
|
package/dist/manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"commit": "
|
|
3
|
+
"commit": "0df47482641c2ac1838b93dd4b3fe0ae3b468176",
|
|
4
4
|
"dirty": false,
|
|
5
|
-
"cliSha256": "
|
|
6
|
-
"builtAt": "2026-09-
|
|
5
|
+
"cliSha256": "d77fbedaffabda1b10f8a901a4aa43842dc1039fee5b419da5e85a29a5b19416",
|
|
6
|
+
"builtAt": "2026-09-29T09:02:15.995Z"
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iyowei/sweep-node-modules-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"bun",
|
|
32
32
|
"node"
|
|
33
33
|
],
|
|
34
|
-
"author": "
|
|
34
|
+
"author": "iTonyYo (https://github.com/iTonyYo)",
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"repository": {
|
|
37
37
|
"type": "git",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"registry": "https://registry.npmjs.org/"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@iyowei/sweep-node-modules": "
|
|
60
|
+
"@iyowei/sweep-node-modules": "*"
|
|
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",
|