dsh-mobile-plugin 0.5.63 → 0.5.65
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/frpc/provision.cjs +384 -0
- package/lib/frpc/runner.cjs +229 -0
- package/lib/impl.js +36 -0
- package/lib/mobile/pairing.js +7 -0
- package/lib/mobile/relay-control.js +11 -0
- package/lib/mobile/session-send.js +4 -2
- package/lib/panel/index.html +9 -9
- package/lib/relay/control.js +260 -0
- package/lib/relay/core.js +13 -1
- package/lib/relay/lan-network.cjs +26 -0
- package/lib/relay/pairing-payload.cjs +8 -0
- package/lib/relay/status.js +3 -0
- package/lib/routes/control-plane.js +54 -1
- package/lib/routes/mobile-api.js +11 -2
- package/lib/shell/updater.js +13 -8
- package/lib/update-install.cjs +43 -12
- package/package.json +1 -1
package/lib/update-install.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** 更新后核对插件依赖,失败时通过原包管理器恢复上一版完整安装。 */
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -11,6 +12,7 @@ const fs = require('node:fs');
|
|
|
11
12
|
const os = require('node:os');
|
|
12
13
|
const path = require('node:path');
|
|
13
14
|
const { spawn } = require('node:child_process');
|
|
15
|
+
const { createRequire } = require('node:module');
|
|
14
16
|
|
|
15
17
|
const { checkForUpdate } = require('./update-registry.cjs');
|
|
16
18
|
|
|
@@ -204,6 +206,22 @@ function installedVersion(profileNodeModules, name = DEFAULT_NAME) {
|
|
|
204
206
|
}
|
|
205
207
|
}
|
|
206
208
|
|
|
209
|
+
/** 版本与必需依赖均能从插件目录解析,才是一份完整安装;不执行插件或依赖代码。 */
|
|
210
|
+
function installationProblem(profileNodeModules, name, version) {
|
|
211
|
+
const file = path.join(profileNodeModules, name, 'package.json');
|
|
212
|
+
try {
|
|
213
|
+
const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
214
|
+
if (pkg.version !== version) return `预期 ${version},盘上是 ${pkg.version ?? '未知版本'}`;
|
|
215
|
+
const fromPlugin = createRequire(fs.realpathSync(file));
|
|
216
|
+
for (const dependency of Object.keys(pkg.dependencies || {})) {
|
|
217
|
+
fs.accessSync(fromPlugin.resolve(dependency));
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
return String(error.message || error);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
207
225
|
/**
|
|
208
226
|
* 这次装完后,插件「按当前平台装上的」可选依赖(例如 tailcat 平台包)各自的实际版本。
|
|
209
227
|
*
|
|
@@ -664,6 +682,7 @@ async function installLatest({
|
|
|
664
682
|
);
|
|
665
683
|
}
|
|
666
684
|
|
|
685
|
+
const previousComplete = beforeVersion !== null && installationProblem(profileNodeModules, name, beforeVersion) === null;
|
|
667
686
|
// 备份正在跑的那一代:包的活就落在下面那一行 spawn 上,它一跑旧目录就没了。
|
|
668
687
|
// 备份失败不该挡住更新(那是多一层保险),所以这里吞掉它的异常,由调用方记日志。
|
|
669
688
|
if (typeof beforeInstall === 'function') {
|
|
@@ -672,13 +691,13 @@ async function installLatest({
|
|
|
672
691
|
} catch { /* 备份失败不挡更新 */ }
|
|
673
692
|
}
|
|
674
693
|
|
|
675
|
-
const spec = `${name}@${version}`;
|
|
676
694
|
// 一律带上:自动更新是「一检测到就装」,手动点的那一下同样是「现在就要」,没理由先让这道
|
|
677
695
|
// 策略挡一次、再靠失败重试绕过来。命令行与环境变量各带一份,pnpm 12 只认后者(见 POLICY_ENV)。
|
|
678
696
|
const policyArgs = ['--config.auto-install-peers=false', '--config.minimum-release-age=0', '--config.ignore-workspace-root-check=true'];
|
|
679
|
-
const
|
|
680
|
-
? ['add',
|
|
681
|
-
: ['install',
|
|
697
|
+
const installArgs = (target) => picked.manager === 'pnpm'
|
|
698
|
+
? ['add', `${name}@${target}`, ...policyArgs]
|
|
699
|
+
: ['install', `${name}@${target}`, '--no-audit', '--no-fund'];
|
|
700
|
+
const args = installArgs(version);
|
|
682
701
|
const command = [picked.manager, ...args].join(' ');
|
|
683
702
|
onEvent({ phase: 'install-started', command, manager: picked.kind });
|
|
684
703
|
|
|
@@ -724,8 +743,23 @@ async function installLatest({
|
|
|
724
743
|
}
|
|
725
744
|
}
|
|
726
745
|
}
|
|
727
|
-
|
|
728
|
-
|
|
746
|
+
let after = installedVersion(profileNodeModules, name);
|
|
747
|
+
const problem = result.ok && (after !== beforeVersion || after === version) ? installationProblem(profileNodeModules, name, version) : null;
|
|
748
|
+
if (!result.ok || problem) {
|
|
749
|
+
let message = result.ok
|
|
750
|
+
? `安装 ${version} 不完整:${problem}`
|
|
751
|
+
: withReason(`${command} ${result.code === null ? '没能跑完' : `退出码 ${result.code}`}${result.error ? `:${result.error}` : ''}`, output);
|
|
752
|
+
let rollback = null;
|
|
753
|
+
// 只有更新破坏了原本完整的安装才重新装旧版;依赖和锁文件都交给同一个包管理器恢复。
|
|
754
|
+
if (previousComplete && installationProblem(profileNodeModules, name, beforeVersion)) {
|
|
755
|
+
onEvent({ phase: 'rollback-started', version: beforeVersion });
|
|
756
|
+
const restored = await runManager(['--force'], installArgs(beforeVersion));
|
|
757
|
+
const restoreProblem = installationProblem(profileNodeModules, name, beforeVersion);
|
|
758
|
+
after = installedVersion(profileNodeModules, name);
|
|
759
|
+
rollback = { ok: restored.ok && !restoreProblem, toVersion: beforeVersion, installedVersion: after };
|
|
760
|
+
output += `\n--- 恢复 ${beforeVersion} ---\n${restored.output}`;
|
|
761
|
+
message += rollback.ok ? `;已恢复 ${beforeVersion}` : `;恢复 ${beforeVersion} 失败:${restoreProblem || restored.error || restored.output}`;
|
|
762
|
+
}
|
|
729
763
|
return {
|
|
730
764
|
installed: false,
|
|
731
765
|
skipped: false,
|
|
@@ -737,13 +771,10 @@ async function installLatest({
|
|
|
737
771
|
healed,
|
|
738
772
|
releaseAgeRecorded: false,
|
|
739
773
|
output,
|
|
740
|
-
|
|
774
|
+
rollback,
|
|
741
775
|
failure: {
|
|
742
|
-
code: result.code === null ? 'INSTALL_ABORTED' : 'INSTALL_FAILED',
|
|
743
|
-
message
|
|
744
|
-
`${command} ${result.code === null ? '没能跑完' : `退出码 ${result.code}`}${result.error ? `:${result.error}` : ''}`,
|
|
745
|
-
output,
|
|
746
|
-
),
|
|
776
|
+
code: result.ok ? 'INSTALL_INCOMPLETE' : result.code === null ? 'INSTALL_ABORTED' : 'INSTALL_FAILED',
|
|
777
|
+
message,
|
|
747
778
|
},
|
|
748
779
|
};
|
|
749
780
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mobile-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.65",
|
|
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",
|