Skip to content

Commit

Permalink
πŸ› Fix registered modules not being requirable in the browser
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Apr 21, 2024
1 parent 99d7f5d commit b473139
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ function BlastInit(modifyPrototype) {
// Already required files
required = {};

// Required results
let required_results = {};

Names = [
'Function',
'Object',
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit b473139

Please sign in to comment.