Skip to content

Commit 99354ef

Browse files
committed
Solve minor bugs in last version, related to require semantics in node loader.
1 parent f25c346 commit 99354ef

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,36 @@ function node_loader_trampoline_load_from_file_require(p) {
4242
/* First try to load the absolute path */
4343
try {
4444
return require(p);
45-
} catch (e) {}
45+
} catch (e) {
46+
if (e.code !== 'MODULE_NOT_FOUND') {
47+
throw e;
48+
}
49+
}
4650

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

5054
try {
5155
return require(basename);
52-
} catch (e) {}
56+
} catch (e) {
57+
if (e.code !== 'MODULE_NOT_FOUND') {
58+
throw e;
59+
}
60+
}
5361

54-
/* Finally try to load without the path and extension */
62+
/* Try to load without the path and extension */
5563
const { name } = path.parse(basename);
5664

57-
return require(name);
65+
try {
66+
return require(name);
67+
} catch (e) {
68+
if (e.code !== 'MODULE_NOT_FOUND') {
69+
throw e;
70+
}
71+
}
72+
73+
/* Try to load base path without extension and with node modules */
74+
return require(path.join(path.dirname(p), 'node_modules', name));
5875
}
5976

6077
function node_loader_trampoline_load_from_file(paths) {

0 commit comments

Comments
 (0)