-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Fix registered modules not being requirable in the browser
- Loading branch information
Showing
1 changed file
with
27 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,6 +411,9 @@ function BlastInit(modifyPrototype) { | |
// Already required files | ||
required = {}; | ||
|
||
// Required results | ||
let required_results = {}; | ||
|
||
Names = [ | ||
'Function', | ||
'Object', | ||
|
@@ -1431,18 +1434,14 @@ function BlastInit(modifyPrototype) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.4.1 | ||
* @version 0.9.0 | ||
* @version 0.9.3 | ||
* | ||
* @param {string} name | ||
* @param {Object} options | ||
*/ | ||
Blast.require = function require(name, options) { | ||
|
||
if (!options) { | ||
options = {}; | ||
} else { | ||
options = {...options}; | ||
} | ||
options = {...options}; | ||
|
||
if (options.client == null) { | ||
options.client = true; | ||
|
@@ -1461,7 +1460,9 @@ function BlastInit(modifyPrototype) { | |
name = name.slice(0); | ||
} | ||
|
||
options.name_id = name.join('/'); | ||
if (!options.name_id) { | ||
options.name_id = name.join('/'); | ||
} | ||
|
||
name.unshift(options.pwd); | ||
} | ||
|
@@ -1479,13 +1480,26 @@ function BlastInit(modifyPrototype) { | |
} | ||
} | ||
|
||
let previously_required_options = required[name]; | ||
let previously_required_options; | ||
|
||
if (options.name_id) { | ||
previously_required_options = required[options.name_id]; | ||
} | ||
|
||
if (!previously_required_options) { | ||
previously_required_options = required[name]; | ||
} | ||
|
||
if (previously_required_options) { | ||
|
||
// Skip duplicates | ||
if (options.client == previously_required_options.client && options.server == previously_required_options.server) { | ||
return; | ||
|
||
if (Blast.isBrowser) { | ||
return required_results[options.path || name]; | ||
} | ||
|
||
return required_results[options.name || name]; | ||
} | ||
|
||
if (options.client && previously_required_options.client) { | ||
|
@@ -1527,8 +1541,6 @@ function BlastInit(modifyPrototype) { | |
} else { | ||
if (!options.name_id) { | ||
options.name_id = index + '_' + options.name; | ||
} else { | ||
options.name_id = index + '_' + options.name_id; | ||
} | ||
} | ||
} else if (!options.name_id) { | ||
|
@@ -1540,6 +1552,8 @@ function BlastInit(modifyPrototype) { | |
} | ||
//PROTOBLAST END CUT | ||
|
||
required[options.name_id] = options; | ||
|
||
if (Blast.isBrowser) { | ||
if (options.is_extra === false && !options.path) { | ||
options.path = options.name_id; | ||
|
@@ -1556,8 +1570,10 @@ function BlastInit(modifyPrototype) { | |
|
||
if (Blast.isNode) { | ||
exports = Blast.requireFileViaVm(options.path || name, options); | ||
required_results[options.name_id] = exports; | ||
} else { | ||
exports = blastRequirer(options.path || name, Blast.getArgumentConfiguration(options.arguments)); | ||
required_results[options.path || name] = exports; | ||
} | ||
|
||
Blast[Blast.ACTIVE_FILE] = null; | ||
|