Skip to content

Commit 19bcb85

Browse files
wip(core): minor refactoring
1 parent dd069a4 commit 19bcb85

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/index.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -892,37 +892,30 @@ export async function loadModule(path : string, options_ : Options = throwNotDef
892892
}
893893

894894

895-
moduleCache[path] = new Loading(
895+
moduleCache[path] = new Loading((async () => {
896896

897-
(async () => {
897+
if ( loadModule ) {
898898

899-
if ( loadModule ) {
900-
901-
const module = await loadModule(path, options);
902-
if ( module !== undefined )
903-
return moduleCache[path] = module;
904-
}
905-
906-
const res = await getFile(path);
907-
908-
const file = typeof res === 'object' ? res : { content: res, extname: pathHandlers.extname(path) };
909-
910-
const moduleHandlers = { ...defaultModuleHandlers, ...additionalModuleHandlers };
899+
const module = await loadModule(path, options);
900+
if ( module !== undefined )
901+
return moduleCache[path] = module;
902+
}
911903

912-
if ( !(file.extname in moduleHandlers) )
913-
throw new TypeError(`Unable to handle ${ file.extname } files (${ path }), see additionalModuleHandlers`);
904+
const res = await getFile(path);
914905

915-
if ( typeof file.content !== 'string' )
916-
throw new TypeError(`Invalid module content (${path}): ${ file.content }`);
906+
const file = typeof res === 'object' ? res : { content: res, extname: pathHandlers.extname(path) };
917907

908+
const moduleHandlers = { ...defaultModuleHandlers, ...additionalModuleHandlers };
918909

919-
const module = await moduleHandlers[file.extname](file.content, path, options);
910+
if ( !(file.extname in moduleHandlers) )
911+
throw new TypeError(`Unable to handle ${ file.extname } files (${ path }), see additionalModuleHandlers`);
920912

921-
return moduleCache[path] = module;
913+
if ( typeof file.content !== 'string' )
914+
throw new TypeError(`Invalid module content (${path}): ${ file.content }`);
922915

923-
})()
916+
return moduleCache[path] = await moduleHandlers[file.extname](file.content, path, options);
924917

925-
);
918+
})());
926919

927920
return await moduleCache[path].promise;
928921
}

0 commit comments

Comments
 (0)