wuchale 0.22.3 → 0.22.5
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/ai/index.js +4 -3
- package/dist/handler/files.js +1 -1
- package/dist/handler/index.js +1 -1
- package/dist/handler/state.d.ts +0 -2
- package/dist/handler/state.js +0 -2
- package/dist/hub.js +28 -20
- package/dist/pofile.js +4 -2
- package/dist/storage.d.ts +2 -0
- package/package.json +1 -1
package/dist/ai/index.js
CHANGED
|
@@ -67,11 +67,12 @@ export default class AIQueue {
|
|
|
67
67
|
const logStart = this.#requestName(batch.id, batch.targetLocales);
|
|
68
68
|
let translated = [];
|
|
69
69
|
try {
|
|
70
|
-
const
|
|
71
|
-
id: item.
|
|
70
|
+
const inputItems = batch.messages.map(item => ({
|
|
71
|
+
id: item.translations.get(this.sourceLocale),
|
|
72
72
|
context: item.context,
|
|
73
73
|
references: item.references,
|
|
74
|
-
}))
|
|
74
|
+
}));
|
|
75
|
+
const translatedstr = await this.ai.translate(JSON.stringify(inputItems), instruct(this.sourceLocale, batch.targetLocales));
|
|
75
76
|
translated = JSON.parse(translatedstr);
|
|
76
77
|
if (Array.isArray(translated)) {
|
|
77
78
|
translated = translated.slice(0, batch.messages.length); // may return more
|
package/dist/handler/files.js
CHANGED
|
@@ -226,7 +226,7 @@ export class Files {
|
|
|
226
226
|
return resolve(this.#localesDirAbs, generatedDir, `${ownerKey}.${id ?? ownerKey}.manifest.js`);
|
|
227
227
|
}
|
|
228
228
|
writeManifest = async (keys, id) => {
|
|
229
|
-
const content = `/** @type {(string | {text: string | string[], context?: string, isUrl?: boolean}
|
|
229
|
+
const content = `/** @type {(string | string[] | {text: string | string[], context?: string, isUrl?: boolean})[]} */\n` +
|
|
230
230
|
`export const keys = ${JSON.stringify(keys)}`;
|
|
231
231
|
await this.#fs.write(this.getManifestFilePath(id), content);
|
|
232
232
|
};
|
package/dist/handler/index.js
CHANGED
|
@@ -101,7 +101,7 @@ export class AdapterHandler {
|
|
|
101
101
|
const isUrl = itemIsUrl(item);
|
|
102
102
|
const id = item.translations.get(this.sourceLocale);
|
|
103
103
|
const text = id.length === 1 ? id[0] : id;
|
|
104
|
-
if (!isUrl && item.context
|
|
104
|
+
if (!isUrl && item.context == null) {
|
|
105
105
|
manifest[index] = text;
|
|
106
106
|
continue;
|
|
107
107
|
}
|
package/dist/handler/state.d.ts
CHANGED
|
@@ -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;
|
package/dist/handler/state.js
CHANGED
|
@@ -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
|
|
69
|
+
await handler.init(this.#getSharedState(adapter, key, handler.sourceLocale));
|
|
71
70
|
handler.onBeforeSave = () => {
|
|
72
71
|
this.#lastSourceTriggeredCatalogWrite = performance.now();
|
|
73
72
|
};
|
|
@@ -112,10 +111,11 @@ 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
|
|
114
|
+
#getSharedState = (adapter, key, sourceLocale) => {
|
|
116
115
|
const storage = adapter.storage({
|
|
117
116
|
locales: this.#config.locales,
|
|
118
117
|
root: this.#projectRoot,
|
|
118
|
+
localesDir: this.#config.localesDir,
|
|
119
119
|
sourceLocale: sourceLocale,
|
|
120
120
|
haveUrl: adapter.url != null,
|
|
121
121
|
fs: this.#fs,
|
|
@@ -129,7 +129,6 @@ export class Hub {
|
|
|
129
129
|
if (sharedState.sourceLocale !== sourceLocale) {
|
|
130
130
|
throw new Error(`${logPrefix} Adapters with different source locales (${sharedState.ownerKey} and ${key}) cannot share catalogs.`);
|
|
131
131
|
}
|
|
132
|
-
sharedState.otherFileMatches.push(fileMatches);
|
|
133
132
|
}
|
|
134
133
|
return sharedState;
|
|
135
134
|
};
|
|
@@ -215,8 +214,18 @@ export class Hub {
|
|
|
215
214
|
const [, updated] = await handler.transform(contents, filename);
|
|
216
215
|
return updated;
|
|
217
216
|
};
|
|
218
|
-
async #directVisitHandler(handler, clean, sync) {
|
|
217
|
+
async #directVisitHandler(handler, clean, sync, existingFilesByOwner) {
|
|
219
218
|
const filePaths = await glob(...globConfToArgs(handler.adapter.files, this.#projectRoot, this.#config.localesDir, handler.adapter.outDir));
|
|
219
|
+
let existingFiles = existingFilesByOwner.get(handler.sharedState.ownerKey);
|
|
220
|
+
if (existingFiles) {
|
|
221
|
+
for (const file of filePaths) {
|
|
222
|
+
existingFiles.add(file);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
existingFiles = new Set(filePaths);
|
|
227
|
+
existingFilesByOwner.set(handler.sharedState.ownerKey, existingFiles);
|
|
228
|
+
}
|
|
220
229
|
const catalog = handler.sharedState.catalog;
|
|
221
230
|
let updated = false;
|
|
222
231
|
if (sync) {
|
|
@@ -228,26 +237,24 @@ export class Hub {
|
|
|
228
237
|
updated ||= (await Promise.all(filePaths.map(f => this.#visitFileHandl(f, handler)))).some(r => r);
|
|
229
238
|
}
|
|
230
239
|
// only owner adapter should clean
|
|
231
|
-
if (
|
|
232
|
-
const logPrefix = logPrefixHandler(handler.key);
|
|
233
|
-
this.#log.info(`${logPrefix} Cleaning...`);
|
|
240
|
+
if (handler.sharedState.ownerKey === handler.key) {
|
|
234
241
|
let cleaned = 0;
|
|
235
242
|
for (const [key, item] of catalog) {
|
|
236
243
|
const initRefsN = item.references.length;
|
|
237
|
-
|
|
238
|
-
|
|
244
|
+
// check if file deleted or pattern no longer matches
|
|
245
|
+
item.references = item.references.filter(ref => existingFiles.has(ref.file));
|
|
239
246
|
if (item.references.length < initRefsN) {
|
|
240
247
|
updated = true;
|
|
241
|
-
cleaned++;
|
|
242
248
|
}
|
|
243
|
-
if (itemIsObsolete(item)) {
|
|
244
|
-
|
|
245
|
-
updated = true;
|
|
246
|
-
cleaned++;
|
|
249
|
+
if (!clean || !itemIsObsolete(item)) {
|
|
250
|
+
continue;
|
|
247
251
|
}
|
|
252
|
+
catalog.delete(key);
|
|
253
|
+
updated = true;
|
|
254
|
+
cleaned++;
|
|
248
255
|
}
|
|
249
|
-
if (cleaned) {
|
|
250
|
-
this.#log.info(`${
|
|
256
|
+
if (cleaned > 0) {
|
|
257
|
+
this.#log.info(`${logPrefixHandler(handler.key)} Cleaned ${cleaned} items`);
|
|
251
258
|
}
|
|
252
259
|
}
|
|
253
260
|
if (updated) {
|
|
@@ -265,9 +272,9 @@ export class Hub {
|
|
|
265
272
|
const bOwner = b.sharedState.ownerKey === b.key;
|
|
266
273
|
return aOwner === bOwner ? 0 : aOwner ? 1 : -1;
|
|
267
274
|
});
|
|
268
|
-
|
|
275
|
+
const existingFilesByOwner = new Map();
|
|
269
276
|
for (const handler of handlers) {
|
|
270
|
-
await this.#directVisitHandler(handler, clean, sync);
|
|
277
|
+
await this.#directVisitHandler(handler, clean, sync, existingFilesByOwner);
|
|
271
278
|
}
|
|
272
279
|
if (!watch) {
|
|
273
280
|
this.#log.info('Extraction finished.');
|
|
@@ -320,9 +327,10 @@ export class Hub {
|
|
|
320
327
|
const errors = [];
|
|
321
328
|
const syncs = [];
|
|
322
329
|
let checkedItems = 0;
|
|
330
|
+
const existingFilesByOwner = new Map();
|
|
323
331
|
for (const handler of this.#handlers.values()) {
|
|
324
332
|
const state = handler.sharedState;
|
|
325
|
-
if (full && (await this.#directVisitHandler(handler, true, false))) {
|
|
333
|
+
if (full && (await this.#directVisitHandler(handler, true, false, existingFilesByOwner))) {
|
|
326
334
|
syncs.push(handler.key);
|
|
327
335
|
}
|
|
328
336
|
if (state.ownerKey !== handler.key) {
|
package/dist/pofile.js
CHANGED
|
@@ -230,6 +230,8 @@ export class POFile {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
export function pofile(pofOpts = {}) {
|
|
233
|
-
|
|
234
|
-
|
|
233
|
+
return opts => new POFile({
|
|
234
|
+
...opts,
|
|
235
|
+
...deepMergeObjects(pofOpts, { ...defaultOpts, dir: opts.localesDir }),
|
|
236
|
+
});
|
|
235
237
|
}
|
package/dist/storage.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export type Catalog = Map<string, Item>;
|
|
|
52
52
|
export type StorageFactoryOpts = {
|
|
53
53
|
locales: string[];
|
|
54
54
|
root: string;
|
|
55
|
+
/** shared locale artifacts directory from the top-level config */
|
|
56
|
+
localesDir: string;
|
|
55
57
|
/** whether the url is configured, can use to load separate url files */
|
|
56
58
|
haveUrl: boolean;
|
|
57
59
|
sourceLocale: string;
|