|
475 | 475 | Condition="'$(_UnoDotnetJsFingerprintPublish)' != '' AND Exists('$(_UnoConfigJsPath)')" /> |
476 | 476 | </Target> |
477 | 477 |
|
| 478 | + <!-- |
| 479 | + Final safety net: Update uno-config.js directly in the publish output directory. |
| 480 | + This runs AFTER files have been copied to ensure the fingerprint is always correct, |
| 481 | + regardless of MSBuild target ordering or caching behavior. |
| 482 | + --> |
| 483 | + <Target Name="_UnoUpdateDotnetJsFingerprintPublishOutput" |
| 484 | + AfterTargets="Publish" |
| 485 | + Condition="'$(WasmFingerprintDotnetJs)' == 'true'"> |
| 486 | + |
| 487 | + <!-- Find the actual dotnet.js file in the publish _framework directory --> |
| 488 | + <ItemGroup> |
| 489 | + <_UnoPublishedDotnetJs Include="$(PublishDir)wwwroot/_framework/dotnet.*.js" |
| 490 | + Exclude="$(PublishDir)wwwroot/_framework/dotnet.native.*.js;$(PublishDir)wwwroot/_framework/dotnet.runtime.*.js" /> |
| 491 | + </ItemGroup> |
| 492 | + |
| 493 | + <!-- Extract fingerprint from actual filename --> |
| 494 | + <PropertyGroup> |
| 495 | + <_UnoActualDotnetJsFingerprint>$([System.Text.RegularExpressions.Regex]::Match('%(_UnoPublishedDotnetJs.Filename)', '^dotnet\.([a-z0-9]+)$').Groups[1].Value)</_UnoActualDotnetJsFingerprint> |
| 496 | + <_UnoPublishConfigJsPath>$(PublishDir)wwwroot/$(WasmShellOutputPackagePath)/uno-config.js</_UnoPublishConfigJsPath> |
| 497 | + </PropertyGroup> |
| 498 | + |
| 499 | + <!-- Update uno-config.js in the publish output with the actual fingerprint --> |
| 500 | + <WriteLinesToFile |
| 501 | + File="$(_UnoPublishConfigJsPath)" |
| 502 | + Lines="$([System.Text.RegularExpressions.Regex]::Replace($([System.Text.RegularExpressions.Regex]::Replace($([System.IO.File]::ReadAllText('$(_UnoPublishConfigJsPath)')), 'config\.dotnet_js_filename = "dotnet(\.[^"]+)?\.js"', 'config.dotnet_js_filename = "dotnet.$(_UnoActualDotnetJsFingerprint).js"')), '_framework/dotnet(\.[^"]+)?\.js', '_framework/dotnet.$(_UnoActualDotnetJsFingerprint).js'))" |
| 503 | + Overwrite="true" |
| 504 | + Condition="'$(_UnoActualDotnetJsFingerprint)' != '' AND Exists('$(_UnoPublishConfigJsPath)')" /> |
| 505 | + |
| 506 | + <Message Importance="normal" |
| 507 | + Text="Updated uno-config.js with dotnet.js fingerprint: $(_UnoActualDotnetJsFingerprint)" |
| 508 | + Condition="'$(_UnoActualDotnetJsFingerprint)' != ''" /> |
| 509 | + </Target> |
| 510 | + |
| 511 | + <!-- |
| 512 | + Validate that uno-config.js fingerprint matches the actual dotnet.js file. |
| 513 | + --> |
| 514 | + <Target Name="_UnoValidateDotnetJsFingerprintPublish" |
| 515 | + AfterTargets="_UnoUpdateDotnetJsFingerprintPublishOutput" |
| 516 | + Condition="'$(WasmFingerprintDotnetJs)' == 'true' AND '$(UnoSkipDotnetJsFingerprintValidation)' != 'true'"> |
| 517 | + |
| 518 | + <PropertyGroup> |
| 519 | + <_UnoPublishConfigJsPath>$(PublishDir)wwwroot/$(WasmShellOutputPackagePath)/uno-config.js</_UnoPublishConfigJsPath> |
| 520 | + <_UnoFrameworkPath>$(PublishDir)wwwroot/_framework</_UnoFrameworkPath> |
| 521 | + </PropertyGroup> |
| 522 | + |
| 523 | + <PropertyGroup Condition="Exists('$(_UnoPublishConfigJsPath)')"> |
| 524 | + <_UnoConfigContent>$([System.IO.File]::ReadAllText('$(_UnoPublishConfigJsPath)'))</_UnoConfigContent> |
| 525 | + <_UnoConfigFingerprint>$([System.Text.RegularExpressions.Regex]::Match('$(_UnoConfigContent)', 'dotnet\.([a-z0-9]+)\.js').Groups[1].Value)</_UnoConfigFingerprint> |
| 526 | + </PropertyGroup> |
| 527 | + |
| 528 | + <Error Condition="'$(_UnoConfigFingerprint)' == ''" |
| 529 | + Code="UNOWASM001" |
| 530 | + Text="uno-config.js does not contain a fingerprinted dotnet.js reference." /> |
| 531 | + |
| 532 | + <Error Condition="'$(_UnoConfigFingerprint)' != '' AND !Exists('$(_UnoFrameworkPath)/dotnet.$(_UnoConfigFingerprint).js')" |
| 533 | + Code="UNOWASM002" |
| 534 | + Text="Fingerprint mismatch: uno-config.js references dotnet.$(_UnoConfigFingerprint).js but file does not exist in $(_UnoFrameworkPath)." /> |
| 535 | + |
| 536 | + <Message Importance="normal" |
| 537 | + Text="Validated: uno-config.js fingerprint ($(_UnoConfigFingerprint)) matches actual dotnet.js file" |
| 538 | + Condition="'$(_UnoConfigFingerprint)' != ''" /> |
| 539 | + </Target> |
| 540 | + |
478 | 541 | <PropertyGroup> |
479 | 542 | <UnoEnableEmccProfiling_BeforeTargets> |
480 | 543 | $(UnoEnableEmccProfiling_BeforeTargets); |
|
0 commit comments