Resolve index files for script imports

This commit is contained in:
Snarling 2024-08-16 19:40:41 -04:00
parent 79bb0d289a
commit 4f78fcab1b

@ -110,14 +110,18 @@ export function getModuleScript(
throw new ModuleResolutionError(`Invalid module: "${moduleName}". Base module: "${baseModule}".`); throw new ModuleResolutionError(`Invalid module: "${moduleName}". Base module: "${baseModule}".`);
} }
script = scripts.get(filename); script = scripts.get(filename);
if (script) { if (script) return script;
break; }
// If no script was found with the base name, check for a folder with index file
for (const extension of validScriptExtensions) {
const filename = resolveScriptFilePath(`${moduleName}/index`, baseModule, extension);
if (!filename) {
throw new ModuleResolutionError(`Invalid module: "${moduleName}". Base module: "${baseModule}".`);
} }
script = scripts.get(filename);
if (script) return script;
} }
if (!script) { throw new ModuleResolutionError(`Invalid module: "${moduleName}". Base module: "${baseModule}".`);
throw new ModuleResolutionError(`Invalid module: "${moduleName}". Base module: "${baseModule}".`);
}
return script;
} }
/** /**