napcat-plugin-debug-cli 1.2.0 → 1.2.1

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.
Files changed (3) hide show
  1. package/cli.mjs +10 -3
  2. package/package.json +1 -1
  3. package/vite.mjs +14 -4
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
- watchDir(path.basename(watchPath), watchPath);
5187
- logHmr(`监听插件: ${path.basename(watchPath)}`);
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()) watchDir(d.name, path.join(watchPath, d.name));
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "napcat-plugin-debug-cli",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "description": "NapCat 插件调试 CLI — 连接调试服务实现热重载",
6
6
  "author": "NapNeko",
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("", C.green)} ${m}`);
20
- const logErr = (m) => console.log(`${PREFIX} ${co("", C.red)} ${m}`);
21
- const logHmr = (m) => console.log(`${PREFIX} ${co("🔥", C.magenta)} ${co(m, C.magenta)}`);
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
194
  await rpc.call("loadDirectoryPlugin", destDir);
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}`);