@verbaly/compiler 0.31.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +60 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +43 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -29,9 +29,15 @@ interface UsedKey {
|
|
|
29
29
|
key: string;
|
|
30
30
|
file: string;
|
|
31
31
|
}
|
|
32
|
+
interface StrayImport {
|
|
33
|
+
name: string;
|
|
34
|
+
source: string;
|
|
35
|
+
file: string;
|
|
36
|
+
}
|
|
32
37
|
interface Analysis {
|
|
33
38
|
tagged: TaggedMessage[];
|
|
34
39
|
usedKeys: UsedKey[];
|
|
40
|
+
strayImports: StrayImport[];
|
|
35
41
|
}
|
|
36
42
|
interface AnalyzeOptions {
|
|
37
43
|
tNames?: readonly string[];
|
|
@@ -125,6 +131,7 @@ declare class MessageRegistry {
|
|
|
125
131
|
remove(file: string): void;
|
|
126
132
|
messages(): Map<string, TaggedMessage>;
|
|
127
133
|
usedKeys(): Map<string, string[]>;
|
|
134
|
+
strayImports(): StrayImport[];
|
|
128
135
|
origins(): Map<string, string[]>;
|
|
129
136
|
}
|
|
130
137
|
//#endregion
|
|
@@ -412,5 +419,5 @@ interface WrapCodeResult {
|
|
|
412
419
|
}
|
|
413
420
|
declare function wrapCode(code: string, file: string): WrapCodeResult;
|
|
414
421
|
//#endregion
|
|
415
|
-
export { type Alternate, type Analysis, type AnalyzeOptions, type BrokenEntry, type Catalog, type Catalogs, type CheckResult, type ClaudeProviderOptions, DRAFTS_FILE, type DoctorEntry, type DoctorResult, type Drafts, type ExchangeFormat, type ExportFormat, type ExportOptions, type ExportResult, type ExportedFile, type Host, type HostSetup, type ImportOptions, type ImportResult, type InitOptions, type InitResult, type IssueSeverity, LOCALE_MODULE_PREFIX, type LocaleStatus, MessageRegistry, type MissingEntry, type MobileFormat, PLURAL_CATEGORIES, PSEUDO_LOCALE, type ParamType, type PluginOptions, RESOLVED_VIRTUAL_ID, type RenderConfig, type RenderHtmlOptions, type RenderHtmlResult, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, type RuntimeModuleOptions, SFC_FILE_RE, SOURCE_FILE_RE, type StatusResult, type StructureIssue, type SyncResult, type TaggedMessage, type TaggedParam, type TransComponent, type TransformResult, type TranslateConfig, type TranslateOptions, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type UsedKey, VIRTUAL_ID, type VerbalyConfig, WIRING_PACKAGES, type WatchProjectOptions, type WrapCodeResult, type WrapEntry, type WrapOptions, type WrapResult, type WrapSkip, analyze, analyzeFile, analyzeSfc, catalogPath, check, checkNextSteps, claudeProvider, clearDrafts, collectOrigins, collectParams, createSourceFilter, detectHost, doctor, effectiveDrafts, exportCatalogs, extractProject, findConfigFile, formatCheckResult, formatCheckWarnings, formatStatusResult, gatePasses, generateDts, generateLocaleModule, generateRuntimeModule, githubCheckAnnotations, importCatalogs, init, isMobileFormat, isTransformTarget, loadCatalogs, loadConfig, loadConfigFile, loadDrafts, loadVirtualModule, markDrafts, parseExchangeFile, pruneCatalogs, pseudoCatalogs, pseudoLocalize, readCatalog, readDependencies, renderHtml, renderParamType, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, serializeCatalog, stableKey, status, structureMatches, syncCatalogs, targetLocales, transformCode, transformSource, translateCatalogs, validateMessage, validatePair, watchProject, wrapCode, wrapProject, writeCatalog, writeDts };
|
|
422
|
+
export { type Alternate, type Analysis, type AnalyzeOptions, type BrokenEntry, type Catalog, type Catalogs, type CheckResult, type ClaudeProviderOptions, DRAFTS_FILE, type DoctorEntry, type DoctorResult, type Drafts, type ExchangeFormat, type ExportFormat, type ExportOptions, type ExportResult, type ExportedFile, type Host, type HostSetup, type ImportOptions, type ImportResult, type InitOptions, type InitResult, type IssueSeverity, LOCALE_MODULE_PREFIX, type LocaleStatus, MessageRegistry, type MissingEntry, type MobileFormat, PLURAL_CATEGORIES, PSEUDO_LOCALE, type ParamType, type PluginOptions, RESOLVED_VIRTUAL_ID, type RenderConfig, type RenderHtmlOptions, type RenderHtmlResult, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, type RuntimeModuleOptions, SFC_FILE_RE, SOURCE_FILE_RE, type StatusResult, type StrayImport, type StructureIssue, type SyncResult, type TaggedMessage, type TaggedParam, type TransComponent, type TransformResult, type TranslateConfig, type TranslateOptions, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type UsedKey, VIRTUAL_ID, type VerbalyConfig, WIRING_PACKAGES, type WatchProjectOptions, type WrapCodeResult, type WrapEntry, type WrapOptions, type WrapResult, type WrapSkip, analyze, analyzeFile, analyzeSfc, catalogPath, check, checkNextSteps, claudeProvider, clearDrafts, collectOrigins, collectParams, createSourceFilter, detectHost, doctor, effectiveDrafts, exportCatalogs, extractProject, findConfigFile, formatCheckResult, formatCheckWarnings, formatStatusResult, gatePasses, generateDts, generateLocaleModule, generateRuntimeModule, githubCheckAnnotations, importCatalogs, init, isMobileFormat, isTransformTarget, loadCatalogs, loadConfig, loadConfigFile, loadDrafts, loadVirtualModule, markDrafts, parseExchangeFile, pruneCatalogs, pseudoCatalogs, pseudoLocalize, readCatalog, readDependencies, renderHtml, renderParamType, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, serializeCatalog, stableKey, status, structureMatches, syncCatalogs, targetLocales, transformCode, transformSource, translateCatalogs, validateMessage, validatePair, watchProject, wrapCode, wrapProject, writeCatalog, writeDts };
|
|
416
423
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -42,8 +42,10 @@ function analyze(code, file, options = {}) {
|
|
|
42
42
|
});
|
|
43
43
|
const tagged = [];
|
|
44
44
|
const usedKeys = [];
|
|
45
|
+
const strayImports = [];
|
|
45
46
|
walk$1(ast.program, (node) => {
|
|
46
|
-
if (node.type === "
|
|
47
|
+
if (node.type === "ImportDeclaration") collectStrayImports(node, file, strayImports);
|
|
48
|
+
else if (node.type === "TaggedTemplateExpression") {
|
|
47
49
|
const tag = node.tag;
|
|
48
50
|
const explicit = explicitId(tag, names);
|
|
49
51
|
if (!explicit && !isTReference(tag, names)) return;
|
|
@@ -72,9 +74,24 @@ function analyze(code, file, options = {}) {
|
|
|
72
74
|
});
|
|
73
75
|
return {
|
|
74
76
|
tagged,
|
|
75
|
-
usedKeys
|
|
77
|
+
usedKeys,
|
|
78
|
+
strayImports
|
|
76
79
|
};
|
|
77
80
|
}
|
|
81
|
+
const VERBALY_PACKAGE = /^(?:verbaly|@verbaly\/[\w-]+)$/;
|
|
82
|
+
function collectStrayImports(node, file, out) {
|
|
83
|
+
const source = node.source;
|
|
84
|
+
if (typeof source.value !== "string" || !VERBALY_PACKAGE.test(source.value)) return;
|
|
85
|
+
for (const spec of node.specifiers) {
|
|
86
|
+
if (spec.type !== "ImportSpecifier") continue;
|
|
87
|
+
const imported = spec.imported;
|
|
88
|
+
if (imported.type === "Identifier" && imported.name === "t") out.push({
|
|
89
|
+
name: "t",
|
|
90
|
+
source: source.value,
|
|
91
|
+
file
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
78
95
|
function handleTrans(code, node, file, tagged, usedKeys, names) {
|
|
79
96
|
const opening = node.openingElement;
|
|
80
97
|
const nameNode = opening.name;
|
|
@@ -303,6 +320,7 @@ function analyzeSfc(code, file) {
|
|
|
303
320
|
const options = svelte ? { tNames: ["t", "$t"] } : void 0;
|
|
304
321
|
const tagged = [];
|
|
305
322
|
const usedKeys = [];
|
|
323
|
+
const strayImports = [];
|
|
306
324
|
const frontmatter = file.endsWith(".astro") ? FRONTMATTER_RE.exec(code) : null;
|
|
307
325
|
if (frontmatter?.[2]) merge(analyzeSegment(frontmatter[2], file, options), frontmatter[1].length, false);
|
|
308
326
|
for (const match of code.matchAll(SCRIPT_RE)) {
|
|
@@ -327,7 +345,8 @@ function analyzeSfc(code, file) {
|
|
|
327
345
|
}
|
|
328
346
|
return {
|
|
329
347
|
tagged,
|
|
330
|
-
usedKeys
|
|
348
|
+
usedKeys,
|
|
349
|
+
strayImports
|
|
331
350
|
};
|
|
332
351
|
function merge(analysis, offset, markupSegment) {
|
|
333
352
|
if (!analysis) return;
|
|
@@ -345,6 +364,7 @@ function analyzeSfc(code, file) {
|
|
|
345
364
|
...markupSegment && { singleQuote: true }
|
|
346
365
|
});
|
|
347
366
|
usedKeys.push(...analysis.usedKeys);
|
|
367
|
+
strayImports.push(...analysis.strayImports);
|
|
348
368
|
}
|
|
349
369
|
}
|
|
350
370
|
function analyzeSegment(code, file, options) {
|
|
@@ -528,6 +548,10 @@ function surplus(a, b) {
|
|
|
528
548
|
function list(items) {
|
|
529
549
|
return items.length > 1 ? `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}` : items[0];
|
|
530
550
|
}
|
|
551
|
+
const ESCAPED_SYNTAX = /(?<!\{)\{\{\s*[\w.]+\s*[|:][^{}]*\}\}/;
|
|
552
|
+
function escapedSyntax(message) {
|
|
553
|
+
return ESCAPED_SYNTAX.exec(message)?.[0];
|
|
554
|
+
}
|
|
531
555
|
function validateMessage(message, locale) {
|
|
532
556
|
const issues = [];
|
|
533
557
|
for (const [name, shape] of shapes(message)) {
|
|
@@ -1240,6 +1264,9 @@ var MessageRegistry = class {
|
|
|
1240
1264
|
}
|
|
1241
1265
|
return out;
|
|
1242
1266
|
}
|
|
1267
|
+
strayImports() {
|
|
1268
|
+
return [...this.files.values()].flatMap((analysis) => analysis.strayImports);
|
|
1269
|
+
}
|
|
1243
1270
|
origins() {
|
|
1244
1271
|
const out = this.usedKeys();
|
|
1245
1272
|
for (const analysis of this.files.values()) for (const msg of analysis.tagged) {
|
|
@@ -1474,7 +1501,7 @@ async function doctor(cfg) {
|
|
|
1474
1501
|
const deps = readDependencies(cfg.root);
|
|
1475
1502
|
const host = detectHost(cfg.root);
|
|
1476
1503
|
const installed = WIRING_PACKAGES.find((pkg) => deps[pkg]);
|
|
1477
|
-
if (!host) ok("plugin", "no bundler detected, the CLI flow (extract/check) applies");
|
|
1504
|
+
if (!host) ok("plugin", "no framework or bundler detected, the CLI flow (extract/check) applies");
|
|
1478
1505
|
else if (installed) ok("plugin", `${installed} installed for ${host.name}`);
|
|
1479
1506
|
else warn("plugin", `${host.name} detected but ${host.pkg} is not installed`, `pnpm add -D ${host.pkg} and ${host.wire}`);
|
|
1480
1507
|
const scanning = cfg.include.length > 0;
|
|
@@ -1486,6 +1513,18 @@ async function doctor(cfg) {
|
|
|
1486
1513
|
else ok("types", "verbaly.d.ts is up to date");
|
|
1487
1514
|
}
|
|
1488
1515
|
const registry = await extractProject(cfg);
|
|
1516
|
+
if (scanning) {
|
|
1517
|
+
const stray = registry.strayImports();
|
|
1518
|
+
if (stray.length > 0) {
|
|
1519
|
+
const files = [...new Set(stray.map((entry) => rel(entry.file)))];
|
|
1520
|
+
error("imports", `${files.length} ${files.length === 1 ? "file imports" : "files import"} t from a verbaly package, which never exports it (${preview(files)})`, "t comes from your instance (React: const t = useT()) or from virtual:verbaly");
|
|
1521
|
+
}
|
|
1522
|
+
const escaped = [...registry.messages().values()].map((msg) => ({
|
|
1523
|
+
file: rel(msg.file),
|
|
1524
|
+
slice: escapedSyntax(msg.message)
|
|
1525
|
+
})).filter((entry) => entry.slice !== void 0);
|
|
1526
|
+
if (escaped.length > 0) warn("messages", `${escaped.length} extracted ${escaped.length === 1 ? "message keeps" : "messages keep"} a block as literal text (${escaped[0].file}: ${escaped[0].slice})`, "a tagged template takes its values from ${…}: use t(key, params) for a plural or format block");
|
|
1527
|
+
}
|
|
1489
1528
|
if (source && scanning) {
|
|
1490
1529
|
const extracted = registry.messages();
|
|
1491
1530
|
const used = registry.usedKeys();
|