next-intlayer 9.2.0 → 9.3.1

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 (75) hide show
  1. package/README.md +24 -24
  2. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -2
  3. package/dist/cjs/client/format/index.cjs +0 -1
  4. package/dist/cjs/client/useLocale.cjs +29 -28
  5. package/dist/cjs/client/useLocale.cjs.map +1 -1
  6. package/dist/cjs/client/useLocalePageRouter.cjs +11 -10
  7. package/dist/cjs/client/useLocalePageRouter.cjs.map +1 -1
  8. package/dist/cjs/client/usePathname.cjs.map +1 -1
  9. package/dist/cjs/proxy/intlayerProxy.cjs +4 -2
  10. package/dist/cjs/proxy/intlayerProxy.cjs.map +1 -1
  11. package/dist/cjs/proxy/localeDetector.cjs.map +1 -1
  12. package/dist/cjs/server/format/index.cjs +0 -1
  13. package/dist/cjs/server/getLocale.cjs.map +1 -1
  14. package/dist/cjs/server/prepareSwcOptimization.cjs +190 -0
  15. package/dist/cjs/server/prepareSwcOptimization.cjs.map +1 -0
  16. package/dist/cjs/server/swcPluginCompatibility.cjs +57 -0
  17. package/dist/cjs/server/swcPluginCompatibility.cjs.map +1 -0
  18. package/dist/cjs/server/useDictionary.cjs +2 -1
  19. package/dist/cjs/server/useDictionary.cjs.map +1 -1
  20. package/dist/cjs/server/useDictionaryAsync.cjs +2 -1
  21. package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
  22. package/dist/cjs/server/useDictionaryDynamic.cjs +2 -1
  23. package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
  24. package/dist/cjs/server/useIntlayer.cjs +2 -1
  25. package/dist/cjs/server/useIntlayer.cjs.map +1 -1
  26. package/dist/cjs/server/withIntlayer.cjs +81 -32
  27. package/dist/cjs/server/withIntlayer.cjs.map +1 -1
  28. package/dist/esm/client/useLocale.mjs +29 -28
  29. package/dist/esm/client/useLocale.mjs.map +1 -1
  30. package/dist/esm/client/useLocalePageRouter.mjs +11 -10
  31. package/dist/esm/client/useLocalePageRouter.mjs.map +1 -1
  32. package/dist/esm/proxy/intlayerProxy.mjs +4 -2
  33. package/dist/esm/proxy/intlayerProxy.mjs.map +1 -1
  34. package/dist/esm/server/prepareSwcOptimization.mjs +185 -0
  35. package/dist/esm/server/prepareSwcOptimization.mjs.map +1 -0
  36. package/dist/esm/server/swcPluginCompatibility.mjs +55 -0
  37. package/dist/esm/server/swcPluginCompatibility.mjs.map +1 -0
  38. package/dist/esm/server/useDictionary.mjs +2 -1
  39. package/dist/esm/server/useDictionary.mjs.map +1 -1
  40. package/dist/esm/server/useDictionaryAsync.mjs +2 -1
  41. package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
  42. package/dist/esm/server/useDictionaryDynamic.mjs +2 -1
  43. package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
  44. package/dist/esm/server/useIntlayer.mjs +2 -1
  45. package/dist/esm/server/useIntlayer.mjs.map +1 -1
  46. package/dist/esm/server/withIntlayer.mjs +82 -35
  47. package/dist/esm/server/withIntlayer.mjs.map +1 -1
  48. package/dist/types/@intlayer/babel/dist/types/babel-plugin-intlayer-extract.d.ts +5 -0
  49. package/dist/types/@intlayer/babel/dist/types/babel-plugin-intlayer-field-rename.d.ts +21 -0
  50. package/dist/types/@intlayer/babel/dist/types/babel-plugin-intlayer-field-rename.d.ts.map +1 -0
  51. package/dist/types/@intlayer/babel/dist/types/babel-plugin-intlayer-minify.d.ts +2 -0
  52. package/dist/types/@intlayer/babel/dist/types/babel-plugin-intlayer-optimize.d.ts +3 -0
  53. package/dist/types/@intlayer/babel/dist/types/babel-plugin-intlayer-purge.d.ts +5 -0
  54. package/dist/types/@intlayer/babel/dist/types/babel-plugin-intlayer-usage-analyzer.d.ts +4 -0
  55. package/dist/types/@intlayer/babel/dist/types/extractContent/contentWriter.d.ts +2 -0
  56. package/dist/types/@intlayer/babel/dist/types/extractContent/extractContent.d.ts +3 -0
  57. package/dist/types/@intlayer/babel/dist/types/extractContent/index.d.ts +4 -0
  58. package/dist/types/@intlayer/babel/dist/types/extractContent/utils/extractDictionaryInfo.d.ts +3 -0
  59. package/dist/types/@intlayer/babel/dist/types/extractContent/utils/getComponentName.d.ts +1 -0
  60. package/dist/types/@intlayer/babel/dist/types/extractContent/utils/getExistingIntlayerInfo.d.ts +2 -0
  61. package/dist/types/@intlayer/babel/dist/types/extractContent/utils/index.d.ts +4 -0
  62. package/dist/types/@intlayer/babel/dist/types/extractContent/utils/resolveDictionaryKey.d.ts +1 -0
  63. package/dist/types/@intlayer/babel/dist/types/getExtractPluginOptions.d.ts +2 -0
  64. package/dist/types/@intlayer/babel/dist/types/getOptimizePluginOptions.d.ts +3 -0
  65. package/dist/types/@intlayer/babel/dist/types/getPurgePluginOptions.d.ts +4 -0
  66. package/dist/types/@intlayer/babel/dist/types/index.d.ts +16 -0
  67. package/dist/types/@intlayer/babel/dist/types/transformers.d.ts +3 -0
  68. package/dist/types/server/prepareSwcOptimization.d.ts +68 -0
  69. package/dist/types/server/prepareSwcOptimization.d.ts.map +1 -0
  70. package/dist/types/server/swcPluginCompatibility.d.ts +52 -0
  71. package/dist/types/server/swcPluginCompatibility.d.ts.map +1 -0
  72. package/dist/types/server/useDictionaryDynamic.d.ts +1 -1
  73. package/dist/types/server/withIntlayer.d.ts +12 -1
  74. package/dist/types/server/withIntlayer.d.ts.map +1 -1
  75. package/package.json +9 -9
