@rspack/binding-wasm32-wasi 2.3.1 → 2.3.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.
@@ -1,11 +1,62 @@
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, Buffer } from '@napi-rs/wasm-runtime/fs'
8
10
 
11
+ export const __napiBindingTarget = 'wasm32-wasi'
12
+ function __napiStampBindingTarget(exportsObject, target) {
13
+ if (
14
+ Object.prototype.hasOwnProperty.call(exportsObject, '__napiBindingTarget')
15
+ ) {
16
+ if (exportsObject.__napiBindingTarget === target) {
17
+ // Already ours: the root entry aliases the object it loaded, so a WASI
18
+ // fallback candidate — or a `NAPI_RS_NATIVE_LIBRARY_PATH` override that
19
+ // is a generated loader — arrives already stamped with this same value.
20
+ return target
21
+ }
22
+ const error = new Error(
23
+ '`__napiBindingTarget` is reserved by the generated binding loader, but the loaded binding already exports it. Rename the export, e.g. #[napi(js_name = "...")].',
24
+ )
25
+ error.code = 'ERR_NAPI_BINDING_TARGET_CONFLICT'
26
+ throw error
27
+ }
28
+ if (!Object.isExtensible(exportsObject)) {
29
+ // A `#[napi(module_exports)]` hook may seal or freeze this object
30
+ // (`Object::seal` / `Object::freeze`). Reporting the artifact is metadata,
31
+ // never a reason to fail an otherwise successful load, so the stamp is
32
+ // skipped. What a consumer still sees then follows the entry point: the
33
+ // browser and deferred loaders declare `__napiBindingTarget` at module
34
+ // level and go on reporting it, while the CommonJS entries hand back this
35
+ // very object as `module.exports`, so there the value is absent.
36
+ return target
37
+ }
38
+ try {
39
+ // [[Define]], not [[Set]]: an ordinary assignment walks the prototype
40
+ // chain, so an inherited accessor could swallow the value or throw and
41
+ // fail an otherwise successful load. The descriptor is what a successful
42
+ // assignment would have produced.
43
+ Object.defineProperty(exportsObject, '__napiBindingTarget', {
44
+ configurable: true,
45
+ enumerable: true,
46
+ value: target,
47
+ writable: true,
48
+ })
49
+ } catch {
50
+ // Same rule as the non-extensible skip above: reporting the artifact is
51
+ // metadata, never a reason to fail an otherwise successful load. An exotic
52
+ // object (a Proxy whose defineProperty trap refuses) is skipped, not
53
+ // thrown over.
54
+ }
55
+ // The CommonJS loaders assign this return value so `cjs-module-lexer` — and
56
+ // therefore Node's CJS -> ESM named export detection — can see
57
+ // `__napiBindingTarget` statically.
58
+ return target
59
+ }
9
60
 
10
61
  export const { fs: __fs, vol: __volume } = memfs()
11
62
 
@@ -18,57 +69,1397 @@ const __wasi = new __WASI({
18
69
  })
19
70
 
20
71
  const __wasmUrl = new URL('./rspack.wasm32-wasi.wasm', import.meta.url).href
21
- const __emnapiContext = __emnapiGetDefaultContext()
22
- __emnapiContext.feature.Buffer = Buffer
72
+ const __wasmResponse = await globalThis.fetch(__wasmUrl)
73
+ if (!__wasmResponse.ok) {
74
+ throw new Error(
75
+ 'Failed to fetch WASI module ' +
76
+ __wasmUrl +
77
+ ': ' +
78
+ __wasmResponse.status +
79
+ ' ' +
80
+ (__wasmResponse.statusText || 'Unknown Status'),
81
+ )
82
+ }
83
+ const __wasmFile = await __wasmResponse.arrayBuffer()
23
84
 
24
- // Allocate 2GB fixed shared memory (initial == maximum to disable memory.grow).
25
85
  const __sharedMemory = new WebAssembly.Memory({
26
86
  initial: 32768,
27
87
  maximum: 32768,
28
88
  shared: true,
29
89
  })
90
+ const __asyncWorkPoolSize = 4
91
+ const __workerPoolSize = Math.max(
92
+ 2,
93
+ globalThis.navigator?.hardwareConcurrency ?? 4,
94
+ )
30
95
 
