Skip to content

Commit a866888

Browse files
committedMay 19, 2021
Made changes to the main Jering.Javascript.NodeJS project
- Bumped dependencies. - Improved XML documentation. - Important breaking changes: - Enabled nullable reference types. - Renamed NewCacheIdentifier parameters in INodeJSService to CacheIdentifier. - Renamed NewCacheIdentifier parameters in StaticNodeJSService to CacheIdentifier - Renamed NewCacheIdentifier parameters in HttpNodeJSPoolService to CacheIdentifier - Minor breaking changes: - Renamed InvocationRequest.NewCacheIdentifier to CacheIdentifier. - Removed unused OutOfProcessNodeJSService constructor. - Renamed NewCacheIdentifier parameters in OutOfProcessNodeJSService to CacheIdentifier - Added generators.
1 parent 268be46 commit a866888

27 files changed

+563
-540
lines changed
 

‎src/NodeJS/AssemblyInfo.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System.Resources;
12
using System.Runtime.CompilerServices;
23

34
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
45
[assembly: InternalsVisibleTo("Jering.Javascript.NodeJS.Tests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100ed30e6f1d3e00f6800aec83aee2311af5c6a2a9046f57fcc1618a4e38bcb2e9464ec505e4fe71061fb261b27287fcf1a3582472e8dbb6a145eeee0a0685ea5b4ef147de7c70cc823af6ad573ab12f6c292f43c6980419859d3a365befe2b1f7a043dc95025c51cd428bc86fe43a3fcfcc71cdf2252a08d684659289eb0de37bc")]
56
[assembly: InternalsVisibleTo("Jering.Javascript.NodeJS.Performance,PublicKey=0024000004800000940000000602000000240000525341310004000001000100ed30e6f1d3e00f6800aec83aee2311af5c6a2a9046f57fcc1618a4e38bcb2e9464ec505e4fe71061fb261b27287fcf1a3582472e8dbb6a145eeee0a0685ea5b4ef147de7c70cc823af6ad573ab12f6c292f43c6980419859d3a365befe2b1f7a043dc95025c51cd428bc86fe43a3fcfcc71cdf2252a08d684659289eb0de37bc")]
7+
[assembly: NeutralResourcesLanguage("en")]

‎src/NodeJS/INodeJSService.cs

+148-88
Large diffs are not rendered by default.

‎src/NodeJS/Jering.Javascript.NodeJS.csproj

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PackageId>Jering.Javascript.NodeJS</PackageId>
77
<Authors>JeremyTCD</Authors>
88
<Title>Invoke Javascript in NodeJS, from C#</Title>
9-
<Description>Jering.Javascript.NodeJS enables you to invoke javascript in NodeJS, from C#. With this ability, you can use javascript libraries and scripts from C# projects.</Description>
9+
<Description>Jering.Javascript.NodeJS enables you to invoke javascript in NodeJS, from C#. With this ability, you can use NodeJS javascript libraries and scripts from C# projects.</Description>
1010
<Copyright>© 2018-2021 Jering. All rights reserved.</Copyright>
1111
<PackageProjectUrl>https://www.jering.tech/utilities/jering.javascript.nodejs/index</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/JeringTech/Javascript.NodeJS</RepositoryUrl>
@@ -30,6 +30,8 @@
3030
<AssemblyOriginatorKeyFile>../../keypair.snk</AssemblyOriginatorKeyFile>
3131
<SignAssembly>true</SignAssembly>
3232
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
33+
<Nullable>enable</Nullable>
34+
<!-- So we can use generators -->
3335
<LangVersion>preview</LangVersion>
3436
</PropertyGroup>
3537

@@ -43,30 +45,28 @@
4345

