Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser] Clean-up typescript code imported from Blazor #89435

Merged
merged 67 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
e1c04bc
Remove assets from public monoConfig
maraf Jul 25, 2023
ddff687
Remove BootConfigResult.initAsync
maraf Jul 25, 2023
1d9b6d3
Remove BootConfigResult
maraf Jul 25, 2023
4677dda
Remove WebAssemblyResourceLoader
maraf Jul 25, 2023
d114b30
Fixes
maraf Jul 25, 2023
5e8c364
Remove _Polyfill.ts
maraf Jul 25, 2023
ce5982f
Fix passing wrong instance of monoConfig by remove the function param…
maraf Jul 25, 2023
9b98975
Remove withStartupOptions
maraf Jul 25, 2023
3df841c
Remove getApplicationEnvironment
maraf Jul 25, 2023
6e0e558
Use fetch_like for boot config with loadBootResource
maraf Jul 25, 2023
7baa70d
Throw error when boot config doesn't contain resources
maraf Jul 25, 2023
a8f8d8c
Always use loadBootConfig
maraf Jul 25, 2023
ee3418a
Init resource cache after config is ready
maraf Jul 25, 2023
f912563
Revert test-main.js
maraf Jul 25, 2023
726f4c8
Remove duplicated modifiableAssemblies and aspnetCoreBrowserTools
maraf Jul 26, 2023
97b8eea
Don't read runtimeAssets
maraf Jul 26, 2023
6c4bb33
Replace icuDataMode with globalizationMode
maraf Jul 26, 2023
c496c08
Replace assetsHash with resources.hash and compute has in WasmSDK
maraf Jul 26, 2023
cb3188f
Remove blazor.ts. Add configs to monoConfig. Produce mainAssemblyName…
maraf Jul 26, 2023
86500c5
Replace manual config merging with deep_merge_config
maraf Jul 26, 2023
fe7f173
Ensure assets collection
maraf Jul 26, 2023
f876a67
Remove unused import
maraf Jul 26, 2023
652e0ae
Fix deep_merge_config
maraf Jul 26, 2023
41f7e38
Split runtime resources into groups by behavior in MSBuild
maraf Jul 26, 2023
7d52aee
Use AssetBehaviours in resourceLoader
maraf Jul 26, 2023
1177476
Use loadResource instead of hooking downloadResource
maraf Jul 26, 2023
cbed599
Update dotnet.d.ts
maraf Jul 26, 2023
48cab75
Merge remote-tracking branch 'upstream/main' into WasmTsCleanUp
maraf Jul 27, 2023
dc19914
Fix WBT
maraf Jul 27, 2023
3b58a64
Move config merge to loadBootConfig
maraf Jul 27, 2023
5a82f25
Drop assemblyRootFolder
maraf Jul 27, 2023
19a05d5
Read js-modules and wasm from resources
maraf Jul 27, 2023
06e2de9
Read boot json assets in assets.ts
maraf Jul 27, 2023
fd3afb5
Fix wait_for_all_assets
maraf Jul 27, 2023
ea3daec
Split AssetBehaviors for single and all
maraf Jul 27, 2023
4d68761
Make hash optional (+ compact schema)
maraf Jul 27, 2023
cfba71d
Revert test-main.js
maraf Jul 27, 2023
dfcbf4b
Fix appsettings
maraf Jul 27, 2023
5bafb73
Fix enumerateResources
maraf Jul 27, 2023
1082f1e
Renames
maraf Jul 27, 2023
30136b2
Refactor hash computation and native resource distribution in SDK tasks
maraf Jul 27, 2023
c32f602
Drop commented code
maraf Jul 27, 2023
7e998bb
Flatten structure of native resources and startup modules
maraf Jul 27, 2023
1f67e01
Remove compact resource schema
maraf Jul 27, 2023
b30cb93
Use ResourceRequest in loadResource
maraf Jul 27, 2023
317a96c
Fix WBT
maraf Jul 27, 2023
1054b19
Drop unused isString
maraf Jul 27, 2023
8d1eec8
Fix resource assemblies
maraf Jul 27, 2023
de7f74b
Rename config to appsettings
maraf Jul 27, 2023
e855052
Use more standard way to get URL and download asset
maraf Jul 27, 2023
f625263
Extract cache from resource loader. Move loading to assets
maraf Jul 28, 2023
d1f16e9
Rename resolve_asset_path to resolve_single_asset_path
maraf Jul 28, 2023
1102ee3
Fix logDownloadStatsToConsole and purgeUnusedCacheEntriesAsync
maraf Jul 28, 2023
d04c549
Stop duplicating values to deprecated fields
maraf Jul 28, 2023
a87bd45
Use relaxed encoding and skip nulls
maraf Jul 28, 2023
35c0ee4
Omit default values from boot config
maraf Jul 28, 2023
3661d89
Unify resource name in boot config in Wasm SDk
maraf Jul 28, 2023
40fc448
Fix reading pendingDownloadInternal in retrieve_asset_download
maraf Jul 28, 2023
6a168ac
Fix retrieve_asset_download
maraf Jul 28, 2023
81b79a6
Feedback
maraf Jul 28, 2023
d13807e
Pass AssetBehaviors to LoadBootResourceCallback, call it for everything
maraf Jul 28, 2023
ef7c8eb
Deep merge resources
maraf Jul 28, 2023
79f2c42
Use System.Text.Json in GenerateWasmBootJson
maraf Jul 28, 2023
9eda778
Merge remote-tracking branch 'upstream/main' into WasmTsCleanUp
maraf Jul 28, 2023
a9f7cf7
Order items when computing hash
maraf Jul 28, 2023
ed81e8e
Hotfix WBT
maraf Jul 28, 2023
6b3712c
Fix WBT
maraf Jul 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ Copyright (c) .NET Foundation. All rights reserved.
RuntimeOptions="$(_BlazorWebAssemblyRuntimeOptions)"
Extensions="@(WasmBootConfigExtension)"
TargetFrameworkVersion="$(TargetFrameworkVersion)"
LibraryInitializerOnRuntimeConfigLoaded="@(WasmLibraryInitializerOnRuntimeConfigLoaded)"
LibraryInitializerOnRuntimeReady="@(WasmLibraryInitializerOnRuntimeReady)" />
ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)"
ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" />

