dsh-mobile-plugin 0.5.72 → 0.5.73
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/lib/mobile/drive-roots.js +45 -14
- package/lib/mobile/workspaces.js +4 -3
- package/lib/update-install.cjs +21 -9
- package/package.json +1 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* 盘符层:被控端那一排可跳的根,供手机端「添加工作区」跨盘浏览。
|
|
5
5
|
*
|
|
6
|
-
* 为什么需要这一层:宿主 browse
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* 为什么需要这一层:宿主 browse 后端只列**某一层目录的内容**、从不枚举盘符/挂载卷,而目录
|
|
7
|
+
* 浏览器一打开就落在被控端主目录,面包屑又只回得到「主目录」上不去根 —— Windows 上它永远
|
|
8
|
+
* 在 C 盘,Mac 上永远在 /Users/<name>。于是别的盘从来不是「读不到」,而是客户端根本没有任何
|
|
9
|
+
* 入口能跳过去(手输完整路径能进,但那条路藏起来了)。
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* 只有一次网络请求的开销。
|
|
11
|
+
* Windows 是 A–Z 逐个 `stat('X:\\')` 探盘符(本插件没有 shell 能力面,也不该为了 26 次 stat
|
|
12
|
+
* 去开一个);macOS 是列 `/Volumes` 下挂的卷(外接硬盘、磁盘镜像都挂这儿)。
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* Linux 等其余平台返回根目录一项:调用方只需处理「一排根」这一种形状,不必自己判平台;只有
|
|
15
|
+
* 一项时客户端不显示这一层,所以这些平台的界面一个像素都不变。
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const { stat } = require('node:fs/promises');
|
|
18
|
+
const { readdir, stat } = require('node:fs/promises');
|
|
19
19
|
|
|
20
20
|
/** 盘符顺序取 A–Z,`Promise.all` 保序,所以结果天然按字母排。 */
|
|
21
21
|
const DRIVE_LETTERS = Object.freeze('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''));
|
|
@@ -46,14 +46,45 @@ async function listWindowsRoots({ statFile = stat } = {}) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* macOS:外接硬盘、磁盘镜像都挂在 `/Volumes` 下。逐个列出来,跳过点开头的隐藏项和符号链接
|
|
50
|
+
* (引导卷的别名 `Macintosh HD -> /` 就是一条符号链接,跳过它才不会和下面的根重复)。
|
|
51
|
+
* `/Volumes` 读不出来(权限/异常)时退回只有根一项,不让这条路由整体失败。
|
|
50
52
|
*
|
|
51
|
-
* @param {{
|
|
53
|
+
* @param {{ readdirFile?: typeof readdir, statFile?: typeof stat }} [options] 注入点,测试用。
|
|
54
|
+
* @returns 根行数组:文件系统根 + 各挂载卷
|
|
55
|
+
*/
|
|
56
|
+
async function listMacRoots({ readdirFile = readdir, statFile = stat } = {}) {
|
|
57
|
+
const roots = [{ name: '/', path: '/', hidden: false }];
|
|
58
|
+
let entries;
|
|
59
|
+
try {
|
|
60
|
+
entries = await readdirFile('/Volumes', { withFileTypes: true });
|
|
61
|
+
} catch {
|
|
62
|
+
return roots;
|
|
63
|
+
}
|
|
64
|
+
for (const entry of entries) {
|
|
65
|
+
if (entry.name.startsWith('.') || entry.isSymbolicLink()) continue;
|
|
66
|
+
const path = `/Volumes/${entry.name}`;
|
|
67
|
+
try {
|
|
68
|
+
if (!(await statFile(path)).isDirectory()) continue;
|
|
69
|
+
} catch {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
roots.push({ name: entry.name, path, hidden: false });
|
|
73
|
+
}
|
|
74
|
+
return roots;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 这台被控端可跳的根:Windows 是各块盘,macOS 是根 + 各挂载卷,其余平台是文件系统根。
|
|
79
|
+
*
|
|
80
|
+
* @param {{ platform?: string, statFile?: typeof stat, readdirFile?: typeof readdir }} [options]
|
|
81
|
+
* 平台与 fs 注入点(测试用)。
|
|
52
82
|
* @returns 根行数组
|
|
53
83
|
*/
|
|
54
|
-
async function listRoots({ platform = process.platform, statFile = stat } = {}) {
|
|
84
|
+
async function listRoots({ platform = process.platform, statFile = stat, readdirFile = readdir } = {}) {
|
|
55
85
|
if (platform === 'win32') return listWindowsRoots({ statFile });
|
|
86
|
+
if (platform === 'darwin') return listMacRoots({ readdirFile, statFile });
|
|
56
87
|
return [{ name: '/', path: '/', hidden: false }];
|
|
57
88
|
}
|
|
58
89
|
|
|
59
|
-
module.exports = { DRIVE_LETTERS, listRoots, listWindowsRoots };
|
|
90
|
+
module.exports = { DRIVE_LETTERS, listMacRoots, listRoots, listWindowsRoots };
|
package/lib/mobile/workspaces.js
CHANGED
|
@@ -168,9 +168,10 @@ async function handleListDirectory(ctx, req, res) {
|
|
|
168
168
|
|
|
169
169
|
/**
|
|
170
170
|
* GET /api/mobile/v1/directory/roots(token)
|
|
171
|
-
* 「添加工作区」的盘符层:宿主 browse
|
|
172
|
-
*
|
|
173
|
-
* Windows
|
|
171
|
+
* 「添加工作区」的盘符层:宿主 browse 后端只列某一层目录的内容、从不枚举盘符/挂载卷,而手机端
|
|
172
|
+
* 的目录浏览器一打开就落在被控端主目录 —— Windows 上它永远在 C 盘、Mac 上永远在主目录,别的盘
|
|
173
|
+
* 没有任何入口。Windows 回真实存在的盘符,macOS 回根 + `/Volumes` 下的挂载卷,其余平台回文件
|
|
174
|
+
* 系统根;只有一项时 App 不显示这一层。
|
|
174
175
|
*
|
|
175
176
|
* 不走宿主:host.listDirectory 只认路径、给不出一份根清单,而枚举本身与目录选择器的部署
|
|
176
177
|
* 形态无关(browse / native 两种宿主下答案一样)。
|
package/lib/update-install.cjs
CHANGED
|
@@ -222,16 +222,26 @@ function installationProblem(profileNodeModules, name, version) {
|
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
/** 声明里写的是不是精确版本(`1.1.4` / `1.1.4-rc.1`),不是范围、标签或 git/url。 */
|
|
226
|
+
function exactDeclaredVersion(spec) {
|
|
227
|
+
if (typeof spec !== 'string') return null;
|
|
228
|
+
const trimmed = spec.trim();
|
|
229
|
+
return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(trimmed) ? trimmed : null;
|
|
230
|
+
}
|
|
231
|
+
|
|
225
232
|
/**
|
|
226
|
-
*
|
|
233
|
+
* 这次装完后,插件声明的可选依赖(例如 tailcat 平台包)各自要登记进排除清单的版本。
|
|
227
234
|
*
|
|
228
235
|
* 它们和插件本体一样可能刚发布就被装进来,登记排除清单时要一并写 —— 否则这些包自己的
|
|
229
|
-
* 锁条目会把后续的安装挡在 24
|
|
230
|
-
*
|
|
236
|
+
* 锁条目会把后续的安装挡在 24 小时冷却窗口里。**必须按声明补齐所有平台**:pnpm 11 在任何
|
|
237
|
+
* add / remove 之前校验的是**整份 lockfile**,lockfile 锁了全部 os / cpu 变体,所以
|
|
238
|
+
* 「os / cpu 不匹配、没落到盘上」的平台包,其锁条目照样参与校验 —— 跳过安装不等于跳过校验。
|
|
231
239
|
*
|
|
232
|
-
*
|
|
240
|
+
* 版本取值:声明里是精确版本就直接用(本项目这些平台包就钉死版本);写的是范围之类解析不出的,
|
|
241
|
+
* 退回读实际装上的那份;两样都拿不到就跳过这条,不猜。读不到插件清单也只跳过、不抛 ——
|
|
242
|
+
* 登记是善后,不该把装好的版本说成没装上。
|
|
233
243
|
*/
|
|
234
|
-
function
|
|
244
|
+
function optionalDepsToExclude(profileNodeModules, name = DEFAULT_NAME) {
|
|
235
245
|
const readVersion = (dir) => {
|
|
236
246
|
try {
|
|
237
247
|
const raw = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
@@ -249,8 +259,10 @@ function installedOptionalDeps(profileNodeModules, name = DEFAULT_NAME) {
|
|
|
249
259
|
}
|
|
250
260
|
if (!optional || typeof optional !== 'object') return out;
|
|
251
261
|
for (const depName of Object.keys(optional)) {
|
|
252
|
-
//
|
|
253
|
-
const version =
|
|
262
|
+
// 精确版本覆盖所有平台(有些平台没装上也照样要登记);范围类才回落到盘上装的那份。
|
|
263
|
+
const version = exactDeclaredVersion(optional[depName])
|
|
264
|
+
// hoisted 布局在 profile/node_modules 顶层;严格布局下在插件自己的 node_modules 里。
|
|
265
|
+
|| readVersion(path.join(profileNodeModules, depName))
|
|
254
266
|
|| readVersion(path.join(profileNodeModules, name, 'node_modules', depName));
|
|
255
267
|
if (version) out.push({ name: depName, version });
|
|
256
268
|
}
|
|
@@ -785,7 +797,7 @@ async function installLatest({
|
|
|
785
797
|
// 插件按平台带出来的可选依赖(如 tailcat 平台包)也是刚发就可能刚装上的,同批登记,
|
|
786
798
|
// 否则这些包自己的锁条目会把后续安装挡在冷却窗口里。逐条尽力写,失败不影响主结果。
|
|
787
799
|
if (changed) {
|
|
788
|
-
for (const dep of
|
|
800
|
+
for (const dep of optionalDepsToExclude(profileNodeModules, name)) {
|
|
789
801
|
recordReleaseAgeExclusion(profileDir, dep.name, dep.version);
|
|
790
802
|
}
|
|
791
803
|
}
|
|
@@ -931,7 +943,7 @@ module.exports = {
|
|
|
931
943
|
installLatest,
|
|
932
944
|
installLatestIfNeeded,
|
|
933
945
|
installedVersion,
|
|
934
|
-
|
|
946
|
+
optionalDepsToExclude,
|
|
935
947
|
declaredSource,
|
|
936
948
|
// 「Windows 上怎么起包管理器」在本机跑不起来,守卫只能验拼好的那一行,所以这两样露出来。
|
|
937
949
|
cmdInvocation,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mobile-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.73",
|
|
4
4
|
"description": "Mobile API (/api/mobile/v1) and relay client for the DSH mobile app — desktop profile build (dsh 0.2.x, peers resolved by the host)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"icon": "./icon.png",
|