File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
source/loaders/node_loader/bootstrap/lib Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff 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+
4160function 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 }
You can’t perform that action at this time.
0 commit comments