@parlajs/compiler 0.0.0-stage → 0.0.0
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/LICENSE +21 -0
- package/README.md +21 -2
- package/build/build.d.ts +18 -0
- package/build/build.d.ts.map +1 -0
- package/build/build.js +10 -0
- package/build/cli.d.ts +3 -0
- package/build/cli.d.ts.map +1 -0
- package/build/cli.js +8 -0
- package/build/command.d.ts +13 -0
- package/build/command.d.ts.map +1 -0
- package/build/command.js +156 -0
- package/build/compile/code.d.ts +13 -0
- package/build/compile/code.d.ts.map +1 -0
- package/build/compile/code.js +42 -0
- package/build/compile/compile.d.ts +11 -0
- package/build/compile/compile.d.ts.map +1 -0
- package/build/compile/compile.js +244 -0
- package/build/compile/error.d.ts +4 -0
- package/build/compile/error.d.ts.map +1 -0
- package/build/compile/error.js +3 -0
- package/build/compile/info.d.ts +49 -0
- package/build/compile/info.d.ts.map +1 -0
- package/build/compile/info.js +22 -0
- package/build/compile/scope.d.ts +7 -0
- package/build/compile/scope.d.ts.map +1 -0
- package/build/compile/scope.js +14 -0
- package/build/compile/single.d.ts +11 -0
- package/build/compile/single.d.ts.map +1 -0
- package/build/compile/single.js +36 -0
- package/build/compile/variants.d.ts +16 -0
- package/build/compile/variants.d.ts.map +1 -0
- package/build/compile/variants.js +48 -0
- package/build/compile.d.ts +61 -0
- package/build/compile.d.ts.map +1 -0
- package/build/compile.js +385 -0
- package/build/config/checks.d.ts +21 -0
- package/build/config/checks.d.ts.map +1 -0
- package/build/config/checks.js +97 -0
- package/build/config/config.d.ts +71 -0
- package/build/config/config.d.ts.map +1 -0
- package/build/config/config.js +7 -0
- package/build/config/fallbacks.d.ts +6 -0
- package/build/config/fallbacks.d.ts.map +1 -0
- package/build/config/fallbacks.js +13 -0
- package/build/config/import.d.ts +31 -0
- package/build/config/import.d.ts.map +1 -0
- package/build/config/import.js +115 -0
- package/build/config/load.d.ts +13 -0
- package/build/config/load.d.ts.map +1 -0
- package/build/config/load.js +59 -0
- package/build/config.d.ts +77 -0
- package/build/config.d.ts.map +1 -0
- package/build/config.js +223 -0
- package/build/diagnostics.d.ts +31 -0
- package/build/diagnostics.d.ts.map +1 -0
- package/build/diagnostics.js +41 -0
- package/build/generate/checks.d.ts +9 -0
- package/build/generate/checks.d.ts.map +1 -0
- package/build/generate/checks.js +93 -0
- package/build/generate/chunk.d.ts +11 -0
- package/build/generate/chunk.d.ts.map +1 -0
- package/build/generate/chunk.js +57 -0
- package/build/generate/digits.d.ts +8 -0
- package/build/generate/digits.d.ts.map +1 -0
- package/build/generate/digits.js +57 -0
- package/build/generate/files.d.ts +7 -0
- package/build/generate/files.d.ts.map +1 -0
- package/build/generate/files.js +59 -0
- package/build/generate/locale.d.ts +21 -0
- package/build/generate/locale.d.ts.map +1 -0
- package/build/generate/locale.js +108 -0
- package/build/generate/modules.d.ts +27 -0
- package/build/generate/modules.d.ts.map +1 -0
- package/build/generate/modules.js +61 -0
- package/build/generate/namespace.d.ts +19 -0
- package/build/generate/namespace.d.ts.map +1 -0
- package/build/generate/namespace.js +65 -0
- package/build/generate/namespaces.d.ts +5 -0
- package/build/generate/namespaces.d.ts.map +1 -0
- package/build/generate/namespaces.js +41 -0
- package/build/generate/read.d.ts +21 -0
- package/build/generate/read.d.ts.map +1 -0
- package/build/generate/read.js +115 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +7 -0
- package/build/init/detect.d.ts +43 -0
- package/build/init/detect.d.ts.map +1 -0
- package/build/init/detect.js +69 -0
- package/build/init/init.d.ts +12 -0
- package/build/init/init.d.ts.map +1 -0
- package/build/init/init.js +126 -0
- package/build/options/date.d.ts +3 -0
- package/build/options/date.d.ts.map +1 -0
- package/build/options/date.js +77 -0
- package/build/options/literal.d.ts +10 -0
- package/build/options/literal.d.ts.map +1 -0
- package/build/options/literal.js +11 -0
- package/build/options/names.d.ts +5 -0
- package/build/options/names.d.ts.map +1 -0
- package/build/options/names.js +56 -0
- package/build/options/number.d.ts +3 -0
- package/build/options/number.d.ts.map +1 -0
- package/build/options/number.js +17 -0
- package/build/options/options.d.ts +7 -0
- package/build/options/options.d.ts.map +1 -0
- package/build/options/options.js +66 -0
- package/build/options.d.ts +9 -0
- package/build/options.d.ts.map +1 -0
- package/build/options.js +214 -0
- package/build/plurals.d.ts +6 -0
- package/build/plurals.d.ts.map +1 -0
- package/build/plurals.js +50 -0
- package/build/types/names.d.ts +9 -0
- package/build/types/names.d.ts.map +1 -0
- package/build/types/names.js +109 -0
- package/build/types/namespace.d.ts +17 -0
- package/build/types/namespace.d.ts.map +1 -0
- package/build/types/namespace.js +113 -0
- package/build/types/signature.d.ts +8 -0
- package/build/types/signature.d.ts.map +1 -0
- package/build/types/signature.js +87 -0
- package/build/types.d.ts +25 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +250 -0
- package/build/vite.d.ts +9 -0
- package/build/vite.d.ts.map +1 -0
- package/build/vite.js +125 -0
- package/build/watch.d.ts +12 -0
- package/build/watch.d.ts.map +1 -0
- package/build/watch.js +93 -0
- package/package.json +84 -3
- package/src/build.ts +31 -0
- package/src/cli.ts +9 -0
- package/src/command.ts +195 -0
- package/src/compile/code.ts +51 -0
- package/src/compile/compile.ts +289 -0
- package/src/compile/error.ts +3 -0
- package/src/compile/info.ts +63 -0
- package/src/compile/scope.ts +14 -0
- package/src/compile/single.ts +46 -0
- package/src/compile/variants.ts +68 -0
- package/src/config/checks.ts +140 -0
- package/src/config/config.ts +83 -0
- package/src/config/fallbacks.ts +18 -0
- package/src/config/import.ts +146 -0
- package/src/config/load.ts +75 -0
- package/src/diagnostics.ts +98 -0
- package/src/generate/checks.ts +103 -0
- package/src/generate/chunk.ts +73 -0
- package/src/generate/digits.ts +74 -0
- package/src/generate/files.ts +83 -0
- package/src/generate/locale.ts +145 -0
- package/src/generate/modules.ts +94 -0
- package/src/generate/namespace.ts +119 -0
- package/src/generate/namespaces.ts +59 -0
- package/src/generate/read.ts +159 -0
- package/src/index.ts +27 -0
- package/src/init/detect.ts +103 -0
- package/src/init/init.ts +158 -0
- package/src/options/date.ts +87 -0
- package/src/options/literal.ts +21 -0
- package/src/options/names.ts +64 -0
- package/src/options/number.ts +20 -0
- package/src/options/options.ts +75 -0
- package/src/plurals.ts +68 -0
- package/src/types/names.ts +115 -0
- package/src/types/namespace.ts +148 -0
- package/src/types/signature.ts +111 -0
- package/src/vite.ts +143 -0
- package/src/watch.ts +115 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { BUILTIN_FUNCTIONS } from '../compile/info.js';
|
|
3
|
+
import { ConfigError } from './config.js';
|
|
4
|
+
export function checkFunctions(functions) {
|
|
5
|
+
const shadowing = Object.keys(functions).filter((name) => BUILTIN_FUNCTIONS.has(name));
|
|
6
|
+
if (shadowing.length > 0) {
|
|
7
|
+
throw new ConfigError(`"functions" cannot redefine the built-in ${shadowing.map((n) => `:${n}`).join(', ')}`);
|
|
8
|
+
}
|
|
9
|
+
return functions;
|
|
10
|
+
}
|
|
11
|
+
/** Names that become path segments under `outDir`: no separators, no `..`. */
|
|
12
|
+
const NAMESPACE_NAME = /^[\w-]+(?:\.[\w-]+)*$/;
|
|
13
|
+
/** A tag `Intl` takes, such as `zh-Hant-TW`: any other would throw at the first plural or number. */
|
|
14
|
+
function checkLocale(locale) {
|
|
15
|
+
let canonical;
|
|
16
|
+
try {
|
|
17
|
+
[canonical] = Intl.getCanonicalLocales(locale);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
const tag = locale.replaceAll('_', '-');
|
|
21
|
+
const hint = tag === locale ? ' such as "en" or "pt-BR"' : `: write "${tag}"`;
|
|
22
|
+
throw new ConfigError(`Locale "${locale}" is not a locale tag${hint}`);
|
|
23
|
+
}
|
|
24
|
+
// Fallbacks match tags by their spelling: `zh-hant-tw` would never inherit from `zh-Hant`.
|
|
25
|
+
if (canonical !== locale) {
|
|
26
|
+
throw new ConfigError(`Locale "${locale}" is not canonical: write "${canonical}"`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function isInside(dir, file) {
|
|
30
|
+
const rel = path.relative(dir, file);
|
|
31
|
+
return rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
|
|
32
|
+
}
|
|
33
|
+
/** Names of files: on macOS and Windows one would overwrite the other. */
|
|
34
|
+
function checkCase(what, names) {
|
|
35
|
+
const seen = new Map();
|
|
36
|
+
for (const name of names) {
|
|
37
|
+
const other = seen.get(name.toLowerCase()) ?? name;
|
|
38
|
+
if (other !== name) {
|
|
39
|
+
throw new ConfigError(`${what} "${other}" and "${name}" differ only in case: rename one`);
|
|
40
|
+
}
|
|
41
|
+
seen.set(name.toLowerCase(), name);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** A fallback outside `locales` lends no text, only its `Intl` formats. */
|
|
45
|
+
export function checkFallbacks(fallbacks, { locales, hasCatalog, }) {
|
|
46
|
+
for (const [locale, chain] of Object.entries(fallbacks)) {
|
|
47
|
+
if (!locales.includes(locale)) {
|
|
48
|
+
throw new ConfigError(`"fallbacks" lists "${locale}", which is not in locales`);
|
|
49
|
+
}
|
|
50
|
+
for (const fallback of chain.filter((l) => !locales.includes(l))) {
|
|
51
|
+
if (hasCatalog(fallback)) {
|
|
52
|
+
throw new ConfigError(`"${locale}" falls back to "${fallback}", whose catalogs are not read: add it to locales`);
|
|
53
|
+
}
|
|
54
|
+
if (Intl.NumberFormat.supportedLocalesOf(fallback).length === 0) {
|
|
55
|
+
throw new ConfigError(`"${locale}" falls back to "${fallback}", neither in locales nor known to Intl`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Every tag `Intl` takes, each locale once, and the source locale among them. */
|
|
61
|
+
export function checkLocales({ locales, sourceLocale, fallbacks, }) {
|
|
62
|
+
for (const locale of [
|
|
63
|
+
...locales,
|
|
64
|
+
...Object.keys(fallbacks),
|
|
65
|
+
...Object.values(fallbacks).flat(),
|
|
66
|
+
]) {
|
|
67
|
+
checkLocale(locale);
|
|
68
|
+
}
|
|
69
|
+
const repeated = locales.find((l, i) => locales.indexOf(l) !== i);
|
|
70
|
+
if (repeated !== undefined) {
|
|
71
|
+
throw new ConfigError(`Locale "${repeated}" is listed twice`);
|
|
72
|
+
}
|
|
73
|
+
if (!locales.includes(sourceLocale)) {
|
|
74
|
+
throw new ConfigError(`sourceLocale "${sourceLocale}" is not in locales`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** The config's namespaces, each with its catalogs' paths, none of them in `outDir`. */
|
|
78
|
+
export function resolveNamespaces(namespaces, { root, outDir, locales }) {
|
|
79
|
+
checkCase('Namespaces', Object.keys(namespaces));
|
|
80
|
+
return Object.entries(namespaces).map(([name, ns]) => {
|
|
81
|
+
if (!NAMESPACE_NAME.test(name)) {
|
|
82
|
+
throw new ConfigError(`Namespace "${name}" must be letters, digits, "_", "-" or inner dots: it names files`);
|
|
83
|
+
}
|
|
84
|
+
if (!ns.path.includes('{locale}')) {
|
|
85
|
+
throw new ConfigError(`Namespace "${name}" path must contain {locale}`);
|
|
86
|
+
}
|
|
87
|
+
const resolved = {
|
|
88
|
+
name,
|
|
89
|
+
format: ns.format,
|
|
90
|
+
file: (locale) => path.resolve(root, ns.path.replaceAll('{locale}', locale)),
|
|
91
|
+
};
|
|
92
|
+
if (locales.some((l) => isInside(outDir, resolved.file(l)))) {
|
|
93
|
+
throw new ConfigError(`Namespace "${name}" has its catalogs in outDir, which holds generated files only: move one of them`);
|
|
94
|
+
}
|
|
95
|
+
return resolved;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Model } from 'messageformat';
|
|
2
|
+
import type { FunctionKind } from '../compile/info.ts';
|
|
3
|
+
/** Parses one message into the MF2 data model, which the compiler reads. */
|
|
4
|
+
export interface FormatAdapter {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly parse: (source: string) => Model.Message;
|
|
7
|
+
/** Reads a catalog file into `{ key: message | group }`, for files that are not JSON. */
|
|
8
|
+
readonly parseFile?: ((text: string) => unknown) | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface NamespaceConfig<Format extends string = string> {
|
|
11
|
+
/** Message syntax: a key of `formats`. */
|
|
12
|
+
format: Format;
|
|
13
|
+
/** Catalog path relative to the config, with a `{locale}` token. */
|
|
14
|
+
path: string;
|
|
15
|
+
}
|
|
16
|
+
/** `Formats` are the keys of `formats`, which a namespace's `format` may name. */
|
|
17
|
+
export interface ParlaConfig<Formats extends string = string> {
|
|
18
|
+
locales?: Array<string>;
|
|
19
|
+
sourceLocale?: string;
|
|
20
|
+
/** Extra fallback chain per locale; the source locale is always last. */
|
|
21
|
+
fallbacks?: Record<string, Array<string>>;
|
|
22
|
+
/** Where generated files go, relative to the config. Default `src/parla`. */
|
|
23
|
+
outDir?: string;
|
|
24
|
+
/** Namespaces this package owns: other packages import their built objects. */
|
|
25
|
+
namespaces?: Record<string, NamespaceConfig<NoInfer<Formats>>>;
|
|
26
|
+
/**
|
|
27
|
+
* Message functions beyond the built-in ones, by what their value is. Each needs an
|
|
28
|
+
* implementation in `createParla({ functions })`.
|
|
29
|
+
*/
|
|
30
|
+
functions?: Record<string, FunctionKind>;
|
|
31
|
+
/** Markup that calls may leave out: `createParla({ markup })` renders it. */
|
|
32
|
+
markup?: Array<string>;
|
|
33
|
+
/** Message syntaxes by the name a namespace's `format` gives: `{ icu }` from `@parlajs/format-icu`. */
|
|
34
|
+
formats?: Record<Formats, FormatAdapter>;
|
|
35
|
+
/**
|
|
36
|
+
* Module the generated types import and augment: the adapter this package depends on.
|
|
37
|
+
* Default: the first of `@parlajs/react`, `solid`, `svelte`, `vue` and `core` in `package.json`.
|
|
38
|
+
*/
|
|
39
|
+
runtime?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ResolvedNamespace {
|
|
42
|
+
name: string;
|
|
43
|
+
format: string;
|
|
44
|
+
readonly file: (locale: string) => string;
|
|
45
|
+
}
|
|
46
|
+
export interface ResolvedConfig {
|
|
47
|
+
root: string;
|
|
48
|
+
configFile: string;
|
|
49
|
+
locales: Array<string>;
|
|
50
|
+
sourceLocale: string;
|
|
51
|
+
fallbacks: Record<string, Array<string>>;
|
|
52
|
+
outDir: string;
|
|
53
|
+
namespaces: Array<ResolvedNamespace>;
|
|
54
|
+
/** Module the generated types import and augment. */
|
|
55
|
+
runtime: string;
|
|
56
|
+
functions: Record<string, FunctionKind>;
|
|
57
|
+
markup: Array<string>;
|
|
58
|
+
formats: Record<string, FormatAdapter>;
|
|
59
|
+
/** Every file whose change should trigger a rebuild. */
|
|
60
|
+
watchFiles: Array<string>;
|
|
61
|
+
/** Folders that hold catalogs, which a config may list from disk. */
|
|
62
|
+
watchFolders: Array<string>;
|
|
63
|
+
/** Whether a change to `file` should trigger a rebuild. */
|
|
64
|
+
readonly watches: (file: string) => boolean;
|
|
65
|
+
}
|
|
66
|
+
export declare class ConfigError extends Error {
|
|
67
|
+
name: string;
|
|
68
|
+
}
|
|
69
|
+
/** Types a `parla.config.ts`: `export default defineConfig({ … })`. */
|
|
70
|
+
export declare function defineConfig<Formats extends string = never>(config: ParlaConfig<Formats>): ParlaConfig<Formats>;
|
|
71
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,4EAA4E;AAC5E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,KAAK,CAAC,OAAO,CAAC;IAClD,yFAAyF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;IACnB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACxC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACvC,wDAAwD;IACxD,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,qEAAqE;IACrE,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CAC7C;AAED,qBAAa,WAAY,SAAQ,KAAK;IAC3B,IAAI,SAAiB;CAC/B;AAED,uEAAuE;AACvE,wBAAgB,YAAY,CAAC,OAAO,SAAS,MAAM,GAAG,KAAK,EACzD,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,WAAW,CAAC,OAAO,CAAC,CAEtB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ResolvedConfig } from './config.ts';
|
|
2
|
+
/** The locales listed for `locale`, then its parents: `zh-Hant-TW` → `zh-Hant`, `zh`. */
|
|
3
|
+
export declare function parents(config: ResolvedConfig, locale: string): Array<string>;
|
|
4
|
+
/** Locales to try, in order, when `locale` lacks a key. */
|
|
5
|
+
export declare function fallbackChain(config: ResolvedConfig, locale: string): Array<string>;
|
|
6
|
+
//# sourceMappingURL=fallbacks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallbacks.d.ts","sourceRoot":"","sources":["../../src/config/fallbacks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,yFAAyF;AACzF,wBAAgB,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAO7E;AAED,2DAA2D;AAC3D,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAInF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The locales listed for `locale`, then its parents: `zh-Hant-TW` → `zh-Hant`, `zh`. */
|
|
2
|
+
export function parents(config, locale) {
|
|
3
|
+
const subtags = locale.split('-');
|
|
4
|
+
const bases = subtags.map((_, i) => subtags.slice(0, -1 - i).join('-'));
|
|
5
|
+
return [
|
|
6
|
+
...(config.fallbacks[locale] ?? []),
|
|
7
|
+
...bases.filter((base) => config.locales.includes(base)),
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
/** Locales to try, in order, when `locale` lacks a key. */
|
|
11
|
+
export function fallbackChain(config, locale) {
|
|
12
|
+
return [...new Set([...parents(config, locale), config.sourceLocale])].filter((l) => l !== locale);
|
|
13
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ResolveHookSync } from 'node:module';
|
|
2
|
+
import type { ParlaConfig, ResolvedConfig } from './config.ts';
|
|
3
|
+
export interface Load {
|
|
4
|
+
/** How many times the catalog folders had other files than before. */
|
|
5
|
+
readonly version: number;
|
|
6
|
+
/** The catalogs in each folder. */
|
|
7
|
+
readonly names: ReadonlyMap<string, string>;
|
|
8
|
+
readonly list: (dir: string) => string;
|
|
9
|
+
/** The modules the config imported from its own folder. */
|
|
10
|
+
readonly imports: ReadonlyArray<string>;
|
|
11
|
+
}
|
|
12
|
+
/** The load to come, before the import: a file added meanwhile counts at the next one. */
|
|
13
|
+
export declare function nextLoad(file: string): Load | undefined;
|
|
14
|
+
interface Importing {
|
|
15
|
+
readonly root: string;
|
|
16
|
+
readonly imports: Set<string>;
|
|
17
|
+
}
|
|
18
|
+
/** A resolve hook that carries a config's query to what it imports from its own folder. */
|
|
19
|
+
export declare function carrying(configs: ReadonlyMap<string, Importing>): ResolveHookSync;
|
|
20
|
+
export declare function importConfig(file: string, load: Load | undefined): Promise<{
|
|
21
|
+
config: ParlaConfig;
|
|
22
|
+
imports: Array<string>;
|
|
23
|
+
}>;
|
|
24
|
+
/** What a watcher of this load follows, kept to tell the next load whether its folders changed. */
|
|
25
|
+
export declare function watching(file: string, { load, catalogs, imports, }: {
|
|
26
|
+
load: Load | undefined;
|
|
27
|
+
catalogs: ReadonlyArray<string>;
|
|
28
|
+
imports: ReadonlyArray<string>;
|
|
29
|
+
}): Pick<ResolvedConfig, 'watchFiles' | 'watchFolders' | 'watches'>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/config/import.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAKnD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE/D,MAAM,WAAW,IAAI;IACnB,sEAAsE;IACtE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACvC,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACzC;AAKD,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAUvD;AAED,UAAU,SAAS;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC/B;AAWD,2FAA2F;AAC3F,wBAAgB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,eAAe,CAgBjF;AAaD,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,IAAI,GAAG,SAAS,GACrB,OAAO,CAAC;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,CA8B1D;AAED,mGAAmG;AACnG,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,EACE,IAAI,EACJ,QAAQ,EACR,OAAO,GACR,EAAE;IAAE,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CAAE,GAC7F,IAAI,CAAC,cAAc,EAAE,YAAY,GAAG,cAAc,GAAG,SAAS,CAAC,CAuBjE"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
10
|
+
import { registerHooks } from 'node:module';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
13
|
+
import { ConfigError } from './config.js';
|
|
14
|
+
/** The last load of each config file, for watchers. */
|
|
15
|
+
const loads = new Map();
|
|
16
|
+
/** The load to come, before the import: a file added meanwhile counts at the next one. */
|
|
17
|
+
export function nextLoad(file) {
|
|
18
|
+
const last = loads.get(file);
|
|
19
|
+
if (!last) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const names = new Map([...last.names.keys()].map((dir) => [dir, last.list(dir)]));
|
|
23
|
+
const same = [...names].every(([dir, list]) => list === last.names.get(dir));
|
|
24
|
+
const next = { ...last, names, version: last.version + (same ? 0 : 1) };
|
|
25
|
+
loads.set(file, next);
|
|
26
|
+
return next;
|
|
27
|
+
}
|
|
28
|
+
/** Each config import under way or done, by its URL's query. */
|
|
29
|
+
const importing = new Map();
|
|
30
|
+
/** A number per config file, so two configs never share a query. */
|
|
31
|
+
const ids = new Map();
|
|
32
|
+
let hooked = false;
|
|
33
|
+
const isInside = (dir, file) => file.startsWith(dir + path.sep) && !file.includes(`${path.sep}node_modules${path.sep}`);
|
|
34
|
+
/** A resolve hook that carries a config's query to what it imports from its own folder. */
|
|
35
|
+
export function carrying(configs) {
|
|
36
|
+
return (specifier, context, nextResolve) => {
|
|
37
|
+
const result = nextResolve(specifier, context);
|
|
38
|
+
const from = context.parentURL ?? '';
|
|
39
|
+
const query = from.slice(from.indexOf('?'));
|
|
40
|
+
const config = from.includes('?') ? configs.get(query) : undefined;
|
|
41
|
+
if (!config || !result.url.startsWith('file:') || result.url.includes('?')) {
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
const file = fileURLToPath(result.url);
|
|
45
|
+
if (!isInside(config.root, file)) {
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
config.imports.add(file);
|
|
49
|
+
return { ...result, url: result.url + query };
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Node would keep what a config imports cached, however its own URL changes. */
|
|
53
|
+
function reloadImports() {
|
|
54
|
+
if (!hooked) {
|
|
55
|
+
hooked = true;
|
|
56
|
+
registerHooks({ resolve: carrying(importing) });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const mtimeOf = (file) => statSync(file, { bigint: true, throwIfNoEntry: false })?.mtimeNs ?? 0n;
|
|
60
|
+
export async function importConfig(file, load) {
|
|
61
|
+
reloadImports();
|
|
62
|
+
// All bust Node's module cache, so a watcher sees an edited config, an edited module it imports,
|
|
63
|
+
// or a config that lists new catalogs.
|
|
64
|
+
let stamp = statSync(file, { bigint: true }).mtimeNs;
|
|
65
|
+
for (const dependency of load?.imports ?? []) {
|
|
66
|
+
const edited = mtimeOf(dependency);
|
|
67
|
+
stamp = edited > stamp ? edited : stamp;
|
|
68
|
+
}
|
|
69
|
+
const id = ids.get(file) ?? ids.size;
|
|
70
|
+
ids.set(file, id);
|
|
71
|
+
const query = `?t=${stamp}&v=${load?.version ?? 0}&c=${id}`;
|
|
72
|
+
const url = pathToFileURL(file).href + query;
|
|
73
|
+
// The same query is the same module, cached: it resolves nothing again.
|
|
74
|
+
const entry = importing.get(query) ?? { root: path.dirname(file), imports: new Set() };
|
|
75
|
+
importing.set(query, entry);
|
|
76
|
+
let mod;
|
|
77
|
+
try {
|
|
78
|
+
mod = await import(__rewriteRelativeImportExtension(url));
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
const { message, stack = '' } = error;
|
|
82
|
+
// Only the stack tells where, a syntax error's included.
|
|
83
|
+
const [position = ''] = /^(?::\d+)+/.exec(stack.split(url)[1] ?? '') ?? [];
|
|
84
|
+
throw new ConfigError(`Cannot load ${file}${position}: ${message}`);
|
|
85
|
+
}
|
|
86
|
+
const config = mod.default;
|
|
87
|
+
if (typeof config !== 'object' || config === null) {
|
|
88
|
+
throw new ConfigError(`${file} must \`export default defineConfig({ … })\``);
|
|
89
|
+
}
|
|
90
|
+
return { config, imports: [...entry.imports] };
|
|
91
|
+
}
|
|
92
|
+
/** What a watcher of this load follows, kept to tell the next load whether its folders changed. */
|
|
93
|
+
export function watching(file, { load, catalogs, imports, }) {
|
|
94
|
+
const watchFiles = [file, ...imports, ...catalogs];
|
|
95
|
+
const extensions = new Set(catalogs.map((f) => path.extname(f)));
|
|
96
|
+
const folders = new Set(catalogs.map((f) => path.dirname(f)));
|
|
97
|
+
const isCatalog = (f) => extensions.has(path.extname(f));
|
|
98
|
+
const list = (dir) => existsSync(dir)
|
|
99
|
+
? readdirSync(dir)
|
|
100
|
+
.filter((f) => isCatalog(f))
|
|
101
|
+
.toSorted()
|
|
102
|
+
.join('/')
|
|
103
|
+
: '';
|
|
104
|
+
loads.set(file, {
|
|
105
|
+
version: load?.version ?? 0,
|
|
106
|
+
names: new Map([...folders].map((dir) => [dir, load?.names.get(dir) ?? list(dir)])),
|
|
107
|
+
list,
|
|
108
|
+
imports,
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
watchFiles,
|
|
112
|
+
watchFolders: [...folders],
|
|
113
|
+
watches: (f) => watchFiles.includes(f) || (folders.has(path.dirname(f)) && isCatalog(f)),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ResolvedConfig } from './config.ts';
|
|
2
|
+
interface PackageJson {
|
|
3
|
+
type?: string;
|
|
4
|
+
dependencies?: Record<string, string>;
|
|
5
|
+
devDependencies?: Record<string, string>;
|
|
6
|
+
peerDependencies?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
/** `.mts` for a package that is not `"type": "module"`, where Node reads a `.ts` as CommonJS. */
|
|
9
|
+
export declare const CONFIG_FILES: readonly ['parla.config.ts', 'parla.config.mts'];
|
|
10
|
+
export declare function readPackageJson(dir: string): PackageJson | undefined;
|
|
11
|
+
export declare function loadConfig(cwd: string, configFile?: string): Promise<ResolvedConfig>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=load.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/config/load.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED,iGAAiG;AACjG,eAAO,MAAM,YAAY,YAAI,iBAAiB,EAAE,kBAAkB,CAAU,CAAC;AAE7E,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAGpE;AAiBD,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAoC1F"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { checkFallbacks, checkFunctions, checkLocales, resolveNamespaces } from './checks.js';
|
|
4
|
+
import { ConfigError } from './config.js';
|
|
5
|
+
import { importConfig, nextLoad, watching } from './import.js';
|
|
6
|
+
/** `.mts` for a package that is not `"type": "module"`, where Node reads a `.ts` as CommonJS. */
|
|
7
|
+
export const CONFIG_FILES = ['parla.config.ts', 'parla.config.mts'];
|
|
8
|
+
export function readPackageJson(dir) {
|
|
9
|
+
const file = path.join(dir, 'package.json');
|
|
10
|
+
return existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : undefined;
|
|
11
|
+
}
|
|
12
|
+
// The adapters first: an app on one may list core too.
|
|
13
|
+
const RUNTIMES = [
|
|
14
|
+
'@parlajs/react',
|
|
15
|
+
'@parlajs/solid',
|
|
16
|
+
'@parlajs/svelte',
|
|
17
|
+
'@parlajs/vue',
|
|
18
|
+
'@parlajs/core',
|
|
19
|
+
];
|
|
20
|
+
function detectRuntime(dir) {
|
|
21
|
+
const pkg = readPackageJson(dir);
|
|
22
|
+
const deps = { ...pkg?.peerDependencies, ...pkg?.devDependencies, ...pkg?.dependencies };
|
|
23
|
+
return RUNTIMES.find((name) => name in deps) ?? '@parlajs/core';
|
|
24
|
+
}
|
|
25
|
+
export async function loadConfig(cwd, configFile) {
|
|
26
|
+
const found = CONFIG_FILES.find((name) => existsSync(path.join(cwd, name)));
|
|
27
|
+
if (!configFile && !found) {
|
|
28
|
+
throw new ConfigError(`No ${CONFIG_FILES[0]} in ${cwd}`);
|
|
29
|
+
}
|
|
30
|
+
const file = path.resolve(cwd, configFile ?? found ?? CONFIG_FILES[0]);
|
|
31
|
+
const load = nextLoad(file);
|
|
32
|
+
const { config, imports } = await importConfig(file, load);
|
|
33
|
+
const root = path.dirname(file);
|
|
34
|
+
const sourceLocale = config.sourceLocale ?? 'en';
|
|
35
|
+
const locales = config.locales ?? [sourceLocale];
|
|
36
|
+
const fallbacks = config.fallbacks ?? {};
|
|
37
|
+
checkLocales({ locales, sourceLocale, fallbacks });
|
|
38
|
+
const outDir = path.resolve(root, config.outDir ?? 'src/parla');
|
|
39
|
+
const namespaces = resolveNamespaces(config.namespaces ?? {}, { root, outDir, locales });
|
|
40
|
+
checkFallbacks(fallbacks, {
|
|
41
|
+
locales,
|
|
42
|
+
hasCatalog: (locale) => namespaces.some((ns) => existsSync(ns.file(locale))),
|
|
43
|
+
});
|
|
44
|
+
const catalogs = namespaces.flatMap((ns) => locales.map((l) => ns.file(l)));
|
|
45
|
+
return {
|
|
46
|
+
root,
|
|
47
|
+
configFile: file,
|
|
48
|
+
locales,
|
|
49
|
+
sourceLocale,
|
|
50
|
+
fallbacks,
|
|
51
|
+
outDir,
|
|
52
|
+
runtime: config.runtime ?? detectRuntime(root),
|
|
53
|
+
functions: checkFunctions(config.functions ?? {}),
|
|
54
|
+
markup: config.markup ?? [],
|
|
55
|
+
formats: config.formats ?? {},
|
|
56
|
+
namespaces,
|
|
57
|
+
...watching(file, { load, catalogs, imports }),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Model } from 'messageformat';
|
|
2
|
+
import type { FunctionKind } from './compile.ts';
|
|
3
|
+
/** Parses one message into the MF2 data model, which the compiler reads. */
|
|
4
|
+
export interface FormatAdapter {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly parse: (source: string) => Model.Message;
|
|
7
|
+
/** Reads a catalog file into `{ key: message | group }`, for files that are not JSON. */
|
|
8
|
+
readonly parseFile?: ((text: string) => unknown) | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare const defaultFormats: Readonly<Record<string, FormatAdapter>>;
|
|
11
|
+
export interface NamespaceConfig {
|
|
12
|
+
/** Message syntax: `icu`, `mf2` or a key of `formats`. */
|
|
13
|
+
format: string;
|
|
14
|
+
/** Catalog path relative to the config, with a `{locale}` token. */
|
|
15
|
+
path: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ParlaConfig {
|
|
18
|
+
locales?: Array<string>;
|
|
19
|
+
sourceLocale?: string;
|
|
20
|
+
/** Extra fallback chain per locale; the source locale is always last. */
|
|
21
|
+
fallbacks?: Record<string, Array<string>>;
|
|
22
|
+
/** Where generated files go, relative to the config. Default `src/parla`. */
|
|
23
|
+
outDir?: string;
|
|
24
|
+
/** Namespaces this package owns: other packages import their built objects. */
|
|
25
|
+
namespaces?: Record<string, NamespaceConfig>;
|
|
26
|
+
/**
|
|
27
|
+
* Message functions beyond the built-in ones, by what their value is. Each needs an
|
|
28
|
+
* implementation in `createParla({ functions })`.
|
|
29
|
+
*/
|
|
30
|
+
functions?: Record<string, FunctionKind>;
|
|
31
|
+
/** Markup that calls may leave out: `createParla({ markup })` renders it. */
|
|
32
|
+
markup?: Array<string>;
|
|
33
|
+
/** Message syntaxes beyond `icu` and `mf2`, by the name a namespace's `format` gives. */
|
|
34
|
+
formats?: Record<string, FormatAdapter>;
|
|
35
|
+
/**
|
|
36
|
+
* Module the generated types import and augment: the adapter this package depends on.
|
|
37
|
+
* Default: the first of `@parlajs/react`, `solid`, `svelte`, `vue` and `core` in `package.json`.
|
|
38
|
+
*/
|
|
39
|
+
runtime?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ResolvedNamespace {
|
|
42
|
+
name: string;
|
|
43
|
+
format: string;
|
|
44
|
+
readonly file: (locale: string) => string;
|
|
45
|
+
}
|
|
46
|
+
export interface ResolvedConfig {
|
|
47
|
+
root: string;
|
|
48
|
+
configFile: string;
|
|
49
|
+
locales: Array<string>;
|
|
50
|
+
sourceLocale: string;
|
|
51
|
+
fallbacks: Record<string, Array<string>>;
|
|
52
|
+
outDir: string;
|
|
53
|
+
namespaces: Array<ResolvedNamespace>;
|
|
54
|
+
/** Module the generated types import and augment. */
|
|
55
|
+
runtime: string;
|
|
56
|
+
functions: Record<string, FunctionKind>;
|
|
57
|
+
markup: Array<string>;
|
|
58
|
+
/** `icu`, `mf2` and the config's own `formats`. */
|
|
59
|
+
formats: Record<string, FormatAdapter>;
|
|
60
|
+
/** Every file whose change should trigger a rebuild. */
|
|
61
|
+
watchFiles: Array<string>;
|
|
62
|
+
/** Folders that hold catalogs, which a config may list from disk. */
|
|
63
|
+
watchFolders: Array<string>;
|
|
64
|
+
/** Whether a change to `file` should trigger a rebuild. */
|
|
65
|
+
readonly watches: (file: string) => boolean;
|
|
66
|
+
}
|
|
67
|
+
export declare class ConfigError extends Error {
|
|
68
|
+
name: string;
|
|
69
|
+
}
|
|
70
|
+
/** Types a `parla.config.ts`: `export default defineConfig({ … })`. */
|
|
71
|
+
export declare function defineConfig(config: ParlaConfig): ParlaConfig;
|
|
72
|
+
export declare function loadConfig(cwd: string, configFile?: string): Promise<ResolvedConfig>;
|
|
73
|
+
/** The locales listed for `locale`, then its parents: `zh-Hant-TW` → `zh-Hant`, `zh`. */
|
|
74
|
+
export declare function parents(config: ResolvedConfig, locale: string): Array<string>;
|
|
75
|
+
/** Locales to try, in order, when `locale` lacks a key. */
|
|
76
|
+
export declare function fallbackChain(config: ResolvedConfig, locale: string): Array<string>;
|
|
77
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,4EAA4E;AAC5E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,KAAK,CAAC,OAAO,CAAC;IAClD,yFAAyF;IACzF,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;CAC9D;AAED,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAgB,CAAC;AAEpF,MAAM,WAAW,eAAe;IAC9B,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1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