scripts/build/esbuild-plugins/replace-module.mjs/setupOnLoadListener
function setupOnLoadListener(build, { concepts, replacements, processors }) {
  if (replacements.size === 0 && processors.size === 0) {
    return;
  }

  const processFunctionsForAllModules = processors.has("*")
    ? processors.get("*")
    : [];

  build.onLoad(concepts, async ({ path: file }) => {
    if (replacements.has(file)) {
      return replacements.get(file);
    }

    const processFunctions = [
      ...processFunctionsForAllModules,
      ...(processors.has(file) ? processors.get(file) : []),
    ];

    if (processFunctions.length === 0) {
      return;
    }

    const original = await fs.readFile(file, "utf8");

    let text = original;
    for (const process of processFunctions) {
      text = process(text);
    }

    // For files not JavaScript, we need add correct `loader` to the result,
    // We can simply return `undefined` to let esbuild process the file.
    if (original === text) {
      return;
    }

    return { contents: text };
  });
}