X Tutup
Skip to content

Commit 46dc743

Browse files
Fix various path issues
1 parent b5fb560 commit 46dc743

File tree

12 files changed

+52
-39
lines changed

12 files changed

+52
-39
lines changed

Microsoft.AspNet.NodeServices.Angular/AngularPrerenderTagHelper.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
44
using Microsoft.AspNet.Http;
55
using Microsoft.AspNet.Http.Extensions;
6+
using Microsoft.Dnx.Runtime;
67

78
namespace Microsoft.AspNet.NodeServices.Angular
89
{
@@ -23,15 +24,16 @@ public class AngularPrerenderTagHelper : TagHelper
2324
private IHttpContextAccessor contextAccessor;
2425
private INodeServices nodeServices;
2526

26-
public AngularPrerenderTagHelper(IServiceProvider nodeServices, IHttpContextAccessor contextAccessor)
27+
public AngularPrerenderTagHelper(IServiceProvider serviceProvider, IHttpContextAccessor contextAccessor)
2728
{
2829
this.contextAccessor = contextAccessor;
29-
this.nodeServices = (INodeServices)nodeServices.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
30+
this.nodeServices = (INodeServices)serviceProvider.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
3031

3132
// Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
3233
// in your startup file, but then again it might be confusing that you don't need to.
3334
if (this.nodeServices == null) {
34-
this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http);
35+
var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof (IApplicationEnvironment));
36+
this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http, appEnv.ApplicationBasePath);
3537
}
3638
}
3739

Microsoft.AspNet.NodeServices.Angular/project.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.0-alpha4",
2+
"version": "1.0.0-alpha5",
33
"description": "Microsoft.AspNet.NodeServices.Angular Class Library",
44
"authors": [
55
"Microsoft"
@@ -25,8 +25,9 @@
2525
}
2626
},
2727
"dependencies": {
28-
"Microsoft.AspNet.NodeServices": "1.0.0-alpha4",
29-
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8"
28+
"Microsoft.AspNet.NodeServices": "1.0.0-alpha5",
29+
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8",
30+
"Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta8"
3031
},
3132
"resource": [
3233
"Content/**/*"

Microsoft.AspNet.NodeServices.React/ReactPrerenderTagHelper.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
44
using Microsoft.AspNet.Http;
55
using Microsoft.AspNet.Http.Extensions;
6+
using Microsoft.Dnx.Runtime;
67

78
namespace Microsoft.AspNet.NodeServices.React
89
{
@@ -23,15 +24,16 @@ public class ReactPrerenderTagHelper : TagHelper
2324
private IHttpContextAccessor contextAccessor;
2425
private INodeServices nodeServices;
2526

26-
public ReactPrerenderTagHelper(IServiceProvider nodeServices, IHttpContextAccessor contextAccessor)
27+
public ReactPrerenderTagHelper(IServiceProvider serviceProvider, IHttpContextAccessor contextAccessor)
2728
{
2829
this.contextAccessor = contextAccessor;
29-
this.nodeServices = (INodeServices)nodeServices.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
30+
this.nodeServices = (INodeServices)serviceProvider.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
3031

3132
// Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
3233
// in your startup file, but then again it might be confusing that you don't need to.
3334
if (this.nodeServices == null) {
34-
this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http);
35+
var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof(IApplicationEnvironment));
36+
this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http, appEnv.ApplicationBasePath);
3537
}
3638
}
3739

