@koishi-ce/plugin-market 1.0.4 → 1.0.6

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.mjs CHANGED
@@ -5,14 +5,11 @@ import { compare, gt, satisfies, valid } from "semver";
5
5
  import { DataService } from "@koishi-ce/console";
6
6
  import { readFileSync } from "node:fs";
7
7
  import { homedir } from "node:os";
8
- import Scanner, { resolvePackageJson } from "@koishi-ce/registry";
8
+ import Scanner, { isResidentInCache, resolvePackageJson } from "@koishi-ce/registry";
9
9
  import spawn from "execa";
10
10
  import pMap from "p-map";
11
11
  import messageZhCN from "./assets/message.zh-CN-B_nH77kB.yml";
12
12
  import schemaZhCN from "./assets/schema.zh-CN-CLU01Lrj.yml";
13
- //#region \0rolldown/runtime.js
14
- var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
15
- //#endregion
16
13
  //#region src/node/deps.ts
17
14
  var DependencyProvider = class extends DataService {
18
15
  constructor(ctx) {
@@ -284,12 +281,7 @@ var Installer = class extends Service {
284
281
  const newDep = newDeps[name];
285
282
  if (!local || !newDep || local.workspace) continue;
286
283
  if (newDep.resolved === local.resolved) continue;
287
- try {
288
- if (!(__require.resolve(name) in __require.cache)) continue;
289
- } catch (error) {
290
- logger$2.error(error);
291
- }
292
- this.ctx.loader.fullReload();
284
+ if (isResidentInCache(name)) this.ctx.loader.fullReload();
293
285
  }
294
286
  this.refreshData();
295
287
  return 0;
package/package.json CHANGED
@@ -1,87 +1,87 @@
1
1
  {
2
- "name": "@koishi-ce/plugin-market",
3
- "description": "Manage your bots and plugins with console",
4
- "version": "1.0.4",
5
- "type": "module",
6
- "main": "lib/index.mjs",
7
- "typings": "lib/index.d.ts",
8
- "files": [
9
- "lib",
10
- "dist",
11
- "src"
12
- ],
13
- "contributors": [
14
- "Shigma <shigma10826@gmail.com>",
15
- "Oppenheymu <oppenheymu@gmail.com>"
16
- ],
17
- "license": "AGPL-3.0",
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/Koishi-CE/koishi.git",
21
- "directory": "plugins/webui/market"
22
- },
23
- "bugs": {
24
- "url": "https://github.com/Koishi-CE/koishi/issues"
25
- },
26
- "homepage": "https://koishi.chat/plugins/console/market.html",
27
- "keywords": [
28
- "bot",
29
- "chatbot",
30
- "koishi",
31
- "plugin",
32
- "market",
33
- "manager",
34
- "server"
35
- ],
36
- "koishi": {
37
- "public": [
38
- "dist"
39
- ],
40
- "description": {
41
- "en": "Manage your plugins with console",
42
- "zh": "使用控制台安装、卸载、更新你的插件"
43
- },
44
- "service": {
45
- "optional": [
46
- "console"
47
- ],
48
- "implements": [
49
- "installer"
50
- ]
51
- }
52
- },
53
- "peerDependencies": {
54
- "@koishijs/plugin-console": "^5.30.11",
55
- "koishi": "^4.18.11"
56
- },
57
- "peerDependenciesMeta": {
58
- "@koishijs/plugin-console": {
59
- "optional": true
60
- }
61
- },
62
- "devDependencies": {
63
- "@koishi-ce/client": "^1.0.1",
64
- "@koishi-ce/loader": "^1.0.1",
65
- "@koishi-ce/plugin-config": "^1.0.3",
66
- "@koishijs/market": "^4.2.10",
67
- "@types/semver": "^7.5.8",
68
- "vue": "^3.5.12"
69
- },
70
- "dependencies": {
71
- "@koishi-ce/console": "^1.0.0",
72
- "@koishi-ce/registry": "^1.0.3",
73
- "execa": "^5.1.1",
74
- "p-map": "^4.0.0",
75
- "semver": "^7.6.3",
76
- "which-pm-runs": "^1.1.0"
77
- },
78
- "exports": {
79
- ".": {
80
- "source": "./src/index.ts",
81
- "types": "./lib/index.d.ts",
82
- "import": "./lib/index.mjs",
83
- "default": "./lib/index.mjs"
84
- },
85
- "./package.json": "./package.json"
86
- }
2
+ "name": "@koishi-ce/plugin-market",
3
+ "description": "Manage your bots and plugins with console",
4
+ "version": "1.0.6",
5
+ "type": "module",
6
+ "main": "lib/index.mjs",
7
+ "typings": "lib/index.d.ts",
8
+ "files": [
9
+ "lib",
10
+ "dist",
11
+ "src"
12
+ ],
13
+ "contributors": [
14
+ "Shigma <shigma10826@gmail.com>",
15
+ "Oppenheymu <oppenheymu@gmail.com>"
16
+ ],
17
+ "license": "AGPL-3.0",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/Koishi-CE/koishi.git",
21
+ "directory": "plugins/webui/market"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/Koishi-CE/koishi/issues"
25
+ },
26
+ "homepage": "https://koishi.chat/plugins/console/market.html",
27
+ "keywords": [
28
+ "bot",
29
+ "chatbot",
30
+ "koishi",
31
+ "plugin",
32
+ "market",
33
+ "manager",
34
+ "server"
35
+ ],
36
+ "koishi": {
37
+ "public": [
38
+ "dist"
39
+ ],
40
+ "description": {
41
+ "en": "Manage your plugins with console",
42
+ "zh": "使用控制台安装、卸载、更新你的插件"
43
+ },
44
+ "service": {
45
+ "optional": [
46
+ "console"
47
+ ],
48
+ "implements": [
49
+ "installer"
50
+ ]
51
+ }
52
+ },
53
+ "peerDependencies": {
54
+ "@koishijs/plugin-console": "^5.30.11",
55
+ "koishi": "^4.18.11"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "@koishijs/plugin-console": {
59
+ "optional": true
60
+ }
61
+ },
62
+ "devDependencies": {
63
+ "@koishi-ce/client": "workspace:*",
64
+ "@koishi-ce/loader": "workspace:*",
65
+ "@koishi-ce/plugin-config": "workspace:*",
66
+ "@koishijs/market": "^4.2.10",
67
+ "@types/semver": "^7.5.8",
68
+ "vue": "^3.5.12"
69
+ },
70
+ "dependencies": {
71
+ "@koishi-ce/console": "workspace:*",
72
+ "@koishi-ce/registry": "workspace:*",
73
+ "execa": "^5.1.1",
74
+ "p-map": "^4.0.0",
75
+ "semver": "^7.6.3",
76
+ "which-pm-runs": "^1.1.0"
77
+ },
78
+ "exports": {
79
+ ".": {
80
+ "source": "./src/index.ts",
81
+ "types": "./lib/index.d.ts",
82
+ "import": "./lib/index.mjs",
83
+ "default": "./lib/index.mjs"
84
+ },
85
+ "./package.json": "./package.json"
86
+ }
87
87
  }
