mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
23 lines
558 B
JavaScript
23 lines
558 B
JavaScript
import tryToCatch from 'try-to-catch';
|
|
|
|
export default async function superImport(str) {
|
|
const tryToCatch = await expandDefault('try-to-catch');
|
|
|
|
const [eJs, resultJs] = await tryToCatch(expandDefault, `${str}.js`);
|
|
|
|
if (!eJs)
|
|
return resultJs;
|
|
|
|
const [eIndex, resultIndex] = await tryToCatch(expandDefault, `${str}/index.js`);
|
|
|
|
if (!eIndex)
|
|
return resultIndex;
|
|
|
|
return await expandDefault(str);
|
|
}
|
|
|
|
async function expandDefault(a) {
|
|
const result = await import(a);
|
|
return result.default;
|
|
}
|
|
|