peisar-utils 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +105 -2
  3. package/index.d.ts +109 -0
  4. package/index.js +1040 -0
  5. package/package.json +46 -4
package/index.js ADDED
@@ -0,0 +1,1040 @@
1
+ /* eslint-disable */
2
+ // @ts-nocheck
3
+ /* auto-generated by NAPI-RS */
4
+
5
+ const { readFileSync } = require("fs");
6
+ let nativeBinding = null;
7
+ // Which artifact actually loaded. The WASI fallback chain overwrites it with
8
+ // the flavor it resolved; the late native retry below leaves it alone because
9
+ // it only runs while no WASI candidate has been loaded. The take-over check
10
+ // after the load-failure block can also set it.
11
+ let __napiLoadedBindingTarget = "native";
12
+ // What this loader's own `requireNative()` calls returned. The check after
13
+ // the load-failure block compares it with `nativeBinding` to tell a binding
14
+ // this loader loaded from one that code outside it put in its place.
15
+ let __napiRequiredNativeBinding = null;
16
+ const loadErrors = [];
17
+
18
+ const isMusl = () => {
19
+ let musl = false;
20
+ if (process.platform === "linux") {
21
+ musl = isMuslFromFilesystem();
22
+ if (musl === null) {
23
+ musl = isMuslFromReport();
24
+ }
25
+ if (musl === null) {
26
+ musl = isMuslFromChildProcess();
27
+ }
28
+ }
29
+ return musl;
30
+ };
31
+
32
+ const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
33
+
34
+ const isMuslFromFilesystem = () => {
35
+ try {
36
+ return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
37
+ } catch {
38
+ return null;
39
+ }
40
+ };
41
+
42
+ const isMuslFromReport = () => {
43
+ let report = null;
44
+ if (process.report && typeof process.report.getReport === "function") {
45
+ process.report.excludeNetwork = true;
46
+ report = process.report.getReport();
47
+ }
48
+ if (!report) {
49
+ return null;
50
+ }
51
+ if (report.header && report.header.glibcVersionRuntime) {
52
+ return false;
53
+ }
54
+ if (Array.isArray(report.sharedObjects)) {
55
+ if (report.sharedObjects.some(isFileMusl)) {
56
+ return true;
57
+ }
58
+ }
59
+ return false;
60
+ };
61
+
62
+ const isMuslFromChildProcess = () => {
63
+ try {
64
+ return require("child_process")
65
+ .execSync("ldd --version", { encoding: "utf8" })
66
+ .includes("musl");
67
+ } catch (e) {
68
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
69
+ return false;
70
+ }
71
+ };
72
+
73
+ function requireNative() {
74
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
75
+ try {
76
+ const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
77
+ // The override may be a generated WASI loader, which already reports its
78
+ // own flavor. Adopt it: `module.exports` aliases this object, so claiming
79
+ // 'native' would both misreport the artifact and overwrite the loader's
80
+ // marker through the alias.
81
+ __napiLoadedBindingTarget =
82
+ overrideBinding && typeof overrideBinding.__napiBindingTarget === "string"
83
+ ? overrideBinding.__napiBindingTarget
84
+ : "native";
85
+ return overrideBinding;
86
+ } catch (err) {
87
+ loadErrors.push(err);
88
+ }
89
+ } else if (process.platform === "android") {
90
+ if (process.arch === "arm64") {
91
+ try {
92
+ return require("./peisar-utils.android-arm64.node");
93
+ } catch (e) {
94
+ loadErrors.push(e);
95
+ }
96
+ try {
97
+ const binding = require("@peisar/peisar-utils-android-arm64");
98
+ const bindingPackageVersion =
99
+ require("@peisar/peisar-utils-android-arm64/package.json").version;
100
+ if (
101
+ bindingPackageVersion !== "1.0.1" &&
102
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
103
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
104
+ ) {
105
+ throw new Error(
106
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
107
+ );
108
+ }
109
+ return binding;
110
+ } catch (e) {
111
+ loadErrors.push(e);
112
+ }
113
+ } else if (process.arch === "arm") {
114
+ try {
115
+ return require("./peisar-utils.android-arm-eabi.node");
116
+ } catch (e) {
117
+ loadErrors.push(e);
118
+ }
119
+ try {
120
+ const binding = require("@peisar/peisar-utils-android-arm-eabi");
121
+ const bindingPackageVersion =
122
+ require("@peisar/peisar-utils-android-arm-eabi/package.json").version;
123
+ if (
124
+ bindingPackageVersion !== "1.0.1" &&
125
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
126
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
127
+ ) {
128
+ throw new Error(
129
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
130
+ );
131
+ }
132
+ return binding;
133
+ } catch (e) {
134
+ loadErrors.push(e);
135
+ }
136
+ } else {
137
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`));
138
+ }
139
+ } else if (process.platform === "win32") {
140
+ if (process.arch === "x64") {
141
+ if (
142
+ (process.config &&
143
+ process.config.variables &&
144
+ process.config.variables.shlib_suffix === "dll.a") ||
145
+ (process.config &&
146
+ process.config.variables &&
147
+ process.config.variables.node_target_type === "shared_library")
148
+ ) {
149
+ try {
150
+ return require("./peisar-utils.win32-x64-gnu.node");
151
+ } catch (e) {
152
+ loadErrors.push(e);
153
+ }
154
+ try {
155
+ const binding = require("@peisar/peisar-utils-win32-x64-gnu");
156
+ const bindingPackageVersion =
157
+ require("@peisar/peisar-utils-win32-x64-gnu/package.json").version;
158
+ if (
159
+ bindingPackageVersion !== "1.0.1" &&
160
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
161
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
162
+ ) {
163
+ throw new Error(
164
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
165
+ );
166
+ }
167
+ return binding;
168
+ } catch (e) {
169
+ loadErrors.push(e);
170
+ }
171
+ } else {
172
+ try {
173
+ return require("./peisar-utils.win32-x64-msvc.node");
174
+ } catch (e) {
175
+ loadErrors.push(e);
176
+ }
177
+ try {
178
+ const binding = require("@peisar/peisar-utils-win32-x64-msvc");
179
+ const bindingPackageVersion =
180
+ require("@peisar/peisar-utils-win32-x64-msvc/package.json").version;
181
+ if (
182
+ bindingPackageVersion !== "1.0.1" &&
183
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
184
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
185
+ ) {
186
+ throw new Error(
187
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
188
+ );
189
+ }
190
+ return binding;
191
+ } catch (e) {
192
+ loadErrors.push(e);
193
+ }
194
+ }
195
+ } else if (process.arch === "ia32") {
196
+ try {
197
+ return require("./peisar-utils.win32-ia32-msvc.node");
198
+ } catch (e) {
199
+ loadErrors.push(e);
200
+ }
201
+ try {
202
+ const binding = require("@peisar/peisar-utils-win32-ia32-msvc");
203
+ const bindingPackageVersion =
204
+ require("@peisar/peisar-utils-win32-ia32-msvc/package.json").version;
205
+ if (
206
+ bindingPackageVersion !== "1.0.1" &&
207
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
208
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
209
+ ) {
210
+ throw new Error(
211
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
212
+ );
213
+ }
214
+ return binding;
215
+ } catch (e) {
216
+ loadErrors.push(e);
217
+ }
218
+ } else if (process.arch === "arm64") {
219
+ try {
220
+ return require("./peisar-utils.win32-arm64-msvc.node");
221
+ } catch (e) {
222
+ loadErrors.push(e);
223
+ }
224
+ try {
225
+ const binding = require("@peisar/peisar-utils-win32-arm64-msvc");
226
+ const bindingPackageVersion =
227
+ require("@peisar/peisar-utils-win32-arm64-msvc/package.json").version;
228
+ if (
229
+ bindingPackageVersion !== "1.0.1" &&
230
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
231
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
232
+ ) {
233
+ throw new Error(
234
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
235
+ );
236
+ }
237
+ return binding;
238
+ } catch (e) {
239
+ loadErrors.push(e);
240
+ }
241
+ } else {
242
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));
243
+ }
244
+ } else if (process.platform === "darwin") {
245
+ try {
246
+ return require("./peisar-utils.darwin-universal.node");
247
+ } catch (e) {
248
+ loadErrors.push(e);
249
+ }
250
+ try {
251
+ const binding = require("@peisar/peisar-utils-darwin-universal");
252
+ const bindingPackageVersion =
253
+ require("@peisar/peisar-utils-darwin-universal/package.json").version;
254
+ if (
255
+ bindingPackageVersion !== "1.0.1" &&
256
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
257
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
258
+ ) {
259
+ throw new Error(
260
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
261
+ );
262
+ }
263
+ return binding;
264
+ } catch (e) {
265
+ loadErrors.push(e);
266
+ }
267
+ if (process.arch === "x64") {
268
+ try {
269
+ return require("./peisar-utils.darwin-x64.node");
270
+ } catch (e) {
271
+ loadErrors.push(e);
272
+ }
273
+ try {
274
+ const binding = require("@peisar/peisar-utils-darwin-x64");
275
+ const bindingPackageVersion =
276
+ require("@peisar/peisar-utils-darwin-x64/package.json").version;
277
+ if (
278
+ bindingPackageVersion !== "1.0.1" &&
279
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
280
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
281
+ ) {
282
+ throw new Error(
283
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
284
+ );
285
+ }
286
+ return binding;
287
+ } catch (e) {
288
+ loadErrors.push(e);
289
+ }
290
+ } else if (process.arch === "arm64") {
291
+ try {
292
+ return require("./peisar-utils.darwin-arm64.node");
293
+ } catch (e) {
294
+ loadErrors.push(e);
295
+ }
296
+ try {
297
+ const binding = require("@peisar/peisar-utils-darwin-arm64");
298
+ const bindingPackageVersion =
299
+ require("@peisar/peisar-utils-darwin-arm64/package.json").version;
300
+ if (
301
+ bindingPackageVersion !== "1.0.1" &&
302
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
303
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
304
+ ) {
305
+ throw new Error(
306
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
307
+ );
308
+ }
309
+ return binding;
310
+ } catch (e) {
311
+ loadErrors.push(e);
312
+ }
313
+ } else {
314
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`));
315
+ }
316
+ } else if (process.platform === "freebsd") {
317
+ if (process.arch === "x64") {
318
+ try {
319
+ return require("./peisar-utils.freebsd-x64.node");
320
+ } catch (e) {
321
+ loadErrors.push(e);
322
+ }
323
+ try {
324
+ const binding = require("@peisar/peisar-utils-freebsd-x64");
325
+ const bindingPackageVersion =
326
+ require("@peisar/peisar-utils-freebsd-x64/package.json").version;
327
+ if (
328
+ bindingPackageVersion !== "1.0.1" &&
329
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
330
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
331
+ ) {
332
+ throw new Error(
333
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
334
+ );
335
+ }
336
+ return binding;
337
+ } catch (e) {
338
+ loadErrors.push(e);
339
+ }
340
+ } else if (process.arch === "arm64") {
341
+ try {
342
+ return require("./peisar-utils.freebsd-arm64.node");
343
+ } catch (e) {
344
+ loadErrors.push(e);
345
+ }
346
+ try {
347
+ const binding = require("@peisar/peisar-utils-freebsd-arm64");
348
+ const bindingPackageVersion =
349
+ require("@peisar/peisar-utils-freebsd-arm64/package.json").version;
350
+ if (
351
+ bindingPackageVersion !== "1.0.1" &&
352
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
353
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
354
+ ) {
355
+ throw new Error(
356
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
357
+ );
358
+ }
359
+ return binding;
360
+ } catch (e) {
361
+ loadErrors.push(e);
362
+ }
363
+ } else if (process.arch === "ppc64") {
364
+ try {
365
+ return require("./peisar-utils.freebsd-ppc64.node");
366
+ } catch (e) {
367
+ loadErrors.push(e);
368
+ }
369
+ try {
370
+ const binding = require("@peisar/peisar-utils-freebsd-ppc64");
371
+ const bindingPackageVersion =
372
+ require("@peisar/peisar-utils-freebsd-ppc64/package.json").version;
373
+ if (
374
+ bindingPackageVersion !== "1.0.1" &&
375
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
376
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
377
+ ) {
378
+ throw new Error(
379
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
380
+ );
381
+ }
382
+ return binding;
383
+ } catch (e) {
384
+ loadErrors.push(e);
385
+ }
386
+ } else {
387
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
388
+ }
389
+ } else if (process.platform === "linux") {
390
+ if (process.arch === "x64") {
391
+ if (isMusl()) {
392
+ try {
393
+ return require("./peisar-utils.linux-x64-musl.node");
394
+ } catch (e) {
395
+ loadErrors.push(e);
396
+ }
397
+ try {
398
+ const binding = require("@peisar/peisar-utils-linux-x64-musl");
399
+ const bindingPackageVersion =
400
+ require("@peisar/peisar-utils-linux-x64-musl/package.json").version;
401
+ if (
402
+ bindingPackageVersion !== "1.0.1" &&
403
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
404
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
405
+ ) {
406
+ throw new Error(
407
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
408
+ );
409
+ }
410
+ return binding;
411
+ } catch (e) {
412
+ loadErrors.push(e);
413
+ }
414
+ } else {
415
+ try {
416
+ return require("./peisar-utils.linux-x64-gnu.node");
417
+ } catch (e) {
418
+ loadErrors.push(e);
419
+ }
420
+ try {
421
+ const binding = require("@peisar/peisar-utils-linux-x64-gnu");
422
+ const bindingPackageVersion =
423
+ require("@peisar/peisar-utils-linux-x64-gnu/package.json").version;
424
+ if (
425
+ bindingPackageVersion !== "1.0.1" &&
426
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
427
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
428
+ ) {
429
+ throw new Error(
430
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
431
+ );
432
+ }
433
+ return binding;
434
+ } catch (e) {
435
+ loadErrors.push(e);
436
+ }
437
+ }
438
+ } else if (process.arch === "arm64") {
439
+ if (isMusl()) {
440
+ try {
441
+ return require("./peisar-utils.linux-arm64-musl.node");
442
+ } catch (e) {
443
+ loadErrors.push(e);
444
+ }
445
+ try {
446
+ const binding = require("@peisar/peisar-utils-linux-arm64-musl");
447
+ const bindingPackageVersion =
448
+ require("@peisar/peisar-utils-linux-arm64-musl/package.json").version;
449
+ if (
450
+ bindingPackageVersion !== "1.0.1" &&
451
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
452
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
453
+ ) {
454
+ throw new Error(
455
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
456
+ );
457
+ }
458
+ return binding;
459
+ } catch (e) {
460
+ loadErrors.push(e);
461
+ }
462
+ } else {
463
+ try {
464
+ return require("./peisar-utils.linux-arm64-gnu.node");
465
+ } catch (e) {
466
+ loadErrors.push(e);
467
+ }
468
+ try {
469
+ const binding = require("@peisar/peisar-utils-linux-arm64-gnu");
470
+ const bindingPackageVersion =
471
+ require("@peisar/peisar-utils-linux-arm64-gnu/package.json").version;
472
+ if (
473
+ bindingPackageVersion !== "1.0.1" &&
474
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
475
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
476
+ ) {
477
+ throw new Error(
478
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
479
+ );
480
+ }
481
+ return binding;
482
+ } catch (e) {
483
+ loadErrors.push(e);
484
+ }
485
+ }
486
+ } else if (process.arch === "arm") {
487
+ if (isMusl()) {
488
+ try {
489
+ return require("./peisar-utils.linux-arm-musleabihf.node");
490
+ } catch (e) {
491
+ loadErrors.push(e);
492
+ }
493
+ try {
494
+ const binding = require("@peisar/peisar-utils-linux-arm-musleabihf");
495
+ const bindingPackageVersion =
496
+ require("@peisar/peisar-utils-linux-arm-musleabihf/package.json").version;
497
+ if (
498
+ bindingPackageVersion !== "1.0.1" &&
499
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
500
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
501
+ ) {
502
+ throw new Error(
503
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
504
+ );
505
+ }
506
+ return binding;
507
+ } catch (e) {
508
+ loadErrors.push(e);
509
+ }
510
+ } else {
511
+ try {
512
+ return require("./peisar-utils.linux-arm-gnueabihf.node");
513
+ } catch (e) {
514
+ loadErrors.push(e);
515
+ }
516
+ try {
517
+ const binding = require("@peisar/peisar-utils-linux-arm-gnueabihf");
518
+ const bindingPackageVersion =
519
+ require("@peisar/peisar-utils-linux-arm-gnueabihf/package.json").version;
520
+ if (
521
+ bindingPackageVersion !== "1.0.1" &&
522
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
523
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
524
+ ) {
525
+ throw new Error(
526
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
527
+ );
528
+ }
529
+ return binding;
530
+ } catch (e) {
531
+ loadErrors.push(e);
532
+ }
533
+ }
534
+ } else if (process.arch === "loong64") {
535
+ if (isMusl()) {
536
+ try {
537
+ return require("./peisar-utils.linux-loong64-musl.node");
538
+ } catch (e) {
539
+ loadErrors.push(e);
540
+ }
541
+ try {
542
+ const binding = require("@peisar/peisar-utils-linux-loong64-musl");
543
+ const bindingPackageVersion =
544
+ require("@peisar/peisar-utils-linux-loong64-musl/package.json").version;
545
+ if (
546
+ bindingPackageVersion !== "1.0.1" &&
547
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
548
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
549
+ ) {
550
+ throw new Error(
551
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
552
+ );
553
+ }
554
+ return binding;
555
+ } catch (e) {
556
+ loadErrors.push(e);
557
+ }
558
+ } else {
559
+ try {
560
+ return require("./peisar-utils.linux-loong64-gnu.node");
561
+ } catch (e) {
562
+ loadErrors.push(e);
563
+ }
564
+ try {
565
+ const binding = require("@peisar/peisar-utils-linux-loong64-gnu");
566
+ const bindingPackageVersion =
567
+ require("@peisar/peisar-utils-linux-loong64-gnu/package.json").version;
568
+ if (
569
+ bindingPackageVersion !== "1.0.1" &&
570
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
571
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
572
+ ) {
573
+ throw new Error(
574
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
575
+ );
576
+ }
577
+ return binding;
578
+ } catch (e) {
579
+ loadErrors.push(e);
580
+ }
581
+ }
582
+ } else if (process.arch === "riscv64") {
583
+ if (isMusl()) {
584
+ try {
585
+ return require("./peisar-utils.linux-riscv64-musl.node");
586
+ } catch (e) {
587
+ loadErrors.push(e);
588
+ }
589
+ try {
590
+ const binding = require("@peisar/peisar-utils-linux-riscv64-musl");
591
+ const bindingPackageVersion =
592
+ require("@peisar/peisar-utils-linux-riscv64-musl/package.json").version;
593
+ if (
594
+ bindingPackageVersion !== "1.0.1" &&
595
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
596
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
597
+ ) {
598
+ throw new Error(
599
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
600
+ );
601
+ }
602
+ return binding;
603
+ } catch (e) {
604
+ loadErrors.push(e);
605
+ }
606
+ } else {
607
+ try {
608
+ return require("./peisar-utils.linux-riscv64-gnu.node");
609
+ } catch (e) {
610
+ loadErrors.push(e);
611
+ }
612
+ try {
613
+ const binding = require("@peisar/peisar-utils-linux-riscv64-gnu");
614
+ const bindingPackageVersion =
615
+ require("@peisar/peisar-utils-linux-riscv64-gnu/package.json").version;
616
+ if (
617
+ bindingPackageVersion !== "1.0.1" &&
618
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
619
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
620
+ ) {
621
+ throw new Error(
622
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
623
+ );
624
+ }
625
+ return binding;
626
+ } catch (e) {
627
+ loadErrors.push(e);
628
+ }
629
+ }
630
+ } else if (process.arch === "ppc64") {
631
+ try {
632
+ return require("./peisar-utils.linux-ppc64-gnu.node");
633
+ } catch (e) {
634
+ loadErrors.push(e);
635
+ }
636
+ try {
637
+ const binding = require("@peisar/peisar-utils-linux-ppc64-gnu");
638
+ const bindingPackageVersion =
639
+ require("@peisar/peisar-utils-linux-ppc64-gnu/package.json").version;
640
+ if (
641
+ bindingPackageVersion !== "1.0.1" &&
642
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
643
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
644
+ ) {
645
+ throw new Error(
646
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
647
+ );
648
+ }
649
+ return binding;
650
+ } catch (e) {
651
+ loadErrors.push(e);
652
+ }
653
+ } else if (process.arch === "s390x") {
654
+ try {
655
+ return require("./peisar-utils.linux-s390x-gnu.node");
656
+ } catch (e) {
657
+ loadErrors.push(e);
658
+ }
659
+ try {
660
+ const binding = require("@peisar/peisar-utils-linux-s390x-gnu");
661
+ const bindingPackageVersion =
662
+ require("@peisar/peisar-utils-linux-s390x-gnu/package.json").version;
663
+ if (
664
+ bindingPackageVersion !== "1.0.1" &&
665
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
666
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
667
+ ) {
668
+ throw new Error(
669
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
670
+ );
671
+ }
672
+ return binding;
673
+ } catch (e) {
674
+ loadErrors.push(e);
675
+ }
676
+ } else {
677
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`));
678
+ }
679
+ } else if (process.platform === "openharmony") {
680
+ if (process.arch === "arm64") {
681
+ try {
682
+ return require("./peisar-utils.openharmony-arm64.node");
683
+ } catch (e) {
684
+ loadErrors.push(e);
685
+ }
686
+ try {
687
+ const binding = require("@peisar/peisar-utils-openharmony-arm64");
688
+ const bindingPackageVersion =
689
+ require("@peisar/peisar-utils-openharmony-arm64/package.json").version;
690
+ if (
691
+ bindingPackageVersion !== "1.0.1" &&
692
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
693
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
694
+ ) {
695
+ throw new Error(
696
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
697
+ );
698
+ }
699
+ return binding;
700
+ } catch (e) {
701
+ loadErrors.push(e);
702
+ }
703
+ } else if (process.arch === "x64") {
704
+ try {
705
+ return require("./peisar-utils.openharmony-x64.node");
706
+ } catch (e) {
707
+ loadErrors.push(e);
708
+ }
709
+ try {
710
+ const binding = require("@peisar/peisar-utils-openharmony-x64");
711
+ const bindingPackageVersion =
712
+ require("@peisar/peisar-utils-openharmony-x64/package.json").version;
713
+ if (
714
+ bindingPackageVersion !== "1.0.1" &&
715
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
716
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
717
+ ) {
718
+ throw new Error(
719
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
720
+ );
721
+ }
722
+ return binding;
723
+ } catch (e) {
724
+ loadErrors.push(e);
725
+ }
726
+ } else if (process.arch === "arm") {
727
+ try {
728
+ return require("./peisar-utils.openharmony-arm.node");
729
+ } catch (e) {
730
+ loadErrors.push(e);
731
+ }
732
+ try {
733
+ const binding = require("@peisar/peisar-utils-openharmony-arm");
734
+ const bindingPackageVersion =
735
+ require("@peisar/peisar-utils-openharmony-arm/package.json").version;
736
+ if (
737
+ bindingPackageVersion !== "1.0.1" &&
738
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
739
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
740
+ ) {
741
+ throw new Error(
742
+ `Native binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
743
+ );
744
+ }
745
+ return binding;
746
+ } catch (e) {
747
+ loadErrors.push(e);
748
+ }
749
+ } else {
750
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`));
751
+ }
752
+ } else {
753
+ loadErrors.push(
754
+ new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`),
755
+ );
756
+ }
757
+ }
758
+
759
+ function createLoadErrorChain(errors) {
760
+ return errors.reduce((previous, current) => {
761
+ let message;
762
+ try {
763
+ message = current && typeof current.message === "string" ? current.message : String(current);
764
+ } catch {
765
+ message = "Unknown error";
766
+ }
767
+ const error = new Error(message);
768
+ error.cause = previous;
769
+ return error;
770
+ }, null);
771
+ }
772
+
773
+ // NAPI_RS_FORCE_WASI is a tri-state flag:
774
+ // unset / any other value → native binding preferred, WASI is only a fallback
775
+ // 'true' → prefer WASI, but retain native as a lazy fallback
776
+ // 'error' → require WASI without initializing a native fallback
777
+ // Treating any non-empty string as truthy (the historical behavior) meant
778
+ // NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
779
+ // the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
780
+ //
781
+ // NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
782
+ // WASI loading. It never crosses into another flavor or falls back to native.
783
+ const __napiWasiFlavors = ["wasm32-wasi"];
784
+ const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR;
785
+ const __napiWasiFlavorRequested =
786
+ typeof __napiWasiFlavor === "string" && __napiWasiFlavor.length > 0;
787
+ if (__napiWasiFlavorRequested && __napiWasiFlavors.indexOf(__napiWasiFlavor) === -1) {
788
+ throw new Error(
789
+ 'Unsupported WASI flavor "' +
790
+ __napiWasiFlavor +
791
+ '". Available flavors: ' +
792
+ __napiWasiFlavors.join(", "),
793
+ );
794
+ }
795
+ const forceWasiError = process.env.NAPI_RS_FORCE_WASI === "error";
796
+ const forceWasi =
797
+ process.env.NAPI_RS_FORCE_WASI === "true" || forceWasiError || __napiWasiFlavorRequested;
798
+
799
+ if (!forceWasi) {
800
+ nativeBinding = requireNative();
801
+ __napiRequiredNativeBinding = nativeBinding;
802
+ }
803
+
804
+ if (!nativeBinding || forceWasi) {
805
+ let wasiBinding = null;
806
+ let wasiBindingLoaded = false;
807
+ const wasiBindingErrors = [];
808
+ const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
809
+ try {
810
+ require.resolve(specifier);
811
+ } catch (resolveError) {
812
+ if (!resolveError || resolveError.code !== "MODULE_NOT_FOUND") {
813
+ throw resolveError;
814
+ }
815
+ if (isPackage) {
816
+ try {
817
+ require.resolve(specifier + "/package.json");
818
+ } catch (packageError) {
819
+ if (packageError && packageError.code === "MODULE_NOT_FOUND") {
820
+ return resolveError;
821
+ }
822
+ // An exports restriction proves the package exists even when its
823
+ // package.json is not public. Preserve the root resolution failure.
824
+ throw resolveError;
825
+ }
826
+ // The package exists but its main/export target is broken.
827
+ throw resolveError;
828
+ }
829
+ return resolveError;
830
+ }
831
+ if (localArtifacts) {
832
+ let artifactError = null;
833
+ for (let i = 0; i < localArtifacts.length; i++) {
834
+ try {
835
+ require.resolve(localArtifacts[i]);
836
+ return null;
837
+ } catch (resolveError) {
838
+ if (!resolveError || resolveError.code !== "MODULE_NOT_FOUND") {
839
+ throw resolveError;
840
+ }
841
+ artifactError = resolveError;
842
+ }
843
+ }
844
+ return artifactError;
845
+ }
846
+ return null;
847
+ };
848
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
849
+ let candidateError = null;
850
+ let candidateFailed = false;
851
+ try {
852
+ candidateError = __napiWasiResolveCandidate("./peisar-utils.wasi.cjs", false, [
853
+ "./peisar-utils.wasm32-wasi.debug.wasm",
854
+ "./peisar-utils.wasm32-wasi.wasm",
855
+ ]);
856
+ candidateFailed = candidateError !== null;
857
+ if (!candidateFailed) {
858
+ wasiBinding = require("./peisar-utils.wasi.cjs");
859
+ nativeBinding = wasiBinding;
860
+ __napiLoadedBindingTarget = "wasm32-wasi";
861
+ wasiBindingLoaded = true;
862
+ }
863
+ } catch (err) {
864
+ candidateError = err;
865
+ candidateFailed = true;
866
+ }
867
+ if (candidateFailed) {
868
+ wasiBindingErrors.push(candidateError);
869
+ loadErrors.push(candidateError);
870
+ }
871
+ }
872
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
873
+ let candidateError = null;
874
+ let candidateFailed = false;
875
+ try {
876
+ candidateError = __napiWasiResolveCandidate(
877
+ "@peisar/peisar-utils-wasm32-wasi",
878
+ true,
879
+ undefined,
880
+ );
881
+ candidateFailed = candidateError !== null;
882
+ if (!candidateFailed) {
883
+ if (
884
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
885
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
886
+ ) {
887
+ const bindingPackageVersion =
888
+ require("@peisar/peisar-utils-wasm32-wasi/package.json").version;
889
+ if (bindingPackageVersion !== "1.0.1") {
890
+ throw new Error(
891
+ `WASI binding package version mismatch, expected 1.0.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
892
+ );
893
+ }
894
+ }
895
+ wasiBinding = require("@peisar/peisar-utils-wasm32-wasi");
896
+ nativeBinding = wasiBinding;
897
+ __napiLoadedBindingTarget = "wasm32-wasi";
898
+ wasiBindingLoaded = true;
899
+ }
900
+ } catch (err) {
901
+ candidateError = err;
902
+ candidateFailed = true;
903
+ }
904
+ if (candidateFailed) {
905
+ wasiBindingErrors.push(candidateError);
906
+ loadErrors.push(candidateError);
907
+ }
908
+ }
909
+ if (!wasiBindingLoaded && forceWasi && !forceWasiError && !__napiWasiFlavorRequested) {
910
+ nativeBinding = requireNative();
911
+ __napiRequiredNativeBinding = nativeBinding;
912
+ }
913
+ if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
914
+ const error = new Error(
915
+ __napiWasiFlavorRequested
916
+ ? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
917
+ : "WASI binding not found and NAPI_RS_FORCE_WASI is set to error",
918
+ );
919
+ error.cause = createLoadErrorChain(wasiBindingErrors);
920
+ throw error;
921
+ }
922
+ }
923
+
924
+ if (!nativeBinding) {
925
+ if (loadErrors.length > 0) {
926
+ const error = new Error(
927
+ `Cannot find native binding. ` +
928
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
929
+ "Please try `npm i` again after removing both package-lock.json and node_modules directory.",
930
+ );
931
+ // assign instead of the `new Error(message, { cause })` options form,
932
+ // which Node < 16.9 silently ignores
933
+ error.cause = createLoadErrorChain(loadErrors);
934
+ throw error;
935
+ }
936
+ throw new Error(`Failed to load native binding`);
937
+ }
938
+
939
+ // A package can patch its own fallback in front of the load-failure check
940
+ // above, e.g. a WebContainer download through `napi-postinstall/fallback`.
941
+ // That fallback swaps `nativeBinding` for a generated WASI loader, which has
942
+ // already stamped its own flavor, while the target above still says 'native'.
943
+ // Take that flavor over, or the CommonJS stamp throws a conflict and the ESM
944
+ // export reports the wrong artifact. Three limits keep the conflict check:
945
+ // - only a binding this loader did not load itself, so a native addon whose
946
+ // `#[napi(module_exports)]` hook claims the name is still rejected;
947
+ // - only an own data property, read through its descriptor, so no addon
948
+ // getter runs here, and it must read back the same, as the stamp reads it;
949
+ // - only a flavor in `__napiWasiFlavors`, the ones this loader's own WASI
950
+ // chain can report ('wasm32-wasi' for a package without a WASI target).
951
+ // This is metadata and never fails a load: a throwing Proxy trap keeps 'native'.
952
+ if (__napiLoadedBindingTarget === "native" && nativeBinding !== __napiRequiredNativeBinding) {
953
+ try {
954
+ const __napiBindingTargetDescriptor = Object.getOwnPropertyDescriptor(
955
+ nativeBinding,
956
+ "__napiBindingTarget",
957
+ );
958
+ if (
959
+ __napiBindingTargetDescriptor &&
960
+ __napiWasiFlavors.indexOf(__napiBindingTargetDescriptor.value) !== -1 &&
961
+ nativeBinding.__napiBindingTarget === __napiBindingTargetDescriptor.value
962
+ ) {
963
+ __napiLoadedBindingTarget = __napiBindingTargetDescriptor.value;
964
+ }
965
+ } catch {
966
+ // keep 'native'
967
+ }
968
+ }
969
+
970
+ function __napiStampBindingTarget(exportsObject, target) {
971
+ if (Object.prototype.hasOwnProperty.call(exportsObject, "__napiBindingTarget")) {
972
+ if (exportsObject.__napiBindingTarget === target) {
973
+ // Already ours: the root entry aliases the object it loaded, so a WASI
974
+ // fallback candidate — or a `NAPI_RS_NATIVE_LIBRARY_PATH` override that
975
+ // is a generated loader — arrives already stamped with this same value.
976
+ return target;
977
+ }
978
+ const error = new Error(
979
+ '`__napiBindingTarget` is reserved by the generated binding loader, but the loaded binding already exports it. Rename the export, e.g. #[napi(js_name = "...")].',
980
+ );
981
+ error.code = "ERR_NAPI_BINDING_TARGET_CONFLICT";
982
+ throw error;
983
+ }
984
+ if (!Object.isExtensible(exportsObject)) {
985
+ // A `#[napi(module_exports)]` hook may seal or freeze this object
986
+ // (`Object::seal` / `Object::freeze`). Reporting the artifact is metadata,
987
+ // never a reason to fail an otherwise successful load, so the stamp is
988
+ // skipped. What a consumer still sees then follows the entry point: the
989
+ // browser and deferred loaders declare `__napiBindingTarget` at module
990
+ // level and go on reporting it, while the CommonJS entries hand back this
991
+ // very object as `module.exports`, so there the value is absent.
992
+ return target;
993
+ }
994
+ try {
995
+ // [[Define]], not [[Set]]: an ordinary assignment walks the prototype
996
+ // chain, so an inherited accessor could swallow the value or throw and
997
+ // fail an otherwise successful load. The descriptor is what a successful
998
+ // assignment would have produced.
999
+ Object.defineProperty(exportsObject, "__napiBindingTarget", {
1000
+ configurable: true,
1001
+ enumerable: true,
1002
+ value: target,
1003
+ writable: true,
1004
+ });
1005
+ } catch {
1006
+ // Same rule as the non-extensible skip above: reporting the artifact is
1007
+ // metadata, never a reason to fail an otherwise successful load. An exotic
1008
+ // object (a Proxy whose defineProperty trap refuses) is skipped, not
1009
+ // thrown over.
1010
+ }
1011
+ // The CommonJS loaders assign this return value so `cjs-module-lexer` — and
1012
+ // therefore Node's CJS -> ESM named export detection — can see
1013
+ // `__napiBindingTarget` statically.
1014
+ return target;
1015
+ }
1016
+ // Stamp before the alias, not after. The guard only reads `nativeBinding`
1017
+ // (`hasOwnProperty` plus a comparison), which is safe against any addon
1018
+ // accessor; an assignment is not, because a `#[napi(module_exports)]` hook can
1019
+ // expose a getter reporting this very value and a setter that throws. So the
1020
+ // assignment lands on the loader's own `module.exports`, still the original
1021
+ // object here, and the alias below replaces it.
1022
+ //
1023
+ // The assignment is what keeps the marker a statically visible CommonJS export:
1024
+ // `cjs-module-lexer` is Node's CJS -> ESM named export detection, it cannot see
1025
+ // a bare call, and the later `module.exports = nativeBinding` does not undo the
1026
+ // detection. The assignment itself always succeeds — its target is this
1027
+ // loader's own, still extensible `module.exports` — and the alias below then
1028
+ // discards the value it wrote. What a consumer reads is whatever the guard put
1029
+ // on `nativeBinding`, so on a frozen binding, where the guard skips, the
1030
+ // linked import resolves to `undefined`.
1031
+ module.exports.__napiBindingTarget = __napiStampBindingTarget(
1032
+ nativeBinding,
1033
+ __napiLoadedBindingTarget,
1034
+ );
1035
+ module.exports = nativeBinding;
1036
+ module.exports.splitMatter = nativeBinding.splitMatter;
1037
+ module.exports.ignore = nativeBinding.ignore;
1038
+ module.exports.toml = nativeBinding.toml;
1039
+ module.exports.watch = nativeBinding.watch;
1040
+ module.exports.yaml = nativeBinding.yaml;