next-intlayer 9.3.3 → 9.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/README.md +4 -1
  2. package/dist/cjs/client/IntlayerClientProvider.cjs +18 -14
  3. package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -1
  4. package/dist/cjs/index.cjs +18 -0
  5. package/dist/cjs/index.cjs.map +1 -1
  6. package/dist/cjs/rsc/index.cjs +96 -0
  7. package/dist/cjs/server/IntlayerProvider.cjs +54 -0
  8. package/dist/cjs/server/IntlayerProvider.cjs.map +1 -0
  9. package/dist/cjs/server/IntlayerServerProvider.cjs +29 -0
  10. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -0
  11. package/dist/cjs/server/ambientLocale.cjs +64 -0
  12. package/dist/cjs/server/ambientLocale.cjs.map +1 -0
  13. package/dist/cjs/server/format/index.cjs +17 -7
  14. package/dist/cjs/server/format/useCompact.cjs +26 -0
  15. package/dist/cjs/server/format/useCompact.cjs.map +1 -0
  16. package/dist/cjs/server/format/useCurrency.cjs +26 -0
  17. package/dist/cjs/server/format/useCurrency.cjs.map +1 -0
  18. package/dist/cjs/server/format/useDate.cjs +33 -0
  19. package/dist/cjs/server/format/useDate.cjs.map +1 -0
  20. package/dist/cjs/server/format/useList.cjs +26 -0
  21. package/dist/cjs/server/format/useList.cjs.map +1 -0
  22. package/dist/cjs/server/format/useNumber.cjs +26 -0
  23. package/dist/cjs/server/format/useNumber.cjs.map +1 -0
  24. package/dist/cjs/server/format/usePercentage.cjs +26 -0
  25. package/dist/cjs/server/format/usePercentage.cjs.map +1 -0
  26. package/dist/cjs/server/format/useRelativeTime.cjs +26 -0
  27. package/dist/cjs/server/format/useRelativeTime.cjs.map +1 -0
  28. package/dist/cjs/server/format/useUnit.cjs +26 -0
  29. package/dist/cjs/server/format/useUnit.cjs.map +1 -0
  30. package/dist/cjs/server/index.cjs +27 -43
  31. package/dist/cjs/server/prepareSwcOptimization.cjs +1 -1
  32. package/dist/cjs/server/prepareSwcOptimization.cjs.map +1 -1
  33. package/dist/cjs/server/suspendingReader.cjs +45 -0
  34. package/dist/cjs/server/suspendingReader.cjs.map +1 -0
  35. package/dist/cjs/server/t.cjs +16 -0
  36. package/dist/cjs/server/t.cjs.map +1 -0
  37. package/dist/cjs/server/useDictionary.cjs +5 -4
  38. package/dist/cjs/server/useDictionary.cjs.map +1 -1
  39. package/dist/cjs/server/useDictionaryAsync.cjs +5 -7
  40. package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
  41. package/dist/cjs/server/useDictionaryDynamic.cjs +5 -4
  42. package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
  43. package/dist/cjs/server/useI18n.cjs +17 -0
  44. package/dist/cjs/server/useI18n.cjs.map +1 -0
  45. package/dist/cjs/server/useIntl.cjs +16 -0
  46. package/dist/cjs/server/useIntl.cjs.map +1 -0
  47. package/dist/cjs/server/useIntlayer.cjs +5 -20
  48. package/dist/cjs/server/useIntlayer.cjs.map +1 -1
  49. package/dist/cjs/server/useLocale.cjs +26 -0
  50. package/dist/cjs/server/useLocale.cjs.map +1 -0
  51. package/dist/cjs/server/withIntlayer.cjs +2 -3
  52. package/dist/cjs/server/withIntlayer.cjs.map +1 -1
  53. package/dist/esm/client/IntlayerClientProvider.mjs +18 -15
  54. package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
  55. package/dist/esm/index.mjs +2 -2
  56. package/dist/esm/index.mjs.map +1 -1
  57. package/dist/esm/rsc/index.mjs +18 -0
  58. package/dist/esm/server/IntlayerProvider.mjs +53 -0
  59. package/dist/esm/server/IntlayerProvider.mjs.map +1 -0
  60. package/dist/esm/server/IntlayerServerProvider.mjs +28 -0
  61. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -0
  62. package/dist/esm/server/ambientLocale.mjs +61 -0
  63. package/dist/esm/server/ambientLocale.mjs.map +1 -0
  64. package/dist/esm/server/format/index.mjs +10 -1
  65. package/dist/esm/server/format/useCompact.mjs +25 -0
  66. package/dist/esm/server/format/useCompact.mjs.map +1 -0
  67. package/dist/esm/server/format/useCurrency.mjs +25 -0
  68. package/dist/esm/server/format/useCurrency.mjs.map +1 -0
  69. package/dist/esm/server/format/useDate.mjs +32 -0
  70. package/dist/esm/server/format/useDate.mjs.map +1 -0
  71. package/dist/esm/server/format/useList.mjs +25 -0
  72. package/dist/esm/server/format/useList.mjs.map +1 -0
  73. package/dist/esm/server/format/useNumber.mjs +25 -0
  74. package/dist/esm/server/format/useNumber.mjs.map +1 -0
  75. package/dist/esm/server/format/usePercentage.mjs +25 -0
  76. package/dist/esm/server/format/usePercentage.mjs.map +1 -0
  77. package/dist/esm/server/format/useRelativeTime.mjs +25 -0
  78. package/dist/esm/server/format/useRelativeTime.mjs.map +1 -0
  79. package/dist/esm/server/format/useUnit.mjs +25 -0
  80. package/dist/esm/server/format/useUnit.mjs.map +1 -0
  81. package/dist/esm/server/index.mjs +12 -2
  82. package/dist/esm/server/prepareSwcOptimization.mjs +1 -1
  83. package/dist/esm/server/prepareSwcOptimization.mjs.map +1 -1
  84. package/dist/esm/server/suspendingReader.mjs +42 -0
  85. package/dist/esm/server/suspendingReader.mjs.map +1 -0
  86. package/dist/esm/server/t.mjs +15 -0
  87. package/dist/esm/server/t.mjs.map +1 -0
  88. package/dist/esm/server/useDictionary.mjs +5 -4
  89. package/dist/esm/server/useDictionary.mjs.map +1 -1
  90. package/dist/esm/server/useDictionaryAsync.mjs +5 -7
  91. package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
  92. package/dist/esm/server/useDictionaryDynamic.mjs +5 -4
  93. package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
  94. package/dist/esm/server/useI18n.mjs +16 -0
  95. package/dist/esm/server/useI18n.mjs.map +1 -0
  96. package/dist/esm/server/useIntl.mjs +15 -0
  97. package/dist/esm/server/useIntl.mjs.map +1 -0
  98. package/dist/esm/server/useIntlayer.mjs +6 -18
  99. package/dist/esm/server/useIntlayer.mjs.map +1 -1
  100. package/dist/esm/server/useLocale.mjs +25 -0
  101. package/dist/esm/server/useLocale.mjs.map +1 -0
  102. package/dist/esm/server/withIntlayer.mjs +2 -3
  103. package/dist/esm/server/withIntlayer.mjs.map +1 -1
  104. package/dist/types/@intlayer/babel/dist/types/babel-plugin-intlayer-purge.d.ts +2 -2
  105. package/dist/types/@intlayer/babel/dist/types/babel-plugin-intlayer-usage-analyzer.d.ts +2 -2
  106. package/dist/types/@intlayer/babel/dist/types/extractContent/contentWriter.d.ts +2 -2
  107. package/dist/types/@intlayer/babel/dist/types/getOptimizePluginOptions.d.ts +2 -2
  108. package/dist/types/@intlayer/babel/dist/types/getPurgePluginOptions.d.ts +2 -2
  109. package/dist/types/client/IntlayerClientProvider.d.ts +20 -14
  110. package/dist/types/client/IntlayerClientProvider.d.ts.map +1 -1
  111. package/dist/types/index.d.ts +2 -2
  112. package/dist/types/index.d.ts.map +1 -1
  113. package/dist/types/rsc/index.d.ts +19 -0
  114. package/dist/types/server/IntlayerProvider.d.ts +43 -0
  115. package/dist/types/server/IntlayerProvider.d.ts.map +1 -0
  116. package/dist/types/server/IntlayerServerProvider.d.ts +30 -0
  117. package/dist/types/server/IntlayerServerProvider.d.ts.map +1 -0
  118. package/dist/types/server/ambientLocale.d.ts +34 -0
  119. package/dist/types/server/ambientLocale.d.ts.map +1 -0
  120. package/dist/types/server/format/index.d.ts +9 -1
  121. package/dist/types/server/format/useCompact.d.ts +16 -0
  122. package/dist/types/server/format/useCompact.d.ts.map +1 -0
  123. package/dist/types/server/format/useCurrency.d.ts +16 -0
  124. package/dist/types/server/format/useCurrency.d.ts.map +1 -0
  125. package/dist/types/server/format/useDate.d.ts +20 -0
  126. package/dist/types/server/format/useDate.d.ts.map +1 -0
  127. package/dist/types/server/format/useList.d.ts +16 -0
  128. package/dist/types/server/format/useList.d.ts.map +1 -0
  129. package/dist/types/server/format/useNumber.d.ts +16 -0
  130. package/dist/types/server/format/useNumber.d.ts.map +1 -0
  131. package/dist/types/server/format/usePercentage.d.ts +16 -0
  132. package/dist/types/server/format/usePercentage.d.ts.map +1 -0
  133. package/dist/types/server/format/useRelativeTime.d.ts +16 -0
  134. package/dist/types/server/format/useRelativeTime.d.ts.map +1 -0
  135. package/dist/types/server/format/useUnit.d.ts +16 -0
  136. package/dist/types/server/format/useUnit.d.ts.map +1 -0
  137. package/dist/types/server/index.d.ts +12 -2
  138. package/dist/types/server/prepareSwcOptimization.d.ts +1 -1
  139. package/dist/types/server/prepareSwcOptimization.d.ts.map +1 -1
  140. package/dist/types/server/suspendingReader.d.ts +22 -0
  141. package/dist/types/server/suspendingReader.d.ts.map +1 -0
  142. package/dist/types/server/t.d.ts +13 -0
  143. package/dist/types/server/t.d.ts.map +1 -0
  144. package/dist/types/server/useDictionary.d.ts +2 -1
  145. package/dist/types/server/useDictionary.d.ts.map +1 -1
  146. package/dist/types/server/useDictionaryAsync.d.ts +5 -4
  147. package/dist/types/server/useDictionaryAsync.d.ts.map +1 -1
  148. package/dist/types/server/useDictionaryDynamic.d.ts +3 -2
  149. package/dist/types/server/useDictionaryDynamic.d.ts.map +1 -1
  150. package/dist/types/server/useI18n.d.ts +14 -0
  151. package/dist/types/server/useI18n.d.ts.map +1 -0
  152. package/dist/types/server/useIntl.d.ts +13 -0
  153. package/dist/types/server/useIntl.d.ts.map +1 -0
  154. package/dist/types/server/useIntlayer.d.ts +4 -5
  155. package/dist/types/server/useIntlayer.d.ts.map +1 -1
  156. package/dist/types/server/useLocale.d.ts +20 -0
  157. package/dist/types/server/useLocale.d.ts.map +1 -0
  158. package/package.json +14 -9
@@ -3,11 +3,11 @@ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
3
  const require_server_prepareSwcOptimization = require('./prepareSwcOptimization.cjs');
4
4
  const require_server_swcPluginCompatibility = require('./swcPluginCompatibility.cjs');
5
5
  let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
6
- let _intlayer_config_logger = require("@intlayer/config/logger");
7
6
  let node_path = require("node:path");
