Repository: nodejs/node
Pull request: esm: syncify default path of `ModuleLoader.load`

In https://github.com/nodejs/node/pull/57390 I somehow inadvertently created a branch on the node repo instead of my fork, and then got stuck.

Parent issue: https://github.com/nodejs/node/issues/55782

Changed files:
filename: lib/internal/modules/esm/load.js
patch: @@ -26,32 +26,7 @@ const {
 
 /**
  * @param {URL} url URL to the module
- * @param {ESModuleContext} context used to decorate error messages
- * @returns {Promise<{ responseURL: string, source: string | BufferView }>}
- */
-async function getSource(url, context) {
-  const { protocol, href } = url;
-  const responseURL = href;
-  let source;
-  if (protocol === 'file:') {
-    const { readFile: readFileAsync } = require('internal/fs/promises').exports;
-    source = await readFileAsync(url);
-  } else if (protocol === 'data:') {
-    const result = dataURLProcessor(url);
-    if (result === 'failure') {
-      throw new ERR_INVALID_URL(responseURL, null);
-    }
-    source = BufferFrom(result.body);
-  } else {
-    const supportedSchemes = ['file', 'data'];
-    throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(url, supportedSchemes);
-  }
-  return { __proto__: null, responseURL, source };
-}
-
-/**
- * @param {URL} url URL to the module
- * @param {ESModuleContext} context used to decorate error messages
+ * @param {LoadContext} context used to decorate error messages
  * @returns {{ responseURL: string, source: string | BufferView }}
  */
 function getSourceSync(url, context) {
@@ -80,7 +55,7 @@ function getSourceSync(url, context) {
  * @param {LoadContext} context
  * @returns {LoadReturn}
  */
-async function defaultLoad(url, context = kEmptyObject) {
+function defaultLoad(url, context = kEmptyObject) {
   let responseURL = url;
   let {
     importAttributes,
@@ -110,13 +85,13 @@ async function defaultLoad(url, context = kEmptyObject) {
     source = null;
   } else if (format !== 'commonjs') {
     if (source == null) {
-      ({ responseURL, source } = await getSource(urlInstance, context));
+      ({ responseURL, source } = getSourceSync(urlInstance, context));
       context = { __proto__: context, source };
     }
 
     if (format == null) {
       // Now that we have the source for the module, run `defaultGetFormat` to detect its format.
-      format = await defaultGetFormat(urlInstance, context);
+      format = defaultGetFormat(urlInstance, context);
 
       if (format === 'commonjs') {
         // For backward compatibility reasons, we need to discard the source in

filename: lib/internal/modules/esm/loader.js
patch: @@ -806,9 +806,9 @@ class ModuleLoader {
    * if any.
    * @param {string} url The URL of the module to be loaded.
    * @param {object} context Metadata about the module
-   * @returns {Promise<{ format: ModuleFormat, source: ModuleSource }>}
+   * @returns {Promise<{ format: ModuleFormat, source: ModuleSource }> | { format: ModuleFormat, source: ModuleSource }}
    */
-  async load(url, context) {
+  load(url, context) {
     if (loadHooks.length) {
       // Has module.registerHooks() hooks, use the synchronous variant that can handle both hooks.
       return this.#loadSync(url, context);

filename: lib/internal/modules/helpers.js
patch: @@ -264,7 +264,7 @@ function normalizeReferrerURL(referrerName) {
     }
 
     if (StringPrototypeStartsWith(referrerName, 'file://') ||
-        URLCanParse(referrerName)) {
+    URLCanParse(referrerName)) {
       return referrerName;
     }