@@ -2445,24 +2445,6 @@ def phase_binaryen(target, options, wasm_target):
2445
2445
write_file (final_js , js )
2446
2446
2447
2447
2448
- def node_pthread_detection ():
2449
- # Under node we detect that we are running in a pthread by checking the
2450
- # workerData property.
2451
- if settings .EXPORT_ES6 :
2452
- return "(await import('worker_threads')).workerData === 'em-pthread';\n "
2453
- else :
2454
- return "require('worker_threads').workerData === 'em-pthread'\n "
2455
-
2456
-
2457
- def node_ww_detection ():
2458
- # Under node we detect that we are running in a wasm worker by checking the
2459
- # workerData property.
2460
- if settings .EXPORT_ES6 :
2461
- return "(await import('worker_threads')).workerData === 'em-ww';\n "
2462
- else :
2463
- return "require('worker_threads').workerData === 'em-ww'\n "
2464
-
2465
-
2466
2448
def modularize ():
2467
2449
global final_js
2468
2450
logger .debug (f'Modularizing, assigning to var { settings .EXPORT_NAME } ' )
@@ -2513,60 +2495,7 @@ def modularize():
2513
2495
if settings .SOURCE_PHASE_IMPORTS :
2514
2496
src = f"import source wasmModule from './{ settings .WASM_BINARY_FILE } ';\n \n " + src
2515
2497
2516
- # Export using a UMD style export, or ES6 exports if selected
2517
- if settings .EXPORT_ES6 :
2518
- src += 'export default %s;\n ' % settings .EXPORT_NAME
2519
- elif not settings .MINIMAL_RUNTIME :
2520
- src += '''\
2521
- if (typeof exports === 'object' && typeof module === 'object') {
2522
- module.exports = %(EXPORT_NAME)s;
2523
- // This default export looks redundant, but it allows TS to import this
2524
- // commonjs style module.
2525
- module.exports.default = %(EXPORT_NAME)s;
2526
- } else if (typeof define === 'function' && define['amd'])
2527
- define([], () => %(EXPORT_NAME)s);
2528
- ''' % {'EXPORT_NAME' : settings .EXPORT_NAME }
2529
-
2530
- if settings .PTHREADS :
2531
- # Create code for detecting if we are running in a pthread.
2532
- # Normally this detection is done when the module is itself run but
2533
- # when running in MODULARIZE mode we need use this to know if we should
2534
- # run the module constructor on startup (true only for pthreads).
2535
- if settings .ENVIRONMENT_MAY_BE_WEB or settings .ENVIRONMENT_MAY_BE_WORKER :
2536
- src += "var isPthread = globalThis.self?.name?.startsWith('em-pthread');\n "
2537
- # In order to support both web and node we also need to detect node here.
2538
- if settings .ENVIRONMENT_MAY_BE_NODE :
2539
- src += f'var isNode = { node_detection_code ()} ;\n '
2540
- src += f'if (isNode) isPthread = { node_pthread_detection ()} \n '
2541
- elif settings .ENVIRONMENT_MAY_BE_NODE :
2542
- src += f'var isPthread = { node_pthread_detection ()} \n '
2543
- src += '// When running as a pthread, construct a new instance on startup\n '
2544
- if settings .MODULARIZE == 'instance' :
2545
- src += 'isPthread && init();\n '
2546
- else :
2547
- src += 'isPthread && %s();\n ' % settings .EXPORT_NAME
2548
-
2549
- if settings .WASM_WORKERS :
2550
- # Same as above for for WASM_WORKERS
2551
- # Normally this detection is done when the module is itself run but
2552
- # when running in MODULARIZE mode we need use this to know if we should
2553
- # run the module constructor on startup (true only for pthreads).
2554
- if settings .ENVIRONMENT_MAY_BE_WEB or settings .ENVIRONMENT_MAY_BE_WORKER :
2555
- src += "var isWW = globalThis.self?.name == 'em-ww';\n "
2556
- # In order to support both web and node we also need to detect node here.
2557
- if settings .ENVIRONMENT_MAY_BE_NODE :
2558
- if not settings .PTHREADS :
2559
- src += f'var isNode = { node_detection_code ()} ;\n '
2560
- src += f'if (isNode) isWW = { node_ww_detection ()} \n '
2561
- elif settings .ENVIRONMENT_MAY_BE_NODE :
2562
- src += f'var isWW = { node_ww_detection ()} \n '
2563
- if settings .AUDIO_WORKLET :
2564
- src += "isWW ||= typeof AudioWorkletGlobalScope !== 'undefined';\n "
2565
- src += '// When running as a wasm worker, construct a new instance on startup\n '
2566
- if settings .MODULARIZE == 'instance' :
2567
- src += 'isWW && init();\n '
2568
- else :
2569
- src += 'isWW && %s();\n ' % settings .EXPORT_NAME
2498
+ src += building .read_and_preprocess (utils .path_from_root ('src/modularize_suffix.js' ), expand_macros = True )
2570
2499
2571
2500
final_js += '.modular.js'
2572
2501
write_file (final_js , src )
0 commit comments