better code

Massimo Melina committed May 9, 2026 at 10:43 UTC d9a532f0f12b50d3ac1ec01b002cb5808c9493cb
3 files changed +6 -6
dev-plugins.md
+1 -1
@@ -812,7 +812,7 @@ This section is still partially documented, and you may need to have a look at t
812 - `ctx: Context`
813 - `node: VfsNode`
814 - async supported
815 - - preventable
815 + - preventable (the entry will be skipped)
816 - note: legacy `onDirEntry` hooks run first; use this event for new code
817 - types `DirEntryBackend` fields:
818 - `n: string` name of the entry. (May include the relative path when searching in subfolders.)
src/api.get_file_list.ts
+1 -1
@@ -78,7 +78,7 @@ export const get_file_list: ApiHandler = async ({ uri='/', offset, limit, c, onl
78 async function* produceEntries() {
79 for await (const sub of walker) {
80 let name = getNodeName(sub)
81 - name = basename(name) || name // on windows, basename('C:') === ''
81 + name = basename(name) || name // on Windows, basename('C:') === ''
82 if (filterName && !filterName(name) || fileMask && !nodeIsFolder(sub) && !fileMask(name)
83 || filterComment && !filterComment(await getCommentFor(sub.source) || ''))
84 continue
src/plugins.ts
+4 -4
@@ -282,7 +282,7 @@ events.once('app', () => Object.assign(app.context, {
282
283 // return false to ask to exclude this entry from results
284 interface OnDirEntryParams { entry:DirEntry, ctx:Koa.Context, node:VfsNode }
285 -type OnDirEntry = (params:OnDirEntryParams) => void | false
285 +type OnDirEntry = (params:OnDirEntryParams) => Promisable<unknown | false>
286
287 export class Plugin implements CommonPluginInterface {
288 started: Date | null = new Date()
@@ -455,16 +455,16 @@ export async function rescan() {
455 const patterns = [PATH + '/*']
456 if (APP_PATH !== process.cwd())
457 patterns.unshift(escapeGlobPath(APP_PATH) + '/' + patterns[0]) // first search bundled plugins, because otherwise they won't be loaded because of the folders with same name in .hfs/plugins (used for storage)
458 - const existing = []
458 + const existing = new Set<string>()
459 for (const { path, dirent } of await glob(patterns, { onlyFiles: false, suppressErrors: true, objectMode: true })) {
460 if (!dirent.isDirectory() || path.endsWith(DISABLING_SUFFIX)) continue
461 const id = path.split('/').slice(-1)[0]!
462 - existing.push(id)
462 + existing.add(id)
463 if (!pluginWatchers.has(id))
464 pluginWatchers.set(id, watchPlugin(id, join(path, PLUGIN_MAIN_FILE)))
465 }
466 for (const [id, cancelWatcher] of pluginWatchers.entries())
467 - if (!existing.includes(id)) {
467 + if (!existing.has(id)) {
468 enablePlugin(id, false)
469 cancelWatcher()
470 pluginWatchers.delete(id)