wuchale 0.22.3 → 0.22.4

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.
@@ -1,4 +1,3 @@
1
- import { type Matcher } from 'picomatch';
2
1
  import { IndexTracker } from '../adapters.js';
3
2
  import { type CompiledElement } from '../compile.js';
4
3
  import { type Catalog, type CatalogStorage, type PluralRules } from '../storage.js';
@@ -11,7 +10,6 @@ export type CompiledCatalogs = Map<string, Compiled>;
11
10
  export declare class SharedState {
12
11
  ownerKey: string;
13
12
  sourceLocale: string;
14
- otherFileMatches: Matcher[];
15
13
  compiled: CompiledCatalogs;
16
14
  indexTracker: IndexTracker;
17
15
  storage: CatalogStorage;
@@ -1,4 +1,3 @@
1
- import {} from 'picomatch';
2
1
  import { getKey, IndexTracker } from '../adapters.js';
3
2
  import {} from '../compile.js';
4
3
  import { defaultPluralRule, fillTranslations } from '../storage.js';
@@ -25,7 +24,6 @@ function validatePluralRule(body) {
25
24
  export class SharedState {
26
25
  ownerKey;
27
26
  sourceLocale;
28
- otherFileMatches = [];
29
27
  compiled = new Map();
30
28
  indexTracker = new IndexTracker();
31
29
  // storage
package/dist/hub.js CHANGED
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import { relative, resolve } from 'node:path';
5
5
  import { watch as watchFS } from 'chokidar';
6
- import {} from 'picomatch';
7
6
  import { glob } from 'tinyglobby';
8
7
  import { compileTranslation, isEquivalent } from './compile.js';
9
8
  import { defaultFS } from './fs.js';
@@ -67,7 +66,7 @@ export class Hub {
67
66
  const handlersByLoaderPath = new Map();
68
67
  for (const [key, adapter] of adaptersData) {
69
68
  const handler = new AdapterHandler(adapter, key, this.#config, this.#mode, this.#fs, this.#projectRoot, this.#log);
70
- await handler.init(this.#getSharedState(adapter, key, handler.sourceLocale, handler.fileMatches));
69
+ await handler.init(this.#getSharedState(adapter, key, handler.sourceLocale));
71
70
  handler.onBeforeSave = () => {
72
71
  this.#lastSourceTriggeredCatalogWrite = performance.now();
73
72
  };
@@ -112,7 +111,7 @@ export class Hub {
112
111
  this.#confUpdateFile = normalizeSep(confUpdateFileAbs);
113
112
  await this.#fs.write(this.#confUpdateFile, '{}'); // only watch changes so prepare first
114
113
  };
115
- #getSharedState = (adapter, key, sourceLocale, fileMatches) => {
114
+ #getSharedState = (adapter, key, sourceLocale) => {
116
115
  const storage = adapter.storage({
117
116
  locales: this.#config.locales,
118
117
  root: this.#projectRoot,
@@ -129,7 +128,6 @@ export class Hub {
129
128
  if (sharedState.sourceLocale !== sourceLocale) {
130
129
  throw new Error(`${logPrefix} Adapters with different source locales (${sharedState.ownerKey} and ${key}) cannot share catalogs.`);
131
130
  }
132
- sharedState.otherFileMatches.push(fileMatches);
133
131
  }
134
132
  return sharedState;
135
133
  };
@@ -215,8 +213,18 @@ export class Hub {
215
213
  const [, updated] = await handler.transform(contents, filename);
216
214
  return updated;
217
215
  };
218
- async #directVisitHandler(handler, clean, sync) {
216
+ async #directVisitHandler(handler, clean, sync, existingFilesByOwner) {
219
217
  const filePaths = await glob(...globConfToArgs(handler.adapter.files, this.#projectRoot, this.#config.localesDir, handler.adapter.outDir));
218
+ let existingFiles = existingFilesByOwner.get(handler.sharedState.ownerKey);
219
+ if (existingFiles) {
220
+ for (const file of filePaths) {
221
+ existingFiles.add(file);
222
+ }
223
+ }
224
+ else {
225
+ existingFiles = new Set(filePaths);
226
+ existingFilesByOwner.set(handler.sharedState.ownerKey, existingFiles);
227
+ }
220
228
  const catalog = handler.sharedState.catalog;
221
229
  let updated = false;
222
230
  if (sync) {
@@ -234,14 +242,14 @@ export class Hub {
234
242
  let cleaned = 0;
235
243
  for (const [key, item] of catalog) {
236
244
  const initRefsN = item.references.length;
237
- item.references = item.references.filter(ref => handler.fileMatches(ref.file) ||
238
- handler.sharedState.otherFileMatches.some(match => match(ref.file)));
239
- if (item.references.length < initRefsN) {
245
+ // check if file deleted or pattern no longer matches
246
+ item.references = item.references.filter(ref => existingFiles.has(ref.file));
247
+ if (itemIsObsolete(item)) {
248
+ catalog.delete(key);
240
249
  updated = true;
241
250
  cleaned++;
242
251
  }
243
- if (itemIsObsolete(item)) {
244
- catalog.delete(key);
252
+ else if (item.references.length < initRefsN) {
245
253
  updated = true;
246
254
  cleaned++;
247
255
  }
@@ -265,9 +273,9 @@ export class Hub {
265
273
  const bOwner = b.sharedState.ownerKey === b.key;
266
274
  return aOwner === bOwner ? 0 : aOwner ? 1 : -1;
267
275
  });
268
- // separate loop to make sure that all otherFileMatchers are collected
276
+ const existingFilesByOwner = new Map();
269
277
  for (const handler of handlers) {
270
- await this.#directVisitHandler(handler, clean, sync);
278
+ await this.#directVisitHandler(handler, clean, sync, existingFilesByOwner);
271
279
  }
272
280
  if (!watch) {
273
281
  this.#log.info('Extraction finished.');
@@ -320,9 +328,10 @@ export class Hub {
320
328
  const errors = [];
321
329
  const syncs = [];
322
330
  let checkedItems = 0;
331
+ const existingFilesByOwner = new Map();
323
332
  for (const handler of this.#handlers.values()) {
324
333
  const state = handler.sharedState;
325
- if (full && (await this.#directVisitHandler(handler, true, false))) {
334
+ if (full && (await this.#directVisitHandler(handler, true, false, existingFilesByOwner))) {
326
335
  syncs.push(handler.key);
327
336
  }
328
337
  if (state.ownerKey !== handler.key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wuchale",
3
- "version": "0.22.3",
3
+ "version": "0.22.4",
4
4
  "description": "Protobuf-like i18n from plain code",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",