{"ast":null,"code":"function 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\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { consoleMessage, isServer } from '../utils';\nimport { defaultConfig } from './default-config';\nconst deepMergeObjects = ['backend', 'detection'];\n\nconst dedupe = names => names.filter((v, i) => names.indexOf(v) === i);\n\nconst STATIC_LOCALE_PATH = 'static/locales';\nexport const 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  const 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  const {\n    allLanguages,\n    defaultLanguage,\n    localeExtension,\n    localePath,\n    localeStructure\n  } = combinedConfig;\n\n  if (isServer()) {\n    const fs = eval(\"require('fs')\");\n\n    const path = require('path'); // eslint-disable-line @typescript-eslint/no-var-requires\n\n\n    const projectRoot = process.cwd();\n    let serverLocalePath = localePath;\n    /*\n        Validate defaultNS\n        https://github.com/isaachinman/next-i18next/issues/358\n    */\n\n    if (typeof combinedConfig.defaultNS === 'string') {\n      const defaultFile = `/${defaultLanguage}/${combinedConfig.defaultNS}.${localeExtension}`;\n      const defaultNSPath = path.join(projectRoot, localePath, defaultFile);\n      const 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        const staticDirPath = path.join(projectRoot, STATIC_LOCALE_PATH, defaultFile);\n        const 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 ${defaultNSPath}`);\n        }\n      }\n    }\n    /*\n        Set server side backend\n    */\n\n\n    combinedConfig.backend = {\n      loadPath: path.join(projectRoot, `${serverLocalePath}/${localeStructure}.${localeExtension}`),\n      addPath: path.join(projectRoot, `${serverLocalePath}/${localeStructure}.missing.${localeExtension}`)\n    };\n    /*\n        Set server side preload (languages and namespaces)\n    */\n\n    combinedConfig.preload = allLanguages;\n\n    if (!combinedConfig.ns) {\n      const getAllNamespaces = p => fs.readdirSync(p).map(file => file.replace(`.${localeExtension}`, ''));\n\n      combinedConfig.ns = getAllNamespaces(path.join(projectRoot, `${serverLocalePath}/${defaultLanguage}`));\n    }\n  } else {\n    let 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: `${process.env.PUBLIC_PATH}/${clientLocalePath}/${localeStructure}.${localeExtension}`,\n      addPath: `${process.env.PUBLIC_PATH}/${clientLocalePath}/${localeStructure}.missing.${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(obj => {\n    if (userConfig[obj]) {\n      combinedConfig[obj] = _objectSpread({}, defaultConfig[obj], {}, userConfig[obj]);\n    }\n  });\n  return combinedConfig;\n};","map":null,"metadata":{},"sourceType":"module"}