intor 2.4.11 → 2.4.13

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.
@@ -4,3 +4,6 @@ import 'logry';
4
4
  import 'p-limit';
5
5
  export { INTOR_MESSAGES_KIND, INTOR_MESSAGES_KIND_KEY, INTOR_PREFIX, getMessagesKind } from '../../src/core/messages/internal-metadata.js';
6
6
  import 'intor-translator';
7
+ export { loadMessages } from '../../src/server/messages/load-messages.js';
8
+ import 'node:path';
9
+ import 'node:fs/promises';
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * NOTE: It is not part of the public stable contract and may change without notice.
3
3
  */
4
- export { resolveLoaderOptions, INTOR_PREFIX, INTOR_MESSAGES_KIND_KEY, INTOR_MESSAGES_KIND, getMessagesKind, type IntorMessagesKind, } from "../../src/core";
4
+ export { resolveLoaderOptions, type DeepMergeOverrideEvent, INTOR_PREFIX, INTOR_MESSAGES_KIND_KEY, INTOR_MESSAGES_KIND, getMessagesKind, type IntorMessagesKind, } from "../../src/core";
5
+ export { loadMessages } from "../../src/server";
5
6
  export type { GenConfigKeys, GenConfig, TranslatorInstance, } from "../../src/core";
6
7
  export type { TranslatorInstanceReact } from "../../src/client/react/translator/translator-instance";
@@ -1,31 +1,29 @@
1
1
  import type { LOCALE_PLACEHOLDER } from "../constants";
2
2
  import type { Locale, LocaleMessages, Replacement, Rich } from "intor-translator";
3
- /**
4
- * =================================================
5
- * Generated-aware type system for Intor
6
- * =================================================
7
- */
8
3
  /**
9
4
  * Sentinel key injected by CLI when generated types exist.
10
- * Used purely for type-level generation detection.
11
5
  */
12
6
  export type INTOR_GENERATED_KEY = "__intor_generated__";
13
7
  /**
14
- * Detect whether generated types are present.
8
+ * Detect generation mode.
9
+ *
10
+ * This works in both source and declaration emit environments.
15
11
  */
16
- type HasGenerated = IntorGeneratedTypes extends {
17
- [K in INTOR_GENERATED_KEY]: true;
18
- } ? true : false;
12
+ type HasGen = INTOR_GENERATED_KEY extends keyof IntorGeneratedTypes ? true : false;
19
13
  /**
20
- * Extract valid configuration keys from generated types.
21
- * (Excludes sentinel key.)
14
+ * Extract concrete generated config keys safely.
15
+ *
16
+ * - Works even if IntorGeneratedTypes is empty.
17
+ * - Prevents keyof widening issues.
22
18
  */
23
- type GeneratedConfigKeys = Exclude<keyof IntorGeneratedTypes, INTOR_GENERATED_KEY>;
19
+ type GeneratedConfigKeys = HasGen extends true ? Exclude<keyof IntorGeneratedTypes & string, INTOR_GENERATED_KEY> : never;
24
20
  /**
25
- * Public configuration key union.
26
- * Falls back to `string` in non-generated mode.
21
+ * Public config key union.
22
+ *
23
+ * - Never resolves to `never`.
24
+ * - Falls back to `string` safely.
27
25
  */
28
- export type GenConfigKeys = HasGenerated extends true ? GeneratedConfigKeys : string;
26
+ export type GenConfigKeys = HasGen extends true ? [GeneratedConfigKeys] extends [never] ? string : GeneratedConfigKeys : string;
29
27
  /**
30
28
  * Fallback configuration shape (non-generated mode).
31
29
  */
@@ -36,11 +34,14 @@ type FallbackConfig = {
36
34
  Rich: Rich;
37
35
  };
38
36
  /**
39
- * Extract generated configuration shape safely.
37
+ * Safely extract generated config structure.
38
+ *
39
+ * - Never leaks `never` to public API.
40
+ * - Handles malformed generated types defensively.
40
41
  */
