@fluenti/vite-plugin 0.2.0 → 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/client.d.ts +3 -9
- package/dist/build-transform.d.ts +8 -3
- package/dist/build-transform.d.ts.map +1 -1
- package/dist/dev-runner.d.ts +6 -0
- package/dist/dev-runner.d.ts.map +1 -1
- package/dist/index.cjs +3 -270
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +336 -555
- package/dist/index.js.map +1 -1
- package/dist/mode-detect.d.ts +9 -2
- package/dist/mode-detect.d.ts.map +1 -1
- package/dist/runtime-template.d.ts +3 -0
- package/dist/runtime-template.d.ts.map +1 -0
- package/dist/sfc-transform.cjs +1 -1
- package/dist/sfc-transform.cjs.map +1 -1
- package/dist/sfc-transform.d.ts +1 -0
- package/dist/sfc-transform.d.ts.map +1 -1
- package/dist/sfc-transform.js +288 -174
- package/dist/sfc-transform.js.map +1 -1
- package/dist/types.d.ts +10 -48
- package/dist/types.d.ts.map +1 -1
- package/dist/virtual-modules.d.ts +3 -1
- package/dist/virtual-modules.d.ts.map +1 -1
- package/llms-full.txt +124 -0
- package/llms.txt +57 -0
- package/package.json +4 -3
- package/dist/scope-transform.d.ts +0 -3
- package/dist/scope-transform.d.ts.map +0 -1
- package/dist/trans-transform.d.ts +0 -3
- package/dist/trans-transform.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,34 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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 {
|
|
6
|
-
import {
|
|
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
|
|
9
|
-
function
|
|
10
|
-
|
|
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
|
|
13
|
-
return e?.mode === "build" ||
|
|
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
|
|
18
|
-
let
|
|
25
|
+
function v(e) {
|
|
26
|
+
let t = e;
|
|
19
27
|
for (;;) {
|
|
20
|
-
let
|
|
21
|
-
if (
|
|
22
|
-
let
|
|
23
|
-
if (
|
|
24
|
-
|
|
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
|
|
36
|
+
async function y(e) {
|
|
37
|
+
if (e.onBeforeCompile && await e.onBeforeCompile() === !1) return;
|
|
29
38
|
if (e.compileOnly) try {
|
|
30
|
-
let { runCompile:
|
|
31
|
-
await
|
|
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
|
-
|
|
40
|
-
|
|
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
|
|
45
|
-
return new Promise((
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
let t = Error(
|
|
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
|
-
|
|
64
|
+
i(t);
|
|
51
65
|
return;
|
|
52
66
|
}
|
|
53
|
-
console.warn("[fluenti] Extract/compile failed:", t.message), e.onError?.(t);
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|
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
|
|
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
|
|
79
|
-
return
|
|
103
|
+
function re(e, t) {
|
|
104
|
+
return b(e, "dynamic", t);
|
|
80
105
|
}
|
|
81
|
-
function
|
|
82
|
-
return
|
|
106
|
+
function ie(e, t) {
|
|
107
|
+
return b(e, "static", t);
|
|
83
108
|
}
|
|
84
|
-
function
|
|
85
|
-
let
|
|
86
|
-
if (!
|
|
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
|
|
92
|
-
if (
|
|
93
|
-
let
|
|
94
|
-
if (
|
|
95
|
-
|
|
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
|
-
|
|
99
|
-
}),
|
|
123
|
+
E(t, c, i);
|
|
124
|
+
}), s.length === 0) return {
|
|
100
125
|
code: e,
|
|
101
126
|
needsCatalogImport: !1,
|
|
102
|
-
usedHashes:
|
|
127
|
+
usedHashes: c
|
|
103
128
|
};
|
|
104
|
-
let
|
|
105
|
-
for (let e =
|
|
106
|
-
let { start: t, end: n, replacement: r } =
|
|
107
|
-
|
|
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:
|
|
135
|
+
code: l,
|
|
111
136
|
needsCatalogImport: !0,
|
|
112
|
-
usedHashes:
|
|
137
|
+
usedHashes: c
|
|
113
138
|
};
|
|
114
139
|
}
|
|
115
|
-
function
|
|
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 =
|
|
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
|
|
123
|
-
if (!
|
|
124
|
-
if (
|
|
125
|
-
|
|
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 &&
|
|
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
|
|
136
|
-
for (let n of e.properties) !
|
|
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
|
|
139
|
-
if (!
|
|
140
|
-
let
|
|
141
|
-
if (!
|
|
142
|
-
let { catalogId:
|
|
143
|
-
i.add(
|
|
144
|
-
let c = s
|
|
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
|
|
176
|
+
function w(e, t, n, r) {
|
|
152
177
|
if (t.arguments.length === 0) return;
|
|
153
|
-
let
|
|
154
|
-
if (!
|
|
155
|
-
let
|
|
156
|
-
if (!
|
|
157
|
-
let
|
|
158
|
-
return
|
|
159
|
-
catalogId:
|
|
160
|
-
valuesSource:
|
|
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
|
|
164
|
-
let
|
|
165
|
-
if (
|
|
166
|
-
if (!
|
|
167
|
-
let
|
|
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 (!
|
|
170
|
-
let e =
|
|
194
|
+
if (!R(t) || t.computed) continue;
|
|
195
|
+
let e = I(t.key);
|
|
171
196
|
if (!e) continue;
|
|
172
|
-
let
|
|
173
|
-
|
|
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 (
|
|
176
|
-
if (
|
|
177
|
-
}
|
|
178
|
-
function
|
|
179
|
-
if (!
|
|
180
|
-
let
|
|
181
|
-
if (
|
|
182
|
-
if (
|
|
183
|
-
let
|
|
184
|
-
if (
|
|
185
|
-
t.add(
|
|
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
|
|
189
|
-
|
|
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 (
|
|
193
|
-
let
|
|
194
|
-
|
|
217
|
+
if (r === "Plural") {
|
|
218
|
+
let r = D(e.openingElement, n);
|
|
219
|
+
r && t.add(r);
|
|
195
220
|
return;
|
|
196
221
|
}
|
|
197
|
-
if (
|
|
198
|
-
let
|
|
199
|
-
|
|
222
|
+
if (r === "Select") {
|
|
223
|
+
let r = O(e.openingElement, n);
|
|
224
|
+
r && t.add(r);
|
|
200
225
|
}
|
|
201
226
|
}
|
|
202
227
|
}
|
|
203
|
-
function
|
|
204
|
-
let
|
|
205
|
-
if (
|
|
206
|
-
let
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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 (
|
|
239
|
+
if (a.length !== 0) return t(`{count, plural,${typeof i == "number" ? ` offset:${i}` : ""} ${a.join(" ")}}`, r);
|
|
215
240
|
}
|
|
216
|
-
function
|
|
217
|
-
let
|
|
218
|
-
if (
|
|
219
|
-
let
|
|
220
|
-
if (!(!
|
|
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
|
|
223
|
-
let t =
|
|
247
|
+
function k(e) {
|
|
248
|
+
let t = j(e, "options");
|
|
224
249
|
if (t) {
|
|
225
|
-
let n =
|
|
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 (!
|
|
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 =
|
|
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
|
|
248
|
-
if (!
|
|
272
|
+
function A(e) {
|
|
273
|
+
if (!L(e)) return;
|
|
249
274
|
let t = {};
|
|
250
275
|
for (let n of e.properties) {
|
|
251
|
-
if (!
|
|
252
|
-
let e =
|
|
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
|
|
259
|
-
let n =
|
|
260
|
-
if (n?.value && n.value.type === "JSXExpressionContainer") return
|
|
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
|
|
263
|
-
return
|
|
287
|
+
function M(e, t) {
|
|
288
|
+
return P(N(e, t));
|
|
264
289
|
}
|
|
265
290
|
function ae(e, t) {
|
|
266
|
-
let n =
|
|
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
|
|
272
|
-
return e.attributes.find((e) =>
|
|
296
|
+
function N(e, t) {
|
|
297
|
+
return e.attributes.find((e) => H(e) && e.name.name === t);
|
|
273
298
|
}
|
|
274
|
-
function
|
|
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
|
|
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
|
|
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
|
|
291
|
-
if (
|
|
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
|
|
325
|
+
function le(e) {
|
|
301
326
|
return e.type === "VariableDeclarator";
|
|
302
327
|
}
|
|
303
|
-
function
|
|
328
|
+
function ue(e) {
|
|
304
329
|
return e.type === "ObjectPattern";
|
|
305
330
|
}
|
|
306
|
-
function
|
|
331
|
+
function L(e) {
|
|
307
332
|
return e.type === "ObjectExpression";
|
|
308
333
|
}
|
|
309
|
-
function
|
|
334
|
+
function R(e) {
|
|
310
335
|
return e.type === "ObjectProperty";
|
|
311
336
|
}
|
|
312
|
-
function
|
|
337
|
+
function z(e) {
|
|
313
338
|
return e.type === "CallExpression";
|
|
314
339
|
}
|
|
315
|
-
function
|
|
340
|
+
function de(e) {
|
|
316
341
|
return e.type === "MemberExpression";
|
|
317
342
|
}
|
|
318
|
-
function
|
|
343
|
+
function B(e) {
|
|
319
344
|
return e?.type === "Identifier";
|
|
320
345
|
}
|
|
321
|
-
function
|
|
346
|
+
function V(e) {
|
|
322
347
|
return e.type === "JSXElement";
|
|
323
348
|
}
|
|
324
|
-
function
|
|
349
|
+
function H(e) {
|
|
325
350
|
return e.type === "JSXAttribute";
|
|
326
351
|
}
|
|
327
|
-
function
|
|
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
|
|
333
|
-
|
|
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
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (e
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (e ===
|
|
346
|
-
if (e ===
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|
|
363
|
-
let {
|
|
400
|
+
function Y(e) {
|
|
401
|
+
let { rootDir: t, catalogDir: n, catalogExtension: r, locales: i, sourceLocale: a, defaultBuildLocale: o } = e;
|
|
364
402
|
return {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
|
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
|
|
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
|
|
665
|
-
let
|
|
666
|
-
for (let
|
|
667
|
-
let e =
|
|
668
|
-
|
|
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
|
|
440
|
+
return i.length > 0 && r.push("", "export default {", ...i, "}"), r.join("\n") + "\n";
|
|
671
441
|
}
|
|
672
|
-
function
|
|
442
|
+
function Ce(e, t) {
|
|
673
443
|
try {
|
|
674
|
-
return a(
|
|
444
|
+
return l(a(e, `${t}.js`), "utf-8");
|
|
675
445
|
} catch {
|
|
676
446
|
return;
|
|
677
447
|
}
|
|
678
448
|
}
|
|
679
|
-
function
|
|
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
|
|
685
|
-
function
|
|
686
|
-
|
|
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
|
-
|
|
474
|
+
C = e.root, h(e.command);
|
|
690
475
|
},
|
|
691
476
|
resolveId(e) {
|
|
692
|
-
if (e.startsWith(
|
|
693
|
-
if (
|
|
694
|
-
let t =
|
|
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(
|
|
700
|
-
if (
|
|
701
|
-
let t =
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
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
|
-
},
|
|
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 =
|
|
718
|
-
if (t.match(/\.[jt]sx(\?|$)/) && /<Trans[\s>]/.test(
|
|
719
|
-
let e =
|
|
720
|
-
e.transformed && (
|
|
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 (
|
|
723
|
-
let e =
|
|
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
|
|
733
|
-
code:
|
|
516
|
+
return i ? {
|
|
517
|
+
code: r,
|
|
734
518
|
map: null
|
|
735
519
|
} : void 0;
|
|
736
520
|
}
|
|
737
|
-
},
|
|
521
|
+
}, D = /* @__PURE__ */ new Map(), O = {
|
|
738
522
|
name: "fluenti:build-split",
|
|
739
523
|
transform(e, t) {
|
|
740
|
-
if (!
|
|
741
|
-
let n =
|
|
742
|
-
if (
|
|
743
|
-
let
|
|
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:
|
|
529
|
+
code: pe(i.code, a, i.usedHashes, b),
|
|
746
530
|
map: null
|
|
747
531
|
};
|
|
748
532
|
},
|
|
749
533
|
generateBundle(e, t) {
|
|
750
|
-
if (
|
|
751
|
-
let
|
|
752
|
-
for (let [e,
|
|
753
|
-
if (
|
|
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(
|
|
756
|
-
let n =
|
|
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 &&
|
|
543
|
+
t.size > 0 && n.set(e, t);
|
|
760
544
|
}
|
|
761
|
-
if (
|
|
762
|
-
let
|
|
763
|
-
for (let [e, t] of
|
|
764
|
-
let t =
|
|
765
|
-
t.push(e),
|
|
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
|
|
768
|
-
for (let [e, t] of
|
|
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 =
|
|
771
|
-
r.add(e),
|
|
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
|
|
774
|
-
for (let e of
|
|
775
|
-
let t =
|
|
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 =
|
|
778
|
-
if (
|
|
779
|
-
let t =
|
|
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
|
|
787
|
-
let i =
|
|
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
|
-
},
|
|
580
|
+
}, k = c.buildAutoCompile ?? !0, A = {
|
|
797
581
|
name: "fluenti:build-compile",
|
|
798
582
|
async buildStart() {
|
|
799
|
-
!
|
|
800
|
-
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
|
-
},
|
|
589
|
+
}, j = c.devAutoCompile ?? !0, M = {
|
|
806
590
|
name: "fluenti:dev",
|
|
807
|
-
configureServer(
|
|
808
|
-
if (!
|
|
809
|
-
let t =
|
|
810
|
-
|
|
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
|
-
|
|
814
|
-
|
|
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(
|
|
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
|
-
|
|
826
|
-
...
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
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 {
|
|
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
|