napcat-plugin-debug-cli 1.2.0 → 1.2.2
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/cli.mjs +16 -4
- package/package.json +1 -1
- package/vite.mjs +15 -5
package/cli.mjs
CHANGED
|
@@ -5183,11 +5183,18 @@ function createWatcher(watchPath, onPluginChange) {
|
|
|
5183
5183
|
}
|
|
5184
5184
|
active = true;
|
|
5185
5185
|
if (fs.existsSync(path.join(watchPath, "package.json"))) {
|
|
5186
|
-
|
|
5187
|
-
|
|
5186
|
+
const baseName = path.basename(watchPath);
|
|
5187
|
+
if (baseName === "napcat-plugin-debug") {
|
|
5188
|
+
logWarn("跳过 napcat-plugin-debug 自身,不能监听自我重载");
|
|
5189
|
+
} else {
|
|
5190
|
+
watchDir(baseName, watchPath);
|
|
5191
|
+
logHmr(`监听插件: ${baseName}`);
|
|
5192
|
+
}
|
|
5188
5193
|
} else {
|
|
5189
5194
|
for (const d of fs.readdirSync(watchPath, { withFileTypes: true })) {
|
|
5190
|
-
if (d.isDirectory()
|
|
5195
|
+
if (d.isDirectory() && d.name !== "napcat-plugin-debug") {
|
|
5196
|
+
watchDir(d.name, path.join(watchPath, d.name));
|
|
5197
|
+
}
|
|
5191
5198
|
}
|
|
5192
5199
|
logHmr(`监听 ${watchers.size} 个插件: ${watchPath}`);
|
|
5193
5200
|
}
|
|
@@ -5265,7 +5272,12 @@ async function deployPlugin(projectDir, remotePluginPath, rpc) {
|
|
|
5265
5272
|
} catch {
|
|
5266
5273
|
try {
|
|
5267
5274
|
logInfo("插件未注册,尝试从目录加载...");
|
|
5268
|
-
await rpc.call("loadDirectoryPlugin",
|
|
5275
|
+
await rpc.call("loadDirectoryPlugin", pluginName);
|
|
5276
|
+
try {
|
|
5277
|
+
await rpc.call("setPluginStatus", pluginName, true);
|
|
5278
|
+
await rpc.call("loadPluginById", pluginName);
|
|
5279
|
+
} catch {
|
|
5280
|
+
}
|
|
5269
5281
|
logOk(`${co(pluginName, C.green, C.bold)} 首次加载成功`);
|
|
5270
5282
|
} catch (e2) {
|
|
5271
5283
|
logWarn(`自动加载失败: ${e2.message},请手动 load ${pluginName}`);
|
package/package.json
CHANGED
package/vite.mjs
CHANGED
|
@@ -16,9 +16,9 @@ const C = {
|
|
|
16
16
|
const co = (t, ...c) => c.join("") + t + C.reset;
|
|
17
17
|
const PREFIX = co("[napcat-hmr]", C.magenta, C.bold);
|
|
18
18
|
const log = (m) => console.log(`${PREFIX} ${m}`);
|
|
19
|
-
const logOk = (m) => console.log(`${PREFIX} ${co("
|
|
20
|
-
const logErr = (m) => console.log(`${PREFIX} ${co("
|
|
21
|
-
const logHmr = (m) => console.log(`${PREFIX} ${co("
|
|
19
|
+
const logOk = (m) => console.log(`${PREFIX} ${co("(o'v'o)", C.green)} ${m}`);
|
|
20
|
+
const logErr = (m) => console.log(`${PREFIX} ${co("(;_;)", C.red)} ${m}`);
|
|
21
|
+
const logHmr = (m) => console.log(`${PREFIX} ${co("(><)", C.yellow)} ${co(m, C.magenta)}`);
|
|
22
22
|
class SimpleRpcClient {
|
|
23
23
|
ws;
|
|
24
24
|
nextId = 1;
|
|
@@ -98,6 +98,8 @@ function napcatHmrPlugin(options = {}) {
|
|
|
98
98
|
if (connecting) return false;
|
|
99
99
|
connecting = true;
|
|
100
100
|
try {
|
|
101
|
+
process.env.WS_NO_BUFFER_UTIL = "1";
|
|
102
|
+
process.env.WS_NO_UTF_8_VALIDATE = "1";
|
|
101
103
|
const { default: WebSocket } = await import('ws');
|
|
102
104
|
let url = wsUrl;
|
|
103
105
|
if (token) {
|
|
@@ -182,11 +184,19 @@ function napcatHmrPlugin(options = {}) {
|
|
|
182
184
|
return;
|
|
183
185
|
}
|
|
184
186
|
try {
|
|
185
|
-
await rpc.call("reloadPlugin", pluginName);
|
|
187
|
+
const reloaded = await rpc.call("reloadPlugin", pluginName);
|
|
188
|
+
if (reloaded === false) {
|
|
189
|
+
throw new Error("not registered");
|
|
190
|
+
}
|
|
186
191
|
logHmr(`${co(pluginName, C.green, C.bold)} 已重载 (${countFiles(distDir)} 个文件)`);
|
|
187
192
|
} catch {
|
|
188
193
|
try {
|
|
189
|
-
await rpc.call("loadDirectoryPlugin",
|
|
194
|
+
await rpc.call("loadDirectoryPlugin", pluginName);
|
|
195
|
+
try {
|
|
196
|
+
await rpc.call("setPluginStatus", pluginName, true);
|
|
197
|
+
await rpc.call("loadPluginById", pluginName);
|
|
198
|
+
} catch {
|
|
199
|
+
}
|
|
190
200
|
logOk(`${co(pluginName, C.green, C.bold)} 首次加载成功`);
|
|
191
201
|
} catch (e2) {
|
|
192
202
|
logErr(`加载失败: ${e2.message}`);
|