@michengai/dsh-codex-ui 0.2.53 → 0.2.54
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/dist/index.d.mts +3 -1
- package/dist/index.mjs +20 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -12,8 +12,10 @@ type HostRequest = {
|
|
|
12
12
|
* 非浏览器客户端(curl、CLI)仍然放行。
|
|
13
13
|
*/
|
|
14
14
|
declare function crossSiteRequest(request: HostRequest): boolean;
|
|
15
|
+
/** 把安装错误收成可给浏览器看的文案:我们自己的中文说明保留,带本地路径的底层错误脱敏。 */
|
|
16
|
+
declare function publicDependencyError(error: unknown): string;
|
|
15
17
|
declare const inject: string[];
|
|
16
18
|
/** 提供不泄露地址、命令和凭证的连接器目录。 */
|
|
17
19
|
declare function apply(ctx: Context): void;
|
|
18
20
|
//#endregion
|
|
19
|
-
export { apply, crossSiteRequest, inject };
|
|
21
|
+
export { apply, crossSiteRequest, inject, publicDependencyError };
|
package/dist/index.mjs
CHANGED
|
@@ -169,6 +169,7 @@ function pluginCommandError(stderr) {
|
|
|
169
169
|
const detail = stderr.replace(/\s+/g, " ").trim();
|
|
170
170
|
if (detail.includes("minimumReleaseAge") || detail.includes("Release age")) return /* @__PURE__ */ new Error("更新被 pnpm 发布时间保护拦截。请确认已写入当前版本白名单后重试。");
|
|
171
171
|
if (detail.includes("EPERM") || detail.includes("EBUSY") || detail.includes("EACCES")) return /* @__PURE__ */ new Error("无法覆盖正在运行的插件文件。请先停止 DSH Web,再点击更新。");
|
|
172
|
+
if (detail.includes("NO_MATCHING_VERSION") || detail.includes("No matching version")) return /* @__PURE__ */ new Error("当前 npm 镜像还没有这个版本。请稍后重试,或改用官方源安装。");
|
|
172
173
|
return /* @__PURE__ */ new Error("从 npm 安装或更新依赖失败。请检查网络、npm registry 或发布时间保护后重试。");
|
|
173
174
|
}
|
|
174
175
|
/**
|
|
@@ -228,7 +229,11 @@ async function installDependencyLocked(id) {
|
|
|
228
229
|
const latestVersion = await npmLatestVersion(dependency.packageName);
|
|
229
230
|
if (latestVersion === void 0) throw new Error("无法获取 npm 最新版本,请检查网络或 npm registry 后重试。");
|
|
230
231
|
await ensureLatestReleaseAllowed(dependency.packageName, latestVersion);
|
|
231
|
-
await runDshPlugin([
|
|
232
|
+
await runDshPlugin([
|
|
233
|
+
"add",
|
|
234
|
+
`${dependency.packageName}@${latestVersion}`,
|
|
235
|
+
"--registry=https://registry.npmjs.org/"
|
|
236
|
+
]);
|
|
232
237
|
const installed = await installedPackageVersion(dependency.packageName);
|
|
233
238
|
if (installed !== latestVersion) throw new Error(`已请求 ${dependency.packageName}@${latestVersion},但当前仍是 ${installed ?? "未安装"}。请先停止 DSH Web 后再更新。`);
|
|
234
239
|
return dependencyStatuses();
|
|
@@ -272,7 +277,18 @@ function crossSiteRequest(request) {
|
|
|
272
277
|
const origin = headerValue(headers, "origin");
|
|
273
278
|
if (origin === void 0) return false;
|
|
274
279
|
const host = headerValue(headers, "host");
|
|
275
|
-
|
|
280
|
+
if (host === void 0) return true;
|
|
281
|
+
try {
|
|
282
|
+
return new URL(origin).host !== host;
|
|
283
|
+
} catch {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/** 把安装错误收成可给浏览器看的文案:我们自己的中文说明保留,带本地路径的底层错误脱敏。 */
|
|
288
|
+
function publicDependencyError(error) {
|
|
289
|
+
const message = error instanceof Error ? error.message : "依赖管理暂不可用。";
|
|
290
|
+
if (/[A-Za-z]:[\\/]|\/(?:home|Users|var|tmp)\//.test(message)) return "依赖管理暂不可用,请查看服务端日志。";
|
|
291
|
+
return message;
|
|
276
292
|
}
|
|
277
293
|
const inject = [
|
|
278
294
|
"webServer",
|
|
@@ -368,7 +384,7 @@ function apply(ctx) {
|
|
|
368
384
|
"content-type": "application/json; charset=utf-8",
|
|
369
385
|
"cache-control": "no-store"
|
|
370
386
|
});
|
|
371
|
-
response.end(JSON.stringify({ error:
|
|
387
|
+
response.end(JSON.stringify({ error: publicDependencyError(error) }));
|
|
372
388
|
}
|
|
373
389
|
}
|
|
374
390
|
});
|
|
@@ -379,4 +395,4 @@ function apply(ctx) {
|
|
|
379
395
|
}, "michengai-codex-ui: catalogs");
|
|
380
396
|
}
|
|
381
397
|
//#endregion
|
|
382
|
-
export { apply, crossSiteRequest, inject };
|
|
398
|
+
export { apply, crossSiteRequest, inject, publicDependencyError };
|