<commit_before>-module(beamjs_mod_require).
-export([exports/0]).
-include_lib("erlv8/include/erlv8.hrl").

exports() ->
	fun require/3.

require(_Script, #erlv8_fun_invocation{} = _Invocation, Filename) ->
	{ok, B} = file:read_file(Filename),
	S = binary_to_list(B),
	{ok, NewScript} = erlv8:new_script(S),	
	beamjs:load_default_mods(NewScript),
	Self = self(),<commit_msg>require_mod: added simple support for Erlang-based modules<commit_after>-module(beamjs_mod_require).
-export([exports/0]).
-include_lib("erlv8/include/erlv8.hrl").

exports() ->
	fun require/3.

require(Script, #erlv8_fun_invocation{} = Invocation, Filename) ->
	case application:get_env(beamjs,available_mods) of
		{ok, Mods} ->
			io:format("Mods = ~p File = ~p~n",[Mods,Filename]),
			case proplists:get_value(Filename,Mods) of
				undefined ->
					require_file(Script, Invocation, Filename);
				Mod -> %% it is an Erlang-implemented module
					Mod:exports()
			end;
		_ ->
			require_file(Script, Invocation, Filename)
	end.

require_file(_Script, #erlv8_fun_invocation{} = _Invocation, Filename) ->
	{ok, B} = file:read_file(Filename),
	S = binary_to_list(B),
	{ok, NewScript} = erlv8:new_script(S),	
	beamjs:load_default_mods(NewScript),
	Self = self(),
{'fraction_non_alphanumeric': 0.1593851132686084, 'fraction_numerical': 0.010517799352750809, 'mean_word_length': 5.376288659793815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '634142', 'n_tokens_mistral': 503, 'n_tokens_neox': 470, 'n_words': 79}