Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

fix: Added protection for files without module exports #28

Merged
merged 1 commit into from
Sep 2, 2023
Merged
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
12 changes: 12 additions & 0 deletions src/core/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ async function importModulesFromFile(path: string): Promise<void> {
// get the *default* export from each file and add it to the array of modules
// dynamic imports import relative to the path of the file being run
const fileExport = await import(path);

if (fileExport.default === undefined) {
const fileName = path.split('/').slice(-1);
logEvent(
EventCategory.Warning,
'core',
`File '${fileName}' has no module exports, skipping it`,
1
);
return;
}

// to allow multiple module exports from the same file, if they exported an array, then iterate over it
if (Array.isArray(fileExport.default)) {
for (const module of fileExport.default) {
Expand Down