@@ -2341,53 +2341,54 @@ def modularize():
2341
2341
if settings .MINIMAL_RUNTIME and not settings .PTHREADS :
2342
2342
# Single threaded MINIMAL_RUNTIME programs do not need access to
2343
2343
# document.currentScript, so a simple export declaration is enough.
2344
- src = '/** @nocollapse */ var %s= %s' % (settings .EXPORT_NAME , src )
2344
+ src = '/** @nocollapse */ var %s = %s' % (settings .EXPORT_NAME , src )
2345
2345
else :
2346
2346
script_url_node = ''
2347
2347
# When MODULARIZE this JS may be executed later,
2348
2348
# after document.currentScript is gone, so we save it.
2349
- # In EXPORT_ES6 + PTHREADS the 'thread' is actually an ES6 module webworker running in strict mode,
2350
- # so doesn't have access to 'document'. In this case use 'import.meta' instead.
2349
+ # In EXPORT_ES6 + PTHREADS the 'thread' is actually an ES6 module
2350
+ # webworker running in strict mode, so doesn't have access to 'document'.
2351
+ # In this case use 'import.meta' instead.
2351
2352
if settings .EXPORT_ES6 and settings .USE_ES6_IMPORT_META :
2352
2353
script_url = 'import.meta.url'
2353
2354
else :
2354
2355
script_url = "typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined"
2355
2356
if shared .target_environment_may_be ('node' ):
2356
- script_url_node = "if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;"
2357
+ script_url_node = "if (typeof __filename !== 'undefined') _scriptDir ||= __filename;"
2357
2358
src = '''%(node_imports)s
2358
2359
var %(EXPORT_NAME)s = (() => {
2359
2360
var _scriptDir = %(script_url)s;
2360
2361
%(script_url_node)s
2361
2362
return (%(src)s);
2362
2363
})();
2363
- %(capture_module_function_for_audio_worklet)s;
2364
2364
''' % {
2365
2365
'node_imports' : node_es6_imports (),
2366
2366
'EXPORT_NAME' : settings .EXPORT_NAME ,
2367
2367
'script_url' : script_url ,
2368
2368
'script_url_node' : script_url_node ,
2369
2369
'src' : src ,
2370
- # Given the async nature of how the Module function and Module object come into existence in AudioWorkletGlobalScope,
2371
- # store the Module function under a different variable name so that AudioWorkletGlobalScope will be able to reference
2372
- # it without aliasing/conflicting with the Module variable name.
2373
- 'capture_module_function_for_audio_worklet' : 'globalThis.AudioWorkletModule = ' + settings .EXPORT_NAME if settings .AUDIO_WORKLET and settings .MODULARIZE else ''
2374
2370
}
2375
-
2376
- final_js += '.modular.js'
2377
- with open (final_js , 'w' , encoding = 'utf-8' ) as f :
2378
- f .write (src )
2379
-
2380
- # Export using a UMD style export, or ES6 exports if selected
2381
- if settings .EXPORT_ES6 :
2382
- f .write ('export default %s;' % settings .EXPORT_NAME )
2383
- elif not settings .MINIMAL_RUNTIME :
2384
- f .write ('''\
2371
+ # Given the async nature of how the Module function and Module object
2372
+ # come into existence in AudioWorkletGlobalScope, store the Module
2373
+ # function under a different variable name so that AudioWorkletGlobalScope
2374
+ # will be able to reference it without aliasing/conflicting with the
2375
+ # Module variable name.
2376
+ if settings .AUDIO_WORKLET and settings .MODULARIZE :
2377
+ src += f'globalThis.AudioWorkletModule = { settings .EXPORT_NAME } ;'
2378
+
2379
+ # Export using a UMD style export, or ES6 exports if selected
2380
+ if settings .EXPORT_ES6 :
2381
+ src += 'export default %s;' % settings .EXPORT_NAME
2382
+ elif not settings .MINIMAL_RUNTIME :
2383
+ src += '''\
2385
2384
if (typeof exports === 'object' && typeof module === 'object')
2386
2385
module.exports = %(EXPORT_NAME)s;
2387
2386
else if (typeof define === 'function' && define['amd'])
2388
2387
define([], () => %(EXPORT_NAME)s);
2389
- ''' % {'EXPORT_NAME' : settings .EXPORT_NAME })
2388
+ ''' % {'EXPORT_NAME' : settings .EXPORT_NAME }
2390
2389
2390
+ final_js += '.modular.js'
2391
+ write_file (final_js , src )
2391
2392
shared .get_temp_files ().note (final_js )
2392
2393
save_intermediate ('modularized' )
2393
2394
0 commit comments