4446
<ItemGroup>
4547
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
46-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19554-01">
48+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
4749
<PrivateAssets>all</PrivateAssets>
4850
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
4951
</PackageReference>
50-
<PackageReference Include="Roslynator.Analyzers" Version="2.2.0" PrivateAssets="all" ExcludeAssets="Runtime">
51-
<IncludeAssets>build; native; contentfiles; analyzers</IncludeAssets>
52-
</PackageReference>
53-
<PackageReference Include="Roslynator.CodeFixes" Version="2.0.0" PrivateAssets="all" ExcludeAssets="Runtime">
54-
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
52+
<PackageReference Include="Nullable" Version="1.3.0">
53+
<PrivateAssets>all</PrivateAssets>
54+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5555
</PackageReference>
56-
<!-- TODO builds fail on linux and mac if we don't explicitly reference this -->
57-
<PackageReference Include="System.Text.Encodings.Web" Version="5.0.0" />
58-
<PackageReference Include="Yarn.MSBuild" Version="1.22.0" PrivateAssets="all" ExcludeAssets="Runtime">
56+
<!-- TODO builds fail on linux and mac if we don't explicitly reference this -->
57+
<PackageReference Include="System.Text.Encodings.Web" Version="5.0.1" />
58+
<PackageReference Include="Yarn.MSBuild" Version="1.22.10" PrivateAssets="all" ExcludeAssets="Runtime">
5959
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6060
</PackageReference>
61-
<PackageReference Include="System.Text.Json" Version="5.0.1" />
61+
<PackageReference Include="System.Text.Json" Version="5.0.2" />
6262
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
6363
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
6464
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
6565
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
6666
</ItemGroup>
6767

6868
<ItemGroup>
69-
<ProjectReference Include="..\..\generators\Jering.Javascript.NodeJS.Generators\Jering.Javascript.NodeJS.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
69+
<ProjectReference Include="..\..\generators\Jering.Javascript.NodeJS.Generators\Jering.Javascript.NodeJS.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
7070
</ItemGroup>
7171

7272
<ItemGroup>
@@ -92,8 +92,8 @@
9292
If we aren't multi-targeting, JavascriptBuild runs before PreBuildEvent.
9393
-->
9494
<Target Name="JavascriptBuildWindows" BeforeTargets="DispatchToInnerBuilds" Inputs="@(JavascriptInputs)" Outputs="@(JavascriptOutputs)">
95-
<Yarn WorkingDirectory=".\Javascript" Command="run build --env mode=$(Configuration) --env entry=./Servers/OutOfProcess/Http/Http11Server.ts" />
96-
<Yarn WorkingDirectory=".\Javascript" Command="run build --env mode=$(Configuration) --env entry=./Servers/OutOfProcess/Http/Http20Server.ts" />
95+
<Yarn WorkingDirectory=".\Javascript" Command="run build --env mode=$(Configuration) --env entry=./Servers/OutOfProcess/Http/Http11Server.ts" />
96+
<Yarn WorkingDirectory=".\Javascript" Command="run build --env mode=$(Configuration) --env entry=./Servers/OutOfProcess/Http/Http20Server.ts" />
9797
</Target>
9898

9999
</Project>

‎src/NodeJS/NodeJSServiceImplementations/InvocationData/InvocationError.cs

+2-9
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,12 @@ public class InvocationError
1111
/// </summary>
1212
/// <param name="errorMessage">The error's description.</param>
1313
/// <param name="errorStack">The error's NodeJS stack trace.</param>
14-
public InvocationError(string errorMessage, string errorStack = null)
14+
public InvocationError(string errorMessage, string? errorStack = null)
1515
{
1616
ErrorMessage = errorMessage;
1717
ErrorStack = errorStack;
1818
}
1919

20-
/// <summary>
21-
/// Creates an <see cref="InvocationError"/>.
22-
/// </summary>
23-
public InvocationError()
24-
{
25-
}
26-
2720
// TODO this class is supposed to be immutable, but System.Text.Json doesn't
2821
// work with private setters the way newtonsoft.json does. Seems like this feature
2922
// will be added eventually - https://github.com/dotnet/corefx/issues/38163#issuecomment-553152589.
@@ -35,6 +28,6 @@ public InvocationError()
3528
/// <summary>
3629
/// The error's NodeJS stack trace.
3730
/// </summary>
38-
public string ErrorStack { get; set; }
31+
public string? ErrorStack { get; set; }
3932
}
4033
}