@@ -58,6 +58,7 @@ import type { RemotePackage } from "@koishi-ce/registry";
58
58
  const { Console } = await import("@koishi-ce/console");
59
59
  const { App, Service } = await import("@koishi-ce/koishi");
60
60
  const http = (await import("@koishi-ce/plugin-http")).default;
61
+ const { isResidentInCache } = await import("@koishi-ce/registry");
61
62
  const market = await import("../node/index.ts");
62
63
  const { default: Installer } = await import("../node/installer.ts");
63
64
  const mockPlugin = (await import("@koishi-ce/plugin-mock")).default;
@@ -331,6 +332,36 @@ describe("Installer 安装链路", () => {
331
332
  });
332
333
  });
333
334
 
335
+ describe("isResidentInCache(装后重载判定)", () => {
336
+ /** 在临时 node_modules 放一个已安装包,返回其目录 */
337
+ function placePkg(name: string) {
338
+ const pkgDir = join(tmp, "node_modules", name);
339
+ mkdirSync(pkgDir, { recursive: true });
340
+ writeFileSync(
341
+ join(pkgDir, "package.json"),
342
+ JSON.stringify({ name, version: "1.0.0", main: "index.js" }),
343
+ );
344
+ writeFileSync(join(pkgDir, "index.js"), "module.exports = {}");
345
+ return pkgDir;
346
+ }
347
+
348
+ it("包目录下有模块驻留 require.cache 时返回 true", () => {
349
+ const pkgDir = placePkg("koishi-plugin-resident-check");
350
+ // 入口经 require 进入 require.cache,模拟旧版本驻留内存
351
+ require(join(pkgDir, "index.js"));
352
+ expect(isResidentInCache("koishi-plugin-resident-check")).toBe(true);
353
+ });
354
+
355
+ it("已安装但无模块驻留内存时返回 false", () => {
356
+ placePkg("koishi-plugin-idle-check");
357
+ expect(isResidentInCache("koishi-plugin-idle-check")).toBe(false);
358
+ });
359
+
360
+ it("包不存在时保守返回 true(宁可多重载不漏判)", () => {
361
+ expect(isResidentInCache("koishi-plugin-absent-check")).toBe(true);
362
+ });
363
+ });
364
+
334
365
  describe("registry 配置探测", () => {
335
366
  it("无显式 endpoint 时按 npmrc / 环境变量探测", async () => {
336
367
  // 环境变量优先:npm_config_registry 指向本地服务
@@ -19,6 +19,7 @@ import type {} from "@koishi-ce/loader";
19
19
  import type {} from "@koishi-ce/plugin-market";
20
20
  import Scanner, {
21
21
  type DependencyMetaKey,
22
+ isResidentInCache,
22
23
  type PackageJson,
23
24
  type Registry,
24
25
  type RemotePackage,
@@ -129,8 +130,8 @@ export interface LocalPackage extends PackageJson {
129
130
  }
130
131
 
131
132
  export function loadManifest(name: string) {
132
- // resolvePackageJson 兜底:安装前对 `pkg/package.json` 形态的
133
- // 探测会被 Bun 记入进程内负缓存,装完后主路径仍解析失败
133
+ // resolvePackageJson 以纯 fs 探测为主路径:市场安装流程在包落盘前的
134
+ // 探测不能触碰解析 API,否则触发 Bun 的父目录快照缓存(装完即失败)
134
135
  const filename = resolvePackageJson(name);
135
136
  const meta: LocalPackage = JSON.parse(readFileSync(filename, "utf8"));
136
137
  meta.dependencies ||= {};
@@ -418,14 +419,9 @@ class Installer extends Service {
418
419
  const newDep = newDeps[name];
419
420
  if (!local || !newDep || local.workspace) continue;
420
421
  if (newDep.resolved === local.resolved) continue;
421
- try {
422
- if (!(require.resolve(name) in require.cache)) continue;
423
- } catch (error) {
424
- // FIXME https://github.com/koishijs/webui/issues/273
425
- // I have no idea why this happens and how to fix it.
426
- logger.error(error);
427
- }
428
- this.ctx.loader.fullReload();
422
+ // 版本变化且旧版本仍驻留内存时才需要整进程重载(判定不走
423
+ // 解析 API,规避 Bun 负缓存,见 isResidentInCache)
424
+ if (isResidentInCache(name)) this.ctx.loader.fullReload();
429
425
  }
430
426
  this.refreshData();
431
427