@discord/intl-message-database 0.0.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cargo/config.toml +12 -0
- package/Cargo.toml +38 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/bench/keyless-json.js +91 -0
- package/bench/native.js +114 -0
- package/bench/util.js +55 -0
- package/build.rs +5 -0
- package/index.d.ts +52 -0
- package/index.js +86 -0
- package/npm/darwin-arm64/README.md +3 -0
- package/npm/darwin-arm64/package.json +18 -0
- package/npm/darwin-x64/README.md +3 -0
- package/npm/darwin-x64/package.json +18 -0
- package/npm/linux-arm64-gnu/README.md +3 -0
- package/npm/linux-arm64-gnu/package.json +21 -0
- package/npm/linux-arm64-musl/README.md +3 -0
- package/npm/linux-arm64-musl/package.json +21 -0
- package/npm/linux-x64-gnu/README.md +3 -0
- package/npm/linux-x64-gnu/package.json +21 -0
- package/npm/linux-x64-musl/README.md +3 -0
- package/npm/linux-x64-musl/package.json +21 -0
- package/npm/win32-arm64-msvc/README.md +3 -0
- package/npm/win32-arm64-msvc/package.json +18 -0
- package/npm/win32-ia32-msvc/README.md +3 -0
- package/npm/win32-ia32-msvc/package.json +18 -0
- package/npm/win32-x64-msvc/README.md +3 -0
- package/npm/win32-x64-msvc/package.json +18 -0
- package/package.json +44 -0
- package/src/lib.rs +14 -0
- package/src/messages/database.rs +343 -0
- package/src/messages/error.rs +43 -0
- package/src/messages/message_definition.rs +169 -0
- package/src/messages/message_variables_visitor.rs +299 -0
- package/src/messages/meta.rs +38 -0
- package/src/messages/mod.rs +27 -0
- package/src/messages/source_file.rs +75 -0
- package/src/messages/symbols.rs +164 -0
- package/src/messages/translation.rs +64 -0
- package/src/messages/value.rs +51 -0
- package/src/napi.rs +300 -0
- package/src/services/mod.rs +9 -0
- package/src/services/precompile.rs +91 -0
- package/src/services/types.rs +237 -0
- package/src/services/validator.rs +104 -0
- package/src/sources/definitions_parser.rs +347 -0
- package/src/sources/mod.rs +87 -0
- package/src/sources/translations.rs +75 -0
- package/src/test.rs +67 -0
- package/src/threading.rs +61 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[target.x86_64-pc-windows-msvc]
|
|
2
|
+
rustflags = ["-C", "target-feature=+crt-static"]
|
|
3
|
+
|
|
4
|
+
[target.aarch64-unknown-linux-musl]
|
|
5
|
+
linker = "aarch64-linux-musl-gcc"
|
|
6
|
+
rustflags = ["-C", "target-feature=-crt-static"]
|
|
7
|
+
|
|
8
|
+
[target.aarch64-apple-darwin.env]
|
|
9
|
+
MACOSX_DEPLOYMENT_TARGET = "11"
|
|
10
|
+
|
|
11
|
+
[target.x86_64-apple-darwin.env]
|
|
12
|
+
MACOSX_DEPLOYMENT_TARGET = "10.13"
|
package/Cargo.toml
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "intl_message_database"
|
|
3
|
+
description = "A core intl message management databae, supporting CRUD for messages with attribution to their source files."
|
|
4
|
+
version = "0.1.0"
|
|
5
|
+
edition = "2021"
|
|
6
|
+
publish = false
|
|
7
|
+
|
|
8
|
+
[lib]
|
|
9
|
+
crate-type = ["cdylib"]
|
|
10
|
+
|
|
11
|
+
[dependencies]
|
|
12
|
+
arcstr = "1"
|
|
13
|
+
anyhow = "1"
|
|
14
|
+
bitflags = "2"
|
|
15
|
+
codespan-reporting = { version = "0.11.1", features = ["serialization"] }
|
|
16
|
+
intl_markdown = { path = "../intl_markdown" }
|
|
17
|
+
intl_message_utils = { path = "../intl_message_utils" }
|
|
18
|
+
keyless_json = { path = "../keyless_json" }
|
|
19
|
+
napi = { version = "2", features = ["error_anyhow", "serde-json"] }
|
|
20
|
+
napi-derive = "2"
|
|
21
|
+
num_cpus = "1"
|
|
22
|
+
rustc-hash = "1"
|
|
23
|
+
serde = "1"
|
|
24
|
+
serde_json = "1"
|
|
25
|
+
string-interner = "0.15.0"
|
|
26
|
+
swc_common = "0.33.25"
|
|
27
|
+
swc_core = { version = "0.90.x", features = [
|
|
28
|
+
"ecma_parser",
|
|
29
|
+
"ecma_ast",
|
|
30
|
+
"ecma_visit",
|
|
31
|
+
] }
|
|
32
|
+
thiserror = "1"
|
|
33
|
+
threadpool = "1.8.1"
|
|
34
|
+
xxhash-rust = { version = "0.8.10", features = ["xxh64"] }
|
|
35
|
+
mimalloc = "0.1"
|
|
36
|
+
|
|
37
|
+
[build-dependencies]
|
|
38
|
+
napi-build = "2"
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Discord, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# intl-message-database
|
|
2
|
+
|
|
3
|
+
A Rust-based native Node extension module for quickly parsing, processing, and generating structured message definitions
|
|
4
|
+
across an entire project. This is the core module powering all of the loaders, transformer plugins, and other tooling
|
|
5
|
+
that relate to messages and translations. It includes a custom parser to handle a combination of ICU MessageFormat syntax
|
|
6
|
+
for variable interpolations, along with (almost) full support for Markdown's inline styling syntax, and is able to output
|
|
7
|
+
reformatted strings, ASTs, type definitions, perform validations across multiple translations, and more.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FORMAT_JS_POUND = exports.FormatJsNodeType = void 0;
|
|
4
|
+
exports.hydrateFormatJsAst = hydrateFormatJsAst;
|
|
5
|
+
exports.hydrateMessages = hydrateMessages;
|
|
6
|
+
var FormatJsNodeType;
|
|
7
|
+
(function (FormatJsNodeType) {
|
|
8
|
+
FormatJsNodeType[FormatJsNodeType["Literal"] = 0] = "Literal";
|
|
9
|
+
FormatJsNodeType[FormatJsNodeType["Argument"] = 1] = "Argument";
|
|
10
|
+
FormatJsNodeType[FormatJsNodeType["Number"] = 2] = "Number";
|
|
11
|
+
FormatJsNodeType[FormatJsNodeType["Date"] = 3] = "Date";
|
|
12
|
+
FormatJsNodeType[FormatJsNodeType["Time"] = 4] = "Time";
|
|
13
|
+
FormatJsNodeType[FormatJsNodeType["Select"] = 5] = "Select";
|
|
14
|
+
FormatJsNodeType[FormatJsNodeType["Plural"] = 6] = "Plural";
|
|
15
|
+
FormatJsNodeType[FormatJsNodeType["Pound"] = 7] = "Pound";
|
|
16
|
+
FormatJsNodeType[FormatJsNodeType["Tag"] = 8] = "Tag";
|
|
17
|
+
})(FormatJsNodeType || (exports.FormatJsNodeType = FormatJsNodeType = {}));
|
|
18
|
+
// Using a static object here ensures there's only one allocation for it, which
|
|
19
|
+
// will likely appear in many, many messages. Freezing ensures that the shared
|
|
20
|
+
// object can't be accidentally modified if a consumer tries to transform the
|
|
21
|
+
// AST.
|
|
22
|
+
exports.FORMAT_JS_POUND = Object.freeze({ type: 7 });
|
|
23
|
+
function hydrateArray(elements) {
|
|
24
|
+
for (var i = 0; i < elements.length; i++) {
|
|
25
|
+
elements[i] = hydrateFormatJsAst(elements[i]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function hydratePlural(keyless) {
|
|
29
|
+
var type = keyless[0], value = keyless[1], options = keyless[2], offset = keyless[3], pluralType = keyless[4];
|
|
30
|
+
// This tries to be efficient about updating the value for each option
|
|
31
|
+
// with a parsed version, reusing the same receiving object, and even
|
|
32
|
+
// the inner key within it, just replacing the end value with the
|
|
33
|
+
// parsed version.
|
|
34
|
+
// This saves multiple allocations compared to building a new object
|
|
35
|
+
// from scratch, either for the whole options object or for each value.
|
|
36
|
+
for (var key in options) {
|
|
37
|
+
hydrateArray(options[key].value);
|
|
38
|
+
}
|
|
39
|
+
// `pluralType` is technically only valid on `Plural` nodes, even
|
|
40
|
+
// though the structure is identical to `Select`.
|
|
41
|
+
if (type === FormatJsNodeType.Plural) {
|
|
42
|
+
return { type: type, value: value, options: options, offset: offset, pluralType: pluralType };
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return { type: type, value: value, options: options, offset: offset };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function hydrateSingle(keyless) {
|
|
49
|
+
var type = keyless[0];
|
|
50
|
+
switch (type) {
|
|
51
|
+
case FormatJsNodeType.Literal:
|
|
52
|
+
case FormatJsNodeType.Argument:
|
|
53
|
+
return { type: type, value: keyless[1] };
|
|
54
|
+
case FormatJsNodeType.Number:
|
|
55
|
+
case FormatJsNodeType.Date:
|
|
56
|
+
case FormatJsNodeType.Time:
|
|
57
|
+
return { type: type, value: keyless[1], style: keyless[2] };
|
|
58
|
+
case FormatJsNodeType.Select:
|
|
59
|
+
case FormatJsNodeType.Plural:
|
|
60
|
+
return hydratePlural(keyless);
|
|
61
|
+
case FormatJsNodeType.Pound:
|
|
62
|
+
return exports.FORMAT_JS_POUND;
|
|
63
|
+
case FormatJsNodeType.Tag: {
|
|
64
|
+
var type_1 = keyless[0], value = keyless[1], children = keyless[2];
|
|
65
|
+
hydrateArray(children);
|
|
66
|
+
return { type: type_1, value: value, children: children };
|
|
67
|
+
}
|
|
68
|
+
default:
|
|
69
|
+
throw new Error("FormatJS keyless JSON encountered an unknown type: ".concat(type));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function hydrateFormatJsAst(keyless) {
|
|
73
|
+
// If the first element of the array is itself an array, then we have a list
|
|
74
|
+
// of elements to parse rather than a single object.
|
|
75
|
+
if (Array.isArray(keyless[0])) {
|
|
76
|
+
hydrateArray(keyless);
|
|
77
|
+
return keyless;
|
|
78
|
+
}
|
|
79
|
+
else if (keyless.length === 0) {
|
|
80
|
+
// Some entries can be empty arrays, like an empty set of children, and those can
|
|
81
|
+
// be preserved.
|
|
82
|
+
return keyless;
|
|
83
|
+
}
|
|
84
|
+
return hydrateSingle(keyless);
|
|
85
|
+
}
|
|
86
|
+
function hydrateMessages(messages) {
|
|
87
|
+
for (var key in messages) {
|
|
88
|
+
messages[key] = hydrateFormatJsAst(messages[key]);
|
|
89
|
+
}
|
|
90
|
+
return messages;
|
|
91
|
+
}
|
package/bench/native.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
// @ts-check
|
|
3
|
+
|
|
4
|
+
const { IntlMessagesDatabase, IntlCompiledMessageFormat } = require('..');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const util = require('node:util');
|
|
8
|
+
const { bench, locales: allLocales } = require('./util');
|
|
9
|
+
const { hydrateMessages } = require('./keyless-json');
|
|
10
|
+
|
|
11
|
+
const locales = allLocales;
|
|
12
|
+
|
|
13
|
+
const database = new IntlMessagesDatabase();
|
|
14
|
+
|
|
15
|
+
/** @type {IntlCompiledMessageFormat} */
|
|
16
|
+
const COMPILATION_FORMAT = IntlCompiledMessageFormat.KeylessJson;
|
|
17
|
+
|
|
18
|
+
bench('processing', () => {
|
|
19
|
+
database.processDefinitionsFile('./data/input/en-US.js');
|
|
20
|
+
// native.processDefinitionsFile(database, './data/input/en-US.untranslated.js');
|
|
21
|
+
// native.processDefinitionsFile(database, './data/input/international.untranslated.js');
|
|
22
|
+
|
|
23
|
+
// // Single threaded:
|
|
24
|
+
// for (const locale of locales) {
|
|
25
|
+
// native.processTranslationsFile(database, `./data/input/${locale}.jsona`, locale);
|
|
26
|
+
// }
|
|
27
|
+
|
|
28
|
+
// Multithreaded:
|
|
29
|
+
/** @type {Record<string, string>} */
|
|
30
|
+
const localeMap = {};
|
|
31
|
+
for (const locale of locales) {
|
|
32
|
+
localeMap[locale] = `./data/input/${locale}.jsona`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
database.processAllTranslationFiles(localeMap);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
bench('get a message', () => {
|
|
39
|
+
// console.log(
|
|
40
|
+
util.inspect(
|
|
41
|
+
database.getMessage('GUILD_SETTINGS_AUDIT_LOG_CHANNEL_PERMISSION_OVERRIDES_DENIED'),
|
|
42
|
+
{
|
|
43
|
+
depth: null,
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
// );
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
bench('get source file', () => {
|
|
50
|
+
const source = database.getSourceFile('./data/input/en-US.js');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
bench('validate', () => {
|
|
54
|
+
database.validateMessages();
|
|
55
|
+
// const allDiagnostics = validations.flatMap((v) => v.diagnostics);
|
|
56
|
+
// console.log(
|
|
57
|
+
// util.inspect(
|
|
58
|
+
// allDiagnostics.filter((d) => d.severity === 'Error'),
|
|
59
|
+
// {depth: null},
|
|
60
|
+
// ),
|
|
61
|
+
// );
|
|
62
|
+
// console.log(util.inspect(validations, {depth: null}));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
bench('generate types', () => {
|
|
66
|
+
const paths = database.getAllSourceFilePaths();
|
|
67
|
+
database.generateTypes(paths[0], './data/output/generated.d.ts');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {IntlCompiledMessageFormat} format
|
|
72
|
+
*/
|
|
73
|
+
function getPrecompileFormat(format) {
|
|
74
|
+
switch (format) {
|
|
75
|
+
case IntlCompiledMessageFormat.Json:
|
|
76
|
+
return 'json';
|
|
77
|
+
case IntlCompiledMessageFormat.KeylessJson:
|
|
78
|
+
return 'keyless';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
bench(`precompile (${getPrecompileFormat(COMPILATION_FORMAT)})`, () => {
|
|
83
|
+
const locales = database.getKnownLocales();
|
|
84
|
+
for (const locale of locales) {
|
|
85
|
+
database.precompile(locale, `./data/output/${locale}.json`, COMPILATION_FORMAT);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/** @type {Record<string, any>} */
|
|
90
|
+
const COMPILED_FILES = {};
|
|
91
|
+
|
|
92
|
+
bench('read compiled files', () => {
|
|
93
|
+
const files = fs.readdirSync('./data/output/');
|
|
94
|
+
for (const file of files) {
|
|
95
|
+
if (path.extname(file) === '.json') {
|
|
96
|
+
// if (file === 'en-US.json') {
|
|
97
|
+
COMPILED_FILES[path.basename(file)] = fs.readFileSync(`./data/output/${file}`).toString();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
bench('parse json', () => {
|
|
103
|
+
for (const [locale, data] of Object.entries(COMPILED_FILES)) {
|
|
104
|
+
COMPILED_FILES[locale] = JSON.parse(data);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (COMPILATION_FORMAT === IntlCompiledMessageFormat.KeylessJson) {
|
|
109
|
+
bench('hydrate json', () => {
|
|
110
|
+
for (const [, data] of Object.entries(COMPILED_FILES)) {
|
|
111
|
+
hydrateMessages(data);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
package/bench/util.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
globalThis.window = globalThis;
|
|
2
|
+
globalThis.navigator = { languages: ['en-US'] };
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} title
|
|
6
|
+
* @param {() => unknown} callback
|
|
7
|
+
* @param {boolean} log
|
|
8
|
+
*/
|
|
9
|
+
function bench(title, callback, log = true) {
|
|
10
|
+
const start = performance.now();
|
|
11
|
+
callback();
|
|
12
|
+
const end = performance.now();
|
|
13
|
+
if (log) {
|
|
14
|
+
console.log(title + ': ', end - start);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const locales = [
|
|
19
|
+
'bg',
|
|
20
|
+
'cs',
|
|
21
|
+
'da',
|
|
22
|
+
'de',
|
|
23
|
+
'el',
|
|
24
|
+
'en-GB',
|
|
25
|
+
'es-419',
|
|
26
|
+
'es-ES',
|
|
27
|
+
'fi',
|
|
28
|
+
'fr',
|
|
29
|
+
'hi',
|
|
30
|
+
'hr',
|
|
31
|
+
'hu',
|
|
32
|
+
'id',
|
|
33
|
+
'it',
|
|
34
|
+
'ja',
|
|
35
|
+
'ko',
|
|
36
|
+
'lt',
|
|
37
|
+
'nl',
|
|
38
|
+
'no',
|
|
39
|
+
'pl',
|
|
40
|
+
'pt-BR',
|
|
41
|
+
'ro',
|
|
42
|
+
'ru',
|
|
43
|
+
'sv-SE',
|
|
44
|
+
'th',
|
|
45
|
+
'tr',
|
|
46
|
+
'uk',
|
|
47
|
+
'vi',
|
|
48
|
+
'zh-CN',
|
|
49
|
+
'zh-TW',
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
bench,
|
|
54
|
+
locales,
|
|
55
|
+
};
|
package/build.rs
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export declare class IntlMessagesDatabase {
|
|
4
|
+
constructor()
|
|
5
|
+
processDefinitionsFile(filePath: string): number
|
|
6
|
+
processDefinitionsFileContent(filePath: string, content: string): number
|
|
7
|
+
processAllTranslationFiles(localeMap: Record<string, string>): void
|
|
8
|
+
processTranslationFileContent(filePath: string, locale: string, content: string): number
|
|
9
|
+
getKnownLocales(): Array<string>
|
|
10
|
+
getSourceFile(filePath: string): IntlSourceFile
|
|
11
|
+
getAllSourceFilePaths(): Array<string>
|
|
12
|
+
getSourceFileHashedKeys(filePath: string): string[]
|
|
13
|
+
getMessage(key: string): unknown
|
|
14
|
+
generateTypes(sourceFilePath: string, outputFilePath: string): void
|
|
15
|
+
precompile(locale: string, outputPath: string, format?: IntlCompiledMessageFormat | undefined | null): void
|
|
16
|
+
precompileToBuffer(locale: string, format?: IntlCompiledMessageFormat | undefined | null): Buffer
|
|
17
|
+
validateMessages(): Array<IntlDiagnostic>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare export function hashMessageKey(key: string): string
|
|
21
|
+
|
|
22
|
+
export declare const enum IntlCompiledMessageFormat {
|
|
23
|
+
Json = 0,
|
|
24
|
+
KeylessJson = 1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface IntlDiagnostic {
|
|
28
|
+
key: string
|
|
29
|
+
diagnostics: unknown
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface IntlMessageMeta {
|
|
33
|
+
secret: boolean
|
|
34
|
+
translate: boolean
|
|
35
|
+
bundleSecrets: boolean
|
|
36
|
+
translationsPath: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface IntlSourceFile {
|
|
40
|
+
type: string
|
|
41
|
+
file: string
|
|
42
|
+
messageKeys: Array<number>
|
|
43
|
+
meta: IntlMessageMeta
|
|
44
|
+
locale?: number
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export declare export function isMessageDefinitionsFile(key: string): boolean
|
|
48
|
+
|
|
49
|
+
export declare export function isMessageTranslationsFile(key: string): boolean
|
|
50
|
+
|
|
51
|
+
export declare export function resolveSymbol(symbol: number): string | null
|
|
52
|
+
|
package/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* Originally auto-generated by NAPI-RS, adapted for working with an `npm` dir for each built package. */
|
|
5
|
+
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
|
|
9
|
+
function isMusl() {
|
|
10
|
+
// For Node 10
|
|
11
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
12
|
+
try {
|
|
13
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim();
|
|
14
|
+
return fs.readFileSync(lddPath, 'utf8').includes('musl');
|
|
15
|
+
} catch (e) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
const { glibcVersionRuntime } = JSON.parse(process.report.getReport()).header;
|
|
20
|
+
return !glibcVersionRuntime;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @type {Record<string, Record<string, string>>} */
|
|
25
|
+
const PACKAGE_NAMES = {
|
|
26
|
+
android: { arm: 'android-arm-eabi', arm64: 'android-arm64' },
|
|
27
|
+
win32: { arm64: 'win32-arm64-msvc', ia32: 'win32-ia32-msvc', x64: 'win32-x64-msvc' },
|
|
28
|
+
darwin: { arm64: 'darwin-arm64', x64: 'darwin-x64' },
|
|
29
|
+
freebsd: { x64: 'freebsd-x64' },
|
|
30
|
+
'linux-gnu': {
|
|
31
|
+
arm: 'linux-arm-gnueabihf',
|
|
32
|
+
arm64: 'linux-arm64-gnu',
|
|
33
|
+
x64: 'linux-64-gnu',
|
|
34
|
+
riscv64: 'linux-riscv64-gnu',
|
|
35
|
+
s390x: 'linux-s390x-gnu',
|
|
36
|
+
},
|
|
37
|
+
'linux-musl': {
|
|
38
|
+
arm: 'linux-arm-musleabihf',
|
|
39
|
+
arm64: 'linux-arm64-musl',
|
|
40
|
+
x64: 'linux-64-musl',
|
|
41
|
+
riscv64: 'linux-riscv64-musl',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const platform =
|
|
46
|
+
process.platform !== 'linux' ? process.platform : 'linux-' + isMusl() ? 'musl' : 'gnu';
|
|
47
|
+
const arch = process.arch;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @returns {string}
|
|
51
|
+
*/
|
|
52
|
+
function getPackageName() {
|
|
53
|
+
if (!(platform in PACKAGE_NAMES)) {
|
|
54
|
+
throw new Error(`Unsupported OS: ${platform}`);
|
|
55
|
+
}
|
|
56
|
+
if (!(arch in PACKAGE_NAMES[platform])) {
|
|
57
|
+
throw new Error(`Unsupported architecture for ${platform}: ${arch}`);
|
|
58
|
+
}
|
|
59
|
+
return PACKAGE_NAMES[platform][arch];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const packageName = getPackageName();
|
|
63
|
+
const localPath = path.join(
|
|
64
|
+
__dirname,
|
|
65
|
+
`npm/${packageName}/intl-message-database.${packageName}.node`,
|
|
66
|
+
);
|
|
67
|
+
const packagePath = `@discord/intl-message-database-${packageName}`;
|
|
68
|
+
const nativeBinding = fs.existsSync(localPath) ? require(localPath) : require(packagePath);
|
|
69
|
+
|
|
70
|
+
const {
|
|
71
|
+
hashMessageKey,
|
|
72
|
+
isMessageDefinitionsFile,
|
|
73
|
+
isMessageTranslationsFile,
|
|
74
|
+
resolveSymbol,
|
|
75
|
+
IntlMessagesDatabase,
|
|
76
|
+
IntlCompiledMessageFormat,
|
|
77
|
+
} = nativeBinding;
|
|
78
|
+
|
|
79
|
+
module.exports = {
|
|
80
|
+
hashMessageKey,
|
|
81
|
+
isMessageDefinitionsFile,
|
|
82
|
+
isMessageTranslationsFile,
|
|
83
|
+
resolveSymbol,
|
|
84
|
+
IntlMessagesDatabase,
|
|
85
|
+
IntlCompiledMessageFormat,
|
|
86
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@discord/intl-message-database-darwin-arm64",
|
|
3
|
+
"version": "0.0.1-rc.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"os": [
|
|
6
|
+
"darwin"
|
|
7
|
+
],
|
|
8
|
+
"cpu": [
|
|
9
|
+
"arm64"
|
|
10
|
+
],
|
|
11
|
+
"main": "intl-message-database.darwin-arm64.node",
|
|
12
|
+
"files": [
|
|
13
|
+
"intl-message-database.darwin-arm64.node"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">= 10"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@discord/intl-message-database-darwin-x64",
|
|
3
|
+
"version": "0.0.1-rc.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"os": [
|
|
6
|
+
"darwin"
|
|
7
|
+
],
|
|
8
|
+
"cpu": [
|
|
9
|
+
"x64"
|
|
10
|
+
],
|
|
11
|
+
"main": "intl-message-database.darwin-x64.node",
|
|
12
|
+
"files": [
|
|
13
|
+
"intl-message-database.darwin-x64.node"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">= 10"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@discord/intl-message-database-linux-arm64-gnu",
|
|
3
|
+
"version": "0.0.1-rc.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"os": [
|
|
6
|
+
"linux"
|
|
7
|
+
],
|
|
8
|
+
"cpu": [
|
|
9
|
+
"arm64"
|
|
10
|
+
],
|
|
11
|
+
"main": "intl-message-database.linux-arm64-gnu.node",
|
|
12
|
+
"files": [
|
|
13
|
+
"intl-message-database.linux-arm64-gnu.node"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">= 10"
|
|
17
|
+
},
|
|
18
|
+
"libc": [
|
|
19
|
+
"glibc"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@discord/intl-message-database-linux-arm64-musl",
|
|
3
|
+
"version": "0.0.1-rc.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"os": [
|
|
6
|
+
"linux"
|
|
7
|
+
],
|
|
8
|
+
"cpu": [
|
|
9
|
+
"arm64"
|
|
10
|
+
],
|
|
11
|
+
"main": "intl-message-database.linux-arm64-musl.node",
|
|
12
|
+
"files": [
|
|
13
|
+
"intl-message-database.linux-arm64-musl.node"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">= 10"
|
|
17
|
+
},
|
|
18
|
+
"libc": [
|
|
19
|
+
"musl"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@discord/intl-message-database-linux-x64-gnu",
|
|
3
|
+
"version": "0.0.1-rc.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"os": [
|
|
6
|
+
"linux"
|
|
7
|
+
],
|
|
8
|
+
"cpu": [
|
|
9
|
+
"x64"
|
|
10
|
+
],
|
|
11
|
+
"main": "intl-message-database.linux-x64-gnu.node",
|
|
12
|
+
"files": [
|
|
13
|
+
"intl-message-database.linux-x64-gnu.node"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">= 10"
|
|
17
|
+
},
|
|
18
|
+
"libc": [
|
|
19
|
+
"glibc"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@discord/intl-message-database-linux-x64-musl",
|
|
3
|
+
"version": "0.0.1-rc.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"os": [
|
|
6
|
+
"linux"
|
|
7
|
+
],
|
|
8
|
+
"cpu": [
|
|
9
|
+
"x64"
|
|
10
|
+
],
|
|
11
|
+
"main": "intl-message-database.linux-x64-musl.node",
|
|
12
|
+
"files": [
|
|
13
|
+
"intl-message-database.linux-x64-musl.node"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">= 10"
|
|
17
|
+
},
|
|
18
|
+
"libc": [
|
|
19
|
+
"musl"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@discord/intl-message-database-win32-arm64-msvc",
|
|
3
|
+
"version": "0.0.1-rc.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"os": [
|
|
6
|
+
"win32"
|
|
7
|
+
],
|
|
8
|
+
"cpu": [
|
|
9
|
+
"arm64"
|
|
10
|
+
],
|
|
11
|
+
"main": "intl-message-database.win32-arm64-msvc.node",
|
|
12
|
+
"files": [
|
|
13
|
+
"intl-message-database.win32-arm64-msvc.node"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">= 10"
|
|
17
|
+
}
|
|
18
|
+
}
|