From b473139c6eef594d338922becc0445089a24da33 Mon Sep 17 00:00:00 2001 From: Jelle De Loecker Date: Sun, 21 Apr 2024 18:05:15 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20registered=20modules=20not?= =?UTF-8?q?=20being=20requirable=20in=20the=20browser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/init.js | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/init.js b/lib/init.js index 5c81579..7d4644e 100644 --- a/lib/init.js +++ b/lib/init.js @@ -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 * @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;