@menapo/vi18n 0.1.1 → 0.2.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/README.md +19 -0
- package/dist/{apply-Bre-lY9J.js → apply-Bg-3rB2m.js} +69 -89
- package/dist/{captured-Bj8bO6vd.js → captured-DfLk50Ji.js} +196 -217
- package/dist/{check-BIKEuu6B.js → check-CunekuYs.js} +76 -85
- package/dist/cli.js +2 -3
- package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
- package/dist/collisions-CDSdtLQm.js +215 -0
- package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
- package/dist/compile-hva0qjhZ.js +240 -0
- package/dist/concurrency-BCY_4zcr.js +1 -0
- package/dist/concurrency-Dy2ny50V.js +107 -0
- package/dist/config.d.ts +1 -5
- package/dist/config.js +4 -5
- package/dist/{types-D3QGM8XO.js → diagnostics-LgIWyeSp.js} +28 -27
- package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
- package/dist/{duplicates-yuRljQ6h.js → duplicates-8cudcHNj.js} +10 -27
- package/dist/engine-ecRD8-IE.js +556 -0
- package/dist/engine.d.ts +1 -5
- package/dist/engine.js +297 -168
- package/dist/exchange-DjwlrTQ9.js +41 -0
- package/dist/{exclude-Du-Zd_qI.js → exclude-BFETmvde.js} +2 -3
- package/dist/{export-C9Sy6UWv.js → export-D2tsqWIr.js} +17 -38
- package/dist/{extract-C3S8btx0.js → extract-BxYchVmY.js} +114 -82
- package/dist/{formats-9unqj_fZ.js → formats-BaryZ2N7.js} +352 -276
- package/dist/fs-ezCMZeDV.js +52 -0
- package/dist/i18next-COO6o0tX.js +1907 -0
- package/dist/i18next-Dr7DCQlQ.js +1 -0
- package/dist/{import-nANvQutw.js → import-vSC29Cn4.js} +81 -75
- package/dist/index.d.ts +1 -13
- package/dist/index.js +14 -16
- package/dist/{init-C2ScuW6a.js → init-Cc7A-8VX.js} +466 -501
- package/dist/{library-D5CWvTQs.js → library-tp_xqzSY.js} +975 -451
- package/dist/lingui-BnnlqGXT.js +902 -0
- package/dist/lint.d.ts +0 -4
- package/dist/lint.js +70 -82
- package/dist/{load-gW-oJt1Q.js → load-BSIeGJ5v.js} +275 -148
- package/dist/{load-CQRz4PpM.js → load-SSrAeJVB.js} +1214 -1116
- package/dist/{locales-DX4MOBFE.js → locales-D0U-yVRm.js} +271 -237
- package/dist/{lsp-RMMMc88P.js → lsp-DvC11pBZ.js} +4 -5
- package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
- package/dist/{mcp-CHVwBoRP.js → mcp-D2zzOTBy.js} +4 -5
- package/dist/{merge-driver-BTX87aVm.js → merge-driver-BLI8OtAc.js} +138 -122
- package/dist/migrate-1r43OBfe.js +1 -0
- package/dist/migrate-ChDGhlC-.js +2169 -0
- package/dist/{openai-CTaMDcl-.js → openai-CLn4puY8.js} +128 -87
- package/dist/{output-DWE3SIUA.js → output-D5tAt8q4.js} +15 -9
- package/dist/parse.d.ts +1 -3
- package/dist/parse.js +7 -8
- package/dist/{pipeline-C9Dbotkh.js → pipeline-BJSkkRYC.js} +387 -359
- package/dist/{pipeline-DbX6rlo5.js → pipeline-BeCc441z.js} +1 -1
- package/dist/project-B5KIO0q-.js +544 -0
- package/dist/{pseudo-DRv30iN5.js → pseudo-B2DUpoLu.js} +126 -3
- package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
- package/dist/react-intl-C8JehBBL.js +634 -0
- package/dist/rename-ZVGq9ZG1.js +577 -0
- package/dist/repeated-uuI1tUGg.js +85 -0
- package/dist/restore-xlBIrtRt.js +199 -0
- package/dist/rewrite-BwzXoBiA.js +415 -0
- package/dist/{rich-DCUKl5HM.js → rich-ApY1Dm4S.js} +35 -28
- package/dist/rolldown-runtime-C1I3wEg2.js +43 -0
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/dist/run-CQ9pDLSa.js +674 -0
- package/dist/scan-worker.d.ts +2 -4
- package/dist/scan-worker.js +1 -1
- package/dist/{scoped-BMYpSthj.js → scoped-h3KE8XWW.js} +3 -4
- package/dist/{server-Da1Ot9IN.js → server-Br8tAuG2.js} +312 -386
- package/dist/{server-deBOq2vq.js → server-DJRpUQVZ.js} +1059 -333
- package/dist/server.d.ts +1 -17
- package/dist/server.js +419 -379
- package/dist/{sitemap-DJXzKoza.js → sitemap-CSAkm6oi.js} +21 -33
- package/dist/{sources-D19czDSA.js → sources-DNVbYsgs.js} +713 -373
- package/dist/{status-zr4jY59Y.js → status-q6M3rBrh.js} +30 -30
- package/dist/{stdio-FPOKQAgu.js → stdio-D9kTzyqB.js} +2 -4
- package/dist/{stdio-CVaJfxA7.js → stdio-FWIVU3P4.js} +1 -2
- package/dist/sync-BNIAwMhR.js +1352 -0
- package/dist/{t-DC-c9zE5.js → t-gvEXx25s.js} +76 -53
- package/dist/test.d.ts +5 -16
- package/dist/test.js +126 -56
- package/dist/translate-BP4iVhOR.js +336 -0
- package/dist/{ts-BaU5yOf0.js → ts-BX6kwig5.js} +25 -14
- package/dist/{types-DtvQ7UdD.js → types-3kwyaCAm.js} +1 -2
- package/dist/{types-DsdWBG0b.d.ts → types-B4wNX6PA.d.ts} +6 -8
- package/dist/{types-CgUCkFU1.d.ts → types-_4UdFhR9.d.ts} +24 -21
- package/dist/types-xR2exI3L.js +42 -0
- package/dist/{units-CQ5Q99RC.js → units-DPPfCN7j.js} +7 -16
- package/dist/{url-CRfCOhUI.js → url-Bpc6wLea.js} +24 -11
- package/dist/{url-CsBkRaJy.js → url-D2_VlEeH.js} +25 -12
- package/dist/{validate-BxpupdAf.js → validate-CgzaDdOY.js} +690 -377
- package/dist/{validate-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
- package/dist/{version-Byqi2guX.js → version-DC-J5WvV.js} +3 -5
- package/dist/{vite-scan-CT_vsp4g.js → vite-scan-kM8Ta3rO.js} +87 -92
- package/dist/vite.d.ts +2 -6
- package/dist/vite.js +6500 -6032
- package/dist/vue-i18n-_uIXlFVh.js +806 -0
- package/dist/{which-BOemZ5Q8.js → which-DFWk_KwN.js} +44 -37
- package/dist/{worker-84U6uYB3.js → worker-zlhNj4y3.js} +454 -608
- package/package.json +5 -5
- package/dist/check-HsmmpJZg.js +0 -1
- package/dist/codec-DuvU2VQy.js +0 -207
- package/dist/collisions-CfpZU8e4.js +0 -217
- package/dist/compile-BaDh0cHG.js +0 -245
- package/dist/concurrency-C9UUWuDC.js +0 -96
- package/dist/concurrency-DONL7t4V.js +0 -1
- package/dist/engine-C2ENBRJe.js +0 -531
- package/dist/i18next-9HAoxwUI.js +0 -1
- package/dist/i18next-BEJgv_S8.js +0 -1596
- package/dist/lingui-zUiCl9Um.js +0 -833
- package/dist/messages-BfjIExyB.js +0 -166
- package/dist/migrate-IpLDMXmq.js +0 -1484
- package/dist/migrate-rCQuOGsf.js +0 -1
- package/dist/project-Bw9UPIdx.js +0 -1046
- package/dist/project-C4GpaN-n.js +0 -381
- package/dist/react-intl-BP0u-D5m.js +0 -519
- package/dist/restore-CiYv-jxS.js +0 -175
- package/dist/rewrite-EsIw_lsq.js +0 -803
- package/dist/run-BEcnBbu-.js +0 -694
- package/dist/runtime-DTMmliT1.js +0 -64
- package/dist/sync-B9V2KFwb.js +0 -658
- package/dist/translate-CQnJfLjO.js +0 -299
- package/dist/types-wSh9fCBY.js +0 -11
- package/dist/vue-i18n-g0iGy6CZ.js +0 -651
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as diagnosticError } from "./diagnostics-LgIWyeSp.js";
|
|
2
2
|
/** Longest wait between retries, whatever the server asks for. */
|
|
3
3
|
const MAX_DELAY_MS = 6e4;
|
|
4
4
|
/** Error bodies are quoted in messages; past this they are noise. */
|
|
@@ -72,14 +72,25 @@ function answerItems(text) {
|
|
|
72
72
|
function field(value, name) {
|
|
73
73
|
return typeof value === "object" && value !== null ? value[name] : void 0;
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Estimated USD at a price per 1M tokens; `NaN` without a price, so a
|
|
77
|
+
* `--max-cost` comparison can never pass by accident. Here rather than in
|
|
78
|
+
* prices.ts so `openaiCompatible` (in `/config`) does not carry Gemini's table.
|
|
79
|
+
*/
|
|
80
|
+
function costAt(price, usage) {
|
|
81
|
+
if (price === null || price === void 0) return NaN;
|
|
82
|
+
return (usage.inputTokens * price.input + usage.outputTokens * price.output) / 1e6;
|
|
83
|
+
}
|
|
84
|
+
/** A token count from a provider's usage block: a positive finite number, else 0. */
|
|
85
|
+
function tokenCount(value) {
|
|
76
86
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
|
|
77
87
|
}
|
|
78
|
-
|
|
88
|
+
/** `JSON.parse`, or `fallback` when the text is not JSON. */
|
|
89
|
+
function parseJson(text, fallback) {
|
|
79
90
|
try {
|
|
80
91
|
return JSON.parse(text);
|
|
81
92
|
} catch {
|
|
82
|
-
return;
|
|
93
|
+
return fallback;
|
|
83
94
|
}
|
|
84
95
|
}
|
|
85
96
|
/**
|
|
@@ -136,6 +147,31 @@ function providerError(message, key) {
|
|
|
136
147
|
message: redact(message, key)
|
|
137
148
|
});
|
|
138
149
|
}
|
|
150
|
+
/** The key in `env[name]`; throws `missing` when it is unset or blank. */
|
|
151
|
+
function requireKey(env, name, missing) {
|
|
152
|
+
const key = readKey(env, name);
|
|
153
|
+
if (key === null) throw diagnosticError(missing());
|
|
154
|
+
return key;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* A provider's `baseURL` without trailing slashes, and its origin; a value
|
|
158
|
+
* that is not a URL is a config error naming the call it was passed to.
|
|
159
|
+
*/
|
|
160
|
+
function parseBaseURL(base, call) {
|
|
161
|
+
const trimmed = base.replace(/\/+$/, "");
|
|
162
|
+
try {
|
|
163
|
+
return {
|
|
164
|
+
base: trimmed,
|
|
165
|
+
origin: new URL(trimmed).origin
|
|
166
|
+
};
|
|
167
|
+
} catch {
|
|
168
|
+
throw diagnosticError({
|
|
169
|
+
code: "config-invalid",
|
|
170
|
+
severity: "error",
|
|
171
|
+
message: `${call}({ baseURL: ${JSON.stringify(trimmed)} }) is not a URL`
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
139
175
|
/** The key in `env[name]`, or null when it is unset or blank. */
|
|
140
176
|
function readKey(env, name) {
|
|
141
177
|
const key = (env ?? globalThis.process?.env ?? {})[name];
|
|
@@ -174,91 +210,97 @@ const FORMATS = [
|
|
|
174
210
|
"text"
|
|
175
211
|
];
|
|
176
212
|
function openaiCompatible(options) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
213
|
+
return new OpenAICompatibleProvider(options);
|
|
214
|
+
}
|
|
215
|
+
var OpenAICompatibleProvider = class {
|
|
216
|
+
name = "openai-compatible";
|
|
217
|
+
model;
|
|
218
|
+
apiKeyEnv;
|
|
219
|
+
url;
|
|
220
|
+
origin;
|
|
221
|
+
label;
|
|
222
|
+
format;
|
|
223
|
+
temperature = true;
|
|
224
|
+
options;
|
|
225
|
+
constructor(options) {
|
|
226
|
+
if (typeof options?.model !== "string" || options.model.trim() === "") throw diagnosticError({
|
|
189
227
|
code: "config-invalid",
|
|
190
228
|
severity: "error",
|
|
191
|
-
message:
|
|
229
|
+
message: "openaiCompatible() needs a model, e.g. { model: \"gpt-5-mini\" }"
|
|
192
230
|
});
|
|
231
|
+
this.options = options;
|
|
232
|
+
this.model = options.model;
|
|
233
|
+
const { base, origin } = parseBaseURL(options.baseURL ?? "https://api.openai.com/v1", "openaiCompatible");
|
|
234
|
+
this.origin = origin;
|
|
235
|
+
this.apiKeyEnv = options.apiKeyEnv ?? (origin === new URL("https://api.openai.com/v1").origin ? OPENAI_KEY_ENV : null);
|
|
236
|
+
this.url = `${base}/chat/completions`;
|
|
237
|
+
this.label = `${this.model} (${origin})`;
|
|
238
|
+
this.format = FORMATS.indexOf(options.responseFormat ?? "json_schema");
|
|
193
239
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const answer = await exchange({
|
|
218
|
-
fetch: options.fetch ?? globalThis.fetch,
|
|
219
|
-
url,
|
|
220
|
-
init: {
|
|
221
|
-
method: "POST",
|
|
222
|
-
headers,
|
|
223
|
-
body: JSON.stringify(requestBody(request, model, FORMATS[sentFormat], sentTemperature))
|
|
224
|
-
},
|
|
225
|
-
key,
|
|
226
|
-
label,
|
|
227
|
-
signal: callOptions?.signal,
|
|
228
|
-
onRateLimit: callOptions?.onRateLimit,
|
|
229
|
-
isRateLimit: (answer) => answer.status === 429 && !quotaExhausted(answer.json),
|
|
230
|
-
serverDelay: (answer) => retryAfterMsDelay(answer.headers),
|
|
231
|
-
advice: "lower ai.concurrency or wait for the rate limit to reset"
|
|
232
|
-
});
|
|
233
|
-
if (answer.ok) return readAnswer(answer.json);
|
|
234
|
-
if (answer.status === 400 || answer.status === 404) {
|
|
235
|
-
const refused = refusedParameter(answer);
|
|
236
|
-
if ((refused === "response_format" || refused === "unnamed") && sentFormat < FORMATS.length - 1) {
|
|
237
|
-
format = Math.max(format, sentFormat + 1);
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
if ((refused === "temperature" || refused === "unnamed") && sentTemperature) {
|
|
241
|
-
temperature = false;
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
throw providerError(failureMessage(answer, label, key, apiKeyEnv, origin), key);
|
|
246
|
-
}
|
|
247
|
-
},
|
|
248
|
-
estimateCost(usage) {
|
|
249
|
-
const prices = options.prices;
|
|
250
|
-
if (prices === void 0) return NaN;
|
|
251
|
-
return (usage.inputTokens * prices.input + usage.outputTokens * prices.output) / 1e6;
|
|
252
|
-
},
|
|
253
|
-
missingKey,
|
|
254
|
-
withModel(next) {
|
|
255
|
-
return openaiCompatible({
|
|
256
|
-
...options,
|
|
257
|
-
model: next
|
|
240
|
+
async translate(request, callOptions) {
|
|
241
|
+
const { apiKeyEnv } = this;
|
|
242
|
+
const key = apiKeyEnv === null ? "" : requireKey(this.options.env, apiKeyEnv, () => this.keyMissing(apiKeyEnv));
|
|
243
|
+
const headers = { "content-type": "application/json" };
|
|
244
|
+
if (key !== "") headers.authorization = `Bearer ${key}`;
|
|
245
|
+
for (;;) {
|
|
246
|
+
const sentFormat = this.format;
|
|
247
|
+
const sentTemperature = this.temperature;
|
|
248
|
+
const answer = await exchange({
|
|
249
|
+
fetch: this.options.fetch ?? globalThis.fetch,
|
|
250
|
+
url: this.url,
|
|
251
|
+
init: {
|
|
252
|
+
method: "POST",
|
|
253
|
+
headers,
|
|
254
|
+
body: JSON.stringify(requestBody(request, this.model, FORMATS[sentFormat], sentTemperature))
|
|
255
|
+
},
|
|
256
|
+
key,
|
|
257
|
+
label: this.label,
|
|
258
|
+
signal: callOptions?.signal,
|
|
259
|
+
onRateLimit: callOptions?.onRateLimit,
|
|
260
|
+
isRateLimit: (answer) => answer.status === 429 && !quotaExhausted(answer.json),
|
|
261
|
+
serverDelay: (answer) => retryAfterMsDelay(answer.headers),
|
|
262
|
+
advice: "lower ai.concurrency or wait for the rate limit to reset"
|
|
258
263
|
});
|
|
264
|
+
if (answer.ok) return readAnswer(answer.json);
|
|
265
|
+
if (!this.fallBack(answer, sentFormat, sentTemperature)) throw providerError(failureMessage(answer, this.label, key, apiKeyEnv, this.origin), key);
|
|
259
266
|
}
|
|
260
|
-
}
|
|
261
|
-
|
|
267
|
+
}
|
|
268
|
+
/** Whether a refused request is worth sending again without what the server refused. */
|
|
269
|
+
fallBack(answer, sentFormat, sentTemperature) {
|
|
270
|
+
if (answer.status !== 400 && answer.status !== 404) return false;
|
|
271
|
+
const refused = refusedParameter(answer);
|
|
272
|
+
if ((refused === "response_format" || refused === "unnamed") && sentFormat < FORMATS.length - 1) {
|
|
273
|
+
this.format = Math.max(this.format, sentFormat + 1);
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
if ((refused === "temperature" || refused === "unnamed") && sentTemperature) {
|
|
277
|
+
this.temperature = false;
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
estimateCost(usage) {
|
|
283
|
+
return costAt(this.options.prices, usage);
|
|
284
|
+
}
|
|
285
|
+
missingKey() {
|
|
286
|
+
const { apiKeyEnv } = this;
|
|
287
|
+
if (apiKeyEnv === null || readKey(this.options.env, apiKeyEnv) !== null) return null;
|
|
288
|
+
return this.keyMissing(apiKeyEnv);
|
|
289
|
+
}
|
|
290
|
+
withModel(next) {
|
|
291
|
+
return openaiCompatible({
|
|
292
|
+
...this.options,
|
|
293
|
+
model: next
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
keyMissing(apiKeyEnv) {
|
|
297
|
+
return {
|
|
298
|
+
code: "ai-missing-key",
|
|
299
|
+
severity: "error",
|
|
300
|
+
message: `Set ${apiKeyEnv} to the API key of ${this.origin} to translate with ${this.model}`
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
};
|
|
262
304
|
function requestBody(request, model, format, temperature) {
|
|
263
305
|
const body = {
|
|
264
306
|
model,
|
|
@@ -303,8 +345,8 @@ function readAnswer(json) {
|
|
|
303
345
|
const result = { items: [] };
|
|
304
346
|
const usage = field(json, "usage");
|
|
305
347
|
if (usage !== void 0) result.usage = {
|
|
306
|
-
inputTokens:
|
|
307
|
-
outputTokens:
|
|
348
|
+
inputTokens: tokenCount(field(usage, "prompt_tokens")),
|
|
349
|
+
outputTokens: tokenCount(field(usage, "completion_tokens"))
|
|
308
350
|
};
|
|
309
351
|
const choices = field(json, "choices");
|
|
310
352
|
const content = field(field(Array.isArray(choices) ? choices[0] : void 0, "message"), "content");
|
|
@@ -342,5 +384,4 @@ function failureMessage(answer, label, key, apiKeyEnv, origin) {
|
|
|
342
384
|
if ((answer.status === 401 || answer.status === 403) && apiKeyEnv === null) return `${base}; no key was sent: set apiKeyEnv to the variable holding the key of ${origin} (a key goes to a host other than OpenAI's only when apiKeyEnv names it)`;
|
|
343
385
|
return base;
|
|
344
386
|
}
|
|
345
|
-
|
|
346
|
-
export { answerItems as a, exchange as c, readKey as d, requestText as f, MAX_DELAY_MS as i, field as l, sleep as m, openaiCompatible as n, count as o, retryAfterDelay as p, openaiPreset as r, detail as s, PROVIDER_PRESETS as t, providerError as u };
|
|
387
|
+
export { tokenCount as _, answerItems as a, exchange as c, providerError as d, readKey as f, sleep as g, retryAfterDelay as h, MAX_DELAY_MS as i, field as l, requireKey as m, openaiCompatible as n, costAt as o, requestText as p, openaiPreset as r, detail as s, PROVIDER_PRESETS as t, parseBaseURL as u };
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { d as toPosix } from "./validate-CgzaDdOY.js";
|
|
2
|
+
import "./library-tp_xqzSY.js";
|
|
3
|
+
import { t as VERSION } from "./version-DC-J5WvV.js";
|
|
4
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
3
5
|
import { existsSync } from "node:fs";
|
|
4
|
-
|
|
6
|
+
// src/cli/errors.ts
|
|
7
|
+
/** How the CLI names a caught value in a message: an `Error`'s message, anything else as text. */
|
|
8
|
+
function errorMessage(error) {
|
|
9
|
+
return error instanceof Error ? error.message : String(error);
|
|
10
|
+
}
|
|
11
|
+
// src/cli/output.ts
|
|
5
12
|
/**
|
|
6
13
|
* Everything the CLI prints (INTERNALS §2.14): results on stdout, diagnostics
|
|
7
14
|
* on stderr as `file:line:col severity code message`, GitHub workflow
|
|
@@ -32,13 +39,13 @@ function createOutput(io, format) {
|
|
|
32
39
|
const absolute = (file) => isAbsolute(file) ? file : resolve(root, file);
|
|
33
40
|
const display = (file) => {
|
|
34
41
|
const rel = relative(io.cwd, absolute(file));
|
|
35
|
-
return (rel === "" ? "." : rel)
|
|
42
|
+
return toPosix(rel === "" ? "." : rel);
|
|
36
43
|
};
|
|
37
44
|
const repoPath = (file) => {
|
|
38
45
|
if (gitRoot === void 0) gitRoot = findGitRoot(io.cwd);
|
|
39
46
|
const abs = absolute(file);
|
|
40
47
|
const rel = relative(gitRoot ?? io.cwd, abs);
|
|
41
|
-
return (rel.startsWith("..") || isAbsolute(rel) ? abs : rel)
|
|
48
|
+
return toPosix(rel.startsWith("..") || isAbsolute(rel) ? abs : rel);
|
|
42
49
|
};
|
|
43
50
|
const print = (diagnostic) => {
|
|
44
51
|
if (format === "json") return;
|
|
@@ -145,8 +152,8 @@ function table(header, rows) {
|
|
|
145
152
|
/** Posix path of `file` relative to `root` (absolute when outside it), as diagnostics store paths. */
|
|
146
153
|
function rootRelative(root, file) {
|
|
147
154
|
const rel = relative(root, file);
|
|
148
|
-
if (rel === "" || rel.startsWith("..") || isAbsolute(rel)) return file
|
|
149
|
-
return rel
|
|
155
|
+
if (rel === "" || rel.startsWith("..") || isAbsolute(rel)) return toPosix(file);
|
|
156
|
+
return toPosix(rel);
|
|
150
157
|
}
|
|
151
158
|
function countBySeverity(list) {
|
|
152
159
|
const counts = {
|
|
@@ -160,5 +167,4 @@ function countBySeverity(list) {
|
|
|
160
167
|
function plural(count, one, many = one + "s") {
|
|
161
168
|
return `${count} ${count === 1 ? one : many}`;
|
|
162
169
|
}
|
|
163
|
-
|
|
164
|
-
export { table as a, rootRelative as i, createOutput as n, plural as r, countBySeverity as t };
|
|
170
|
+
export { table as a, rootRelative as i, createOutput as n, errorMessage as o, plural as r, countBySeverity as t };
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { a as Message, b as Values, s as MessageRef } from "./types-
|
|
2
|
-
//#region src/parse/index.d.ts
|
|
1
|
+
import { a as Message, b as Values, s as MessageRef } from "./types-B4wNX6PA.js";
|
|
3
2
|
interface ParseOptions {
|
|
4
3
|
/**
|
|
5
4
|
* `"auto"` (default): ICU MessageFormat, or MessageFormat 2 when the text
|
|
@@ -58,5 +57,4 @@ export declare function format(message: string | ParsedMessage, values?: Values,
|
|
|
58
57
|
* text and options while it is cached; returns the unsubscribe function.
|
|
59
58
|
*/
|
|
60
59
|
export declare function onParseError(handler: (message: ParsedMessage) => void): () => void;
|
|
61
|
-
//#endregion
|
|
62
60
|
export type { ParseIssue, ParseOptions, ParsedMessage };
|
package/dist/parse.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { f as isDiagnosticError, i as normalizeSource, s as parseSource, t as compileMessage } from "./compile-DqkofbiO.js";
|
|
2
|
+
import { n as validateTranslation, t as validateSource } from "./validate-PGgMsasz.js";
|
|
3
|
+
import { b as warnOnce, g as DEV, m as createScope, n as S, y as trim } from "./dir-TGLYuOZb.js";
|
|
4
|
+
import { o as formatMessage, r as t } from "./t-gvEXx25s.js";
|
|
5
|
+
// src/parse/index.ts
|
|
6
6
|
/**
|
|
7
7
|
* `@menapo/vi18n/parse` (PLAN §4.1, INTERNALS §3.6): messages that are not in
|
|
8
8
|
* the code — a CMS, a database, a template an admin edits — parsed at
|
|
@@ -114,9 +114,9 @@ function build(text, syntax, sourceText, locale) {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
let ir;
|
|
117
|
-
if (errors.length === 0) ir = compileMessage(ast);
|
|
117
|
+
if (ast !== null && errors.length === 0) ir = compileMessage(ast);
|
|
118
118
|
else if (source !== null) ir = compileMessage(source);
|
|
119
|
-
else ir = text.replace(/[
|
|
119
|
+
else ir = text.replace(/[\u202a-\u202e\u2066-\u2069]/g, "");
|
|
120
120
|
return Object.freeze({
|
|
121
121
|
id: "",
|
|
122
122
|
message: text,
|
|
@@ -152,5 +152,4 @@ function report(parsed) {
|
|
|
152
152
|
if (DEV) warnOnce(`onParseError handler threw: ${String(error)}`);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
//#endregion
|
|
156
155
|
export { format, onParseError, parse };
|