File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -3,4 +3,7 @@ var require = require || undefined;
33let ENVIRONMENT_IS_GLOBAL = typeof globalThis . Module === "object" && globalThis . __dotnet_runtime === __dotnet_runtime ;
44if ( ENVIRONMENT_IS_GLOBAL ) {
55 createDotnetRuntime ( ( ) => { return globalThis . Module ; } ) . then ( ( exports ) => exports ) ;
6+ }
7+ else if ( typeof globalThis . __onDotnetRuntimeLoaded === "function" ) {
8+ globalThis . __onDotnetRuntimeLoaded ( createDotnetRuntime ) ;
69}
Original file line number Diff line number Diff line change @@ -160,8 +160,7 @@ loadDotnet("./dotnet.js").then((createDotnetRuntime) => {
160160 } ) )
161161} ) . catch ( function ( err ) {
162162 console . error ( err ) ;
163- set_exit_code ( 1 , "failed to load the dotnet.js file" ) ;
164- throw err ;
163+ set_exit_code ( 1 , "failed to load the dotnet.js file.\n" + err ) ;
165164} ) ;
166165
167166const App = {
@@ -361,10 +360,20 @@ async function loadDotnet(file) {
361360 return require ( file ) ;
362361 } ;
363362 } else if ( is_browser ) { // vanila JS in browser
364- loadScript = async function ( file ) {
365- globalThis . exports = { } ; // if we are loading cjs file
366- const createDotnetRuntime = await import ( file ) ;
367- return typeof createDotnetRuntime === "function" ? createDotnetRuntime : globalThis . exports . createDotnetRuntime ;
363+ loadScript = function ( file ) {
364+ var loaded = new Promise ( ( resolve , reject ) => {
365+ globalThis . __onDotnetRuntimeLoaded = ( createDotnetRuntime ) => {
366+ // this is callback we have in CJS version of the runtime
367+ resolve ( createDotnetRuntime ) ;
368+ } ;
369+ import ( file ) . then ( ( { default : createDotnetRuntime } ) => {
370+ // this would work with ES6 default export
371+ if ( createDotnetRuntime ) {
372+ resolve ( createDotnetRuntime ) ;
373+ }
374+ } , reject ) ;
375+ } ) ;
376+ return loaded ;
368377 }
369378 }
370379 else if ( typeof globalThis . load !== 'undefined' ) {
You can’t perform that action at this time.
0 commit comments