pi-webdav-backup 1.3.0 → 1.3.1

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.
@@ -16,7 +16,7 @@
16
16
  */
17
17
 
18
18
  import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from "node:fs";
19
- import { join } from "node:path";
19
+ import { join, dirname } from "node:path";
20
20
  import { spawnSync } from "node:child_process";
21
21
 
22
22
  /**
@@ -164,13 +164,35 @@ function readDeps(pkgDir) {
164
164
  }
165
165
 
166
166
  /**
167
- * 缺依赖检测:逐个依赖名查 node_modules(同 pi 的 hasMissingGitDependencies),
168
- * 只看 dependencies。只判断 node_modules 目录存在会漏掉「拷了一半」的情况。
167
+ * 依赖解析根:从 pkgDir 起逐级向上收集所有 node_modules(Node 模块解析算法)。
168
+ * npm 的依赖会被提升到父级(如 agentDir/npm/node_modules),只查 pkgDir/node_modules
169
+ * 会误报“缺依赖”——尤其是 npm 安装的包。
170
+ */
171
+ function dependencyRoots(pkgDir) {
172
+ const roots = [];
173
+ let dir = pkgDir;
174
+ for (let i = 0; i < 12; i++) {
175
+ roots.push(join(dir, "node_modules"));
176
+ const parent = dirname(dir);
177
+ if (parent === dir) break;
178
+ dir = parent;
179
+ }
180
+ return roots;
181
+ }
182
+
183
+ /**
184
+ * 缺依赖检测:逐个依赖名沿 Node 解析路径查找(含祖先 node_modules 的提升)。
185
+ * 只看 dependencies;只判断“包目录/node_modules 存在”会漏掉「拷了一半」的情况。
169
186
  * 返回缺失的依赖名数组;无法判断时返回 null。
170
187
  */
171
188
  function missingDeps(pkgDir, depNames) {
172
189
  if (!depNames) return null;
173
- return depNames.filter((name) => !existsSync(join(pkgDir, "node_modules", ...String(name).split("/"))));
190
+ const roots = dependencyRoots(pkgDir);
191
+ return depNames.filter((name) => {
192
+ const parts = String(name).split("/");
193
+ // 命中任一祖先 node_modules 即视为已安装
194
+ return !roots.some((root) => existsSync(join(root, ...parts)));
195
+ });
174
196
  }
175
197
 
176
198
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-webdav-backup",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "pi 配置与插件数据自动备份到 WebDAV(坚果云 / Nextcloud / 群晖 / 自建):归档与快照两种模式、AES-256-GCM 加密、DPAPI 密钥管理、敏感字段脱敏、agentDir 之外的额外数据(extraScope)、插件实现代码随备份(includePlugins)实现换机一键还原、退出自动备份与每日定时备份。",
5
5
  "keywords": [
6
6
  "pi-package",