8
7
  let _intlayer_config_colors = require("@intlayer/config/colors");
9
8
  _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
10
9
  let _intlayer_config_envVars = require("@intlayer/config/envVars");
10
+ let _intlayer_config_logger = require("@intlayer/config/logger");
11
11
  let _intlayer_config_node = require("@intlayer/config/node");
12
12
  let _intlayer_config_utils = require("@intlayer/config/utils");
13
13
  let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
@@ -67,7 +67,6 @@ const resolvePluginPath = (pluginPath, intlayerConfig, isTurbopackEnabled) => {
67
67
  };
68
68
  const getPruneConfig = ({ intlayerConfig, isBuildCommand, isTurbopackEnabled, isDevCommand, isGteNext13, isSwcPluginSupported, nextVersion, swcExtraCallers, fieldRenameMap }) => {
69
69
  const { optimize, minify, purge } = intlayerConfig.build;
70
- const editorEnabled = intlayerConfig.editor.enabled;
71
70
  const importMode = intlayerConfig.build.importMode ?? intlayerConfig.dictionary?.importMode;
72
71
  const { dictionariesDir, unmergedDictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, mainDir } = intlayerConfig.system;
73
72
  const { baseDir } = intlayerConfig.system;
@@ -92,7 +91,7 @@ const getPruneConfig = ({ intlayerConfig, isBuildCommand, isTurbopackEnabled, is
92
91
  (0, _intlayer_config_logger.colorize)(importMode ?? _intlayer_config_defaultValues.IMPORT_MODE, _intlayer_config_colors.BLUE),
93
92
  (0, _intlayer_config_logger.colorize)(`)`, _intlayer_config_colors.GREY_DARK)
94
93
  ]);
95
- const isPurgePipelineEnabled = !editorEnabled && !swcExtraCallers?.length && require_server_prepareSwcOptimization.getIsPurgePipelineAvailable(intlayerConfig);
94
+ const isPurgePipelineEnabled = !swcExtraCallers?.length && require_server_prepareSwcOptimization.getIsPurgePipelineAvailable(intlayerConfig);
96
95
  if (isPurgePipelineEnabled && minify) logger(`Dictionary minification ${(0, _intlayer_config_logger.colorize)("enabled", _intlayer_config_colors.GREEN)}`);
97
96
  if (isPurgePipelineEnabled && purge) logger(`Dictionary purge unused keys ${(0, _intlayer_config_logger.colorize)("enabled", _intlayer_config_colors.GREEN)}`);
98
97
  } else logger([
@@ -1 +1 @@
1
- {"version":3,"file":"withIntlayer.cjs","names":["nextPackageJSON","getProjectRequire","compareVersions","getIsSwcPluginSupported","normalizePath","relative","getAppLogger","join","colorize","ANSIColors","MINIMUM_SWC_PLUGIN_NEXT_VERSION","IMPORT_MODE","getIsPurgePipelineAvailable","buildComponentFilesList","getDictionaries","getNestedDictionaryGraph","resolveSwcLogLevel","getConfiguration","getAlias","getUnusedNodeTypes","formatNodeTypeToEnvVar","formatOptimizedNestingEnvVar","formatDictionarySelectorEnvVar","getHasDictionarySelector","getConfigEnvVars","resolve","IntlayerPlugin","prepareIntlayer","prepareSwcOptimization"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport type { SwcExtraCallerConfig } from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { IMPORT_MODE } from '@intlayer/config/defaultValues';\nimport {\n formatDictionarySelectorEnvVar,\n formatNodeTypeToEnvVar,\n formatOptimizedNestingEnvVar,\n getConfigEnvVars,\n} from '@intlayer/config/envVars';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n compareVersions,\n getAlias,\n getHasDictionarySelector,\n getProjectRequire,\n getUnusedNodeTypes,\n normalizePath,\n} from '@intlayer/config/utils';\nimport { getNestedDictionaryGraph } from '@intlayer/core/dictionaryManipulator';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { logConfigDetails } from '@intlayer/engine/cli';\nimport { buildComponentFilesList, runOnce } from '@intlayer/engine/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport { defu } from 'defu';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\nimport nextPackageJSON from 'next/package.json' with { type: 'json' };\nimport {\n type FieldRenameMapByDictionaryKey,\n getIsPurgePipelineAvailable,\n prepareSwcOptimization,\n resolveSwcLogLevel,\n} from './prepareSwcOptimization';\nimport {\n getIsSwcPluginSupported,\n MINIMUM_SWC_PLUGIN_NEXT_VERSION,\n} from './swcPluginCompatibility';\n\nexport {\n getIsSwcPluginSupported,\n MINIMUM_SWC_PLUGIN_NEXT_VERSION,\n} from './swcPluginCompatibility';\n\n/**\n * Resolve the Next.js version from the *user's* project at runtime.\n * A static `import from 'next/package.json'` would resolve relative to\n * next-intlayer's own node_modules, which may differ in a monorepo.\n */\nconst getNextVersionFlags = (intlayerConfig: IntlayerConfig) => {\n let nextVersion = nextPackageJSON.version;\n\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n const pkg = requireFunction('next/package.json') as { version: string };\n nextVersion = pkg.version;\n } catch {\n // keep default\n }\n\n return {\n nextVersion,\n isGteNext13: compareVersions(nextVersion, '≥', '13.0.0'),\n isGteNext15: compareVersions(nextVersion, '≥', '15.0.0'),\n isGteNext16: compareVersions(nextVersion, '≥', '16.0.0'),\n isTurbopackStable: compareVersions(nextVersion, '≥', '15.3.0'),\n /**\n * Whether this Next.js release can load the `@intlayer/swc` Wasm plugin.\n * See {@link MINIMUM_SWC_PLUGIN_NEXT_VERSION}.\n */\n isSwcPluginSupported: getIsSwcPluginSupported(nextVersion),\n };\n};\n\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/swc');\n return true;\n } catch (_e) {\n return false;\n }\n};\n\n// Check if Babel plugin is available\nconst getIsBabelExtractPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/babel');\n return true;\n } catch (_e) {\n return false;\n }\n};\n\nconst resolvePluginPath = (\n pluginPath: string,\n intlayerConfig: IntlayerConfig,\n isTurbopackEnabled: boolean\n): string => {\n const requireFunction = intlayerConfig.build?.require ?? getProjectRequire();\n const pluginPathResolved = requireFunction?.resolve(pluginPath);\n\n if (isTurbopackEnabled)\n // Relative path for turbopack\n return normalizePath(`./${relative(process.cwd(), pluginPathResolved)}`);\n\n // Absolute path for webpack\n return pluginPathResolved;\n};\n\ntype GetPruneConfigParams = {\n intlayerConfig: IntlayerConfig;\n isBuildCommand: boolean;\n isTurbopackEnabled: boolean;\n isDevCommand: boolean;\n isGteNext13: boolean;\n /** Whether the resolved Next.js version can load the Wasm plugin. */\n isSwcPluginSupported: boolean;\n /** Resolved Next.js version, reported when the plugin has to stand down. */\n nextVersion: string;\n swcExtraCallers?: SwcExtraCallerConfig[];\n fieldRenameMap?: FieldRenameMapByDictionaryKey;\n};\n\nconst getPruneConfig = ({\n intlayerConfig,\n isBuildCommand,\n isTurbopackEnabled,\n isDevCommand,\n isGteNext13,\n isSwcPluginSupported,\n nextVersion,\n swcExtraCallers,\n fieldRenameMap,\n}: GetPruneConfigParams): Partial<NextConfig> => {\n const { optimize, minify, purge } = intlayerConfig.build;\n const editorEnabled = intlayerConfig.editor.enabled;\n const importMode =\n intlayerConfig.build.importMode ?? intlayerConfig.dictionary?.importMode;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n } = intlayerConfig.system;\n const { baseDir } = intlayerConfig.system;\n const logger = getAppLogger(intlayerConfig);\n\n if (optimize === false) {\n return {};\n }\n if (optimize === undefined && !isBuildCommand) {\n return {};\n }\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => {\n if (isSwcPluginAvailable && !isSwcPluginSupported) {\n logger(\n [\n `Build optimization ${colorize('disabled', ANSIColors.GREY_DARK)}:`,\n colorize('@intlayer/swc', ANSIColors.GREY_LIGHT),\n colorize(\n `cannot run on Next.js ${nextVersion} — its bundled SWC predates the`,\n ANSIColors.GREY\n ),\n colorize(\n 'stable Wasm plugin ABI. Upgrade to Next.js',\n ANSIColors.GREY\n ),\n colorize(MINIMUM_SWC_PLUGIN_NEXT_VERSION, ANSIColors.BLUE),\n colorize('or later to enable it.', ANSIColors.GREY),\n ],\n { level: 'warn' }\n );\n } else if (isSwcPluginAvailable) {\n logger([\n `Build optimization ${colorize('enabled', ANSIColors.GREEN)}`,\n colorize(`(import mode:`, ANSIColors.GREY_DARK),\n colorize(importMode ?? IMPORT_MODE, ANSIColors.BLUE),\n colorize(`)`, ANSIColors.GREY_DARK),\n ]);\n\n // The purge / minify pipeline stands down — with its own explanation —\n // when the editor needs full dictionary content, when compat-adapter\n // callers hide call sites from the usage analyser, or when\n // `@intlayer/babel` (which runs it) is not resolvable.\n const isPurgePipelineEnabled =\n !editorEnabled &&\n !swcExtraCallers?.length &&\n getIsPurgePipelineAvailable(intlayerConfig);\n\n if (isPurgePipelineEnabled && minify) {\n logger(\n `Dictionary minification ${colorize('enabled', ANSIColors.GREEN)}`\n );\n }\n\n if (isPurgePipelineEnabled && purge) {\n logger(\n `Dictionary purge unused keys ${colorize('enabled', ANSIColors.GREEN)}`\n );\n }\n } else {\n logger([\n colorize('Recommended: Install', ANSIColors.GREY),\n colorize('@intlayer/swc', ANSIColors.GREY_LIGHT),\n colorize(\n 'package to enable build optimization. See documentation:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://intlayer.org/docs/bundle-optimization',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n runOnce(\n join(\n baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-compiler-plugin-enabled.lock'\n ),\n () => {\n const isBabelExtractPluginAvailable =\n getIsBabelExtractPluginAvailable(intlayerConfig);\n\n if (isBabelExtractPluginAvailable) {\n let isEnabled = intlayerConfig.compiler?.enabled ?? true;\n\n if (isEnabled === 'build-only') {\n isEnabled = !isDevCommand;\n }\n\n // Only the enabled state is reported: disabling the compiler is an\n // explicit configuration choice, so announcing it on every build adds\n // noise without telling the user anything they did not ask for.\n if (isEnabled) {\n logger('Intlayer compiler enabled');\n }\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n // Registering the plugin on a host that cannot load it is not a degraded\n // build but a failed one: SWC aborts with `failed to invoke plugin`. Standing\n // down leaves the app running off the runtime dictionary registry, which the\n // transform would otherwise have emptied.\n if (!isSwcPluginAvailable || !isSwcPluginSupported) {\n return {};\n }\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n\n const unmergedDictionariesEntryPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = buildComponentFilesList(intlayerConfig);\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n unmergedDictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n ];\n\n const dictionaries = getDictionaries(intlayerConfig);\n\n const dictionaryModeMap: Record<string, 'static' | 'dynamic' | 'fetch'> = {};\n\n (Object.values(dictionaries) as Dictionary[]).forEach((dictionary) => {\n dictionaryModeMap[dictionary.key] =\n dictionary.importMode ?? importMode ?? IMPORT_MODE;\n });\n\n // Dictionaries holding `nest()` references: their static import is re-pointed\n // at the companion module carrying the nest targets.\n const nestingDictionaryKeys = [\n ...getNestedDictionaryGraph(Object.values(dictionaries)).keys(),\n ];\n\n return {\n experimental: {\n swcPlugins: [\n [\n resolvePluginPath(\n '@intlayer/swc',\n intlayerConfig,\n isTurbopackEnabled\n ),\n {\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: true,\n nestingDictionaryKeys,\n dictionaryModeMap,\n extraCallers: swcExtraCallers ?? [],\n // Rewrites `content.title` → `content.a` to match the compiled\n // dictionaries the `build.minify` pass already renamed.\n fieldRenameMap: fieldRenameMap ?? {},\n logLevel: resolveSwcLogLevel(intlayerConfig),\n },\n ],\n ],\n },\n };\n};\n\nconst getCommandsEvent = () => {\n const lifecycleEvent = process.env['npm_lifecycle_event'];\n const lifecycleScript = process.env['npm_lifecycle_script'] ?? '';\n\n const isDevCommand =\n lifecycleEvent === 'dev' ||\n process.argv.some((arg) => arg === 'dev') ||\n /(^|\\s)(next\\s+)?dev(\\s|$)/.test(lifecycleScript);\n\n const isBuildCommand =\n lifecycleEvent === 'build' ||\n process.argv.some((arg) => arg === 'build') ||\n /(^|\\s)(next\\s+)?build(\\s|$)/.test(lifecycleScript);\n\n const isStartCommand =\n lifecycleEvent === 'start' ||\n process.argv.some((arg) => arg === 'start') ||\n /(^|\\s)(next\\s+)?start(\\s|$)/.test(lifecycleScript);\n\n return {\n isDevCommand,\n isBuildCommand,\n isStartCommand,\n };\n};\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\ntype WithIntlayerOptions = GetConfigurationOptions & {\n enableTurbopack?: boolean;\n swcExtraCallers?: SwcExtraCallerConfig[];\n\n /**\n * Field-rename tables produced by the purge / minify pipeline, forwarded to\n * the `@intlayer/swc` plugin so it rewrites source accesses to match the\n * renamed dictionaries.\n *\n * @internal Set by {@link withIntlayer}; `withIntlayerSync` on its own runs\n * no dictionary rewrite, so it leaves this unset and no rename is applied.\n */\n fieldRenameMap?: FieldRenameMapByDictionaryKey;\n};\n\n/**\n * Pin the env file used to resolve the Intlayer configuration to the Next.js\n * command being run (`dev` → `development`, `build`/`start` → `production`).\n *\n * Next.js loads the config file in several processes during a single command\n * (the main `build` process plus one or more Turbopack/webpack workers), and\n * `process.env.NODE_ENV` is not guaranteed to hold the same value in all of\n * them. Since `getConfiguration` falls back to `NODE_ENV` to pick its env file\n * (`.env.development.local` vs `.env.production.local`), those processes could\n * otherwise resolve *different* env values (e.g. `applicationURL`,\n * `INTLAYER_CLIENT_ID`). The resulting configuration would differ between\n * processes, defeating the `isCachedConfigurationUpToDate` check and forcing a\n * redundant full dictionary rebuild.\n *\n * Passing an explicit `env` keeps configuration resolution deterministic across\n * every process of the command. An `env` already set by the caller is\n * respected, and when the command cannot be determined we fall back to\n * `getConfiguration`'s own default (i.e. leave `env` unset).\n */\nconst resolveConfigOptions = (\n configOptions?: WithIntlayerOptions\n): WithIntlayerOptions | undefined => {\n // Respect an explicit override from the caller (idempotent on re-entry).\n if (configOptions?.env) return configOptions;\n\n const { isDevCommand, isBuildCommand, isStartCommand } = getCommandsEvent();\n\n const env = isDevCommand\n ? 'development'\n : isBuildCommand || isStartCommand\n ? 'production'\n : undefined;\n\n if (!env) return configOptions;\n\n return {\n ...configOptions,\n env,\n };\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayerSync(nextConfig)\n * ```\n */\nexport const withIntlayerSync = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: WithIntlayerOptions\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const resolvedConfigOptions = resolveConfigOptions(configOptions);\n\n const intlayerConfig = getConfiguration(resolvedConfigOptions);\n\n logConfigDetails(resolvedConfigOptions);\n\n const appLogger = getAppLogger(intlayerConfig);\n\n const {\n nextVersion,\n isGteNext13,\n isGteNext15,\n isGteNext16,\n isTurbopackStable,\n isSwcPluginSupported,\n } = getNextVersionFlags(intlayerConfig);\n\n const isTurbopackEnabledFromCommand = isGteNext16\n ? // Next@16 enables turbopack by default; disable with --webpack\n !process.env['npm_lifecycle_script']?.includes('--webpack')\n : // Next@15 uses --turbopack, Next@14 uses --turbo\n process.env['npm_lifecycle_script']?.includes('--turbo');\n\n const isTurbopackEnabled =\n configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;\n\n if (isTurbopackEnabled && typeof nextConfig.webpack !== 'undefined') {\n appLogger(\n 'Turbopack is enabled but a custom webpack config is present. It will be ignored.'\n );\n }\n\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = {\n resolveAlias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => `./${value}`, // prefix by './' to consider the path as relative to the project root. This is necessary for turbopack to work correctly.\n }),\n\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n };\n\n const serverExternalPackages = [\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n 'recast',\n '@intlayer/engine',\n '@intlayer/webpack',\n ];\n\n let env: Record<string, string> = {};\n\n if (isBuildCommand) {\n const dictionaries = getDictionaries(intlayerConfig);\n\n if (Object.keys(dictionaries).length === 0) {\n appLogger('No dictionaries found. Please check your configuration.', {\n isVerbose: true,\n });\n }\n\n const unusedNodeTypes = getUnusedNodeTypes(dictionaries);\n\n if (unusedNodeTypes && unusedNodeTypes.length > 0) {\n appLogger(\n [\n 'Filtering out unused logic:',\n unusedNodeTypes\n .filter(\n (key) => !['reactNode', 'solidNode', 'preactNode'].includes(key)\n )\n .map((key) => colorize(key, ANSIColors.BLUE))\n .join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n }\n\n env = {\n ...env,\n\n // Tree shacking based on unused node types\n ...formatNodeTypeToEnvVar(unusedNodeTypes),\n\n // Selects the local `nest()` resolver, which reads the nest targets\n // attached to each dictionary by the optimize transform instead of the\n // registry that transform empties.\n ...formatOptimizedNestingEnvVar(intlayerConfig.build.optimize !== false),\n\n // Tree shacking the dictionary selector logic\n // (collections / variants)\n ...formatDictionarySelectorEnvVar(getHasDictionarySelector(dictionaries)),\n\n // Tree shacking based on config\n ...getConfigEnvVars(intlayerConfig),\n };\n }\n\n const getNewConfig = (): Partial<NextConfig> => {\n let config: Partial<NextConfig> = {\n env,\n };\n\n if (isGteNext15) {\n config = {\n ...config,\n serverExternalPackages,\n };\n }\n\n if (isGteNext13 && !isGteNext15) {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n serverComponentsExternalPackages: serverExternalPackages,\n },\n };\n }\n\n if (isTurbopackEnabled) {\n if (isGteNext15 && isTurbopackStable) {\n config = {\n ...config,\n turbopack: turboConfig,\n };\n } else {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n // @ts-ignore exist in next@14\n turbo: turboConfig,\n },\n };\n }\n } else {\n config = {\n ...config,\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Rspack set external as false by default\n // Overwrite it to allow pushing the desired externals\n if (config.externals === false) {\n config.externals = [];\n }\n\n // Mark server-only modules as externals (function form handles subpaths)\n const externalExact = new Set([\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n 'recast',\n ]);\n const externalPrefixes = ['@intlayer/engine', '@intlayer/webpack'];\n config.externals.push(\n (\n { request }: { request?: string },\n callback: (err: Error | null, result?: string) => void\n ) => {\n if (\n request &&\n (externalExact.has(request) ||\n externalPrefixes.some(\n (prefix) =>\n request === prefix || request.startsWith(`${prefix}/`)\n ))\n ) {\n return callback(null, `commonjs ${request}`);\n }\n callback(null);\n }\n );\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Always alias on the server (node/edge) for stability.\n // On the client, alias only when not using live sync.\n config.resolve.alias = {\n ...config.resolve.alias,\n ...getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n };\n\n // Activate watch mode webpack plugin\n if (isDevCommand && isServer && nextRuntime === 'nodejs') {\n // Optional as rspack not support plugin yet\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n const pruneConfig: Partial<NextConfig> = getPruneConfig({\n intlayerConfig,\n isBuildCommand,\n isTurbopackEnabled: isTurbopackEnabled ?? false,\n isDevCommand,\n isGteNext13,\n isSwcPluginSupported,\n nextVersion,\n swcExtraCallers: configOptions?.swcExtraCallers,\n fieldRenameMap: configOptions?.fieldRenameMap,\n });\n\n const intlayerNextConfig: Partial<NextConfig> = defu(\n getNewConfig(),\n pruneConfig\n );\n\n // Merge the new config with the user's config\n const result = defu(intlayerNextConfig, nextConfig) as NextConfig & T;\n\n return result;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n *\n * > Node withIntlayer is a promise function. Use withIntlayerSync instead if you want to use it synchronously.\n * > Using the promise allows to prepare the intlayer dictionaries before the build starts.\n *\n */\nexport const withIntlayer = async <T extends NextConfig | Partial<NextConfig>>(\n nextConfig: T | Promise<T> = {} as T,\n configOptions?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand, isStartCommand } = getCommandsEvent();\n\n process.env.INTLAYER_IS_DEV_COMMAND = isDevCommand ? 'true' : 'false';\n\n const resolvedConfigOptions = resolveConfigOptions(configOptions);\n\n const intlayerConfig = getConfiguration(resolvedConfigOptions);\n\n const { mode } = intlayerConfig.build;\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (!isStartCommand && (isDevCommand || isBuildCommand || mode === 'auto')) {\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n env: isBuildCommand ? 'prod' : 'dev',\n });\n }\n\n // Remove unused content fields and rename the remaining ones to short\n // aliases, then hand the rename tables to `withIntlayerSync` so the SWC\n // plugin rewrites the matching source accesses. Only meaningful for a\n // production build — the optimize pipeline is off during `next dev`.\n //\n // `isSwcPluginUsable` gates the dictionary rewrite on the plugin actually\n // running: it is the only half that fixes up the source, so minifying without\n // it would leave the code reading field names the dictionaries no longer have.\n const { isSwcPluginSupported } = getNextVersionFlags(intlayerConfig);\n\n const fieldRenameMap = isBuildCommand\n ? await prepareSwcOptimization(intlayerConfig, {\n configOptions: resolvedConfigOptions,\n swcExtraCallers: configOptions?.swcExtraCallers,\n isSwcPluginUsable:\n isSwcPluginSupported && getIsSwcPluginAvailable(intlayerConfig),\n })\n : {};\n\n const nextConfigResolved = await nextConfig;\n\n return withIntlayerSync(nextConfigResolved, {\n ...resolvedConfigOptions,\n fieldRenameMap,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,MAAM,uBAAuB,mBAAmC;CAC9D,IAAI,cAAcA,0BAAgB;CAElC,IAAI;EAIF,eAFE,eAAe,OAAO,eAAWC,0CAAkB,EAC1B,CAAC,mBACZ,CAAC,CAAC;CACpB,QAAQ,CAER;CAEA,OAAO;EACL;EACA,iBAAaC,wCAAgB,aAAa,KAAK,QAAQ;EACvD,iBAAaA,wCAAgB,aAAa,KAAK,QAAQ;EACvD,iBAAaA,wCAAgB,aAAa,KAAK,QAAQ;EACvD,uBAAmBA,wCAAgB,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jectRequire","compareVersions","getIsSwcPluginSupported","normalizePath","relative","getAppLogger","join","colorize","ANSIColors","MINIMUM_SWC_PLUGIN_NEXT_VERSION","IMPORT_MODE","getIsPurgePipelineAvailable","buildComponentFilesList","getDictionaries","getNestedDictionaryGraph","resolveSwcLogLevel","getConfiguration","getAlias","getUnusedNodeTypes","formatNodeTypeToEnvVar","formatOptimizedNestingEnvVar","formatDictionarySelectorEnvVar","getHasDictionarySelector","getConfigEnvVars","resolve","IntlayerPlugin","prepareIntlayer","prepareSwcOptimization"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport type { SwcExtraCallerConfig } from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { IMPORT_MODE } from '@intlayer/config/defaultValues';\nimport {\n formatDictionarySelectorEnvVar,\n formatNodeTypeToEnvVar,\n formatOptimizedNestingEnvVar,\n getConfigEnvVars,\n} from '@intlayer/config/envVars';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n compareVersions,\n getAlias,\n getHasDictionarySelector,\n getProjectRequire,\n getUnusedNodeTypes,\n normalizePath,\n} from '@intlayer/config/utils';\nimport { getNestedDictionaryGraph } from '@intlayer/core/dictionaryManipulator';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { logConfigDetails } from '@intlayer/engine/cli';\nimport { buildComponentFilesList, runOnce } from '@intlayer/engine/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport { defu } from 'defu';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\nimport nextPackageJSON from 'next/package.json' with { type: 'json' };\nimport {\n type FieldRenameMapByDictionaryKey,\n getIsPurgePipelineAvailable,\n prepareSwcOptimization,\n resolveSwcLogLevel,\n} from './prepareSwcOptimization';\nimport {\n getIsSwcPluginSupported,\n MINIMUM_SWC_PLUGIN_NEXT_VERSION,\n} from './swcPluginCompatibility';\n\nexport {\n getIsSwcPluginSupported,\n MINIMUM_SWC_PLUGIN_NEXT_VERSION,\n} from './swcPluginCompatibility';\n\n/**\n * Resolve the Next.js version from the *user's* project at runtime.\n * A static `import from 'next/package.json'` would resolve relative to\n * next-intlayer's own node_modules, which may differ in a monorepo.\n */\nconst getNextVersionFlags = (intlayerConfig: IntlayerConfig) => {\n let nextVersion = nextPackageJSON.version;\n\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n const pkg = requireFunction('next/package.json') as { version: string };\n nextVersion = pkg.version;\n } catch {\n // keep default\n }\n\n return {\n nextVersion,\n isGteNext13: compareVersions(nextVersion, '≥', '13.0.0'),\n isGteNext15: compareVersions(nextVersion, '≥', '15.0.0'),\n isGteNext16: compareVersions(nextVersion, '≥', '16.0.0'),\n isTurbopackStable: compareVersions(nextVersion, '≥', '15.3.0'),\n /**\n * Whether this Next.js release can load the `@intlayer/swc` Wasm plugin.\n * See {@link MINIMUM_SWC_PLUGIN_NEXT_VERSION}.\n */\n isSwcPluginSupported: getIsSwcPluginSupported(nextVersion),\n };\n};\n\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/swc');\n return true;\n } catch (_e) {\n return false;\n }\n};\n\n// Check if Babel plugin is available\nconst getIsBabelExtractPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/babel');\n return true;\n } catch (_e) {\n return false;\n }\n};\n\nconst resolvePluginPath = (\n pluginPath: string,\n intlayerConfig: IntlayerConfig,\n isTurbopackEnabled: boolean\n): string => {\n const requireFunction = intlayerConfig.build?.require ?? getProjectRequire();\n const pluginPathResolved = requireFunction?.resolve(pluginPath);\n\n if (isTurbopackEnabled)\n // Relative path for turbopack\n return normalizePath(`./${relative(process.cwd(), pluginPathResolved)}`);\n\n // Absolute path for webpack\n return pluginPathResolved;\n};\n\ntype GetPruneConfigParams = {\n intlayerConfig: IntlayerConfig;\n isBuildCommand: boolean;\n isTurbopackEnabled: boolean;\n isDevCommand: boolean;\n isGteNext13: boolean;\n /** Whether the resolved Next.js version can load the Wasm plugin. */\n isSwcPluginSupported: boolean;\n /** Resolved Next.js version, reported when the plugin has to stand down. */\n nextVersion: string;\n swcExtraCallers?: SwcExtraCallerConfig[];\n fieldRenameMap?: FieldRenameMapByDictionaryKey;\n};\n\nconst getPruneConfig = ({\n intlayerConfig,\n isBuildCommand,\n isTurbopackEnabled,\n isDevCommand,\n isGteNext13,\n isSwcPluginSupported,\n nextVersion,\n swcExtraCallers,\n fieldRenameMap,\n}: GetPruneConfigParams): Partial<NextConfig> => {\n const { optimize, minify, purge } = intlayerConfig.build;\n const importMode =\n intlayerConfig.build.importMode ?? intlayerConfig.dictionary?.importMode;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n } = intlayerConfig.system;\n const { baseDir } = intlayerConfig.system;\n const logger = getAppLogger(intlayerConfig);\n\n if (optimize === false) {\n return {};\n }\n if (optimize === undefined && !isBuildCommand) {\n return {};\n }\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => {\n if (isSwcPluginAvailable && !isSwcPluginSupported) {\n logger(\n [\n `Build optimization ${colorize('disabled', ANSIColors.GREY_DARK)}:`,\n colorize('@intlayer/swc', ANSIColors.GREY_LIGHT),\n colorize(\n `cannot run on Next.js ${nextVersion} — its bundled SWC predates the`,\n ANSIColors.GREY\n ),\n colorize(\n 'stable Wasm plugin ABI. Upgrade to Next.js',\n ANSIColors.GREY\n ),\n colorize(MINIMUM_SWC_PLUGIN_NEXT_VERSION, ANSIColors.BLUE),\n colorize('or later to enable it.', ANSIColors.GREY),\n ],\n { level: 'warn' }\n );\n } else if (isSwcPluginAvailable) {\n logger([\n `Build optimization ${colorize('enabled', ANSIColors.GREEN)}`,\n colorize(`(import mode:`, ANSIColors.GREY_DARK),\n colorize(importMode ?? IMPORT_MODE, ANSIColors.BLUE),\n colorize(`)`, ANSIColors.GREY_DARK),\n ]);\n\n // The purge / minify pipeline stands down — with its own explanation —\n // when compat-adapter callers hide call sites from the usage analyser,\n // or when `@intlayer/babel` (which runs it) is not resolvable. The\n // editor only stands the field-rename step down, not the pipeline.\n const isPurgePipelineEnabled =\n !swcExtraCallers?.length &&\n getIsPurgePipelineAvailable(intlayerConfig);\n\n // The purge pipeline reports the field-rename step standing down when\n // the editor is enabled, so this line stays a plain one.\n if (isPurgePipelineEnabled && minify) {\n logger(\n `Dictionary minification ${colorize('enabled', ANSIColors.GREEN)}`\n );\n }\n\n if (isPurgePipelineEnabled && purge) {\n logger(\n `Dictionary purge unused keys ${colorize('enabled', ANSIColors.GREEN)}`\n );\n }\n } else {\n logger([\n colorize('Recommended: Install', ANSIColors.GREY),\n colorize('@intlayer/swc', ANSIColors.GREY_LIGHT),\n colorize(\n 'package to enable build optimization. See documentation:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://intlayer.org/docs/bundle-optimization',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n runOnce(\n join(\n baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-compiler-plugin-enabled.lock'\n ),\n () => {\n const isBabelExtractPluginAvailable =\n getIsBabelExtractPluginAvailable(intlayerConfig);\n\n if (isBabelExtractPluginAvailable) {\n let isEnabled = intlayerConfig.compiler?.enabled ?? true;\n\n if (isEnabled === 'build-only') {\n isEnabled = !isDevCommand;\n }\n\n // Only the enabled state is reported: disabling the compiler is an\n // explicit configuration choice, so announcing it on every build adds\n // noise without telling the user anything they did not ask for.\n if (isEnabled) {\n logger('Intlayer compiler enabled');\n }\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n // Registering the plugin on a host that cannot load it is not a degraded\n // build but a failed one: SWC aborts with `failed to invoke plugin`. Standing\n // down leaves the app running off the runtime dictionary registry, which the\n // transform would otherwise have emptied.\n if (!isSwcPluginAvailable || !isSwcPluginSupported) {\n return {};\n }\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n\n const unmergedDictionariesEntryPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = buildComponentFilesList(intlayerConfig);\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n unmergedDictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n ];\n\n const dictionaries = getDictionaries(intlayerConfig);\n\n const dictionaryModeMap: Record<string, 'static' | 'dynamic' | 'fetch'> = {};\n\n (Object.values(dictionaries) as Dictionary[]).forEach((dictionary) => {\n dictionaryModeMap[dictionary.key] =\n dictionary.importMode ?? importMode ?? IMPORT_MODE;\n });\n\n // Dictionaries holding `nest()` references: their static import is re-pointed\n // at the companion module carrying the nest targets.\n const nestingDictionaryKeys = [\n ...getNestedDictionaryGraph(Object.values(dictionaries)).keys(),\n ];\n\n return {\n experimental: {\n swcPlugins: [\n [\n resolvePluginPath(\n '@intlayer/swc',\n intlayerConfig,\n isTurbopackEnabled\n ),\n {\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: true,\n nestingDictionaryKeys,\n dictionaryModeMap,\n extraCallers: swcExtraCallers ?? [],\n // Rewrites `content.title` → `content.a` to match the compiled\n // dictionaries the `build.minify` pass already renamed.\n fieldRenameMap: fieldRenameMap ?? {},\n logLevel: resolveSwcLogLevel(intlayerConfig),\n },\n ],\n ],\n },\n };\n};\n\nconst getCommandsEvent = () => {\n const lifecycleEvent = process.env['npm_lifecycle_event'];\n const lifecycleScript = process.env['npm_lifecycle_script'] ?? '';\n\n const isDevCommand =\n lifecycleEvent === 'dev' ||\n process.argv.some((arg) => arg === 'dev') ||\n /(^|\\s)(next\\s+)?dev(\\s|$)/.test(lifecycleScript);\n\n const isBuildCommand =\n lifecycleEvent === 'build' ||\n process.argv.some((arg) => arg === 'build') ||\n /(^|\\s)(next\\s+)?build(\\s|$)/.test(lifecycleScript);\n\n const isStartCommand =\n lifecycleEvent === 'start' ||\n process.argv.some((arg) => arg === 'start') ||\n /(^|\\s)(next\\s+)?start(\\s|$)/.test(lifecycleScript);\n\n return {\n isDevCommand,\n isBuildCommand,\n isStartCommand,\n };\n};\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\ntype WithIntlayerOptions = GetConfigurationOptions & {\n enableTurbopack?: boolean;\n swcExtraCallers?: SwcExtraCallerConfig[];\n\n /**\n * Field-rename tables produced by the purge / minify pipeline, forwarded to\n * the `@intlayer/swc` plugin so it rewrites source accesses to match the\n * renamed dictionaries.\n *\n * @internal Set by {@link withIntlayer}; `withIntlayerSync` on its own runs\n * no dictionary rewrite, so it leaves this unset and no rename is applied.\n */\n fieldRenameMap?: FieldRenameMapByDictionaryKey;\n};\n\n/**\n * Pin the env file used to resolve the Intlayer configuration to the Next.js\n * command being run (`dev` → `development`, `build`/`start` → `production`).\n *\n * Next.js loads the config file in several processes during a single command\n * (the main `build` process plus one or more Turbopack/webpack workers), and\n * `process.env.NODE_ENV` is not guaranteed to hold the same value in all of\n * them. Since `getConfiguration` falls back to `NODE_ENV` to pick its env file\n * (`.env.development.local` vs `.env.production.local`), those processes could\n * otherwise resolve *different* env values (e.g. `applicationURL`,\n * `INTLAYER_CLIENT_ID`). The resulting configuration would differ between\n * processes, defeating the `isCachedConfigurationUpToDate` check and forcing a\n * redundant full dictionary rebuild.\n *\n * Passing an explicit `env` keeps configuration resolution deterministic across\n * every process of the command. An `env` already set by the caller is\n * respected, and when the command cannot be determined we fall back to\n * `getConfiguration`'s own default (i.e. leave `env` unset).\n */\nconst resolveConfigOptions = (\n configOptions?: WithIntlayerOptions\n): WithIntlayerOptions | undefined => {\n // Respect an explicit override from the caller (idempotent on re-entry).\n if (configOptions?.env) return configOptions;\n\n const { isDevCommand, isBuildCommand, isStartCommand } = getCommandsEvent();\n\n const env = isDevCommand\n ? 'development'\n : isBuildCommand || isStartCommand\n ? 'production'\n : undefined;\n\n if (!env) return configOptions;\n\n return {\n ...configOptions,\n env,\n };\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayerSync(nextConfig)\n * ```\n */\nexport const withIntlayerSync = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: WithIntlayerOptions\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const resolvedConfigOptions = resolveConfigOptions(configOptions);\n\n const intlayerConfig = getConfiguration(resolvedConfigOptions);\n\n logConfigDetails(resolvedConfigOptions);\n\n const appLogger = getAppLogger(intlayerConfig);\n\n const {\n nextVersion,\n isGteNext13,\n isGteNext15,\n isGteNext16,\n isTurbopackStable,\n isSwcPluginSupported,\n } = getNextVersionFlags(intlayerConfig);\n\n const isTurbopackEnabledFromCommand = isGteNext16\n ? // Next@16 enables turbopack by default; disable with --webpack\n !process.env['npm_lifecycle_script']?.includes('--webpack')\n : // Next@15 uses --turbopack, Next@14 uses --turbo\n process.env['npm_lifecycle_script']?.includes('--turbo');\n\n const isTurbopackEnabled =\n configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;\n\n if (isTurbopackEnabled && typeof nextConfig.webpack !== 'undefined') {\n appLogger(\n 'Turbopack is enabled but a custom webpack config is present. It will be ignored.'\n );\n }\n\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = {\n resolveAlias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => `./${value}`, // prefix by './' to consider the path as relative to the project root. This is necessary for turbopack to work correctly.\n }),\n\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n };\n\n const serverExternalPackages = [\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n 'recast',\n '@intlayer/engine',\n '@intlayer/webpack',\n ];\n\n let env: Record<string, string> = {};\n\n if (isBuildCommand) {\n const dictionaries = getDictionaries(intlayerConfig);\n\n if (Object.keys(dictionaries).length === 0) {\n appLogger('No dictionaries found. Please check your configuration.', {\n isVerbose: true,\n });\n }\n\n const unusedNodeTypes = getUnusedNodeTypes(dictionaries);\n\n if (unusedNodeTypes && unusedNodeTypes.length > 0) {\n appLogger(\n [\n 'Filtering out unused logic:',\n unusedNodeTypes\n .filter(\n (key) => !['reactNode', 'solidNode', 'preactNode'].includes(key)\n )\n .map((key) => colorize(key, ANSIColors.BLUE))\n .join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n }\n\n env = {\n ...env,\n\n // Tree shacking based on unused node types\n ...formatNodeTypeToEnvVar(unusedNodeTypes),\n\n // Selects the local `nest()` resolver, which reads the nest targets\n // attached to each dictionary by the optimize transform instead of the\n // registry that transform empties.\n ...formatOptimizedNestingEnvVar(intlayerConfig.build.optimize !== false),\n\n // Tree shacking the dictionary selector logic\n // (collections / variants)\n ...formatDictionarySelectorEnvVar(getHasDictionarySelector(dictionaries)),\n\n // Tree shacking based on config\n ...getConfigEnvVars(intlayerConfig),\n };\n }\n\n const getNewConfig = (): Partial<NextConfig> => {\n let config: Partial<NextConfig> = {\n env,\n };\n\n if (isGteNext15) {\n config = {\n ...config,\n serverExternalPackages,\n };\n }\n\n if (isGteNext13 && !isGteNext15) {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n serverComponentsExternalPackages: serverExternalPackages,\n },\n };\n }\n\n if (isTurbopackEnabled) {\n if (isGteNext15 && isTurbopackStable) {\n config = {\n ...config,\n turbopack: turboConfig,\n };\n } else {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n // @ts-ignore exist in next@14\n turbo: turboConfig,\n },\n };\n }\n } else {\n config = {\n ...config,\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Rspack set external as false by default\n // Overwrite it to allow pushing the desired externals\n if (config.externals === false) {\n config.externals = [];\n }\n\n // Mark server-only modules as externals (function form handles subpaths)\n const externalExact = new Set([\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n 'recast',\n ]);\n const externalPrefixes = ['@intlayer/engine', '@intlayer/webpack'];\n config.externals.push(\n (\n { request }: { request?: string },\n callback: (err: Error | null, result?: string) => void\n ) => {\n if (\n request &&\n (externalExact.has(request) ||\n externalPrefixes.some(\n (prefix) =>\n request === prefix || request.startsWith(`${prefix}/`)\n ))\n ) {\n return callback(null, `commonjs ${request}`);\n }\n callback(null);\n }\n );\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Always alias on the server (node/edge) for stability.\n // On the client, alias only when not using live sync.\n config.resolve.alias = {\n ...config.resolve.alias,\n ...getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n };\n\n // Activate watch mode webpack plugin\n if (isDevCommand && isServer && nextRuntime === 'nodejs') {\n // Optional as rspack not support plugin yet\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n const pruneConfig: Partial<NextConfig> = getPruneConfig({\n intlayerConfig,\n isBuildCommand,\n isTurbopackEnabled: isTurbopackEnabled ?? false,\n isDevCommand,\n isGteNext13,\n isSwcPluginSupported,\n nextVersion,\n swcExtraCallers: configOptions?.swcExtraCallers,\n fieldRenameMap: configOptions?.fieldRenameMap,\n });\n\n const intlayerNextConfig: Partial<NextConfig> = defu(\n getNewConfig(),\n pruneConfig\n );\n\n // Merge the new config with the user's config\n const result = defu(intlayerNextConfig, nextConfig) as NextConfig & T;\n\n return result;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n *\n * > Node withIntlayer is a promise function. Use withIntlayerSync instead if you want to use it synchronously.\n * > Using the promise allows to prepare the intlayer dictionaries before the build starts.\n *\n */\nexport const withIntlayer = async <T extends NextConfig | Partial<NextConfig>>(\n nextConfig: T | Promise<T> = {} as T,\n configOptions?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand, isStartCommand } = getCommandsEvent();\n\n process.env.INTLAYER_IS_DEV_COMMAND = isDevCommand ? 'true' : 'false';\n\n const resolvedConfigOptions = resolveConfigOptions(configOptions);\n\n const intlayerConfig = getConfiguration(resolvedConfigOptions);\n\n const { mode } = intlayerConfig.build;\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (!isStartCommand && (isDevCommand || isBuildCommand || mode === 'auto')) {\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n env: isBuildCommand ? 'prod' : 'dev',\n });\n }\n\n // Remove unused content fields and rename the remaining ones to short\n // aliases, then hand the rename tables to `withIntlayerSync` so the SWC\n // plugin rewrites the matching source accesses. Only meaningful for a\n // production build — the optimize pipeline is off during `next dev`.\n //\n // `isSwcPluginUsable` gates the dictionary rewrite on the plugin actually\n // running: it is the only half that fixes up the source, so minifying without\n // it would leave the code reading field names the dictionaries no longer have.\n const { isSwcPluginSupported } = getNextVersionFlags(intlayerConfig);\n\n const fieldRenameMap = isBuildCommand\n ? await prepareSwcOptimization(intlayerConfig, {\n configOptions: resolvedConfigOptions,\n swcExtraCallers: configOptions?.swcExtraCallers,\n isSwcPluginUsable:\n isSwcPluginSupported && getIsSwcPluginAvailable(intlayerConfig),\n })\n : {};\n\n const nextConfigResolved = await nextConfig;\n\n return withIntlayerSync(nextConfigResolved, {\n ...resolvedConfigOptions,\n fieldRenameMap,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,MAAM,uBAAuB,mBAAmC;CAC9D,IAAI,cAAcA,0BAAgB;CAElC,IAAI;EAIF,eAFE,eAAe,OAAO,eAAWC,0CAAkB,EAC1B,CAAC,mBACZ,CAAC,CAAC;CACpB,QAAQ,CAER;CAEA,OAAO;EACL;EACA,iBAAaC,wCAAgB,aAAa,KAAK,QAAQ;EACvD,iBAAaA,wCAAgB,aAAa,KAAK,QAAQ;EACvD,iBAAaA,wCAAgB,aAAa,KAAK,QAAQ;EACvD,uBAAmBA,wCAAgB,aAAa,KAAK,QAAQ;;;;;EAK7D,sBAAsBC,8DAAwB,WAAW;CAC3D;AACF;AAGA,MAAM,2BAA2B,mBAAmC;CAClE,IAAI;EAGF,CADE,eAAe,OAAO,eAAWF,0CAAkB,EACt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AAK,IAAIC,iCAAe,cAAc,CAAC;IAGxD,OAAO;GACT;EACF;EAGF,OAAO;CACT;CAEA,MAAM,cAAmC,eAAe;EACtD;EACA;EACA,oBAAoB,sBAAsB;EAC1C;EACA;EACA;EACA;EACA,iBAAiB,eAAe;EAChC,gBAAgB,eAAe;CACjC,CAAC;CAED,MAAM,yBAA0C,WAC9C,aAAa,GACb,WACF;CAKA,WAFe,WAAK,oBAAoB,UAE5B;AACd;;;;;;;;;;;;;;;;AAiBA,MAAa,eAAe,OAC1B,aAA6B,CAAC,GAC9B,kBAC4B;CAC5B,MAAM,EAAE,gBAAgB,cAAc,mBAAmB,iBAAiB;CAE1E,QAAQ,IAAI,0BAA0B,eAAe,SAAS;CAE9D,MAAM,wBAAwB,qBAAqB,aAAa;CAEhE,MAAM,qBAAiBT,wCAAiB,qBAAqB;CAE7D,MAAM,EAAE,SAAS,eAAe;CAKhC,IAAI,CAAC,mBAAmB,gBAAgB,kBAAkB,SAAS,SAEjE,UAAMU,wCAAgB,gBAAgB;EACpC,OAAO;EACP,gBAAgB,iBACZ,MACA;EACJ,KAAK,iBAAiB,SAAS;CACjC,CAAC;CAWH,MAAM,EAAE,yBAAyB,oBAAoB,cAAc;CAEnE,MAAM,iBAAiB,iBACnB,MAAMC,6DAAuB,gBAAgB;EAC3C,eAAe;EACf,iBAAiB,eAAe;EAChC,mBACE,wBAAwB,wBAAwB,cAAc;CAClE,CAAC,IACD,CAAC;CAEL,MAAM,qBAAqB,MAAM;CAEjC,OAAO,iBAAiB,oBAAoB;EAC1C,GAAG;EACH;CACF,CAAC;AACH"}
@@ -5,31 +5,34 @@ import { jsx } from "react/jsx-runtime";
5
5
 
