intor 2.4.12 → 2.4.14

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.
@@ -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"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor",
3
- "version": "2.4.12",
3
+ "version": "2.4.14",
4
4
  "description": "The i18n library for modern JavaScript",
5
5
  "author": "Yiming Liao",
6
6
  "homepage": "https://intor.dev",
@@ -32,6 +32,7 @@
32
32
  "exports": {
33
33
  ".": {
34
34
  "import": "./dist/core/export/index.js",
35
+ "require": "./dist/core/export/index.js",
35
36
  "types": "./dist/types/export/index.d.ts"
36
37
  },
37
38
  "./internal": {
@@ -92,7 +93,7 @@
92
93
  ],
93
94
  "sideEffects": false,
94
95
  "engines": {
95
- "node": ">=16.0.0"
96
+ "node": ">=20"
96
97
  },
97
98
  "scripts": {
98
99
  "type": "tsc --noEmit",
@@ -103,11 +104,10 @@
103
104
  "test:check": "tsx scripts/check-test-structure.ts",
104
105
  "knip": "knip --config .config/knip.config.ts",
105
106
  "build": "tsx scripts/build.ts",
106
- "prepublishOnly": "yarn build",
107
- "examples:html": "vite --config examples/html/vite.config.ts"
107
+ "prepublishOnly": "yarn build"
108
108
  },
109
109
  "dependencies": {
110
- "intor-translator": "1.4.13",
110
+ "intor-translator": "^1.4.14",
111
111
  "logry": "2.1.6",
112
112
  "p-limit": "7.2.0"
113
113
  },
@@ -152,6 +152,7 @@
152
152
  "svelte": "5.46.1",
153
153
  "tsc-alias": "1.8.16",
154
154
  "tsd": "0.33.0",
155
+ "tsx": "^4.21.0",
155
156
  "typescript": "5.8.3",
156
157
  "typescript-eslint": "8.32.1",
157
158
  "vite": "7.3.0",