@@ -13,41 +13,28 @@ import type { App, ESEngineModule } from 'esengine';
1313let currentLauncher : ProjectLauncher | null = null ;
1414let wasmModule : ESEngineModule | null = null ;
1515
16- function loadScript ( src : string ) : Promise < void > {
17- return new Promise ( ( resolve ) => {
16+ function loadWasmScript ( ) : Promise < void > {
17+ return new Promise ( ( resolve , reject ) => {
18+ if ( window . __ESEngineModule ) {
19+ resolve ( ) ;
20+ return ;
21+ }
22+
1823 const script = document . createElement ( 'script' ) ;
1924 script . type = 'module' ;
20- script . innerHTML = `
21- import createModule from '${ src } ';
22- window.__ESEngineModule = createModule;
23- window.dispatchEvent(new Event('esengine-loaded'));
24- ` ;
25+ script . src = '/wasm/wasm-loader.js' ;
26+ script . onerror = ( ) => reject ( new Error ( 'Failed to load WASM loader script' ) ) ;
2527 document . head . appendChild ( script ) ;
26- resolve ( ) ;
28+
29+ window . addEventListener ( 'esengine-loaded' , ( ) => resolve ( ) , { once : true } ) ;
2730 } ) ;
2831}
2932
3033async function loadWasmModule ( ) : Promise < ESEngineModule | null > {
3134 if ( wasmModule ) return wasmModule ;
3235
3336 try {
34- await loadScript ( '/wasm/esengine.js' ) ;
35-
36- await new Promise < void > ( ( resolve , reject ) => {
37- if ( window . __ESEngineModule ) {
38- resolve ( ) ;
39- return ;
40- }
41-
42- const timeout = setTimeout ( ( ) => {
43- reject ( new Error ( 'WASM module load timeout' ) ) ;
44- } , 10000 ) ;
45-
46- window . addEventListener ( 'esengine-loaded' , ( ) => {
47- clearTimeout ( timeout ) ;
48- resolve ( ) ;
49- } , { once : true } ) ;
50- } ) ;
37+ await loadWasmScript ( ) ;
5138
5239 const createModule = window . __ESEngineModule ;
5340 if ( typeof createModule !== 'function' ) {
@@ -92,6 +79,7 @@ async function init(): Promise<void> {
9279 fs : nativeFS ,
9380 invoke,
9481 shell : nativeShell ,
82+ esbuildWasmURL : '/esbuild.wasm' ,
9583 } ) ;
9684
9785 const container = document . getElementById ( 'editor-root' ) ;
0 commit comments