@nifrajs/cli 5.1.0 → 5.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/CHANGELOG.md +3211 -0
- package/README.md +3 -0
- package/dist/agent-files.d.ts +19 -11
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +26 -18
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +1 -0
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +14 -1
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +131 -45
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check-diagnostics.d.ts +5 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +3 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +6 -3
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +52 -12
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +23 -12
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +9 -5
- package/dist/command-catalog.js.map +1 -1
- package/dist/dev-bun-config.d.ts +6 -3
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +13 -10
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/dev-feed-tool.d.ts +3 -2
- package/dist/dev-feed-tool.d.ts.map +1 -1
- package/dist/dev-feed-tool.js +26 -5
- package/dist/dev-feed-tool.js.map +1 -1
- package/dist/doctor.d.ts +15 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +79 -61
- package/dist/doctor.js.map +1 -1
- package/dist/i18n-check.d.ts +11 -1
- package/dist/i18n-check.d.ts.map +1 -1
- package/dist/i18n-check.js +170 -17
- package/dist/i18n-check.js.map +1 -1
- package/dist/init-agents.d.ts +46 -6
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +193 -31
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +9 -1
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/source-facts.d.ts +6 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +106 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/workspace-packages.d.ts +22 -0
- package/dist/internal/workspace-packages.d.ts.map +1 -0
- package/dist/internal/workspace-packages.js +215 -0
- package/dist/internal/workspace-packages.js.map +1 -0
- package/dist/load.d.ts +7 -2
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +11 -2
- package/dist/load.js.map +1 -1
- package/dist/lock-links.d.ts +42 -0
- package/dist/lock-links.d.ts.map +1 -0
- package/dist/lock-links.js +144 -0
- package/dist/lock-links.js.map +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +5 -2
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-root.d.ts +6 -4
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +12 -8
- package/dist/mcp-root.js.map +1 -1
- package/dist/migrate-layout.d.ts +2 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +434 -29
- package/dist/migrate-layout.js.map +1 -1
- package/dist/project-site.d.ts +7 -0
- package/dist/project-site.d.ts.map +1 -0
- package/dist/project-site.js +19 -0
- package/dist/project-site.js.map +1 -0
- package/dist/recipes/4.0.0.d.ts.map +1 -1
- package/dist/recipes/4.0.0.js +2 -0
- package/dist/recipes/4.0.0.js.map +1 -1
- package/dist/recipes/5.1.0.d.ts +9 -0
- package/dist/recipes/5.1.0.d.ts.map +1 -0
- package/dist/recipes/5.1.0.js +22 -0
- package/dist/recipes/5.1.0.js.map +1 -0
- package/dist/recipes/5.2.0.d.ts +10 -0
- package/dist/recipes/5.2.0.d.ts.map +1 -0
- package/dist/recipes/5.2.0.js +32 -0
- package/dist/recipes/5.2.0.js.map +1 -0
- package/dist/recipes/index.d.ts +3 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +7 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +2 -0
- package/dist/review.js.map +1 -1
- package/dist/rule-explain.d.ts +26 -0
- package/dist/rule-explain.d.ts.map +1 -0
- package/dist/rule-explain.js +49 -0
- package/dist/rule-explain.js.map +1 -0
- package/dist/rules/codes.d.ts +2 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +2 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +93 -21
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/explanations.d.ts +14 -0
- package/dist/rules/explanations.d.ts.map +1 -0
- package/dist/rules/explanations.js +316 -0
- package/dist/rules/explanations.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +24 -1
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/merge-auth.d.ts +12 -0
- package/dist/rules/merge-auth.d.ts.map +1 -0
- package/dist/rules/merge-auth.js +52 -0
- package/dist/rules/merge-auth.js.map +1 -0
- package/dist/rules/pages.d.ts +27 -0
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +177 -2
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/routes.d.ts +3 -2
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +4 -3
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +3 -2
- package/dist/rules/zones.js.map +1 -1
- package/dist/typecheck-coverage.d.ts +11 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +50 -7
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/upgrade.d.ts +37 -1
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +171 -20
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +2 -0
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.d.ts.map +1 -1
- package/dist/version-drift.js +12 -1
- package/dist/version-drift.js.map +1 -1
- package/dist/web-app-options.d.ts +1 -1
- package/dist/web-app-options.d.ts.map +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/docs/examples.json +19 -1
- package/docs/llms-full.txt +625 -130
- package/docs/types.json +396 -50
- package/package.json +13 -12
- package/src/agent-files.ts +27 -17
- package/src/assure-hydration.ts +1 -0
- package/src/assure.ts +11 -1
- package/src/capabilities-tool.ts +159 -50
- package/src/check-diagnostics.ts +8 -0
- package/src/check-scan.ts +9 -3
- package/src/check.ts +67 -12
- package/src/cli.ts +24 -11
- package/src/command-catalog.ts +16 -8
- package/src/dev-bun-config.ts +13 -9
- package/src/dev-feed-tool.ts +40 -6
- package/src/doctor.ts +102 -66
- package/src/i18n-check.ts +254 -18
- package/src/init-agents.ts +221 -41
- package/src/internal/project-specifiers.ts +9 -1
- package/src/internal/source-facts.ts +124 -0
- package/src/internal/workspace-packages.ts +218 -0
- package/src/load.ts +19 -3
- package/src/lock-links.ts +173 -0
- package/src/mcp-exec.ts +5 -2
- package/src/mcp-http.ts +1 -1
- package/src/mcp-root.ts +14 -8
- package/src/migrate-layout.ts +495 -31
- package/src/project-site.ts +18 -0
- package/src/recipes/4.0.0.ts +2 -0
- package/src/recipes/5.1.0.ts +23 -0
- package/src/recipes/5.2.0.ts +33 -0
- package/src/recipes/index.ts +7 -0
- package/src/review.ts +2 -0
- package/src/rule-explain.ts +75 -0
- package/src/rules/codes.ts +2 -0
- package/src/rules/contract-visibility.ts +118 -20
- package/src/rules/explanations.ts +329 -0
- package/src/rules/legacy.ts +24 -1
- package/src/rules/merge-auth.ts +55 -0
- package/src/rules/pages.ts +221 -2
- package/src/rules/routes.ts +4 -3
- package/src/rules/zones.ts +3 -2
- package/src/typecheck-coverage.ts +51 -6
- package/src/upgrade.ts +227 -22
- package/src/verification-plan.ts +6 -0
- package/src/version-drift.ts +15 -0
- package/src/web-app-options.ts +9 -1
package/src/i18n-check.ts
CHANGED
|
@@ -2,14 +2,25 @@
|
|
|
2
2
|
* `nifra i18n check [entry]` - runs `checkCatalogs()` from `@nifrajs/i18n/check` over an app's locale
|
|
3
3
|
* registry and catalogs. Unlike `nifra check`, this IMPORTS app code: the entry module, which exports
|
|
4
4
|
* `locales` (from `defineLocales`) and `catalogs` (by locale key: a catalog, or a function returning
|
|
5
|
-
* one or a promise of one, such as `() => import("./messages/fr.json")`), plus an optional `ignore
|
|
5
|
+
* one or a promise of one, such as `() => import("./messages/fr.json")`), plus an optional `ignore`
|
|
6
|
+
* and `check`, the rest of `checkCatalogs()`'s options (`latinWords`, thresholds, `rules`).
|
|
6
7
|
* The default entry is the first of {@link DEFAULT_ENTRIES} that exists.
|
|
8
|
+
*
|
|
9
|
+
* An entry may export a copy function (`defineCopy` from `@nifrajs/i18n/copy`) as well as, or instead
|
|
10
|
+
* of, `catalogs`. Its tables are found in the project's source with the TypeScript AST, read without
|
|
11
|
+
* running them, and checked as catalogs too: each under its id, its `file:line` or `copy.id()`'s.
|
|
7
12
|
*/
|
|
8
|
-
import { existsSync } from "node:fs"
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
9
14
|
import { relative, resolve } from "node:path"
|
|
10
15
|
import { pathToFileURL } from "node:url"
|
|
11
16
|
import type { MessageTree } from "@nifrajs/i18n"
|
|
12
|
-
import type {
|
|
17
|
+
import type {
|
|
18
|
+
CatalogCheckOptions,
|
|
19
|
+
CatalogCheckResult,
|
|
20
|
+
CatalogFinding,
|
|
21
|
+
CopyTableEntry,
|
|
22
|
+
} from "@nifrajs/i18n/check"
|
|
23
|
+
import type { CopyTableSite } from "@nifrajs/i18n/extract"
|
|
13
24
|
|
|
14
25
|
export const DEFAULT_ENTRIES = [
|
|
15
26
|
"shared/i18n.ts",
|
|
@@ -20,10 +31,21 @@ export const DEFAULT_ENTRIES = [
|
|
|
20
31
|
"app/i18n.ts",
|
|
21
32
|
] as const
|
|
22
33
|
|
|
34
|
+
/** The copy tables a check read, when the entry exports a copy function. */
|
|
35
|
+
export interface CopyTablesChecked {
|
|
36
|
+
/** Where the copy function is defined (`shared/i18n.ts`). */
|
|
37
|
+
readonly definitions: readonly string[]
|
|
38
|
+
readonly tables: number
|
|
39
|
+
readonly files: number
|
|
40
|
+
/** Each table's id -> its `file:line`. */
|
|
41
|
+
readonly locations: Readonly<Record<string, string>>
|
|
42
|
+
}
|
|
43
|
+
|
|
23
44
|
export interface I18nCheckOutput {
|
|
24
45
|
/** The entry module, relative to the project directory. */
|
|
25
46
|
readonly entry: string
|
|
26
47
|
readonly result: CatalogCheckResult
|
|
48
|
+
readonly copy?: CopyTablesChecked
|
|
27
49
|
}
|
|
28
50
|
|
|
29
51
|
const isObject = (value: unknown): value is Record<string, unknown> =>
|
|
@@ -35,6 +57,15 @@ const unwrapModule = (value: unknown): unknown =>
|
|
|
35
57
|
? value.default
|
|
36
58
|
: value
|
|
37
59
|
|
|
60
|
+
/** A copy function `defineCopy` returned: callable, with `pick`, `format` and its registry. */
|
|
61
|
+
const isCopy = (value: unknown): value is { readonly locales: unknown } =>
|
|
62
|
+
typeof value === "function" &&
|
|
63
|
+
"pick" in value &&
|
|
64
|
+
typeof value.pick === "function" &&
|
|
65
|
+
"format" in value &&
|
|
66
|
+
typeof value.format === "function" &&
|
|
67
|
+
"locales" in value
|
|
68
|
+
|
|
38
69
|
const isRegistry = (value: unknown): value is CatalogCheckOptions["locales"] =>
|
|
39
70
|
isObject(value) &&
|
|
40
71
|
typeof value.default === "string" &&
|
|
@@ -57,7 +88,7 @@ function resolveEntry(cwd: string, entry: string | undefined): string {
|
|
|
57
88
|
)
|
|
58
89
|
}
|
|
59
90
|
|
|
60
|
-
/** Import the entry, load every catalog it names, and check them. */
|
|
91
|
+
/** Import the entry, load every catalog it names, read the copy tables, and check them. */
|
|
61
92
|
export async function runI18nCheck(
|
|
62
93
|
cwd: string,
|
|
63
94
|
options: { readonly entry?: string | undefined } = {},
|
|
@@ -65,36 +96,221 @@ export async function runI18nCheck(
|
|
|
65
96
|
const path = resolveEntry(cwd, options.entry)
|
|
66
97
|
const mod = (await import(pathToFileURL(path).href)) as Record<string, unknown>
|
|
67
98
|
const source = isObject(mod.default) && mod.locales === undefined ? mod.default : mod
|
|
68
|
-
const {
|
|
99
|
+
const { catalogs, ignore, check } = source
|
|
69
100
|
const entry = relative(cwd, path).replaceAll("\\", "/") || path
|
|
101
|
+
const copies = Object.entries(source).filter(
|
|
102
|
+
(entry): entry is [string, { readonly locales: unknown }] => isCopy(entry[1]),
|
|
103
|
+
)
|
|
104
|
+
const locales = source.locales ?? copies[0]?.[1].locales
|
|
70
105
|
if (!isRegistry(locales)) {
|
|
71
106
|
throw new Error(
|
|
72
107
|
`i18n check: ${entry} must export \`locales\`, the registry defineLocales() returns`,
|
|
73
108
|
)
|
|
74
109
|
}
|
|
75
|
-
if (!isObject(catalogs)) {
|
|
110
|
+
if (!isObject(catalogs) && copies.length === 0) {
|
|
76
111
|
throw new Error(
|
|
77
|
-
`i18n check: ${entry} must export \`catalogs\`, an object of catalogs by locale key`,
|
|
112
|
+
`i18n check: ${entry} must export \`catalogs\`, an object of catalogs by locale key, or a copy function from defineCopy()`,
|
|
78
113
|
)
|
|
79
114
|
}
|
|
80
115
|
if (ignore !== undefined && !isObject(ignore)) {
|
|
81
116
|
throw new Error(`i18n check: \`ignore\` in ${entry} must be an object of key patterns by check`)
|
|
82
117
|
}
|
|
118
|
+
if (check !== undefined && !isObject(check)) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
`i18n check: \`check\` in ${entry} must be an object of checkCatalogs() options`,
|
|
121
|
+
)
|
|
122
|
+
}
|
|
83
123
|
const loaded: Record<string, MessageTree | undefined> = {}
|
|
84
|
-
for (const key of Object.
|
|
85
|
-
let value =
|
|
124
|
+
for (const [key, entryValue] of isObject(catalogs) ? Object.entries(catalogs) : []) {
|
|
125
|
+
let value = entryValue
|
|
86
126
|
if (typeof value === "function") value = (value as () => unknown)()
|
|
87
127
|
loaded[key] = unwrapModule(await value) as MessageTree | undefined
|
|
88
128
|
}
|
|
89
129
|
// Loaded on use: the command catalog imports this module on every CLI start.
|
|
90
130
|
const { checkCatalogs } = await import("@nifrajs/i18n/check")
|
|
131
|
+
const copy =
|
|
132
|
+
copies.length === 0
|
|
133
|
+
? undefined
|
|
134
|
+
: await readCopyTables(
|
|
135
|
+
cwd,
|
|
136
|
+
path,
|
|
137
|
+
locales,
|
|
138
|
+
copies.map(([name]) => name),
|
|
139
|
+
loaded,
|
|
140
|
+
)
|
|
141
|
+
const result = checkCatalogs({
|
|
142
|
+
// biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: the app's own entry module supplies these options; checkCatalogs reads each one by name.
|
|
143
|
+
...(check as Omit<CatalogCheckOptions, "locales" | "catalogs"> | undefined),
|
|
144
|
+
locales,
|
|
145
|
+
catalogs: copy?.catalogs ?? loaded,
|
|
146
|
+
// biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: the app's own entry module supplies the patterns; checkCatalogs only compares them with keys.
|
|
147
|
+
ignore: (ignore ??
|
|
148
|
+
(isObject(check) ? check.ignore : undefined)) as CatalogCheckOptions["ignore"],
|
|
149
|
+
})
|
|
150
|
+
if (copy === undefined) return { entry, result }
|
|
151
|
+
const findings = [...copy.findings, ...result.findings]
|
|
91
152
|
return {
|
|
92
153
|
entry,
|
|
93
|
-
result:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
154
|
+
result: { ...result, findings, ok: findings.every((finding) => finding.severity !== "error") },
|
|
155
|
+
copy: copy.checked,
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Find every table of the entry's copy functions in the project, and merge them into `loaded` as
|
|
161
|
+
* catalogs. Problems with the tables themselves come back as findings.
|
|
162
|
+
*/
|
|
163
|
+
async function readCopyTables(
|
|
164
|
+
cwd: string,
|
|
165
|
+
entryPath: string,
|
|
166
|
+
locales: CatalogCheckOptions["locales"],
|
|
167
|
+
exportNames: readonly string[],
|
|
168
|
+
loaded: Readonly<Record<string, MessageTree | undefined>>,
|
|
169
|
+
): Promise<{
|
|
170
|
+
readonly catalogs: Record<string, MessageTree | undefined>
|
|
171
|
+
readonly findings: readonly CatalogFinding[]
|
|
172
|
+
readonly checked: CopyTablesChecked
|
|
173
|
+
}> {
|
|
174
|
+
const [{ walkSource }, { loadProjectTypeScript }, { createCopyScanner }, { tablesToCatalogs }] =
|
|
175
|
+
await Promise.all([
|
|
176
|
+
import("./check-scan.ts"),
|
|
177
|
+
import("./internal/typescript-import.ts"),
|
|
178
|
+
import("@nifrajs/i18n/extract"),
|
|
179
|
+
import("@nifrajs/i18n/check"),
|
|
180
|
+
])
|
|
181
|
+
const root = resolve(cwd).replaceAll("\\", "/")
|
|
182
|
+
const files = new Map<string, string>()
|
|
183
|
+
await walkSource(cwd, (file, content) => files.set(`${root}/${file}`, content), { scripts: true })
|
|
184
|
+
const ts = await loadProjectTypeScript(cwd)
|
|
185
|
+
const findings: CatalogFinding[] = []
|
|
186
|
+
const finding = (
|
|
187
|
+
severity: CatalogFinding["severity"],
|
|
188
|
+
code: "copy-table" | "copy-id",
|
|
189
|
+
key: string | undefined,
|
|
190
|
+
message: string,
|
|
191
|
+
): void => {
|
|
192
|
+
const found: CatalogFinding = { severity, code, locale: locales.default, message }
|
|
193
|
+
findings.push(key === undefined ? found : { ...found, key })
|
|
194
|
+
}
|
|
195
|
+
const checked = (
|
|
196
|
+
definitions: readonly string[],
|
|
197
|
+
sites: readonly CopyTableSite[],
|
|
198
|
+
): CopyTablesChecked => ({
|
|
199
|
+
definitions,
|
|
200
|
+
tables: sites.length,
|
|
201
|
+
files: new Set(sites.map((site) => site.file)).size,
|
|
202
|
+
// The first table under an id is the one checked; a later one is reported as reusing it.
|
|
203
|
+
locations: Object.fromEntries(
|
|
204
|
+
sites.toReversed().map((site) => [site.id, `${site.file}:${site.line}`]),
|
|
205
|
+
),
|
|
206
|
+
})
|
|
207
|
+
try {
|
|
208
|
+
if (ts.compiler === undefined) {
|
|
209
|
+
finding(
|
|
210
|
+
"error",
|
|
211
|
+
"copy-table",
|
|
212
|
+
undefined,
|
|
213
|
+
"copy tables need the project's TypeScript to be read; install typescript",
|
|
214
|
+
)
|
|
215
|
+
return { catalogs: { ...loaded }, findings, checked: checked([], []) }
|
|
216
|
+
}
|
|
217
|
+
const scanner = createCopyScanner(ts.compiler, {
|
|
218
|
+
root,
|
|
219
|
+
read: (file) => {
|
|
220
|
+
const known = files.get(file)
|
|
221
|
+
if (known !== undefined) return known
|
|
222
|
+
try {
|
|
223
|
+
return readFileSync(file, "utf8")
|
|
224
|
+
} catch {
|
|
225
|
+
return undefined
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
})
|
|
229
|
+
const entryFile = entryPath.replaceAll("\\", "/")
|
|
230
|
+
const definitions = new Set<string>()
|
|
231
|
+
for (const name of exportNames) {
|
|
232
|
+
const ref = scanner.exportedDefinition(entryFile, name)
|
|
233
|
+
if (ref === undefined) {
|
|
234
|
+
finding(
|
|
235
|
+
"error",
|
|
236
|
+
"copy-table",
|
|
237
|
+
undefined,
|
|
238
|
+
`\`${name}\` in ${relative(cwd, entryPath)} does not lead to a \`defineCopy(...)\` constant, so its tables cannot be found`,
|
|
239
|
+
)
|
|
240
|
+
continue
|
|
241
|
+
}
|
|
242
|
+
definitions.add(`${ref.file}\u0000${ref.name}`)
|
|
243
|
+
const unreadable = scanner.definition(ref)?.unreadable
|
|
244
|
+
if (unreadable !== undefined) {
|
|
245
|
+
finding(
|
|
246
|
+
"warning",
|
|
247
|
+
"copy-table",
|
|
248
|
+
undefined,
|
|
249
|
+
`${ref.file}: ${unreadable}, so a production client build keeps every locale of its tables in every page`,
|
|
250
|
+
)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const sites = [...files.keys()]
|
|
254
|
+
.flatMap((file) => scanner.tables(file))
|
|
255
|
+
.filter((site) => definitions.has(`${site.definition.file}\u0000${site.definition.name}`))
|
|
256
|
+
const tables: CopyTableEntry[] = []
|
|
257
|
+
const seen = new Map<string, CopyTableSite>()
|
|
258
|
+
for (const site of sites) {
|
|
259
|
+
const where = `${site.file}:${site.line}`
|
|
260
|
+
if (site.values === undefined) {
|
|
261
|
+
finding(
|
|
262
|
+
"warning",
|
|
263
|
+
"copy-table",
|
|
264
|
+
site.id,
|
|
265
|
+
`${where} is not read statically (${site.unreadable}), so it is not checked and a production client build keeps every locale of it`,
|
|
266
|
+
)
|
|
267
|
+
continue
|
|
268
|
+
}
|
|
269
|
+
const first = seen.get(site.id)
|
|
270
|
+
if (first !== undefined) {
|
|
271
|
+
finding(
|
|
272
|
+
"error",
|
|
273
|
+
"copy-id",
|
|
274
|
+
site.id,
|
|
275
|
+
`${where} reuses the id of ${first.file}:${first.line}`,
|
|
276
|
+
)
|
|
277
|
+
continue
|
|
278
|
+
}
|
|
279
|
+
seen.set(site.id, site)
|
|
280
|
+
tables.push({ id: site.id, values: site.values })
|
|
281
|
+
}
|
|
282
|
+
const transposed = tablesToCatalogs(tables, locales)
|
|
283
|
+
for (const id of transposed.conflicts) {
|
|
284
|
+
finding("error", "copy-id", id, `${id} nests under, or over, another table's id`)
|
|
285
|
+
}
|
|
286
|
+
// Catalog keys and table ids share one namespace per locale.
|
|
287
|
+
const catalogs: Record<string, MessageTree | undefined> = { ...loaded }
|
|
288
|
+
for (const [locale, tree] of Object.entries(transposed.catalogs)) {
|
|
289
|
+
const own = catalogs[locale]
|
|
290
|
+
if (own === undefined) {
|
|
291
|
+
catalogs[locale] = tree
|
|
292
|
+
continue
|
|
293
|
+
}
|
|
294
|
+
const merged: MessageTree = { ...own }
|
|
295
|
+
for (const [key, value] of Object.entries(tree)) {
|
|
296
|
+
if (Object.hasOwn(merged, key)) {
|
|
297
|
+
finding("error", "copy-id", key, `the ${locale} catalog and a copy table both use ${key}`)
|
|
298
|
+
continue
|
|
299
|
+
}
|
|
300
|
+
merged[key] = value
|
|
301
|
+
}
|
|
302
|
+
catalogs[locale] = merged
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
catalogs,
|
|
306
|
+
findings,
|
|
307
|
+
checked: checked(
|
|
308
|
+
[...definitions].map((key) => key.split("\u0000", 1)[0] ?? key),
|
|
309
|
+
sites,
|
|
310
|
+
),
|
|
311
|
+
}
|
|
312
|
+
} finally {
|
|
313
|
+
await ts.session?.close()
|
|
98
314
|
}
|
|
99
315
|
}
|
|
100
316
|
|
|
@@ -125,22 +341,42 @@ const percent = (share: number): string => `${(share * 100).toFixed(share === 1
|
|
|
125
341
|
|
|
126
342
|
/** The human report: a coverage table, then findings, grouped where they are key lists. */
|
|
127
343
|
export function renderI18nCheck(out: I18nCheckOutput): readonly string[] {
|
|
128
|
-
const { result } = out
|
|
344
|
+
const { result, copy } = out
|
|
129
345
|
const lines = [`nifra i18n check - ${out.entry}`, ""]
|
|
346
|
+
if (copy !== undefined) {
|
|
347
|
+
lines.splice(
|
|
348
|
+
1,
|
|
349
|
+
0,
|
|
350
|
+
`${copy.tables} copy table${copy.tables === 1 ? "" : "s"} in ${copy.files} file${copy.files === 1 ? "" : "s"} (${copy.definitions.join(", ") || "no definition found"})`,
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
// An explicit copy.id() reads as a key; say where it is.
|
|
354
|
+
const located = (key: string): string => {
|
|
355
|
+
const at = copy?.locations[key]
|
|
356
|
+
return at === undefined || key.startsWith(at) ? key : `${key} (${at})`
|
|
357
|
+
}
|
|
130
358
|
const width = Math.max(6, ...result.coverage.map((row) => row.locale.length))
|
|
131
359
|
for (const row of result.coverage) {
|
|
132
360
|
const label = row.default ? "default" : row.draft ? "draft" : ""
|
|
133
361
|
const counts = row.default
|
|
134
362
|
? `${row.total} messages`
|
|
135
363
|
: `${row.translated}/${row.total} (${percent(row.coverage)})${row.own === row.translated ? "" : `, ${row.own} own`}`
|
|
136
|
-
|
|
364
|
+
const latin =
|
|
365
|
+
row.latinShare === undefined || row.latinShare === 0
|
|
366
|
+
? ""
|
|
367
|
+
: `, ${percent(row.latinShare)} Latin words`
|
|
368
|
+
lines.push(` ${row.locale.padEnd(width)} ${label.padEnd(7)} ${counts}${latin}`)
|
|
137
369
|
}
|
|
138
370
|
if (result.coverage.length > 0) lines.push("")
|
|
139
371
|
|
|
140
372
|
const groups = new Map<string, CatalogFinding[]>()
|
|
141
373
|
for (const finding of result.findings) {
|
|
142
374
|
if (!GROUPED.has(finding.code) || finding.key === undefined) {
|
|
143
|
-
|
|
375
|
+
const at = finding.key === undefined ? undefined : copy?.locations[finding.key]
|
|
376
|
+
const where = at === undefined || finding.message.includes(at) ? "" : ` (${at})`
|
|
377
|
+
lines.push(
|
|
378
|
+
`${MARK[finding.severity]} ${finding.locale} ${finding.code}: ${finding.message}${where}`,
|
|
379
|
+
)
|
|
144
380
|
continue
|
|
145
381
|
}
|
|
146
382
|
const id = `${finding.severity}\u0000${finding.locale}\u0000${finding.code}`
|
|
@@ -150,7 +386,7 @@ export function renderI18nCheck(out: I18nCheckOutput): readonly string[] {
|
|
|
150
386
|
}
|
|
151
387
|
for (const group of groups.values()) {
|
|
152
388
|
const first = group[0] as CatalogFinding
|
|
153
|
-
const keys = group.map((finding) => finding.key as string)
|
|
389
|
+
const keys = group.map((finding) => located(finding.key as string))
|
|
154
390
|
const shown = keys.slice(0, SHOWN_KEYS).join(", ")
|
|
155
391
|
const more = keys.length > SHOWN_KEYS ? `, +${keys.length - SHOWN_KEYS} more` : ""
|
|
156
392
|
lines.push(
|