mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 10:08:57 +00:00
Compare commits
251 Commits
release/2.
...
rybrande/m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdc621d428 | ||
|
|
128562955e | ||
|
|
964498a69d | ||
|
|
f6f7628718 | ||
|
|
e657e7d79a | ||
|
|
160d822f52 | ||
|
|
8027397d67 | ||
|
|
f024e779a6 | ||
|
|
7819c2f950 | ||
|
|
f47c5901b6 | ||
|
|
cdfa5d85f6 | ||
|
|
3265b92086 | ||
|
|
9c6a1b577f | ||
|
|
25e9c50585 | ||
|
|
ef999a57fd | ||
|
|
0050b505ec | ||
|
|
e231b29e58 | ||
|
|
ec82df4287 | ||
|
|
e9621c8add | ||
|
|
59ca023f46 | ||
|
|
d8662392a0 | ||
|
|
78a8bbf783 | ||
|
|
587ead92e4 | ||
|
|
28798452a9 | ||
|
|
622be9084a | ||
|
|
cd009006c8 | ||
|
|
817c0e4f24 | ||
|
|
f0e66325c3 | ||
|
|
c2f15f4199 | ||
|
|
cfd3a19279 | ||
|
|
24ebd9ff3e | ||
|
|
a4be7b3898 | ||
|
|
15884cbadb | ||
|
|
ae7b7c2663 | ||
|
|
e47f15fdc8 | ||
|
|
4bc67d6a60 | ||
|
|
bc50741043 | ||
|
|
1af86b7ba8 | ||
|
|
9281cbaf72 | ||
|
|
cd2b52bbd0 | ||
|
|
97022a1ff2 | ||
|
|
78dd174aed | ||
|
|
040a58578c | ||
|
|
4d7485bba2 | ||
|
|
02383cd614 | ||
|
|
a4bb72e58c | ||
|
|
df85010938 | ||
|
|
9c741600d2 | ||
|
|
4763ad5b8c | ||
|
|
dd9957bc39 | ||
|
|
601909865f | ||
|
|
d9d4359a1e | ||
|
|
5f44de86f6 | ||
|
|
c8342594a8 | ||
|
|
ea3a7bc897 | ||
|
|
578124e1ce | ||
|
|
0da7460fa2 | ||
|
|
0dc570a0c8 | ||
|
|
5fa87a0313 | ||
|
|
b1d04c99c9 | ||
|
|
d742bea01e | ||
|
|
7a04134345 | ||
|
|
c177cc001c | ||
|
|
067298bead | ||
|
|
cf659b3fda | ||
|
|
1e85713d75 | ||
|
|
a04813edc3 | ||
|
|
e49b0e439e | ||
|
|
d65a4f3b6d | ||
|
|
47828ee727 | ||
|
|
0d1c99c1d1 | ||
|
|
240dd82473 | ||
|
|
b616db4918 | ||
|
|
436cdb0e96 | ||
|
|
2698d77487 | ||
|
|
447359af84 | ||
|
|
823630c508 | ||
|
|
c35a3a17c0 | ||
|
|
98c47a1c70 | ||
|
|
0a1c83ab81 | ||
|
|
2167b28ffd | ||
|
|
966bfcb172 | ||
|
|
b8f85dc2d9 | ||
|
|
8c84e35392 | ||
|
|
944e8d396d | ||
|
|
6ba3014c57 | ||
|
|
961619c5c9 | ||
|
|
da66cc1fee | ||
|
|
b7ba837d6e | ||
|
|
7d30f2bbc3 | ||
|
|
424e5ed91a | ||
|
|
67267eabf7 | ||
|
|
1e5b6f864e | ||
|
|
8ddacb8b73 | ||
|
|
2c81117b4b | ||
|
|
4d151a599e | ||
|
|
78f7dccfab | ||
|
|
7f550fb469 | ||
|
|
087a459c9c | ||
|
|
f22297a4db | ||
|
|
61b4951961 | ||
|
|
02beb11a5c | ||
|
|
c42db123bd | ||
|
|
04b8c17bdd | ||
|
|
8583f205f9 | ||
|
|
e6af1b892e | ||
|
|
24766621e1 | ||
|
|
ae4c4d6e8f | ||
|
|
8553647ce8 | ||
|
|
67560266ab | ||
|
|
ce49379afb | ||
|
|
4dc05d96ac | ||
|
|
53742ad649 | ||
|
|
91a1d83acd | ||
|
|
1d504e4565 | ||
|
|
873cfa9adf | ||
|
|
41b8642c2d | ||
|
|
d6b67ca75d | ||
|
|
4af70a0907 | ||
|
|
bf5f40b1ed | ||
|
|
a515f6bb0a | ||
|
|
12a2314a5e | ||
|
|
f35c814fc7 | ||
|
|
dbaa453d18 | ||
|
|
b2373e157e | ||
|
|
08c2f231ea | ||
|
|
6274733565 | ||
|
|
5f6f288056 | ||
|
|
78e583d0fb | ||
|
|
7c07beb494 | ||
|
|
e7ffb8bb71 | ||
|
|
3e6f7f3e45 | ||
|
|
0d83504863 | ||
|
|
370b5f7341 | ||
|
|
0b53b92bc6 | ||
|
|
116f33c66c | ||
|
|
c3964a0437 | ||
|
|
f291f87dfc | ||
|
|
a1c2c18326 | ||
|
|
d6588c31bf | ||
|
|
15d2f5a898 | ||
|
|
814441c933 | ||
|
|
a98c1459b5 | ||
|
|
975d537a0a | ||
|
|
4af2e8670e | ||
|
|
160c91f1b9 | ||
|
|
8ded472fe9 | ||
|
|
f9c62ebb5a | ||
|
|
74512dc3b2 | ||
|
|
e6285f30ae | ||
|
|
bd5793e284 | ||
|
|
02bbcb68f1 | ||
|
|
18140929e7 | ||
|
|
50ba6114ee | ||
|
|
cd3e3c667c | ||
|
|
0de9f0e3ce | ||
|
|
9b1509a52b | ||
|
|
a8809f9a96 | ||
|
|
68c4620a55 | ||
|
|
296435e40c | ||
|
|
aeabbdcada | ||
|
|
96d7f85327 | ||
|
|
30333e250a | ||
|
|
08002e961b | ||
|
|
0c77224f46 | ||
|
|
a83ec3a053 | ||
|
|
a16343681b | ||
|
|
c8b337ebaa | ||
|
|
7bf5516bb2 | ||
|
|
2d98a1808c | ||
|
|
e583a17ef8 | ||
|
|
ba0d82d801 | ||
|
|
e67a30132f | ||
|
|
d51bef194c | ||
|
|
78436adb08 | ||
|
|
09317b83a8 | ||
|
|
a0269fb0ad | ||
|
|
64ed1c7945 | ||
|
|
04fe1204a9 | ||
|
|
e2030fb1fa | ||
|
|
e5f1299239 | ||
|
|
c922eee1d6 | ||
|
|
8b243e8cc7 | ||
|
|
28920c7691 | ||
|
|
412ec1b427 | ||
|
|
c62a3b491c | ||
|
|
559832bb6d | ||
|
|
45d645931b | ||
|
|
8d6119f31d | ||
|
|
0291686b20 | ||
|
|
7c52be5e42 | ||
|
|
900e9ca835 | ||
|
|
ad758b1060 | ||
|
|
cd9ad38a99 | ||
|
|
e057cb35ec | ||
|
|
eea2066a6d | ||
|
|
d6ae8829b6 | ||
|
|
a94ac6f37e | ||
|
|
a40adab38d | ||
|
|
c2a284d5b8 | ||
|
|
fc398d602a | ||
|
|
90c59ff4e7 | ||
|
|
a7e715c88f | ||
|
|
6dddc9d01d | ||
|
|
5ed1a35ce0 | ||
|
|
680ba7497a | ||
|
|
287c10fd2e | ||
|
|
63f7ac9330 | ||
|
|
d2858beaa1 | ||
|
|
5f1450c9ba | ||
|
|
c83605baff | ||
|
|
fc12d722b8 | ||
|
|
372e597f34 | ||
|
|
3715ec7c3f | ||
|
|
d2eaa36372 | ||
|
|
169ef12cd8 | ||
|
|
f5d58f3f2e | ||
|
|
c2e4d4f261 | ||
|
|
50481fe23f | ||
|
|
895a61160e | ||
|
|
b8b769aa74 | ||
|
|
c4aad6bcab | ||
|
|
27f1d07d21 | ||
|
|
0cb14a3c68 | ||
|
|
2457b4ee5d | ||
|
|
789ea5a320 | ||
|
|
a902874754 | ||
|
|
f43ea777eb | ||
|
|
c79db4e8e2 | ||
|
|
d1198aeab2 | ||
|
|
9528dd7432 | ||
|
|
b8c006a3e9 | ||
|
|
a9ddf1413f | ||
|
|
8b37dc8561 | ||
|
|
7b07fb66eb | ||
|
|
cdb04c74f9 | ||
|
|
a74941e3c8 | ||
|
|
a0a710a0df | ||
|
|
d5f5ad7fdc | ||
|
|
dab0faea66 | ||
|
|
2df0febfba | ||
|
|
e65ecebac6 | ||
|
|
bb0727c34c | ||
|
|
4903e12373 | ||
|
|
56c806b34e | ||
|
|
8acba88160 | ||
|
|
b434eefd83 | ||
|
|
44360b6955 | ||
|
|
72b1e627b0 | ||
|
|
781c5dc37c | ||
|
|
c2f63f21fd |
51
.gitattributes
vendored
51
.gitattributes
vendored
@@ -1,51 +0,0 @@
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
||||
|
||||
*.jpg binary
|
||||
*.png binary
|
||||
*.gif binary
|
||||
|
||||
*.cs text=auto diff=csharp
|
||||
*.vb text=auto
|
||||
*.resx text=auto
|
||||
*.c text=auto
|
||||
*.cpp text=auto
|
||||
*.cxx text=auto
|
||||
*.h text=auto
|
||||
*.hxx text=auto
|
||||
*.py text=auto
|
||||
*.rb text=auto
|
||||
*.java text=auto
|
||||
*.html text=auto
|
||||
*.htm text=auto
|
||||
*.css text=auto
|
||||
*.scss text=auto
|
||||
*.sass text=auto
|
||||
*.less text=auto
|
||||
*.js text=auto
|
||||
*.lisp text=auto
|
||||
*.clj text=auto
|
||||
*.sql text=auto
|
||||
*.php text=auto
|
||||
*.lua text=auto
|
||||
*.m text=auto
|
||||
*.asm text=auto
|
||||
*.erl text=auto
|
||||
*.fs text=auto
|
||||
*.fsx text=auto
|
||||
*.hs text=auto
|
||||
|
||||
*.csproj text=auto
|
||||
*.vbproj text=auto
|
||||
*.fsproj text=auto
|
||||
*.dbproj text=auto
|
||||
*.sln text=auto eol=crlf
|
||||
*.sh eol=lf
|
||||
44
.gitignore
vendored
44
.gitignore
vendored
@@ -1,44 +0,0 @@
|
||||
[Oo]bj/
|
||||
[Bb]in/
|
||||
TestResults/
|
||||
.nuget/
|
||||
*.sln.ide/
|
||||
_ReSharper.*/
|
||||
packages/
|
||||
artifacts/
|
||||
PublishProfiles/
|
||||
*.user
|
||||
*.suo
|
||||
*.cache
|
||||
*.docstates
|
||||
_ReSharper.*
|
||||
nuget.exe
|
||||
*net45.csproj
|
||||
*net451.csproj
|
||||
*k10.csproj
|
||||
*.psess
|
||||
*.vsp
|
||||
*.pidb
|
||||
*.userprefs
|
||||
*DS_Store
|
||||
*.ncrunchsolution
|
||||
*.*sdf
|
||||
*.ipch
|
||||
|
||||
.vs/
|
||||
npm-debug.log
|
||||
/.build/
|
||||
global.json
|
||||
*.g.targets
|
||||
|
||||
# The templates can't contain their own .gitignore files, because Yeoman has strange default handling for
|
||||
# files with that name (https://github.com/npm/npm/issues/1862). So, each template instead has a template_gitignore
|
||||
# file which gets renamed after the files are copied. And so any files that need to be excluded in the source
|
||||
# repo have to be excluded here.
|
||||
/templates/*/node_modules/
|
||||
/templates/*/wwwroot/dist/
|
||||
/templates/*/ClientApp/dist/
|
||||
/templates/*/yarn.lock
|
||||
.vscode/
|
||||
|
||||
/templates/*/Properties/launchSettings.json
|
||||
19
.travis.yml
19
.travis.yml
@@ -1,19 +0,0 @@
|
||||
language: csharp
|
||||
sudo: required
|
||||
dist: trusty
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gettext
|
||||
- libcurl4-openssl-dev
|
||||
- libicu-dev
|
||||
- libssl-dev
|
||||
- libunwind8
|
||||
- zlib1g
|
||||
mono: none
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
osx_image: xcode7.1
|
||||
script:
|
||||
- ./build.sh
|
||||
@@ -1,4 +0,0 @@
|
||||
Contributing
|
||||
======
|
||||
|
||||
Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/dev/CONTRIBUTING.md) in the Home repo.
|
||||
@@ -1,9 +0,0 @@
|
||||
<Project>
|
||||
<Import Project="version.props" />
|
||||
<Import Project="build\dependencies.props" />
|
||||
<Import Project="build\sources.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<RepositoryRoot>$(MSBuildThisFileDirectory)</RepositoryRoot>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<clear />
|
||||
<!-- Restore sources should be defined in build/sources.props. -->
|
||||
</packageSources>
|
||||
</configuration>
|
||||
100
README.md
100
README.md
@@ -1,100 +0,0 @@
|
||||
# JavaScriptServices
|
||||
|
||||
AppVeyor: [](https://ci.appveyor.com/project/aspnetci/javascriptservices/branch/dev)
|
||||
|
||||
This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the [Home](https://github.com/aspnet/home) repo.
|
||||
|
||||
## What is this?
|
||||
|
||||
`JavaScriptServices` is a set of client-side technologies for ASP.NET Core. It provides infrastructure that you'll find useful if you:
|
||||
|
||||
- Use Angular / React / Vue / Aurelia / Knockout / etc.
|
||||
- Build your client-side resources using Webpack.
|
||||
- Execute JavaScript on the server at runtime.
|
||||
|
||||
Read [Building Single Page Applications on ASP.NET Core with JavaScriptServices](https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/) for more details.
|
||||
|
||||
This repo contains:
|
||||
|
||||
* A set of NuGet/NPM packages that implement functionality for:
|
||||
* Invoking arbitrary NPM packages at runtime from .NET code ([docs](https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.NodeServices#simple-usage-example))
|
||||
* Server-side prerendering of SPA components ([docs](https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.SpaServices#server-side-prerendering))
|
||||
* Webpack dev middleware ([docs](https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.SpaServices#webpack-dev-middleware))
|
||||
* Hot module replacement (HMR) ([docs](https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.SpaServices#webpack-hot-module-replacement))
|
||||
* Server-side and client-side routing integration ([docs](https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.SpaServices#routing-helper-mapspafallbackroute))
|
||||
* Server-side and client-side validation integration
|
||||
* "Lazy loading" for Knockout apps
|
||||
* A Yeoman generator that creates preconfigured app starting points ([guide](http://blog.stevensanderson.com/2016/05/02/angular2-react-knockout-apps-on-aspnet-core/))
|
||||
* Samples and docs
|
||||
|
||||
It's cross-platform (Windows, Linux, or macOS) and works with .NET Core 1.0.1 or later.
|
||||
|
||||
## Creating new applications
|
||||
|
||||
If you want to build a brand-new ASP.NET Core app that uses Angular / React / Knockout on the client, consider starting with the `aspnetcore-spa` generator. This lets you choose your client-side framework. It generates a starting point that includes applicable features such as Webpack dev middleware, server-side prerendering, and efficient production builds. It's much easier than configuring everything to work together manually!
|
||||
|
||||
To do this, install Yeoman and these generator templates:
|
||||
|
||||
npm install -g yo generator-aspnetcore-spa
|
||||
|
||||
Generate your new application starting point:
|
||||
|
||||
cd some-empty-directory
|
||||
yo aspnetcore-spa
|
||||
|
||||
Once the generator has run and restored all the dependencies, you can start up your new ASP.NET Core SPA:
|
||||
|
||||
dotnet run
|
||||
|
||||
For a more detailed walkthrough, see [getting started with the `aspnetcore-spa` generator](http://blog.stevensanderson.com/2016/05/02/angular2-react-knockout-apps-on-aspnet-core/).
|
||||
|
||||
## Adding to existing applications
|
||||
|
||||
If you have an existing ASP.NET Core application, or if you just want to use the underlying JavaScriptServices packages directly, you can install these packages using NuGet and NPM:
|
||||
|
||||
* `Microsoft.AspNetCore.NodeServices`
|
||||
* This provides a fast and robust way for .NET code to run JavaScript on the server inside a Node.js environment. You can use this to consume arbitrary functionality from NPM packages at runtime in your ASP.NET Core app.
|
||||
* Most applications developers don't need to use this directly, but you can do so if you want to implement your own functionality that involves calling Node.js code from .NET at runtime.
|
||||
* Find [documentation and usage examples here](https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.NodeServices#microsoftaspnetcorenodeservices).
|
||||
* `Microsoft.AspNetCore.SpaServices`
|
||||
* This provides infrastructure that's generally useful when building Single Page Applications (SPAs) with technologies such as Angular or React (for example, server-side prerendering and webpack middleware). Internally, it uses the `NodeServices` package to implement its features.
|
||||
* Find [documentation and usage examples here](https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.SpaServices#microsoftaspnetcorespaservices).
|
||||
* `Microsoft.AspNetCore.AngularServices`
|
||||
* This builds on the `SpaServices` package and includes features specific to Angular. Currently, this includes validation helpers.
|
||||
* The code is [here](https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.AngularServices). You'll find a usage example for [the validation helper here](https://github.com/aspnet/JavaScriptServices/blob/dev/samples/angular/MusicStore/wwwroot/ng-app/components/admin/album-edit/album-edit.ts).
|
||||
|
||||
There was previously a `Microsoft.AspNetCore.ReactServices` but this is not currently needed - all applicable functionality is in `Microsoft.AspNetCore.SpaServices`, because it's sufficiently general. We might add a new `Microsoft.AspNetCore.ReactServices` package in the future if new React-specific requirements emerge.
|
||||
|
||||
If you want to build a helper library for some other SPA framework, you can do so by taking a dependency on `Microsoft.AspNetCore.SpaServices` and wrapping its functionality in whatever way is most useful for your SPA framework.
|
||||
|
||||
## Samples and templates
|
||||
|
||||
Inside this repo, [the `templates` directory](https://github.com/aspnet/JavaScriptServices/tree/dev/templates) contains the application starting points that the `aspnetcore-spa` generator emits. You can clone this repo and run those applications directly. But it's easier to [use the Yeoman tool to run the generator](http://blog.stevensanderson.com/2016/05/02/angular2-react-knockout-apps-on-aspnet-core/).
|
||||
|
||||
The [`samples` directory](https://github.com/aspnet/JavaScriptServices/tree/dev/samples) contains examples of:
|
||||
|
||||
- Using the JavaScript services family of packages with Angular and React.
|
||||
- A standalone `NodeServices` usage for runtime code transpilation and image processing.
|
||||
|
||||
**To run the samples:**
|
||||
|
||||
* Clone this repo
|
||||
* At the repo's root directory (the one containing `src`, `samples`, etc.), run `dotnet restore`
|
||||
* Change directory to the sample you want to run (for example, `cd samples/angular/MusicStore`)
|
||||
* Restore Node dependencies by running `npm install`
|
||||
* If you're trying to run the Angular "Music Store" sample, then also run `gulp` (which you need to have installed globally). None of the other samples require this.
|
||||
* Run the application (`dotnet run`)
|
||||
* Browse to [http://localhost:5000](http://localhost:5000)
|
||||
|
||||
## Contributing
|
||||
|
||||
If you're interested in contributing to the various packages, samples, and project templates in this repo, that's great! You can run the code in this repo as follows:
|
||||
|
||||
* Clone the repo
|
||||
* Run `dotnet restore` at the repo root dir
|
||||
* Go to whatever sample or template you want to run (for example, `cd templates/AngularSpa`)
|
||||
* Restore NPM dependencies (run `npm install`)
|
||||
* If the sample/template you're trying to run has a file called `webpack.config.vendor.js` at its root, run `webpack --config webpack.config.vendor.js`. If it has a file called `webpack.config.js`, run `webpack` (no args). You might need to install webpack first, by running `npm install -g webpack`.
|
||||
* Launch it (`dotnet run`)
|
||||
|
||||
If you're planning to submit a pull request, and if it's more than a trivial fix (for example, for a typo), it's usually a good idea first to file an issue describing what you're proposing to do and how it will work. Then you can find out if it's likely that such a pull request will be accepted, and how it fits into wider ongoing plans.
|
||||
40
appveyor.yml
40
appveyor.yml
@@ -1,40 +0,0 @@
|
||||
init:
|
||||
- git config --global core.autocrlf true
|
||||
install:
|
||||
- ps: Install-Product node 6.9.2 x64
|
||||
# .NET Core SDK binaries
|
||||
# Download .NET Core 2.0 Preview 3 SDK and add to PATH
|
||||
- ps: $urlCurrent = "https://dotnetcli.azureedge.net/dotnet/Sdk/2.0.0-preview3-006729/dotnet-sdk-2.0.0-preview3-006729-win-x64.zip"
|
||||
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk"
|
||||
- ps: mkdir $env:DOTNET_INSTALL_DIR -Force | Out-Null
|
||||
- ps: $tempFileCurrent = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())
|
||||
- ps: (New-Object System.Net.WebClient).DownloadFile($urlCurrent, $tempFileCurrent)
|
||||
- ps: Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory($tempFileCurrent, $env:DOTNET_INSTALL_DIR)
|
||||
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
|
||||
build_script:
|
||||
- ps: Push-Location
|
||||
- cd templates/package-builder
|
||||
- npm install
|
||||
- npm run build
|
||||
- ps: Pop-Location
|
||||
artifacts:
|
||||
- path: templates\package-builder\dist\artifacts\generator-aspnetcore-spa.tar.gz
|
||||
name: generator-aspnetcore-spa
|
||||
- path: templates\package-builder\dist\artifacts\*.nupkg
|
||||
name: Microsoft.AspNetCore.SpaTemplates
|
||||
type: NuGetPackage
|
||||
# - ps: .\build.ps1
|
||||
clone_depth: 1
|
||||
test_script:
|
||||
- dotnet restore
|
||||
- ps: Push-Location
|
||||
- cd test
|
||||
- npm install selenium-standalone
|
||||
- ps: Start-Process node './start-selenium.js'
|
||||
- npm install
|
||||
- npm test
|
||||
on_finish :
|
||||
- ps: Pop-Location
|
||||
# After running tests, upload results to Appveyor
|
||||
- ps: (new-object net.webclient).UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\test\tmp\junit\*.xml))
|
||||
deploy: off
|
||||
@@ -1,2 +0,0 @@
|
||||
@ECHO OFF
|
||||
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*; exit $LASTEXITCODE"
|
||||
186
build.ps1
186
build.ps1
@@ -1,186 +0,0 @@
|
||||
#!/usr/bin/env powershell
|
||||
#requires -version 4
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Build this repository
|
||||
|
||||
.DESCRIPTION
|
||||
Downloads korebuild if required. Then builds the repository.
|
||||
|
||||
.PARAMETER Path
|
||||
The folder to build. Defaults to the folder containing this script.
|
||||
|
||||
.PARAMETER Channel
|
||||
The channel of KoreBuild to download. Overrides the value from the config file.
|
||||
|
||||
.PARAMETER DotNetHome
|
||||
The directory where .NET Core tools will be stored.
|
||||
|
||||
.PARAMETER ToolsSource
|
||||
The base url where build tools can be downloaded. Overrides the value from the config file.
|
||||
|
||||
.PARAMETER Update
|
||||
Updates KoreBuild to the latest version even if a lock file is present.
|
||||
|
||||
.PARAMETER ConfigFile
|
||||
The path to the configuration file that stores values. Defaults to version.props.
|
||||
|
||||
.PARAMETER MSBuildArgs
|
||||
Arguments to be passed to MSBuild
|
||||
|
||||
.NOTES
|
||||
This function will create a file $PSScriptRoot/korebuild-lock.txt. This lock file can be committed to source, but does not have to be.
|
||||
When the lockfile is not present, KoreBuild will create one using latest available version from $Channel.
|
||||
|
||||
The $ConfigFile is expected to be an JSON file. It is optional, and the configuration values in it are optional as well. Any options set
|
||||
in the file are overridden by command line parameters.
|
||||
|
||||
.EXAMPLE
|
||||
Example config file:
|
||||
```json
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json",
|
||||
"channel": "dev",
|
||||
"toolsSource": "https://aspnetcore.blob.core.windows.net/buildtools"
|
||||
}
|
||||
```
|
||||
#>
|
||||
[CmdletBinding(PositionalBinding = $false)]
|
||||
param(
|
||||
[string]$Path = $PSScriptRoot,
|
||||
[Alias('c')]
|
||||
[string]$Channel,
|
||||
[Alias('d')]
|
||||
[string]$DotNetHome,
|
||||
[Alias('s')]
|
||||
[string]$ToolsSource,
|
||||
[Alias('u')]
|
||||
[switch]$Update,
|
||||
[string]$ConfigFile = $null,
|
||||
[Parameter(ValueFromRemainingArguments = $true)]
|
||||
[string[]]$MSBuildArgs
|
||||
)
|
||||
|
||||
Set-StrictMode -Version 2
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
#
|
||||
# Functions
|
||||
#
|
||||
|
||||
function Get-KoreBuild {
|
||||
|
||||
$lockFile = Join-Path $Path 'korebuild-lock.txt'
|
||||
|
||||
if (!(Test-Path $lockFile) -or $Update) {
|
||||
Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $lockFile
|
||||
}
|
||||
|
||||
$version = Get-Content $lockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1
|
||||
if (!$version) {
|
||||
Write-Error "Failed to parse version from $lockFile. Expected a line that begins with 'version:'"
|
||||
}
|
||||
$version = $version.TrimStart('version:').Trim()
|
||||
$korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version)
|
||||
|
||||
if (!(Test-Path $korebuildPath)) {
|
||||
Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version"
|
||||
New-Item -ItemType Directory -Path $korebuildPath | Out-Null
|
||||
$remotePath = "$ToolsSource/korebuild/artifacts/$version/korebuild.$version.zip"
|
||||
|
||||
try {
|
||||
$tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip"
|
||||
Get-RemoteFile $remotePath $tmpfile
|
||||
if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) {
|
||||
# Use built-in commands where possible as they are cross-plat compatible
|
||||
Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath
|
||||
}
|
||||
else {
|
||||
# Fallback to old approach for old installations of PowerShell
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory($tmpfile, $korebuildPath)
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Remove-Item -Recurse -Force $korebuildPath -ErrorAction Ignore
|
||||
throw
|
||||
}
|
||||
finally {
|
||||
Remove-Item $tmpfile -ErrorAction Ignore
|
||||
}
|
||||
}
|
||||
|
||||
return $korebuildPath
|
||||
}
|
||||
|
||||
function Join-Paths([string]$path, [string[]]$childPaths) {
|
||||
$childPaths | ForEach-Object { $path = Join-Path $path $_ }
|
||||
return $path
|
||||
}
|
||||
|
||||
function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) {
|
||||
if ($RemotePath -notlike 'http*') {
|
||||
Copy-Item $RemotePath $LocalPath
|
||||
return
|
||||
}
|
||||
|
||||
$retries = 10
|
||||
while ($retries -gt 0) {
|
||||
$retries -= 1
|
||||
try {
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $RemotePath -OutFile $LocalPath
|
||||
return
|
||||
}
|
||||
catch {
|
||||
Write-Verbose "Request failed. $retries retries remaining"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Error "Download failed: '$RemotePath'."
|
||||
}
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
|
||||
# Load configuration or set defaults
|
||||
|
||||
$Path = Resolve-Path $Path
|
||||
if (!$ConfigFile) { $ConfigFile = Join-Path $Path 'korebuild.json' }
|
||||
|
||||
if (Test-Path $ConfigFile) {
|
||||
try {
|
||||
$config = Get-Content -Raw -Encoding UTF8 -Path $ConfigFile | ConvertFrom-Json
|
||||
if ($config) {
|
||||
if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel }
|
||||
if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource}
|
||||
}
|
||||
} catch {
|
||||
Write-Warning "$ConfigFile could not be read. Its settings will be ignored."
|
||||
Write-Warning $Error[0]
|
||||
}
|
||||
}
|
||||
|
||||
if (!$DotNetHome) {
|
||||
$DotNetHome = if ($env:DOTNET_HOME) { $env:DOTNET_HOME } `
|
||||
elseif ($env:USERPROFILE) { Join-Path $env:USERPROFILE '.dotnet'} `
|
||||
elseif ($env:HOME) {Join-Path $env:HOME '.dotnet'}`
|
||||
else { Join-Path $PSScriptRoot '.dotnet'}
|
||||
}
|
||||
|
||||
if (!$Channel) { $Channel = 'dev' }
|
||||
if (!$ToolsSource) { $ToolsSource = 'https://aspnetcore.blob.core.windows.net/buildtools' }
|
||||
|
||||
# Execute
|
||||
|
||||
$korebuildPath = Get-KoreBuild
|
||||
Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1')
|
||||
|
||||
try {
|
||||
Install-Tools $ToolsSource $DotNetHome
|
||||
Invoke-RepositoryBuild $Path @MSBuildArgs
|
||||
}
|
||||
finally {
|
||||
Remove-Module 'KoreBuild' -ErrorAction Ignore
|
||||
}
|
||||
220
build.sh
220
build.sh
@@ -1,220 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
#
|
||||
# variables
|
||||
#
|
||||
|
||||
RESET="\033[0m"
|
||||
RED="\033[0;31m"
|
||||
YELLOW="\033[0;33m"
|
||||
MAGENTA="\033[0;95m"
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
[ -z "${DOTNET_HOME:-}" ] && DOTNET_HOME="$HOME/.dotnet"
|
||||
config_file="$DIR/korebuild.json"
|
||||
verbose=false
|
||||
update=false
|
||||
repo_path="$DIR"
|
||||
channel=''
|
||||
tools_source=''
|
||||
|
||||
#
|
||||
# Functions
|
||||
#
|
||||
__usage() {
|
||||
echo "Usage: $(basename "${BASH_SOURCE[0]}") [options] [[--] <MSBUILD_ARG>...]"
|
||||
echo ""
|
||||
echo "Arguments:"
|
||||
echo " <MSBUILD_ARG>... Arguments passed to MSBuild. Variable number of arguments allowed."
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --verbose Show verbose output."
|
||||
echo " -c|--channel <CHANNEL> The channel of KoreBuild to download. Overrides the value from the config file.."
|
||||
echo " --config-file <FILE> The path to the configuration file that stores values. Defaults to korebuild.json."
|
||||
echo " -d|--dotnet-home <DIR> The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet."
|
||||
echo " --path <PATH> The directory to build. Defaults to the directory containing the script."
|
||||
echo " -s|--tools-source <URL> The base url where build tools can be downloaded. Overrides the value from the config file."
|
||||
echo " -u|--update Update to the latest KoreBuild even if the lock file is present."
|
||||
echo ""
|
||||
echo "Description:"
|
||||
echo " This function will create a file \$DIR/korebuild-lock.txt. This lock file can be committed to source, but does not have to be."
|
||||
echo " When the lockfile is not present, KoreBuild will create one using latest available version from \$channel."
|
||||
|
||||
if [[ "${1:-}" != '--no-exit' ]]; then
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
get_korebuild() {
|
||||
local version
|
||||
local lock_file="$repo_path/korebuild-lock.txt"
|
||||
if [ ! -f "$lock_file" ] || [ "$update" = true ]; then
|
||||
__get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file"
|
||||
fi
|
||||
version="$(grep 'version:*' -m 1 "$lock_file")"
|
||||
if [[ "$version" == '' ]]; then
|
||||
__error "Failed to parse version from $lock_file. Expected a line that begins with 'version:'"
|
||||
return 1
|
||||
fi
|
||||
version="$(echo "${version#version:}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version"
|
||||
|
||||
{
|
||||
if [ ! -d "$korebuild_path" ]; then
|
||||
mkdir -p "$korebuild_path"
|
||||
local remote_path="$tools_source/korebuild/artifacts/$version/korebuild.$version.zip"
|
||||
tmpfile="$(mktemp)"
|
||||
echo -e "${MAGENTA}Downloading KoreBuild ${version}${RESET}"
|
||||
if __get_remote_file "$remote_path" "$tmpfile"; then
|
||||
unzip -q -d "$korebuild_path" "$tmpfile"
|
||||
fi
|
||||
rm "$tmpfile" || true
|
||||
fi
|
||||
|
||||
source "$korebuild_path/KoreBuild.sh"
|
||||
} || {
|
||||
if [ -d "$korebuild_path" ]; then
|
||||
echo "Cleaning up after failed installation"
|
||||
rm -rf "$korebuild_path" || true
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
__error() {
|
||||
echo -e "${RED}error: $*${RESET}" 1>&2
|
||||
}
|
||||
|
||||
__warn() {
|
||||
echo -e "${YELLOW}warning: $*${RESET}"
|
||||
}
|
||||
|
||||
__machine_has() {
|
||||
hash "$1" > /dev/null 2>&1
|
||||
return $?
|
||||
}
|
||||
|
||||
__get_remote_file() {
|
||||
local remote_path=$1
|
||||
local local_path=$2
|
||||
|
||||
if [[ "$remote_path" != 'http'* ]]; then
|
||||
cp "$remote_path" "$local_path"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local failed=false
|
||||
if __machine_has wget; then
|
||||
wget --tries 10 --quiet -O "$local_path" "$remote_path" || failed=true
|
||||
else
|
||||
failed=true
|
||||
fi
|
||||
|
||||
if [ "$failed" = true ] && __machine_has curl; then
|
||||
failed=false
|
||||
curl --retry 10 -sSL -f --create-dirs -o "$local_path" "$remote_path" || failed=true
|
||||
fi
|
||||
|
||||
if [ "$failed" = true ]; then
|
||||
__error "Download failed: $remote_path" 1>&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# main
|
||||
#
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-\?|-h|--help)
|
||||
__usage --no-exit
|
||||
exit 0
|
||||
;;
|
||||
-c|--channel|-Channel)
|
||||
shift
|
||||
channel="${1:-}"
|
||||
[ -z "$channel" ] && __usage
|
||||
;;
|
||||
--config-file|-ConfigFile)
|
||||
shift
|
||||
config_file="${1:-}"
|
||||
[ -z "$config_file" ] && __usage
|
||||
if [ ! -f "$config_file" ]; then
|
||||
__error "Invalid value for --config-file. $config_file does not exist."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
-d|--dotnet-home|-DotNetHome)
|
||||
shift
|
||||
DOTNET_HOME="${1:-}"
|
||||
[ -z "$DOTNET_HOME" ] && __usage
|
||||
;;
|
||||
--path|-Path)
|
||||
shift
|
||||
repo_path="${1:-}"
|
||||
[ -z "$repo_path" ] && __usage
|
||||
;;
|
||||
-s|--tools-source|-ToolsSource)
|
||||
shift
|
||||
tools_source="${1:-}"
|
||||
[ -z "$tools_source" ] && __usage
|
||||
;;
|
||||
-u|--update|-Update)
|
||||
update=true
|
||||
;;
|
||||
--verbose|-Verbose)
|
||||
verbose=true
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if ! __machine_has unzip; then
|
||||
__error 'Missing required command: unzip'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! __machine_has curl && ! __machine_has wget; then
|
||||
__error 'Missing required command. Either wget or curl is required.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[ -z "${config_file:-}" ] && config_file="$repo_path/korebuild.json"
|
||||
if [ -f "$config_file" ]; then
|
||||
if __machine_has jq ; then
|
||||
if jq '.' "$config_file" >/dev/null ; then
|
||||
config_channel="$(jq -r 'select(.channel!=null) | .channel' "$config_file")"
|
||||
config_tools_source="$(jq -r 'select(.toolsSource!=null) | .toolsSource' "$config_file")"
|
||||
else
|
||||
__warn "$config_file is invalid JSON. Its settings will be ignored."
|
||||
fi
|
||||
elif __machine_has python ; then
|
||||
if python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'))" >/dev/null ; then
|
||||
config_channel="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['channel'] if 'channel' in obj else '')")"
|
||||
config_tools_source="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['toolsSource'] if 'toolsSource' in obj else '')")"
|
||||
else
|
||||
__warn "$config_file is invalid JSON. Its settings will be ignored."
|
||||
fi
|
||||
else
|
||||
__warn 'Missing required command: jq or pyton. Could not parse the JSON file. Its settings will be ignored.'
|
||||
fi
|
||||
|
||||
[ ! -z "${config_channel:-}" ] && channel="$config_channel"
|
||||
[ ! -z "${config_tools_source:-}" ] && tools_source="$config_tools_source"
|
||||
fi
|
||||
|
||||
[ -z "$channel" ] && channel='dev'
|
||||
[ -z "$tools_source" ] && tools_source='https://aspnetcore.blob.core.windows.net/buildtools'
|
||||
|
||||
get_korebuild
|
||||
install_tools "$tools_source" "$DOTNET_HOME"
|
||||
invoke_repository_build "$repo_path" "$@"
|
||||
@@ -1,23 +0,0 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<InternalAspNetCoreSdkPackageVersion>2.0.2-rc1-15526</InternalAspNetCoreSdkPackageVersion>
|
||||
<MicrosoftAspNetCoreDiagnosticsPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreDiagnosticsPackageVersion>
|
||||
<MicrosoftAspNetCoreHostingAbstractionsPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreHostingAbstractionsPackageVersion>
|
||||
<MicrosoftAspNetCoreHostingPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreHostingPackageVersion>
|
||||
<MicrosoftAspNetCoreMvcPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreMvcPackageVersion>
|
||||
<MicrosoftAspNetCoreMvcTagHelpersPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreMvcTagHelpersPackageVersion>
|
||||
<MicrosoftAspNetCoreMvcViewFeaturesPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreMvcViewFeaturesPackageVersion>
|
||||
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
|
||||
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreServerKestrelPackageVersion>
|
||||
<MicrosoftAspNetCoreStaticFilesPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreStaticFilesPackageVersion>
|
||||
<MicrosoftExtensionsDependencyInjectionPackageVersion>2.0.0</MicrosoftExtensionsDependencyInjectionPackageVersion>
|
||||
<MicrosoftExtensionsLoggingConsolePackageVersion>2.0.0</MicrosoftExtensionsLoggingConsolePackageVersion>
|
||||
<MicrosoftExtensionsLoggingDebugPackageVersion>2.0.0</MicrosoftExtensionsLoggingDebugPackageVersion>
|
||||
<NewtonsoftJsonRuntimePackageVersion>10.0.1</NewtonsoftJsonRuntimePackageVersion>
|
||||
<MicrosoftNETCoreApp20PackageVersion>2.0.5</MicrosoftNETCoreApp20PackageVersion>
|
||||
<NETStandardLibrary20PackageVersion>2.0.1</NETStandardLibrary20PackageVersion>
|
||||
<SystemThreadingTasksDataflowPackageVersion>4.8.0</SystemThreadingTasksDataflowPackageVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(DotNetPackageVersionPropsPath)" Condition=" '$(DotNetPackageVersionPropsPath)' != '' " />
|
||||
</Project>
|
||||
@@ -1,2 +0,0 @@
|
||||
version:2.0.5-rtm-10016
|
||||
commithash:02bda79ac9c564229da734a836f258d6c1321eb7
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/release/2.0/tools/korebuild.schema.json",
|
||||
"channel": "release/2.0"
|
||||
}
|
||||
31
src/JavaScriptServices/.gitignore
vendored
Normal file
31
src/JavaScriptServices/.gitignore
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
[Oo]bj/
|
||||
[Bb]in/
|
||||
TestResults/
|
||||
.nuget/
|
||||
*.sln.ide/
|
||||
_ReSharper.*/
|
||||
packages/
|
||||
artifacts/
|
||||
PublishProfiles/
|
||||
*.user
|
||||
*.suo
|
||||
*.cache
|
||||
*.docstates
|
||||
_ReSharper.*
|
||||
nuget.exe
|
||||
*net45.csproj
|
||||
*net451.csproj
|
||||
*k10.csproj
|
||||
*.psess
|
||||
*.vsp
|
||||
*.pidb
|
||||
*.userprefs
|
||||
*DS_Store
|
||||
*.ncrunchsolution
|
||||
*.*sdf
|
||||
*.ipch
|
||||
.vs/
|
||||
npm-debug.log
|
||||
/.build/
|
||||
.vscode/
|
||||
global.json
|
||||
@@ -1,17 +1,15 @@
|
||||
<Project>
|
||||
<Import Project="version.props" />
|
||||
<Import Project="build\dependencies.props" />
|
||||
<Import Project="build\sources.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<Product>Microsoft ASP.NET Core</Product>
|
||||
<RepositoryUrl>https://github.com/aspnet/javascriptservices</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)Key.snk</AssemblyOriginatorKeyFile>
|
||||
<RepositoryRoot>$(MSBuildThisFileDirectory)</RepositoryRoot>
|
||||
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)build\Key.snk</AssemblyOriginatorKeyFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Internal.AspNetCore.Sdk" Version="$(InternalAspNetCoreSdkPackageVersion)" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">$(MicrosoftNETCoreAppPackageVersion)</RuntimeFrameworkVersion>
|
||||
<NETStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard2.0' ">$(NETStandardLibrary20PackageVersion)</NETStandardImplicitPackageVersion>
|
||||
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">$(MicrosoftNETCoreApp20PackageVersion)</RuntimeFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,9 +1,12 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.4
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
VisualStudioVersion = 15.0.26730.16
|
||||
MinimumVisualStudioVersion = 15.0.26730.03
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{27304DDE-AFB2-4F8B-B765-E3E2F11E886C}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
src\Directory.Build.props = src\Directory.Build.props
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.NodeServices", "src\Microsoft.AspNetCore.NodeServices\Microsoft.AspNetCore.NodeServices.csproj", "{66B77203-1469-41DF-92F2-2BE6900BD36F}"
|
||||
EndProject
|
||||
@@ -28,14 +31,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Webpack", "samples\misc\Web
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NodeServicesExamples", "samples\misc\NodeServicesExamples\NodeServicesExamples.csproj", "{93EFCC5F-C6EE-4623-894F-A42B22C0B6FE}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{1598B415-73F1-4B37-B3B4-0A10677ABB2D}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{E415FE14-13B0-469F-836D-95059E6BAA6E}"
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{645F7363-1240-4FB6-9422-B32A327C979F}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
src\build\common.props = src\build\common.props
|
||||
src\build\Key.snk = src\build\Key.snk
|
||||
Directory.Build.props = Directory.Build.props
|
||||
Directory.Build.targets = Directory.Build.targets
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SpaServices.Extensions", "src\Microsoft.AspNetCore.SpaServices.Extensions\Microsoft.AspNetCore.SpaServices.Extensions.csproj", "{D40BD1C4-6A6F-4213-8535-1057F3EB3400}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -66,6 +69,10 @@ Global
|
||||
{93EFCC5F-C6EE-4623-894F-A42B22C0B6FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{93EFCC5F-C6EE-4623-894F-A42B22C0B6FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{93EFCC5F-C6EE-4623-894F-A42B22C0B6FE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D40BD1C4-6A6F-4213-8535-1057F3EB3400}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D40BD1C4-6A6F-4213-8535-1057F3EB3400}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D40BD1C4-6A6F-4213-8535-1057F3EB3400}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D40BD1C4-6A6F-4213-8535-1057F3EB3400}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -78,5 +85,9 @@ Global
|
||||
{1931B19A-EC42-4D56-B2D0-FB06D17244DA} = {E6A161EA-646C-4033-9090-95BE809AB8D9}
|
||||
{DE479DC3-1461-4EAD-A188-4AF7AA4AE344} = {E6A161EA-646C-4033-9090-95BE809AB8D9}
|
||||
{93EFCC5F-C6EE-4623-894F-A42B22C0B6FE} = {E6A161EA-646C-4033-9090-95BE809AB8D9}
|
||||
{D40BD1C4-6A6F-4213-8535-1057F3EB3400} = {27304DDE-AFB2-4F8B-B765-E3E2F11E886C}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {DDF59B0D-2DEC-45D6-8667-DCB767487101}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
7
src/JavaScriptServices/NuGetPackageVerifier.json
Normal file
7
src/JavaScriptServices/NuGetPackageVerifier.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"Default": {
|
||||
"rules": [
|
||||
"DefaultCompositeRule"
|
||||
]
|
||||
}
|
||||
}
|
||||
96
src/JavaScriptServices/README.md
Normal file
96
src/JavaScriptServices/README.md
Normal file
@@ -0,0 +1,96 @@
|
||||
# JavaScriptServices
|
||||
|
||||
AppVeyor: [](https://ci.appveyor.com/project/aspnetci/javascriptservices/branch/dev)
|
||||
|
||||
This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the [Home](https://github.com/aspnet/home) repo.
|
||||
|
||||
## What is this?
|
||||
|
||||
`JavaScriptServices` is a set of client-side technologies for ASP.NET Core. It provides infrastructure that you'll find useful if you:
|
||||
|
||||
- Use Angular / React / Vue / Aurelia / Knockout / etc.
|
||||
- Build your client-side resources using Webpack.
|
||||
- Execute JavaScript on the server at runtime.
|
||||
|
||||
Read [Building Single Page Applications on ASP.NET Core with JavaScriptServices](https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/) for more details.
|
||||
|
||||
This repo contains:
|
||||
|
||||
* A set of NuGet/NPM packages that implement functionality for:
|
||||
* Invoking arbitrary NPM packages at runtime from .NET code ([docs](/src/Microsoft.AspNetCore.NodeServices#simple-usage-example))
|
||||
* Server-side prerendering of SPA components ([docs](/src/Microsoft.AspNetCore.SpaServices#server-side-prerendering))
|
||||
* Webpack dev middleware ([docs](/src/Microsoft.AspNetCore.SpaServices#webpack-dev-middleware))
|
||||
* Hot module replacement (HMR) ([docs](/src/Microsoft.AspNetCore.SpaServices#webpack-hot-module-replacement))
|
||||
* Server-side and client-side routing integration ([docs](/src/Microsoft.AspNetCore.SpaServices#routing-helper-mapspafallbackroute))
|
||||
* Server-side and client-side validation integration
|
||||
* "Lazy loading" for Knockout apps
|
||||
* Samples and docs
|
||||
|
||||
It's cross-platform (Windows, Linux, or macOS) and works with .NET Core 2.0 or later.
|
||||
|
||||
## Creating new applications
|
||||
|
||||
Prerequisites:
|
||||
|
||||
* [.NET Core 2.0](https://www.microsoft.com/net/core) (or later) SDK
|
||||
* [Node.js](https://nodejs.org/) version 6 (or later)
|
||||
|
||||
With these prerequisites, you can immediately create new ASP.NET Core applications that use Angular, React, or React+Redux without having to install anything extra.
|
||||
|
||||
### Option 1: Creating Angular/React/Redux applications from the command line (cross-platform)
|
||||
|
||||
In an empty directory, run (for example) `dotnet new angular`. Other supported SPA frameworks include React and React+Redux. You can see the list of available SPA templates by running `dotnet new spa`.
|
||||
|
||||
Once the generator has run and restored all the dependencies, you can start up your new ASP.NET Core SPA:
|
||||
|
||||
npm install
|
||||
dotnet run
|
||||
|
||||
### Option 2: Creating Angular/React/Redux applications using Visual Studio 2017 Update 3 or later (Windows only)
|
||||
|
||||
Using the `File`->`New Project` dialog, select *ASP.NET Core Web Application*. You will then be offered the option to create an application with Angular, React, or React+Redux. When the application is created, you can build and run it in the normal way.
|
||||
|
||||
### More info and other SPA frameworks
|
||||
|
||||
For a more detailed (albeit somewhat outdated) walkthrough, see [getting started with the `aspnetcore-spa` generator](http://blog.stevensanderson.com/2016/05/02/angular2-react-knockout-apps-on-aspnet-core/).
|
||||
|
||||
If you want to build an ASP.NET Core application with Aurelia, Knockout, or Vue, you can use the `Microsoft.AspNetCore.SpaTemplates` package. On the command line, run `dotnet new --install Microsoft.AspNetCore.SpaTemplates`. Then you will be able to run `dotnet new aurelia` (or `dotnet new vue`, etc.) to create your new application.
|
||||
|
||||
## Adding to existing applications
|
||||
|
||||
If you have an existing ASP.NET Core application, or if you just want to use the underlying JavaScriptServices packages directly, you can install these packages using NuGet and NPM:
|
||||
|
||||
* `Microsoft.AspNetCore.NodeServices`
|
||||
* This provides a fast and robust way for .NET code to run JavaScript on the server inside a Node.js environment. You can use this to consume arbitrary functionality from NPM packages at runtime in your ASP.NET Core app.
|
||||
* Most applications developers don't need to use this directly, but you can do so if you want to implement your own functionality that involves calling Node.js code from .NET at runtime.
|
||||
* Find [documentation and usage examples here](/src/Microsoft.AspNetCore.NodeServices#microsoftaspnetcorenodeservices).
|
||||
* `Microsoft.AspNetCore.SpaServices`
|
||||
* This provides infrastructure that's generally useful when building Single Page Applications (SPAs) with technologies such as Angular or React (for example, server-side prerendering and webpack middleware). Internally, it uses the `NodeServices` package to implement its features.
|
||||
* Find [documentation and usage examples here](/src/Microsoft.AspNetCore.SpaServices#microsoftaspnetcorespaservices)
|
||||
|
||||
There were previously other packages called `Microsoft.AspNetCore.AngularServices` and `Microsoft.AspNetCore.ReactServices` but these are not currently needed - all applicable functionality is in `Microsoft.AspNetCore.SpaServices`, because it's sufficiently general.
|
||||
|
||||
If you want to build a helper library for some other SPA framework, you can do so by taking a dependency on `Microsoft.AspNetCore.SpaServices` and wrapping its functionality in whatever way is most useful for your SPA framework.
|
||||
|
||||
## Samples
|
||||
|
||||
The [`samples` directory](/samples) contains examples of:
|
||||
|
||||
- Using the JavaScript services family of packages with Angular and React.
|
||||
- A standalone `NodeServices` usage for runtime code transpilation and image processing.
|
||||
|
||||
**To run the samples:**
|
||||
|
||||
* Clone this repo
|
||||
* At the repo's root directory (the one containing `src`, `samples`, etc.), run `dotnet restore`
|
||||
* Change directory to the sample you want to run (for example, `cd samples/angular/MusicStore`)
|
||||
* Restore Node dependencies by running `npm install`
|
||||
* If you're trying to run the Angular "Music Store" sample, then also run `gulp` (which you need to have installed globally). None of the other samples require this.
|
||||
* Run the application (`dotnet run`)
|
||||
* Browse to [http://localhost:5000](http://localhost:5000)
|
||||
|
||||
## Contributing
|
||||
|
||||
If you're interested in contributing to the various packages, samples, and project templates in this repo, that's great!
|
||||
|
||||
Before working on a pull request, especially if it's more than a trivial fix (for example, for a typo), it's usually a good idea first to file an issue describing what you're proposing to do and how it will work. Then you can find out if it's likely that such a pull request will be accepted, and how it fits into wider ongoing plans.
|
||||
30
src/JavaScriptServices/build/dependencies.props
Normal file
30
src/JavaScriptServices/build/dependencies.props
Normal file
@@ -0,0 +1,30 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Package Versions">
|
||||
<InternalAspNetCoreSdkPackageVersion>3.0.0-build-20181114.5</InternalAspNetCoreSdkPackageVersion>
|
||||
<MicrosoftAspNetCoreDiagnosticsPackageVersion>3.0.0-alpha1-10742</MicrosoftAspNetCoreDiagnosticsPackageVersion>
|
||||
<MicrosoftAspNetCoreHostingAbstractionsPackageVersion>3.0.0-alpha1-10742</MicrosoftAspNetCoreHostingAbstractionsPackageVersion>
|
||||
<MicrosoftAspNetCoreHostingPackageVersion>3.0.0-alpha1-10742</MicrosoftAspNetCoreHostingPackageVersion>
|
||||
<MicrosoftAspNetCoreMvcPackageVersion>3.0.0-alpha1-10742</MicrosoftAspNetCoreMvcPackageVersion>
|
||||
<MicrosoftAspNetCoreMvcTagHelpersPackageVersion>3.0.0-alpha1-10742</MicrosoftAspNetCoreMvcTagHelpersPackageVersion>
|
||||
<MicrosoftAspNetCoreMvcViewFeaturesPackageVersion>3.0.0-alpha1-10742</MicrosoftAspNetCoreMvcViewFeaturesPackageVersion>
|
||||
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>3.0.0-alpha1-10742</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
|
||||
<MicrosoftAspNetCoreServerKestrelPackageVersion>3.0.0-alpha1-10742</MicrosoftAspNetCoreServerKestrelPackageVersion>
|
||||
<MicrosoftAspNetCoreStaticFilesPackageVersion>3.0.0-alpha1-10742</MicrosoftAspNetCoreStaticFilesPackageVersion>
|
||||
<MicrosoftAspNetCoreWebSocketsPackageVersion>3.0.0-alpha1-10742</MicrosoftAspNetCoreWebSocketsPackageVersion>
|
||||
<MicrosoftExtensionsDependencyInjectionPackageVersion>3.0.0-preview-181113-11</MicrosoftExtensionsDependencyInjectionPackageVersion>
|
||||
<MicrosoftExtensionsFileProvidersPhysicalPackageVersion>3.0.0-preview-181113-11</MicrosoftExtensionsFileProvidersPhysicalPackageVersion>
|
||||
<MicrosoftExtensionsLoggingAbstractionsPackageVersion>3.0.0-preview-181113-11</MicrosoftExtensionsLoggingAbstractionsPackageVersion>
|
||||
<MicrosoftExtensionsLoggingConsolePackageVersion>3.0.0-preview-181113-11</MicrosoftExtensionsLoggingConsolePackageVersion>
|
||||
<MicrosoftExtensionsLoggingDebugPackageVersion>3.0.0-preview-181113-11</MicrosoftExtensionsLoggingDebugPackageVersion>
|
||||
<MicrosoftNETCoreAppPackageVersion>3.0.0-preview1-26907-05</MicrosoftNETCoreAppPackageVersion>
|
||||
<MicrosoftNETSdkRazorPackageVersion>3.0.0-alpha1-10742</MicrosoftNETSdkRazorPackageVersion>
|
||||
<NETStandardLibrary20PackageVersion>2.0.3</NETStandardLibrary20PackageVersion>
|
||||
<NewtonsoftJsonPackageVersion>11.0.2</NewtonsoftJsonPackageVersion>
|
||||
<SystemThreadingTasksDataflowPackageVersion>4.10.0-preview1-26907-04</SystemThreadingTasksDataflowPackageVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(DotNetPackageVersionPropsPath)" Condition=" '$(DotNetPackageVersionPropsPath)' != '' " />
|
||||
<PropertyGroup Label="Package Versions: Pinned" />
|
||||
</Project>
|
||||
13
src/JavaScriptServices/build/repo.props
Normal file
13
src/JavaScriptServices/build/repo.props
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project>
|
||||
<Import Project="dependencies.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- These properties are use by the automation that updates dependencies.props -->
|
||||
<LineupPackageId>Internal.AspNetCore.Universe.Lineup</LineupPackageId>
|
||||
<LineupPackageRestoreSource>https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json</LineupPackageRestoreSource>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DotNetCoreRuntime Include="$(MicrosoftNETCoreAppPackageVersion)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,12 +1,12 @@
|
||||
<Project>
|
||||
<Project>
|
||||
<Import Project="$(DotNetRestoreSourcePropsPath)" Condition="'$(DotNetRestoreSourcePropsPath)' != ''"/>
|
||||
|
||||
<PropertyGroup>
|
||||
<PropertyGroup Label="RestoreSources">
|
||||
<RestoreSources>$(DotNetRestoreSources)</RestoreSources>
|
||||
<RestoreSources Condition="'$(DotNetBuildOffline)' != 'true' AND '$(AspNetUniverseBuildOffline)' != 'true' ">
|
||||
$(RestoreSources);
|
||||
https://dotnet.myget.org/F/aspnet-2-0-2-october2017-patch/api/v3/index.json;
|
||||
https://dotnet.myget.org/F/aspnetcore-master/api/v3/index.json;
|
||||
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json;
|
||||
https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
|
||||
https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json;
|
||||
</RestoreSources>
|
||||
<RestoreSources Condition="'$(DotNetBuildOffline)' != 'true'">
|
||||
@@ -1,9 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\..\build\common.props" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<OutputType>exe</OutputType>
|
||||
</PropertyGroup>
|
||||
@@ -15,6 +13,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsLoggingConsolePackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
1
samples/misc/LatencyTest/Program.cs → src/JavaScriptServices/samples/misc/LatencyTest/Program.cs
Executable file → Normal file
1
samples/misc/LatencyTest/Program.cs → src/JavaScriptServices/samples/misc/LatencyTest/Program.cs
Executable file → Normal file
@@ -21,7 +21,6 @@ namespace ConsoleApplication
|
||||
// Since .NET Core 1.1, the HTTP hosting model has become basically as fast as the Socket hosting model
|
||||
//options.UseSocketHosting();
|
||||
|
||||
options.ProjectPath = Directory.GetCurrentDirectory();
|
||||
options.WatchFileExtensions = new string[] {}; // Don't watch anything
|
||||
});
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
@@ -1,9 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<Import Project="..\..\..\build\common.props" />
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
@@ -20,6 +18,8 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="$(MicrosoftAspNetCoreStaticFilesPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="$(MicrosoftExtensionsLoggingDebugPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsLoggingConsolePackageVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Sdk.Razor" Version="$(MicrosoftNETSdkRazorPackageVersion)" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
|
||||
0
samples/misc/NodeServicesExamples/Startup.cs → src/JavaScriptServices/samples/misc/NodeServicesExamples/Startup.cs
Executable file → Normal file
0
samples/misc/NodeServicesExamples/Startup.cs → src/JavaScriptServices/samples/misc/NodeServicesExamples/Startup.cs
Executable file → Normal file
0
samples/misc/NodeServicesExamples/appsettings.json → src/JavaScriptServices/samples/misc/NodeServicesExamples/appsettings.json
Executable file → Normal file
0
samples/misc/NodeServicesExamples/appsettings.json → src/JavaScriptServices/samples/misc/NodeServicesExamples/appsettings.json
Executable file → Normal file
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
0
samples/misc/Webpack/Controllers/HomeController.cs → src/JavaScriptServices/samples/misc/Webpack/Controllers/HomeController.cs
Executable file → Normal file
0
samples/misc/Webpack/Controllers/HomeController.cs → src/JavaScriptServices/samples/misc/Webpack/Controllers/HomeController.cs
Executable file → Normal file
0
samples/misc/Webpack/Startup.cs → src/JavaScriptServices/samples/misc/Webpack/Startup.cs
Executable file → Normal file
0
samples/misc/Webpack/Startup.cs → src/JavaScriptServices/samples/misc/Webpack/Startup.cs
Executable file → Normal file
0
samples/misc/Webpack/Views/Home/Index.cshtml → src/JavaScriptServices/samples/misc/Webpack/Views/Home/Index.cshtml
Executable file → Normal file
0
samples/misc/Webpack/Views/Home/Index.cshtml → src/JavaScriptServices/samples/misc/Webpack/Views/Home/Index.cshtml
Executable file → Normal file
0
samples/misc/Webpack/Views/Shared/Error.cshtml → src/JavaScriptServices/samples/misc/Webpack/Views/Shared/Error.cshtml
Executable file → Normal file
0
samples/misc/Webpack/Views/Shared/Error.cshtml → src/JavaScriptServices/samples/misc/Webpack/Views/Shared/Error.cshtml
Executable file → Normal file
0
samples/misc/Webpack/Views/Shared/_Layout.cshtml → src/JavaScriptServices/samples/misc/Webpack/Views/Shared/_Layout.cshtml
Executable file → Normal file
0
samples/misc/Webpack/Views/Shared/_Layout.cshtml → src/JavaScriptServices/samples/misc/Webpack/Views/Shared/_Layout.cshtml
Executable file → Normal file
0
samples/misc/Webpack/Views/_ViewImports.cshtml → src/JavaScriptServices/samples/misc/Webpack/Views/_ViewImports.cshtml
Executable file → Normal file
0
samples/misc/Webpack/Views/_ViewImports.cshtml → src/JavaScriptServices/samples/misc/Webpack/Views/_ViewImports.cshtml
Executable file → Normal file
0
samples/misc/Webpack/Views/_ViewStart.cshtml → src/JavaScriptServices/samples/misc/Webpack/Views/_ViewStart.cshtml
Executable file → Normal file
0
samples/misc/Webpack/Views/_ViewStart.cshtml → src/JavaScriptServices/samples/misc/Webpack/Views/_ViewStart.cshtml
Executable file → Normal file
@@ -1,9 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<Import Project="..\..\..\build\common.props" />
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
@@ -20,6 +18,8 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="$(MicrosoftAspNetCoreStaticFilesPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="$(MicrosoftExtensionsLoggingDebugPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsLoggingConsolePackageVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Sdk.Razor" Version="$(MicrosoftNETSdkRazorPackageVersion)" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
|
||||
0
samples/misc/Webpack/appsettings.json → src/JavaScriptServices/samples/misc/Webpack/appsettings.json
Executable file → Normal file
0
samples/misc/Webpack/appsettings.json → src/JavaScriptServices/samples/misc/Webpack/appsettings.json
Executable file → Normal file
0
samples/misc/Webpack/wwwroot/favicon.ico → src/JavaScriptServices/samples/misc/Webpack/wwwroot/favicon.ico
Executable file → Normal file
0
samples/misc/Webpack/wwwroot/favicon.ico → src/JavaScriptServices/samples/misc/Webpack/wwwroot/favicon.ico
Executable file → Normal file
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
28
src/JavaScriptServices/scripts/Regenerate-JSFiles.ps1
Normal file
28
src/JavaScriptServices/scripts/Regenerate-JSFiles.ps1
Normal file
@@ -0,0 +1,28 @@
|
||||
[cmdletbinding(SupportsShouldProcess = $true)]
|
||||
param(
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 2
|
||||
|
||||
Push-Location "src"
|
||||
try {
|
||||
$dirs = Get-ChildItem -Directory
|
||||
foreach($dir in $dirs)
|
||||
{
|
||||
Push-Location $dir
|
||||
try{
|
||||
if(Test-Path -Path "package.json")
|
||||
{
|
||||
npm install
|
||||
npm run build
|
||||
}
|
||||
}
|
||||
finally{
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
13
src/JavaScriptServices/src/Directory.Build.props
Normal file
13
src/JavaScriptServices/src/Directory.Build.props
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project>
|
||||
<Import Project="..\Directory.Build.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;aspnetcoremvc;nodeservices</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Internal.AspNetCore.Sdk" PrivateAssets="All" Version="$(InternalAspNetCoreSdkPackageVersion)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,626 @@
|
||||
(function (e, a) { for (var i in a) e[i] = a[i]; }(exports, /******/(function (modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if (installedModules[moduleId]) {
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
/******/
|
||||
}
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/
|
||||
};
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/
|
||||
}
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function (exports, name, getter) {
|
||||
/******/ if (!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
||||
/******/
|
||||
}
|
||||
/******/
|
||||
};
|
||||
/******/
|
||||
/******/ // define __esModule on exports
|
||||
/******/ __webpack_require__.r = function (exports) {
|
||||
/******/ if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
/******/
|
||||
}
|
||||
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||
/******/
|
||||
};
|
||||
/******/
|
||||
/******/ // create a fake namespace object
|
||||
/******/ // mode & 1: value is a module id, require it
|
||||
/******/ // mode & 2: merge all properties of value into the ns
|
||||
/******/ // mode & 4: return value when already ns object
|
||||
/******/ // mode & 8|1: behave like require
|
||||
/******/ __webpack_require__.t = function (value, mode) {
|
||||
/******/ if (mode & 1) value = __webpack_require__(value);
|
||||
/******/ if (mode & 8) return value;
|
||||
/******/ if ((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
||||
/******/ var ns = Object.create(null);
|
||||
/******/ __webpack_require__.r(ns);
|
||||
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
||||
/******/ if (mode & 2 && typeof value != 'string') for (var key in value) __webpack_require__.d(ns, key, function (key) { return value[key]; }.bind(null, key));
|
||||
/******/ return ns;
|
||||
/******/
|
||||
};
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function (module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/
|
||||
};
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function (object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
/******/
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
||||
/******/
|
||||
})
|
||||
/************************************************************************/
|
||||
/******/([
|
||||
/* 0 */
|
||||
/***/ (function (module, exports, __webpack_require__) {
|
||||
|
||||
module.exports = __webpack_require__(1);
|
||||
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 1 */
|
||||
/***/ (function (module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
// Limit dependencies to core Node modules. This means the code in this file has to be very low-level and unattractive,
|
||||
// but simplifies things for the consumer of this module.
|
||||
__webpack_require__(2);
|
||||
var net = __webpack_require__(3);
|
||||
var path = __webpack_require__(4);
|
||||
var readline = __webpack_require__(5);
|
||||
var ArgsUtil_1 = __webpack_require__(6);
|
||||
var ExitWhenParentExits_1 = __webpack_require__(7);
|
||||
var virtualConnectionServer = __webpack_require__(8);
|
||||
// Webpack doesn't support dynamic requires for files not present at compile time, so grab a direct
|
||||
// reference to Node's runtime 'require' function.
|
||||
var dynamicRequire = eval('require');
|
||||
// Signal to the .NET side when we're ready to accept invocations
|
||||
var server = net.createServer().on('listening', function () {
|
||||
console.log('[Microsoft.AspNetCore.NodeServices:Listening]');
|
||||
});
|
||||
// Each virtual connection represents a separate invocation
|
||||
virtualConnectionServer.createInterface(server).on('connection', function (connection) {
|
||||
readline.createInterface(connection, null).on('line', function (line) {
|
||||
try {
|
||||
// Get a reference to the function to invoke
|
||||
var invocation = JSON.parse(line);
|
||||
var invokedModule = dynamicRequire(path.resolve(process.cwd(), invocation.moduleName));
|
||||
var invokedFunction = invocation.exportedFunctionName ? invokedModule[invocation.exportedFunctionName] : invokedModule;
|
||||
// Prepare a callback for accepting non-streamed JSON responses
|
||||
var hasInvokedCallback_1 = false;
|
||||
var invocationCallback = function (errorValue, successValue) {
|
||||
if (hasInvokedCallback_1) {
|
||||
throw new Error('Cannot supply more than one result. The callback has already been invoked,'
|
||||
+ ' or the result stream has already been accessed');
|
||||
}
|
||||
hasInvokedCallback_1 = true;
|
||||
connection.end(JSON.stringify({
|
||||
result: successValue,
|
||||
errorMessage: errorValue && (errorValue.message || errorValue),
|
||||
errorDetails: errorValue && (errorValue.stack || null)
|
||||
}));
|
||||
};
|
||||
// Also support streamed binary responses
|
||||
Object.defineProperty(invocationCallback, 'stream', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
hasInvokedCallback_1 = true;
|
||||
return connection;
|
||||
}
|
||||
});
|
||||
// Actually invoke it, passing through any supplied args
|
||||
invokedFunction.apply(null, [invocationCallback].concat(invocation.args));
|
||||
}
|
||||
catch (ex) {
|
||||
connection.end(JSON.stringify({
|
||||
errorMessage: ex.message,
|
||||
errorDetails: ex.stack
|
||||
}));
|
||||
}
|
||||
});
|
||||
});
|
||||
// Begin listening now. The underlying transport varies according to the runtime platform.
|
||||
// On Windows it's Named Pipes; on Linux/OSX it's Domain Sockets.
|
||||
var useWindowsNamedPipes = /^win/.test(process.platform);
|
||||
var parsedArgs = ArgsUtil_1.parseArgs(process.argv);
|
||||
var listenAddress = (useWindowsNamedPipes ? '\\\\.\\pipe\\' : '/tmp/') + parsedArgs.listenAddress;
|
||||
server.listen(listenAddress);
|
||||
ExitWhenParentExits_1.exitWhenParentExits(parseInt(parsedArgs.parentPid), /* ignoreSigint */ true);
|
||||
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 2 */
|
||||
/***/ (function (module, exports) {
|
||||
|
||||
// When Node writes to stdout/strerr, we capture that and convert the lines into calls on the
|
||||
// active .NET ILogger. But by default, stdout/stderr don't have any way of distinguishing
|
||||
// linebreaks inside log messages from the linebreaks that delimit separate log messages,
|
||||
// so multiline strings will end up being written to the ILogger as multiple independent
|
||||
// log messages. This makes them very hard to make sense of, especially when they represent
|
||||
// something like stack traces.
|
||||
//
|
||||
// To fix this, we intercept stdout/stderr writes, and replace internal linebreaks with a
|
||||
// marker token. When .NET receives the lines, it converts the marker tokens back to regular
|
||||
// linebreaks within the logged messages.
|
||||
//
|
||||
// Note that it's better to do the interception at the stdout/stderr level, rather than at
|
||||
// the console.log/console.error (etc.) level, because this takes place after any native
|
||||
// message formatting has taken place (e.g., inserting values for % placeholders).
|
||||
var findInternalNewlinesRegex = /\n(?!$)/g;
|
||||
var encodedNewline = '__ns_newline__';
|
||||
encodeNewlinesWrittenToStream(process.stdout);
|
||||
encodeNewlinesWrittenToStream(process.stderr);
|
||||
function encodeNewlinesWrittenToStream(outputStream) {
|
||||
var origWriteFunction = outputStream.write;
|
||||
outputStream.write = function (value) {
|
||||
// Only interfere with the write if it's definitely a string
|
||||
if (typeof value === 'string') {
|
||||
var argsClone = Array.prototype.slice.call(arguments, 0);
|
||||
argsClone[0] = encodeNewlinesInString(value);
|
||||
origWriteFunction.apply(this, argsClone);
|
||||
}
|
||||
else {
|
||||
origWriteFunction.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
function encodeNewlinesInString(str) {
|
||||
return str.replace(findInternalNewlinesRegex, encodedNewline);
|
||||
}
|
||||
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 3 */
|
||||
/***/ (function (module, exports) {
|
||||
|
||||
module.exports = require("net");
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 4 */
|
||||
/***/ (function (module, exports) {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 5 */
|
||||
/***/ (function (module, exports) {
|
||||
|
||||
module.exports = require("readline");
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 6 */
|
||||
/***/ (function (module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
function parseArgs(args) {
|
||||
// Very simplistic parsing which is sufficient for the cases needed. We don't want to bring in any external
|
||||
// dependencies (such as an args-parsing library) to this file.
|
||||
var result = {};
|
||||
var currentKey = null;
|
||||
args.forEach(function (arg) {
|
||||
if (arg.indexOf('--') === 0) {
|
||||
var argName = arg.substring(2);
|
||||
result[argName] = undefined;
|
||||
currentKey = argName;
|
||||
}
|
||||
else if (currentKey) {
|
||||
result[currentKey] = arg;
|
||||
currentKey = null;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
exports.parseArgs = parseArgs;
|
||||
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 7 */
|
||||
/***/ (function (module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
In general, we want the Node child processes to be terminated as soon as the parent .NET processes exit,
|
||||
because we have no further use for them. If the .NET process shuts down gracefully, it will run its
|
||||
finalizers, one of which (in OutOfProcessNodeInstance.cs) will kill its associated Node process immediately.
|
||||
|
||||
But if the .NET process is terminated forcefully (e.g., on Linux/OSX with 'kill -9'), then it won't have
|
||||
any opportunity to shut down its child processes, and by default they will keep running. In this case, it's
|
||||
up to the child process to detect this has happened and terminate itself.
|
||||
|
||||
There are many possible approaches to detecting when a parent process has exited, most of which behave
|
||||
differently between Windows and Linux/OS X:
|
||||
|
||||
- On Windows, the parent process can mark its child as being a 'job' that should auto-terminate when
|
||||
the parent does (http://stackoverflow.com/a/4657392). Not cross-platform.
|
||||
- The child Node process can get a callback when the parent disconnects (process.on('disconnect', ...)).
|
||||
But despite http://stackoverflow.com/a/16487966, no callback fires in any case I've tested (Windows / OS X).
|
||||
- The child Node process can get a callback when its stdin/stdout are disconnected, as described at
|
||||
http://stackoverflow.com/a/15693934. This works well on OS X, but calling stdout.resume() on Windows
|
||||
causes the process to terminate prematurely.
|
||||
- I don't know why, but on Windows, it's enough to invoke process.stdin.resume(). For some reason this causes
|
||||
the child Node process to exit as soon as the parent one does, but I don't see this documented anywhere.
|
||||
- You can poll to see if the parent process, or your stdin/stdout connection to it, is gone
|
||||
- You can directly pass a parent process PID to the child, and then have the child poll to see if it's
|
||||
still running (e.g., using process.kill(pid, 0), which doesn't kill it but just tests whether it exists,
|
||||
as per https://nodejs.org/api/process.html#process_process_kill_pid_signal)
|
||||
- Or, on each poll, you can try writing to process.stdout. If the parent has died, then this will throw.
|
||||
However I don't see this documented anywhere. It would be nice if you could just poll for whether or not
|
||||
process.stdout is still connected (without actually writing to it) but I haven't found any property whose
|
||||
value changes until you actually try to write to it.
|
||||
|
||||
Of these, the only cross-platform approach that is actually documented as a valid strategy is simply polling
|
||||
to check whether the parent PID is still running. So that's what we do here.
|
||||
*/
|
||||
exports.__esModule = true;
|
||||
var pollIntervalMs = 1000;
|
||||
function exitWhenParentExits(parentPid, ignoreSigint) {
|
||||
setInterval(function () {
|
||||
if (!processExists(parentPid)) {
|
||||
// Can't log anything at this point, because out stdout was connected to the parent,
|
||||
// but the parent is gone.
|
||||
process.exit();
|
||||
}
|
||||
}, pollIntervalMs);
|
||||
if (ignoreSigint) {
|
||||
// Pressing ctrl+c in the terminal sends a SIGINT to all processes in the foreground process tree.
|
||||
// By default, the Node process would then exit before the .NET process, because ASP.NET implements
|
||||
// a delayed shutdown to allow ongoing requests to complete.
|
||||
//
|
||||
// This is problematic, because if Node exits first, the CopyToAsync code in ConditionalProxyMiddleware
|
||||
// will experience a read fault, and logs a huge load of errors. Fortunately, since the Node process is
|
||||
// already set up to shut itself down if it detects the .NET process is terminated, all we have to do is
|
||||
// ignore the SIGINT. The Node process will then terminate automatically after the .NET process does.
|
||||
//
|
||||
// A better solution would be to have WebpackDevMiddleware listen for SIGINT and gracefully close any
|
||||
// ongoing EventSource connections before letting the Node process exit, independently of the .NET
|
||||
// process exiting. However, doing this well in general is very nontrivial (see all the discussion at
|
||||
// https://github.com/nodejs/node/issues/2642).
|
||||
process.on('SIGINT', function () {
|
||||
console.log('Received SIGINT. Waiting for .NET process to exit...');
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.exitWhenParentExits = exitWhenParentExits;
|
||||
function processExists(pid) {
|
||||
try {
|
||||
// Sending signal 0 - on all platforms - tests whether the process exists. As long as it doesn't
|
||||
// throw, that means it does exist.
|
||||
process.kill(pid, 0);
|
||||
return true;
|
||||
}
|
||||
catch (ex) {
|
||||
// If the reason for the error is that we don't have permission to ask about this process,
|
||||
// report that as a separate problem.
|
||||
if (ex.code === 'EPERM') {
|
||||
throw new Error("Attempted to check whether process " + pid + " was running, but got a permissions error.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 8 */
|
||||
/***/ (function (module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
var events_1 = __webpack_require__(9);
|
||||
var VirtualConnection_1 = __webpack_require__(10);
|
||||
// Keep this in sync with the equivalent constant in the .NET code. Both sides split up their transmissions into frames with this max length,
|
||||
// and both will reject longer frames.
|
||||
var MaxFrameBodyLength = 16 * 1024;
|
||||
/**
|
||||
* Accepts connections to a net.Server and adapts them to behave as multiplexed connections. That is, for each physical socket connection,
|
||||
* we track a list of 'virtual connections' whose API is a Duplex stream. The remote clients may open and close as many virtual connections
|
||||
* as they wish, reading and writing to them independently, without the overhead of establishing new physical connections each time.
|
||||
*/
|
||||
function createInterface(server) {
|
||||
var emitter = new events_1.EventEmitter();
|
||||
server.on('connection', function (socket) {
|
||||
// For each physical socket connection, maintain a set of virtual connections. Issue a notification whenever
|
||||
// a new virtual connections is opened.
|
||||
var childSockets = new VirtualConnectionsCollection(socket, function (virtualConnection) {
|
||||
emitter.emit('connection', virtualConnection);
|
||||
});
|
||||
});
|
||||
return emitter;
|
||||
}
|
||||
exports.createInterface = createInterface;
|
||||
/**
|
||||
* Tracks the 'virtual connections' associated with a single physical socket connection.
|
||||
*/
|
||||
var VirtualConnectionsCollection = /** @class */ (function () {
|
||||
function VirtualConnectionsCollection(_socket, _onVirtualConnectionCallback) {
|
||||
var _this = this;
|
||||
this._socket = _socket;
|
||||
this._onVirtualConnectionCallback = _onVirtualConnectionCallback;
|
||||
this._currentFrameHeader = null;
|
||||
this._virtualConnections = {};
|
||||
// If the remote end closes the physical socket, treat all the virtual connections as being closed remotely too
|
||||
this._socket.on('close', function () {
|
||||
Object.getOwnPropertyNames(_this._virtualConnections).forEach(function (id) {
|
||||
// A 'null' frame signals that the connection was closed remotely
|
||||
_this._virtualConnections[id].onReceivedData(null);
|
||||
});
|
||||
});
|
||||
this._socket.on('readable', this._onIncomingDataAvailable.bind(this));
|
||||
}
|
||||
/**
|
||||
* This is called whenever the underlying socket signals that it may have some data available to read. It will synchronously read as many
|
||||
* message frames as it can from the underlying socket, opens virtual connections as needed, and dispatches data to them.
|
||||
*/
|
||||
VirtualConnectionsCollection.prototype._onIncomingDataAvailable = function () {
|
||||
var exhaustedAllData = false;
|
||||
while (!exhaustedAllData) {
|
||||
// We might already have a pending frame header from the previous time this method ran, but if not, that's the next thing we need to read
|
||||
if (this._currentFrameHeader === null) {
|
||||
this._currentFrameHeader = this._readNextFrameHeader();
|
||||
}
|
||||
if (this._currentFrameHeader === null) {
|
||||
// There's not enough data to fill a frameheader, so wait until more arrives later
|
||||
// The next attempt to read from the socket will start from the same place this one did (incomplete reads don't consume any data)
|
||||
exhaustedAllData = true;
|
||||
}
|
||||
else {
|
||||
var frameBodyLength = this._currentFrameHeader.bodyLength;
|
||||
var frameBodyOrNull = frameBodyLength > 0 ? this._socket.read(this._currentFrameHeader.bodyLength) : null;
|
||||
if (frameBodyOrNull !== null || frameBodyLength === 0) {
|
||||
// We have a complete frame header+body pair, so we can now dispatch this to a virtual connection. We set _currentFrameHeader back to null
|
||||
// so that the next thing we try to read is the next frame header.
|
||||
var headerCopy = this._currentFrameHeader;
|
||||
this._currentFrameHeader = null;
|
||||
this._onReceivedCompleteFrame(headerCopy, frameBodyOrNull);
|
||||
}
|
||||
else {
|
||||
// There's not enough data to fill the pending frame body, so wait until more arrives later
|
||||
// The next attempt to read from the socket will start from the same place this one did (incomplete reads don't consume any data)
|
||||
exhaustedAllData = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
VirtualConnectionsCollection.prototype._onReceivedCompleteFrame = function (header, bodyIfNotEmpty) {
|
||||
// An incoming zero-length frame signals that there's no more data to read.
|
||||
// Signal this to the Node stream APIs by pushing a 'null' chunk to it.
|
||||
var virtualConnection = this._getOrOpenVirtualConnection(header);
|
||||
virtualConnection.onReceivedData(header.bodyLength > 0 ? bodyIfNotEmpty : null);
|
||||
};
|
||||
VirtualConnectionsCollection.prototype._getOrOpenVirtualConnection = function (header) {
|
||||
if (this._virtualConnections.hasOwnProperty(header.connectionIdString)) {
|
||||
// It's an existing virtual connection
|
||||
return this._virtualConnections[header.connectionIdString];
|
||||
}
|
||||
else {
|
||||
// It's a new one
|
||||
return this._openVirtualConnection(header);
|
||||
}
|
||||
};
|
||||
VirtualConnectionsCollection.prototype._openVirtualConnection = function (header) {
|
||||
var _this = this;
|
||||
var beginWriteCallback = function (data, writeCompletedCallback) {
|
||||
// Only send nonempty frames, since empty ones are a signal to close the virtual connection
|
||||
if (data.length > 0) {
|
||||
_this._sendFrame(header.connectionIdBinary, data, writeCompletedCallback);
|
||||
}
|
||||
};
|
||||
var newVirtualConnection = new VirtualConnection_1.VirtualConnection(beginWriteCallback);
|
||||
newVirtualConnection.on('end', function () {
|
||||
// The virtual connection was closed remotely. Clean up locally.
|
||||
_this._onVirtualConnectionWasClosed(header.connectionIdString);
|
||||
});
|
||||
newVirtualConnection.on('finish', function () {
|
||||
// The virtual connection was closed locally. Clean up locally, and notify the remote that we're done.
|
||||
_this._onVirtualConnectionWasClosed(header.connectionIdString);
|
||||
_this._sendFrame(header.connectionIdBinary, Buffer.alloc(0));
|
||||
});
|
||||
this._virtualConnections[header.connectionIdString] = newVirtualConnection;
|
||||
this._onVirtualConnectionCallback(newVirtualConnection);
|
||||
return newVirtualConnection;
|
||||
};
|
||||
/**
|
||||
* Attempts to read a complete frame header, synchronously, from the underlying socket.
|
||||
* If not enough data is available synchronously, returns null without consuming any data from the socket.
|
||||
*/
|
||||
VirtualConnectionsCollection.prototype._readNextFrameHeader = function () {
|
||||
var headerBuf = this._socket.read(12);
|
||||
if (headerBuf !== null) {
|
||||
// We have enough data synchronously
|
||||
var connectionIdBinary = headerBuf.slice(0, 8);
|
||||
var connectionIdString = connectionIdBinary.toString('hex');
|
||||
var bodyLength = headerBuf.readInt32LE(8);
|
||||
if (bodyLength < 0 || bodyLength > MaxFrameBodyLength) {
|
||||
// Throwing here is going to bring down the whole process, so this cannot be allowed to happen in real use.
|
||||
// But it won't happen in real use, because this is only used with our .NET client, which doesn't violate this rule.
|
||||
throw new Error('Illegal frame body length: ' + bodyLength);
|
||||
}
|
||||
return { connectionIdBinary: connectionIdBinary, connectionIdString: connectionIdString, bodyLength: bodyLength };
|
||||
}
|
||||
else {
|
||||
// Not enough bytes are available synchronously, so none were consumed
|
||||
return null;
|
||||
}
|
||||
};
|
||||
VirtualConnectionsCollection.prototype._sendFrame = function (connectionIdBinary, data, callback) {
|
||||
// For all sends other than the last one, only invoke the callback if it failed.
|
||||
// Also, only invoke the callback at most once.
|
||||
var hasInvokedCallback = false;
|
||||
var finalCallback = callback && (function (error) {
|
||||
if (!hasInvokedCallback) {
|
||||
hasInvokedCallback = true;
|
||||
callback(error);
|
||||
}
|
||||
});
|
||||
var notFinalCallback = callback && (function (error) {
|
||||
if (error) {
|
||||
finalCallback(error);
|
||||
}
|
||||
});
|
||||
// The amount of data we're writing might exceed MaxFrameBodyLength, so split into frames as needed.
|
||||
// Note that we always send at least one frame, even if it's empty (because that's the close-virtual-connection signal).
|
||||
// If needed, this could be changed to send frames asynchronously, so that large sends could proceed in parallel
|
||||
// (though that would involve making a clone of 'data', to avoid the risk of it being mutated during the send).
|
||||
var bytesSent = 0;
|
||||
do {
|
||||
var nextFrameBodyLength = Math.min(MaxFrameBodyLength, data.length - bytesSent);
|
||||
var isFinalChunk = (bytesSent + nextFrameBodyLength) === data.length;
|
||||
this._socket.write(connectionIdBinary, notFinalCallback);
|
||||
this._sendInt32LE(nextFrameBodyLength, notFinalCallback);
|
||||
this._socket.write(data.slice(bytesSent, bytesSent + nextFrameBodyLength), isFinalChunk ? finalCallback : notFinalCallback);
|
||||
bytesSent += nextFrameBodyLength;
|
||||
} while (bytesSent < data.length);
|
||||
};
|
||||
/**
|
||||
* Sends a number serialized in the correct format for .NET to receive as a System.Int32
|
||||
*/
|
||||
VirtualConnectionsCollection.prototype._sendInt32LE = function (value, callback) {
|
||||
var buf = Buffer.alloc(4);
|
||||
buf.writeInt32LE(value, 0);
|
||||
this._socket.write(buf, callback);
|
||||
};
|
||||
VirtualConnectionsCollection.prototype._onVirtualConnectionWasClosed = function (id) {
|
||||
if (this._virtualConnections.hasOwnProperty(id)) {
|
||||
delete this._virtualConnections[id];
|
||||
}
|
||||
};
|
||||
return VirtualConnectionsCollection;
|
||||
}());
|
||||
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 9 */
|
||||
/***/ (function (module, exports) {
|
||||
|
||||
module.exports = require("events");
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 10 */
|
||||
/***/ (function (module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
}
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
exports.__esModule = true;
|
||||
var stream_1 = __webpack_require__(11);
|
||||
/**
|
||||
* Represents a virtual connection. Multiple virtual connections may be multiplexed over a single physical socket connection.
|
||||
*/
|
||||
var VirtualConnection = /** @class */ (function (_super) {
|
||||
__extends(VirtualConnection, _super);
|
||||
function VirtualConnection(_beginWriteCallback) {
|
||||
var _this = _super.call(this) || this;
|
||||
_this._beginWriteCallback = _beginWriteCallback;
|
||||
_this._flowing = false;
|
||||
_this._receivedDataQueue = [];
|
||||
return _this;
|
||||
}
|
||||
VirtualConnection.prototype._read = function () {
|
||||
this._flowing = true;
|
||||
// Keep pushing data until we run out, or the underlying framework asks us to stop.
|
||||
// When we finish, the 'flowing' state is detemined by whether more data is still being requested.
|
||||
while (this._flowing && this._receivedDataQueue.length > 0) {
|
||||
var nextChunk = this._receivedDataQueue.shift();
|
||||
this._flowing = this.push(nextChunk);
|
||||
}
|
||||
};
|
||||
VirtualConnection.prototype._write = function (chunk, encodingIfString, callback) {
|
||||
if (typeof chunk === 'string') {
|
||||
chunk = Buffer.from(chunk, encodingIfString);
|
||||
}
|
||||
this._beginWriteCallback(chunk, callback);
|
||||
};
|
||||
VirtualConnection.prototype.onReceivedData = function (dataOrNullToSignalEOF) {
|
||||
if (this._flowing) {
|
||||
this._flowing = this.push(dataOrNullToSignalEOF);
|
||||
}
|
||||
else {
|
||||
this._receivedDataQueue.push(dataOrNullToSignalEOF);
|
||||
}
|
||||
};
|
||||
return VirtualConnection;
|
||||
}(stream_1.Duplex));
|
||||
exports.VirtualConnection = VirtualConnection;
|
||||
|
||||
|
||||
/***/
|
||||
}),
|
||||
/* 11 */
|
||||
/***/ (function (module, exports) {
|
||||
|
||||
module.exports = require("stream");
|
||||
|
||||
/***/
|
||||
})
|
||||
/******/])));
|
||||
@@ -1,12 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\build\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Socket-based RPC for Microsoft.AspNetCore.NodeServices.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<PackageTags>aspnetcore;aspnetcoremvc;nodeservices</PackageTags>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -16,6 +12,9 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.NodeServices\Microsoft.AspNetCore.NodeServices.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="$(SystemThreadingTasksDataflowPackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -14,8 +14,7 @@ namespace Microsoft.AspNetCore.NodeServices.Sockets
|
||||
/// <summary>
|
||||
/// A specialisation of the OutOfProcessNodeInstance base class that uses a lightweight binary streaming protocol
|
||||
/// to perform RPC invocations. The physical transport is Named Pipes on Windows, or Domain Sockets on Linux/Mac.
|
||||
/// For details on the binary streaming protocol, see
|
||||
/// Microsoft.AspNetCore.NodeServices.HostingModels.VirtualConnections.VirtualConnectionClient.
|
||||
/// For details on the binary streaming protocol, see <see cref="Microsoft.AspNetCore.NodeServices.Sockets.VirtualConnections.VirtualConnectionClient" />
|
||||
/// The advantage versus using HTTP for RPC is that this is faster (not surprisingly - there's much less overhead
|
||||
/// because we don't need most of the functionality of HTTP.
|
||||
///
|
||||
@@ -238,4 +237,4 @@ namespace Microsoft.AspNetCore.NodeServices.Sockets
|
||||
}
|
||||
#pragma warning restore 649
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ export class VirtualConnection extends Duplex {
|
||||
|
||||
public _write(chunk: Buffer | string, encodingIfString: string, callback: EndWriteCallback) {
|
||||
if (typeof chunk === 'string') {
|
||||
chunk = new Buffer(chunk as string, encodingIfString);
|
||||
chunk = Buffer.from(chunk as string, encodingIfString);
|
||||
}
|
||||
|
||||
this._beginWriteCallback(chunk as Buffer, callback);
|
||||
@@ -113,7 +113,7 @@ class VirtualConnectionsCollection {
|
||||
newVirtualConnection.on('finish', () => {
|
||||
// The virtual connection was closed locally. Clean up locally, and notify the remote that we're done.
|
||||
this._onVirtualConnectionWasClosed(header.connectionIdString);
|
||||
this._sendFrame(header.connectionIdBinary, new Buffer(0));
|
||||
this._sendFrame(header.connectionIdBinary, Buffer.alloc(0));
|
||||
});
|
||||
|
||||
this._virtualConnections[header.connectionIdString] = newVirtualConnection;
|
||||
@@ -180,7 +180,7 @@ class VirtualConnectionsCollection {
|
||||
* Sends a number serialized in the correct format for .NET to receive as a System.Int32
|
||||
*/
|
||||
private _sendInt32LE(value: number, callback?: EndWriteCallback) {
|
||||
const buf = new Buffer(4);
|
||||
const buf = Buffer.alloc(4);
|
||||
buf.writeInt32LE(value, 0);
|
||||
this._socket.write(buf, callback);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
{
|
||||
"AssemblyIdentity": "Microsoft.AspNetCore.NodeServices.Sockets, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60",
|
||||
"Types": [
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.NodeServices.Sockets.NodeServicesOptionsExtensions",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"Abstract": true,
|
||||
"Static": true,
|
||||
"Sealed": true,
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "UseSocketHosting",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "options",
|
||||
"Type": "Microsoft.AspNetCore.NodeServices.NodeServicesOptions"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Void",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.NodeServices.Sockets.VirtualConnections.VirtualConnectionReadErrorHandler",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"Sealed": true,
|
||||
"BaseType": "System.MulticastDelegate",
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Invoke",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "ex",
|
||||
"Type": "System.Exception"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Void",
|
||||
"Virtual": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "BeginInvoke",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "ex",
|
||||
"Type": "System.Exception"
|
||||
},
|
||||
{
|
||||
"Name": "callback",
|
||||
"Type": "System.AsyncCallback"
|
||||
},
|
||||
{
|
||||
"Name": "object",
|
||||
"Type": "System.Object"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.IAsyncResult",
|
||||
"Virtual": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "EndInvoke",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "result",
|
||||
"Type": "System.IAsyncResult"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Void",
|
||||
"Virtual": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Constructor",
|
||||
"Name": ".ctor",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "object",
|
||||
"Type": "System.Object"
|
||||
},
|
||||
{
|
||||
"Name": "method",
|
||||
"Type": "System.IntPtr"
|
||||
}
|
||||
],
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
}
|
||||
]
|
||||
}
|
||||
4230
src/JavaScriptServices/src/Microsoft.AspNetCore.NodeServices.Sockets/package-lock.json
generated
Normal file
4230
src/JavaScriptServices/src/Microsoft.AspNetCore.NodeServices.Sockets/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -5,14 +5,15 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "./node_modules/.bin/webpack"
|
||||
"build": "webpack --mode production"
|
||||
},
|
||||
"author": "Microsoft",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@types/node": "^6.0.42",
|
||||
"ts-loader": "^0.8.2",
|
||||
"typescript": "^2.0.0",
|
||||
"webpack": "^1.13.1"
|
||||
"@types/node": "^10.9.2",
|
||||
"ts-loader": "^4.5.0",
|
||||
"typescript": "^3.0.1",
|
||||
"webpack": "^4.17.1",
|
||||
"webpack-cli": "^3.1.0"
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
target: 'node',
|
||||
externals: ['fs', 'net', 'events', 'readline', 'stream'],
|
||||
resolve: {
|
||||
extensions: [ '.ts' ]
|
||||
},
|
||||
module: {
|
||||
loaders: [
|
||||
{ test: /\.ts$/, loader: 'ts-loader' },
|
||||
rules: [
|
||||
{ test: /\.ts$/, use: 'ts-loader' },
|
||||
]
|
||||
},
|
||||
entry: {
|
||||
@@ -14,7 +15,10 @@ module.exports = {
|
||||
},
|
||||
output: {
|
||||
libraryTarget: 'commonjs',
|
||||
path: './Content/Node',
|
||||
path: path.join(__dirname, 'Content', 'Node'),
|
||||
filename: '[name].js'
|
||||
},
|
||||
optimization: {
|
||||
minimize: false
|
||||
}
|
||||
};
|
||||
@@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNetCore.NodeServices.HostingModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Logging.Console;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace Microsoft.AspNetCore.NodeServices
|
||||
{
|
||||
@@ -34,14 +35,18 @@ namespace Microsoft.AspNetCore.NodeServices
|
||||
InvocationTimeoutMilliseconds = DefaultInvocationTimeoutMilliseconds;
|
||||
WatchFileExtensions = (string[])DefaultWatchFileExtensions.Clone();
|
||||
|
||||
// In an ASP.NET environment, we can use the IHostingEnvironment data to auto-populate a few
|
||||
// things that you'd otherwise have to specify manually
|
||||
var hostEnv = serviceProvider.GetService<IHostingEnvironment>();
|
||||
if (hostEnv != null)
|
||||
{
|
||||
// In an ASP.NET environment, we can use the IHostingEnvironment data to auto-populate a few
|
||||
// things that you'd otherwise have to specify manually
|
||||
ProjectPath = hostEnv.ContentRootPath;
|
||||
EnvironmentVariables["NODE_ENV"] = hostEnv.IsDevelopment() ? "development" : "production"; // De-facto standard values for Node
|
||||
}
|
||||
else
|
||||
{
|
||||
ProjectPath = Directory.GetCurrentDirectory();
|
||||
}
|
||||
|
||||
var applicationLifetime = serviceProvider.GetService<IApplicationLifetime>();
|
||||
if (applicationLifetime != null)
|
||||
@@ -53,8 +58,7 @@ namespace Microsoft.AspNetCore.NodeServices
|
||||
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
|
||||
NodeInstanceOutputLogger = loggerFactory != null
|
||||
? loggerFactory.CreateLogger(LogCategoryName)
|
||||
: new ConsoleLogger(LogCategoryName, null, false);
|
||||
|
||||
: NullLogger.Instance;
|
||||
// By default, we use this package's built-in out-of-process-via-HTTP hosting/transport
|
||||
this.UseHttpHosting();
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId]) {
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // define __esModule on exports
|
||||
/******/ __webpack_require__.r = function(exports) {
|
||||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
/******/ }
|
||||
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // create a fake namespace object
|
||||
/******/ // mode & 1: value is a module id, require it
|
||||
/******/ // mode & 2: merge all properties of value into the ns
|
||||
/******/ // mode & 4: return value when already ns object
|
||||
/******/ // mode & 8|1: behave like require
|
||||
/******/ __webpack_require__.t = function(value, mode) {
|
||||
/******/ if(mode & 1) value = __webpack_require__(value);
|
||||
/******/ if(mode & 8) return value;
|
||||
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
||||
/******/ var ns = Object.create(null);
|
||||
/******/ __webpack_require__.r(ns);
|
||||
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
||||
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
||||
/******/ return ns;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function(module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
/******/
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(__webpack_require__.s = 1);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
/* 1 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
module.exports = __webpack_require__(2);
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 2 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
// Limit dependencies to core Node modules. This means the code in this file has to be very low-level and unattractive,
|
||||
// but simplifies things for the consumer of this module.
|
||||
__webpack_require__(3);
|
||||
__webpack_require__(4);
|
||||
var http = __webpack_require__(5);
|
||||
var path = __webpack_require__(0);
|
||||
var ArgsUtil_1 = __webpack_require__(6);
|
||||
var ExitWhenParentExits_1 = __webpack_require__(7);
|
||||
// Webpack doesn't support dynamic requires for files not present at compile time, so grab a direct
|
||||
// reference to Node's runtime 'require' function.
|
||||
var dynamicRequire = eval('require');
|
||||
var server = http.createServer(function (req, res) {
|
||||
readRequestBodyAsJson(req, function (bodyJson) {
|
||||
var hasSentResult = false;
|
||||
var callback = function (errorValue, successValue) {
|
||||
if (!hasSentResult) {
|
||||
hasSentResult = true;
|
||||
if (errorValue) {
|
||||
respondWithError(res, errorValue);
|
||||
}
|
||||
else if (typeof successValue !== 'string') {
|
||||
// Arbitrary object/number/etc - JSON-serialize it
|
||||
var successValueJson = void 0;
|
||||
try {
|
||||
successValueJson = JSON.stringify(successValue);
|
||||
}
|
||||
catch (ex) {
|
||||
// JSON serialization error - pass it back to .NET
|
||||
respondWithError(res, ex);
|
||||
return;
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(successValueJson);
|
||||
}
|
||||
else {
|
||||
// String - can bypass JSON-serialization altogether
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
res.end(successValue);
|
||||
}
|
||||
}
|
||||
};
|
||||
// Support streamed responses
|
||||
Object.defineProperty(callback, 'stream', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
if (!hasSentResult) {
|
||||
hasSentResult = true;
|
||||
res.setHeader('Content-Type', 'application/octet-stream');
|
||||
}
|
||||
return res;
|
||||
}
|
||||
});
|
||||
try {
|
||||
var resolvedPath = path.resolve(process.cwd(), bodyJson.moduleName);
|
||||
var invokedModule = dynamicRequire(resolvedPath);
|
||||
var func = bodyJson.exportedFunctionName ? invokedModule[bodyJson.exportedFunctionName] : invokedModule;
|
||||
if (!func) {
|
||||
throw new Error('The module "' + resolvedPath + '" has no export named "' + bodyJson.exportedFunctionName + '"');
|
||||
}
|
||||
func.apply(null, [callback].concat(bodyJson.args));
|
||||
}
|
||||
catch (synchronousException) {
|
||||
callback(synchronousException, null);
|
||||
}
|
||||
});
|
||||
});
|
||||
var parsedArgs = ArgsUtil_1.parseArgs(process.argv);
|
||||
var requestedPortOrZero = parsedArgs.port || 0; // 0 means 'let the OS decide'
|
||||
server.listen(requestedPortOrZero, 'localhost', function () {
|
||||
var addressInfo = server.address();
|
||||
// Signal to HttpNodeHost which loopback IP address (IPv4 or IPv6) and port it should make its HTTP connections on
|
||||
console.log('[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on {' + addressInfo.address + '} port ' + addressInfo.port + '\]');
|
||||
// Signal to the NodeServices base class that we're ready to accept invocations
|
||||
console.log('[Microsoft.AspNetCore.NodeServices:Listening]');
|
||||
});
|
||||
ExitWhenParentExits_1.exitWhenParentExits(parseInt(parsedArgs.parentPid), /* ignoreSigint */ true);
|
||||
function readRequestBodyAsJson(request, callback) {
|
||||
var requestBodyAsString = '';
|
||||
request.on('data', function (chunk) { requestBodyAsString += chunk; });
|
||||
request.on('end', function () { callback(JSON.parse(requestBodyAsString)); });
|
||||
}
|
||||
function respondWithError(res, errorValue) {
|
||||
res.statusCode = 500;
|
||||
res.end(JSON.stringify({
|
||||
errorMessage: errorValue.message || errorValue,
|
||||
errorDetails: errorValue.stack || null
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 3 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
var path = __webpack_require__(0);
|
||||
var startsWith = function (str, prefix) { return str.substring(0, prefix.length) === prefix; };
|
||||
var appRootDir = process.cwd();
|
||||
function patchedLStat(pathToStatLong, fsReqWrap) {
|
||||
try {
|
||||
// If the lstat completes without errors, we don't modify its behavior at all
|
||||
return origLStat.apply(this, arguments);
|
||||
}
|
||||
catch (ex) {
|
||||
var shouldOverrideError = startsWith(ex.message, 'EPERM') // It's a permissions error
|
||||
&& typeof appRootDirLong === 'string'
|
||||
&& startsWith(appRootDirLong, pathToStatLong) // ... for an ancestor directory
|
||||
&& ex.stack.indexOf('Object.realpathSync ') >= 0; // ... during symlink resolution
|
||||
if (shouldOverrideError) {
|
||||
// Fake the result to give the same result as an 'lstat' on the app root dir.
|
||||
// This stops Node failing to load modules just because it doesn't know whether
|
||||
// ancestor directories are symlinks or not. If there's a genuine file
|
||||
// permissions issue, it will still surface later when Node actually
|
||||
// tries to read the file.
|
||||
return origLStat.call(this, appRootDir, fsReqWrap);
|
||||
}
|
||||
else {
|
||||
// In any other case, preserve the original error
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
// It's only necessary to apply this workaround on Windows
|
||||
var appRootDirLong = null;
|
||||
var origLStat = null;
|
||||
if (/^win/.test(process.platform)) {
|
||||
try {
|
||||
// Get the app's root dir in Node's internal "long" format (e.g., \\?\C:\dir\subdir)
|
||||
appRootDirLong = path._makeLong(appRootDir);
|
||||
// Actually apply the patch, being as defensive as possible
|
||||
var bindingFs = process.binding('fs');
|
||||
origLStat = bindingFs.lstat;
|
||||
if (typeof origLStat === 'function') {
|
||||
bindingFs.lstat = patchedLStat;
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
// If some future version of Node throws (e.g., to prevent use of process.binding()),
|
||||
// don't apply the patch, but still let the application run.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 4 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
// When Node writes to stdout/strerr, we capture that and convert the lines into calls on the
|
||||
// active .NET ILogger. But by default, stdout/stderr don't have any way of distinguishing
|
||||
// linebreaks inside log messages from the linebreaks that delimit separate log messages,
|
||||
// so multiline strings will end up being written to the ILogger as multiple independent
|
||||
// log messages. This makes them very hard to make sense of, especially when they represent
|
||||
// something like stack traces.
|
||||
//
|
||||
// To fix this, we intercept stdout/stderr writes, and replace internal linebreaks with a
|
||||
// marker token. When .NET receives the lines, it converts the marker tokens back to regular
|
||||
// linebreaks within the logged messages.
|
||||
//
|
||||
// Note that it's better to do the interception at the stdout/stderr level, rather than at
|
||||
// the console.log/console.error (etc.) level, because this takes place after any native
|
||||
// message formatting has taken place (e.g., inserting values for % placeholders).
|
||||
var findInternalNewlinesRegex = /\n(?!$)/g;
|
||||
var encodedNewline = '__ns_newline__';
|
||||
encodeNewlinesWrittenToStream(process.stdout);
|
||||
encodeNewlinesWrittenToStream(process.stderr);
|
||||
function encodeNewlinesWrittenToStream(outputStream) {
|
||||
var origWriteFunction = outputStream.write;
|
||||
outputStream.write = function (value) {
|
||||
// Only interfere with the write if it's definitely a string
|
||||
if (typeof value === 'string') {
|
||||
var argsClone = Array.prototype.slice.call(arguments, 0);
|
||||
argsClone[0] = encodeNewlinesInString(value);
|
||||
origWriteFunction.apply(this, argsClone);
|
||||
}
|
||||
else {
|
||||
origWriteFunction.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
function encodeNewlinesInString(str) {
|
||||
return str.replace(findInternalNewlinesRegex, encodedNewline);
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 5 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
/* 6 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
function parseArgs(args) {
|
||||
// Very simplistic parsing which is sufficient for the cases needed. We don't want to bring in any external
|
||||
// dependencies (such as an args-parsing library) to this file.
|
||||
var result = {};
|
||||
var currentKey = null;
|
||||
args.forEach(function (arg) {
|
||||
if (arg.indexOf('--') === 0) {
|
||||
var argName = arg.substring(2);
|
||||
result[argName] = undefined;
|
||||
currentKey = argName;
|
||||
}
|
||||
else if (currentKey) {
|
||||
result[currentKey] = arg;
|
||||
currentKey = null;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
exports.parseArgs = parseArgs;
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 7 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
In general, we want the Node child processes to be terminated as soon as the parent .NET processes exit,
|
||||
because we have no further use for them. If the .NET process shuts down gracefully, it will run its
|
||||
finalizers, one of which (in OutOfProcessNodeInstance.cs) will kill its associated Node process immediately.
|
||||
|
||||
But if the .NET process is terminated forcefully (e.g., on Linux/OSX with 'kill -9'), then it won't have
|
||||
any opportunity to shut down its child processes, and by default they will keep running. In this case, it's
|
||||
up to the child process to detect this has happened and terminate itself.
|
||||
|
||||
There are many possible approaches to detecting when a parent process has exited, most of which behave
|
||||
differently between Windows and Linux/OS X:
|
||||
|
||||
- On Windows, the parent process can mark its child as being a 'job' that should auto-terminate when
|
||||
the parent does (http://stackoverflow.com/a/4657392). Not cross-platform.
|
||||
- The child Node process can get a callback when the parent disconnects (process.on('disconnect', ...)).
|
||||
But despite http://stackoverflow.com/a/16487966, no callback fires in any case I've tested (Windows / OS X).
|
||||
- The child Node process can get a callback when its stdin/stdout are disconnected, as described at
|
||||
http://stackoverflow.com/a/15693934. This works well on OS X, but calling stdout.resume() on Windows
|
||||
causes the process to terminate prematurely.
|
||||
- I don't know why, but on Windows, it's enough to invoke process.stdin.resume(). For some reason this causes
|
||||
the child Node process to exit as soon as the parent one does, but I don't see this documented anywhere.
|
||||
- You can poll to see if the parent process, or your stdin/stdout connection to it, is gone
|
||||
- You can directly pass a parent process PID to the child, and then have the child poll to see if it's
|
||||
still running (e.g., using process.kill(pid, 0), which doesn't kill it but just tests whether it exists,
|
||||
as per https://nodejs.org/api/process.html#process_process_kill_pid_signal)
|
||||
- Or, on each poll, you can try writing to process.stdout. If the parent has died, then this will throw.
|
||||
However I don't see this documented anywhere. It would be nice if you could just poll for whether or not
|
||||
process.stdout is still connected (without actually writing to it) but I haven't found any property whose
|
||||
value changes until you actually try to write to it.
|
||||
|
||||
Of these, the only cross-platform approach that is actually documented as a valid strategy is simply polling
|
||||
to check whether the parent PID is still running. So that's what we do here.
|
||||
*/
|
||||
exports.__esModule = true;
|
||||
var pollIntervalMs = 1000;
|
||||
function exitWhenParentExits(parentPid, ignoreSigint) {
|
||||
setInterval(function () {
|
||||
if (!processExists(parentPid)) {
|
||||
// Can't log anything at this point, because out stdout was connected to the parent,
|
||||
// but the parent is gone.
|
||||
process.exit();
|
||||
}
|
||||
}, pollIntervalMs);
|
||||
if (ignoreSigint) {
|
||||
// Pressing ctrl+c in the terminal sends a SIGINT to all processes in the foreground process tree.
|
||||
// By default, the Node process would then exit before the .NET process, because ASP.NET implements
|
||||
// a delayed shutdown to allow ongoing requests to complete.
|
||||
//
|
||||
// This is problematic, because if Node exits first, the CopyToAsync code in ConditionalProxyMiddleware
|
||||
// will experience a read fault, and logs a huge load of errors. Fortunately, since the Node process is
|
||||
// already set up to shut itself down if it detects the .NET process is terminated, all we have to do is
|
||||
// ignore the SIGINT. The Node process will then terminate automatically after the .NET process does.
|
||||
//
|
||||
// A better solution would be to have WebpackDevMiddleware listen for SIGINT and gracefully close any
|
||||
// ongoing EventSource connections before letting the Node process exit, independently of the .NET
|
||||
// process exiting. However, doing this well in general is very nontrivial (see all the discussion at
|
||||
// https://github.com/nodejs/node/issues/2642).
|
||||
process.on('SIGINT', function () {
|
||||
console.log('Received SIGINT. Waiting for .NET process to exit...');
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.exitWhenParentExits = exitWhenParentExits;
|
||||
function processExists(pid) {
|
||||
try {
|
||||
// Sending signal 0 - on all platforms - tests whether the process exists. As long as it doesn't
|
||||
// throw, that means it does exist.
|
||||
process.kill(pid, 0);
|
||||
return true;
|
||||
}
|
||||
catch (ex) {
|
||||
// If the reason for the error is that we don't have permission to ask about this process,
|
||||
// report that as a separate problem.
|
||||
if (ex.code === 'EPERM') {
|
||||
throw new Error("Attempted to check whether process " + pid + " was running, but got a permissions error.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
/******/ ])));
|
||||
@@ -21,8 +21,8 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
/// <seealso cref="Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance" />
|
||||
internal class HttpNodeInstance : OutOfProcessNodeInstance
|
||||
{
|
||||
private static readonly Regex PortMessageRegex =
|
||||
new Regex(@"^\[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on port (\d+)\]$");
|
||||
private static readonly Regex EndpointMessageRegex =
|
||||
new Regex(@"^\[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on {(.*?)} port (\d+)\]$");
|
||||
|
||||
private static readonly JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
@@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
|
||||
private readonly HttpClient _client;
|
||||
private bool _disposed;
|
||||
private int _portNumber;
|
||||
private string _endpoint;
|
||||
|
||||
public HttpNodeInstance(NodeServicesOptions options, int port = 0)
|
||||
: base(
|
||||
@@ -50,6 +50,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
options.DebuggingPort)
|
||||
{
|
||||
_client = new HttpClient();
|
||||
_client.Timeout = TimeSpan.FromMilliseconds(options.InvocationTimeoutMilliseconds + 1000);
|
||||
}
|
||||
|
||||
private static string MakeCommandLineOptions(int port)
|
||||
@@ -62,7 +63,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
{
|
||||
var payloadJson = JsonConvert.SerializeObject(invocationInfo, jsonSerializerSettings);
|
||||
var payload = new StringContent(payloadJson, Encoding.UTF8, "application/json");
|
||||
var response = await _client.PostAsync("http://localhost:" + _portNumber, payload, cancellationToken);
|
||||
var response = await _client.PostAsync(_endpoint, payload, cancellationToken);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
@@ -110,13 +111,19 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
|
||||
protected override void OnOutputDataReceived(string outputData)
|
||||
{
|
||||
// Watch for "port selected" messages, and when observed, store the port number
|
||||
// Watch for "port selected" messages, and when observed,
|
||||
// store the IP (IPv4/IPv6) and port number
|
||||
// so we can use it when making HTTP requests. The child process will always send
|
||||
// one of these messages before it sends a "ready for connections" message.
|
||||
var match = _portNumber != 0 ? null : PortMessageRegex.Match(outputData);
|
||||
var match = string.IsNullOrEmpty(_endpoint) ? EndpointMessageRegex.Match(outputData) : null;
|
||||
if (match != null && match.Success)
|
||||
{
|
||||
_portNumber = int.Parse(match.Groups[1].Captures[0].Value);
|
||||
var port = int.Parse(match.Groups[2].Captures[0].Value);
|
||||
var resolvedIpAddress = match.Groups[1].Captures[0].Value;
|
||||
|
||||
//IPv6 must be wrapped with [] brackets
|
||||
resolvedIpAddress = resolvedIpAddress == "::1" ? $"[{resolvedIpAddress}]" : resolvedIpAddress;
|
||||
_endpoint = $"http://{resolvedIpAddress}:{port}";
|
||||
}
|
||||
else
|
||||
{
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user