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