@@ -0,0 +1,190 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ let node_path = require("node:path");
4
+ let _intlayer_config_colors = require("@intlayer/config/colors");
5
+ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
6
+ let _intlayer_config_logger = require("@intlayer/config/logger");
7
+ let _intlayer_config_utils = require("@intlayer/config/utils");
8
+ let _intlayer_engine_utils = require("@intlayer/engine/utils");
9
+ let node_fs = require("node:fs");
10
+ let node_fs_promises = require("node:fs/promises");
11
+
12
+ //#region src/server/prepareSwcOptimization.ts
13
+ /**
14
+ * Opt-in to the SWC plugin's per-file tracing.
15
+ *
16
+ * The plugin transforms one file at a time with no cross-file state, so all it
17
+ * can report is a line per file — hundreds of them on a real project, and with
18
+ * no counterpart in the Vite build output. The purge and minify summaries that
19
+ * `log.mode` does control are emitted by the pipeline itself, in Node; this
20
+ * variable is purely a debugging aid on top.
21
+ */
22
+ const SWC_LOG_LEVEL_ENV_VAR = "INTLAYER_SWC_LOG_LEVEL";
23
+ /** Sentinel coordinating the pipeline across the processes of one build. */
24
+ const PURGE_SENTINEL_FILE_NAME = "intlayer-swc-purge.lock";
25
+ /** Where the serialised field-rename tables are cached between processes. */
26
+ const FIELD_RENAME_MAP_FILE_NAME = "swc-field-rename-map.json";
27
+ /**
28
+ * Next.js evaluates `next.config.*` in the main build process and again in each
29
+ * Turbopack/webpack worker. The dictionary rewrite must happen exactly once —
30
+ * a second run would derive the short aliases from the already-renamed JSON —
31
+ * so the sentinel window has to cover a whole build startup.
32
+ */
33
+ const PURGE_CACHE_TIMEOUT_MS = 3e4;
34
+ /** Absolute path of a file in the intlayer cache directory. */
35
+ const getCacheFilePath = (intlayerConfig, fileName) => (0, node_path.join)(intlayerConfig.system.baseDir, ".intlayer", "cache", fileName);
36
+ /**
37
+ * Resolves the verbosity the `@intlayer/swc` plugin should report at.
38
+ *
39
+ * Off unless {@link SWC_LOG_LEVEL_ENV_VAR} asks for tracing: `log.mode` governs
40
+ * the purge and minify reporting, which the pipeline emits in Node so the
41
+ * Next.js build reads the same as the Vite one.
42
+ */
43
+ const resolveSwcLogLevel = (intlayerConfig) => {
44
+ if (intlayerConfig.log.mode === "disabled") return "off";
45
+ const requestedLogLevel = process.env[SWC_LOG_LEVEL_ENV_VAR];
46
+ return requestedLogLevel === "info" || requestedLogLevel === "debug" ? requestedLogLevel : "off";
47
+ };
48
+ /**
49
+ * Whether the purge / minify pipeline should run for this build.
50
+ *
51
+ * Compat-adapter callers disable it: their descriptors reach `withIntlayer`
52
+ * only in the SWC plugin's lossy wire format, so the usage analyser would not
53
+ * recognise `useTranslation(...)` & co. and would purge fields those call sites
54
+ * still read.
55
+ */
56
+ const getIsPurgePipelineEnabled = (intlayerConfig, swcExtraCallers, isSwcPluginUsable) => {
57
+ const { purge, minify, optimize } = intlayerConfig.build;
58
+ if (optimize === false) return false;
59
+ if (!purge && !minify) return false;
60
+ if (!isSwcPluginUsable) return false;
61
+ if (swcExtraCallers && swcExtraCallers.length > 0) {
62
+ (0, _intlayer_config_logger.getAppLogger)(intlayerConfig)([
63
+ "Dictionary purge and minification are",
64
+ (0, _intlayer_config_logger.colorize)("disabled", _intlayer_config_colors.GREY_DARK),
65
+ "because compat-adapter callers are configured — their call sites are",
66
+ "not visible to the usage analyser."
67
+ ], { level: "warn" });
68
+ return false;
69
+ }
70
+ return true;
71
+ };
72
+ /**
73
+ * Exports this module needs from `@intlayer/babel`. Checked one by one so a
74
+ * version predating the purge pipeline is rejected like a missing package,
75
+ * instead of failing later with `runIntlayerPurgePipeline is not a function`.
76
+ */
77
+ const REQUIRED_BABEL_EXPORTS = [
78
+ "getPurgePluginOptions",
79
+ "runIntlayerPurgePipeline",
80
+ "serializeFieldRenameMap"
81
+ ];
82
+ /**
83
+ * Lazily loads `@intlayer/babel`, or `null` when it is not installed or too old
84
+ * to expose the purge pipeline.
85
+ */
86
+ const loadIntlayerBabel = (intlayerConfig) => {
87
+ try {
88
+ const intlayerBabel = (intlayerConfig.build?.require ?? (0, _intlayer_config_utils.getProjectRequire)())("@intlayer/babel");
89
+ if (!REQUIRED_BABEL_EXPORTS.every((exportName) => typeof intlayerBabel?.[exportName] === "function")) return null;
90
+ return intlayerBabel;
91
+ } catch {
92
+ return null;
93
+ }
94
+ };
95
+ /**
96
+ * Whether the purge / minify pipeline can run at all, i.e. whether a usable
97
+ * `@intlayer/babel` is resolvable from the project.
98
+ *
99
+ * Used by `withIntlayer` to keep the build report honest: announcing
100
+ * `Dictionary minification enabled` while the pipeline cannot load would describe a
101
+ * pass that never happens.
102
+ */
103
+ const getIsPurgePipelineAvailable = (intlayerConfig) => loadIntlayerBabel(intlayerConfig) !== null;
104
+ /**
105
+ * Runs the purge / minify pipeline and writes the resulting field-rename
106
+ * tables to the cache file so every process of the build reads the same ones.
107
+ */
108
+ const runPurgePipelineOnce = async (intlayerConfig, configOptions, dictionaries, fieldRenameMapFilePath) => {
109
+ const appLogger = (0, _intlayer_config_logger.getAppLogger)(intlayerConfig);
110
+ const intlayerBabel = loadIntlayerBabel(intlayerConfig);
111
+ if (!intlayerBabel) {
112
+ appLogger([
113
+ "Dictionary purge and minification are",
114
+ (0, _intlayer_config_logger.colorize)("disabled", _intlayer_config_colors.GREY_DARK),
115
+ "because",
116
+ (0, _intlayer_config_logger.colorize)("@intlayer/babel", _intlayer_config_colors.GREY_LIGHT),
117
+ "is missing or too old to expose the purge pipeline — install it in",
118
+ "this project to enable them."
119
+ ], { level: "warn" });
120
+ return;
121
+ }
122
+ const { getPurgePluginOptions, runIntlayerPurgePipeline, serializeFieldRenameMap } = intlayerBabel;
123
+ let fieldRenameMap;
124
+ try {
125
+ fieldRenameMap = serializeFieldRenameMap(runIntlayerPurgePipeline(getPurgePluginOptions({
126
+ configOptions,
127
+ dictionaries
128
+ })));
129
+ } catch (pipelineError) {
130
+ appLogger([
131
+ "Dictionary purge and minification",
132
+ (0, _intlayer_config_logger.colorize)("failed", _intlayer_config_colors.RED),
133
+ "— the compiled dictionaries are left untouched.",
134
+ pipelineError instanceof Error ? `(${pipelineError.message})` : String(pipelineError)
135
+ ], { level: "error" });
136
+ return;
137
+ }
138
+ await (0, node_fs_promises.mkdir)((0, node_path.dirname)(fieldRenameMapFilePath), { recursive: true });
139
+ await (0, node_fs_promises.writeFile)(fieldRenameMapFilePath, JSON.stringify(fieldRenameMap), "utf-8");
140
+ };
141
+ /** Reads the cached field-rename tables, or `{}` when none were written. */
142
+ const readFieldRenameMapFile = (fieldRenameMapFilePath) => {
143
+ try {
144
+ return JSON.parse((0, node_fs.readFileSync)(fieldRenameMapFilePath, "utf-8"));
145
+ } catch {
146
+ return {};
147
+ }
148
+ };
149
+ /** Removes the cached field-rename tables, ignoring a missing file. */
150
+ const removeFieldRenameMapFile = (fieldRenameMapFilePath) => {
151
+ try {
152
+ (0, node_fs.rmSync)(fieldRenameMapFilePath, { force: true });
153
+ } catch {}
154
+ };
155
+ /**
156
+ * Prepares the parts of the build optimisation the `@intlayer/swc` plugin
157
+ * cannot do itself, and returns the field-rename tables it needs.
158
+ *
159
+ * Removing unused content fields (`build.purge`) and assigning short field
160
+ * aliases (`build.minify`) require reading every component source file and
161
+ * rewriting the compiled dictionary JSON — file I/O and cross-file state that a
162
+ * per-file Wasm transform has no access to. That analysis therefore runs here,
163
+ * in Node, through `@intlayer/babel`; the plugin only receives the resulting
164
+ * tables and rewrites the matching source accesses
165
+ * (`content.title` → `content.a`).
166
+ *
167
+ * The work is coordinated by a sentinel file: Next.js loads `next.config.*` in
168
+ * several processes per build, and running the minify pass twice would derive
169
+ * the aliases from the already-renamed dictionaries. Processes that lose the
170
+ * race read the tables the winner cached.
171
+ *
172
+ * @returns The field-rename tables, keyed by dictionary key. Empty when the
173
+ * pipeline is disabled, unavailable, or renamed nothing.
174
+ */
175
+ const prepareSwcOptimization = async (intlayerConfig, params) => {
176
+ const { configOptions, dictionaries, swcExtraCallers, isSwcPluginUsable } = params;
177
+ const fieldRenameMapFilePath = getCacheFilePath(intlayerConfig, FIELD_RENAME_MAP_FILE_NAME);
178
+ if (!getIsPurgePipelineEnabled(intlayerConfig, swcExtraCallers, isSwcPluginUsable)) {
179
+ removeFieldRenameMapFile(fieldRenameMapFilePath);
180
+ return {};
181
+ }
182
+ await (0, _intlayer_engine_utils.runOnce)(getCacheFilePath(intlayerConfig, PURGE_SENTINEL_FILE_NAME), () => runPurgePipelineOnce(intlayerConfig, configOptions, dictionaries, fieldRenameMapFilePath), { cacheTimeoutMs: PURGE_CACHE_TIMEOUT_MS });
183
+ return readFieldRenameMapFile(fieldRenameMapFilePath);
184
+ };
185
+
186
+ //#endregion
187
+ exports.getIsPurgePipelineAvailable = getIsPurgePipelineAvailable;
188
+ exports.prepareSwcOptimization = prepareSwcOptimization;
189
+ exports.resolveSwcLogLevel = resolveSwcLogLevel;
190
+ //# sourceMappingURL=prepareSwcOptimization.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareSwcOptimization.cjs","names":["join","colorize","ANSIColors","getProjectRequire","getAppLogger","mkdir","dirname","writeFile","readFileSync","runOnce"],"sources":["../../../src/server/prepareSwcOptimization.ts"],"sourcesContent":["import { readFileSync, rmSync } from 'node:fs';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport type {\n getPurgePluginOptions as GetPurgePluginOptions,\n runIntlayerPurgePipeline as RunIntlayerPurgePipeline,\n SerializedFieldRenameMap,\n serializeFieldRenameMap as SerializeFieldRenameMap,\n} from '@intlayer/babel';\nimport type { SwcExtraCallerConfig } from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { GetConfigurationOptions } from '@intlayer/config/node';\nimport { getProjectRequire } from '@intlayer/config/utils';\nimport { runOnce } from '@intlayer/engine/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\n\n/**\n * Field-rename tables keyed by dictionary key, forwarded to the\n * `@intlayer/swc` plugin's `fieldRenameMap` option.\n */\nexport type FieldRenameMapByDictionaryKey = Record<\n string,\n SerializedFieldRenameMap\n>;\n\n/** Verbosity forwarded to the `@intlayer/swc` plugin's `logLevel` option. */\nexport type SwcLogLevel = 'off' | 'info' | 'debug';\n\n/**\n * Subset of `@intlayer/babel` this module needs. The package is only an\n * optional runtime dependency, so it is required lazily and never imported at\n * module scope.\n */\ntype IntlayerBabelModule = {\n getPurgePluginOptions: typeof GetPurgePluginOptions;\n runIntlayerPurgePipeline: typeof RunIntlayerPurgePipeline;\n serializeFieldRenameMap: typeof SerializeFieldRenameMap;\n};\n\n/**\n * Opt-in to the SWC plugin's per-file tracing.\n *\n * The plugin transforms one file at a time with no cross-file state, so all it\n * can report is a line per file — hundreds of them on a real project, and with\n * no counterpart in the Vite build output. The purge and minify summaries that\n * `log.mode` does control are emitted by the pipeline itself, in Node; this\n * variable is purely a debugging aid on top.\n */\nconst SWC_LOG_LEVEL_ENV_VAR = 'INTLAYER_SWC_LOG_LEVEL';\n\n/** Sentinel coordinating the pipeline across the processes of one build. */\nconst PURGE_SENTINEL_FILE_NAME = 'intlayer-swc-purge.lock';\n\n/** Where the serialised field-rename tables are cached between processes. */\nconst FIELD_RENAME_MAP_FILE_NAME = 'swc-field-rename-map.json';\n\n/**\n * Next.js evaluates `next.config.*` in the main build process and again in each\n * Turbopack/webpack worker. The dictionary rewrite must happen exactly once —\n * a second run would derive the short aliases from the already-renamed JSON —\n * so the sentinel window has to cover a whole build startup.\n */\nconst PURGE_CACHE_TIMEOUT_MS = 30 * 1000;\n\n/** Absolute path of a file in the intlayer cache directory. */\nconst getCacheFilePath = (\n intlayerConfig: IntlayerConfig,\n fileName: string\n): string =>\n join(intlayerConfig.system.baseDir, '.intlayer', 'cache', fileName);\n\n/**\n * Resolves the verbosity the `@intlayer/swc` plugin should report at.\n *\n * Off unless {@link SWC_LOG_LEVEL_ENV_VAR} asks for tracing: `log.mode` governs\n * the purge and minify reporting, which the pipeline emits in Node so the\n * Next.js build reads the same as the Vite one.\n */\nexport const resolveSwcLogLevel = (\n intlayerConfig: IntlayerConfig\n): SwcLogLevel => {\n if (intlayerConfig.log.mode === 'disabled') return 'off';\n\n const requestedLogLevel = process.env[SWC_LOG_LEVEL_ENV_VAR];\n\n return requestedLogLevel === 'info' || requestedLogLevel === 'debug'\n ? requestedLogLevel\n : 'off';\n};\n\n/**\n * Whether the purge / minify pipeline should run for this build.\n *\n * Compat-adapter callers disable it: their descriptors reach `withIntlayer`\n * only in the SWC plugin's lossy wire format, so the usage analyser would not\n * recognise `useTranslation(...)` & co. and would purge fields those call sites\n * still read.\n */\nconst getIsPurgePipelineEnabled = (\n intlayerConfig: IntlayerConfig,\n swcExtraCallers: SwcExtraCallerConfig[] | undefined,\n isSwcPluginUsable: boolean\n): boolean => {\n const { purge, minify, optimize } = intlayerConfig.build;\n\n if (optimize === false) return false;\n if (!purge && !minify) return false;\n\n // The pipeline rewrites the compiled dictionaries in place — dropping unused\n // fields and renaming the rest to short aliases. Only the SWC plugin rewrites\n // the matching source accesses, so running this without it would ship\n // dictionaries whose keys no longer match the code reading them.\n if (!isSwcPluginUsable) return false;\n\n // `editor.enabled` is deliberately not checked here: the pipeline stands down\n // on its own and explains why, the same way the Vite build does.\n\n if (swcExtraCallers && swcExtraCallers.length > 0) {\n getAppLogger(intlayerConfig)(\n [\n 'Dictionary purge and minification are',\n colorize('disabled', ANSIColors.GREY_DARK),\n 'because compat-adapter callers are configured — their call sites are',\n 'not visible to the usage analyser.',\n ],\n { level: 'warn' }\n );\n return false;\n }\n\n return true;\n};\n\n/**\n * Exports this module needs from `@intlayer/babel`. Checked one by one so a\n * version predating the purge pipeline is rejected like a missing package,\n * instead of failing later with `runIntlayerPurgePipeline is not a function`.\n */\nconst REQUIRED_BABEL_EXPORTS = [\n 'getPurgePluginOptions',\n 'runIntlayerPurgePipeline',\n 'serializeFieldRenameMap',\n] as const satisfies readonly (keyof IntlayerBabelModule)[];\n\n/**\n * Lazily loads `@intlayer/babel`, or `null` when it is not installed or too old\n * to expose the purge pipeline.\n */\nconst loadIntlayerBabel = (\n intlayerConfig: IntlayerConfig\n): IntlayerBabelModule | null => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n\n const intlayerBabel = requireFunction(\n '@intlayer/babel'\n ) as Partial<IntlayerBabelModule>;\n\n const hasEveryRequiredExport = REQUIRED_BABEL_EXPORTS.every(\n (exportName) => typeof intlayerBabel?.[exportName] === 'function'\n );\n\n if (!hasEveryRequiredExport) return null;\n\n return intlayerBabel as IntlayerBabelModule;\n } catch {\n return null;\n }\n};\n\n/**\n * Whether the purge / minify pipeline can run at all, i.e. whether a usable\n * `@intlayer/babel` is resolvable from the project.\n *\n * Used by `withIntlayer` to keep the build report honest: announcing\n * `Dictionary minification enabled` while the pipeline cannot load would describe a\n * pass that never happens.\n */\nexport const getIsPurgePipelineAvailable = (\n intlayerConfig: IntlayerConfig\n): boolean => loadIntlayerBabel(intlayerConfig) !== null;\n\n/**\n * Runs the purge / minify pipeline and writes the resulting field-rename\n * tables to the cache file so every process of the build reads the same ones.\n */\nconst runPurgePipelineOnce = async (\n intlayerConfig: IntlayerConfig,\n configOptions: GetConfigurationOptions | undefined,\n dictionaries: Dictionary[] | undefined,\n fieldRenameMapFilePath: string\n): Promise<void> => {\n const appLogger = getAppLogger(intlayerConfig);\n\n const intlayerBabel = loadIntlayerBabel(intlayerConfig);\n\n if (!intlayerBabel) {\n // Not verbose: the build asked for purge / minify and is silently getting\n // neither, which is exactly the kind of thing a default build must report.\n appLogger(\n [\n 'Dictionary purge and minification are',\n colorize('disabled', ANSIColors.GREY_DARK),\n 'because',\n colorize('@intlayer/babel', ANSIColors.GREY_LIGHT),\n 'is missing or too old to expose the purge pipeline — install it in',\n 'this project to enable them.',\n ],\n { level: 'warn' }\n );\n return;\n }\n\n const {\n getPurgePluginOptions,\n runIntlayerPurgePipeline,\n serializeFieldRenameMap,\n } = intlayerBabel;\n\n // `runOnce` discards whatever this callback throws, so a pipeline failure\n // would otherwise leave the build with no dictionaries rewritten and no\n // explanation of why.\n let fieldRenameMap: FieldRenameMapByDictionaryKey;\n\n try {\n // The pipeline reports what it purged and minified through the intlayer\n // logger, matching the Vite build output.\n const pruneContext = runIntlayerPurgePipeline(\n getPurgePluginOptions({ configOptions, dictionaries })\n );\n\n fieldRenameMap = serializeFieldRenameMap(pruneContext);\n } catch (pipelineError) {\n appLogger(\n [\n 'Dictionary purge and minification',\n colorize('failed', ANSIColors.RED),\n '— the compiled dictionaries are left untouched.',\n pipelineError instanceof Error\n ? `(${pipelineError.message})`\n : String(pipelineError),\n ],\n { level: 'error' }\n );\n return;\n }\n\n await mkdir(dirname(fieldRenameMapFilePath), { recursive: true });\n await writeFile(\n fieldRenameMapFilePath,\n JSON.stringify(fieldRenameMap),\n 'utf-8'\n );\n};\n\n/** Reads the cached field-rename tables, or `{}` when none were written. */\nconst readFieldRenameMapFile = (\n fieldRenameMapFilePath: string\n): FieldRenameMapByDictionaryKey => {\n try {\n return JSON.parse(\n readFileSync(fieldRenameMapFilePath, 'utf-8')\n ) as FieldRenameMapByDictionaryKey;\n } catch {\n return {};\n }\n};\n\n/** Removes the cached field-rename tables, ignoring a missing file. */\nconst removeFieldRenameMapFile = (fieldRenameMapFilePath: string): void => {\n try {\n rmSync(fieldRenameMapFilePath, { force: true });\n } catch {\n // Nothing to clean up.\n }\n};\n\ntype PrepareSwcOptimizationParams = {\n /** Options forwarded to the intlayer configuration loader. */\n configOptions?: GetConfigurationOptions;\n /** Pre-loaded dictionaries, to avoid a second `getDictionaries` call. */\n dictionaries?: Dictionary[];\n /** Compat-adapter callers declared by the consuming plugin, if any. */\n swcExtraCallers?: SwcExtraCallerConfig[];\n /**\n * Whether the `@intlayer/swc` plugin is installed *and* the resolved Next.js\n * version can load it. False leaves the compiled dictionaries untouched.\n */\n isSwcPluginUsable: boolean;\n};\n\n/**\n * Prepares the parts of the build optimisation the `@intlayer/swc` plugin\n * cannot do itself, and returns the field-rename tables it needs.\n *\n * Removing unused content fields (`build.purge`) and assigning short field\n * aliases (`build.minify`) require reading every component source file and\n * rewriting the compiled dictionary JSON — file I/O and cross-file state that a\n * per-file Wasm transform has no access to. That analysis therefore runs here,\n * in Node, through `@intlayer/babel`; the plugin only receives the resulting\n * tables and rewrites the matching source accesses\n * (`content.title` → `content.a`).\n *\n * The work is coordinated by a sentinel file: Next.js loads `next.config.*` in\n * several processes per build, and running the minify pass twice would derive\n * the aliases from the already-renamed dictionaries. Processes that lose the\n * race read the tables the winner cached.\n *\n * @returns The field-rename tables, keyed by dictionary key. Empty when the\n * pipeline is disabled, unavailable, or renamed nothing.\n */\nexport const prepareSwcOptimization = async (\n intlayerConfig: IntlayerConfig,\n params: PrepareSwcOptimizationParams\n): Promise<FieldRenameMapByDictionaryKey> => {\n const { configOptions, dictionaries, swcExtraCallers, isSwcPluginUsable } =\n params;\n\n const fieldRenameMapFilePath = getCacheFilePath(\n intlayerConfig,\n FIELD_RENAME_MAP_FILE_NAME\n );\n\n // A stale file from an earlier build would rename source accesses that the\n // dictionaries no longer match.\n if (\n !getIsPurgePipelineEnabled(\n intlayerConfig,\n swcExtraCallers,\n isSwcPluginUsable\n )\n ) {\n removeFieldRenameMapFile(fieldRenameMapFilePath);\n return {};\n }\n\n await runOnce(\n getCacheFilePath(intlayerConfig, PURGE_SENTINEL_FILE_NAME),\n () =>\n runPurgePipelineOnce(\n intlayerConfig,\n configOptions,\n dictionaries,\n fieldRenameMapFilePath\n ),\n { cacheTimeoutMs: PURGE_CACHE_TIMEOUT_MS }\n );\n\n return readFieldRenameMapFile(fieldRenameMapFilePath);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkDA,MAAM,wBAAwB;;AAG9B,MAAM,2BAA2B;;AAGjC,MAAM,6BAA6B;;;;;;;AAQnC,MAAM,yBAAyB;;AAG/B,MAAM,oBACJ,gBACA,iBAEAA,gBAAK,eAAe,OAAO,SAAS,aAAa,SAAS,QAAQ;;;;;;;;AASpE,MAAa,sBACX,mBACgB;CAChB,IAAI,eAAe,IAAI,SAAS,YAAY,OAAO;CAEnD,MAAM,oBAAoB,QAAQ,IAAI;CAEtC,OAAO,sBAAsB,UAAU,sBAAsB,UACzD,oBACA;AACN;;;;;;;;;AAUA,MAAM,6BACJ,gBACA,iBACA,sBACY;CACZ,MAAM,EAAE,OAAO,QAAQ,aAAa,eAAe;CAEnD,IAAI,aAAa,OAAO,OAAO;CAC/B,IAAI,CAAC,SAAS,CAAC,QAAQ,OAAO;CAM9B,IAAI,CAAC,mBAAmB,OAAO;CAK/B,IAAI,mBAAmB,gBAAgB,SAAS,GAAG;EACjD,0CAAa,cAAc,CAAC,CAC1B;GACE;OACAC,kCAAS,YAAYC,wBAAW,SAAS;GACzC;GACA;EACF,GACA,EAAE,OAAO,OAAO,CAClB;EACA,OAAO;CACT;CAEA,OAAO;AACT;;;;;;AAOA,MAAM,yBAAyB;CAC7B;CACA;CACA;AACF;;;;;AAMA,MAAM,qBACJ,mBAC+B;CAC/B,IAAI;EAIF,MAAM,iBAFJ,eAAe,OAAO,eAAWC,0CAAkB,EAEhB,CACnC,iBACF;EAMA,IAAI,CAJ2B,uBAAuB,OACnD,eAAe,OAAO,gBAAgB,gBAAgB,UAG/B,GAAG,OAAO;EAEpC,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;AAUA,MAAa,+BACX,mBACY,kBAAkB,cAAc,MAAM;;;;;AAMpD,MAAM,uBAAuB,OAC3B,gBACA,eACA,cACA,2BACkB;CAClB,MAAM,gBAAYC,sCAAa,cAAc;CAE7C,MAAM,gBAAgB,kBAAkB,cAAc;CAEtD,IAAI,CAAC,eAAe;EAGlB,UACE;GACE;OACAH,kCAAS,YAAYC,wBAAW,SAAS;GACzC;OACAD,kCAAS,mBAAmBC,wBAAW,UAAU;GACjD;GACA;EACF,GACA,EAAE,OAAO,OAAO,CAClB;EACA;CACF;CAEA,MAAM,EACJ,uBACA,0BACA,4BACE;CAKJ,IAAI;CAEJ,IAAI;EAOF,iBAAiB,wBAJI,yBACnB,sBAAsB;GAAE;GAAe;EAAa,CAAC,CAGH,CAAC;CACvD,SAAS,eAAe;EACtB,UACE;GACE;OACAD,kCAAS,UAAUC,wBAAW,GAAG;GACjC;GACA,yBAAyB,QACrB,IAAI,cAAc,QAAQ,KAC1B,OAAO,aAAa;EAC1B,GACA,EAAE,OAAO,QAAQ,CACnB;EACA;CACF;CAEA,UAAMG,4BAAMC,mBAAQ,sBAAsB,GAAG,EAAE,WAAW,KAAK,CAAC;CAChE,UAAMC,4BACJ,wBACA,KAAK,UAAU,cAAc,GAC7B,OACF;AACF;;AAGA,MAAM,0BACJ,2BACkC;CAClC,IAAI;EACF,OAAO,KAAK,UACVC,sBAAa,wBAAwB,OAAO,CAC9C;CACF,QAAQ;EACN,OAAO,CAAC;CACV;AACF;;AAGA,MAAM,4BAA4B,2BAAyC;CACzE,IAAI;EACF,oBAAO,wBAAwB,EAAE,OAAO,KAAK,CAAC;CAChD,QAAQ,CAER;AACF;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,yBAAyB,OACpC,gBACA,WAC2C;CAC3C,MAAM,EAAE,eAAe,cAAc,iBAAiB,sBACpD;CAEF,MAAM,yBAAyB,iBAC7B,gBACA,0BACF;CAIA,IACE,CAAC,0BACC,gBACA,iBACA,iBACF,GACA;EACA,yBAAyB,sBAAsB;EAC/C,OAAO,CAAC;CACV;CAEA,UAAMC,gCACJ,iBAAiB,gBAAgB,wBAAwB,SAEvD,qBACE,gBACA,eACA,cACA,sBACF,GACF,EAAE,gBAAgB,uBAAuB,CAC3C;CAEA,OAAO,uBAAuB,sBAAsB;AACtD"}
@@ -0,0 +1,57 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _intlayer_config_utils = require("@intlayer/config/utils");
3
+
4
+ //#region src/server/swcPluginCompatibility.ts
5
+ /**
6
+ * Oldest Next.js release whose bundled SWC can load the `@intlayer/swc` Wasm
7
+ * plugin.
8
+ *
9
+ * A Wasm plugin only loads in a host that speaks its `swc_ecma_ast` schema.
10
+ * Next.js 16.1.0 is the first release built on SWC's forward-compatible plugin
11
+ * ABI — the AST travels as self-describing CBOR instead of rkyv, so a plugin
12
+ * compiled against an older `swc_core` keeps loading in newer hosts. Every
13
+ * earlier release uses the rkyv ABI, which requires an exact schema match and
14
+ * rejects the plugin outright, failing the build with `failed to invoke
15
+ * plugin`.
16
+ *
17
+ * Verified by driving `transformSync` on the shipped `@next/swc` binaries with
18
+ * the plugin attached:
19
+ *
20
+ * | Next.js | swc_ecma_ast | plugin loads |
21
+ * | ------- | ------------ | ------------ |
22
+ * | 14.2.x | 0.112.7 | no |
23
+ * | 15.5.x | 14.0.0 | no |
24
+ * | 16.0.x | 16.0.0 | no |
25
+ * | 16.1.x | 19.0.0 | yes |
26
+ * | 16.2.x | 20.0.1 | yes |
27
+ * | 16.3.x | 25.0.0 | yes |
28
+ *
29
+ * Keep in sync with the `swc_core` pin in
30
+ * `packages/@intlayer/swc/Cargo.toml`: the plugin must stay on the
31
+ * `swc_ecma_ast` version this Next.js release ships, never a newer one, or the
32
+ * floor moves up with it.
33
+ */
34
+ const MINIMUM_SWC_PLUGIN_NEXT_VERSION = "16.1.0";
35
+ /**
36
+ * Whether `nextVersion` bundles an SWC able to load the `@intlayer/swc` Wasm
37
+ * plugin.
38
+ *
39
+ * Pre-releases of a supported version (`16.1.0-canary.4`, `16.3.0-preview.5`)
40
+ * count as supported: they track the release they lead to, and opting into a
41
+ * canary already means opting into its churn.
42
+ *
43
+ * @param nextVersion - Version string read from the project's `next/package.json`.
44
+ * @returns `true` when the plugin can be registered in `experimental.swcPlugins`.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * getIsSwcPluginSupported('16.3.0'); // true
49
+ * getIsSwcPluginSupported('15.5.18'); // false
50
+ * ```
51
+ */
52
+ const getIsSwcPluginSupported = (nextVersion) => (0, _intlayer_config_utils.compareVersions)(nextVersion, "≥", MINIMUM_SWC_PLUGIN_NEXT_VERSION);
53
+
54
+ //#endregion
55
+ exports.MINIMUM_SWC_PLUGIN_NEXT_VERSION = MINIMUM_SWC_PLUGIN_NEXT_VERSION;
56
+ exports.getIsSwcPluginSupported = getIsSwcPluginSupported;
57
+ //# sourceMappingURL=swcPluginCompatibility.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swcPluginCompatibility.cjs","names":["compareVersions"],"sources":["../../../src/server/swcPluginCompatibility.ts"],"sourcesContent":["import { compareVersions } from '@intlayer/config/utils';\n\n/**\n * Oldest Next.js release whose bundled SWC can load the `@intlayer/swc` Wasm\n * plugin.\n *\n * A Wasm plugin only loads in a host that speaks its `swc_ecma_ast` schema.\n * Next.js 16.1.0 is the first release built on SWC's forward-compatible plugin\n * ABI — the AST travels as self-describing CBOR instead of rkyv, so a plugin\n * compiled against an older `swc_core` keeps loading in newer hosts. Every\n * earlier release uses the rkyv ABI, which requires an exact schema match and\n * rejects the plugin outright, failing the build with `failed to invoke\n * plugin`.\n *\n * Verified by driving `transformSync` on the shipped `@next/swc` binaries with\n * the plugin attached:\n *\n * | Next.js | swc_ecma_ast | plugin loads |\n * | ------- | ------------ | ------------ |\n * | 14.2.x | 0.112.7 | no |\n * | 15.5.x | 14.0.0 | no |\n * | 16.0.x | 16.0.0 | no |\n * | 16.1.x | 19.0.0 | yes |\n * | 16.2.x | 20.0.1 | yes |\n * | 16.3.x | 25.0.0 | yes |\n *\n * Keep in sync with the `swc_core` pin in\n * `packages/@intlayer/swc/Cargo.toml`: the plugin must stay on the\n * `swc_ecma_ast` version this Next.js release ships, never a newer one, or the\n * floor moves up with it.\n */\nexport const MINIMUM_SWC_PLUGIN_NEXT_VERSION = '16.1.0';\n\n/**\n * Whether `nextVersion` bundles an SWC able to load the `@intlayer/swc` Wasm\n * plugin.\n *\n * Pre-releases of a supported version (`16.1.0-canary.4`, `16.3.0-preview.5`)\n * count as supported: they track the release they lead to, and opting into a\n * canary already means opting into its churn.\n *\n * @param nextVersion - Version string read from the project's `next/package.json`.\n * @returns `true` when the plugin can be registered in `experimental.swcPlugins`.\n *\n * @example\n * ```ts\n * getIsSwcPluginSupported('16.3.0'); // true\n * getIsSwcPluginSupported('15.5.18'); // false\n * ```\n */\nexport const getIsSwcPluginSupported = (nextVersion: string): boolean =>\n compareVersions(nextVersion, '≥', MINIMUM_SWC_PLUGIN_NEXT_VERSION);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,kCAAkC;;;;;;;;;;;;;;;;;;AAmB/C,MAAa,2BAA2B,oBACtCA,wCAAgB,aAAa,KAAK,+BAA+B"}
@@ -10,7 +10,8 @@ let react_intlayer_server = require("react-intlayer/server");
10
10
  * If the locale is not provided, it will use the locale from the server context.
