@nativescript/windows 0.1.0-alpha.50 → 0.1.0-alpha.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections.Concurrent;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using System.IO;
|
|
5
|
+
using System.Linq;
|
|
3
6
|
using System.Reflection;
|
|
4
7
|
using System.Runtime.InteropServices;
|
|
8
|
+
using System.Runtime.Loader;
|
|
5
9
|
using System.Text.Json;
|
|
6
10
|
|
|
7
11
|
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("DotNetBridgeTests")]
|
|
@@ -24,6 +28,11 @@ public static partial class Bridge
|
|
|
24
28
|
private static readonly ConcurrentDictionary<MethodKey, DispatchEntry> s_methodCache = new();
|
|
25
29
|
private static readonly ConcurrentDictionary<PropKey, PropertyInfo?> s_propCache = new();
|
|
26
30
|
private static readonly ConcurrentDictionary<CtorKey, CtorEntry> s_ctorCache = new();
|
|
31
|
+
// Cache of attempted assembly loads (simple name -> Assembly or null if not found).
|
|
32
|
+
private static readonly ConcurrentDictionary<string, Assembly?> s_assemblyLoadCache
|
|
33
|
+
= new(StringComparer.OrdinalIgnoreCase);
|
|
34
|
+
// Directories to search for assemblies (initialized once in static ctor).
|
|
35
|
+
private static readonly string[] s_assemblySearchDirs;
|
|
27
36
|
|
|
28
37
|
private static readonly JsonSerializerOptions s_coerceOpts = new()
|
|
29
38
|
{
|
|
@@ -40,6 +49,131 @@ public static partial class Bridge
|
|
|
40
49
|
s_nextHandle = 0;
|
|
41
50
|
}
|
|
42
51
|
|
|
52
|
+
// Returns a JSON object mapping top-level namespace roots (e.g. "NativeScript")
|
|
53
|
+
// to the assembly simple-name that most likely contains that namespace's types.
|
|
54
|
+
// This probes the application base directory and libs/ for assemblies and
|
|
55
|
+
// inspects exported types. The result is safe-to-call and tolerant of
|
|
56
|
+
// non-.NET DLLs.
|
|
57
|
+
public static string GetNamespaceAssemblyMapJson()
|
|
58
|
+
{
|
|
59
|
+
var map = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
60
|
+
try
|
|
61
|
+
{
|
|
62
|
+
var baseDir = AppContext.BaseDirectory ?? AppDomain.CurrentDomain.BaseDirectory;
|
|
63
|
+
var dirs = new List<string> { baseDir };
|
|
64
|
+
var libs = Path.Combine(baseDir, "libs");
|
|
65
|
+
if (Directory.Exists(libs))
|
|
66
|
+
{
|
|
67
|
+
dirs.Add(libs);
|
|
68
|
+
try { dirs.AddRange(Directory.GetDirectories(libs, "*", SearchOption.AllDirectories)); } catch { }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
foreach (var dir in dirs.Where(d => !string.IsNullOrEmpty(d) && Directory.Exists(d)))
|
|
72
|
+
{
|
|
73
|
+
try
|
|
74
|
+
{
|
|
75
|
+
foreach (var file in Directory.EnumerateFiles(dir, "*.dll", SearchOption.TopDirectoryOnly))
|
|
76
|
+
{
|
|
77
|
+
try
|
|
78
|
+
{
|
|
79
|
+
var simple = Path.GetFileNameWithoutExtension(file);
|
|
80
|
+
if (string.IsNullOrEmpty(simple)) continue;
|
|
81
|
+
|
|
82
|
+
Assembly asm = AppDomain.CurrentDomain.GetAssemblies()
|
|
83
|
+
.FirstOrDefault(a => string.Equals(a.GetName().Name, simple, StringComparison.OrdinalIgnoreCase));
|
|
84
|
+
if (asm is null)
|
|
85
|
+
{
|
|
86
|
+
try { asm = AssemblyLoadContext.Default.LoadFromAssemblyPath(file); }
|
|
87
|
+
catch { continue; }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Type[] types;
|
|
91
|
+
try { types = asm.GetExportedTypes(); }
|
|
92
|
+
catch { types = Array.Empty<Type>(); }
|
|
93
|
+
|
|
94
|
+
foreach (var t in types)
|
|
95
|
+
{
|
|
96
|
+
if (string.IsNullOrEmpty(t.Namespace)) continue;
|
|
97
|
+
var root = t.Namespace.Split('.')[0];
|
|
98
|
+
if (!map.ContainsKey(root)) map[root] = asm.GetName().Name;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch { }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch { }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch { }
|
|
108
|
+
try { return JsonSerializer.Serialize(map); } catch { return "{}"; }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Static ctor: initialize assembly search directories and register resolver.
|
|
112
|
+
static Bridge()
|
|
113
|
+
{
|
|
114
|
+
try
|
|
115
|
+
{
|
|
116
|
+
var baseDir = AppContext.BaseDirectory ?? AppDomain.CurrentDomain.BaseDirectory;
|
|
117
|
+
var dirs = new List<string> { baseDir };
|
|
118
|
+
var libs = Path.Combine(baseDir, "libs");
|
|
119
|
+
if (Directory.Exists(libs))
|
|
120
|
+
{
|
|
121
|
+
dirs.Add(libs);
|
|
122
|
+
try { dirs.AddRange(Directory.GetDirectories(libs, "*", SearchOption.AllDirectories)); } catch { }
|
|
123
|
+
}
|
|
124
|
+
s_assemblySearchDirs = dirs.Where(d => !string.IsNullOrEmpty(d)).Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
|
|
125
|
+
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
|
|
126
|
+
}
|
|
127
|
+
catch
|
|
128
|
+
{
|
|
129
|
+
s_assemblySearchDirs = Array.Empty<string>();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private static Assembly? OnAssemblyResolve(object? sender, ResolveEventArgs args)
|
|
134
|
+
{
|
|
135
|
+
try
|
|
136
|
+
{
|
|
137
|
+
var requested = new AssemblyName(args.Name).Name;
|
|
138
|
+
if (string.IsNullOrEmpty(requested)) return null;
|
|
139
|
+
|
|
140
|
+
if (s_assemblyLoadCache.TryGetValue(requested, out var cached)) return cached;
|
|
141
|
+
|
|
142
|
+
// Check already-loaded assemblies first (avoid recursive Assembly.Load).
|
|
143
|
+
var loadedAsm = AppDomain.CurrentDomain.GetAssemblies()
|
|
144
|
+
.FirstOrDefault(a => string.Equals(a.GetName().Name, requested, StringComparison.OrdinalIgnoreCase));
|
|
145
|
+
if (loadedAsm is not null)
|
|
146
|
+
{
|
|
147
|
+
s_assemblyLoadCache[requested] = loadedAsm;
|
|
148
|
+
return loadedAsm;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Try to locate a matching dll in known search directories.
|
|
152
|
+
foreach (var dir in s_assemblySearchDirs)
|
|
153
|
+
{
|
|
154
|
+
try
|
|
155
|
+
{
|
|
156
|
+
var candidate = Path.Combine(dir, requested + ".dll");
|
|
157
|
+
if (File.Exists(candidate))
|
|
158
|
+
{
|
|
159
|
+
try
|
|
160
|
+
{
|
|
161
|
+
var asm = AssemblyLoadContext.Default.LoadFromAssemblyPath(candidate);
|
|
162
|
+
s_assemblyLoadCache[requested] = asm;
|
|
163
|
+
return asm;
|
|
164
|
+
}
|
|
165
|
+
catch { }
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch { }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
s_assemblyLoadCache[requested] = null;
|
|
172
|
+
}
|
|
173
|
+
catch { }
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
43
177
|
[UnmanagedCallersOnly(EntryPoint = "RegisterJsCallback",
|
|
44
178
|
CallConvs = [typeof(System.Runtime.CompilerServices.CallConvCdecl)])]
|
|
45
179
|
public static unsafe int RegisterJsCallback(
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|