diff --git a/.gitignore b/.gitignore index 107b0acb..1d9ac77e 100644 --- a/.gitignore +++ b/.gitignore @@ -64,8 +64,6 @@ tools/build /test/Properties/ /test/test.nuget.cache -package-lock.json - tools/nuget/content tools/nuget/lib tools/nuget/*.nupkg diff --git a/README.md b/README.md index e6873b9d..1fb726d9 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ ### This library is based on https://github.com/tjanczuk/edge all credit for original work goes to Tomasz Janczuk. ------ -## Introduction +## Overview -**Edge.js allows you to run Node.js and .NET code in one process on Windows, macOS, and Linux.** +**Edge.js allows you to run Node.js and .NET code in one process on Windows, macOS, and Linux** You can call .NET functions from Node.js and Node.js functions from .NET. Edge.js takes care of marshaling data between CLR and V8. Edge.js also reconciles threading models of single-threaded V8 and multi-threaded CLR. @@ -40,7 +40,7 @@ The CLR code can be pre-compiled or specified as C#, F#, Python (IronPython), or ## Electron -For use with Electron refer to `electron-edge-js`. https://github.com/agracio/electron-edge-js +For use with Electron refer to `electron-edge-js` https://github.com/agracio/electron-edge-js ## Quick start @@ -54,8 +54,7 @@ https://github.com/agracio/edge-js-quick-start | 16.x | Supported | | 18.x | Supported | | 20.x | Supported | -| 21.x | Supported | -| 22.x | In development | +| 22.x | Supported | ## Scripting CLR from Node.js and Node.js from CRL @@ -84,7 +83,6 @@ https://github.com/agracio/edge-js-quick-start Mono is no longer actively supported. Existing code will remain In Edge.Js but focus will be on .NET Core. Mono tests are excluded from CI. - ## Node.js application packaging When packaging your application using Webpack make sure that `edge-js` is specified as external module. @@ -105,7 +103,7 @@ When packaging your application using Webpack make sure that `edge-js` is specif | Framework | Platform | NPM Package | Language code | Documentation | | ----------- | ------------ | ----------- |-------------- | ------------- | -| .NET 4.5 | Windows | `edge-fs` | `fs` | [Script F# in Node.js](#how-to-script-f-in-a-nodejs-application) | +| ~~.NET 4.5~~ | ~~Windows~~ | ~~`edge-fs`~~ | ~~`fs`~~ | ~~[Script F# in Node.js](#how-to-script-f-in-a-nodejs-application)~~ | | CoreCLR | Any | In development | N/A| N/A | ### Python (IronPython) scripting @@ -133,10 +131,12 @@ Provides simple access to MS SQL without the need to write separate C# code. | .NET 4.5 | Windows | `edge-sql` | `sql`| Script T-SQL in Node.js :link: | | .NET Standard | Any | `edge-sql` | `sql`| Script T-SQL in Node.js :link: | +--------- + ## How to use -#### Full documentation [Scripting CLR from Node.js](#scripting-clr-from-nodejs) -#### Full documentation [Scripting Node.Js from CLR](#how-to-integrate-nodejs-code-into-clr-code) +#### [Scripting CLR from Node.js](#scripting-clr-from-nodejs) - full documentation +#### [Scripting Node.js from CLR](#how-to-integrate-nodejs-code-into-clr-code) - full documentation #### Scripting CLR from Node.js sample app https://github.com/agracio/edge-js-quick-start ---- @@ -308,7 +308,14 @@ getPerson({name: 'John Smith', email: 'john.smith@myemailprovider', age: 35}, fu ``` -### :exclamation: `edge.func()` only supports `public async Task MyMethod(dynamic input)` C# methods. +### Edge.js C# method must have the following signature + +```cs +public async Task MyMethod(dynamic input) +{ + //return results sync/async; +} +``` ### Executing synchronously without function callback @@ -1988,7 +1995,7 @@ The edge module is intended to remain a very small component with core functiona ## More -Issues? Feedback? You [know what to do](https://github.com/tjanczuk/edge/issues/new). Pull requests welcome. +Issues? Feedback? You [know what to do](https://github.com/agracio/edge-js/issues/new). Pull requests welcome. [dependencies-url]: https://www.npmjs.com/package/edge-js?activeTab=dependencies [dependencies-img]: https://img.shields.io/librariesio/release/npm/edge-js.svg?style=flat-square diff --git a/binding.gyp b/binding.gyp index f13f0c08..47ac9fae 100644 --- a/binding.gyp +++ b/binding.gyp @@ -204,50 +204,38 @@ [ '"/dev/null) || echo not_found)"!="not_found"', { - 'sources+': [ - 'src/mono/clractioncontext.cpp', - 'src/mono/clrfunc.cpp', - 'src/mono/clrfuncinvokecontext.cpp', - 'src/mono/monoembedding.cpp', - 'src/mono/task.cpp', - 'src/mono/dictionary.cpp', - 'src/mono/nodejsfunc.cpp', - 'src/mono/nodejsfuncinvokecontext.cpp', - 'src/mono/utils.cpp', - 'src/common/utils.cpp', - 'src/common/v8synchronizationcontext.cpp', - 'src/common/callbackhelper.cpp', - 'src/common/edge.cpp' - ], - 'conditions': - [ - [ - '"/dev/null) || echo not_found)"!="not_found"', - { - 'include_dirs': [ - '/dev/null) || echo not_found)"=="not_found"', - { - 'include_dirs': [ - '/dev/null) || echo not_found)"!="not_found"', + { + 'sources+': [ + 'src/mono/clractioncontext.cpp', + 'src/mono/clrfunc.cpp', + 'src/mono/clrfuncinvokecontext.cpp', + 'src/mono/monoembedding.cpp', + 'src/mono/task.cpp', + 'src/mono/dictionary.cpp', + 'src/mono/nodejsfunc.cpp', + 'src/mono/nodejsfuncinvokecontext.cpp', + 'src/mono/utils.cpp', + 'src/common/utils.cpp', + 'src/common/v8synchronizationcontext.cpp', + 'src/common/callbackhelper.cpp', + 'src/common/edge.cpp' + ], + + 'include_dirs': [ + ' -// { -// X509Store store = new X509Store( -// (string)data.storeName, -// (StoreLocation)Enum.Parse(typeof(StoreLocation), (string)data.storeLocation)); -// store.Open(OpenFlags.ReadOnly); -// try -// { -// List result = new List(); -// foreach (X509Certificate2 certificate in store.Certificates) -// { -// result.Add(certificate.Subject); -// } - -// return result; -// } -// finally -// { -// store.Close(); -// } -// } -// */}); - -var listCertificates = edge.func({ - source: function() {/* - - using System.Security.Cryptography; - using System.Collections.Generic; - using System.Security.Cryptography.X509Certificates; - - async (dynamic data) => +var listCertificates = edge.func(function() {/* + #r "System.dll" + + using System.Collections.Generic; + using System.Security.Cryptography.X509Certificates; + + async (dynamic data) => + { + X509Store store = new X509Store( + (string)data.storeName, + (StoreLocation)Enum.Parse(typeof(StoreLocation), (string)data.storeLocation)); + store.Open(OpenFlags.ReadOnly); + try { - X509Store store = new X509Store( - (string)data.storeName, - (StoreLocation)Enum.Parse(typeof(StoreLocation), (string)data.storeLocation)); - store.Open(OpenFlags.ReadOnly); - try + List result = new List(); + foreach (X509Certificate2 certificate in store.Certificates) { - List result = new List(); - foreach (X509Certificate2 certificate in store.Certificates) - { - result.Add(certificate.Subject); - } - - return result; - } - finally - { - store.Close(); + result.Add(certificate.Subject); } + + return result; + } + finally + { + store.Close(); } - */}, - references: [ 'System.Security.Cryptography' ] -}); + } +*/}); var result = listCertificates({ storeName: 'My', storeLocation: 'LocalMachine' }, true); console.log(result); diff --git a/src/common/clrfuncreflectionwrap.cs b/src/common/clrfuncreflectionwrap.cs index 840d4a00..4c260a7b 100644 --- a/src/common/clrfuncreflectionwrap.cs +++ b/src/common/clrfuncreflectionwrap.cs @@ -22,7 +22,7 @@ public static ClrFuncReflectionWrap Create(Assembly assembly, String typeName, S if (wrap.invokeMethod == null) { throw new System.InvalidOperationException( - "Unable to access the CLR method to wrap through reflection. Make sure it is a public instance method."); + $"Unable to access the CLR method to wrap through reflection. Make sure it is a public instance method.\r\nType: {typeName}, Method: {methodName}, Assembly: {assembly.GetName().FullName}"); } return wrap; diff --git a/src/double/Edge.js/Edge.js.csproj b/src/double/Edge.js/Edge.js.csproj index 45eda819..78d05c62 100644 --- a/src/double/Edge.js/Edge.js.csproj +++ b/src/double/Edge.js/Edge.js.csproj @@ -58,7 +58,6 @@ - diff --git a/src/double/Edge.js/dotnetcore/coreclrembedding.cs b/src/double/Edge.js/dotnetcore/coreclrembedding.cs index 1ded9085..7a1e8a86 100644 --- a/src/double/Edge.js/dotnetcore/coreclrembedding.cs +++ b/src/double/Edge.js/dotnetcore/coreclrembedding.cs @@ -287,7 +287,7 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon } string libraryNameFromPath = Path.GetFileNameWithoutExtension(assemblyPath); - if (!File.Exists(assemblyPath)) + if (!File.Exists(assemblyPath) && !string.IsNullOrEmpty(runtimePath)) { assemblyPath = Path.Combine(runtimePath, Path.GetFileName(assemblyPath)); } @@ -391,7 +391,7 @@ private void AddNativeAssemblies(DependencyContext dependencyContext, RuntimeLib foreach (var nativeAssembly in nativeAssemblies) { var nativeAssemblyPath = Path.Combine(_packagesPath, runtimeLibrary.Name, runtimeLibrary.Version, nativeAssembly.Replace('/', Path.DirectorySeparatorChar)); - if (!File.Exists(nativeAssemblyPath)) + if (!File.Exists(nativeAssemblyPath) && !string.IsNullOrEmpty(runtimePath)) { nativeAssemblyPath = Path.Combine(runtimePath, nativeAssembly.Replace('/', Path.DirectorySeparatorChar)); } @@ -415,6 +415,11 @@ private void AddCompileDependencyFromRuntime(RuntimeLibrary runtimeLibrary) { var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath); DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing compile dependency {1} {0} using runtime path {2}", runtimeLibrary.Name, runtimeLibrary.Type, runtimePath); + if (string.IsNullOrEmpty(runtimePath)) + { + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - runtime path could not be resolved, skipping"); + return; + } if (!CompileAssemblies.ContainsKey(runtimeLibrary.Name)) { @@ -469,7 +474,7 @@ private void AddCompileDependencies(DependencyContext dependencyContext, bool st assemblyPath = Path.Combine(_packagesPath, compileLibrary.Name.ToLower(), compileLibrary.Version, compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar)); } - if (!File.Exists(assemblyPath)) + if (!File.Exists(assemblyPath) && !string.IsNullOrEmpty(runtimePath)) { assemblyPath = Path.Combine(runtimePath, Path.GetFileName(assemblyPath)); } diff --git a/test/test.csproj b/test/test.csproj index 2538187d..0a0cb54a 100644 --- a/test/test.csproj +++ b/test/test.csproj @@ -36,7 +36,6 @@ -