11
11
  */
12
12
  const useDictionary = (dictionary, localeOrSelector) => {
13
- return (0, react_intlayer_server.useDictionary)(dictionary, localeOrSelector, require_server_useIntlayer.safeUseLocale());
13
+ const storedLocale = require_server_useIntlayer.safeUseLocale();
14
+ return (0, react_intlayer_server.useDictionary)(dictionary, localeOrSelector, storedLocale);
14
15
  };
15
16
 
16
17
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionary.cjs","names":["safeUseLocale"],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useDictionary as useDictionaryBase } from 'react-intlayer/server';\nimport { safeUseLocale } from './useIntlayer';\n\n/**\n * On the server side, hook that transforms a dictionary (or qualified\n * dictionary group) and returns the content for the given locale or selector.\n *\n * If the locale is not provided, it will use the locale from the server context.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): ReturnType<typeof useDictionaryBase<T, A>> => {\n const storedLocale = safeUseLocale();\n\n return useDictionaryBase<T, A>(dictionary, localeOrSelector, storedLocale);\n};\n"],"mappings":";;;;;;;;;;;AAmBA,MAAa,iBAMX,YACA,qBAC+C;CAG/C,gDAA+B,YAAY,kBAFtBA,yCAEmD,CAAC;AAC3E"}
1
+ {"version":3,"file":"useDictionary.cjs","names":["safeUseLocale","useDictionaryBase"],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelector,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useDictionary as useDictionaryBase } from 'react-intlayer/server';\nimport { safeUseLocale } from './useIntlayer';\n\n/**\n * On the server side, hook that transforms a dictionary (or qualified\n * dictionary group) and returns the content for the given locale or selector.\n *\n * If the locale is not provided, it will use the locale from the server context.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): ReturnType<typeof useDictionaryBase<T, A>> => {\n const storedLocale = safeUseLocale();\n\n return useDictionaryBase<T, A>(dictionary, localeOrSelector, storedLocale);\n};\n"],"mappings":";;;;;;;;;;;AAmBA,MAAa,iBAMX,YACA,qBAC+C;CAC/C,MAAM,eAAeA,yCAAc;CAEnC,WAAOC,qCAAwB,YAAY,kBAAkB,YAAY;AAC3E"}
@@ -9,7 +9,8 @@ let react_intlayer_server = require("react-intlayer/server");
9
9
  * If the locale is not provided, it will use the locale from the server context
10
10
  */
