Skip to content

Updated precompiler directives to support .net 5 and above #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ This project uses [semantic versioning](http://semver.org/spec/v2.0.0.html). Ref
*[Semantic Versioning in Practice](https://www.jering.tech/articles/semantic-versioning-in-practice)*
for an overview of semantic versioning.

## [Unreleased](https://github.com/JeringTech/Javascript.NodeJS/compare/6.2.0...HEAD)
## [Unreleased](https://github.com/JeringTech/Javascript.NodeJS/compare/6.3.0...HEAD)

## [6.3.0](https://github.com/JeringTech/Javascript.NodeJS/compare/6.2.0...6.3.0) - Dec 27, 2021
### Additions
- Added net6.0 target. ([#128](https://github.com/JeringTech/Javascript.NodeJS/pull/128))
### Fixes
- Now supports HTTP2.0 for net6.0 and beyond. ([#128](https://github.com/JeringTech/Javascript.NodeJS/pull/128))

## [6.2.0](https://github.com/JeringTech/Javascript.NodeJS/compare/6.1.0...6.2.0) - Nov 26, 2021
### Additions
Expand Down
2 changes: 2 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Assert.Equal(8, result);
- .NET Framework 4.6.1
- .NET Core 3.1
- .NET 5.0
- .NET 6.0

## Platforms
- Windows
Expand Down Expand Up @@ -1764,6 +1765,7 @@ Contributions are welcome!
- [dustinsoftware](https://github.com/dustinsoftware)
- [blushingpenguin](https://github.com/blushingpenguin)
- [flcdrg](https://github.com/flcdrg)
- [samcic](https://github.com/samcic)

## About
Follow [@JeringTech](https://twitter.com/JeringTech) for updates and more.
2 changes: 1 addition & 1 deletion perf/NodeJS/Jering.Javascript.NodeJS.Performance.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<DefaultItemExcludes>Javascript\node_modules\**;$(DefaultItemExcludes)</DefaultItemExcludes>
Expand Down
2 changes: 1 addition & 1 deletion perf/NodeJS/packages.lock.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": 1,
"dependencies": {
".NETCoreApp,Version=v5.0": {
"net6.0": {
"BenchmarkDotNet": {
"type": "Direct",
"requested": "[0.12.1, )",
Expand Down
4 changes: 2 additions & 2 deletions src/NodeJS/Jering.Javascript.NodeJS.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net461;net5.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard2.0;net5.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net461;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard2.0;net5.0;netcoreapp3.1;net6.0</TargetFrameworks>
<PackageId>Jering.Javascript.NodeJS</PackageId>
<Authors>JeremyTCD</Authors>
<Title>Invoke Javascript in NodeJS, from C#</Title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class HttpNodeJSService : OutOfProcessNodeJSService
private readonly IJsonService _jsonService;
private readonly ILogger<HttpNodeJSService> _logger;
private readonly IHttpClientService _httpClientService;
#if NETCOREAPP3_1 || NET5_0
#if NETCOREAPP3_1 || NET5_0_OR_GREATER
private readonly Version _httpVersion;
#endif

Expand Down Expand Up @@ -66,7 +66,7 @@ public HttpNodeJSService(IOptions<OutOfProcessNodeJSServiceOptions> outOfProcess
monitorService,
taskService,
typeof(HttpNodeJSService).GetTypeInfo().Assembly,
#if NETCOREAPP3_1 || NET5_0
#if NETCOREAPP3_1 || NET5_0_OR_GREATER
httpNodeJSServiceOptionsAccessor.Value.Version == HttpVersion.Version20 ? HTTP20_SERVER_SCRIPT_NAME : HTTP11_SERVER_SCRIPT_NAME)
#else
HTTP11_SERVER_SCRIPT_NAME)
Expand All @@ -77,7 +77,7 @@ public HttpNodeJSService(IOptions<OutOfProcessNodeJSServiceOptions> outOfProcess
_jsonService = jsonService;
_logger = logger;
_httpContentFactory = httpContentFactory;
#if NETCOREAPP3_1 || NET5_0
#if NETCOREAPP3_1 || NET5_0_OR_GREATER
_httpVersion = httpNodeJSServiceOptionsAccessor.Value.Version == HttpVersion.Version20 ? HttpVersion.Version20 : HttpVersion.Version11;
#endif
}
Expand All @@ -88,10 +88,10 @@ public HttpNodeJSService(IOptions<OutOfProcessNodeJSServiceOptions> outOfProcess
using HttpContent httpContent = _httpContentFactory.Create(invocationRequest);
using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, _endpoint)
{
#if NETCOREAPP3_1 || NET5_0
#if NETCOREAPP3_1 || NET5_0_OR_GREATER
Version = _httpVersion,
#endif
#if NET5_0
#if NET5_0_OR_GREATER
VersionPolicy = HttpVersionPolicy.RequestVersionExact,
#endif
Content = httpContent,
Expand All @@ -116,7 +116,7 @@ public HttpNodeJSService(IOptions<OutOfProcessNodeJSServiceOptions> outOfProcess

if (httpResponseMessage.StatusCode == HttpStatusCode.InternalServerError)
{
#if NET5_0
#if NET5_0_OR_GREATER
using Stream stream = await httpResponseMessage.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
#else
using Stream stream = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);
Expand All @@ -133,7 +133,7 @@ public HttpNodeJSService(IOptions<OutOfProcessNodeJSServiceOptions> outOfProcess
}
else if (typeof(T) == typeof(string))
{
#if NET5_0
#if NET5_0_OR_GREATER
string result = await httpResponseMessage.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
#else
string result = await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
Expand All @@ -142,7 +142,7 @@ public HttpNodeJSService(IOptions<OutOfProcessNodeJSServiceOptions> outOfProcess
}
else if (typeof(T) == typeof(Stream))
{
#if NET5_0
#if NET5_0_OR_GREATER
Stream stream = await httpResponseMessage.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
#else
Stream stream = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);
Expand All @@ -151,7 +151,7 @@ public HttpNodeJSService(IOptions<OutOfProcessNodeJSServiceOptions> outOfProcess
}
else
{
#if NET5_0
#if NET5_0_OR_GREATER
using Stream stream = await httpResponseMessage.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
#else
using Stream stream = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Jering.Javascript.NodeJS
/// </summary>
public class HttpNodeJSServiceOptions
{
#if NETCOREAPP3_1 || NET5_0
#if NETCOREAPP3_1 || NET5_0_OR_GREATER
/// <summary>The HTTP version to use.</summary>
/// <remarks>
/// <para>This value can be <see cref="HttpVersion.Version11"/> or <see cref="HttpVersion.Version20"/>. <see cref="HttpVersion.Version11"/> is faster than <see cref="HttpVersion.Version20"/>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal ProcessStartInfo CreateStartInfo(string nodeServerScript)
{
nodeServerScript = EscapeCommandLineArg(nodeServerScript); // TODO can we escape before embedding? Would avoid an allocation every time we start a NodeJS process.

#if NET5_0
#if NET5_0_OR_GREATER
int currentProcessPid = Environment.ProcessId;
#else
int currentProcessPid = Process.GetCurrentProcess().Id;
Expand Down
8 changes: 8 additions & 0 deletions src/NodeJS/Utils/JsonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
#if NET6_0_OR_GREATER
using System.Text.Json.Serialization;
#endif

namespace Jering.Javascript.NodeJS
{
Expand All @@ -16,7 +19,12 @@ public class JsonService : IJsonService
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,

PropertyNamingPolicy = JsonNamingPolicy.CamelCase,

#if NET6_0_OR_GREATER
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, // https://docs.microsoft.com/en-sg/dotnet/fundamentals/syslib-diagnostics/syslib0020
#else
IgnoreNullValues = true,
#endif

PropertyNameCaseInsensitive = true
};
Expand Down
178 changes: 167 additions & 11 deletions src/NodeJS/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "ZD9TMpsmYJLrxbbmdvhwt9YEgG5WntEnZ/d1eH8JBX9LBp+Ju8BSBhUGbZMNVHHomWo2KVImJhTDl2hIgw/6MA=="
},
"jering.javascript.nodejs.documentationgenerators": {
"type": "Project"
}
},
".NETFramework,Version=v4.6.1": {
Expand Down Expand Up @@ -431,9 +428,6 @@
"type": "Transitive",
"resolved": "4.5.0",
"contentHash": "okurQJO6NRE/apDIP23ajJ0hpiNmJ+f0BwOlB/cSqTLQlw5upkf+5+96+iG2Jw40G1fCVCyPz/FhIABUjMR+RQ=="
},
"jering.javascript.nodejs.documentationgenerators": {
"type": "Project"
}
},
".NETStandard,Version=v2.0": {
Expand Down Expand Up @@ -687,9 +681,6 @@
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "4.5.3"
}
},
"jering.javascript.nodejs.documentationgenerators": {
"type": "Project"
}
},
".NETCoreApp,Version=v5.0": {
Expand Down Expand Up @@ -858,9 +849,174 @@
"type": "Transitive",
"resolved": "1.0.0",
"contentHash": "G8DuQY8/DK5NN+3jm5wcMcd9QYD90UV7MiLmdljSJixi3U/vNaeBKmmXUqI4DJCOeWizIUEh4ALhSt58mR+5eg=="
}
},
"net6.0": {
"Microsoft.AspNetCore.Hosting.Abstractions": {
"type": "Direct",
"requested": "[2.2.0, )",
"resolved": "2.2.0",
"contentHash": "ubycklv+ZY7Kutdwuy1W4upWcZ6VFR8WUXU7l7B2+mvbDBBPAcfpi+E+Y5GFe+Q157YfA3C49D2GCjAZc7Mobw==",
"dependencies": {
"Microsoft.AspNetCore.Hosting.Server.Abstractions": "2.2.0",
"Microsoft.AspNetCore.Http.Abstractions": "2.2.0",
"Microsoft.Extensions.Hosting.Abstractions": "2.2.0"
}
},
"jering.javascript.nodejs.documentationgenerators": {
"type": "Project"
"Microsoft.Extensions.DependencyInjection": {
"type": "Direct",
"requested": "[5.0.1, )",
"resolved": "5.0.1",
"contentHash": "//mDNrYeiJ0eh/awFhDFJQzkRVra/njU5Y4fyK7X29g5HScrzbUkKOKlyTtygthcGFt4zNC8G5CFCjb/oizomA==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "5.0.0"
}
},
"Microsoft.Extensions.Http": {
"type": "Direct",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "kT1ijDKZuSUhBtYoC1sXrmVKP7mA08h9Xrsr4VrS/QOtiKCEtUTTd7dd3XI9dwAb46tZSak13q/zdIcr4jqbyg==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "5.0.0",
"Microsoft.Extensions.Logging": "5.0.0",
"Microsoft.Extensions.Logging.Abstractions": "5.0.0",
"Microsoft.Extensions.Options": "5.0.0"
}
},
"Microsoft.Extensions.Logging": {
"type": "Direct",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "MgOwK6tPzB6YNH21wssJcw/2MKwee8b2gI7SllYfn6rvTpIrVvVS5HAjSU2vqSku1fwqRvWP0MdIi14qjd93Aw==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "5.0.0",
"Microsoft.Extensions.DependencyInjection.Abstractions": "5.0.0",
"Microsoft.Extensions.Logging.Abstractions": "5.0.0",
"Microsoft.Extensions.Options": "5.0.0"
}
},
"Microsoft.Extensions.Options": {
"type": "Direct",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "CBvR92TCJ5uBIdd9/HzDSrxYak+0W/3+yxrNg8Qm6Bmrkh5L+nu6m3WeazQehcZ5q1/6dDA7J5YdQjim0165zg==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "5.0.0",
"Microsoft.Extensions.Primitives": "5.0.0"
}
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
"requested": "[1.0.0, )",
"resolved": "1.0.0",
"contentHash": "aZyGyGg2nFSxix+xMkPmlmZSsnGQ3w+mIG23LTxJZHN+GPwTQ5FpPgDo7RMOq+Kcf5D4hFWfXkGhoGstawX13Q==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "1.0.0",
"Microsoft.SourceLink.Common": "1.0.0"
}
},
"Nullable": {
"type": "Direct",
"requested": "[1.3.0, )",
"resolved": "1.3.0",
"contentHash": "xHAviTdTY3n+t1nEPN4JPRQR5lI124qRKVw+U9H7dO5sDNPpzoWeo/MQy7dSUmv9eD3k/CJVKokz1tFK+JOzRw=="
},
"System.Text.Encodings.Web": {
"type": "Direct",
"requested": "[5.0.1, )",
"resolved": "5.0.1",
"contentHash": "KmJ+CJXizDofbq6mpqDoRRLcxgOd2z9X3XoFNULSbvbqVRZkFX3istvr+MUjL6Zw1RT+RNdoI4GYidIINtgvqQ=="
},
"System.Text.Json": {
"type": "Direct",
"requested": "[5.0.2, )",
"resolved": "5.0.2",
"contentHash": "I47dVIGiV6SfAyppphxqupertT/5oZkYLDCX6vC3HpOI4ZLjyoKAreUoem2ie6G0RbRuFrlqz/PcTQjfb2DOfQ=="
},
"Yarn.MSBuild": {
"type": "Direct",
"requested": "[1.22.10, )",
"resolved": "1.22.10",
"contentHash": "bcSeuS8ovq0VHhAmRuUWf2VZA4I9KrBxjUqSP7ZpkpBCL1YqR81BKGN/13LC06PueavdjSuV8Yyx+Z4b8Rnk9A=="
},
"Microsoft.AspNetCore.Hosting.Server.Abstractions": {
"type": "Transitive",
"resolved": "2.2.0",
"contentHash": "1PMijw8RMtuQF60SsD/JlKtVfvh4NORAhF4wjysdABhlhTrYmtgssqyncR0Stq5vqtjplZcj6kbT4LRTglt9IQ==",
"dependencies": {
"Microsoft.AspNetCore.Http.Features": "2.2.0",
"Microsoft.Extensions.Configuration.Abstractions": "2.2.0"
}
},
"Microsoft.AspNetCore.Http.Abstractions": {
"type": "Transitive",
"resolved": "2.2.0",
"contentHash": "Nxs7Z1q3f1STfLYKJSVXCs1iBl+Ya6E8o4Oy1bCxJ/rNI44E/0f6tbsrVqAWfB7jlnJfyaAtIalBVxPKUPQb4Q==",
"dependencies": {
"Microsoft.AspNetCore.Http.Features": "2.2.0",
"System.Text.Encodings.Web": "4.5.0"
}
},
"Microsoft.AspNetCore.Http.Features": {
"type": "Transitive",
"resolved": "2.2.0",
"contentHash": "ziFz5zH8f33En4dX81LW84I6XrYXKf9jg6aM39cM+LffN9KJahViKZ61dGMSO2gd3e+qe5yBRwsesvyqlZaSMg==",
"dependencies": {
"Microsoft.Extensions.Primitives": "2.2.0"
}
},
"Microsoft.Build.Tasks.Git": {
"type": "Transitive",
"resolved": "1.0.0",
"contentHash": "z2fpmmt+1Jfl+ZnBki9nSP08S1/tbEOxFdsK1rSR+LBehIJz1Xv9/6qOOoGNqlwnAGGVGis1Oj6S8Kt9COEYlQ=="
},
"Microsoft.Extensions.Configuration.Abstractions": {
"type": "Transitive",
"resolved": "2.2.0",
"contentHash": "65MrmXCziWaQFrI0UHkQbesrX5wTwf9XPjY5yFm/VkgJKFJ5gqvXRoXjIZcf2wLi5ZlwGz/oMYfyURVCWbM5iw==",
"dependencies": {
"Microsoft.Extensions.Primitives": "2.2.0"
}
},
"Microsoft.Extensions.DependencyInjection.Abstractions": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "ORj7Zh81gC69TyvmcUm9tSzytcy8AVousi+IVRAI8nLieQjOFryRusSFh7+aLk16FN9pQNqJAiMd7BTKINK0kA=="
},
"Microsoft.Extensions.FileProviders.Abstractions": {
"type": "Transitive",
"resolved": "2.2.0",
"contentHash": "EcnaSsPTqx2MGnHrmWOD0ugbuuqVT8iICqSqPzi45V5/MA1LjUNb0kwgcxBGqizV1R+WeBK7/Gw25Jzkyk9bIw==",
"dependencies": {
"Microsoft.Extensions.Primitives": "2.2.0"
}
},
"Microsoft.Extensions.Hosting.Abstractions": {
"type": "Transitive",
"resolved": "2.2.0",
"contentHash": "+k4AEn68HOJat5gj1TWa6X28WlirNQO9sPIIeQbia+91n03esEtMSSoekSTpMjUzjqtJWQN3McVx0GvSPFHF/Q==",
"dependencies": {
"Microsoft.Extensions.Configuration.Abstractions": "2.2.0",
"Microsoft.Extensions.DependencyInjection.Abstractions": "2.2.0",
"Microsoft.Extensions.FileProviders.Abstractions": "2.2.0",
"Microsoft.Extensions.Logging.Abstractions": "2.2.0"
}
},
"Microsoft.Extensions.Logging.Abstractions": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "NxP6ahFcBnnSfwNBi2KH2Oz8Xl5Sm2krjId/jRR3I7teFphwiUoUeZPwTNA21EX+5PtjqmyAvKaOeBXcJjcH/w=="
},
"Microsoft.Extensions.Primitives": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "cI/VWn9G1fghXrNDagX9nYaaB/nokkZn0HYAawGaELQrl8InSezfe9OnfPZLcJq3esXxygh3hkq2c3qoV3SDyQ=="
},
"Microsoft.SourceLink.Common": {
"type": "Transitive",
"resolved": "1.0.0",
"contentHash": "G8DuQY8/DK5NN+3jm5wcMcd9QYD90UV7MiLmdljSJixi3U/vNaeBKmmXUqI4DJCOeWizIUEh4ALhSt58mR+5eg=="
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/NodeJS/Helpers/StringBuilderLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public bool IsEnabled(LogLevel logLevel)
return true;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
lock (_lock)
{
Expand Down
Loading