@i18n.site/nt-js 0.0.0-stage → 0.1.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/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # @i18n.site/nt-js
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@i18n.site/nt-js` is the Node.js / Bun native binding for `i18n_nt_js` powered by `napi-rs`.
4
+
5
+ See [i18n/zh/README.md](./i18n/zh/README.md).
package/index.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ export interface CompileOpt {
2
+ dirLi: string[]
3
+ cwd?: string
4
+ fromLang: string
5
+ target: 'web' | 'lynx'
6
+ mode: 'dev' | 'prod'
7
+ suffix?: string
8
+ includeDemo?: boolean
9
+ }
10
+
11
+ export interface CompManifest {
12
+ id: number
13
+ keys: Record<string, number>
14
+ }
15
+
16
+ export interface LangAsset {
17
+ lang: string
18
+ compKey?: string
19
+ filename: string
20
+ code: string
21
+ }
22
+
23
+ export interface CompileResult {
24
+ manifest: Record<string, CompManifest>
25
+ assetLi: LangAsset[]
26
+ diagLi: string[]
27
+ }
28
+
29
+ export declare function compileNt(opt: CompileOpt): CompileResult
package/index.js ADDED
@@ -0,0 +1,51 @@
1
+ const { readFileSync } = require('fs')
2
+
3
+ const TARGET_MAP = {
4
+ 'darwin:arm64': ['./i18n_nt_js.darwin-arm64.node', '@i18n.site/nt-js-darwin-arm64'],
5
+ 'darwin:x64': ['./i18n_nt_js.darwin-x64.node', '@i18n.site/nt-js-darwin-x64'],
6
+ 'win32:arm64': ['./i18n_nt_js.win32-arm64-msvc.node', '@i18n.site/nt-js-win32-arm64-msvc'],
7
+ 'win32:x64': ['./i18n_nt_js.win32-x64-msvc.node', '@i18n.site/nt-js-win32-x64-msvc'],
8
+ 'linux:arm64:gnu': ['./i18n_nt_js.linux-arm64-gnu.node', '@i18n.site/nt-js-linux-arm64-gnu'],
9
+ 'linux:x64:gnu': ['./i18n_nt_js.linux-x64-gnu.node', '@i18n.site/nt-js-linux-x64-gnu'],
10
+ 'linux:arm64:musl': ['./i18n_nt_js.linux-arm64-musl.node', '@i18n.site/nt-js-linux-arm64-musl'],
11
+ 'linux:x64:musl': ['./i18n_nt_js.linux-x64-musl.node', '@i18n.site/nt-js-linux-x64-musl']
12
+ }
13
+
14
+ const isMusl = () => {
15
+ if (process.platform !== 'linux') return false
16
+ const rep =
17
+ process.report && typeof process.report.getReport === 'function'
18
+ ? process.report.getReport()
19
+ : null
20
+ if (rep && rep.header && rep.header.glibcVersionRuntime) return false
21
+ try {
22
+ if (readFileSync('/usr/bin/ldd', 'utf8').includes('musl')) return true
23
+ } catch {}
24
+ return Boolean(rep && Array.isArray(rep.sharedObjects) && rep.sharedObjects.some((f) => f.includes('musl')))
25
+ }
26
+
27
+ const override = process.env.NAPI_RS_NATIVE_LIBRARY_PATH
28
+ if (override) {
29
+ module.exports = require(override)
30
+ } else {
31
+ const key =
32
+ process.platform === 'linux'
33
+ ? 'linux:' + process.arch + ':' + (isMusl() ? 'musl' : 'gnu')
34
+ : process.platform + ':' + process.arch
35
+ const entry = TARGET_MAP[key]
36
+ if (!entry) throw new Error('Unsupported platform: ' + key)
37
+ let dlopen_err = null
38
+ let last_err = null
39
+ let loaded = false
40
+ for (let i = 0; i < entry.length; ++i) {
41
+ try {
42
+ module.exports = require(entry[i])
43
+ loaded = true
44
+ break
45
+ } catch (e) {
46
+ if (!dlopen_err && e && e.code !== 'MODULE_NOT_FOUND') dlopen_err = e
47
+ last_err = e
48
+ }
49
+ }
50
+ if (!loaded) throw dlopen_err || last_err
51
+ }
package/package.json CHANGED
@@ -1,6 +1 @@
1
- {
2
- "name": "@i18n.site/nt-js",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {"name":"@i18n.site/nt-js","description":"Compile flat NestedText component dictionaries to Web ESM and Lynx JSON via napi-rs","keywords":["i18n","nestedtext","webc","lynx","napi-rs"],"main":"index.js","types":"index.d.ts","files":["index.js","index.d.ts","README.md"],"optionalDependencies":{"@i18n.site/nt-js-darwin-arm64":"0.1.0","@i18n.site/nt-js-darwin-x64":"0.1.0","@i18n.site/nt-js-linux-arm64-gnu":"0.1.0","@i18n.site/nt-js-linux-x64-gnu":"0.1.0","@i18n.site/nt-js-linux-arm64-musl":"0.1.0","@i18n.site/nt-js-linux-x64-musl":"0.1.0","@i18n.site/nt-js-win32-arm64-msvc":"0.1.0","@i18n.site/nt-js-win32-x64-msvc":"0.1.0"},"version":"0.1.0","license":"MulanPSL-2.0","repository":{"type":"git","url":"git+https://atomgit.com/i18n-site/i18n.site.git"},"engines":{"node":">= 18"},"publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}