11
11
  const useDictionaryAsync = async (dictionaryPromise, locale) => {
12
- return (0, react_intlayer_server.useDictionaryAsync)(dictionaryPromise, locale, await require_server_getLocale.getLocale());
12
+ const storedLocale = await require_server_getLocale.getLocale();
13
+ return (0, react_intlayer_server.useDictionaryAsync)(dictionaryPromise, locale, storedLocale);
13
14
  };
14
15
 
15
16
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionaryAsync.cjs","names":["getLocale"],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useDictionaryAsync as useDictionaryAsyncBase } from 'react-intlayer/server';\nimport { getLocale } from './getLocale';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <\n const T extends Dictionary,\n const L extends DeclaredLocales = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\n): ReturnType<typeof useDictionaryAsyncBase<T, L>> => {\n const storedLocale = await getLocale();\n\n return useDictionaryAsyncBase<T, L>(dictionaryPromise, locale, storedLocale);\n};\n"],"mappings":";;;;;;;;;;AAaA,MAAa,qBAAqB,OAIhC,mBACA,WACoD;CAGpD,qDAAoC,mBAAmB,QAAQ,MAFpCA,mCAAU,CAEsC;AAC7E"}
1
+ {"version":3,"file":"useDictionaryAsync.cjs","names":["getLocale","useDictionaryAsyncBase"],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useDictionaryAsync as useDictionaryAsyncBase } from 'react-intlayer/server';\nimport { getLocale } from './getLocale';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <\n const T extends Dictionary,\n const L extends DeclaredLocales = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\n): ReturnType<typeof useDictionaryAsyncBase<T, L>> => {\n const storedLocale = await getLocale();\n\n return useDictionaryAsyncBase<T, L>(dictionaryPromise, locale, storedLocale);\n};\n"],"mappings":";;;;;;;;;;AAaA,MAAa,qBAAqB,OAIhC,mBACA,WACoD;CACpD,MAAM,eAAe,MAAMA,mCAAU;CAErC,WAAOC,0CAA6B,mBAAmB,QAAQ,YAAY;AAC7E"}
@@ -10,7 +10,8 @@ let react_intlayer_server = require("react-intlayer/server");
10
10
  * If the locale is not provided, it will use the locale from the server context.