<ItemGroup>
<FileWrites Include="$(_WasmBuildBootJsonPath)" />
Expand Down Expand Up @@ -551,8 +551,8 @@ Copyright (c) .NET Foundation. All rights reserved.
RuntimeOptions="$(_BlazorWebAssemblyRuntimeOptions)"
Extensions="@(WasmBootConfigExtension)"
TargetFrameworkVersion="$(TargetFrameworkVersion)"
LibraryInitializerOnRuntimeConfigLoaded="@(WasmLibraryInitializerOnRuntimeConfigLoaded)"
LibraryInitializerOnRuntimeReady="@(WasmLibraryInitializerOnRuntimeReady)" />
ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)"
ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" />

<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)blazor.publish.boot.json" />
Expand Down
6 changes: 5 additions & 1 deletion src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,11 @@ public void AssertBootJson(AssertBundleOptionsBase options)
Assert.True(File.Exists(bootJsonPath), $"Expected to find {bootJsonPath}");

BootJsonData bootJson = ParseBootData(bootJsonPath);
var bootJsonEntries = bootJson.resources.runtime.Keys.Where(k => k.StartsWith("dotnet.", StringComparison.Ordinal)).ToArray();
var bootJsonEntries = bootJson.resources.jsModuleNative.Keys
.Union(bootJson.resources.jsModuleRuntime.Keys)
.Union(bootJson.resources.jsModuleWorker.Keys)
.Union(bootJson.resources.wasmNative.Keys)
.ToArray();

