Skip to content

Commit f25c346

Browse files
committed
Add a more complete require schema for node loader.
1 parent bc995c0 commit f25c346

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

source/loaders/node_loader/bootstrap/lib/bootstrap.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ function node_loader_trampoline_execution_path() {
3838
// TODO
3939
}
4040

41+
function node_loader_trampoline_load_from_file_require(p) {
42+
/* First try to load the absolute path */
43+
try {
44+
return require(p);
45+
} catch (e) {}
46+
47+
/* Then try to load without the path */
48+
const basename = path.basename(p);
49+
50+
try {
51+
return require(basename);
52+
} catch (e) {}
53+
54+
/* Finally try to load without the path and extension */
55+
const { name } = path.parse(basename);
56+
57+
return require(name);
58+
}
59+
4160
function node_loader_trampoline_load_from_file(paths) {
4261
if (!Array.isArray(paths)) {
4362
throw new Error('Load from file paths must be an array, not ' + typeof paths);
@@ -48,7 +67,7 @@ function node_loader_trampoline_load_from_file(paths) {
4867

4968
for (let i = 0; i < paths.length; ++i) {
5069
const p = paths[i];
51-
const m = require(path.resolve(__dirname, p));
70+
const m = node_loader_trampoline_load_from_file_require(path.resolve(__dirname, p));
5271

5372
handle[p] = node_loader_trampoline_module(m);
5473
}

0 commit comments

Comments
 (0)