Skip to content

Commit

Permalink
merging from master
Browse files Browse the repository at this point in the history
  • Loading branch information
agracio committed May 8, 2024
1 parent 6785e98 commit 610e5da
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 122 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ tools/build
/test/Properties/
/test/test.nuget.cache

package-lock.json

tools/nuget/content
tools/nuget/lib
tools/nuget/*.nupkg
Expand Down
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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`| <a href="https://github.com/agracio/edge-sql" target="_blank">Script T-SQL in Node.js</a> :link: |
| .NET Standard | Any | `edge-sql` | `sql`| <a href="https://github.com/agracio/edge-sql" target="_blank">Script T-SQL in Node.js</a> :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
----
Expand Down Expand Up @@ -308,7 +308,14 @@ getPerson({name: 'John Smith', email: 'john.smith@myemailprovider', age: 35}, fu

```

### :exclamation: `edge.func()` only supports `public async Task<object> MyMethod(dynamic input)` C# methods.
### Edge.js C# method must have the following signature

```cs
public async Task<object> MyMethod(dynamic input)
{
//return results sync/async;
}
```

### Executing synchronously without function callback

Expand Down Expand Up @@ -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
Expand Down
76 changes: 32 additions & 44 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -204,50 +204,38 @@
[
'"<!((which mono 2>/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':
[
[
'"<!((pkg-config mono-2 --libs 2>/dev/null) || echo not_found)"!="not_found"',
{
'include_dirs': [
'<!@(pkg-config mono-2 --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config glib-2.0 --cflags-only-I | sed s/-I//g)',
],
'link_settings': {
'libraries': [
'<!@(pkg-config mono-2 --libs)'
]
}
},
'"<!((pkg-config mono-2 --libs 2>/dev/null) || echo not_found)"=="not_found"',
{
'include_dirs': [
'<!@(<(DFLT_PKG_CONFIG_PATH) pkg-config mono-2 --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config glib-2.0 --cflags-only-I | sed s/-I//g)',
],
'link_settings': {
'libraries': [
'<!@(<(DFLT_PKG_CONFIG_PATH) pkg-config mono-2 --libs)'
]
}
}
]
],
'conditions': [
[
'"<!((pkg-config mono-2 --libs 2>/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': [
'<!@(pkg-config mono-2 --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config glib-2.0 --cflags-only-I | sed s/-I//g)',
],
'link_settings': {
'libraries': [
'<!@(pkg-config mono-2 --libs)'
]
}
}
]
],
},
{
'type': 'none'
Expand Down
1 change: 0 additions & 1 deletion lib/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var versionMap = [
[ /^16\./, '16.20.2' ],
[ /^18\./, '18.19.1' ],
[ /^20\./, '20.11.1' ],
[ /^21\./, '21.7.1' ],
[ /^22\./, '22.1.0' ],
];

Expand Down
Binary file removed lib/native/win32/ia32/21.7.1/edge_coreclr.node
Binary file not shown.
Binary file removed lib/native/win32/ia32/21.7.1/edge_nativeclr.node
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "http://tomasz.janczuk.org",
"twitter": "tjanczuk"
},
"version": "22.1.0",
"version": "22.1.1",
"description": "Edge.js: run .NET and Node.js in-process on Windows, Mac OS, and Linux",
"tags": [
"owin",
Expand Down
81 changes: 24 additions & 57 deletions samples/203_x509store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,34 @@

var edge = require('../lib/edge');

// var listCertificates = edge.func(function() {/*
// //#r "System.Security.Cryptography"

// using System.Security.Cryptography;
// 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
// {
// List<string> result = new List<string>();
// 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<string> result = new List<string>();
foreach (X509Certificate2 certificate in store.Certificates)
{
List<string> result = new List<string>();
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);
2 changes: 1 addition & 1 deletion src/common/clrfuncreflectionwrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/double/Edge.js/Edge.js.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.9.2" />
Expand Down
11 changes: 8 additions & 3 deletions src/double/Edge.js/dotnetcore/coreclrembedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand All @@ -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))
{
Expand Down Expand Up @@ -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));
}
Expand Down
1 change: 0 additions & 1 deletion test/test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.9.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

Expand Down

0 comments on commit 610e5da

Please sign in to comment.