41
- type ExtractGeneratedConfig<T> = T extends {
42
+ type SafeExtract<T> = T extends {
42
43
  Locales: infer L extends string;
43
- Messages: Record<typeof LOCALE_PLACEHOLDER, infer M>;
44
+ Messages: Record<typeof LOCALE_PLACEHOLDER, infer M extends LocaleMessages[string]>;
44
45
  Replacements: infer RE;
45
46
  Rich: infer RI;
46
47
  } ? {
@@ -48,17 +49,15 @@ type ExtractGeneratedConfig<T> = T extends {
48
49
  Messages: Record<L, M>;
49
50
  Replacements: RE;
50
51
  Rich: RI;
51
- } : never;
52
+ } : FallbackConfig;
52
53
  /**
53
- * Configuration shape resolver.
54
+ * Main configuration resolver.
54
55
  *
55
- * - Uses generated types when available.
56
- * - Falls back to default shape otherwise.
57
- */
58
- export type GenConfig<CK extends GenConfigKeys> = HasGenerated extends true ? CK extends GeneratedConfigKeys ? ExtractGeneratedConfig<IntorGeneratedTypes[CK]> : never : FallbackConfig;
59
- /**
60
- * Derived helpers
56
+ * - Never returns `never`.
57
+ * - Fully declaration-safe.
58
+ * - Stable under generic distribution.
61
59
  */
60
+ export type GenConfig<CK extends GenConfigKeys> = HasGen extends true ? CK extends GeneratedConfigKeys ? SafeExtract<IntorGeneratedTypes[CK]> : FallbackConfig : FallbackConfig;
62
61
  export type GenMessages<CK extends GenConfigKeys> = GenConfig<CK>["Messages"];
63
62
  export type GenLocale<CK extends GenConfigKeys> = GenConfig<CK>["Locales"];
64
63
  export type GenReplacements<CK extends GenConfigKeys> = GenConfig<CK>["Replacements"];
@@ -1,4 +1,4 @@
1
1
  export { intor, type IntorValue } from "./intor";
2
- export { clearMessagesPool } from "./messages";
2
+ export { loadMessages, clearMessagesPool } from "./messages";
3
3
  export { getTranslator, type GetTranslatorParams } from "./helpers";
4
4
  export type { MessagesLoader } from "./translator";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor",
3
- "version": "2.4.11",
3
+ "version": "2.4.13",
4
4
  "description": "The i18n library for modern JavaScript",
5
5
  "author": "Yiming Liao",
6
6
  "homepage": "https://intor.dev",
@@ -32,9 +32,7 @@
32
32
  "exports": {
33
33
  ".": {
34
34
  "import": "./dist/core/export/index.js",
35
- "types": "./dist/types/export/index.d.ts",
36
- "require": "./dist/core/export/index.js",
37
- "default": "./dist/core/export/index.js"
35
+ "types": "./dist/types/export/index.d.ts"
38
36
  },
39
37
  "./internal": {
40
38
  "import": "./dist/core/export/internal/index.js",
@@ -42,9 +40,7 @@
42
40
  },
43
41
  "./server": {
44
42
  "import": "./dist/core/export/server/index.js",
45
- "types": "./dist/types/export/server/index.d.ts",
46
- "require": "./dist/core/export/server/index.js",
47
- "default": "./dist/core/export/server/index.js"
43
+ "types": "./dist/types/export/server/index.d.ts"
48
44
  },
49
45
  "./edge": {
50
46
  "import": "./dist/core/export/edge/index.js",
@@ -76,15 +72,11 @@
76
72
  },
77
73
  "./express": {
78
74
  "import": "./dist/express/export/express/index.js",
79
- "types": "./dist/types/export/express/index.d.ts",
80
- "require": "./dist/express/export/express/index.js",
81
- "default": "./dist/express/export/express/index.js"
75
+ "types": "./dist/types/export/express/index.d.ts"
82
76
  },
83
77
  "./fastify": {
84
78
  "import": "./dist/fastify/export/fastify/index.js",
85
- "types": "./dist/types/export/fastify/index.d.ts",
86
- "require": "./dist/fastify/export/fastify/index.js",
87
- "default": "./dist/fastify/export/fastify/index.js"
79
+ "types": "./dist/types/export/fastify/index.d.ts"
88
80
  },
89
81
  "./hono": {
90
82
  "import": "./dist/hono/export/hono/index.js",
@@ -100,7 +92,7 @@
100
92
  ],
101
93
  "sideEffects": false,
102
94
  "engines": {
103
- "node": ">=16.0.0"
95
+ "node": ">=20"
104
96
  },
105
97
  "scripts": {
106
98
  "type": "tsc --noEmit",
@@ -111,11 +103,10 @@
111
103
  "test:check": "tsx scripts/check-test-structure.ts",
112
104
  "knip": "knip --config .config/knip.config.ts",
113
105
  "build": "tsx scripts/build.ts",
114
- "prepublishOnly": "yarn build",
115
- "examples:html": "vite --config examples/html/vite.config.ts"
106
+ "prepublishOnly": "yarn build"
116
107
  },
117
108
  "dependencies": {
118
- "intor-translator": "1.4.13",
109
+ "intor-translator": "^1.4.14",
119
110
  "logry": "2.1.6",
120
111
  "p-limit": "7.2.0"
121
112
  },
@@ -160,6 +151,7 @@
160
151
  "svelte": "5.46.1",
161
152
  "tsc-alias": "1.8.16",
162
153
  "tsd": "0.33.0",
154
+ "tsx": "^4.21.0",
163
155
  "typescript": "5.8.3",
164
156
  "typescript-eslint": "8.32.1",
165
157
  "vite": "7.3.0",