dsh-deepseek-balance-widget 1.2.2 → 1.2.3
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/index.js +34 -8
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { dirname, resolve } from "node:path";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
@@ -101,17 +101,43 @@ async function queryNpmVersion() {
|
|
|
101
101
|
return { ok: true, local: LOCAL_VERSION, latest, updateAvailable };
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/** @returns {Promise<boolean>} whether the given path exists. */
|
|
105
|
+
async function fileExists(path) {
|
|
106
|
+
try {
|
|
107
|
+
await stat(path);
|
|
108
|
+
return true;
|
|
109
|
+
} catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Detect the package manager used by UPDATE_CWD.
|
|
116
|
+
* @returns {Promise<"pnpm" | "npm">}
|
|
117
|
+
*/
|
|
118
|
+
async function detectPackageManager() {
|
|
119
|
+
const pnpmLock = resolve(UPDATE_CWD, "pnpm-lock.yaml");
|
|
120
|
+
const pnpmLockYml = resolve(UPDATE_CWD, "pnpm-lock.yml");
|
|
121
|
+
if (await fileExists(pnpmLock) || await fileExists(pnpmLockYml)) return "pnpm";
|
|
122
|
+
return "npm";
|
|
123
|
+
}
|
|
124
|
+
|
|
104
125
|
/**
|
|
105
|
-
* Run
|
|
126
|
+
* Run the package-manager update command for this package in the discovered project root.
|
|
127
|
+
* Uses shell mode on Windows so that .cmd scripts (npm.cmd / pnpm.cmd) can actually spawn.
|
|
106
128
|
* @returns {Promise<{ok:boolean, output:string, error?:string}>}
|
|
107
129
|
*/
|
|
108
|
-
async function
|
|
109
|
-
const
|
|
110
|
-
const
|
|
130
|
+
async function runPackageUpdate() {
|
|
131
|
+
const pm = await detectPackageManager();
|
|
132
|
+
const isWin = process.platform === "win32";
|
|
133
|
+
const cmd = isWin ? (pm === "pnpm" ? "pnpm.cmd" : "npm.cmd") : pm;
|
|
134
|
+
const args = pm === "pnpm"
|
|
135
|
+
? ["add", "dsh-deepseek-balance-widget@latest"]
|
|
136
|
+
: ["install", "dsh-deepseek-balance-widget@latest"];
|
|
111
137
|
return new Promise((resolve) => {
|
|
112
138
|
const child = spawn(cmd, args, {
|
|
113
139
|
cwd: UPDATE_CWD,
|
|
114
|
-
shell:
|
|
140
|
+
shell: isWin,
|
|
115
141
|
env: { ...process.env, NPM_CONFIG_FUND: "false", NPM_CONFIG_AUDIT: "false" }
|
|
116
142
|
});
|
|
117
143
|
let stdout = "";
|
|
@@ -126,7 +152,7 @@ async function runNpmUpdate() {
|
|
|
126
152
|
if (code === 0) {
|
|
127
153
|
resolve({ ok: true, output: output.slice(-800) });
|
|
128
154
|
} else {
|
|
129
|
-
resolve({ ok: false, output, error:
|
|
155
|
+
resolve({ ok: false, output, error: `${pm} ${args.join(" ")} exited with code ${code}` });
|
|
130
156
|
}
|
|
131
157
|
});
|
|
132
158
|
});
|
|
@@ -533,7 +559,7 @@ function apply(ctx) {
|
|
|
533
559
|
res.end(JSON.stringify({ ok: true, noOp: true, local: before.local, latest: before.latest, message: "已是最新版本" }));
|
|
534
560
|
return;
|
|
535
561
|
}
|
|
536
|
-
const result = await
|
|
562
|
+
const result = await runPackageUpdate();
|
|
537
563
|
if (result.ok) {
|
|
538
564
|
res.writeHead(200, { "content-type": "application/json; charset=utf-8" });
|
|
539
565
|
res.end(JSON.stringify({ ok: true, message: "更新成功,请彻底重启 dsh 以加载新版本", output: result.output }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-deepseek-balance-widget",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "DeepSeek API balance widget for the dsh web sidebar: a live, auto-refreshing balance pill (balance / today spend / today tokens) with a detail popover (cumulative spend, monthly usage, request count). Every user sees only their own balance — keys are resolved per-machine from the local credential seam, never hardcoded.",
|
|
6
6
|
"keywords": [
|