Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOMara committed Aug 3, 2024
1 parent 5d169a4 commit 1ae713e
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -217,27 +217,31 @@ function resolveModuleDir(name, file) {
*/
function resolveExtension(value, base, extensions, expand = false) {
let paths;
if (/[\\/]$/.test(base)) {
paths = ['index'];
} else {
paths = [''];
while (!paths) {
if (/[\\/]$/.test(base)) {
paths = ['index'];
break;
}

const stat = pathStat(base);
if (stat) {
if (stat.isDirectory()) {
paths.push('/index');
} else {
return value;
}
if (!stat) {
paths = [''];
break;
}

if (stat.isDirectory()) {
paths = ['', '/index'];
break;
}

return value;
}

for (const path of paths) {
for (const extension of extensions) {
const {srcs, dst} = expand
? expandExtensions(extension)
: {
srcs: [extension],
dst: extension
};
: {srcs: [extension], dst: extension};
for (const src of srcs) {
const stat = pathStat(`${base}${path}${src}`);
if (stat && !stat.isDirectory()) {
Expand Down

0 comments on commit 1ae713e

Please sign in to comment.