@@ -59,30 +59,27 @@ export function mono_wasm_set_runtime_options(options: string[]): void {
59
59
async function _fetch_asset ( url : string ) : Promise < Response > {
60
60
if ( typeof ( fetch ) === "function" ) {
61
61
return fetch ( url , { credentials : "same-origin" } ) ;
62
- } else if ( ENVIRONMENT_IS_NODE || typeof ( read ) === "function" ) {
63
- let data : any = null ;
64
- try {
65
- if ( ENVIRONMENT_IS_NODE ) {
66
- // eslint-disable-next-line @typescript-eslint/no-var-requires
67
- const fs = require ( "fs" ) ;
68
- data = await fs . promises . readFile ( url ) ;
69
- }
70
- else {
71
- data = read ( url , "binary" ) ;
72
- }
73
- return Promise . resolve ( < Response > < any > {
74
- ok : ! ! data ,
75
- url : url ,
76
- arrayBuffer : ( ) => Promise . resolve ( new Uint8Array ( data ) ) ,
77
- json : ( ) => Promise . resolve ( JSON . parse ( ENVIRONMENT_IS_NODE ? data : read ( url ) ) )
78
- } ) ;
79
- }
80
- catch ( exc ) {
81
- return Promise . reject ( exc ) ;
82
- }
83
- } else {
84
- return Promise . reject ( Error ( "No fetch implementation available" ) ) ;
85
62
}
63
+ else if ( ENVIRONMENT_IS_NODE ) {
64
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
65
+ const fs = require ( "fs" ) ;
66
+ const arrayBuffer = await fs . readFileSync ( url ) ;
67
+ return < Response > < any > {
68
+ ok : true ,
69
+ url,
70
+ arrayBuffer : ( ) => arrayBuffer ,
71
+ json : ( ) => JSON . parse ( arrayBuffer )
72
+ } ;
73
+ }
74
+ else if ( typeof ( read ) === "function" ) {
75
+ return < Response > < any > {
76
+ ok : true ,
77
+ url,
78
+ arrayBuffer : ( ) => new Uint8Array ( read ( url , "binary" ) ) ,
79
+ json : ( ) => JSON . parse ( read ( url ) )
80
+ } ;
81
+ }
82
+ throw new Error ( "No fetch implementation available" ) ;
86
83
}
87
84
88
85
function _handle_fetched_asset ( ctx : MonoInitContext , asset : AssetEntry , url : string , blob : ArrayBuffer ) {
0 commit comments