Skip to content

Commit bfe5471

Browse files
authored
Use minified .js files from submodule in source-build (dotnet#56864)
* Use minified .js files from submodule in source-build * Fixup * Fixup again * Add check for changes to minified .js files * Fix typo * Add doc * Fix md error * Update Microsoft.AspNetCore.Components.Endpoints.csproj * Fix script * Update submodule * Print it * Upload the .js files as part of the build * Update submodule
1 parent 65cc716 commit bfe5471

File tree

11 files changed

+64
-3
lines changed

11 files changed

+64
-3
lines changed

.azure/pipelines/ci-public.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ stages:
556556
beforeBuild:
557557
- powershell: "& ./src/Servers/IIS/tools/UpdateIISExpressCertificate.ps1; & ./src/Servers/IIS/tools/update_schema.ps1"
558558
displayName: Setup IISExpress test certificates and schema
559+
afterBuild:
560+
- powershell: ./eng/scripts/CompareMinifiedJsFiles.ps1
561+
displayName: Check for changes in generated minified .js files
559562
artifacts:
560563
- name: Windows_Test_Logs_Attempt_$(System.JobAttempt)
561564
path: artifacts/log/
@@ -565,6 +568,10 @@ stages:
565568
path: artifacts/TestResults/
566569
publishOnError: true
567570
includeForks: true
571+
- name: Minified_JS_Files
572+
path: src/Components/Web.JS/dist/Release/
573+
publishOnError: true
574+
includeForks: true
568575

569576
- template: jobs/default-build.yml
570577
parameters:

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
url = https://github.com/dotnet/Node-Externals
1212
branch = main
1313
depth = 1
14+
[submodule "src/submodules/BlazorMinifiedJs"]
15+
path = src/submodules/BlazorMinifiedJs
16+
url = https://github.com/dotnet/BlazorMinifiedJs
17+
branch = main

docs/UpdatingMinifiedJsFiles.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Updating minified .js files
2+
3+
Building our `src/Components` projects will produce minified.js files under `src/Components/Web.JS/dist/Release`. In order to avoid constant merge conflicts, and to avoid having to restore NPM components over the network during offline source-build, we keep the latest versions of those files in a submodule repo, https://github.com/dotnet/blazorminifiedjs. If you are prepping a PR that is going to change the contents of those files, please follow the steps in this doc.
4+
5+
1. Build the node components of the repo
6+
1. Running `npm run build` from the repo root should be sufficient, assuming you have already installed the prereqs listed in our [Building from source doc](https://github.com/dotnet/aspnetcore/edit/main/docs/BuildFromSource.md).
7+
2. In a separate folder, clone the [BlazorMinifiedJs repo](https://github.com/dotnet/blazorminifiedjs).
8+
3. Check out a new branch in your clone, based off of `main`.
9+
4. Replace the files in `BlazorMinifiedJs/src` with the minified .js files you just generated in aspnetcore (these can be found at `aspnetcore/src/Components/Web.JS/dist/Release`).
10+
5. Push your `BlazorMinifiedJs` branch and open a PR in that repo.
11+
6. Once that PR has been merged, return to your aspnetcore PR, navigate to `src/submodules/BlazorMinifiedJs`, and checkout the commit you just pushed.
12+
7. Push the submodule update to your aspnetcore PR.
13+
14+
Alternatively, you can find the generated .js files in the artifacts of your PR build, under the artifact named "Minified_JS_Files". This may be more reliable than building the node components locally.
15+
16+
Following these steps should remediate any build errors related to `BlazorMinifiedJs` in your PR.

eng/Common.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<BuildNative Condition=" '$(BuildNative)' == '' ">true</BuildNative>
1919

2020
<BuildManaged Condition="'$(BuildManaged)' == ''">true</BuildManaged>
21+
<BuildNodeJS>$(BuildNodeJSUnlessSourcebuild)</BuildNodeJS>
22+
<BuildNodeJS Condition="'$(DotNetBuildSourceOnly)' == 'true'">false</BuildNodeJS>
2123
<BuildNodeJS Condition="'$(BuildNodeJS)' == ''">true</BuildNodeJS>
2224
<BuildJava Condition="'$(BuildJava)' == ''">true</BuildJava>
2325
</PropertyGroup>

eng/build.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ if ($BuildManaged -or ($All -and (-not $NoBuildManaged))) {
235235
if ($node) {
236236
$nodeHome = Split-Path -Parent (Split-Path -Parent $node.Path)
237237
Write-Host -f Magenta "Building of C# project is enabled and has dependencies on NodeJS projects. Building of NodeJS projects is enabled since node is detected in $nodeHome."
238+
Write-Host -f Magenta "Note that if you are running Source Build, building NodeJS projects will be disabled later on."
238239
$BuildNodeJS = $true
239240
}
240241
else {
@@ -310,8 +311,8 @@ if ($NoBuildJava) { $dotnetBuildArguments += "/p:BuildJava=false"; $BuildJava =
310311
if ($BuildJava) { $dotnetBuildArguments += "/p:BuildJava=true" }
311312
if ($NoBuildManaged) { $dotnetBuildArguments += "/p:BuildManaged=false"; $BuildManaged = $false }
312313
if ($BuildManaged) { $dotnetBuildArguments += "/p:BuildManaged=true" }
313-
if ($NoBuildNodeJS) { $dotnetBuildArguments += "/p:BuildNodeJS=false"; $BuildNodeJS = $false }
314-
if ($BuildNodeJS) { $dotnetBuildArguments += "/p:BuildNodeJS=true" }
314+
if ($NoBuildNodeJS) { $dotnetBuildArguments += "/p:BuildNodeJSUnlessSourcebuild=false"; $BuildNodeJS = $false }
315+
if ($BuildNodeJS) { $dotnetBuildArguments += "/p:BuildNodeJSUnlessSourcebuild=true" }
315316

316317
# Don't bother with two builds if just one will build everything. Ignore super-weird cases like
317318
# "-Projects ... -NoBuildJava -NoBuildManaged -NoBuildNodeJS". An empty `./build.ps1` command will build both

eng/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ if [ "$build_managed" = true ] || ([ "$build_all" = true ] && [ "$build_managed"
266266
if [ -z "$build_nodejs" ]; then
267267
if [ -x "$(command -v node)" ]; then
268268
__warn "Building of C# project is enabled and has dependencies on NodeJS projects. Building of NodeJS projects is enabled since node is detected on PATH."
269+
__warn "Note that if you are running Source Build, building NodeJS projects will be disabled later on."
269270
build_nodejs=true
270271
else
271272
__warn "Building of NodeJS projects is disabled since node is not detected on Path and no BuildNodeJs or NoBuildNodeJs setting is set explicitly."
@@ -281,7 +282,7 @@ fi
281282
# Only set these MSBuild properties if they were explicitly set by build parameters.
282283
[ ! -z "$build_java" ] && msbuild_args[${#msbuild_args[*]}]="-p:BuildJava=$build_java"
283284
[ ! -z "$build_native" ] && msbuild_args[${#msbuild_args[*]}]="-p:BuildNative=$build_native"
284-
[ ! -z "$build_nodejs" ] && msbuild_args[${#msbuild_args[*]}]="-p:BuildNodeJS=$build_nodejs"
285+
[ ! -z "$build_nodejs" ] && msbuild_args[${#msbuild_args[*]}]="-p:BuildNodeJSUnlessSourcebuild=$build_nodejs"
285286
[ ! -z "$build_managed" ] && msbuild_args[${#msbuild_args[*]}]="-p:BuildManaged=$build_managed"
286287
[ ! -z "$build_installers" ] && msbuild_args[${#msbuild_args[*]}]="-p:BuildInstallers=$build_installers"
287288

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[string[]] $errors = @()
2+
3+
function _compareFiles($fileName) {
4+
Write-Host "Comparing contents for $fileName"
5+
$repoRoot = Resolve-Path "$PSScriptRoot/../.."
6+
$localFile = "$repoRoot/src/Components/Web.JS/dist/Release/$fileName"
7+
$submoduleFile = "$repoRoot/src/submodules/BlazorMinifiedJs/src/$fileName"
8+
$delta = Compare-Object -ReferenceObject ((Get-Content -Path $submoduleFile).trim()) -DifferenceObject ((Get-Content -Path $localFile).trim())
9+
if (![string]::IsNullOrEmpty($delta)) {
10+
$script:errors += "Diff found in $fileName, please see https://github.com/dotnet/aspnetcore/blob/main/docs/UpdatingMinifiedJsFiles.md for remediation steps"
11+
}
12+
}
13+
14+
$MinifiedJsFiles = "blazor.web.js","blazor.server.js","blazor.webview.js"
15+
16+
foreach ($JsFile in $MinifiedJsFiles) {
17+
_compareFiles -fileName $JsFile
18+
}
19+
20+
foreach ($err in $errors) {
21+
Write-Host -f Red $err
22+
}
23+
24+
if ($errors) {
25+
exit 1
26+
}

src/Components/Endpoints/src/Microsoft.AspNetCore.Components.Endpoints.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<BlazorWebJSFilename>blazor.web.js</BlazorWebJSFilename>
6666
<BlazorWebJSFile Condition=" '$(Configuration)' == 'Debug' ">$(MSBuildThisFileDirectory)..\..\Web.JS\dist\Debug\$(BlazorWebJSFilename)</BlazorWebJSFile>
6767
<BlazorWebJSFile Condition=" '$(Configuration)' != 'Debug' ">$(MSBuildThisFileDirectory)..\..\Web.JS\dist\Release\$(BlazorWebJSFilename)</BlazorWebJSFile>
68+
<BlazorWebJSFile Condition="!Exists('$(BlazorWebJSFile)') and '$(BuildNodeJS)' != 'true' ">$(RepoRoot)src\submodules\BlazorMinifiedJs\src\$(BlazorWebJSFilename)</BlazorWebJSFile>
6869
</PropertyGroup>
6970

7071
<Warning Condition="!Exists('$(BlazorWebJSFile)')" Text="'$(BlazorWebJSFile)' does not exist. Ensure the JS assets have been build by running 'npm run build' from the repository root." />

src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<BlazorServerJSFilename>blazor.server.js</BlazorServerJSFilename>
104104
<BlazorServerJSFile Condition=" '$(Configuration)' == 'Debug' ">$(MSBuildThisFileDirectory)..\..\Web.JS\dist\Debug\$(BlazorServerJSFilename)</BlazorServerJSFile>
105105
<BlazorServerJSFile Condition=" '$(Configuration)' != 'Debug' ">$(MSBuildThisFileDirectory)..\..\Web.JS\dist\Release\$(BlazorServerJSFilename)</BlazorServerJSFile>
106+
<BlazorServerJSFile Condition="!Exists('$(BlazorServerJSFile)') and '$(BuildNodeJS)' != 'true' ">$(RepoRoot)src\submodules\BlazorMinifiedJs\src\$(BlazorServerJSFilename)</BlazorServerJSFile>
106107
</PropertyGroup>
107108

108109
<Warning Condition="!Exists('$(BlazorServerJSFile)')" Text="'$(BlazorServerJSFile)' does not exist. Ensure the JS assets have been build by running 'npm run build' from the repository root." />

src/Components/WebView/WebView/src/Microsoft.AspNetCore.Components.WebView.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<BlazorWebViewJSFilename>blazor.webview.js</BlazorWebViewJSFilename>
6363
<BlazorWebViewJSFile Condition=" '$(Configuration)' == 'Debug' ">$(MSBuildThisFileDirectory)..\..\..\Web.JS\dist\Debug\$(BlazorWebViewJSFilename)</BlazorWebViewJSFile>
6464
<BlazorWebViewJSFile Condition=" '$(Configuration)' != 'Debug' ">$(MSBuildThisFileDirectory)..\..\..\Web.JS\dist\Release\$(BlazorWebViewJSFilename)</BlazorWebViewJSFile>
65+
<BlazorWebViewJSFile Condition="!Exists('$(BlazorWebViewJSFile)') and '$(BuildNodeJS)' != 'true' ">$(RepoRoot)src\submodules\BlazorMinifiedJs\src\$(BlazorWebViewJSFilename)</BlazorWebViewJSFile>
6566
</PropertyGroup>
6667

6768
<Warning Condition="!Exists('$(BlazorWebViewJSFile)')" Text="'$(BlazorWebViewJSFile)' does not exist. Ensure the JS assets have been build by running 'npm run build' from the repository root." />

src/submodules/BlazorMinifiedJs

Submodule BlazorMinifiedJs added at 42f116d

0 commit comments

Comments
 (0)