Skip to content

Commit

Permalink
Solve minor bugs in last version, related to require semantics in nod…
Browse files Browse the repository at this point in the history
…e loader.
  • Loading branch information
viferga committed Dec 15, 2020
1 parent f25c346 commit 99354ef
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions source/loaders/node_loader/bootstrap/lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,36 @@ function node_loader_trampoline_load_from_file_require(p) {
/* First try to load the absolute path */
try {
return require(p);
} catch (e) {}
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}
}

/* Then try to load without the path */
const basename = path.basename(p);

try {
return require(basename);
} catch (e) {}
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}
}

/* Finally try to load without the path and extension */
/* Try to load without the path and extension */
const { name } = path.parse(basename);

return require(name);
try {
return require(name);
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}
}

/* Try to load base path without extension and with node modules */
return require(path.join(path.dirname(p), 'node_modules', name));
}

function node_loader_trampoline_load_from_file(paths) {
Expand Down

0 comments on commit 99354ef

Please sign in to comment.