‎src/NodeJS/NodeJSServiceImplementations/InvocationData/InvocationException.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public InvocationException(string message) : base(message)
2929
/// </summary>
3030
/// <param name="message">The NodeJS error's description.</param>
3131
/// <param name="stack">The NodeJS error's stack trace.</param>
32-
public InvocationException(string message, string stack)
33-
: base(message + Environment.NewLine + stack)
32+
public InvocationException(string message, string? stack)
33+
: base(message + Environment.NewLine + (stack ?? string.Empty))
3434
{
3535
}
3636

3737
/// <summary>
38-
/// Creates a <see cref="InvocationException"/>.
38+
/// Creates an <see cref="InvocationException"/>.
3939
/// </summary>
4040
/// <param name="info">The data store for serialization/deserialization.</param>
4141
/// <param name="context">The struct representing the source and destination of a serialized stream.</param>

‎src/NodeJS/NodeJSServiceImplementations/InvocationData/InvocationRequest.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ public class InvocationRequest
1414
/// <summary>
1515
/// Creates an <see cref="InvocationRequest"/>.
1616
/// </summary>
17-
/// <param name="moduleSourceType">The source type of the module.</param>
17+
/// <param name="moduleSourceType">The module's source type.</param>
1818
/// <param name="moduleSource">
1919
/// <para>The module's source.</para>
20-
/// <para>This value may be the path of the module relative to <see cref="NodeJSProcessOptions.ProjectPath"/>, the module as a string, or the module's cache identifier.</para>
20+
/// <para>This value may be the module's path relative to <see cref="NodeJSProcessOptions.ProjectPath"/>, the module as a string, or the module's cache identifier.</para>
2121
/// <para>If <paramref name="moduleSourceType"/> is not <see cref="ModuleSourceType.Stream"/>, this value must not be <c>null</c>. Additionally, if <paramref name="moduleSourceType"/>
2222
/// is <see cref="ModuleSourceType.File"/> or <see cref="ModuleSourceType.String"/>, this value must not be an empty string or whitespace.</para>
2323
/// </param>
24-
/// <param name="newCacheIdentifier">The module's cache identifier. If this value is <c>null</c>, no attempt is made to retrieve or cache the module's exports.</param>
24+
/// <param name="cacheIdentifier">The module's cache identifier. If this value is <c>null</c>, no attempt is made to retrieve or cache the module's exports.</param>
2525
/// <param name="exportName">The name of the function in the module's exports to invoke. If this value is <c>null</c>, the module's exports is assumed to be a function and is invoked.</param>
2626
/// <param name="args">The sequence of JSON-serializable arguments to pass to the function to invoke. If this value is <c>null</c>, no arguments are passed.</param>
2727
/// <param name="moduleStreamSource">The module as a <see cref="Stream"/>.</param>
@@ -30,11 +30,11 @@ public class InvocationRequest
3030
/// <exception cref="ArgumentException">Thrown if <paramref name="moduleSourceType"/> is <see cref="ModuleSourceType.File"/> or <see cref="ModuleSourceType.String"/> but <paramref name="moduleSource"/>
3131
/// is <c>null</c>, whitespace or an empty string.</exception>
3232
public InvocationRequest(ModuleSourceType moduleSourceType,
33-
string moduleSource = null,
34-
string newCacheIdentifier = null,
35-
string exportName = null,
36-
object[] args = null,
37-
Stream moduleStreamSource = null)
33+
string? moduleSource = null,
34+
string? cacheIdentifier = null,
35+
string? exportName = null,
36+
object[]? args = null,
37+
Stream? moduleStreamSource = null)
3838
{
3939
if (moduleSourceType == ModuleSourceType.Stream)
4040
{
@@ -65,7 +65,7 @@ public InvocationRequest(ModuleSourceType moduleSourceType,
6565

6666
ModuleSourceType = moduleSourceType;
6767
ModuleSource = moduleSource;
68-
NewCacheIdentifier = newCacheIdentifier;
68+
CacheIdentifier = cacheIdentifier;
6969
ExportName = exportName;
7070
Args = args;
7171
}
@@ -118,27 +118,27 @@ public bool CheckStreamAtInitialPosition()
118118
/// <summary>
119119
/// Gets the module's source
120120
/// </summary>
121-
public string ModuleSource { get; }
121+
public string? ModuleSource { get; }
122122

123123
/// <summary>
124124
/// Gets the module's cache identifier.
125125
/// </summary>
126-
public string NewCacheIdentifier { get; }
126+
public string? CacheIdentifier { get; }
127127

128128
/// <summary>
129129
/// Gets the name of the function in the module's exports to invoke.
130130
/// </summary>
131-
public string ExportName { get; }
131+
public string? ExportName { get; }
132132

133133
/// <summary>
134134
/// Gets the sequence of JSON-serializable arguments to pass to the function to invoke.
135135
/// </summary>
136-
public object[] Args { get; }
136+
public object[]? Args { get; }
137137

138138
/// <summary>
139139
/// Gets the module as a <see cref="Stream"/>.
140140
/// </summary>
141141
[JsonIgnore]
142-
public Stream ModuleStreamSource { get; }
142+
public Stream? ModuleStreamSource { get; }
143143
}
144144
}

