fuma-translate 0.0.1 → 0.0.3

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.
@@ -0,0 +1,21 @@
1
+ import { Span } from "oxc-parser";
2
+
3
+ //#region src/compiler.d.ts
4
+ interface CompileOptions {
5
+ /** glob patterns */
6
+ input: string[];
7
+ }
8
+ interface CompileOutput {
9
+ /** All encoded keys */
10
+ translationKeys: string[];
11
+ }
12
+ declare class StaticAnalysisError extends Error {
13
+ readonly file: string;
14
+ readonly span?: Span | undefined;
15
+ constructor(message: string, file: string, span?: Span | undefined);
16
+ }
17
+ declare function compile(options: CompileOptions): Promise<CompileOutput>;
18
+ declare function typegen(output: CompileOutput): string;
19
+ //#endregion
20
+ export { CompileOptions, CompileOutput, StaticAnalysisError, compile, typegen };
21
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/compiler.ts"],"mappings":";;;UAgBiB,cAAA;;EAEf,KAAK;AAAA;AAAA,UAGU,aAAA;EAHV;EAKL,eAAe;AAAA;AAAA,cAGJ,mBAAA,SAA4B,KAAA;EAAA,SAG5B,IAAA;EAAA,SACA,IAAA,GAAO,IAAA;cAFhB,OAAA,UACS,IAAA,UACA,IAAA,GAAO,IAAA;AAAA;AAAA,iBAyWE,OAAA,CAAQ,OAAA,EAAS,cAAA,GAAiB,OAAA,CAAQ,aAAA;AAAA,iBAkBhD,OAAA,CAAQ,MAAqB,EAAb,aAAa"}
package/dist/index.mjs ADDED
@@ -0,0 +1,218 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { Visitor, parseSync } from "oxc-parser";
4
+ import { glob } from "tinyglobby";
5
+ //#region src/compiler.ts
6
+ var StaticAnalysisError = class extends Error {
7
+ file;
8
+ span;
9
+ constructor(message, file, span) {
10
+ super(message);
11
+ this.file = file;
12
+ this.span = span;
13
+ this.name = "StaticAnalysisError";
14
+ }
15
+ };
16
+ function formatLocation(source, offset) {
17
+ let line = 1;
18
+ let column = 1;
19
+ for (let i = 0; i < offset && i < source.length; i++) if (source[i] === "\n") {
20
+ line++;
21
+ column = 1;
22
+ } else column++;
23
+ return `${line}:${column}`;
24
+ }
25
+ function parseUseTranslationsCall(expr, source, file) {
26
+ if (expr.type !== "CallExpression") return null;
27
+ if (expr.callee.type !== "Identifier" || expr.callee.name !== "useTranslations") return null;
28
+ if (expr.arguments.length === 0) return [void 0];
29
+ if (expr.arguments.length > 1) fail(source, file, expr, "useTranslations accepts at most one options argument");
30
+ const arg = expr.arguments[0];
31
+ if (!arg || arg.type === "SpreadElement") fail(source, file, arg ?? expr, "useTranslations options must be a static object");
32
+ return collectNotes(arg, source, file);
33
+ }
34
+ function unwrapExpression(expr) {
35
+ while (expr.type === "ParenthesizedExpression" || expr.type === "TSAsExpression" || expr.type === "TSSatisfiesExpression" || expr.type === "TSTypeAssertion") expr = expr.expression;
36
+ return expr;
37
+ }
38
+ function fail(source, file, span, message) {
39
+ throw new StaticAnalysisError(`${file}:${formatLocation(source, span.start)}: ${message}`, file, span);
40
+ }
41
+ function collectStaticStrings(expr, source, file) {
42
+ expr = unwrapExpression(expr);
43
+ if (expr.type === "Literal" && typeof expr.value === "string") return [expr.value];
44
+ if (expr.type === "TemplateLiteral") {
45
+ if (expr.expressions.length > 0) fail(source, file, expr, "translation key must be a static string");
46
+ return [expr.quasis.map((q) => q.value.cooked ?? q.value.raw).join("")];
47
+ }
48
+ if (expr.type === "ConditionalExpression") return [...collectStaticStrings(expr.consequent, source, file), ...collectStaticStrings(expr.alternate, source, file)];
49
+ fail(source, file, expr, "translation key must be a static string");
50
+ }
51
+ function getNoteProperty(properties) {
52
+ for (const prop of properties) {
53
+ if (prop.type !== "Property") continue;
54
+ if (prop.kind !== "init") continue;
55
+ if (prop.shorthand && prop.key.type === "Identifier") {
56
+ if (prop.key.name === "note") return prop;
57
+ continue;
58
+ }
59
+ if (prop.key.type === "Identifier" && prop.key.name === "note") return prop;
60
+ if (prop.key.type === "Literal" && typeof prop.key.value === "string" && prop.key.value === "note") return prop;
61
+ }
62
+ }
63
+ function collectNotes(expr, source, file) {
64
+ if (!expr) return [void 0];
65
+ expr = unwrapExpression(expr);
66
+ if (expr.type === "ConditionalExpression") return [...collectNotes(expr.consequent, source, file), ...collectNotes(expr.alternate, source, file)];
67
+ if (expr.type !== "ObjectExpression") fail(source, file, expr, "translation options must be a static object");
68
+ for (const prop of expr.properties) if (prop.type === "SpreadElement") fail(source, file, prop, "translation options cannot use spread properties");
69
+ const noteProp = getNoteProperty(expr.properties);
70
+ if (!noteProp) return [void 0];
71
+ if (noteProp.shorthand) fail(source, file, noteProp, "translation note must be a static string");
72
+ return collectStaticStrings(noteProp.value, source, file).map((note) => note);
73
+ }
74
+ function currentScope(scopes) {
75
+ const scope = scopes.at(-1);
76
+ if (!scope) throw new Error("scope stack is empty");
77
+ return scope;
78
+ }
79
+ function registerBinding(pattern, hookNotes, scopes) {
80
+ switch (pattern.type) {
81
+ case "Identifier":
82
+ currentScope(scopes).set(pattern.name, hookNotes);
83
+ return;
84
+ case "ObjectPattern":
85
+ for (const prop of pattern.properties) if (prop.type === "RestElement") registerBinding(prop.argument, false, scopes);
86
+ else registerBinding(prop.value, false, scopes);
87
+ return;
88
+ case "ArrayPattern":
89
+ for (const element of pattern.elements) {
90
+ if (!element) continue;
91
+ if (element.type === "RestElement") registerBinding(element.argument, false, scopes);
92
+ else registerBinding(element, false, scopes);
93
+ }
94
+ return;
95
+ case "AssignmentPattern":
96
+ registerBinding(pattern.left, hookNotes, scopes);
97
+ return;
98
+ }
99
+ }
100
+ function registerParams(params, scopes) {
101
+ for (const param of params) if (param.type === "TSParameterProperty") registerBinding(param.parameter, false, scopes);
102
+ else if (param.type === "RestElement") registerBinding(param.argument, false, scopes);
103
+ else registerBinding(param, false, scopes);
104
+ }
105
+ function getTranslationHookNotes(name, scopes) {
106
+ for (let i = scopes.length - 1; i >= 0; i--) {
107
+ const scope = scopes[i];
108
+ if (!scope) continue;
109
+ if (scope.has(name)) return scope.get(name);
110
+ }
111
+ return false;
112
+ }
113
+ function encodeTranslationKey(text, hookNotes, callNotes) {
114
+ const keys = [];
115
+ for (const hookNote of hookNotes) for (const callNote of callNotes) {
116
+ const notes = [];
117
+ if (hookNote) notes.push(hookNote);
118
+ if (callNote) notes.push(callNote);
119
+ keys.push(encodeKey(text, notes));
120
+ }
121
+ return keys;
122
+ }
123
+ function analyzeCall(call, source, file, keys, scopes) {
124
+ const callee = unwrapExpression(call.callee);
125
+ if (callee.type !== "Identifier") return;
126
+ const hookNotes = getTranslationHookNotes(callee.name, scopes);
127
+ if (hookNotes === false) return;
128
+ if (call.arguments.length === 0) fail(source, file, call, "translation call requires a static string argument");
129
+ const firstArg = call.arguments[0];
130
+ if (!firstArg || firstArg.type === "SpreadElement") fail(source, file, firstArg ?? call, "translation key must be a static string");
131
+ const texts = collectStaticStrings(firstArg, source, file);
132
+ let callNotes = [void 0];
133
+ if (call.arguments.length > 1) {
134
+ const secondArg = call.arguments[1];
135
+ if (!secondArg || secondArg.type === "SpreadElement") fail(source, file, secondArg ?? call, "translation options must be a static object");
136
+ callNotes = collectNotes(secondArg, source, file);
137
+ }
138
+ for (const text of texts) for (const key of encodeTranslationKey(text, hookNotes, callNotes)) keys.add(key);
139
+ }
140
+ function analyzeSource(file, lang, source) {
141
+ const result = parseSync(file, source, {
142
+ lang,
143
+ sourceType: "module"
144
+ });
145
+ if (result.errors.length > 0) throw new StaticAnalysisError(result.errors.map((error) => error.message).join("\n"), file);
146
+ const keys = /* @__PURE__ */ new Set();
147
+ const scopes = [/* @__PURE__ */ new Map()];
148
+ const pushScope = () => {
149
+ scopes.push(/* @__PURE__ */ new Map());
150
+ };
151
+ const popScope = () => {
152
+ scopes.pop();
153
+ };
154
+ new Visitor({
155
+ BlockStatement: pushScope,
156
+ "BlockStatement:exit": popScope,
157
+ CatchClause: pushScope,
158
+ "CatchClause:exit": popScope,
159
+ FunctionDeclaration(node) {
160
+ pushScope();
161
+ registerParams(node.params, scopes);
162
+ },
163
+ "FunctionDeclaration:exit": popScope,
164
+ FunctionExpression(node) {
165
+ pushScope();
166
+ registerParams(node.params, scopes);
167
+ },
168
+ "FunctionExpression:exit": popScope,
169
+ ArrowFunctionExpression(node) {
170
+ pushScope();
171
+ registerParams(node.params, scopes);
172
+ },
173
+ "ArrowFunctionExpression:exit": popScope,
174
+ VariableDeclarator(decl) {
175
+ if (!decl.init) return;
176
+ const hookNotes = parseUseTranslationsCall(unwrapExpression(decl.init), source, file);
177
+ registerBinding(decl.id, hookNotes ?? false, scopes);
178
+ },
179
+ CallExpression(call) {
180
+ analyzeCall(call, source, file, keys, scopes);
181
+ }
182
+ }).visit(result.program);
183
+ return [...keys];
184
+ }
185
+ function getLang(file) {
186
+ switch (path.extname(file)) {
187
+ case ".tsx": return "tsx";
188
+ case ".ts":
189
+ case ".cts":
190
+ case ".mts": return "ts";
191
+ case ".jsx": return "jsx";
192
+ case ".cjs":
193
+ case ".mjs":
194
+ case ".js": return "js";
195
+ }
196
+ }
197
+ async function compile(options) {
198
+ const files = await glob(options.input, { absolute: true });
199
+ const keys = /* @__PURE__ */ new Set();
200
+ for (const file of files) {
201
+ const lang = getLang(file);
202
+ if (!lang) continue;
203
+ const source = await fs.readFile(file, "utf8");
204
+ for (const key of analyzeSource(file, lang, source)) keys.add(key);
205
+ }
206
+ return { translationKeys: [...keys].sort() };
207
+ }
208
+ function typegen(output) {
209
+ if (output.translationKeys.length === 0) return "export type Translations = {};\n";
210
+ return `export type Translations = {\n${output.translationKeys.map((key) => ` ${JSON.stringify(key)}: string;`).join("\n")}\n};\n`;
211
+ }
212
+ function encodeKey(text, notes) {
213
+ return text + notes.map((n) => `(${n})`).join("");
214
+ }
215
+ //#endregion
216
+ export { StaticAnalysisError, compile, typegen };
217
+
218
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/compiler.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type {\n BindingPattern,\n CallExpression,\n Expression,\n ObjectProperty,\n ObjectPropertyKind,\n ParamPattern,\n Span,\n} from \"oxc-parser\";\nimport { parseSync, Visitor } from \"oxc-parser\";\nimport { glob } from \"tinyglobby\";\n\ntype SupportedLang = \"js\" | \"jsx\" | \"ts\" | \"tsx\";\n\nexport interface CompileOptions {\n /** glob patterns */\n input: string[];\n}\n\nexport interface CompileOutput {\n /** All encoded keys */\n translationKeys: string[];\n}\n\nexport class StaticAnalysisError extends Error {\n constructor(\n message: string,\n readonly file: string,\n readonly span?: Span,\n ) {\n super(message);\n this.name = \"StaticAnalysisError\";\n }\n}\n\nfunction formatLocation(source: string, offset: number): string {\n let line = 1;\n let column = 1;\n\n for (let i = 0; i < offset && i < source.length; i++) {\n if (source[i] === \"\\n\") {\n line++;\n column = 1;\n } else {\n column++;\n }\n }\n\n return `${line}:${column}`;\n}\n\ntype HookNoteBranches = (string | undefined)[];\n\nfunction parseUseTranslationsCall(\n expr: Expression,\n source: string,\n file: string,\n): HookNoteBranches | null {\n if (expr.type !== \"CallExpression\") return null;\n if (expr.callee.type !== \"Identifier\" || expr.callee.name !== \"useTranslations\") {\n return null;\n }\n\n if (expr.arguments.length === 0) return [undefined];\n\n if (expr.arguments.length > 1) {\n fail(source, file, expr, \"useTranslations accepts at most one options argument\");\n }\n\n const arg = expr.arguments[0];\n if (!arg || arg.type === \"SpreadElement\") {\n fail(source, file, arg ?? expr, \"useTranslations options must be a static object\");\n }\n\n return collectNotes(arg, source, file);\n}\n\nfunction unwrapExpression(expr: Expression): Expression {\n while (\n expr.type === \"ParenthesizedExpression\" ||\n expr.type === \"TSAsExpression\" ||\n expr.type === \"TSSatisfiesExpression\" ||\n expr.type === \"TSTypeAssertion\"\n ) {\n expr = expr.expression;\n }\n return expr;\n}\n\nfunction fail(source: string, file: string, span: Span, message: string): never {\n throw new StaticAnalysisError(\n `${file}:${formatLocation(source, span.start)}: ${message}`,\n file,\n span,\n );\n}\n\nfunction collectStaticStrings(expr: Expression, source: string, file: string): string[] {\n expr = unwrapExpression(expr);\n\n if (expr.type === \"Literal\" && typeof expr.value === \"string\") {\n return [expr.value];\n }\n\n if (expr.type === \"TemplateLiteral\") {\n if (expr.expressions.length > 0) {\n fail(source, file, expr, \"translation key must be a static string\");\n }\n return [expr.quasis.map((q) => q.value.cooked ?? q.value.raw).join(\"\")];\n }\n\n if (expr.type === \"ConditionalExpression\") {\n return [\n ...collectStaticStrings(expr.consequent, source, file),\n ...collectStaticStrings(expr.alternate, source, file),\n ];\n }\n\n fail(source, file, expr, \"translation key must be a static string\");\n}\n\nfunction getNoteProperty(properties: ObjectPropertyKind[]): ObjectProperty | undefined {\n for (const prop of properties) {\n if (prop.type !== \"Property\") continue;\n if (prop.kind !== \"init\") continue;\n\n if (prop.shorthand && prop.key.type === \"Identifier\") {\n if (prop.key.name === \"note\") return prop;\n continue;\n }\n\n if (prop.key.type === \"Identifier\" && prop.key.name === \"note\") {\n return prop;\n }\n\n if (\n prop.key.type === \"Literal\" &&\n typeof prop.key.value === \"string\" &&\n prop.key.value === \"note\"\n ) {\n return prop;\n }\n }\n return undefined;\n}\n\nfunction collectNotes(\n expr: Expression | undefined,\n source: string,\n file: string,\n): (string | undefined)[] {\n if (!expr) return [undefined];\n\n expr = unwrapExpression(expr);\n\n if (expr.type === \"ConditionalExpression\") {\n return [\n ...collectNotes(expr.consequent, source, file),\n ...collectNotes(expr.alternate, source, file),\n ];\n }\n\n if (expr.type !== \"ObjectExpression\") {\n fail(source, file, expr, \"translation options must be a static object\");\n }\n\n for (const prop of expr.properties) {\n if (prop.type === \"SpreadElement\") {\n fail(source, file, prop, \"translation options cannot use spread properties\");\n }\n }\n\n const noteProp = getNoteProperty(expr.properties);\n if (!noteProp) return [undefined];\n\n if (noteProp.shorthand) {\n fail(source, file, noteProp, \"translation note must be a static string\");\n }\n\n const noteValues = collectStaticStrings(noteProp.value, source, file);\n return noteValues.map((note) => note);\n}\n\nfunction currentScope(\n scopes: Map<string, HookNoteBranches | false>[],\n): Map<string, HookNoteBranches | false> {\n const scope = scopes.at(-1);\n if (!scope) throw new Error(\"scope stack is empty\");\n return scope;\n}\n\nfunction registerBinding(\n pattern: BindingPattern,\n hookNotes: HookNoteBranches | false,\n scopes: Map<string, HookNoteBranches | false>[],\n): void {\n switch (pattern.type) {\n case \"Identifier\":\n currentScope(scopes).set(pattern.name, hookNotes);\n return;\n case \"ObjectPattern\":\n for (const prop of pattern.properties) {\n if (prop.type === \"RestElement\") {\n registerBinding(prop.argument, false, scopes);\n } else {\n registerBinding(prop.value, false, scopes);\n }\n }\n return;\n case \"ArrayPattern\":\n for (const element of pattern.elements) {\n if (!element) continue;\n if (element.type === \"RestElement\") {\n registerBinding(element.argument, false, scopes);\n } else {\n registerBinding(element, false, scopes);\n }\n }\n return;\n case \"AssignmentPattern\":\n registerBinding(pattern.left, hookNotes, scopes);\n return;\n }\n}\n\nfunction registerParams(\n params: ParamPattern[],\n scopes: Map<string, HookNoteBranches | false>[],\n): void {\n for (const param of params) {\n if (param.type === \"TSParameterProperty\") {\n registerBinding(param.parameter, false, scopes);\n } else if (param.type === \"RestElement\") {\n registerBinding(param.argument, false, scopes);\n } else {\n registerBinding(param, false, scopes);\n }\n }\n}\n\nfunction getTranslationHookNotes(\n name: string,\n scopes: Map<string, HookNoteBranches | false>[],\n): HookNoteBranches | false {\n for (let i = scopes.length - 1; i >= 0; i--) {\n const scope = scopes[i];\n if (!scope) continue;\n if (scope.has(name)) return scope.get(name)!;\n }\n return false;\n}\n\nfunction encodeTranslationKey(\n text: string,\n hookNotes: HookNoteBranches,\n callNotes: HookNoteBranches,\n): string[] {\n const keys: string[] = [];\n\n for (const hookNote of hookNotes) {\n for (const callNote of callNotes) {\n const notes: string[] = [];\n if (hookNote) notes.push(hookNote);\n if (callNote) notes.push(callNote);\n keys.push(encodeKey(text, notes));\n }\n }\n\n return keys;\n}\n\nfunction analyzeCall(\n call: CallExpression,\n source: string,\n file: string,\n keys: Set<string>,\n scopes: Map<string, HookNoteBranches | false>[],\n): void {\n const callee = unwrapExpression(call.callee);\n if (callee.type !== \"Identifier\") return;\n\n const hookNotes = getTranslationHookNotes(callee.name, scopes);\n if (hookNotes === false) return;\n\n if (call.arguments.length === 0) {\n fail(source, file, call, \"translation call requires a static string argument\");\n }\n\n const firstArg = call.arguments[0];\n if (!firstArg || firstArg.type === \"SpreadElement\") {\n fail(source, file, firstArg ?? call, \"translation key must be a static string\");\n }\n\n const texts = collectStaticStrings(firstArg, source, file);\n\n let callNotes: HookNoteBranches = [undefined];\n if (call.arguments.length > 1) {\n const secondArg = call.arguments[1];\n if (!secondArg || secondArg.type === \"SpreadElement\") {\n fail(source, file, secondArg ?? call, \"translation options must be a static object\");\n }\n callNotes = collectNotes(secondArg, source, file);\n }\n\n for (const text of texts) {\n for (const key of encodeTranslationKey(text, hookNotes, callNotes)) {\n keys.add(key);\n }\n }\n}\n\nfunction analyzeSource(file: string, lang: SupportedLang, source: string): string[] {\n const result = parseSync(file, source, { lang, sourceType: \"module\" });\n\n if (result.errors.length > 0) {\n const message = result.errors.map((error) => error.message).join(\"\\n\");\n throw new StaticAnalysisError(message, file);\n }\n\n const keys = new Set<string>();\n const scopes: Map<string, HookNoteBranches | false>[] = [new Map()];\n\n const pushScope = () => {\n scopes.push(new Map());\n };\n\n const popScope = () => {\n scopes.pop();\n };\n\n const visitor = new Visitor({\n BlockStatement: pushScope,\n \"BlockStatement:exit\": popScope,\n\n CatchClause: pushScope,\n \"CatchClause:exit\": popScope,\n\n FunctionDeclaration(node) {\n pushScope();\n registerParams(node.params, scopes);\n },\n \"FunctionDeclaration:exit\": popScope,\n\n FunctionExpression(node) {\n pushScope();\n registerParams(node.params, scopes);\n },\n \"FunctionExpression:exit\": popScope,\n\n ArrowFunctionExpression(node) {\n pushScope();\n registerParams(node.params, scopes);\n },\n \"ArrowFunctionExpression:exit\": popScope,\n\n VariableDeclarator(decl) {\n if (!decl.init) return;\n\n const init = unwrapExpression(decl.init);\n const hookNotes = parseUseTranslationsCall(init, source, file);\n registerBinding(decl.id, hookNotes ?? false, scopes);\n },\n\n CallExpression(call) {\n analyzeCall(call, source, file, keys, scopes);\n },\n });\n\n visitor.visit(result.program);\n return [...keys];\n}\n\nfunction getLang(file: string): SupportedLang | undefined {\n switch (path.extname(file)) {\n case \".tsx\":\n return \"tsx\";\n case \".ts\":\n case \".cts\":\n case \".mts\":\n return \"ts\";\n case \".jsx\":\n return \"jsx\";\n case \".cjs\":\n case \".mjs\":\n case \".js\":\n return \"js\";\n }\n}\n\nexport async function compile(options: CompileOptions): Promise<CompileOutput> {\n const files = await glob(options.input, { absolute: true });\n const keys = new Set<string>();\n\n for (const file of files) {\n const lang = getLang(file);\n if (!lang) continue;\n\n const source = await fs.readFile(file, \"utf8\");\n for (const key of analyzeSource(file, lang, source)) {\n keys.add(key);\n }\n }\n\n const translationKeys = [...keys].sort();\n return { translationKeys };\n}\n\nexport function typegen(output: CompileOutput): string {\n if (output.translationKeys.length === 0) {\n return \"export type Translations = {};\\n\";\n }\n\n const entries = output.translationKeys\n .map((key) => ` ${JSON.stringify(key)}: string;`)\n .join(\"\\n\");\n\n return `export type Translations = {\\n${entries}\\n};\\n`;\n}\n\nfunction encodeKey(text: string, notes: string[]): string {\n return text + notes.map((n) => `(${n})`).join(\"\");\n}\n"],"mappings":";;;;;AA0BA,IAAa,sBAAb,cAAyC,MAAM;CAGlC;CACA;CAHX,YACE,SACA,MACA,MACA;EACA,MAAM,OAAO;EAHJ,KAAA,OAAA;EACA,KAAA,OAAA;EAGT,KAAK,OAAO;CACd;AACF;AAEA,SAAS,eAAe,QAAgB,QAAwB;CAC9D,IAAI,OAAO;CACX,IAAI,SAAS;CAEb,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,IAAI,OAAO,QAAQ,KAC/C,IAAI,OAAO,OAAO,MAAM;EACtB;EACA,SAAS;CACX,OACE;CAIJ,OAAO,GAA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AQ,QAA+B;CACrD,IAAI,OAAO,gBAAgB,WAAW,GACpC,OAAO;CAOT,OAAO,iCAJS,OAAO,gBACpB,KAAK,QAAQ,KAAK,KAAK,UAAU,GAAG,EAAE,UAAU,CAAC,CACjD,KAAK,IAEsC,EAAE;AAClD;AAEA,SAAS,UAAU,MAAc,OAAyB;CACxD,OAAO,OAAO,MAAM,KAAK,MAAM,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE;AAClD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fuma-translate",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "The build-time package to implement multilingual in your JavaScript app",
5
5
  "license": "MIT",
