@@ -48,6 +48,7 @@ const {
4848} = require ( 'internal/modules/helpers' ) ;
4949
5050let defaultConditions ;
51+ let seaBinding ;
5152/**
5253 * Returns the default conditions for ES module loading.
5354 * @returns {object }
@@ -68,6 +69,10 @@ function getDefaultConditionsSet() {
6869 return defaultConditionsSet ;
6970}
7071
72+ function getSeaBinding ( ) {
73+ return seaBinding ??= internalBinding ( 'sea' ) ;
74+ }
75+
7176/**
7277 * Initializes the default conditions for ESM module loading.
7378 * This function is called during pre-execution, before any user code is run.
@@ -238,15 +243,25 @@ function getBuiltinModuleWrapForEmbedder(specifier) {
238243}
239244
240245/**
241- * Get the built-in module dynamically for embedder ESM.
246+ * Handle dynamic import for embedder entry points.
247+ * SEA can opt into the default loader via explicit configuration; other embedder
248+ * entry points continue to be limited to built-in modules.
242249 * @param {string } specifier - The module specifier string.
243- * @param {number } phase - The module import phase. Ignored for now.
244- * @param {Record<string, string> } attributes - The import attributes object. Ignored for now.
250+ * @param {number } phase - The module import phase.
251+ * @param {Record<string, string> } attributes - The import attributes object.
245252 * @param {string|null|undefined } referrerName - name of the referrer.
246- * @returns {import('internal/modules/esm/loader.js').ModuleExports } - The imported module object.
253+ * @returns {Promise< import('internal/modules/esm/loader.js').ModuleExports> } - The imported module object.
247254 */
248255function importModuleDynamicallyForEmbedder ( specifier , phase , attributes , referrerName ) {
249- // Ignore phase and attributes for embedder ESM for now, because this only supports loading builtins.
256+ const { isSeaDynamicImportFromFileSystemEnabled } = getSeaBinding ( ) ;
257+ if ( isSeaDynamicImportFromFileSystemEnabled ( ) ) {
258+ return defaultImportModuleDynamicallyForScript (
259+ specifier ,
260+ phase ,
261+ attributes ,
262+ referrerName ,
263+ ) ;
264+ }
250265 return getBuiltinModuleWrapForEmbedder ( specifier ) . getNamespace ( ) ;
251266}
252267
@@ -277,7 +292,7 @@ async function importModuleDynamicallyCallback(referrerSymbol, specifier, phase,
277292 if ( referrerSymbol === source_text_module_default_hdo ) {
278293 return defaultImportModuleDynamicallyForModule ( specifier , phase , attributes , referrerName ) ;
279294 }
280- // For embedder entry point ESM, only allow built-in modules .
295+ // For embedder entry points, proxy dynamic import to the default loader .
281296 if ( referrerSymbol === embedder_module_hdo ) {
282297 return importModuleDynamicallyForEmbedder ( specifier , phase , attributes , referrerName ) ;
283298 }
0 commit comments