@rolldown/binding-wasm32-wasi 1.2.0 → 1.2.1
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 +8 -8
- package/rolldown-binding.wasi-browser.js +333 -40
- package/rolldown-binding.wasi.cjs +603 -58
- package/rolldown-binding.wasi.d.cts +3112 -0
- package/rolldown-binding.wasm32-wasi.wasm +0 -0
- package/wasi-worker-browser.mjs +13 -1
- package/wasi-worker.mjs +12 -1
package/package.json
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rolldown/binding-wasm32-wasi",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"cpu": [
|
|
5
|
-
"wasm32"
|
|
6
|
-
],
|
|
3
|
+
"version": "1.2.1",
|
|
7
4
|
"main": "rolldown-binding.wasi.cjs",
|
|
8
5
|
"files": [
|
|
9
6
|
"rolldown-binding.wasm32-wasi.wasm",
|
|
10
7
|
"rolldown-binding.wasi.cjs",
|
|
8
|
+
"rolldown-binding.wasi.d.cts",
|
|
11
9
|
"rolldown-binding.wasi-browser.js",
|
|
12
10
|
"wasi-worker.mjs",
|
|
13
11
|
"wasi-worker-browser.mjs"
|
|
@@ -24,7 +22,7 @@
|
|
|
24
22
|
"homepage": "https://rolldown.rs/",
|
|
25
23
|
"license": "MIT",
|
|
26
24
|
"engines": {
|
|
27
|
-
"node": "^20.19.0 ||
|
|
25
|
+
"node": "^20.19.0 || ^22.13.0 || >=23.5.0"
|
|
28
26
|
},
|
|
29
27
|
"repository": {
|
|
30
28
|
"type": "git",
|
|
@@ -35,10 +33,12 @@
|
|
|
35
33
|
"registry": "https://registry.npmjs.org/",
|
|
36
34
|
"access": "public"
|
|
37
35
|
},
|
|
36
|
+
"types": "rolldown-binding.wasi.d.cts",
|
|
38
37
|
"browser": "rolldown-binding.wasi-browser.js",
|
|
38
|
+
"type": "module",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@napi-rs/wasm-runtime": "^1.
|
|
41
|
-
"@emnapi/core": "
|
|
42
|
-
"@emnapi/runtime": "
|
|
40
|
+
"@napi-rs/wasm-runtime": "^1.2.0",
|
|
41
|
+
"@emnapi/core": "2.0.0-alpha.3",
|
|
42
|
+
"@emnapi/runtime": "2.0.0-alpha.3"
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
emnapiAsyncWorkPlugin as __emnapiAsyncWorkPlugin,
|
|
3
|
+
emnapiTSFNPlugin as __emnapiTSFNPlugin,
|
|
2
4
|
createOnMessage as __wasmCreateOnMessageForFsProxy,
|
|
3
|
-
getDefaultContext as __emnapiGetDefaultContext,
|
|
4
5
|
instantiateNapiModule as __emnapiInstantiateNapiModule,
|
|
5
6
|
WASI as __WASI,
|
|
6
7
|
} from '@napi-rs/wasm-runtime'
|
|
8
|
+
import { createContext as __emnapiCreateContext } from '@emnapi/runtime'
|
|
7
9
|
import { memfs } from '@napi-rs/wasm-runtime/fs'
|
|
8
10
|
|
|
9
11
|
|
|
@@ -18,8 +20,18 @@ const __wasi = new __WASI({
|
|
|
18
20
|
})
|
|
19
21
|
|
|
20
22
|
const __wasmUrl = new URL('./rolldown-binding.wasm32-wasi.wasm', import.meta.url).href
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
+
const __wasmResponse = await globalThis.fetch(__wasmUrl)
|
|
24
|
+
if (!__wasmResponse.ok) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
'Failed to fetch WASI module ' +
|
|
27
|
+
__wasmUrl +
|
|
28
|
+
': ' +
|
|
29
|
+
__wasmResponse.status +
|
|
30
|
+
' ' +
|
|
31
|
+
(__wasmResponse.statusText || 'Unknown Status'),
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
const __wasmFile = await __wasmResponse.arrayBuffer()
|
|
23
35
|
|
|
24
36
|
const __sharedMemory = new WebAssembly.Memory({
|
|
25
37
|
initial: 16384,
|
|
@@ -27,47 +39,328 @@ const __sharedMemory = new WebAssembly.Memory({
|
|
|
27
39
|
shared: true,
|
|
28
40
|
})
|
|
29
41
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
let __emnapiContext
|
|
43
|
+
|
|
44
|
+
const __wasiDisposeSymbol = Symbol.for('napi.rs.wasi.dispose')
|
|
45
|
+
const __wasiWorkers = new Set()
|
|
46
|
+
let __napiInstance
|
|
47
|
+
let __emnapiContextDestroyed = false
|
|
48
|
+
let __emnapiContextDestroyPromise
|
|
49
|
+
let __emnapiWasmEnvCleanupPrepared = false
|
|
50
|
+
let __wasiDisposed = false
|
|
51
|
+
let __wasiDisposePromise
|
|
52
|
+
let __completeWasiDisposal = function() {}
|
|
53
|
+
|
|
54
|
+
function __isThenable(value) {
|
|
55
|
+
return (
|
|
56
|
+
value !== null &&
|
|
57
|
+
(typeof value === 'object' || typeof value === 'function') &&
|
|
58
|
+
typeof value.then === 'function'
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function __createCleanupError(errors, message) {
|
|
63
|
+
if (errors.length === 1) {
|
|
64
|
+
return errors[0]
|
|
65
|
+
}
|
|
66
|
+
const __AggregateError = globalThis.AggregateError
|
|
67
|
+
if (typeof __AggregateError === 'function') {
|
|
68
|
+
return new __AggregateError(errors, message)
|
|
69
|
+
}
|
|
70
|
+
const error = new Error(message)
|
|
71
|
+
error.errors = errors
|
|
72
|
+
return error
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function __attachCleanupErrors(error, cleanupErrors) {
|
|
76
|
+
if (cleanupErrors.length === 0) {
|
|
77
|
+
return error
|
|
78
|
+
}
|
|
79
|
+
const cleanupError = __createCleanupError(
|
|
80
|
+
cleanupErrors,
|
|
81
|
+
'WASI binding cleanup failed',
|
|
82
|
+
)
|
|
83
|
+
try {
|
|
84
|
+
if (
|
|
85
|
+
error &&
|
|
86
|
+
(typeof error === 'object' || typeof error === 'function')
|
|
87
|
+
) {
|
|
88
|
+
if (error.cause === undefined) {
|
|
89
|
+
error.cause = cleanupError
|
|
90
|
+
if (error.cause === cleanupError) {
|
|
91
|
+
return error
|
|
92
|
+
}
|
|
49
93
|
}
|
|
50
|
-
|
|
94
|
+
if (Array.isArray(error.cleanupErrors)) {
|
|
95
|
+
error.cleanupErrors.push(cleanupError)
|
|
96
|
+
return error
|
|
97
|
+
} else {
|
|
98
|
+
const attachedCleanupErrors = [cleanupError]
|
|
99
|
+
error.cleanupErrors = attachedCleanupErrors
|
|
100
|
+
if (error.cleanupErrors === attachedCleanupErrors) {
|
|
101
|
+
return error
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} catch {}
|
|
106
|
+
const aggregate = __createCleanupError(
|
|
107
|
+
[error, cleanupError],
|
|
108
|
+
'WASI binding initialization and cleanup failed',
|
|
109
|
+
)
|
|
110
|
+
try {
|
|
111
|
+
aggregate.cause = error
|
|
112
|
+
} catch {}
|
|
113
|
+
return aggregate
|
|
114
|
+
}
|
|
51
115
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
116
|
+
function __prepareWasmEnvCleanup() {
|
|
117
|
+
if (__emnapiWasmEnvCleanupPrepared) {
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
const prepare = __napiInstance?.exports?.napi_prepare_wasm_env_cleanup
|
|
121
|
+
if (typeof prepare === 'function') {
|
|
122
|
+
prepare()
|
|
123
|
+
}
|
|
124
|
+
__emnapiWasmEnvCleanupPrepared = true
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function __destroyEmnapiContext() {
|
|
128
|
+
if (__emnapiContextDestroyed || __emnapiContext === undefined) {
|
|
129
|
+
__emnapiContextDestroyed = true
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
if (__emnapiContextDestroyPromise) {
|
|
133
|
+
return __emnapiContextDestroyPromise
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
__prepareWasmEnvCleanup()
|
|
137
|
+
const result = __emnapiContext.destroy()
|
|
138
|
+
if (!__isThenable(result)) {
|
|
139
|
+
__emnapiContextDestroyed = true
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const destroyPromise = Promise.resolve(result).then(
|
|
144
|
+
(value) => {
|
|
145
|
+
__emnapiContextDestroyed = true
|
|
146
|
+
return value
|
|
147
|
+
},
|
|
148
|
+
(error) => {
|
|
149
|
+
__emnapiContextDestroyPromise = undefined
|
|
150
|
+
throw error
|
|
151
|
+
},
|
|
152
|
+
)
|
|
153
|
+
__emnapiContextDestroyPromise = destroyPromise
|
|
154
|
+
return destroyPromise
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function __terminateWasiWorkers() {
|
|
158
|
+
const cleanupErrors = []
|
|
159
|
+
const pending = []
|
|
160
|
+
|
|
161
|
+
for (const worker of __wasiWorkers) {
|
|
162
|
+
let result
|
|
163
|
+
try {
|
|
164
|
+
result = worker.terminate()
|
|
165
|
+
} catch (error) {
|
|
166
|
+
cleanupErrors.push(error)
|
|
167
|
+
continue
|
|
60
168
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
169
|
+
if (__isThenable(result)) {
|
|
170
|
+
pending.push(
|
|
171
|
+
Promise.resolve(result).then(
|
|
172
|
+
() => {
|
|
173
|
+
__wasiWorkers.delete(worker)
|
|
174
|
+
},
|
|
175
|
+
(error) => {
|
|
176
|
+
cleanupErrors.push(error)
|
|
177
|
+
},
|
|
178
|
+
),
|
|
179
|
+
)
|
|
180
|
+
} else {
|
|
181
|
+
__wasiWorkers.delete(worker)
|
|
68
182
|
}
|
|
69
|
-
}
|
|
70
|
-
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const finish = () => {
|
|
186
|
+
if (cleanupErrors.length > 0) {
|
|
187
|
+
throw __createCleanupError(
|
|
188
|
+
cleanupErrors,
|
|
189
|
+
'Failed to terminate WASI workers',
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return pending.length > 0 ? Promise.all(pending).then(finish) : finish()
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function __finishWasiDisposal() {
|
|
197
|
+
const workerResult = __terminateWasiWorkers()
|
|
198
|
+
if (__isThenable(workerResult)) {
|
|
199
|
+
return Promise.resolve(workerResult).then(__completeWasiDisposal)
|
|
200
|
+
}
|
|
201
|
+
return __completeWasiDisposal()
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function __startWasiDisposal() {
|
|
205
|
+
const destroyResult = __destroyEmnapiContext()
|
|
206
|
+
if (__isThenable(destroyResult)) {
|
|
207
|
+
return Promise.resolve(destroyResult).then(__finishWasiDisposal)
|
|
208
|
+
}
|
|
209
|
+
return __finishWasiDisposal()
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Disposes this generated WASI binding.
|
|
214
|
+
*
|
|
215
|
+
* Access this function with:
|
|
216
|
+
* binding[Symbol.for('napi.rs.wasi.dispose')]()
|
|
217
|
+
*/
|
|
218
|
+
function __disposeWasiBinding() {
|
|
219
|
+
if (__wasiDisposePromise) {
|
|
220
|
+
return __wasiDisposePromise
|
|
221
|
+
}
|
|
222
|
+
if (__wasiDisposed) {
|
|
223
|
+
return Promise.resolve()
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let resolveDispose
|
|
227
|
+
let rejectDispose
|
|
228
|
+
const disposePromise = new Promise((resolve, reject) => {
|
|
229
|
+
resolveDispose = resolve
|
|
230
|
+
rejectDispose = reject
|
|
231
|
+
})
|
|
232
|
+
__wasiDisposePromise = disposePromise
|
|
233
|
+
|
|
234
|
+
let result
|
|
235
|
+
try {
|
|
236
|
+
result = __startWasiDisposal()
|
|
237
|
+
} catch (error) {
|
|
238
|
+
__wasiDisposePromise = undefined
|
|
239
|
+
rejectDispose(error)
|
|
240
|
+
return disposePromise
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
Promise.resolve(result).then(
|
|
244
|
+
(value) => {
|
|
245
|
+
__wasiDisposed = true
|
|
246
|
+
resolveDispose(value)
|
|
247
|
+
},
|
|
248
|
+
(error) => {
|
|
249
|
+
__wasiDisposePromise = undefined
|
|
250
|
+
rejectDispose(error)
|
|
251
|
+
},
|
|
252
|
+
)
|
|
253
|
+
return disposePromise
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function __publishWasiDispose(exports) {
|
|
257
|
+
Object.defineProperty(exports, __wasiDisposeSymbol, {
|
|
258
|
+
configurable: false,
|
|
259
|
+
enumerable: false,
|
|
260
|
+
value: __disposeWasiBinding,
|
|
261
|
+
writable: false,
|
|
262
|
+
})
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function __finishWasiInitializationRollback(cleanupErrors) {
|
|
266
|
+
let workerResult
|
|
267
|
+
try {
|
|
268
|
+
workerResult = __terminateWasiWorkers()
|
|
269
|
+
} catch (cleanupError) {
|
|
270
|
+
cleanupErrors.push(cleanupError)
|
|
271
|
+
return cleanupErrors
|
|
272
|
+
}
|
|
273
|
+
if (__isThenable(workerResult)) {
|
|
274
|
+
return Promise.resolve(workerResult)
|
|
275
|
+
.catch((cleanupError) => {
|
|
276
|
+
cleanupErrors.push(cleanupError)
|
|
277
|
+
})
|
|
278
|
+
.then(() => cleanupErrors)
|
|
279
|
+
}
|
|
280
|
+
return cleanupErrors
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function __rollbackWasiInitialization() {
|
|
284
|
+
const cleanupErrors = []
|
|
285
|
+
let destroyResult
|
|
286
|
+
try {
|
|
287
|
+
destroyResult = __destroyEmnapiContext()
|
|
288
|
+
} catch (cleanupError) {
|
|
289
|
+
cleanupErrors.push(cleanupError)
|
|
290
|
+
return __finishWasiInitializationRollback(cleanupErrors)
|
|
291
|
+
}
|
|
292
|
+
if (__isThenable(destroyResult)) {
|
|
293
|
+
return Promise.resolve(destroyResult)
|
|
294
|
+
.catch((cleanupError) => {
|
|
295
|
+
cleanupErrors.push(cleanupError)
|
|
296
|
+
})
|
|
297
|
+
.then(() => __finishWasiInitializationRollback(cleanupErrors))
|
|
298
|
+
}
|
|
299
|
+
return __finishWasiInitializationRollback(cleanupErrors)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
let __wasiModule
|
|
303
|
+
let __napiModule
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
__emnapiContext = __emnapiCreateContext({ autoDestroy: false })
|
|
307
|
+
__emnapiContext.suppressDestroy()
|
|
308
|
+
|
|
309
|
+
;({
|
|
310
|
+
instance: __napiInstance,
|
|
311
|
+
module: __wasiModule,
|
|
312
|
+
napiModule: __napiModule,
|
|
313
|
+
} = await __emnapiInstantiateNapiModule(__wasmFile, {
|
|
314
|
+
context: __emnapiContext,
|
|
315
|
+
asyncWorkPoolSize: 4,
|
|
316
|
+
plugins: [__emnapiAsyncWorkPlugin, __emnapiTSFNPlugin],
|
|
317
|
+
wasi: __wasi,
|
|
318
|
+
onCreateWorker() {
|
|
319
|
+
const worker = new Worker(new URL('@rolldown/binding-wasm32-wasi/wasi-worker-browser.mjs', import.meta.url), {
|
|
320
|
+
type: 'module',
|
|
321
|
+
})
|
|
322
|
+
__wasiWorkers.add(worker)
|
|
323
|
+
worker.addEventListener('message', __wasmCreateOnMessageForFsProxy(__fs))
|
|
324
|
+
|
|
325
|
+
worker.addEventListener('message', (event) => {
|
|
326
|
+
if (event.data && typeof event.data === 'object' && event.data.type === 'error') {
|
|
327
|
+
const __CustomEvent = globalThis.CustomEvent
|
|
328
|
+
if (
|
|
329
|
+
typeof globalThis.dispatchEvent === 'function' &&
|
|
330
|
+
typeof __CustomEvent === 'function'
|
|
331
|
+
) {
|
|
332
|
+
globalThis.dispatchEvent(
|
|
333
|
+
new __CustomEvent('napi-rs-worker-error', { detail: event.data }),
|
|
334
|
+
)
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
return worker
|
|
340
|
+
},
|
|
341
|
+
overwriteImports(importObject) {
|
|
342
|
+
importObject.env = {
|
|
343
|
+
...importObject.env,
|
|
344
|
+
...importObject.napi,
|
|
345
|
+
...importObject.emnapi,
|
|
346
|
+
memory: __sharedMemory,
|
|
347
|
+
}
|
|
348
|
+
return importObject
|
|
349
|
+
},
|
|
350
|
+
beforeInit({ instance }) {
|
|
351
|
+
__napiInstance = instance
|
|
352
|
+
for (const name of Object.keys(instance.exports)) {
|
|
353
|
+
if (name.startsWith('__napi_register__')) {
|
|
354
|
+
instance.exports[name]()
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
}))
|
|
359
|
+
__publishWasiDispose(__napiModule.exports)
|
|
360
|
+
} catch (error) {
|
|
361
|
+
const cleanupErrors = await __rollbackWasiInitialization()
|
|
362
|
+
throw __attachCleanupErrors(error, cleanupErrors)
|
|
363
|
+
}
|
|
71
364
|
export default __napiModule.exports
|
|
72
365
|
export const LegalCommentsMode = __napiModule.exports.LegalCommentsMode
|
|
73
366
|
export const minify = __napiModule.exports.minify
|