@dialexjs/cli 0.6.0 → 0.7.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/dist/api.d.mts CHANGED
@@ -120,6 +120,35 @@ interface AnalysisConfig {
120
120
  defaultLocale?: string;
121
121
  locales?: string[];
122
122
  include?: string | string[];
123
+ exclude?: string[];
124
+ }
125
+ /**
126
+ * Remembers parsed dictionaries and scanned source files between `analyzeProject` calls, keyed by
127
+ * modification time and size, so a long-lived caller (the editor extension) only re-reads what
128
+ * changed. Create one with {@link createAnalysisCache}; one-shot callers do not need it.
129
+ */
130
+ interface AnalysisCache {
131
+ dictionaries: Map<string, {
132
+ stamp: string;
133
+ loaded: Loaded;
134
+ }>;
135
+ sources: Map<string, {
136
+ stamp: string;
137
+ scan: SourceScan;
138
+ }>;
139
+ /** The `.gitignore` filter, reused until {@link clearGitignore} is called. */
140
+ gitignore: Map<string, (absolutePath: string) => boolean>;
141
+ }
142
+ export declare function createAnalysisCache(): AnalysisCache;
143
+ /** Forget the cached `.gitignore` rules, for example after a `.gitignore` file changed. */
144
+ export declare function clearGitignore(cache: AnalysisCache): void;
145
+ interface SourceScan {
146
+ /** Distinct word-like tokens, for the unused-key heuristic. */
147
+ tokens: string[];
148
+ refs: {
149
+ ref: Reference;
150
+ range: SourceRange;
151
+ }[];
123
152
  }
