fuma-translate 0.0.3 → 1.0.1
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/dist/cli.d.mts +24 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.mjs +168 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/compiler-DxWiaGcG.mjs +28 -0
- package/dist/compiler-DxWiaGcG.mjs.map +1 -0
- package/dist/index.d.mts +10 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -217
- package/native/browser.js +1 -0
- package/native/native.d.ts +7 -0
- package/native/native.js +593 -0
- package/package.json +58 -7
- package/dist/index.mjs.map +0 -1
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/cli.d.ts
|
|
2
|
+
interface CompileAndWriteOptions {
|
|
3
|
+
input: string[];
|
|
4
|
+
out: string;
|
|
5
|
+
strict: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface WatchOptions extends CompileAndWriteOptions {
|
|
8
|
+
onCompiled?: (result: {
|
|
9
|
+
ok: true;
|
|
10
|
+
keyCount: number;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
error: string;
|
|
14
|
+
}) => void;
|
|
15
|
+
}
|
|
16
|
+
declare function getWatchRoots(globs: string[]): string[];
|
|
17
|
+
declare function compileAndWrite(options: CompileAndWriteOptions): Promise<{
|
|
18
|
+
keyCount: number;
|
|
19
|
+
}>;
|
|
20
|
+
declare function watchCompile(options: WatchOptions, signal?: AbortSignal): Promise<void>;
|
|
21
|
+
declare function main(argv?: string[]): Promise<number>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { CompileAndWriteOptions, WatchOptions, compileAndWrite, getWatchRoots, main, watchCompile };
|
|
24
|
+
//# sourceMappingURL=cli.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.mts","names":[],"sources":["../src/cli.ts"],"mappings":";UA0BiB,sBAAA;EACf,KAAA;EACA,GAAA;EACA,MAAA;AAAA;AAAA,UAGe,YAAA,SAAqB,sBAAsB;EAC1D,UAAA,IAAc,MAAA;IAAU,EAAA;IAAU,QAAA;EAAA;IAAuB,EAAA;IAAW,KAAA;EAAA;AAAA;AAAA,iBAGtD,aAAA,CAAc,KAAe;AAAA,iBA0BvB,eAAA,CACpB,OAAA,EAAS,sBAAA,GACR,OAAO;EAAG,QAAA;AAAA;AAAA,iBAWS,YAAA,CAAa,OAAA,EAAS,YAAA,EAAc,MAAA,GAAS,WAAA,GAAc,OAAA;AAAA,iBA+D3D,IAAA,CAAK,IAAA,cAAyC,OAAO"}
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { n as compile, r as typegen, t as StaticAnalysisError } from "./compiler-DxWiaGcG.mjs";
|
|
3
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import chokidar from "chokidar";
|
|
8
|
+
//#region src/cli.ts
|
|
9
|
+
function writeManifest(output) {
|
|
10
|
+
return `${JSON.stringify({ translationKeys: [...output.translationKeys].sort() }, null, 2)}\n`;
|
|
11
|
+
}
|
|
12
|
+
const HELP = `Usage: fuma-translate [options] <glob>...
|
|
13
|
+
|
|
14
|
+
Compile translation keys from source files.
|
|
15
|
+
|
|
16
|
+
Arguments:
|
|
17
|
+
<glob>... Glob patterns to scan (e.g. src/**/*.tsx)
|
|
18
|
+
|
|
19
|
+
Options:
|
|
20
|
+
-o, --out <dir> Output directory (default: .translations)
|
|
21
|
+
-w, --watch Recompile when matching files change
|
|
22
|
+
--no-strict Extract all static t() calls, not only hook-bound ones
|
|
23
|
+
-h, --help Show this help message
|
|
24
|
+
`;
|
|
25
|
+
function getWatchRoots(globs) {
|
|
26
|
+
const roots = /* @__PURE__ */ new Set();
|
|
27
|
+
for (const pattern of globs) {
|
|
28
|
+
const index = pattern.search(/[*?[{]/);
|
|
29
|
+
const root = index === -1 ? dirname(pattern) : pattern.slice(0, index).replace(/[/\\]+$/, "") || ".";
|
|
30
|
+
roots.add(resolve(root));
|
|
31
|
+
}
|
|
32
|
+
return [...roots];
|
|
33
|
+
}
|
|
34
|
+
function debounce(fn, ms) {
|
|
35
|
+
let timer;
|
|
36
|
+
return () => {
|
|
37
|
+
if (timer) clearTimeout(timer);
|
|
38
|
+
timer = setTimeout(fn, ms);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function compileAndWrite(options) {
|
|
42
|
+
const output = await compile({
|
|
43
|
+
input: options.input,
|
|
44
|
+
strict: options.strict
|
|
45
|
+
});
|
|
46
|
+
const outDir = resolve(options.out);
|
|
47
|
+
await mkdir(outDir, { recursive: true });
|
|
48
|
+
await writeFile(join(outDir, "manifest.json"), writeManifest(output), "utf8");
|
|
49
|
+
await writeFile(join(outDir, "index.ts"), typegen(output), "utf8");
|
|
50
|
+
return { keyCount: output.translationKeys.length };
|
|
51
|
+
}
|
|
52
|
+
async function watchCompile(options, signal) {
|
|
53
|
+
const outDir = resolve(options.out);
|
|
54
|
+
const roots = getWatchRoots(options.input);
|
|
55
|
+
let compiling = false;
|
|
56
|
+
let queued = false;
|
|
57
|
+
const run = async () => {
|
|
58
|
+
if (compiling) {
|
|
59
|
+
queued = true;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
compiling = true;
|
|
63
|
+
try {
|
|
64
|
+
const { keyCount } = await compileAndWrite(options);
|
|
65
|
+
options.onCompiled?.({
|
|
66
|
+
ok: true,
|
|
67
|
+
keyCount
|
|
68
|
+
});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
const message = error instanceof StaticAnalysisError ? error.message : String(error);
|
|
71
|
+
process.stderr.write(`${message}\n`);
|
|
72
|
+
options.onCompiled?.({
|
|
73
|
+
ok: false,
|
|
74
|
+
error: message
|
|
75
|
+
});
|
|
76
|
+
} finally {
|
|
77
|
+
compiling = false;
|
|
78
|
+
if (queued) {
|
|
79
|
+
queued = false;
|
|
80
|
+
run();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const schedule = debounce(() => {
|
|
85
|
+
run();
|
|
86
|
+
}, 100);
|
|
87
|
+
const watcher = chokidar.watch(roots, {
|
|
88
|
+
ignoreInitial: true,
|
|
89
|
+
ignored: (path) => path.startsWith(outDir),
|
|
90
|
+
awaitWriteFinish: {
|
|
91
|
+
stabilityThreshold: 100,
|
|
92
|
+
pollInterval: 50
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
watcher.on("all", schedule);
|
|
96
|
+
if (signal) {
|
|
97
|
+
if (signal.aborted) {
|
|
98
|
+
await watcher.close();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
signal.addEventListener("abort", () => {
|
|
102
|
+
watcher.close();
|
|
103
|
+
}, { once: true });
|
|
104
|
+
}
|
|
105
|
+
process.stdout.write(`Watching ${options.input.join(", ")}...\n`);
|
|
106
|
+
await run();
|
|
107
|
+
}
|
|
108
|
+
async function main(argv = process.argv.slice(2)) {
|
|
109
|
+
const { values, positionals } = parseArgs({
|
|
110
|
+
args: argv,
|
|
111
|
+
options: {
|
|
112
|
+
out: {
|
|
113
|
+
type: "string",
|
|
114
|
+
short: "o",
|
|
115
|
+
default: ".translations"
|
|
116
|
+
},
|
|
117
|
+
watch: {
|
|
118
|
+
type: "boolean",
|
|
119
|
+
short: "w",
|
|
120
|
+
default: false
|
|
121
|
+
},
|
|
122
|
+
strict: {
|
|
123
|
+
type: "boolean",
|
|
124
|
+
default: true
|
|
125
|
+
},
|
|
126
|
+
help: {
|
|
127
|
+
type: "boolean",
|
|
128
|
+
short: "h",
|
|
129
|
+
default: false
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
allowPositionals: true
|
|
133
|
+
});
|
|
134
|
+
if (values.help) {
|
|
135
|
+
process.stdout.write(HELP);
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
if (positionals.length === 0) {
|
|
139
|
+
process.stderr.write(HELP);
|
|
140
|
+
return 1;
|
|
141
|
+
}
|
|
142
|
+
const options = {
|
|
143
|
+
input: positionals,
|
|
144
|
+
out: values.out,
|
|
145
|
+
strict: values.strict
|
|
146
|
+
};
|
|
147
|
+
if (values.watch) {
|
|
148
|
+
await watchCompile(options);
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
await compileAndWrite(options);
|
|
153
|
+
return 0;
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (error instanceof StaticAnalysisError) {
|
|
156
|
+
process.stderr.write(`${error.message}\n`);
|
|
157
|
+
return 1;
|
|
158
|
+
}
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if ((process.argv[1] ? resolve(process.argv[1]) : "") === fileURLToPath(import.meta.url)) main().then((code) => {
|
|
163
|
+
process.exitCode = code;
|
|
164
|
+
});
|
|
165
|
+
//#endregion
|
|
166
|
+
export { compileAndWrite, getWatchRoots, main, watchCompile };
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=cli.mjs.map
|
package/dist/cli.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { parseArgs } from \"node:util\";\nimport chokidar from \"chokidar\";\nimport { compile, StaticAnalysisError, typegen, type CompileOutput } from \"./compiler\";\n\nfunction writeManifest(output: CompileOutput): string {\n return `${JSON.stringify({ translationKeys: [...output.translationKeys].sort() }, null, 2)}\\n`;\n}\n\nconst HELP = `Usage: fuma-translate [options] <glob>...\n\nCompile translation keys from source files.\n\nArguments:\n <glob>... Glob patterns to scan (e.g. src/**/*.tsx)\n\nOptions:\n -o, --out <dir> Output directory (default: .translations)\n -w, --watch Recompile when matching files change\n --no-strict Extract all static t() calls, not only hook-bound ones\n -h, --help Show this help message\n`;\n\nexport interface CompileAndWriteOptions {\n input: string[];\n out: string;\n strict: boolean;\n}\n\nexport interface WatchOptions extends CompileAndWriteOptions {\n onCompiled?: (result: { ok: true; keyCount: number } | { ok: false; error: string }) => void;\n}\n\nexport function getWatchRoots(globs: string[]): string[] {\n const roots = new Set<string>();\n\n for (const pattern of globs) {\n const index = pattern.search(/[*?[{]/);\n const root =\n index === -1 ? dirname(pattern) : pattern.slice(0, index).replace(/[/\\\\]+$/, \"\") || \".\";\n\n roots.add(resolve(root));\n }\n\n return [...roots];\n}\n\nfunction debounce(fn: () => void, ms: number): () => void {\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n return () => {\n if (timer) {\n clearTimeout(timer);\n }\n\n timer = setTimeout(fn, ms);\n };\n}\n\nexport async function compileAndWrite(\n options: CompileAndWriteOptions,\n): Promise<{ keyCount: number }> {\n const output = await compile({ input: options.input, strict: options.strict });\n const outDir = resolve(options.out);\n\n await mkdir(outDir, { recursive: true });\n await writeFile(join(outDir, \"manifest.json\"), writeManifest(output), \"utf8\");\n await writeFile(join(outDir, \"index.ts\"), typegen(output), \"utf8\");\n\n return { keyCount: output.translationKeys.length };\n}\n\nexport async function watchCompile(options: WatchOptions, signal?: AbortSignal): Promise<void> {\n const outDir = resolve(options.out);\n const roots = getWatchRoots(options.input);\n let compiling = false;\n let queued = false;\n\n const run = async () => {\n if (compiling) {\n queued = true;\n return;\n }\n\n compiling = true;\n\n try {\n const { keyCount } = await compileAndWrite(options);\n options.onCompiled?.({ ok: true, keyCount });\n } catch (error) {\n const message = error instanceof StaticAnalysisError ? error.message : String(error);\n\n process.stderr.write(`${message}\\n`);\n options.onCompiled?.({ ok: false, error: message });\n } finally {\n compiling = false;\n\n if (queued) {\n queued = false;\n void run();\n }\n }\n };\n\n const schedule = debounce(() => {\n void run();\n }, 100);\n\n const watcher = chokidar.watch(roots, {\n ignoreInitial: true,\n ignored: (path) => path.startsWith(outDir),\n awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 50 },\n });\n\n watcher.on(\"all\", schedule);\n\n if (signal) {\n if (signal.aborted) {\n await watcher.close();\n return;\n }\n\n signal.addEventListener(\n \"abort\",\n () => {\n void watcher.close();\n },\n { once: true },\n );\n }\n\n process.stdout.write(`Watching ${options.input.join(\", \")}...\\n`);\n await run();\n}\n\nexport async function main(argv: string[] = process.argv.slice(2)): Promise<number> {\n const { values, positionals } = parseArgs({\n args: argv,\n options: {\n out: { type: \"string\", short: \"o\", default: \".translations\" },\n watch: { type: \"boolean\", short: \"w\", default: false },\n strict: { type: \"boolean\", default: true },\n help: { type: \"boolean\", short: \"h\", default: false },\n },\n allowPositionals: true,\n });\n\n if (values.help) {\n process.stdout.write(HELP);\n return 0;\n }\n\n if (positionals.length === 0) {\n process.stderr.write(HELP);\n return 1;\n }\n\n const options: CompileAndWriteOptions = {\n input: positionals,\n out: values.out,\n strict: values.strict,\n };\n\n if (values.watch) {\n await watchCompile(options);\n return 0;\n }\n\n try {\n await compileAndWrite(options);\n return 0;\n } catch (error) {\n if (error instanceof StaticAnalysisError) {\n process.stderr.write(`${error.message}\\n`);\n return 1;\n }\n\n throw error;\n }\n}\n\nconst entry = process.argv[1] ? resolve(process.argv[1]) : \"\";\nconst isMain = entry === fileURLToPath(import.meta.url);\n\nif (isMain) {\n main().then((code) => {\n process.exitCode = code;\n });\n}\n"],"mappings":";;;;;;;;AAQA,SAAS,cAAc,QAA+B;CACpD,OAAO,GAAG,KAAK,UAAU,EAAE,iBAAiB,CAAC,GAAG,OAAO,eAAe,CAAC,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,EAAE;AAC7F;AAEA,MAAM,OAAO;;;;;;;;;;;;;AAwBb,SAAgB,cAAc,OAA2B;CACvD,MAAM,wBAAQ,I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AO;EAChB,MAAM,aAAa,OAAO;EAC1B,OAAO;CACT;CAEA,IAAI;EACF,MAAM,gBAAgB,OAAO;EAC7B,OAAO;CACT,SAAS,OAAO;EACd,IAAI,iBAAiB,qBAAqB;GACxC,QAAQ,OAAO,MAAM,GAAG,MAAM,QAAQ,GAAG;GACzC,OAAO;EACT;EAEA,MAAM;CACR;AACF;AAKA,KAHc,QAAQ,KAAK,KAAK,QAAQ,QAAQ,KAAK,EAAE,IAAI,QAClC,cAAc,OAAO,KAAK,GAAG,GAGpD,KAAK,CAAC,CAAC,MAAM,SAAS;CACpB,QAAQ,WAAW;AACrB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/compiler.ts
|
|
2
|
+
var StaticAnalysisError = class extends Error {
|
|
3
|
+
file;
|
|
4
|
+
span;
|
|
5
|
+
constructor(message, file = "", span) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.file = file;
|
|
8
|
+
this.span = span;
|
|
9
|
+
this.name = "StaticAnalysisError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
async function compile(options) {
|
|
13
|
+
const { compileSync } = await import("../native/native.js");
|
|
14
|
+
try {
|
|
15
|
+
return compileSync(options.input, options.strict);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error instanceof Error) throw new StaticAnalysisError(error.message);
|
|
18
|
+
throw new StaticAnalysisError(String(error));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function typegen(output) {
|
|
22
|
+
if (output.translationKeys.length === 0) return "export type Translations = {};\n";
|
|
23
|
+
return `export type Translations = {\n${output.translationKeys.sort().map((key) => ` ${JSON.stringify(key)}: string;`).join("\n")}\n};\n`;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { compile as n, typegen as r, StaticAnalysisError as t };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=compiler-DxWiaGcG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler-DxWiaGcG.mjs","names":[],"sources":["../src/compiler.ts"],"sourcesContent":["export interface CompileOptions {\n /** glob patterns */\n input: string[];\n /** when false, extract all static t() calls; defaults to true (only useTranslations/fromTranslations) */\n strict?: boolean;\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?: { start: number; end: number },\n ) {\n super(message);\n this.name = \"StaticAnalysisError\";\n }\n}\n\nexport async function compile(options: CompileOptions): Promise<CompileOutput> {\n const { compileSync } = await import(\"../native/native.js\");\n\n try {\n return compileSync(options.input, options.strict);\n } catch (error) {\n if (error instanceof Error) {\n throw new StaticAnalysisError(error.message);\n }\n\n throw new StaticAnalysisError(String(error));\n }\n}\n\nexport function typegen(output: CompileOutput): string {\n if (output.translationKeys.length === 0) {\n return \"export type Translations = {};\\n\";\n }\n\n const keys = output.translationKeys.sort();\n const entries = keys.map((key) => ` ${JSON.stringify(key)}: string;`).join(\"\\n\");\n\n return `export type Translations = {\\n${entries}\\n};\\n`;\n}\n"],"mappings":";AAYA,IAAa,sBAAb,cAAyC,MAAM;CAGlC;CACA;CAHX,YACE,SACA,OAAwB,IACxB,MACA;EACA,MAAM,OAAO;EAHJ,KAAA,OAAA;EACA,KAAA,OAAA;EAGT,KAAK,OAAO;CACd;AACF;AAEA,eAAsB,QAAQ,SAAiD;CAC7E,MAAM,EAAE,gBAAgB,MAAM,OAAO;CAErC,IAAI;EACF,OAAO,YAAY,QAAQ,OAAO,QAAQ,MAAM;CAClD,SAAS,OAAO;EACd,IAAI,iBAAiB,OACnB,MAAM,IAAI,oBAAoB,MAAM,OAAO;EAG7C,MAAM,IAAI,oBAAoB,OAAO,KAAK,CAAC;CAC7C;AACF;AAEA,SAAgB,QAAQ,QAA+B;CACrD,IAAI,OAAO,gBAAgB,WAAW,GACpC,OAAO;CAMT,OAAO,iCAHM,OAAO,gBAAgB,KACjB,CAAC,CAAC,KAAK,QAAQ,KAAK,KAAK,UAAU,GAAG,EAAE,UAAU,CAAC,CAAC,KAAK,IAE9B,EAAE;AAClD"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Span } from "oxc-parser";
|
|
2
|
-
|
|
3
1
|
//#region src/compiler.d.ts
|
|
4
2
|
interface CompileOptions {
|
|
5
3
|
/** glob patterns */
|
|
6
4
|
input: string[];
|
|
5
|
+
/** when false, extract all static t() calls; defaults to true (only useTranslations/fromTranslations) */
|
|
6
|
+
strict?: boolean;
|
|
7
7
|
}
|
|
8
8
|
interface CompileOutput {
|
|
9
9
|
/** All encoded keys */
|
|
@@ -11,8 +11,14 @@ interface CompileOutput {
|
|
|
11
11
|
}
|
|
12
12
|
declare class StaticAnalysisError extends Error {
|
|
13
13
|
readonly file: string;
|
|
14
|
-
readonly span?:
|
|
15
|
-
|
|
14
|
+
readonly span?: {
|
|
15
|
+
start: number;
|
|
16
|
+
end: number;
|
|
17
|
+
} | undefined;
|
|
18
|
+
constructor(message: string, file?: string, span?: {
|
|
19
|
+
start: number;
|
|
20
|
+
end: number;
|
|
21
|
+
} | undefined);
|
|
16
22
|
}
|
|
17
23
|
declare function compile(options: CompileOptions): Promise<CompileOutput>;
|
|
18
24
|
declare function typegen(output: CompileOutput): string;
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/compiler.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/compiler.ts"],"mappings":";UAAiB,cAAA;EAAA;EAEf,KAAA;;EAEA,MAAM;AAAA;AAAA,UAGS,aAAA;EAAa;EAE5B,eAAe;AAAA;AAAA,cAGJ,mBAAA,SAA4B,KAAK;EAAA,SAGjC,IAAA;EAAA,SACA,IAAA;IAAS,KAAA;IAAe,GAAA;EAAA;cAFjC,OAAA,UACS,IAAA,WACA,IAAA;IAAS,KAAA;IAAe,GAAA;EAAA;AAAA;AAAA,iBAOf,OAAA,CAAQ,OAAA,EAAS,cAAA,GAAiB,OAAA,CAAQ,aAAA;AAAA,iBAchD,OAAA,CAAQ,MAAqB,EAAb,aAAa"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,218 +1,2 @@
|
|
|
1
|
-
import
|
|
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
|
|
1
|
+
import { n as compile, r as typegen, t as StaticAnalysisError } from "./compiler-DxWiaGcG.mjs";
|
|
216
2
|
export { StaticAnalysisError, compile, typegen };
|
|
217
|
-
|
|
218
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@fuma-translate/binding-wasm32-wasi'
|
package/native/native.js
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
import { createRequire } from 'node:module'
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
|
+
const __dirname = new URL('.', import.meta.url).pathname
|
|
9
|
+
|
|
10
|
+
const { readFileSync } = require('node:fs')
|
|
11
|
+
let nativeBinding = null
|
|
12
|
+
const loadErrors = []
|
|
13
|
+
|
|
14
|
+
const isMusl = () => {
|
|
15
|
+
let musl = false
|
|
16
|
+
if (process.platform === 'linux') {
|
|
17
|
+
musl = isMuslFromFilesystem()
|
|
18
|
+
if (musl === null) {
|
|
19
|
+
musl = isMuslFromReport()
|
|
20
|
+
}
|
|
21
|
+
if (musl === null) {
|
|
22
|
+
musl = isMuslFromChildProcess()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return musl
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
29
|
+
|
|
30
|
+
const isMuslFromFilesystem = () => {
|
|
31
|
+
try {
|
|
32
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
33
|
+
} catch {
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const isMuslFromReport = () => {
|
|
39
|
+
let report = null
|
|
40
|
+
if (typeof process.report?.getReport === 'function') {
|
|
41
|
+
process.report.excludeNetwork = true
|
|
42
|
+
report = process.report.getReport()
|
|
43
|
+
}
|
|
44
|
+
if (!report) {
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
51
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const isMuslFromChildProcess = () => {
|
|
59
|
+
try {
|
|
60
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
61
|
+
} catch (e) {
|
|
62
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function requireNative() {
|
|
68
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
69
|
+
try {
|
|
70
|
+
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
loadErrors.push(err)
|
|
73
|
+
}
|
|
74
|
+
} else if (process.platform === 'android') {
|
|
75
|
+
if (process.arch === 'arm64') {
|
|
76
|
+
try {
|
|
77
|
+
return require('./fuma-translate.android-arm64.node')
|
|
78
|
+
} catch (e) {
|
|
79
|
+
loadErrors.push(e)
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const binding = require('@fuma-translate/binding-android-arm64')
|
|
83
|
+
const bindingPackageVersion = require('@fuma-translate/binding-android-arm64/package.json').version
|
|
84
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
85
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
86
|
+
}
|
|
87
|
+
return binding
|
|
88
|
+
} catch (e) {
|
|
89
|
+
loadErrors.push(e)
|
|
90
|
+
}
|
|
91
|
+
} else if (process.arch === 'arm') {
|
|
92
|
+
try {
|
|
93
|
+
return require('./fuma-translate.android-arm-eabi.node')
|
|
94
|
+
} catch (e) {
|
|
95
|
+
loadErrors.push(e)
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const binding = require('@fuma-translate/binding-android-arm-eabi')
|
|
99
|
+
const bindingPackageVersion = require('@fuma-translate/binding-android-arm-eabi/package.json').version
|
|
100
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
101
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
102
|
+
}
|
|
103
|
+
return binding
|
|
104
|
+
} catch (e) {
|
|
105
|
+
loadErrors.push(e)
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
109
|
+
}
|
|
110
|
+
} else if (process.platform === 'win32') {
|
|
111
|
+
if (process.arch === 'x64') {
|
|
112
|
+
if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
|
|
113
|
+
try {
|
|
114
|
+
return require('./fuma-translate.win32-x64-gnu.node')
|
|
115
|
+
} catch (e) {
|
|
116
|
+
loadErrors.push(e)
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const binding = require('@fuma-translate/binding-win32-x64-gnu')
|
|
120
|
+
const bindingPackageVersion = require('@fuma-translate/binding-win32-x64-gnu/package.json').version
|
|
121
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
122
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
123
|
+
}
|
|
124
|
+
return binding
|
|
125
|
+
} catch (e) {
|
|
126
|
+
loadErrors.push(e)
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
try {
|
|
130
|
+
return require('./fuma-translate.win32-x64-msvc.node')
|
|
131
|
+
} catch (e) {
|
|
132
|
+
loadErrors.push(e)
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const binding = require('@fuma-translate/binding-win32-x64-msvc')
|
|
136
|
+
const bindingPackageVersion = require('@fuma-translate/binding-win32-x64-msvc/package.json').version
|
|
137
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
138
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
139
|
+
}
|
|
140
|
+
return binding
|
|
141
|
+
} catch (e) {
|
|
142
|
+
loadErrors.push(e)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} else if (process.arch === 'ia32') {
|
|
146
|
+
try {
|
|
147
|
+
return require('./fuma-translate.win32-ia32-msvc.node')
|
|
148
|
+
} catch (e) {
|
|
149
|
+
loadErrors.push(e)
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const binding = require('@fuma-translate/binding-win32-ia32-msvc')
|
|
153
|
+
const bindingPackageVersion = require('@fuma-translate/binding-win32-ia32-msvc/package.json').version
|
|
154
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
155
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
156
|
+
}
|
|
157
|
+
return binding
|
|
158
|
+
} catch (e) {
|
|
159
|
+
loadErrors.push(e)
|
|
160
|
+
}
|
|
161
|
+
} else if (process.arch === 'arm64') {
|
|
162
|
+
try {
|
|
163
|
+
return require('./fuma-translate.win32-arm64-msvc.node')
|
|
164
|
+
} catch (e) {
|
|
165
|
+
loadErrors.push(e)
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const binding = require('@fuma-translate/binding-win32-arm64-msvc')
|
|
169
|
+
const bindingPackageVersion = require('@fuma-translate/binding-win32-arm64-msvc/package.json').version
|
|
170
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
171
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
172
|
+
}
|
|
173
|
+
return binding
|
|
174
|
+
} catch (e) {
|
|
175
|
+
loadErrors.push(e)
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
179
|
+
}
|
|
180
|
+
} else if (process.platform === 'darwin') {
|
|
181
|
+
try {
|
|
182
|
+
return require('./fuma-translate.darwin-universal.node')
|
|
183
|
+
} catch (e) {
|
|
184
|
+
loadErrors.push(e)
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
const binding = require('@fuma-translate/binding-darwin-universal')
|
|
188
|
+
const bindingPackageVersion = require('@fuma-translate/binding-darwin-universal/package.json').version
|
|
189
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
190
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
191
|
+
}
|
|
192
|
+
return binding
|
|
193
|
+
} catch (e) {
|
|
194
|
+
loadErrors.push(e)
|
|
195
|
+
}
|
|
196
|
+
if (process.arch === 'x64') {
|
|
197
|
+
try {
|
|
198
|
+
return require('./fuma-translate.darwin-x64.node')
|
|
199
|
+
} catch (e) {
|
|
200
|
+
loadErrors.push(e)
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
const binding = require('@fuma-translate/binding-darwin-x64')
|
|
204
|
+
const bindingPackageVersion = require('@fuma-translate/binding-darwin-x64/package.json').version
|
|
205
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
206
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
207
|
+
}
|
|
208
|
+
return binding
|
|
209
|
+
} catch (e) {
|
|
210
|
+
loadErrors.push(e)
|
|
211
|
+
}
|
|
212
|
+
} else if (process.arch === 'arm64') {
|
|
213
|
+
try {
|
|
214
|
+
return require('./fuma-translate.darwin-arm64.node')
|
|
215
|
+
} catch (e) {
|
|
216
|
+
loadErrors.push(e)
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
const binding = require('@fuma-translate/binding-darwin-arm64')
|
|
220
|
+
const bindingPackageVersion = require('@fuma-translate/binding-darwin-arm64/package.json').version
|
|
221
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
222
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
223
|
+
}
|
|
224
|
+
return binding
|
|
225
|
+
} catch (e) {
|
|
226
|
+
loadErrors.push(e)
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
230
|
+
}
|
|
231
|
+
} else if (process.platform === 'freebsd') {
|
|
232
|
+
if (process.arch === 'x64') {
|
|
233
|
+
try {
|
|
234
|
+
return require('./fuma-translate.freebsd-x64.node')
|
|
235
|
+
} catch (e) {
|
|
236
|
+
loadErrors.push(e)
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
const binding = require('@fuma-translate/binding-freebsd-x64')
|
|
240
|
+
const bindingPackageVersion = require('@fuma-translate/binding-freebsd-x64/package.json').version
|
|
241
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
242
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
243
|
+
}
|
|
244
|
+
return binding
|
|
245
|
+
} catch (e) {
|
|
246
|
+
loadErrors.push(e)
|
|
247
|
+
}
|
|
248
|
+
} else if (process.arch === 'arm64') {
|
|
249
|
+
try {
|
|
250
|
+
return require('./fuma-translate.freebsd-arm64.node')
|
|
251
|
+
} catch (e) {
|
|
252
|
+
loadErrors.push(e)
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
const binding = require('@fuma-translate/binding-freebsd-arm64')
|
|
256
|
+
const bindingPackageVersion = require('@fuma-translate/binding-freebsd-arm64/package.json').version
|
|
257
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
258
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
259
|
+
}
|
|
260
|
+
return binding
|
|
261
|
+
} catch (e) {
|
|
262
|
+
loadErrors.push(e)
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
266
|
+
}
|
|
267
|
+
} else if (process.platform === 'linux') {
|
|
268
|
+
if (process.arch === 'x64') {
|
|
269
|
+
if (isMusl()) {
|
|
270
|
+
try {
|
|
271
|
+
return require('./fuma-translate.linux-x64-musl.node')
|
|
272
|
+
} catch (e) {
|
|
273
|
+
loadErrors.push(e)
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
const binding = require('@fuma-translate/binding-linux-x64-musl')
|
|
277
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-x64-musl/package.json').version
|
|
278
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
279
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
280
|
+
}
|
|
281
|
+
return binding
|
|
282
|
+
} catch (e) {
|
|
283
|
+
loadErrors.push(e)
|
|
284
|
+
}
|
|
285
|
+
} else {
|
|
286
|
+
try {
|
|
287
|
+
return require('./fuma-translate.linux-x64-gnu.node')
|
|
288
|
+
} catch (e) {
|
|
289
|
+
loadErrors.push(e)
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
const binding = require('@fuma-translate/binding-linux-x64-gnu')
|
|
293
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-x64-gnu/package.json').version
|
|
294
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
295
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
296
|
+
}
|
|
297
|
+
return binding
|
|
298
|
+
} catch (e) {
|
|
299
|
+
loadErrors.push(e)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
} else if (process.arch === 'arm64') {
|
|
303
|
+
if (isMusl()) {
|
|
304
|
+
try {
|
|
305
|
+
return require('./fuma-translate.linux-arm64-musl.node')
|
|
306
|
+
} catch (e) {
|
|
307
|
+
loadErrors.push(e)
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
const binding = require('@fuma-translate/binding-linux-arm64-musl')
|
|
311
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-arm64-musl/package.json').version
|
|
312
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
313
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
314
|
+
}
|
|
315
|
+
return binding
|
|
316
|
+
} catch (e) {
|
|
317
|
+
loadErrors.push(e)
|
|
318
|
+
}
|
|
319
|
+
} else {
|
|
320
|
+
try {
|
|
321
|
+
return require('./fuma-translate.linux-arm64-gnu.node')
|
|
322
|
+
} catch (e) {
|
|
323
|
+
loadErrors.push(e)
|
|
324
|
+
}
|
|
325
|
+
try {
|
|
326
|
+
const binding = require('@fuma-translate/binding-linux-arm64-gnu')
|
|
327
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-arm64-gnu/package.json').version
|
|
328
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
329
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
330
|
+
}
|
|
331
|
+
return binding
|
|
332
|
+
} catch (e) {
|
|
333
|
+
loadErrors.push(e)
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
} else if (process.arch === 'arm') {
|
|
337
|
+
if (isMusl()) {
|
|
338
|
+
try {
|
|
339
|
+
return require('./fuma-translate.linux-arm-musleabihf.node')
|
|
340
|
+
} catch (e) {
|
|
341
|
+
loadErrors.push(e)
|
|
342
|
+
}
|
|
343
|
+
try {
|
|
344
|
+
const binding = require('@fuma-translate/binding-linux-arm-musleabihf')
|
|
345
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-arm-musleabihf/package.json').version
|
|
346
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
347
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
348
|
+
}
|
|
349
|
+
return binding
|
|
350
|
+
} catch (e) {
|
|
351
|
+
loadErrors.push(e)
|
|
352
|
+
}
|
|
353
|
+
} else {
|
|
354
|
+
try {
|
|
355
|
+
return require('./fuma-translate.linux-arm-gnueabihf.node')
|
|
356
|
+
} catch (e) {
|
|
357
|
+
loadErrors.push(e)
|
|
358
|
+
}
|
|
359
|
+
try {
|
|
360
|
+
const binding = require('@fuma-translate/binding-linux-arm-gnueabihf')
|
|
361
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-arm-gnueabihf/package.json').version
|
|
362
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
363
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
364
|
+
}
|
|
365
|
+
return binding
|
|
366
|
+
} catch (e) {
|
|
367
|
+
loadErrors.push(e)
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
} else if (process.arch === 'loong64') {
|
|
371
|
+
if (isMusl()) {
|
|
372
|
+
try {
|
|
373
|
+
return require('./fuma-translate.linux-loong64-musl.node')
|
|
374
|
+
} catch (e) {
|
|
375
|
+
loadErrors.push(e)
|
|
376
|
+
}
|
|
377
|
+
try {
|
|
378
|
+
const binding = require('@fuma-translate/binding-linux-loong64-musl')
|
|
379
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-loong64-musl/package.json').version
|
|
380
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
381
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
382
|
+
}
|
|
383
|
+
return binding
|
|
384
|
+
} catch (e) {
|
|
385
|
+
loadErrors.push(e)
|
|
386
|
+
}
|
|
387
|
+
} else {
|
|
388
|
+
try {
|
|
389
|
+
return require('./fuma-translate.linux-loong64-gnu.node')
|
|
390
|
+
} catch (e) {
|
|
391
|
+
loadErrors.push(e)
|
|
392
|
+
}
|
|
393
|
+
try {
|
|
394
|
+
const binding = require('@fuma-translate/binding-linux-loong64-gnu')
|
|
395
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-loong64-gnu/package.json').version
|
|
396
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
397
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
398
|
+
}
|
|
399
|
+
return binding
|
|
400
|
+
} catch (e) {
|
|
401
|
+
loadErrors.push(e)
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
} else if (process.arch === 'riscv64') {
|
|
405
|
+
if (isMusl()) {
|
|
406
|
+
try {
|
|
407
|
+
return require('./fuma-translate.linux-riscv64-musl.node')
|
|
408
|
+
} catch (e) {
|
|
409
|
+
loadErrors.push(e)
|
|
410
|
+
}
|
|
411
|
+
try {
|
|
412
|
+
const binding = require('@fuma-translate/binding-linux-riscv64-musl')
|
|
413
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-riscv64-musl/package.json').version
|
|
414
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
415
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
416
|
+
}
|
|
417
|
+
return binding
|
|
418
|
+
} catch (e) {
|
|
419
|
+
loadErrors.push(e)
|
|
420
|
+
}
|
|
421
|
+
} else {
|
|
422
|
+
try {
|
|
423
|
+
return require('./fuma-translate.linux-riscv64-gnu.node')
|
|
424
|
+
} catch (e) {
|
|
425
|
+
loadErrors.push(e)
|
|
426
|
+
}
|
|
427
|
+
try {
|
|
428
|
+
const binding = require('@fuma-translate/binding-linux-riscv64-gnu')
|
|
429
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-riscv64-gnu/package.json').version
|
|
430
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
431
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
432
|
+
}
|
|
433
|
+
return binding
|
|
434
|
+
} catch (e) {
|
|
435
|
+
loadErrors.push(e)
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
} else if (process.arch === 'ppc64') {
|
|
439
|
+
try {
|
|
440
|
+
return require('./fuma-translate.linux-ppc64-gnu.node')
|
|
441
|
+
} catch (e) {
|
|
442
|
+
loadErrors.push(e)
|
|
443
|
+
}
|
|
444
|
+
try {
|
|
445
|
+
const binding = require('@fuma-translate/binding-linux-ppc64-gnu')
|
|
446
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-ppc64-gnu/package.json').version
|
|
447
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
448
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
449
|
+
}
|
|
450
|
+
return binding
|
|
451
|
+
} catch (e) {
|
|
452
|
+
loadErrors.push(e)
|
|
453
|
+
}
|
|
454
|
+
} else if (process.arch === 's390x') {
|
|
455
|
+
try {
|
|
456
|
+
return require('./fuma-translate.linux-s390x-gnu.node')
|
|
457
|
+
} catch (e) {
|
|
458
|
+
loadErrors.push(e)
|
|
459
|
+
}
|
|
460
|
+
try {
|
|
461
|
+
const binding = require('@fuma-translate/binding-linux-s390x-gnu')
|
|
462
|
+
const bindingPackageVersion = require('@fuma-translate/binding-linux-s390x-gnu/package.json').version
|
|
463
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
464
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
465
|
+
}
|
|
466
|
+
return binding
|
|
467
|
+
} catch (e) {
|
|
468
|
+
loadErrors.push(e)
|
|
469
|
+
}
|
|
470
|
+
} else {
|
|
471
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
472
|
+
}
|
|
473
|
+
} else if (process.platform === 'openharmony') {
|
|
474
|
+
if (process.arch === 'arm64') {
|
|
475
|
+
try {
|
|
476
|
+
return require('./fuma-translate.openharmony-arm64.node')
|
|
477
|
+
} catch (e) {
|
|
478
|
+
loadErrors.push(e)
|
|
479
|
+
}
|
|
480
|
+
try {
|
|
481
|
+
const binding = require('@fuma-translate/binding-openharmony-arm64')
|
|
482
|
+
const bindingPackageVersion = require('@fuma-translate/binding-openharmony-arm64/package.json').version
|
|
483
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
484
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
485
|
+
}
|
|
486
|
+
return binding
|
|
487
|
+
} catch (e) {
|
|
488
|
+
loadErrors.push(e)
|
|
489
|
+
}
|
|
490
|
+
} else if (process.arch === 'x64') {
|
|
491
|
+
try {
|
|
492
|
+
return require('./fuma-translate.openharmony-x64.node')
|
|
493
|
+
} catch (e) {
|
|
494
|
+
loadErrors.push(e)
|
|
495
|
+
}
|
|
496
|
+
try {
|
|
497
|
+
const binding = require('@fuma-translate/binding-openharmony-x64')
|
|
498
|
+
const bindingPackageVersion = require('@fuma-translate/binding-openharmony-x64/package.json').version
|
|
499
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
500
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
501
|
+
}
|
|
502
|
+
return binding
|
|
503
|
+
} catch (e) {
|
|
504
|
+
loadErrors.push(e)
|
|
505
|
+
}
|
|
506
|
+
} else if (process.arch === 'arm') {
|
|
507
|
+
try {
|
|
508
|
+
return require('./fuma-translate.openharmony-arm.node')
|
|
509
|
+
} catch (e) {
|
|
510
|
+
loadErrors.push(e)
|
|
511
|
+
}
|
|
512
|
+
try {
|
|
513
|
+
const binding = require('@fuma-translate/binding-openharmony-arm')
|
|
514
|
+
const bindingPackageVersion = require('@fuma-translate/binding-openharmony-arm/package.json').version
|
|
515
|
+
if (bindingPackageVersion !== '1.0.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
516
|
+
throw new Error(`Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
517
|
+
}
|
|
518
|
+
return binding
|
|
519
|
+
} catch (e) {
|
|
520
|
+
loadErrors.push(e)
|
|
521
|
+
}
|
|
522
|
+
} else {
|
|
523
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
524
|
+
}
|
|
525
|
+
} else {
|
|
526
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
nativeBinding = requireNative()
|
|
531
|
+
|
|
532
|
+
// NAPI_RS_FORCE_WASI is a tri-state flag:
|
|
533
|
+
// unset / any other value → native binding preferred, WASI is only a fallback
|
|
534
|
+
// 'true' → force WASI fallback even if native loaded
|
|
535
|
+
// 'error' → force WASI and throw if no WASI binding is found
|
|
536
|
+
// Treating any non-empty string as truthy (the historical behavior) meant
|
|
537
|
+
// NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
|
|
538
|
+
// the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
|
|
539
|
+
const forceWasi =
|
|
540
|
+
process.env.NAPI_RS_FORCE_WASI === 'true' || process.env.NAPI_RS_FORCE_WASI === 'error'
|
|
541
|
+
|
|
542
|
+
if (!nativeBinding || forceWasi) {
|
|
543
|
+
let wasiBinding = null
|
|
544
|
+
let wasiBindingError = null
|
|
545
|
+
try {
|
|
546
|
+
wasiBinding = require('./fuma-translate.wasi.cjs')
|
|
547
|
+
nativeBinding = wasiBinding
|
|
548
|
+
} catch (err) {
|
|
549
|
+
if (forceWasi) {
|
|
550
|
+
wasiBindingError = err
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (!nativeBinding || forceWasi) {
|
|
554
|
+
try {
|
|
555
|
+
wasiBinding = require('@fuma-translate/binding-wasm32-wasi')
|
|
556
|
+
nativeBinding = wasiBinding
|
|
557
|
+
} catch (err) {
|
|
558
|
+
if (forceWasi) {
|
|
559
|
+
if (!wasiBindingError) {
|
|
560
|
+
wasiBindingError = err
|
|
561
|
+
} else {
|
|
562
|
+
wasiBindingError.cause = err
|
|
563
|
+
}
|
|
564
|
+
loadErrors.push(err)
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
|
|
569
|
+
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
|
|
570
|
+
error.cause = wasiBindingError
|
|
571
|
+
throw error
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (!nativeBinding) {
|
|
576
|
+
if (loadErrors.length > 0) {
|
|
577
|
+
throw new Error(
|
|
578
|
+
`Cannot find native binding. ` +
|
|
579
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
580
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
581
|
+
{
|
|
582
|
+
cause: loadErrors.reduce((err, cur) => {
|
|
583
|
+
cur.cause = err
|
|
584
|
+
return cur
|
|
585
|
+
}),
|
|
586
|
+
},
|
|
587
|
+
)
|
|
588
|
+
}
|
|
589
|
+
throw new Error(`Failed to load native binding`)
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
const { compileSync } = nativeBinding
|
|
593
|
+
export { compileSync }
|
package/package.json
CHANGED
|
@@ -1,35 +1,86 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fuma-translate",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "The build-time package to implement multilingual in your JavaScript app",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Fuma Nama",
|
|
7
|
-
"repository":
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "github:fuma-nama/fuma-translate"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"fuma-translate": "./dist/cli.mjs"
|
|
13
|
+
},
|
|
8
14
|
"files": [
|
|
9
|
-
"dist"
|
|
15
|
+
"dist",
|
|
16
|
+
"native/native.js",
|
|
17
|
+
"native/native.d.ts",
|
|
18
|
+
"native/browser.js",
|
|
19
|
+
"native/webcontainer-fallback.cjs"
|
|
10
20
|
],
|
|
11
21
|
"type": "module",
|
|
12
22
|
"exports": {
|
|
13
23
|
".": "./dist/index.mjs",
|
|
24
|
+
"./cli": "./dist/cli.mjs",
|
|
14
25
|
"./package.json": "./package.json"
|
|
15
26
|
},
|
|
16
27
|
"publishConfig": {
|
|
17
28
|
"access": "public"
|
|
18
29
|
},
|
|
19
30
|
"dependencies": {
|
|
20
|
-
"
|
|
21
|
-
"tinyglobby": "^0.2.17"
|
|
31
|
+
"chokidar": "^5.0.0"
|
|
22
32
|
},
|
|
23
33
|
"devDependencies": {
|
|
34
|
+
"@emnapi/core": "^1.11.0",
|
|
35
|
+
"@emnapi/runtime": "^1.11.0",
|
|
36
|
+
"@napi-rs/cli": "^3.7.1",
|
|
37
|
+
"@tybys/wasm-util": "^0.10.0",
|
|
24
38
|
"@types/node": "^25.9.2",
|
|
25
39
|
"@types/react": "^19.2.17",
|
|
26
40
|
"tsdown": "^0.22.2",
|
|
27
41
|
"typescript": "6.0.3",
|
|
28
42
|
"@repo/typescript-config": "0.0.0"
|
|
29
43
|
},
|
|
44
|
+
"napi": {
|
|
45
|
+
"binaryName": "fuma-translate",
|
|
46
|
+
"packageName": "@fuma-translate/binding",
|
|
47
|
+
"targets": [
|
|
48
|
+
"aarch64-apple-darwin",
|
|
49
|
+
"aarch64-unknown-linux-gnu",
|
|
50
|
+
"aarch64-unknown-linux-musl",
|
|
51
|
+
"aarch64-pc-windows-msvc",
|
|
52
|
+
"x86_64-apple-darwin",
|
|
53
|
+
"x86_64-unknown-linux-gnu",
|
|
54
|
+
"x86_64-unknown-linux-musl",
|
|
55
|
+
"x86_64-pc-windows-msvc",
|
|
56
|
+
"wasm32-wasip1-threads"
|
|
57
|
+
],
|
|
58
|
+
"wasm": {
|
|
59
|
+
"browser": {
|
|
60
|
+
"fs": false
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=22"
|
|
66
|
+
},
|
|
67
|
+
"optionalDependencies": {
|
|
68
|
+
"@fuma-translate/binding-darwin-arm64": "1.0.1",
|
|
69
|
+
"@fuma-translate/binding-linux-arm64-gnu": "1.0.1",
|
|
70
|
+
"@fuma-translate/binding-linux-arm64-musl": "1.0.1",
|
|
71
|
+
"@fuma-translate/binding-win32-arm64-msvc": "1.0.1",
|
|
72
|
+
"@fuma-translate/binding-darwin-x64": "1.0.1",
|
|
73
|
+
"@fuma-translate/binding-linux-x64-gnu": "1.0.1",
|
|
74
|
+
"@fuma-translate/binding-linux-x64-musl": "1.0.1",
|
|
75
|
+
"@fuma-translate/binding-win32-x64-msvc": "1.0.1",
|
|
76
|
+
"@fuma-translate/binding-wasm32-wasi": "1.0.1"
|
|
77
|
+
},
|
|
30
78
|
"scripts": {
|
|
31
79
|
"types:check": "tsc --noEmit",
|
|
32
|
-
"build": "
|
|
33
|
-
"
|
|
80
|
+
"build:native": "napi build --platform --release --esm --js native.js --dts native.d.ts --output-dir native",
|
|
81
|
+
"build:js": "tsdown",
|
|
82
|
+
"build": "pnpm build:native && pnpm build:js",
|
|
83
|
+
"dev": "tsdown --watch",
|
|
84
|
+
"artifacts": "napi create-npm-dirs && napi artifacts --npm-dir npm --output-dir native --build-output-dir native"
|
|
34
85
|
}
|
|
35
86
|
}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,GAAG,KAAK,GAAG;AACpB;AAIA,SAAS,yBACP,MACA,QACA,MACyB;CACzB,IAAI,KAAK,SAAS,kBAAkB,OAAO;CAC3C,IAAI,KAAK,OAAO,SAAS,gBAAgB,KAAK,OAAO,SAAS,mBAC5D,OAAO;CAGT,IAAI,KAAK,UAAU,WAAW,GAAG,OAAO,CAAC,KAAA,CAAS;CAElD,IAAI,KAAK,UAAU,SAAS,GAC1B,KAAK,QAAQ,MAAM,MAAM,sDAAsD;CAGjF,MAAM,MAAM,KAAK,UAAU;CAC3B,IAAI,CAAC,OAAO,IAAI,SAAS,iBACvB,KAAK,QAAQ,MAAM,OAAO,MAAM,iDAAiD;CAGnF,OAAO,aAAa,KAAK,QAAQ,IAAI;AACvC;AAEA,SAAS,iBAAiB,MAA8B;CACtD,OACE,KAAK,SAAS,6BACd,KAAK,SAAS,oBACd,KAAK,SAAS,2BACd,KAAK,SAAS,mBAEd,OAAO,KAAK;CAEd,OAAO;AACT;AAEA,SAAS,KAAK,QAAgB,MAAc,MAAY,SAAwB;CAC9E,MAAM,IAAI,oBACR,GAAG,KAAK,GAAG,eAAe,QAAQ,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