@@ -749,6 +749,11 @@ def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915
749
749
if s in user_settings :
750
750
diagnostics .warning ('deprecated' , f'{ s } is deprecated ({ reason } ). Please open a bug if you have a continuing need for this setting' )
751
751
752
+ # Set the EXPORT_ES6 default early since it affects the setting of the
753
+ # default oformat below.
754
+ if settings .WASM_ESM_INTEGRATION or settings .MODULARIZE == 'instance' :
755
+ default_setting ('EXPORT_ES6' , 1 )
756
+
752
757
# If no output format was specified we try to deduce the format based on
753
758
# the output filename extension
754
759
if not options .oformat and (options .relocatable or (options .shared and not settings .SIDE_MODULE )):
@@ -766,10 +771,10 @@ def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915
766
771
if not options .oformat :
767
772
if settings .SIDE_MODULE or final_suffix == '.wasm' :
768
773
options .oformat = OFormat .WASM
769
- elif final_suffix == '.mjs' :
770
- options .oformat = OFormat .MJS
771
774
elif final_suffix == '.html' :
772
775
options .oformat = OFormat .HTML
776
+ elif final_suffix == '.mjs' or settings .EXPORT_ES6 :
777
+ options .oformat = OFormat .MJS
773
778
else :
774
779
options .oformat = OFormat .JS
775
780
@@ -786,10 +791,11 @@ def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915
786
791
787
792
if settings .WASM_ESM_INTEGRATION :
788
793
diagnostics .warning ('experimental' , '-sWASM_ESM_INTEGRATION is still experimental and not yet supported in browsers' )
789
- default_setting ('EXPORT_ES6' , 1 )
790
794
default_setting ('MODULARIZE' , 'instance' )
791
- if not settings .EXPORT_ES6 or settings .MODULARIZE != 'instance' :
792
- exit_with_error ('WASM_ESM_INTEGRATION requires EXPORT_ES6 and MODULARIZE=instance' )
795
+ if options .oformat != OFormat .MJS :
796
+ exit_with_error ('WASM_ESM_INTEGRATION is only compatible with EM module output format' )
797
+ if settings .MODULARIZE != 'instance' :
798
+ exit_with_error ('WASM_ESM_INTEGRATION requires MODULARIZE=instance' )
793
799
if settings .RELOCATABLE :
794
800
exit_with_error ('WASM_ESM_INTEGRATION is not compatible with dynamic linking' )
795
801
@@ -806,11 +812,11 @@ def limit_incoming_module_api():
806
812
if settings .MODULARIZE == 'instance' :
807
813
diagnostics .warning ('experimental' , '-sMODULARIZE=instance is still experimental. Many features may not work or will change.' )
808
814
if options .oformat != OFormat .MJS :
809
- exit_with_error ('emcc: MODULARIZE instance is only compatible with .mjs output files ' )
815
+ exit_with_error ('MODULARIZE instance is only compatible with ES module output format ' )
810
816
limit_incoming_module_api ()
811
817
for s in ['wasmMemory' , 'INITIAL_MEMORY' ]:
812
818
if s in settings .INCOMING_MODULE_JS_API :
813
- exit_with_error (f'emcc: { s } cannot be in INCOMING_MODULE_JS_API in MODULARIZE=instance mode' )
819
+ exit_with_error (f'{ s } cannot be in INCOMING_MODULE_JS_API in MODULARIZE=instance mode' )
814
820
815
821
if options .oformat in (OFormat .WASM , OFormat .BARE ):
816
822
if options .emit_tsd :
@@ -826,7 +832,7 @@ def limit_incoming_module_api():
826
832
wasm_target = get_secondary_target (target , '.wasm' )
827
833
828
834
if settings .SAFE_HEAP not in [0 , 1 , 2 ]:
829
- exit_with_error ('emcc: SAFE_HEAP must be 0, 1 or 2' )
835
+ exit_with_error ('SAFE_HEAP must be 0, 1 or 2' )
830
836
831
837
if not settings .WASM :
832
838
# When the user requests non-wasm output, we enable wasm2js. that is,
@@ -2130,9 +2136,10 @@ def create_esm_wrapper(wrapper_file, support_target, wasm_target):
2130
2136
else :
2131
2137
wrapper .append (f"export {{ default }} from '{ support_url } ';" )
2132
2138
2133
- if settings .ENVIRONMENT_MAY_BE_NODE and settings . INVOKE_RUN and settings . EXPECT_MAIN :
2139
+ if settings .ENVIRONMENT_MAY_BE_NODE :
2134
2140
wrapper .append (f'''
2135
- // When run as the main module under node, execute main directly here
2141
+ // When run as the main module under node, create the module directly. This will
2142
+ // execute any startup code along with main (if it exists).
2136
2143
import init from '{ support_url } ';
2137
2144
const isNode = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string' && process.type != 'renderer';
2138
2145
if (isNode) {{
0 commit comments