@vmz/vmz 0.1.17 → 0.1.18
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/application-cmd.d.ts +6 -16
- package/dist/application-cmd.js +34 -180
- package/dist/author-input.d.ts +40 -19
- package/dist/author-input.js +2 -16
- package/dist/build-assemble.d.ts +63 -41
- package/dist/build-assemble.js +42 -43
- package/dist/bundler-adapter.d.ts +46 -48
- package/dist/bundler-adapter.js +4 -43
- package/dist/cdn-policy.d.ts +77 -93
- package/dist/cdn-policy.js +10 -16
- package/dist/cli-localize.d.ts +34 -0
- package/dist/cli-localize.js +58 -0
- package/dist/cli.d.ts +8 -19
- package/dist/cli.js +69 -252
- package/dist/content-addressed-assets.d.ts +24 -10
- package/dist/content-addressed-assets.js +2 -7
- package/dist/delivery-profile.d.ts +54 -27
- package/dist/delivery-profile.js +15 -13
- package/dist/dev-session.d.ts +29 -23
- package/dist/dev-session.js +0 -21
- package/dist/dev-watch-roots.d.ts +34 -25
- package/dist/dev-watch-roots.js +0 -31
- package/dist/document-build.d.ts +22 -97
- package/dist/document-build.js +4 -19
- package/dist/document-check.d.ts +30 -53
- package/dist/document-check.js +14 -29
- package/dist/document-cmd.d.ts +3 -6
- package/dist/document-cmd.js +19 -79
- package/dist/document-designs.d.ts +5 -8
- package/dist/document-designs.js +2 -15
- package/dist/document-enrich.d.ts +52 -24
- package/dist/document-enrich.js +4 -32
- package/dist/document-evidence.d.ts +46 -43
- package/dist/document-evidence.js +6 -47
- package/dist/document-integrate.d.ts +13 -29
- package/dist/document-integrate.js +2 -13
- package/dist/document-interactive.d.ts +45 -67
- package/dist/document-interactive.js +9 -50
- package/dist/document-layout-render.d.ts +7 -16
- package/dist/document-layout-render.js +0 -17
- package/dist/document-locale.d.ts +12 -25
- package/dist/document-locale.js +3 -14
- package/dist/document-markdown.d.ts +9 -5
- package/dist/document-markdown.js +0 -4
- package/dist/document-routing-config.d.ts +7 -14
- package/dist/document-routing-config.js +0 -9
- package/dist/document-scan.d.ts +14 -18
- package/dist/document-scan.js +2 -23
- package/dist/document-schema.d.ts +154 -41
- package/dist/document-schema.js +0 -35
- package/dist/embedded-packaging.d.ts +20 -8
- package/dist/embedded-packaging.js +0 -1
- package/dist/explain-cmd.d.ts +4 -3
- package/dist/explain-cmd.js +16 -65
- package/dist/index.d.ts +70 -143
- package/dist/index.js +16 -136
- package/dist/invocation.d.ts +29 -50
- package/dist/invocation.js +11 -57
- package/dist/locale-check.d.ts +69 -70
- package/dist/locale-check.js +5 -66
- package/dist/locale-cmd.d.ts +2 -5
- package/dist/locale-cmd.js +62 -142
- package/dist/locale-delivery.d.ts +294 -191
- package/dist/locale-delivery.js +8 -94
- package/dist/locale-route-emit.d.ts +23 -9
- package/dist/locale-route-emit.js +0 -7
- package/dist/locale-router.d.ts +189 -162
- package/dist/locale-router.js +13 -122
- package/dist/locale-runtime.d.ts +292 -262
- package/dist/locale-runtime.js +8 -102
- package/dist/locale-schema.js +0 -1
- package/dist/locale-tooling.d.ts +100 -63
- package/dist/locale-tooling.js +7 -45
- package/dist/log.d.ts +22 -15
- package/dist/log.js +24 -21
- package/dist/native-addon.d.ts +10 -9
- package/dist/native-addon.js +1 -10
- package/dist/pack-client-packages.d.ts +5 -1
- package/dist/pack-client-packages.js +0 -6
- package/dist/pack.d.ts +17 -15
- package/dist/pack.js +0 -12
- package/dist/packages.d.ts +10 -23
- package/dist/packages.js +1 -37
- package/dist/plan-cmd.d.ts +6 -0
- package/dist/plan-cmd.js +35 -0
- package/dist/plugin-host.js +0 -1
- package/dist/port.d.ts +2 -10
- package/dist/port.js +2 -11
- package/dist/pretty-json.d.ts +9 -19
- package/dist/pretty-json.js +3 -17
- package/dist/production-observability.d.ts +37 -181
- package/dist/production-observability.js +1 -9
- package/dist/production-test-pack.d.ts +17 -3
- package/dist/production-test-pack.js +0 -2
- package/dist/public-static-assets.d.ts +6 -1
- package/dist/public-static-assets.js +0 -5
- package/dist/refactor-cmd.d.ts +3 -6
- package/dist/refactor-cmd.js +16 -69
- package/dist/release-cmd.d.ts +7 -6
- package/dist/release-cmd.js +17 -59
- package/dist/release-pack.d.ts +7 -3
- package/dist/release-pack.js +0 -6
- package/dist/resolve.d.ts +15 -19
- package/dist/resolve.js +1 -15
- package/dist/server-artifact.d.ts +30 -75
- package/dist/server-artifact.js +0 -10
- package/dist/server-language-backend.d.ts +22 -79
- package/dist/server-language-backend.js +0 -26
- package/dist/site-delivery.d.ts +46 -59
- package/dist/site-delivery.js +3 -8
- package/dist/site-favicon.d.ts +6 -1
- package/dist/site-favicon.js +0 -5
- package/dist/static-emit.d.ts +73 -103
- package/dist/static-emit.js +1 -26
- package/dist/test-cmd.d.ts +3 -5
- package/dist/test-cmd.js +15 -25
- package/dist/test-compile.js +0 -1
- package/dist/test-discover.js +0 -1
- package/dist/test-logic.js +0 -1
- package/dist/test-protocol.js +0 -1
- package/dist/toolchain-dx.d.ts +11 -0
- package/dist/toolchain-dx.js +10 -0
- package/dist/watch-diff.d.ts +4 -13
- package/dist/watch-diff.js +0 -17
- package/dist/wechat-packaging.d.ts +8 -7
- package/dist/wechat-packaging.js +0 -6
- package/locales/en-US/cli.json +105 -0
- package/locales/locales.json +4 -0
- package/package.json +15 -12
- package/dist/resolve-native-cli.d.ts +0 -14
- package/dist/resolve-native-cli.js +0 -84
package/dist/locale-check.d.ts
CHANGED
|
@@ -1,56 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare function validateLocaleId(literal: any): {
|
|
5
|
-
ok: boolean;
|
|
1
|
+
export interface LocaleDiagnostic {
|
|
2
|
+
code: string;
|
|
3
|
+
severity: string;
|
|
6
4
|
message: string;
|
|
7
|
-
|
|
5
|
+
path?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface MessageParam {
|
|
8
|
+
name: string;
|
|
9
|
+
kind: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MessageVariant {
|
|
12
|
+
template: string;
|
|
13
|
+
params: MessageParam[];
|
|
14
|
+
path: string;
|
|
15
|
+
}
|
|
16
|
+
export interface MessageNode {
|
|
17
|
+
messageId: string;
|
|
18
|
+
catalogId: string;
|
|
19
|
+
variants: Record<string, MessageVariant>;
|
|
20
|
+
}
|
|
21
|
+
export declare function validateLocaleId(literal: string): {
|
|
8
22
|
ok: boolean;
|
|
9
|
-
message?:
|
|
23
|
+
message?: string;
|
|
10
24
|
};
|
|
11
25
|
/**
|
|
12
26
|
* Flatten catalog object into MessageId → string template.
|
|
13
27
|
* Arrays are forbidden.
|
|
14
|
-
* @param {any} node
|
|
15
|
-
* @param {string} prefix
|
|
16
|
-
* @param {Array<{code:string,severity:string,message:string,path?:string}>} diagnostics
|
|
17
|
-
* @param {string} sourcePath
|
|
18
|
-
* @returns {Map<string, string>}
|
|
19
28
|
*/
|
|
20
|
-
export declare function flattenCatalog(node:
|
|
29
|
+
export declare function flattenCatalog(node: unknown, prefix: string, diagnostics: LocaleDiagnostic[], sourcePath: string): Map<string, string>;
|
|
21
30
|
/**
|
|
22
31
|
* ICU MessageFormat compatible subset: extract argument names + kinds.
|
|
23
|
-
* @param {string} template
|
|
24
|
-
* @returns {{ ok: boolean, params: Array<{ name: string, kind: string }>, error?: string }}
|
|
25
32
|
*/
|
|
26
|
-
export declare function extractMessageParams(template:
|
|
27
|
-
ok: boolean;
|
|
28
|
-
params: any[];
|
|
29
|
-
error: string;
|
|
30
|
-
} | {
|
|
33
|
+
export declare function extractMessageParams(template: string): {
|
|
31
34
|
ok: boolean;
|
|
32
|
-
params:
|
|
33
|
-
|
|
34
|
-
kind: any;
|
|
35
|
-
}[];
|
|
36
|
-
error?: undefined;
|
|
35
|
+
params: MessageParam[];
|
|
36
|
+
error?: string;
|
|
37
37
|
};
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*/
|
|
43
|
-
export declare function findFallbackCycles(fallback: any, known: any): {
|
|
44
|
-
cycles: any[];
|
|
45
|
-
unknown: any[];
|
|
38
|
+
/** Detect fallback cycles (explicit DAG). */
|
|
39
|
+
export declare function findFallbackCycles(fallback: Record<string, string[]>, known: Set<string>): {
|
|
40
|
+
cycles: string[];
|
|
41
|
+
unknown: string[];
|
|
46
42
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
export interface CheckLocalesOpts {
|
|
44
|
+
projectRoot: string;
|
|
45
|
+
strict?: boolean;
|
|
46
|
+
checkUnused?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export declare function checkLocales(opts: CheckLocalesOpts): {
|
|
51
49
|
schema: string;
|
|
52
50
|
status: string;
|
|
53
|
-
root:
|
|
51
|
+
root: string;
|
|
54
52
|
localesRoot: string;
|
|
55
53
|
manifest: any;
|
|
56
54
|
catalogIds: any[];
|
|
@@ -63,60 +61,61 @@ export declare function checkLocales(opts: any): {
|
|
|
63
61
|
catalogs: any[];
|
|
64
62
|
messageIds: any[];
|
|
65
63
|
};
|
|
66
|
-
diagnostics:
|
|
64
|
+
diagnostics: LocaleDiagnostic[];
|
|
67
65
|
};
|
|
68
66
|
/**
|
|
69
67
|
* Scan src for `#locales/<catalog>` imports and `messageId` string literals after import.
|
|
70
68
|
* First-slice heuristic — full VPG edges land with compiler deepen.
|
|
71
69
|
*/
|
|
72
|
-
export declare function scanLocaleUsages(projectRoot:
|
|
73
|
-
catalogs: Set<
|
|
74
|
-
messageIds: Set<
|
|
75
|
-
importedNames: Map<
|
|
70
|
+
export declare function scanLocaleUsages(projectRoot: string): {
|
|
71
|
+
catalogs: Set<string>;
|
|
72
|
+
messageIds: Set<string>;
|
|
73
|
+
importedNames: Map<string, Set<string>>;
|
|
76
74
|
};
|
|
77
|
-
/**
|
|
78
|
-
|
|
79
|
-
* @param {ReturnType<typeof checkLocales>} report
|
|
80
|
-
* @param {string} outDir
|
|
81
|
-
*/
|
|
82
|
-
export declare function emitLocaleTypedModules(report: any, outDir: any): any[];
|
|
75
|
+
/** Emit typed module stubs for `#locales/*`. */
|
|
76
|
+
export declare function emitLocaleTypedModules(report: ReturnType<typeof checkLocales>, outDir: string): string[];
|
|
83
77
|
/**
|
|
84
78
|
* Emit runtime `#locales/<catalog>.js` into application `dist/` and rewrite
|
|
85
79
|
* client imports from `#locales/...` to relative ESM paths.
|
|
86
80
|
*
|
|
87
81
|
* Variant pick reads `html[data-locale]` (else defaultLocale). Thin bridge until
|
|
88
82
|
* host LocaleTransition reloads locale-scoped chunks (I2/I4).
|
|
89
|
-
*
|
|
90
|
-
* @param {string} projectRoot
|
|
91
|
-
* @param {string} distDir
|
|
92
|
-
* @returns {{ ok: boolean, written: string[], diagnostics: any[] }}
|
|
93
83
|
*/
|
|
94
|
-
export declare function emitLocaleRuntimeModules(projectRoot:
|
|
84
|
+
export declare function emitLocaleRuntimeModules(projectRoot: string, distDir: string): {
|
|
95
85
|
ok: boolean;
|
|
96
|
-
written:
|
|
97
|
-
diagnostics:
|
|
86
|
+
written: string[];
|
|
87
|
+
diagnostics: LocaleDiagnostic[];
|
|
98
88
|
};
|
|
99
|
-
/**
|
|
100
|
-
|
|
101
|
-
* @param {ReturnType<typeof checkLocales>} report
|
|
102
|
-
* @param {string} fromId
|
|
103
|
-
* @param {string} toId
|
|
104
|
-
*/
|
|
105
|
-
export declare function planLocaleRename(report: any, fromId: any, toId: any): {
|
|
89
|
+
/** MessageId rename plan — WorkspaceEdit-shaped, no parallel rename IR. */
|
|
90
|
+
export declare function planLocaleRename(report: ReturnType<typeof checkLocales>, fromId: string, toId: string): {
|
|
106
91
|
schema: string;
|
|
107
92
|
status: string;
|
|
108
|
-
fromId:
|
|
109
|
-
toId:
|
|
110
|
-
edits:
|
|
93
|
+
fromId: string;
|
|
94
|
+
toId: string;
|
|
95
|
+
edits: Array<{
|
|
96
|
+
path: string;
|
|
97
|
+
kind: string;
|
|
98
|
+
from: string;
|
|
99
|
+
to: string;
|
|
100
|
+
}>;
|
|
111
101
|
error: string;
|
|
112
102
|
virtualModule?: undefined;
|
|
113
103
|
} | {
|
|
114
104
|
schema: string;
|
|
115
105
|
status: string;
|
|
116
|
-
fromId:
|
|
117
|
-
toId:
|
|
118
|
-
edits:
|
|
106
|
+
fromId: string;
|
|
107
|
+
toId: string;
|
|
108
|
+
edits: {
|
|
109
|
+
path: string;
|
|
110
|
+
kind: string;
|
|
111
|
+
from: string;
|
|
112
|
+
to: string;
|
|
113
|
+
}[];
|
|
119
114
|
virtualModule: string;
|
|
120
115
|
error?: undefined;
|
|
121
116
|
};
|
|
122
|
-
export declare function localeHasErrors(report:
|
|
117
|
+
export declare function localeHasErrors(report: {
|
|
118
|
+
diagnostics?: Array<{
|
|
119
|
+
severity?: string;
|
|
120
|
+
}>;
|
|
121
|
+
}): boolean;
|
package/dist/locale-check.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
/**
|
|
3
2
|
* Locale check + message contracts / typed module projection.
|
|
4
3
|
*
|
|
@@ -10,9 +9,6 @@ import { loadLocalePlan, mapPlanDiagnostics, parseAuthorInput } from './author-i
|
|
|
10
9
|
import { DIAG_CATALOG_CONFLICT, DIAG_CATALOG_PARSE, DIAG_DIR_MISSING, DIAG_DIR_ORPHAN, DIAG_ID_INVALID, DIAG_LAYOUT_ILLEGAL, DIAG_MANIFEST_MISSING, DIAG_MESSAGE_ARRAY_FORBIDDEN, DIAG_MESSAGE_HTML_FORBIDDEN, DIAG_MESSAGE_MISSING_DEFAULT, DIAG_MESSAGE_MISSING_VARIANT, DIAG_MESSAGE_PARAMETER_MISMATCH, DIAG_MESSAGE_SYNTAX_INVALID, DIAG_MESSAGE_UNUSED, LOCALE_CHECK_SCHEMA, LOCALE_ID_RE, LOCALE_MANIFEST_SCHEMA, LOCALE_RESERVED_TOP, LOCALE_TYPED_MODULE_SCHEMA, LOCALE_VIRTUAL_MODULE_PREFIX, MESSAGE_CATALOG_SCHEMA, MESSAGE_NODE_SCHEMA, } from './locale-schema.js';
|
|
11
10
|
import { requireNativeAddon } from './native-addon.js';
|
|
12
11
|
import { writePrettyJsonFile } from './pretty-json.js';
|
|
13
|
-
/**
|
|
14
|
-
* @param {string} literal
|
|
15
|
-
*/
|
|
16
12
|
export function validateLocaleId(literal) {
|
|
17
13
|
const name = String(literal || '');
|
|
18
14
|
if (!name)
|
|
@@ -34,14 +30,8 @@ export function validateLocaleId(literal) {
|
|
|
34
30
|
/**
|
|
35
31
|
* Flatten catalog object into MessageId → string template.
|
|
36
32
|
* Arrays are forbidden.
|
|
37
|
-
* @param {any} node
|
|
38
|
-
* @param {string} prefix
|
|
39
|
-
* @param {Array<{code:string,severity:string,message:string,path?:string}>} diagnostics
|
|
40
|
-
* @param {string} sourcePath
|
|
41
|
-
* @returns {Map<string, string>}
|
|
42
33
|
*/
|
|
43
34
|
export function flattenCatalog(node, prefix, diagnostics, sourcePath) {
|
|
44
|
-
/** @type {Map<string, string>} */
|
|
45
35
|
const out = new Map();
|
|
46
36
|
if (node == null || typeof node !== 'object') {
|
|
47
37
|
diagnostics.push({
|
|
@@ -101,12 +91,9 @@ export function flattenCatalog(node, prefix, diagnostics, sourcePath) {
|
|
|
101
91
|
}
|
|
102
92
|
/**
|
|
103
93
|
* ICU MessageFormat compatible subset: extract argument names + kinds.
|
|
104
|
-
* @param {string} template
|
|
105
|
-
* @returns {{ ok: boolean, params: Array<{ name: string, kind: string }>, error?: string }}
|
|
106
94
|
*/
|
|
107
95
|
export function extractMessageParams(template) {
|
|
108
96
|
const text = String(template ?? '');
|
|
109
|
-
/** @type {Map<string, string>} */
|
|
110
97
|
const params = new Map();
|
|
111
98
|
let i = 0;
|
|
112
99
|
while (i < text.length) {
|
|
@@ -181,7 +168,6 @@ function findMatchingBrace(text, openIdx) {
|
|
|
181
168
|
return -1;
|
|
182
169
|
}
|
|
183
170
|
function splitTopLevel(text, sep) {
|
|
184
|
-
/** @type {string[]} */
|
|
185
171
|
const parts = [];
|
|
186
172
|
let depth = 0;
|
|
187
173
|
let start = 0;
|
|
@@ -199,15 +185,9 @@ function splitTopLevel(text, sep) {
|
|
|
199
185
|
parts.push(text.slice(start));
|
|
200
186
|
return parts;
|
|
201
187
|
}
|
|
202
|
-
/**
|
|
203
|
-
* Detect fallback cycles (explicit DAG).
|
|
204
|
-
* @param {Record<string, string[]>} fallback
|
|
205
|
-
* @param {Set<string>} known
|
|
206
|
-
*/
|
|
188
|
+
/** Detect fallback cycles (explicit DAG). */
|
|
207
189
|
export function findFallbackCycles(fallback, known) {
|
|
208
|
-
/** @type {string[]} */
|
|
209
190
|
const cycles = [];
|
|
210
|
-
/** @type {string[]} */
|
|
211
191
|
const unknown = [];
|
|
212
192
|
for (const [from, tos] of Object.entries(fallback || {})) {
|
|
213
193
|
if (!known.has(from))
|
|
@@ -218,9 +198,7 @@ export function findFallbackCycles(fallback, known) {
|
|
|
218
198
|
}
|
|
219
199
|
}
|
|
220
200
|
for (const start of Object.keys(fallback || {})) {
|
|
221
|
-
/** @type {Set<string>} */
|
|
222
201
|
const stack = new Set();
|
|
223
|
-
/** @type {string[]} */
|
|
224
202
|
const path = [];
|
|
225
203
|
const visit = (node) => {
|
|
226
204
|
if (stack.has(node)) {
|
|
@@ -240,13 +218,9 @@ export function findFallbackCycles(fallback, known) {
|
|
|
240
218
|
}
|
|
241
219
|
return { cycles: [...new Set(cycles)], unknown: [...new Set(unknown)] };
|
|
242
220
|
}
|
|
243
|
-
/**
|
|
244
|
-
* @param {{ projectRoot: string, strict?: boolean, checkUnused?: boolean }} opts
|
|
245
|
-
*/
|
|
246
221
|
export function checkLocales(opts) {
|
|
247
222
|
const projectRoot = path.resolve(opts.projectRoot);
|
|
248
223
|
const localesRoot = path.join(projectRoot, 'locales');
|
|
249
|
-
/** @type {Array<{ code: string, severity: string, message: string, path?: string }>} */
|
|
250
224
|
const diagnostics = [];
|
|
251
225
|
const plan = loadLocalePlan(projectRoot);
|
|
252
226
|
diagnostics.push(...mapPlanDiagnostics(plan.diagnostics));
|
|
@@ -255,15 +229,12 @@ export function checkLocales(opts) {
|
|
|
255
229
|
return emptyReport(projectRoot, diagnostics);
|
|
256
230
|
}
|
|
257
231
|
const localeEntries = plan.locales || [];
|
|
258
|
-
/** @type {string[]} */
|
|
259
232
|
const orderedIds = localeEntries.map((e) => e.id);
|
|
260
|
-
/** @type {Set<string>} */
|
|
261
233
|
const seen = new Set(orderedIds);
|
|
262
234
|
const defaultLocale = String(plan.defaultLocale || '');
|
|
263
235
|
const fallback = plan.fallback && typeof plan.fallback === 'object' ? plan.fallback : {};
|
|
264
236
|
const missingPolicy = plan.missing || 'error';
|
|
265
237
|
const routing = plan.routing || { strategy: 'prefix', defaultPrefix: 'include' };
|
|
266
|
-
/** @type {string[]} */
|
|
267
238
|
const diskLocales = [];
|
|
268
239
|
if (fs.existsSync(localesRoot)) {
|
|
269
240
|
for (const ent of fs.readdirSync(localesRoot, { withFileTypes: true })) {
|
|
@@ -311,9 +282,7 @@ export function checkLocales(opts) {
|
|
|
311
282
|
});
|
|
312
283
|
}
|
|
313
284
|
}
|
|
314
|
-
/** @type {Map<string, { messageId: string, catalogId: string, variants: Record<string, { template: string, params: any[], path: string }> }>} */
|
|
315
285
|
const messages = new Map();
|
|
316
|
-
/** @type {string[]} */
|
|
317
286
|
const catalogIds = [];
|
|
318
287
|
for (const locale of orderedIds) {
|
|
319
288
|
const dir = path.join(localesRoot, locale);
|
|
@@ -324,7 +293,6 @@ export function checkLocales(opts) {
|
|
|
324
293
|
const catalogId = rel.replace(/\.(json5|json|ya?ml)$/i, '').replace(/\//g, '.');
|
|
325
294
|
if (!catalogIds.includes(catalogId))
|
|
326
295
|
catalogIds.push(catalogId);
|
|
327
|
-
/** @type {any} */
|
|
328
296
|
let parsed = null;
|
|
329
297
|
try {
|
|
330
298
|
const text = fs.readFileSync(fileAbs, 'utf8');
|
|
@@ -340,10 +308,11 @@ export function checkLocales(opts) {
|
|
|
340
308
|
parsed = parseAuthorInput(text);
|
|
341
309
|
}
|
|
342
310
|
catch (e) {
|
|
311
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
343
312
|
diagnostics.push({
|
|
344
313
|
code: DIAG_CATALOG_PARSE,
|
|
345
314
|
severity: 'error',
|
|
346
|
-
message: `catalog parse failed: ${
|
|
315
|
+
message: `catalog parse failed: ${msg}`,
|
|
347
316
|
path: path.relative(projectRoot, fileAbs).replace(/\\/g, '/'),
|
|
348
317
|
});
|
|
349
318
|
return;
|
|
@@ -421,7 +390,6 @@ export function checkLocales(opts) {
|
|
|
421
390
|
}
|
|
422
391
|
}
|
|
423
392
|
const used = scanLocaleUsages(projectRoot);
|
|
424
|
-
/** @type {any[]} */
|
|
425
393
|
const typedModules = [];
|
|
426
394
|
const byCatalog = new Map();
|
|
427
395
|
for (const node of messages.values()) {
|
|
@@ -430,7 +398,6 @@ export function checkLocales(opts) {
|
|
|
430
398
|
byCatalog.get(node.catalogId).push(node);
|
|
431
399
|
}
|
|
432
400
|
for (const [catalogId, nodes] of byCatalog) {
|
|
433
|
-
/** @type {Map<string, number>} */
|
|
434
401
|
const leafCount = new Map();
|
|
435
402
|
for (const n of nodes) {
|
|
436
403
|
const leaf = leafExportName(n.messageId);
|
|
@@ -549,11 +516,8 @@ function walkCatalogFiles(dir, fn) {
|
|
|
549
516
|
* First-slice heuristic — full VPG edges land with compiler deepen.
|
|
550
517
|
*/
|
|
551
518
|
export function scanLocaleUsages(projectRoot) {
|
|
552
|
-
/** @type {Set<string>} */
|
|
553
519
|
const catalogs = new Set();
|
|
554
|
-
/** @type {Set<string>} */
|
|
555
520
|
const messageIds = new Set();
|
|
556
|
-
/** @type {Map<string, Set<string>>} */
|
|
557
521
|
const importedNames = new Map();
|
|
558
522
|
const src = path.join(projectRoot, 'src');
|
|
559
523
|
if (!fs.existsSync(src))
|
|
@@ -592,14 +556,9 @@ function walkSource(dir, fn) {
|
|
|
592
556
|
fn(full);
|
|
593
557
|
}
|
|
594
558
|
}
|
|
595
|
-
/**
|
|
596
|
-
* Emit typed module stubs for `#locales/*` ( surface).
|
|
597
|
-
* @param {ReturnType<typeof checkLocales>} report
|
|
598
|
-
* @param {string} outDir
|
|
599
|
-
*/
|
|
559
|
+
/** Emit typed module stubs for `#locales/*`. */
|
|
600
560
|
export function emitLocaleTypedModules(report, outDir) {
|
|
601
561
|
fs.mkdirSync(outDir, { recursive: true });
|
|
602
|
-
/** @type {string[]} */
|
|
603
562
|
const written = [];
|
|
604
563
|
const native = requireNativeAddon();
|
|
605
564
|
if (typeof native.generateLocaleTypedModule !== 'function') {
|
|
@@ -630,10 +589,6 @@ export function emitLocaleTypedModules(report, outDir) {
|
|
|
630
589
|
*
|
|
631
590
|
* Variant pick reads `html[data-locale]` (else defaultLocale). Thin bridge until
|
|
632
591
|
* host LocaleTransition reloads locale-scoped chunks (I2/I4).
|
|
633
|
-
*
|
|
634
|
-
* @param {string} projectRoot
|
|
635
|
-
* @param {string} distDir
|
|
636
|
-
* @returns {{ ok: boolean, written: string[], diagnostics: any[] }}
|
|
637
592
|
*/
|
|
638
593
|
export function emitLocaleRuntimeModules(projectRoot, distDir) {
|
|
639
594
|
const report = checkLocales({ projectRoot, checkUnused: false });
|
|
@@ -646,7 +601,6 @@ export function emitLocaleRuntimeModules(projectRoot, distDir) {
|
|
|
646
601
|
}
|
|
647
602
|
const defaultLocale = report.manifest.defaultLocale || 'zh-hans';
|
|
648
603
|
const byId = new Map((report.messageCatalog?.messages || []).map((m) => [m.messageId, m]));
|
|
649
|
-
/** @type {string[]} */
|
|
650
604
|
const written = [];
|
|
651
605
|
const localesOut = path.join(distDir, 'locales');
|
|
652
606
|
fs.mkdirSync(localesOut, { recursive: true });
|
|
@@ -654,7 +608,6 @@ export function emitLocaleRuntimeModules(projectRoot, distDir) {
|
|
|
654
608
|
const exports = [];
|
|
655
609
|
for (const exp of mod.exports || []) {
|
|
656
610
|
const node = byId.get(exp.messageId);
|
|
657
|
-
/** @type {string[][]} */
|
|
658
611
|
const variants = [];
|
|
659
612
|
if (node?.variants) {
|
|
660
613
|
for (const [loc, v] of Object.entries(node.variants)) {
|
|
@@ -680,11 +633,7 @@ export function emitLocaleRuntimeModules(projectRoot, distDir) {
|
|
|
680
633
|
rewriteLocaleImportsInDist(distDir);
|
|
681
634
|
return { ok: true, written, diagnostics: report.diagnostics || [] };
|
|
682
635
|
}
|
|
683
|
-
/**
|
|
684
|
-
* @param {string} distDir
|
|
685
|
-
*/
|
|
686
636
|
function rewriteLocaleImportsInDist(distDir) {
|
|
687
|
-
/** @type {string[]} */
|
|
688
637
|
const files = [];
|
|
689
638
|
walkDistJs(distDir, (file) => files.push(file));
|
|
690
639
|
for (const file of files) {
|
|
@@ -704,10 +653,6 @@ function rewriteLocaleImportsInDist(distDir) {
|
|
|
704
653
|
fs.writeFileSync(file, next, 'utf8');
|
|
705
654
|
}
|
|
706
655
|
}
|
|
707
|
-
/**
|
|
708
|
-
* @param {string} dir
|
|
709
|
-
* @param {(file: string) => void} fn
|
|
710
|
-
*/
|
|
711
656
|
function walkDistJs(dir, fn) {
|
|
712
657
|
if (!fs.existsSync(dir))
|
|
713
658
|
return;
|
|
@@ -723,12 +668,7 @@ function walkDistJs(dir, fn) {
|
|
|
723
668
|
}
|
|
724
669
|
}
|
|
725
670
|
}
|
|
726
|
-
/**
|
|
727
|
-
* MessageId rename plan — WorkspaceEdit-shaped, no parallel rename IR.
|
|
728
|
-
* @param {ReturnType<typeof checkLocales>} report
|
|
729
|
-
* @param {string} fromId
|
|
730
|
-
* @param {string} toId
|
|
731
|
-
*/
|
|
671
|
+
/** MessageId rename plan — WorkspaceEdit-shaped, no parallel rename IR. */
|
|
732
672
|
export function planLocaleRename(report, fromId, toId) {
|
|
733
673
|
const node = (report.messageCatalog?.messages || []).find((m) => m.messageId === fromId);
|
|
734
674
|
if (!node) {
|
|
@@ -741,7 +681,6 @@ export function planLocaleRename(report, fromId, toId) {
|
|
|
741
681
|
error: `unknown MessageId ${fromId}`,
|
|
742
682
|
};
|
|
743
683
|
}
|
|
744
|
-
/** @type {Array<{ path: string, kind: string, from: string, to: string }>} */
|
|
745
684
|
const edits = [];
|
|
746
685
|
for (const variant of Object.values(node.variants || {})) {
|
|
747
686
|
edits.push({
|
package/dist/locale-cmd.d.ts
CHANGED