Microsoft.AspNet.NodeServices.React/project.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.0-alpha4",
2+
"version": "1.0.0-alpha5",
33
"description": "Microsoft.AspNet.NodeServices.React Class Library",
44
"authors": [
55
"Microsoft"
@@ -25,8 +25,9 @@
2525
}
2626
},
2727
"dependencies": {
28-
"Microsoft.AspNet.NodeServices": "1.0.0-alpha4",
29-
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8"
28+
"Microsoft.AspNet.NodeServices": "1.0.0-alpha5",
29+
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8",
30+
"Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta8"
3031
},
3132
"resource": [
3233
"Content/**/*"

Microsoft.AspNet.NodeServices/Configuration.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1+
using Microsoft.Dnx.Runtime;
12
using Microsoft.Framework.DependencyInjection;
23

34
namespace Microsoft.AspNet.NodeServices {
45
public static class Configuration {
56
public static void AddNodeServices(this IServiceCollection serviceCollection, NodeHostingModel hostingModel = NodeHostingModel.Http) {
67
serviceCollection.AddSingleton(typeof(INodeServices), (serviceProvider) => {
7-
return CreateNodeServices(hostingModel);
8+
var appEnv = serviceProvider.GetRequiredService<IApplicationEnvironment>();
9+
return CreateNodeServices(hostingModel, appEnv.ApplicationBasePath);
810
});
911
}
1012

11-
public static INodeServices CreateNodeServices(NodeHostingModel hostingModel)
13+
public static INodeServices CreateNodeServices(NodeHostingModel hostingModel, string projectPath)
1214
{
1315
switch (hostingModel)
1416
{
1517
case NodeHostingModel.Http:
16-
return new HttpNodeInstance();
18+
return new HttpNodeInstance(projectPath);
1719
case NodeHostingModel.InputOutputStream:
18-
return new InputOutputStreamNodeInstance();
20+
return new InputOutputStreamNodeInstance(projectPath);
1921
default:
2022
throw new System.ArgumentException("Unknown hosting model: " + hostingModel.ToString());
2123
}

Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ internal class HttpNodeInstance : OutOfProcessNodeInstance {
1515

1616
private int _portNumber;
1717

18-
public HttpNodeInstance(int port = 0)
19-
: base(EmbeddedResourceReader.Read(typeof(HttpNodeInstance), "/Content/Node/entrypoint-http.js"), port.ToString())
18+
public HttpNodeInstance(string projectPath, int port = 0)
19+
: base(EmbeddedResourceReader.Read(typeof(HttpNodeInstance), "/Content/Node/entrypoint-http.js"), projectPath, port.ToString())
2020
{
2121
}
2222

Microsoft.AspNet.NodeServices/HostingModels/InputOutputStreamNodeInstance.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ internal class InputOutputStreamNodeInstance : OutOfProcessNodeInstance
2424
ContractResolver = new CamelCasePropertyNamesContractResolver()
2525
};
2626

27-
public InputOutputStreamNodeInstance()
28-
: base(EmbeddedResourceReader.Read(typeof(InputOutputStreamNodeInstance), "/Content/Node/entrypoint-stream.js"))
27+
public InputOutputStreamNodeInstance(string projectPath)
28+
: base(EmbeddedResourceReader.Read(typeof(InputOutputStreamNodeInstance), "/Content/Node/entrypoint-stream.js"), projectPath)
2929
{
3030
}
3131

Microsoft.AspNet.NodeServices/HostingModels/OutOfProcessNodeInstance.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public abstract class OutOfProcessNodeInstance : INodeServices {
1212
private object _childProcessLauncherLock;
1313
private bool disposed;
1414
private StringAsTempFile _entryPointScript;
15+
private string _projectPath;
1516
private string _commandLineArguments;
1617
private Process _nodeProcess;
1718
private TaskCompletionSource<bool> _nodeProcessIsReadySource;
@@ -24,10 +25,11 @@ protected Process NodeProcess {
2425
}
2526
}
2627

27-
public OutOfProcessNodeInstance(string entryPointScript, string commandLineArguments = null)
28+
public OutOfProcessNodeInstance(string entryPointScript, string projectPath, string commandLineArguments = null)
2829
{
2930
this._childProcessLauncherLock = new object();
3031
this._entryPointScript = new StringAsTempFile(entryPointScript);
32+
this._projectPath = projectPath;
3133
this._commandLineArguments = commandLineArguments ?? string.Empty;
3234
}
3335

@@ -49,20 +51,20 @@ protected async Task EnsureReady() {
4951
lock (this._childProcessLauncherLock) {
5052
if (this._nodeProcess == null || this._nodeProcess.HasExited) {
5153
var startInfo = new ProcessStartInfo("node") {
52-
Arguments = this._entryPointScript.FileName + " " + this._commandLineArguments,
54+
Arguments = "\"" + this._entryPointScript.FileName + "\" " + this._commandLineArguments,
5355
UseShellExecute = false,
5456
RedirectStandardInput = true,
5557
RedirectStandardOutput = true,
5658
RedirectStandardError = true
5759
};
5860

59-
// Append current directory to NODE_PATH so it can locate node_modules
61+
// Append projectPath to NODE_PATH so it can locate node_modules
6062
var existingNodePath = Environment.GetEnvironmentVariable("NODE_PATH") ?? string.Empty;
6163
if (existingNodePath != string.Empty) {
6264
existingNodePath += ":";
6365
}
6466

65-
var nodePathValue = existingNodePath + Path.Combine(Directory.GetCurrentDirectory(), "node_modules");
67+
var nodePathValue = existingNodePath + Path.Combine(this._projectPath, "node_modules");
6668
#if DNX451
6769
startInfo.EnvironmentVariables.Add("NODE_PATH", nodePathValue);
6870
#else
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
{
2-
"version": "1.0.0-alpha4",
2+
"version": "1.0.0-alpha5",
33
"description": "Microsoft.AspNet.NodeServices",
4-
"authors": [ "Microsoft" ],
5-
"tags": [""],
4+
"authors": [
5+
"Microsoft"
6+
],
7+
"tags": [
8+
""
9+
],
610
"projectUrl": "",
711
"licenseUrl": "",
8-
912
"dependencies": {
10-
"System.Net.Http": "4.0.1-beta-23409",
11-
"Newtonsoft.Json": "8.0.1-beta1",
12-
"Microsoft.Framework.DependencyInjection": "1.0.0-beta8"
13+
"System.Net.Http": "4.0.1-beta-23409",
14+
"Newtonsoft.Json": "8.0.1-beta1",
15+
"Microsoft.Framework.DependencyInjection": "1.0.0-beta8",
16+
"Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta8"
1317
},
14-
1518
"frameworks": {
16-
"dnx451": { },
19+
"dnx451": {},
1720
"dnxcore50": {
1821
"dependencies": {
1922
"Microsoft.CSharp": "4.0.1-beta-23217",
@@ -28,8 +31,7 @@
2831
}
2932
}
3033
},
31-
3234
"resource": [
33-
"Content/**/*"
35+
"Content/**/*"
3436
]
35-
}
37+
}

samples/angular/MusicStore/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"EntityFramework.SQLite": "7.0.0-beta8",
2020
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta8",
2121
"AutoMapper": "4.0.0-alpha1",
22-
"Microsoft.AspNet.NodeServices.Angular": "1.0.0-alpha4"
22+
"Microsoft.AspNet.NodeServices.Angular": "1.0.0-alpha5",
23+
"Microsoft.AspNet.NodeServices": "1.0.0-alpha5"
2324
},
2425
"commands": {
2526
"web": "Microsoft.AspNet.Server.Kestrel"

0 commit comments

Comments
 (0)
X Tutup