From b00548e6aec97fc184aca945aa8f7dfe5754c7d1 Mon Sep 17 00:00:00 2001 From: agracio Date: Wed, 8 May 2024 16:48:42 +0100 Subject: [PATCH] merging from master --- .github/workflows/main.yml | 64 ++++++++++++--------- .gitignore | 3 +- README.md | 30 ++++------ appveyor.yml | 2 +- binding.gyp | 76 +++++++++++-------------- package-lock.json | 38 ++++++------- package.json | 2 +- src/common/clrfuncreflectionwrap.cs | 2 +- tools/coverage.js | 88 ----------------------------- 9 files changed, 105 insertions(+), 200 deletions(-) delete mode 100644 tools/coverage.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2f67b7ff..38c96445 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Main +name: CI on: push: @@ -14,21 +14,30 @@ on: - 'Dockerfile' - '.gitconfig' - '.gitignore' - - 'appveyor.*' + - 'appveyor*.*' - 'LICENSE*' - '.idea/**' - '.vscode/**' + - '*.bat' + - '*.nuspec' + - 'tools/nuget/*' + - '.npmignore' + - 'test/config.json' + - 'test/config.json' + - 'test/double' env: ACTIONS_ALLOW_UNSECURE_COMMANDS: true # required to setup CSC jobs: - main: + build-test: runs-on: ${{ matrix.os }} strategy: matrix: - os: [macos-latest, ubuntu-latest, windows-2019] - node: [21.x, 20.x, 18.x, 16.x] + # os: [macos-latest, ubuntu-latest, windows-2019] + # node: [21.x, 20.x, 18.x, 16.x] + os: [macos-14] + node: [20.x] steps: - name: Checkout code uses: actions/checkout@v4 @@ -47,42 +56,43 @@ jobs: with: dotnet-version: '8.0.x' # SDK Version to use; x will use the latest version of the 8.0 channel - - if: runner.os == 'macOS' - name: Remove Mono from macOS # Mono interferes with Core CLR gyp compile - run: | - sudo rm -rf /Library/Frameworks/Mono.framework - sudo pkgutil --forget com.xamarin.mono-MDK.pkg - sudo rm /etc/paths.d/mono-commands + - name: Versions + run: node -v && npm -v && dotnet --version && node -p process.platform && node -p process.arch + + # - if: runner.os == 'macOS' + # name: Mono + # run: | + # which mono + # export PKG_CONFIG_PATH="/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig":$PKG_CONFIG_PATH + # name: Remove Mono from macOS # Incomplete Mono install interferes with gyp compile + # run: | + # sudo rm -rf /Library/Frameworks/Mono.framework + # sudo pkgutil --forget com.xamarin.mono-MDK.pkg + # sudo rm /etc/paths.d/mono-commands - if: runner.os == 'macOS' && matrix.node == '16.x' - name: Add missing packages for macOS NodeJs 16 # Mono interferes with Core CLR gyp compile + name: Add missing packages for macOS NodeJs 16 run: | pip install setuptools - name: npm install - run: npm i + run: npm ci - if: runner.os == 'Windows' name: Run .NET 4.x tests - run: npm test - - if: runner.os == 'Windows' - name: Create .NET 4.x tests report - run: node tools/coverage.js + run: node tools/test.js CI - name: "Run .net core tests" - run: npm test - env: - EDGE_USE_CORECLR: 1 - - - name: "Create .net core tests report" - run: node tools/coverage.js + run: node tools/test.js CI env: EDGE_USE_CORECLR: 1 - name: Test Report - uses: dorny/test-reporter@v1 + uses: phoenix-actions/test-reporting@v15 + if: success() with: - name: Test results (${{ matrix.os }}, ${{ matrix.node }}) # Name of the check run which will be created - path: test-results.xml # Path to test results - reporter: jest-junit # Format of test results + name: Tests (${{ matrix.os }}, ${{ matrix.node }}) # Name of the check run which will be created + path: mochawesome.json # Path to test results + reporter: mochawesome-json + fail-on-error: false diff --git a/.gitignore b/.gitignore index 1d9ac77e..f6090290 100644 --- a/.gitignore +++ b/.gitignore @@ -72,7 +72,8 @@ tools/*.nupkg tools/*.zip tools/nuget.exe -test-results*.* +*test-results*.* +TemporaryGeneratedFile*.* /lib/native/win32/ia32/*/concrt140.dll /lib/native/win32/ia32/*/msvcp140.dll /lib/native/win32/ia32/*/vccorlib140.dll diff --git a/README.md b/README.md index 5164de18..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. @@ -47,19 +47,6 @@ For use with Electron refer to `electron-edge-js` https://github.com/agracio/ele Sample app that shows how to work with .NET Core using inline code and compiled C# libraries. https://github.com/agracio/edge-js-quick-start -## macOS - -`edge-js` will fail to build on macOS if Visual Studio for Mac is installed. -VS installs incomplete Mono runtimes that `edge-js` fails to access during `npm install`. -Removing VS does not remove Mono fully and leaves behind an incomplete Mono install. -To remove Mono from macOS use this script - -```bash -sudo rm -rf /Library/Frameworks/Mono.framework -sudo pkgutil --forget com.xamarin.mono-MDK.pkg -sudo rm /etc/paths.d/mono-commands -``` - ## Node.Js Versions | Version | Status | @@ -116,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 @@ -321,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 @@ -2001,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/appveyor.yml b/appveyor.yml index 21332204..65ddd360 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,7 +17,7 @@ environment: - nodejs: "16" install: - - sh: if [ "$APPVEYOR_BUILD_WORKER_IMAGE" = 'Ubuntu2204' ]; then sudo apt-get -qq update && sudo apt-get -y -qq install build-essential libgconf-2-4 python3 libglib2.0-dev; fi + # - sh: if [ "$APPVEYOR_BUILD_WORKER_IMAGE" = 'Ubuntu2204' ]; then sudo apt-get -qq update && sudo apt-get -y -qq install build-essential libgconf-2-4 python3 libglib2.0-dev; fi # - cmd: powershell .\appveyor.ps1 - cmd: powershell Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs) x64 - sh: nvm ls 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': [ + '=16" + "node": ">=18" } }, "node_modules/concat-map": { @@ -1649,12 +1649,12 @@ } }, "node_modules/junit-report-merger": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/junit-report-merger/-/junit-report-merger-6.0.3.tgz", - "integrity": "sha512-gtGHrq+otZLtSP1FPDSKYiFkDayCoEx1wslgzodLVxckwL8XgdbQlko1mz9wdXqieeniCQjkJFrTtqDEsTWzTQ==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/junit-report-merger/-/junit-report-merger-7.0.0.tgz", + "integrity": "sha512-i7IYPpwVFpju+UKdxYIG9UTMb6NjfRGzWzE/lRExdEf4K3agqXtVBnJWhL9aMM2lNX7uWW/rhVidiDBsG4n5cw==", "dev": true, "dependencies": { - "commander": "~11.1.0", + "commander": "~12.0.0", "fast-glob": "~3.3.0", "xmlbuilder2": "3.1.1" }, @@ -1663,7 +1663,7 @@ "junit-report-merger": "cli.js" }, "engines": { - "node": ">=14" + "node": ">=18" } }, "node_modules/locate-path": { @@ -3839,9 +3839,9 @@ "dev": true }, "commander": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", - "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.0.0.tgz", + "integrity": "sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==", "dev": true }, "concat-map": { @@ -4534,12 +4534,12 @@ } }, "junit-report-merger": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/junit-report-merger/-/junit-report-merger-6.0.3.tgz", - "integrity": "sha512-gtGHrq+otZLtSP1FPDSKYiFkDayCoEx1wslgzodLVxckwL8XgdbQlko1mz9wdXqieeniCQjkJFrTtqDEsTWzTQ==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/junit-report-merger/-/junit-report-merger-7.0.0.tgz", + "integrity": "sha512-i7IYPpwVFpju+UKdxYIG9UTMb6NjfRGzWzE/lRExdEf4K3agqXtVBnJWhL9aMM2lNX7uWW/rhVidiDBsG4n5cw==", "dev": true, "requires": { - "commander": "~11.1.0", + "commander": "~12.0.0", "fast-glob": "~3.3.0", "xmlbuilder2": "3.1.1" } diff --git a/package.json b/package.json index 3d61f10a..e91939b3 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "devDependencies": { "follow-redirects": "^1.15.6", - "junit-report-merger": "6.0.3", + "junit-report-merger": "7.0.0", "mocha": "10.4.0", "mocha-junit-reporter": "^2.2.1", "mocha-multi-reporters": "^1.5.1", 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/tools/coverage.js b/tools/coverage.js deleted file mode 100644 index 0a628594..00000000 --- a/tools/coverage.js +++ /dev/null @@ -1,88 +0,0 @@ -var spawn = require('child_process').spawn; -var path = require('path'); -var testDir = path.resolve(__dirname, '../test'); -var input = path.resolve(testDir, 'tests.cs'); -var output = path.resolve(testDir, 'Edge.Tests.dll'); -var buildParameters = ['-target:library', '/debug', '-out:' + output, input]; -var mocha = path.resolve(__dirname, '../node_modules/mocha/bin/mocha'); -var xunit = path.resolve(__dirname, '../node_modules/xunit-viewer/bin/xunit-viewer'); -var fs = require('fs'); -const merge = require('junit-report-merger'); - -if (!process.env.EDGE_USE_CORECLR) { - run(process.platform === 'win32' ? 'csc' : 'mcs', buildParameters, runOnSuccess, 'net'); -} - -else { - run(process.platform === 'win32' ? 'dotnet.exe' : 'dotnet', ['restore'], function(code, signal) { - if (code === 0) { - run(process.platform === 'win32' ? 'dotnet.exe' : 'dotnet', ['build'], runOnSuccess, 'coreclr'); - } - }); -} - -function run(cmd, args, onClose, signal){ - - var params = process.env.EDGE_USE_CORECLR ? {cwd: testDir} : {}; - var command = spawn(cmd, args, params); - var result = ''; - var error = ''; - command.stdout.on('data', function(data) { - result += data.toString(); - }); - command.stderr.on('data', function(data) { - error += data.toString(); - }); - - command.on('error', function(err) { - console.log(error); - console.log(err); - }); - - command.on('close', function(code){ - //console.log(result); - onClose(code, signal); - }); -} - -function runOnSuccess(code, framework) { - if (code === 0) { - process.env['EDGE_APP_ROOT'] = path.join(testDir, 'bin', 'Debug', 'net6.0'); - - createJunitReports(framework, false); - //createJunitReports(framework, true); - } -} - -function createJunitReports(framework, createHtml){ - let suffix = createHtml ? '-xunit-viewer' : ''; - spawn('node', [mocha, testDir, '-R', 'mocha-junit-reporter', '-t', '10000', '-n', 'expose-gc', '--reporter-options', `mochaFile=./test-results-${framework}${suffix}.xml,testCaseSwitchClassnameAndName=${createHtml ? 'true' : ''}`], { - stdio: 'inherit' - }).on('close', function(code) { - let source = []; - if(fs.existsSync(`./test-results-coreclr${suffix}.xml`)){ - source.push(`./test-results-coreclr${suffix}.xml`); - } - if(fs.existsSync(`./test-results-net${suffix}.xml`)){ - source.push(`./test-results-net${suffix}.xml`); - } - merge.mergeFiles(`./test-results${suffix}.xml`, source, function(err) { - if(err) - { - console.log(err) - }else{ - if(createHtml){ - spawn('node', [xunit, '--results=test-results-xunit-viewer.xml','--output=test-results-xunit-viewer.html'], { - stdio: 'inherit' - }).on('close', function(code) { - }).on('error', function(err) { - console.log(err); - }); - } - } - }) - }).on('error', function(err) { - console.log(err); - }); -} -