@iyowei/sweep-node-modules 0.2.0 → 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.
Files changed (3) hide show
  1. package/README.md +4 -1
  2. package/dist/cli.js +30 -12
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -88,6 +88,9 @@ sweep-nm --exclude my-kits --exclude url-tool
88
88
  # 只清理名单命中的目录(可重复, 与配置合并)
89
89
  sweep-nm --include my-kits
90
90
 
91
+ # 查看实际生效的配置文件位置与状态 (来源 / 路径 / 是否存在)
92
+ sweep-nm config
93
+
91
94
  # 初始化向导: 交互式生成配置文件
92
95
  sweep-nm init
93
96
  ```
@@ -96,7 +99,7 @@ sweep-nm init
96
99
 
97
100
  ## 配置
98
101
 
99
- 配置文件位置 (平台自适应): Windows 为 `%APPDATA%\sweep-node-modules\config.json`, 其余为 `~/.config/sweep-node-modules/config.json`; 可用 `--config` 或环境变量 `SWEEP_NM_CONFIG` 覆盖。
102
+ 配置文件位置 (平台自适应): Windows 为 `%APPDATA%\sweep-node-modules\config.json`, 其余为 `~/.config/sweep-node-modules/config.json`; 可用 `--config` 或环境变量 `SWEEP_NM_CONFIG` 覆盖, 本次实际生效的路径与文件状态用 `sweep-nm config` 查看。
100
103
 
101
104
  ```json
102
105
  {
package/dist/cli.js CHANGED
@@ -1064,11 +1064,11 @@ function parseArgs(argv) {
1064
1064
  positionals.push(arg);
1065
1065
  }
1066
1066
  const [only] = positionals;
1067
- if (positionals.length > 1 || only !== undefined && only !== "init") {
1067
+ if (positionals.length > 1 || only !== undefined && only !== "init" && only !== "config") {
1068
1068
  return { ok: false, message: `未知参数: ${positionals.join(" ")}` };
1069
1069
  }
1070
- if (only === "init")
1071
- options.command = "init";
1070
+ if (only === "init" || only === "config")
1071
+ options.command = only;
1072
1072
  return { ok: true, options };
1073
1073
  }
1074
1074
  function colorEnabled() {
@@ -1103,29 +1103,32 @@ function helpText(color) {
1103
1103
  row("sweep-nm --exclude <name>", "临时追加排除 (可重复, 与配置合并)"),
1104
1104
  row("sweep-nm --include <name>", "只清理命中名单的目录 (可重复, 与配置合并)"),
1105
1105
  row("sweep-nm --config <path>", "指定配置文件 (优先于 SWEEP_NM_CONFIG)"),
1106
+ row("sweep-nm config", "查看实际生效的配置: 来源 + 路径 + 文件状态"),
1106
1107
  row("sweep-nm init", "初始化向导: 交互生成配置文件"),
1107
1108
  row("sweep-nm --help", "帮助"),
1108
1109
  "",
1109
1110
  "说明:",
1110
1111
  " --exclude 按目录名精确匹配 (区分大小写), 从根到命中点的任意一级命中即跳过",
1111
1112
  " --include 同款匹配口径, 命中才纳入; 同时命中 exclude 的照旧跳过",
1112
- ` 默认配置位置 (平台自适应): ${defaultConfigPath()}`,
1113
+ ` 默认配置位置 (平台自适应; 用了 --config 或 SWEEP_NM_CONFIG 时实际读的不是它): ${defaultConfigPath()}`,
1114
+ " 查实际生效的路径: sweep-nm config",
1113
1115
  "",
1114
1116
  "退出码: 0 成功 (含预览与空结果); 1 删除失败 / 配置损坏 / 参数错误"
1115
1117
  ].join(`
1116
1118
  `);
1117
1119
  }
1120
+ async function fileExists(path) {
1121
+ try {
1122
+ await lstat2(path);
1123
+ return true;
1124
+ } catch {
1125
+ return false;
1126
+ }
1127
+ }
1118
1128
  function runWizard(configPath) {
1119
1129
  return runInit({
1120
1130
  configPath,
1121
- async fileExists(path) {
1122
- try {
1123
- await lstat2(path);
1124
- return true;
1125
- } catch {
1126
- return false;
1127
- }
1128
- },
1131
+ fileExists,
1129
1132
  async writeFile(path, text) {
1130
1133
  await mkdir(dirname(path), { recursive: true });
1131
1134
  await writeTextFile(path, text);
@@ -1133,6 +1136,18 @@ function runWizard(configPath) {
1133
1136
  io: createReadlineIO()
1134
1137
  });
1135
1138
  }
1139
+ var SOURCE_LABELS = {
1140
+ flag: "--config 指定",
1141
+ env: "环境变量 SWEEP_NM_CONFIG",
1142
+ "platform-default": "平台默认"
1143
+ };
1144
+ async function reportConfig(resolved) {
1145
+ const exists = await fileExists(resolved.path);
1146
+ print(`配置来源: ${SOURCE_LABELS[resolved.source]}`);
1147
+ print(`配置路径: ${resolved.path}`);
1148
+ print(`文件状态: ${exists ? "存在" : "不存在"}`);
1149
+ return 0;
1150
+ }
1136
1151
  async function resolveConfig(resolved) {
1137
1152
  const loaded = await loadResolvedConfig(resolved);
1138
1153
  if (loaded.state === "ok")
@@ -1304,6 +1319,9 @@ async function main() {
1304
1319
  print("配置未变更");
1305
1320
  return 0;
1306
1321
  }
1322
+ if (options.command === "config") {
1323
+ return await reportConfig(resolvedPath);
1324
+ }
1307
1325
  const resolved = await resolveConfig(resolvedPath);
1308
1326
  if (resolved === null)
1309
1327
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iyowei/sweep-node-modules",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "工作区级 node_modules 清理工具: 一次扫描多个根目录, 跨项目列出体积, 确认后批量删除。",
5
5
  "keywords": [
6
6
  "cli",