6
6
  //#region src/client/IntlayerClientProvider.tsx
7
7
  /**
8
- * Provider for client-side components in Next.js.
8
+ * Client boundary mounted by the unified `IntlayerProvider`.
9
9
  *
10
- * This component wraps the `IntlayerProvider` from `react-intlayer` and is intended
11
- * to be used within Next.js App Router client components.
10
+ * Wraps the `IntlayerProvider` from `react-intlayer` so that client components
11
+ * rendered below a Next.js App Router server component receive the locale and
12
+ * the ambient variant through context.
12
13
  *
13
14
  * @param props - The provider props.
14
15
  * @returns The provider component.
16
+ */
17
+ const IntlayerClientProviderBase = (props) => /* @__PURE__ */ jsx(IntlayerProvider, { ...props });
18
+ /**
19
+ * @deprecated Use `IntlayerProvider` from `next-intlayer/server` instead.
20
+ * Mounted once in the locale layout, it seeds the request-scoped server
21
+ * context *and* mounts this client provider, so a single provider covers both
22
+ * halves of the tree:
15
23
  *
16
- * @example
17
24
  * ```tsx
18
- * 'use client';
25
+ * import { IntlayerProvider } from 'next-intlayer/server';
19
26
  *
20
- * import { IntlayerClientProvider } from 'next-intlayer';
27
+ * const LocaleLayout = async ({ children, params }) => {
28
+ * const { locale } = await params;
21
29
  *
22
- * export default function ClientLayout({ children, locale }) {
23
- * return (
24
- * <IntlayerClientProvider locale={locale}>
25
- * {children}
26
- * </IntlayerClientProvider>
27
- * );
28
- * }
30
+ * return <IntlayerProvider locale={locale}>{children}</IntlayerProvider>;
31
+ * };
29
32
  * ```
30
33
  */
