@kreuzberg/html-to-markdown-node 3.4.0 → 3.5.0-rc.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/index.d.ts +668 -112
  3. package/index.js +109 -755
  4. package/package.json +10 -11
package/index.js CHANGED
@@ -1,786 +1,140 @@
1
- // prettier-ignore
2
- /* eslint-disable */
3
- // @ts-nocheck
4
- /* auto-generated by NAPI-RS */
5
-
6
- const { readFileSync } = require('node:fs')
7
- let nativeBinding = null;
8
- const loadErrors = [];
1
+ "use strict";
9
2
 
3
+ const { platform, arch } = process;
4
+ const isWindows = platform === "win32";
10
5
  const isMusl = () => {
11
- let musl = false;
12
- if (process.platform === "linux") {
13
- musl = isMuslFromFilesystem();
14
- if (musl === null) {
15
- musl = isMuslFromReport();
16
- }
17
- if (musl === null) {
18
- musl = isMuslFromChildProcess();
6
+ // Prefer the report-header `glibcVersion` string when present — fastest and
7
+ // unambiguous on Node builds that populate it. On Node 22+, certain CI
8
+ // environments leave `glibcVersion` undefined even on glibc systems, so the
9
+ // `=== undefined` branch from older napi-rs templates produces a false
10
+ // "is musl" positive. Fall through to the filesystem heuristic instead: on
11
+ // glibc systems `/lib64/ld-musl-x86_64.so.1` does not exist; on musl systems
12
+ // it always does. statSync errors → not musl.
13
+ if (typeof process.report === "object" && typeof process.report.getReport === "function") {
14
+ const report = process.report.getReport();
15
+ if (report && report.header && typeof report.header.glibcVersion === "string") {
16
+ return false;
19
17
  }
20
18
  }
21
- return musl;
22
- };
23
-
24
- const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
25
-
26
- const isMuslFromFilesystem = () => {
27
19
  try {
28
- return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
20
+ require("fs").statSync("/lib64/ld-musl-x86_64.so.1");
21
+ return true;
29
22
  } catch {
30
- return null;
31
- }
32
- };
33
-
34
- const isMuslFromReport = () => {
35
- let report = null;
36
- if (typeof process.report?.getReport === "function") {
37
- process.report.excludeNetwork = true;
38
- report = process.report.getReport();
39
- }
40
- if (!report) {
41
- return null;
42
- }
43
- if (report.header && report.header.glibcVersionRuntime) {
44
23
  return false;
45
24
  }
46
- if (Array.isArray(report.sharedObjects)) {
47
- if (report.sharedObjects.some(isFileMusl)) {
48
- return true;
49
- }
50
- }
51
- return false;
52
25
  };
53
26
 
54
- const isMuslFromChildProcess = () => {
27
+ let nativeBinding = null;
28
+ const loadErrors = [];
29
+
30
+ function requireOptionalDependency(name) {
55
31
  try {
56
- return require("child_process")
57
- .execSync("ldd --version", { encoding: "utf8" })
58
- .includes("musl");
32
+ return require(name);
59
33
  } catch (e) {
60
- // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
61
- return false;
34
+ loadErrors.push(`Optional dependency ${name}: ${e.message}`);
35
+ return null;
62
36
  }
63
- };
37
+ }
64
38
 
65
- function requireNative() {
66
- if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
67
- try {
68
- return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
69
- } catch (err) {
70
- loadErrors.push(err);
71
- }
72
- } else if (process.platform === "android") {
73
- if (process.arch === "arm64") {
74
- try {
75
- return require("./html-to-markdown-node.android-arm64.node");
76
- } catch (e) {
77
- loadErrors.push(e);
78
- }
79
- try {
80
- const binding = require("@kreuzberg/html-to-markdown-node-android-arm64");
81
- const bindingPackageVersion =
82
- require("@kreuzberg/html-to-markdown-node-android-arm64/package.json").version;
83
- if (
84
- bindingPackageVersion !== "3.4.0-rc.27" &&
85
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
86
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
87
- ) {
88
- throw new Error(
89
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
90
- );
91
- }
92
- return binding;
93
- } catch (e) {
94
- loadErrors.push(e);
95
- }
96
- } else if (process.arch === "arm") {
97
- try {
98
- return require("./html-to-markdown-node.android-arm-eabi.node");
99
- } catch (e) {
100
- loadErrors.push(e);
101
- }
102
- try {
103
- const binding = require("@kreuzberg/html-to-markdown-node-android-arm-eabi");
104
- const bindingPackageVersion =
105
- require("@kreuzberg/html-to-markdown-node-android-arm-eabi/package.json").version;
106
- if (
107
- bindingPackageVersion !== "3.4.0-rc.27" &&
108
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
109
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
110
- ) {
111
- throw new Error(
112
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
113
- );
114
- }
115
- return binding;
116
- } catch (e) {
117
- loadErrors.push(e);
118
- }
119
- } else {
120
- loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`));
39
+ const tryLoadBinding = () => {
40
+ const targets = [
41
+ [
42
+ "linux",
43
+ "x64",
44
+ "gnu",
45
+ "./html-to-markdown-node.linux-x64-gnu.node",
46
+ "html-to-markdown-node-linux-x64-gnu",
47
+ ],
48
+ [
49
+ "linux",
50
+ "x64",
51
+ "musl",
52
+ "./html-to-markdown-node.linux-x64-musl.node",
53
+ "html-to-markdown-node-linux-x64-musl",
54
+ ],
55
+ [
56
+ "linux",
57
+ "arm64",
58
+ "gnu",
59
+ "./html-to-markdown-node.linux-arm64-gnu.node",
60
+ "html-to-markdown-node-linux-arm64-gnu",
61
+ ],
62
+ [
63
+ "linux",
64
+ "arm64",
65
+ "musl",
66
+ "./html-to-markdown-node.linux-arm64-musl.node",
67
+ "html-to-markdown-node-linux-arm64-musl",
68
+ ],
69
+ [
70
+ "darwin",
71
+ "x64",
72
+ null,
73
+ "./html-to-markdown-node.darwin-x64.node",
74
+ "html-to-markdown-node-darwin-x64",
75
+ ],
76
+ [
77
+ "darwin",
78
+ "arm64",
79
+ null,
80
+ "./html-to-markdown-node.darwin-arm64.node",
81
+ "html-to-markdown-node-darwin-arm64",
82
+ ],
83
+ [
84
+ "win32",
85
+ "x64",
86
+ null,
87
+ "./html-to-markdown-node.win32-x64-msvc.node",
88
+ "html-to-markdown-node-win32-x64-msvc",
89
+ ],
90
+ [
91
+ "win32",
92
+ "arm64",
93
+ null,
94
+ "./html-to-markdown-node.win32-arm64-msvc.node",
95
+ "html-to-markdown-node-win32-arm64-msvc",
96
+ ],
97
+ ];
98
+
99
+ for (const [plat, a, abi, localPath, optionalDep] of targets) {
100
+ if (platform !== plat || arch !== a) {
101
+ continue;
121
102
  }
122
- } else if (process.platform === "win32") {
123
- if (process.arch === "x64") {
124
- if (
125
- process.config?.variables?.shlib_suffix === "dll.a" ||
126
- process.config?.variables?.node_target_type === "shared_library"
127
- ) {
128
- try {
129
- return require("./html-to-markdown-node.win32-x64-gnu.node");
130
- } catch (e) {
131
- loadErrors.push(e);
132
- }
133
- try {
134
- const binding = require("@kreuzberg/html-to-markdown-node-win32-x64-gnu");
135
- const bindingPackageVersion =
136
- require("@kreuzberg/html-to-markdown-node-win32-x64-gnu/package.json").version;
137
- if (
138
- bindingPackageVersion !== "3.4.0-rc.27" &&
139
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
140
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
141
- ) {
142
- throw new Error(
143
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
144
- );
145
- }
146
- return binding;
147
- } catch (e) {
148
- loadErrors.push(e);
149
- }
150
- } else {
151
- try {
152
- return require("./html-to-markdown-node.win32-x64-msvc.node");
153
- } catch (e) {
154
- loadErrors.push(e);
155
- }
156
- try {
157
- const binding = require("@kreuzberg/html-to-markdown-node-win32-x64-msvc");
158
- const bindingPackageVersion =
159
- require("@kreuzberg/html-to-markdown-node-win32-x64-msvc/package.json").version;
160
- if (
161
- bindingPackageVersion !== "3.4.0-rc.27" &&
162
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
163
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
164
- ) {
165
- throw new Error(
166
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
167
- );
168
- }
169
- return binding;
170
- } catch (e) {
171
- loadErrors.push(e);
172
- }
173
- }
174
- } else if (process.arch === "ia32") {
175
- try {
176
- return require("./html-to-markdown-node.win32-ia32-msvc.node");
177
- } catch (e) {
178
- loadErrors.push(e);
179
- }
180
- try {
181
- const binding = require("@kreuzberg/html-to-markdown-node-win32-ia32-msvc");
182
- const bindingPackageVersion =
183
- require("@kreuzberg/html-to-markdown-node-win32-ia32-msvc/package.json").version;
184
- if (
185
- bindingPackageVersion !== "3.4.0-rc.27" &&
186
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
187
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
188
- ) {
189
- throw new Error(
190
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
191
- );
192
- }
193
- return binding;
194
- } catch (e) {
195
- loadErrors.push(e);
196
- }
197
- } else if (process.arch === "arm64") {
198
- try {
199
- return require("./html-to-markdown-node.win32-arm64-msvc.node");
200
- } catch (e) {
201
- loadErrors.push(e);
202
- }
203
- try {
204
- const binding = require("@kreuzberg/html-to-markdown-node-win32-arm64-msvc");
205
- const bindingPackageVersion =
206
- require("@kreuzberg/html-to-markdown-node-win32-arm64-msvc/package.json").version;
207
- if (
208
- bindingPackageVersion !== "3.4.0-rc.27" &&
209
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
210
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
211
- ) {
212
- throw new Error(
213
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
214
- );
215
- }
216
- return binding;
217
- } catch (e) {
218
- loadErrors.push(e);
103
+
104
+ if (plat === "linux" && abi) {
105
+ const isCurMusl = isMusl();
106
+ if ((abi === "musl") !== isCurMusl) {
107
+ continue;
219
108
  }
220
- } else {
221
- loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));
222
- }
223
- } else if (process.platform === "darwin") {
224
- try {
225
- return require("./html-to-markdown-node.darwin-universal.node");
226
- } catch (e) {
227
- loadErrors.push(e);
228
109
  }
110
+
229
111
  try {
230
- const binding = require("@kreuzberg/html-to-markdown-node-darwin-universal");
231
- const bindingPackageVersion =
232
- require("@kreuzberg/html-to-markdown-node-darwin-universal/package.json").version;
233
- if (
234
- bindingPackageVersion !== "3.4.0-rc.27" &&
235
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
236
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
237
- ) {
238
- throw new Error(
239
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
240
- );
112
+ nativeBinding = require(localPath);
113
+ if (nativeBinding) {
114
+ return;
241
115
  }
242
- return binding;
243
116
  } catch (e) {
244
- loadErrors.push(e);
117
+ loadErrors.push(e.message);
245
118
  }
246
- if (process.arch === "x64") {
247
- try {
248
- return require("./html-to-markdown-node.darwin-x64.node");
249
- } catch (e) {
250
- loadErrors.push(e);
251
- }
252
- try {
253
- const binding = require("@kreuzberg/html-to-markdown-node-darwin-x64");
254
- const bindingPackageVersion =
255
- require("@kreuzberg/html-to-markdown-node-darwin-x64/package.json").version;
256
- if (
257
- bindingPackageVersion !== "3.4.0-rc.27" &&
258
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
259
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
260
- ) {
261
- throw new Error(
262
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
263
- );
264
- }
265
- return binding;
266
- } catch (e) {
267
- loadErrors.push(e);
268
- }
269
- } else if (process.arch === "arm64") {
270
- try {
271
- return require("./html-to-markdown-node.darwin-arm64.node");
272
- } catch (e) {
273
- loadErrors.push(e);
274
- }
275
- try {
276
- const binding = require("@kreuzberg/html-to-markdown-node-darwin-arm64");
277
- const bindingPackageVersion =
278
- require("@kreuzberg/html-to-markdown-node-darwin-arm64/package.json").version;
279
- if (
280
- bindingPackageVersion !== "3.4.0-rc.27" &&
281
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
282
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
283
- ) {
284
- throw new Error(
285
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
286
- );
287
- }
288
- return binding;
289
- } catch (e) {
290
- loadErrors.push(e);
291
- }
292
- } else {
293
- loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`));
294
- }
295
- } else if (process.platform === "freebsd") {
296
- if (process.arch === "x64") {
297
- try {
298
- return require("./html-to-markdown-node.freebsd-x64.node");
299
- } catch (e) {
300
- loadErrors.push(e);
301
- }
302
- try {
303
- const binding = require("@kreuzberg/html-to-markdown-node-freebsd-x64");
304
- const bindingPackageVersion =
305
- require("@kreuzberg/html-to-markdown-node-freebsd-x64/package.json").version;
306
- if (
307
- bindingPackageVersion !== "3.4.0-rc.27" &&
308
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
309
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
310
- ) {
311
- throw new Error(
312
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
313
- );
314
- }
315
- return binding;
316
- } catch (e) {
317
- loadErrors.push(e);
318
- }
319
- } else if (process.arch === "arm64") {
320
- try {
321
- return require("./html-to-markdown-node.freebsd-arm64.node");
322
- } catch (e) {
323
- loadErrors.push(e);
324
- }
325
- try {
326
- const binding = require("@kreuzberg/html-to-markdown-node-freebsd-arm64");
327
- const bindingPackageVersion =
328
- require("@kreuzberg/html-to-markdown-node-freebsd-arm64/package.json").version;
329
- if (
330
- bindingPackageVersion !== "3.4.0-rc.27" &&
331
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
332
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
333
- ) {
334
- throw new Error(
335
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
336
- );
337
- }
338
- return binding;
339
- } catch (e) {
340
- loadErrors.push(e);
341
- }
342
- } else {
343
- loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
344
- }
345
- } else if (process.platform === "linux") {
346
- if (process.arch === "x64") {
347
- if (isMusl()) {
348
- try {
349
- return require("./html-to-markdown-node.linux-x64-musl.node");
350
- } catch (e) {
351
- loadErrors.push(e);
352
- }
353
- try {
354
- const binding = require("@kreuzberg/html-to-markdown-node-linux-x64-musl");
355
- const bindingPackageVersion =
356
- require("@kreuzberg/html-to-markdown-node-linux-x64-musl/package.json").version;
357
- if (
358
- bindingPackageVersion !== "3.4.0-rc.27" &&
359
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
360
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
361
- ) {
362
- throw new Error(
363
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
364
- );
365
- }
366
- return binding;
367
- } catch (e) {
368
- loadErrors.push(e);
369
- }
370
- } else {
371
- try {
372
- return require("./html-to-markdown-node.linux-x64-gnu.node");
373
- } catch (e) {
374
- loadErrors.push(e);
375
- }
376
- try {
377
- const binding = require("@kreuzberg/html-to-markdown-node-linux-x64-gnu");
378
- const bindingPackageVersion =
379
- require("@kreuzberg/html-to-markdown-node-linux-x64-gnu/package.json").version;
380
- if (
381
- bindingPackageVersion !== "3.4.0-rc.27" &&
382
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
383
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
384
- ) {
385
- throw new Error(
386
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
387
- );
388
- }
389
- return binding;
390
- } catch (e) {
391
- loadErrors.push(e);
392
- }
393
- }
394
- } else if (process.arch === "arm64") {
395
- if (isMusl()) {
396
- try {
397
- return require("./html-to-markdown-node.linux-arm64-musl.node");
398
- } catch (e) {
399
- loadErrors.push(e);
400
- }
401
- try {
402
- const binding = require("@kreuzberg/html-to-markdown-node-linux-arm64-musl");
403
- const bindingPackageVersion =
404
- require("@kreuzberg/html-to-markdown-node-linux-arm64-musl/package.json").version;
405
- if (
406
- bindingPackageVersion !== "3.4.0-rc.27" &&
407
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
408
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
409
- ) {
410
- throw new Error(
411
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
412
- );
413
- }
414
- return binding;
415
- } catch (e) {
416
- loadErrors.push(e);
417
- }
418
- } else {
419
- try {
420
- return require("./html-to-markdown-node.linux-arm64-gnu.node");
421
- } catch (e) {
422
- loadErrors.push(e);
423
- }
424
- try {
425
- const binding = require("@kreuzberg/html-to-markdown-node-linux-arm64-gnu");
426
- const bindingPackageVersion =
427
- require("@kreuzberg/html-to-markdown-node-linux-arm64-gnu/package.json").version;
428
- if (
429
- bindingPackageVersion !== "3.4.0-rc.27" &&
430
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
431
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
432
- ) {
433
- throw new Error(
434
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
435
- );
436
- }
437
- return binding;
438
- } catch (e) {
439
- loadErrors.push(e);
440
- }
441
- }
442
- } else if (process.arch === "arm") {
443
- if (isMusl()) {
444
- try {
445
- return require("./html-to-markdown-node.linux-arm-musleabihf.node");
446
- } catch (e) {
447
- loadErrors.push(e);
448
- }
449
- try {
450
- const binding = require("@kreuzberg/html-to-markdown-node-linux-arm-musleabihf");
451
- const bindingPackageVersion =
452
- require("@kreuzberg/html-to-markdown-node-linux-arm-musleabihf/package.json").version;
453
- if (
454
- bindingPackageVersion !== "3.4.0-rc.27" &&
455
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
456
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
457
- ) {
458
- throw new Error(
459
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
460
- );
461
- }
462
- return binding;
463
- } catch (e) {
464
- loadErrors.push(e);
465
- }
466
- } else {
467
- try {
468
- return require("./html-to-markdown-node.linux-arm-gnueabihf.node");
469
- } catch (e) {
470
- loadErrors.push(e);
471
- }
472
- try {
473
- const binding = require("@kreuzberg/html-to-markdown-node-linux-arm-gnueabihf");
474
- const bindingPackageVersion =
475
- require("@kreuzberg/html-to-markdown-node-linux-arm-gnueabihf/package.json").version;
476
- if (
477
- bindingPackageVersion !== "3.4.0-rc.27" &&
478
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
479
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
480
- ) {
481
- throw new Error(
482
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
483
- );
484
- }
485
- return binding;
486
- } catch (e) {
487
- loadErrors.push(e);
488
- }
489
- }
490
- } else if (process.arch === "loong64") {
491
- if (isMusl()) {
492
- try {
493
- return require("./html-to-markdown-node.linux-loong64-musl.node");
494
- } catch (e) {
495
- loadErrors.push(e);
496
- }
497
- try {
498
- const binding = require("@kreuzberg/html-to-markdown-node-linux-loong64-musl");
499
- const bindingPackageVersion =
500
- require("@kreuzberg/html-to-markdown-node-linux-loong64-musl/package.json").version;
501
- if (
502
- bindingPackageVersion !== "3.4.0-rc.27" &&
503
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
504
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
505
- ) {
506
- throw new Error(
507
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
508
- );
509
- }
510
- return binding;
511
- } catch (e) {
512
- loadErrors.push(e);
513
- }
514
- } else {
515
- try {
516
- return require("./html-to-markdown-node.linux-loong64-gnu.node");
517
- } catch (e) {
518
- loadErrors.push(e);
519
- }
520
- try {
521
- const binding = require("@kreuzberg/html-to-markdown-node-linux-loong64-gnu");
522
- const bindingPackageVersion =
523
- require("@kreuzberg/html-to-markdown-node-linux-loong64-gnu/package.json").version;
524
- if (
525
- bindingPackageVersion !== "3.4.0-rc.27" &&
526
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
527
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
528
- ) {
529
- throw new Error(
530
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
531
- );
532
- }
533
- return binding;
534
- } catch (e) {
535
- loadErrors.push(e);
536
- }
537
- }
538
- } else if (process.arch === "riscv64") {
539
- if (isMusl()) {
540
- try {
541
- return require("./html-to-markdown-node.linux-riscv64-musl.node");
542
- } catch (e) {
543
- loadErrors.push(e);
544
- }
545
- try {
546
- const binding = require("@kreuzberg/html-to-markdown-node-linux-riscv64-musl");
547
- const bindingPackageVersion =
548
- require("@kreuzberg/html-to-markdown-node-linux-riscv64-musl/package.json").version;
549
- if (
550
- bindingPackageVersion !== "3.4.0-rc.27" &&
551
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
552
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
553
- ) {
554
- throw new Error(
555
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
556
- );
557
- }
558
- return binding;
559
- } catch (e) {
560
- loadErrors.push(e);
561
- }
562
- } else {
563
- try {
564
- return require("./html-to-markdown-node.linux-riscv64-gnu.node");
565
- } catch (e) {
566
- loadErrors.push(e);
567
- }
568
- try {
569
- const binding = require("@kreuzberg/html-to-markdown-node-linux-riscv64-gnu");
570
- const bindingPackageVersion =
571
- require("@kreuzberg/html-to-markdown-node-linux-riscv64-gnu/package.json").version;
572
- if (
573
- bindingPackageVersion !== "3.4.0-rc.27" &&
574
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
575
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
576
- ) {
577
- throw new Error(
578
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
579
- );
580
- }
581
- return binding;
582
- } catch (e) {
583
- loadErrors.push(e);
584
- }
585
- }
586
- } else if (process.arch === "ppc64") {
587
- try {
588
- return require("./html-to-markdown-node.linux-ppc64-gnu.node");
589
- } catch (e) {
590
- loadErrors.push(e);
591
- }
592
- try {
593
- const binding = require("@kreuzberg/html-to-markdown-node-linux-ppc64-gnu");
594
- const bindingPackageVersion =
595
- require("@kreuzberg/html-to-markdown-node-linux-ppc64-gnu/package.json").version;
596
- if (
597
- bindingPackageVersion !== "3.4.0-rc.27" &&
598
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
599
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
600
- ) {
601
- throw new Error(
602
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
603
- );
604
- }
605
- return binding;
606
- } catch (e) {
607
- loadErrors.push(e);
608
- }
609
- } else if (process.arch === "s390x") {
610
- try {
611
- return require("./html-to-markdown-node.linux-s390x-gnu.node");
612
- } catch (e) {
613
- loadErrors.push(e);
614
- }
615
- try {
616
- const binding = require("@kreuzberg/html-to-markdown-node-linux-s390x-gnu");
617
- const bindingPackageVersion =
618
- require("@kreuzberg/html-to-markdown-node-linux-s390x-gnu/package.json").version;
619
- if (
620
- bindingPackageVersion !== "3.4.0-rc.27" &&
621
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
622
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
623
- ) {
624
- throw new Error(
625
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
626
- );
627
- }
628
- return binding;
629
- } catch (e) {
630
- loadErrors.push(e);
631
- }
632
- } else {
633
- loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`));
634
- }
635
- } else if (process.platform === "openharmony") {
636
- if (process.arch === "arm64") {
637
- try {
638
- return require("./html-to-markdown-node.openharmony-arm64.node");
639
- } catch (e) {
640
- loadErrors.push(e);
641
- }
642
- try {
643
- const binding = require("@kreuzberg/html-to-markdown-node-openharmony-arm64");
644
- const bindingPackageVersion =
645
- require("@kreuzberg/html-to-markdown-node-openharmony-arm64/package.json").version;
646
- if (
647
- bindingPackageVersion !== "3.4.0-rc.27" &&
648
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
649
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
650
- ) {
651
- throw new Error(
652
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
653
- );
654
- }
655
- return binding;
656
- } catch (e) {
657
- loadErrors.push(e);
658
- }
659
- } else if (process.arch === "x64") {
660
- try {
661
- return require("./html-to-markdown-node.openharmony-x64.node");
662
- } catch (e) {
663
- loadErrors.push(e);
664
- }
665
- try {
666
- const binding = require("@kreuzberg/html-to-markdown-node-openharmony-x64");
667
- const bindingPackageVersion =
668
- require("@kreuzberg/html-to-markdown-node-openharmony-x64/package.json").version;
669
- if (
670
- bindingPackageVersion !== "3.4.0-rc.27" &&
671
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
672
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
673
- ) {
674
- throw new Error(
675
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
676
- );
677
- }
678
- return binding;
679
- } catch (e) {
680
- loadErrors.push(e);
681
- }
682
- } else if (process.arch === "arm") {
683
- try {
684
- return require("./html-to-markdown-node.openharmony-arm.node");
685
- } catch (e) {
686
- loadErrors.push(e);
687
- }
688
- try {
689
- const binding = require("@kreuzberg/html-to-markdown-node-openharmony-arm");
690
- const bindingPackageVersion =
691
- require("@kreuzberg/html-to-markdown-node-openharmony-arm/package.json").version;
692
- if (
693
- bindingPackageVersion !== "3.4.0-rc.27" &&
694
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
695
- process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
696
- ) {
697
- throw new Error(
698
- `Native binding package version mismatch, expected 3.4.0-rc.27 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
699
- );
700
- }
701
- return binding;
702
- } catch (e) {
703
- loadErrors.push(e);
704
- }
705
- } else {
706
- loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`));
707
- }
708
- } else {
709
- loadErrors.push(
710
- new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`),
711
- );
712
- }
713
- }
714
-
715
- nativeBinding = requireNative();
716
119
 
