@fluenti/next 0.5.0 → 0.6.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 (80) hide show
  1. package/dist/chunk-DyIg6Wiv.js +7 -0
  2. package/dist/i18n-config.cjs +1 -1
  3. package/dist/i18n-config.cjs.map +1 -1
  4. package/dist/index.cjs +69 -41
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.js +188 -124
  7. package/dist/index.js.map +1 -1
  8. package/dist/loader.cjs +1 -1
  9. package/dist/loader.cjs.map +1 -1
  10. package/dist/loader.js +5 -0
  11. package/dist/loader.js.map +1 -1
  12. package/dist/middleware.cjs +1 -1
  13. package/dist/middleware.cjs.map +1 -1
  14. package/dist/middleware.js +66 -71
  15. package/dist/middleware.js.map +1 -1
  16. package/dist/navigation.cjs +1 -1
  17. package/dist/navigation.cjs.map +1 -1
  18. package/dist/navigation.js +61 -63
  19. package/dist/navigation.js.map +1 -1
  20. package/dist/{client-provider.d.ts → packages/next-plugin/src/client-provider.d.ts} +1 -1
  21. package/dist/packages/next-plugin/src/client-provider.d.ts.map +1 -0
  22. package/dist/packages/next-plugin/src/create-navigation.d.ts.map +1 -0
  23. package/dist/packages/next-plugin/src/dev-runner.d.ts.map +1 -0
  24. package/dist/packages/next-plugin/src/dev-watcher.d.ts.map +1 -0
  25. package/dist/packages/next-plugin/src/generate-server-module.d.ts.map +1 -0
  26. package/dist/packages/next-plugin/src/i18n-config.d.ts.map +1 -0
  27. package/dist/{index.d.ts → packages/next-plugin/src/index.d.ts} +32 -29
  28. package/dist/packages/next-plugin/src/index.d.ts.map +1 -0
  29. package/dist/packages/next-plugin/src/middleware.d.ts.map +1 -0
  30. package/dist/{navigation.d.ts → packages/next-plugin/src/navigation.d.ts} +2 -2
  31. package/dist/packages/next-plugin/src/navigation.d.ts.map +1 -0
  32. package/dist/packages/next-plugin/src/provider.d.ts.map +1 -0
  33. package/dist/packages/next-plugin/src/read-config.d.ts.map +1 -0
  34. package/dist/packages/next-plugin/src/routing.d.ts.map +1 -0
  35. package/dist/packages/next-plugin/src/server.d.ts.map +1 -0
  36. package/dist/{types.d.ts → packages/next-plugin/src/types.d.ts} +11 -1
  37. package/dist/packages/next-plugin/src/types.d.ts.map +1 -0
  38. package/dist/packages/next-plugin/src/with-fluenti.d.ts.map +1 -0
  39. package/dist/packages/next-plugin/src/with-locale.d.ts.map +1 -0
  40. package/dist/provider.cjs +1 -1
  41. package/dist/provider.cjs.map +1 -1
  42. package/dist/routing-CRln5Gw7.js +65 -0
  43. package/dist/routing-CRln5Gw7.js.map +1 -0
  44. package/dist/routing-D4p8HvMH.cjs +2 -0
  45. package/dist/routing-D4p8HvMH.cjs.map +1 -0
  46. package/dist/server.cjs +1 -1
  47. package/dist/server.cjs.map +1 -1
  48. package/package.json +16 -16
  49. package/dist/client-provider.d.ts.map +0 -1
  50. package/dist/create-navigation.d.ts.map +0 -1
  51. package/dist/dev-runner.d.ts.map +0 -1
  52. package/dist/dev-watcher.d.ts.map +0 -1
  53. package/dist/generate-server-module.d.ts.map +0 -1
  54. package/dist/i18n-config.d.ts.map +0 -1
  55. package/dist/index.d.ts.map +0 -1
  56. package/dist/middleware.d.ts.map +0 -1
  57. package/dist/navigation.d.ts.map +0 -1
  58. package/dist/provider.d.ts.map +0 -1
  59. package/dist/read-config.d.ts.map +0 -1
  60. package/dist/routing-DBVu_7tk.js +0 -72
  61. package/dist/routing-DBVu_7tk.js.map +0 -1
  62. package/dist/routing-Dy57-Uao.cjs +0 -2
  63. package/dist/routing-Dy57-Uao.cjs.map +0 -1
  64. package/dist/routing.d.ts.map +0 -1
  65. package/dist/server.d.ts.map +0 -1
  66. package/dist/types.d.ts.map +0 -1
  67. package/dist/with-fluenti.d.ts.map +0 -1
  68. package/dist/with-locale.d.ts.map +0 -1
  69. /package/dist/{create-navigation.d.ts → packages/next-plugin/src/create-navigation.d.ts} +0 -0
  70. /package/dist/{dev-runner.d.ts → packages/next-plugin/src/dev-runner.d.ts} +0 -0
  71. /package/dist/{dev-watcher.d.ts → packages/next-plugin/src/dev-watcher.d.ts} +0 -0
  72. /package/dist/{generate-server-module.d.ts → packages/next-plugin/src/generate-server-module.d.ts} +0 -0
  73. /package/dist/{i18n-config.d.ts → packages/next-plugin/src/i18n-config.d.ts} +0 -0
  74. /package/dist/{middleware.d.ts → packages/next-plugin/src/middleware.d.ts} +0 -0
  75. /package/dist/{provider.d.ts → packages/next-plugin/src/provider.d.ts} +0 -0
  76. /package/dist/{read-config.d.ts → packages/next-plugin/src/read-config.d.ts} +0 -0
  77. /package/dist/{routing.d.ts → packages/next-plugin/src/routing.d.ts} +0 -0
  78. /package/dist/{server.d.ts → packages/next-plugin/src/server.d.ts} +0 -0
  79. /package/dist/{with-fluenti.d.ts → packages/next-plugin/src/with-fluenti.d.ts} +0 -0
  80. /package/dist/{with-locale.d.ts → packages/next-plugin/src/with-locale.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,15 +1,16 @@
1
- import { n as e, o as t, t as n } from "./routing-DBVu_7tk.js";
2
- import { existsSync as r, mkdirSync as i, watch as a, writeFileSync as o } from "node:fs";
3
- import { execSync as s } from "node:child_process";
1
+ import { t as e } from "./chunk-DyIg6Wiv.js";
2
+ import { t } from "./routing-CRln5Gw7.js";
3
+ import { existsSync as n, mkdirSync as r, watch as i, writeFileSync as a } from "node:fs";
4
+ import { execSync as o } from "node:child_process";
5
+ import { createRequire as s } from "node:module";
4
6
  import { dirname as c, join as l, relative as u, resolve as d } from "node:path";
5
7
  import { fileURLToPath as f } from "node:url";
6
8
  import { DEFAULT_FLUENTI_CONFIG as p, loadConfigSync as m } from "@fluenti/core/config";
7
9
  import { validateLocale as h } from "@fluenti/core";
8
- import { resolveLocaleCodes as g } from "@fluenti/core/internal";
9
- import { createRequire as _ } from "node:module";
10
- import { msg as v } from "@fluenti/react";
10
+ import { resolveLocaleCodes as g } from "@fluenti/core/compiler";
11
+ import { msg as _ } from "@fluenti/react";
11
12
  //#region src/read-config.ts
12
- function y(e, t) {
13
+ function v(e, t) {
13
14
  let n;
14
15
  n = t?.config && typeof t.config == "object" ? {
15
16
  ...p,
@@ -18,50 +19,71 @@ function y(e, t) {
18
19
  ...p,
19
20
  locales: t.locales
20
21
  } : m(typeof t?.config == "string" ? t.config : void 0, e);
21
- let r = t?.serverModuleOutDir ?? ".fluenti", i = t?.cookieName ?? "locale", a = {
22
+ let r = t?.serverModuleOutDir ?? ".fluenti", i = t?.cookieName ?? "locale", a = t?.runtimeInterpolate ?? !0, o = {
22
23
  fluentiConfig: n,
23
24
  serverModule: t?.serverModule ?? null,
24
25
  serverModuleOutDir: r,
25
- cookieName: i
26
+ cookieName: i,
27
+ runtimeInterpolate: a
26
28
  };
27
- return t?.resolveLocale && (a.resolveLocale = t.resolveLocale), a;
29
+ return t?.resolveLocale && (o.resolveLocale = t.resolveLocale), o;
28
30
  }
29
31
  //#endregion
30
32
  //#region src/generate-server-module.ts
31
- function b(e, t) {
33
+ function y(e, t) {
32
34
  try {
33
- o(e, t, "utf-8");
35
+ a(e, t, "utf-8");
34
36
  } catch (t) {
35
37
  throw Error(`[fluenti] Failed to write generated module at ${e}: ${t instanceof Error ? t.message : String(t)}`);
36
38
  }
37
39
  }
38
- function x(e, t) {
40
+ function b(e, t) {
39
41
  if (t.serverModule) return d(e, t.serverModule);
40
- let n = d(e, t.serverModuleOutDir), a = d(n, "server.js"), o = d(n, "server.d.ts");
41
- r(n) || i(n, { recursive: !0 });
42
- let s = g(t.fluentiConfig.locales), c = t.fluentiConfig.defaultLocale ?? t.fluentiConfig.sourceLocale, l = t.fluentiConfig.compileOutDir, f = t.fluentiConfig.fallbackChain, p = t.fluentiConfig.dateFormats, m = t.fluentiConfig.numberFormats, _ = S(t.cookieName), v = S(c);
42
+ let i = d(e, t.serverModuleOutDir), a = d(i, "server.js"), o = d(i, "server.d.ts");
43
+ n(i) || r(i, { recursive: !0 });
44
+ let s = g(t.fluentiConfig.locales), c = t.fluentiConfig.defaultLocale ?? t.fluentiConfig.sourceLocale, l = t.fluentiConfig.compileOutDir, f = t.fluentiConfig.fallbackChain, p = t.fluentiConfig.dateFormats, m = t.fluentiConfig.numberFormats, _ = x(t.cookieName), v = x(c);
43
45
  for (let e of s) h(e, "next-plugin");
44
- let y = C(u(n, d(e, l))), x = s.map((e) => ` case '${S(e)}': return import('${y}/${e}')`).join("\n"), w = f ? JSON.stringify(f) : "undefined";
45
- b(d(n, "client-provider.js"), `"use client";
46
+ let b = S(u(i, d(e, l))), E = s.map((e) => ` case ${x(e)}: return import(${x(`${b}/${e}`)})`).join("\n"), D = f ? JSON.stringify(f) : "undefined", O = d(i, "client-provider.js"), k = p === void 0 ? "undefined" : JSON.stringify(p), A = m === void 0 ? "undefined" : JSON.stringify(m), j = t.runtimeInterpolate ? "import { interpolate as __interpolate } from '@fluenti/core/runtime'\n" : "", M = t.runtimeInterpolate ? ", interpolate: __interpolate" : "", N = t.runtimeInterpolate ? " interpolate: __interpolate,\n" : "";
47
+ y(O, `"use client";
46
48
  // Auto-generated by @fluenti/next — do not edit
47
49
  // @ts-nocheck
48
50
  import { createElement } from 'react'
49
51
  import { I18nProvider } from '@fluenti/react'
50
- import { interpolate as __interpolate } from '@fluenti/core/internal'
51
- ${s.map((e) => `import ${e.replace(/[^a-zA-Z0-9]/g, "_")} from '${y}/${e}'`).join("\n")}
52
+ ${j}
53
+ const __dateFormats = ${k}
54
+ const __numberFormats = ${A}
55
+
56
+ export function ClientI18nProvider({ locale, fallbackLocale, messages, loadMessages, fallbackChain, children }) {
57
+ return createElement(I18nProvider, { locale, fallbackLocale, messages, loadMessages, fallbackChain, dateFormats: __dateFormats, numberFormats: __numberFormats${M} }, children)
58
+ }
59
+ `), y(d(i, "client-provider.d.ts"), "// Auto-generated by @fluenti/next — do not edit\nimport type { ReactNode, ReactElement } from 'react'\nimport type { AllMessages, Messages } from '@fluenti/core'\n\nexport declare function ClientI18nProvider(props: {\n locale: string\n fallbackLocale: string\n messages: AllMessages\n loadMessages: (locale: string) => Promise<Messages | { default: Messages }>\n fallbackChain?: Record<string, string[]>\n children: ReactNode\n}): ReactElement\n");
60
+ for (let e of s) {
61
+ let t = d(i, C(e)), n = T(e, c, f, s);
62
+ y(t, `"use client";
63
+ // Auto-generated by @fluenti/next — do not edit
64
+ // @ts-nocheck
65
+ import { createElement } from 'react'
66
+ import { ClientI18nProvider as __FluentiClientI18nProvider } from './client-provider.js'
67
+ ${n.map((e) => `import ${w(e)} from ${x(`${b}/${e}`)}`).join("\n")}
52
68
 
53
- const __allMessages = { ${s.map((e) => {
54
- let t = e.replace(/[^a-zA-Z0-9]/g, "_");
55
- return `'${S(e)}': ${t}`;
56
- }).join(", ")} }
57
- const __dateFormats = ${p === void 0 ? "undefined" : JSON.stringify(p)}
58
- const __numberFormats = ${m === void 0 ? "undefined" : JSON.stringify(m)}
69
+ const __messages = { ${n.map((e) => `${x(e)}: ${w(e)}`).join(", ")} }
70
+
71
+ async function __loadMessages(locale) {
72
+ switch (locale) {
73
+ ${s.map((e) => {
74
+ let t = x(`${b}/${e}`);
75
+ return n.includes(e) ? ` case ${x(e)}: return ${w(e)}` : ` case ${x(e)}: return import(${t})`;
76
+ }).join("\n")}
77
+ default: return import(${x(`${b}/${c}`)})
78
+ }
79
+ }
59
80
 
60
81
  export function ClientI18nProvider({ locale, fallbackLocale, fallbackChain, children }) {
61
- return createElement(I18nProvider, { locale, fallbackLocale, messages: __allMessages, fallbackChain, dateFormats: __dateFormats, numberFormats: __numberFormats, interpolate: __interpolate }, children)
82
+ return createElement(__FluentiClientI18nProvider, { locale, fallbackLocale, messages: __messages, loadMessages: __loadMessages, fallbackChain }, children)
62
83
  }
63
- `), b(d(n, "client-provider.d.ts"), "// Auto-generated by @fluenti/next — do not edit\nimport type { ReactNode, ReactElement } from 'react'\n\nexport declare function ClientI18nProvider(props: {\n locale: string\n fallbackLocale: string\n fallbackChain?: Record<string, string[]>\n children: ReactNode\n}): ReactElement\n");
64
- let T = t.resolveLocale ? `import __resolveLocale from '${C(u(n, d(e, t.resolveLocale)))}'` : null, E = t.resolveLocale ? "resolveLocale: __resolveLocale," : `resolveLocale: async () => {
84
+ `);
85
+ }
86
+ let P = t.resolveLocale ? `import __resolveLocale from ${x(S(u(i, d(e, t.resolveLocale))))}` : null, F = t.resolveLocale ? "resolveLocale: __resolveLocale," : `resolveLocale: async () => {
65
87
  try {
66
88
  const { cookies, headers } = await import('next/headers')
67
89
  const [cookieStore, headerStore] = await Promise.all([cookies(), headers()])
@@ -71,7 +93,7 @@ export function ClientI18nProvider({ locale, fallbackLocale, fallbackChain, chil
71
93
  if (fromMiddleware && __locales.includes(fromMiddleware)) return fromMiddleware
72
94
 
73
95
  // 1. Cookie (configurable name)
74
- const fromCookie = cookieStore.get('${_}')?.value
96
+ const fromCookie = cookieStore.get(${_})?.value
75
97
  if (fromCookie && __locales.includes(fromCookie)) return fromCookie
76
98
 
77
99
  // 2. Accept-Language header
@@ -86,30 +108,28 @@ export function ClientI18nProvider({ locale, fallbackLocale, fallbackChain, chil
86
108
  }
87
109
  }
88
110
 
89
- return '${v}'
111
+ return ${v}
90
112
  } catch {
91
- return '${v}'
113
+ return ${v}
92
114
  }
93
- },`, D = JSON.stringify(s);
94
- b(a, `// Auto-generated by @fluenti/next — do not edit
115
+ },`, I = JSON.stringify(s);
116
+ y(a, `// Auto-generated by @fluenti/next — do not edit
95
117
  // @ts-nocheck
96
118
  import { createServerI18n } from '@fluenti/react/server'
97
119
  import { createElement } from 'react'
98
- import { interpolate as __interpolate } from '@fluenti/core/internal'
99
- ${T ? `${T}\n` : ""}
100
- const __locales = ${D}
120
+ ${j}${P ? `${P}\n` : ""}
121
+ const __locales = ${I}
101
122
 
102
123
  const serverI18n = createServerI18n({
103
- interpolate: __interpolate,
104
- loadMessages: async (locale) => {
124
+ ${N} loadMessages: async (locale) => {
105
125
  switch (locale) {
106
- ${x}
107
- default: return import('${y}/${v}')
126
+ ${E}
127
+ default: return import(${x(`${b}/${c}`)})
108
128
  }
109
129
  },
110
- fallbackLocale: '${v}',
111
- fallbackChain: ${w},
112
- ${E}
130
+ fallbackLocale: ${v},
131
+ fallbackChain: ${D},
132
+ ${F}
113
133
  })
114
134
 
115
135
  export const setLocale = serverI18n.setLocale
@@ -135,41 +155,57 @@ export const NumberFormat = serverI18n.NumberFormat
135
155
  * Sets up both server-side (React.cache) and client-side (I18nProvider) i18n.
136
156
  */
137
157
  export async function I18nProvider({ locale, children }) {
138
- const activeLocale = (locale && locale.trim()) ? locale : '${v}'
158
+ const activeLocale = (locale && locale.trim()) ? locale : ${v}
139
159
 
140
160
  // 1. Initialize server-side i18n (React.cache scoped)
141
161
  serverI18n.setLocale(activeLocale)
142
162
  await serverI18n.getI18n()
143
163
 
144
- // 2. Import the local 'use client' provider that has messages statically bundled.
145
- // Messages contain functions (interpolation) which can't be serialized across the RSC boundary.
146
- const { ClientI18nProvider } = await import('./client-provider.js')
164
+ // 2. Import the locale-specific client provider chunk. It eagerly bundles the
165
+ // active locale plus only the fallback locales relevant to that locale.
166
+ const { ClientI18nProvider } = await (async () => {
167
+ switch (activeLocale) {
168
+ ${s.map((e) => ` case ${x(e)}: return import(${x(`./${C(e)}`)})`).join("\n")}
169
+ default: return import(${x(`./${C(c)}`)})
170
+ }
171
+ })()
147
172
 
148
173
  return createElement(ClientI18nProvider, {
149
174
  locale: activeLocale,
150
- fallbackLocale: '${v}',
151
- fallbackChain: ${w},
175
+ fallbackLocale: ${v},
176
+ fallbackChain: ${D},
152
177
  }, children)
153
178
  }
154
- `), b(o, "// Auto-generated by @fluenti/next — do not edit\nimport type { ReactNode, ReactElement } from 'react'\nimport type { CompileTimeT, FluentiCoreInstanceFull } from '@fluenti/core'\n\nexport declare function setLocale(locale: string): void\nexport declare function getI18n(): Promise<FluentiCoreInstanceFull & { locale: string }>\nexport declare const t: CompileTimeT\n\nexport declare function Trans(props: {\n children: ReactNode\n id?: string\n context?: string\n comment?: string\n render?: (translation: ReactNode) => ReactNode\n}): Promise<ReactElement>\n\nexport declare function Plural(props: {\n value: number\n id?: string\n context?: string\n comment?: string\n zero?: ReactNode\n one?: ReactNode\n two?: ReactNode\n few?: ReactNode\n many?: ReactNode\n other: ReactNode\n offset?: number\n}): Promise<ReactElement>\n\nexport declare function Select(props: {\n value: string\n id?: string\n context?: string\n comment?: string\n other: ReactNode\n options?: Record<string, ReactNode>\n [key: string]: ReactNode | Record<string, ReactNode> | string | undefined\n}): Promise<ReactElement>\n\nexport declare function DateTime(props: {\n value: Date | number\n format?: string\n}): Promise<ReactElement>\n\nexport declare function NumberFormat(props: {\n value: number\n format?: string\n}): Promise<ReactElement>\n\nexport declare function I18nProvider(props: {\n locale?: string\n children: ReactNode\n}): Promise<ReactElement>\n");
155
- let O = d(n, "i18n-config.js"), k = d(n, "i18n-config.d.ts");
156
- return b(O, `// Auto-generated by @fluenti/next — do not edit
157
- export const locales = ${D}
158
- export const sourceLocale = '${v}'
159
- export const cookieName = '${_}'
160
- `), b(k, "// Auto-generated by @fluenti/next — do not edit\nexport declare const locales: string[]\nexport declare const sourceLocale: string\nexport declare const cookieName: string\n"), a;
179
+ `), y(o, "// Auto-generated by @fluenti/next — do not edit\nimport type { ReactNode, ReactElement } from 'react'\nimport type { CompileTimeT, FluentiCoreInstanceFull } from '@fluenti/core'\n\nexport declare function setLocale(locale: string): void\nexport declare function getI18n(): Promise<FluentiCoreInstanceFull & { locale: string }>\nexport declare const t: CompileTimeT\n\nexport declare function Trans(props: {\n children: ReactNode\n id?: string\n context?: string\n comment?: string\n render?: (translation: ReactNode) => ReactNode\n}): Promise<ReactElement>\n\nexport declare function Plural(props: {\n value: number\n id?: string\n context?: string\n comment?: string\n zero?: ReactNode\n one?: ReactNode\n two?: ReactNode\n few?: ReactNode\n many?: ReactNode\n other: ReactNode\n offset?: number\n}): Promise<ReactElement>\n\nexport declare function Select(props: {\n value: string\n id?: string\n context?: string\n comment?: string\n other: ReactNode\n options?: Record<string, ReactNode>\n [key: string]: ReactNode | Record<string, ReactNode> | string | undefined\n}): Promise<ReactElement>\n\nexport declare function DateTime(props: {\n value: Date | number\n format?: string\n}): Promise<ReactElement>\n\nexport declare function NumberFormat(props: {\n value: number\n format?: string\n}): Promise<ReactElement>\n\nexport declare function I18nProvider(props: {\n locale?: string\n children: ReactNode\n}): Promise<ReactElement>\n");
180
+ let L = d(i, "i18n-config.js"), R = d(i, "i18n-config.d.ts");
181
+ return y(L, `// Auto-generated by @fluenti/next — do not edit
182
+ export const locales = ${I}
183
+ export const sourceLocale = ${v}
184
+ export const cookieName = ${_}
185
+ `), y(R, "// Auto-generated by @fluenti/next — do not edit\nexport declare const locales: string[]\nexport declare const sourceLocale: string\nexport declare const cookieName: string\n"), a;
186
+ }
187
+ function x(e) {
188
+ return `'${e.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\0/g, "\\0")}'`;
161
189
  }
162
190
  function S(e) {
163
- return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\0/g, "\\0");
191
+ return e.split("\\").join("/");
164
192
  }
165
193
  function C(e) {
166
- return e.split("\\").join("/");
194
+ return `client-provider-${e.replace(/[^a-zA-Z0-9]/g, "_")}.js`;
195
+ }
196
+ function w(e) {
197
+ return `__messages_${e.replace(/[^a-zA-Z0-9]/g, "_")}`;
198
+ }
199
+ function T(e, t, n, r) {
200
+ let i = new Set([e, t]), a = n?.[e] ?? [];
201
+ for (let e of a) r.includes(e) && i.add(e);
202
+ return Array.from(i);
167
203
  }
168
204
  //#endregion
169
205
  //#region src/dev-runner.ts
170
- async function w(e) {
206
+ async function E(e) {
171
207
  if (e.compileOnly) try {
172
- let { runCompile: t } = _(l(e.cwd, "package.json"))("@fluenti/cli");
208
+ let { runCompile: t } = s(l(e.cwd, "package.json"))("@fluenti/cli");
173
209
  await t(e.cwd), console.log("[fluenti] Compiling... done"), e.onSuccess?.();
174
210
  return;
175
211
  } catch (t) {
@@ -180,7 +216,7 @@ async function w(e) {
180
216
  }
181
217
  let t = null;
182
218
  try {
183
- t = _(l(e.cwd, "package.json"))("@fluenti/cli");
219
+ t = s(l(e.cwd, "package.json"))("@fluenti/cli");
184
220
  } catch {}
185
221
  if (t) try {
186
222
  await t.runExtract(e.cwd), e.parallelCompile ? await t.runCompile(e.cwd, { parallel: !0 }) : await t.runCompile(e.cwd), console.log("[fluenti] Extracting and compiling... done"), e.onSuccess?.();
@@ -195,12 +231,12 @@ async function w(e) {
195
231
  if (e.throwOnError) throw Error(n);
196
232
  console.warn(n), e.onError?.(Error(n));
197
233
  }
198
- function T(e, t = 300) {
234
+ function D(e, t = 300) {
199
235
  let n = null, r = !1, i = !1;
200
236
  async function a() {
201
237
  r = !0;
202
238
  try {
203
- await w(e);
239
+ await E(e);
204
240
  } finally {
205
241
  r = !1, i && (i = !1, o());
206
242
  }
@@ -214,8 +250,8 @@ function T(e, t = 300) {
214
250
  }
215
251
  //#endregion
216
252
  //#region src/dev-watcher.ts
217
- var E = null;
218
- function D(e, t) {
253
+ var O = null;
254
+ function k(e, t) {
219
255
  if (!t || t.length === 0) return [d(e, "src")];
220
256
  let n = /* @__PURE__ */ new Set();
221
257
  for (let e of t) {
@@ -224,30 +260,30 @@ function D(e, t) {
224
260
  }
225
261
  return [...n].map((t) => d(e, t));
226
262
  }
227
- function O(e) {
228
- E && E();
229
- let { cwd: t, compiledDir: n, delay: r = 1e3, include: i, exclude: o, parallelCompile: s } = e, c = d(t, n), l = _(typeof __filename < "u" ? __filename : import.meta.url)("picomatch"), u = o?.length ? l(o) : () => !1, f = { cwd: t };
230
- s && (f.parallelCompile = !0);
231
- let p = T(f, r);
232
- p();
233
- let m = D(t, i).map((e) => a(e, { recursive: !0 }, (t, n) => {
234
- n && /\.[jt]sx?$/.test(n) && (n.includes("node_modules") || n.includes(".next") || d(e, n).startsWith(c) || u(n) || p());
235
- })), h = () => {
236
- for (let e of m) e.close();
237
- E = null;
263
+ function A(e) {
264
+ O && O();
265
+ let { cwd: t, compiledDir: n, delay: r = 1e3, include: a, exclude: o, parallelCompile: c } = e, l = d(t, n), u = s(typeof __filename < "u" ? __filename : import.meta.url)("picomatch"), f = o?.length ? u(o) : () => !1, p = { cwd: t };
266
+ c && (p.parallelCompile = !0);
267
+ let m = D(p, r);
268
+ m();
269
+ let h = k(t, a).map((e) => i(e, { recursive: !0 }, (t, n) => {
270
+ n && /\.[jt]sx?$/.test(n) && (n.includes("node_modules") || n.includes(".next") || d(e, n).startsWith(l) || f(n) || m());
271
+ })), g = () => {
272
+ for (let e of h) e.close();
273
+ O = null;
238
274
  };
239
- return E = h, h;
275
+ return O = g, g;
240
276
  }
241
277
  //#endregion
242
278
  //#region src/with-fluenti.ts
243
- function k(e) {
244
- if (e && !A(e)) return j({}, e);
279
+ function j(e) {
280
+ if (e && !M(e)) return N({}, e);
245
281
  let t = e ?? {};
246
282
  return function(e) {
247
- return j(t, e ?? {});
283
+ return N(t, e ?? {});
248
284
  };
249
285
  }
250
- function A(e) {
286
+ function M(e) {
251
287
  return [
252
288
  "config",
253
289
  "locales",
@@ -255,15 +291,16 @@ function A(e) {
255
291
  "serverModuleOutDir",
256
292
  "resolveLocale",
257
293
  "cookieName",
294
+ "runtimeInterpolate",
258
295
  "loaderEnforce"
259
296
  ].some((t) => t in e);
260
297
  }
261
- function j(e, n) {
262
- let a = process.cwd(), o = y(a, e), l = o.fluentiConfig, p = l.compileOutDir, m = d(a, p);
263
- r(m) || i(m, { recursive: !0 });
264
- let h = d(a, "app", "[locale]"), g = d(a, "src", "app", "[locale]");
265
- (r(h) || r(g)) && ("rewriteDefaultLocale" in e || (o._autoRewriteDefaultLocale = !0));
266
- let _ = x(a, o), v = d(typeof __dirname < "u" ? __dirname : c(f(import.meta.url)), "loader.js"), b = n.webpack, S = !1, C = Object.fromEntries([
298
+ function N(t, i) {
299
+ let a = process.cwd(), l = v(a, t), p = l.fluentiConfig, m = p.compileOutDir, h = d(a, m);
300
+ n(h) || r(h, { recursive: !0 });
301
+ let g = d(a, "app", "[locale]"), _ = d(a, "src", "app", "[locale]");
302
+ (n(g) || n(_)) && ("rewriteDefaultLocale" in t || (l._autoRewriteDefaultLocale = !0));
303
+ let y = b(a, l), x = d(typeof __dirname < "u" ? __dirname : c(f(import.meta.url)), "loader.js"), S = i.webpack, C = !1, w = Object.fromEntries([
267
304
  "*.ts",
268
305
  "*.tsx",
269
306
  "*.js",
@@ -271,58 +308,62 @@ function j(e, n) {
271
308
  ].map((e) => [e, {
272
309
  condition: { not: "foreign" },
273
310
  loaders: ["@fluenti/next/loader"]
274
- }])), w = d(c(_), "i18n-config.js"), T = "./" + u(a, _).split("\\").join("/"), E = "./" + u(a, w).split("\\").join("/"), D = {
275
- "@fluenti/next": T,
276
- "@fluenti/next/i18n-config": E
277
- }, k = process.env.NODE_ENV === "development" || process.argv.some((e) => e === "dev"), A = l.buildAutoCompile ?? !0;
278
- if (!k && A && !S) {
279
- S = !0;
311
+ }])), T = d(c(y), "i18n-config.js"), E = "./" + u(a, y).split("\\").join("/"), D = "./" + u(a, T).split("\\").join("/"), O = {
312
+ "@fluenti/next": E,
313
+ "@fluenti/next/i18n-config": D
314
+ }, k = process.env.NODE_ENV === "development" || process.argv.some((e) => e === "dev"), j = p.buildAutoCompile ?? !0;
315
+ if (!k && j && !C) {
316
+ C = !0;
280
317
  try {
281
- s("npx fluenti compile" + (l.parallelCompile ? " --parallel" : ""), {
318
+ o(`node "${d(c(s(d(a, "noop.js")).resolve("@fluenti/cli")), "cli.js")}" compile` + (p.parallelCompile ? " --parallel" : ""), {
282
319
  cwd: a,
283
320
  stdio: "inherit"
284
321
  });
285
- } catch {}
322
+ } catch (e) {
323
+ let t = e instanceof Error ? e.message : String(e);
324
+ throw Error(`[fluenti] Production auto-compile failed. Run "fluenti compile" successfully before continuing the Next.js build.
325
+ ${t}`);
326
+ }
286
327
  }
287
- let j = l.devAutoCompile ?? !0;
288
- if (k && j) {
328
+ let M = p.devAutoCompile ?? !0;
329
+ if (k && M) {
289
330
  let e = {
290
331
  cwd: a,
291
- compiledDir: p,
292
- delay: l.devAutoCompileDelay ?? 1e3
332
+ compiledDir: m,
333
+ delay: p.devAutoCompileDelay ?? 1e3
293
334
  };
294
- l.parallelCompile && (e.parallelCompile = !0), l.include && (e.include = l.include), l.exclude && (e.exclude = l.exclude), O(e);
335
+ p.parallelCompile && (e.parallelCompile = !0), p.include && (e.include = p.include), p.exclude && (e.exclude = p.exclude), A(e);
295
336
  }
296
337
  let N = 15;
297
338
  try {
298
- let e = t("next/package.json");
299
- e.version && (N = parseInt(e.version.split(".")[0], 10) || 15);
339
+ let t = e("next/package.json");
340
+ t.version && (N = parseInt(t.version.split(".")[0], 10) || 15);
300
341
  } catch {}
301
- let P = M(N >= 15 ? n.turbopack : n.experimental?.turbo, {
302
- rules: C,
303
- resolveAlias: D
304
- }), F = N >= 15 ? { turbopack: P } : { experimental: {
305
- ...n.experimental ?? {},
306
- turbo: P
342
+ let F = P(N >= 15 ? i.turbopack : i.experimental?.turbo, {
343
+ rules: w,
344
+ resolveAlias: O
345
+ }), I = N >= 15 ? { turbopack: F } : { experimental: {
346
+ ...i.experimental ?? {},
347
+ turbo: F
307
348
  } };
308
349
  return {
309
- ...n,
310
- ...F,
311
- webpack(t, n) {
312
- let r = e.loaderEnforce === void 0 && !("loaderEnforce" in e) ? "pre" : e.loaderEnforce;
313
- return t.module.rules.push({
350
+ ...i,
351
+ ...I,
352
+ webpack(e, n) {
353
+ let r = t.loaderEnforce === void 0 && !("loaderEnforce" in t) ? "pre" : t.loaderEnforce;
354
+ return e.module.rules.push({
314
355
  test: /\.[jt]sx?$/,
315
356
  ...r ? { enforce: r } : {},
316
357
  exclude: [/node_modules/, /\.next/],
317
358
  use: [{
318
- loader: v,
319
- options: { serverModulePath: _ }
359
+ loader: x,
360
+ options: { serverModulePath: y }
320
361
  }]
321
- }), t.resolve = t.resolve ?? {}, t.resolve.alias = t.resolve.alias ?? {}, t.resolve.alias["@fluenti/next$"] = _, t.resolve.alias["@fluenti/next/i18n-config$"] = w, b ? b(t, n) : t;
362
+ }), e.resolve = e.resolve ?? {}, e.resolve.alias = e.resolve.alias ?? {}, e.resolve.alias["@fluenti/next$"] = y, e.resolve.alias["@fluenti/next/i18n-config$"] = T, S ? S(e, n) : e;
322
363
  }
323
364
  };
324
365
  }
325
- function M(e, t) {
366
+ function P(e, t) {
326
367
  let n = e ?? {}, r = n.rules ?? {}, i = Object.keys(t.rules).filter((e) => e in r);
327
368
  return i.length > 0 && console.warn(`[fluenti] Your turbopack.rules override Fluenti's loader for: ${i.join(", ")}.\n Fluenti's t\`\` transform will NOT run on these file types.\n If this is intentional, you can suppress this warning with { devAutoCompile: false }.`), {
328
369
  ...n,
@@ -338,13 +379,36 @@ function M(e, t) {
338
379
  }
339
380
  //#endregion
340
381
  //#region src/index.ts
341
- e();
342
- var N = "[fluenti] `withFluenti()` must be configured in next.config.ts before importing from \"@fluenti/next\".";
343
- function P() {
344
- throw Error(N);
382
+ var F = [
383
+ "[fluenti] `@fluenti/next` was imported before `withFluenti()` generated the server module.",
384
+ "Fix this by:",
385
+ " 1. Wrapping next.config.ts with `withFluenti()` from '@fluenti/next'",
386
+ " 2. Restarting the Next dev server after the generated module is written",
387
+ " 3. Importing client runtime APIs from '@fluenti/react' and server APIs from '@fluenti/next'"
388
+ ].join("\n");
389
+ function I() {
390
+ throw Error(F);
391
+ }
392
+ var L = I, R = I, z = I;
393
+ async function B(e) {
394
+ return I();
395
+ }
396
+ async function V(e) {
397
+ return I();
398
+ }
399
+ async function H(e) {
400
+ return I();
401
+ }
402
+ async function U(e) {
403
+ return I();
404
+ }
405
+ async function W(e) {
406
+ return I();
407
+ }
408
+ async function G(e) {
409
+ return I();
345
410
  }
346
- var F = P, I = P, L = P, R = P, z = P, B = P, V = P, H = P, U = P;
347
411
  //#endregion
348
- export { V as DateTime, U as I18nProvider, H as NumberFormat, z as Plural, B as Select, R as Trans, n as defineRouting, I as getI18n, v as msg, F as setLocale, L as t, k as withFluenti };
412
+ export { U as DateTime, G as I18nProvider, W as NumberFormat, V as Plural, H as Select, B as Trans, t as defineRouting, R as getI18n, _ as msg, L as setLocale, z as t, j as withFluenti };
349
413
 
350
414
  //# sourceMappingURL=index.js.map