Skip to content
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
6 changes: 5 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ 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/5.3.0...HEAD)
## [Unreleased](https://github.com/JeringTech/Javascript.NodeJS/compare/5.3.1...HEAD)

## [5.3.1](https://github.com/JeringTech/Javascript.NodeJS/compare/5.3.0...5.3.1) - Feb 12, 2020
### Fixes
- `ConfigureNodeJSProcessOptions` no longer overwrites user specified `NodeJSProcessOptions` options. ([#71](https://github.com/JeringTech/Javascript.NodeJS/pull/71)).

## [5.3.0](https://github.com/JeringTech/Javascript.NodeJS/compare/5.2.1...5.3.0) - Dec 10, 2019
### Changes
Expand Down
5 changes: 3 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ The next two sections list all available options.
#### NodeJSProcessOptions
| Option | Type | Description | Default |
| ------ | ---- | ----------- | ------- |
| ProjectPath | `string` | The base path for resolving paths of NodeJS modules on disk. | If the application is an ASP.NET Core application, this value defaults to `IHostingEnvironment.ContentRootPath`. Otherwise, it defaults to the current working directory. |
| ProjectPath | `string` | The base path for resolving paths of NodeJS modules on disk. If this value is `null`, whitespace or an empty string and the application is an ASP.NET Core application, project path is `IHostingEnvironment.ContentRootPath` | The current directory (value returned by `Directory.GetCurrentDirectory()`) |
| NodeAndV8Options | `string` | NodeJS and V8 options in the form "[NodeJS options] [V8 options]". The full list of NodeJS options can be found here: https://nodejs.org/api/cli.html#cli_options. | `null` |
| Port | `int` | The port that the server running on NodeJS will listen on. If set to 0, the OS will choose the port. | `0` |
| EnvironmentVariables | `IDictionary<string, string>` | The environment variables for the NodeJS process. The full list of NodeJS environment variables can be found here: https://nodejs.org/api/cli.html#cli_environment_variables. | `null` |
| EnvironmentVariables | `IDictionary<string, string>` | The environment variables for the NodeJS process. The full list of NodeJS environment variables can be found here: https://nodejs.org/api/cli.html#cli_environment_variables. If this value doesn't contain an element with key "NODE_ENV" and the application is an ASP.NET Core application, an element with key "NODE_ENV" is added with value "development" if `IHostingEnvironment.EnvironmentName` is `EnvironmentName.Development` or "production" otherwise. | An Empty `IDictionary<string, string>` |

#### OutOfProcessNodeJSServiceOptions
| Option | Type | Description | Default |
Expand Down Expand Up @@ -1003,6 +1003,7 @@ Contributions are welcome!
### Contributors
- [JeremyTCD](https://github.com/JeremyTCD)
- [Daniil Sokolyuk](https://github.com/DaniilSokolyuk)
- [dustinsoftware](https://github.com/dustinsoftware)

## About
Follow [@JeringTech](https://twitter.com/JeringTech) for updates and more.
2 changes: 1 addition & 1 deletion src/NodeJS/Jering.Javascript.NodeJS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Authors>JeremyTCD</Authors>
<Title>Invoke Javascript in NodeJS, from C#</Title>
<Description>Jering.Javascript.NodeJS enables you to invoke javascript in NodeJS, from C#. With this ability, you can use javascript libraries and scripts from your C# projects.</Description>
<Copyright>© 2018-2019 Jering. All rights reserved.</Copyright>
<Copyright>© 2018-2020 Jering. All rights reserved.</Copyright>
<PackageProjectUrl>https://www.jering.tech/utilities/jering.javascript.nodejs/index</PackageProjectUrl>
<RepositoryUrl>https://github.com/JeringTech/Javascript.NodeJS</RepositoryUrl>
<PackageLicenseUrl>$(RepositoryUrl)/blob/master/License.md</PackageLicenseUrl>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;

namespace Jering.Javascript.NodeJS
{
Expand All @@ -28,6 +28,27 @@ public ConfigureNodeJSProcessOptions(IServiceScopeFactory serviceScopeFactory)
/// <param name="options">The target <see cref="NodeJSProcessOptions"/> to configure.</param>
public void Configure(NodeJSProcessOptions options)
{
// Check whether project path already specified
bool projectPathSpecified = !string.IsNullOrWhiteSpace(options.ProjectPath);

// Check whether NODE_ENV already specified
bool nodeEnvSpecified;
if (options.EnvironmentVariables == null)
{
options.EnvironmentVariables = new Dictionary<string, string>();
nodeEnvSpecified = false;
}
else
{
nodeEnvSpecified = options.EnvironmentVariables.ContainsKey("NODE_ENV");
}

// Return if both project path and NODE_ENV already specified
if (projectPathSpecified && nodeEnvSpecified)
{
return;
}

// Create a scope to avoid leaking unintended singletons - https://wildermuth.com/2016/08/07/ASP-NET-Core-Dependency-Injection
using (IServiceScope scope = _serviceScopeFactory.CreateScope())
{
Expand All @@ -39,12 +60,15 @@ public void Configure(NodeJSProcessOptions options)
return;
}

options.ProjectPath = hostingEnvironment.ContentRootPath;
if (options.EnvironmentVariables == null)
if(!projectPathSpecified)
{
options.ProjectPath = hostingEnvironment.ContentRootPath;
}

if (!nodeEnvSpecified)
{
options.EnvironmentVariables = new Dictionary<string, string>();
options.EnvironmentVariables["NODE_ENV"] = hostingEnvironment.IsDevelopment() ? "development" : "production"; // De-facto standard values for Node
}
options.EnvironmentVariables["NODE_ENV"] = hostingEnvironment.IsDevelopment() ? "development" : "production"; // De-facto standard values for Node
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class NodeJSProcessOptions
{
/// <summary>
/// <para>The base path for resolving paths of NodeJS modules on disk.</para>
/// <para>If the application is an ASP.NET Core application, this value defaults to <see cref="IHostingEnvironment.ContentRootPath"/>.
/// Otherwise, it defaults to the current working directory.</para>
/// <para>If this value is <c>null</c>, whitespace or an empty string and the application is an ASP.NET Core application,
/// project path is <see cref="IHostingEnvironment.ContentRootPath"/>.</para>
/// </summary>
public string ProjectPath { get; set; } = Directory.GetCurrentDirectory();

Expand All @@ -31,6 +31,9 @@ public class NodeJSProcessOptions
/// <summary>
/// <para>The environment variables for the NodeJS process.</para>
/// <para>The full list of NodeJS environment variables can be found here: https://nodejs.org/api/cli.html#cli_environment_variables.</para>
/// <para>If this value doesn't contain an element with key "NODE_ENV" and the application is an ASP.NET Core application,
/// an element with key "NODE_ENV" is added. The added element's value is "development" if <see cref="IHostingEnvironment.EnvironmentName"/> is <see cref="EnvironmentName.Development"/>,
/// and "production" otherwise.</para>
/// </summary>
public IDictionary<string, string> EnvironmentVariables { get; set; } = new Dictionary<string, string>();
}
Expand Down
Loading