@vmz/vmz 0.1.16 → 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-router.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
/**
|
|
3
2
|
* Locale router / PageMeta: route realization · canonical · hreflang ·
|
|
4
3
|
* Link locale retain · locale-aware cache key.
|
|
@@ -7,9 +6,6 @@
|
|
|
7
6
|
*/
|
|
8
7
|
import { negotiateLocale } from './locale-runtime.js';
|
|
9
8
|
import { DIAG_LOCALE_CACHE_KEY_STEALS_CONTENT, DIAG_LOCALE_CANONICAL_MISSING, DIAG_LOCALE_HREFLANG_INCOMPLETE, DIAG_LOCALE_LINK_HARDCODED_PATH, DIAG_LOCALE_META_LOCALE_MISMATCH, DIAG_LOCALE_PREFIX_OMIT_WITHOUT_REDIRECT, DIAG_LOCALE_ROUTE_COLLISION, LOCALE_LINK_RESOLUTION_SCHEMA, LOCALE_PAGE_META_SCHEMA, LOCALE_ROUTE_REALIZATION_SCHEMA, LOCALE_ROUTER_CHECK_SCHEMA, } from './locale-schema.js';
|
|
10
|
-
/**
|
|
11
|
-
* @param {string} path
|
|
12
|
-
*/
|
|
13
9
|
function normalizePath(path) {
|
|
14
10
|
let p = String(path || '/');
|
|
15
11
|
if (!p.startsWith('/'))
|
|
@@ -18,12 +14,7 @@ function normalizePath(path) {
|
|
|
18
14
|
p = p.slice(0, -1);
|
|
19
15
|
return p || '/';
|
|
20
16
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Join locale prefix with a stable route path pattern.
|
|
23
|
-
* @param {string} localeId
|
|
24
|
-
* @param {string} pathPattern stable path without locale (e.g. /account/profile)
|
|
25
|
-
* @param {{ strategy?: string, defaultPrefix?: string, defaultLocale?: string }} routing
|
|
26
|
-
*/
|
|
17
|
+
/** Join locale prefix with a stable route path pattern. */
|
|
27
18
|
export function realizeRoutePath(localeId, pathPattern, routing = {}) {
|
|
28
19
|
const strategy = routing.strategy || 'prefix';
|
|
29
20
|
const defaultPrefix = routing.defaultPrefix || 'include';
|
|
@@ -60,26 +51,15 @@ export function realizeRoutePath(localeId, pathPattern, routing = {}) {
|
|
|
60
51
|
defaultPrefix,
|
|
61
52
|
};
|
|
62
53
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Build RouteId × LocaleId realization table.
|
|
65
|
-
* @param {{
|
|
66
|
-
* routes: Array<{ routeId: string, path: string }>,
|
|
67
|
-
* locales: string[],
|
|
68
|
-
* defaultLocale: string,
|
|
69
|
-
* routing?: { strategy?: string, defaultPrefix?: string },
|
|
70
|
-
* }} input
|
|
71
|
-
*/
|
|
54
|
+
/** Build RouteId × LocaleId realization table. */
|
|
72
55
|
export function buildLocaleRouteRealizationTable(input) {
|
|
73
56
|
const routing = {
|
|
74
57
|
strategy: input.routing?.strategy || 'prefix',
|
|
75
58
|
defaultPrefix: input.routing?.defaultPrefix || 'include',
|
|
76
59
|
defaultLocale: input.defaultLocale,
|
|
77
60
|
};
|
|
78
|
-
/** @type {any[]} */
|
|
79
61
|
const realizations = [];
|
|
80
|
-
/** @type {Map<string, string>} */
|
|
81
62
|
const pathOwners = new Map();
|
|
82
|
-
/** @type {any[]} */
|
|
83
63
|
const diagnostics = [];
|
|
84
64
|
for (const route of input.routes || []) {
|
|
85
65
|
for (const localeId of input.locales || []) {
|
|
@@ -129,34 +109,16 @@ export function buildLocaleRouteRealizationTable(input) {
|
|
|
129
109
|
diagnostics,
|
|
130
110
|
};
|
|
131
111
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Absolute URL helper.
|
|
134
|
-
* @param {string} origin
|
|
135
|
-
* @param {string} path
|
|
136
|
-
*/
|
|
112
|
+
/** Absolute URL helper. */
|
|
137
113
|
export function absoluteUrl(origin, path) {
|
|
138
114
|
const o = String(origin || '').replace(/\/$/, '');
|
|
139
115
|
const p = normalizePath(path);
|
|
140
116
|
return `${o}${p}`;
|
|
141
117
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Locale-aware PageMeta for one RouteId × LocaleId.
|
|
144
|
-
* @param {{
|
|
145
|
-
* routeId: string,
|
|
146
|
-
* localeId: string,
|
|
147
|
-
* direction?: string,
|
|
148
|
-
* title: string,
|
|
149
|
-
* description?: string,
|
|
150
|
-
* origin: string,
|
|
151
|
-
* realizations: Array<{ routeId: string, localeId: string, path: string }>,
|
|
152
|
-
* locales: string[],
|
|
153
|
-
* defaultLocale: string,
|
|
154
|
-
* }} input
|
|
155
|
-
*/
|
|
118
|
+
/** Locale-aware PageMeta for one RouteId × LocaleId. */
|
|
156
119
|
export function buildLocalePageMeta(input) {
|
|
157
120
|
const forRoute = (input.realizations || []).filter((r) => r.routeId === input.routeId);
|
|
158
121
|
const self = forRoute.find((r) => r.localeId === input.localeId);
|
|
159
|
-
/** @type {any[]} */
|
|
160
122
|
const diagnostics = [];
|
|
161
123
|
if (!self?.path) {
|
|
162
124
|
diagnostics.push({
|
|
@@ -167,7 +129,6 @@ export function buildLocalePageMeta(input) {
|
|
|
167
129
|
}
|
|
168
130
|
const canonicalPath = self?.path || '/';
|
|
169
131
|
const canonical = absoluteUrl(input.origin, canonicalPath);
|
|
170
|
-
/** @type {Array<{ localeId: string, hreflang: string, href: string }>} */
|
|
171
132
|
const alternates = [];
|
|
172
133
|
for (const loc of input.locales || []) {
|
|
173
134
|
const hit = forRoute.find((r) => r.localeId === loc);
|
|
@@ -207,14 +168,7 @@ export function buildLocalePageMeta(input) {
|
|
|
207
168
|
status: diagnostics.length ? 'failed' : 'ready',
|
|
208
169
|
};
|
|
209
170
|
}
|
|
210
|
-
/**
|
|
211
|
-
* `<Link to="routeId">` retains current locale — never hand-written localized paths.
|
|
212
|
-
* @param {{
|
|
213
|
-
* to: string,
|
|
214
|
-
* currentLocale: string,
|
|
215
|
-
* realizations: Array<{ routeId: string, localeId: string, path: string }>,
|
|
216
|
-
* }} input
|
|
217
|
-
*/
|
|
171
|
+
/** `<Link to="routeId">` retains current locale — never hand-written localized paths. */
|
|
218
172
|
export function resolveLinkHref(input) {
|
|
219
173
|
const to = input.to;
|
|
220
174
|
if (typeof to === 'string' && (to.startsWith('/') || /^https?:/i.test(to))) {
|
|
@@ -263,11 +217,7 @@ export function resolveLinkHref(input) {
|
|
|
263
217
|
diagnostics: [],
|
|
264
218
|
};
|
|
265
219
|
}
|
|
266
|
-
/**
|
|
267
|
-
* Parse locale prefix from a pathname under prefix strategy.
|
|
268
|
-
* @param {string} pathname
|
|
269
|
-
* @param {string[]} supportedLocales
|
|
270
|
-
*/
|
|
220
|
+
/** Parse locale prefix from a pathname under prefix strategy. */
|
|
271
221
|
export function parseLocaleFromPath(pathname, supportedLocales) {
|
|
272
222
|
const parts = normalizePath(pathname).split('/').filter(Boolean);
|
|
273
223
|
if (!parts.length)
|
|
@@ -278,17 +228,7 @@ export function parseLocaleFromPath(pathname, supportedLocales) {
|
|
|
278
228
|
}
|
|
279
229
|
return { localeId: null, restPath: normalizePath(pathname) };
|
|
280
230
|
}
|
|
281
|
-
/**
|
|
282
|
-
* Rewrite a same-app href to the given LocaleId via route realization.
|
|
283
|
-
* Stable path (no locale) is recovered first, then re-realized — Link never hardcodes locale.
|
|
284
|
-
* @param {string} href
|
|
285
|
-
* @param {string} localeId
|
|
286
|
-
* @param {{
|
|
287
|
-
* locales?: Array<{ id: string }|string>,
|
|
288
|
-
* defaultLocale?: string,
|
|
289
|
-
* routing?: { strategy?: string, defaultPrefix?: string, defaultLocale?: string },
|
|
290
|
-
* }} artifact
|
|
291
|
-
*/
|
|
231
|
+
/** Rewrite a same-app href to the given LocaleId via route realization. */
|
|
292
232
|
export function localizeSameAppHref(href, localeId, artifact) {
|
|
293
233
|
if (!href || !localeId || !artifact)
|
|
294
234
|
return href;
|
|
@@ -323,13 +263,7 @@ export function localizeSameAppHref(href, localeId, artifact) {
|
|
|
323
263
|
const realized = realizeRoutePath(localeId, rest, routing);
|
|
324
264
|
return `${realized.path}${search}${hash}`;
|
|
325
265
|
}
|
|
326
|
-
/**
|
|
327
|
-
* Rewrite `<a data-vmz-route href>` in HTML body to retain `localeId`.
|
|
328
|
-
* @param {string} html
|
|
329
|
-
* @param {string} localeId
|
|
330
|
-
* @param {Parameters<typeof localizeSameAppHref>[2]} artifact
|
|
331
|
-
* @param {(s: string) => string} [escapeAttr]
|
|
332
|
-
*/
|
|
266
|
+
/** Rewrite `<a data-vmz-route href>` in HTML body to retain `localeId`. */
|
|
333
267
|
export function localizeBodyLinks(html, localeId, artifact, escapeAttr = (s) => String(s).replace(/&/g, '&').replace(/"/g, '"')) {
|
|
334
268
|
if (!html || !localeId || !artifact)
|
|
335
269
|
return html;
|
|
@@ -346,18 +280,7 @@ export function localizeBodyLinks(html, localeId, artifact, escapeAttr = (s) =>
|
|
|
346
280
|
return `<a${newAttrs}>`;
|
|
347
281
|
});
|
|
348
282
|
}
|
|
349
|
-
/**
|
|
350
|
-
* Plan redirect / negotiation for an incoming URL (omit-prefix aware).
|
|
351
|
-
* @param {{
|
|
352
|
-
* pathname: string,
|
|
353
|
-
* supportedLocales: string[],
|
|
354
|
-
* defaultLocale: string,
|
|
355
|
-
* routing?: { strategy?: string, defaultPrefix?: string },
|
|
356
|
-
* hostCandidates?: string[],
|
|
357
|
-
* preference?: string|null,
|
|
358
|
-
* userChoice?: string|null,
|
|
359
|
-
* }} input
|
|
360
|
-
*/
|
|
283
|
+
/** Plan redirect / negotiation for an incoming URL (omit-prefix aware). */
|
|
361
284
|
export function planLocalePathNavigation(input) {
|
|
362
285
|
const routing = {
|
|
363
286
|
strategy: input.routing?.strategy || 'prefix',
|
|
@@ -373,7 +296,6 @@ export function planLocalePathNavigation(input) {
|
|
|
373
296
|
preference: input.preference,
|
|
374
297
|
hostCandidates: input.hostCandidates,
|
|
375
298
|
});
|
|
376
|
-
/** @type {any[]} */
|
|
377
299
|
const diagnostics = [];
|
|
378
300
|
let redirectTo = null;
|
|
379
301
|
if (routing.strategy === 'prefix' && routing.defaultPrefix === 'omit') {
|
|
@@ -411,19 +333,12 @@ export function planLocalePathNavigation(input) {
|
|
|
411
333
|
contentLocale: routing.defaultPrefix === 'omit' && !parsed.localeId ? input.defaultLocale : negotiated,
|
|
412
334
|
};
|
|
413
335
|
}
|
|
414
|
-
/**
|
|
415
|
-
* Locale-aware cache key — must include LocaleId so Accept-Language cannot steal content.
|
|
416
|
-
* @param {{ routeId: string, localeId: string, path: string }} input
|
|
417
|
-
*/
|
|
336
|
+
/** Locale-aware cache key — must include LocaleId so Accept-Language cannot steal content. */
|
|
418
337
|
export function localeAwareCacheKey(input) {
|
|
419
338
|
return `locale=${input.localeId}|route=${input.routeId}|path=${normalizePath(input.path)}`;
|
|
420
339
|
}
|
|
421
|
-
/**
|
|
422
|
-
* Reject Vary: Accept-Language on a cache key that does not encode LocaleId.
|
|
423
|
-
* @param {{ cacheKey: string, varyAcceptLanguage?: boolean, localeId?: string }} input
|
|
424
|
-
*/
|
|
340
|
+
/** Reject Vary: Accept-Language on a cache key that does not encode LocaleId. */
|
|
425
341
|
export function assertLocaleCacheKey(input) {
|
|
426
|
-
/** @type {any[]} */
|
|
427
342
|
const diagnostics = [];
|
|
428
343
|
const key = String(input.cacheKey || '');
|
|
429
344
|
const hasLocale = /(?:^|[|&])locale=/.test(key) || (input.localeId && key.includes(input.localeId));
|
|
@@ -436,18 +351,8 @@ export function assertLocaleCacheKey(input) {
|
|
|
436
351
|
}
|
|
437
352
|
return { ok: diagnostics.length === 0, diagnostics };
|
|
438
353
|
}
|
|
439
|
-
/**
|
|
440
|
-
* LocaleTransition must commit Route realization + PageMeta together.
|
|
441
|
-
* @param {{
|
|
442
|
-
* fromLocale: string,
|
|
443
|
-
* toLocale: string,
|
|
444
|
-
* routeId: string,
|
|
445
|
-
* realizations: Array<{ routeId: string, localeId: string, path: string }>,
|
|
446
|
-
* pageMetaByLocale: Record<string, { locale: string, canonical: string }>,
|
|
447
|
-
* }} input
|
|
448
|
-
*/
|
|
354
|
+
/** LocaleTransition must commit Route realization + PageMeta together. */
|
|
449
355
|
export function commitLocaleRouteMetaTransition(input) {
|
|
450
|
-
/** @type {any[]} */
|
|
451
356
|
const diagnostics = [];
|
|
452
357
|
const fromPath = (input.realizations || []).find((r) => r.routeId === input.routeId && r.localeId === input.fromLocale)?.path;
|
|
453
358
|
const toPath = (input.realizations || []).find((r) => r.routeId === input.routeId && r.localeId === input.toLocale)?.path;
|
|
@@ -485,21 +390,8 @@ export function commitLocaleRouteMetaTransition(input) {
|
|
|
485
390
|
diagnostics,
|
|
486
391
|
};
|
|
487
392
|
}
|
|
488
|
-
/**
|
|
489
|
-
* Aggregate router/meta proof.
|
|
490
|
-
* @param {{
|
|
491
|
-
* manifest: {
|
|
492
|
-
* defaultLocale: string,
|
|
493
|
-
* locales: Array<{ id: string, direction?: string }>,
|
|
494
|
-
* routing?: { strategy?: string, defaultPrefix?: string },
|
|
495
|
-
* },
|
|
496
|
-
* routes: Array<{ routeId: string, path: string }>,
|
|
497
|
-
* titles?: Record<string, Record<string, string>>,
|
|
498
|
-
* origin?: string,
|
|
499
|
-
* }} input
|
|
500
|
-
*/
|
|
393
|
+
/** Aggregate router/meta proof. */
|
|
501
394
|
export function checkLocaleRouter(input) {
|
|
502
|
-
/** @type {any[]} */
|
|
503
395
|
const diagnostics = [];
|
|
504
396
|
const locales = (input.manifest?.locales || []).map((l) => l.id);
|
|
505
397
|
const directions = Object.fromEntries((input.manifest?.locales || []).map((l) => [l.id, l.direction || 'ltr']));
|
|
@@ -512,7 +404,6 @@ export function checkLocaleRouter(input) {
|
|
|
512
404
|
});
|
|
513
405
|
diagnostics.push(...table.diagnostics);
|
|
514
406
|
const origin = input.origin || 'https://example.test';
|
|
515
|
-
/** @type {any[]} */
|
|
516
407
|
const pageMetas = [];
|
|
517
408
|
for (const route of input.routes || []) {
|
|
518
409
|
for (const loc of locales) {
|