31
- const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
32
-
33
- const {
34
- instance: __napiInstance,
35
- module: __wasiModule,
36
- napiModule: __napiModule,
37
- } = await __emnapiInstantiateNapiModule(__wasmFile, {
38
- context: __emnapiContext,
39
- asyncWorkPoolSize: 4,
40
- wasi: __wasi,
41
- onCreateWorker() {
42
- const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
43
- type: 'module',
44
- })
45
- worker.addEventListener('message', __wasmCreateOnMessageForFsProxy(__fs))
96
+ let __emnapiContext
97
+
98
+ const __wasiDisposeSymbol = Symbol.for('napi.rs.wasi.dispose')
99
+ const __wasiWorkers = new Set()
100
+ // The thread manager has to be reachable *before* anything that can throw
101
+ // during load or registration. Initialization can fail after the pool has
102
+ // already spawned workers, and the rollback still has to mark their
103
+ // terminations as expected — but `__napiModule` is assigned only when
104
+ // instantiation RETURNS, so on exactly that path it is still undefined. A
105
+ // plugin factory runs while the emnapi module is being created, before the
106
+ // wasm is loaded and before any registration function runs, and its context
107
+ // carries the very same manager instance.
108
+ let __wasiThreadManager
109
+
110
+ function __captureWasiThreadManager(context) {
111
+ if (context && context.PThread) {
112
+ __wasiThreadManager = context.PThread
113
+ }
114
+ return {}
115
+ }
116
+
117
+ function __getWasiThreadManager() {
118
+ const manager =
119
+ __wasiThreadManager !== undefined
120
+ ? __wasiThreadManager
121
+ : __napiModule
122
+ ? __napiModule.PThread
123
+ : undefined
124
+ if (manager && typeof manager.terminateWorker === 'function') {
125
+ return manager
126
+ }
127
+ return undefined
128
+ }
129
+ let __napiInstance
130
+ let __emnapiContextDestroyed = false
131
+ let __emnapiContextDestroyPromise
132
+ let __emnapiWasmEnvCleanupPrepared = false
133
+ let __emnapiWasmEnvCleanupPreparing = false
134
+ // The closer for a barrier that is parked between `…_begin` and `…_finish`,
135
+ // set only while that window is open. `__emnapiWasmEnvCleanupPreparing` cannot
136
+ // tell those two apart on its own: it is raised both for a purely synchronous
137
+ // frame — which must not be re-entered, and which nothing outside it can
138
+ // finish — and across this window, which spans real event-loop turns, so a
139
+ // caller that cannot yield can land in the middle of one. That caller can close
140
+ // this window, because `…_finish` is idempotent and joins, which is exactly
141
+ // what the single call does. See `__prepareWasmEnvCleanup`.
142
+ let __finishParkedWasmEnvCleanup
143
+ // Raised while a caller that can still yield is driving the barrier, so the
144
+ // queue it leaves behind is expected rather than lost. See
145
+ // `__reportUnreachedWasmEnvSettlements`.
146
+ let __emnapiWasmEnvCleanupYielding = false
147
+ let __emnapiWasmEnvSettlementLossReported = false
148
+ let __emnapiWasmEnvCleanupRan = false
149
+ let __emnapiWasmEnvCleanupDrained = false
150
+ let __emnapiWasmEnvCleanupDrainPromise
151
+ let __wasiDisposed = false
152
+ let __wasiAsyncWorkDrainPromise
153
+ let __wasiDisposePromise
154
+ let __completeWasiDisposal = function () {}
155
+ // Overridden by loader flavors that have a last-resort reclaim for a rollback
156
+ // that stopped short of destroying the context. See
157
+ // `__rollbackWasiInitialization`.
158
+ let __retainWasiRollbackForRetry = function () {}
159
+
160
+ function __isThenable(value) {
161
+ return (
162
+ value !== null &&
163
+ (typeof value === 'object' || typeof value === 'function') &&
164
+ typeof value.then === 'function'
165
+ )
166
+ }
46
167
 
47
- worker.addEventListener('error', (event) => {
48
- if (event.data && typeof event.data === 'object' && event.data.type === 'error') {
49
- window.dispatchEvent(new CustomEvent('napi-rs-worker-error', { detail: event.data }))
168
+ function __createCleanupError(errors, message) {
169
+ if (errors.length === 1) {
170
+ return errors[0]
171
+ }
172
+ const __AggregateError = globalThis.AggregateError
173
+ if (typeof __AggregateError === 'function') {
174
+ return new __AggregateError(errors, message)
175
+ }
176
+ const error = new Error(message)
177
+ error.errors = errors
178
+ return error
179
+ }
180
+
181
+ function __attachCleanupErrors(error, cleanupErrors) {
182
+ if (cleanupErrors.length === 0) {
183
+ return error
184
+ }
185
+ const cleanupError = __createCleanupError(
186
+ cleanupErrors,
187
+ 'WASI binding cleanup failed',
188
+ )
189
+ try {
190
+ if (
191
+ error &&
192
+ (typeof error === 'object' || typeof error === 'function')
193
+ ) {
194
+ if (error.cause === undefined) {
195
+ error.cause = cleanupError
196
+ if (error.cause === cleanupError) {
197
+ return error
198
+ }
199
+ }
200
+ if (Array.isArray(error.cleanupErrors)) {
201
+ error.cleanupErrors.push(cleanupError)
202
+ return error
203
+ } else {
204
+ const attachedCleanupErrors = [cleanupError]
205
+ error.cleanupErrors = attachedCleanupErrors
206
+ if (error.cleanupErrors === attachedCleanupErrors) {
207
+ return error
208
+ }
50
209
  }
210
+ }
211
+ } catch {}
212
+ const aggregate = __createCleanupError(
213
+ [error, cleanupError],
214
+ 'WASI binding initialization and cleanup failed',
215
+ )
216
+ try {
217
+ aggregate.cause = error
218
+ } catch {}
219
+ return aggregate
220
+ }
221
+
222
+ function __wrapEmnapiContextDestroyForSettlement(
223
+ context,
224
+ prepareEnvCleanup,
225
+ isPreparingEnvCleanup,
226
+ ) {
227
+ let destroy
228
+ try {
229
+ destroy = context.destroy
230
+ } catch {
231
+ return context
232
+ }
233
+ if (typeof destroy !== 'function') {
234
+ return context
235
+ }
236
+ try {
237
+ Object.defineProperty(context, 'destroy', {
238
+ configurable: true,
239
+ enumerable: false,
240
+ writable: true,
241
+ value: function () {
242
+ // Reentered from a promise hook that fired inside the barrier: the
243
+ // frame running it destroys as soon as it returns.
244
+ if (isPreparingEnvCleanup?.()) {
245
+ return
246
+ }
247
+ prepareEnvCleanup?.()
248
+ return Reflect.apply(destroy, this, arguments)
249
+ },
51
250
  })
251
+ } catch {}
252
+ return context
253
+ }
52
254
 
53
- return worker
54
- },
55
- overwriteImports(importObject) {
56
- importObject.env = {
57
- ...importObject.env,
58
- ...importObject.napi,
59
- ...importObject.emnapi,
60
- memory: __sharedMemory,
61
- }
62
- return importObject
63
- },
64
- beforeInit({ instance }) {
65
- for (const name of Object.keys(instance.exports)) {
66
- if (name.startsWith('__napi_register__')) {
67
- instance.exports[name]()
255
+ function __isPreparingWasmEnvCleanup() {
256
+ return __emnapiWasmEnvCleanupPreparing
257
+ }
258
+
259
+ function __prepareWasmEnvCleanup() {
260
+ if (__emnapiWasmEnvCleanupPrepared) {
261
+ return
262
+ }
263
+ // A handshake parked between its two halves is one this frame can close, and
264
+ // must: every caller of this function is about to destroy the context, and
265
+ // the turns the poll is waiting for will not come — an 'exit' teardown is
266
+ // the last thing the process runs, and `Context.destroy()` takes the
267
+ // environment away. Closing it here runs `…_finish`, which is the call that joins, so
268
+ // this degrades to exactly the single call below. Leaving it open instead
269
+ // destroys the context with the barrier still raised, the runtime never
270
+ // joined and the workers never drained.
271
+ const finishParked = __finishParkedWasmEnvCleanup
272
+ if (finishParked !== undefined) {
273
+ finishParked()
274
+ __reportUnreachedWasmEnvSettlements()
275
+ return
276
+ }
277
+ if (__emnapiWasmEnvCleanupPreparing) {
278
+ return
279
+ }
280
+ const prepare = __napiInstance?.exports?.napi_prepare_wasm_env_cleanup
281
+ if (typeof prepare === 'function') {
282
+ // The addon settles the promises it cancels synchronously, under a
283
+ // non-reentrant lifecycle mutex: anything a promise hook calls from in
284
+ // here must not reach this export again.
285
+ __emnapiWasmEnvCleanupPreparing = true
286
+ try {
287
+ prepare()
288
+ } finally {
289
+ __emnapiWasmEnvCleanupPreparing = false
290
+ }
291
+ __emnapiWasmEnvCleanupRan = true
292
+ __reportUnreachedWasmEnvSettlements()
293
+ }
294
+ __emnapiWasmEnvCleanupPrepared = true
295
+ }
296
+
297
+ /**
298
+ * Say so when the barrier leaves settlements queued and nothing is left that
299
+ * could deliver them.
300
+ *
301
+ * Only the disposal chain yields the event-loop turns @emnapi/core needs to
302
+ * dispatch its queue. Every other caller of the barrier destroys in the same
303
+ * turn — a raw `Context.destroy()`, the 'exit' teardown — and
304
+ * `Context.destroy()` runs the threadsafe function's cleanup hook, which drains
305
+ * that queue with a null env and discards it. The promises those settlements
306
+ * were for then hang forever, silently.
307
+ *
308
+ * Loud, once, and never throwing: this runs from inside `Context.destroy()`,
309
+ * emnapi's own beforeExit destroy included, where throwing would take the whole
310
+ * teardown down with it. Destroying anyway is still the right trade — the queue
311
+ * is already unreachable by then.
312
+ */
313
+ function __reportUnreachedWasmEnvSettlements() {
314
+ if (__emnapiWasmEnvCleanupYielding || __emnapiWasmEnvSettlementLossReported) {
315
+ return
316
+ }
317
+ const pending = __napiInstance?.exports?.napi_wasm_env_cleanup_pending
318
+ if (typeof pending !== 'function') {
319
+ return
320
+ }
321
+ let queued
322
+ try {
323
+ queued = pending()
324
+ } catch {
325
+ return
326
+ }
327
+ if (!queued) {
328
+ return
329
+ }
330
+ __emnapiWasmEnvSettlementLossReported = true
331
+ try {
332
+ const consoleHost = globalThis.console
333
+ if (consoleHost && typeof consoleHost.error === 'function') {
334
+ consoleHost.error(
335
+ "napi-rs: the wasm environment is being destroyed with " +
336
+ queued +
337
+ " queued promise settlement(s). Context.destroy() discards them, so those promises never settle. Dispose with binding[Symbol.for('napi.rs.wasi.dispose')]() instead: only it yields the event-loop turns the settlements need.",
338
+ )
339
+ }
340
+ } catch {}
341
+ }
342
+
343
+ // Mirror the primitive @emnapi/core schedules its threadsafe-function dispatch
344
+ // on, so the drain turns below interleave with that dispatch instead of racing
345
+ // ahead of it on a faster queue.
346
+ const __scheduleMacrotask = (function () {
347
+ if (typeof setImmediate === 'function') {
348
+ return function (callback) {
349
+ setImmediate(callback)
350
+ }
351
+ }
352
+ const __MessageChannel = globalThis.MessageChannel
353
+ if (typeof __MessageChannel === 'function') {
354
+ return function (callback) {
355
+ const channel = new __MessageChannel()
356
+ channel.port1.onmessage = function () {
357
+ channel.port1.onmessage = null
358
+ try {
359
+ channel.port1.close()
360
+ } catch {}
361
+ try {
362
+ channel.port2.close()
363
+ } catch {}
364
+ callback()
68
365
  }
366
+ channel.port2.postMessage(null)
69
367
  }
70
- },
71
- })
368
+ }
369
+ return function (callback) {
370
+ setTimeout(callback, 0)
371
+ }
372
+ })()
373
+
374
+ // A real, *referenced* timer, for waits that must let the whole host make
375
+ // progress between looks — the async-work drain polls the addon rather than
376
+ // interleaving with the @emnapi/core dispatch, so a zero-delay macrotask there
377
+ // would spin the loop instead of yielding it. Falls back to the macrotask
378
+ // scheduler on a host without timers.
379
+ function __scheduleTimer(callback, delay) {
380
+ const setTimer = globalThis.setTimeout
381
+ if (typeof setTimer !== 'function') {
382
+ __scheduleMacrotask(callback)
383
+ return
384
+ }
385
+ try {
386
+ setTimer(callback, delay)
387
+ } catch {
388
+ __scheduleMacrotask(callback)
389
+ }
390
+ }
391
+
392
+ // A real, referenced timer rather than a zero-delay macrotask, for the same
393
+ // reason the async-work drain uses one: this polls the addon instead of
394
+ // interleaving with the @emnapi/core dispatch, so a zero-delay turn would spin
395
+ // the loop instead of yielding it.
396
+ const __WASM_RUNTIME_WORK_POLL_INTERVAL_MS = 1
397
+ // Arrivals it takes before the poll paces on the host's timers alone. One
398
+ // proves nothing: a timer armed before the host's timers stopped still fires.
399
+ const __WASM_RUNTIME_WORK_POLL_TRUSTED_ARRIVALS = 2
400
+ // How long a parked turn's own timer must already have been due before a
401
+ // backup that runs calls it dropped. Slack, not a deadline: a timer is due
402
+ // against the event loop's clock, which is read once per iteration, while
403
+ // these are `Date.now()` readings taken part-way through one, so the two
404
+ // drift apart by however long the loop has been inside the current iteration.
405
+ const __WASM_RUNTIME_WORK_POLL_STALL_MS = 50
406
+ // How long a backup itself waits. What is left of it after the slack and one
407
+ // interval — 149 ms — has to cover the *two* poll turns that can separate a
408
+ // parked turn from the last backup armed while the host's timers still
409
+ // worked, so the ceiling on a single turn is half of it. See the invariant on
410
+ // `__armWasmRuntimePollStallBackup`.
411
+ const __WASM_RUNTIME_WORK_POLL_BACKUP_MS = 200
412
+
413
+ /**
414
+ * Pacing state for one runtime-work poll.
415
+ *
416
+ * Per poll, never per module: whether the host's timers arrive is not a
417
+ * property of the module. A host can lose its timers between two disposals,
418
+ * and in the deferred shape every instance shares this module — one healthy
419
+ * instance must not disarm the fallback for the next one.
420
+ */
421
+ function __createWasmRuntimePollPace() {
422
+ return {
423
+ // Timers armed by *this* poll that have actually arrived.
424
+ arrivals: 0,
425
+ // The turn waiting on a timer alone *right now* — undefined whenever no
426
+ // turn is parked — and when that turn's own timer came due.
427
+ settleTurn: undefined,
428
+ turnTimerDueAt: 0,
429
+ }
430
+ }
431
+
432
+ /**
433
+ * The backup that ends a turn whose timer is never going to arrive.
434
+ *
435
+ * Once the poll paces on the timer alone it has nothing left to fall back on
436
+ * if the host's timers stop mid-poll: the turn that armed the dead timer is
437
+ * the turn that parks, and a parked poll schedules nothing that could notice.
438
+ * So every turn arms one of these before it yields, and each one compares due
439
+ * times instead of measuring how long the parked turn has been waiting.
440
+ *
441
+ * Invariant: a parked turn is ended by the newest backup that was armed while
442
+ * the host's timers still worked, and a backup ends a turn only when that
443
+ * turn's own timer was already due a whole window before the backup itself.
444
+ * Neither half turns on how far apart the arms happen to fall — what bounds
445
+ * the rescue is how far back that newest live backup is:
446
+ *
447
+ * - *Ends it.* Hosts run timers in due order, so a backup that runs while a
448
+ * turn due a whole window earlier is still parked proves that turn's timer
449
+ * was dropped rather than merely late. That same comparison is what leaves a
450
+ * healthy host alone: there the turn's timer has already run and cleared
451
+ * `settleTurn` before any backup due after it can look.
452
+ * - *Two turns back, not one.* A turn that ended does not prove its own timer
453
+ * arrived: until `…_TRUSTED_ARRIVALS` is reached every turn arms both
454
+ * primitives and the macrotask wins, so such a turn can end with its own
455
+ * timer — and the backup armed one line before it — already dead. The
456
+ * arrival that then flips the poll onto the timer alone can itself be a
457
+ * timer armed before the host's timers died. So the turn that parks can sit
458
+ * two turns past the last live arm, and the newest live backup is due
459
+ * `…_BACKUP_MS` less *two* turn lengths after that turn's own timer.
460
+ * Arming on every turn is what holds it to two, rather than however far back
461
+ * a throttle last let one through.
462
+ * - *Ceiling.* Coverage therefore holds while two consecutive poll turns fit
463
+ * inside `…_BACKUP_MS` less the slack and one interval: 149 ms, so 74 ms
464
+ * per turn (measured: a 74 ms turn is still rescued, a 75 ms one parks).
465
+ * Past that the turn stays parked and the disposal promise never settles.
466
+ * The bound is deliberate: reaching it takes a host that drops timers
467
+ * mid-poll *and* keeps every poll turn busy for more than 74 ms, and neither
468
+ * Node nor WebContainer — the hosts that run the threaded artifact — does
469
+ * the second.
470
+ *
471
+ * The poll then goes back to arming both primitives until two fresh arrivals
472
+ * prove the timers again. A host that stops running the timers it has
473
+ * *already* accepted leaves nothing to fire, and the disposal promise stays
474
+ * pending rather than wedging the thread — the same outcome as a blocking
475
+ * closure that never returns. Unreferenced wherever the host allows it: the
476
+ * poll's own turn timers are what keep the loop alive, never these.
477
+ */
478
+ function __armWasmRuntimePollStallBackup(pace) {
479
+ const setTimer = globalThis.setTimeout
480
+ if (typeof setTimer !== 'function') {
481
+ // Nothing to back up: `__scheduleTimer` is on the macrotask channel
482
+ // already, and that one cannot park.
483
+ return
484
+ }
485
+ // Read before arming, so this never claims to be due earlier than the timer
486
+ // actually is: a backup ends a turn only when it is provably due after it.
487
+ const dueAt = Date.now() + __WASM_RUNTIME_WORK_POLL_BACKUP_MS
488
+ let handle
489
+ try {
490
+ handle = setTimer(() => {
491
+ const settleTurn = pace.settleTurn
492
+ if (
493
+ !settleTurn ||
494
+ pace.turnTimerDueAt > dueAt - __WASM_RUNTIME_WORK_POLL_STALL_MS
495
+ ) {
496
+ // No turn is parked, or the parked one's timer came due too close to
497
+ // this backup to call it dropped — it may still arrive, and the turn
498
+ // that armed it armed a backup due a whole window after *that*.
499
+ return
500
+ }
501
+ pace.arrivals = 0
502
+ pace.settleTurn = undefined
503
+ settleTurn()
504
+ }, __WASM_RUNTIME_WORK_POLL_BACKUP_MS)
505
+ } catch {
506
+ return
507
+ }
508
+ if (handle && typeof handle.unref === 'function') {
509
+ try {
510
+ handle.unref()
511
+ } catch {}
512
+ }
513
+ }
514
+
515
+ /**
516
+ * One turn of the runtime-work poll.
517
+ *
518
+ * `__scheduleTimer` falls back to the macrotask scheduler when `setTimeout` is
519
+ * missing or throws, but not when it is present, returns a handle and never
520
+ * fires — fake timers in a test suite that disposes from an `afterEach`, or a
521
+ * host whose timers belong to an IO context that is already gone. That host
522
+ * would park this poll forever, and the poll is unbounded, so nothing would
523
+ * ever call `…_finish`.
524
+ *
525
+ * Arm both primitives until timers armed by this poll have arrived twice, and
526
+ * let whichever lands first end the turn; the loser resolves nothing. A host
527
+ * with working timers therefore pays the double arming for the first turn or
528
+ * two — the macrotask wins the race, but the timers behind it still arrive and
529
+ * are counted — and paces on the timer alone from then on, instead of spinning
530
+ * the loop on a zero-delay queue. A host whose timers never arrive keeps both,
531
+ * and the macrotask is what keeps the poll moving. A host whose timers stop
532
+ * after proving themselves is caught by `__armWasmRuntimePollStallBackup`,
533
+ * which ends the parked turn and puts this poll back on both.
534
+ */
535
+ function __yieldWasmRuntimePollTurn(pace) {
536
+ // Armed before the turn yields, and by every turn: what rescues a parked
537
+ // turn has to have been armed while the host's timers still worked, and the
538
+ // turn that parks is the one whose own timer is already dead.
539
+ __armWasmRuntimePollStallBackup(pace)
540
+ return new Promise((resolve) => {
541
+ let settled = false
542
+ const settle = () => {
543
+ if (settled) {
544
+ return
545
+ }
546
+ settled = true
547
+ if (pace.settleTurn === settle) {
548
+ // Nothing is parked any more: a backup running later must not read a
549
+ // due time this turn has already answered.
550
+ pace.settleTurn = undefined
551
+ }
552
+ resolve()
553
+ }
554
+ __scheduleTimer(() => {
555
+ pace.arrivals++
556
+ settle()
557
+ }, __WASM_RUNTIME_WORK_POLL_INTERVAL_MS)
558
+ // Read next to the arming it describes; see
559
+ // `__armWasmRuntimePollStallBackup` for what the two due times mean.
560
+ const turnTimerDueAt = Date.now() + __WASM_RUNTIME_WORK_POLL_INTERVAL_MS
561
+ if (pace.arrivals < __WASM_RUNTIME_WORK_POLL_TRUSTED_ARRIVALS) {
562
+ __scheduleMacrotask(settle)
563
+ return
564
+ }
565
+ // Paced by the timer alone from here; the backup is what ends this turn if
566
+ // the timer never arrives.
567
+ pace.settleTurn = settle
568
+ pace.turnTimerDueAt = turnTimerDueAt
569
+ })
570
+ }
571
+
572
+ /**
573
+ * The barrier for callers that can yield: `__prepareWasmEnvCleanup` with real
574
+ * event-loop turns in the middle.
575
+ *
576
+ * `napi_prepare_wasm_env_cleanup` waits — it returns only once the addon's
577
+ * async runtime has quiesced, and on `wasm32-wasip1-threads` the thread it
578
+ * waits on is this one, the only thread that can give a running blocking
579
+ * closure the JavaScript turn *it* is waiting for. A single call there can wait
580
+ * for work that can never finish. The addon's two-phase form splits that:
581
+ * `…_begin` stops the runtime without joining and reports whether anything is
582
+ * still live, `napi_wasm_runtime_work_pending` answers that question again
583
+ * without blocking, and `…_finish` joins. The turns yielded in between are the
584
+ * entire point.
585
+ *
586
+ * The poll has no deadline, for the same reason the async-work drain below has
587
+ * none: giving up means calling `…_finish`, which joins on this thread, and the
588
+ * work it would join is the work that is waiting for a turn from this thread —
589
+ * so a bound does not end the wait, it only moves it somewhere the JavaScript
590
+ * thread can no longer be reached. A blocking closure that never returns keeps
591
+ * the disposal promise pending instead, exactly as a task whose `execute` never
592
+ * returns already keeps an *undisposed* process alive. The host contract is in
593
+ * `crates/async-runtime/README.md`: a blocking closure must never wait on a
594
+ * JavaScript turn. The process-exit path still blocks in `…_finish`, because it
595
+ * has no turns left to give (see `__prepareWasmEnvCleanup`).
596
+ *
597
+ * Feature-detected like every other export in this teardown, so an addon built
598
+ * against a napi crate that predates the split keeps the single blocking call.
599
+ * Returns nothing whenever the handshake finished without yielding, which keeps
600
+ * an idle disposal synchronous.
601
+ */
602
+ function __prepareWasmEnvCleanupWithTurns() {
603
+ if (__emnapiWasmEnvCleanupPrepared || __emnapiWasmEnvCleanupPreparing) {
604
+ return
605
+ }
606
+ const exports = __napiInstance?.exports
607
+ const begin = exports?.napi_prepare_wasm_env_cleanup_begin
608
+ const finish = exports?.napi_prepare_wasm_env_cleanup_finish
609
+ if (typeof begin !== 'function' || typeof finish !== 'function') {
610
+ // No split to use. The settlement drain still follows this, so the queue
611
+ // the single call leaves behind is expected rather than lost.
612
+ __emnapiWasmEnvCleanupYielding = true
613
+ try {
614
+ __prepareWasmEnvCleanup()
615
+ } finally {
616
+ __emnapiWasmEnvCleanupYielding = false
617
+ }
618
+ return
619
+ }
620
+ const workPending = exports?.napi_wasm_runtime_work_pending
621
+ // The in-flight flag stays raised across the turns below, so a `destroy()`
622
+ // from one of the JavaScript handlers they run is the same no-op it is inside
623
+ // the single call: the barrier is up and the runtime is mid-teardown, and
624
+ // destroying between the halves would strand exactly what this delivers.
625
+ __emnapiWasmEnvCleanupPreparing = true
626
+ let live
627
+ try {
628
+ live = begin()
629
+ } catch (error) {
630
+ __emnapiWasmEnvCleanupPreparing = false
631
+ throw error
632
+ }
633
+ __emnapiWasmEnvCleanupRan = true
634
+ const finishCleanup = () => {
635
+ if (__emnapiWasmEnvCleanupPrepared) {
636
+ // Already closed by a caller that could not yield — the 'exit' teardown
637
+ // reached `__prepareWasmEnvCleanup` while this poll was parked. `…_finish`
638
+ // is idempotent, but the flags it lowers are not: running it again here
639
+ // would clear a `preparing` some later barrier had raised.
640
+ return
641
+ }
642
+ __finishParkedWasmEnvCleanup = undefined
643
+ try {
644
+ finish()
645
+ } finally {
646
+ __emnapiWasmEnvCleanupPreparing = false
647
+ }
648
+ __emnapiWasmEnvCleanupPrepared = true
649
+ }
650
+ if (!live || typeof workPending !== 'function') {
651
+ finishCleanup()
652
+ return
653
+ }
654
+ // Publish the closer before yielding: from here until `finishCleanup` runs,
655
+ // a caller that cannot yield is entitled to end this handshake itself.
656
+ __finishParkedWasmEnvCleanup = finishCleanup
657
+ return (async () => {
658
+ // Unbounded, exactly like the async-work drain below. The wait ends when
659
+ // the addon reports its runtime work finished; the turns spent here are
660
+ // what let that happen at all.
661
+ const pace = __createWasmRuntimePollPace()
662
+ for (;;) {
663
+ await __yieldWasmRuntimePollTurn(pace)
664
+ try {
665
+ if (!workPending()) {
666
+ return
667
+ }
668
+ } catch {
669
+ // A trap is the only way this fails, and a trapped instance has no
670
+ // reachable work left. Stop polling and finish.
671
+ return
672
+ }
673
+ }
674
+ })().then(finishCleanup, finishCleanup)
675
+ }
676
+
677
+ // Turns to wait for while the addon still reports queued settlements. Reaching
678
+ // zero is the only success. A counter still nonzero at this bound rejects the
679
+ // disposal as retryable (`ERR_NAPI_WASI_CLEANUP_PENDING`) rather than
680
+ // destroying the context over a still-queued settlement — the wait stays
681
+ // bounded either way.
682
+ const __WASM_ENV_CLEANUP_DRAIN_TURNS = 128
683
+ // Without `napi_wasm_env_cleanup_pending` the queue is not observable. Fall
684
+ // back to the number of turns @emnapi/core needs to coalesce and dispatch a
685
+ // call made on this thread (two), plus a margin.
686
+ const __WASM_ENV_CLEANUP_BLIND_DRAIN_TURNS = 4
687
+
688
+ /**
689
+ * `napi_prepare_wasm_env_cleanup` only *queues* the promise settlements of the
690
+ * tasks it cancelled: `napi_call_threadsafe_function` appends to the
691
+ * threadsafe-function queue, and @emnapi/core dispatches that queue from a
692
+ * macrotask — two coalescing turns later, even for a call made on this very
693
+ * thread. `Context.destroy()` then runs the threadsafe function's cleanup hook,
694
+ * which drains the queue with a null env and *discards* whatever is still in it.
695
+ *
696
+ * So destroying without yielding first strands exactly the promises the barrier
697
+ * exists to settle. Yield real event-loop turns until the addon reports the
698
+ * queue empty; microtask checkpoints cannot help, no number of them lets a
699
+ * macrotask run.
700
+ *
701
+ * Returns nothing when there is nothing to wait for, which keeps disposal
702
+ * synchronous in the common case.
703
+ *
704
+ * The "already drained" flag is set only once a wait has actually finished.
705
+ * Scheduling a macrotask can fail — a host-provided or patched `setImmediate`
706
+ * that throws is enough — and a disposal that rejects stays retryable, so
707
+ * marking the drain complete up front would make the retry skip it and destroy
708
+ * the context with the barrier's settlements still queued.
709
+ *
710
+ * A wait that runs out of turns with the counter still nonzero rejects with
711
+ * `ERR_NAPI_WASI_CLEANUP_PENDING` for the same reason: at that point
712
+ * "finished" is indistinguishable from the stranding above, and destroying
713
+ * would discard the very settlement the wait was for. The rejection leaves the
714
+ * flag unset and disposal retryable.
715
+ */
716
+ function __drainWasmEnvCleanup() {
717
+ if (__emnapiWasmEnvCleanupDrained || !__emnapiWasmEnvCleanupRan) {
718
+ return
719
+ }
720
+ if (__emnapiWasmEnvCleanupDrainPromise) {
721
+ return __emnapiWasmEnvCleanupDrainPromise
722
+ }
723
+ const pending = __napiInstance?.exports?.napi_wasm_env_cleanup_pending
724
+ const observable = typeof pending === 'function'
725
+ if (observable) {
726
+ let queued
727
+ try {
728
+ queued = pending()
729
+ } catch {
730
+ __emnapiWasmEnvCleanupDrained = true
731
+ return
732
+ }
733
+ if (!queued) {
734
+ __emnapiWasmEnvCleanupDrained = true
735
+ return
736
+ }
737
+ }
738
+ const limit = observable
739
+ ? __WASM_ENV_CLEANUP_DRAIN_TURNS
740
+ : __WASM_ENV_CLEANUP_BLIND_DRAIN_TURNS
741
+ const drainPromise = (async () => {
742
+ let queued = 0
743
+ for (let turn = 0; turn < limit; turn++) {
744
+ await new Promise((resolve) => {
745
+ __scheduleMacrotask(resolve)
746
+ })
747
+ if (!observable) {
748
+ continue
749
+ }
750
+ try {
751
+ queued = pending()
752
+ } catch {
753
+ return
754
+ }
755
+ if (!queued) {
756
+ return
757
+ }
758
+ }
759
+ if (!observable) {
760
+ // Blind wait: without `napi_wasm_env_cleanup_pending` the bound IS the
761
+ // contract — there is nothing to consult, so finishing the turns is
762
+ // finishing the drain.
763
+ return
764
+ }
765
+ // The counter is still nonzero after every turn the bound allows. The wait
766
+ // stays bounded — but claiming success here would be indistinguishable from
767
+ // the stranding this drain exists to prevent: disposal would go on to
768
+ // destroy the context, whose cleanup hook discards the still-queued
769
+ // settlement with a null env, and the promise it was for hangs forever.
770
+ // Reject instead, as a retryable cleanup failure: the drained flag stays
771
+ // unset, dispose() (and the rollback) decline to destroy, and a later
772
+ // dispose() runs the drain again — by which time the queue has usually been
773
+ // delivered. A counter that is somehow stuck nonzero therefore costs each
774
+ // attempt at most another bounded wait and a rejection, never a stranded
775
+ // promise; the process-exit teardown still reclaims the context.
776
+ const drainError = new Error(
777
+ 'the wasm environment still reports ' +
778
+ queued +
779
+ ' queued settlement(s) after ' +
780
+ limit +
781
+ ' event-loop turns; the context was not destroyed - retry dispose() to wait for the queue again',
782
+ )
783
+ drainError.code = 'ERR_NAPI_WASI_CLEANUP_PENDING'
784
+ throw drainError
785
+ })().then(
786
+ (value) => {
787
+ // Set only when the wait actually finished AND the queue was seen empty
788
+ // (or is unobservable): a drain that timed out with settlements still
789
+ // queued rejects above and must stay repeatable.
790
+ __emnapiWasmEnvCleanupDrained = true
791
+ __emnapiWasmEnvCleanupDrainPromise = undefined
792
+ return value
793
+ },
794
+ (error) => {
795
+ __emnapiWasmEnvCleanupDrainPromise = undefined
796
+ throw error
797
+ },
798
+ )
799
+ __emnapiWasmEnvCleanupDrainPromise = drainPromise
800
+ return drainPromise
801
+ }
802
+
803
+ function __destroyEmnapiContext() {
804
+ if (__emnapiContextDestroyed || __emnapiContext === undefined) {
805
+ __emnapiContextDestroyed = true
806
+ return
807
+ }
808
+ if (__emnapiContextDestroyPromise) {
809
+ return __emnapiContextDestroyPromise
810
+ }
811
+
812
+ __prepareWasmEnvCleanup()
813
+ if (__isPreparingWasmEnvCleanup()) {
814
+ // Reached from inside the synchronous barrier — a promise hook one of the
815
+ // settlements above ran, which is the reentrancy the destroy wrapper
816
+ // exists for. `Context.destroy()` below would hit that wrapper's in-flight
817
+ // no-op and answer `undefined`, and recording that as a completed destroy
818
+ // is what makes the frame that *did* start the barrier skip the real one
819
+ // afterwards, leaving the context retained with its cleanup hooks unrun.
820
+ // Refuse instead: nothing is flagged, and that frame destroys for real the
821
+ // moment it returns. The deferred loader carries the same backstop. A
822
+ // parked handshake cannot get here — `__prepareWasmEnvCleanup` closes one
823
+ // rather than skipping it.
824
+ return
825
+ }
826
+ const result = __emnapiContext.destroy()
827
+ if (!__isThenable(result)) {
828
+ __emnapiContextDestroyed = true
829
+ return
830
+ }
831
+
832
+ const destroyPromise = Promise.resolve(result).then(
833
+ (value) => {
834
+ __emnapiContextDestroyed = true
835
+ return value
836
+ },
837
+ (error) => {
838
+ __emnapiContextDestroyPromise = undefined
839
+ throw error
840
+ },
841
+ )
842
+ __emnapiContextDestroyPromise = destroyPromise
843
+ return destroyPromise
844
+ }
845
+
846
+ /**
847
+ * Holds the event loop open until `work` settles.
848
+ *
849
+ * Nothing else can: the pool workers are deliberately unreferenced so an idle
850
+ * binding cannot keep a process alive, and referencing them again for the
851
+ * termination does not hold either — emnapi unreferences a worker the moment it
852
+ * reports `async-thread-ready`, which for a worker that was still starting
853
+ * lands *after* the termination began. Without a handle of its own, an
854
+ * `await dispose()` with nothing else pending exits the process with its
855
+ * promise unsettled, and everything after the `await` is skipped.
856
+ *
857
+ * The timer is cleared as soon as the work settles, so this never outlives the
858
+ * disposal that asked for it.
859
+ */
860
+ function __keepEventLoopAliveUntil(work) {
861
+ const setTimer = globalThis.setInterval
862
+ const clearTimer = globalThis.clearInterval
863
+ if (typeof setTimer !== 'function' || typeof clearTimer !== 'function') {
864
+ return work
865
+ }
866
+ let timer
867
+ try {
868
+ timer = setTimer(function () {}, 50)
869
+ } catch {
870
+ return work
871
+ }
872
+ const release = function () {
873
+ try {
874
+ clearTimer(timer)
875
+ } catch {}
876
+ }
877
+ return work.then(
878
+ (value) => {
879
+ release()
880
+ return value
881
+ },
882
+ (error) => {
883
+ release()
884
+ throw error
885
+ },
886
+ )
887
+ }
888
+
889
+ // How often to re-read `napi_wasm_async_work_pending` while waiting. The wait
890
+ // ends when the addon reports zero, so this only decides how promptly disposal
891
+ // notices — not how long it waits.
892
+ const __WASI_ASYNC_WORK_POLL_INTERVAL_MS = 1
893
+
894
+ /**
895
+ * Settles this addon's outstanding `napi_async_work` before the teardown that
896
+ * would strand it.
897
+ *
898
+ * `napi_prepare_wasm_env_cleanup` does not cover async work, and nothing about
899
+ * it is observable from JavaScript: the threadless archive resolves
900
+ * `napi_*_async_work` through the `@emnapi/core` plugins, but the threaded one
901
+ * links the C `async_work.c` on the uv threadpool, so there the wasm neither
902
+ * imports nor exports those symbols and the only brackets a loader could watch
903
+ * (`_emnapi_ctx_*_waiting_request_counter`) are shared with threadsafe
904
+ * functions. The addon is the one place both flavors go through, so it answers
905
+ * for both, through the same kind of handshake the settlement drain uses:
906
+ *
907
+ * - `napi_wasm_cancel_pending_async_work()` cancels what no thread has
908
+ * started. Those completion callbacks run with `napi_cancelled`, which
909
+ * napi-rs turns into a promise rejected with an `AbortError`.
910
+ * - `napi_wasm_async_work_pending()` counts what is still owed a completion
911
+ * callback. Work already executing refuses cancellation and stays counted
912
+ * until it finishes normally — which it can, because this runs before the
913
+ * barrier, before `Context.destroy()` and before anything is terminated.
914
+ *
915
+ * Both exports are optional: an addon built against a napi crate that predates
916
+ * them drains nothing and keeps the previous behavior, exactly as the
917
+ * `napi_wasm_env_cleanup_pending` handshake degrades.
918
+ *
919
+ * Returns nothing when there is nothing outstanding, which keeps disposal
920
+ * synchronous in the common case. The promise it returns otherwise never
921
+ * rejects.
922
+ *
923
+ * The wait has no deadline, and that is the point: giving up would destroy the
924
+ * environment with a completion callback still owed, which is the stranding
925
+ * this exists to prevent. A task whose `execute` never returns already keeps an
926
+ * *undisposed* process alive in exactly the same way, so disposal inherits that
927
+ * rather than inventing a bound it cannot honor.
928
+ *
929
+ * Safe to call from inside a completion callback, which is reachable: settling
930
+ * a task runs addon code that can re-enter JavaScript — a setter on the value
931
+ * being handed back, a threadsafe-function callback — and that JavaScript can
932
+ * call `dispose()`. Two things make it terminate rather than wait on itself:
933
+ *
934
+ * - The addon keeps a work registered until its completion callback
935
+ * *finishes*, so the count read here is at least one and this takes the
936
+ * polling path instead of declaring the environment drained and tearing it
937
+ * down from inside the frame that is still settling a promise.
938
+ * - The poll is a timer, so it cannot run until the callback has returned to
939
+ * the host — by which time that work has left the registry. The count the
940
+ * next poll reads is the one taken after the callback finished.
941
+ *
942
+ * `__disposeWasiBinding` hands every caller the same in-flight promise, so the
943
+ * nested call joins this disposal rather than starting a second one.
944
+ */
945
+ function __drainWasiAsyncWork() {
946
+ if (__wasiAsyncWorkDrainPromise !== undefined) {
947
+ return __wasiAsyncWorkDrainPromise
948
+ }
949
+ const exports = __napiInstance?.exports
950
+ const pending = exports?.napi_wasm_async_work_pending
951
+ const cancelPending = exports?.napi_wasm_cancel_pending_async_work
952
+ if (typeof pending !== 'function' || typeof cancelPending !== 'function') {
953
+ return
954
+ }
955
+
956
+ const readPending = () => {
957
+ try {
958
+ return pending()
959
+ } catch (error) {
960
+ // A trap is the only way this call fails: it reads a counter and cannot
961
+ // allocate or call back into JavaScript. A trapped instance can no longer
962
+ // run anything, so its outstanding work is unreachable by definition —
963
+ // there is nothing left to wait for, and refusing to dispose would only
964
+ // keep a dead instance and its stuck counter alive. Best-effort here is
965
+ // the honest answer, and it is what disposal did before this drain
966
+ // existed.
967
+ //
968
+ // Only a trap. Anything else means the export is not what this loader
969
+ // thinks it is, which is a defect worth surfacing rather than disposing
970
+ // over.
971
+ if (error instanceof globalThis.WebAssembly.RuntimeError) {
972
+ return 0
973
+ }
974
+ throw error
975
+ }
976
+ }
977
+
978
+ if (!readPending()) {
979
+ return
980
+ }
981
+ try {
982
+ cancelPending()
983
+ } catch {
984
+ // Cancellation is an optimization: it bounds the wait by the work already
985
+ // executing. Failing it only means waiting for the whole queue instead.
986
+ }
987
+ if (!readPending()) {
988
+ return
989
+ }
990
+
991
+ const drainPromise = __keepEventLoopAliveUntil(
992
+ (async () => {
993
+ while (readPending()) {
994
+ await new Promise((resolve) => {
995
+ __scheduleTimer(resolve, __WASI_ASYNC_WORK_POLL_INTERVAL_MS)
996
+ })
997
+ }
998
+ })(),
999
+ ).then(
1000
+ () => {
1001
+ __wasiAsyncWorkDrainPromise = undefined
1002
+ },
1003
+ (error) => {
1004
+ // A wait that could not run is not a wait that finished. The only way
1005
+ // here is a host whose timers and macrotask primitives all refuse, and
1006
+ // the work is still outstanding — reporting success would destroy the
1007
+ // environment over it, which is the stranding this exists to prevent.
1008
+ // Reject instead: disposal stays retryable, and the context is not
1009
+ // destroyed. Clearing the memo first is what makes the retry re-run this.
1010
+ __wasiAsyncWorkDrainPromise = undefined
1011
+ throw error
1012
+ },
1013
+ )
1014
+ __wasiAsyncWorkDrainPromise = drainPromise
1015
+ return drainPromise
1016
+ }
1017
+
1018
+ /**
1019
+ * `@emnapi/wasi-threads` counts a worker exit as expected only when its own
1020
+ * thread manager performed the termination. A bare `worker.terminate()` reaches
1021
+ * the manager's `exit` listener instead, which reports
1022
+ * `worker (tid = N) sent an error! ... stopped with exit code 1` and rethrows
1023
+ * inside the emit — aborting the `once('exit')` that backs the terminate
1024
+ * promise, so disposal never settles and the process dies with an uncaught
1025
+ * exception. Mark the termination through the manager first.
1026
+ *
1027
+ * The manager comes from `__getWasiThreadManager`, not from `__napiModule`:
1028
+ * the initialization rollback runs on the one path where instantiation never
1029
+ * returned, so `__napiModule` is still undefined there while the workers it
1030
+ * spawned are already registered and loaded.
1031
+ *
1032
+ * Not `terminateAllThreads()`: that one recreates the pool it just shut down.
1033
+ */
1034
+ function __terminateWasiWorkers() {
1035
+ const cleanupErrors = []
1036
+ const pending = []
1037
+ const threadManager = __getWasiThreadManager()
1038
+
1039
+ for (const worker of __wasiWorkers) {
1040
+ let result
1041
+ try {
1042
+ if (threadManager) {
1043
+ threadManager.terminateWorker(worker)
1044
+ // `terminateWorker` leaves behind a reporter that logs every message
1045
+ // still queued on the port, which Node flushes on exit. Nothing is
1046
+ // listening for those any more.
1047
+ worker.onmessage = undefined
1048
+ }
1049
+ result = worker.terminate()
1050
+ } catch (error) {
1051
+ cleanupErrors.push(error)
1052
+ continue
1053
+ }
1054
+ if (__isThenable(result)) {
1055
+ pending.push(
1056
+ Promise.resolve(result).then(
1057
+ () => {
1058
+ __wasiWorkers.delete(worker)
1059
+ },
1060
+ (error) => {
1061
+ cleanupErrors.push(error)
1062
+ },
1063
+ ),
1064
+ )
1065
+ } else {
1066
+ __wasiWorkers.delete(worker)
1067
+ }
1068
+ }
1069
+
1070
+ const finish = () => {
1071
+ if (cleanupErrors.length > 0) {
1072
+ throw __createCleanupError(
1073
+ cleanupErrors,
1074
+ 'Failed to terminate WASI workers',
1075
+ )
1076
+ }
1077
+ }
1078
+ return pending.length > 0
1079
+ ? __keepEventLoopAliveUntil(Promise.all(pending)).then(finish)
1080
+ : finish()
1081
+ }
1082
+
1083
+ function __finishWasiDisposal() {
1084
+ const workerResult = __terminateWasiWorkers()
1085
+ if (__isThenable(workerResult)) {
1086
+ return Promise.resolve(workerResult).then(__completeWasiDisposal)
1087
+ }
1088
+ return __completeWasiDisposal()
1089
+ }
1090
+
1091
+ function __continueWasiDisposal() {
1092
+ const destroyResult = __destroyEmnapiContext()
1093
+ if (__isThenable(destroyResult)) {
1094
+ return Promise.resolve(destroyResult).then(__finishWasiDisposal)
1095
+ }
1096
+ return __finishWasiDisposal()
1097
+ }
1098
+
1099
+ function __drainWasmEnvForWasiDisposal() {
1100
+ const drainResult = __drainWasmEnvCleanup()
1101
+ if (__isThenable(drainResult)) {
1102
+ return Promise.resolve(drainResult).then(__continueWasiDisposal)
1103
+ }
1104
+ return __continueWasiDisposal()
1105
+ }
1106
+
1107
+ function __cleanUpWasmEnvForWasiDisposal() {
1108
+ // Run the pre-teardown barrier — yielding the turns its two-phase form asks
1109
+ // for, when the addon has one — then let the settlements it queued actually
1110
+ // reach JavaScript, and only then destroy the environment. Doing any two of
1111
+ // these back to back is what strands them.
1112
+ const prepareResult = __prepareWasmEnvCleanupWithTurns()
1113
+ if (__isThenable(prepareResult)) {
1114
+ return Promise.resolve(prepareResult).then(__drainWasmEnvForWasiDisposal)
1115
+ }
1116
+ return __drainWasmEnvForWasiDisposal()
1117
+ }
1118
+
1119
+ function __startWasiDisposal() {
1120
+ // Outstanding `napi_async_work` goes first, while the environment is still
1121
+ // completely live: the completion callbacks run addon code, and everything
1122
+ // after this point takes that away from them — the barrier shuts the async
1123
+ // runtime down, `Context.destroy()` stops JavaScript calls, and terminating
1124
+ // the pool threads removes what would have reported the work finished.
1125
+ const asyncWorkResult = __drainWasiAsyncWork()
1126
+ if (__isThenable(asyncWorkResult)) {
1127
+ return Promise.resolve(asyncWorkResult).then(
1128
+ __cleanUpWasmEnvForWasiDisposal,
1129
+ )
1130
+ }
1131
+ return __cleanUpWasmEnvForWasiDisposal()
1132
+ }
1133
+
1134
+ /**
1135
+ * Disposes this generated WASI binding.
1136
+ *
1137
+ * Access this function with:
1138
+ * binding[Symbol.for('napi.rs.wasi.dispose')]()
1139
+ */
1140
+ function __disposeWasiBinding() {
1141
+ if (__wasiDisposePromise) {
1142
+ return __wasiDisposePromise
1143
+ }
1144
+ if (__wasiDisposed) {
1145
+ return Promise.resolve()
1146
+ }
1147
+
1148
+ let resolveDispose
1149
+ let rejectDispose
1150
+ const disposePromise = new Promise((resolve, reject) => {
1151
+ resolveDispose = resolve
1152
+ rejectDispose = reject
1153
+ })
1154
+ __wasiDisposePromise = disposePromise
1155
+
1156
+ let result
1157
+ try {
1158
+ result = __startWasiDisposal()
1159
+ } catch (error) {
1160
+ __wasiDisposePromise = undefined
1161
+ rejectDispose(error)
1162
+ return disposePromise
1163
+ }
1164
+
1165
+ Promise.resolve(result).then(
1166
+ (value) => {
1167
+ __wasiDisposed = true
1168
+ resolveDispose(value)
1169
+ },
1170
+ (error) => {
1171
+ __wasiDisposePromise = undefined
1172
+ rejectDispose(error)
1173
+ },
1174
+ )
1175
+ return disposePromise
1176
+ }
1177
+
1178
+ function __publishWasiDispose(exports) {
1179
+ Object.defineProperty(exports, __wasiDisposeSymbol, {
1180
+ configurable: false,
1181
+ enumerable: false,
1182
+ value: __disposeWasiBinding,
1183
+ writable: false,
1184
+ })
1185
+ }
1186
+
1187
+ function __finishWasiInitializationRollback(cleanupErrors) {
1188
+ let workerResult
1189
+ try {
1190
+ workerResult = __terminateWasiWorkers()
1191
+ } catch (cleanupError) {
1192
+ cleanupErrors.push(cleanupError)
1193
+ return cleanupErrors
1194
+ }
1195
+ if (__isThenable(workerResult)) {
1196
+ return Promise.resolve(workerResult)
1197
+ .catch((cleanupError) => {
1198
+ cleanupErrors.push(cleanupError)
1199
+ })
1200
+ .then(() => cleanupErrors)
1201
+ }
1202
+ return cleanupErrors
1203
+ }
1204
+
1205
+ function __destroyContextForWasiRollback(cleanupErrors) {
1206
+ let destroyResult
1207
+ try {
1208
+ destroyResult = __destroyEmnapiContext()
1209
+ } catch (cleanupError) {
1210
+ cleanupErrors.push(cleanupError)
1211
+ return __finishWasiInitializationRollback(cleanupErrors)
1212
+ }
1213
+ if (__isThenable(destroyResult)) {
1214
+ return Promise.resolve(destroyResult)
1215
+ .catch((cleanupError) => {
1216
+ cleanupErrors.push(cleanupError)
1217
+ })
1218
+ .then(() => __finishWasiInitializationRollback(cleanupErrors))
1219
+ }
1220
+ return __finishWasiInitializationRollback(cleanupErrors)
1221
+ }
1222
+
1223
+ /**
1224
+ * Leaves a rollback that could not reach the queued settlements undestroyed, and
1225
+ * hands it to whatever this flavor has that can still reclaim it.
1226
+ */
1227
+ function __retainFailedWasiRollback(cleanupErrors) {
1228
+ try {
1229
+ __retainWasiRollbackForRetry()
1230
+ } catch (cleanupError) {
1231
+ cleanupErrors.push(cleanupError)
1232
+ }
1233
+ return cleanupErrors
1234
+ }
1235
+
1236
+ /**
1237
+ * Initialization can fail *after* registration has already run, and registration
1238
+ * runs with a live environment: a module-init hook can start async work and then
1239
+ * return an error, and the promise it created may already have escaped into
1240
+ * JavaScript. The barrier cancels that work and *queues* the settlement, so this
1241
+ * path needs the same drain the ordinary disposal does — destroying without
1242
+ * yielding discards the queue with a null env and strands the promise.
1243
+ *
1244
+ * Stays synchronous when nothing is queued, which covers every failure before
1245
+ * `beforeInit`: there is no instance to run the barrier on, so nothing to drain.
1246
+ *
1247
+ * A barrier or drain that did *not* finish stops the rollback short of
1248
+ * destroying, which is what `dispose()` already does — a rejected drain there
1249
+ * never reaches `__continueWasiDisposal`. Destroying anyway is the worse of the
1250
+ * two trades, and not because of what it saves:
1251
+ *
1252
+ * - It cannot deliver the settlements. `Context.destroy()` runs the
1253
+ * threadsafe function's cleanup hook, which drains the queue with a null env
1254
+ * and discards it, so a promise that already escaped into JavaScript hangs
1255
+ * forever with nothing left that could ever settle it.
1256
+ * - It saves less than it looks. `Context.destroy()` stops JavaScript calls
1257
+ * and runs cleanup hooks; it does not free the wasm instance or its Memory,
1258
+ * which this module's scope holds either way. What stopping short retains is
1259
+ * the emnapi context's bookkeeping and its un-run cleanup hooks.
1260
+ * - Retry is not theoretical. A rollback that records a cleanup error is
1261
+ * already kept in the process-wide registry above, so re-`require()`ing this
1262
+ * file replays it instead of re-instantiating — and the `6e15de6f` flag fix
1263
+ * means the replay drains again rather than skipping it. Destroying first is
1264
+ * what makes that retained record useless.
1265
+ *
1266
+ * The residual cost is honest: the CJS flavor hands the context to its
1267
+ * `process.on('exit')` teardown, so a process that never retries still reclaims
1268
+ * it on the way out. The ESM browser flavor has no equivalent — a module that
1269
+ * throws while evaluating is permanently errored, so re-importing rethrows
1270
+ * without re-running this file — and there the context stays until the realm
1271
+ * goes away. That is the deliberate choice: a hung promise is a silent liveness
1272
+ * bug with no upper bound, while the retained bookkeeping is bounded by the page.
1273
+ */
1274
+ function __rollbackWasiInitialization() {
1275
+ // The environment teardown this rollback performs, kept nested so it cannot
1276
+ // be reached without the async-work drain below running first.
1277
+ function __rollbackWasmEnvForWasiInitialization() {
1278
+ const cleanupErrors = []
1279
+ let prepareResult
1280
+ try {
1281
+ prepareResult = __prepareWasmEnvCleanupWithTurns()
1282
+ } catch (cleanupError) {
1283
+ cleanupErrors.push(cleanupError)
1284
+ return __retainFailedWasiRollback(cleanupErrors)
1285
+ }
1286
+ if (__isThenable(prepareResult)) {
1287
+ return Promise.resolve(prepareResult).then(
1288
+ () => __drainWasmEnvForWasiRollback(cleanupErrors),
1289
+ (cleanupError) => {
1290
+ cleanupErrors.push(cleanupError)
1291
+ return __retainFailedWasiRollback(cleanupErrors)
1292
+ },
1293
+ )
1294
+ }
1295
+ return __drainWasmEnvForWasiRollback(cleanupErrors)
1296
+ }
1297
+
1298
+ // The settlement drain of the rollback above, reached either straight away or
1299
+ // after the barrier's two-phase form has yielded its turns. A barrier that
1300
+ // did not finish never gets here: it retains instead, exactly as a drain that
1301
+ // did not finish does.
1302
+ function __drainWasmEnvForWasiRollback(cleanupErrors) {
1303
+ let drainResult
1304
+ try {
1305
+ drainResult = __drainWasmEnvCleanup()
1306
+ } catch (cleanupError) {
1307
+ cleanupErrors.push(cleanupError)
1308
+ return __retainFailedWasiRollback(cleanupErrors)
1309
+ }
1310
+ if (__isThenable(drainResult)) {
1311
+ return Promise.resolve(drainResult).then(
1312
+ () => __destroyContextForWasiRollback(cleanupErrors),
1313
+ (cleanupError) => {
1314
+ cleanupErrors.push(cleanupError)
1315
+ return __retainFailedWasiRollback(cleanupErrors)
1316
+ },
1317
+ )
1318
+ }
1319
+ return __destroyContextForWasiRollback(cleanupErrors)
1320
+ }
1321
+
1322
+ // Same reason as `__startWasiDisposal`: a module-init hook can start async
1323
+ // work before the load goes on to fail, and this rollback tears down exactly
1324
+ // what those completions need. Settle them while everything is still live,
1325
+ // before the barrier and the teardown above take that away.
1326
+ //
1327
+ // A drain that could not finish leaves async work possibly outstanding, and
1328
+ // destroying the context over it would strand exactly what this rollback is
1329
+ // there to settle. Stop short and retain instead — the same trade
1330
+ // `__rollbackWasmEnvForWasiInitialization` makes for the settlement drain, so
1331
+ // the context stays reclaimable by a retry or by this flavor's own
1332
+ // last-resort teardown.
1333
+ const __retainAfterAsyncWorkDrainFailure = (cleanupError) =>
1334
+ __retainFailedWasiRollback([cleanupError])
1335
+ let asyncWorkResult
1336
+ try {
1337
+ asyncWorkResult = __drainWasiAsyncWork()
1338
+ } catch (cleanupError) {
1339
+ return __retainAfterAsyncWorkDrainFailure(cleanupError)
1340
+ }
1341
+ if (__isThenable(asyncWorkResult)) {
1342
+ return Promise.resolve(asyncWorkResult).then(
1343
+ __rollbackWasmEnvForWasiInitialization,
1344
+ __retainAfterAsyncWorkDrainFailure,
1345
+ )
1346
+ }
1347
+ return __rollbackWasmEnvForWasiInitialization()
1348
+ }
1349
+
1350
+ // A view of the addon's crash flag, one word of the shared wasm memory, for the
1351
+ // pool workers: they raise it when their wasm thread dies, and the shutdown
1352
+ // waits inside the cleanup calls on this thread then trap instead of waiting on
1353
+ // the dead thread for good. Undefined for an addon built with an older napi.
1354
+ let __wasiAddonCrashFlag
1355
+
1356
+ function __captureWasiAddonCrashFlag(instance) {
1357
+ try {
1358
+ const getAddress = instance.exports.napi_wasm_thread_crash_flag_address
1359
+ if (typeof getAddress !== 'function') {
1360
+ return
1361
+ }
1362
+ const address = getAddress() >>> 0
1363
+ const buffer = __sharedMemory.buffer
1364
+ if (address === 0 || address % 4 !== 0 || address + 4 > buffer.byteLength) {
1365
+ return
1366
+ }
1367
+ __wasiAddonCrashFlag = new Int32Array(buffer, address, 1)
1368
+ } catch {}
1369
+ }
1370
+
1371
+ function __shareWasiAddonCrashFlag(worker) {
1372
+ if (__wasiAddonCrashFlag === undefined) {
1373
+ return
1374
+ }
1375
+ try {
1376
+ worker.postMessage({ __napiRsAddonCrashFlag: __wasiAddonCrashFlag })
1377
+ } catch {}
1378
+ }
1379
+
1380
+ let __wasiModule
1381
+ let __napiModule
1382
+
1383
+ try {
1384
+ __emnapiContext = __wrapEmnapiContextDestroyForSettlement(
1385
+ __emnapiCreateContext({ autoDestroy: false }),
1386
+ __prepareWasmEnvCleanup,
1387
+ __isPreparingWasmEnvCleanup,
1388
+ )
1389
+ __emnapiContext.suppressDestroy()
1390
+ __emnapiContext.features.Buffer = Buffer
1391
+
1392
+ ;({
1393
+ instance: __napiInstance,
1394
+ module: __wasiModule,
1395
+ napiModule: __napiModule,
1396
+ } = await __emnapiInstantiateNapiModule(__wasmFile, {
1397
+ context: __emnapiContext,
1398
+ asyncWorkPoolSize: __asyncWorkPoolSize,
1399
+ reuseWorker: { size: __asyncWorkPoolSize + __workerPoolSize },
1400
+ plugins: [
1401
+ __captureWasiThreadManager,
1402
+ __emnapiAsyncWorkPlugin,
1403
+ __emnapiTSFNPlugin,
1404
+ ],
1405
+ wasi: __wasi,
1406
+ onCreateWorker() {
1407
+ const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
1408
+ type: 'module',
1409
+ })
1410
+ __wasiWorkers.add(worker)
1411
+ __shareWasiAddonCrashFlag(worker)
1412
+ worker.addEventListener('message', __wasmCreateOnMessageForFsProxy(__fs))
1413
+
1414
+ worker.addEventListener('message', (event) => {
1415
+ if (event.data && typeof event.data === 'object' && event.data.type === 'error') {
1416
+ const __CustomEvent = globalThis.CustomEvent
1417
+ if (
1418
+ typeof globalThis.dispatchEvent === 'function' &&
1419
+ typeof __CustomEvent === 'function'
1420
+ ) {
1421
+ globalThis.dispatchEvent(
1422
+ new __CustomEvent('napi-rs-worker-error', { detail: event.data }),
1423
+ )
1424
+ }
1425
+ }
1426
+ })
1427
+
1428
+ return worker
1429
+ },
1430
+ overwriteImports(importObject) {
1431
+ importObject.env = {
1432
+ ...importObject.env,
1433
+ ...importObject.napi,
1434
+ ...importObject.emnapi,
1435
+ memory: __sharedMemory,
1436
+ }
1437
+ return importObject
1438
+ },
1439
+ beforeInit({ instance }) {
1440
+ __napiInstance = instance
1441
+ __captureWasiAddonCrashFlag(instance)
1442
+ for (const worker of __wasiWorkers) {
1443
+ __shareWasiAddonCrashFlag(worker)
1444
+ }
1445
+ for (const name of Object.keys(instance.exports)) {
1446
+ if (name.startsWith('__napi_register__')) {
1447
+ instance.exports[name]()
1448
+ }
1449
+ }
1450
+ },
1451
+ }))
1452
+ __publishWasiDispose(__napiModule.exports)
1453
+ // The default export hands out this object; a named module export does not
1454
+ // travel with it, so carry the marker on the binding itself too. After the
1455
+ // host install, which hands the same object to addon-provided registration
1456
+ // functions that may put anything on it, and inside this `try`, so a claimed
1457
+ // name fails the load through the rollback below rather than past it.
1458
+ __napiStampBindingTarget(__napiModule.exports, __napiBindingTarget)
1459
+ } catch (error) {
1460
+ const cleanupErrors = await __rollbackWasiInitialization()
1461
+ throw __attachCleanupErrors(error, cleanupErrors)
1462
+ }
72
1463
  export default __napiModule.exports
73
1464
  export const Assets = __napiModule.exports.Assets
74
1465
  export const AsyncDependenciesBlock = __napiModule.exports.AsyncDependenciesBlock
@@ -78,17 +1469,14 @@ export const ChunkGroup = __napiModule.exports.ChunkGroup
78
1469
  export const Chunks = __napiModule.exports.Chunks
79
1470
  export const CodeGenerationResult = __napiModule.exports.CodeGenerationResult
80
1471
  export const CodeGenerationResults = __napiModule.exports.CodeGenerationResults
81
- export const ConcatenatedModule = __napiModule.exports.ConcatenatedModule
82
- export const ContextModule = __napiModule.exports.ContextModule
83
1472
  export const Dependency = __napiModule.exports.Dependency
84
- export const FileSystemDependencies = __napiModule.exports.FileSystemDependencies
85
1473
  export const Diagnostics = __napiModule.exports.Diagnostics
86
1474
  export const EntryDataDto = __napiModule.exports.EntryDataDto
87
1475
  export const EntryDataDTO = __napiModule.exports.EntryDataDTO
88
1476
  export const EntryDependency = __napiModule.exports.EntryDependency
89
1477
  export const EntryOptionsDto = __napiModule.exports.EntryOptionsDto
90
1478
  export const EntryOptionsDTO = __napiModule.exports.EntryOptionsDTO
91
- export const ExternalModule = __napiModule.exports.ExternalModule
1479
+ export const FileSystemDependencies = __napiModule.exports.FileSystemDependencies
92
1480
  export const JsCache = __napiModule.exports.JsCache
93
1481
  export const JsCompilation = __napiModule.exports.JsCompilation
94
1482
  export const JsCompiler = __napiModule.exports.JsCompiler
@@ -98,15 +1486,16 @@ export const JsCoordinator = __napiModule.exports.JsCoordinator
98
1486
  export const JsEntries = __napiModule.exports.JsEntries
99
1487
  export const JsExportsInfo = __napiModule.exports.JsExportsInfo
100
1488
  export const JsModuleGraph = __napiModule.exports.JsModuleGraph
1489
+ export const JsNativeSource = __napiModule.exports.JsNativeSource
101
1490
  export const JsResolver = __napiModule.exports.JsResolver
102
1491
  export const JsResolverFactory = __napiModule.exports.JsResolverFactory
103
1492
  export const JsStats = __napiModule.exports.JsStats
104
1493
  export const KnownBuildInfo = __napiModule.exports.KnownBuildInfo
105
- export const Module = __napiModule.exports.Module
106
1494
  export const ModuleGraphConnection = __napiModule.exports.ModuleGraphConnection
1495
+ export const Modules = __napiModule.exports.Modules
1496
+ export const NativeTimeInfoEntries = __napiModule.exports.NativeTimeInfoEntries
107
1497
  export const NativeWatcher = __napiModule.exports.NativeWatcher
108
1498
  export const NativeWatchResult = __napiModule.exports.NativeWatchResult
109
- export const NormalModule = __napiModule.exports.NormalModule
110
1499
  export const RawExternalItemFnCtx = __napiModule.exports.RawExternalItemFnCtx
111
1500
  export const ReadonlyResourceData = __napiModule.exports.ReadonlyResourceData
112
1501
  export const ResolverFactory = __napiModule.exports.ResolverFactory
@@ -116,16 +1505,48 @@ export const JsVirtualFileStore = __napiModule.exports.JsVirtualFileStore
116
1505
  export const async = __napiModule.exports.async
117
1506
  export const BuiltinPluginName = __napiModule.exports.BuiltinPluginName
118
1507
  export const cleanupGlobalTrace = __napiModule.exports.cleanupGlobalTrace
1508
+ export const concatenatedModuleGetModules = __napiModule.exports.concatenatedModuleGetModules
1509
+ export const concatenatedModuleGetRootModule = __napiModule.exports.concatenatedModuleGetRootModule
119
1510
  export const EnforceExtension = __napiModule.exports.EnforceExtension
120
1511
  export const EXPECTED_RSPACK_CORE_VERSION = __napiModule.exports.EXPECTED_RSPACK_CORE_VERSION
1512
+ export const externalModuleGetUserRequest = __napiModule.exports.externalModuleGetUserRequest
121
1513
  export const formatDiagnostic = __napiModule.exports.formatDiagnostic
122
1514
  export const JsLoaderState = __napiModule.exports.JsLoaderState
123
1515
  export const JsRspackSeverity = __napiModule.exports.JsRspackSeverity
124
1516
  export const loadBrowserslist = __napiModule.exports.loadBrowserslist
125
1517
  export const minify = __napiModule.exports.minify
126
1518
  export const minifySync = __napiModule.exports.minifySync
1519
+ export const moduleEmitFile = __napiModule.exports.moduleEmitFile
1520
+ export const moduleGetBlocks = __napiModule.exports.moduleGetBlocks
1521
+ export const moduleGetBuildInfo = __napiModule.exports.moduleGetBuildInfo
1522
+ export const moduleGetContext = __napiModule.exports.moduleGetContext
1523
+ export const moduleGetDependencies = __napiModule.exports.moduleGetDependencies
1524
+ export const moduleGetFactoryMeta = __napiModule.exports.moduleGetFactoryMeta
1525
+ export const moduleGetIdentifier = __napiModule.exports.moduleGetIdentifier
1526
+ export const moduleGetLayer = __napiModule.exports.moduleGetLayer
1527
+ export const moduleGetNameForCondition = __napiModule.exports.moduleGetNameForCondition
1528
+ export const moduleGetOriginalSource = __napiModule.exports.moduleGetOriginalSource
1529
+ export const moduleGetReadableIdentifier = __napiModule.exports.moduleGetReadableIdentifier
1530
+ export const moduleGetType = __napiModule.exports.moduleGetType
1531
+ export const moduleGetUseSimpleSourceMap = __napiModule.exports.moduleGetUseSimpleSourceMap
1532
+ export const moduleGetUseSourceMap = __napiModule.exports.moduleGetUseSourceMap
1533
+ export const ModuleKind = __napiModule.exports.ModuleKind
1534
+ export const moduleLibIdent = __napiModule.exports.moduleLibIdent
1535
+ export const moduleSetBuildInfo = __napiModule.exports.moduleSetBuildInfo
1536
+ export const moduleSetFactoryMeta = __napiModule.exports.moduleSetFactoryMeta
1537
+ export const moduleSize = __napiModule.exports.moduleSize
1538
+ export const normalModuleGetError = __napiModule.exports.normalModuleGetError
1539
+ export const normalModuleGetLoaders = __napiModule.exports.normalModuleGetLoaders
1540
+ export const normalModuleGetMatchResource = __napiModule.exports.normalModuleGetMatchResource
1541
+ export const normalModuleGetRawRequest = __napiModule.exports.normalModuleGetRawRequest
1542
+ export const normalModuleGetRequest = __napiModule.exports.normalModuleGetRequest
1543
+ export const normalModuleGetResource = __napiModule.exports.normalModuleGetResource
1544
+ export const normalModuleGetResourceResolveData = __napiModule.exports.normalModuleGetResourceResolveData
1545
+ export const normalModuleGetUserRequest = __napiModule.exports.normalModuleGetUserRequest
1546
+ export const normalModuleSetMatchResource = __napiModule.exports.normalModuleSetMatchResource
127
1547
  export const RawJavascriptParserCommonjsExports = __napiModule.exports.RawJavascriptParserCommonjsExports
128
1548
  export const RawRuleSetConditionType = __napiModule.exports.RawRuleSetConditionType
1549
+ export const RawSyncModuleIdsPluginMode = __napiModule.exports.RawSyncModuleIdsPluginMode
129
1550
  export const registerGlobalTrace = __napiModule.exports.registerGlobalTrace
130
1551
  export const RegisterJsTapKind = __napiModule.exports.RegisterJsTapKind
131
1552
  export const sync = __napiModule.exports.sync