@bennyblader/ddk-ts 0.3.41 → 0.3.43
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/browser.js +1 -0
- package/dist/ddk-ts.wasi-browser.js +90 -0
- package/dist/ddk-ts.wasi.cjs +141 -0
- package/dist/index.js +97 -67
- package/dist/wasi-worker-browser.mjs +34 -0
- package/dist/wasi-worker.mjs +63 -0
- package/package.json +12 -6
- package/dist/ddk-ts.darwin-arm64.node +0 -0
package/dist/browser.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@bennyblader/ddk-ts-wasm32-wasi'
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createOnMessage as __wasmCreateOnMessageForFsProxy,
|
|
3
|
+
getDefaultContext as __emnapiGetDefaultContext,
|
|
4
|
+
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
|
|
5
|
+
WASI as __WASI,
|
|
6
|
+
} from '@napi-rs/wasm-runtime'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const __wasi = new __WASI({
|
|
11
|
+
version: 'preview1',
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const __wasmUrl = new URL('./ddk-ts.wasm32-wasi.wasm', import.meta.url).href
|
|
15
|
+
const __emnapiContext = __emnapiGetDefaultContext()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const __sharedMemory = new WebAssembly.Memory({
|
|
19
|
+
initial: 4000,
|
|
20
|
+
maximum: 65536,
|
|
21
|
+
shared: true,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
instance: __napiInstance,
|
|
28
|
+
module: __wasiModule,
|
|
29
|
+
napiModule: __napiModule,
|
|
30
|
+
} = __emnapiInstantiateNapiModuleSync(__wasmFile, {
|
|
31
|
+
context: __emnapiContext,
|
|
32
|
+
asyncWorkPoolSize: 4,
|
|
33
|
+
wasi: __wasi,
|
|
34
|
+
onCreateWorker() {
|
|
35
|
+
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
|
|
36
|
+
type: 'module',
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
return worker
|
|
41
|
+
},
|
|
42
|
+
overwriteImports(importObject) {
|
|
43
|
+
importObject.env = {
|
|
44
|
+
...importObject.env,
|
|
45
|
+
...importObject.napi,
|
|
46
|
+
...importObject.emnapi,
|
|
47
|
+
memory: __sharedMemory,
|
|
48
|
+
}
|
|
49
|
+
return importObject
|
|
50
|
+
},
|
|
51
|
+
beforeInit({ instance }) {
|
|
52
|
+
for (const name of Object.keys(instance.exports)) {
|
|
53
|
+
if (name.startsWith('__napi_register__')) {
|
|
54
|
+
instance.exports[name]()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
export default __napiModule.exports
|
|
60
|
+
export const addSignatureToTransaction = __napiModule.exports.addSignatureToTransaction
|
|
61
|
+
export const convertMnemonicToSeed = __napiModule.exports.convertMnemonicToSeed
|
|
62
|
+
export const createCet = __napiModule.exports.createCet
|
|
63
|
+
export const createCetAdaptorPointsFromOracleInfo = __napiModule.exports.createCetAdaptorPointsFromOracleInfo
|
|
64
|
+
export const createCetAdaptorSignatureFromOracleInfo = __napiModule.exports.createCetAdaptorSignatureFromOracleInfo
|
|
65
|
+
export const createCetAdaptorSigsFromOracleInfo = __napiModule.exports.createCetAdaptorSigsFromOracleInfo
|
|
66
|
+
export const createCetAdaptorSigsFromPoints = __napiModule.exports.createCetAdaptorSigsFromPoints
|
|
67
|
+
export const createCets = __napiModule.exports.createCets
|
|
68
|
+
export const createDlcTransactions = __napiModule.exports.createDlcTransactions
|
|
69
|
+
export const createExtkeyFromParentPath = __napiModule.exports.createExtkeyFromParentPath
|
|
70
|
+
export const createExtkeyFromSeed = __napiModule.exports.createExtkeyFromSeed
|
|
71
|
+
export const createFundTxLockingScript = __napiModule.exports.createFundTxLockingScript
|
|
72
|
+
export const createRefundTransaction = __napiModule.exports.createRefundTransaction
|
|
73
|
+
export const createSplicedDlcTransactions = __napiModule.exports.createSplicedDlcTransactions
|
|
74
|
+
export const createXprivFromParentPath = __napiModule.exports.createXprivFromParentPath
|
|
75
|
+
export const extractEcdsaSignatureFromOracleSignatures = __napiModule.exports.extractEcdsaSignatureFromOracleSignatures
|
|
76
|
+
export const getCetAdaptorSignatureInputs = __napiModule.exports.getCetAdaptorSignatureInputs
|
|
77
|
+
export const getCetSighash = __napiModule.exports.getCetSighash
|
|
78
|
+
export const getChangeOutputAndFees = __napiModule.exports.getChangeOutputAndFees
|
|
79
|
+
export const getPubkeyFromExtkey = __napiModule.exports.getPubkeyFromExtkey
|
|
80
|
+
export const getRawFundingTransactionInputSignature = __napiModule.exports.getRawFundingTransactionInputSignature
|
|
81
|
+
export const getTotalInputVsize = __napiModule.exports.getTotalInputVsize
|
|
82
|
+
export const getXpubFromXpriv = __napiModule.exports.getXpubFromXpriv
|
|
83
|
+
export const isDustOutput = __napiModule.exports.isDustOutput
|
|
84
|
+
export const signCet = __napiModule.exports.signCet
|
|
85
|
+
export const signFundTransactionInput = __napiModule.exports.signFundTransactionInput
|
|
86
|
+
export const signMultiSigInput = __napiModule.exports.signMultiSigInput
|
|
87
|
+
export const verifyCetAdaptorSigFromOracleInfo = __napiModule.exports.verifyCetAdaptorSigFromOracleInfo
|
|
88
|
+
export const verifyCetAdaptorSigsFromOracleInfo = __napiModule.exports.verifyCetAdaptorSigsFromOracleInfo
|
|
89
|
+
export const verifyFundTxSignature = __napiModule.exports.verifyFundTxSignature
|
|
90
|
+
export const version = __napiModule.exports.version
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* prettier-ignore */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const __nodeFs = require('node:fs')
|
|
7
|
+
const __nodePath = require('node:path')
|
|
8
|
+
const { WASI: __nodeWASI } = require('node:wasi')
|
|
9
|
+
const { Worker } = require('node:worker_threads')
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
createOnMessage: __wasmCreateOnMessageForFsProxy,
|
|
13
|
+
getDefaultContext: __emnapiGetDefaultContext,
|
|
14
|
+
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
15
|
+
} = require('@napi-rs/wasm-runtime')
|
|
16
|
+
|
|
17
|
+
const __rootDir = __nodePath.parse(process.cwd()).root
|
|
18
|
+
|
|
19
|
+
const __wasi = new __nodeWASI({
|
|
20
|
+
version: 'preview1',
|
|
21
|
+
env: process.env,
|
|
22
|
+
preopens: {
|
|
23
|
+
[__rootDir]: __rootDir,
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const __emnapiContext = __emnapiGetDefaultContext()
|
|
28
|
+
|
|
29
|
+
const __sharedMemory = new WebAssembly.Memory({
|
|
30
|
+
initial: 4000,
|
|
31
|
+
maximum: 65536,
|
|
32
|
+
shared: true,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
let __wasmFilePath = __nodePath.join(__dirname, 'ddk-ts.wasm32-wasi.wasm')
|
|
36
|
+
const __wasmDebugFilePath = __nodePath.join(__dirname, 'ddk-ts.wasm32-wasi.debug.wasm')
|
|
37
|
+
|
|
38
|
+
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
|
|
39
|
+
__wasmFilePath = __wasmDebugFilePath
|
|
40
|
+
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
|
|
41
|
+
try {
|
|
42
|
+
__wasmFilePath = require.resolve('@bennyblader/ddk-ts-wasm32-wasi/ddk-ts.wasm32-wasi.wasm')
|
|
43
|
+
} catch {
|
|
44
|
+
throw new Error('Cannot find ddk-ts.wasm32-wasi.wasm file, and @bennyblader/ddk-ts-wasm32-wasi package is not installed.')
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
|
|
49
|
+
context: __emnapiContext,
|
|
50
|
+
asyncWorkPoolSize: (function() {
|
|
51
|
+
const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
|
|
52
|
+
// NaN > 0 is false
|
|
53
|
+
if (threadsSizeFromEnv > 0) {
|
|
54
|
+
return threadsSizeFromEnv
|
|
55
|
+
} else {
|
|
56
|
+
return 4
|
|
57
|
+
}
|
|
58
|
+
})(),
|
|
59
|
+
reuseWorker: true,
|
|
60
|
+
wasi: __wasi,
|
|
61
|
+
onCreateWorker() {
|
|
62
|
+
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
|
|
63
|
+
env: process.env,
|
|
64
|
+
})
|
|
65
|
+
worker.onmessage = ({ data }) => {
|
|
66
|
+
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The main thread of Node.js waits for all the active handles before exiting.
|
|
70
|
+
// But Rust threads are never waited without `thread::join`.
|
|
71
|
+
// So here we hack the code of Node.js to prevent the workers from being referenced (active).
|
|
72
|
+
// According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
|
|
73
|
+
// a worker is consist of two handles: kPublicPort and kHandle.
|
|
74
|
+
{
|
|
75
|
+
const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
|
|
76
|
+
s.toString().includes("kPublicPort")
|
|
77
|
+
);
|
|
78
|
+
if (kPublicPort) {
|
|
79
|
+
worker[kPublicPort].ref = () => {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
|
|
83
|
+
s.toString().includes("kHandle")
|
|
84
|
+
);
|
|
85
|
+
if (kHandle) {
|
|
86
|
+
worker[kHandle].ref = () => {};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
worker.unref();
|
|
90
|
+
}
|
|
91
|
+
return worker
|
|
92
|
+
},
|
|
93
|
+
overwriteImports(importObject) {
|
|
94
|
+
importObject.env = {
|
|
95
|
+
...importObject.env,
|
|
96
|
+
...importObject.napi,
|
|
97
|
+
...importObject.emnapi,
|
|
98
|
+
memory: __sharedMemory,
|
|
99
|
+
}
|
|
100
|
+
return importObject
|
|
101
|
+
},
|
|
102
|
+
beforeInit({ instance }) {
|
|
103
|
+
for (const name of Object.keys(instance.exports)) {
|
|
104
|
+
if (name.startsWith('__napi_register__')) {
|
|
105
|
+
instance.exports[name]()
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
module.exports = __napiModule.exports
|
|
111
|
+
module.exports.addSignatureToTransaction = __napiModule.exports.addSignatureToTransaction
|
|
112
|
+
module.exports.convertMnemonicToSeed = __napiModule.exports.convertMnemonicToSeed
|
|
113
|
+
module.exports.createCet = __napiModule.exports.createCet
|
|
114
|
+
module.exports.createCetAdaptorPointsFromOracleInfo = __napiModule.exports.createCetAdaptorPointsFromOracleInfo
|
|
115
|
+
module.exports.createCetAdaptorSignatureFromOracleInfo = __napiModule.exports.createCetAdaptorSignatureFromOracleInfo
|
|
116
|
+
module.exports.createCetAdaptorSigsFromOracleInfo = __napiModule.exports.createCetAdaptorSigsFromOracleInfo
|
|
117
|
+
module.exports.createCetAdaptorSigsFromPoints = __napiModule.exports.createCetAdaptorSigsFromPoints
|
|
118
|
+
module.exports.createCets = __napiModule.exports.createCets
|
|
119
|
+
module.exports.createDlcTransactions = __napiModule.exports.createDlcTransactions
|
|
120
|
+
module.exports.createExtkeyFromParentPath = __napiModule.exports.createExtkeyFromParentPath
|
|
121
|
+
module.exports.createExtkeyFromSeed = __napiModule.exports.createExtkeyFromSeed
|
|
122
|
+
module.exports.createFundTxLockingScript = __napiModule.exports.createFundTxLockingScript
|
|
123
|
+
module.exports.createRefundTransaction = __napiModule.exports.createRefundTransaction
|
|
124
|
+
module.exports.createSplicedDlcTransactions = __napiModule.exports.createSplicedDlcTransactions
|
|
125
|
+
module.exports.createXprivFromParentPath = __napiModule.exports.createXprivFromParentPath
|
|
126
|
+
module.exports.extractEcdsaSignatureFromOracleSignatures = __napiModule.exports.extractEcdsaSignatureFromOracleSignatures
|
|
127
|
+
module.exports.getCetAdaptorSignatureInputs = __napiModule.exports.getCetAdaptorSignatureInputs
|
|
128
|
+
module.exports.getCetSighash = __napiModule.exports.getCetSighash
|
|
129
|
+
module.exports.getChangeOutputAndFees = __napiModule.exports.getChangeOutputAndFees
|
|
130
|
+
module.exports.getPubkeyFromExtkey = __napiModule.exports.getPubkeyFromExtkey
|
|
131
|
+
module.exports.getRawFundingTransactionInputSignature = __napiModule.exports.getRawFundingTransactionInputSignature
|
|
132
|
+
module.exports.getTotalInputVsize = __napiModule.exports.getTotalInputVsize
|
|
133
|
+
module.exports.getXpubFromXpriv = __napiModule.exports.getXpubFromXpriv
|
|
134
|
+
module.exports.isDustOutput = __napiModule.exports.isDustOutput
|
|
135
|
+
module.exports.signCet = __napiModule.exports.signCet
|
|
136
|
+
module.exports.signFundTransactionInput = __napiModule.exports.signFundTransactionInput
|
|
137
|
+
module.exports.signMultiSigInput = __napiModule.exports.signMultiSigInput
|
|
138
|
+
module.exports.verifyCetAdaptorSigFromOracleInfo = __napiModule.exports.verifyCetAdaptorSigFromOracleInfo
|
|
139
|
+
module.exports.verifyCetAdaptorSigsFromOracleInfo = __napiModule.exports.verifyCetAdaptorSigsFromOracleInfo
|
|
140
|
+
module.exports.verifyFundTxSignature = __napiModule.exports.verifyFundTxSignature
|
|
141
|
+
module.exports.version = __napiModule.exports.version
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
// @ts-nocheck
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
|
-
const {
|
|
7
|
-
require = createRequire(__filename)
|
|
8
|
-
|
|
9
|
-
const { readFileSync } = require('node:fs')
|
|
6
|
+
const { readFileSync } = require('fs')
|
|
10
7
|
let nativeBinding = null
|
|
11
8
|
const loadErrors = []
|
|
12
9
|
|
|
@@ -36,7 +33,7 @@ const isMuslFromFilesystem = () => {
|
|
|
36
33
|
|
|
37
34
|
const isMuslFromReport = () => {
|
|
38
35
|
let report = null
|
|
39
|
-
if (typeof process.report
|
|
36
|
+
if (process.report && typeof process.report.getReport === 'function') {
|
|
40
37
|
process.report.excludeNetwork = true
|
|
41
38
|
report = process.report.getReport()
|
|
42
39
|
}
|
|
@@ -80,8 +77,8 @@ function requireNative() {
|
|
|
80
77
|
try {
|
|
81
78
|
const binding = require('@bennyblader/ddk-ts-android-arm64')
|
|
82
79
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-android-arm64/package.json').version
|
|
83
|
-
if (bindingPackageVersion !== '0.3.
|
|
84
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
80
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
85
82
|
}
|
|
86
83
|
return binding
|
|
87
84
|
} catch (e) {
|
|
@@ -96,8 +93,8 @@ function requireNative() {
|
|
|
96
93
|
try {
|
|
97
94
|
const binding = require('@bennyblader/ddk-ts-android-arm-eabi')
|
|
98
95
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-android-arm-eabi/package.json').version
|
|
99
|
-
if (bindingPackageVersion !== '0.3.
|
|
100
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
96
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
101
98
|
}
|
|
102
99
|
return binding
|
|
103
100
|
} catch (e) {
|
|
@@ -108,7 +105,24 @@ function requireNative() {
|
|
|
108
105
|
}
|
|
109
106
|
} else if (process.platform === 'win32') {
|
|
110
107
|
if (process.arch === 'x64') {
|
|
108
|
+
if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
|
|
109
|
+
try {
|
|
110
|
+
return require('./ddk-ts.win32-x64-gnu.node')
|
|
111
|
+
} catch (e) {
|
|
112
|
+
loadErrors.push(e)
|
|
113
|
+
}
|
|
111
114
|
try {
|
|
115
|
+
const binding = require('@bennyblader/ddk-ts-win32-x64-gnu')
|
|
116
|
+
const bindingPackageVersion = require('@bennyblader/ddk-ts-win32-x64-gnu/package.json').version
|
|
117
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
|
+
}
|
|
120
|
+
return binding
|
|
121
|
+
} catch (e) {
|
|
122
|
+
loadErrors.push(e)
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
try {
|
|
112
126
|
return require('./ddk-ts.win32-x64-msvc.node')
|
|
113
127
|
} catch (e) {
|
|
114
128
|
loadErrors.push(e)
|
|
@@ -116,13 +130,14 @@ function requireNative() {
|
|
|
116
130
|
try {
|
|
117
131
|
const binding = require('@bennyblader/ddk-ts-win32-x64-msvc')
|
|
118
132
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-win32-x64-msvc/package.json').version
|
|
119
|
-
if (bindingPackageVersion !== '0.3.
|
|
120
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
133
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
121
135
|
}
|
|
122
136
|
return binding
|
|
123
137
|
} catch (e) {
|
|
124
138
|
loadErrors.push(e)
|
|
125
139
|
}
|
|
140
|
+
}
|
|
126
141
|
} else if (process.arch === 'ia32') {
|
|
127
142
|
try {
|
|
128
143
|
return require('./ddk-ts.win32-ia32-msvc.node')
|
|
@@ -132,8 +147,8 @@ function requireNative() {
|
|
|
132
147
|
try {
|
|
133
148
|
const binding = require('@bennyblader/ddk-ts-win32-ia32-msvc')
|
|
134
149
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-win32-ia32-msvc/package.json').version
|
|
135
|
-
if (bindingPackageVersion !== '0.3.
|
|
136
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
150
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
137
152
|
}
|
|
138
153
|
return binding
|
|
139
154
|
} catch (e) {
|
|
@@ -148,8 +163,8 @@ function requireNative() {
|
|
|
148
163
|
try {
|
|
149
164
|
const binding = require('@bennyblader/ddk-ts-win32-arm64-msvc')
|
|
150
165
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-win32-arm64-msvc/package.json').version
|
|
151
|
-
if (bindingPackageVersion !== '0.3.
|
|
152
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
166
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
153
168
|
}
|
|
154
169
|
return binding
|
|
155
170
|
} catch (e) {
|
|
@@ -167,8 +182,8 @@ function requireNative() {
|
|
|
167
182
|
try {
|
|
168
183
|
const binding = require('@bennyblader/ddk-ts-darwin-universal')
|
|
169
184
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-darwin-universal/package.json').version
|
|
170
|
-
if (bindingPackageVersion !== '0.3.
|
|
171
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
185
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
172
187
|
}
|
|
173
188
|
return binding
|
|
174
189
|
} catch (e) {
|
|
@@ -183,8 +198,8 @@ function requireNative() {
|
|
|
183
198
|
try {
|
|
184
199
|
const binding = require('@bennyblader/ddk-ts-darwin-x64')
|
|
185
200
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-darwin-x64/package.json').version
|
|
186
|
-
if (bindingPackageVersion !== '0.3.
|
|
187
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
201
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
188
203
|
}
|
|
189
204
|
return binding
|
|
190
205
|
} catch (e) {
|
|
@@ -199,8 +214,8 @@ function requireNative() {
|
|
|
199
214
|
try {
|
|
200
215
|
const binding = require('@bennyblader/ddk-ts-darwin-arm64')
|
|
201
216
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-darwin-arm64/package.json').version
|
|
202
|
-
if (bindingPackageVersion !== '0.3.
|
|
203
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
217
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
204
219
|
}
|
|
205
220
|
return binding
|
|
206
221
|
} catch (e) {
|
|
@@ -219,8 +234,8 @@ function requireNative() {
|
|
|
219
234
|
try {
|
|
220
235
|
const binding = require('@bennyblader/ddk-ts-freebsd-x64')
|
|
221
236
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-freebsd-x64/package.json').version
|
|
222
|
-
if (bindingPackageVersion !== '0.3.
|
|
223
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
237
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
224
239
|
}
|
|
225
240
|
return binding
|
|
226
241
|
} catch (e) {
|
|
@@ -235,8 +250,8 @@ function requireNative() {
|
|
|
235
250
|
try {
|
|
236
251
|
const binding = require('@bennyblader/ddk-ts-freebsd-arm64')
|
|
237
252
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-freebsd-arm64/package.json').version
|
|
238
|
-
if (bindingPackageVersion !== '0.3.
|
|
239
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
253
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
240
255
|
}
|
|
241
256
|
return binding
|
|
242
257
|
} catch (e) {
|
|
@@ -256,8 +271,8 @@ function requireNative() {
|
|
|
256
271
|
try {
|
|
257
272
|
const binding = require('@bennyblader/ddk-ts-linux-x64-musl')
|
|
258
273
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-x64-musl/package.json').version
|
|
259
|
-
if (bindingPackageVersion !== '0.3.
|
|
260
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
274
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
261
276
|
}
|
|
262
277
|
return binding
|
|
263
278
|
} catch (e) {
|
|
@@ -272,8 +287,8 @@ function requireNative() {
|
|
|
272
287
|
try {
|
|
273
288
|
const binding = require('@bennyblader/ddk-ts-linux-x64-gnu')
|
|
274
289
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-x64-gnu/package.json').version
|
|
275
|
-
if (bindingPackageVersion !== '0.3.
|
|
276
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
290
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
277
292
|
}
|
|
278
293
|
return binding
|
|
279
294
|
} catch (e) {
|
|
@@ -290,8 +305,8 @@ function requireNative() {
|
|
|
290
305
|
try {
|
|
291
306
|
const binding = require('@bennyblader/ddk-ts-linux-arm64-musl')
|
|
292
307
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-arm64-musl/package.json').version
|
|
293
|
-
if (bindingPackageVersion !== '0.3.
|
|
294
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
308
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
295
310
|
}
|
|
296
311
|
return binding
|
|
297
312
|
} catch (e) {
|
|
@@ -306,8 +321,8 @@ function requireNative() {
|
|
|
306
321
|
try {
|
|
307
322
|
const binding = require('@bennyblader/ddk-ts-linux-arm64-gnu')
|
|
308
323
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-arm64-gnu/package.json').version
|
|
309
|
-
if (bindingPackageVersion !== '0.3.
|
|
310
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
324
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
311
326
|
}
|
|
312
327
|
return binding
|
|
313
328
|
} catch (e) {
|
|
@@ -324,8 +339,8 @@ function requireNative() {
|
|
|
324
339
|
try {
|
|
325
340
|
const binding = require('@bennyblader/ddk-ts-linux-arm-musleabihf')
|
|
326
341
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-arm-musleabihf/package.json').version
|
|
327
|
-
if (bindingPackageVersion !== '0.3.
|
|
328
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
342
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
329
344
|
}
|
|
330
345
|
return binding
|
|
331
346
|
} catch (e) {
|
|
@@ -340,8 +355,8 @@ function requireNative() {
|
|
|
340
355
|
try {
|
|
341
356
|
const binding = require('@bennyblader/ddk-ts-linux-arm-gnueabihf')
|
|
342
357
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-arm-gnueabihf/package.json').version
|
|
343
|
-
if (bindingPackageVersion !== '0.3.
|
|
344
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
358
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
345
360
|
}
|
|
346
361
|
return binding
|
|
347
362
|
} catch (e) {
|
|
@@ -358,8 +373,8 @@ function requireNative() {
|
|
|
358
373
|
try {
|
|
359
374
|
const binding = require('@bennyblader/ddk-ts-linux-loong64-musl')
|
|
360
375
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-loong64-musl/package.json').version
|
|
361
|
-
if (bindingPackageVersion !== '0.3.
|
|
362
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
376
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
363
378
|
}
|
|
364
379
|
return binding
|
|
365
380
|
} catch (e) {
|
|
@@ -374,8 +389,8 @@ function requireNative() {
|
|
|
374
389
|
try {
|
|
375
390
|
const binding = require('@bennyblader/ddk-ts-linux-loong64-gnu')
|
|
376
391
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-loong64-gnu/package.json').version
|
|
377
|
-
if (bindingPackageVersion !== '0.3.
|
|
378
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
392
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
379
394
|
}
|
|
380
395
|
return binding
|
|
381
396
|
} catch (e) {
|
|
@@ -392,8 +407,8 @@ function requireNative() {
|
|
|
392
407
|
try {
|
|
393
408
|
const binding = require('@bennyblader/ddk-ts-linux-riscv64-musl')
|
|
394
409
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-riscv64-musl/package.json').version
|
|
395
|
-
if (bindingPackageVersion !== '0.3.
|
|
396
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
410
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
397
412
|
}
|
|
398
413
|
return binding
|
|
399
414
|
} catch (e) {
|
|
@@ -408,8 +423,8 @@ function requireNative() {
|
|
|
408
423
|
try {
|
|
409
424
|
const binding = require('@bennyblader/ddk-ts-linux-riscv64-gnu')
|
|
410
425
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-riscv64-gnu/package.json').version
|
|
411
|
-
if (bindingPackageVersion !== '0.3.
|
|
412
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
426
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
413
428
|
}
|
|
414
429
|
return binding
|
|
415
430
|
} catch (e) {
|
|
@@ -425,8 +440,8 @@ function requireNative() {
|
|
|
425
440
|
try {
|
|
426
441
|
const binding = require('@bennyblader/ddk-ts-linux-ppc64-gnu')
|
|
427
442
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-ppc64-gnu/package.json').version
|
|
428
|
-
if (bindingPackageVersion !== '0.3.
|
|
429
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
443
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
430
445
|
}
|
|
431
446
|
return binding
|
|
432
447
|
} catch (e) {
|
|
@@ -441,8 +456,8 @@ function requireNative() {
|
|
|
441
456
|
try {
|
|
442
457
|
const binding = require('@bennyblader/ddk-ts-linux-s390x-gnu')
|
|
443
458
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-s390x-gnu/package.json').version
|
|
444
|
-
if (bindingPackageVersion !== '0.3.
|
|
445
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
459
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
446
461
|
}
|
|
447
462
|
return binding
|
|
448
463
|
} catch (e) {
|
|
@@ -461,8 +476,8 @@ function requireNative() {
|
|
|
461
476
|
try {
|
|
462
477
|
const binding = require('@bennyblader/ddk-ts-openharmony-arm64')
|
|
463
478
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-openharmony-arm64/package.json').version
|
|
464
|
-
if (bindingPackageVersion !== '0.3.
|
|
465
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
479
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
466
481
|
}
|
|
467
482
|
return binding
|
|
468
483
|
} catch (e) {
|
|
@@ -477,8 +492,8 @@ function requireNative() {
|
|
|
477
492
|
try {
|
|
478
493
|
const binding = require('@bennyblader/ddk-ts-openharmony-x64')
|
|
479
494
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-openharmony-x64/package.json').version
|
|
480
|
-
if (bindingPackageVersion !== '0.3.
|
|
481
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
495
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
482
497
|
}
|
|
483
498
|
return binding
|
|
484
499
|
} catch (e) {
|
|
@@ -493,8 +508,8 @@ function requireNative() {
|
|
|
493
508
|
try {
|
|
494
509
|
const binding = require('@bennyblader/ddk-ts-openharmony-arm')
|
|
495
510
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-openharmony-arm/package.json').version
|
|
496
|
-
if (bindingPackageVersion !== '0.3.
|
|
497
|
-
throw new Error(`Native binding package version mismatch, expected 0.3.
|
|
511
|
+
if (bindingPackageVersion !== '0.3.43' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 0.3.43 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
498
513
|
}
|
|
499
514
|
return binding
|
|
500
515
|
} catch (e) {
|
|
@@ -510,24 +525,38 @@ function requireNative() {
|
|
|
510
525
|
|
|
511
526
|
nativeBinding = requireNative()
|
|
512
527
|
|
|
513
|
-
|
|
528
|
+
// NAPI_RS_FORCE_WASI is a tri-state flag:
|
|
529
|
+
// unset / any other value → native binding preferred, WASI is only a fallback
|
|
530
|
+
// 'true' → force WASI fallback even if native loaded
|
|
531
|
+
// 'error' → force WASI and throw if no WASI binding is found
|
|
532
|
+
// Treating any non-empty string as truthy (the historical behavior) meant
|
|
533
|
+
// NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
|
|
534
|
+
// the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
|
|
535
|
+
const forceWasi =
|
|
536
|
+
process.env.NAPI_RS_FORCE_WASI === 'true' || process.env.NAPI_RS_FORCE_WASI === 'error'
|
|
537
|
+
|
|
538
|
+
if (!nativeBinding || forceWasi) {
|
|
514
539
|
let wasiBinding = null
|
|
515
540
|
let wasiBindingError = null
|
|
516
541
|
try {
|
|
517
542
|
wasiBinding = require('./ddk-ts.wasi.cjs')
|
|
518
543
|
nativeBinding = wasiBinding
|
|
519
544
|
} catch (err) {
|
|
520
|
-
if (
|
|
545
|
+
if (forceWasi) {
|
|
521
546
|
wasiBindingError = err
|
|
522
547
|
}
|
|
523
548
|
}
|
|
524
|
-
if (!nativeBinding) {
|
|
549
|
+
if (!nativeBinding || forceWasi) {
|
|
525
550
|
try {
|
|
526
551
|
wasiBinding = require('@bennyblader/ddk-ts-wasm32-wasi')
|
|
527
552
|
nativeBinding = wasiBinding
|
|
528
553
|
} catch (err) {
|
|
529
|
-
if (
|
|
530
|
-
wasiBindingError
|
|
554
|
+
if (forceWasi) {
|
|
555
|
+
if (!wasiBindingError) {
|
|
556
|
+
wasiBindingError = err
|
|
557
|
+
} else {
|
|
558
|
+
wasiBindingError.cause = err
|
|
559
|
+
}
|
|
531
560
|
loadErrors.push(err)
|
|
532
561
|
}
|
|
533
562
|
}
|
|
@@ -541,17 +570,18 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
|
541
570
|
|
|
542
571
|
if (!nativeBinding) {
|
|
543
572
|
if (loadErrors.length > 0) {
|
|
544
|
-
|
|
573
|
+
const error = new Error(
|
|
545
574
|
`Cannot find native binding. ` +
|
|
546
575
|
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
547
576
|
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
548
|
-
{
|
|
549
|
-
cause: loadErrors.reduce((err, cur) => {
|
|
550
|
-
cur.cause = err
|
|
551
|
-
return cur
|
|
552
|
-
}),
|
|
553
|
-
},
|
|
554
577
|
)
|
|
578
|
+
// assign instead of the `new Error(message, { cause })` options form,
|
|
579
|
+
// which Node < 16.9 silently ignores
|
|
580
|
+
error.cause = loadErrors.reduce((err, cur) => {
|
|
581
|
+
cur.cause = err
|
|
582
|
+
return cur
|
|
583
|
+
})
|
|
584
|
+
throw error
|
|
555
585
|
}
|
|
556
586
|
throw new Error(`Failed to load native binding`)
|
|
557
587
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
|
|
2
|
+
|
|
3
|
+
const handler = new MessageHandler({
|
|
4
|
+
onLoad({ wasmModule, wasmMemory }) {
|
|
5
|
+
const wasi = new WASI({
|
|
6
|
+
print: function () {
|
|
7
|
+
// eslint-disable-next-line no-console
|
|
8
|
+
console.log.apply(console, arguments)
|
|
9
|
+
},
|
|
10
|
+
printErr: function() {
|
|
11
|
+
// eslint-disable-next-line no-console
|
|
12
|
+
console.error.apply(console, arguments)
|
|
13
|
+
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
return instantiateNapiModuleSync(wasmModule, {
|
|
17
|
+
childThread: true,
|
|
18
|
+
wasi,
|
|
19
|
+
overwriteImports(importObject) {
|
|
20
|
+
importObject.env = {
|
|
21
|
+
...importObject.env,
|
|
22
|
+
...importObject.napi,
|
|
23
|
+
...importObject.emnapi,
|
|
24
|
+
memory: wasmMemory,
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
globalThis.onmessage = function (e) {
|
|
33
|
+
handler.handle(e)
|
|
34
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { parse } from "node:path";
|
|
4
|
+
import { WASI } from "node:wasi";
|
|
5
|
+
import { parentPort, Worker } from "node:worker_threads";
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
|
|
10
|
+
|
|
11
|
+
if (parentPort) {
|
|
12
|
+
parentPort.on("message", (data) => {
|
|
13
|
+
globalThis.onmessage({ data });
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Object.assign(globalThis, {
|
|
18
|
+
self: globalThis,
|
|
19
|
+
require,
|
|
20
|
+
Worker,
|
|
21
|
+
importScripts: function (f) {
|
|
22
|
+
;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
|
|
23
|
+
},
|
|
24
|
+
postMessage: function (msg) {
|
|
25
|
+
if (parentPort) {
|
|
26
|
+
parentPort.postMessage(msg);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const emnapiContext = getDefaultContext();
|
|
32
|
+
|
|
33
|
+
const __rootDir = parse(process.cwd()).root;
|
|
34
|
+
|
|
35
|
+
const handler = new MessageHandler({
|
|
36
|
+
onLoad({ wasmModule, wasmMemory }) {
|
|
37
|
+
const wasi = new WASI({
|
|
38
|
+
version: 'preview1',
|
|
39
|
+
env: process.env,
|
|
40
|
+
preopens: {
|
|
41
|
+
[__rootDir]: __rootDir,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return instantiateNapiModuleSync(wasmModule, {
|
|
46
|
+
childThread: true,
|
|
47
|
+
wasi,
|
|
48
|
+
context: emnapiContext,
|
|
49
|
+
overwriteImports(importObject) {
|
|
50
|
+
importObject.env = {
|
|
51
|
+
...importObject.env,
|
|
52
|
+
...importObject.napi,
|
|
53
|
+
...importObject.emnapi,
|
|
54
|
+
memory: wasmMemory
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
globalThis.onmessage = function (e) {
|
|
62
|
+
handler.handle(e);
|
|
63
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bennyblader/ddk-ts",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.43",
|
|
4
4
|
"description": "dlcdevkit typescript bindings",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"browser": "dist/browser.js",
|
|
7
8
|
"type": "module",
|
|
8
9
|
"repository": "https://github.com/bennyhodl/ddk-ffi",
|
|
9
10
|
"license": "MIT",
|
|
@@ -22,7 +23,8 @@
|
|
|
22
23
|
"packageName": "@bennyblader/ddk-ts",
|
|
23
24
|
"targets": [
|
|
24
25
|
"aarch64-apple-darwin",
|
|
25
|
-
"x86_64-unknown-linux-gnu"
|
|
26
|
+
"x86_64-unknown-linux-gnu",
|
|
27
|
+
"wasm32-wasip1-threads"
|
|
26
28
|
]
|
|
27
29
|
},
|
|
28
30
|
"engines": {
|
|
@@ -37,6 +39,7 @@
|
|
|
37
39
|
"build": "napi build --platform --release --js index.js --dts index.d.ts --output-dir dist",
|
|
38
40
|
"build:darwin-arm64": "napi build --platform --release --js index.js --dts index.d.ts --output-dir dist --target aarch64-apple-darwin",
|
|
39
41
|
"build:linux-x64": "napi build --platform --release --js index.js --dts index.d.ts --output-dir dist --target x86_64-unknown-linux-gnu",
|
|
42
|
+
"build:wasm": "napi build --platform --release --js index.js --dts index.d.ts --output-dir dist --target wasm32-wasip1-threads",
|
|
40
43
|
"build:debug": "napi build --platform --js index.js --dts index.d.ts --output-dir dist",
|
|
41
44
|
"build:all": "napi build --release --js index.js --dts index.d.ts --output-dir dist --target aarch64-apple-darwin --target x86_64-unknown-linux-gnu",
|
|
42
45
|
"prepublishOnly": "napi prepublish -t npm",
|
|
@@ -52,13 +55,15 @@
|
|
|
52
55
|
"version": "napi version"
|
|
53
56
|
},
|
|
54
57
|
"devDependencies": {
|
|
55
|
-
"@emnapi/core": "^1.
|
|
56
|
-
"@emnapi/runtime": "^1.
|
|
58
|
+
"@emnapi/core": "^1.11.2",
|
|
59
|
+
"@emnapi/runtime": "^1.11.2",
|
|
57
60
|
"@napi-rs/cli": "^3.0.3",
|
|
61
|
+
"@napi-rs/wasm-runtime": "^1.1.6",
|
|
58
62
|
"@tybys/wasm-util": "^0.10.0",
|
|
59
63
|
"@types/node": "^20.0.0",
|
|
60
64
|
"ava": "^6.4.1",
|
|
61
65
|
"chalk": "^5.4.1",
|
|
66
|
+
"emnapi": "^1.11.2",
|
|
62
67
|
"lint-staged": "^16.1.2",
|
|
63
68
|
"npm-run-all2": "^8.0.4",
|
|
64
69
|
"prettier": "^3.6.2",
|
|
@@ -79,7 +84,8 @@
|
|
|
79
84
|
],
|
|
80
85
|
"packageManager": "pnpm@10.14.0",
|
|
81
86
|
"optionalDependencies": {
|
|
82
|
-
"@bennyblader/ddk-ts-darwin-arm64": "0.3.
|
|
83
|
-
"@bennyblader/ddk-ts-linux-x64-gnu": "0.3.
|
|
87
|
+
"@bennyblader/ddk-ts-darwin-arm64": "0.3.43",
|
|
88
|
+
"@bennyblader/ddk-ts-linux-x64-gnu": "0.3.43",
|
|
89
|
+
"@bennyblader/ddk-ts-wasm32-wasi": "0.3.43"
|
|
84
90
|
}
|
|
85
91
|
}
|
|
Binary file
|