717
- if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
718
- let wasiBinding = null;
719
- let wasiBindingError = null;
720
- try {
721
- wasiBinding = require("./html-to-markdown-node.wasi.cjs");
722
- nativeBinding = wasiBinding;
723
- } catch (err) {
724
- if (process.env.NAPI_RS_FORCE_WASI) {
725
- wasiBindingError = err;
726
- }
727
- }
728
- if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
729
120
  try {
730
- wasiBinding = require("@kreuzberg/html-to-markdown-node-wasm32-wasi");
731
- nativeBinding = wasiBinding;
732
- } catch (err) {
733
- if (process.env.NAPI_RS_FORCE_WASI) {
734
- if (!wasiBindingError) {
735
- wasiBindingError = err;
736
- } else {
737
- wasiBindingError.cause = err;
738
- }
739
- loadErrors.push(err);
121
+ const optBinding = requireOptionalDependency(optionalDep);
122
+ if (optBinding) {
123
+ nativeBinding = optBinding;
124
+ return;
740
125
  }
126
+ } catch (e) {
127
+ loadErrors.push(e.message);
741
128
  }
742
129
  }
743
- if (process.env.NAPI_RS_FORCE_WASI === "error" && !wasiBinding) {
744
- const error = new Error("WASI binding not found and NAPI_RS_FORCE_WASI is set to error");
745
- error.cause = wasiBindingError;
746
- throw error;
747
- }
748
- }
130
+ };
131
+
132
+ tryLoadBinding();
749
133
 