11
11
  */
12
12
  const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
13
- return (0, react_intlayer_server.useDictionaryDynamic)(dictionaryPromise, key, localeOrSelector, require_server_useIntlayer.safeUseLocale());
13
+ const storedLocale = require_server_useIntlayer.safeUseLocale();
14
+ return (0, react_intlayer_server.useDictionaryDynamic)(dictionaryPromise, key, localeOrSelector, storedLocale);
14
15
  };
15
16
 
16
17
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionaryDynamic.cjs","names":["safeUseLocale"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import type { QualifiedDynamicLoaderMap } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useDictionaryDynamic as useDictionaryDynamicBase } from 'react-intlayer/server';\nimport { safeUseLocale } from './useIntlayer';\n\n/**\n * On the server side, hook that lazily loads a dictionary (plain or qualified)\n * and returns the content for the given locale or selector.\n *\n * If the locale is not provided, it will use the locale from the server context.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A\n): ReturnType<typeof useDictionaryDynamicBase<T, A>> => {\n const storedLocale = safeUseLocale();\n\n return useDictionaryDynamicBase<T, A>(\n dictionaryPromise,\n key,\n localeOrSelector,\n storedLocale\n );\n};\n"],"mappings":";;;;;;;;;;;AAmBA,MAAa,wBAIX,mBAGA,KACA,qBACsD;CAGtD,uDACE,mBACA,KACA,kBALmBA,yCAMR,CACb;AACF"}
1
+ {"version":3,"file":"useDictionaryDynamic.cjs","names":["safeUseLocale","useDictionaryDynamicBase"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import type { QualifiedDynamicLoaderMap } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useDictionaryDynamic as useDictionaryDynamicBase } from 'react-intlayer/server';\nimport { safeUseLocale } from './useIntlayer';\n\n/**\n * On the server side, hook that lazily loads a dictionary (plain or qualified)\n * and returns the content for the given locale or selector.\n *\n * If the locale is not provided, it will use the locale from the server context.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A\n): ReturnType<typeof useDictionaryDynamicBase<T, A>> => {\n const storedLocale = safeUseLocale();\n\n return useDictionaryDynamicBase<T, A>(\n dictionaryPromise,\n key,\n localeOrSelector,\n storedLocale\n );\n};\n"],"mappings":";;;;;;;;;;;AAmBA,MAAa,wBAIX,mBAGA,KACA,qBACsD;CACtD,MAAM,eAAeA,yCAAc;CAEnC,WAAOC,4CACL,mBACA,KACA,kBACA,YACF;AACF"}
@@ -23,7 +23,8 @@ const safeUseLocale = () => {
23
23
  * If the locale is not provided, it will use the locale from the server context.
24
24
  */
25
25
  const useIntlayer = (key, localeOrSelector) => {
26
- return (0, react_intlayer_server.useIntlayer)(key, localeOrSelector, safeUseLocale());
26
+ const storedLocale = safeUseLocale();
27
+ return (0, react_intlayer_server.useIntlayer)(key, localeOrSelector, storedLocale);
27
28
  };
28
29
 
29
30
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"useIntlayer.cjs","names":["React","getLocale"],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport React from 'react';\nimport { useIntlayer as useIntlayerBase } from 'react-intlayer/server';\nimport { getLocale } from './getLocale';\n\nconst getCachedLocale =\n typeof React.cache === 'function' ? React.cache(getLocale) : getLocale;\n\nexport const safeUseLocale = (): Locale | undefined => {\n // getLocale returns a Promise based on your TS error\n const localeData = getCachedLocale() as Promise<Locale> | Locale;\n\n if (localeData instanceof Promise) {\n if (typeof React.use === 'function') {\n return React.use(localeData); // Safely unwraps in React 19+\n }\n\n // React < 19 cannot synchronously unwrap Promises in hooks.\n // Return undefined to trigger the localeTarget fallback.\n return undefined;\n }\n\n return localeData;\n};\n\n/**\n * On the server side, hook that picks one dictionary by its key and returns the\n * content for the given locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n *\n * If the locale is not provided, it will use the locale from the server context.\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): ReturnType<typeof useIntlayerBase<T, A>> => {\n const storedLocale = safeUseLocale();\n\n return useIntlayerBase<T, A>(key, localeOrSelector, storedLocale);\n};\n"],"mappings":";;;;;;;;AAWA,MAAM,kBACJ,OAAOA,cAAM,UAAU,aAAaA,cAAM,MAAMC,kCAAS,IAAIA;AAE/D,MAAa,sBAA0C;CAErD,MAAM,aAAa,gBAAgB;CAEnC,IAAI,sBAAsB,SAAS;EACjC,IAAI,OAAOD,cAAM,QAAQ,YACvB,OAAOA,cAAM,IAAI,UAAU;EAK7B;CACF;CAEA,OAAO;AACT;;;;;;;;AASA,MAAa,eAIX,KACA,qBAC6C;CAG7C,8CAA6B,KAAK,kBAFb,cAE0C,CAAC;AAClE"}
1
+ {"version":3,"file":"useIntlayer.cjs","names":["React","getLocale","useIntlayerBase"],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport React from 'react';\nimport { useIntlayer as useIntlayerBase } from 'react-intlayer/server';\nimport { getLocale } from './getLocale';\n\nconst getCachedLocale =\n typeof React.cache === 'function' ? React.cache(getLocale) : getLocale;\n\nexport const safeUseLocale = (): Locale | undefined => {\n // getLocale returns a Promise based on your TS error\n const localeData = getCachedLocale() as Promise<Locale> | Locale;\n\n if (localeData instanceof Promise) {\n if (typeof React.use === 'function') {\n return React.use(localeData); // Safely unwraps in React 19+\n }\n\n // React < 19 cannot synchronously unwrap Promises in hooks.\n // Return undefined to trigger the localeTarget fallback.\n return undefined;\n }\n\n return localeData;\n};\n\n/**\n * On the server side, hook that picks one dictionary by its key and returns the\n * content for the given locale or selector (`{ item }`, `{ variant }`,\n * optionally combined with `locale`).\n *\n * If the locale is not provided, it will use the locale from the server context.\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): ReturnType<typeof useIntlayerBase<T, A>> => {\n const storedLocale = safeUseLocale();\n\n return useIntlayerBase<T, A>(key, localeOrSelector, storedLocale);\n};\n"],"mappings":";;;;;;;;AAWA,MAAM,kBACJ,OAAOA,cAAM,UAAU,aAAaA,cAAM,MAAMC,kCAAS,IAAIA;AAE/D,MAAa,sBAA0C;CAErD,MAAM,aAAa,gBAAgB;CAEnC,IAAI,sBAAsB,SAAS;EACjC,IAAI,OAAOD,cAAM,QAAQ,YACvB,OAAOA,cAAM,IAAI,UAAU;EAK7B;CACF;CAEA,OAAO;AACT;;;;;;;;AASA,MAAa,eAIX,KACA,qBAC6C;CAC7C,MAAM,eAAe,cAAc;CAEnC,WAAOE,mCAAsB,KAAK,kBAAkB,YAAY;AAClE"}
@@ -1,5 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_server_prepareSwcOptimization = require('./prepareSwcOptimization.cjs');
4
+ const require_server_swcPluginCompatibility = require('./swcPluginCompatibility.cjs');
3
5
  let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
4
6
  let node_path = require("node:path");
5
7
  let _intlayer_config_colors = require("@intlayer/config/colors");
@@ -8,6 +10,7 @@ let _intlayer_config_envVars = require("@intlayer/config/envVars");
8
10
  let _intlayer_config_logger = require("@intlayer/config/logger");
9
11
  let _intlayer_config_node = require("@intlayer/config/node");
10
12
  let _intlayer_config_utils = require("@intlayer/config/utils");
13
+ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
11
14
  let _intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
12
15
  let _intlayer_engine_build = require("@intlayer/engine/build");
13
16
  let _intlayer_engine_cli = require("@intlayer/engine/cli");
@@ -29,10 +32,16 @@ const getNextVersionFlags = (intlayerConfig) => {
29
32
  nextVersion = (intlayerConfig.build?.require ?? (0, _intlayer_config_utils.getProjectRequire)())("next/package.json").version;
30
33
  } catch {}
31
34
  return {
35
+ nextVersion,
32
36
  isGteNext13: (0, _intlayer_config_utils.compareVersions)(nextVersion, "≥", "13.0.0"),
33
37
  isGteNext15: (0, _intlayer_config_utils.compareVersions)(nextVersion, "≥", "15.0.0"),
34
38
  isGteNext16: (0, _intlayer_config_utils.compareVersions)(nextVersion, "≥", "16.0.0"),
35
- isTurbopackStable: (0, _intlayer_config_utils.compareVersions)(nextVersion, "≥", "15.3.0")
39
+ isTurbopackStable: (0, _intlayer_config_utils.compareVersions)(nextVersion, "≥", "15.3.0"),
40
+ /**
41
+ * Whether this Next.js release can load the `@intlayer/swc` Wasm plugin.
42
+ * See {@link MINIMUM_SWC_PLUGIN_NEXT_VERSION}.
43
+ */
44
+ isSwcPluginSupported: require_server_swcPluginCompatibility.getIsSwcPluginSupported(nextVersion)
36
45
  };
37
46
  };
38
47
  const getIsSwcPluginAvailable = (intlayerConfig) => {
@@ -56,8 +65,9 @@ const resolvePluginPath = (pluginPath, intlayerConfig, isTurbopackEnabled) => {
56
65
  if (isTurbopackEnabled) return (0, _intlayer_config_utils.normalizePath)(`./${(0, node_path.relative)(process.cwd(), pluginPathResolved)}`);
57
66
  return pluginPathResolved;
58
67
  };
59
- const getPruneConfig = (intlayerConfig, isBuildCommand, isTurbopackEnabled, isDevCommand, isGteNext13, swcExtraCallers) => {
60
- const { optimize } = intlayerConfig.build;
68
+ const getPruneConfig = ({ intlayerConfig, isBuildCommand, isTurbopackEnabled, isDevCommand, isGteNext13, isSwcPluginSupported, nextVersion, swcExtraCallers, fieldRenameMap }) => {
69
+ const { optimize, minify, purge } = intlayerConfig.build;
70
+ const editorEnabled = intlayerConfig.editor.enabled;
61
71
  const importMode = intlayerConfig.build.importMode ?? intlayerConfig.dictionary?.importMode;
62
72
  const { dictionariesDir, unmergedDictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, mainDir } = intlayerConfig.system;
63
73
  const { baseDir } = intlayerConfig.system;
@@ -67,28 +77,39 @@ const getPruneConfig = (intlayerConfig, isBuildCommand, isTurbopackEnabled, isDe
67
77
  if (!isGteNext13) return {};
68
78
  const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);
69
79
  (0, _intlayer_engine_utils.runOnce)((0, node_path.join)(baseDir, ".intlayer", "cache", "intlayer-prune-plugin-enabled.lock"), () => {
70
- if (isSwcPluginAvailable) logger([
71
- `Build optimization ${(0, _intlayer_config_logger.colorize)("enabled", _intlayer_config_colors.GREEN)}`,
72
- (0, _intlayer_config_logger.colorize)(`(import mode:`, _intlayer_config_colors.GREY_DARK),
73
- (0, _intlayer_config_logger.colorize)(importMode ?? _intlayer_config_defaultValues.IMPORT_MODE, _intlayer_config_colors.BLUE),
74
- (0, _intlayer_config_logger.colorize)(`)`, _intlayer_config_colors.GREY_DARK)
75
- ]);
76
- else logger([
80
+ if (isSwcPluginAvailable && !isSwcPluginSupported) logger([
81
+ `Build optimization ${(0, _intlayer_config_logger.colorize)("disabled", _intlayer_config_colors.GREY_DARK)}:`,
82
+ (0, _intlayer_config_logger.colorize)("@intlayer/swc", _intlayer_config_colors.GREY_LIGHT),
83
+ (0, _intlayer_config_logger.colorize)(`cannot run on Next.js ${nextVersion} — its bundled SWC predates the`, _intlayer_config_colors.GREY),
84
+ (0, _intlayer_config_logger.colorize)("stable Wasm plugin ABI. Upgrade to Next.js", _intlayer_config_colors.GREY),
85
+ (0, _intlayer_config_logger.colorize)(require_server_swcPluginCompatibility.MINIMUM_SWC_PLUGIN_NEXT_VERSION, _intlayer_config_colors.BLUE),
86
+ (0, _intlayer_config_logger.colorize)("or later to enable it.", _intlayer_config_colors.GREY)
87
+ ], { level: "warn" });
88
+ else if (isSwcPluginAvailable) {
89
+ logger([
90
+ `Build optimization ${(0, _intlayer_config_logger.colorize)("enabled", _intlayer_config_colors.GREEN)}`,
91
+ (0, _intlayer_config_logger.colorize)(`(import mode:`, _intlayer_config_colors.GREY_DARK),
92
+ (0, _intlayer_config_logger.colorize)(importMode ?? _intlayer_config_defaultValues.IMPORT_MODE, _intlayer_config_colors.BLUE),
93
+ (0, _intlayer_config_logger.colorize)(`)`, _intlayer_config_colors.GREY_DARK)
94
+ ]);
95
+ const isPurgePipelineEnabled = !editorEnabled && !swcExtraCallers?.length && require_server_prepareSwcOptimization.getIsPurgePipelineAvailable(intlayerConfig);
96
+ if (isPurgePipelineEnabled && minify) logger(`Dictionary minification ${(0, _intlayer_config_logger.colorize)("enabled", _intlayer_config_colors.GREEN)}`);
97
+ if (isPurgePipelineEnabled && purge) logger(`Dictionary purge unused keys ${(0, _intlayer_config_logger.colorize)("enabled", _intlayer_config_colors.GREEN)}`);
98
+ } else logger([
77
99
  (0, _intlayer_config_logger.colorize)("Recommended: Install", _intlayer_config_colors.GREY),
78
100
  (0, _intlayer_config_logger.colorize)("@intlayer/swc", _intlayer_config_colors.GREY_LIGHT),
79
101
  (0, _intlayer_config_logger.colorize)("package to enable build optimization. See documentation:", _intlayer_config_colors.GREY),
80
102
  (0, _intlayer_config_logger.colorize)("https://intlayer.org/docs/bundle-optimization", _intlayer_config_colors.GREY_LIGHT)
81
103
  ]);
82
- }, { cacheTimeoutMs: 1e3 * 30 });
104
+ }, { cacheTimeoutMs: 3e4 });
83
105
  (0, _intlayer_engine_utils.runOnce)((0, node_path.join)(baseDir, ".intlayer", "cache", "intlayer-compiler-plugin-enabled.lock"), () => {
84
106
  if (getIsBabelExtractPluginAvailable(intlayerConfig)) {
85
107
  let isEnabled = intlayerConfig.compiler?.enabled ?? true;
86
108
  if (isEnabled === "build-only") isEnabled = !isDevCommand;
87
109
  if (isEnabled) logger("Intlayer compiler enabled");
88
- else logger("Intlayer compiler disabled");
89
110
  }
90
- }, { cacheTimeoutMs: 1e3 * 30 });
91
- if (!isSwcPluginAvailable) return {};
111
+ }, { cacheTimeoutMs: 3e4 });
112
+ if (!isSwcPluginAvailable || !isSwcPluginSupported) return {};
92
113
  const dictionariesEntryPath = (0, node_path.join)(mainDir, "dictionaries.mjs");
93
114
  const dynamicDictionariesEntryPath = (0, node_path.join)(mainDir, "dynamic_dictionaries.mjs");
94
115
  const unmergedDictionariesEntryPath = (0, node_path.join)(mainDir, "unmerged_dictionaries.mjs");
@@ -103,6 +124,7 @@ const getPruneConfig = (intlayerConfig, isBuildCommand, isTurbopackEnabled, isDe
103
124
  Object.values(dictionaries).forEach((dictionary) => {
104
125
  dictionaryModeMap[dictionary.key] = dictionary.importMode ?? importMode ?? _intlayer_config_defaultValues.IMPORT_MODE;
105
126
  });
127
+ const nestingDictionaryKeys = [...(0, _intlayer_core_dictionaryManipulator.getNestedDictionaryGraph)(Object.values(dictionaries)).keys()];
106
128
  return { experimental: { swcPlugins: [[resolvePluginPath("@intlayer/swc", intlayerConfig, isTurbopackEnabled), {
107
129
  dictionariesDir,
108
130
  dictionariesEntryPath,
@@ -115,8 +137,11 @@ const getPruneConfig = (intlayerConfig, isBuildCommand, isTurbopackEnabled, isDe
115
137
  importMode,
116
138
  filesList,
117
139
  replaceDictionaryEntry: true,
140
+ nestingDictionaryKeys,
118
141
  dictionaryModeMap,
119
- extraCallers: swcExtraCallers ?? []
142
+ extraCallers: swcExtraCallers ?? [],
143
+ fieldRenameMap: fieldRenameMap ?? {},
144
+ logLevel: require_server_prepareSwcOptimization.resolveSwcLogLevel(intlayerConfig)
120
145
  }]] } };
121
146
  };
122
147
  const getCommandsEvent = () => {
@@ -174,7 +199,7 @@ const withIntlayerSync = (nextConfig = {}, configOptions) => {
174
199
  const intlayerConfig = (0, _intlayer_config_node.getConfiguration)(resolvedConfigOptions);
175
200
  (0, _intlayer_engine_cli.logConfigDetails)(resolvedConfigOptions);
176
201
  const appLogger = (0, _intlayer_config_logger.getAppLogger)(intlayerConfig);
177
- const { isGteNext13, isGteNext15, isGteNext16, isTurbopackStable } = getNextVersionFlags(intlayerConfig);
202
+ const { nextVersion, isGteNext13, isGteNext15, isGteNext16, isTurbopackStable, isSwcPluginSupported } = getNextVersionFlags(intlayerConfig);
178
203
  const isTurbopackEnabledFromCommand = isGteNext16 ? !process.env["npm_lifecycle_script"]?.includes("--webpack") : process.env["npm_lifecycle_script"]?.includes("--turbo");
179
204
  const isTurbopackEnabled = configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;
180
205
  if (isTurbopackEnabled && typeof nextConfig.webpack !== "undefined") appLogger("Turbopack is enabled but a custom webpack config is present. It will be ignored.");
@@ -212,6 +237,7 @@ const withIntlayerSync = (nextConfig = {}, configOptions) => {
212
237
  env = {
213
238
  ...env,
214
239
  ...(0, _intlayer_config_envVars.formatNodeTypeToEnvVar)(unusedNodeTypes),
240
+ ...(0, _intlayer_config_envVars.formatOptimizedNestingEnvVar)(intlayerConfig.build.optimize !== false),
215
241
  ...(0, _intlayer_config_envVars.formatDictionarySelectorEnvVar)((0, _intlayer_config_utils.getHasDictionarySelector)(dictionaries)),
216
242
  ...(0, _intlayer_config_envVars.getConfigEnvVars)(intlayerConfig)
217
243
  };
@@ -229,18 +255,19 @@ const withIntlayerSync = (nextConfig = {}, configOptions) => {
229
255
  serverComponentsExternalPackages: serverExternalPackages
230
256
  }
231
257
  };
232
- if (isTurbopackEnabled) if (isGteNext15 && isTurbopackStable) config = {
233
- ...config,
234
- turbopack: turboConfig
235
- };
236
- else config = {
237
- ...config,
238
- experimental: {
239
- ...config?.experimental ?? {},
240
- turbo: turboConfig
241
- }
242
- };
243
- else config = {
258
+ if (isTurbopackEnabled) {
259
+ if (isGteNext15 && isTurbopackStable) config = {
260
+ ...config,
261
+ turbopack: turboConfig
262
+ };
263
+ else config = {
264
+ ...config,
265
+ experimental: {
266
+ ...config?.experimental ?? {},
267
+ turbo: turboConfig
268
+ }
269
+ };
270
+ } else config = {
244
271
  ...config,
245
272
  webpack: (config, options) => {
246
273
  const { isServer, nextRuntime } = options;
@@ -276,8 +303,19 @@ const withIntlayerSync = (nextConfig = {}, configOptions) => {
276
303
  };
277
304
  return config;
278
305
  };
279
- const pruneConfig = getPruneConfig(intlayerConfig, isBuildCommand, isTurbopackEnabled ?? false, isDevCommand, isGteNext13, configOptions?.swcExtraCallers);
280
- return (0, defu.defu)((0, defu.defu)(getNewConfig(), pruneConfig), nextConfig);
306
+ const pruneConfig = getPruneConfig({
307
+ intlayerConfig,
308
+ isBuildCommand,
309
+ isTurbopackEnabled: isTurbopackEnabled ?? false,
310
+ isDevCommand,
311
+ isGteNext13,
312
+ isSwcPluginSupported,
313
+ nextVersion,
314
+ swcExtraCallers: configOptions?.swcExtraCallers,
315
+ fieldRenameMap: configOptions?.fieldRenameMap
316
+ });
317
+ const intlayerNextConfig = (0, defu.defu)(getNewConfig(), pruneConfig);
318
+ return (0, defu.defu)(intlayerNextConfig, nextConfig);
281
319
  };
282
320
  /**
283
321
  * A Next.js plugin that adds the intlayer configuration to the webpack configuration
@@ -302,14 +340,25 @@ const withIntlayer = async (nextConfig = {}, configOptions) => {
302
340
  const { mode } = intlayerConfig.build;
303
341
  if (!isStartCommand && (isDevCommand || isBuildCommand || mode === "auto")) await (0, _intlayer_engine_build.prepareIntlayer)(intlayerConfig, {
304
342
  clean: isBuildCommand,
305
- cacheTimeoutMs: isBuildCommand ? 1e3 * 30 : 1e3 * 60 * 60,
343
+ cacheTimeoutMs: isBuildCommand ? 3e4 : 36e5,
306
344
  env: isBuildCommand ? "prod" : "dev"
307
345
  });
346
+ const { isSwcPluginSupported } = getNextVersionFlags(intlayerConfig);
347
+ const fieldRenameMap = isBuildCommand ? await require_server_prepareSwcOptimization.prepareSwcOptimization(intlayerConfig, {
348
+ configOptions: resolvedConfigOptions,
349
+ swcExtraCallers: configOptions?.swcExtraCallers,
350
+ isSwcPluginUsable: isSwcPluginSupported && getIsSwcPluginAvailable(intlayerConfig)
351
+ }) : {};
308
352
  const nextConfigResolved = await nextConfig;
309
- return withIntlayerSync(nextConfigResolved, resolvedConfigOptions);
353
+ return withIntlayerSync(nextConfigResolved, {
354
+ ...resolvedConfigOptions,
355
+ fieldRenameMap
356
+ });
310
357
  };
311
358
 
312
359
  //#endregion
360
+ exports.MINIMUM_SWC_PLUGIN_NEXT_VERSION = require_server_swcPluginCompatibility.MINIMUM_SWC_PLUGIN_NEXT_VERSION;
361
+ exports.getIsSwcPluginSupported = require_server_swcPluginCompatibility.getIsSwcPluginSupported;
313
362
  exports.withIntlayer = withIntlayer;
314
363
  exports.withIntlayerSync = withIntlayerSync;
315
364
  //# sourceMappingURL=withIntlayer.cjs.map