mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
Fix various path issues
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Http.Extensions;
|
using Microsoft.AspNet.Http.Extensions;
|
||||||
|
using Microsoft.Dnx.Runtime;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.NodeServices.Angular
|
namespace Microsoft.AspNet.NodeServices.Angular
|
||||||
{
|
{
|
||||||
@@ -23,15 +24,16 @@ namespace Microsoft.AspNet.NodeServices.Angular
|
|||||||
private IHttpContextAccessor contextAccessor;
|
private IHttpContextAccessor contextAccessor;
|
||||||
private INodeServices nodeServices;
|
private INodeServices nodeServices;
|
||||||
|
|
||||||
public AngularPrerenderTagHelper(IServiceProvider nodeServices, IHttpContextAccessor contextAccessor)
|
public AngularPrerenderTagHelper(IServiceProvider serviceProvider, IHttpContextAccessor contextAccessor)
|
||||||
{
|
{
|
||||||
this.contextAccessor = contextAccessor;
|
this.contextAccessor = contextAccessor;
|
||||||
this.nodeServices = (INodeServices)nodeServices.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
|
this.nodeServices = (INodeServices)serviceProvider.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
|
||||||
|
|
||||||
// Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
|
// Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
|
||||||
// in your startup file, but then again it might be confusing that you don't need to.
|
// in your startup file, but then again it might be confusing that you don't need to.
|
||||||
if (this.nodeServices == null) {
|
if (this.nodeServices == null) {
|
||||||
this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http);
|
var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof (IApplicationEnvironment));
|
||||||
|
this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http, appEnv.ApplicationBasePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "1.0.0-alpha4",
|
"version": "1.0.0-alpha5",
|
||||||
"description": "Microsoft.AspNet.NodeServices.Angular Class Library",
|
"description": "Microsoft.AspNet.NodeServices.Angular Class Library",
|
||||||
"authors": [
|
"authors": [
|
||||||
"Microsoft"
|
"Microsoft"
|
||||||
@@ -25,8 +25,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.NodeServices": "1.0.0-alpha4",
|
"Microsoft.AspNet.NodeServices": "1.0.0-alpha5",
|
||||||
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8"
|
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8",
|
||||||
|
"Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta8"
|
||||||
},
|
},
|
||||||
"resource": [
|
"resource": [
|
||||||
"Content/**/*"
|
"Content/**/*"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Http.Extensions;
|
using Microsoft.AspNet.Http.Extensions;
|
||||||
|
using Microsoft.Dnx.Runtime;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.NodeServices.React
|
namespace Microsoft.AspNet.NodeServices.React
|
||||||
{
|
{
|
||||||
@@ -23,15 +24,16 @@ namespace Microsoft.AspNet.NodeServices.React
|
|||||||
private IHttpContextAccessor contextAccessor;
|
private IHttpContextAccessor contextAccessor;
|
||||||
private INodeServices nodeServices;
|
private INodeServices nodeServices;
|
||||||
|
|
||||||
public ReactPrerenderTagHelper(IServiceProvider nodeServices, IHttpContextAccessor contextAccessor)
|
public ReactPrerenderTagHelper(IServiceProvider serviceProvider, IHttpContextAccessor contextAccessor)
|
||||||
{
|
{
|
||||||
this.contextAccessor = contextAccessor;
|
this.contextAccessor = contextAccessor;
|
||||||
this.nodeServices = (INodeServices)nodeServices.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
|
this.nodeServices = (INodeServices)serviceProvider.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
|
||||||
|
|
||||||
// Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
|
// Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
|
||||||
// in your startup file, but then again it might be confusing that you don't need to.
|
// in your startup file, but then again it might be confusing that you don't need to.
|
||||||
if (this.nodeServices == null) {
|
if (this.nodeServices == null) {
|
||||||
this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http);
|
var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof(IApplicationEnvironment));
|
||||||
|
this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http, appEnv.ApplicationBasePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "1.0.0-alpha4",
|
"version": "1.0.0-alpha5",
|
||||||
"description": "Microsoft.AspNet.NodeServices.React Class Library",
|
"description": "Microsoft.AspNet.NodeServices.React Class Library",
|
||||||
"authors": [
|
"authors": [
|
||||||
"Microsoft"
|
"Microsoft"
|
||||||
@@ -25,8 +25,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.NodeServices": "1.0.0-alpha4",
|
"Microsoft.AspNet.NodeServices": "1.0.0-alpha5",
|
||||||
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8"
|
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8",
|
||||||
|
"Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta8"
|
||||||
},
|
},
|
||||||
"resource": [
|
"resource": [
|
||||||
"Content/**/*"
|
"Content/**/*"
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
|
using Microsoft.Dnx.Runtime;
|
||||||
using Microsoft.Framework.DependencyInjection;
|
using Microsoft.Framework.DependencyInjection;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.NodeServices {
|
namespace Microsoft.AspNet.NodeServices {
|
||||||
public static class Configuration {
|
public static class Configuration {
|
||||||
public static void AddNodeServices(this IServiceCollection serviceCollection, NodeHostingModel hostingModel = NodeHostingModel.Http) {
|
public static void AddNodeServices(this IServiceCollection serviceCollection, NodeHostingModel hostingModel = NodeHostingModel.Http) {
|
||||||
serviceCollection.AddSingleton(typeof(INodeServices), (serviceProvider) => {
|
serviceCollection.AddSingleton(typeof(INodeServices), (serviceProvider) => {
|
||||||
return CreateNodeServices(hostingModel);
|
var appEnv = serviceProvider.GetRequiredService<IApplicationEnvironment>();
|
||||||
|
return CreateNodeServices(hostingModel, appEnv.ApplicationBasePath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static INodeServices CreateNodeServices(NodeHostingModel hostingModel)
|
public static INodeServices CreateNodeServices(NodeHostingModel hostingModel, string projectPath)
|
||||||
{
|
{
|
||||||
switch (hostingModel)
|
switch (hostingModel)
|
||||||
{
|
{
|
||||||
case NodeHostingModel.Http:
|
case NodeHostingModel.Http:
|
||||||
return new HttpNodeInstance();
|
return new HttpNodeInstance(projectPath);
|
||||||
case NodeHostingModel.InputOutputStream:
|
case NodeHostingModel.InputOutputStream:
|
||||||
return new InputOutputStreamNodeInstance();
|
return new InputOutputStreamNodeInstance(projectPath);
|
||||||
default:
|
default:
|
||||||
throw new System.ArgumentException("Unknown hosting model: " + hostingModel.ToString());
|
throw new System.ArgumentException("Unknown hosting model: " + hostingModel.ToString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ namespace Microsoft.AspNet.NodeServices {
|
|||||||
|
|
||||||
private int _portNumber;
|
private int _portNumber;
|
||||||
|
|
||||||
public HttpNodeInstance(int port = 0)
|
public HttpNodeInstance(string projectPath, int port = 0)
|
||||||
: base(EmbeddedResourceReader.Read(typeof(HttpNodeInstance), "/Content/Node/entrypoint-http.js"), port.ToString())
|
: base(EmbeddedResourceReader.Read(typeof(HttpNodeInstance), "/Content/Node/entrypoint-http.js"), projectPath, port.ToString())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ namespace Microsoft.AspNet.NodeServices {
|
|||||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||||
};
|
};
|
||||||
|
|
||||||
public InputOutputStreamNodeInstance()
|
public InputOutputStreamNodeInstance(string projectPath)
|
||||||
: base(EmbeddedResourceReader.Read(typeof(InputOutputStreamNodeInstance), "/Content/Node/entrypoint-stream.js"))
|
: base(EmbeddedResourceReader.Read(typeof(InputOutputStreamNodeInstance), "/Content/Node/entrypoint-stream.js"), projectPath)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace Microsoft.AspNet.NodeServices {
|
|||||||
private object _childProcessLauncherLock;
|
private object _childProcessLauncherLock;
|
||||||
private bool disposed;
|
private bool disposed;
|
||||||
private StringAsTempFile _entryPointScript;
|
private StringAsTempFile _entryPointScript;
|
||||||
|
private string _projectPath;
|
||||||
private string _commandLineArguments;
|
private string _commandLineArguments;
|
||||||
private Process _nodeProcess;
|
private Process _nodeProcess;
|
||||||
private TaskCompletionSource<bool> _nodeProcessIsReadySource;
|
private TaskCompletionSource<bool> _nodeProcessIsReadySource;
|
||||||
@@ -24,10 +25,11 @@ namespace Microsoft.AspNet.NodeServices {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public OutOfProcessNodeInstance(string entryPointScript, string commandLineArguments = null)
|
public OutOfProcessNodeInstance(string entryPointScript, string projectPath, string commandLineArguments = null)
|
||||||
{
|
{
|
||||||
this._childProcessLauncherLock = new object();
|
this._childProcessLauncherLock = new object();
|
||||||
this._entryPointScript = new StringAsTempFile(entryPointScript);
|
this._entryPointScript = new StringAsTempFile(entryPointScript);
|
||||||
|
this._projectPath = projectPath;
|
||||||
this._commandLineArguments = commandLineArguments ?? string.Empty;
|
this._commandLineArguments = commandLineArguments ?? string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,20 +51,20 @@ namespace Microsoft.AspNet.NodeServices {
|
|||||||
lock (this._childProcessLauncherLock) {
|
lock (this._childProcessLauncherLock) {
|
||||||
if (this._nodeProcess == null || this._nodeProcess.HasExited) {
|
if (this._nodeProcess == null || this._nodeProcess.HasExited) {
|
||||||
var startInfo = new ProcessStartInfo("node") {
|
var startInfo = new ProcessStartInfo("node") {
|
||||||
Arguments = this._entryPointScript.FileName + " " + this._commandLineArguments,
|
Arguments = "\"" + this._entryPointScript.FileName + "\" " + this._commandLineArguments,
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
RedirectStandardInput = true,
|
RedirectStandardInput = true,
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
RedirectStandardError = true
|
RedirectStandardError = true
|
||||||
};
|
};
|
||||||
|
|
||||||
// Append current directory to NODE_PATH so it can locate node_modules
|
// Append projectPath to NODE_PATH so it can locate node_modules
|
||||||
var existingNodePath = Environment.GetEnvironmentVariable("NODE_PATH") ?? string.Empty;
|
var existingNodePath = Environment.GetEnvironmentVariable("NODE_PATH") ?? string.Empty;
|
||||||
if (existingNodePath != string.Empty) {
|
if (existingNodePath != string.Empty) {
|
||||||
existingNodePath += ":";
|
existingNodePath += ":";
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodePathValue = existingNodePath + Path.Combine(Directory.GetCurrentDirectory(), "node_modules");
|
var nodePathValue = existingNodePath + Path.Combine(this._projectPath, "node_modules");
|
||||||
#if DNX451
|
#if DNX451
|
||||||
startInfo.EnvironmentVariables.Add("NODE_PATH", nodePathValue);
|
startInfo.EnvironmentVariables.Add("NODE_PATH", nodePathValue);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
{
|
{
|
||||||
"version": "1.0.0-alpha4",
|
"version": "1.0.0-alpha5",
|
||||||
"description": "Microsoft.AspNet.NodeServices",
|
"description": "Microsoft.AspNet.NodeServices",
|
||||||
"authors": [ "Microsoft" ],
|
"authors": [
|
||||||
"tags": [""],
|
"Microsoft"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
""
|
||||||
|
],
|
||||||
"projectUrl": "",
|
"projectUrl": "",
|
||||||
"licenseUrl": "",
|
"licenseUrl": "",
|
||||||
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"System.Net.Http": "4.0.1-beta-23409",
|
"System.Net.Http": "4.0.1-beta-23409",
|
||||||
"Newtonsoft.Json": "8.0.1-beta1",
|
"Newtonsoft.Json": "8.0.1-beta1",
|
||||||
"Microsoft.Framework.DependencyInjection": "1.0.0-beta8"
|
"Microsoft.Framework.DependencyInjection": "1.0.0-beta8",
|
||||||
|
"Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta8"
|
||||||
},
|
},
|
||||||
|
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"dnx451": {},
|
"dnx451": {},
|
||||||
"dnxcore50": {
|
"dnxcore50": {
|
||||||
@@ -28,7 +31,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"resource": [
|
"resource": [
|
||||||
"Content/**/*"
|
"Content/**/*"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
"EntityFramework.SQLite": "7.0.0-beta8",
|
"EntityFramework.SQLite": "7.0.0-beta8",
|
||||||
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta8",
|
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta8",
|
||||||
"AutoMapper": "4.0.0-alpha1",
|
"AutoMapper": "4.0.0-alpha1",
|
||||||
"Microsoft.AspNet.NodeServices.Angular": "1.0.0-alpha4"
|
"Microsoft.AspNet.NodeServices.Angular": "1.0.0-alpha5",
|
||||||
|
"Microsoft.AspNet.NodeServices": "1.0.0-alpha5"
|
||||||
},
|
},
|
||||||
"commands": {
|
"commands": {
|
||||||
"web": "Microsoft.AspNet.Server.Kestrel"
|
"web": "Microsoft.AspNet.Server.Kestrel"
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
"Microsoft.Framework.Logging": "1.0.0-beta8",
|
"Microsoft.Framework.Logging": "1.0.0-beta8",
|
||||||
"Microsoft.Framework.Logging.Console": "1.0.0-beta8",
|
"Microsoft.Framework.Logging.Console": "1.0.0-beta8",
|
||||||
"Microsoft.Framework.Logging.Debug": "1.0.0-beta8",
|
"Microsoft.Framework.Logging.Debug": "1.0.0-beta8",
|
||||||
"Microsoft.AspNet.NodeServices": "1.0.0-alpha3"
|
"Microsoft.AspNet.NodeServices": "1.0.0-alpha5"
|
||||||
},
|
},
|
||||||
"commands": {
|
"commands": {
|
||||||
"web": "Microsoft.AspNet.Server.Kestrel"
|
"web": "Microsoft.AspNet.Server.Kestrel"
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
"Microsoft.Framework.Logging": "1.0.0-beta8",
|
"Microsoft.Framework.Logging": "1.0.0-beta8",
|
||||||
"Microsoft.Framework.Logging.Console": "1.0.0-beta8",
|
"Microsoft.Framework.Logging.Console": "1.0.0-beta8",
|
||||||
"Microsoft.Framework.Logging.Debug": "1.0.0-beta8",
|
"Microsoft.Framework.Logging.Debug": "1.0.0-beta8",
|
||||||
"Microsoft.AspNet.NodeServices.React": "1.0.0-alpha4"
|
"Microsoft.AspNet.NodeServices.React": "1.0.0-alpha5"
|
||||||
},
|
},
|
||||||
"commands": {
|
"commands": {
|
||||||
"web": "Microsoft.AspNet.Server.Kestrel"
|
"web": "Microsoft.AspNet.Server.Kestrel"
|
||||||
|
|||||||
Reference in New Issue
Block a user