@koishi-ce/plugin-market 1.0.5 → 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 +3 -32
- package/package.json +85 -85
- package/src/__tests__/index.test.ts +2 -3
- package/src/node/installer.ts +5 -35
package/lib/index.mjs
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import {
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
3
|
import { Logger, Schema, Service, Time, defineProperty, pick, sleep, valueMap } from "@koishi-ce/koishi";
|
|
4
4
|
import { compare, gt, satisfies, valid } from "semver";
|
|
5
5
|
import { DataService } from "@koishi-ce/console";
|
|
6
|
-
import { readFileSync
|
|
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) {
|
|
@@ -86,32 +83,6 @@ function loadManifest(name) {
|
|
|
86
83
|
defineProperty(meta, "$workspace", !filename.includes("node_modules"));
|
|
87
84
|
return meta;
|
|
88
85
|
}
|
|
89
|
-
/** 缓存键归一(win32 大小写不敏感),对齐 require.cache 键与探测路径的比对 */
|
|
90
|
-
function normalizeCacheKey(path) {
|
|
91
|
-
return process.platform === "win32" ? path.toLowerCase() : path;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* 判断某依赖包是否有模块驻留在 require.cache(旧版本仍在内存)。
|
|
95
|
-
*
|
|
96
|
-
* 原上游实现用 require.resolve(name)(FIXME koishijs/webui#273 的报错
|
|
97
|
-
* 源):安装流程在包落盘前的探测已把该裸名记入 Bun 的进程内解析负缓
|
|
98
|
-
* 存,装完后同进程内必然抛 ResolveMessage。改为经 resolvePackageJson
|
|
99
|
-
* (fs 探测兜底)取包目录后扫 require.cache 前缀;任何环节失败都保守
|
|
100
|
-
* 返回 true——多一次重载只是进程重启,漏判才会让旧版本代码继续驻留。
|
|
101
|
-
*/
|
|
102
|
-
function isResidentInCache(name) {
|
|
103
|
-
try {
|
|
104
|
-
const dir = dirname(resolvePackageJson(name));
|
|
105
|
-
const prefixes = [normalizeCacheKey(dir + sep)];
|
|
106
|
-
try {
|
|
107
|
-
const real = realpathSync(dir);
|
|
108
|
-
if (real !== dir) prefixes.push(normalizeCacheKey(real + sep));
|
|
109
|
-
} catch {}
|
|
110
|
-
return Object.keys(__require.cache).some((key) => prefixes.some((prefix) => normalizeCacheKey(key).startsWith(prefix)));
|
|
111
|
-
} catch {
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
86
|
function getVersions(versions) {
|
|
116
87
|
return Object.fromEntries(versions.map((item) => [item.version, pick(item, [
|
|
117
88
|
"peerDependencies",
|
package/package.json
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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,10 +58,9 @@ 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
|
-
const { default: Installer
|
|
63
|
-
"../node/installer.ts"
|
|
64
|
-
);
|
|
63
|
+
const { default: Installer } = await import("../node/installer.ts");
|
|
65
64
|
const mockPlugin = (await import("@koishi-ce/plugin-mock")).default;
|
|
66
65
|
// 加载包入口占位文件(纯 re-export,无独立逻辑),保证 src 全量被加载
|
|
67
66
|
await import("../index.ts");
|
package/src/node/installer.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { readFileSync
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import {
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
5
|
import type {} from "@koishi-ce/console";
|
|
6
6
|
import {
|
|
7
7
|
type Context,
|
|
@@ -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
|
-
//
|
|
133
|
-
//
|
|
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 ||= {};
|
|
@@ -138,37 +139,6 @@ export function loadManifest(name: string) {
|
|
|
138
139
|
return meta;
|
|
139
140
|
}
|
|
140
141
|
|
|
141
|
-
/** 缓存键归一(win32 大小写不敏感),对齐 require.cache 键与探测路径的比对 */
|
|
142
|
-
function normalizeCacheKey(path: string): string {
|
|
143
|
-
return process.platform === "win32" ? path.toLowerCase() : path;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* 判断某依赖包是否有模块驻留在 require.cache(旧版本仍在内存)。
|
|
148
|
-
*
|
|
149
|
-
* 原上游实现用 require.resolve(name)(FIXME koishijs/webui#273 的报错
|
|
150
|
-
* 源):安装流程在包落盘前的探测已把该裸名记入 Bun 的进程内解析负缓
|
|
151
|
-
* 存,装完后同进程内必然抛 ResolveMessage。改为经 resolvePackageJson
|
|
152
|
-
* (fs 探测兜底)取包目录后扫 require.cache 前缀;任何环节失败都保守
|
|
153
|
-
* 返回 true——多一次重载只是进程重启,漏判才会让旧版本代码继续驻留。
|
|
154
|
-
*/
|
|
155
|
-
export function isResidentInCache(name: string): boolean {
|
|
156
|
-
try {
|
|
157
|
-
const dir = dirname(resolvePackageJson(name));
|
|
158
|
-
const prefixes = [normalizeCacheKey(dir + sep)];
|
|
159
|
-
// 符号链接布局下缓存键可能是 realpath 形态,两种前缀都查
|
|
160
|
-
try {
|
|
161
|
-
const real = realpathSync(dir);
|
|
162
|
-
if (real !== dir) prefixes.push(normalizeCacheKey(real + sep));
|
|
163
|
-
} catch {}
|
|
164
|
-
return Object.keys(require.cache).some((key) =>
|
|
165
|
-
prefixes.some((prefix) => normalizeCacheKey(key).startsWith(prefix)),
|
|
166
|
-
);
|
|
167
|
-
} catch {
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
142
|
function getVersions(versions: RemotePackage[]) {
|
|
173
143
|
return Object.fromEntries(
|
|
174
144
|
versions
|