@rolldown/binding-wasm32-wasi 1.2.0 → 1.2.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 +8 -8
- package/rolldown-binding.wasi-browser.js +333 -40
- package/rolldown-binding.wasi.cjs +603 -58
- package/rolldown-binding.wasi.d.cts +3141 -0
- package/rolldown-binding.wasm32-wasi.wasm +0 -0
- package/wasi-worker-browser.mjs +13 -1
- package/wasi-worker.mjs +12 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// napi-rs-artifact-metadata:{"version":2,"rootEntry":"binding.cjs","exports":["LegalCommentsMode","minify","minifySync","Severity","ParseResult","ExportExportNameKind","ExportImportNameKind","ExportLocalNameKind","ImportNameKind","parse","parseSync","rawTransferSupported","ResolverFactory","EnforceExtension","ModuleType","sync","HelperMode","isolatedDeclaration","isolatedDeclarationSync","moduleRunnerTransform","moduleRunnerTransformSync","transform","transformSync","BindingBundleEndEventData","BindingBundleErrorEventData","BindingBundler","BindingCallableBuiltinPlugin","BindingChunkingContext","BindingDecodedMap","BindingDevEngine","BindingLoadPluginContext","BindingMagicString","BindingModuleInfo","BindingNormalizedOptions","BindingOutputAsset","BindingOutputChunk","BindingPluginContext","BindingRenderedChunk","BindingRenderedChunkMeta","BindingRenderedModule","BindingSourceMap","BindingTransformPluginContext","BindingWatcher","BindingWatcherBundler","BindingWatcherChangeData","BindingWatcherEvent","ParallelJsPluginRegistry","TraceSubscriberGuard","TsconfigCache","BindingAttachDebugInfo","BindingBuiltinPluginName","BindingChunkModuleOrderBy","BindingErrorStage","BindingLogLevel","BindingPluginOrder","BindingPropertyReadSideEffects","BindingPropertyWriteSideEffects","BindingRebuildStrategy","collapseSourcemaps","enhancedTransform","enhancedTransformSync","FilterTokenKind","initTraceSubscriber","registerPlugins","resolveTsconfig","shutdownAsyncRuntime","startAsyncRuntime"],"managedRootEntries":["browser.js","binding.cjs","rolldown-binding.wasm","rolldown-binding.debug.wasm"]}
|
|
1
2
|
/* eslint-disable */
|
|
2
3
|
/* prettier-ignore */
|
|
3
4
|
|
|
@@ -9,10 +10,101 @@ const { WASI: __nodeWASI } = require('node:wasi')
|
|
|
9
10
|
const { Worker } = require('node:worker_threads')
|
|
10
11
|
|
|
11
12
|
const {
|
|
13
|
+
emnapiAsyncWorkPlugin: __emnapiAsyncWorkPlugin,
|
|
14
|
+
emnapiTSFNPlugin: __emnapiTSFNPlugin,
|
|
12
15
|
createOnMessage: __wasmCreateOnMessageForFsProxy,
|
|
13
|
-
getDefaultContext: __emnapiGetDefaultContext,
|
|
14
16
|
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
15
17
|
} = require('@napi-rs/wasm-runtime')
|
|
18
|
+
const { createContext: __emnapiCreateContext } = require('@emnapi/runtime')
|
|
19
|
+
|
|
20
|
+
function __getWasiWorkerExecArgv() {
|
|
21
|
+
const __workerExecArgv = []
|
|
22
|
+
for (let __index = 0; __index < process.execArgv.length; __index += 1) {
|
|
23
|
+
const __arg = process.execArgv[__index]
|
|
24
|
+
if (
|
|
25
|
+
__arg === '--input-type' ||
|
|
26
|
+
__arg === '--eval' ||
|
|
27
|
+
__arg === '-e' ||
|
|
28
|
+
__arg === '--print' ||
|
|
29
|
+
__arg === '-p'
|
|
30
|
+
) {
|
|
31
|
+
__index += 1
|
|
32
|
+
continue
|
|
33
|
+
}
|
|
34
|
+
if (
|
|
35
|
+
__arg.startsWith('--input-type=') ||
|
|
36
|
+
__arg.startsWith('--eval=') ||
|
|
37
|
+
__arg.startsWith('--print=')
|
|
38
|
+
) {
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
__workerExecArgv.push(__arg)
|
|
42
|
+
}
|
|
43
|
+
return __workerExecArgv
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function __isInvalidWasiWorkerExecArgv(errorMessage, argument) {
|
|
47
|
+
const __equalsIndex = argument.indexOf('=')
|
|
48
|
+
const __argumentName =
|
|
49
|
+
__equalsIndex === -1 ? argument : argument.slice(0, __equalsIndex)
|
|
50
|
+
return (
|
|
51
|
+
errorMessage.includes(': ' + __argumentName + ',') ||
|
|
52
|
+
errorMessage.includes(': ' + __argumentName + '=') ||
|
|
53
|
+
errorMessage.endsWith(': ' + __argumentName) ||
|
|
54
|
+
errorMessage.includes(', ' + __argumentName + ',') ||
|
|
55
|
+
errorMessage.includes(', ' + __argumentName + '=') ||
|
|
56
|
+
errorMessage.endsWith(', ' + __argumentName)
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function __removeInvalidWasiWorkerExecArgv(execArgv, error) {
|
|
61
|
+
if (typeof error.message !== 'string') {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
const __workerExecArgv = []
|
|
65
|
+
let __removed = false
|
|
66
|
+
for (let __index = 0; __index < execArgv.length; __index += 1) {
|
|
67
|
+
const __arg = execArgv[__index]
|
|
68
|
+
if (
|
|
69
|
+
__arg.startsWith('-') &&
|
|
70
|
+
__isInvalidWasiWorkerExecArgv(error.message, __arg)
|
|
71
|
+
) {
|
|
72
|
+
__removed = true
|
|
73
|
+
if (
|
|
74
|
+
!__arg.includes('=') &&
|
|
75
|
+
__index + 1 < execArgv.length &&
|
|
76
|
+
!execArgv[__index + 1].startsWith('-')
|
|
77
|
+
) {
|
|
78
|
+
__index += 1
|
|
79
|
+
}
|
|
80
|
+
continue
|
|
81
|
+
}
|
|
82
|
+
__workerExecArgv.push(__arg)
|
|
83
|
+
}
|
|
84
|
+
return __removed ? __workerExecArgv : undefined
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function __createWasiWorker(filename) {
|
|
88
|
+
let __workerExecArgv = __getWasiWorkerExecArgv()
|
|
89
|
+
while (true) {
|
|
90
|
+
try {
|
|
91
|
+
return new Worker(filename, {
|
|
92
|
+
env: process.env,
|
|
93
|
+
execArgv: __workerExecArgv,
|
|
94
|
+
})
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (!error || error.code !== 'ERR_WORKER_INVALID_EXEC_ARGV') {
|
|
97
|
+
throw error
|
|
98
|
+
}
|
|
99
|
+
const __nextWorkerExecArgv =
|
|
100
|
+
__removeInvalidWasiWorkerExecArgv(__workerExecArgv, error)
|
|
101
|
+
if (!__nextWorkerExecArgv) {
|
|
102
|
+
throw error
|
|
103
|
+
}
|
|
104
|
+
__workerExecArgv = __nextWorkerExecArgv
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
16
108
|
|
|
17
109
|
const __rootDir = __nodePath.parse(process.cwd()).root
|
|
18
110
|
|
|
@@ -24,8 +116,6 @@ const __wasi = new __nodeWASI({
|
|
|
24
116
|
}
|
|
25
117
|
})
|
|
26
118
|
|
|
27
|
-
const __emnapiContext = __emnapiGetDefaultContext()
|
|
28
|
-
|
|
29
119
|
const __sharedMemory = new WebAssembly.Memory({
|
|
30
120
|
initial: 16384,
|
|
31
121
|
maximum: 65536,
|
|
@@ -38,75 +128,530 @@ const __wasmDebugFilePath = __nodePath.join(__dirname, 'rolldown-binding.wasm32-
|
|
|
38
128
|
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
|
|
39
129
|
__wasmFilePath = __wasmDebugFilePath
|
|
40
130
|
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
|
|
131
|
+
const __wasiPackageEntry = require.resolve('@rolldown/binding-wasm32-wasi')
|
|
132
|
+
const __packagedWasmFilePath = __nodePath.join(
|
|
133
|
+
__nodePath.dirname(__wasiPackageEntry),
|
|
134
|
+
'rolldown-binding.wasm32-wasi.wasm',
|
|
135
|
+
)
|
|
136
|
+
if (!__nodeFs.existsSync(__packagedWasmFilePath)) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
'@rolldown/binding-wasm32-wasi is installed but is missing rolldown-binding.wasm32-wasi.wasm.',
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
__wasmFilePath = __packagedWasmFilePath
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const __wasmFile = __nodeFs.readFileSync(__wasmFilePath)
|
|
145
|
+
let __emnapiContext
|
|
146
|
+
|
|
147
|
+
const __wasiDisposeSymbol = Symbol.for('napi.rs.wasi.dispose')
|
|
148
|
+
const __wasiWorkers = new Set()
|
|
149
|
+
let __napiInstance
|
|
150
|
+
let __emnapiContextDestroyed = false
|
|
151
|
+
let __emnapiContextDestroyPromise
|
|
152
|
+
let __emnapiWasmEnvCleanupPrepared = false
|
|
153
|
+
let __wasiDisposed = false
|
|
154
|
+
let __wasiDisposePromise
|
|
155
|
+
let __completeWasiDisposal = function() {}
|
|
156
|
+
|
|
157
|
+
function __isThenable(value) {
|
|
158
|
+
return (
|
|
159
|
+
value !== null &&
|
|
160
|
+
(typeof value === 'object' || typeof value === 'function') &&
|
|
161
|
+
typeof value.then === 'function'
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function __createCleanupError(errors, message) {
|
|
166
|
+
if (errors.length === 1) {
|
|
167
|
+
return errors[0]
|
|
168
|
+
}
|
|
169
|
+
const __AggregateError = globalThis.AggregateError
|
|
170
|
+
if (typeof __AggregateError === 'function') {
|
|
171
|
+
return new __AggregateError(errors, message)
|
|
172
|
+
}
|
|
173
|
+
const error = new Error(message)
|
|
174
|
+
error.errors = errors
|
|
175
|
+
return error
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function __attachCleanupErrors(error, cleanupErrors) {
|
|
179
|
+
if (cleanupErrors.length === 0) {
|
|
180
|
+
return error
|
|
181
|
+
}
|
|
182
|
+
const cleanupError = __createCleanupError(
|
|
183
|
+
cleanupErrors,
|
|
184
|
+
'WASI binding cleanup failed',
|
|
185
|
+
)
|
|
41
186
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
187
|
+
if (
|
|
188
|
+
error &&
|
|
189
|
+
(typeof error === 'object' || typeof error === 'function')
|
|
190
|
+
) {
|
|
191
|
+
if (error.cause === undefined) {
|
|
192
|
+
error.cause = cleanupError
|
|
193
|
+
if (error.cause === cleanupError) {
|
|
194
|
+
return error
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (Array.isArray(error.cleanupErrors)) {
|
|
198
|
+
error.cleanupErrors.push(cleanupError)
|
|
199
|
+
return error
|
|
200
|
+
} else {
|
|
201
|
+
const attachedCleanupErrors = [cleanupError]
|
|
202
|
+
error.cleanupErrors = attachedCleanupErrors
|
|
203
|
+
if (error.cleanupErrors === attachedCleanupErrors) {
|
|
204
|
+
return error
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
} catch {}
|
|
209
|
+
const aggregate = __createCleanupError(
|
|
210
|
+
[error, cleanupError],
|
|
211
|
+
'WASI binding initialization and cleanup failed',
|
|
212
|
+
)
|
|
213
|
+
try {
|
|
214
|
+
aggregate.cause = error
|
|
215
|
+
} catch {}
|
|
216
|
+
return aggregate
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function __prepareWasmEnvCleanup() {
|
|
220
|
+
if (__emnapiWasmEnvCleanupPrepared) {
|
|
221
|
+
return
|
|
45
222
|
}
|
|
223
|
+
const prepare = __napiInstance?.exports?.napi_prepare_wasm_env_cleanup
|
|
224
|
+
if (typeof prepare === 'function') {
|
|
225
|
+
prepare()
|
|
226
|
+
}
|
|
227
|
+
__emnapiWasmEnvCleanupPrepared = true
|
|
46
228
|
}
|
|
47
229
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
230
|
+
function __destroyEmnapiContext() {
|
|
231
|
+
if (__emnapiContextDestroyed || __emnapiContext === undefined) {
|
|
232
|
+
__emnapiContextDestroyed = true
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
if (__emnapiContextDestroyPromise) {
|
|
236
|
+
return __emnapiContextDestroyPromise
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
__prepareWasmEnvCleanup()
|
|
240
|
+
const result = __emnapiContext.destroy()
|
|
241
|
+
if (!__isThenable(result)) {
|
|
242
|
+
__emnapiContextDestroyed = true
|
|
243
|
+
return
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const destroyPromise = Promise.resolve(result).then(
|
|
247
|
+
(value) => {
|
|
248
|
+
__emnapiContextDestroyed = true
|
|
249
|
+
return value
|
|
250
|
+
},
|
|
251
|
+
(error) => {
|
|
252
|
+
__emnapiContextDestroyPromise = undefined
|
|
253
|
+
throw error
|
|
254
|
+
},
|
|
255
|
+
)
|
|
256
|
+
__emnapiContextDestroyPromise = destroyPromise
|
|
257
|
+
return destroyPromise
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function __terminateWasiWorkers() {
|
|
261
|
+
const cleanupErrors = []
|
|
262
|
+
const pending = []
|
|
263
|
+
|
|
264
|
+
for (const worker of __wasiWorkers) {
|
|
265
|
+
let result
|
|
266
|
+
try {
|
|
267
|
+
result = worker.terminate()
|
|
268
|
+
} catch (error) {
|
|
269
|
+
cleanupErrors.push(error)
|
|
270
|
+
continue
|
|
271
|
+
}
|
|
272
|
+
if (__isThenable(result)) {
|
|
273
|
+
pending.push(
|
|
274
|
+
Promise.resolve(result).then(
|
|
275
|
+
() => {
|
|
276
|
+
__wasiWorkers.delete(worker)
|
|
277
|
+
},
|
|
278
|
+
(error) => {
|
|
279
|
+
cleanupErrors.push(error)
|
|
280
|
+
},
|
|
281
|
+
),
|
|
282
|
+
)
|
|
55
283
|
} else {
|
|
56
|
-
|
|
284
|
+
__wasiWorkers.delete(worker)
|
|
57
285
|
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const finish = () => {
|
|
289
|
+
if (cleanupErrors.length > 0) {
|
|
290
|
+
throw __createCleanupError(
|
|
291
|
+
cleanupErrors,
|
|
292
|
+
'Failed to terminate WASI workers',
|
|
293
|
+
)
|
|
67
294
|
}
|
|
295
|
+
}
|
|
296
|
+
return pending.length > 0 ? Promise.all(pending).then(finish) : finish()
|
|
297
|
+
}
|
|
68
298
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
299
|
+
function __finishWasiDisposal() {
|
|
300
|
+
const workerResult = __terminateWasiWorkers()
|
|
301
|
+
if (__isThenable(workerResult)) {
|
|
302
|
+
return Promise.resolve(workerResult).then(__completeWasiDisposal)
|
|
303
|
+
}
|
|
304
|
+
return __completeWasiDisposal()
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function __startWasiDisposal() {
|
|
308
|
+
const destroyResult = __destroyEmnapiContext()
|
|
309
|
+
if (__isThenable(destroyResult)) {
|
|
310
|
+
return Promise.resolve(destroyResult).then(__finishWasiDisposal)
|
|
311
|
+
}
|
|
312
|
+
return __finishWasiDisposal()
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Disposes this generated WASI binding.
|
|
317
|
+
*
|
|
318
|
+
* Access this function with:
|
|
319
|
+
* binding[Symbol.for('napi.rs.wasi.dispose')]()
|
|
320
|
+
*/
|
|
321
|
+
function __disposeWasiBinding() {
|
|
322
|
+
if (__wasiDisposePromise) {
|
|
323
|
+
return __wasiDisposePromise
|
|
324
|
+
}
|
|
325
|
+
if (__wasiDisposed) {
|
|
326
|
+
return Promise.resolve()
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
let resolveDispose
|
|
330
|
+
let rejectDispose
|
|
331
|
+
const disposePromise = new Promise((resolve, reject) => {
|
|
332
|
+
resolveDispose = resolve
|
|
333
|
+
rejectDispose = reject
|
|
334
|
+
})
|
|
335
|
+
__wasiDisposePromise = disposePromise
|
|
336
|
+
|
|
337
|
+
let result
|
|
338
|
+
try {
|
|
339
|
+
result = __startWasiDisposal()
|
|
340
|
+
} catch (error) {
|
|
341
|
+
__wasiDisposePromise = undefined
|
|
342
|
+
rejectDispose(error)
|
|
343
|
+
return disposePromise
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
Promise.resolve(result).then(
|
|
347
|
+
(value) => {
|
|
348
|
+
__wasiDisposed = true
|
|
349
|
+
resolveDispose(value)
|
|
350
|
+
},
|
|
351
|
+
(error) => {
|
|
352
|
+
__wasiDisposePromise = undefined
|
|
353
|
+
rejectDispose(error)
|
|
354
|
+
},
|
|
355
|
+
)
|
|
356
|
+
return disposePromise
|
|
357
|
+
}
|
|
81
358
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
359
|
+
function __publishWasiDispose(exports) {
|
|
360
|
+
Object.defineProperty(exports, __wasiDisposeSymbol, {
|
|
361
|
+
configurable: false,
|
|
362
|
+
enumerable: false,
|
|
363
|
+
value: __disposeWasiBinding,
|
|
364
|
+
writable: false,
|
|
365
|
+
})
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function __finishWasiInitializationRollback(cleanupErrors) {
|
|
369
|
+
let workerResult
|
|
370
|
+
try {
|
|
371
|
+
workerResult = __terminateWasiWorkers()
|
|
372
|
+
} catch (cleanupError) {
|
|
373
|
+
cleanupErrors.push(cleanupError)
|
|
374
|
+
return cleanupErrors
|
|
375
|
+
}
|
|
376
|
+
if (__isThenable(workerResult)) {
|
|
377
|
+
return Promise.resolve(workerResult)
|
|
378
|
+
.catch((cleanupError) => {
|
|
379
|
+
cleanupErrors.push(cleanupError)
|
|
380
|
+
})
|
|
381
|
+
.then(() => cleanupErrors)
|
|
382
|
+
}
|
|
383
|
+
return cleanupErrors
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function __rollbackWasiInitialization() {
|
|
387
|
+
const cleanupErrors = []
|
|
388
|
+
let destroyResult
|
|
389
|
+
try {
|
|
390
|
+
destroyResult = __destroyEmnapiContext()
|
|
391
|
+
} catch (cleanupError) {
|
|
392
|
+
cleanupErrors.push(cleanupError)
|
|
393
|
+
return __finishWasiInitializationRollback(cleanupErrors)
|
|
394
|
+
}
|
|
395
|
+
if (__isThenable(destroyResult)) {
|
|
396
|
+
return Promise.resolve(destroyResult)
|
|
397
|
+
.catch((cleanupError) => {
|
|
398
|
+
cleanupErrors.push(cleanupError)
|
|
399
|
+
})
|
|
400
|
+
.then(() => __finishWasiInitializationRollback(cleanupErrors))
|
|
401
|
+
}
|
|
402
|
+
return __finishWasiInitializationRollback(cleanupErrors)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const __wasiRollbackRegistrySymbol = Symbol.for('napi.rs.wasi.rollback.registry.v1')
|
|
406
|
+
const __wasiRollbackRegistryKey =
|
|
407
|
+
typeof __filename === 'string' ? __filename : __wasmFilePath
|
|
408
|
+
|
|
409
|
+
function __getWasiRollbackRegistry() {
|
|
410
|
+
const existing = process[__wasiRollbackRegistrySymbol]
|
|
411
|
+
if (existing !== undefined) {
|
|
412
|
+
if (!(existing instanceof Map)) {
|
|
413
|
+
throw new TypeError(
|
|
414
|
+
'The process-wide NAPI-RS WASI rollback registry is invalid',
|
|
415
|
+
)
|
|
416
|
+
}
|
|
417
|
+
return existing
|
|
418
|
+
}
|
|
419
|
+
const registry = new Map()
|
|
420
|
+
Object.defineProperty(process, __wasiRollbackRegistrySymbol, {
|
|
421
|
+
configurable: false,
|
|
422
|
+
enumerable: false,
|
|
423
|
+
value: registry,
|
|
424
|
+
writable: false,
|
|
425
|
+
})
|
|
426
|
+
return registry
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const __wasiRollbackRegistry = __getWasiRollbackRegistry()
|
|
430
|
+
|
|
431
|
+
function __completeWasiInitializationRollback(record, cleanupErrors) {
|
|
432
|
+
try {
|
|
433
|
+
if (cleanupErrors.length === 0) {
|
|
434
|
+
if (
|
|
435
|
+
__wasiRollbackRegistry.get(__wasiRollbackRegistryKey) === record
|
|
436
|
+
) {
|
|
437
|
+
__wasiRollbackRegistry.delete(__wasiRollbackRegistryKey)
|
|
87
438
|
}
|
|
439
|
+
return
|
|
440
|
+
}
|
|
441
|
+
record.error = __attachCleanupErrors(record.error, cleanupErrors)
|
|
442
|
+
} catch (cleanupError) {
|
|
443
|
+
try {
|
|
444
|
+
record.error = __createCleanupError(
|
|
445
|
+
[record.error, cleanupError],
|
|
446
|
+
'WASI binding initialization and cleanup failed',
|
|
447
|
+
)
|
|
448
|
+
} catch {}
|
|
449
|
+
} finally {
|
|
450
|
+
record.active = false
|
|
451
|
+
record.promise = undefined
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function __runWasiInitializationRollback(record) {
|
|
456
|
+
if (record.active) {
|
|
457
|
+
return
|
|
458
|
+
}
|
|
459
|
+
record.active = true
|
|
460
|
+
|
|
461
|
+
let rollbackResult
|
|
462
|
+
try {
|
|
463
|
+
rollbackResult = record.rollback()
|
|
464
|
+
} catch (cleanupError) {
|
|
465
|
+
__completeWasiInitializationRollback(record, [cleanupError])
|
|
466
|
+
return
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (!__isThenable(rollbackResult)) {
|
|
470
|
+
__completeWasiInitializationRollback(record, rollbackResult)
|
|
471
|
+
return
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
record.promise = Promise.resolve(rollbackResult).then(
|
|
475
|
+
(cleanupErrors) => {
|
|
476
|
+
__completeWasiInitializationRollback(record, cleanupErrors)
|
|
477
|
+
},
|
|
478
|
+
(cleanupError) => {
|
|
479
|
+
__completeWasiInitializationRollback(record, [cleanupError])
|
|
480
|
+
},
|
|
481
|
+
)
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const __pendingWasiRollback = __wasiRollbackRegistry.get(
|
|
485
|
+
__wasiRollbackRegistryKey,
|
|
486
|
+
)
|
|
487
|
+
if (__pendingWasiRollback !== undefined) {
|
|
488
|
+
__runWasiInitializationRollback(__pendingWasiRollback)
|
|
489
|
+
throw __pendingWasiRollback.error
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
let __wasiModule
|
|
493
|
+
let __napiModule
|
|
494
|
+
let __wasiExitListenerRegistered = false
|
|
88
495
|
|
|
89
|
-
|
|
496
|
+
function __removeWasiExitListener() {
|
|
497
|
+
if (
|
|
498
|
+
__wasiExitListenerRegistered &&
|
|
499
|
+
typeof process.removeListener === 'function'
|
|
500
|
+
) {
|
|
501
|
+
process.removeListener('exit', __disposeWasiBindingAtExit)
|
|
502
|
+
}
|
|
503
|
+
__wasiExitListenerRegistered = false
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function __disposeWasiBindingAtExit() {
|
|
507
|
+
__wasiExitListenerRegistered = false
|
|
508
|
+
try {
|
|
509
|
+
const result = __disposeWasiBinding()
|
|
510
|
+
if (__isThenable(result)) {
|
|
511
|
+
void Promise.resolve(result).catch(() => {})
|
|
90
512
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
513
|
+
} catch {}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function __registerWasiExitListener() {
|
|
517
|
+
if (
|
|
518
|
+
!__wasiExitListenerRegistered &&
|
|
519
|
+
typeof process.once === 'function'
|
|
520
|
+
) {
|
|
521
|
+
process.once('exit', __disposeWasiBindingAtExit)
|
|
522
|
+
__wasiExitListenerRegistered = true
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
__completeWasiDisposal = __removeWasiExitListener
|
|
527
|
+
|
|
528
|
+
function __captureEmnapiAutoDestroyListener() {
|
|
529
|
+
if (
|
|
530
|
+
typeof process.prependListener !== 'function' ||
|
|
531
|
+
typeof process.removeListener !== 'function'
|
|
532
|
+
) {
|
|
533
|
+
return
|
|
534
|
+
}
|
|
535
|
+
let __autoDestroyListener
|
|
536
|
+
const __captureListener = (__event, __listener) => {
|
|
537
|
+
if (__event === 'beforeExit' && __autoDestroyListener === undefined) {
|
|
538
|
+
__autoDestroyListener = __listener
|
|
99
539
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
540
|
+
}
|
|
541
|
+
try {
|
|
542
|
+
// Run before existing newListener hooks so a hook that registers its own
|
|
543
|
+
// beforeExit listener cannot be mistaken for emnapi's registration.
|
|
544
|
+
process.prependListener('newListener', __captureListener)
|
|
545
|
+
} catch {
|
|
546
|
+
return
|
|
547
|
+
}
|
|
548
|
+
return () => {
|
|
549
|
+
try {
|
|
550
|
+
process.removeListener('newListener', __captureListener)
|
|
551
|
+
} catch {}
|
|
552
|
+
if (__autoDestroyListener !== undefined) {
|
|
553
|
+
try {
|
|
554
|
+
process.removeListener('beforeExit', __autoDestroyListener)
|
|
555
|
+
} catch {}
|
|
107
556
|
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
try {
|
|
561
|
+
const __finishAutoDestroyCapture = __captureEmnapiAutoDestroyListener()
|
|
562
|
+
try {
|
|
563
|
+
__emnapiContext = __emnapiCreateContext({ autoDestroy: false })
|
|
564
|
+
// emnapi 2.x still registers an unconditional once-listener for
|
|
565
|
+
// beforeExit that auto-destroys the context, and suppressDestroy() only
|
|
566
|
+
// neutralizes its callback without removing it. This loader owns cleanup
|
|
567
|
+
// through its 'exit' listener, so emnapi's listener is captured and
|
|
568
|
+
// removed; suppressDestroy() remains the safety net when removal fails.
|
|
569
|
+
__emnapiContext.suppressDestroy()
|
|
570
|
+
} finally {
|
|
571
|
+
// Remove only the exact emnapi callback captured above.
|
|
572
|
+
__finishAutoDestroyCapture?.()
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
;({
|
|
576
|
+
instance: __napiInstance,
|
|
577
|
+
module: __wasiModule,
|
|
578
|
+
napiModule: __napiModule,
|
|
579
|
+
} = __emnapiInstantiateNapiModuleSync(__wasmFile, {
|
|
580
|
+
context: __emnapiContext,
|
|
581
|
+
asyncWorkPoolSize: (function() {
|
|
582
|
+
const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
|
|
583
|
+
// NaN > 0 is false
|
|
584
|
+
if (threadsSizeFromEnv > 0) {
|
|
585
|
+
return threadsSizeFromEnv
|
|
586
|
+
} else {
|
|
587
|
+
return 4
|
|
588
|
+
}
|
|
589
|
+
})(),
|
|
590
|
+
reuseWorker: true,
|
|
591
|
+
plugins: [__emnapiAsyncWorkPlugin, __emnapiTSFNPlugin],
|
|
592
|
+
wasi: __wasi,
|
|
593
|
+
onCreateWorker() {
|
|
594
|
+
const worker = __createWasiWorker(__nodePath.join(__dirname, 'wasi-worker.mjs'))
|
|
595
|
+
__wasiWorkers.add(worker)
|
|
596
|
+
worker.onmessage = ({ data }) => {
|
|
597
|
+
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// The main thread of Node.js waits for all the active handles before exiting.
|
|
601
|
+
// But Rust threads are never waited without `thread::join`.
|
|
602
|
+
// So here we hack the code of Node.js to prevent the workers from being referenced (active).
|
|
603
|
+
// According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
|
|
604
|
+
// a worker is consist of two handles: kPublicPort and kHandle.
|
|
605
|
+
{
|
|
606
|
+
const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
|
|
607
|
+
s.toString().includes("kPublicPort")
|
|
608
|
+
);
|
|
609
|
+
if (kPublicPort) {
|
|
610
|
+
worker[kPublicPort].ref = () => {};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
|
|
614
|
+
s.toString().includes("kHandle")
|
|
615
|
+
);
|
|
616
|
+
if (kHandle) {
|
|
617
|
+
worker[kHandle].ref = () => {};
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
worker.unref();
|
|
621
|
+
}
|
|
622
|
+
return worker
|
|
623
|
+
},
|
|
624
|
+
overwriteImports(importObject) {
|
|
625
|
+
importObject.env = {
|
|
626
|
+
...importObject.env,
|
|
627
|
+
...importObject.napi,
|
|
628
|
+
...importObject.emnapi,
|
|
629
|
+
memory: __sharedMemory,
|
|
630
|
+
}
|
|
631
|
+
return importObject
|
|
632
|
+
},
|
|
633
|
+
beforeInit({ instance }) {
|
|
634
|
+
__napiInstance = instance
|
|
635
|
+
for (const name of Object.keys(instance.exports)) {
|
|
636
|
+
if (name.startsWith('__napi_register__')) {
|
|
637
|
+
instance.exports[name]()
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
}))
|
|
642
|
+
__publishWasiDispose(__napiModule.exports)
|
|
643
|
+
__registerWasiExitListener()
|
|
644
|
+
} catch (error) {
|
|
645
|
+
const rollback = {
|
|
646
|
+
active: false,
|
|
647
|
+
error,
|
|
648
|
+
promise: undefined,
|
|
649
|
+
rollback: __rollbackWasiInitialization,
|
|
650
|
+
}
|
|
651
|
+
__wasiRollbackRegistry.set(__wasiRollbackRegistryKey, rollback)
|
|
652
|
+
__runWasiInitializationRollback(rollback)
|
|
653
|
+
throw rollback.error
|
|
654
|
+
}
|
|
110
655
|
module.exports = __napiModule.exports
|
|
111
656
|
module.exports.LegalCommentsMode = __napiModule.exports.LegalCommentsMode
|
|
112
657
|
module.exports.minify = __napiModule.exports.minify
|