@@ -9,6 +9,8 @@ import { mono_log_debug } from "./logging";
9
9
import { mono_exit } from "./exit" ;
10
10
import { addCachedReponse , findCachedResponse , isCacheAvailable } from "./assetsCache" ;
11
11
import { getIcuResourceName } from "./icu" ;
12
+ import { mono_log_warn } from "./logging" ;
13
+ import { makeURLAbsoluteWithApplicationBase } from "./polyfills" ;
12
14
13
15
14
16
let throttlingPromise : PromiseAndController < void > | undefined ;
@@ -20,6 +22,7 @@ const jsModulesAssetTypes: {
20
22
} = {
21
23
"js-module-threads" : true ,
22
24
"js-module-runtime" : true ,
25
+ "js-module-dotnet" : true ,
23
26
"js-module-native" : true ,
24
27
} ;
25
28
@@ -78,10 +81,10 @@ function getSingleAssetWithResolvedUrl(resources: ResourceList | undefined, beha
78
81
79
82
const customSrc = invokeLoadBootResource ( asset ) ;
80
83
if ( typeof ( customSrc ) === "string" ) {
81
- asset . resolvedUrl = customSrc ;
84
+ asset . resolvedUrl = makeURLAbsoluteWithApplicationBase ( customSrc ) ;
82
85
} else if ( customSrc ) {
83
- // Since we must load this via a import, it's only valid to supply a URI (and not a Request, say)
84
- throw new Error ( `For a ${ behavior } resource, custom loaders must supply a URI string.` ) ;
86
+ mono_log_warn ( `For ${ behavior } resource: ${ name } , custom loaders must supply a URI string.` ) ;
87
+ // we apply a default URL
85
88
}
86
89
87
90
return asset ;
@@ -164,8 +167,9 @@ export async function mono_download_assets(): Promise<void> {
164
167
const asset = await downloadPromise ;
165
168
if ( asset . buffer ) {
166
169
if ( ! skipInstantiateByAssetTypes [ asset . behavior ] ) {
167
- const url = asset . pendingDownloadInternal ! . url ;
168
170
mono_assert ( asset . buffer && typeof asset . buffer === "object" , "asset buffer must be array or buffer like" ) ;
171
+ mono_assert ( typeof asset . resolvedUrl === "string" , "resolvedUrl must be string" ) ;
172
+ const url = asset . resolvedUrl ! ;
169
173
const data = new Uint8Array ( asset . buffer ! ) ;
170
174
cleanupAsset ( asset ) ;
171
175
@@ -220,8 +224,25 @@ export async function mono_download_assets(): Promise<void> {
220
224
221
225
function prepareAssets ( containedInSnapshotAssets : AssetEntryInternal [ ] , alwaysLoadedAssets : AssetEntryInternal [ ] ) {
222
226
const config = loaderHelpers . config ;
223
- const resources = loaderHelpers . config . resources ;
224
- if ( resources ) {
227
+
228
+ // if assets exits, we will assume Net7 legacy and not process resources object
229
+ if ( config . assets ) {
230
+ for ( const a of config . assets ) {
231
+ const asset : AssetEntryInternal = a ;
232
+ mono_assert ( typeof asset === "object" , ( ) => `asset must be object, it was ${ typeof asset } : ${ asset } ` ) ;
233
+ mono_assert ( typeof asset . behavior === "string" , "asset behavior must be known string" ) ;
234
+ mono_assert ( typeof asset . name === "string" , "asset name must be string" ) ;
235
+ mono_assert ( ! asset . resolvedUrl || typeof asset . resolvedUrl === "string" , "asset resolvedUrl could be string" ) ;
236
+ mono_assert ( ! asset . hash || typeof asset . hash === "string" , "asset resolvedUrl could be string" ) ;
237
+ mono_assert ( ! asset . pendingDownload || typeof asset . pendingDownload === "object" , "asset pendingDownload could be object" ) ;
238
+ if ( containedInSnapshotByAssetTypes [ asset . behavior ] ) {
239
+ containedInSnapshotAssets . push ( asset ) ;
240
+ } else {
241
+ alwaysLoadedAssets . push ( asset ) ;
242
+ }
243
+ }
244
+ } else if ( config . resources ) {
245
+ const resources = config . resources ;
225
246
if ( resources . assembly ) {
226
247
for ( const name in resources . assembly ) {
227
248
containedInSnapshotAssets . push ( {
@@ -282,11 +303,11 @@ function prepareAssets(containedInSnapshotAssets: AssetEntryInternal[], alwaysLo
282
303
}
283
304
}
284
305
285
- if ( resources . jsSymbols ) {
286
- for ( const name in resources . jsSymbols ) {
306
+ if ( resources . wasmSymbols ) {
307
+ for ( const name in resources . wasmSymbols ) {
287
308
alwaysLoadedAssets . push ( {
288
309
name,
289
- hash : resources . jsSymbols [ name ] ,
310
+ hash : resources . wasmSymbols [ name ] ,
290
311
behavior : "symbols"
291
312
} ) ;
292
313
}
@@ -307,31 +328,7 @@ function prepareAssets(containedInSnapshotAssets: AssetEntryInternal[], alwaysLo
307
328
}
308
329
}
309
330
310
- const newAssets = [ ...containedInSnapshotAssets , ...alwaysLoadedAssets ] ;
311
-
312
- if ( loaderHelpers . config . assets ) {
313
- for ( const a of loaderHelpers . config . assets ) {
314
- const asset : AssetEntryInternal = a ;
315
- mono_assert ( typeof asset === "object" , "asset must be object" ) ;
316
- mono_assert ( typeof asset . behavior === "string" , "asset behavior must be known string" ) ;
317
- mono_assert ( typeof asset . name === "string" , "asset name must be string" ) ;
318
- mono_assert ( ! asset . resolvedUrl || typeof asset . resolvedUrl === "string" , "asset resolvedUrl could be string" ) ;
319
- mono_assert ( ! asset . hash || typeof asset . hash === "string" , "asset resolvedUrl could be string" ) ;
320
- mono_assert ( ! asset . pendingDownload || typeof asset . pendingDownload === "object" , "asset pendingDownload could be object" ) ;
321
- if ( containedInSnapshotByAssetTypes [ asset . behavior ] ) {
322
- containedInSnapshotAssets . push ( asset ) ;
323
- } else {
324
- alwaysLoadedAssets . push ( asset ) ;
325
- }
326
- }
327
- }
328
-
329
- if ( ! loaderHelpers . config . assets ) {
330
- loaderHelpers . config . assets = [ ] ;
331
- }
332
-
333
- loaderHelpers . config . assets = [ ...loaderHelpers . config . assets , ...newAssets ] ;
334
-
331
+ config . assets = [ ...containedInSnapshotAssets , ...alwaysLoadedAssets ] ;
335
332
}
336
333
337
334
export function delay ( ms : number ) : Promise < void > {
@@ -431,12 +428,17 @@ async function start_asset_download_sources(asset: AssetEntryInternal): Promise<
431
428
}
432
429
if ( asset . buffer ) {
433
430
const buffer = asset . buffer ;
434
- asset . buffer = null as any ; // GC
431
+ if ( ! asset . resolvedUrl ) {
432
+ asset . resolvedUrl = "undefined://" + asset . name ;
433
+ }
435
434
asset . pendingDownloadInternal = {
436
- url : "undefined://" + asset . name ,
435
+ url : asset . resolvedUrl ,
437
436
name : asset . name ,
438
437
response : Promise . resolve ( {
438
+ ok : true ,
439
439
arrayBuffer : ( ) => buffer ,
440
+ json : ( ) => JSON . parse ( new TextDecoder ( "utf-8" ) . decode ( buffer ) ) ,
441
+ text : ( ) => { throw new Error ( "NotImplementedException" ) ; } ,
440
442
headers : {
441
443
get : ( ) => undefined ,
442
444
}
@@ -585,8 +587,7 @@ function fetchResource(request: ResourceRequest): Promise<Response> {
585
587
// They are supplying an entire custom response, so just use that
586
588
return customLoadResult ;
587
589
} else if ( typeof customLoadResult === "string" ) {
588
- // They are supplying a custom URL, so use that with the default fetch behavior
589
- url = customLoadResult ;
590
+ url = makeURLAbsoluteWithApplicationBase ( customLoadResult ) ;
590
591
}
591
592
}
592
593
@@ -614,7 +615,9 @@ const monoToBlazorAssetTypeMap: { [key: string]: WebAssemblyBootResourceType | u
614
615
"pdb" : "pdb" ,
615
616
"icu" : "globalization" ,
616
617
"vfs" : "configuration" ,
618
+ "manifest" : "manifest" ,
617
619
"dotnetwasm" : "dotnetwasm" ,
620
+ "js-module-dotnet" : "dotnetjs" ,
618
621
"js-module-native" : "dotnetjs" ,
619
622
"js-module-runtime" : "dotnetjs" ,
620
623
"js-module-threads" : "dotnetjs"
@@ -625,17 +628,10 @@ function invokeLoadBootResource(request: ResourceRequest): string | Promise<Resp
625
628
const requestHash = request . hash ?? "" ;
626
629
const url = request . resolvedUrl ! ;
627
630
628
- // Try to send with AssetBehaviors
629
- let customLoadResult = loaderHelpers . loadBootResource ( request . behavior , request . name , url , requestHash ) ;
630
- if ( ! customLoadResult ) {
631
- // If we don't get result, try to send with WebAssemblyBootResourceType
632
- const resourceType = monoToBlazorAssetTypeMap [ request . behavior ] ;
633
- if ( resourceType ) {
634
- customLoadResult = loaderHelpers . loadBootResource ( resourceType as AssetBehaviors , request . name , url , requestHash ) ;
635
- }
631
+ const resourceType = monoToBlazorAssetTypeMap [ request . behavior ] ;
632
+ if ( resourceType ) {
633
+ return loaderHelpers . loadBootResource ( resourceType , request . name , url , requestHash , request . behavior ) ;
636
634
}
637
-
638
- return customLoadResult ;
639
635
}
640
636
641
637
return undefined ;
0 commit comments