@fluenti/vite-plugin 0.4.0-rc.0 → 0.4.0-rc.2

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.
package/dist/index.js CHANGED
@@ -1,30 +1,39 @@
1
1
  import { createFilter as e } from "vite";
2
2
  import { hashMessage as t, resolveLocaleCodes as n } from "@fluenti/core/internal";
3
- import { join as r, resolve as i } from "node:path";
4
- import { createRequire as a } from "node:module";
5
- import { createRuntimeGenerator as o, createTransformPipeline as s, hasScopeTransformCandidate as c, parseSourceModule as l, walkSourceAst as u } from "@fluenti/core/transform";
6
- import { validateLocale as d } from "@fluenti/core";
7
- import { readFileSync as f } from "node:fs";
3
+ import { createRequire as r } from "node:module";
4
+ import { join as i, resolve as a } from "node:path";
5
+ import { existsSync as o, mkdirSync as s } from "node:fs";
6
+ import { createRuntimeGenerator as c, createTransformPipeline as l, hasScopeTransformCandidate as u, parseSourceModule as d, walkSourceAst as f } from "@fluenti/core/transform";
7
+ import { validateLocale as p } from "@fluenti/core";
8
8
  //#region src/mode-detect.ts
9
- var p = "dev";
10
- function m(e) {
11
- p = e === "build" ? "build" : "dev";
12
- }
9
+ var m = "dev";
13
10
  function h(e) {
11
+ m = e === "build" ? "build" : "dev";
12
+ }
13
+ function g(e) {
14
14
  if (typeof e == "object" && e && "environment" in e) {
15
15
  let t = e.environment;
16
16
  if (typeof t == "object" && t) return t;
17
17
  }
18
18
  }
