@uruhalushia/rule-converter-napi 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +15 -21
- package/package.json +13 -13
package/index.js
CHANGED
|
@@ -5,28 +5,21 @@
|
|
|
5
5
|
import { existsSync } from 'node:fs'
|
|
6
6
|
import { join } from 'node:path'
|
|
7
7
|
import { createRequire } from 'node:module'
|
|
8
|
-
import packageJson from './package.json' with { type: 'json' }
|
|
9
8
|
|
|
10
9
|
const require = createRequire(import.meta.url)
|
|
11
10
|
const __dirname = new URL('.', import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')
|
|
12
11
|
|
|
13
12
|
const packageName = '@uruhalushia/rule-converter-napi'
|
|
14
|
-
const packageVersion = packageJson.version
|
|
15
13
|
const binaryName = 'rule-converter'
|
|
16
14
|
const loadErrors = []
|
|
17
15
|
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
return require('node:child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
21
|
-
} catch (_) {
|
|
22
|
-
return false
|
|
23
|
-
}
|
|
16
|
+
function shouldCheckVersion() {
|
|
17
|
+
return process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
|
|
24
18
|
}
|
|
25
19
|
|
|
26
20
|
function requireLocal(tuple) {
|
|
27
21
|
const filename = join(__dirname, `${binaryName}.${tuple}.node`)
|
|
28
22
|
if (!existsSync(filename)) {
|
|
29
|
-
loadErrors.push(new Error(`Native binding not found: ${filename}`))
|
|
30
23
|
return null
|
|
31
24
|
}
|
|
32
25
|
try {
|
|
@@ -41,14 +34,9 @@ function requirePackage(tuple) {
|
|
|
41
34
|
const nativePackage = `${packageName}-${tuple}`
|
|
42
35
|
try {
|
|
43
36
|
const binding = require(nativePackage)
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
bindingPackageVersion !== packageVersion &&
|
|
47
|
-
process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
|
|
48
|
-
process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
|
|
49
|
-
) {
|
|
37
|
+
if (shouldCheckVersion() && require(`${nativePackage}/package.json`).version !== require('./package.json').version) {
|
|
50
38
|
throw new Error(
|
|
51
|
-
`Native binding package version mismatch
|
|
39
|
+
`Native binding package version mismatch. You can reinstall dependencies to fix this issue.`,
|
|
52
40
|
)
|
|
53
41
|
}
|
|
54
42
|
return binding
|
|
@@ -62,6 +50,13 @@ function requireBinding(tuple) {
|
|
|
62
50
|
return requireLocal(tuple) || requirePackage(tuple)
|
|
63
51
|
}
|
|
64
52
|
|
|
53
|
+
function requireLinuxBinding(gnuTuple, muslTuple) {
|
|
54
|
+
if (existsSync('/etc/alpine-release')) {
|
|
55
|
+
return requireBinding(muslTuple) || requireBinding(gnuTuple)
|
|
56
|
+
}
|
|
57
|
+
return requireBinding(gnuTuple) || requireBinding(muslTuple)
|
|
58
|
+
}
|
|
59
|
+
|
|
65
60
|
function requireNative() {
|
|
66
61
|
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
67
62
|
try {
|
|
@@ -78,11 +73,10 @@ function requireNative() {
|
|
|
78
73
|
if (process.arch === 'x64') return requireBinding('darwin-x64')
|
|
79
74
|
if (process.arch === 'arm64') return requireBinding('darwin-arm64')
|
|
80
75
|
} else if (process.platform === 'linux') {
|
|
81
|
-
|
|
82
|
-
if (process.arch === '
|
|
83
|
-
if (process.arch === '
|
|
84
|
-
if (process.arch === '
|
|
85
|
-
if (process.arch === 'loong64') return requireBinding(musl ? 'linux-loong64-musl' : 'linux-loong64-gnu')
|
|
76
|
+
if (process.arch === 'x64') return requireLinuxBinding('linux-x64-gnu', 'linux-x64-musl')
|
|
77
|
+
if (process.arch === 'arm64') return requireLinuxBinding('linux-arm64-gnu', 'linux-arm64-musl')
|
|
78
|
+
if (process.arch === 'riscv64') return requireLinuxBinding('linux-riscv64-gnu', 'linux-riscv64-musl')
|
|
79
|
+
if (process.arch === 'loong64') return requireLinuxBinding('linux-loong64-gnu', 'linux-loong64-musl')
|
|
86
80
|
}
|
|
87
81
|
|
|
88
82
|
loadErrors.push(new Error(`Unsupported OS or architecture: ${process.platform} ${process.arch}`))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uruhalushia/rule-converter-napi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Node.js bindings for converting mihomo, sing-box, Egern, and generic rule sets.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -51,17 +51,17 @@
|
|
|
51
51
|
"@napi-rs/cli": "^3"
|
|
52
52
|
},
|
|
53
53
|
"optionalDependencies": {
|
|
54
|
-
"@uruhalushia/rule-converter-napi-linux-x64-gnu": "0.1.
|
|
55
|
-
"@uruhalushia/rule-converter-napi-linux-arm64-gnu": "0.1.
|
|
56
|
-
"@uruhalushia/rule-converter-napi-linux-riscv64-gnu": "0.1.
|
|
57
|
-
"@uruhalushia/rule-converter-napi-linux-loong64-gnu": "0.1.
|
|
58
|
-
"@uruhalushia/rule-converter-napi-linux-x64-musl": "0.1.
|
|
59
|
-
"@uruhalushia/rule-converter-napi-linux-arm64-musl": "0.1.
|
|
60
|
-
"@uruhalushia/rule-converter-napi-linux-riscv64-musl": "0.1.
|
|
61
|
-
"@uruhalushia/rule-converter-napi-linux-loong64-musl": "0.1.
|
|
62
|
-
"@uruhalushia/rule-converter-napi-darwin-x64": "0.1.
|
|
63
|
-
"@uruhalushia/rule-converter-napi-darwin-arm64": "0.1.
|
|
64
|
-
"@uruhalushia/rule-converter-napi-win32-x64-msvc": "0.1.
|
|
65
|
-
"@uruhalushia/rule-converter-napi-win32-arm64-msvc": "0.1.
|
|
54
|
+
"@uruhalushia/rule-converter-napi-linux-x64-gnu": "0.1.3",
|
|
55
|
+
"@uruhalushia/rule-converter-napi-linux-arm64-gnu": "0.1.3",
|
|
56
|
+
"@uruhalushia/rule-converter-napi-linux-riscv64-gnu": "0.1.3",
|
|
57
|
+
"@uruhalushia/rule-converter-napi-linux-loong64-gnu": "0.1.3",
|
|
58
|
+
"@uruhalushia/rule-converter-napi-linux-x64-musl": "0.1.3",
|
|
59
|
+
"@uruhalushia/rule-converter-napi-linux-arm64-musl": "0.1.3",
|
|
60
|
+
"@uruhalushia/rule-converter-napi-linux-riscv64-musl": "0.1.3",
|
|
61
|
+
"@uruhalushia/rule-converter-napi-linux-loong64-musl": "0.1.3",
|
|
62
|
+
"@uruhalushia/rule-converter-napi-darwin-x64": "0.1.3",
|
|
63
|
+
"@uruhalushia/rule-converter-napi-darwin-arm64": "0.1.3",
|
|
64
|
+
"@uruhalushia/rule-converter-napi-win32-x64-msvc": "0.1.3",
|
|
65
|
+
"@uruhalushia/rule-converter-napi-win32-arm64-msvc": "0.1.3"
|
|
66
66
|
}
|
|
67
67
|
}
|