"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.normalizeConfig = normalizeConfig;
function normalizeDevServerHost(host) {
  switch (host) {
    case 'local-ip':
      return 'localhost';
    case 'local-ipv4':
      return '127.0.0.1';
    case 'local-ipv6':
      return '::1';
    default:
      return host;
  }
}
function normalizeOutputPath(outputPath, context, platform) {
  return outputPath.replaceAll('[context]', context).replaceAll('[platform]', platform);
}
function normalizeResolveExtensions(extensions, platform) {
  return extensions.map(ext => ext.replaceAll('[platform]', platform));
}
function normalizeConfig(config, platform) {
  /* normalize compiler name to be equal to platform */
  config.name = platform;

  /* normalize dev server host by resolving special values */
  if (config.devServer) {
    config.devServer.host = normalizeDevServerHost(config.devServer.host);
  }

  /* normalize output path by resolving [platform] & [context] placeholders */
  if (config.output?.path) {
    config.output.path = normalizeOutputPath(config.output.path, config.context ?? process.cwd(), config.name);
  }

  /* unset public path if it's using the deprecated `getPublicPath` function */
  if (config.output?.publicPath === 'DEPRECATED_GET_PUBLIC_PATH') {
    config.output.publicPath = undefined;
  }

  /* normalize resolve extensions by resolving [platform] placeholder */
  if (config.resolve?.extensions) {
    config.resolve.extensions = normalizeResolveExtensions(config.resolve.extensions, config.name);
  }

  /* return the normalized config object */
  return config;
}
//# sourceMappingURL=normalizeConfig.js.map