wuchale 0.19.1 → 0.19.2
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/adapter-vanilla/index.js +2 -2
- package/dist/adapter-vanilla/transformer.js +11 -6
- package/dist/adapters.js +5 -5
- package/dist/cli/extract.js +1 -1
- package/dist/cli/status.js +1 -1
- package/dist/compile.js +1 -1
- package/dist/config.js +2 -2
- package/dist/handler.js +12 -12
- package/dist/load-utils/index.js +3 -3
- package/dist/load-utils/pure.js +1 -1
- package/dist/runtime.js +1 -1
- package/package.json +1 -1
- package/src/adapter-vanilla/loaders/bundle.js +1 -1
|
@@ -8,6 +8,11 @@ export const scriptParseOptions = {
|
|
|
8
8
|
sourceType: 'module',
|
|
9
9
|
ecmaVersion: 'latest',
|
|
10
10
|
locations: true,
|
|
11
|
+
// relaxed because checking correctness is not the focus here
|
|
12
|
+
allowReturnOutsideFunction: true,
|
|
13
|
+
allowAwaitOutsideFunction: true,
|
|
14
|
+
allowSuperOutsideMethod: true,
|
|
15
|
+
allowImportExportEverywhere: true,
|
|
11
16
|
};
|
|
12
17
|
const ScriptParser = Parser.extend(tsPlugin());
|
|
13
18
|
export function scriptParseOptionsWithComments() {
|
|
@@ -17,7 +22,7 @@ export function scriptParseOptionsWithComments() {
|
|
|
17
22
|
{
|
|
18
23
|
...scriptParseOptions,
|
|
19
24
|
// parse comments for when they are not part of the AST
|
|
20
|
-
onToken:
|
|
25
|
+
onToken: token => {
|
|
21
26
|
if (accumulateComments.length) {
|
|
22
27
|
comments[token.start] = accumulateComments;
|
|
23
28
|
}
|
|
@@ -158,7 +163,7 @@ export class Transformer {
|
|
|
158
163
|
this.mstr.update(start, end, `${this.vars().rtTrans}(${this.index.get(msgInfo.toKey())})`);
|
|
159
164
|
return [msgInfo];
|
|
160
165
|
};
|
|
161
|
-
visitArrayExpression = (node) => node.elements.flatMap(
|
|
166
|
+
visitArrayExpression = (node) => node.elements.flatMap(elm => (elm ? this.visit(elm) : []));
|
|
162
167
|
visitSequenceExpression = (node) => node.expressions.flatMap(this.visit);
|
|
163
168
|
visitObjectExpression = (node) => node.properties.flatMap(this.visit);
|
|
164
169
|
visitObjectPattern = (node) => node.properties.flatMap(this.visit);
|
|
@@ -194,7 +199,7 @@ export class Transformer {
|
|
|
194
199
|
return this.defaultVisitCallExpression(node);
|
|
195
200
|
}
|
|
196
201
|
const calleeName = node.callee.name;
|
|
197
|
-
const pattern = this.patterns.find(
|
|
202
|
+
const pattern = this.patterns.find(p => p.name === calleeName);
|
|
198
203
|
if (!pattern) {
|
|
199
204
|
return this.defaultVisitCallExpression(node);
|
|
200
205
|
}
|
|
@@ -410,7 +415,7 @@ export class Transformer {
|
|
|
410
415
|
if (this.mstr.toString() !== currentContent ||
|
|
411
416
|
(bod.type === 'IfStatement' &&
|
|
412
417
|
bod.consequent.type === 'BlockStatement' &&
|
|
413
|
-
bod.consequent.body.some(
|
|
418
|
+
bod.consequent.body.some(n => n.type === 'ReturnStatement'))) {
|
|
414
419
|
bodyStart = bod.start;
|
|
415
420
|
}
|
|
416
421
|
}
|
|
@@ -591,7 +596,7 @@ export class Transformer {
|
|
|
591
596
|
this.heuristciDetails.call = prevCall;
|
|
592
597
|
return msgs;
|
|
593
598
|
};
|
|
594
|
-
visitSwitchStatement = (node) => node.cases.flatMap(
|
|
599
|
+
visitSwitchStatement = (node) => node.cases.flatMap(c => c.consequent.map(this.visit)).flat();
|
|
595
600
|
visitTryStatement = (node) => {
|
|
596
601
|
const msgs = this.visit(node.block);
|
|
597
602
|
if (node.handler) {
|
|
@@ -642,7 +647,7 @@ export class Transformer {
|
|
|
642
647
|
});
|
|
643
648
|
finalize = (msgs, hmrHeaderIndex, additionalHeader = '') => ({
|
|
644
649
|
msgs,
|
|
645
|
-
output:
|
|
650
|
+
output: header => {
|
|
646
651
|
this.mstr.prependRight(hmrHeaderIndex, `\n${header}\n${additionalHeader}\n`);
|
|
647
652
|
return {
|
|
648
653
|
code: this.mstr.toString(),
|
package/dist/adapters.js
CHANGED
|
@@ -11,11 +11,11 @@ export class Message {
|
|
|
11
11
|
this.msgStr = [msgStr];
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
|
-
this.msgStr = msgStr.filter(
|
|
14
|
+
this.msgStr = msgStr.filter(str => str != null);
|
|
15
15
|
}
|
|
16
|
-
this.msgStr = this.msgStr.map(
|
|
16
|
+
this.msgStr = this.msgStr.map(msg => msg
|
|
17
17
|
.split('\n')
|
|
18
|
-
.map(
|
|
18
|
+
.map(line => line.trim())
|
|
19
19
|
.join('\n'));
|
|
20
20
|
this.details = heuristicDetails;
|
|
21
21
|
this.context = context;
|
|
@@ -30,7 +30,7 @@ export const defaultHeuristicOpts = {
|
|
|
30
30
|
urlCalls: [],
|
|
31
31
|
};
|
|
32
32
|
export function createHeuristic(opts) {
|
|
33
|
-
return
|
|
33
|
+
return msg => {
|
|
34
34
|
if (msg.details.element && opts.ignoreElements.includes(msg.details.element)) {
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
@@ -89,7 +89,7 @@ export function createHeuristic(opts) {
|
|
|
89
89
|
/** Default heuristic */
|
|
90
90
|
export const defaultHeuristic = createHeuristic(defaultHeuristicOpts);
|
|
91
91
|
/** Default heuristic which ignores messages outside functions in the `script` scope */
|
|
92
|
-
export const defaultHeuristicFuncOnly =
|
|
92
|
+
export const defaultHeuristicFuncOnly = msg => {
|
|
93
93
|
if (defaultHeuristic(msg) && (msg.details.scope !== 'script' || msg.details.funcName != null)) {
|
|
94
94
|
return 'message';
|
|
95
95
|
}
|
package/dist/cli/extract.js
CHANGED
|
@@ -30,7 +30,7 @@ export async function extract(config, clean, watch, sync) {
|
|
|
30
30
|
}
|
|
31
31
|
// watch
|
|
32
32
|
logger.info('Watching for changes');
|
|
33
|
-
const handlersWithExtr = handlers.map(
|
|
33
|
+
const handlersWithExtr = handlers.map(h => [h.fileMatches, extractor(h, logger)]);
|
|
34
34
|
watchFS('.', { ignoreInitial: true }).on('all', async (event, filename) => {
|
|
35
35
|
if (!['add', 'change'].includes(event)) {
|
|
36
36
|
return;
|
package/dist/cli/status.js
CHANGED
|
@@ -17,7 +17,7 @@ async function statPO(filename) {
|
|
|
17
17
|
}
|
|
18
18
|
export async function status(config, locales) {
|
|
19
19
|
// console.log because if the user invokes this command, they want full info regardless of config
|
|
20
|
-
console.log(`Locales: ${locales.map(
|
|
20
|
+
console.log(`Locales: ${locales.map(l => color.cyan(`${l} (${getLanguageName(l)})`)).join(', ')}`);
|
|
21
21
|
for (const [key, adapter] of Object.entries(config.adapters)) {
|
|
22
22
|
const handler = new AdapterHandler(adapter, key, config, 'cli', process.cwd(), new Logger(config.logLevel));
|
|
23
23
|
const loaderPath = await handler.getLoaderPath();
|
package/dist/compile.js
CHANGED
|
@@ -2,7 +2,7 @@ const OPEN = Symbol();
|
|
|
2
2
|
const CLOSE = Symbol();
|
|
3
3
|
const SELF_CLOSE = Symbol();
|
|
4
4
|
const PLACEHOLDER = Symbol();
|
|
5
|
-
const digitRange = ['0', '9'].map(
|
|
5
|
+
const digitRange = ['0', '9'].map(d => d.charCodeAt(0));
|
|
6
6
|
function extractSpecial(msgStr, start) {
|
|
7
7
|
const inPlaceHolder = msgStr[start] === '{';
|
|
8
8
|
const inTag = msgStr[start] === '<';
|
package/dist/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
2
|
import { defaultGemini } from './ai/gemini.js';
|
|
3
3
|
export const defaultConfig = {
|
|
4
|
-
locales: [],
|
|
4
|
+
locales: ['en'],
|
|
5
5
|
adapters: {},
|
|
6
6
|
hmr: true,
|
|
7
7
|
ai: defaultGemini,
|
|
@@ -31,7 +31,7 @@ export function deepMergeObjects(source, target) {
|
|
|
31
31
|
deepAssign(source, full);
|
|
32
32
|
return full;
|
|
33
33
|
}
|
|
34
|
-
export const defaultConfigNames = ['js', 'mjs', 'ts', 'mts'].map(
|
|
34
|
+
export const defaultConfigNames = ['js', 'mjs', 'ts', 'mts'].map(ext => `wuchale.config.${ext}`);
|
|
35
35
|
const displayName = new Intl.DisplayNames(['en'], { type: 'language' });
|
|
36
36
|
export const getLanguageName = (code) => displayName.of(code) ?? code;
|
|
37
37
|
export function checkValidLocale(locale) {
|
package/dist/handler.js
CHANGED
|
@@ -74,7 +74,7 @@ async function saveCatalogToPO(catalog, filename, headers = {}) {
|
|
|
74
74
|
po.items.push(item);
|
|
75
75
|
}
|
|
76
76
|
return new Promise((res, rej) => {
|
|
77
|
-
po.save(filename,
|
|
77
|
+
po.save(filename, err => {
|
|
78
78
|
if (err) {
|
|
79
79
|
rej(err);
|
|
80
80
|
}
|
|
@@ -311,7 +311,7 @@ export class AdapterHandler {
|
|
|
311
311
|
if (typeof compiledTranslatedPatt === 'string') {
|
|
312
312
|
return compiledTranslatedPatt;
|
|
313
313
|
}
|
|
314
|
-
const urlTokens = compiledTranslatedPatt.map(
|
|
314
|
+
const urlTokens = compiledTranslatedPatt.map(part => {
|
|
315
315
|
if (typeof part === 'number') {
|
|
316
316
|
return keys[part];
|
|
317
317
|
}
|
|
@@ -324,12 +324,12 @@ export class AdapterHandler {
|
|
|
324
324
|
if (!patterns) {
|
|
325
325
|
return;
|
|
326
326
|
}
|
|
327
|
-
const manifest = patterns.map(
|
|
327
|
+
const manifest = patterns.map(patt => {
|
|
328
328
|
const catalogPattKey = this.#urlPatternKeys.get(patt);
|
|
329
329
|
const { keys } = pathToRegexp(patt);
|
|
330
330
|
return [
|
|
331
331
|
patt,
|
|
332
|
-
this.#config.locales.map(
|
|
332
|
+
this.#config.locales.map(loc => {
|
|
333
333
|
let pattern = patt;
|
|
334
334
|
const item = this.sharedState.poFilesByLoc.get(loc).catalog.get(catalogPattKey);
|
|
335
335
|
if (item) {
|
|
@@ -423,13 +423,13 @@ export class AdapterHandler {
|
|
|
423
423
|
}
|
|
424
424
|
return new Message(locPattern, undefined, context);
|
|
425
425
|
});
|
|
426
|
-
const urlPatternCatKeys = urlPatternMsgs.map(
|
|
426
|
+
const urlPatternCatKeys = urlPatternMsgs.map(msg => msg.toKey());
|
|
427
427
|
for (const [key, item] of catalog.entries()) {
|
|
428
428
|
if (!item.flags[urlPatternFlag]) {
|
|
429
429
|
continue;
|
|
430
430
|
}
|
|
431
431
|
if (!urlPatternCatKeys.includes(key)) {
|
|
432
|
-
item.references = item.references.filter(
|
|
432
|
+
item.references = item.references.filter(r => r !== this.key);
|
|
433
433
|
if (item.references.length === 0) {
|
|
434
434
|
item.obsolete = true;
|
|
435
435
|
}
|
|
@@ -603,7 +603,7 @@ export class AdapterHandler {
|
|
|
603
603
|
continue;
|
|
604
604
|
}
|
|
605
605
|
// compile only if it came from a file under this adapter
|
|
606
|
-
if (!poItem.references.some(
|
|
606
|
+
if (!poItem.references.some(f => this.fileMatches(f))) {
|
|
607
607
|
continue;
|
|
608
608
|
}
|
|
609
609
|
const index = this.sharedState.indexTracker.get(key);
|
|
@@ -834,7 +834,7 @@ export class AdapterHandler {
|
|
|
834
834
|
if (msgInfo.context) {
|
|
835
835
|
poItem.msgctxt = msgInfo.context;
|
|
836
836
|
}
|
|
837
|
-
const newComments = msgInfo.comments.map(
|
|
837
|
+
const newComments = msgInfo.comments.map(c => c.replace(/\s+/g, ' ').trim());
|
|
838
838
|
let iStartComm;
|
|
839
839
|
if (key in previousReferences) {
|
|
840
840
|
const prevRef = previousReferences.get(key);
|
|
@@ -950,7 +950,7 @@ export class AdapterHandler {
|
|
|
950
950
|
hmrData = { version: hmrVersion, data: {} };
|
|
951
951
|
for (const loc of this.#config.locales) {
|
|
952
952
|
hmrData.data[loc] =
|
|
953
|
-
hmrKeys.get(loc)?.map(
|
|
953
|
+
hmrKeys.get(loc)?.map(key => {
|
|
954
954
|
const index = indexTracker.get(key);
|
|
955
955
|
return [index, compiled.get(loc).items[index]];
|
|
956
956
|
}) ?? [];
|
|
@@ -981,18 +981,18 @@ export class AdapterHandler {
|
|
|
981
981
|
for (const item of items) {
|
|
982
982
|
// unreference all references that belong to this adapter
|
|
983
983
|
if (item.flags[urlPatternFlag]) {
|
|
984
|
-
item.references = item.references.filter(
|
|
984
|
+
item.references = item.references.filter(ref => ref !== this.key);
|
|
985
985
|
}
|
|
986
986
|
else {
|
|
987
987
|
// don't touch other adapters' files. related extracted comments handled by handler
|
|
988
|
-
item.references = item.references.filter(
|
|
988
|
+
item.references = item.references.filter(ref => {
|
|
989
989
|
if (this.fileMatches(ref)) {
|
|
990
990
|
return false;
|
|
991
991
|
}
|
|
992
992
|
if (this.sharedState.ownerKey !== this.key) {
|
|
993
993
|
return true;
|
|
994
994
|
}
|
|
995
|
-
return this.sharedState.otherFileMatches.some(
|
|
995
|
+
return this.sharedState.otherFileMatches.some(match => match(ref));
|
|
996
996
|
});
|
|
997
997
|
}
|
|
998
998
|
}
|
package/dist/load-utils/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import toRuntime, {} from '../runtime.js';
|
|
2
2
|
export function defaultCollection(store) {
|
|
3
3
|
return {
|
|
4
|
-
get:
|
|
4
|
+
get: loadID => store[loadID],
|
|
5
5
|
set: (loadID, rt) => {
|
|
6
6
|
store[loadID] = rt;
|
|
7
7
|
},
|
|
@@ -17,13 +17,13 @@ const emptyRuntime = toRuntime();
|
|
|
17
17
|
export function registerLoaders(key, load, loadIDs, collection) {
|
|
18
18
|
states[key] = {
|
|
19
19
|
load,
|
|
20
|
-
catalogs: Object.fromEntries(loadIDs.map(
|
|
20
|
+
catalogs: Object.fromEntries(loadIDs.map(id => [id])),
|
|
21
21
|
collection: collection ?? defaultCollection({}),
|
|
22
22
|
};
|
|
23
23
|
for (const id of loadIDs) {
|
|
24
24
|
states[key].collection.set(id, emptyRuntime);
|
|
25
25
|
}
|
|
26
|
-
return
|
|
26
|
+
return loadID => states[key].collection.get(loadID);
|
|
27
27
|
}
|
|
28
28
|
/* Sets the most recently loaded locale as the current one */
|
|
29
29
|
export function commitLocale(locale) {
|
package/dist/load-utils/pure.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** No-side effect way to load catalogs. Can be used for multiple file IDs. */
|
|
2
2
|
export async function loadCatalogs(locale, loadIDs, loadCatalog) {
|
|
3
3
|
const data = {};
|
|
4
|
-
const promises = loadIDs.map(
|
|
4
|
+
const promises = loadIDs.map(id => loadCatalog(id, locale));
|
|
5
5
|
// merge into one object
|
|
6
6
|
for (const [i, loaded] of (await Promise.all(promises)).entries()) {
|
|
7
7
|
data[loadIDs[i]] = loaded;
|
package/dist/runtime.js
CHANGED
|
@@ -49,7 +49,7 @@ export default function toRuntime(mod = { [catalogVarName]: [] }, locale) {
|
|
|
49
49
|
/** for tagged template strings */
|
|
50
50
|
rt.t = (tag, id, args) => {
|
|
51
51
|
const ctx = getCompositeContext(id);
|
|
52
|
-
return tag(ctx.filter(
|
|
52
|
+
return tag(ctx.filter(m => typeof m === 'string'), ...ctx.filter(m => typeof m === 'number').map(a => args?.[a]));
|
|
53
53
|
};
|
|
54
54
|
/** get translation for plural */
|
|
55
55
|
rt.p = (id) => catalog[id] ?? [];
|
package/package.json
CHANGED
|
@@ -13,5 +13,5 @@ export function setLocale(newLocale) {
|
|
|
13
13
|
/**
|
|
14
14
|
* @param {{ [locale: string]: import("wuchale/runtime").CatalogModule }} catalogs
|
|
15
15
|
*/
|
|
16
|
-
export const getRuntime =
|
|
16
|
+
export const getRuntime = catalogs => toRuntime(catalogs[locale], locale)
|
|
17
17
|
export const getRuntimeRx = getRuntime
|