Skip to content

Commit

Permalink
Merge pull request #70 from Daddoon/dev_issue_68_support_net6
Browse files Browse the repository at this point in the history
Dev issue 68 support net6
  • Loading branch information
Daddoon authored Nov 9, 2021
2 parents 13c1c25 + 2ba2578 commit 057db9d
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 61 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Blazor server-side Polyfills and fixes for **Internet Explorer 11** & **Edge Leg

# INSTALLATION

- [.NET 5.0+](#net-50)
- [.NET 5.0 / .NET 6.0](#net-50--net-60)
- [Installation](#installation)
- [(Optional) Javascript isolation & module import support](#optional-javascript-isolation--module-import-support)
- [Additional options](#additional-options)
- [.NET 3.1](#net-31)

## .NET 5.0+
## .NET 5.0 / .NET 6.0

### Installation

Expand All @@ -29,11 +29,18 @@ Blazor server-side Polyfills and fixes for **Internet Explorer 11** & **Edge Leg
- (Optional) If updating from Blazor.Polyfill **3.0.8**, please remove any reference to **blazor.polyfill.js** or **blazor.polyfill.min.js** from your **_Host.cshtml** code, or any static file about the library you would link to in your code, as the library is now embedded is the NuGet package, and managed by **_framework/blazor.polyfill.min.js** as a magic path.


- Install the **BlazorPolyfill.Server** package interactively from the NuGet Package manager in Visual Studio
- Install the **BlazorPolyfill.Server** package interactively from the NuGet Package manager in Visual Studio.
- If installing for **.NET 6.x**, please install the **6.0.100** version.
- If installing for **.NET 5.x**, please install the **5.0.102** version.
- **Or** install it from the Package Manager CLI with this command:
```
Install-Package BlazorPolyfill.Server
```
- For **.NET 6.x**
```
Install-Package BlazorPolyfill.Server
```
- For **.NET 5.x**
```
Install-Package BlazorPolyfill.Server -Version 5.0.102
```
- **Or** additional syntax and possibilities available from the [NuGet package page](https://www.nuget.org/packages/BlazorPolyfill.Server/)
- In your **_Host.cshtml** page, include **_framework/blazor.polyfill.min.js** file before the **_framework/blazor.server.js** script tag.
Expand Down
12 changes: 8 additions & 4 deletions src/Blazor.Polyfill.Server/Blazor.Polyfill.Server.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>5.0.102.0</Version>
<Version>6.0.100.0</Version>
<Authors>Guillaume ZAHRA</Authors>
<Company>Daddoon</Company>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Description>Support of Blazor server-side for Internet Explorer 11, Edge Legacy and more on .NET 5.0.100</Description>
<Description>Support of Blazor server-side for Internet Explorer 11, Edge Legacy and more on .NET 6.0.100</Description>
<PackageProjectUrl>https://github.com/Daddoon/Blazor.Polyfill</PackageProjectUrl>
<PackageIcon>logo_blazorpolyfill_128.png</PackageIcon>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>https://github.com/Daddoon/Blazor.Polyfill</RepositoryUrl>
<PackageTags>blazor blazor-server ie11 edgeHTML edge-legacy polyfill</PackageTags>
<PackageReleaseNotes>5.0.102.0:
<PackageReleaseNotes>
6.0.100.0:
- Support for .NET 6.0.100

5.0.102.0:
- Added option to disable automatic React.NET registration, to give more control to advanced scenarios.
- Updated V8 and Native V8 dependencies to 7.1.0
- Added V8 native dependencies for ARM64 (Linux) and ARM64 (Windows)
Expand Down
163 changes: 145 additions & 18 deletions src/Blazor.Polyfill.Server/BlazorPolyfillMiddlewareExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;
using Blazor.Polyfill.Server.Model;
using JavaScriptEngineSwitcher.ChakraCore;
using JavaScriptEngineSwitcher.Extensions.MsDependencyInjection;
using JavaScriptEngineSwitcher.V8;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.Server;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Net.Http.Headers;
using System.IO;
using System.Reflection;
using System.Linq;
using Microsoft.AspNetCore.Components.Server;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using NUglify;
using React;
using React.AspNet;
using JavaScriptEngineSwitcher.Extensions.MsDependencyInjection;
using JavaScriptEngineSwitcher.V8;
using React.Exceptions;
using System.Text.RegularExpressions;
using NUglify;
using System;
using System.Globalization;
using System.Net;
using Blazor.Polyfill.Server.Model;
using JavaScriptEngineSwitcher.ChakraCore;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace Blazor.Polyfill.Server
{
Expand Down Expand Up @@ -360,15 +358,32 @@ private static FileContentReference GetPatchedBlazorServerFile()
{
string js = reader.ReadToEnd();


#region Patch Regex

//Patch Descriptor Regex as it make Babel crash during transform
js = js.Replace("/\\W*Blazor:[^{]*(?<descriptor>.*)$/;", @"/[\0-\/:-@\[-\^`\{-\uFFFF]*Blazor:(?:(?!\{)[\s\S])*(.*)$/;");

js = js.Replace("/^\\s*Blazor-Component-State:(?<state>[a-zA-Z0-9\\+\\/=]+)$/", @"/^[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*Blazor\x2DComponent\x2DState:([\+\/-9=A-Za-z]+)$/");

js = js.Replace("/^\\s*Blazor:[^{]*(?<descriptor>.*)$/", @"/^[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*Blazor:(?:(?!\{)[\s\S])*(.*)$/");

#endregion Patch Regex

//Transpile code to ES5 for IE11 before manual patching
js = Transform(js, "blazor.server.js", "{\"plugins\":[\"proposal-class-properties\",\"proposal-object-rest-spread\"],\"presets\":[[\"env\",{\"targets\":{\"browsers\":[\"ie 11\"]}}], \"es2015\",\"es2016\",\"es2017\",\"stage-3\"], \"sourceType\": \"script\"}");
js = Transform(js, "blazor.server.js", "{\"plugins\":[\"proposal-class-properties\",\"proposal-object-rest-spread\"],\"presets\":[[\"env\",{\"targets\":{\"browsers\":[\"ie 11\",\"Chrome 78\"]}}], \"es2015\",\"es2016\",\"es2017\",\"stage-3\"], \"sourceType\": \"script\"}");

#region Regex named groups fix

//At this point, Babel has unminified the code, and fixed IE11 issues, like 'import' method calls.

//We still need to fix 'descriptor' regex evaluation code, as it was expecting a named capture group.
js = Regex.Replace(js, "([a-zA-Z]+)(.groups[ ]*&&[ ]*[a-zA-Z]+.groups.descriptor)", "$1[1]");
js = Regex.Replace(js, "([_a-zA-Z0-9]+)(.groups[ ]*&&[ ]*[_a-zA-Z0-9]+.groups.descriptor)", "$1[1]");

//We still need to fix 'state' regex evaluation code, as it was expecting a named capture group.
js = Regex.Replace(js, "([_a-zA-Z0-9]+)(.groups[ ]*&&[ ]*[_a-zA-Z0-9]+.groups.state)", "$1[1]");

#endregion Regex named groups fix

//Minify with AjaxMin (we don't want an additional external tool with NPM or else for managing this
//kind of thing here...
Expand Down Expand Up @@ -400,6 +415,118 @@ private static FileContentReference GetPatchedBlazorServerFile()

#endregion PATCHED BLAZOR.SERVER.JS

#region PATCHED ASPNETCORE-BROWSER-REFRESH.JS

//private static FileContentReference _patchedAspNetCoreBrowserRefreshFile = null;

//private static FileContentReference GetPatchedAspNetCoreBrowserRefreshFile()
//{
// if (_patchedAspNetCoreBrowserRefreshFile == null)
// {
// BlazorPolyfillOptions option = GetOptions();

// if (option.UsePackagedBlazorServerLibrary)
// {
// //Get packaged blazor.server.js
// var assembly = GetBlazorPolyfillAssembly();

// var resources = assembly.GetManifestResourceNames();
// var resourceName = resources.Single(str => str.EndsWith("blazor.server.packaged.js"));

// using (Stream stream = assembly.GetManifestResourceStream(resourceName))
// {
// using (StreamReader reader = new StreamReader(stream))
// {
// string js = reader.ReadToEnd();

// string Etag = EtagGenerator.GenerateEtagFromString(js);

// //Computing Build time for the Last-Modified Http Header
// //We should rely on the creation date of the Microsoft API
// //not the Blazor.Polyfill.Server one as the Microsoft.AspNetCore.Components.Server
// //assembly may be updated in time. We will rely on the current creation/modification date on disk
// DateTime buildTime = GetAssemblyCreationDate(assembly);

// _patchedBlazorServerFile = new FileContentReference()
// {
// Value = js,
// ETag = Etag,
// LastModified = buildTime,
// ContentLength = System.Text.UTF8Encoding.UTF8.GetByteCount(js).ToString(CultureInfo.InvariantCulture)
// };
// }
// }
// }
// else
// {
// var assembly = GetAspNetCoreComponentsServerAssembly();

// var resources = assembly.GetManifestResourceNames();
// var resourceName = resources.Single(str => str.EndsWith("blazor.server.js"));

// using (Stream stream = assembly.GetManifestResourceStream(resourceName))
// {
// using (StreamReader reader = new StreamReader(stream))
// {
// string js = reader.ReadToEnd();


// #region Patch Regex

// //Patch Descriptor Regex as it make Babel crash during transform
// js = js.Replace("/\\W*Blazor:[^{]*(?<descriptor>.*)$/;", @"/[\0-\/:-@\[-\^`\{-\uFFFF]*Blazor:(?:(?!\{)[\s\S])*(.*)$/;");

// js = js.Replace("/^\\s*Blazor-Component-State:(?<state>[a-zA-Z0-9\\+\\/=]+)$/", @"/^[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*Blazor\x2DComponent\x2DState:([\+\/-9=A-Za-z]+)$/");

// js = js.Replace("/^\\s*Blazor:[^{]*(?<descriptor>.*)$/", @"/^[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*Blazor:(?:(?!\{)[\s\S])*(.*)$/");

// #endregion Patch Regex

// //Transpile code to ES5 for IE11 before manual patching
// js = Transform(js, "blazor.server.js", "{\"plugins\":[\"proposal-class-properties\",\"proposal-object-rest-spread\"],\"presets\":[[\"env\",{\"targets\":{\"browsers\":[\"ie 11\",\"Chrome 78\"]}}], \"es2015\",\"es2016\",\"es2017\",\"stage-3\"], \"sourceType\": \"script\"}");

// #region Regex named groups fix

// //At this point, Babel has unminified the code, and fixed IE11 issues, like 'import' method calls.

// //We still need to fix 'descriptor' regex evaluation code, as it was expecting a named capture group.
// js = Regex.Replace(js, "([a-zA-Z]+)(.groups[ ]*&&[ ]*[a-zA-Z]+.groups.descriptor)", "$1[1]");

// //We still need to fix 'state' regex evaluation code, as it was expecting a named capture group.
// js = Regex.Replace(js, "([a-zA-Z]+)(.groups[ ]*&&[ ]*[a-zA-Z]+.groups.state)", "$1[1]");

// #endregion Regex named groups fix

// //Minify with AjaxMin (we don't want an additional external tool with NPM or else for managing this
// //kind of thing here...
// js = Uglify.Js(js).Code;

// //Computing ETag. Should be computed last !
// string Etag = EtagGenerator.GenerateEtagFromString(js);

// //Computing Build time for the Last-Modified Http Header
// //We should rely on the creation date of the Microsoft API
// //not the Blazor.Polyfill.Server one as the Microsoft.AspNetCore.Components.Server
// //assembly may be updated in time. We will rely on the current creation/modification date on disk
// DateTime buildTime = GetAssemblyCreationDate(assembly);

// _patchedBlazorServerFile = new FileContentReference()
// {
// Value = js,
// ETag = Etag,
// LastModified = buildTime,
// ContentLength = System.Text.UTF8Encoding.UTF8.GetByteCount(js).ToString(CultureInfo.InvariantCulture)
// };
// }
// }
// }
// }

// return _patchedBlazorServerFile;
//}

#endregion PATCHED ASPNETCORE-BROWSER-REFRESH.JS

#region IE11 BLAZOR.POLYFILL.JS

private static FileContentReference _ie11Polyfill = null;
Expand Down
22 changes: 1 addition & 21 deletions src/Blazor.Polyfill.Server/dist/blazor.server.packaged.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<Exec Command="npm install --save core-js" />
<Exec Command="npm install --save whatwg-fetch" />
<Exec Command="npm install --save web-animations-js" />
<Exec Command="npm install --save regenerator-runtime" />
<Exec Command="npm install --save get-root-node-polyfill" />
<Exec Command="npm run build" />
</Target>
</Project>
22 changes: 22 additions & 0 deletions src/Daddoon.Blazor.Polyfill.JS/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/Daddoon.Blazor.Polyfill.JS/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"dependencies": {
"abortcontroller-polyfill": "^1.4.0",
"core-js": "^3.8.2",
"get-root-node-polyfill": "^1.0.0",
"regenerator-runtime": "^0.13.9",
"web-animations-js": "^2.3.2",
"whatwg-fetch": "^2.0.4"
}
Expand Down
7 changes: 6 additions & 1 deletion src/Daddoon.Blazor.Polyfill.JS/src/Boot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 057db9d

Please sign in to comment.