Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ const load = async (filePath, sandbox) => {
};

const loadDir = async (dir, sandbox) => {
const files = await fsp.readdir(dir);
const files = await fsp.readdir(dir, { withFileTypes: true });
const container = {};
for (const fileName of files) {
if (!fileName.endsWith('.js')) continue;
const filePath = path.join(dir, fileName);
const name = path.basename(fileName, '.js');
container[name] = await load(filePath, sandbox);
for (const file of files) {
const { name } = file;
if (file.isFile() && !name.endsWith('.js')) continue;
const location = path.join(dir, name);
const key = path.basename(name, '.js');
const loader = file.isFile() ? load : loadDir;
container[key] = await loader(location, sandbox);
}
return container;
};
Expand Down