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

Code before:
      this.#reporterRunner.report({
        type: 'buildStart',
      });
      let {assetGraph, changedAssets} = await this.#assetGraphBuilder.build(
        signal,
      );
      dumpGraphToGraphViz(assetGraph, 'MainAssetGraph');

      // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
      let [
        bundleGraph,
        serializedBundleGraph,
      ] = await this.#bundlerRunner.bundle(assetGraph, {
        signal,
      });
      // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381 (Windows only)
      dumpGraphToGraphViz(bundleGraph._graph, 'BundleGraph');

      await this.#packagerRunner.writeBundles(
        bundleGraph,
        serializedBundleGraph,
      );
      assertSignalNotAborted(signal);

      let event = {
        type: 'buildSuccess',
        changedAssets: new Map(
          Array.from(changedAssets).map(([id, asset]) => [
            id,
            assetFromValue(asset, options),
          ]),
        ),
        bundleGraph: new BundleGraph(bundleGraph, NamedBundle.get, options),
        buildTime: Date.now() - startTime,
      };

      await this.#reporterRunner.report(event);

      await this.#assetGraphBuilder.validate();
      return event;
    } catch (e) {
      if (e instanceof BuildAbortError) {
        throw e;
      }

      let diagnostic = anyToDiagnostic(e);
      let event = {
        type: 'buildFailure',
        diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
      };


Review comment (suggestion):
Hmm this will be interesting once these are separate requests... I know you thought about using a WeakMap in the serializer. What was the reason for not going with that approach? Would also enable you to avoid passing the buffer around so many places in addition to the original object.

Code after:
    };
  }

  async _build({
    signal,
    startTime = Date.now(),
  }: {|
    signal?: AbortSignal,
    startTime?: number,
  |} = {}): Promise<BuildEvent> {
    let options = nullthrows(this.#resolvedOptions);
    try {
      if (options.profile) {
        await this.startProfiling();
      }
      this.#reporterRunner.report({
        type: 'buildStart',
      });
      let {assetGraph, changedAssets} = await this.#assetGraphBuilder.build(
        signal,
      );

      // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
      let [
        bundleGraph,
        serializedBundleGraph,
      ] = await this.#bundlerRunner.bundle(assetGraph, {
        signal,
      });
      // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381 (Windows only)
      dumpGraphToGraphViz(bundleGraph._graph, 'BundleGraph');

      await this.#packagerRunner.writeBundles(
        bundleGraph,
        serializedBundleGraph,
      );
      assertSignalNotAborted(signal);

      let event = {
        type: 'buildSuccess',
        changedAssets: new Map(
          Array.from(changedAssets).map(([id, asset]) => [
            id,
            assetFromValue(asset, options),
          ]),
        ),
        bundleGraph: new BundleGraph(bundleGraph, NamedBundle.get, options),
        buildTime: Date.now() - startTime,
      };

      await this.#reporterRunner.report(event);