750
134
  if (!nativeBinding) {
751
- if (loadErrors.length > 0) {
752
- throw new Error(
753
- `Cannot find native binding. ` +
754
- `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
755
- "Please try `npm i` again after removing both package-lock.json and node_modules directory.",
756
- {
757
- cause: loadErrors.reduce((err, cur) => {
758
- cur.cause = err;
759
- return cur;
760
- }),
761
- },
762
- );
763
- }
764
- throw new Error(`Failed to load native binding`);
135
+ throw new Error(
136
+ `Failed to load native binding for ${platform}-${arch}. Errors: ${loadErrors.join(", ")}`,
137
+ );
765
138
  }
766
139
 
767
140
  module.exports = nativeBinding;
768
- module.exports.JsConversionOptionsBuilder = nativeBinding.JsConversionOptionsBuilder;
769
- module.exports.JsVisitorHandle = nativeBinding.JsVisitorHandle;
770
- module.exports.convert = nativeBinding.convert;
771
- module.exports.JsCodeBlockStyle = nativeBinding.JsCodeBlockStyle;
772
- module.exports.JsHeadingStyle = nativeBinding.JsHeadingStyle;
773
- module.exports.JsHighlightStyle = nativeBinding.JsHighlightStyle;
774
- module.exports.JsImageType = nativeBinding.JsImageType;
775
- module.exports.JsLinkStyle = nativeBinding.JsLinkStyle;
776
- module.exports.JsLinkType = nativeBinding.JsLinkType;
777
- module.exports.JsListIndentType = nativeBinding.JsListIndentType;
778
- module.exports.JsNewlineStyle = nativeBinding.JsNewlineStyle;
779
- module.exports.JsNodeType = nativeBinding.JsNodeType;
780
- module.exports.JsOutputFormat = nativeBinding.JsOutputFormat;
781
- module.exports.JsPreprocessingPreset = nativeBinding.JsPreprocessingPreset;
782
- module.exports.JsStructuredDataType = nativeBinding.JsStructuredDataType;
783
- module.exports.JsTextDirection = nativeBinding.JsTextDirection;
784
- module.exports.JsVisitResult = nativeBinding.JsVisitResult;
785
- module.exports.JsWarningKind = nativeBinding.JsWarningKind;
786
- module.exports.JsWhitespaceMode = nativeBinding.JsWhitespaceMode;