var expectedEntries = new SortedDictionary<string, Action<string>>();
IReadOnlySet<string> expected = GetDotNetFilesExpectedSet(options);
Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/TestMainJsProjectProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public TestMainJsProjectProvider(ITestOutputHelper _testOutput, string? _project
protected override IReadOnlyDictionary<string, bool> GetAllKnownDotnetFilesToFingerprintMap(AssertBundleOptionsBase assertOptions)
=> new SortedDictionary<string, bool>()
{
{ "dotnet.js", false },
Copy link
Member Author

@maraf maraf Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radical I have removed dotnet.js from boot json, but it is expected to be present in the _framework. How would you prefer this method to be updated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also remove dotnet.runtime.js.map ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a hotfix to unblock WBT in this PR

{ "dotnet.js.map", false },
{ "dotnet.native.js", false },
{ "dotnet.native.js.symbols", false },
{ "dotnet.native.wasm", false },
Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public WasmSdkBasedProjectProvider(ITestOutputHelper _testOutput, string? _proje
protected override IReadOnlyDictionary<string, bool> GetAllKnownDotnetFilesToFingerprintMap(AssertBundleOptionsBase assertOptions)
=> new SortedDictionary<string, bool>()
{
{ "dotnet.js", false },
{ "dotnet.js.map", false },
{ "dotnet.native.js", true },
{ "dotnet.native.js.symbols", false },
{ "dotnet.native.wasm", false },
Expand Down
77 changes: 35 additions & 42 deletions src/mono/wasm/runtime/dotnet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,6 @@ interface DotnetHostBuilder {
run(): Promise<number>;
}
type MonoConfig = {
/**
* The subfolder containing managed assemblies and pdbs. This is relative to dotnet.js script.
*/
assemblyRootFolder?: string;
/**
* A list of assets to load along with the runtime.
*/
assets?: AssetEntry[];
/**
* Additional search locations for assets.
*/
Expand Down Expand Up @@ -133,6 +125,10 @@ type MonoConfig = {
* debugLevel < 0 enables debugging and disables debug logging.
*/
debugLevel?: number;
/**
* Gets a value that determines whether to enable caching of the 'resources' inside a CacheStorage instance within the browser.
*/
cacheBootResources?: boolean;
/**
* Enables diagnostic log messages during startup
*/
Expand All @@ -151,10 +147,6 @@ type MonoConfig = {
* If true, the snapshot of runtime's memory will be stored in the browser and used for faster startup next time. Default is false.
*/
startupMemoryCache?: boolean;
/**
* hash of assets
*/
assetsHash?: string;
maraf marked this conversation as resolved.
Show resolved Hide resolved
/**
* application environment
*/
Expand All @@ -167,6 +159,10 @@ type MonoConfig = {
* definition of assets to load along with the runtime.
*/
resources?: ResourceGroups;
/**
* appsettings files to load to VFS
*/
appsettings?: string[];
/**
* config extensions declared in MSBuild items @(WasmBootConfigExtension)
*/
Expand All @@ -182,15 +178,17 @@ interface ResourceGroups {
readonly assembly?: ResourceList;
readonly lazyAssembly?: ResourceList;
readonly pdb?: ResourceList;
readonly runtime?: ResourceList;
readonly jsModuleWorker?: ResourceList;
readonly jsModuleNative: ResourceList;
readonly jsModuleRuntime: ResourceList;
readonly jsSymbols?: ResourceList;
readonly wasmNative: ResourceList;
readonly icu?: ResourceList;
readonly satelliteResources?: {
[cultureName: string]: ResourceList;
};
readonly libraryInitializers?: ResourceList;
readonly libraryStartupModules?: {
readonly onRuntimeConfigLoaded?: ResourceList;
readonly onRuntimeReady?: ResourceList;
};
readonly modulesAfterConfigLoaded?: ResourceList;
readonly modulesAfterRuntimeReady?: ResourceList;
readonly extensions?: ResourceExtensions;
readonly vfs?: {
[virtualPath: string]: ResourceList;
Expand All @@ -211,7 +209,7 @@ type ResourceList = {
type LoadBootResourceCallback = (type: WebAssemblyBootResourceType, name: string, defaultUri: string, integrity: string) => string | Promise<Response> | null | undefined;
interface ResourceRequest {
name: string;
behavior: AssetBehaviours;
behavior: AssetBehaviors;
resolvedUrl?: string;
hash?: string;
}
Expand Down Expand Up @@ -248,7 +246,24 @@ interface AssetEntry extends ResourceRequest {
*/
pendingDownload?: LoadingResource;
}
type AssetBehaviours =
type SingleAssetBehaviors =
/**
* The binary of the dotnet runtime.
*/
"dotnetwasm"
/**
* The javascript module for threads.
*/
| "js-module-threads"
/**
* The javascript module for threads.
*/
| "js-module-runtime"
/**
* The javascript module for threads.
*/
| "js-module-native";
type AssetBehaviors = SingleAssetBehaviors |
/**
* Load asset as a managed resource assembly.
*/
Expand All @@ -273,26 +288,6 @@ type AssetBehaviours =
* Load asset into the virtual filesystem (for fopen, File.Open, etc).
*/
| "vfs"
/**
* The binary of the dotnet runtime.
*/
| "dotnetwasm"
/**
* The javascript module for threads.
*/
| "js-module-threads"
/**
* The javascript module for threads.
*/
| "js-module-runtime"
/**
* The javascript module for threads.
*/
| "js-module-dotnet"
/**
* The javascript module for threads.
*/
| "js-module-native"
/**
* The javascript module that came from nuget package .
*/
Expand Down Expand Up @@ -330,10 +325,8 @@ type DotnetModuleConfig = {
onConfigLoaded?: (config: MonoConfig) => void | Promise<void>;
onDotnetReady?: () => void | Promise<void>;
onDownloadResourceProgress?: (resourcesLoaded: number, totalResources: number) => void;
getApplicationEnvironment?: (bootConfigResponse: Response) => string | null;
imports?: any;
exports?: string[];
downloadResource?: (request: ResourceRequest) => LoadingResource | undefined;
} & Partial<EmscriptenModule>;
type APIType = {
runMain: (mainAssemblyName: string, args: string[]) => Promise<number>;
Expand Down
34 changes: 22 additions & 12 deletions src/mono/wasm/runtime/lazyLoading.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import { INTERNAL, loaderHelpers, runtimeHelpers } from "./globals";
import type { WebAssemblyResourceLoader } from "./loader/blazor/WebAssemblyResourceLoader";
import { loaderHelpers, runtimeHelpers } from "./globals";
import { AssetEntry } from "./types";

export async function loadLazyAssembly(assemblyNameToLoad: string): Promise<boolean> {
const resourceLoader: WebAssemblyResourceLoader = INTERNAL.resourceLoader;
const resources = resourceLoader.bootConfig.resources;
const resources = loaderHelpers.config.resources!;
const lazyAssemblies = resources.lazyAssembly;
if (!lazyAssemblies) {
throw new Error("No assemblies have been marked as lazy-loadable. Use the 'BlazorWebAssemblyLazyLoad' item group in your project file to enable lazy loading an assembly.");
}

const assemblyMarkedAsLazy = Object.prototype.hasOwnProperty.call(lazyAssemblies, assemblyNameToLoad);
if (!assemblyMarkedAsLazy) {
if (!lazyAssemblies[assemblyNameToLoad]) {
throw new Error(`${assemblyNameToLoad} must be marked with 'BlazorWebAssemblyLazyLoad' item group in your project file to allow lazy-loading.`);
}

const dllAsset: AssetEntry = {
name: assemblyNameToLoad,
hash: lazyAssemblies[assemblyNameToLoad],
behavior: "assembly",
};

if (loaderHelpers.loadedAssemblies.some(f => f.includes(assemblyNameToLoad))) {
return false;
}

const dllNameToLoad = assemblyNameToLoad;
const pdbNameToLoad = changeExtension(assemblyNameToLoad, ".pdb");
const shouldLoadPdb = loaderHelpers.hasDebuggingEnabled(resourceLoader.bootConfig) && resources.pdb && Object.prototype.hasOwnProperty.call(lazyAssemblies, pdbNameToLoad);
const pdbNameToLoad = changeExtension(dllAsset.name, ".pdb");
const shouldLoadPdb = loaderHelpers.hasDebuggingEnabled(loaderHelpers.config) && Object.prototype.hasOwnProperty.call(lazyAssemblies, pdbNameToLoad);

const dllBytesPromise = resourceLoader.loadResource(dllNameToLoad, loaderHelpers.locateFile(dllNameToLoad), lazyAssemblies[dllNameToLoad], "assembly").response.then(response => response.arrayBuffer());
const dllBytesPromise = loaderHelpers.retrieve_asset_download(dllAsset).then(response => response.arrayBuffer());

let dll = null;
let pdb = null;
if (shouldLoadPdb) {
const pdbBytesPromise = await resourceLoader.loadResource(pdbNameToLoad, loaderHelpers.locateFile(pdbNameToLoad), lazyAssemblies[pdbNameToLoad], "pdb").response.then(response => response.arrayBuffer());
const pdbBytesPromise = lazyAssemblies[pdbNameToLoad]
? loaderHelpers.retrieve_asset_download({
name: pdbNameToLoad,
hash: lazyAssemblies[pdbNameToLoad],
behavior: "pdb"
}).then(response => response.arrayBuffer())
: Promise.resolve(null);

const [dllBytes, pdbBytes] = await Promise.all([dllBytesPromise, pdbBytesPromise]);

dll = new Uint8Array(dllBytes);
pdb = new Uint8Array(pdbBytes);
pdb = pdbBytes ? new Uint8Array(pdbBytes) : null;
} else {
const dllBytes = await dllBytesPromise;
dll = new Uint8Array(dllBytes);
Expand Down
Loading
Loading