Repository: storybookjs/storybook
File: code/core/src/core-server/build-static.ts (TypeScript)

Code before:
            .build({
              startTime,
              options: fullOptions,
            })
            .then(async (previewStats) => {
              logger.trace({ message: 'Preview built', time: process.hrtime(startTime) });

              const statsOption = options.webpackStatsJson || options.statsJson;
              if (statsOption) {
                const target = statsOption === true ? options.outputDir : statsOption;
                await outputStats(target, previewStats);
              }
            })
            .catch((error) => {
              logger.error('Failed to build the preview');
              process.exitCode = 1;
              throw error;
            }),
        ]),
    ...effects,
  ]);

  // Now the code has successfully built, we can count this as a 'dev' event.
  // NOTE: we don't send the 'build' event for test runs as we want to be as fast as possible.
  if (!core?.disableTelemetry && !options.test) {
    await initializedStoryIndexGenerator.then(async (generator) => {
      const storyIndex = await generator?.getIndex();
      const payload: any = {
        precedingUpgrade: await getPrecedingUpgrade(),
      };
      if (storyIndex) {
        Object.assign(payload, {
          storyIndex: summarizeIndex(storyIndex),
        });
      }

      await telemetry('build', payload, { configDir: options.configDir });
    });
  }

  logger.step(`Output directory: ${options.outputDir}`);
}


Review comment (performance):
@shilman are you ok with this change? I assume this wasn't awaited for a reason (likely performance reasons)

Code after:
            .build({
              startTime,
              options: fullOptions,
            })
            .then(async (previewStats) => {
              logger.trace({ message: 'Preview built', time: process.hrtime(startTime) });

              const statsOption = options.webpackStatsJson || options.statsJson;
              if (statsOption) {
                const target = statsOption === true ? options.outputDir : statsOption;
                await outputStats(target, previewStats);
              }
            })
            .catch((error) => {
              logger.error('Failed to build the preview');
              process.exitCode = 1;
              throw error;
            }),
        ]),
    ...effects,
  ]);

  // Now the code has successfully built, we can count this as a 'build' event.
  // NOTE: we don't send the 'build' event for test runs as we want to be as fast as possible.
  if (!core?.disableTelemetry && !options.test) {
    try {
      const generator = await initializedStoryIndexGenerator;
      const storyIndex = await generator?.getIndex();
      const payload: any = {
        precedingUpgrade: await getPrecedingUpgrade(),
      };
      if (storyIndex) {
        Object.assign(payload, {
          storyIndex: summarizeIndex(storyIndex),
        });
      }

      await telemetry('build', payload, { configDir: options.configDir });
    } catch (e) {
      // Telemetry failures should not fail the build process
      logger.debug?.(`Build telemetry failed: ${e instanceof Error ? e.message : String(e)}`);
    }
  }

  logger.step(`Output directory: ${options.outputDir}`);
}