ext-localize 0.0.0-stage → 0.2.1
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/CHANGELOG.md +42 -0
- package/LICENSE +21 -0
- package/README.md +586 -2
- package/assets/fill-core.js +398 -0
- package/dist/batch.js +25 -0
- package/dist/check.js +392 -0
- package/dist/cli.js +722 -0
- package/dist/config.js +114 -0
- package/dist/glossary.js +71 -0
- package/dist/import.js +89 -0
- package/dist/listing.js +318 -0
- package/dist/locales.js +86 -0
- package/dist/messages.js +123 -0
- package/dist/paths.js +30 -0
- package/dist/placeholders.js +171 -0
- package/dist/plurals.js +63 -0
- package/dist/providers/anthropic.js +60 -0
- package/dist/providers/deepl.js +269 -0
- package/dist/providers/index.js +40 -0
- package/dist/providers/ollama.js +48 -0
- package/dist/providers/openai.js +50 -0
- package/dist/providers/prompt.js +100 -0
- package/dist/providers/types.js +18 -0
- package/dist/retry.js +66 -0
- package/dist/stale.js +152 -0
- package/dist/state.js +237 -0
- package/dist/stores/chrome-auto.js +205 -0
- package/dist/stores/chrome.js +194 -0
- package/dist/stores/edge.js +43 -0
- package/dist/stores/firefox.js +235 -0
- package/dist/translate.js +309 -0
- package/dist/usage.js +3 -0
- package/dist/zip.js +88 -0
- package/package.json +55 -4
package/dist/check.js
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { RTL_LOCALES, isChromeLocale } from "./locales.js";
|
|
4
|
+
import { compareFormat, summarizeFormat, tokenize } from "./placeholders.js";
|
|
5
|
+
import { listLocaleDirs, messagesPath, readMessagesFile, stripJsonComments } from "./messages.js";
|
|
6
|
+
import { checkListing, listingDir } from "./listing.js";
|
|
7
|
+
import { configBase, relPath } from "./paths.js";
|
|
8
|
+
import { loadGlossary } from "./glossary.js";
|
|
9
|
+
import { findStale } from "./stale.js";
|
|
10
|
+
import { familyMember, pluralCategories, pluralFamilies } from "./plurals.js";
|
|
11
|
+
/** Message keys may only use these characters (Chrome i18n docs). */
|
|
12
|
+
export const KEY_RE = /^[A-Za-z0-9_@]+$/;
|
|
13
|
+
/** Manifest fields with Chrome Web Store length limits. Warning level. */
|
|
14
|
+
const MANIFEST_LIMITS = { name: 75, short_name: 12, description: 132 };
|
|
15
|
+
/** Hebrew, Arabic (incl. Persian) script blocks and presentation forms. */
|
|
16
|
+
const RTL_CHAR_RE = /[--ۿݐ-ݿࢠ-ࣿיִ-﷿ﹰ-]/;
|
|
17
|
+
function plainText(message) {
|
|
18
|
+
return tokenize(message)
|
|
19
|
+
.filter((s) => s.kind === "text")
|
|
20
|
+
.map((s) => s.raw)
|
|
21
|
+
.join("");
|
|
22
|
+
}
|
|
23
|
+
function asEntry(value) {
|
|
24
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
25
|
+
}
|
|
26
|
+
/** Checks on key names and message shape that apply to every locale file. */
|
|
27
|
+
function checkEntries(data, locale) {
|
|
28
|
+
const issues = [];
|
|
29
|
+
const err = (key, message) => issues.push({ level: "error", locale, key, message });
|
|
30
|
+
const lowerSeen = new Map();
|
|
31
|
+
for (const [key, value] of Object.entries(data)) {
|
|
32
|
+
if (key.startsWith("@@"))
|
|
33
|
+
err(key, `keys starting with "@@" are reserved by Chrome`);
|
|
34
|
+
else if (!KEY_RE.test(key))
|
|
35
|
+
err(key, `invalid key name; use only A-Z a-z 0-9 _ @`);
|
|
36
|
+
const lower = key.toLowerCase();
|
|
37
|
+
const prev = lowerSeen.get(lower);
|
|
38
|
+
if (prev !== undefined)
|
|
39
|
+
err(key, `duplicate of "${prev}" (keys are case-insensitive)`);
|
|
40
|
+
else
|
|
41
|
+
lowerSeen.set(lower, key);
|
|
42
|
+
const entry = asEntry(value);
|
|
43
|
+
if (!entry) {
|
|
44
|
+
err(key, `value must be an object with a "message" field`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (typeof entry.message !== "string") {
|
|
48
|
+
err(key, `missing "message" string`);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (entry.message.trim() === "")
|
|
52
|
+
err(key, `empty message`);
|
|
53
|
+
// Every $name$ used must be defined in this file's own placeholders block.
|
|
54
|
+
const defined = new Set();
|
|
55
|
+
const ph = asEntry(entry.placeholders);
|
|
56
|
+
if (entry.placeholders !== undefined && !ph)
|
|
57
|
+
err(key, `"placeholders" must be an object`);
|
|
58
|
+
if (ph) {
|
|
59
|
+
for (const [name, def] of Object.entries(ph)) {
|
|
60
|
+
defined.add(name.toLowerCase());
|
|
61
|
+
if (!KEY_RE.test(name))
|
|
62
|
+
err(key, `invalid placeholder name "${name}"`);
|
|
63
|
+
const d = asEntry(def);
|
|
64
|
+
if (!d || typeof d.content !== "string") {
|
|
65
|
+
err(key, `placeholder "${name}" needs a "content" string`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const name of summarizeFormat(entry.message).named) {
|
|
70
|
+
if (!defined.has(name))
|
|
71
|
+
err(key, `$${name}$ is used but not defined in "placeholders"`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return issues;
|
|
75
|
+
}
|
|
76
|
+
/** Validate the default locale file on its own. */
|
|
77
|
+
export function checkSource(data, locale) {
|
|
78
|
+
const issues = checkEntries(data, locale);
|
|
79
|
+
for (const [key, value] of Object.entries(data)) {
|
|
80
|
+
const entry = asEntry(value);
|
|
81
|
+
if (!entry || typeof entry.message !== "string")
|
|
82
|
+
continue;
|
|
83
|
+
const s = summarizeFormat(entry.message);
|
|
84
|
+
if (s.lone > 0) {
|
|
85
|
+
issues.push({ level: "warning", locale, key, message: `stray "$" in message; use "$$" for a literal dollar sign` });
|
|
86
|
+
}
|
|
87
|
+
const ph = asEntry(entry.placeholders);
|
|
88
|
+
if (ph) {
|
|
89
|
+
for (const name of Object.keys(ph)) {
|
|
90
|
+
if (!s.named.includes(name.toLowerCase())) {
|
|
91
|
+
issues.push({ level: "warning", locale, key, message: `placeholder "${name}" is defined but not used` });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return issues;
|
|
97
|
+
}
|
|
98
|
+
/** Validate one translated locale against the source. Pure; used by `check` and tests. */
|
|
99
|
+
/**
|
|
100
|
+
* RTL check: does a message in ar/he/fa look untranslated? Quiet on purpose:
|
|
101
|
+
* glossary "keep" terms are ignored, and so are messages with fewer than 4 letters
|
|
102
|
+
* (A4, KB, v1.x) and short ones (up to 3 words) identical to the source (brand names).
|
|
103
|
+
*/
|
|
104
|
+
export function looksUntranslated(target, source, keep = []) {
|
|
105
|
+
let text = plainText(target);
|
|
106
|
+
if (RTL_CHAR_RE.test(text))
|
|
107
|
+
return false;
|
|
108
|
+
for (const term of [...keep].sort((a, b) => b.length - a.length))
|
|
109
|
+
if (term.trim())
|
|
110
|
+
text = text.split(term).join(" ");
|
|
111
|
+
const letters = text.match(/\p{L}/gu)?.length ?? 0;
|
|
112
|
+
if (letters < 4)
|
|
113
|
+
return false;
|
|
114
|
+
const words = plainText(target).trim().split(/\s+/).filter(Boolean).length;
|
|
115
|
+
if (plainText(target).trim() === plainText(source).trim() && words <= 3)
|
|
116
|
+
return false;
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
export function checkLocale(source, target, locale, opts = {}) {
|
|
120
|
+
const issues = checkEntries(target, locale);
|
|
121
|
+
const err = (key, message) => issues.push({ level: "error", locale, key, message });
|
|
122
|
+
const warn = (key, message) => issues.push({ level: "warning", locale, key, message });
|
|
123
|
+
const targetByLower = new Map(Object.keys(target).map((k) => [k.toLowerCase(), k]));
|
|
124
|
+
const sourceLower = new Set(Object.keys(source).map((k) => k.toLowerCase()));
|
|
125
|
+
const families = pluralFamilies(Object.keys(source));
|
|
126
|
+
for (const [key, srcValue] of Object.entries(source)) {
|
|
127
|
+
const tKey = targetByLower.get(key.toLowerCase());
|
|
128
|
+
if (tKey === undefined) {
|
|
129
|
+
// items_one is not needed in Japanese: its plural rules have no "one".
|
|
130
|
+
const member = familyMember(key, families, locale);
|
|
131
|
+
if (!member || member.used)
|
|
132
|
+
err(key, `missing (present in source)`);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (tKey !== key)
|
|
136
|
+
warn(key, `key spelled "${tKey}" here; same key for Chrome, but keep the source spelling`);
|
|
137
|
+
const src = asEntry(srcValue);
|
|
138
|
+
const tgt = asEntry(target[tKey]);
|
|
139
|
+
if (!src || typeof src.message !== "string" || !tgt || typeof tgt.message !== "string")
|
|
140
|
+
continue;
|
|
141
|
+
for (const p of compareFormat(src.message, tgt.message))
|
|
142
|
+
(p.severity === "error" ? err : warn)(key, p.message);
|
|
143
|
+
if (RTL_LOCALES.has(locale) && looksUntranslated(tgt.message, src.message, opts.keep)) {
|
|
144
|
+
warn(key, `no right-to-left letters; message may be untranslated`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
for (const key of Object.keys(target)) {
|
|
148
|
+
if (sourceLower.has(key.toLowerCase()))
|
|
149
|
+
continue;
|
|
150
|
+
const member = familyMember(key, families, locale);
|
|
151
|
+
if (!member) {
|
|
152
|
+
err(key, `extra key (not in source)`);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (!member.used) {
|
|
156
|
+
warn(key, `plural form "${member.category}" is not used in ${locale} (Intl.PluralRules); Chrome never needs it`);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
// items_few has no source key: compare its placeholders with the source items_other.
|
|
160
|
+
const otherKey = Object.keys(source).find((k) => k.toLowerCase() === `${member.base}_other`);
|
|
161
|
+
const src = otherKey ? asEntry(source[otherKey]) : null;
|
|
162
|
+
const tgt = asEntry(target[key]);
|
|
163
|
+
if (src && typeof src.message === "string" && tgt && typeof tgt.message === "string") {
|
|
164
|
+
for (const p of compareFormat(src.message, tgt.message))
|
|
165
|
+
(p.severity === "error" ? err : warn)(key, `${p.message} (compared with ${otherKey})`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Plural forms the locale's language uses but the locale file does not have.
|
|
169
|
+
for (const base of families) {
|
|
170
|
+
const otherKey = Object.keys(source).find((k) => k.toLowerCase() === `${base}_other`);
|
|
171
|
+
const prefix = otherKey.slice(0, otherKey.length - "_other".length);
|
|
172
|
+
for (const cat of pluralCategories(locale)) {
|
|
173
|
+
const k = `${prefix}_${cat}`;
|
|
174
|
+
if (sourceLower.has(k.toLowerCase()) || targetByLower.has(k.toLowerCase()))
|
|
175
|
+
continue;
|
|
176
|
+
warn(k, `plural form "${cat}" is missing; ${locale} uses it (Intl.PluralRules), and the source has no such key to fall back to`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return issues;
|
|
180
|
+
}
|
|
181
|
+
/** Look up a __MSG_key__ value in a locale (case-insensitive key). */
|
|
182
|
+
function lookupMessage(data, key) {
|
|
183
|
+
const lower = key.toLowerCase();
|
|
184
|
+
for (const [k, v] of Object.entries(data)) {
|
|
185
|
+
const e = asEntry(v);
|
|
186
|
+
if (k.toLowerCase() === lower && e && typeof e.message === "string")
|
|
187
|
+
return e.message;
|
|
188
|
+
}
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
/** Run every check on an extension folder. */
|
|
192
|
+
export function checkProject(root, opts = {}) {
|
|
193
|
+
const issues = [];
|
|
194
|
+
const listingAbs = listingDir(root, opts.listingDir, configBase(root));
|
|
195
|
+
const listingRel = relPath(root, listingAbs);
|
|
196
|
+
let staleCheck = {
|
|
197
|
+
mode: opts.stale ?? "warning",
|
|
198
|
+
status: "no-source",
|
|
199
|
+
stale: 0,
|
|
200
|
+
untracked: 0,
|
|
201
|
+
note: "The source messages could not be read, so stale strings were not checked.",
|
|
202
|
+
};
|
|
203
|
+
const report = () => {
|
|
204
|
+
annotate(root, issues, listingRel);
|
|
205
|
+
if (opts.listingOnly) {
|
|
206
|
+
// Keep listing issues and project-level problems (no manifest, no default locale...).
|
|
207
|
+
const listingPrefix = listingRel === "." ? "" : `${listingRel}/`;
|
|
208
|
+
const keepIssue = (i) => i.key?.startsWith("listing.") || (i.file !== undefined && i.file.startsWith(listingPrefix) && i.file.endsWith(".json") && !i.file.startsWith("_locales/")) || (i.locale === null && i.kind !== "state");
|
|
209
|
+
issues.splice(0, issues.length, ...issues.filter(keepIssue));
|
|
210
|
+
staleCheck = { ...staleCheck, stale: issues.filter((i) => i.kind === "stale").length };
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
defaultLocale,
|
|
214
|
+
locales,
|
|
215
|
+
issues,
|
|
216
|
+
errors: issues.filter((i) => i.level === "error").length,
|
|
217
|
+
warnings: issues.filter((i) => i.level === "warning").length,
|
|
218
|
+
stale: issues.filter((i) => i.kind === "stale").length,
|
|
219
|
+
staleCheck,
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
let defaultLocale = null;
|
|
223
|
+
let locales = [];
|
|
224
|
+
const manifestPath = join(root, "manifest.json");
|
|
225
|
+
if (!existsSync(manifestPath)) {
|
|
226
|
+
issues.push({ level: "error", locale: null, message: `no manifest.json in ${root}` });
|
|
227
|
+
return report();
|
|
228
|
+
}
|
|
229
|
+
let manifest;
|
|
230
|
+
try {
|
|
231
|
+
let raw = readFileSync(manifestPath, "utf8");
|
|
232
|
+
if (raw.charCodeAt(0) === 0xfeff)
|
|
233
|
+
raw = raw.slice(1);
|
|
234
|
+
manifest = JSON.parse(stripJsonComments(raw));
|
|
235
|
+
}
|
|
236
|
+
catch (e) {
|
|
237
|
+
issues.push({ level: "error", locale: null, message: `manifest.json does not parse: ${e.message}` });
|
|
238
|
+
return report();
|
|
239
|
+
}
|
|
240
|
+
const localesDir = join(root, "_locales");
|
|
241
|
+
locales = listLocaleDirs(localesDir);
|
|
242
|
+
const dl = manifest["default_locale"];
|
|
243
|
+
if (typeof dl !== "string" || !dl) {
|
|
244
|
+
if (locales.length)
|
|
245
|
+
issues.push({ level: "error", locale: null, message: `_locales/ exists but manifest.json has no "default_locale"` });
|
|
246
|
+
return report();
|
|
247
|
+
}
|
|
248
|
+
defaultLocale = dl;
|
|
249
|
+
if (!locales.includes(dl)) {
|
|
250
|
+
issues.push({ level: "error", locale: dl, message: `default_locale "${dl}" has no _locales/${dl}/messages.json` });
|
|
251
|
+
return report();
|
|
252
|
+
}
|
|
253
|
+
const parsed = new Map();
|
|
254
|
+
for (const locale of locales) {
|
|
255
|
+
if (!isChromeLocale(locale)) {
|
|
256
|
+
issues.push({
|
|
257
|
+
level: "warning",
|
|
258
|
+
locale,
|
|
259
|
+
message: `"${locale}" is not in the Chrome Web Store locale list, so the store will not offer it; the Chrome runtime may still use it (for example "nb" for Norwegian)`,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
const path = messagesPath(localesDir, locale);
|
|
263
|
+
if (!existsSync(path)) {
|
|
264
|
+
issues.push({ level: "error", locale, message: `folder has no messages.json (Chrome refuses to load the extension)` });
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const r = readMessagesFile(path);
|
|
268
|
+
if (!r.ok) {
|
|
269
|
+
issues.push({ level: "error", locale, message: `${r.error} (Chrome drops this locale)` });
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (r.hadBom)
|
|
273
|
+
issues.push({ level: "warning", locale, message: `file starts with a byte order mark (BOM); save as UTF-8 without BOM` });
|
|
274
|
+
parsed.set(locale, r.data);
|
|
275
|
+
}
|
|
276
|
+
const source = parsed.get(dl);
|
|
277
|
+
if (!source)
|
|
278
|
+
return report();
|
|
279
|
+
let keep = opts.keep;
|
|
280
|
+
if (!keep) {
|
|
281
|
+
try {
|
|
282
|
+
keep = loadGlossary(root).keep;
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
keep = []; // a broken glossary is reported by translate
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
issues.push(...checkSource(source, dl));
|
|
289
|
+
// Manifest __MSG_key__ references must exist in the source.
|
|
290
|
+
const manifestText = JSON.stringify(manifest);
|
|
291
|
+
for (const m of manifestText.matchAll(/__MSG_([A-Za-z0-9_@]+)__/g)) {
|
|
292
|
+
const key = m[1];
|
|
293
|
+
if (key.startsWith("@@"))
|
|
294
|
+
continue;
|
|
295
|
+
if (lookupMessage(source, key) === undefined) {
|
|
296
|
+
issues.push({ level: "error", locale: dl, key, message: `manifest.json uses __MSG_${key}__ but the key is missing`, file: "manifest.json" });
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
for (const [locale, data] of parsed) {
|
|
300
|
+
if (locale !== dl)
|
|
301
|
+
issues.push(...checkLocale(source, data, locale, { keep }));
|
|
302
|
+
// Store length limits for localized manifest fields.
|
|
303
|
+
for (const [field, max] of Object.entries(MANIFEST_LIMITS)) {
|
|
304
|
+
const value = manifest[field];
|
|
305
|
+
const ref = typeof value === "string" ? /^__MSG_([A-Za-z0-9_@]+)__$/.exec(value) : null;
|
|
306
|
+
if (!ref)
|
|
307
|
+
continue;
|
|
308
|
+
const text = lookupMessage(data, ref[1]);
|
|
309
|
+
if (text !== undefined && [...text].length > max) {
|
|
310
|
+
issues.push({ level: "warning", locale, key: ref[1], message: `manifest "${field}" is ${[...text].length} chars; the limit is ${max}` });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// Store listing (only when the listing folder exists).
|
|
315
|
+
issues.push(...checkListing({ manifest, localesDir, defaultLocale: dl }, listingAbs, opts.stores ?? ["chrome"], listingRel));
|
|
316
|
+
// Stale strings (from .localizer/state.json).
|
|
317
|
+
const stale = findStale({ root, manifest, localesDir, defaultLocale: dl }, source, listingRel, opts.stale ?? "warning");
|
|
318
|
+
issues.push(...stale.issues);
|
|
319
|
+
staleCheck = stale.check;
|
|
320
|
+
return report();
|
|
321
|
+
}
|
|
322
|
+
export function formatIssue(i) {
|
|
323
|
+
const where = [i.locale ?? "manifest", i.key].filter(Boolean).join(" > ");
|
|
324
|
+
return `${i.level === "error" ? "ERROR" : "warn "} ${where}: ${i.message}`;
|
|
325
|
+
}
|
|
326
|
+
// ---------------------------------------------------------------------------
|
|
327
|
+
// File and line for each issue
|
|
328
|
+
// ---------------------------------------------------------------------------
|
|
329
|
+
function escapeRegExp(s) {
|
|
330
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
331
|
+
}
|
|
332
|
+
function lineAt(text, index) {
|
|
333
|
+
let n = 1;
|
|
334
|
+
for (let i = 0; i < index && i < text.length; i++)
|
|
335
|
+
if (text.charCodeAt(i) === 10)
|
|
336
|
+
n++;
|
|
337
|
+
return n;
|
|
338
|
+
}
|
|
339
|
+
/** Fill in `file` (when not set) and `line` (when it can be found) for every issue. */
|
|
340
|
+
export function annotate(root, issues, listingRel) {
|
|
341
|
+
const texts = new Map();
|
|
342
|
+
const read = (file) => {
|
|
343
|
+
if (!texts.has(file)) {
|
|
344
|
+
try {
|
|
345
|
+
texts.set(file, readFileSync(join(root, file), "utf8"));
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
texts.set(file, null);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return texts.get(file) ?? null;
|
|
352
|
+
};
|
|
353
|
+
for (const issue of issues) {
|
|
354
|
+
const isListing = issue.key?.startsWith("listing.") || issue.message.startsWith("listing");
|
|
355
|
+
if (!issue.file) {
|
|
356
|
+
if (issue.locale === null)
|
|
357
|
+
issue.file = "manifest.json";
|
|
358
|
+
else if (isListing)
|
|
359
|
+
issue.file = `${listingRel}/${issue.locale}.json`;
|
|
360
|
+
else
|
|
361
|
+
issue.file = `_locales/${issue.locale}/messages.json`;
|
|
362
|
+
}
|
|
363
|
+
if (issue.line !== undefined)
|
|
364
|
+
continue;
|
|
365
|
+
const text = read(issue.file);
|
|
366
|
+
if (text === null)
|
|
367
|
+
continue;
|
|
368
|
+
// JSON syntax errors: Node reports "(line N column M)" or "at position P".
|
|
369
|
+
const lineMatch = /\(line (\d+) column \d+\)/.exec(issue.message);
|
|
370
|
+
const posMatch = /at position (\d+)/.exec(issue.message);
|
|
371
|
+
if (lineMatch) {
|
|
372
|
+
issue.line = Number(lineMatch[1]);
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (posMatch) {
|
|
376
|
+
issue.line = lineAt(text, Number(posMatch[1]));
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (!issue.key)
|
|
380
|
+
continue;
|
|
381
|
+
let re;
|
|
382
|
+
if (issue.file === "manifest.json")
|
|
383
|
+
re = new RegExp(`__MSG_${escapeRegExp(issue.key)}__`, "i");
|
|
384
|
+
else if (issue.key.startsWith("listing."))
|
|
385
|
+
re = new RegExp(`"${escapeRegExp(issue.key.slice(8))}"\\s*:`);
|
|
386
|
+
else
|
|
387
|
+
re = new RegExp(`^\\s*"${escapeRegExp(issue.key)}"\\s*:`, "im");
|
|
388
|
+
const m = re.exec(text);
|
|
389
|
+
if (m)
|
|
390
|
+
issue.line = lineAt(text, m.index + (m[0].length - m[0].trimStart().length));
|
|
391
|
+
}
|
|
392
|
+
}
|