31
- const IntlayerClientProvider = (props) => /* @__PURE__ */ jsx(IntlayerProvider, { ...props });
34
+ const IntlayerClientProvider = IntlayerClientProviderBase;
32
35
 
33
36
  //#endregion
34
- export { IntlayerClientProvider };
37
+ export { IntlayerClientProvider, IntlayerClientProviderBase };
35
38
  //# sourceMappingURL=IntlayerClientProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"IntlayerClientProvider.mjs","names":[],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\n/**\n * Provider for client-side components in Next.js.\n *\n * This component wraps the `IntlayerProvider` from `react-intlayer` and is intended\n * to be used within Next.js App Router client components.\n *\n * @param props - The provider props.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { IntlayerClientProvider } from 'next-intlayer';\n *\n * export default function ClientLayout({ children, locale }) {\n * return (\n * <IntlayerClientProvider locale={locale}>\n * {children}\n * </IntlayerClientProvider>\n * );\n * }\n * ```\n */\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerProvider {...props} />\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,0BAAqD,UAChE,oBAAC,kBAAD,EAAkB,GAAI,MAAQ"}
1
+ {"version":3,"file":"IntlayerClientProvider.mjs","names":[],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\n\n/**\n * @deprecated Use `IntlayerProviderProps` from `next-intlayer/server` instead.\n */\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\n/**\n * Client boundary mounted by the unified `IntlayerProvider`.\n *\n * Wraps the `IntlayerProvider` from `react-intlayer` so that client components\n * rendered below a Next.js App Router server component receive the locale and\n * the ambient variant through context.\n *\n * @param props - The provider props.\n * @returns The provider component.\n */\nexport const IntlayerClientProviderBase: FC<IntlayerProviderProps> = (\n props\n) => <IntlayerProvider {...props} />;\n\n/**\n * @deprecated Use `IntlayerProvider` from `next-intlayer/server` instead.\n * Mounted once in the locale layout, it seeds the request-scoped server\n * context *and* mounts this client provider, so a single provider covers both\n * halves of the tree:\n *\n * ```tsx\n * import { IntlayerProvider } from 'next-intlayer/server';\n *\n * const LocaleLayout = async ({ children, params }) => {\n * const { locale } = await params;\n *\n * return <IntlayerProvider locale={locale}>{children}</IntlayerProvider>;\n * };\n * ```\n */\nexport const IntlayerClientProvider = IntlayerClientProviderBase;\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,MAAa,8BACX,UACG,oBAAC,kBAAD,EAAkB,GAAI,MAAQ;;;;;;;;;;;;;;;;;AAkBnC,MAAa,yBAAyB"}
@@ -5,7 +5,7 @@ import { useLocalePageRouter } from "./client/useLocalePageRouter.mjs";
5
5
  import { useRewriteURL } from "./client/useRewriteURL.mjs";
6
6
  import { generateStaticParams } from "./generateStaticParams.mjs";
7
7
  import { markdown_exports } from "./markdown/index.mjs";
8
- import { IntlayerClientContext, getDictionary, getIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocaleCookie, useLocaleStorage } from "react-intlayer";
8
+ import { IntlayerClientContext, IntlayerProvider, getDictionary, getIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useConversion, useDictionary, useDictionaryAsync, useDictionaryDynamic, useExperiment, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocaleCookie, useLocaleStorage } from "react-intlayer";
9
9
 
10
10
  //#region src/index.ts
11
11
  /**
@@ -30,5 +30,5 @@ const useMarkdownRenderer = markdown_exports.useMarkdownRenderer;
30
30
  const MarkdownRenderer = markdown_exports.MarkdownRenderer;
31
31
 
32
32
  //#endregion
33
- export { IntlayerClientContext, IntlayerClientProvider, MarkdownProvider, MarkdownRenderer, generateStaticParams, getDictionary, getIntlayer, localeCookie, localeInStorage, renderMarkdown, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocale, useLocaleCookie, useLocalePageRouter, useLocaleStorage, useMarkdownContext, useMarkdownRenderer, usePathname, useRewriteURL };
33
+ export { IntlayerClientContext, IntlayerClientProvider, IntlayerProvider, MarkdownProvider, MarkdownRenderer, generateStaticParams, getDictionary, getIntlayer, localeCookie, localeInStorage, renderMarkdown, setLocaleCookie, setLocaleInStorage, t, useConversion, useDictionary, useDictionaryAsync, useDictionaryDynamic, useExperiment, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocale, useLocaleCookie, useLocalePageRouter, useLocaleStorage, useMarkdownContext, useMarkdownRenderer, usePathname, useRewriteURL };
34
34
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["_MarkdownProvider","_useMarkdownContext","_renderMarkdown","_useMarkdownRenderer","_MarkdownRenderer"],"sources":["../../src/index.ts"],"sourcesContent":["export {\n getDictionary,\n getIntlayer,\n IntlayerClientContext,\n type IntlayerNode,\n localeCookie,\n localeInStorage,\n setLocaleCookie,\n setLocaleInStorage,\n t,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useI18n,\n useIntl,\n useIntlayer,\n useLoadDynamic,\n useLocaleCookie,\n useLocaleStorage,\n} from 'react-intlayer';\nexport * from './client/index';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n LocalPromiseParams,\n Next14LayoutIntlayer,\n Next14PageIntlayer,\n Next15LayoutIntlayer,\n Next15PageIntlayer,\n NextLayoutIntlayer,\n NextPageIntlayer,\n} from './types/index';\n\nimport type {\n MarkdownProviderOptions as _MarkdownProviderOptions,\n MarkdownRendererProps as _MarkdownRendererProps,\n RenderMarkdownProps as _RenderMarkdownProps,\n} from './markdown';\nimport {\n MarkdownProvider as _MarkdownProvider,\n MarkdownRenderer as _MarkdownRenderer,\n renderMarkdown as _renderMarkdown,\n useMarkdownContext as _useMarkdownContext,\n useMarkdownRenderer as _useMarkdownRenderer,\n} from './markdown';\n\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const MarkdownProvider = _MarkdownProvider;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const useMarkdownContext = _useMarkdownContext;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type MarkdownProviderOptions = _MarkdownProviderOptions;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const renderMarkdown = _renderMarkdown;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const useMarkdownRenderer = _useMarkdownRenderer;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const MarkdownRenderer = _MarkdownRenderer;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type RenderMarkdownProps = _RenderMarkdownProps;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type MarkdownRendererProps = _MarkdownRendererProps;\n"],"mappings":";;;;;;;;;;;;;AAiDA,MAAa,mBAAmBA;;;;AAIhC,MAAa,qBAAqBC;;;;AAQlC,MAAa,iBAAiBC;;;;AAI9B,MAAa,sBAAsBC;;;;AAInC,MAAa,mBAAmBC"}
1
+ {"version":3,"file":"index.mjs","names":["_MarkdownProvider","_useMarkdownContext","_renderMarkdown","_useMarkdownRenderer","_MarkdownRenderer"],"sources":["../../src/index.ts"],"sourcesContent":["export {\n type ConversionParams,\n type ExperimentState,\n getDictionary,\n getIntlayer,\n IntlayerClientContext,\n type IntlayerNode,\n IntlayerProvider,\n type IntlayerProviderProps,\n localeCookie,\n localeInStorage,\n setLocaleCookie,\n setLocaleInStorage,\n t,\n useConversion,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useExperiment,\n useI18n,\n useIntl,\n useIntlayer,\n useLoadDynamic,\n useLocaleCookie,\n useLocaleStorage,\n} from 'react-intlayer';\nexport * from './client/index';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n LocalPromiseParams,\n Next14LayoutIntlayer,\n Next14PageIntlayer,\n Next15LayoutIntlayer,\n Next15PageIntlayer,\n NextLayoutIntlayer,\n NextPageIntlayer,\n} from './types/index';\n\nimport type {\n MarkdownProviderOptions as _MarkdownProviderOptions,\n MarkdownRendererProps as _MarkdownRendererProps,\n RenderMarkdownProps as _RenderMarkdownProps,\n} from './markdown';\nimport {\n MarkdownProvider as _MarkdownProvider,\n MarkdownRenderer as _MarkdownRenderer,\n renderMarkdown as _renderMarkdown,\n useMarkdownContext as _useMarkdownContext,\n useMarkdownRenderer as _useMarkdownRenderer,\n} from './markdown';\n\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const MarkdownProvider = _MarkdownProvider;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const useMarkdownContext = _useMarkdownContext;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type MarkdownProviderOptions = _MarkdownProviderOptions;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const renderMarkdown = _renderMarkdown;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const useMarkdownRenderer = _useMarkdownRenderer;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const MarkdownRenderer = _MarkdownRenderer;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type RenderMarkdownProps = _RenderMarkdownProps;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type MarkdownRendererProps = _MarkdownRendererProps;\n"],"mappings":";;;;;;;;;;;;;AAuDA,MAAa,mBAAmBA;;;;AAIhC,MAAa,qBAAqBC;;;;AAQlC,MAAa,iBAAiBC;;;;AAI9B,MAAa,sBAAsBC;;;;AAInC,MAAa,mBAAmBC"}
@@ -0,0 +1,18 @@
1
+ import { IntlayerClientProvider } from "../client/IntlayerClientProvider.mjs";
2
+ import { usePathname } from "../client/usePathname.mjs";
3
+ import { useLocalePageRouter } from "../client/useLocalePageRouter.mjs";
4
+ import { useRewriteURL } from "../client/useRewriteURL.mjs";
5
+ import { generateStaticParams } from "../generateStaticParams.mjs";
6
+ import { IntlayerProvider } from "../server/IntlayerProvider.mjs";
7
+ import { t } from "../server/t.mjs";
8
+ import { useDictionary } from "../server/useDictionary.mjs";
9
+ import { useDictionaryAsync } from "../server/useDictionaryAsync.mjs";
10
+ import { useDictionaryDynamic } from "../server/useDictionaryDynamic.mjs";
11
+ import { useI18n } from "../server/useI18n.mjs";
12
+ import { useIntl } from "../server/useIntl.mjs";
13
+ import { useIntlayer } from "../server/useIntlayer.mjs";
14
+ import { useLocale } from "../server/useLocale.mjs";
15
+ import { IntlayerClientContext, getDictionary, getIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "react-intlayer";
16
+ import { useLoadDynamic } from "react-intlayer/server";
17
+
18
+ export { IntlayerClientContext, IntlayerClientProvider, IntlayerProvider, generateStaticParams, getDictionary, getIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocale, useLocaleCookie, useLocalePageRouter, useLocaleStorage, usePathname, useRewriteURL };
@@ -0,0 +1,53 @@
1
+ import { IntlayerClientProvider } from "../client/IntlayerClientProvider.mjs";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { IntlayerServerProvider } from "react-intlayer/server";
4
+
5
+ //#region src/server/IntlayerProvider.tsx
6
+ /**
7
+ * Unified Intlayer provider for the Next.js App Router.
8
+ *
9
+ * Server component that seeds the request-scoped server context (locale and
10
+ * ambient variant) read by the server hooks, and mounts the client provider so
11
+ * client components receive the same values — one provider for both halves.
12
+ *
13
+ * Mount it once, in the locale layout:
14
+ *
15
+ * ```tsx
16
+ * import { IntlayerProvider } from 'next-intlayer/server';
17
+ *
18
+ * const LocaleLayout: NextLayoutIntlayer = async ({ children, params }) => {
19
+ * const { locale } = await params;
20
+ *
21
+ * return (
22
+ * <IntlayerProvider locale={locale}>
23
+ * <html lang={locale}>
24
+ * <body>{children}</body>
25
+ * </html>
26
+ * </IntlayerProvider>
27
+ * );
28
+ * };
29
+ * ```
30
+ *
31
+ * The server context is request-scoped, not tree-scoped: on client-side
32
+ * navigations that only re-render the page segment, the layout — and with it
33
+ * this provider — does not re-run. The server hooks then fall back to the
34
+ * locale carried by the request (the `x-intlayer-locale` header set by the
35
+ * intlayer proxy, then the locale cookie), so content stays correct without a
36
+ * per-page provider. The ambient `variant` has no request-carried fallback:
37
+ * seed it per request with `setVariant` when server components read it outside
38
+ * a full render of this provider.
39
+ */
40
+ const IntlayerProvider = ({ children, locale, variant, ...clientProps }) => /* @__PURE__ */ jsx(IntlayerServerProvider, {
41
+ locale,
42
+ variant,
43
+ children: /* @__PURE__ */ jsx(IntlayerClientProvider, {
44
+ locale,
45
+ variant,
46
+ ...clientProps,
47
+ children
48
+ })
49
+ });
50
+
51
+ //#endregion
52
+ export { IntlayerProvider };
53
+ //# sourceMappingURL=IntlayerProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../../src/server/IntlayerProvider.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport type { IntlayerProviderProps as IntlayerClientProviderProps } from 'react-intlayer';\nimport {\n IntlayerServerProvider,\n type IntlayerServerProviderProps,\n} from 'react-intlayer/server';\nimport { IntlayerClientProvider } from '../client/IntlayerClientProvider';\n\nexport type IntlayerProviderProps = IntlayerClientProviderProps &\n IntlayerServerProviderProps;\n\n/**\n * Unified Intlayer provider for the Next.js App Router.\n *\n * Server component that seeds the request-scoped server context (locale and\n * ambient variant) read by the server hooks, and mounts the client provider so\n * client components receive the same values — one provider for both halves.\n *\n * Mount it once, in the locale layout:\n *\n * ```tsx\n * import { IntlayerProvider } from 'next-intlayer/server';\n *\n * const LocaleLayout: NextLayoutIntlayer = async ({ children, params }) => {\n * const { locale } = await params;\n *\n * return (\n * <IntlayerProvider locale={locale}>\n * <html lang={locale}>\n * <body>{children}</body>\n * </html>\n * </IntlayerProvider>\n * );\n * };\n * ```\n *\n * The server context is request-scoped, not tree-scoped: on client-side\n * navigations that only re-render the page segment, the layout — and with it\n * this provider — does not re-run. The server hooks then fall back to the\n * locale carried by the request (the `x-intlayer-locale` header set by the\n * intlayer proxy, then the locale cookie), so content stays correct without a\n * per-page provider. The ambient `variant` has no request-carried fallback:\n * seed it per request with `setVariant` when server components read it outside\n * a full render of this provider.\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n children,\n locale,\n variant,\n ...clientProps\n}) => (\n <IntlayerServerProvider locale={locale} variant={variant}>\n <IntlayerClientProvider locale={locale} variant={variant} {...clientProps}>\n {children}\n </IntlayerClientProvider>\n </IntlayerServerProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,oBAA+C,EAC1D,UACA,QACA,SACA,GAAG,kBAEH,oBAAC,wBAAD;CAAgC;CAAiB;WAC/C,oBAAC,wBAAD;EAAgC;EAAiB;EAAS,GAAI;EAC3D;CACqB;AACF"}
@@ -0,0 +1,28 @@
1
+ import { IntlayerServerProvider as IntlayerServerProvider$1 } from "react-intlayer/server";
2
+
3
+ //#region src/server/IntlayerServerProvider.ts
4
+ /**
5
+ * @deprecated Use `IntlayerProvider` from `next-intlayer/server` instead — and
6
+ * in most trees, no replacement at all. Mounting `IntlayerProvider` once in the
7
+ * locale layout already seeds both the server context and the client provider
8
+ * for every page below it, and the server hooks fall back to the locale carried
9
+ * by the request when the layout is skipped on client-side navigations. This
10
+ * component's only remaining use is a page that must seed the locale itself
11
+ * (statically rendered routes on Next.js < 16); prefer the imperative
12
+ * `setLocale` over wrapping the tree even there.
13
+ *
14
+ * ```tsx
15
+ * import { IntlayerProvider } from 'next-intlayer/server';
16
+ *
17
+ * const LocaleLayout = async ({ children, params }) => {
18
+ * const { locale } = await params;
19
+ *
20
+ * return <IntlayerProvider locale={locale}>{children}</IntlayerProvider>;
21
+ * };
22
+ * ```
23
+ */
24
+ const IntlayerServerProvider = IntlayerServerProvider$1;
25
+
26
+ //#endregion
27
+ export { IntlayerServerProvider };
28
+ //# sourceMappingURL=IntlayerServerProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlayerServerProvider.mjs","names":["IntlayerServerProviderBase"],"sources":["../../../src/server/IntlayerServerProvider.ts"],"sourcesContent":["import {\n IntlayerServerProvider as IntlayerServerProviderBase,\n type IntlayerServerProviderProps as IntlayerServerProviderPropsBase,\n} from 'react-intlayer/server';\n\n/**\n * @deprecated Use `IntlayerProviderProps` from `next-intlayer/server` instead.\n */\nexport type IntlayerServerProviderProps = IntlayerServerProviderPropsBase;\n\n/**\n * @deprecated Use `IntlayerProvider` from `next-intlayer/server` instead — and\n * in most trees, no replacement at all. Mounting `IntlayerProvider` once in the\n * locale layout already seeds both the server context and the client provider\n * for every page below it, and the server hooks fall back to the locale carried\n * by the request when the layout is skipped on client-side navigations. This\n * component's only remaining use is a page that must seed the locale itself\n * (statically rendered routes on Next.js < 16); prefer the imperative\n * `setLocale` over wrapping the tree even there.\n *\n * ```tsx\n * import { IntlayerProvider } from 'next-intlayer/server';\n *\n * const LocaleLayout = async ({ children, params }) => {\n * const { locale } = await params;\n *\n * return <IntlayerProvider locale={locale}>{children}</IntlayerProvider>;\n * };\n * ```\n */\nexport const IntlayerServerProvider = IntlayerServerProviderBase;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,yBAAyBA"}
@@ -0,0 +1,61 @@
1
+ import { getLocale } from "./getLocale.mjs";
2
+ import { createSuspendingReader } from "./suspendingReader.mjs";
3
+ import { IntlayerServer, getServerContext } from "react-intlayer/server";
4
+
5
+ //#region src/server/ambientLocale.ts
6
+ /**
7
+ * Whether the call site already carries a locale — either a plain locale
8
+ * argument or a selector object with an explicit `locale` field.
9
+ */
10
+ const hasExplicitLocale = (localeOrSelector) => typeof localeOrSelector === "string" || typeof localeOrSelector === "object" && localeOrSelector !== null && Boolean(localeOrSelector.locale);
11
+ /**
12
+ * Whether the request-derived locale is worth reading at all.
13
+ *
14
+ * The base hooks in `react-intlayer/server` already prefer, in order, the
15
+ * locale passed at the call site and the request-scoped server context seeded
16
+ * by `IntlayerProvider`; they only fall back to the third argument these
17
+ * helpers produce. Reading request storage means calling `headers()` /
18
+ * `cookies()`, which opts the route into dynamic rendering — so it must stay
19
+ * behind both of those, and never run when either already answers.
20
+ */
21
+ const needsRequestLocale = (localeOrSelector) => !hasExplicitLocale(localeOrSelector) && !getServerContext(IntlayerServer);
22
+ /**
23
+ * Reads the locale carried by the request: the `x-intlayer-locale` header set
24
+ * by the intlayer proxy, then the locale cookie, then `accept-language`.
25
+ *
26
+ * Errors are not swallowed — during prerendering Next.js relies on the throw
27
+ * from `headers()` to mark the route dynamic.
28
+ */
29
+ const readStoredLocale = createSuspendingReader(getLocale);
30
+ /**
31
+ * Fallback locale for the synchronous server hooks, so a page does not need a
32
+ * provider of its own. Not a React hook despite suspending — it holds no
33
+ * positional state, which is what lets it run conditionally (see
34
+ * {@link createSuspendingReader}): on a client-side navigation that re-renders only the
35
+ * page segment, the layout — and with it `IntlayerProvider` — does not re-run,
36
+ * and the locale carried by the request takes over.
37
+ *
38
+ * Suspends until the request storage resolves. Returns `undefined` when the
39
+ * call site or the server context already carries the locale.
40
+ */
41
+ const resolveFallbackLocale = (localeOrSelector) => needsRequestLocale(localeOrSelector) ? readStoredLocale() : void 0;
42
+ /**
43
+ * Asynchronous twin of {@link resolveFallbackLocale}, for the hooks that are
44
+ * already async and can await the request storage instead of suspending on it.
45
+ */
46
+ const getFallbackLocale = async (localeOrSelector) => needsRequestLocale(localeOrSelector) ? await getLocale() : void 0;
47
+ /**
48
+ * Full ambient locale for the server APIs that take a plain locale argument
49
+ * (or none at all): call site → server context → locale carried by the
50
+ * request.
51
+ *
52
+ * {@link resolveFallbackLocale} only yields the last rung, because the base hooks
53
+ * in `react-intlayer/server` consult the first two themselves. The APIs
54
+ * reimplemented here have no such fallback slot, so they need the resolved
55
+ * value.
56
+ */
57
+ const resolveAmbientLocale = (locale) => locale ?? getServerContext(IntlayerServer) ?? resolveFallbackLocale(locale);
58
+
59
+ //#endregion
60
+ export { getFallbackLocale, resolveAmbientLocale, resolveFallbackLocale };
61
+ //# sourceMappingURL=ambientLocale.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ambientLocale.mjs","names":[],"sources":["../../../src/server/ambientLocale.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getServerContext, IntlayerServer } from 'react-intlayer/server';\nimport { getLocale } from './getLocale';\nimport { createSuspendingReader } from './suspendingReader';\n\n/**\n * Whether the call site already carries a locale — either a plain locale\n * argument or a selector object with an explicit `locale` field.\n */\nconst hasExplicitLocale = (localeOrSelector?: unknown): boolean =>\n typeof localeOrSelector === 'string' ||\n (typeof localeOrSelector === 'object' &&\n localeOrSelector !== null &&\n Boolean((localeOrSelector as { locale?: unknown }).locale));\n\n/**\n * Whether the request-derived locale is worth reading at all.\n *\n * The base hooks in `react-intlayer/server` already prefer, in order, the\n * locale passed at the call site and the request-scoped server context seeded\n * by `IntlayerProvider`; they only fall back to the third argument these\n * helpers produce. Reading request storage means calling `headers()` /\n * `cookies()`, which opts the route into dynamic rendering — so it must stay\n * behind both of those, and never run when either already answers.\n */\nconst needsRequestLocale = (localeOrSelector?: unknown): boolean =>\n !hasExplicitLocale(localeOrSelector) && !getServerContext(IntlayerServer);\n\n/**\n * Reads the locale carried by the request: the `x-intlayer-locale` header set\n * by the intlayer proxy, then the locale cookie, then `accept-language`.\n *\n * Errors are not swallowed — during prerendering Next.js relies on the throw\n * from `headers()` to mark the route dynamic.\n */\nconst readStoredLocale = createSuspendingReader<Locale>(getLocale);\n\n/**\n * Fallback locale for the synchronous server hooks, so a page does not need a\n * provider of its own. Not a React hook despite suspending — it holds no\n * positional state, which is what lets it run conditionally (see\n * {@link createSuspendingReader}): on a client-side navigation that re-renders only the\n * page segment, the layout — and with it `IntlayerProvider` — does not re-run,\n * and the locale carried by the request takes over.\n *\n * Suspends until the request storage resolves. Returns `undefined` when the\n * call site or the server context already carries the locale.\n */\nexport const resolveFallbackLocale = (\n localeOrSelector?: unknown\n): Locale | undefined =>\n needsRequestLocale(localeOrSelector) ? readStoredLocale() : undefined;\n\n/**\n * Asynchronous twin of {@link resolveFallbackLocale}, for the hooks that are\n * already async and can await the request storage instead of suspending on it.\n */\nexport const getFallbackLocale = async (\n localeOrSelector?: unknown\n): Promise<Locale | undefined> =>\n needsRequestLocale(localeOrSelector) ? await getLocale() : undefined;\n\n/**\n * Full ambient locale for the server APIs that take a plain locale argument\n * (or none at all): call site → server context → locale carried by the\n * request.\n *\n * {@link resolveFallbackLocale} only yields the last rung, because the base hooks\n * in `react-intlayer/server` consult the first two themselves. The APIs\n * reimplemented here have no such fallback slot, so they need the resolved\n * value.\n */\nexport const resolveAmbientLocale = (\n locale?: LocalesValues\n): LocalesValues | undefined =>\n locale ??\n getServerContext<LocalesValues>(IntlayerServer) ??\n resolveFallbackLocale(locale);\n"],"mappings":";;;;;;;;;AAUA,MAAM,qBAAqB,qBACzB,OAAO,qBAAqB,YAC3B,OAAO,qBAAqB,YAC3B,qBAAqB,QACrB,QAAS,iBAA0C,MAAM;;;;;;;;;;;AAY7D,MAAM,sBAAsB,qBAC1B,CAAC,kBAAkB,gBAAgB,KAAK,CAAC,iBAAiB,cAAc;;;;;;;;AAS1E,MAAM,mBAAmB,uBAA+B,SAAS;;;;;;;;;;;;AAajE,MAAa,yBACX,qBAEA,mBAAmB,gBAAgB,IAAI,iBAAiB,IAAI;;;;;AAM9D,MAAa,oBAAoB,OAC/B,qBAEA,mBAAmB,gBAAgB,IAAI,MAAM,UAAU,IAAI;;;;;;;;;;;AAY7D,MAAa,wBACX,WAEA,UACA,iBAAgC,cAAc,KAC9C,sBAAsB,MAAM"}
@@ -1 +1,10 @@
1
- export * from "react-intlayer/server/format"
1
+ import { useUnit } from "./useUnit.mjs";
2
+ import { useDate } from "./useDate.mjs";
3
+ import { useNumber } from "./useNumber.mjs";
4
+ import { useRelativeTime } from "./useRelativeTime.mjs";
5
+ import { useCompact } from "./useCompact.mjs";
6
+ import { useList } from "./useList.mjs";
7
+ import { usePercentage } from "./usePercentage.mjs";
8
+ import { useCurrency } from "./useCurrency.mjs";
9
+
10
+ export { useCompact, useCurrency, useDate, useList, useNumber, usePercentage, useRelativeTime, useUnit };
@@ -0,0 +1,25 @@
1
+ import { resolveAmbientLocale } from "../ambientLocale.mjs";
2
+ import { compact } from "@intlayer/core/formatters";
3
+
4
+ //#region src/server/format/useCompact.ts
5
+ /**
6
+ * On the server side, hook returning a `compact` formatter bound to the ambient
7
+ * locale: the server context, falling back to the locale carried by the
8
+ * request. A per-call `locale` option still wins.
9
+ *
10
+ * Reimplemented rather than re-exported from `react-intlayer/server/format`:
11
+ * that one takes no locale argument, so there is no way to hand it the ambient
12
+ * locale — it would read the server context alone and format with the default
13
+ * locale on any render the provider did not reach.
14
+ */
15
+ const useCompact = () => {
16
+ const locale = resolveAmbientLocale();
17
+ return (...args) => compact(args[0], {
18
+ ...args[1],
19
+ locale: args[1]?.locale ?? locale
20
+ });
21
+ };
22
+
23
+ //#endregion
24
+ export { useCompact };
25
+ //# sourceMappingURL=useCompact.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCompact.mjs","names":[],"sources":["../../../../src/server/format/useCompact.ts"],"sourcesContent":["import { compact } from '@intlayer/core/formatters';\nimport { resolveAmbientLocale } from '../ambientLocale';\n\n/**\n * On the server side, hook returning a `compact` formatter bound to the ambient\n * locale: the server context, falling back to the locale carried by the\n * request. A per-call `locale` option still wins.\n *\n * Reimplemented rather than re-exported from `react-intlayer/server/format`:\n * that one takes no locale argument, so there is no way to hand it the ambient\n * locale — it would read the server context alone and format with the default\n * locale on any render the provider did not reach.\n */\nexport const useCompact = () => {\n const locale = resolveAmbientLocale();\n\n return (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,mBAAmB;CAC9B,MAAM,SAAS,qBAAqB;CAEpC,QAAQ,GAAG,SACT,QAAQ,KAAK,IAAI;EACf,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,25 @@
1
+ import { resolveAmbientLocale } from "../ambientLocale.mjs";
2
+ import { currency } from "@intlayer/core/formatters";
3
+
4
+ //#region src/server/format/useCurrency.ts
5
+ /**
6
+ * On the server side, hook returning a `currency` formatter bound to the ambient
7
+ * locale: the server context, falling back to the locale carried by the
8
+ * request. A per-call `locale` option still wins.
9
+ *
10
+ * Reimplemented rather than re-exported from `react-intlayer/server/format`:
11
+ * that one takes no locale argument, so there is no way to hand it the ambient
12
+ * locale — it would read the server context alone and format with the default
13
+ * locale on any render the provider did not reach.
14
+ */
15
+ const useCurrency = () => {
16
+ const locale = resolveAmbientLocale();
17
+ return (...args) => currency(args[0], {
18
+ ...args[1],
19
+ locale: args[1]?.locale ?? locale
20
+ });
21
+ };
22
+
23
+ //#endregion
24
+ export { useCurrency };
25
+ //# sourceMappingURL=useCurrency.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCurrency.mjs","names":[],"sources":["../../../../src/server/format/useCurrency.ts"],"sourcesContent":["import { currency } from '@intlayer/core/formatters';\nimport { resolveAmbientLocale } from '../ambientLocale';\n\n/**\n * On the server side, hook returning a `currency` formatter bound to the ambient\n * locale: the server context, falling back to the locale carried by the\n * request. A per-call `locale` option still wins.\n *\n * Reimplemented rather than re-exported from `react-intlayer/server/format`:\n * that one takes no locale argument, so there is no way to hand it the ambient\n * locale — it would read the server context alone and format with the default\n * locale on any render the provider did not reach.\n */\nexport const useCurrency = () => {\n const locale = resolveAmbientLocale();\n\n return (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,oBAAoB;CAC/B,MAAM,SAAS,qBAAqB;CAEpC,QAAQ,GAAG,SACT,SAAS,KAAK,IAAI;EAChB,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,32 @@
1
+ import { resolveAmbientLocale } from "../ambientLocale.mjs";
2
+ import { date, presets } from "@intlayer/core/formatters";
3
+
4
+ //#region src/server/format/useDate.ts
5
+ /**
6
+ * On the server side, hook returning a `date` formatter bound to the ambient
7
+ * locale: the server context, falling back to the locale carried by the
8
+ * request. A per-call `locale` option still wins.
9
+ *
10
+ * Reimplemented rather than re-exported from `react-intlayer/server/format`:
11
+ * that one takes no locale argument, so there is no way to hand it the ambient
12
+ * locale — it would read the server context alone and format with the default
13
+ * locale on any render the provider did not reach.
14
+ *
15
+ * The options argument is either a preset name or an options object, so the
16
+ * preset is resolved before the locale is merged in — spreading the string
17
+ * itself would scatter its characters and drop the preset.
18
+ */
19
+ const useDate = () => {
20
+ const locale = resolveAmbientLocale();
21
+ return (...args) => date(args[0], typeof args[1] === "string" ? {
22
+ ...presets[args[1]],
23
+ locale
24
+ } : {
25
+ ...args[1],
26
+ locale: args[1]?.locale ?? locale
27
+ });
28
+ };
29
+
30
+ //#endregion
31
+ export { useDate };
32
+ //# sourceMappingURL=useDate.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDate.mjs","names":[],"sources":["../../../../src/server/format/useDate.ts"],"sourcesContent":["import { date, presets } from '@intlayer/core/formatters';\nimport { resolveAmbientLocale } from '../ambientLocale';\n\n/**\n * On the server side, hook returning a `date` formatter bound to the ambient\n * locale: the server context, falling back to the locale carried by the\n * request. A per-call `locale` option still wins.\n *\n * Reimplemented rather than re-exported from `react-intlayer/server/format`:\n * that one takes no locale argument, so there is no way to hand it the ambient\n * locale — it would read the server context alone and format with the default\n * locale on any render the provider did not reach.\n *\n * The options argument is either a preset name or an options object, so the\n * preset is resolved before the locale is merged in — spreading the string\n * itself would scatter its characters and drop the preset.\n */\nexport const useDate = () => {\n const locale = resolveAmbientLocale();\n\n return (...args: Parameters<typeof date>) =>\n date(\n args[0],\n typeof args[1] === 'string'\n ? { ...presets[args[1]], locale }\n : { ...args[1], locale: args[1]?.locale ?? locale }\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,qBAAqB;CAEpC,QAAQ,GAAG,SACT,KACE,KAAK,IACL,OAAO,KAAK,OAAO,WACf;EAAE,GAAG,QAAQ,KAAK;EAAK;CAAO,IAC9B;EAAE,GAAG,KAAK;EAAI,QAAQ,KAAK,EAAE,EAAE,UAAU;CAAO,CACtD;AACJ"}