text: "use strict";
  var __importDefault = (this && this.__importDefault) || function (mod) {
      return (mod && mod.__esModule) ? mod : { "default": mod };
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.extractAssets = void 0;
  const get_1 = __importDefault(require("lodash/get"));
  const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
  const utils_1 = require("../utils");
  const IGNORE_PATTERN = /\.(map|LICENSE\.txt)$/;
  const extractAssets = (webpackStats) => {
      const webpackAssets = get_1.default(webpackStats, 'assets', []);
      const webpackChunks = get_1.default(webpackStats, 'chunks', []);
      const webpackEntrypoints = get_1.default(webpackStats, 'entrypoints', {});
      const entryItems = Object.values(webpackEntrypoints)
          .map(({ assets: items }) => items)
          .flat();
      const initialItems = webpackChunks
          .filter(({ initial }) => initial)
          .map(({ files }) => files)
          .flat();
      const normalizedChunks = webpackChunks.map(({ id, names, files }) => ({
          id: id.toString(),
          name: names.join('+') || `chunk-${id}`,
          files,
      }));
      const assets = webpackAssets.reduce((aggregator, asset) => {
          const baseName = asset === null || asset === void 0 ? void 0 : asset.name.split('?')[0];
          if (IGNORE_PATTERN.test(baseName)) {
              return aggregator;
          }
          const assetChunk = normalizedChunks.find((chunk) => chunk.files.includes(asset.name));
          const normalizedName = utils_1.getAssetName(baseName);
          const { size, name } = asset;
          return {
              ...aggregator,
              [normalizedName]: {
                  name: baseName,
                  value: size,
                  isEntry: entryItems.includes(name),
                  isInitial: initialItems.includes(name),
                  isChunk: Boolean(assetChunk),
                  ...(assetChunk ? { chunkId: assetChunk.id } : {}),
              },
          };
      }, {});
      return {
          metrics: {
              assets,
          },
          ...(!isEmpty_1.default(normalizedChunks)
              ? {
                  meta: {
                      chunks: normalizedChunks.map(({ id, name }) => ({ id, name })),
                  },
              }
              : {}),
      };
  };
  exports.extractAssets = extractAssets;
  //# sourceMappingURL=assets.js.map