Skip to content

Commit

Permalink
Merge pull request #912 from unoplatform/dev/jela/adjust-assets
Browse files Browse the repository at this point in the history
fix: don't prefix uno-assets path with the package folder for compatibility
  • Loading branch information
jeromelaban authored Nov 1, 2024
2 parents 61861ee + fd21e87 commit 954d9f4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
20 changes: 16 additions & 4 deletions doc/features-additional-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ Exclusions:

1. Files in the `WasmScript` folder will be set as `UnoDeploy="None"` by default (they are not treat as content)

2. Files in the `wwwroot` folder will be set as `UnoDeploy="Root"` by default
1. Files in the `wwwroot` folder will be set as `UnoDeploy="Root"` by default

3. You can manually set the _deploy mode_ in the `.csproj` in the following way:
1. You can manually set the _deploy mode_ in the `.csproj` in the following way:

```xml
<ItemGroup>
Expand All @@ -56,6 +56,18 @@ Exclusions:
</ItemGroup>
```

Asset files: `wwwroot/uno-assets.txt` contains the package relative paths of the content files that were copied to the `wwwroot` folder. It can be used to identify which assets are packaged with the application at runtime and avoid costly probing operations. Important: Will only contain files deployed in `UnoDeploy="Package"` mode.
1. A few files extensions are excluded (`UnoDeploy="None")`by default such as `*.a`, `*.o`. `.html` files are those named `web.config` will default to `UnoDeploy="Root"`.

A few files extensions are excluded (`UnoDeploy="None")`by default such as `*.a`, `*.o`. `.html` files are those named `web.config` will default to `UnoDeploy="Root"`.
### Asset dictionary

The file `wwwroot/package_XXX/uno-assets.txt` contains the package relative paths of the content files that were copied to the `wwwroot` folder.

It can be used to identify which assets are packaged with the application at runtime and avoid costly probing operations.

The files are specified in two parts:

- The files located in the `_framework` folder, which are all the assemblies used to run the app. The path in the `uno-assets.txt` file is relative to the base uri of the site.
- The files contained in `package_XXX` folder, which are the Content files specified at build time. The path in the `uno-assets.txt` file is relative to the `package_XXX` folder of the site.

> [!IMPORTANT]
> This file only contain files deployed in `UnoDeploy="Package"` mode.
11 changes: 10 additions & 1 deletion src/Uno.Wasm.Bootstrap/GenerateUnoAssetsManifestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ public override bool Execute()
foreach(var asset in StaticWebAsset)
{
var assetPath = Path.GetDirectoryName(asset.GetMetadata("RelativePath")) + "/" + Path.GetFileName(asset.GetMetadata("FullPath"));
assets.Add(assetPath.Replace("\\", "/").TrimStart('/'));
var sanitizedAssetPath = assetPath.Replace("\\", "/").TrimStart('/');

if (sanitizedAssetPath.StartsWith(OutputPackagePath + "/"))
{
// Remove the original path OutputPackagePath from the path to keep
// net8 compatibility.
sanitizedAssetPath = sanitizedAssetPath.Substring(OutputPackagePath.Length + 1);
}

assets.Add(sanitizedAssetPath);
}

var assetsFilePath = Path.Combine(_intermediateAssetsPath, "uno-assets.txt");
Expand Down
23 changes: 23 additions & 0 deletions src/Uno.Wasm.Sample/sample.common.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,28 @@
<ItemGroup>
<ProjectReference Include="..\Uno.Wasm.Sample.Library\Uno.Wasm.Sample.Library.csproj" />
</ItemGroup>

<Target Name="AfterPublishValidation" AfterTargets="Publish">

<PropertyGroup>
<_appOutput>$(PublishDir)wwwroot/$(WasmShellOutputPackagePath)</_appOutput>
</PropertyGroup>

<!-- read the contents of the file uno-assets.txt -->
<ReadLinesFromFile File="$(_appOutput)/uno-assets.txt">
<Output TaskParameter="Lines" ItemName="_UnoAssetsLines"/>
</ReadLinesFromFile>

<ItemGroup>
<_InvalidAssetLines Include="@(_UnoAssetsLines)"
Condition="$([System.String]::Copy('%(Identity)').StartsWith('package_'))" />
</ItemGroup>

<!-- Fail if any _UnoAssetsLines item contains the string `package_` -->
<Error Condition=" '@(_InvalidAssetLines)' != ''"
Text="No asset should start with 'package_'" />

<Message Importance="high" Text="Output dist validated" />
</Target>

</Project>

0 comments on commit 954d9f4

Please sign in to comment.