@xndrjs/i18n 0.7.0 → 0.8.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/README.md +67 -872
- package/dist/codegen/index.d.ts +117 -51
- package/dist/codegen/index.js +1585 -93
- package/dist/codegen/index.js.map +1 -1
- package/dist/index.d.ts +100 -234
- package/dist/index.js +74 -638
- package/dist/index.js.map +1 -1
- package/dist/validation/index.d.ts +5 -0
- package/dist/validation/index.js.map +1 -1
- package/package.json +2 -2
- package/src/IcuTranslationProviderMulti.test.ts +18 -40
- package/src/IcuTranslationProviderMulti.ts +27 -37
- package/src/audit/audit-dictionaries.ts +1 -1
- package/src/audit/run-audit.test.ts +6 -7
- package/src/builder-load-registry.ts +26 -5
- package/src/builder-loaders.ts +8 -11
- package/src/builder-types.test.ts +11 -42
- package/src/builder.test.ts +82 -243
- package/src/builder.ts +8 -110
- package/src/codegen/codegen-config-schema.ts +82 -77
- package/src/codegen/config.test.ts +55 -143
- package/src/codegen/config.ts +10 -67
- package/src/codegen/dictionary-spec-contract.test.ts +28 -0
- package/src/codegen/dictionary-spec-contract.ts +138 -0
- package/src/codegen/emit/dictionary-schema-file.ts +7 -43
- package/src/codegen/emit/instance-file.test.ts +35 -52
- package/src/codegen/emit/instance-file.ts +170 -268
- package/src/codegen/emit/namespace-loaders-file.test.ts +72 -74
- package/src/codegen/emit/namespace-loaders-file.ts +147 -90
- package/src/codegen/emit/types-file.test.ts +20 -41
- package/src/codegen/emit/types-file.ts +48 -74
- package/src/codegen/generate-i18n-types.test.ts +163 -492
- package/src/codegen/generate-i18n-types.ts +7 -269
- package/src/codegen/paths.ts +0 -14
- package/src/codegen/project-locales-set-namespace.test.ts +44 -86
- package/src/codegen/read-dictionary.test.ts +27 -9
- package/src/codegen/read-dictionary.ts +18 -40
- package/src/codegen/regenerate-namespaces.ts +180 -0
- package/src/codegen/run-codegen.test.ts +230 -0
- package/src/codegen/run-codegen.ts +252 -0
- package/src/codegen/types.ts +0 -6
- package/src/codegen-config/build-config.ts +4 -23
- package/src/codegen-config/codegen-config.test.ts +10 -6
- package/src/codegen-config/index.ts +18 -3
- package/src/engine.ts +3 -27
- package/src/fetch-artifact.ts +16 -0
- package/src/i18n-handle.ts +202 -0
- package/src/index.ts +15 -34
- package/src/project-locales.ts +2 -2
- package/src/scope-multi.ts +1 -20
- package/src/scope-types.ts +14 -6
- package/src/scope.test.ts +3 -312
- package/src/serialized-state.test.ts +114 -0
- package/src/serialized-state.ts +28 -0
- package/src/setup/setup-i18n.test.ts +22 -33
- package/src/setup/setup-i18n.ts +22 -27
- package/src/types.ts +3 -3
- package/src/validation/index.ts +4 -0
- package/src/IcuTranslationProviderSingle.test.ts +0 -177
- package/src/IcuTranslationProviderSingle.ts +0 -114
- package/src/builder-multi.ts +0 -481
- package/src/codegen/emit/dictionary-file.test.ts +0 -215
- package/src/codegen/emit/dictionary-file.ts +0 -244
- package/src/deep-freeze.test.ts +0 -40
- package/src/deep-freeze.ts +0 -22
- package/src/patch-key.test.ts +0 -186
- package/src/patch-key.ts +0 -140
- package/src/scope-single.ts +0 -85
- package/src/single-builder.ts +0 -153
package/dist/codegen/index.d.ts
CHANGED
|
@@ -1,79 +1,100 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const DELIVERY_MODES: readonly ["
|
|
3
|
+
declare const DELIVERY_MODES: readonly ["split-by-locale", "custom"];
|
|
4
4
|
type DeliveryMode = (typeof DELIVERY_MODES)[number];
|
|
5
|
+
declare const LOADER_STRATEGIES: readonly ["import", "fetch"];
|
|
6
|
+
type LoaderStrategy = (typeof LOADER_STRATEGIES)[number];
|
|
5
7
|
declare const codegenConfigShape: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
importExtension: z.ZodOptional<z.ZodEnum<{
|
|
16
|
-
none: "none";
|
|
17
|
-
".ts": ".ts";
|
|
18
|
-
".js": ".js";
|
|
19
|
-
}>>;
|
|
20
|
-
paramsTypeName: z.ZodString;
|
|
21
|
-
schemaTypeName: z.ZodString;
|
|
22
|
-
localeTypeName: z.ZodOptional<z.ZodString>;
|
|
23
|
-
localeFallbackConstName: z.ZodOptional<z.ZodString>;
|
|
8
|
+
/** PascalCase project id — generates `{project}Params`, `{project}Schema`, `{project}Locale`. */
|
|
9
|
+
projectName: z.ZodString;
|
|
10
|
+
namespaces: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
11
|
+
/**
|
|
12
|
+
* Directory for generated TypeScript modules:
|
|
13
|
+
* `i18n-types.generated.ts`, `instance.generated.ts`,
|
|
14
|
+
* `namespace-loaders.generated.ts`, `dictionary-schema.generated.ts`.
|
|
15
|
+
*/
|
|
16
|
+
codegenPath: z.ZodString;
|
|
24
17
|
localeFallback: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>>;
|
|
25
|
-
factoryName: z.ZodOptional<z.ZodString>;
|
|
26
18
|
delivery: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
27
19
|
custom: "custom";
|
|
28
|
-
canonical: "canonical";
|
|
29
20
|
"split-by-locale": "split-by-locale";
|
|
30
21
|
}>>>;
|
|
31
22
|
deliveryArtifacts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
32
|
-
|
|
23
|
+
/** Directory for delivery JSON (`translations/`). Defaults to {@link codegenPath}. */
|
|
24
|
+
artifactsPath: z.ZodOptional<z.ZodString>;
|
|
25
|
+
/**
|
|
26
|
+
* How generated `namespaceLoaders` resolve artifacts.
|
|
27
|
+
* - `import` (default): dynamic `import()` — JSON is bundled; content updates need a rebuild.
|
|
28
|
+
* - `fetch`: runtime `fetchImpl({ locale, namespace, area? })` via required `createI18n({ fetchImpl })`.
|
|
29
|
+
* Codegen does not know URLs — mapping id → transport is an application concern.
|
|
30
|
+
*/
|
|
31
|
+
loaderStrategy: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
32
|
+
import: "import";
|
|
33
|
+
fetch: "fetch";
|
|
34
|
+
}>>>;
|
|
33
35
|
};
|
|
34
36
|
declare const codegenConfigKeys: (keyof typeof codegenConfigShape)[];
|
|
35
37
|
declare const codegenConfigSchema: z.ZodObject<{
|
|
36
|
-
|
|
37
|
-
namespaces: z.
|
|
38
|
-
|
|
39
|
-
typesOutput: z.ZodString;
|
|
40
|
-
dictionaryOutput: z.ZodOptional<z.ZodString>;
|
|
41
|
-
instanceOutput: z.ZodString;
|
|
42
|
-
dictionarySchemaOutput: z.ZodOptional<z.ZodString>;
|
|
43
|
-
loadOnInit: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
44
|
-
namespaceLoadersOutput: z.ZodOptional<z.ZodString>;
|
|
45
|
-
importExtension: z.ZodOptional<z.ZodEnum<{
|
|
46
|
-
none: "none";
|
|
47
|
-
".ts": ".ts";
|
|
48
|
-
".js": ".js";
|
|
49
|
-
}>>;
|
|
50
|
-
paramsTypeName: z.ZodString;
|
|
51
|
-
schemaTypeName: z.ZodString;
|
|
52
|
-
localeTypeName: z.ZodOptional<z.ZodString>;
|
|
53
|
-
localeFallbackConstName: z.ZodOptional<z.ZodString>;
|
|
38
|
+
projectName: z.ZodString;
|
|
39
|
+
namespaces: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
40
|
+
codegenPath: z.ZodString;
|
|
54
41
|
localeFallback: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>>;
|
|
55
|
-
factoryName: z.ZodOptional<z.ZodString>;
|
|
56
42
|
delivery: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
57
43
|
custom: "custom";
|
|
58
|
-
canonical: "canonical";
|
|
59
44
|
"split-by-locale": "split-by-locale";
|
|
60
45
|
}>>>;
|
|
61
46
|
deliveryArtifacts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
62
|
-
|
|
47
|
+
artifactsPath: z.ZodOptional<z.ZodString>;
|
|
48
|
+
loaderStrategy: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
49
|
+
import: "import";
|
|
50
|
+
fetch: "fetch";
|
|
51
|
+
}>>>;
|
|
63
52
|
}, z.core.$strict>;
|
|
64
53
|
type CodegenConfigInput = z.input<typeof codegenConfigSchema>;
|
|
65
54
|
type CodegenConfig = z.infer<typeof codegenConfigSchema>;
|
|
66
|
-
declare
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
55
|
+
declare const GENERATED_BASENAMES: {
|
|
56
|
+
readonly types: "i18n-types.generated.ts";
|
|
57
|
+
readonly instance: "instance.generated.ts";
|
|
58
|
+
readonly namespaceLoaders: "namespace-loaders.generated.ts";
|
|
59
|
+
readonly dictionarySchema: "dictionary-schema.generated.ts";
|
|
60
|
+
};
|
|
61
|
+
declare const DEFAULT_FACTORY_NAME = "createI18n";
|
|
62
|
+
declare const DEFAULT_LOCALE_FALLBACK_CONST_NAME = "LOCALE_FALLBACK";
|
|
63
|
+
/** Derived paths and symbol names from `projectName` + `codegenPath`. */
|
|
64
|
+
interface ResolvedCodegenPaths {
|
|
65
|
+
codegenPath: string;
|
|
66
|
+
typesOutput: string;
|
|
67
|
+
instanceOutput: string;
|
|
68
|
+
namespaceLoadersOutput: string;
|
|
69
|
+
dictionarySchemaOutput: string;
|
|
70
|
+
artifactsPath: string;
|
|
71
|
+
paramsTypeName: string;
|
|
72
|
+
schemaTypeName: string;
|
|
73
|
+
localeTypeName: string;
|
|
74
|
+
localeFallbackConstName: string;
|
|
75
|
+
factoryName: string;
|
|
76
|
+
deliveryAreaTypeName: string;
|
|
77
|
+
}
|
|
78
|
+
declare function resolveCodegenPaths(config: Pick<CodegenConfig, "projectName" | "codegenPath" | "artifactsPath">): ResolvedCodegenPaths;
|
|
79
|
+
declare function resolveArtifactsPath(config: Pick<CodegenConfig, "codegenPath" | "artifactsPath">): string;
|
|
80
|
+
declare function formatCodegenConfigIssues(error: z.ZodError): string;
|
|
71
81
|
|
|
72
82
|
declare const SUPPORTED_IMPORT_EXTENSIONS: readonly ["none", ".ts", ".js"];
|
|
73
83
|
type SupportedImportExtension = (typeof SUPPORTED_IMPORT_EXTENSIONS)[number];
|
|
74
84
|
|
|
75
|
-
|
|
76
|
-
|
|
85
|
+
interface NamespaceEntry {
|
|
86
|
+
namespace: string;
|
|
87
|
+
filePath: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Parses and validates `i18n.codegen.json`; first step of the codegen pipeline. */
|
|
91
|
+
declare function loadConfig(configPath: string): CodegenConfig;
|
|
92
|
+
/** Maps config namespaces to namespace entries. */
|
|
93
|
+
declare function resolveNamespaces(config: CodegenConfig): NamespaceEntry[];
|
|
94
|
+
|
|
95
|
+
type DeliveryArtifactsMap = Record<string, readonly string[]>;
|
|
96
|
+
|
|
97
|
+
declare function buildCodegenConfig(project: string): CodegenConfigInput;
|
|
77
98
|
|
|
78
99
|
declare function inferProjectName(dirName: string): string;
|
|
79
100
|
declare function typeNamesForProject(project: string): {
|
|
@@ -84,4 +105,49 @@ declare function typeNamesForProject(project: string): {
|
|
|
84
105
|
|
|
85
106
|
declare function writeCodegenConfig(configPath: string, config: CodegenConfigInput): void;
|
|
86
107
|
|
|
87
|
-
|
|
108
|
+
type RunCodegenInput = string | {
|
|
109
|
+
configPath?: string;
|
|
110
|
+
config?: CodegenConfig;
|
|
111
|
+
projectRoot?: string;
|
|
112
|
+
/** When false, skip console.log summaries (default true). */
|
|
113
|
+
log?: boolean;
|
|
114
|
+
};
|
|
115
|
+
interface RunCodegenResult {
|
|
116
|
+
projectRoot: string;
|
|
117
|
+
generatedFiles: string[];
|
|
118
|
+
compiledFiles: string[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Full codegen pipeline: types + instance + loaders + delivery JSON (+ schema).
|
|
122
|
+
* Run at build time or when the *contract* changes (keys, params, namespaces, locales).
|
|
123
|
+
* Content-only refreshes (same ICU contract) should use {@link regenerateNamespaces} instead.
|
|
124
|
+
*/
|
|
125
|
+
declare function runCodegen(input?: RunCodegenInput): RunCodegenResult;
|
|
126
|
+
|
|
127
|
+
interface RegenerateNamespacesInput {
|
|
128
|
+
/** Namespaces whose delivery JSON should be refreshed from authoring sources. */
|
|
129
|
+
namespaces: readonly string[];
|
|
130
|
+
configPath?: string;
|
|
131
|
+
config?: CodegenConfig;
|
|
132
|
+
projectRoot?: string;
|
|
133
|
+
/** When false, skip console.log summaries (default true). */
|
|
134
|
+
log?: boolean;
|
|
135
|
+
}
|
|
136
|
+
interface RegenerateNamespacesResult {
|
|
137
|
+
projectRoot: string;
|
|
138
|
+
compiledFiles: string[];
|
|
139
|
+
splitPathsByNamespace: Record<string, Record<string, string>>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Content-only refresh: re-materialize delivery JSON for selected namespaces from
|
|
143
|
+
* current authoring files, without rewriting generated TypeScript.
|
|
144
|
+
*
|
|
145
|
+
* Must not change the ICU key/param contract established by a prior {@link runCodegen}.
|
|
146
|
+
* If authoring changed keys or ICU args, this throws — run {@link runCodegen} and ship a release.
|
|
147
|
+
*
|
|
148
|
+
* Authoring updates are out of scope for this library (CMS or editors write those files).
|
|
149
|
+
* End-to-end without app rebuild requires `loaderStrategy: "fetch"`.
|
|
150
|
+
*/
|
|
151
|
+
declare function regenerateNamespaces(input: RegenerateNamespacesInput): RegenerateNamespacesResult;
|
|
152
|
+
|
|
153
|
+
export { type CodegenConfig, type CodegenConfigInput, DEFAULT_FACTORY_NAME, DEFAULT_LOCALE_FALLBACK_CONST_NAME, DELIVERY_MODES, type DeliveryArtifactsMap, type DeliveryMode, GENERATED_BASENAMES, LOADER_STRATEGIES, type LoaderStrategy, type RegenerateNamespacesInput, type RegenerateNamespacesResult, type ResolvedCodegenPaths, type RunCodegenInput, type RunCodegenResult, SUPPORTED_IMPORT_EXTENSIONS, type SupportedImportExtension, buildCodegenConfig, codegenConfigKeys, formatCodegenConfigIssues, inferProjectName, loadConfig, regenerateNamespaces, resolveArtifactsPath, resolveCodegenPaths, resolveNamespaces, runCodegen, typeNamesForProject, writeCodegenConfig };
|