@koishi-ce/plugin-explorer 1.0.1 → 1.1.0

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.
@@ -0,0 +1,6 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
5
+ root: Stammverzeichnis des Explorers, standardmäßig der aktuelle Arbeitspfad.
6
+ ignored: Zu ignorierende Dateien oder Verzeichnisse. Unterstützt [Glob Patterns](https://github.com/micromatch/micromatch)-Syntax.
@@ -0,0 +1,6 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
5
+ root: Root directory of the explorer, defaults to the current working path.
6
+ ignored: Files or directories to ignore. Supports [Glob Patterns](https://github.com/micromatch/micromatch) syntax.
@@ -0,0 +1,6 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
5
+ root: Répertoire racine de l'explorateur, par défaut le répertoire de travail actuel.
6
+ ignored: Fichiers ou répertoires à ignorer. Prend en charge la syntaxe [Glob Patterns](https://github.com/micromatch/micromatch).
@@ -0,0 +1,6 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
5
+ root: エクスプローラーのルートディレクトリ。デフォルトは現在の作業パスです。
6
+ ignored: 除外するファイルまたはディレクトリ。[Glob Patterns](https://github.com/micromatch/micromatch) 記法に対応しています。
@@ -0,0 +1,6 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
5
+ root: Корневой каталог проводника, по умолчанию текущий рабочий путь.
6
+ ignored: Файлы или каталоги, которые следует игнорировать. Поддерживается синтаксис [Glob Patterns](https://github.com/micromatch/micromatch).
@@ -0,0 +1,6 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
5
+ root: 檔案總管的根目錄,預設為當前工作路徑。
6
+ ignored: 要忽略的檔案或目錄。支援 [Glob Patterns](https://github.com/micromatch/micromatch) 語法。
package/lib/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { DataService } from "@koishi-ce/console";
2
- import { Context, Dict, Schema } from "@koishi-ce/koishi";
2
+ import { Context, Schema } from "@koishi-ce/koishi";
3
3
  import { Tester } from "anymatch";
4
- import { FSWatcher } from "chokidar";
5
4
  //#region src/index.d.ts
6
5
  declare module "@koishi-ce/console" {
7
6
  namespace Console {
@@ -19,7 +18,7 @@ declare module "@koishi-ce/console" {
19
18
  }
20
19
  }
21
20
  /** explorer/read 事件返回给客户端的文件内容:base64 编码 + 探测出的元信息。 */
22
- interface File {
21
+ export interface File {
23
22
  /** 文件内容的 base64 编码(客户端用 Binary.fromBase64 解码) */
24
23
  base64: string;
25
24
  /** 由 file-type 从文件头字节探测出的 MIME 类型,识别为文本时不存在 */
@@ -28,7 +27,7 @@ interface File {
28
27
  encoding?: string;
29
28
  }
30
29
  /** 文件树节点:文件 / 目录 / 符号链接三类,由 traverse() 递归生成。 */
31
- interface Entry {
30
+ export interface Entry {
32
31
  type: "file" | "directory" | "symlink";
33
32
  /** 显示名(不含路径) */
34
33
  name: string;
@@ -57,14 +56,11 @@ interface Entry {
57
56
  declare class Explorer extends DataService<Entry[]> {
58
57
  static Config: Schema<Explorer.Config>;
59
58
  task: Promise<Entry[]>;
60
- /** 已创建的文件监视器集合(键为路径),stop() 时统一关闭 */
61
- watchers: Dict<FSWatcher>;
62
59
  /** 由 ignored 配置编译出的 anymatch 过滤器 */
63
60
  globFilter: Tester;
64
61
  /** 文件树的根目录(ctx.baseDir + 配置的 root 解析出的绝对路径) */
65
62
  root: string;
66
63
  constructor(ctx: Context, config: Explorer.Config);
67
- stop(): void;
68
64
  /**
69
65
  * 递归遍历目录,生成排序后的文件树。
70
66
  * 排序规则:目录排在最前,其余按名称字母序;被 globFilter
@@ -88,4 +84,4 @@ declare namespace Explorer {
88
84
  }
89
85
  }
90
86
  //#endregion
91
- export { Entry, File, Explorer as default };
87
+ export { Explorer as default };
package/lib/index.mjs CHANGED
@@ -5,7 +5,13 @@ import { Schema } from "@koishi-ce/koishi";
5
5
  import * as anymatchModule from "anymatch";
6
6
  import { detect } from "chardet";
7
7
  import { fileTypeFromBuffer } from "file-type";
8
+ import deDE from "./assets/de-DE-II4Ckgph.yml";
9
+ import enUS from "./assets/en-US-J6VOXFdn.yml";
10
+ import frFR from "./assets/fr-FR-9iD4s5Ik.yml";
11
+ import jaJP from "./assets/ja-JP-Bvregs-c.yml";
12
+ import ruRU from "./assets/ru-RU-BzXcpw8Q.yml";
8
13
  import zhCN from "./assets/zh-CN-X-yi2Y2F.yml";
14
+ import zhTW from "./assets/zh-TW-sNsmvdmi.yml";
9
15
  //#region src/index.ts
10
16
  /**
11
17
  * explorer 插件(服务端):网页文件管理器的 node 侧实现。
@@ -31,10 +37,16 @@ var Explorer = class extends DataService {
31
37
  "**/.*",
32
38
  "cache"
33
39
  ])
34
- }).i18n({ "zh-CN": zhCN });
40
+ }).i18n({
41
+ "de-DE": deDE,
42
+ "en-US": enUS,
43
+ "fr-FR": frFR,
44
+ "ja-JP": jaJP,
45
+ "ru-RU": ruRU,
46
+ "zh-CN": zhCN,
47
+ "zh-TW": zhTW
48
+ });
35
49
  task;
36
- /** 已创建的文件监视器集合(键为路径),stop() 时统一关闭 */
37
- watchers = Object.create(null);
38
50
  /** 由 ignored 配置编译出的 anymatch 过滤器 */
39
51
  globFilter;
40
52
  /** 文件树的根目录(ctx.baseDir + 配置的 root 解析出的绝对路径) */
@@ -85,9 +97,6 @@ var Explorer = class extends DataService {
85
97
  this.refresh();
86
98
  }, { authority: 4 });
87
99
  }
88
- stop() {
89
- for (const watcher of Object.values(this.watchers)) watcher.close();
90
- }
91
100
  /**
92
101
  * 递归遍历目录,生成排序后的文件树。
93
102
  * 排序规则:目录排在最前,其余按名称字母序;被 globFilter
package/locales/de-DE.yml CHANGED
@@ -2,6 +2,5 @@
2
2
  # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
3
  # Copyright (c) 2026-present Koishi-CE contributors.
4
4
 
5
- root: 资源管理器的根目录,默认为当前工作路径。
6
- ignored: 要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。
7
-
5
+ root: Stammverzeichnis des Explorers, standardmäßig der aktuelle Arbeitspfad.
6
+ ignored: Zu ignorierende Dateien oder Verzeichnisse. Unterstützt [Glob Patterns](https://github.com/micromatch/micromatch)-Syntax.
package/locales/en-US.yml CHANGED
@@ -2,6 +2,5 @@
2
2
  # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
3
  # Copyright (c) 2026-present Koishi-CE contributors.
4
4
 
5
- root: 资源管理器的根目录,默认为当前工作路径。
5
+ root: Root directory of the explorer, defaults to the current working path.
6
6
  ignored: Files or directories to ignore. Supports [Glob Patterns](https://github.com/micromatch/micromatch) syntax.
7
-
package/locales/fr-FR.yml CHANGED
@@ -2,6 +2,5 @@
2
2
  # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
3
  # Copyright (c) 2026-present Koishi-CE contributors.
4
4
 
5
- root: 资源管理器的根目录,默认为当前工作路径。
6
- ignored: 要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。
7
-
5
+ root: Répertoire racine de l'explorateur, par défaut le répertoire de travail actuel.
6
+ ignored: Fichiers ou répertoires à ignorer. Prend en charge la syntaxe [Glob Patterns](https://github.com/micromatch/micromatch).
package/locales/ja-JP.yml CHANGED
@@ -2,6 +2,5 @@
2
2
  # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
3
  # Copyright (c) 2026-present Koishi-CE contributors.
4
4
 
5
- root: 资源管理器的根目录,默认为当前工作路径。
6
- ignored: 要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。
7
-
5
+ root: エクスプローラーのルートディレクトリ。デフォルトは現在の作業パスです。
6
+ ignored: 除外するファイルまたはディレクトリ。[Glob Patterns](https://github.com/micromatch/micromatch) 記法に対応しています。
package/locales/ru-RU.yml CHANGED
@@ -2,6 +2,5 @@
2
2
  # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
3
  # Copyright (c) 2026-present Koishi-CE contributors.
4
4
 
5
- root: 资源管理器的根目录,默认为当前工作路径。
6
- ignored: 要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。
7
-
5
+ root: Корневой каталог проводника, по умолчанию текущий рабочий путь.
6
+ ignored: Файлы или каталоги, которые следует игнорировать. Поддерживается синтаксис [Glob Patterns](https://github.com/micromatch/micromatch).
package/locales/zh-TW.yml CHANGED
@@ -2,6 +2,5 @@
2
2
  # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
3
  # Copyright (c) 2026-present Koishi-CE contributors.
4
4
 
5
- root: 資源管理器的根目錄,默認為當前工作路徑。
6
- ignored: 要忽略的文件或目錄。支援 [Glob Patterns](https://github.com/micromatch/micromatch) 語法。
7
-
5
+ root: 檔案總管的根目錄,預設為當前工作路徑。
6
+ ignored: 要忽略的檔案或目錄。支援 [Glob Patterns](https://github.com/micromatch/micromatch) 語法。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@koishi-ce/plugin-explorer",
3
3
  "description": "File explorer and editor for Koishi",
4
- "version": "1.0.1",
4
+ "version": "1.1.0",
5
5
  "type": "module",
6
6
  "main": "lib/index.mjs",
7
7
  "types": "lib/index.d.ts",
@@ -63,9 +63,9 @@
63
63
  "@koishi-ce/koishi": "^1.0.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@koishi-ce/client": "^1.0.3",
67
- "@koishi-ce/plugin-console": "^1.0.3",
68
- "@koishi-ce/koishi": "^1.0.4",
66
+ "@koishi-ce/client": "^1.1.0",
67
+ "@koishi-ce/plugin-console": "^1.1.0",
68
+ "@koishi-ce/koishi": "^1.0.8",
69
69
  "@vueuse/core": "^14.4.0",
70
70
  "monaco-editor": "~0.56.0",
71
71
  "vue": "^3.5.12",
@@ -75,7 +75,6 @@
75
75
  "@koishi-ce/console": "^1.0.0",
76
76
  "anymatch": "^3.1.3",
77
77
  "chardet": "^2.2.0",
78
- "chokidar": "^5.0.0",
79
78
  "file-type": "^22.0.2"
80
79
  }
81
80
  }
package/src/index.test.ts CHANGED
@@ -2,42 +2,76 @@
2
2
  // Copyright (c) 2019-present Shigma and Koishijs contributors.
3
3
  // Copyright (c) 2026-present Koishi-CE contributors.
4
4
 
5
- import { afterAll, beforeAll, describe, expect, it } from "bun:test";
5
+ import {
6
+ afterAll,
7
+ beforeAll,
8
+ describe,
9
+ expect,
10
+ it,
11
+ } from "bun:test";
6
12
  import { existsSync, mkdtempSync, rmSync } from "node:fs";
7
- import { mkdir, readFile, symlink, writeFile } from "node:fs/promises";
13
+ import {
14
+ mkdir,
15
+ readFile,
16
+ symlink,
17
+ writeFile,
18
+ } from "node:fs/promises";
8
19
  import { tmpdir } from "node:os";
9
20
  import { join } from "node:path";
10
21
  import { Console, type Entry } from "@koishi-ce/console";
11
22
  import { App, type Plugin } from "@koishi-ce/koishi";
12
- import explorer, { type Entry as TreeEntry } from "./index.ts";
23
+ import explorer, {
24
+ type Entry as TreeEntry,
25
+ } from "./index.ts";
13
26
 
14
27
  /** 控制台服务桩:仅实现入口登记所需的最小面。 */
15
28
  class FakeConsole extends Console {
16
- protected resolveEntry(_files: Entry.Files, _key: string): string[] {
29
+ protected resolveEntry(
30
+ _files: Entry.Files,
31
+ _key: string,
32
+ ): string[] {
17
33
  return [];
18
34
  }
19
35
  }
20
36
 
21
37
  /** 在系统临时目录构造文件管理场景(含被忽略的隐藏文件与 node_modules)。 */
22
38
  async function createScenario() {
23
- const root = mkdtempSync(join(tmpdir(), "explorer-test-"));
24
- await writeFile(join(root, "b.txt"), "hello world", "utf8");
39
+ const root = mkdtempSync(
40
+ join(tmpdir(), "explorer-test-"),
41
+ );
42
+ await writeFile(
43
+ join(root, "b.txt"),
44
+ "hello world",
45
+ "utf8",
46
+ );
25
47
  // PNG 魔数 + IHDR chunk 头(file-type 依此识别 MIME)
26
48
  await writeFile(
27
49
  join(root, "a.png"),
28
50
  Buffer.from([
29
- 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
30
- 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
31
- 0x08, 0x06, 0x00, 0x00, 0x00,
51
+ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00,
52
+ 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00,
53
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00,
54
+ 0x00, 0x00,
32
55
  ]),
33
56
  );
34
57
  await mkdir(join(root, "sub"));
35
- await writeFile(join(root, "sub", "c.txt"), "nested", "utf8");
58
+ await writeFile(
59
+ join(root, "sub", "c.txt"),
60
+ "nested",
61
+ "utf8",
62
+ );
36
63
  await mkdir(join(root, "node_modules"));
37
- await writeFile(join(root, "node_modules", "x.txt"), "ignored");
64
+ await writeFile(
65
+ join(root, "node_modules", "x.txt"),
66
+ "ignored",
67
+ );
38
68
  await writeFile(join(root, ".hidden"), "ignored");
39
69
  // win32 无特权环境下用 junction 目录链接充当符号链接
40
- await symlink(join(root, "sub"), join(root, "link"), "junction");
70
+ await symlink(
71
+ join(root, "sub"),
72
+ join(root, "link"),
73
+ "junction",
74
+ );
41
75
  return root;
42
76
  }
43
77
 
@@ -45,7 +79,9 @@ const root = await createScenario();
45
79
 
46
80
  const app = new App();
47
81
 
48
- app.plugin(FakeConsole as unknown as Plugin.Constructor<App>);
82
+ app.plugin(
83
+ FakeConsole as unknown as Plugin.Constructor<App>,
84
+ );
49
85
  app.plugin(explorer, { root });
50
86
 
51
87
  /** 以假客户端身份调用指定 RPC 监听器。 */
@@ -54,8 +90,12 @@ async function call<K extends keyof Console["listeners"]>(
54
90
  ...args: unknown[]
55
91
  ) {
56
92
  const listener = app.console.listeners[event];
57
- if (!listener) throw new Error(`listener ${String(event)} not found`);
58
- return listener.callback.call({} as never, ...(args as never[]));
93
+ if (!listener)
94
+ throw new Error(`listener ${String(event)} not found`);
95
+ return listener.callback.call(
96
+ {} as never,
97
+ ...(args as never[]),
98
+ );
59
99
  }
60
100
 
61
101
  const service = () => app.get("console.services.explorer");
@@ -72,10 +112,17 @@ describe("explorer 文件管理服务", () => {
72
112
  const entries = (await service()?.get()) as TreeEntry[];
73
113
  const names = entries.map((entry) => entry.name);
74
114
  // 目录排最前,其余按字母序;ignored 项不出现
75
- expect(names).toEqual(["sub", "a.png", "b.txt", "link"]);
115
+ expect(names).toEqual([
116
+ "sub",
117
+ "a.png",
118
+ "b.txt",
119
+ "link",
120
+ ]);
76
121
  const sub = entries[0];
77
122
  expect(sub?.type).toBe("directory");
78
- expect(sub?.children?.map((child) => child.name)).toEqual(["c.txt"]);
123
+ expect(
124
+ sub?.children?.map((child) => child.name),
125
+ ).toEqual(["c.txt"]);
79
126
  // junction 链接识别为符号链接并给出目标
80
127
  const link = entries[3];
81
128
  expect(link?.type).toBe("symlink");
@@ -88,9 +135,9 @@ describe("explorer 文件管理服务", () => {
88
135
  encoding?: string;
89
136
  mime?: string;
90
137
  };
91
- expect(Buffer.from(file.base64, "base64").toString("utf8")).toBe(
92
- "hello world",
93
- );
138
+ expect(
139
+ Buffer.from(file.base64, "base64").toString("utf8"),
140
+ ).toBe("hello world");
94
141
  expect(file.encoding).toBeTruthy();
95
142
  // 文本文件不携带 mime
96
143
  expect(file.mime).toBeUndefined();
@@ -106,7 +153,9 @@ describe("explorer 文件管理服务", () => {
106
153
 
107
154
  it("write 支持文本与 base64 二进制写入", async () => {
108
155
  await call("explorer/write", "sub/new.txt", "新内容");
109
- expect(await readFile(join(root, "sub", "new.txt"), "utf8")).toBe("新内容");
156
+ expect(
157
+ await readFile(join(root, "sub", "new.txt"), "utf8"),
158
+ ).toBe("新内容");
110
159
 
111
160
  const buffer = Buffer.from([1, 2, 3, 4]);
112
161
  await call(
@@ -115,7 +164,9 @@ describe("explorer 文件管理服务", () => {
115
164
  buffer.toString("base64"),
116
165
  true,
117
166
  );
118
- expect(await readFile(join(root, "sub", "new.bin"))).toEqual(buffer);
167
+ expect(
168
+ await readFile(join(root, "sub", "new.bin")),
169
+ ).toEqual(buffer);
119
170
  });
120
171
 
121
172
  it("mkdir / rename / remove 执行实际文件操作", async () => {
@@ -139,10 +190,14 @@ describe("explorer 文件管理服务", () => {
139
190
  // 文件变动后强制刷新得到新树
140
191
  await writeFile(join(root, "z.txt"), "tail");
141
192
  const fresh = (await svc?.get(true)) as TreeEntry[];
142
- expect(fresh.map((entry) => entry.name)).toContain("z.txt");
193
+ expect(fresh.map((entry) => entry.name)).toContain(
194
+ "z.txt",
195
+ );
143
196
  });
144
197
 
145
198
  it("read 不存在的文件时抛错", async () => {
146
- expect(call("explorer/read", "not-exist.txt")).rejects.toThrow();
199
+ expect(
200
+ call("explorer/read", "not-exist.txt"),
201
+ ).rejects.toThrow();
147
202
  });
148
203
  });
package/src/index.ts CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  } from "node:fs/promises";
23
23
  import { join, relative, resolve } from "node:path";
24
24
  import { DataService } from "@koishi-ce/console";
25
- import { type Context, type Dict, Schema } from "@koishi-ce/koishi";
25
+ import { type Context, Schema } from "@koishi-ce/koishi";
26
26
  import type { Tester } from "anymatch";
27
27
  import * as anymatchModule from "anymatch";
28
28
 
@@ -32,9 +32,14 @@ const anymatch =
32
32
  anymatchModule.default as unknown as typeof anymatchModule.default.default;
33
33
 
34
34
  import { detect } from "chardet";
35
- import type { FSWatcher } from "chokidar";
36
35
  import { fileTypeFromBuffer } from "file-type";
36
+ import deDE from "../locales/de-DE.yml";
37
+ import enUS from "../locales/en-US.yml";
38
+ import frFR from "../locales/fr-FR.yml";
39
+ import jaJP from "../locales/ja-JP.yml";
40
+ import ruRU from "../locales/ru-RU.yml";
37
41
  import zhCN from "../locales/zh-CN.yml";
42
+ import zhTW from "../locales/zh-TW.yml";
38
43
 
39
44
  declare module "@koishi-ce/console" {
40
45
  namespace Console {
@@ -44,7 +49,10 @@ declare module "@koishi-ce/console" {
44
49
  }
45
50
 
46
51
  interface Events {
47
- "explorer/read"(filename: string, binary?: boolean): Promise<File>;
52
+ "explorer/read"(
53
+ filename: string,
54
+ binary?: boolean,
55
+ ): Promise<File>;
48
56
  "explorer/write"(
49
57
  filename: string,
50
58
  content: string,
@@ -52,7 +60,10 @@ declare module "@koishi-ce/console" {
52
60
  ): Promise<void>;
53
61
  "explorer/mkdir"(filename: string): Promise<void>;
54
62
  "explorer/remove"(filename: string): Promise<void>;
55
- "explorer/rename"(oldValue: string, newValue: string): Promise<void>;
63
+ "explorer/rename"(
64
+ oldValue: string,
65
+ newValue: string,
66
+ ): Promise<void>;
56
67
  "explorer/refresh"(): void;
57
68
  }
58
69
  }
@@ -104,12 +115,16 @@ class Explorer extends DataService<Entry[]> {
104
115
  .role("table")
105
116
  .default(["**/node_modules", "**/.*", "cache"]),
106
117
  }).i18n({
118
+ "de-DE": deDE,
119
+ "en-US": enUS,
120
+ "fr-FR": frFR,
121
+ "ja-JP": jaJP,
122
+ "ru-RU": ruRU,
107
123
  "zh-CN": zhCN,
124
+ "zh-TW": zhTW,
108
125
  });
109
126
 
110
127
  task!: Promise<Entry[]>;
111
- /** 已创建的文件监视器集合(键为路径),stop() 时统一关闭 */
112
- watchers: Dict<FSWatcher> = Object.create(null);
113
128
  /** 由 ignored 配置编译出的 anymatch 过滤器 */
114
129
  globFilter: Tester;
115
130
  /** 文件树的根目录(ctx.baseDir + 配置的 root 解析出的绝对路径) */
@@ -125,7 +140,12 @@ class Explorer extends DataService<Entry[]> {
125
140
  `${process.env["KOISHI_BASE"]}/dist/style.css`,
126
141
  ]
127
142
  : process.env["KOISHI_ENV"] === "browser"
128
- ? [import.meta.url.replace(/\/src\/[^/]+$/, "/client/index.ts")]
143
+ ? [
144
+ import.meta.url.replace(
145
+ /\/src\/[^/]+$/,
146
+ "/client/index.ts",
147
+ ),
148
+ ]
129
149
  : {
130
150
  dev: resolve(__dirname, "../client/index.ts"),
131
151
  prod: resolve(__dirname, "../dist"),
@@ -149,7 +169,9 @@ class Explorer extends DataService<Entry[]> {
149
169
  const encoding = detect(buffer);
150
170
  // exactOptionalPropertyTypes:探测失败时不上键,与原先携带 undefined
151
171
  // 值的对象在 JSON 序列化后表现一致
152
- const file: File = { base64: buffer.toString("base64") };
172
+ const file: File = {
173
+ base64: buffer.toString("base64"),
174
+ };
153
175
  if (result) file.mime = result.mime;
154
176
  if (encoding) file.encoding = encoding;
155
177
  return file;
@@ -214,47 +236,48 @@ class Explorer extends DataService<Entry[]> {
214
236
  );
215
237
  }
216
238
 
217
- override stop() {
218
- // 插件停用:关闭所有已创建的文件监视器
219
- for (const watcher of Object.values(this.watchers)) {
220
- watcher.close();
221
- }
222
- }
223
-
224
239
  /**
225
240
  * 递归遍历目录,生成排序后的文件树。
226
241
  * 排序规则:目录排在最前,其余按名称字母序;被 globFilter
227
242
  * 命中的路径(node_modules、隐藏文件等)直接跳过。
228
243
  */
229
244
  private async traverse(root: string): Promise<Entry[]> {
230
- const dirents = await readdir(root, { withFileTypes: true });
245
+ const dirents = await readdir(root, {
246
+ withFileTypes: true,
247
+ });
231
248
  return Promise.all(
232
- dirents.map(async (dirent): Promise<Entry | undefined> => {
233
- const filename = join(root, dirent.name);
234
- if (this.globFilter(relative(this.root, filename))) return;
235
- if (dirent.isFile()) {
236
- return { type: "file", name: dirent.name };
237
- } else if (dirent.isDirectory()) {
238
- return {
239
- type: "directory",
240
- name: dirent.name,
241
- children: await this.traverse(filename),
242
- };
243
- } else if (dirent.isSymbolicLink()) {
244
- return {
245
- type: "symlink",
246
- name: dirent.name,
247
- target: await readlink(filename),
248
- };
249
- }
250
- // 其余类型(FIFO / socket 等)不展示,显式返回以通过 noImplicitReturns
251
- return;
252
- }),
249
+ dirents.map(
250
+ async (dirent): Promise<Entry | undefined> => {
251
+ const filename = join(root, dirent.name);
252
+ if (
253
+ this.globFilter(relative(this.root, filename))
254
+ )
255
+ return;
256
+ if (dirent.isFile()) {
257
+ return { type: "file", name: dirent.name };
258
+ } else if (dirent.isDirectory()) {
259
+ return {
260
+ type: "directory",
261
+ name: dirent.name,
262
+ children: await this.traverse(filename),
263
+ };
264
+ } else if (dirent.isSymbolicLink()) {
265
+ return {
266
+ type: "symlink",
267
+ name: dirent.name,
268
+ target: await readlink(filename),
269
+ };
270
+ }
271
+ // 其余类型(FIFO / socket 等)不展示,显式返回以通过 noImplicitReturns
272
+ return;
273
+ },
274
+ ),
253
275
  ).then((entries) =>
254
276
  entries
255
277
  .filter((entry): entry is Entry => !!entry)
256
278
  .sort((a, b) => {
257
- if (a.type !== b.type) return a.type === "directory" ? -1 : 1;
279
+ if (a.type !== b.type)
280
+ return a.type === "directory" ? -1 : 1;
258
281
  return a.name.localeCompare(b.name);
259
282
  }),
260
283
  );