fix: try to use fs.walk to avoid issues with jsr.io
This commit is contained in:
parent
dd2e98ccd9
commit
c1ccfa70cf
1 changed files with 12 additions and 5 deletions
17
server.ts
17
server.ts
|
@ -6,6 +6,7 @@
|
|||
import * as colors from '@std/fmt/colors';
|
||||
import * as fs from '@std/fs';
|
||||
import * as path from '@std/path';
|
||||
import { walk } from '@std/fs';
|
||||
|
||||
const DEFAULT_HANDLER_DIRECTORIES = [path.join(import.meta.dirname ?? '.', 'handlers')];
|
||||
|
||||
|
@ -108,16 +109,22 @@ export class SERVER {
|
|||
DEFAULT_HANDLER_DIRECTORIES;
|
||||
|
||||
for (const handler_directory of HANDLERS_DIRECTORIES) {
|
||||
const resolved_handler_directory_glob = path.resolve(path.join(handler_directory, '*.ts'));
|
||||
for await (const globbed_record of fs.expandGlob(resolved_handler_directory_glob)) {
|
||||
if (!globbed_record.isFile) {
|
||||
const root_directory = path.resolve(handler_directory);
|
||||
|
||||
for await (
|
||||
const entry of walk(root_directory, {
|
||||
exts: ['.ts'],
|
||||
skip: [/\.test\.ts$/]
|
||||
})
|
||||
) {
|
||||
if (!entry.isFile) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const import_path = new URL('file://' + globbed_record.path, import.meta.url).toString();
|
||||
const import_path = new URL('file://' + entry.path, import.meta.url).toString();
|
||||
const handler_module: HANDLER_MODULE = await import(import_path);
|
||||
if (typeof handler_module.default !== 'function') {
|
||||
console.warn(`Could not load handler, no default exported function: ${globbed_record.path}`);
|
||||
console.warn(`Could not load handler, no default exported function: ${entry.path}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue