@rrule-rust/lib-wasm32-wasi 2.1.0-alpha.5 → 3.0.0-alpha.2
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/package.json
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rrule-rust/lib-wasm32-wasi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.2",
|
|
4
|
+
"cpu": [
|
|
5
|
+
"wasm32"
|
|
6
|
+
],
|
|
4
7
|
"main": "rrule-rust.wasi.cjs",
|
|
5
8
|
"files": [
|
|
6
9
|
"rrule-rust.wasm32-wasi.wasm",
|
|
7
10
|
"rrule-rust.wasi.cjs",
|
|
8
11
|
"rrule-rust.wasi-browser.js",
|
|
9
12
|
"wasi-worker.mjs",
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
"wasi-worker-browser.mjs"
|
|
14
|
+
],
|
|
15
|
+
"description": "RRule implementation for Node.js written in Rust",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"rrule",
|
|
18
|
+
"icalendar",
|
|
19
|
+
"rust",
|
|
20
|
+
"rs"
|
|
13
21
|
],
|
|
14
22
|
"author": {
|
|
15
23
|
"name": "lsndr",
|
|
16
|
-
"email": "alexander@lsndr.
|
|
17
|
-
"url": "https://lsndr.
|
|
24
|
+
"email": "alexander@lsndr.me",
|
|
25
|
+
"url": "https://lsndr.me"
|
|
18
26
|
},
|
|
19
27
|
"license": "MIT",
|
|
20
28
|
"engines": {
|
|
@@ -23,13 +31,9 @@
|
|
|
23
31
|
"repository": "lsndr/rrule-rust",
|
|
24
32
|
"browser": "rrule-rust.wasi-browser.js",
|
|
25
33
|
"dependencies": {
|
|
26
|
-
"@napi-rs/wasm-runtime": "
|
|
27
|
-
"patch-package": "^8.0.0"
|
|
34
|
+
"@napi-rs/wasm-runtime": "^1.0.3"
|
|
28
35
|
},
|
|
29
36
|
"publishConfig": {
|
|
30
37
|
"access": "public"
|
|
31
|
-
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"postinstall": "patch-package"
|
|
34
38
|
}
|
|
35
39
|
}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createOnMessage as __wasmCreateOnMessageForFsProxy,
|
|
3
3
|
getDefaultContext as __emnapiGetDefaultContext,
|
|
4
|
+
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
|
|
4
5
|
WASI as __WASI,
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
} from '@napi-rs/wasm-runtime'
|
|
7
|
+
|
|
7
8
|
|
|
8
|
-
import __wasmUrl from './rrule-rust.wasm32-wasi.wasm?url'
|
|
9
9
|
|
|
10
10
|
const __wasi = new __WASI({
|
|
11
11
|
version: 'preview1',
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
+
const __wasmUrl = new URL('./rrule-rust.wasm32-wasi.wasm', import.meta.url).href
|
|
14
15
|
const __emnapiContext = __emnapiGetDefaultContext()
|
|
15
16
|
|
|
17
|
+
|
|
16
18
|
const __sharedMemory = new WebAssembly.Memory({
|
|
17
19
|
initial: 4000,
|
|
18
20
|
maximum: 65536,
|
|
@@ -46,22 +48,14 @@ const {
|
|
|
46
48
|
return importObject
|
|
47
49
|
},
|
|
48
50
|
beforeInit({ instance }) {
|
|
49
|
-
|
|
51
|
+
for (const name of Object.keys(instance.exports)) {
|
|
52
|
+
if (name.startsWith('__napi_register__')) {
|
|
53
|
+
instance.exports[name]()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
50
56
|
},
|
|
51
57
|
})
|
|
52
|
-
|
|
53
|
-
function __napi_rs_initialize_modules(__napiInstance) {
|
|
54
|
-
__napiInstance.exports['__napi_register__Frequency_0']?.()
|
|
55
|
-
__napiInstance.exports['__napi_register__Month_1']?.()
|
|
56
|
-
__napiInstance.exports['__napi_register__NWeekday_struct_2']?.()
|
|
57
|
-
__napiInstance.exports['__napi_register__RRule_struct_3']?.()
|
|
58
|
-
__napiInstance.exports['__napi_register__RRule_impl_21']?.()
|
|
59
|
-
__napiInstance.exports['__napi_register__RRuleSet_struct_22']?.()
|
|
60
|
-
__napiInstance.exports['__napi_register__RRuleSet_impl_36']?.()
|
|
61
|
-
__napiInstance.exports['__napi_register__RRuleSetIterator_struct_37']?.()
|
|
62
|
-
__napiInstance.exports['__napi_register__RRuleSetIterator_impl_39']?.()
|
|
63
|
-
__napiInstance.exports['__napi_register__Weekday_40']?.()
|
|
64
|
-
}
|
|
58
|
+
export default __napiModule.exports
|
|
65
59
|
export const RRule = __napiModule.exports.RRule
|
|
66
60
|
export const RRuleSet = __napiModule.exports.RRuleSet
|
|
67
61
|
export const RRuleSetIterator = __napiModule.exports.RRuleSetIterator
|
package/rrule-rust.wasi.cjs
CHANGED
|
@@ -9,10 +9,10 @@ const { WASI: __nodeWASI } = require('node:wasi')
|
|
|
9
9
|
const { Worker } = require('node:worker_threads')
|
|
10
10
|
|
|
11
11
|
const {
|
|
12
|
-
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
13
|
-
getDefaultContext: __emnapiGetDefaultContext,
|
|
14
12
|
createOnMessage: __wasmCreateOnMessageForFsProxy,
|
|
15
|
-
|
|
13
|
+
getDefaultContext: __emnapiGetDefaultContext,
|
|
14
|
+
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
15
|
+
} = require('@napi-rs/wasm-runtime')
|
|
16
16
|
|
|
17
17
|
const __rootDir = __nodePath.parse(process.cwd()).root
|
|
18
18
|
|
|
@@ -56,15 +56,38 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
|
|
|
56
56
|
return 4
|
|
57
57
|
}
|
|
58
58
|
})(),
|
|
59
|
+
reuseWorker: true,
|
|
59
60
|
wasi: __wasi,
|
|
60
61
|
onCreateWorker() {
|
|
61
62
|
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
|
|
62
63
|
env: process.env,
|
|
63
|
-
execArgv: ['--experimental-wasi-unstable-preview1'],
|
|
64
64
|
})
|
|
65
65
|
worker.onmessage = ({ data }) => {
|
|
66
66
|
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
|
|
67
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
|
+
}
|
|
68
91
|
return worker
|
|
69
92
|
},
|
|
70
93
|
overwriteImports(importObject) {
|
|
@@ -77,22 +100,14 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
|
|
|
77
100
|
return importObject
|
|
78
101
|
},
|
|
79
102
|
beforeInit({ instance }) {
|
|
80
|
-
|
|
81
|
-
|
|
103
|
+
for (const name of Object.keys(instance.exports)) {
|
|
104
|
+
if (name.startsWith('__napi_register__')) {
|
|
105
|
+
instance.exports[name]()
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
82
109
|
})
|
|
83
|
-
|
|
84
|
-
function __napi_rs_initialize_modules(__napiInstance) {
|
|
85
|
-
__napiInstance.exports['__napi_register__Frequency_0']?.()
|
|
86
|
-
__napiInstance.exports['__napi_register__Month_1']?.()
|
|
87
|
-
__napiInstance.exports['__napi_register__NWeekday_struct_2']?.()
|
|
88
|
-
__napiInstance.exports['__napi_register__RRule_struct_3']?.()
|
|
89
|
-
__napiInstance.exports['__napi_register__RRule_impl_21']?.()
|
|
90
|
-
__napiInstance.exports['__napi_register__RRuleSet_struct_22']?.()
|
|
91
|
-
__napiInstance.exports['__napi_register__RRuleSet_impl_36']?.()
|
|
92
|
-
__napiInstance.exports['__napi_register__RRuleSetIterator_struct_37']?.()
|
|
93
|
-
__napiInstance.exports['__napi_register__RRuleSetIterator_impl_39']?.()
|
|
94
|
-
__napiInstance.exports['__napi_register__Weekday_40']?.()
|
|
95
|
-
}
|
|
110
|
+
module.exports = __napiModule.exports
|
|
96
111
|
module.exports.RRule = __napiModule.exports.RRule
|
|
97
112
|
module.exports.RRuleSet = __napiModule.exports.RRuleSet
|
|
98
113
|
module.exports.RRuleSetIterator = __napiModule.exports.RRuleSetIterator
|
|
Binary file
|
package/wasi-worker-browser.mjs
CHANGED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
diff --git a/node_modules/@napi-rs/wasm-runtime/dist/runtime.js b/node_modules/@napi-rs/wasm-runtime/dist/runtime.js
|
|
2
|
-
index e06c158..a23882c 100644
|
|
3
|
-
--- a/node_modules/@napi-rs/wasm-runtime/dist/runtime.js
|
|
4
|
-
+++ b/node_modules/@napi-rs/wasm-runtime/dist/runtime.js
|
|
5
|
-
@@ -2532,7 +2532,22 @@ function createNapiModule(options) {
|
|
6
|
-
}
|
|
7
|
-
return str;
|
|
8
|
-
}
|
|
9
|
-
- return emnapiString.utf8Decoder.decode(((typeof SharedArrayBuffer === "function" && HEAPU8.buffer instanceof SharedArrayBuffer) || (Object.prototype.toString.call(HEAPU8.buffer.constructor) === "[object SharedArrayBuffer]")) ? HEAPU8.slice(ptr, end) : HEAPU8.subarray(ptr, end));
|
|
10
|
-
+ var decodeFromSharedBuffer = (sharedBuffer) => {
|
|
11
|
-
+ const decoder = new TextDecoder()
|
|
12
|
-
+ const copyLength = sharedBuffer.byteLength
|
|
13
|
-
+
|
|
14
|
-
+ const tempBuffer = new ArrayBuffer(copyLength)
|
|
15
|
-
+ const tempView = new Uint8Array(tempBuffer)
|
|
16
|
-
+
|
|
17
|
-
+ let sharedView = new Uint8Array(sharedBuffer)
|
|
18
|
-
+ if (sharedBuffer.byteLength != copyLength) {
|
|
19
|
-
+ sharedView = sharedView.subarray(0, copyLength)
|
|
20
|
-
+ }
|
|
21
|
-
+ tempView.set(sharedView)
|
|
22
|
-
+
|
|
23
|
-
+ return decoder.decode(tempBuffer)
|
|
24
|
-
+ }
|
|
25
|
-
+ return decodeFromSharedBuffer(((typeof SharedArrayBuffer === "function" && HEAPU8.buffer instanceof SharedArrayBuffer) || (Object.prototype.toString.call(HEAPU8.buffer.constructor) === "[object SharedArrayBuffer]")) ? HEAPU8.slice(ptr, end) : HEAPU8.subarray(ptr, end));
|
|
26
|
-
},
|
|
27
|
-
stringToUTF8: function (str, outPtr, maxBytesToWrite) {
|
|
28
|
-
var HEAPU8 = new Uint8Array(wasmMemory.buffer);
|