wuchale 0.22.2 → 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
  };
@@ -139,7 +137,9 @@ export class Hub {
139
137
  const updateTxt = await read();
140
138
  const update = JSON.parse(updateTxt);
141
139
  this.#log.info(`${logPrefix} config update received: ${color.cyan(updateTxt)}`);
142
- this.#config.hmr = update.hmr;
140
+ if (update.hmr !== undefined) {
141
+ this.#config.hmr = update.hmr;
142
+ }
143
143
  return ignoreChange;
144
144
  }
145
145
  if (!this.#config.hmr) {
@@ -213,8 +213,18 @@ export class Hub {
213
213
  const [, updated] = await handler.transform(contents, filename);
214
214
  return updated;
215
215
  };
216
- async #directVisitHandler(handler, clean, sync) {
216
+ async #directVisitHandler(handler, clean, sync, existingFilesByOwner) {
217
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
+ }
218
228
  const catalog = handler.sharedState.catalog;
219
229
  let updated = false;
220
230
  if (sync) {
@@ -232,14 +242,14 @@ export class Hub {
232
242
  let cleaned = 0;
233
243
  for (const [key, item] of catalog) {
234
244
  const initRefsN = item.references.length;
235
- item.references = item.references.filter(ref => handler.fileMatches(ref.file) ||
236
- handler.sharedState.otherFileMatches.some(match => match(ref.file)));
237
- 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);
238
249
  updated = true;
239
250
  cleaned++;
240
251
  }
241
- if (itemIsObsolete(item)) {
242
- catalog.delete(key);
252
+ else if (item.references.length < initRefsN) {
243
253
  updated = true;
244
254
  cleaned++;
245
255
  }
@@ -263,9 +273,9 @@ export class Hub {
263
273
  const bOwner = b.sharedState.ownerKey === b.key;
264
274
  return aOwner === bOwner ? 0 : aOwner ? 1 : -1;
265
275
  });
266
- // separate loop to make sure that all otherFileMatchers are collected
276
+ const existingFilesByOwner = new Map();
267
277
  for (const handler of handlers) {
268
- await this.#directVisitHandler(handler, clean, sync);
278
+ await this.#directVisitHandler(handler, clean, sync, existingFilesByOwner);
269
279
  }
270
280
  if (!watch) {
271
281
  this.#log.info('Extraction finished.');
@@ -318,9 +328,10 @@ export class Hub {
318
328
  const errors = [];
319
329
  const syncs = [];
320
330
  let checkedItems = 0;
331
+ const existingFilesByOwner = new Map();
321
332
  for (const handler of this.#handlers.values()) {
322
333
  const state = handler.sharedState;
323
- if (full && (await this.#directVisitHandler(handler, true, false))) {
334
+ if (full && (await this.#directVisitHandler(handler, true, false, existingFilesByOwner))) {
324
335
  syncs.push(handler.key);
325
336
  }
326
337
  if (state.ownerKey !== handler.key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wuchale",
3
- "version": "0.22.2",
3
+ "version": "0.22.4",
4
4
  "description": "Protobuf-like i18n from plain code",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -89,7 +89,7 @@
89
89
  "chokidar": "^5.0.0",
90
90
  "magic-string": "^0.30.21",
91
91
  "path-to-regexp": "^8.3.0",
92
- "picomatch": "^4.0.3",
92
+ "picomatch": "^4.0.4",
93
93
  "pofile": "^1.1.4",
94
94
  "tinyglobby": "^0.2.15"
95
95
  },