@jongleberry/vurst-markdown 0.0.4 → 0.1.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/index.d.ts CHANGED
@@ -1,6 +1,17 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
1
3
  /// <reference types="node" />
2
4
 
3
- export interface Chunk {
5
+ export declare function chunk(text: Buffer, options?: ChunkOptions | undefined | null): Promise<Array<Chunk>>
6
+
7
+ export declare function extractMarkdownUrls(text: Buffer): Promise<MarkdownUrls>
8
+
9
+ export interface MarkdownUrls {
10
+ linkUrls: Array<string>
11
+ imageUrls: Array<string>
12
+ }
13
+
14
+ export interface NapiChunk {
4
15
  level: number
5
16
  header?: string
6
17
  headers: Array<string | undefined | null>
@@ -9,13 +20,17 @@ export interface Chunk {
9
20
  length: number
10
21
  }
11
22
 
12
- export interface ChunkOptions {
23
+ export interface Chunk extends NapiChunk {}
24
+
25
+ export interface NapiChunkOptions {
13
26
  minLength?: number
14
27
  maxLength?: number
15
28
  phase?: number
16
29
  title?: string
17
30
  }
18
31
 
32
+ export interface ChunkOptions extends NapiChunkOptions {}
33
+
19
34
  export interface NapiMarkdownRenderOptions {
20
35
  allowHtml?: boolean
21
36
  nofollowLinks?: boolean
@@ -24,21 +39,6 @@ export interface NapiMarkdownRenderOptions {
24
39
  imageProxySigningKeys?: Array<string>
25
40
  }
26
41
 
27
- export interface MarkdownUrls {
28
- linkUrls: Array<string>
29
- imageUrls: Array<string>
30
- }
42
+ export declare function renderMarkdownToHtml(text: Buffer, options?: NapiMarkdownRenderOptions | undefined | null): Promise<Buffer>
31
43
 
32
- export declare function chunk(text: Buffer, options?: ChunkOptions): Promise<Array<Chunk>>
33
-
34
- export declare function renderMarkdownToHtml(
35
- text: Buffer,
36
- options?: NapiMarkdownRenderOptions,
37
- ): Promise<Buffer>
38
-
39
- export declare function renderMarkdownToHtmlBatch(
40
- inputs: Array<Buffer>,
41
- options?: NapiMarkdownRenderOptions,
42
- ): Promise<Array<Buffer>>
43
-
44
- export declare function extractMarkdownUrls(text: Buffer): Promise<MarkdownUrls>
44
+ export declare function renderMarkdownToHtmlBatch(inputs: Array<Buffer>, options?: NapiMarkdownRenderOptions | undefined | null): Promise<Array<Buffer>>
package/index.js CHANGED
@@ -1,28 +1,612 @@
1
- 'use strict'
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ /* auto-generated by NAPI-RS */
2
5
 
3
- // Platform dispatcher for @jongleberry/vurst-markdown.
6
+ const { readFileSync } = require('node:fs')
7
+ let nativeBinding = null
8
+ const loadErrors = []
9
+ const supportedPlatforms = 'macOS arm64, Linux x64 glibc, and Linux arm64 glibc'
4
10
 
5
- const { platform, arch } = process
11
+ const isPublishedPlatform = () => {
12
+ if (process.platform === 'darwin') {
13
+ return process.arch === 'arm64'
14
+ }
15
+ if (process.platform === 'linux') {
16
+ return (process.arch === 'x64' || process.arch === 'arm64') && !isMusl()
17
+ }
18
+ return false
19
+ }
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 (typeof process.report?.getReport === 'function') {
48
+ const previousExcludeNetwork = process.report.excludeNetwork
49
+ try {
50
+ process.report.excludeNetwork = true
51
+ report = process.report.getReport()
52
+ } finally {
53
+ process.report.excludeNetwork = previousExcludeNetwork
54
+ }
55
+ }
56
+ if (!report) {
57
+ return null
58
+ }
59
+ if (report.header && report.header.glibcVersionRuntime) {
60
+ return false
61
+ }
62
+ if (Array.isArray(report.sharedObjects)) {
63
+ if (report.sharedObjects.some(isFileMusl)) {
64
+ return true
65
+ }
66
+ }
67
+ return false
68
+ }
69
+
70
+ const isMuslFromChildProcess = () => {
71
+ try {
72
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
73
+ } catch (e) {
74
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
75
+ return false
76
+ }
77
+ }
78
+
79
+ function requireNative() {
80
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
81
+ try {
82
+ return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
83
+ } catch (err) {
84
+ loadErrors.push(err)
85
+ }
86
+ } else if (process.platform === 'android') {
87
+ if (process.arch === 'arm64') {
88
+ try {
89
+ return require('./vurst-markdown.android-arm64.node')
90
+ } catch (e) {
91
+ loadErrors.push(e)
92
+ }
93
+ try {
94
+ const binding = require('@jongleberry/vurst-markdown-android-arm64')
95
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-android-arm64/package.json').version
96
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
98
+ }
99
+ return binding
100
+ } catch (e) {
101
+ loadErrors.push(e)
102
+ }
103
+ } else if (process.arch === 'arm') {
104
+ try {
105
+ return require('./vurst-markdown.android-arm-eabi.node')
106
+ } catch (e) {
107
+ loadErrors.push(e)
108
+ }
109
+ try {
110
+ const binding = require('@jongleberry/vurst-markdown-android-arm-eabi')
111
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-android-arm-eabi/package.json').version
112
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
113
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
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}`))
121
+ }
122
+ } else if (process.platform === 'win32') {
123
+ if (process.arch === 'x64') {
124
+ if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
125
+ try {
126
+ return require('./vurst-markdown.win32-x64-gnu.node')
127
+ } catch (e) {
128
+ loadErrors.push(e)
129
+ }
130
+ try {
131
+ const binding = require('@jongleberry/vurst-markdown-win32-x64-gnu')
132
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-win32-x64-gnu/package.json').version
133
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
135
+ }
136
+ return binding
137
+ } catch (e) {
138
+ loadErrors.push(e)
139
+ }
140
+ } else {
141
+ try {
142
+ return require('./vurst-markdown.win32-x64-msvc.node')
143
+ } catch (e) {
144
+ loadErrors.push(e)
145
+ }
146
+ try {
147
+ const binding = require('@jongleberry/vurst-markdown-win32-x64-msvc')
148
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-win32-x64-msvc/package.json').version
149
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
150
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
151
+ }
152
+ return binding
153
+ } catch (e) {
154
+ loadErrors.push(e)
155
+ }
156
+ }
157
+ } else if (process.arch === 'ia32') {
158
+ try {
159
+ return require('./vurst-markdown.win32-ia32-msvc.node')
160
+ } catch (e) {
161
+ loadErrors.push(e)
162
+ }
163
+ try {
164
+ const binding = require('@jongleberry/vurst-markdown-win32-ia32-msvc')
165
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-win32-ia32-msvc/package.json').version
166
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
168
+ }
169
+ return binding
170
+ } catch (e) {
171
+ loadErrors.push(e)
172
+ }
173
+ } else if (process.arch === 'arm64') {
174
+ try {
175
+ return require('./vurst-markdown.win32-arm64-msvc.node')
176
+ } catch (e) {
177
+ loadErrors.push(e)
178
+ }
179
+ try {
180
+ const binding = require('@jongleberry/vurst-markdown-win32-arm64-msvc')
181
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-win32-arm64-msvc/package.json').version
182
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
183
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
184
+ }
185
+ return binding
186
+ } catch (e) {
187
+ loadErrors.push(e)
188
+ }
189
+ } else {
190
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
191
+ }
192
+ } else if (process.platform === 'darwin') {
193
+ try {
194
+ return require('./vurst-markdown.darwin-universal.node')
195
+ } catch (e) {
196
+ loadErrors.push(e)
197
+ }
198
+ try {
199
+ const binding = require('@jongleberry/vurst-markdown-darwin-universal')
200
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-darwin-universal/package.json').version
201
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
+ }
204
+ return binding
205
+ } catch (e) {
206
+ loadErrors.push(e)
207
+ }
208
+ if (process.arch === 'x64') {
209
+ try {
210
+ return require('./vurst-markdown.darwin-x64.node')
211
+ } catch (e) {
212
+ loadErrors.push(e)
213
+ }
214
+ try {
215
+ const binding = require('@jongleberry/vurst-markdown-darwin-x64')
216
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-darwin-x64/package.json').version
217
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
219
+ }
220
+ return binding
221
+ } catch (e) {
222
+ loadErrors.push(e)
223
+ }
224
+ } else if (process.arch === 'arm64') {
225
+ try {
226
+ return require('./vurst-markdown.darwin-arm64.node')
227
+ } catch (e) {
228
+ loadErrors.push(e)
229
+ }
230
+ try {
231
+ const binding = require('@jongleberry/vurst-markdown-darwin-arm64')
232
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-darwin-arm64/package.json').version
233
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
234
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
235
+ }
236
+ return binding
237
+ } catch (e) {
238
+ loadErrors.push(e)
239
+ }
240
+ } else {
241
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
242
+ }
243
+ } else if (process.platform === 'freebsd') {
244
+ if (process.arch === 'x64') {
245
+ try {
246
+ return require('./vurst-markdown.freebsd-x64.node')
247
+ } catch (e) {
248
+ loadErrors.push(e)
249
+ }
250
+ try {
251
+ const binding = require('@jongleberry/vurst-markdown-freebsd-x64')
252
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-freebsd-x64/package.json').version
253
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
255
+ }
256
+ return binding
257
+ } catch (e) {
258
+ loadErrors.push(e)
259
+ }
260
+ } else if (process.arch === 'arm64') {
261
+ try {
262
+ return require('./vurst-markdown.freebsd-arm64.node')
263
+ } catch (e) {
264
+ loadErrors.push(e)
265
+ }
266
+ try {
267
+ const binding = require('@jongleberry/vurst-markdown-freebsd-arm64')
268
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-freebsd-arm64/package.json').version
269
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
270
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
271
+ }
272
+ return binding
273
+ } catch (e) {
274
+ loadErrors.push(e)
275
+ }
276
+ } else {
277
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
278
+ }
279
+ } else if (process.platform === 'linux') {
280
+ if (process.arch === 'x64') {
281
+ if (isMusl()) {
282
+ try {
283
+ return require('./vurst-markdown.linux-x64-musl.node')
284
+ } catch (e) {
285
+ loadErrors.push(e)
286
+ }
287
+ try {
288
+ const binding = require('@jongleberry/vurst-markdown-linux-x64-musl')
289
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-x64-musl/package.json').version
290
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
292
+ }
293
+ return binding
294
+ } catch (e) {
295
+ loadErrors.push(e)
296
+ }
297
+ } else {
298
+ try {
299
+ return require('./vurst-markdown.linux-x64-gnu.node')
300
+ } catch (e) {
301
+ loadErrors.push(e)
302
+ }
303
+ try {
304
+ const binding = require('@jongleberry/vurst-markdown-linux-x64-gnu')
305
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-x64-gnu/package.json').version
306
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
307
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
308
+ }
309
+ return binding
310
+ } catch (e) {
311
+ loadErrors.push(e)
312
+ }
313
+ }
314
+ } else if (process.arch === 'arm64') {
315
+ if (isMusl()) {
316
+ try {
317
+ return require('./vurst-markdown.linux-arm64-musl.node')
318
+ } catch (e) {
319
+ loadErrors.push(e)
320
+ }
321
+ try {
322
+ const binding = require('@jongleberry/vurst-markdown-linux-arm64-musl')
323
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-arm64-musl/package.json').version
324
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
+ }
327
+ return binding
328
+ } catch (e) {
329
+ loadErrors.push(e)
330
+ }
331
+ } else {
332
+ try {
333
+ return require('./vurst-markdown.linux-arm64-gnu.node')
334
+ } catch (e) {
335
+ loadErrors.push(e)
336
+ }
337
+ try {
338
+ const binding = require('@jongleberry/vurst-markdown-linux-arm64-gnu')
339
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-arm64-gnu/package.json').version
340
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
341
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
342
+ }
343
+ return binding
344
+ } catch (e) {
345
+ loadErrors.push(e)
346
+ }
347
+ }
348
+ } else if (process.arch === 'arm') {
349
+ if (isMusl()) {
350
+ try {
351
+ return require('./vurst-markdown.linux-arm-musleabihf.node')
352
+ } catch (e) {
353
+ loadErrors.push(e)
354
+ }
355
+ try {
356
+ const binding = require('@jongleberry/vurst-markdown-linux-arm-musleabihf')
357
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-arm-musleabihf/package.json').version
358
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
+ }
361
+ return binding
362
+ } catch (e) {
363
+ loadErrors.push(e)
364
+ }
365
+ } else {
366
+ try {
367
+ return require('./vurst-markdown.linux-arm-gnueabihf.node')
368
+ } catch (e) {
369
+ loadErrors.push(e)
370
+ }
371
+ try {
372
+ const binding = require('@jongleberry/vurst-markdown-linux-arm-gnueabihf')
373
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-arm-gnueabihf/package.json').version
374
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
375
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
376
+ }
377
+ return binding
378
+ } catch (e) {
379
+ loadErrors.push(e)
380
+ }
381
+ }
382
+ } else if (process.arch === 'loong64') {
383
+ if (isMusl()) {
384
+ try {
385
+ return require('./vurst-markdown.linux-loong64-musl.node')
386
+ } catch (e) {
387
+ loadErrors.push(e)
388
+ }
389
+ try {
390
+ const binding = require('@jongleberry/vurst-markdown-linux-loong64-musl')
391
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-loong64-musl/package.json').version
392
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
+ }
395
+ return binding
396
+ } catch (e) {
397
+ loadErrors.push(e)
398
+ }
399
+ } else {
400
+ try {
401
+ return require('./vurst-markdown.linux-loong64-gnu.node')
402
+ } catch (e) {
403
+ loadErrors.push(e)
404
+ }
405
+ try {
406
+ const binding = require('@jongleberry/vurst-markdown-linux-loong64-gnu')
407
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-loong64-gnu/package.json').version
408
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
409
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
410
+ }
411
+ return binding
412
+ } catch (e) {
413
+ loadErrors.push(e)
414
+ }
415
+ }
416
+ } else if (process.arch === 'riscv64') {
417
+ if (isMusl()) {
418
+ try {
419
+ return require('./vurst-markdown.linux-riscv64-musl.node')
420
+ } catch (e) {
421
+ loadErrors.push(e)
422
+ }
423
+ try {
424
+ const binding = require('@jongleberry/vurst-markdown-linux-riscv64-musl')
425
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-riscv64-musl/package.json').version
426
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
+ }
429
+ return binding
430
+ } catch (e) {
431
+ loadErrors.push(e)
432
+ }
433
+ } else {
434
+ try {
435
+ return require('./vurst-markdown.linux-riscv64-gnu.node')
436
+ } catch (e) {
437
+ loadErrors.push(e)
438
+ }
439
+ try {
440
+ const binding = require('@jongleberry/vurst-markdown-linux-riscv64-gnu')
441
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-riscv64-gnu/package.json').version
442
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
443
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
444
+ }
445
+ return binding
446
+ } catch (e) {
447
+ loadErrors.push(e)
448
+ }
449
+ }
450
+ } else if (process.arch === 'ppc64') {
451
+ try {
452
+ return require('./vurst-markdown.linux-ppc64-gnu.node')
453
+ } catch (e) {
454
+ loadErrors.push(e)
455
+ }
456
+ try {
457
+ const binding = require('@jongleberry/vurst-markdown-linux-ppc64-gnu')
458
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-ppc64-gnu/package.json').version
459
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
+ }
462
+ return binding
463
+ } catch (e) {
464
+ loadErrors.push(e)
465
+ }
466
+ } else if (process.arch === 's390x') {
467
+ try {
468
+ return require('./vurst-markdown.linux-s390x-gnu.node')
469
+ } catch (e) {
470
+ loadErrors.push(e)
471
+ }
472
+ try {
473
+ const binding = require('@jongleberry/vurst-markdown-linux-s390x-gnu')
474
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-linux-s390x-gnu/package.json').version
475
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
476
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
477
+ }
478
+ return binding
479
+ } catch (e) {
480
+ loadErrors.push(e)
481
+ }
482
+ } else {
483
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
484
+ }
485
+ } else if (process.platform === 'openharmony') {
486
+ if (process.arch === 'arm64') {
487
+ try {
488
+ return require('./vurst-markdown.openharmony-arm64.node')
489
+ } catch (e) {
490
+ loadErrors.push(e)
491
+ }
492
+ try {
493
+ const binding = require('@jongleberry/vurst-markdown-openharmony-arm64')
494
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-openharmony-arm64/package.json').version
495
+ if (bindingPackageVersion !== '0.0.4' && 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.0.4 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 if (process.arch === 'x64') {
503
+ try {
504
+ return require('./vurst-markdown.openharmony-x64.node')
505
+ } catch (e) {
506
+ loadErrors.push(e)
507
+ }
508
+ try {
509
+ const binding = require('@jongleberry/vurst-markdown-openharmony-x64')
510
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-openharmony-x64/package.json').version
511
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
+ }
514
+ return binding
515
+ } catch (e) {
516
+ loadErrors.push(e)
517
+ }
518
+ } else if (process.arch === 'arm') {
519
+ try {
520
+ return require('./vurst-markdown.openharmony-arm.node')
521
+ } catch (e) {
522
+ loadErrors.push(e)
523
+ }
524
+ try {
525
+ const binding = require('@jongleberry/vurst-markdown-openharmony-arm')
526
+ const bindingPackageVersion = require('@jongleberry/vurst-markdown-openharmony-arm/package.json').version
527
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
528
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
529
+ }
530
+ return binding
531
+ } catch (e) {
532
+ loadErrors.push(e)
533
+ }
534
+ } else {
535
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
536
+ }
537
+ } else {
538
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
539
+ }
540
+ }
541
+
542
+ nativeBinding = requireNative()
6
543
 
7
- function loadBinding() {
8
- switch (`${platform}-${arch}`) {
9
- case 'darwin-arm64':
10
- return require('./vurst-markdown.darwin-arm64.node')
11
- case 'linux-x64':
12
- return require('./vurst-markdown.linux-x64-gnu.node')
13
- case 'linux-arm64':
14
- return require('./vurst-markdown.linux-arm64-gnu.node')
15
- default:
16
- throw new Error(
17
- `Unsupported platform: ${platform}-${arch}. ` +
18
- `@jongleberry/vurst-markdown supports darwin-arm64, linux-x64 (glibc), and linux-arm64 (glibc).`,
19
- )
544
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
545
+ let wasiBinding = null
546
+ let wasiBindingError = null
547
+ try {
548
+ wasiBinding = require('./vurst-markdown.wasi.cjs')
549
+ nativeBinding = wasiBinding
550
+ } catch (err) {
551
+ if (process.env.NAPI_RS_FORCE_WASI) {
552
+ wasiBindingError = err
553
+ }
554
+ }
555
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
556
+ try {
557
+ wasiBinding = require('@jongleberry/vurst-markdown-wasm32-wasi')
558
+ nativeBinding = wasiBinding
559
+ } catch (err) {
560
+ if (process.env.NAPI_RS_FORCE_WASI) {
561
+ if (!wasiBindingError) {
562
+ wasiBindingError = err
563
+ } else {
564
+ wasiBindingError.cause = err
565
+ }
566
+ loadErrors.push(err)
567
+ }
568
+ }
569
+ }
570
+ if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
571
+ const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
572
+ error.cause = wasiBindingError
573
+ throw error
20
574
  }
21
575
  }
22
576
 
23
- const binding = loadBinding()
577
+ if (!nativeBinding) {
578
+ if (!isPublishedPlatform()) {
579
+ throw new Error(
580
+ `Unsupported platform for @jongleberry/vurst-markdown: ${process.platform} ${process.arch}. ` +
581
+ `Published native bindings currently support ${supportedPlatforms}.`,
582
+ {
583
+ cause: loadErrors.length > 0
584
+ ? loadErrors.reduce((err, cur) => {
585
+ cur.cause = err
586
+ return cur
587
+ })
588
+ : undefined,
589
+ },
590
+ )
591
+ }
592
+ if (loadErrors.length > 0) {
593
+ throw new Error(
594
+ `Cannot find native binding. ` +
595
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
596
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
597
+ {
598
+ cause: loadErrors.reduce((err, cur) => {
599
+ cur.cause = err
600
+ return cur
601
+ }),
602
+ },
603
+ )
604
+ }
605
+ throw new Error(`Failed to load native binding`)
606
+ }
24
607
 
25
- module.exports.chunk = binding.chunk
26
- module.exports.renderMarkdownToHtml = binding.renderMarkdownToHtml
27
- module.exports.renderMarkdownToHtmlBatch = binding.renderMarkdownToHtmlBatch
28
- module.exports.extractMarkdownUrls = binding.extractMarkdownUrls
608
+ module.exports = nativeBinding
609
+ module.exports.chunk = nativeBinding.chunk
610
+ module.exports.extractMarkdownUrls = nativeBinding.extractMarkdownUrls
611
+ module.exports.renderMarkdownToHtml = nativeBinding.renderMarkdownToHtml
612
+ module.exports.renderMarkdownToHtmlBatch = nativeBinding.renderMarkdownToHtmlBatch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jongleberry/vurst-markdown",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "Rust + N-API: Markdown chunking and rendering.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -49,8 +49,8 @@
49
49
  "@types/node": "^24"
50
50
  },
51
51
  "optionalDependencies": {
52
- "@jongleberry/vurst-markdown-darwin-arm64": "0.0.4",
53
- "@jongleberry/vurst-markdown-linux-arm64-gnu": "0.0.4",
54
- "@jongleberry/vurst-markdown-linux-x64-gnu": "0.0.4"
52
+ "@jongleberry/vurst-markdown-darwin-arm64": "0.1.0",
53
+ "@jongleberry/vurst-markdown-linux-arm64-gnu": "0.1.0",
54
+ "@jongleberry/vurst-markdown-linux-x64-gnu": "0.1.0"
55
55
  }
56
56
  }
Binary file
Binary file
Binary file