124
153
  interface AnalysisOptions {
125
154
  root: string;
@@ -134,6 +163,8 @@ interface AnalysisOptions {
134
163
  unused?: boolean;
135
164
  /** Report translations whose source text changed since `dialex.lock.json` recorded them. @default true */
136
165
  lock?: boolean;
166
+ /** Reuse work between calls. Ignored when `runtime` is set, because that evaluates code. */
167
+ cache?: AnalysisCache;
137
168
  }
138
169
  interface LeafInfo {
139
170
  kind: "string" | "function" | "other";
@@ -170,10 +201,51 @@ interface Reference {
170
201
  }
171
202
  /** Finds `getDictionary("x")`-style and `t("x.y.z")` references in source text. */
172
203
  export declare function scanReferences(text: string): Reference[];
204
+ interface DictionaryData {
205
+ name: string;
206
+ locales: string[];
207
+ leaves: Map<string, Map<string, LeafInfo>>;
208
+ df?: DictionaryFile;
209
+ }
210
+ type Loaded = {
211
+ ok: true;
212
+ data: DictionaryData;
213
+ } | {
214
+ ok: false;
215
+ level: IssueLevel;
216
+ code: IssueCode;
217
+ message: string;
218
+ };
173
219
  export declare function analyzeProject(options: AnalysisOptions): Promise<AnalysisResult>;
174
220
  /** Project root-relative path with forward slashes, for display. */
175
221
  export declare function relativeFile(root: string, file: string): string;
176
222
  //#endregion
223
+ //#region src/utils/files.d.ts
224
+ /** Folders that never hold project dictionaries or sources, in every scanner. */
225
+ export declare const BUILTIN_IGNORE: string[];
226
+ /** What the source scan skips on top: other tools' output, declarations, generated and config files. */
227
+ export declare const SOURCE_BUILTIN_IGNORE: string[];
228
+ /**
229
+ * A function that says whether an absolute path is ignored by Git. It reads the `.gitignore`
230
+ * files of the project folder, of every folder above it up to the repository root (monorepo
231
+ * packages inherit the root's rules), and of nested folders.
232
+ */
233
+ export declare function createGitignoreFilter(root: string): (absolutePath: string) => boolean;
234
+ interface ScanOptions {
235
+ /** Which built-in ignore list applies. @default "dictionary" */
236
+ kind?: "dictionary" | "source";
237
+ /** `exclude` from the config: extra globs, relative to `root`. */
238
+ exclude?: string[];
239
+ /** More ignore globs, relative to `root` (nested projects, for example). */
240
+ ignore?: string[];
241
+ /** Skip what `.gitignore` files ignore. @default true */
242
+ gitignore?: boolean;
243
+ /** A filter from {@link createGitignoreFilter} to reuse instead of reading `.gitignore` again. */
244
+ gitignoreFilter?: (absolutePath: string) => boolean;
245
+ }
246
+ /** Finds files under `root`, skipping build output, configured excludes and Git-ignored paths. */
247
+ export declare function scanFiles(root: string, patterns: string | string[], options?: ScanOptions): string[];
248
+ //#endregion
177
249
  //#region src/utils/lockfile.d.ts
178
250
  export declare const LOCK_FILE = "dialex.lock.json";
179
251
  /**
@@ -214,6 +286,7 @@ interface StaticConfig {
214
286
  defaultLocale: string;
215
287
  locales: string[];
216
288
  include: string | string[];
289
+ exclude: string[];
217
290
  fallbacks: Record<string, string[]>;
218
291
  prefixDefault: boolean;
219
292
  lazy: boolean | "locale";
@@ -307,6 +380,14 @@ export declare function generateDictionaries(root: string, options?: GenerateOpt
307
380
  configFile?: string;
308
381
  notes: string[];
309
382
  };
383
+ /**
384
+ * Regenerates when a dictionary or config file is added, edited or removed. chokidar 4+ no longer
385
+ * understands globs, so this watches the project directory and decides for itself which events
386
+ * matter, using the same `include` glob as `generate`.
387
+ */
388
+ export declare function startGenerateWatcher(root: string, options: GenerateOptions, regenerate: () => void, delay?: number,
389
+ /** Where to report what triggered a regeneration. Defaults to the CLI logger (stdout). */
390
+ log?: (message: string) => void): import("chokidar").FSWatcher;
310
391
  //#endregion
311
- export type { AnalysisConfig, AnalysisIssue, AnalysisOptions, AnalysisResult, AnalyzedDictionary, DictionaryFile, GenerateOptions, IssueCode, IssueLevel, Leaf, LeafInfo, LeafKind, Lockfile, Project, ProjectDictionary, Reference, RenderedGenerate, SourceRange, StaticConfig, StaticConfigResult };
392
+ export type { AnalysisCache, AnalysisConfig, AnalysisIssue, AnalysisOptions, AnalysisResult, AnalyzedDictionary, DictionaryFile, GenerateOptions, IssueCode, IssueLevel, Leaf, LeafInfo, LeafKind, Lockfile, Project, ProjectDictionary, Reference, RenderedGenerate, ScanOptions, SourceRange, StaticConfig, StaticConfigResult };
312
393
  //# sourceMappingURL=api.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.mts","names":[],"sources":["../src/utils/dictionary-edit.ts","../src/analysis.ts","../src/utils/lockfile.ts","../src/utils/static-config.ts","../src/utils/project.ts","../src/commands/generate.ts"],"mappings":";;;;;;;;;;;;;;;KAiBK;EAAS;GAAe;;qBAEhB;UAII;EACf;;EAEA;EACA,KAAK,QAAQ,kBAAkB;;EAE/B,YAAY;;EAEZ;;;;;;EAMA;;;UAIe;EACf;IAAS;IAAc;;EACvB;IAAO;IAAc;;;KAGX;UAEK;EACf;EACA,MAA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4B;;wBA8C5D,iBAAiB,cAAc,sBAAsB;;;UC5JpD;;EAEf;EACA;EACA,IAAI;;UAGW;EACf;EACA,QAAQ;EACR,cAAc;;EAEd;;EAEA;;;;;;wBAgCoB,YAAY,cAAc,sBAAsB,QAAQ;;;;;wBASxD,kBAAkB,cAAc,sBAAsB,QAAQ;;qBAMvE,QAAK,oBAAsB;;;UCvDvB;EACf;EACA;EACA;EACA;EACA;;;;;EAKA;;UAUe;;EAEf;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA;IAAc;IAAc;;;EAE5B;;;;;;;;;wBAcc,gBAAgB,cAAc,UAAS,kBAAuB;wBA8J9D,qBACd,cACA,UAAS;EAET;EACA;EACA;EACA;EACA"}
1
+ {"version":3,"file":"api.d.mts","names":[],"sources":["../src/utils/dictionary-edit.ts","../src/analysis.ts","../src/utils/files.ts","../src/utils/lockfile.ts","../src/utils/static-config.ts","../src/utils/project.ts","../src/commands/generate.ts"],"mappings":";;;;;;;;;;;;;;;KAiBK;EAAS;GAAe;;qBAEhB;UAII;EACf;;EAEA;EACA,KAAK,QAAQ,kBAAkB;;EAE/B,YAAY;;EAEZ;;;;;;EAMA;;;UAIe;EACf;IAAS;IAAc;;EACvB;IAAO;IAAc;;;KAGX;UAEK;EACf;EACA,MAAM;;EAEN;;;;;;wBAgIc,oBAAoB,cAAc,eAAe;;wBAoB3C,mBAAmB,eAAe,QAAQ;;wBAKhD,qBAAqB,IAAI;wBAKnB,mBAAmB,IAAI,iBAAiB;wBAQ9C,YAAY,IAAI;;wBAahB,WAAW,IAAI,gBAAgB,iBAAiB;wBAoChD,QAAQ,IAAI,gBAAgB,gBAAgB;wBAI5C,UAAU,IAAI,gBAAgB,gBAAgB;KA+BlD;;;;;wBAMI,UACd,IAAI,gBACJ,gBACA,gBACA,gBACC;;;;;;wBAsBa,SACd,IAAI,gBACJ,oBACA,kBACA,gBACA,aAAa;;;;;wBAwCC,WACd,IAAI,gBACJ,gBACA,kBACC;;wBAMa,mBAA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kBAAkB,cAAc,gBAA4B;;wBA+C5D,iBAAiB,cAAc,sBAAsB;;;UChKpD;;EAEf;EACA;EACA,IAAI;;UAGW;EACf;EACA,QAAQ;EACR,cAAc;;EAEd;;EAEA;;;;;;wBA4BoB,YAAY,cAAc,sBAAsB,QAAQ;;;;;wBASxD,kBAAkB,cAAc,sBAAsB,QAAQ;;qBAMvE,QAAK,oBAAsB;;;UCnDvB;EACf;EACA;EACA;EACA;EACA;;;;;EAKA;;UAGe;;EAEf;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA;IAAc;IAAc;;;EAE5B;;;;;;;;;wBAcc,gBAAgB,cAAc,UAAS,kBAAuB;wBA8J9D,qBACd,cACA,UAAS;EAET;EACA;EACA;EACA;EACA;;;;;;;wBAmGc,qBACd,cACA,SAAS,iBACT,wBACA,gBAEA;;AAAA,OAAM,8CAA4D"}
package/dist/api.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { A as listLeaves, C as writeLock, D as getLeafSource, E as dictionaryLocation, F as renderDictionaryFile, I as saveDictionaryFile, L as setString, M as loadDictionaryFile, N as locationOf, O as getString, P as parseDictionaryText, T as copyLeaf, _ as hashSource, a as renderGenerated, c as parseStaticConfig, f as DEFAULT_SOURCE_GLOB, g as LOCK_FILE, h as scanReferences, i as generateDictionaries, j as listLocales, k as hasPath, l as readStaticConfig, m as relativeFile, n as loadStaticProject, p as analyzeProject, r as toKey, s as DEFAULT_STATIC_CONFIG, t as loadProject, v as isStale, w as TODO_PREFIX, x as readLock } from "./project-DquSNdz8.mjs";
2
- export { DEFAULT_SOURCE_GLOB, DEFAULT_STATIC_CONFIG, LOCK_FILE, TODO_PREFIX, analyzeProject, copyLeaf, dictionaryLocation, generateDictionaries, getLeafSource, getString, hasPath, hashSource, isStale, listLeaves, listLocales, loadDictionaryFile, loadProject, loadStaticProject, locationOf, parseDictionaryText, parseStaticConfig, readLock, readStaticConfig, relativeFile, renderDictionaryFile, renderGenerated, saveDictionaryFile, scanReferences, setString, toKey, writeLock };
1
+ import { A as scanFiles, B as locationOf, D as BUILTIN_IGNORE, E as writeLock, F as getString, H as renderDictionaryFile, I as hasPath, L as listLeaves, M as copyLeaf, N as dictionaryLocation, O as SOURCE_BUILTIN_IGNORE, P as getLeafSource, R as listLocales, U as saveDictionaryFile, V as parseDictionaryText, W as setString, _ as relativeFile, a as renderGenerated, b as hashSource, c as DEFAULT_STATIC_CONFIG, g as createAnalysisCache, h as clearGitignore, i as generateDictionaries, j as TODO_PREFIX, k as createGitignoreFilter, l as parseStaticConfig, m as analyzeProject, n as loadStaticProject, p as DEFAULT_SOURCE_GLOB, r as toKey, s as startGenerateWatcher, t as loadProject, u as readStaticConfig, v as scanReferences, w as readLock, x as isStale, y as LOCK_FILE, z as loadDictionaryFile } from "./project-Dz0FbydQ.mjs";
2
+ export { BUILTIN_IGNORE, DEFAULT_SOURCE_GLOB, DEFAULT_STATIC_CONFIG, LOCK_FILE, SOURCE_BUILTIN_IGNORE, TODO_PREFIX, analyzeProject, clearGitignore, copyLeaf, createAnalysisCache, createGitignoreFilter, dictionaryLocation, generateDictionaries, getLeafSource, getString, hasPath, hashSource, isStale, listLeaves, listLocales, loadDictionaryFile, loadProject, loadStaticProject, locationOf, parseDictionaryText, parseStaticConfig, readLock, readStaticConfig, relativeFile, renderDictionaryFile, renderGenerated, saveDictionaryFile, scanFiles, scanReferences, setString, startGenerateWatcher, toKey, writeLock };
package/dist/index.mjs CHANGED
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { A as listLeaves, C as writeLock, I as saveDictionaryFile, L as setString, M as loadDictionaryFile, O as getString, S as record, T as copyLeaf, a as renderGenerated, b as lockPath, d as logger, g as LOCK_FILE, i as generateDictionaries, j as listLocales, k as hasPath, o as runGenerate, p as analyzeProject, r as toKey, t as loadProject, u as resolveDialexConfig, v as isStale, w as TODO_PREFIX, x as readLock, y as lockFor } from "./project-DquSNdz8.mjs";
2
+ import { A as scanFiles, C as lockPath, E as writeLock, F as getString, I as hasPath, L as listLeaves, M as copyLeaf, R as listLocales, S as lockFor, T as record, U as saveDictionaryFile, W as setString, a as renderGenerated, d as resolveDialexConfig, f as logger, i as generateDictionaries, j as TODO_PREFIX, m as analyzeProject, o as runGenerate, r as toKey, t as loadProject, w as readLock, x as isStale, y as LOCK_FILE, z as loadDictionaryFile } from "./project-Dz0FbydQ.mjs";
3
3
  import { Command } from "commander";
4
4
  import fs from "node:fs";
5
5
  import path from "node:path";
6
- import fg from "fast-glob";
7
6
  import pc from "picocolors";
8
7
  import { fileURLToPath } from "node:url";
9
8
  import { loadFile, parseModule, writeFile } from "magicast";
@@ -11,15 +10,9 @@ import { argumentSignature, getArguments, isIcuStructured, parseMessage } from "
11
10
  import * as p from "@clack/prompts";
12
11
  import { addNuxtModule } from "magicast/helpers";
13
12
  //#region package.json
14
- var version = "0.6.0";
13
+ var version = "0.7.1";
15
14
  //#endregion
16
15
  //#region src/commands/check.ts
17
- const DICTIONARY_IGNORE = [
18
- "**/node_modules/**",
19
- "**/dist/**",
20
- "**/.next/**",
21
- "**/dialex.locales/**"
22
- ];
23
16
  function addIssue(diag, issue) {
24
17
  const level = issue.level === "error" ? "error" : "warning";
25
18
  (level === "error" ? diag.errors : diag.warnings).push(issue.message);
@@ -123,11 +116,7 @@ async function runCheck(options = {}) {
123
116
  const include = config.include || "**/*.content.ts";
124
117
  const configuredLocales = config.locales || [];
125
118
  const defaultLocale = config.defaultLocale || "en";
126
- const files = fg.sync(include, {
127
- cwd: root,
128
- absolute: true,
129
- ignore: DICTIONARY_IGNORE
130
- });
119
+ const files = scanFiles(root, include, { exclude: config.exclude });
131
120
  if (files.length === 0) {
132
121
  if (!quiet) {
133
122
  const patternStr = Array.isArray(include) ? include.join(", ") : include;