@remedia/node 0.0.0-stage → 0.1.0-dev.0

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/native.js ADDED
@@ -0,0 +1,778 @@
1
+ /* eslint-disable */
2
+ // @ts-nocheck
3
+ /* auto-generated by NAPI-RS */
4
+
5
+ import { createRequire } from 'module'
6
+ const require = createRequire(import.meta.url)
7
+
8
+ const { readFileSync } = require('fs')
9
+ let nativeBinding = null
10
+ // Which artifact actually loaded. The WASI fallback chain overwrites it with
11
+ // the flavor it resolved; the late native retry below leaves it alone because
12
+ // it only runs while no WASI candidate has been loaded. The take-over check
13
+ // after the load-failure block can also set it.
14
+ let __napiLoadedBindingTarget = 'native'
15
+ // What this loader's own `requireNative()` calls returned. The check after
16
+ // the load-failure block compares it with `nativeBinding` to tell a binding
17
+ // this loader loaded from one that code outside it put in its place.
18
+ let __napiRequiredNativeBinding = null
19
+ const loadErrors = []
20
+
21
+ const isMusl = () => {
22
+ let musl = false
23
+ if (process.platform === 'linux') {
24
+ musl = isMuslFromFilesystem()
25
+ if (musl === null) {
26
+ musl = isMuslFromReport()
27
+ }
28
+ if (musl === null) {
29
+ musl = isMuslFromChildProcess()
30
+ }
31
+ }
32
+ return musl
33
+ }
34
+
35
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
36
+
37
+ const isMuslFromFilesystem = () => {
38
+ try {
39
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
40
+ } catch {
41
+ return null
42
+ }
43
+ }
44
+
45
+ const isMuslFromReport = () => {
46
+ let report = null
47
+ if (process.report && typeof process.report.getReport === 'function') {
48
+ process.report.excludeNetwork = true
49
+ report = process.report.getReport()
50
+ }
51
+ if (!report) {
52
+ return null
53
+ }
54
+ if (report.header && report.header.glibcVersionRuntime) {
55
+ return false
56
+ }
57
+ if (Array.isArray(report.sharedObjects)) {
58
+ if (report.sharedObjects.some(isFileMusl)) {
59
+ return true
60
+ }
61
+ }
62
+ return false
63
+ }
64
+
65
+ const isMuslFromChildProcess = () => {
66
+ try {
67
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
68
+ } catch (e) {
69
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
70
+ return false
71
+ }
72
+ }
73
+
74
+ function requireNative() {
75
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
76
+ try {
77
+ const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
78
+ // The override may be a generated WASI loader, which already reports its
79
+ // own flavor. Adopt it: `module.exports` aliases this object, so claiming
80
+ // 'native' would both misreport the artifact and overwrite the loader's
81
+ // marker through the alias.
82
+ __napiLoadedBindingTarget =
83
+ overrideBinding && typeof overrideBinding.__napiBindingTarget === 'string'
84
+ ? overrideBinding.__napiBindingTarget
85
+ : 'native'
86
+ return overrideBinding
87
+ } catch (err) {
88
+ loadErrors.push(err)
89
+ }
90
+ } else if (process.platform === 'android') {
91
+ if (process.arch === 'arm64') {
92
+ try {
93
+ return require('./node.android-arm64.node')
94
+ } catch (e) {
95
+ loadErrors.push(e)
96
+ }
97
+ try {
98
+ const binding = require('@remedia/node-android-arm64')
99
+ const bindingPackageVersion = require('@remedia/node-android-arm64/package.json').version
100
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
101
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
102
+ }
103
+ return binding
104
+ } catch (e) {
105
+ loadErrors.push(e)
106
+ }
107
+ } else if (process.arch === 'arm') {
108
+ try {
109
+ return require('./node.android-arm-eabi.node')
110
+ } catch (e) {
111
+ loadErrors.push(e)
112
+ }
113
+ try {
114
+ const binding = require('@remedia/node-android-arm-eabi')
115
+ const bindingPackageVersion = require('@remedia/node-android-arm-eabi/package.json').version
116
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
117
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
118
+ }
119
+ return binding
120
+ } catch (e) {
121
+ loadErrors.push(e)
122
+ }
123
+ } else {
124
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
125
+ }
126
+ } else if (process.platform === 'win32') {
127
+ if (process.arch === 'x64') {
128
+ if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
129
+ try {
130
+ return require('./node.win32-x64-gnu.node')
131
+ } catch (e) {
132
+ loadErrors.push(e)
133
+ }
134
+ try {
135
+ const binding = require('@remedia/node-win32-x64-gnu')
136
+ const bindingPackageVersion = require('@remedia/node-win32-x64-gnu/package.json').version
137
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
138
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
139
+ }
140
+ return binding
141
+ } catch (e) {
142
+ loadErrors.push(e)
143
+ }
144
+ } else {
145
+ try {
146
+ return require('./node.win32-x64-msvc.node')
147
+ } catch (e) {
148
+ loadErrors.push(e)
149
+ }
150
+ try {
151
+ const binding = require('@remedia/node-win32-x64-msvc')
152
+ const bindingPackageVersion = require('@remedia/node-win32-x64-msvc/package.json').version
153
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
154
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
155
+ }
156
+ return binding
157
+ } catch (e) {
158
+ loadErrors.push(e)
159
+ }
160
+ }
161
+ } else if (process.arch === 'ia32') {
162
+ try {
163
+ return require('./node.win32-ia32-msvc.node')
164
+ } catch (e) {
165
+ loadErrors.push(e)
166
+ }
167
+ try {
168
+ const binding = require('@remedia/node-win32-ia32-msvc')
169
+ const bindingPackageVersion = require('@remedia/node-win32-ia32-msvc/package.json').version
170
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
172
+ }
173
+ return binding
174
+ } catch (e) {
175
+ loadErrors.push(e)
176
+ }
177
+ } else if (process.arch === 'arm64') {
178
+ try {
179
+ return require('./node.win32-arm64-msvc.node')
180
+ } catch (e) {
181
+ loadErrors.push(e)
182
+ }
183
+ try {
184
+ const binding = require('@remedia/node-win32-arm64-msvc')
185
+ const bindingPackageVersion = require('@remedia/node-win32-arm64-msvc/package.json').version
186
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
187
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
188
+ }
189
+ return binding
190
+ } catch (e) {
191
+ loadErrors.push(e)
192
+ }
193
+ } else {
194
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
195
+ }
196
+ } else if (process.platform === 'darwin') {
197
+ try {
198
+ return require('./node.darwin-universal.node')
199
+ } catch (e) {
200
+ loadErrors.push(e)
201
+ }
202
+ try {
203
+ const binding = require('@remedia/node-darwin-universal')
204
+ const bindingPackageVersion = require('@remedia/node-darwin-universal/package.json').version
205
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
206
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
207
+ }
208
+ return binding
209
+ } catch (e) {
210
+ loadErrors.push(e)
211
+ }
212
+ if (process.arch === 'x64') {
213
+ try {
214
+ return require('./node.darwin-x64.node')
215
+ } catch (e) {
216
+ loadErrors.push(e)
217
+ }
218
+ try {
219
+ const binding = require('@remedia/node-darwin-x64')
220
+ const bindingPackageVersion = require('@remedia/node-darwin-x64/package.json').version
221
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
222
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
223
+ }
224
+ return binding
225
+ } catch (e) {
226
+ loadErrors.push(e)
227
+ }
228
+ } else if (process.arch === 'arm64') {
229
+ try {
230
+ return require('./node.darwin-arm64.node')
231
+ } catch (e) {
232
+ loadErrors.push(e)
233
+ }
234
+ try {
235
+ const binding = require('@remedia/node-darwin-arm64')
236
+ const bindingPackageVersion = require('@remedia/node-darwin-arm64/package.json').version
237
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
+ }
240
+ return binding
241
+ } catch (e) {
242
+ loadErrors.push(e)
243
+ }
244
+ } else {
245
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
246
+ }
247
+ } else if (process.platform === 'freebsd') {
248
+ if (process.arch === 'x64') {
249
+ try {
250
+ return require('./node.freebsd-x64.node')
251
+ } catch (e) {
252
+ loadErrors.push(e)
253
+ }
254
+ try {
255
+ const binding = require('@remedia/node-freebsd-x64')
256
+ const bindingPackageVersion = require('@remedia/node-freebsd-x64/package.json').version
257
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
258
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
259
+ }
260
+ return binding
261
+ } catch (e) {
262
+ loadErrors.push(e)
263
+ }
264
+ } else if (process.arch === 'arm64') {
265
+ try {
266
+ return require('./node.freebsd-arm64.node')
267
+ } catch (e) {
268
+ loadErrors.push(e)
269
+ }
270
+ try {
271
+ const binding = require('@remedia/node-freebsd-arm64')
272
+ const bindingPackageVersion = require('@remedia/node-freebsd-arm64/package.json').version
273
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
274
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
275
+ }
276
+ return binding
277
+ } catch (e) {
278
+ loadErrors.push(e)
279
+ }
280
+ } else if (process.arch === 'ppc64') {
281
+ try {
282
+ return require('./node.freebsd-ppc64.node')
283
+ } catch (e) {
284
+ loadErrors.push(e)
285
+ }
286
+ try {
287
+ const binding = require('@remedia/node-freebsd-ppc64')
288
+ const bindingPackageVersion = require('@remedia/node-freebsd-ppc64/package.json').version
289
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
290
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
291
+ }
292
+ return binding
293
+ } catch (e) {
294
+ loadErrors.push(e)
295
+ }
296
+ } else {
297
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
298
+ }
299
+ } else if (process.platform === 'linux') {
300
+ if (process.arch === 'x64') {
301
+ if (isMusl()) {
302
+ try {
303
+ return require('./node.linux-x64-musl.node')
304
+ } catch (e) {
305
+ loadErrors.push(e)
306
+ }
307
+ try {
308
+ const binding = require('@remedia/node-linux-x64-musl')
309
+ const bindingPackageVersion = require('@remedia/node-linux-x64-musl/package.json').version
310
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
311
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
312
+ }
313
+ return binding
314
+ } catch (e) {
315
+ loadErrors.push(e)
316
+ }
317
+ } else {
318
+ try {
319
+ return require('./node.linux-x64-gnu.node')
320
+ } catch (e) {
321
+ loadErrors.push(e)
322
+ }
323
+ try {
324
+ const binding = require('@remedia/node-linux-x64-gnu')
325
+ const bindingPackageVersion = require('@remedia/node-linux-x64-gnu/package.json').version
326
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
327
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
328
+ }
329
+ return binding
330
+ } catch (e) {
331
+ loadErrors.push(e)
332
+ }
333
+ }
334
+ } else if (process.arch === 'arm64') {
335
+ if (isMusl()) {
336
+ try {
337
+ return require('./node.linux-arm64-musl.node')
338
+ } catch (e) {
339
+ loadErrors.push(e)
340
+ }
341
+ try {
342
+ const binding = require('@remedia/node-linux-arm64-musl')
343
+ const bindingPackageVersion = require('@remedia/node-linux-arm64-musl/package.json').version
344
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
345
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
346
+ }
347
+ return binding
348
+ } catch (e) {
349
+ loadErrors.push(e)
350
+ }
351
+ } else {
352
+ try {
353
+ return require('./node.linux-arm64-gnu.node')
354
+ } catch (e) {
355
+ loadErrors.push(e)
356
+ }
357
+ try {
358
+ const binding = require('@remedia/node-linux-arm64-gnu')
359
+ const bindingPackageVersion = require('@remedia/node-linux-arm64-gnu/package.json').version
360
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
361
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
362
+ }
363
+ return binding
364
+ } catch (e) {
365
+ loadErrors.push(e)
366
+ }
367
+ }
368
+ } else if (process.arch === 'arm') {
369
+ if (isMusl()) {
370
+ try {
371
+ return require('./node.linux-arm-musleabihf.node')
372
+ } catch (e) {
373
+ loadErrors.push(e)
374
+ }
375
+ try {
376
+ const binding = require('@remedia/node-linux-arm-musleabihf')
377
+ const bindingPackageVersion = require('@remedia/node-linux-arm-musleabihf/package.json').version
378
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
379
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
380
+ }
381
+ return binding
382
+ } catch (e) {
383
+ loadErrors.push(e)
384
+ }
385
+ } else {
386
+ try {
387
+ return require('./node.linux-arm-gnueabihf.node')
388
+ } catch (e) {
389
+ loadErrors.push(e)
390
+ }
391
+ try {
392
+ const binding = require('@remedia/node-linux-arm-gnueabihf')
393
+ const bindingPackageVersion = require('@remedia/node-linux-arm-gnueabihf/package.json').version
394
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
395
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
396
+ }
397
+ return binding
398
+ } catch (e) {
399
+ loadErrors.push(e)
400
+ }
401
+ }
402
+ } else if (process.arch === 'loong64') {
403
+ if (isMusl()) {
404
+ try {
405
+ return require('./node.linux-loong64-musl.node')
406
+ } catch (e) {
407
+ loadErrors.push(e)
408
+ }
409
+ try {
410
+ const binding = require('@remedia/node-linux-loong64-musl')
411
+ const bindingPackageVersion = require('@remedia/node-linux-loong64-musl/package.json').version
412
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
413
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
414
+ }
415
+ return binding
416
+ } catch (e) {
417
+ loadErrors.push(e)
418
+ }
419
+ } else {
420
+ try {
421
+ return require('./node.linux-loong64-gnu.node')
422
+ } catch (e) {
423
+ loadErrors.push(e)
424
+ }
425
+ try {
426
+ const binding = require('@remedia/node-linux-loong64-gnu')
427
+ const bindingPackageVersion = require('@remedia/node-linux-loong64-gnu/package.json').version
428
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
429
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
430
+ }
431
+ return binding
432
+ } catch (e) {
433
+ loadErrors.push(e)
434
+ }
435
+ }
436
+ } else if (process.arch === 'riscv64') {
437
+ if (isMusl()) {
438
+ try {
439
+ return require('./node.linux-riscv64-musl.node')
440
+ } catch (e) {
441
+ loadErrors.push(e)
442
+ }
443
+ try {
444
+ const binding = require('@remedia/node-linux-riscv64-musl')
445
+ const bindingPackageVersion = require('@remedia/node-linux-riscv64-musl/package.json').version
446
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
447
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
448
+ }
449
+ return binding
450
+ } catch (e) {
451
+ loadErrors.push(e)
452
+ }
453
+ } else {
454
+ try {
455
+ return require('./node.linux-riscv64-gnu.node')
456
+ } catch (e) {
457
+ loadErrors.push(e)
458
+ }
459
+ try {
460
+ const binding = require('@remedia/node-linux-riscv64-gnu')
461
+ const bindingPackageVersion = require('@remedia/node-linux-riscv64-gnu/package.json').version
462
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
463
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
464
+ }
465
+ return binding
466
+ } catch (e) {
467
+ loadErrors.push(e)
468
+ }
469
+ }
470
+ } else if (process.arch === 'ppc64') {
471
+ try {
472
+ return require('./node.linux-ppc64-gnu.node')
473
+ } catch (e) {
474
+ loadErrors.push(e)
475
+ }
476
+ try {
477
+ const binding = require('@remedia/node-linux-ppc64-gnu')
478
+ const bindingPackageVersion = require('@remedia/node-linux-ppc64-gnu/package.json').version
479
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
481
+ }
482
+ return binding
483
+ } catch (e) {
484
+ loadErrors.push(e)
485
+ }
486
+ } else if (process.arch === 's390x') {
487
+ try {
488
+ return require('./node.linux-s390x-gnu.node')
489
+ } catch (e) {
490
+ loadErrors.push(e)
491
+ }
492
+ try {
493
+ const binding = require('@remedia/node-linux-s390x-gnu')
494
+ const bindingPackageVersion = require('@remedia/node-linux-s390x-gnu/package.json').version
495
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
497
+ }
498
+ return binding
499
+ } catch (e) {
500
+ loadErrors.push(e)
501
+ }
502
+ } else {
503
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
504
+ }
505
+ } else if (process.platform === 'openharmony') {
506
+ if (process.arch === 'arm64') {
507
+ try {
508
+ return require('./node.openharmony-arm64.node')
509
+ } catch (e) {
510
+ loadErrors.push(e)
511
+ }
512
+ try {
513
+ const binding = require('@remedia/node-openharmony-arm64')
514
+ const bindingPackageVersion = require('@remedia/node-openharmony-arm64/package.json').version
515
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
516
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
517
+ }
518
+ return binding
519
+ } catch (e) {
520
+ loadErrors.push(e)
521
+ }
522
+ } else if (process.arch === 'x64') {
523
+ try {
524
+ return require('./node.openharmony-x64.node')
525
+ } catch (e) {
526
+ loadErrors.push(e)
527
+ }
528
+ try {
529
+ const binding = require('@remedia/node-openharmony-x64')
530
+ const bindingPackageVersion = require('@remedia/node-openharmony-x64/package.json').version
531
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
532
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
533
+ }
534
+ return binding
535
+ } catch (e) {
536
+ loadErrors.push(e)
537
+ }
538
+ } else if (process.arch === 'arm') {
539
+ try {
540
+ return require('./node.openharmony-arm.node')
541
+ } catch (e) {
542
+ loadErrors.push(e)
543
+ }
544
+ try {
545
+ const binding = require('@remedia/node-openharmony-arm')
546
+ const bindingPackageVersion = require('@remedia/node-openharmony-arm/package.json').version
547
+ if (bindingPackageVersion !== '0.1.0-dev.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
548
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
549
+ }
550
+ return binding
551
+ } catch (e) {
552
+ loadErrors.push(e)
553
+ }
554
+ } else {
555
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
556
+ }
557
+ } else {
558
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
559
+ }
560
+ }
561
+
562
+ function createLoadErrorChain(errors) {
563
+ return errors.reduce((previous, current) => {
564
+ let message
565
+ try {
566
+ message =
567
+ current && typeof current.message === 'string'
568
+ ? current.message
569
+ : String(current)
570
+ } catch {
571
+ message = 'Unknown error'
572
+ }
573
+ const error = new Error(message)
574
+ error.cause = previous
575
+ return error
576
+ }, null)
577
+ }
578
+
579
+ // NAPI_RS_FORCE_WASI is a tri-state flag:
580
+ // unset / any other value → native binding preferred, WASI is only a fallback
581
+ // 'true' → prefer WASI, but retain native as a lazy fallback
582
+ // 'error' → require WASI without initializing a native fallback
583
+ // Treating any non-empty string as truthy (the historical behavior) meant
584
+ // NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
585
+ // the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
586
+ //
587
+ // NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
588
+ // WASI loading. It never crosses into another flavor or falls back to native.
589
+ const __napiWasiFlavors = ['wasm32-wasi']
590
+ const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
591
+ const __napiWasiFlavorRequested =
592
+ typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
593
+ if (
594
+ __napiWasiFlavorRequested &&
595
+ __napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
596
+ ) {
597
+ throw new Error(
598
+ 'Unsupported WASI flavor "' +
599
+ __napiWasiFlavor +
600
+ '". Available flavors: ' +
601
+ __napiWasiFlavors.join(', '),
602
+ )
603
+ }
604
+ const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
605
+ const forceWasi =
606
+ process.env.NAPI_RS_FORCE_WASI === 'true' ||
607
+ forceWasiError ||
608
+ __napiWasiFlavorRequested
609
+
610
+ if (!forceWasi) {
611
+ nativeBinding = requireNative()
612
+ __napiRequiredNativeBinding = nativeBinding
613
+ }
614
+
615
+ if (!nativeBinding || forceWasi) {
616
+ let wasiBinding = null
617
+ let wasiBindingLoaded = false
618
+ const wasiBindingErrors = []
619
+ const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
620
+ try {
621
+ require.resolve(specifier)
622
+ } catch (resolveError) {
623
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
624
+ throw resolveError
625
+ }
626
+ if (isPackage) {
627
+ try {
628
+ require.resolve(specifier + '/package.json')
629
+ } catch (packageError) {
630
+ if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
631
+ return resolveError
632
+ }
633
+ // An exports restriction proves the package exists even when its
634
+ // package.json is not public. Preserve the root resolution failure.
635
+ throw resolveError
636
+ }
637
+ // The package exists but its main/export target is broken.
638
+ throw resolveError
639
+ }
640
+ return resolveError
641
+ }
642
+ if (localArtifacts) {
643
+ let artifactError = null
644
+ for (let i = 0; i < localArtifacts.length; i++) {
645
+ try {
646
+ require.resolve(localArtifacts[i])
647
+ return null
648
+ } catch (resolveError) {
649
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
650
+ throw resolveError
651
+ }
652
+ artifactError = resolveError
653
+ }
654
+ }
655
+ return artifactError
656
+ }
657
+ return null
658
+ }
659
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
660
+ let candidateError = null
661
+ let candidateFailed = false
662
+ try {
663
+ candidateError = __napiWasiResolveCandidate('./node.wasi.cjs', false, ['./node.wasm32-wasi.debug.wasm', './node.wasm32-wasi.wasm'])
664
+ candidateFailed = candidateError !== null
665
+ if (!candidateFailed) {
666
+ wasiBinding = require('./node.wasi.cjs')
667
+ nativeBinding = wasiBinding
668
+ __napiLoadedBindingTarget = 'wasm32-wasi'
669
+ wasiBindingLoaded = true
670
+ }
671
+ } catch (err) {
672
+ candidateError = err
673
+ candidateFailed = true
674
+ }
675
+ if (candidateFailed) {
676
+ wasiBindingErrors.push(candidateError)
677
+ loadErrors.push(candidateError)
678
+ }
679
+ }
680
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
681
+ let candidateError = null
682
+ let candidateFailed = false
683
+ try {
684
+ candidateError = __napiWasiResolveCandidate('@remedia/node-wasm32-wasi', true, undefined)
685
+ candidateFailed = candidateError !== null
686
+ if (!candidateFailed) {
687
+ if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
688
+ const bindingPackageVersion = require('@remedia/node-wasm32-wasi/package.json').version
689
+ if (bindingPackageVersion !== '0.1.0-dev.0') {
690
+ throw new Error(`WASI binding package version mismatch, expected 0.1.0-dev.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
691
+ }
692
+ }
693
+ wasiBinding = require('@remedia/node-wasm32-wasi')
694
+ nativeBinding = wasiBinding
695
+ __napiLoadedBindingTarget = 'wasm32-wasi'
696
+ wasiBindingLoaded = true
697
+ }
698
+ } catch (err) {
699
+ candidateError = err
700
+ candidateFailed = true
701
+ }
702
+ if (candidateFailed) {
703
+ wasiBindingErrors.push(candidateError)
704
+ loadErrors.push(candidateError)
705
+ }
706
+ }
707
+ if (
708
+ !wasiBindingLoaded &&
709
+ forceWasi &&
710
+ !forceWasiError &&
711
+ !__napiWasiFlavorRequested
712
+ ) {
713
+ nativeBinding = requireNative()
714
+ __napiRequiredNativeBinding = nativeBinding
715
+ }
716
+ if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
717
+ const error = new Error(
718
+ __napiWasiFlavorRequested
719
+ ? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
720
+ : 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
721
+ )
722
+ error.cause = createLoadErrorChain(wasiBindingErrors)
723
+ throw error
724
+ }
725
+ }
726
+
727
+ if (!nativeBinding) {
728
+ if (loadErrors.length > 0) {
729
+ const error = new Error(
730
+ `Cannot find native binding. ` +
731
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
732
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
733
+ )
734
+ // assign instead of the `new Error(message, { cause })` options form,
735
+ // which Node < 16.9 silently ignores
736
+ error.cause = createLoadErrorChain(loadErrors)
737
+ throw error
738
+ }
739
+ throw new Error(`Failed to load native binding`)
740
+ }
741
+
742
+ // A package can patch its own fallback in front of the load-failure check
743
+ // above, e.g. a WebContainer download through `napi-postinstall/fallback`.
744
+ // That fallback swaps `nativeBinding` for a generated WASI loader, which has
745
+ // already stamped its own flavor, while the target above still says 'native'.
746
+ // Take that flavor over, or the CommonJS stamp throws a conflict and the ESM
747
+ // export reports the wrong artifact. Three limits keep the conflict check:
748
+ // - only a binding this loader did not load itself, so a native addon whose
749
+ // `#[napi(module_exports)]` hook claims the name is still rejected;
750
+ // - only an own data property, read through its descriptor, so no addon
751
+ // getter runs here, and it must read back the same, as the stamp reads it;
752
+ // - only a flavor in `__napiWasiFlavors`, the ones this loader's own WASI
753
+ // chain can report ('wasm32-wasi' for a package without a WASI target).
754
+ // This is metadata and never fails a load: a throwing Proxy trap keeps 'native'.
755
+ if (
756
+ __napiLoadedBindingTarget === 'native' &&
757
+ nativeBinding !== __napiRequiredNativeBinding
758
+ ) {
759
+ try {
760
+ const __napiBindingTargetDescriptor = Object.getOwnPropertyDescriptor(
761
+ nativeBinding,
762
+ '__napiBindingTarget',
763
+ )
764
+ if (
765
+ __napiBindingTargetDescriptor &&
766
+ __napiWasiFlavors.indexOf(__napiBindingTargetDescriptor.value) !== -1 &&
767
+ nativeBinding.__napiBindingTarget === __napiBindingTargetDescriptor.value
768
+ ) {
769
+ __napiLoadedBindingTarget = __napiBindingTargetDescriptor.value
770
+ }
771
+ } catch {
772
+ // keep 'native'
773
+ }
774
+ }
775
+
776
+ const { NativeRemedia } = nativeBinding
777
+ export { NativeRemedia }
778
+ export const __napiBindingTarget = __napiLoadedBindingTarget