‎src/NodeJS/NodeJSServiceImplementations/OutOfProcess/ConfigureNodeJSProcessOptions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ConfigureNodeJSProcessOptions : IConfigureOptions<NodeJSProcessOpti
1616
/// <summary>
1717
/// Creates a <see cref="ConfigureNodeJSProcessOptions"/>.
1818
/// </summary>
19-
/// <param name="serviceScopeFactory"></param>
19+
/// <param name="serviceScopeFactory">The factory for creating <see cref="IServiceScope"/>s.</param>
2020
public ConfigureNodeJSProcessOptions(IServiceScopeFactory serviceScopeFactory)
2121
{
2222
_serviceScopeFactory = serviceScopeFactory;
@@ -55,11 +55,11 @@ public void Configure(NodeJSProcessOptions options)
5555
return;
5656
}
5757

58-
// Create a scope to avoid leaking unintended singletons - https://wildermuth.com/2016/08/07/ASP-NET-Core-Dependency-Injection
58+
// Create a scope to avoid leaking singletons - https://wildermuth.com/2016/08/07/ASP-NET-Core-Dependency-Injection
5959
using IServiceScope scope = _serviceScopeFactory.CreateScope();
6060
IServiceProvider serviceProvider = scope.ServiceProvider;
6161

62-
IHostingEnvironment hostingEnvironment = serviceProvider.GetService<IHostingEnvironment>();
62+
IHostingEnvironment? hostingEnvironment = serviceProvider.GetService<IHostingEnvironment>();
6363
if (hostingEnvironment == null)
6464
{
6565
return;

‎src/NodeJS/NodeJSServiceImplementations/OutOfProcess/Http/HttpClientService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class HttpClientService : IHttpClientService
2020
/// Creates a <see cref="HttpClientService"/>.
2121
/// </summary>
2222
/// <param name="httpClient">The <see cref="HttpClient"/> to send HTTP requests with.</param>
23-
/// <param name="outOfProcessNodeJSServiceOptionsAccessor"></param>
23+
/// <param name="outOfProcessNodeJSServiceOptionsAccessor">The <see cref="OutOfProcessNodeJSServiceOptions"/> accessor.</param>
2424
public HttpClientService(HttpClient httpClient,
2525
IOptions<OutOfProcessNodeJSServiceOptions> outOfProcessNodeJSServiceOptionsAccessor)
2626
{

‎src/NodeJS/NodeJSServiceImplementations/OutOfProcess/Http/HttpNodeJSPoolService.cs

+2-75
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
using System;
22
using System.Collections.ObjectModel;
3-
using System.IO;
43
using System.Threading;
5-
using System.Threading.Tasks;
64

75
namespace Jering.Javascript.NodeJS
86
{
97
/// <summary>
108
/// An implementation of <see cref="INodeJSService"/> that uses Http for inter-process communication with a pool of NodeJS processes.
119
/// </summary>
12-
public class HttpNodeJSPoolService : INodeJSService
10+
public partial class HttpNodeJSPoolService : INodeJSService
1311
{
1412
private readonly ReadOnlyCollection<HttpNodeJSService> _httpNodeJSServices;
1513

@@ -31,78 +29,6 @@ public HttpNodeJSPoolService(ReadOnlyCollection<HttpNodeJSService> httpNodeJSSer
3129
Size = httpNodeJSServices.Count;
3230
}
3331

34-
/// <inheritdoc />
35-
public Task<T> InvokeFromFileAsync<T>(string modulePath, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
36-
{
37-
return GetHttpNodeJSService().InvokeFromFileAsync<T>(modulePath, exportName, args, cancellationToken);
38-
}
39-
40-
/// <inheritdoc />
41-
public Task InvokeFromFileAsync(string modulePath, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
42-
{
43-
return GetHttpNodeJSService().InvokeFromFileAsync(modulePath, exportName, args, cancellationToken);
44-
}
45-
46-
/// <inheritdoc />
47-
public Task<T> InvokeFromStringAsync<T>(string moduleString, string newCacheIdentifier = null, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
48-
{
49-
return GetHttpNodeJSService().InvokeFromStringAsync<T>(moduleString, newCacheIdentifier, exportName, args, cancellationToken);
50-
}
51-
52-
/// <inheritdoc />
53-
public Task InvokeFromStringAsync(string moduleString, string newCacheIdentifier = null, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
54-
{
55-
return GetHttpNodeJSService().InvokeFromStringAsync(moduleString, newCacheIdentifier, exportName, args, cancellationToken);
56-
}
57-
58-
/// <inheritdoc />
59-
public Task<T> InvokeFromStringAsync<T>(Func<string> moduleFactory, string cacheIdentifier, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
60-
{
61-
return GetHttpNodeJSService().InvokeFromStringAsync<T>(moduleFactory, cacheIdentifier, exportName, args, cancellationToken);
62-
}
63-
64-
/// <inheritdoc />
65-
public Task InvokeFromStringAsync(Func<string> moduleFactory, string cacheIdentifier, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
66-
{
67-
return GetHttpNodeJSService().InvokeFromStringAsync(moduleFactory, cacheIdentifier, exportName, args, cancellationToken);
68-
}
69-
70-
/// <inheritdoc />
71-
public Task<T> InvokeFromStreamAsync<T>(Stream moduleStream, string newCacheIdentifier = null, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
72-
{
73-
return GetHttpNodeJSService().InvokeFromStreamAsync<T>(moduleStream, newCacheIdentifier, exportName, args, cancellationToken);
74-
}
75-
76-
/// <inheritdoc />
77-
public Task InvokeFromStreamAsync(Stream moduleStream, string newCacheIdentifier = null, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
78-
{
79-
return GetHttpNodeJSService().InvokeFromStreamAsync(moduleStream, newCacheIdentifier, exportName, args, cancellationToken);
80-
}
81-
82-
/// <inheritdoc />
83-
public Task<T> InvokeFromStreamAsync<T>(Func<Stream> moduleFactory, string cacheIdentifier, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
84-
{
85-
return GetHttpNodeJSService().InvokeFromStreamAsync<T>(moduleFactory, cacheIdentifier, exportName, args, cancellationToken);
86-
}
87-
88-
/// <inheritdoc />
89-
public Task InvokeFromStreamAsync(Func<Stream> moduleFactory, string cacheIdentifier, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
90-
{
91-
return GetHttpNodeJSService().InvokeFromStreamAsync(moduleFactory, cacheIdentifier, exportName, args, cancellationToken);
92-
}
93-
94-
/// <inheritdoc />
95-
public Task<(bool, T)> TryInvokeFromCacheAsync<T>(string moduleCacheIdentifier, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
96-
{
97-
return GetHttpNodeJSService().TryInvokeFromCacheAsync<T>(moduleCacheIdentifier, exportName, args, cancellationToken);
98-
}
99-
100-
/// <inheritdoc />
101-
public Task<bool> TryInvokeFromCacheAsync(string moduleCacheIdentifier, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
102-
{
103-
return GetHttpNodeJSService().TryInvokeFromCacheAsync(moduleCacheIdentifier, exportName, args, cancellationToken);
104-
}
105-
10632
internal HttpNodeJSService GetHttpNodeJSService()
10733
{
10834
// Notes
@@ -121,6 +47,7 @@ internal HttpNodeJSService GetHttpNodeJSService()
12147
public void Dispose()
12248
{
12349
Dispose(true);
50+
GC.SuppressFinalize(this);
12451
}
12552

12653
/// <summary>

0 commit comments

Comments
 (0)
Please sign in to comment.