{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { consoleMessage, isServer } from '../utils';\nimport { defaultConfig } from './default-config';\nvar deepMergeObjects = ['backend', 'detection'];\n\nvar dedupe = function dedupe(names) {\n  return names.filter(function (v, i) {\n    return names.indexOf(v) === i;\n  });\n};\n\nvar STATIC_LOCALE_PATH = 'static/locales';\nexport var createConfig = function createConfig(userConfig) {\n  if (typeof userConfig.localeSubpaths === 'string') {\n    throw new Error('The localeSubpaths option has been changed to an object. Please refer to documentation.');\n  }\n  /*\n      Initial merge of default and user-provided config\n  */\n\n\n  var combinedConfig = _objectSpread({}, defaultConfig, {}, userConfig);\n  /*\n      Sensible defaults to prevent user duplication\n  */\n\n\n  combinedConfig.allLanguages = dedupe(combinedConfig.otherLanguages.concat([combinedConfig.defaultLanguage]));\n  combinedConfig.whitelist = combinedConfig.allLanguages;\n  var allLanguages = combinedConfig.allLanguages,\n      defaultLanguage = combinedConfig.defaultLanguage,\n      localeExtension = combinedConfig.localeExtension,\n      localePath = combinedConfig.localePath,\n      localeStructure = combinedConfig.localeStructure;\n\n  if (isServer()) {\n    var fs = eval(\"require('fs')\");\n\n    var path = require('path'); // eslint-disable-line @typescript-eslint/no-var-requires\n\n\n    var projectRoot = process.cwd();\n    var serverLocalePath = localePath;\n    /*\n        Validate defaultNS\n        https://github.com/isaachinman/next-i18next/issues/358\n    */\n\n    if (typeof combinedConfig.defaultNS === 'string') {\n      var defaultFile = \"/\".concat(defaultLanguage, \"/\").concat(combinedConfig.defaultNS, \".\").concat(localeExtension);\n      var defaultNSPath = path.join(projectRoot, localePath, defaultFile);\n      var defaultNSExists = fs.existsSync(defaultNSPath);\n\n      if (!defaultNSExists) {\n        /*\n            If defaultNS doesn't exist, try to fall back to the deprecated static folder\n            https://github.com/isaachinman/next-i18next/issues/523\n        */\n        var staticDirPath = path.join(projectRoot, STATIC_LOCALE_PATH, defaultFile);\n        var staticDirExists = fs.existsSync(staticDirPath);\n\n        if (staticDirExists) {\n          consoleMessage('warn', 'next-i18next: Falling back to /static folder, deprecated in next@9.1.*', combinedConfig);\n          serverLocalePath = STATIC_LOCALE_PATH;\n        } else if (false) {\n          throw new Error(\"Default namespace not found at \".concat(defaultNSPath));\n        }\n      }\n    }\n    /*\n        Set server side backend\n    */\n\n\n    combinedConfig.backend = {\n      loadPath: path.join(projectRoot, \"\".concat(serverLocalePath, \"/\").concat(localeStructure, \".\").concat(localeExtension)),\n      addPath: path.join(projectRoot, \"\".concat(serverLocalePath, \"/\").concat(localeStructure, \".missing.\").concat(localeExtension))\n    };\n    /*\n        Set server side preload (languages and namespaces)\n    */\n\n    combinedConfig.preload = allLanguages;\n\n    if (!combinedConfig.ns) {\n      var getAllNamespaces = function getAllNamespaces(p) {\n        return fs.readdirSync(p).map(function (file) {\n          return file.replace(\".\".concat(localeExtension), '');\n        });\n      };\n\n      combinedConfig.ns = getAllNamespaces(path.join(projectRoot, \"\".concat(serverLocalePath, \"/\").concat(defaultLanguage)));\n    }\n  } else {\n    var clientLocalePath = localePath;\n    /*\n        Remove public prefix from client site config\n    */\n\n    if (localePath.startsWith('public/')) {\n      clientLocalePath = localePath.replace(/^public\\//, '');\n    }\n    /*\n        Set client side backend\n    */\n\n\n    combinedConfig.backend = {\n      loadPath: \"\".concat(process.env.PUBLIC_PATH, \"/\").concat(clientLocalePath, \"/\").concat(localeStructure, \".\").concat(localeExtension),\n      addPath: \"\".concat(process.env.PUBLIC_PATH, \"/\").concat(clientLocalePath, \"/\").concat(localeStructure, \".missing.\").concat(localeExtension)\n    };\n    combinedConfig.ns = [combinedConfig.defaultNS];\n  }\n  /*\n      Set fallback language to defaultLanguage in production\n  */\n\n\n  if (!userConfig.fallbackLng) {\n    combinedConfig.fallbackLng = true ? combinedConfig.defaultLanguage : false;\n  }\n  /*\n      Deep merge with overwrite - goes last\n  */\n\n\n  deepMergeObjects.forEach(function (obj) {\n    if (userConfig[obj]) {\n      combinedConfig[obj] = _objectSpread({}, defaultConfig[obj], {}, userConfig[obj]);\n    }\n  });\n  return combinedConfig;\n};","map":null,"metadata":{},"sourceType":"module"}