From 104afeb9fb3a5220d207ad69629301f0c50e14f7 Mon Sep 17 00:00:00 2001 From: Vicente Ferrer Date: Thu, 18 Feb 2021 13:30:08 +0100 Subject: [PATCH] Solve minor bugs in fail paths for nodejs require. --- .../cs_loader/netcore/source/MetacallEntryPoint.cs | 12 ++++++++---- source/ports/node_port/index.js | 5 +++++ source/ports/node_port/test/index.js | 6 ++++++ source/tests/metacall_node_port_test/CMakeLists.txt | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/source/loaders/cs_loader/netcore/source/MetacallEntryPoint.cs b/source/loaders/cs_loader/netcore/source/MetacallEntryPoint.cs index 5058ca20d..437b81eb4 100644 --- a/source/loaders/cs_loader/netcore/source/MetacallEntryPoint.cs +++ b/source/loaders/cs_loader/netcore/source/MetacallEntryPoint.cs @@ -18,12 +18,10 @@ namespace CSLoader public static class MetacallEntryPoint { private static LoaderBase loader = null; + private static ConsoleLog log = new ConsoleLog(); static MetacallEntryPoint() { - - var log = new ConsoleLog(); - log.Info("CSLoader static initialization"); #if NETCOREAPP1_0 || NETCOREAPP1_1 || NETCOREAPP1_2 @@ -45,7 +43,13 @@ public static bool Load(string source) public static bool Load(string[] files) { - return loader.LoadFromSourceFunctions(files.Select(x => System.IO.File.ReadAllText(x)).ToArray()); + try { + return loader.LoadFromSourceFunctions(files.Select(x => System.IO.File.ReadAllText(x)).ToArray()); + } catch (FileNotFoundException ex) { + // TODO: Implement error handling + log.Info(ex.Message); + return false; + } } public static ReflectFunction[] GetFunctionsInternal() diff --git a/source/ports/node_port/index.js b/source/ports/node_port/index.js index 26628711a..587cbbb46 100644 --- a/source/ports/node_port/index.js +++ b/source/ports/node_port/index.js @@ -195,10 +195,15 @@ mod.prototype.require = function (name) { /* NodeJS Loader */ js: 'node', node: 'node', + + /* TODO: TypeScript Loader is not supported to run with NodeJS Loader at the same time yet */ + /* TypeScript Loader */ + /* ts: 'ts', jsx: 'ts', tsx: 'ts', + */ /* Note: By default js extension uses NodeJS loader instead of JavaScript V8 */ /* Probably in the future we can differenciate between them, but it is not trivial */ diff --git a/source/ports/node_port/test/index.js b/source/ports/node_port/test/index.js index 64d3d244f..726a89b41 100644 --- a/source/ports/node_port/test/index.js +++ b/source/ports/node_port/test/index.js @@ -42,6 +42,12 @@ describe('metacall', () => { }); }); + describe('fail', () => { + it('require', () => { + assert.strictEqual(require('./asd.invalid'), undefined); + }); + }); + describe('load', () => { it('metacall_load_from_file (py)', () => { assert.strictEqual(metacall_load_from_file('py', [ 'helloworld.py' ] ), undefined); diff --git a/source/tests/metacall_node_port_test/CMakeLists.txt b/source/tests/metacall_node_port_test/CMakeLists.txt index d0fedd9fa..083603511 100644 --- a/source/tests/metacall_node_port_test/CMakeLists.txt +++ b/source/tests/metacall_node_port_test/CMakeLists.txt @@ -135,6 +135,7 @@ if(OPTION_BUILD_LOADERS_COB) endif() add_dependencies(${target} + node_port node_loader mock_loader py_loader