19
- function g(e) {
20
- return e?.mode === "build" || p === "build" || process.env.NODE_ENV === "production";
19
+ function _(e) {
20
+ return e?.mode === "build" || m === "build" || process.env.NODE_ENV === "production";
21
21
  }
22
22
  //#endregion
23
23
  //#region src/dev-runner.ts
24
- async function _(e) {
24
+ async function v(e) {
25
+ try {
26
+ let { DEFAULT_FLUENTI_CONFIG: t, loadConfigSync: n } = r(i(e.cwd, "package.json"))("@fluenti/core/config"), o;
27
+ try {
28
+ o = n(void 0, e.cwd);
29
+ } catch {
30
+ o = t;
31
+ }
32
+ s(a(e.cwd, o.compileOutDir), { recursive: !0 }), s(a(e.cwd, o.catalogDir), { recursive: !0 });
33
+ } catch {}
25
34
  if (!(e.onBeforeCompile && await e.onBeforeCompile() === !1)) {
26
35
  if (e.compileOnly) try {
27
- let { runCompile: t } = a(r(e.cwd, "package.json"))("@fluenti/cli");
36
+ let { runCompile: t } = r(i(e.cwd, "package.json"))("@fluenti/cli");
28
37
  await t(e.cwd), console.log("[fluenti] Compiling... done"), e.onAfterCompile && await e.onAfterCompile(), e.onSuccess?.();
29
38
  return;
30
39
  } catch (t) {
@@ -34,7 +43,7 @@ async function _(e) {
34
43
  return;
35
44
  }
36
45
  try {
37
- let { runExtract: t, runCompile: n } = a(r(e.cwd, "package.json"))("@fluenti/cli");
46
+ let { runExtract: t, runCompile: n } = r(i(e.cwd, "package.json"))("@fluenti/cli");
38
47
  await t(e.cwd), await n(e.cwd, { parallel: e.parallelCompile }), console.log("[fluenti] Extracting and compiling... done"), e.onAfterCompile && await e.onAfterCompile(), e.onSuccess?.();
39
48
  return;
40
49
  } catch (t) {
@@ -50,12 +59,12 @@ async function _(e) {
50
59
  }
51
60
  }
52
61
  }
53
- function v(e, t = 300) {
62
+ function ee(e, t = 300) {
54
63
  let n = null, r = !1, i = !1;
55
64
  async function a() {
56
65
  r = !0;
57
66
  try {
58
- await _(e);
67
+ await v(e);
59
68
  } finally {
60
69
  r = !1, i && (i = !1, o());
61
70
  }
@@ -69,68 +78,68 @@ function v(e, t = 300) {
69
78
  }
70
79
  //#endregion
71
80
  //#region src/build-transform.ts
72
- function ee(e, t) {
73
- return y(e, "dynamic", t);
81
+ function y(e, t) {
82
+ return b(e, "dynamic", t);
74
83
  }
75
84
  function te(e, t) {
76
- return y(e, "static", t);
85
+ return b(e, "static", t);
77
86
  }
78
- function y(e, n, r) {
79
- let i = r?.hashFn ?? t, a = l(e);
87
+ function b(e, n, r) {
88
+ let i = r?.hashFn ?? t, a = d(e);
80
89
  if (!a || a.type !== "Program") return {
81
90
  code: e,
82
91
  needsCatalogImport: !1,
83
92
  usedHashes: /* @__PURE__ */ new Set()
84
93
  };
85
- let o = b(a), s = [], c = /* @__PURE__ */ new Set();
86
- if (u(a, (t) => {
87
- let r = S(e, t, o, n, c, i);
94
+ let o = x(a), s = [], c = /* @__PURE__ */ new Set();
95
+ if (f(a, (t) => {
96
+ let r = ne(e, t, o, n, c, i);
88
97
  if (r) {
89
98
  s.push(r);
90
99
  return;
91
100
  }
92
- ne(t, c, i);
101
+ ie(t, c, i);
93
102
  }), s.length === 0) return {
94
103
  code: e,
95
104
  needsCatalogImport: !1,
96
105
  usedHashes: c
97
106
  };
98
- let d = e;
107
+ let l = e;
99
108
  for (let e = s.length - 1; e >= 0; e--) {
100
109
  let { start: t, end: n, replacement: r } = s[e];
101
- d = d.slice(0, t) + r + d.slice(n);
110
+ l = l.slice(0, t) + r + l.slice(n);
102
111
  }
103
112
  return {
104
- code: d,
113
+ code: l,
105
114
  needsCatalogImport: !0,
106
115
  usedHashes: c
107
116
  };
108
117
  }
109
- function b(e) {
118
+ function x(e) {
110
119
  let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
111
- for (let t of e.body) if (se(t)) for (let e of t.specifiers) {
112
- if (!ce(e)) continue;
113
- let t = B(e);
120
+ for (let t of e.body) if (P(t)) for (let e of t.specifiers) {
121
+ if (!F(e)) continue;
122
+ let t = G(e);
114
123
  t && (t === "useI18n" && n.add(e.local.name), t === "getI18n" && r.add(e.local.name), t === "unref" && i.add(e.local.name));
115
124
  }
116
- return u(e, (e) => {
117
- if (!le(e) || !e.init || !ue(e.id)) return;
118
- if (F(e.init) && L(e.init.callee) && n.has(e.init.callee.name)) {
119
- x(e.id, t);
125
+ return f(e, (e) => {
126
+ if (!I(e) || !e.init || !L(e.id)) return;
127
+ if (B(e.init) && H(e.init.callee) && n.has(e.init.callee.name)) {
128
+ S(e.id, t);
120
129
  return;
121
130
  }
122
131
  let i = e.init.type === "AwaitExpression" ? e.init.argument : null;
123
- i && F(i) && L(i.callee) && r.has(i.callee.name) && x(e.id, t);
132
+ i && B(i) && H(i.callee) && r.has(i.callee.name) && S(e.id, t);
124
133
  }), {
125
134
  tracked: t,
126
135
  unref: i
127
136
  };
128
137
  }
129
- function x(e, t) {
130
- for (let n of e.properties) !P(n) || n.computed || !L(n.key) || n.key.name !== "t" || L(n.value) && t.add(n.value.name);
138
+ function S(e, t) {
139
+ for (let n of e.properties) !z(n) || n.computed || !H(n.key) || n.key.name !== "t" || H(n.value) && t.add(n.value.name);
131
140
  }
132
- function S(e, t, n, r, i, a) {
133
- if (!F(t) || t.start == null || t.end == null) return;
141
+ function ne(e, t, n, r, i, a) {
142
+ if (!B(t) || t.start == null || t.end == null) return;
134
143
  let o = C(e, t, n, a);
135
144
  if (!o) return;
136
145
  let { catalogId: s } = o;
@@ -144,9 +153,9 @@ function S(e, t, n, r, i, a) {
144
153
  }
145
154
  function C(e, t, n, r) {
146
155
  if (t.arguments.length === 0) return;
147
- let i = t.callee, a = L(i) && (n.tracked.has(i.name) || i.name === "$t"), o = I(i) && !i.computed && L(i.property) && (i.property.name === "$t" || i.property.name === "t" && L(i.object) && (i.object.name === "_ctx" || i.object.name === "$setup")), s = F(i) && L(i.callee) && n.unref.has(i.callee.name) && i.arguments.length === 1 && L(i.arguments[0]) && n.tracked.has(i.arguments[0].name);
156
+ let i = t.callee, a = H(i) && (n.tracked.has(i.name) || i.name === "$t"), o = V(i) && !i.computed && H(i.property) && (i.property.name === "$t" || i.property.name === "t" && H(i.object) && (i.object.name === "_ctx" || i.object.name === "$setup")), s = B(i) && H(i.callee) && n.unref.has(i.callee.name) && i.arguments.length === 1 && H(i.arguments[0]) && n.tracked.has(i.arguments[0].name);
148
157
  if (!a && !o && !s) return;
149
- let c = w(t.arguments[0], r);
158
+ let c = re(t.arguments[0], r);
150
159
  if (!c) return;
151
160
  let l = t.arguments[1] && t.arguments[1].start != null && t.arguments[1].end != null ? e.slice(t.arguments[1].start, t.arguments[1].end) : void 0;
152
161
  return l === void 0 ? { catalogId: c } : {
@@ -154,69 +163,69 @@ function C(e, t, n, r) {
154
163
  valuesSource: l
155
164
  };
156
165
  }
157
- function w(e, t) {
158
- let n = j(e);
166
+ function re(e, t) {
167
+ let n = M(e);
159
168
  if (n !== void 0) return t(n);
160
- if (!N(e)) return;
169
+ if (!R(e)) return;
161
170
  let r, i, a;
162
171
  for (let t of e.properties) {
163
- if (!P(t) || t.computed) continue;
164
- let e = M(t.key);
172
+ if (!z(t) || t.computed) continue;
173
+ let e = N(t.key);
165
174
  if (!e) continue;
166
- let n = j(t.value);
175
+ let n = M(t.value);
167
176
  n !== void 0 && (e === "id" && (r = n), e === "message" && (i = n), e === "context" && (a = n));
168
177
  }
169
178
  if (r) return r;
170
179
  if (i) return t(i, a);
171
180
  }
172
- function ne(e, t, n) {
173
- if (!R(e)) return;
181
+ function ie(e, t, n) {
182
+ if (!U(e)) return;
174
183
  let r = oe(e.openingElement.name);
175
184
  if (r) {
176
185
  if (r === "Trans") {
177
- let r = O(e.openingElement, "__id") ?? O(e.openingElement, "id");
186
+ let r = k(e.openingElement, "__id") ?? k(e.openingElement, "id");
178
187
  if (r) {
179
188
  t.add(r);
180
189
  return;
181
190
  }
182
- let i = O(e.openingElement, "__message"), a = O(e.openingElement, "context");
191
+ let i = k(e.openingElement, "__message"), a = k(e.openingElement, "context");
183
192
  i && t.add(n(i, a));
184
193
  return;
185
194
  }
186
195
  if (r === "Plural") {
187
- let r = re(e.openingElement, n);
196
+ let r = w(e.openingElement, n);
188
197
  r && t.add(r);
189
198
  return;
190
199
  }
191
200
  if (r === "Select") {
192
- let r = ie(e.openingElement, n);
201
+ let r = T(e.openingElement, n);
193
202
  r && t.add(r);
194
203
  }
195
204
  }
196
205
  }
197
- function re(e, t) {
198
- let n = O(e, "id");
206
+ function w(e, t) {
207
+ let n = k(e, "id");
199
208
  if (n) return n;
200
- let r = O(e, "context"), i = ae(e, "offset"), a = [
201
- O(e, "zero") === void 0 ? void 0 : `=0 {${O(e, "zero")}}`,
202
- O(e, "one") === void 0 ? void 0 : `one {${O(e, "one")}}`,
203
- O(e, "two") === void 0 ? void 0 : `two {${O(e, "two")}}`,
204
- O(e, "few") === void 0 ? void 0 : `few {${O(e, "few")}}`,
205
- O(e, "many") === void 0 ? void 0 : `many {${O(e, "many")}}`,
206
- O(e, "other") === void 0 ? void 0 : `other {${O(e, "other")}}`
209
+ let r = k(e, "context"), i = ae(e, "offset"), a = [
210
+ k(e, "zero") === void 0 ? void 0 : `=0 {${k(e, "zero")}}`,
211
+ k(e, "one") === void 0 ? void 0 : `one {${k(e, "one")}}`,
212
+ k(e, "two") === void 0 ? void 0 : `two {${k(e, "two")}}`,
213
+ k(e, "few") === void 0 ? void 0 : `few {${k(e, "few")}}`,
214
+ k(e, "many") === void 0 ? void 0 : `many {${k(e, "many")}}`,
215
+ k(e, "other") === void 0 ? void 0 : `other {${k(e, "other")}}`
207
216
  ].filter(Boolean);
208
217
  if (a.length !== 0) return t(`{count, plural,${typeof i == "number" ? ` offset:${i}` : ""} ${a.join(" ")}}`, r);
209
218
  }
210
- function ie(e, t) {
211
- let n = O(e, "id");
219
+ function T(e, t) {
220
+ let n = k(e, "id");
212
221
  if (n) return n;
213
- let r = O(e, "context"), i = T(e);
222
+ let r = k(e, "context"), i = E(e);
214
223
  if (!(!i || i.other === void 0)) return t(`{value, select, ${[...Object.keys(i).filter((e) => e !== "other").sort(), "other"].map((e) => `${e} {${i[e]}}`).join(" ")}}`, r);
215
224
  }
216
- function T(e) {
217
- let t = D(e, "options");
225
+ function E(e) {
226
+ let t = O(e, "options");
218
227
  if (t) {
219
- let n = O(e, "other");
228
+ let n = k(e, "other");
220
229
  return {
221
230
  ...t,
222
231
  ...n === void 0 ? {} : { other: n }
@@ -224,7 +233,7 @@ function T(e) {
224
233
  }
225
234
  let n = {};
226
235
  for (let t of e.attributes) {
227
- if (!z(t)) continue;
236
+ if (!W(t)) continue;
228
237
  let e = t.name.name;
229
238
  if ([
230
239
  "value",
@@ -233,140 +242,132 @@ function T(e) {
233
242
  "comment",
234
243
  "options"
235
244
  ].includes(e)) continue;
236
- let r = A(t);
245
+ let r = j(t);
237
246
  r !== void 0 && (n[e] = r);
238
247
  }
239
248
  return Object.keys(n).length > 0 ? n : void 0;
240
249
  }
241
- function E(e) {
242
- if (!N(e)) return;
250
+ function D(e) {
251
+ if (!R(e)) return;
243
252
  let t = {};
244
253
  for (let n of e.properties) {
245
- if (!P(n) || n.computed) return;
246
- let e = M(n.key), r = j(n.value);
254
+ if (!z(n) || n.computed) return;
255
+ let e = N(n.key), r = M(n.value);
247
256
  if (!e || r === void 0) return;
248
257
  t[e] = r;
249
258
  }
250
259
  return t;
251
260
  }
252
- function D(e, t) {
253
- let n = k(e, t);
254
- if (n?.value && n.value.type === "JSXExpressionContainer") return E(n.value.expression);
255
- }
256
261
  function O(e, t) {
257
- return A(k(e, t));
262
+ let n = A(e, t);
263
+ if (n?.value && n.value.type === "JSXExpressionContainer") return D(n.value.expression);
264
+ }
265
+ function k(e, t) {
266
+ return j(A(e, t));
258
267
  }
259
268
  function ae(e, t) {
260
- let n = k(e, t);
269
+ let n = A(e, t);
261
270
  if (!n?.value || n.value.type !== "JSXExpressionContainer") return;
262
271
  let r = n.value.expression;
263
272
  return r.type === "NumericLiteral" ? r.value : void 0;
264
273
  }
265
- function k(e, t) {
266
- return e.attributes.find((e) => z(e) && e.name.name === t);
274
+ function A(e, t) {
275
+ return e.attributes.find((e) => W(e) && e.name.name === t);
267
276
  }
268
- function A(e) {
277
+ function j(e) {
269
278
  if (e?.value) {
270
279
  if (e.value.type === "StringLiteral") return e.value.value;
271
- if (e.value.type === "JSXExpressionContainer") return j(e.value.expression);
280
+ if (e.value.type === "JSXExpressionContainer") return M(e.value.expression);
272
281
  }
273
282
  }
274
283
  function oe(e) {
275
284
  return e.type === "JSXIdentifier" ? e.name : void 0;
276
285
  }
277
- function j(e) {
286
+ function M(e) {
278
287
  if (e.type === "StringLiteral") return e.value;
279
288
  if (e.type === "TemplateLiteral") {
280
289
  let t = e;
281
290
  if (t.expressions.length === 0 && t.quasis.length === 1) return t.quasis[0].value.cooked ?? t.quasis[0].value.raw;
282
291
  }
283
292
  }
284
- function M(e) {
285
- if (L(e)) return e.name;
293
+ function N(e) {
294
+ if (H(e)) return e.name;
286
295
  if (e.type === "StringLiteral") return e.value;
287
296
  }
288
- function se(e) {
297
+ function P(e) {
289
298
  return e.type === "ImportDeclaration";
290
299
  }
291
- function ce(e) {
300
+ function F(e) {
292
301
  return e.type === "ImportSpecifier";
293
302
  }
294
- function le(e) {
303
+ function I(e) {
295
304
  return e.type === "VariableDeclarator";
296
305
  }
297
- function ue(e) {
306
+ function L(e) {
298
307
  return e.type === "ObjectPattern";
299
308
  }
300
- function N(e) {
309
+ function R(e) {
301
310
  return e.type === "ObjectExpression";
302
311
  }
303
- function P(e) {
312
+ function z(e) {
304
313
  return e.type === "ObjectProperty";
305
314
  }
306
- function F(e) {
315
+ function B(e) {
307
316
  return e.type === "CallExpression";
308
317
  }
309
- function I(e) {
318
+ function V(e) {
310
319
  return e.type === "MemberExpression";
311
320
  }
312
- function L(e) {
321
+ function H(e) {
313
322
  return e?.type === "Identifier";
314
323
  }
315
- function R(e) {
324
+ function U(e) {
316
325
  return e.type === "JSXElement";
317
326
  }
318
- function z(e) {
327
+ function W(e) {
319
328
  return e.type === "JSXAttribute";
320
329
  }
321
- function B(e) {
330
+ function G(e) {
322
331
  let t = e.imported;
323
332
  if (t.type === "Identifier") return t.name;
324
333
  if (t.type === "StringLiteral") return t.value;
325
334
  }
326
- function V(e, n, r, i) {
335
+ function K(e, n, r, i) {
327
336
  if (n === "dynamic") return `import { __catalog } from 'virtual:fluenti/runtime';\n${e}`;
328
- if (n === "per-route") return `import { __catalog } from 'virtual:fluenti/route-runtime';\n${e}`;
329
337
  let a = i ?? t;
330
338
  return `import { ${[...r].map((e) => `_${a(e)}`).join(", ")} } from 'virtual:fluenti/messages';\n${e}`;
331
339
  }
332
340
  //#endregion
333
341
  //#region src/virtual-modules.ts
334
- function H(e) {
342
+ function se(e) {
335
343
  return JSON.stringify(e);
336
344
  }
337
- function U(e) {
345
+ function q(e) {
338
346
  if (e.includes("`") || e.includes("$")) throw Error(`[fluenti] vite-plugin: catalogDir must not contain backticks or $ characters, got ${JSON.stringify(e)}`);
339
347
  }
340
- var de = "virtual:fluenti/runtime", fe = "virtual:fluenti/messages", pe = "virtual:fluenti/route-runtime", W = "\0virtual:fluenti/runtime", G = "\0virtual:fluenti/messages", K = "\0virtual:fluenti/route-runtime";
341
- function q(e) {
342
- if (e === de) return W;
343
- if (e === fe) return G;
344
- if (e === pe) return K;
348
+ var ce = "virtual:fluenti/runtime", le = "virtual:fluenti/messages", J = "\0virtual:fluenti/runtime", Y = "\0virtual:fluenti/messages";
349
+ function X(e) {
350
+ if (e === ce) return J;
351
+ if (e === le) return Y;
345
352
  }
346
- function J(e, t) {
347
- if (e === W) return me(t);
348
- if (e === G) return he(t);
349
- if (e === K) return ge(t);
353
+ function Z(e, t) {
354
+ if (e === J) return ue(t);
355
+ if (e === Y) return de(t);
350
356
  }
351
- function me(e) {
357
+ function ue(e) {
352
358
  let { locales: t, runtimeGenerator: n, catalogDir: r } = e;
353
- U(r);
354
- for (let e of t) d(e, "vite-plugin");
359
+ q(r);
360
+ for (let e of t) p(e, "vite-plugin");
355
361
  if (!n) throw Error("[fluenti] vite-plugin: runtimeGenerator is required. Use a framework-specific plugin (e.g. @fluenti/vue/vite-plugin).");
356
- return n.generateRuntime(Y(e));
357
- }
358
- function he(e) {
359
- let { rootDir: t, catalogDir: n, catalogExtension: r, defaultBuildLocale: a, sourceLocale: o } = e, s = a || o;
360
- return d(s, "vite-plugin"), U(n), `export * from ${H(i(t, n) + "/" + s + r)}\n`;
362
+ return n.generateRuntime(fe(e));
361
363
  }
362
- function ge(e) {
363
- let { locales: t, runtimeGenerator: n, catalogDir: r } = e;
364
- U(r);
365
- for (let e of t) d(e, "vite-plugin");
366
- if (!n) throw Error("[fluenti] vite-plugin: runtimeGenerator is required. Use a framework-specific plugin (e.g. @fluenti/vue/vite-plugin).");
367
- return n.generateRouteRuntime(Y(e));
364
+ function de(e) {
365
+ let { rootDir: t, catalogDir: n, catalogExtension: r, defaultBuildLocale: i, sourceLocale: s } = e, c = i || s;
366
+ p(c, "vite-plugin"), q(n);
367
+ let l = a(a(t, n), c + r);
368
+ return o(l) || console.warn(`[fluenti] Compiled catalog for locale "${c}" not found at ${l}. Run "fluenti compile" first.`), `export * from ${se(l)}\n`;
368
369
  }
369
- function Y(e) {
370
+ function fe(e) {
370
371
  let { rootDir: t, catalogDir: n, catalogExtension: r, locales: i, sourceLocale: a, defaultBuildLocale: o } = e;
371
372
  return {
372
373
  rootDir: t,
@@ -378,49 +379,8 @@ function Y(e) {
378
379
  };
379
380
  }
380
381
  //#endregion
381
- //#region src/route-resolve.ts
382
- function X(e) {
383
- let t = (e.includes("/") ? e.slice(e.lastIndexOf("/") + 1) : e).replace(/\.[^.]+$/, "");
384
- return t.replace(/-[a-zA-Z0-9]{4,}$/, "") || t;
385
- }
386
- function _e(e) {
387
- let t = /* @__PURE__ */ new Map(), n = e.split("\n");
388
- for (let e = 0; e < n.length; e++) {
389
- let r = n[e], i = r.match(/^(?:\/\*.*?\*\/\s*)?export\s+const\s+_([a-z0-9]+)\s*=\s*/);
390
- if (!i) continue;
391
- let a = i[1], o = r, s = 0, c = 0, l = 0;
392
- for (let e of r.slice(i[0].length)) e === "{" && s++, e === "}" && s--, e === "(" && c++, e === ")" && c--, e === "`" && (l = l === 0 ? 1 : 0);
393
- for (; (s > 0 || c > 0 || l > 0) && e + 1 < n.length;) {
394
- e++;
395
- let t = n[e];
396
- o += "\n" + t;
397
- for (let e of t) e === "{" && s++, e === "}" && s--, e === "(" && c++, e === ")" && c--, e === "`" && (l = l === 0 ? 1 : 0);
398
- }
399
- t.set(a, o);
400
- }
401
- return t;
402
- }
403
- function Z(e, n) {
404
- let r = [], i = [];
405
- for (let a of e) {
406
- let e = t(a), o = n.get(e);
407
- o && (r.push(o), i.push(` '${ye(a)}': _${e},`));
408
- }
409
- return i.length > 0 && r.push("", "export default {", ...i, "}"), r.join("\n") + "\n";
410
- }
411
- function ve(e, t) {
412
- try {
413
- return f(i(e, `${t}.js`), "utf-8");
414
- } catch {
415
- return;
416
- }
417
- }
418
- function ye(e) {
419
- return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
420
- }
421
- //#endregion
422
382
  //#region src/index.ts
423
- var Q = a(typeof __filename < "u" ? __filename : import.meta.url), be = "virtual:fluenti/messages/", xe = "\0virtual:fluenti/messages/";
383
+ var Q = r(typeof __filename < "u" ? __filename : import.meta.url), pe = "virtual:fluenti/messages/", me = "\0virtual:fluenti/messages/";
424
384
  function $(e, t) {
425
385
  if (typeof e == "object") {
426
386
  let { DEFAULT_FLUENTI_CONFIG: t } = Q("@fluenti/core/config");
@@ -432,70 +392,72 @@ function $(e, t) {
432
392
  let { loadConfigSync: n } = Q("@fluenti/core/config");
433
393
  return n(typeof e == "string" ? e : void 0, t);
434
394
  }
435
- function Se(t, r, a) {
436
- let o, l = process.cwd();
437
- function u(e) {
438
- let n = e ?? l;
439
- return o ||= $(t.config, n), o;
395
+ function he(t, r, i) {
396
+ let a, o = process.cwd();
397
+ function s(e) {
398
+ let n = e ?? o;
399
+ return a ||= $(t.config, n), a;
440
400
  }
441
- let d = t.framework;
442
- function f(e) {
443
- let t = u(e), r = t.compileOutDir.replace(/^\.\//, ""), i = t.catalogExtension ?? ".js", a = t.splitting ?? !1, o = t.sourceLocale;
401
+ let c = t.framework;
402
+ function d(e) {
403
+ let t = s(e), r = t.compileOutDir.replace(/^\.\//, ""), i = t.catalogExtension ?? ".js", a = t.splitting ?? !1;
404
+ a && a !== "dynamic" && a !== "static" && console.warn(`[fluenti] Invalid splitting value "${a}". Expected 'dynamic', 'static', or false. Falling back to 'dynamic'.`);
405
+ let o = a === "static" ? "static" : a ? "dynamic" : !1, c = t.sourceLocale;
444
406
  return {
445
407
  config: t,
446
408
  catalogDir: r,
447
409
  catalogExtension: i,
448
- splitting: a,
449
- sourceLocale: o,
410
+ splitting: o,
411
+ sourceLocale: c,
450
412
  localeCodes: n(t.locales),
451
- defaultBuildLocale: t.defaultBuildLocale ?? o
413
+ defaultBuildLocale: t.defaultBuildLocale ?? c
452
414
  };
453
415
  }
454
- let p = {
416
+ let f = {
455
417
  name: "fluenti:virtual",
456
418
  configResolved(e) {
457
- l = e.root, o = $(t.config, l), m(e.command);
419
+ o = e.root, a = $(t.config, o), h(e.command);
458
420
  },
459
421
  resolveId(e) {
460
- if (e.startsWith(be)) return "\0" + e;
461
- let { splitting: t } = f();
422
+ if (e.startsWith(pe)) return "\0" + e;
423
+ let { splitting: t } = d();
462
424
  if (t) {
463
- let t = q(e);
425
+ let t = X(e);
464
426
  if (t) return t;
465
427
  }
466
428
  },
467
429
  load(e) {
468
- let { catalogDir: t, catalogExtension: n, splitting: r, localeCodes: i, sourceLocale: o, defaultBuildLocale: s } = f();
469
- if (e.startsWith(xe)) {
430
+ let { catalogDir: t, catalogExtension: n, splitting: r, localeCodes: a, sourceLocale: s, defaultBuildLocale: l } = d();
431
+ if (e.startsWith(me)) {
470
432
  let r = e.slice(26);
471
- return i.includes(r) ? `export { default } from '${`${t}/${r}${n}`}'` : void 0;
433
+ return a.includes(r) ? `export { default } from '${`${t}/${r}${n}`}'` : void 0;
472
434
  }
473
435
  if (r) {
474
- let r = J(e, {
475
- rootDir: l,
436
+ let r = Z(e, {
437
+ rootDir: o,
476
438
  catalogDir: t,
477
439
  catalogExtension: n,
478
- locales: i,
479
- sourceLocale: o,
480
- defaultBuildLocale: s,
481
- framework: d,
482
- runtimeGenerator: a
440
+ locales: a,
441
+ sourceLocale: s,
442
+ defaultBuildLocale: l,
443
+ framework: c,
444
+ runtimeGenerator: i
483
445
  });
484
446
  if (r) return r;
485
447
  }
486
448
  }
487
- }, y = s({ framework: d }), b = {
449
+ }, p = l({ framework: c }), m = {
488
450
  name: "fluenti:script-transform",
489
451
  enforce: "pre",
490
452
  transform(e, t) {
491
453
  if (t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/) || t.includes(".vue") && !t.includes("type=script")) return;
492
- let n = d === "vue" && t.includes(".vue"), r = e, i = !1;
454
+ let n = c === "vue" && t.includes(".vue"), r = e, i = !1;
493
455
  if (t.match(/\.[jt]sx(\?|$)/) && /<Trans[\s>]/.test(r)) {
494
- let e = y.transformTrans(r);
456
+ let e = p.transformTrans(r);
495
457
  e.transformed && (r = e.code, i = !0);
496
458
  }
497
- if (c(r)) {
498
- let e = y.transformScope(r, n ? { allowTopLevelImportedT: !0 } : void 0);
459
+ if (u(r)) {
460
+ let e = p.transformScope(r, n ? { allowTopLevelImportedT: !0 } : void 0);
499
461
  if (e.transformed) return {
500
462
  code: e.code,
501
463
  map: null
@@ -506,84 +468,31 @@ function Se(t, r, a) {
506
468
  map: null
507
469
  } : void 0;
508
470
  }
509
- }, x = /* @__PURE__ */ new Map(), S = {
471
+ }, b = {
510
472
  name: "fluenti:build-split",
511
473
  transform(e, t) {
512
- let { splitting: n, config: r } = f();
513
- if (!n || !g(h(this)) || t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)) return;
514
- let i = n === "static" ? "static" : "dynamic", a = r.idGenerator ? { hashFn: r.idGenerator } : void 0, o = i === "static" ? te(e, a) : ee(e, a);
515
- if (n === "per-route" && o.usedHashes.size > 0 && x.set(t, o.usedHashes), !o.needsCatalogImport) return;
516
- let s = n === "per-route" ? "per-route" : i;
517
- return {
518
- code: V(o.code, s, o.usedHashes, r.idGenerator),
474
+ let { splitting: n, config: r } = d();
475
+ if (!n || !_(g(this)) || t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)) return;
476
+ let i = n === "static" ? "static" : "dynamic", a = r.idGenerator ? { hashFn: r.idGenerator } : void 0, o = i === "static" ? te(e, a) : y(e, a);
477
+ if (o.needsCatalogImport) return {
478
+ code: K(o.code, i, o.usedHashes, r.idGenerator),
519
479
  map: null
520
480
  };
521
- },
522
- generateBundle(e, t) {
523
- let { splitting: n, localeCodes: r, catalogDir: a } = f();
524
- if (n !== "per-route" || x.size === 0) return;
525
- let o = /* @__PURE__ */ new Map();
526
- for (let [e, n] of Object.entries(t)) {
527
- if (n.type !== "chunk") continue;
528
- let t = /* @__PURE__ */ new Set();
529
- for (let e of Object.keys(n.modules)) {
530
- let n = x.get(e);
531
- if (n) for (let e of n) t.add(e);
532
- }
533
- t.size > 0 && o.set(e, t);
534
- }
535
- if (o.size === 0) return;
536
- let s = /* @__PURE__ */ new Map();
537
- for (let [e, t] of o) for (let n of t) {
538
- let t = s.get(n) ?? [];
539
- t.push(e), s.set(n, t);
540
- }
541
- let c = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Map();
542
- for (let [e, t] of s) if (t.length > 1) c.add(e);
543
- else {
544
- let n = X(t[0]), r = u.get(n) ?? /* @__PURE__ */ new Set();
545
- r.add(e), u.set(n, r);
546
- }
547
- let d = i(l, a);
548
- for (let e of r) {
549
- let t = ve(d, e);
550
- if (!t) {
551
- this.warn(`[fluenti] per-route splitting: compiled catalog for locale "${e}" not found in ${d} — skipping chunk generation`);
552
- continue;
553
- }
554
- let n = _e(t);
555
- if (c.size > 0) {
556
- let t = Z(c, n);
557
- this.emitFile({
558
- type: "asset",
559
- fileName: `_fluenti/shared-${e}.js`,
560
- source: t
561
- });
562
- }
563
- for (let [t, r] of u) {
564
- let i = Z(r, n);
565
- this.emitFile({
566
- type: "asset",
567
- fileName: `_fluenti/${t}-${e}.js`,
568
- source: i
569
- });
570
- }
571
- }
572
481
  }
573
- }, C = {
482
+ }, x = {
574
483
  name: "fluenti:build-compile",
575
484
  async buildStart() {
576
- let { config: e } = f();
577
- g(h(this)) && (e.buildAutoCompile ?? !0) && (e.onBeforeCompile && await e.onBeforeCompile() === !1 || (await _({
578
- cwd: l,
485
+ let { config: e } = d();
486
+ _(g(this)) && (e.buildAutoCompile ?? !0) && (e.onBeforeCompile && await e.onBeforeCompile() === !1 || (await v({
487
+ cwd: o,
579
488
  throwOnError: !0,
580
489
  compileOnly: !0
581
490
  }), e.onAfterCompile && await e.onAfterCompile()));
582
491
  }
583
- }, w = {
492
+ }, S = {
584
493
  name: "fluenti:dev",
585
494
  configureServer(t) {
586
- let { config: n, catalogDir: r } = f(t.config.root);
495
+ let { config: n, catalogDir: r } = d(t.config.root);
587
496
  if (!(n.devAutoCompile ?? !0)) return;
588
497
  let i = e(n.include ?? ["src/**/*.{vue,tsx,jsx,ts,js}"], [
589
498
  ...n.exclude ?? [],
@@ -594,13 +503,13 @@ function Se(t, r, a) {
594
503
  onSuccess: () => {}
595
504
  };
596
505
  n.parallelCompile && (a.parallelCompile = !0), n.onBeforeCompile && (a.onBeforeCompile = n.onBeforeCompile), n.onAfterCompile && (a.onAfterCompile = n.onAfterCompile);
597
- let o = v(a, n.devAutoCompileDelay ?? 500);
506
+ let o = ee(a, n.devAutoCompileDelay ?? 500);
598
507
  o(), t.watcher.on("change", (e) => {
599
508
  i(e) && o();
600
509
  });
601
510
  },
602
511
  hotUpdate({ file: e }) {
603
- let { catalogDir: t } = f();
512
+ let { catalogDir: t } = d();
604
513
  if (e.includes(t)) {
605
514
  let e = [...this.environment.moduleGraph.urlToModuleMap.entries()].filter(([e]) => e.includes("virtual:fluenti")).map(([, e]) => e);
606
515
  if (e.length > 0) return e;
@@ -608,15 +517,15 @@ function Se(t, r, a) {
608
517
  }
609
518
  };
610
519
  return [
611
- p,
520
+ f,
612
521
  ...r,
522
+ m,
523
+ x,
613
524
  b,
614
- C,
615
- S,
616
- w
525
+ S
617
526
  ];
618
527
  }
619
528
  //#endregion
620
- export { Se as createFluentiPlugins, o as createRuntimeGenerator, h as getPluginEnvironment, g as isBuildMode, J as loadVirtualSplitModule, q as resolveVirtualSplitId, m as setResolvedMode };
529
+ export { he as createFluentiPlugins, c as createRuntimeGenerator, g as getPluginEnvironment, _ as isBuildMode, Z as loadVirtualSplitModule, X as resolveVirtualSplitId, h as setResolvedMode };
621
530
 
622
531
  //# sourceMappingURL=index.js.map