6
6
  "author": "Fuma Nama",
@@ -10,8 +10,7 @@
10
10
  ],
11
11
  "type": "module",
12
12
  "exports": {
13
- "./compiler": "./dist/compiler.mjs",
14
- "./react": "./dist/react.mjs",
13
+ ".": "./dist/index.mjs",
15
14
  "./package.json": "./package.json"
16
15
  },
17
16
  "publishConfig": {
@@ -23,30 +22,11 @@
23
22
  },
24
23
  "devDependencies": {
25
24
  "@types/node": "^25.9.2",
26
- "@types/react": "19.2.17",
27
- "@types/react-dom": "19.2.3",
28
- "react": "^19.2.7",
29
- "react-dom": "^19.2.7",
25
+ "@types/react": "^19.2.17",
30
26
  "tsdown": "^0.22.2",
31
27
  "typescript": "6.0.3",
32
28
  "@repo/typescript-config": "0.0.0"
33
29
  },
34
- "peerDependencies": {
35
- "@types/react": "*",
36
- "react": "^19.2.0",
37
- "react-dom": "^19.2.0"
38
- },
39
- "peerDependenciesMeta": {
40
- "react": {
41
- "optional": true
42
- },
43
- "react-dom": {
44
- "optional": true
45
- },
46
- "@types/react": {
47
- "optional": true
48
- }
49
- },
50
30
  "scripts": {
51
31
  "types:check": "tsc --noEmit",
52
32
  "build": "tsdown",