@@ -53,7 +53,9 @@ let defaultConditions;
5353 * @returns {object }
5454 */
5555function getDefaultConditions ( ) {
56- assert ( defaultConditions !== undefined ) ;
56+ if ( defaultConditions === undefined ) {
57+ initializeDefaultConditions ( ) ;
58+ }
5759 return defaultConditions ;
5860}
5961
@@ -64,7 +66,9 @@ let defaultConditionsSet;
6466 * @returns {Set<any> }
6567 */
6668function getDefaultConditionsSet ( ) {
67- assert ( defaultConditionsSet !== undefined ) ;
69+ if ( defaultConditionsSet === undefined ) {
70+ initializeDefaultConditions ( ) ;
71+ }
6872 return defaultConditionsSet ;
6973}
7074
@@ -74,18 +78,27 @@ function getDefaultConditionsSet() {
7478 * @returns {void }
7579 */
7680function initializeDefaultConditions ( ) {
81+ if ( defaultConditions !== undefined ) {
82+ return ;
83+ }
7784 const userConditions = getOptionValue ( '--conditions' ) ;
7885 const noAddons = getOptionValue ( '--no-addons' ) ;
79- const addonConditions = noAddons ? [ ] : [ 'node-addons' ] ;
80- const moduleConditions = getOptionValue ( '--require-module' ) ? [ 'module-sync' ] : [ ] ;
81- defaultConditions = ObjectFreeze ( [
82- 'node' ,
83- 'import' ,
84- ...moduleConditions ,
85- ...addonConditions ,
86- ...userConditions ,
87- ] ) ;
88- defaultConditionsSet = new SafeSet ( defaultConditions ) ;
86+ const conditions = [ 'node' , 'import' ] ;
87+ if ( getOptionValue ( '--require-module' ) ) {
88+ conditions [ conditions . length ] = 'module-sync' ;
89+ }
90+ if ( ! noAddons ) {
91+ conditions [ conditions . length ] = 'node-addons' ;
92+ }
93+ for ( let i = 0 ; i < userConditions . length ; i ++ ) {
94+ conditions [ conditions . length ] = userConditions [ i ] ;
95+ }
96+ defaultConditions = ObjectFreeze ( conditions ) ;
97+ const set = new SafeSet ( ) ;
98+ for ( let i = 0 ; i < defaultConditions . length ; i ++ ) {
99+ set . add ( defaultConditions [ i ] ) ;
100+ }
101+ defaultConditionsSet = set ;
89102}
90103
91104/**
@@ -295,12 +308,17 @@ async function importModuleDynamicallyCallback(referrerSymbol, specifier, phase,
295308}
296309
297310let _shouldSpawnLoaderHookWorker = true ;
311+ let esmInitialized = false ;
298312/**
299313 * Initializes handling of ES modules.
300314 * @param {boolean } [shouldSpawnLoaderHookWorker] Whether the custom loader worker
301315 * should be spawned later.
302316 */
303317function initializeESM ( shouldSpawnLoaderHookWorker = true ) {
318+ if ( esmInitialized ) {
319+ return ;
320+ }
321+ esmInitialized = true ;
304322 _shouldSpawnLoaderHookWorker = shouldSpawnLoaderHookWorker ;
305323 initializeDefaultConditions ( ) ;
306324 // Setup per-realm callbacks that locate data or callbacks that we keep
@@ -391,6 +409,8 @@ module.exports = {
391409 embedder_module_hdo,
392410 registerModule,
393411 initializeESM,
412+ initializeImportMetaObject,
413+ importModuleDynamicallyCallback,
394414 getDefaultConditions,
395415 getConditionsSet,
396416 shouldSpawnLoaderHookWorker,
0 commit comments