Repository: parcel-bundler/parcel
File: packages/core/core/src/PackagerRunner.js (JavaScript)

Code before:
          pluginConfigs.set(plugin.name, config);
          configs.set(plugin.name, config);
        }
      }
    }

    let loadGlobalInfo = plugin.plugin.loadGlobalInfo;
    if (!globalInfos.has(plugin.name) && loadGlobalInfo != null) {
      let config = createConfig({
        plugin: plugin.name,
        searchPath: toProjectPathUnsafe('index'),
      });
      config.result = await loadGlobalInfo({
        bundle: NamedBundle.get(bundle, bundleGraph, this.options),
        bundleGraph: new BundleGraph<NamedBundleType>(
          bundleGraph,
          NamedBundle.get.bind(NamedBundle),
          this.options,
        ),
        options: new PluginOptions(this.options),
        logger: new PluginLogger({origin: plugin.name}),
      });
      // TODO expose config and let plugin set key?
      config.cacheKey = hashString(JSON.stringify(config.result) ?? '');
      globalInfos.set(plugin.name, config);
    }
  }

  async getBundleInfoFromCache(
    bundleGraph: InternalBundleGraph,
    bundle: InternalBundle,
    configs: Map<string, Config>,
    globalInfos: Map<string, Config>,
  ): Async<?BundleInfo> {
    if (this.options.shouldDisableCache) {
      return;
    }

    let cacheKey = await this.getCacheKey(
      bundle,
      bundleGraph,
      configs,
      globalInfos,
      this.previousInvalidations,
    );
    let infoKey = PackagerRunner.getInfoKey(cacheKey);
    return this.options.cache.get<BundleInfo>(infoKey);
  }

  async getBundleInfo(
    bundle: InternalBundle,

Review comment (performance):
Should this new method also receive a `config` object (currently it doesn't)? Currently the cache key logic for the config is a bit counterintuitive, especially for this new usecase:

https://github.com/parcel-bundler/parcel/blob/9e5d05586577e89991ccf90400f2c741dca11aa3/packages/core/core/src/requests/ConfigRequest.js#L136-L165

But there would ideally still be some way to pass non-serializable data here.

Code after:

          pluginConfigs.set(plugin.name, config);
          configs.set(plugin.name, config);
        }
      }
    }

    let loadBundleConfig = plugin.plugin.loadBundleConfig;
    if (!bundleConfigs.has(plugin.name) && loadBundleConfig != null) {
      let config = createConfig({
        plugin: plugin.name,
        searchPath: joinProjectPath(
          bundle.target.distDir,
          bundle.name ?? bundle.id,
        ),
      });
      config.result = await loadBundleConfig({
        bundle: NamedBundle.get(bundle, bundleGraph, this.options),
        bundleGraph: new BundleGraph<NamedBundleType>(
          bundleGraph,
          NamedBundle.get.bind(NamedBundle),
          this.options,
        ),
        config: new PublicConfig(config, this.options),
        options: new PluginOptions(this.options),
        logger: new PluginLogger({origin: plugin.name}),
      });
      bundleConfigs.set(plugin.name, config);
    }
  }

  async getBundleInfoFromCache(
    bundleGraph: InternalBundleGraph,
    bundle: InternalBundle,
    configs: Map<string, Config>,
    bundleConfigs: Map<string, Config>,
  ): Async<?BundleInfo> {
    if (this.options.shouldDisableCache) {
      return;
    }

    let cacheKey = await this.getCacheKey(
      bundle,
      bundleGraph,
      configs,
      bundleConfigs,
      this.previousInvalidations,
    );
    let infoKey = PackagerRunner.getInfoKey(cacheKey);
    return this.options.cache.get<BundleInfo>(infoKey);
  }