@fluenti/vite-plugin 0.2.1 → 0.3.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.
package/dist/index.js CHANGED
@@ -1,34 +1,43 @@
1
- import { dirname as e, join as t, resolve as n } from "node:path";
2
- import { exec as r } from "node:child_process";
3
- import { existsSync as i, readFileSync as a } from "node:fs";
1
+ import { createFilter as e } from "vite";
2
+ import { hashMessage as t, resolveLocaleCodes as n } from "@fluenti/core/internal";
3
+ import { dirname as r, join as i, resolve as a } from "node:path";
4
4
  import { createRequire as o } from "node:module";
5
- import { hashMessage as s, validateLocale as c } from "@fluenti/core";
6
- import { parseSourceModule as l, scopeTransform as u, transformTransComponents as ee, walkSourceAst as d } from "@fluenti/core/internal";
5
+ import { execFile as s } from "node:child_process";
6
+ import { existsSync as c, readFileSync as l } from "node:fs";
7
+ import { createRuntimeGenerator as u, createTransformPipeline as ee, hasScopeTransformCandidate as te, parseSourceModule as d, walkSourceAst as f } from "@fluenti/core/transform";
8
+ import { validateLocale as p } from "@fluenti/core";
7
9
  //#region src/mode-detect.ts
8
- var f = "dev";
9
- function p(e) {
10
- f = e === "build" ? "build" : "dev";
10
+ var m = "dev";
11
+ function h(e) {
12
+ m = e === "build" ? "build" : "dev";
13
+ }
14
+ function g(e) {
15
+ if (typeof e == "object" && e && "environment" in e) {
16
+ let t = e.environment;
17
+ if (typeof t == "object" && t) return t;
18
+ }
11
19
  }
12
- function m(e) {
13
- return e?.mode === "build" || f === "build" || process.env.NODE_ENV === "production";
20
+ function _(e) {
21
+ return e?.mode === "build" || m === "build" || process.env.NODE_ENV === "production";
14
22
  }
15
23
  //#endregion
16
24
  //#region src/dev-runner.ts
17
- function h(t) {
18
- let r = t;
25
+ function v(e) {
26
+ let t = e;
19
27
  for (;;) {
20
- let t = n(r, "node_modules/.bin/fluenti");
21
- if (i(t)) return t;
22
- let a = e(r);
23
- if (a === r) break;
24
- r = a;
28
+ let e = a(t, "node_modules/.bin/fluenti");
29
+ if (c(e)) return e;
30
+ let n = r(t);
31
+ if (n === t) break;
32
+ t = n;
25
33
  }
26
34
  return null;
27
35
  }
28
- async function g(e) {
36
+ async function y(e) {
37
+ if (e.onBeforeCompile && await e.onBeforeCompile() === !1) return;
29
38
  if (e.compileOnly) try {
30
- let { runCompile: n } = o(t(e.cwd, "package.json"))("@fluenti/cli");
31
- await n(e.cwd), console.log("[fluenti] Compiling... done"), e.onSuccess?.();
39
+ let { runCompile: t } = o(i(e.cwd, "package.json"))("@fluenti/cli");
40
+ await t(e.cwd), console.log("[fluenti] Compiling... done"), e.onAfterCompile && await e.onAfterCompile(), e.onSuccess?.();
32
41
  return;
33
42
  } catch (t) {
34
43
  let n = t instanceof Error ? t : Error(String(t));
@@ -36,32 +45,48 @@ async function g(e) {
36
45
  console.warn("[fluenti] Compile failed:", n.message), e.onError?.(n);
37
46
  return;
38
47
  }
39
- let n = h(e.cwd);
40
- if (!n) {
48
+ try {
49
+ let { runExtract: t, runCompile: n } = o(i(e.cwd, "package.json"))("@fluenti/cli");
50
+ 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?.();
51
+ return;
52
+ } catch {}
53
+ let t = v(e.cwd);
54
+ if (!t) {
41
55
  let t = "[fluenti] CLI not found — skipping auto-compile. Install @fluenti/cli as a devDependency.";
42
56
  return e.throwOnError ? Promise.reject(Error(t)) : (console.warn(t), Promise.resolve());
43
57
  }
44
- let i = `${n} extract && ${n} compile`;
45
- return new Promise((t, n) => {
46
- r(i, { cwd: e.cwd }, (r, i, a) => {
47
- if (r) {
48
- let t = Error(a || r.message);
58
+ let n = e.parallelCompile ? ["compile", "--parallel"] : ["compile"];
59
+ return new Promise((r, i) => {
60
+ s(t, ["extract"], { cwd: e.cwd }, (a, o, c) => {
61
+ if (a) {
62
+ let t = Error(c || a.message);
49
63
  if (e.throwOnError) {
50
- n(t);
64
+ i(t);
51
65
  return;
52
66
  }
53
- console.warn("[fluenti] Extract/compile failed:", t.message), e.onError?.(t);
54
- } else console.log("[fluenti] Extracting and compiling... done"), e.onSuccess?.();
55
- t();
67
+ console.warn("[fluenti] Extract/compile failed:", t.message), e.onError?.(t), r();
68
+ return;
69
+ }
70
+ s(t, n, { cwd: e.cwd }, (t, n, a) => {
71
+ if (t) {
72
+ let n = Error(a || t.message);
73
+ if (e.throwOnError) {
74
+ i(n);
75
+ return;
76
+ }
77
+ console.warn("[fluenti] Extract/compile failed:", n.message), e.onError?.(n);
78
+ } else console.log("[fluenti] Extracting and compiling... done"), e.onAfterCompile && Promise.resolve(e.onAfterCompile()).catch(() => {}), e.onSuccess?.();
79
+ r();
80
+ });
56
81
  });
57
82
  });
58
83
  }
59
- function te(e, t = 300) {
84
+ function ne(e, t = 300) {
60
85
  let n = null, r = !1, i = !1;
61
86
  async function a() {
62
87
  r = !0;
63
88
  try {
64
- await g(e);
89
+ await y(e);
65
90
  } finally {
66
91
  r = !1, i && (i = !1, o());
67
92
  }
@@ -75,154 +100,154 @@ function te(e, t = 300) {
75
100
  }
76
101
  //#endregion
77
102
  //#region src/build-transform.ts
78
- function ne(e) {
79
- return _(e, "dynamic");
103
+ function re(e, t) {
104
+ return b(e, "dynamic", t);
80
105
  }
81
- function re(e) {
82
- return _(e, "static");
106
+ function ie(e, t) {
107
+ return b(e, "static", t);
83
108
  }
84
- function _(e, t) {
85
- let n = l(e);
86
- if (!n || n.type !== "Program") return {
109
+ function b(e, n, r) {
110
+ let i = r?.hashFn ?? t, a = d(e);
111
+ if (!a || a.type !== "Program") return {
87
112
  code: e,
88
113
  needsCatalogImport: !1,
89
114
  usedHashes: /* @__PURE__ */ new Set()
90
115
  };
91
- let r = v(n), i = [], a = /* @__PURE__ */ new Set();
92
- if (d(n, (n) => {
93
- let o = b(e, n, r, t, a);
94
- if (o) {
95
- i.push(o);
116
+ let o = x(a), s = [], c = /* @__PURE__ */ new Set();
117
+ if (f(a, (t) => {
118
+ let r = C(e, t, o, n, c, i);
119
+ if (r) {
120
+ s.push(r);
96
121
  return;
97
122
  }
98
- ie(n, a);
99
- }), i.length === 0) return {
123
+ E(t, c, i);
124
+ }), s.length === 0) return {
100
125
  code: e,
101
126
  needsCatalogImport: !1,
102
- usedHashes: a
127
+ usedHashes: c
103
128
  };
104
- let o = e;
105
- for (let e = i.length - 1; e >= 0; e--) {
106
- let { start: t, end: n, replacement: r } = i[e];
107
- o = o.slice(0, t) + r + o.slice(n);
129
+ let l = e;
130
+ for (let e = s.length - 1; e >= 0; e--) {
131
+ let { start: t, end: n, replacement: r } = s[e];
132
+ l = l.slice(0, t) + r + l.slice(n);
108
133
  }
109
134
  return {
110
- code: o,
135
+ code: l,
111
136
  needsCatalogImport: !0,
112
- usedHashes: a
137
+ usedHashes: c
113
138
  };
114
139
  }
115
- function v(e) {
140
+ function x(e) {
116
141
  let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
117
142
  for (let t of e.body) if (se(t)) for (let e of t.specifiers) {
118
143
  if (!ce(e)) continue;
119
- let t = H(e);
144
+ let t = fe(e);
120
145
  t && (t === "useI18n" && n.add(e.local.name), t === "getI18n" && r.add(e.local.name), t === "unref" && i.add(e.local.name));
121
146
  }
122
- return d(e, (e) => {
123
- if (!N(e) || !e.init || !P(e.id)) return;
124
- if (L(e.init) && z(e.init.callee) && n.has(e.init.callee.name)) {
125
- y(e.id, t);
147
+ return f(e, (e) => {
148
+ if (!le(e) || !e.init || !ue(e.id)) return;
149
+ if (z(e.init) && B(e.init.callee) && n.has(e.init.callee.name)) {
150
+ S(e.id, t);
126
151
  return;
127
152
  }
128
153
  let i = e.init.type === "AwaitExpression" ? e.init.argument : null;
129
- i && L(i) && z(i.callee) && r.has(i.callee.name) && y(e.id, t);
154
+ i && z(i) && B(i.callee) && r.has(i.callee.name) && S(e.id, t);
130
155
  }), {
131
156
  tracked: t,
132
157
  unref: i
133
158
  };
134
159
  }
135
- function y(e, t) {
136
- for (let n of e.properties) !I(n) || n.computed || !z(n.key) || n.key.name !== "t" || z(n.value) && t.add(n.value.name);
160
+ function S(e, t) {
161
+ for (let n of e.properties) !R(n) || n.computed || !B(n.key) || n.key.name !== "t" || B(n.value) && t.add(n.value.name);
137
162
  }
138
- function b(e, t, n, r, i) {
139
- if (!L(t) || t.start == null || t.end == null) return;
140
- let a = x(e, t, n);
141
- if (!a) return;
142
- let { catalogId: o } = a;
143
- i.add(o);
144
- let c = s(o), l = r === "dynamic" ? `__catalog[${JSON.stringify(o)}]` : `_${c}`, u = a.valuesSource ? `${l}(${a.valuesSource})` : l;
163
+ function C(e, t, n, r, i, a) {
164
+ if (!z(t) || t.start == null || t.end == null) return;
165
+ let o = w(e, t, n, a);
166
+ if (!o) return;
167
+ let { catalogId: s } = o;
168
+ i.add(s);
169
+ let c = a(s), l = r === "dynamic" ? `__catalog[${JSON.stringify(s)}]` : `_${c}`, u = o.valuesSource ? `${l}(${o.valuesSource})` : l;
145
170
  return {
146
171
  start: t.start,
147
172
  end: t.end,
148
173
  replacement: u
149
174
  };
150
175
  }
151
- function x(e, t, n) {
176
+ function w(e, t, n, r) {
152
177
  if (t.arguments.length === 0) return;
153
- let r = t.callee, i = z(r) && (n.tracked.has(r.name) || r.name === "$t"), a = R(r) && !r.computed && z(r.property) && (r.property.name === "$t" || r.property.name === "t" && z(r.object) && (r.object.name === "_ctx" || r.object.name === "$setup")), o = L(r) && z(r.callee) && n.unref.has(r.callee.name) && r.arguments.length === 1 && z(r.arguments[0]) && n.tracked.has(r.arguments[0].name);
154
- if (!i && !a && !o) return;
155
- let s = S(t.arguments[0]);
156
- if (!s) return;
157
- let c = 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;
158
- return c === void 0 ? { catalogId: s } : {
159
- catalogId: s,
160
- valuesSource: c
178
+ let i = t.callee, a = B(i) && (n.tracked.has(i.name) || i.name === "$t"), o = de(i) && !i.computed && B(i.property) && (i.property.name === "$t" || i.property.name === "t" && B(i.object) && (i.object.name === "_ctx" || i.object.name === "$setup")), s = z(i) && B(i.callee) && n.unref.has(i.callee.name) && i.arguments.length === 1 && B(i.arguments[0]) && n.tracked.has(i.arguments[0].name);
179
+ if (!a && !o && !s) return;
180
+ let c = T(t.arguments[0], r);
181
+ if (!c) return;
182
+ 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;
183
+ return l === void 0 ? { catalogId: c } : {
184
+ catalogId: c,
185
+ valuesSource: l
161
186
  };
162
187
  }
163
- function S(e) {
164
- let t = j(e);
165
- if (t !== void 0) return s(t);
166
- if (!F(e)) return;
167
- let n, r, i;
188
+ function T(e, t) {
189
+ let n = F(e);
190
+ if (n !== void 0) return t(n);
191
+ if (!L(e)) return;
192
+ let r, i, a;
168
193
  for (let t of e.properties) {
169
- if (!I(t) || t.computed) continue;
170
- let e = M(t.key);
194
+ if (!R(t) || t.computed) continue;
195
+ let e = I(t.key);
171
196
  if (!e) continue;
172
- let a = j(t.value);
173
- a !== void 0 && (e === "id" && (n = a), e === "message" && (r = a), e === "context" && (i = a));
197
+ let n = F(t.value);
198
+ n !== void 0 && (e === "id" && (r = n), e === "message" && (i = n), e === "context" && (a = n));
174
199
  }
175
- if (n) return n;
176
- if (r) return s(r, i);
177
- }
178
- function ie(e, t) {
179
- if (!B(e)) return;
180
- let n = oe(e.openingElement.name);
181
- if (n) {
182
- if (n === "Trans") {
183
- let n = O(e.openingElement, "__id") ?? O(e.openingElement, "id");
184
- if (n) {
185
- t.add(n);
200
+ if (r) return r;
201
+ if (i) return t(i, a);
202
+ }
203
+ function E(e, t, n) {
204
+ if (!V(e)) return;
205
+ let r = oe(e.openingElement.name);
206
+ if (r) {
207
+ if (r === "Trans") {
208
+ let r = M(e.openingElement, "__id") ?? M(e.openingElement, "id");
209
+ if (r) {
210
+ t.add(r);
186
211
  return;
187
212
  }
188
- let r = O(e.openingElement, "__message"), i = O(e.openingElement, "context");
189
- r && t.add(s(r, i));
213
+ let i = M(e.openingElement, "__message"), a = M(e.openingElement, "context");
214
+ i && t.add(n(i, a));
190
215
  return;
191
216
  }
192
- if (n === "Plural") {
193
- let n = C(e.openingElement);
194
- n && t.add(n);
217
+ if (r === "Plural") {
218
+ let r = D(e.openingElement, n);
219
+ r && t.add(r);
195
220
  return;
196
221
  }
197
- if (n === "Select") {
198
- let n = w(e.openingElement);
199
- n && t.add(n);
222
+ if (r === "Select") {
223
+ let r = O(e.openingElement, n);
224
+ r && t.add(r);
200
225
  }
201
226
  }
202
227
  }
203
- function C(e) {
204
- let t = O(e, "id");
205
- if (t) return t;
206
- let n = O(e, "context"), r = ae(e, "offset"), i = [
207
- O(e, "zero") === void 0 ? void 0 : `=0 {${O(e, "zero")}}`,
208
- O(e, "one") === void 0 ? void 0 : `one {${O(e, "one")}}`,
209
- O(e, "two") === void 0 ? void 0 : `two {${O(e, "two")}}`,
210
- O(e, "few") === void 0 ? void 0 : `few {${O(e, "few")}}`,
211
- O(e, "many") === void 0 ? void 0 : `many {${O(e, "many")}}`,
212
- O(e, "other") === void 0 ? void 0 : `other {${O(e, "other")}}`
228
+ function D(e, t) {
229
+ let n = M(e, "id");
230
+ if (n) return n;
231
+ let r = M(e, "context"), i = ae(e, "offset"), a = [
232
+ M(e, "zero") === void 0 ? void 0 : `=0 {${M(e, "zero")}}`,
233
+ M(e, "one") === void 0 ? void 0 : `one {${M(e, "one")}}`,
234
+ M(e, "two") === void 0 ? void 0 : `two {${M(e, "two")}}`,
235
+ M(e, "few") === void 0 ? void 0 : `few {${M(e, "few")}}`,
236
+ M(e, "many") === void 0 ? void 0 : `many {${M(e, "many")}}`,
237
+ M(e, "other") === void 0 ? void 0 : `other {${M(e, "other")}}`
213
238
  ].filter(Boolean);
214
- if (i.length !== 0) return s(`{count, plural,${typeof r == "number" ? ` offset:${r}` : ""} ${i.join(" ")}}`, n);
239
+ if (a.length !== 0) return t(`{count, plural,${typeof i == "number" ? ` offset:${i}` : ""} ${a.join(" ")}}`, r);
215
240
  }
216
- function w(e) {
217
- let t = O(e, "id");
218
- if (t) return t;
219
- let n = O(e, "context"), r = T(e);
220
- if (!(!r || r.other === void 0)) return s(`{value, select, ${[...Object.keys(r).filter((e) => e !== "other").sort(), "other"].map((e) => `${e} {${r[e]}}`).join(" ")}}`, n);
241
+ function O(e, t) {
242
+ let n = M(e, "id");
243
+ if (n) return n;
244
+ let r = M(e, "context"), i = k(e);
245
+ 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);
221
246
  }
222
- function T(e) {
223
- let t = D(e, "options");
247
+ function k(e) {
248
+ let t = j(e, "options");
224
249
  if (t) {
225
- let n = O(e, "other");
250
+ let n = M(e, "other");
226
251
  return {
227
252
  ...t,
228
253
  ...n === void 0 ? {} : { other: n }
@@ -230,7 +255,7 @@ function T(e) {
230
255
  }
231
256
  let n = {};
232
257
  for (let t of e.attributes) {
233
- if (!V(t)) continue;
258
+ if (!H(t)) continue;
234
259
  let e = t.name.name;
235
260
  if ([
236
261
  "value",
@@ -239,56 +264,56 @@ function T(e) {
239
264
  "comment",
240
265
  "options"
241
266
  ].includes(e)) continue;
242
- let r = A(t);
267
+ let r = P(t);
243
268
  r !== void 0 && (n[e] = r);
244
269
  }
245
270
  return Object.keys(n).length > 0 ? n : void 0;
246
271
  }
247
- function E(e) {
248
- if (!F(e)) return;
272
+ function A(e) {
273
+ if (!L(e)) return;
249
274
  let t = {};
250
275
  for (let n of e.properties) {
251
- if (!I(n) || n.computed) return;
252
- let e = M(n.key), r = j(n.value);
276
+ if (!R(n) || n.computed) return;
277
+ let e = I(n.key), r = F(n.value);
253
278
  if (!e || r === void 0) return;
254
279
  t[e] = r;
255
280
  }
256
281
  return t;
257
282
  }
258
- function D(e, t) {
259
- let n = k(e, t);
260
- if (n?.value && n.value.type === "JSXExpressionContainer") return E(n.value.expression);
283
+ function j(e, t) {
284
+ let n = N(e, t);
285
+ if (n?.value && n.value.type === "JSXExpressionContainer") return A(n.value.expression);
261
286
  }
262
- function O(e, t) {
263
- return A(k(e, t));
287
+ function M(e, t) {
288
+ return P(N(e, t));
264
289
  }
265
290
  function ae(e, t) {
266
- let n = k(e, t);
291
+ let n = N(e, t);
267
292
  if (!n?.value || n.value.type !== "JSXExpressionContainer") return;
268
293
  let r = n.value.expression;
269
294
  return r.type === "NumericLiteral" ? r.value : void 0;
270
295
  }
271
- function k(e, t) {
272
- return e.attributes.find((e) => V(e) && e.name.name === t);
296
+ function N(e, t) {
297
+ return e.attributes.find((e) => H(e) && e.name.name === t);
273
298
  }
274
- function A(e) {
299
+ function P(e) {
275
300
  if (e?.value) {
276
301
  if (e.value.type === "StringLiteral") return e.value.value;
277
- if (e.value.type === "JSXExpressionContainer") return j(e.value.expression);
302
+ if (e.value.type === "JSXExpressionContainer") return F(e.value.expression);
278
303
  }
279
304
  }
280
305
  function oe(e) {
281
306
  return e.type === "JSXIdentifier" ? e.name : void 0;
282
307
  }
283
- function j(e) {
308
+ function F(e) {
284
309
  if (e.type === "StringLiteral") return e.value;
285
310
  if (e.type === "TemplateLiteral") {
286
311
  let t = e;
287
312
  if (t.expressions.length === 0 && t.quasis.length === 1) return t.quasis[0].value.cooked ?? t.quasis[0].value.raw;
288
313
  }
289
314
  }
290
- function M(e) {
291
- if (z(e)) return e.name;
315
+ function I(e) {
316
+ if (B(e)) return e.name;
292
317
  if (e.type === "StringLiteral") return e.value;
293
318
  }
294
319
  function se(e) {
@@ -297,354 +322,99 @@ function se(e) {
297
322
  function ce(e) {
298
323
  return e.type === "ImportSpecifier";
299
324
  }
300
- function N(e) {
325
+ function le(e) {
301
326
  return e.type === "VariableDeclarator";
302
327
  }
303
- function P(e) {
328
+ function ue(e) {
304
329
  return e.type === "ObjectPattern";
305
330
  }
306
- function F(e) {
331
+ function L(e) {
307
332
  return e.type === "ObjectExpression";
308
333
  }
309
- function I(e) {
334
+ function R(e) {
310
335
  return e.type === "ObjectProperty";
311
336
  }
312
- function L(e) {
337
+ function z(e) {
313
338
  return e.type === "CallExpression";
314
339
  }
315
- function R(e) {
340
+ function de(e) {
316
341
  return e.type === "MemberExpression";
317
342
  }
318
- function z(e) {
343
+ function B(e) {
319
344
  return e?.type === "Identifier";
320
345
  }
321
- function B(e) {
346
+ function V(e) {
322
347
  return e.type === "JSXElement";
323
348
  }
324
- function V(e) {
349
+ function H(e) {
325
350
  return e.type === "JSXAttribute";
326
351
  }
327
- function H(e) {
352
+ function fe(e) {
328
353
  let t = e.imported;
329
354
  if (t.type === "Identifier") return t.name;
330
355
  if (t.type === "StringLiteral") return t.value;
331
356
  }
332
- function U(e, t, n) {
333
- return t === "dynamic" ? `import { __catalog } from 'virtual:fluenti/runtime';\n${e}` : t === "per-route" ? `import { __catalog } from 'virtual:fluenti/route-runtime';\n${e}` : `import { ${[...n].map((e) => `_${s(e)}`).join(", ")} } from 'virtual:fluenti/messages';\n${e}`;
357
+ function pe(e, n, r, i) {
358
+ if (n === "dynamic") return `import { __catalog } from 'virtual:fluenti/runtime';\n${e}`;
359
+ if (n === "per-route") return `import { __catalog } from 'virtual:fluenti/route-runtime';\n${e}`;
360
+ let a = i ?? t;
361
+ return `import { ${[...r].map((e) => `_${a(e)}`).join(", ")} } from 'virtual:fluenti/messages';\n${e}`;
334
362
  }
335
363
  //#endregion
336
364
  //#region src/virtual-modules.ts
337
- var W = "virtual:fluenti/runtime", G = "virtual:fluenti/messages", le = "virtual:fluenti/route-runtime", K = "\0virtual:fluenti/runtime", q = "\0virtual:fluenti/messages", J = "\0virtual:fluenti/route-runtime";
338
- function Y(e) {
339
- if (e === W) return K;
340
- if (e === G) return q;
341
- if (e === le) return J;
342
- }
343
- function X(e, t) {
344
- if (e === K) return ue(t);
345
- if (e === q) return de(t);
346
- if (e === J) return fe(t);
347
- }
348
- function ue(e) {
349
- let { locales: t, runtimeGenerator: n } = e;
350
- for (let e of t) c(e, "vite-plugin");
351
- return n ? n.generateRuntime(Z(e)) : pe(e);
352
- }
353
- function de(e) {
354
- let { catalogDir: t, defaultBuildLocale: r, sourceLocale: i } = e, a = r || i;
355
- return `export * from '${n(process.cwd(), t)}/${a}.js'\n`;
356
- }
357
- function fe(e) {
358
- let { locales: t, runtimeGenerator: n } = e;
359
- for (let e of t) c(e, "vite-plugin");
360
- return n ? n.generateRouteRuntime(Z(e)) : me(e);
365
+ function me(e) {
366
+ return JSON.stringify(e);
367
+ }
368
+ function U(e) {
369
+ if (e.includes("`") || e.includes("$")) throw Error(`[fluenti] vite-plugin: catalogDir must not contain backticks or $ characters, got ${JSON.stringify(e)}`);
370
+ }
371
+ var he = "virtual:fluenti/runtime", ge = "virtual:fluenti/messages", _e = "virtual:fluenti/route-runtime", W = "\0virtual:fluenti/runtime", G = "\0virtual:fluenti/messages", K = "\0virtual:fluenti/route-runtime";
372
+ function q(e) {
373
+ if (e === he) return W;
374
+ if (e === ge) return G;
375
+ if (e === _e) return K;
376
+ }
377
+ function J(e, t) {
378
+ if (e === W) return ve(t);
379
+ if (e === G) return ye(t);
380
+ if (e === K) return be(t);
381
+ }
382
+ function ve(e) {
383
+ let { locales: t, runtimeGenerator: n, catalogDir: r } = e;
384
+ U(r);
385
+ for (let e of t) p(e, "vite-plugin");
386
+ if (!n) throw Error("[fluenti] vite-plugin: runtimeGenerator is required. Use a framework-specific plugin (e.g. @fluenti/vue/vite-plugin).");
387
+ return n.generateRuntime(Y(e));
388
+ }
389
+ function ye(e) {
390
+ let { rootDir: t, catalogDir: n, catalogExtension: r, defaultBuildLocale: i, sourceLocale: o } = e, s = i || o;
391
+ return p(s, "vite-plugin"), U(n), `export * from ${me(a(t, n) + "/" + s + r)}\n`;
392
+ }
393
+ function be(e) {
394
+ let { locales: t, runtimeGenerator: n, catalogDir: r } = e;
395
+ U(r);
396
+ for (let e of t) p(e, "vite-plugin");
397
+ if (!n) throw Error("[fluenti] vite-plugin: runtimeGenerator is required. Use a framework-specific plugin (e.g. @fluenti/vue/vite-plugin).");
398
+ return n.generateRouteRuntime(Y(e));
361
399
  }
362
- function Z(e) {
363
- let { catalogDir: t, locales: n, sourceLocale: r, defaultBuildLocale: i } = e;
400
+ function Y(e) {
401
+ let { rootDir: t, catalogDir: n, catalogExtension: r, locales: i, sourceLocale: a, defaultBuildLocale: o } = e;
364
402
  return {
365
- catalogDir: t,
366
- locales: n,
367
- sourceLocale: r,
368
- defaultBuildLocale: i
403
+ rootDir: t,
404
+ catalogDir: n,
405
+ catalogExtension: r,
406
+ locales: i,
407
+ sourceLocale: a,
408
+ defaultBuildLocale: o
369
409
  };
370
410
  }
371
- function pe(e) {
372
- let { catalogDir: t, locales: r, sourceLocale: i, defaultBuildLocale: a, framework: o } = e, s = a || i, c = n(process.cwd(), t), l = `fluenti.runtime.${o}`, u = r.filter((e) => e !== s);
373
- return o === "react" ? `
374
- import __defaultMsgs from '${c}/${s}.js'
375
-
376
- const __catalog = { ...__defaultMsgs }
377
- let __currentLocale = '${s}'
378
- const __loadedLocales = new Set(['${s}'])
379
- let __loading = false
380
- const __cache = new Map()
381
- const __normalizeMessages = (mod) => mod.default ?? mod
382
-
383
- const __loaders = {
384
- ${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
385
- }
386
-
387
- async function __switchLocale(locale) {
388
- if (__loadedLocales.has(locale)) {
389
- Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)
390
- __currentLocale = locale
391
- return
392
- }
393
- __loading = true
394
- try {
395
- const mod = __normalizeMessages(await __loaders[locale]())
396
- __cache.set(locale, mod)
397
- __loadedLocales.add(locale)
398
- Object.assign(__catalog, mod)
399
- __currentLocale = locale
400
- } finally {
401
- __loading = false
402
- }
403
- }
404
-
405
- async function __preloadLocale(locale) {
406
- if (__loadedLocales.has(locale) || !__loaders[locale]) return
407
- try {
408
- const mod = __normalizeMessages(await __loaders[locale]())
409
- __cache.set(locale, mod)
410
- __loadedLocales.add(locale)
411
- } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
412
- }
413
-
414
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
415
-
416
- export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
417
- ` : o === "vue" ? `
418
- import { shallowReactive, triggerRef, ref } from 'vue'
419
- import __defaultMsgs from '${c}/${s}.js'
420
-
421
- const __catalog = shallowReactive({ ...__defaultMsgs })
422
- const __currentLocale = ref('${s}')
423
- const __loadedLocales = new Set(['${s}'])
424
- const __loading = ref(false)
425
- const __cache = new Map()
426
- const __normalizeMessages = (mod) => mod.default ?? mod
427
-
428
- const __loaders = {
429
- ${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
430
- }
431
-
432
- async function __switchLocale(locale) {
433
- if (__loadedLocales.has(locale)) {
434
- Object.assign(__catalog, __cache.get(locale) || __defaultMsgs)
435
- __currentLocale.value = locale
436
- return
437
- }
438
- __loading.value = true
439
- try {
440
- const mod = __normalizeMessages(await __loaders[locale]())
441
- __cache.set(locale, mod)
442
- __loadedLocales.add(locale)
443
- Object.assign(__catalog, mod)
444
- __currentLocale.value = locale
445
- } finally {
446
- __loading.value = false
447
- }
448
- }
449
-
450
- async function __preloadLocale(locale) {
451
- if (__loadedLocales.has(locale) || !__loaders[locale]) return
452
- try {
453
- const mod = __normalizeMessages(await __loaders[locale]())
454
- __cache.set(locale, mod)
455
- __loadedLocales.add(locale)
456
- } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
457
- }
458
-
459
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
460
-
461
- export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
462
- ` : `
463
- import { createSignal } from 'solid-js'
464
- import { createStore, reconcile } from 'solid-js/store'
465
- import __defaultMsgs from '${c}/${s}.js'
466
-
467
- const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
468
- const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
469
- const __loadedLocales = new Set(['${s}'])
470
- const [__loading, __setLoading] = createSignal(false)
471
- const __cache = new Map()
472
- const __normalizeMessages = (mod) => mod.default ?? mod
473
-
474
- const __loaders = {
475
- ${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
476
- }
477
-
478
- async function __switchLocale(locale) {
479
- if (__loadedLocales.has(locale)) {
480
- __setCatalog(reconcile(__cache.get(locale) || __defaultMsgs))
481
- __setCurrentLocale(locale)
482
- return
483
- }
484
- __setLoading(true)
485
- try {
486
- const mod = __normalizeMessages(await __loaders[locale]())
487
- __cache.set(locale, mod)
488
- __loadedLocales.add(locale)
489
- __setCatalog(reconcile(mod))
490
- __setCurrentLocale(locale)
491
- } finally {
492
- __setLoading(false)
493
- }
494
- }
495
-
496
- async function __preloadLocale(locale) {
497
- if (__loadedLocales.has(locale) || !__loaders[locale]) return
498
- try {
499
- const mod = __normalizeMessages(await __loaders[locale]())
500
- __cache.set(locale, mod)
501
- __loadedLocales.add(locale)
502
- } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
503
- }
504
-
505
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
506
-
507
- export { __catalog, __switchLocale, __preloadLocale, __currentLocale, __loading, __loadedLocales }
508
- `;
509
- }
510
- function me(e) {
511
- let { catalogDir: t, locales: r, sourceLocale: i, defaultBuildLocale: a, framework: o } = e, s = a || i, c = n(process.cwd(), t), l = `fluenti.runtime.${o}`, u = r.filter((e) => e !== s);
512
- return o === "vue" ? `
513
- import { shallowReactive, ref } from 'vue'
514
- import __defaultMsgs from '${c}/${s}.js'
515
-
516
- const __catalog = shallowReactive({ ...__defaultMsgs })
517
- const __currentLocale = ref('${s}')
518
- const __loadedLocales = new Set(['${s}'])
519
- const __loading = ref(false)
520
- const __cache = new Map()
521
- const __loadedRoutes = new Set()
522
- const __normalizeMessages = (mod) => mod.default ?? mod
523
-
524
- const __loaders = {
525
- ${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
526
- }
527
-
528
- const __routeLoaders = {}
529
-
530
- function __registerRouteLoader(routeId, locale, loader) {
531
- const key = routeId + ':' + locale
532
- __routeLoaders[key] = loader
533
- }
534
-
535
- async function __loadRoute(routeId, locale) {
536
- const key = routeId + ':' + (locale || __currentLocale.value)
537
- if (__loadedRoutes.has(key)) return
538
- const loader = __routeLoaders[key]
539
- if (!loader) return
540
- const mod = __normalizeMessages(await loader())
541
- Object.assign(__catalog, mod)
542
- __loadedRoutes.add(key)
543
- }
544
-
545
- async function __switchLocale(locale) {
546
- if (locale === __currentLocale.value) return
547
- __loading.value = true
548
- try {
549
- if (__cache.has(locale)) {
550
- Object.assign(__catalog, __cache.get(locale))
551
- } else {
552
- const mod = __normalizeMessages(await __loaders[locale]())
553
- __cache.set(locale, mod)
554
- Object.assign(__catalog, mod)
555
- }
556
- __loadedLocales.add(locale)
557
- __currentLocale.value = locale
558
- } finally {
559
- __loading.value = false
560
- }
561
- }
562
-
563
- async function __preloadLocale(locale) {
564
- if (__cache.has(locale) || !__loaders[locale]) return
565
- try {
566
- const mod = __normalizeMessages(await __loaders[locale]())
567
- __cache.set(locale, mod)
568
- __loadedLocales.add(locale)
569
- } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
570
- }
571
-
572
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
573
-
574
- export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
575
- ` : `
576
- import { createSignal } from 'solid-js'
577
- import { createStore, reconcile } from 'solid-js/store'
578
- import __defaultMsgs from '${c}/${s}.js'
579
-
580
- const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })
581
- const [__currentLocale, __setCurrentLocale] = createSignal('${s}')
582
- const __loadedLocales = new Set(['${s}'])
583
- const [__loading, __setLoading] = createSignal(false)
584
- const __cache = new Map()
585
- const __loadedRoutes = new Set()
586
- const __normalizeMessages = (mod) => mod.default ?? mod
587
-
588
- const __loaders = {
589
- ${u.map((e) => ` '${e}': () => import('${c}/${e}.js'),`).join("\n")}
590
- }
591
-
592
- const __routeLoaders = {}
593
-
594
- function __registerRouteLoader(routeId, locale, loader) {
595
- const key = routeId + ':' + locale
596
- __routeLoaders[key] = loader
597
- }
598
-
599
- async function __loadRoute(routeId, locale) {
600
- const key = routeId + ':' + (locale || __currentLocale())
601
- if (__loadedRoutes.has(key)) return
602
- const loader = __routeLoaders[key]
603
- if (!loader) return
604
- const mod = __normalizeMessages(await loader())
605
- __setCatalog(reconcile({ ...__catalog, ...mod }))
606
- __loadedRoutes.add(key)
607
- }
608
-
609
- async function __switchLocale(locale) {
610
- if (locale === __currentLocale()) return
611
- __setLoading(true)
612
- try {
613
- if (__cache.has(locale)) {
614
- __setCatalog(reconcile(__cache.get(locale)))
615
- } else {
616
- const mod = __normalizeMessages(await __loaders[locale]())
617
- __cache.set(locale, mod)
618
- __setCatalog(reconcile(mod))
619
- }
620
- __loadedLocales.add(locale)
621
- __setCurrentLocale(locale)
622
- } finally {
623
- __setLoading(false)
624
- }
625
- }
626
-
627
- async function __preloadLocale(locale) {
628
- if (__cache.has(locale) || !__loaders[locale]) return
629
- try {
630
- const mod = __normalizeMessages(await __loaders[locale]())
631
- __cache.set(locale, mod)
632
- __loadedLocales.add(locale)
633
- } catch (e) { console.warn('[fluenti] preload failed:', locale, e) }
634
- }
635
-
636
- globalThis[Symbol.for('${l}')] = { __switchLocale, __preloadLocale }
637
-
638
- export { __catalog, __switchLocale, __preloadLocale, __loadRoute, __registerRouteLoader, __currentLocale, __loading, __loadedLocales }
639
- `;
640
- }
641
411
  //#endregion
642
412
  //#region src/route-resolve.ts
643
- function Q(e) {
413
+ function xe(e) {
644
414
  let t = (e.includes("/") ? e.slice(e.lastIndexOf("/") + 1) : e).replace(/\.[^.]+$/, "");
645
415
  return t.replace(/-[a-zA-Z0-9]{4,}$/, "") || t;
646
416
  }
647
- function he(e) {
417
+ function Se(e) {
648
418
  let t = /* @__PURE__ */ new Map(), n = e.split("\n");
649
419
  for (let e = 0; e < n.length; e++) {
650
420
  let r = n[e], i = r.match(/^(?:\/\*.*?\*\/\s*)?export\s+const\s+_([a-z0-9]+)\s*=\s*/);
@@ -661,130 +431,144 @@ function he(e) {
661
431
  }
662
432
  return t;
663
433
  }
664
- function $(e, t) {
665
- let n = [], r = [];
666
- for (let i of e) {
667
- let e = s(i), a = t.get(e);
668
- a && (n.push(a), r.push(` '${_e(i)}': _${e},`));
434
+ function X(e, n) {
435
+ let r = [], i = [];
436
+ for (let a of e) {
437
+ let e = t(a), o = n.get(e);
438
+ o && (r.push(o), i.push(` '${we(a)}': _${e},`));
669
439
  }
670
- return r.length > 0 && n.push("", "export default {", ...r, "}"), n.join("\n") + "\n";
440
+ return i.length > 0 && r.push("", "export default {", ...i, "}"), r.join("\n") + "\n";
671
441
  }
672
- function ge(e, t) {
442
+ function Ce(e, t) {
673
443
  try {
674
- return a(n(e, `${t}.js`), "utf-8");
444
+ return l(a(e, `${t}.js`), "utf-8");
675
445
  } catch {
676
446
  return;
677
447
  }
678
448
  }
679
- function _e(e) {
449
+ function we(e) {
680
450
  return e.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
681
451
  }
682
452
  //#endregion
683
453
  //#region src/index.ts
684
- var ve = "virtual:fluenti/messages/", ye = "\0virtual:fluenti/messages/";
685
- function be(e, t, r) {
686
- let i = e.catalogDir ?? "src/locales/compiled", a = e.framework, o = e.splitting ?? !1, s = e.sourceLocale ?? "en", c = e.locales ?? [s], l = e.defaultBuildLocale ?? s, d = {
454
+ var Z = o(import.meta.url), Q = "virtual:fluenti/messages/", Te = "\0virtual:fluenti/messages/";
455
+ function $(e, t) {
456
+ if (typeof e == "object") {
457
+ let { DEFAULT_FLUENTI_CONFIG: t } = Z("@fluenti/core/config");
458
+ return {
459
+ ...t,
460
+ ...e
461
+ };
462
+ }
463
+ let { loadConfigSync: n } = Z("@fluenti/core/config");
464
+ return n(typeof e == "string" ? e : void 0, t);
465
+ }
466
+ function Ee(t, r, i) {
467
+ let o;
468
+ function s(e) {
469
+ return o ||= $(t.config, e), o;
470
+ }
471
+ let c = $(t.config), l = c.compileOutDir.replace(/^\.\//, ""), u = c.catalogExtension ?? ".js", d = t.framework, f = c.splitting ?? !1, p = c.sourceLocale, m = n(c.locales), v = c.defaultBuildLocale ?? p, b = c.idGenerator, x = c.onBeforeCompile, S = c.onAfterCompile, C = process.cwd(), w = {
687
472
  name: "fluenti:virtual",
688
473
  configResolved(e) {
689
- p(e.command);
474
+ C = e.root, h(e.command);
690
475
  },
691
476
  resolveId(e) {
692
- if (e.startsWith(ve)) return "\0" + e;
693
- if (o) {
694
- let t = Y(e);
477
+ if (e.startsWith(Q)) return "\0" + e;
478
+ if (f) {
479
+ let t = q(e);
695
480
  if (t) return t;
696
481
  }
697
482
  },
698
483
  load(e) {
699
- if (e.startsWith(ye)) return `export { default } from '${`${i}/${e.slice(26)}.js`}'`;
700
- if (o) {
701
- let t = X(e, {
702
- catalogDir: i,
703
- locales: c,
704
- sourceLocale: s,
705
- defaultBuildLocale: l,
706
- framework: a,
707
- runtimeGenerator: r
484
+ if (e.startsWith(Te)) return `export { default } from '${`${l}/${e.slice(26)}${u}`}'`;
485
+ if (f) {
486
+ let t = J(e, {
487
+ rootDir: C,
488
+ catalogDir: l,
489
+ catalogExtension: u,
490
+ locales: m,
491
+ sourceLocale: p,
492
+ defaultBuildLocale: v,
493
+ framework: d,
494
+ runtimeGenerator: i
708
495
  });
709
496
  if (t) return t;
710
497
  }
711
498
  }
712
- }, f = {
499
+ }, T = ee({ framework: d }), E = {
713
500
  name: "fluenti:script-transform",
714
501
  enforce: "pre",
715
502
  transform(e, t) {
716
503
  if (t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/) || t.includes(".vue") && !t.includes("type=script")) return;
717
- let n = e, r = !1;
718
- if (t.match(/\.[jt]sx(\?|$)/) && /<Trans[\s>]/.test(n)) {
719
- let e = ee(n);
720
- e.transformed && (n = e.code, r = !0);
504
+ let n = d === "vue" && t.includes(".vue"), r = e, i = !1;
505
+ if (t.match(/\.[jt]sx(\?|$)/) && /<Trans[\s>]/.test(r)) {
506
+ let e = T.transformTrans(r);
507
+ e.transformed && (r = e.code, i = !0);
721
508
  }
722
- if (Se(n)) {
723
- let e = u(n, {
724
- framework: a,
725
- allowTopLevelImportedT: a === "vue" && t.includes(".vue")
726
- });
509
+ if (te(r)) {
510
+ let e = T.transformScope(r, n ? { allowTopLevelImportedT: !0 } : void 0);
727
511
  if (e.transformed) return {
728
512
  code: e.code,
729
513
  map: null
730
514
  };
731
515
  }
732
- return r ? {
733
- code: n,
516
+ return i ? {
517
+ code: r,
734
518
  map: null
735
519
  } : void 0;
736
520
  }
737
- }, h = /* @__PURE__ */ new Map(), _ = {
521
+ }, D = /* @__PURE__ */ new Map(), O = {
738
522
  name: "fluenti:build-split",
739
523
  transform(e, t) {
740
- if (!o || !m(this.environment) || t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)) return;
741
- let n = o === "static" ? "static" : "dynamic", r = n === "static" ? re(e) : ne(e);
742
- if (o === "per-route" && r.usedHashes.size > 0 && h.set(t, r.usedHashes), !r.needsCatalogImport) return;
743
- let i = o === "per-route" ? "per-route" : n;
524
+ if (!f || !_(g(this)) || t.includes("node_modules") || !t.match(/\.(vue|tsx|jsx|ts|js)(\?|$)/)) return;
525
+ let n = f === "static" ? "static" : "dynamic", r = b ? { hashFn: b } : void 0, i = n === "static" ? ie(e, r) : re(e, r);
526
+ if (f === "per-route" && i.usedHashes.size > 0 && D.set(t, i.usedHashes), !i.needsCatalogImport) return;
527
+ let a = f === "per-route" ? "per-route" : n;
744
528
  return {
745
- code: U(r.code, i, r.usedHashes),
529
+ code: pe(i.code, a, i.usedHashes, b),
746
530
  map: null
747
531
  };
748
532
  },
749
533
  generateBundle(e, t) {
750
- if (o !== "per-route" || h.size === 0) return;
751
- let r = /* @__PURE__ */ new Map();
752
- for (let [e, n] of Object.entries(t)) {
753
- if (n.type !== "chunk") continue;
534
+ if (f !== "per-route" || D.size === 0) return;
535
+ let n = /* @__PURE__ */ new Map();
536
+ for (let [e, r] of Object.entries(t)) {
537
+ if (r.type !== "chunk") continue;
754
538
  let t = /* @__PURE__ */ new Set();
755
- for (let e of Object.keys(n.modules)) {
756
- let n = h.get(e);
539
+ for (let e of Object.keys(r.modules)) {
540
+ let n = D.get(e);
757
541
  if (n) for (let e of n) t.add(e);
758
542
  }
759
- t.size > 0 && r.set(e, t);
543
+ t.size > 0 && n.set(e, t);
760
544
  }
761
- if (r.size === 0) return;
762
- let a = /* @__PURE__ */ new Map();
763
- for (let [e, t] of r) for (let n of t) {
764
- let t = a.get(n) ?? [];
765
- t.push(e), a.set(n, t);
545
+ if (n.size === 0) return;
546
+ let r = /* @__PURE__ */ new Map();
547
+ for (let [e, t] of n) for (let n of t) {
548
+ let t = r.get(n) ?? [];
549
+ t.push(e), r.set(n, t);
766
550
  }
767
- let s = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Map();
768
- for (let [e, t] of a) if (t.length > 1) s.add(e);
551
+ let i = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
552
+ for (let [e, t] of r) if (t.length > 1) i.add(e);
769
553
  else {
770
- let n = Q(t[0]), r = l.get(n) ?? /* @__PURE__ */ new Set();
771
- r.add(e), l.set(n, r);
554
+ let n = xe(t[0]), r = o.get(n) ?? /* @__PURE__ */ new Set();
555
+ r.add(e), o.set(n, r);
772
556
  }
773
- let u = n(process.cwd(), i);
774
- for (let e of c) {
775
- let t = ge(u, e);
557
+ let s = a(C, l);
558
+ for (let e of m) {
559
+ let t = Ce(s, e);
776
560
  if (!t) continue;
777
- let n = he(t);
778
- if (s.size > 0) {
779
- let t = $(s, n);
561
+ let n = Se(t);
562
+ if (i.size > 0) {
563
+ let t = X(i, n);
780
564
  this.emitFile({
781
565
  type: "asset",
782
566
  fileName: `_fluenti/shared-${e}.js`,
783
567
  source: t
784
568
  });
785
569
  }
786
- for (let [t, r] of l) {
787
- let i = $(r, n);
570
+ for (let [t, r] of o) {
571
+ let i = X(r, n);
788
572
  this.emitFile({
789
573
  type: "asset",
790
574
  fileName: `_fluenti/${t}-${e}.js`,
@@ -793,53 +577,50 @@ function be(e, t, r) {
793
577
  }
794
578
  }
795
579
  }
796
- }, v = e.buildAutoCompile ?? !0, y = {
580
+ }, k = c.buildAutoCompile ?? !0, A = {
797
581
  name: "fluenti:build-compile",
798
582
  async buildStart() {
799
- !m(this.environment) || !v || await g({
800
- cwd: process.cwd(),
583
+ !_(g(this)) || !k || x && await x() === !1 || (await y({
584
+ cwd: C,
801
585
  throwOnError: !0,
802
586
  compileOnly: !0
803
- });
587
+ }), S && await S());
804
588
  }
805
- }, b = e.devAutoCompile ?? !0, x = e.include ?? ["src/**/*.{vue,tsx,jsx,ts,js}"], S = {
589
+ }, j = c.devAutoCompile ?? !0, M = {
806
590
  name: "fluenti:dev",
807
- configureServer(e) {
808
- if (!b) return;
809
- let t = te({
810
- cwd: e.config.root,
591
+ configureServer(t) {
592
+ if (!j) return;
593
+ let n = s(t.config.root), r = e(n.include ?? ["src/**/*.{vue,tsx,jsx,ts,js}"], [
594
+ ...n.exclude ?? [],
595
+ "**/node_modules/**",
596
+ `**/${l}/**`
597
+ ]), i = {
598
+ cwd: t.config.root,
811
599
  onSuccess: () => {}
812
- });
813
- t(), e.watcher.on("change", (e) => {
814
- xe(e, x) && !e.includes(i) && t();
600
+ };
601
+ c.parallelCompile && (i.parallelCompile = !0), x && (i.onBeforeCompile = x), S && (i.onAfterCompile = S);
602
+ let a = ne(i, c.devAutoCompileDelay ?? 500);
603
+ a(), t.watcher.on("change", (e) => {
604
+ r(e) && a();
815
605
  });
816
606
  },
817
607
  hotUpdate({ file: e }) {
818
- if (e.includes(i)) {
608
+ if (e.includes(l)) {
819
609
  let e = [...this.environment.moduleGraph.urlToModuleMap.entries()].filter(([e]) => e.includes("virtual:fluenti")).map(([, e]) => e);
820
610
  if (e.length > 0) return e;
821
611
  }
822
612
  }
823
613
  };
824
614
  return [
825
- d,
826
- ...t,
827
- f,
828
- y,
829
- _,
830
- S
615
+ w,
616
+ ...r,
617
+ E,
618
+ A,
619
+ O,
620
+ M
831
621
  ];
832
622
  }
833
- function xe(e, t) {
834
- return !/\.(vue|tsx|jsx|ts|js)$/.test(e) || e.includes("node_modules") ? !1 : t.some((t) => {
835
- let n = t.split("*")[0] ?? "";
836
- return n === "" || e.includes(n.replace("./", ""));
837
- });
838
- }
839
- function Se(e) {
840
- return /(?<![.\w$])t\(\s*['"]/.test(e) || /[A-Za-z_$][\w$]*\(\s*\{/.test(e) || /[A-Za-z_$][\w$]*`/.test(e) && (e.includes("useI18n") || e.includes("getI18n")) ? !0 : /import\s*\{[^}]*\bt(?:\s+as\s+[A-Za-z_$][\w$]*)?\b[^}]*\}/.test(e) && /@fluenti\/(react|vue|solid|next)/.test(e);
841
- }
842
623
  //#endregion
843
- export { be as createFluentiPlugins, m as isBuildMode, X as loadVirtualSplitModule, Y as resolveVirtualSplitId, p as setResolvedMode };
624
+ export { Ee as createFluentiPlugins, u as createRuntimeGenerator, g as getPluginEnvironment, _ as isBuildMode, J as loadVirtualSplitModule, q as resolveVirtualSplitId, h as setResolvedMode };
844
625
 
845
626
  //# sourceMappingURL=index.js.map