diff --git a/package-lock.json b/package-lock.json index eba35cc4..334fa4ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "edge-js", - "version": "23.1.1", + "version": "23.1.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "edge-js", - "version": "23.1.1", + "version": "23.1.2", "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -16,7 +16,7 @@ "devDependencies": { "follow-redirects": "^1.15.9", "junit-report-merger": "7.0.0", - "mocha": "10.8.1", + "mocha": "10.8.2", "mocha-junit-reporter": "^2.2.1", "mocha-multi-reporters": "^1.5.1", "mochawesome": "^7.1.3", @@ -911,9 +911,9 @@ } }, "node_modules/mocha": { - "version": "10.8.1", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.8.1.tgz", - "integrity": "sha512-WxSpEWgF03HfgNKBuysfK40DUaOSVX5zxgLDoieMGO+zyE69iq2eQ1vBypvIJ5mOPKpuVAqWiTbt4Orj7L6wVw==", + "version": "10.8.2", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.8.2.tgz", + "integrity": "sha512-VZlYo/WE8t1tstuRmqgeyBgCbJc/lEdopaa+axcKzTBJ+UIdlAB9XnmvTCAH4pwR4ElNInaedhEBmZD8iCSVEg==", "dev": true, "license": "MIT", "dependencies": { @@ -2446,9 +2446,9 @@ "dev": true }, "mocha": { - "version": "10.8.1", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.8.1.tgz", - "integrity": "sha512-WxSpEWgF03HfgNKBuysfK40DUaOSVX5zxgLDoieMGO+zyE69iq2eQ1vBypvIJ5mOPKpuVAqWiTbt4Orj7L6wVw==", + "version": "10.8.2", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.8.2.tgz", + "integrity": "sha512-VZlYo/WE8t1tstuRmqgeyBgCbJc/lEdopaa+axcKzTBJ+UIdlAB9XnmvTCAH4pwR4ElNInaedhEBmZD8iCSVEg==", "dev": true, "requires": { "ansi-colors": "^4.1.3", diff --git a/package.json b/package.json index daf57b9e..05f78381 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "url": "http://tomasz.janczuk.org", "twitter": "tjanczuk" }, - "version": "23.1.1", + "version": "23.1.2", "description": "Edge.js: run .NET and Node.js in-process on Windows, Mac OS, and Linux", "tags": [ "owin", @@ -45,7 +45,7 @@ "devDependencies": { "follow-redirects": "^1.15.9", "junit-report-merger": "7.0.0", - "mocha": "10.8.1", + "mocha": "10.8.2", "mocha-junit-reporter": "^2.2.1", "mocha-multi-reporters": "^1.5.1", "mochawesome": "^7.1.3", diff --git a/src/double/Edge.js/dotnetcore/coreclrembedding.cs b/src/double/Edge.js/dotnetcore/coreclrembedding.cs index ed6eb2f6..b5714a25 100644 --- a/src/double/Edge.js/dotnetcore/coreclrembedding.cs +++ b/src/double/Edge.js/dotnetcore/coreclrembedding.cs @@ -12,10 +12,11 @@ using System.Threading.Tasks; using System.IO; using Microsoft.Extensions.DependencyModel; + // ReSharper disable InconsistentNaming +// ReSharper disable once CheckNamespace [StructLayout(LayoutKind.Sequential)] -// ReSharper disable once CheckNamespace public struct V8ObjectData { public int propertiesCount; @@ -95,6 +96,10 @@ public EdgeRuntimeEnvironment(EdgeBootstrapperContext bootstrapperContext) RuntimePath = bootstrapperContext.RuntimeDirectory; DependencyManifestFile = bootstrapperContext.DependencyManifestFile; StandaloneApplication = Path.GetDirectoryName(RuntimePath) == ApplicationDirectory; + DebugMessage("EdgeRuntimeEnvironment::ctor (CLR) - ApplicationDirectory {0}", ApplicationDirectory); + DebugMessage("EdgeRuntimeEnvironment::ctor (CLR) - RuntimePath {0}", RuntimePath); + DebugMessage("EdgeRuntimeEnvironment::ctor (CLR) - DependencyManifestFile {0}", DependencyManifestFile); + DebugMessage("EdgeRuntimeEnvironment::ctor (CLR) - StandaloneApplication {0}", StandaloneApplication); } public string RuntimePath @@ -244,7 +249,6 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon AddCompileDependencies(dependencyContext, standalone); - Dictionary supplementaryRuntimeLibraries = new Dictionary(); var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath); foreach (RuntimeLibrary runtimeLibrary in dependencyContext.RuntimeLibraries) @@ -263,7 +267,6 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon AddSupplementaryRuntime(runtimeLibrary); continue; } - List assets = runtimeLibrary.RuntimeAssemblyGroups.GetRuntimeAssets(RuntimeInformation.RuntimeIdentifier).ToList(); @@ -286,7 +289,9 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon assemblyPath = Path.Combine(_packagesPath, runtimeLibrary.Name.ToLower(), runtimeLibrary.Version, assetPath.Replace('/', Path.DirectorySeparatorChar).ToLower()); if(!File.Exists(assemblyPath)) assemblyPath = Path.Combine(_packagesPath, runtimeLibrary.Name.ToLower(), runtimeLibrary.Version, assetPath.Replace('/', Path.DirectorySeparatorChar)); + } + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Assembly path {0}", assemblyPath); string libraryNameFromPath = Path.GetFileNameWithoutExtension(assemblyPath); if (!File.Exists(assemblyPath) && !string.IsNullOrEmpty(runtimePath)) @@ -300,71 +305,29 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon { _libraries[runtimeLibrary.Name] = assemblyPath; DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added runtime assembly {1} from {0}", assemblyPath, runtimeLibrary.Name); + CompileAssemblies.TryAdd(runtimeLibrary.Name, assemblyPath); + if (!string.Equals(runtimeLibrary.Name, libraryNameFromPath, StringComparison.CurrentCultureIgnoreCase)) + { + _libraries.TryAdd(libraryNameFromPath, assemblyPath); + CompileAssemblies.TryAdd(libraryNameFromPath, assemblyPath); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added supplementary runtime assembly {1} from {0}", assemblyPath, libraryNameFromPath); + } } else { - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not resolve runtime assembly {0}", - assemblyPath); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not resolve runtime assembly {0}", assemblyPath); } } - else { DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Already present in the runtime assemblies list, skipping"); } - - if (runtimeLibrary.Name != libraryNameFromPath && !_libraries.ContainsKey(libraryNameFromPath)) - { - if (File.Exists(assemblyPath)) - { - supplementaryRuntimeLibraries[libraryNameFromPath] = assemblyPath; - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added supplementary runtime assembly {1} from {0}", assemblyPath, libraryNameFromPath); - } - else - { - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not resolve supplementary runtime assembly {0}", - assemblyPath); - } - } - - if (!CompileAssemblies.ContainsKey(runtimeLibrary.Name)) - { - if (File.Exists(assemblyPath)) - { - CompileAssemblies[runtimeLibrary.Name] = assemblyPath; - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added compile assembly {1} from {0}", assemblyPath, runtimeLibrary.Name); - } - else - { - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not resolve compile assembly {0}", assemblyPath); - } - } - - else - { - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Already present in the compile assemblies list, skipping"); - } } else { DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - RuntimeAssemblyGroups does not have RuntimeAssets or DefaultAssets"); - if (!CompileAssemblies.ContainsKey(runtimeLibrary.Name)) AddCompileDependencyFromRuntime(runtimeLibrary); - } - - foreach (string libraryName in supplementaryRuntimeLibraries.Keys) - { - if (!_libraries.ContainsKey(libraryName)) - { - DebugMessage( - "EdgeAssemblyResolver::AddDependencies (CLR) - Filename in the dependency context did not match the package/project name, added additional resolver for {0}", - libraryName); - _libraries[libraryName] = supplementaryRuntimeLibraries[libraryName]; - } - - if (!CompileAssemblies.ContainsKey(libraryName)) - { - CompileAssemblies[libraryName] = supplementaryRuntimeLibraries[libraryName]; - } + if (!CompileAssemblies.ContainsKey(runtimeLibrary.Name) || !_libraries.ContainsKey(runtimeLibrary.Name)) AddDependencyFromRuntime(runtimeLibrary); + if (!CompileAssemblies.ContainsKey(runtimeLibrary.Name) || !_libraries.ContainsKey(runtimeLibrary.Name)) AddDependencyFromAppDirectory(runtimeLibrary); } AddNativeAssemblies(dependencyContext, runtimeLibrary); @@ -374,10 +337,11 @@ private void AddDependencies(DependencyContext dependencyContext, bool standalon private void AddSupplementaryRuntime(RuntimeLibrary runtimeLibrary) { var libraryNameFromPath = Path.GetFileNameWithoutExtension(_libraries[runtimeLibrary.Name]); - if (runtimeLibrary.Name != libraryNameFromPath) + if (!string.Equals(runtimeLibrary.Name, libraryNameFromPath, StringComparison.CurrentCultureIgnoreCase)) { _libraries.TryAdd(libraryNameFromPath, _libraries[runtimeLibrary.Name]); CompileAssemblies.TryAdd(libraryNameFromPath, _libraries[runtimeLibrary.Name]); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added supplementary runtime assembly {1} from {0}", _libraries[runtimeLibrary.Name], libraryNameFromPath); } } @@ -401,55 +365,103 @@ private void AddNativeAssemblies(DependencyContext dependencyContext, RuntimeLib if (File.Exists(nativeAssemblyPath)) { _nativeLibraries[Path.GetFileNameWithoutExtension(nativeAssembly)] = nativeAssemblyPath; - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Adding native assembly {0} at {1}", - Path.GetFileNameWithoutExtension(nativeAssembly), nativeAssemblyPath); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Adding native assembly {0} at {1}", Path.GetFileNameWithoutExtension(nativeAssembly), nativeAssemblyPath); } else { - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not resolve native assembly {0} at {1}", - Path.GetFileNameWithoutExtension(nativeAssembly), nativeAssemblyPath); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not resolve native assembly {0} at {1}", Path.GetFileNameWithoutExtension(nativeAssembly), nativeAssemblyPath); } } } } - private void AddCompileDependencyFromRuntime(RuntimeLibrary runtimeLibrary) + private void AddDependencyFromRuntime(RuntimeLibrary runtimeLibrary) { + if (CompileAssemblies.ContainsKey(runtimeLibrary.Name) && _libraries.ContainsKey(runtimeLibrary.Name)) return; + var runtimePath = Path.GetDirectoryName(RuntimeEnvironment.RuntimePath); - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing compile dependency {1} {0} using runtime path {2}", runtimeLibrary.Name, runtimeLibrary.Type, runtimePath); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing 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; } + + var asset = runtimeLibrary.Name; + if (!asset.EndsWith(".dll")) + { + asset += ".dll"; + } + + if (asset == "runtime.native.System.dll") + { + asset = "System.dll"; + } - if (!CompileAssemblies.ContainsKey(runtimeLibrary.Name)) + var assemblyPath = Path.Combine(runtimePath, Path.GetFileName(asset)); + if (File.Exists(assemblyPath)) { - var asset = runtimeLibrary.Name; - if (!asset.EndsWith(".dll")) + CompileAssemblies.TryAdd(runtimeLibrary.Name, assemblyPath); + _libraries.TryAdd(runtimeLibrary.Name, assemblyPath); + + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added dependency {1} from {0}", assemblyPath, runtimeLibrary.Name); + + var libraryNameFromPath = Path.GetFileNameWithoutExtension(assemblyPath); + if (!string.Equals(runtimeLibrary.Name, libraryNameFromPath, StringComparison.CurrentCultureIgnoreCase)) { - asset += ".dll"; + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added supplementary assembly {1} from {0}", assemblyPath, libraryNameFromPath); + CompileAssemblies.TryAdd(libraryNameFromPath, assemblyPath); + _libraries.TryAdd(libraryNameFromPath, assemblyPath); } + } + else + { + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not add dependency {0}", assemblyPath); + } - if (asset == "runtime.native.System.dll") - { - asset = "System.dll"; - } + } + + private void AddDependencyFromAppDirectory(RuntimeLibrary runtimeLibrary) + { + if (CompileAssemblies.ContainsKey(runtimeLibrary.Name) && _libraries.ContainsKey(runtimeLibrary.Name)) return; + + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing dependency {1} {0} using .nuget packages and ApplicationDirectory path.", runtimeLibrary.Name, runtimeLibrary.Type); - var assemblyPath = Path.Combine(runtimePath, Path.GetFileName(asset)); - if (File.Exists(assemblyPath)) - { - CompileAssemblies[runtimeLibrary.Name] = assemblyPath; - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added compile dependency {1} from {0}", assemblyPath, runtimeLibrary.Name); - } - else + var asset = runtimeLibrary.Name; + if (!asset.EndsWith(".dll")) + { + asset += ".dll"; + } + + if (asset == "runtime.native.System.dll") + { + asset = "System.dll"; + } + + var assemblyPath = Path.Combine(_packagesPath, runtimeLibrary.Name.ToLower(), runtimeLibrary.Version, Path.GetFileName(asset)); + + if(!File.Exists(assemblyPath)) + { + assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(asset)); + } + if (File.Exists(assemblyPath)) + { + CompileAssemblies.TryAdd(runtimeLibrary.Name, assemblyPath); + _libraries.TryAdd(runtimeLibrary.Name, assemblyPath); + + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added dependency {1} from {0}", assemblyPath, runtimeLibrary.Name); + + var libraryNameFromPath = Path.GetFileNameWithoutExtension(assemblyPath); + if (!string.Equals(runtimeLibrary.Name, libraryNameFromPath, StringComparison.CurrentCultureIgnoreCase)) { - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not add compile dependency {0}", assemblyPath); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added supplementary assembly {1} from {0}", assemblyPath, libraryNameFromPath); + CompileAssemblies.TryAdd(libraryNameFromPath, assemblyPath); + _libraries.TryAdd(libraryNameFromPath, assemblyPath); } } else { - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Already present in compile dependency list, skipping"); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not add dependency {0}", assemblyPath); } } @@ -463,26 +475,37 @@ private void AddCompileDependencies(DependencyContext dependencyContext, bool st continue; } - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing compile assembly {1} {0} {2}", compileLibrary.Name, compileLibrary.Type, compileLibrary.Assemblies[0]); - var assemblyPath = compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar); + var normalizedPath = compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar); + + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Processing compile assembly {1} {0} {2}", compileLibrary.Name, compileLibrary.Type, compileLibrary.Assemblies[0]); if (standalone) { - if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar))))) + if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)))) + { + assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)); + } + else if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(normalizedPath)))) { - assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar))); + assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, "refs", Path.GetFileName(normalizedPath)); } - else if(!string.IsNullOrEmpty(runtimePath) && File.Exists(Path.Combine(runtimePath, Path.GetFileName(compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar))))) + else if(!string.IsNullOrEmpty(runtimePath) && File.Exists(Path.Combine(runtimePath, Path.GetFileName(normalizedPath)))) { - assemblyPath = Path.Combine(runtimePath, Path.GetFileName(compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar))); + assemblyPath = Path.Combine(runtimePath, Path.GetFileName(normalizedPath)); } } else { - assemblyPath = Path.Combine(_packagesPath, compileLibrary.Name.ToLower(), compileLibrary.Version, compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar).ToLower()); - if(!File.Exists(assemblyPath)) - assemblyPath = Path.Combine(_packagesPath, compileLibrary.Name.ToLower(), compileLibrary.Version, compileLibrary.Assemblies[0].Replace('/', Path.DirectorySeparatorChar)); + assemblyPath = Path.Combine(_packagesPath, compileLibrary.Name.ToLower(), compileLibrary.Version, normalizedPath.ToLower()); + if(!File.Exists(assemblyPath)) + { + assemblyPath = Path.Combine(_packagesPath, compileLibrary.Name.ToLower(), compileLibrary.Version, normalizedPath); + } + if(!File.Exists(assemblyPath) && File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)))) + { + assemblyPath = Path.Combine(RuntimeEnvironment.ApplicationDirectory, Path.GetFileName(normalizedPath)); + } } if (!File.Exists(assemblyPath) && !string.IsNullOrEmpty(runtimePath)) @@ -492,17 +515,22 @@ private void AddCompileDependencies(DependencyContext dependencyContext, bool st if (!CompileAssemblies.ContainsKey(compileLibrary.Name)) { + var libraryNameFromPath = Path.GetFileNameWithoutExtension(assemblyPath); if (File.Exists(assemblyPath)) { CompileAssemblies[compileLibrary.Name] = assemblyPath; - DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added compile assembly {0}", assemblyPath); + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added compile assembly {1} from {0}", assemblyPath, compileLibrary.Name); + if (!string.Equals(compileLibrary.Name, libraryNameFromPath, StringComparison.CurrentCultureIgnoreCase)) + { + DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Added supplementary compile assembly {1} from {0}", assemblyPath, libraryNameFromPath); + CompileAssemblies.TryAdd(libraryNameFromPath, assemblyPath); + } } else { DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Could not add compile assembly {0}", assemblyPath); } } - else { DebugMessage("EdgeAssemblyResolver::AddDependencies (CLR) - Already present in the compile assemblies list, skipping"); @@ -848,7 +876,7 @@ public static void CallFunc(IntPtr function, IntPtr payload, int payloadType, In Task functionTask = wrapperFunc(MarshalV8ToCLR(payload, (V8Type)payloadType)); - // Read the task status only once - you can't assume that an asychronous task's state won't change between reads + // Read the task status only once - you can't assume that an asynchronous task's state won't change between reads TaskStatus taskStatus = functionTask.Status; Marshal.WriteInt32(taskState, (int)taskStatus); @@ -893,9 +921,7 @@ public static void CallFunc(IntPtr function, IntPtr payload, int payloadType, In { DebugMessage("CoreCLREmbedding::CallFunc (CLR) - Exception was thrown: {0}{1}{2}", e.Message, Environment.NewLine, e.StackTrace); - V8Type v8Type; - - Marshal.WriteIntPtr(result, MarshalCLRToV8(e, out v8Type)); + Marshal.WriteIntPtr(result, MarshalCLRToV8(e, out var v8Type)); Marshal.WriteInt32(resultType, (int)v8Type); Marshal.WriteInt32(taskState, (int)TaskStatus.Faulted); } @@ -1254,8 +1280,7 @@ public static IntPtr MarshalCLRToV8(object clrObject, out V8Type v8Type) foreach (object key in keys) { Marshal.WriteIntPtr(objectData.propertyNames, counter*PointerSize, Marshal.StringToCoTaskMemUTF8(key.ToString())); - V8Type propertyType; - Marshal.WriteIntPtr(objectData.propertyValues, counter*PointerSize, MarshalCLRToV8(getValue(key), out propertyType)); + Marshal.WriteIntPtr(objectData.propertyValues, counter*PointerSize, MarshalCLRToV8(getValue(key), out var propertyType)); Marshal.WriteInt32(objectData.propertyTypes, counter*sizeof (int), (int) propertyType); counter++; @@ -1277,9 +1302,7 @@ public static IntPtr MarshalCLRToV8(object clrObject, out V8Type v8Type) foreach (object item in (IEnumerable) clrObject) { - V8Type itemType; - - itemValues.Add(MarshalCLRToV8(item, out itemType)); + itemValues.Add(MarshalCLRToV8(item, out var itemType)); itemTypes.Add((int) itemType); }