wuchale 0.21.2 → 0.22.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/adapter-vanilla/transformer.js +11 -7
- package/dist/adapters.d.ts +8 -0
- package/dist/ai/index.js +23 -3
- package/dist/bundlers/vite.d.ts +32 -0
- package/dist/bundlers/vite.js +64 -0
- package/dist/cli/check.d.ts +3 -0
- package/dist/cli/check.js +35 -0
- package/dist/cli/index.js +42 -11
- package/dist/cli/status.d.ts +2 -1
- package/dist/cli/status.js +33 -45
- package/dist/compile.js +13 -13
- package/dist/fs.d.ts +9 -0
- package/dist/fs.js +33 -0
- package/dist/handler/files.d.ts +13 -3
- package/dist/handler/files.js +47 -38
- package/dist/handler/index.d.ts +6 -6
- package/dist/handler/index.js +75 -51
- package/dist/handler/state.d.ts +0 -4
- package/dist/handler/state.js +26 -19
- package/dist/handler/url.d.ts +3 -2
- package/dist/handler/url.js +11 -8
- package/dist/hub.d.ts +57 -0
- package/dist/hub.js +361 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/pofile.d.ts +1 -1
- package/dist/pofile.js +68 -71
- package/dist/runtime.js +3 -8
- package/dist/storage.d.ts +2 -1
- package/package.json +10 -2
- package/dist/cli/extract.d.ts +0 -2
- package/dist/cli/extract.js +0 -87
|
@@ -113,7 +113,7 @@ export class Transformer {
|
|
|
113
113
|
}
|
|
114
114
|
const wrapInit = initReactive ? rtConf.reactive.wrapInit : rtConf.plain.wrapInit;
|
|
115
115
|
const expr = initReactive ? catalogExpr.reactive : catalogExpr.plain;
|
|
116
|
-
return `\nconst ${this.currentRtVar} = ${wrapInit(expr)}
|
|
116
|
+
return `\nconst ${this.currentRtVar} = ${wrapInit(expr)};\n`;
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
fullHeuristicDetails = (detailsBase) => ({
|
|
@@ -408,19 +408,23 @@ export class Transformer {
|
|
|
408
408
|
if (!node.init) {
|
|
409
409
|
return [];
|
|
410
410
|
}
|
|
411
|
+
const init = this.getActualExpression(node.init);
|
|
411
412
|
if (topLevel) {
|
|
412
|
-
|
|
413
|
-
if (init?.type === 'ArrowFunctionExpression' || init?.type === 'FunctionExpression') {
|
|
413
|
+
if (init.type === 'ArrowFunctionExpression' || init.type === 'FunctionExpression') {
|
|
414
414
|
this.heuristciDetails.declaring = 'function';
|
|
415
415
|
}
|
|
416
416
|
else {
|
|
417
417
|
this.heuristciDetails.declaring = 'variable';
|
|
418
|
-
if (init?.type === 'CallExpression') {
|
|
419
|
-
this.heuristciDetails.topLevelCall = this.getCalleeName(init.callee);
|
|
420
|
-
}
|
|
421
418
|
}
|
|
422
419
|
}
|
|
423
|
-
|
|
420
|
+
this.heuristciDetails.leftSide = true;
|
|
421
|
+
const msgs = this.visit(node.id);
|
|
422
|
+
this.heuristciDetails.leftSide = false;
|
|
423
|
+
if (topLevel && this.heuristciDetails.declaring === 'variable' && init.type === 'CallExpression') {
|
|
424
|
+
this.heuristciDetails.topLevelCall = this.getCalleeName(init.callee);
|
|
425
|
+
}
|
|
426
|
+
delete this.heuristciDetails.leftSide;
|
|
427
|
+
return [...msgs, ...this.visit(node.init)];
|
|
424
428
|
});
|
|
425
429
|
visitExpressionStatement = (node) => this.withUpdateTLDetails(topLevel => {
|
|
426
430
|
const expr = this.getActualExpression(node.expression);
|
package/dist/adapters.d.ts
CHANGED
|
@@ -9,11 +9,19 @@ export type HeuristicDetailsBase = {
|
|
|
9
9
|
export type ScriptDeclType = 'variable' | 'function' | 'class' | 'expression';
|
|
10
10
|
export type HeuristicDetails = HeuristicDetailsBase & {
|
|
11
11
|
file: string;
|
|
12
|
+
/** the type of the top level declaration */
|
|
12
13
|
declaring?: ScriptDeclType;
|
|
14
|
+
/** in assignments, whether the string is on the left side as destructuring default */
|
|
15
|
+
leftSide?: boolean;
|
|
16
|
+
/** the name of the function being defined, '' for arrow or null for global */
|
|
13
17
|
funcName?: string | null;
|
|
18
|
+
/** whether the function being defined is nested inside another, null for no function */
|
|
14
19
|
funcIsNested?: boolean;
|
|
20
|
+
/** whether inside a script file/<script> instead of an expression inside markup */
|
|
15
21
|
insideProgram: boolean;
|
|
22
|
+
/** the name of the call at the top level */
|
|
16
23
|
topLevelCall?: string;
|
|
24
|
+
/** the name of the nearest call (for arguments) */
|
|
17
25
|
call?: string;
|
|
18
26
|
};
|
|
19
27
|
export type MessageType = 'message' | 'url';
|
package/dist/ai/index.js
CHANGED
|
@@ -87,19 +87,39 @@ export default class AIQueue {
|
|
|
87
87
|
const unTranslated = batch.messages.slice(translated.length);
|
|
88
88
|
for (const [i, outItem] of translated.entries()) {
|
|
89
89
|
const item = batch.messages[i];
|
|
90
|
-
const
|
|
90
|
+
const id = item.translations.get(this.sourceLocale);
|
|
91
|
+
const sourceComp = id.map(i => compileTranslation(i, ''));
|
|
91
92
|
for (const loc of batch.targetLocales) {
|
|
92
93
|
const translation = outItem[loc];
|
|
93
|
-
if (translation
|
|
94
|
+
if (translation === undefined) {
|
|
94
95
|
unTranslated.push(item);
|
|
95
96
|
break;
|
|
96
97
|
}
|
|
98
|
+
if (id.length > 1) {
|
|
99
|
+
// plural
|
|
100
|
+
if (translation.length === 0) {
|
|
101
|
+
// TODO: pass pluralRule and check nplurals
|
|
102
|
+
unTranslated.push(item);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
item.translations.set(loc, translation);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (translation.length !== id.length) {
|
|
109
|
+
unTranslated.push(item);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
let equivalent = true;
|
|
97
113
|
for (const [i, sou] of sourceComp.entries()) {
|
|
98
114
|
if (!isEquivalent(sou, compileTranslation(translation[i], ''))) {
|
|
99
|
-
|
|
115
|
+
equivalent = false;
|
|
100
116
|
break;
|
|
101
117
|
}
|
|
102
118
|
}
|
|
119
|
+
if (!equivalent) {
|
|
120
|
+
unTranslated.push(item);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
103
123
|
item.translations.set(loc, translation);
|
|
104
124
|
}
|
|
105
125
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare function toViteError(err: any, adapterKey: string, filename: string): Error;
|
|
2
|
+
export declare function trimViteQueries(id: string): string;
|
|
3
|
+
type HotUpdateCtx = {
|
|
4
|
+
file: string;
|
|
5
|
+
server: {
|
|
6
|
+
ws: {
|
|
7
|
+
send: Function;
|
|
8
|
+
};
|
|
9
|
+
moduleGraph: {
|
|
10
|
+
getModulesByFile: Function;
|
|
11
|
+
invalidateModule: Function;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
read: () => string | Promise<string>;
|
|
15
|
+
timestamp: number;
|
|
16
|
+
};
|
|
17
|
+
export declare const wuchale: (configPath?: string, hmrDelayThreshold?: number) => {
|
|
18
|
+
name: string;
|
|
19
|
+
configResolved(config: {
|
|
20
|
+
env: {
|
|
21
|
+
DEV?: boolean;
|
|
22
|
+
};
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
handleHotUpdate(ctx: HotUpdateCtx): Promise<never[] | undefined>;
|
|
25
|
+
transform: {
|
|
26
|
+
order: "pre";
|
|
27
|
+
handler(code: string, id: string, options?: {
|
|
28
|
+
ssr?: boolean | undefined;
|
|
29
|
+
}): Promise<import("wuchale").TransformOutputCode>;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { dirname } from 'node:path';
|
|
2
|
+
import { getConfig } from 'wuchale';
|
|
3
|
+
import { Hub, pluginName } from '../hub.js';
|
|
4
|
+
export function toViteError(err, adapterKey, filename) {
|
|
5
|
+
const prefix = `${adapterKey}: transform failed for ${filename}`;
|
|
6
|
+
// Ensure we always throw an Error instance with a non-empty message so build tools (e.g. Vite)
|
|
7
|
+
// don't end up printing only a generic "error during build:" line.
|
|
8
|
+
const frame = typeof err.frame === 'string' ? err.frame : undefined;
|
|
9
|
+
if (!err.message || !err.message.startsWith(prefix)) {
|
|
10
|
+
const details = err.message ? `\n${err.message}` : '';
|
|
11
|
+
const frameText = frame ? `\n\n${frame}` : '';
|
|
12
|
+
err.message = `${prefix}${details}${frameText}`;
|
|
13
|
+
}
|
|
14
|
+
// Preserve useful metadata that some tooling expects.
|
|
15
|
+
if (err.id == null)
|
|
16
|
+
err.id = filename;
|
|
17
|
+
if (err.loc == null && err.start?.line != null && err.start?.column != null) {
|
|
18
|
+
err.loc = { file: filename, line: err.start.line, column: err.start.column };
|
|
19
|
+
}
|
|
20
|
+
return err;
|
|
21
|
+
}
|
|
22
|
+
export function trimViteQueries(id) {
|
|
23
|
+
let queryIndex = id.indexOf('?v=');
|
|
24
|
+
if (queryIndex === -1) {
|
|
25
|
+
queryIndex = id.indexOf('?t=');
|
|
26
|
+
}
|
|
27
|
+
if (queryIndex >= 0 && !id.includes('&', queryIndex)) {
|
|
28
|
+
// trim after this, like ?v=b65b2c3b when it's from node_modules
|
|
29
|
+
id = id.slice(0, queryIndex);
|
|
30
|
+
}
|
|
31
|
+
return id;
|
|
32
|
+
}
|
|
33
|
+
export const wuchale = (configPath, hmrDelayThreshold = 1000) => {
|
|
34
|
+
const hub = new Hub(() => getConfig(configPath), dirname(configPath ?? '.'), hmrDelayThreshold, undefined, toViteError);
|
|
35
|
+
return {
|
|
36
|
+
name: pluginName,
|
|
37
|
+
async configResolved(config) {
|
|
38
|
+
await hub.init(config.env.DEV ? 'dev' : 'build');
|
|
39
|
+
},
|
|
40
|
+
async handleHotUpdate(ctx) {
|
|
41
|
+
const changeInfo = await hub.onFileChange(ctx.file, ctx.read);
|
|
42
|
+
if (!changeInfo) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const invalidatedModules = new Set();
|
|
46
|
+
for (const fileID of changeInfo.invalidate ?? []) {
|
|
47
|
+
for (const module of ctx.server.moduleGraph.getModulesByFile(fileID) ?? []) {
|
|
48
|
+
ctx.server.moduleGraph.invalidateModule(module, invalidatedModules, ctx.timestamp, false);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!changeInfo.sourceTriggered && changeInfo.invalidate.size > 0) {
|
|
52
|
+
ctx.server.ws.send({ type: 'full-reload' });
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
transform: {
|
|
57
|
+
order: 'pre',
|
|
58
|
+
async handler(code, id, options) {
|
|
59
|
+
const [output] = await hub.transform(code, trimViteQueries(id), options?.ssr);
|
|
60
|
+
return output;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {} from '../config.js';
|
|
2
|
+
import { readOnlyFS } from '../fs.js';
|
|
3
|
+
import { Hub } from '../hub.js';
|
|
4
|
+
import { color } from '../log.js';
|
|
5
|
+
export const checkHelp = `
|
|
6
|
+
Usage:
|
|
7
|
+
${color.cyan('wuchale check {options}')}
|
|
8
|
+
|
|
9
|
+
Options:
|
|
10
|
+
${color.cyan('--full')} check if there are unextracted and newly obsolete messages in source code as well
|
|
11
|
+
${color.cyan('--help')}, ${color.cyan('-h')} Show this help
|
|
12
|
+
`;
|
|
13
|
+
const checkErrMsgs = {
|
|
14
|
+
notEquivalent: 'Not equivalent',
|
|
15
|
+
unequalLength: 'Unequal length',
|
|
16
|
+
};
|
|
17
|
+
export async function check(config, root, full) {
|
|
18
|
+
// console.log because if the user invokes this command, they want full info regardless of config
|
|
19
|
+
const hub = new Hub(() => config, root, 0, readOnlyFS);
|
|
20
|
+
await hub.init('cli');
|
|
21
|
+
const { checked, errors, syncs } = await hub.check(full);
|
|
22
|
+
for (const err of errors) {
|
|
23
|
+
console.error(`${color.magenta(err.adapter)}: ${color.red(checkErrMsgs[err.type])}`);
|
|
24
|
+
console.error(` ${color.grey('Source:')} ${err.source}`);
|
|
25
|
+
console.error(` ${color.grey('Target locale:')} ${err.locale}`);
|
|
26
|
+
console.error(` ${color.grey('Translation:')} ${err.translation}`);
|
|
27
|
+
}
|
|
28
|
+
for (const key of syncs) {
|
|
29
|
+
console.error(`${color.red(key)}: Pending changes`);
|
|
30
|
+
}
|
|
31
|
+
if (errors.length > 0 || syncs.length > 0) {
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
console.log(color.green(`${checked} items checked. No errors found`));
|
|
35
|
+
}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { dirname } from 'node:path';
|
|
2
3
|
import { parseArgs } from 'node:util';
|
|
3
4
|
import { defaultConfigNames, getConfig } from '../config.js';
|
|
5
|
+
import { Hub } from '../hub.js';
|
|
4
6
|
import { color, logLevels } from '../log.js';
|
|
5
|
-
import {
|
|
6
|
-
import { status } from './status.js';
|
|
7
|
+
import { check, checkHelp } from './check.js';
|
|
8
|
+
import { status, statusHelp } from './status.js';
|
|
7
9
|
const { positionals, values } = parseArgs({
|
|
8
10
|
options: {
|
|
9
11
|
config: {
|
|
@@ -19,6 +21,14 @@ const { positionals, values } = parseArgs({
|
|
|
19
21
|
short: 'w',
|
|
20
22
|
default: false,
|
|
21
23
|
},
|
|
24
|
+
json: {
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
default: false,
|
|
27
|
+
},
|
|
28
|
+
full: {
|
|
29
|
+
type: 'boolean',
|
|
30
|
+
default: false,
|
|
31
|
+
},
|
|
22
32
|
sync: {
|
|
23
33
|
type: 'boolean',
|
|
24
34
|
default: false,
|
|
@@ -44,30 +54,51 @@ Commands:
|
|
|
44
54
|
${color.grey('[none]')} Extract/compile messages from the codebase into catalogs
|
|
45
55
|
deleting unused messages if ${color.cyan('--clean')} is specified
|
|
46
56
|
${color.cyan('status')} Show current status
|
|
57
|
+
${color.cyan('check')} Check for errors
|
|
47
58
|
|
|
48
59
|
Options:
|
|
49
60
|
${color.cyan('--config')} use another config file instead of ${defaultConfigNames.map(color.cyan).join('|')}
|
|
50
|
-
${color.cyan('--clean')}, ${color.cyan('-c')}
|
|
51
|
-
${color.cyan('--watch')}, ${color.cyan('-w')}
|
|
52
|
-
${color.cyan('--sync')}
|
|
61
|
+
${color.cyan('--clean')}, ${color.cyan('-c')} remove unused messages from catalogs
|
|
62
|
+
${color.cyan('--watch')}, ${color.cyan('-w')} continuously watch for file changes
|
|
63
|
+
${color.cyan('--sync')} extract sequentially instead of in parallel
|
|
53
64
|
${color.cyan('--log-level')}, ${color.cyan('-l')} {${Object.keys(logLevels).map(color.cyan)}} (only when no commands) set log level
|
|
54
65
|
${color.cyan('--help')}, ${color.cyan('-h')} Show this help
|
|
66
|
+
|
|
67
|
+
You can specify ${color.cyan('--help')} after a sub-command for more.
|
|
55
68
|
`;
|
|
56
69
|
async function configRootLocales() {
|
|
57
70
|
const config = await getConfig(values.config);
|
|
58
71
|
config.logLevel = values['log-level'];
|
|
59
|
-
|
|
72
|
+
const root = values.config ? dirname(values.config) : process.cwd();
|
|
73
|
+
return [config, root, config.locales];
|
|
74
|
+
}
|
|
75
|
+
if (cmd === 'status') {
|
|
76
|
+
if (values.help) {
|
|
77
|
+
console.log(statusHelp);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const [config, root] = await configRootLocales();
|
|
81
|
+
await status(config, root, values.json);
|
|
82
|
+
}
|
|
60
83
|
}
|
|
61
|
-
if (
|
|
84
|
+
else if (cmd === 'check') {
|
|
85
|
+
if (values.help) {
|
|
86
|
+
console.log(checkHelp);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const [config, root] = await configRootLocales();
|
|
90
|
+
await check(config, root, values.full);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (values.help) {
|
|
62
94
|
console.log('wuchale cli');
|
|
63
95
|
console.log(help.trimEnd());
|
|
64
96
|
}
|
|
65
97
|
else if (cmd == null) {
|
|
66
98
|
const [config, root] = await configRootLocales();
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
await status(...(await configRootLocales()));
|
|
99
|
+
const hub = new Hub(() => config, root);
|
|
100
|
+
await hub.init('cli');
|
|
101
|
+
await hub.directVisit(values.clean, values.watch, values.sync);
|
|
71
102
|
}
|
|
72
103
|
else {
|
|
73
104
|
console.warn(`${color.yellow('Unknown command')}: ${cmd}`);
|
package/dist/cli/status.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type Config } from '../config.js';
|
|
2
|
-
export declare
|
|
2
|
+
export declare const statusHelp: string;
|
|
3
|
+
export declare function status(config: Config, root: string, json: boolean): Promise<void>;
|
package/dist/cli/status.js
CHANGED
|
@@ -1,59 +1,47 @@
|
|
|
1
1
|
import { relative } from 'node:path';
|
|
2
2
|
import { getLanguageName } from '../config.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { color
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
stats.Untranslated++;
|
|
16
|
-
}
|
|
17
|
-
if (itemIsObsolete(item)) {
|
|
18
|
-
stats.Obsolete++;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return stats;
|
|
22
|
-
}
|
|
23
|
-
export async function status(config, root, locales) {
|
|
3
|
+
import { readOnlyFS } from '../fs.js';
|
|
4
|
+
import { Hub } from '../hub.js';
|
|
5
|
+
import { color } from '../log.js';
|
|
6
|
+
export const statusHelp = `
|
|
7
|
+
Usage:
|
|
8
|
+
${color.cyan('wuchale status {options}')}
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
${color.cyan('--json')} output info as structured JSON instead of table and text
|
|
12
|
+
${color.cyan('--help')}, ${color.cyan('-h')} Show this help
|
|
13
|
+
`;
|
|
14
|
+
export async function status(config, root, json) {
|
|
24
15
|
// console.log because if the user invokes this command, they want full info regardless of config
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
console.log(`${color.magenta(key)}
|
|
33
|
-
if (
|
|
16
|
+
const hub = new Hub(() => config, root, 0, readOnlyFS);
|
|
17
|
+
await hub.init('cli');
|
|
18
|
+
if (json) {
|
|
19
|
+
console.log(JSON.stringify(await hub.status(), null, process.stdout.isTTY ? ' ' : undefined));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
for (const stat of await hub.status()) {
|
|
23
|
+
console.log(`${color.magenta(stat.key)}:`);
|
|
24
|
+
if (stat.loaders) {
|
|
34
25
|
console.log(` Loader files:`);
|
|
35
|
-
for (const [side, path] of Object.entries(
|
|
26
|
+
for (const [side, path] of Object.entries(stat.loaders)) {
|
|
36
27
|
console.log(` ${color.cyan(side)}: ${color.cyan(relative(root, path))}`);
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
30
|
else {
|
|
40
31
|
console.warn(color.yellow(' No loader file found.'));
|
|
41
|
-
console.log(` Run ${color.cyan('npx wuchale
|
|
32
|
+
console.log(` Run ${color.cyan('npx wuchale')} to initialize.`);
|
|
42
33
|
}
|
|
34
|
+
if (!stat.storage.own) {
|
|
35
|
+
console.log(` Storage shared with ${color.magenta(stat.storage.ownerKey)}`);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
console.log(` Messages: ${color.cyan(stat.storage.total)} (${color.cyan(stat.storage.url)} URL)`);
|
|
43
39
|
const statsData = {};
|
|
44
|
-
for (const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
]) {
|
|
50
|
-
await state.load(locales);
|
|
51
|
-
const stats = await statCatalog(locale, state.catalog, url);
|
|
52
|
-
if (stats.Total === 0) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
statsData[name] = stats;
|
|
56
|
-
}
|
|
40
|
+
for (const det of stat.storage.details) {
|
|
41
|
+
statsData[getLanguageName(det.locale)] = {
|
|
42
|
+
Obsolete: det.obsolete,
|
|
43
|
+
Untranslated: det.untranslated,
|
|
44
|
+
};
|
|
57
45
|
}
|
|
58
46
|
console.table(statsData);
|
|
59
47
|
}
|
package/dist/compile.js
CHANGED
|
@@ -77,7 +77,7 @@ function compile(msgStr, start = 0, parentTag = null) {
|
|
|
77
77
|
if (type === CLOSE) {
|
|
78
78
|
if (currentOpenTag != null) {
|
|
79
79
|
if (currentOpenTag != n) {
|
|
80
|
-
|
|
80
|
+
return [compiled, 0, 'Closing a different tag'];
|
|
81
81
|
}
|
|
82
82
|
currentOpenTag = null;
|
|
83
83
|
}
|
|
@@ -85,7 +85,7 @@ function compile(msgStr, start = 0, parentTag = null) {
|
|
|
85
85
|
break;
|
|
86
86
|
}
|
|
87
87
|
else {
|
|
88
|
-
|
|
88
|
+
return [compiled, 0, 'Closing a different tag'];
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
else if (type === SELF_CLOSE) {
|
|
@@ -100,24 +100,24 @@ function compile(msgStr, start = 0, parentTag = null) {
|
|
|
100
100
|
if (curTxt) {
|
|
101
101
|
compiled.push(curTxt);
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
if (currentOpenTag !== null) {
|
|
104
|
+
return [compiled, 0, 'Unexpected end'];
|
|
105
|
+
}
|
|
106
|
+
return [compiled, i, null];
|
|
104
107
|
}
|
|
105
108
|
export function compileTranslation(msgStr, fallback) {
|
|
106
109
|
if (!msgStr) {
|
|
107
110
|
return fallback;
|
|
108
111
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return compiled[0];
|
|
113
|
-
}
|
|
114
|
-
return compiled;
|
|
115
|
-
}
|
|
116
|
-
catch (err) {
|
|
117
|
-
console.error(err);
|
|
118
|
-
console.error(msgStr);
|
|
112
|
+
const [compiled, , err] = compile(msgStr);
|
|
113
|
+
if (err !== null) {
|
|
114
|
+
console.error('Compile error:', err, ':', msgStr);
|
|
119
115
|
return fallback;
|
|
120
116
|
}
|
|
117
|
+
if (compiled.length === 1 && typeof compiled[0] === 'string') {
|
|
118
|
+
return compiled[0];
|
|
119
|
+
}
|
|
120
|
+
return compiled;
|
|
121
121
|
}
|
|
122
122
|
export function isEquivalent(source, translation) {
|
|
123
123
|
const sourceStr = typeof source === 'string';
|
package/dist/fs.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type FS = {
|
|
2
|
+
read(file: string): string | Promise<string>;
|
|
3
|
+
write(file: string, content: string): void | Promise<void>;
|
|
4
|
+
mkdir(path: string): void | Promise<void>;
|
|
5
|
+
exists(path: string): boolean | Promise<boolean>;
|
|
6
|
+
unlink(path: string): void | Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export declare const defaultFS: FS;
|
|
9
|
+
export declare const readOnlyFS: FS;
|
package/dist/fs.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mkdir, readFile, statfs, unlink, writeFile } from 'node:fs/promises';
|
|
2
|
+
export const defaultFS = {
|
|
3
|
+
async read(file) {
|
|
4
|
+
return await readFile(file, 'utf-8');
|
|
5
|
+
},
|
|
6
|
+
async write(file, content) {
|
|
7
|
+
await writeFile(file, content);
|
|
8
|
+
},
|
|
9
|
+
async mkdir(path) {
|
|
10
|
+
await mkdir(path, { recursive: true });
|
|
11
|
+
},
|
|
12
|
+
async exists(path) {
|
|
13
|
+
try {
|
|
14
|
+
await statfs(path);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
if (err.code !== 'ENOENT') {
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
async unlink(path) {
|
|
25
|
+
await unlink(path);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export const readOnlyFS = {
|
|
29
|
+
...defaultFS,
|
|
30
|
+
write: () => { },
|
|
31
|
+
mkdir: () => { },
|
|
32
|
+
unlink: () => { },
|
|
33
|
+
};
|
package/dist/handler/files.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import type { Adapter, GlobConf, LoaderPath } from '../adapters.js';
|
|
2
2
|
import type { CompiledElement } from '../compile.js';
|
|
3
|
+
import type { FS } from '../fs.js';
|
|
3
4
|
import { type URLManifest } from '../url.js';
|
|
5
|
+
export declare const dataFileName = "data.js";
|
|
4
6
|
export declare const generatedDir = ".wuchale";
|
|
7
|
+
export type ManifestEntryObj = {
|
|
8
|
+
text: string | string[];
|
|
9
|
+
context?: string;
|
|
10
|
+
isUrl?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type ManifestEntry = string | string[] | ManifestEntryObj | null;
|
|
5
13
|
export declare const objKeyLocale: (locale: string) => string;
|
|
6
14
|
export declare function normalizeSep(path: string): string;
|
|
7
|
-
export declare function globConfToArgs(conf: GlobConf, localesDir: string, outDir?: string): [string[], {
|
|
15
|
+
export declare function globConfToArgs(conf: GlobConf, root: string, localesDir: string, outDir?: string): [string[], {
|
|
8
16
|
ignore: string[];
|
|
9
17
|
}];
|
|
10
18
|
export declare class Files {
|
|
@@ -14,7 +22,7 @@ export declare class Files {
|
|
|
14
22
|
loaderPath: LoaderPath;
|
|
15
23
|
proxyPath: string;
|
|
16
24
|
proxySyncPath: string;
|
|
17
|
-
constructor(adapter: Adapter, key: string, localesDir: string, root: string);
|
|
25
|
+
constructor(adapter: Adapter, key: string, localesDir: string, fs: FS, root: string);
|
|
18
26
|
getLoaderPaths(): LoaderPath[];
|
|
19
27
|
getLoaderPath(): Promise<LoaderPath>;
|
|
20
28
|
getCompiledFilePath(loc: string, id: string | null): string;
|
|
@@ -23,8 +31,10 @@ export declare class Files {
|
|
|
23
31
|
genProxy(locales: string[], loadIDs: string[], loadIDsImport: string[]): string;
|
|
24
32
|
genProxySync(locales: string[], loadIDs: string[], loadIDsImport: string[]): string;
|
|
25
33
|
writeProxies: (locales: string[], loadIDs: string[], loadIDsImport: string[]) => Promise<void>;
|
|
26
|
-
init: (
|
|
34
|
+
init: (ownerKey: string) => Promise<void>;
|
|
27
35
|
writeUrlFiles: (manifest: URLManifest, fallbackLocale: string) => Promise<void>;
|
|
36
|
+
getManifestFilePath(id: string | null): string;
|
|
37
|
+
writeManifest: (keys: ManifestEntry[], id: string | null) => Promise<void>;
|
|
28
38
|
writeCatalogModule: (compiledData: CompiledElement[], pluralRule: string | null, locale: string, hmrVersion: number | null, loadID: string | null) => Promise<void>;
|
|
29
39
|
writeTransformed: (filename: string, content: string) => Promise<void>;
|
|
30
40
|
getImportLoaderPath(forServer: boolean, relativeTo: string): string;
|