@farhnkrnapratma/markers 0.0.0-stage → 1.0.0-alpha1

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/LICENSE-APACHE ADDED
@@ -0,0 +1,73 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+
37
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
38
+
39
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+
41
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
42
+
43
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
56
+
57
+ APPENDIX: How to apply the Apache License to your work.
58
+
59
+ To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
60
+
61
+ Copyright [yyyy] [name of copyright owner]
62
+
63
+ Licensed under the Apache License, Version 2.0 (the "License");
64
+ you may not use this file except in compliance with the License.
65
+ You may obtain a copy of the License at
66
+
67
+ http://www.apache.org/licenses/LICENSE-2.0
68
+
69
+ Unless required by applicable law or agreed to in writing, software
70
+ distributed under the License is distributed on an "AS IS" BASIS,
71
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
72
+ See the License for the specific language governing permissions and
73
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Farhan Kurnia Pratama
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,133 @@
1
- # Temporary Holding Version
1
+ # markers
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ High-performance HTML to Markdown conversion for LLMs, written in Rust.
4
+
5
+ ## Status
6
+
7
+ Alpha (`v1.0.0-alpha1`). The API can still change before the first stable release.
8
+
9
+ | Registry | Name |
10
+ | --- | --- |
11
+ | crates.io | [`markers`](https://crates.io/crates/markers) |
12
+ | npm | [`@farhnkrnapratma/markers`](https://www.npmjs.com/package/@farhnkrnapratma/markers) |
13
+
14
+ One package, one `src/`. The bindings are optional Cargo features:
15
+
16
+ | Feature | Source | Purpose |
17
+ | --- | --- | --- |
18
+ | *(none)* | `src/lib.rs` | Rust library |
19
+ | `napi` | `src/bindings/node.rs` | Node.js / Bun bindings, published as `@farhnkrnapratma/markers` |
20
+ | `wasm` | `src/bindings/wasm.rs` | WebAssembly bindings |
21
+
22
+ ## Install
23
+
24
+ ```sh
25
+ cargo add markers # Rust
26
+ bun add @farhnkrnapratma/markers # Node.js / Bun (or: npm install @farhnkrnapratma/markers)
27
+ ```
28
+
29
+ The npm package ships prebuilt binaries for Linux (x64 and arm64, glibc and musl), macOS (x64 and arm64) and Windows (x64 and arm64) as optional dependencies, so nothing is compiled on install.
30
+
31
+ ## Usage
32
+
33
+ Rust:
34
+
35
+ ```rust
36
+ fn main() -> Result<(), String> {
37
+ let _markdown = markers::convert("<h1>Hello</h1>");
38
+
39
+ let options = markers::ConversionOptions::new()
40
+ .heading_style(markers::HeadingStyle::Setext)
41
+ .base_url(Some("https://example.com".to_string()))
42
+ .exclude_selectors(vec!["nav".to_string()]);
43
+ let markdown = markers::convert_with_options("<h1>Hello</h1>", &options)?;
44
+ println!("{markdown}");
45
+ Ok(())
46
+ }
47
+ ```
48
+
49
+ `convert_with_options` returns an error when an include or exclude CSS selector is invalid.
50
+
51
+ Node.js / Bun:
52
+
53
+ ```js
54
+ const { convert, convertAsync } = require('@farhnkrnapratma/markers')
55
+
56
+ convert('<h1>Hello</h1>')
57
+ convert('<h1>Hello</h1>', { headingStyle: 'setext', baseUrl: 'https://example.com' })
58
+ await convertAsync('<h1>Hello</h1>')
59
+ ```
60
+
61
+ ## Options
62
+
63
+ | Option (Rust / JS) | Values | Default |
64
+ | --- | --- | --- |
65
+ | `heading_style` / `headingStyle` | `atx`, `setext` | `atx` |
66
+ | `link_style` / `linkStyle` | `inline`, `referenced` | `inline` |
67
+ | `code_fence` / `codeFence` | `` ` ``, `~` | `` ` `` |
68
+ | `bullet_marker` / `bulletMarker` | `-`, `*`, `+` | `-` |
69
+ | `base_url` / `baseUrl` | URL used to resolve relative links and images | none |
70
+ | `exclude_selectors` / `excludeSelectors` | CSS selectors to drop | none |
71
+ | `include_selectors` / `includeSelectors` | CSS selectors kept even if an exclude selector matches | none |
72
+
73
+ ## Repository layout
74
+
75
+ ```
76
+ src/
77
+ lib.rs public API: convert, convert_with_options, ConversionOptions
78
+ options.rs ConversionOptions, HeadingStyle, LinkStyle
79
+ pipeline/ the conversion: input_guard -> parse -> annotate -> render -> cleanup
80
+ handlers/ one TagHandler per group of tags (block/ and inline/)
81
+ text/ Markdown escaping, URL handling, whitespace
82
+ bindings/ Node.js (napi) and WebAssembly (wasm) glue
83
+ tests/ integration tests and HTML fixtures
84
+ examples/ Rust, Node.js and browser demos
85
+ ```
86
+
87
+ ## Development
88
+
89
+ Requirements: Rust (stable) and Cargo, and [Bun](https://bun.sh) for the JavaScript side (`bun.lock` is the only lockfile).
90
+
91
+ ```sh
92
+ bun install # JS dependencies and git hooks
93
+ bun run build # Node.js / Bun binding for this platform
94
+ cargo test --features napi # unit and integration tests, plus the napi module
95
+ bun run test # Node.js binding tests (after bun run build)
96
+ cargo clippy --all-targets --features napi
97
+ cargo bench --bench conversion # set MARKERS_BENCH_ITERATIONS to change the run length
98
+ ```
99
+
100
+ Examples:
101
+
102
+ ```sh
103
+ cargo run --example basic # default options
104
+ cargo run --example options # headings, bullets, links, selectors
105
+ bun examples/node.js # Node.js / Bun (after bun run build)
106
+ ```
107
+
108
+ `examples/wasm.html` is a browser demo for the `wasm` build, which needs the `wasm32-unknown-unknown` target (`napi` is compiled out on `wasm32`, so `--all-features` also works there):
109
+
110
+ ```sh
111
+ cargo check --target wasm32-unknown-unknown --features wasm
112
+ ```
113
+
114
+ Releases are cut with git-flow (`git-flow release start/finish`). Pushing a `v*` tag makes CircleCI build the bindings for every platform and publish them to npm; the crate is published with `cargo publish`.
115
+
116
+ ## Contributing
117
+
118
+ This repository uses [git-flow-next](https://git-flow.sh/) (classic preset): `main` is release-only, work happens on `feature/*` and `bugfix/*` branches off `develop`. Commits are signed off (`git commit -s`) and follow [Conventional Commits](https://www.conventionalcommits.org), enforced by commitlint in a `commit-msg` hook and in CI. Install the hooks with `bash .githooks/install.sh` (`bun install` does it through the `prepare` script). CI runs on CircleCI: `reuse lint`, format and lint, tests, `cargo deny`, a TruffleHog secret scan and commitlint on every push. The branch rules are written out in [`CLAUDE.md`](CLAUDE.md).
119
+
120
+ ## License
121
+
122
+ Licensed under either of
123
+
124
+ - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>)
125
+ - MIT License ([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/licenses/MIT>)
126
+
127
+ at your option.
128
+
129
+ Unless you explicitly state otherwise, any contribution intentionally submitted
130
+ for inclusion in this project by you, as defined in the Apache-2.0 license,
131
+ shall be dual licensed as above, without any additional terms or conditions.
132
+
133
+ Copyright © 2026 Farhan Kurnia Pratama
package/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Which binding artifact the generated loader actually loaded: `'native'` for
6
+ * a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
7
+ * flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
8
+ * can point the loader at a WASI artifact this package does not build itself.
9
+ */
10
+ export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
11
+
12
+ export interface ConversionOptions {
13
+ headingStyle?: 'atx' | 'setext'
14
+ linkStyle?: 'inline' | 'referenced'
15
+ codeFence?: '`' | '~'
16
+ bulletMarker?: '-' | '*' | '+'
17
+ baseUrl?: string
18
+ excludeSelectors?: Array<string>
19
+ includeSelectors?: Array<string>
20
+ }
21
+
22
+ export declare function convert(html: string, options?: ConversionOptions | undefined | null): string
23
+
24
+ export declare function convertAsync(html: string, options?: ConversionOptions | undefined | null): Promise<string>
package/index.js ADDED
@@ -0,0 +1,839 @@
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').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
65
+ } catch (e) {
66
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
67
+ return false
68
+ }
69
+ }
70
+
71
+ function requireNative() {
72
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
73
+ try {
74
+ const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
75
+ // The override may be a generated WASI loader, which already reports its
76
+ // own flavor. Adopt it: `module.exports` aliases this object, so claiming
77
+ // 'native' would both misreport the artifact and overwrite the loader's
78
+ // marker through the alias.
79
+ __napiLoadedBindingTarget =
80
+ overrideBinding && typeof overrideBinding.__napiBindingTarget === 'string'
81
+ ? overrideBinding.__napiBindingTarget
82
+ : 'native'
83
+ return overrideBinding
84
+ } catch (err) {
85
+ loadErrors.push(err)
86
+ }
87
+ } else if (process.platform === 'android') {
88
+ if (process.arch === 'arm64') {
89
+ try {
90
+ return require('./markers.android-arm64.node')
91
+ } catch (e) {
92
+ loadErrors.push(e)
93
+ }
94
+ try {
95
+ const binding = require('@farhnkrnapratma/markers-android-arm64')
96
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-android-arm64/package.json').version
97
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
98
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
99
+ }
100
+ return binding
101
+ } catch (e) {
102
+ loadErrors.push(e)
103
+ }
104
+ } else if (process.arch === 'arm') {
105
+ try {
106
+ return require('./markers.android-arm-eabi.node')
107
+ } catch (e) {
108
+ loadErrors.push(e)
109
+ }
110
+ try {
111
+ const binding = require('@farhnkrnapratma/markers-android-arm-eabi')
112
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-android-arm-eabi/package.json').version
113
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
114
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
115
+ }
116
+ return binding
117
+ } catch (e) {
118
+ loadErrors.push(e)
119
+ }
120
+ } else {
121
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
122
+ }
123
+ } else if (process.platform === 'win32') {
124
+ if (process.arch === 'x64') {
125
+ if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
126
+ try {
127
+ return require('./markers.win32-x64-gnu.node')
128
+ } catch (e) {
129
+ loadErrors.push(e)
130
+ }
131
+ try {
132
+ const binding = require('@farhnkrnapratma/markers-win32-x64-gnu')
133
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-win32-x64-gnu/package.json').version
134
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
135
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
136
+ }
137
+ return binding
138
+ } catch (e) {
139
+ loadErrors.push(e)
140
+ }
141
+ } else {
142
+ try {
143
+ return require('./markers.win32-x64-msvc.node')
144
+ } catch (e) {
145
+ loadErrors.push(e)
146
+ }
147
+ try {
148
+ const binding = require('@farhnkrnapratma/markers-win32-x64-msvc')
149
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-win32-x64-msvc/package.json').version
150
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
+ }
153
+ return binding
154
+ } catch (e) {
155
+ loadErrors.push(e)
156
+ }
157
+ }
158
+ } else if (process.arch === 'ia32') {
159
+ try {
160
+ return require('./markers.win32-ia32-msvc.node')
161
+ } catch (e) {
162
+ loadErrors.push(e)
163
+ }
164
+ try {
165
+ const binding = require('@farhnkrnapratma/markers-win32-ia32-msvc')
166
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-win32-ia32-msvc/package.json').version
167
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
168
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
169
+ }
170
+ return binding
171
+ } catch (e) {
172
+ loadErrors.push(e)
173
+ }
174
+ } else if (process.arch === 'arm64') {
175
+ try {
176
+ return require('./markers.win32-arm64-msvc.node')
177
+ } catch (e) {
178
+ loadErrors.push(e)
179
+ }
180
+ try {
181
+ const binding = require('@farhnkrnapratma/markers-win32-arm64-msvc')
182
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-win32-arm64-msvc/package.json').version
183
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
184
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
185
+ }
186
+ return binding
187
+ } catch (e) {
188
+ loadErrors.push(e)
189
+ }
190
+ } else {
191
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
192
+ }
193
+ } else if (process.platform === 'darwin') {
194
+ try {
195
+ return require('./markers.darwin-universal.node')
196
+ } catch (e) {
197
+ loadErrors.push(e)
198
+ }
199
+ try {
200
+ const binding = require('@farhnkrnapratma/markers-darwin-universal')
201
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-darwin-universal/package.json').version
202
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
203
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
204
+ }
205
+ return binding
206
+ } catch (e) {
207
+ loadErrors.push(e)
208
+ }
209
+ if (process.arch === 'x64') {
210
+ try {
211
+ return require('./markers.darwin-x64.node')
212
+ } catch (e) {
213
+ loadErrors.push(e)
214
+ }
215
+ try {
216
+ const binding = require('@farhnkrnapratma/markers-darwin-x64')
217
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-darwin-x64/package.json').version
218
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
219
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
220
+ }
221
+ return binding
222
+ } catch (e) {
223
+ loadErrors.push(e)
224
+ }
225
+ } else if (process.arch === 'arm64') {
226
+ try {
227
+ return require('./markers.darwin-arm64.node')
228
+ } catch (e) {
229
+ loadErrors.push(e)
230
+ }
231
+ try {
232
+ const binding = require('@farhnkrnapratma/markers-darwin-arm64')
233
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-darwin-arm64/package.json').version
234
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
235
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
236
+ }
237
+ return binding
238
+ } catch (e) {
239
+ loadErrors.push(e)
240
+ }
241
+ } else {
242
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
243
+ }
244
+ } else if (process.platform === 'freebsd') {
245
+ if (process.arch === 'x64') {
246
+ try {
247
+ return require('./markers.freebsd-x64.node')
248
+ } catch (e) {
249
+ loadErrors.push(e)
250
+ }
251
+ try {
252
+ const binding = require('@farhnkrnapratma/markers-freebsd-x64')
253
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-freebsd-x64/package.json').version
254
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
255
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
256
+ }
257
+ return binding
258
+ } catch (e) {
259
+ loadErrors.push(e)
260
+ }
261
+ } else if (process.arch === 'arm64') {
262
+ try {
263
+ return require('./markers.freebsd-arm64.node')
264
+ } catch (e) {
265
+ loadErrors.push(e)
266
+ }
267
+ try {
268
+ const binding = require('@farhnkrnapratma/markers-freebsd-arm64')
269
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-freebsd-arm64/package.json').version
270
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
271
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
272
+ }
273
+ return binding
274
+ } catch (e) {
275
+ loadErrors.push(e)
276
+ }
277
+ } else if (process.arch === 'ppc64') {
278
+ try {
279
+ return require('./markers.freebsd-ppc64.node')
280
+ } catch (e) {
281
+ loadErrors.push(e)
282
+ }
283
+ try {
284
+ const binding = require('@farhnkrnapratma/markers-freebsd-ppc64')
285
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-freebsd-ppc64/package.json').version
286
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
287
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
288
+ }
289
+ return binding
290
+ } catch (e) {
291
+ loadErrors.push(e)
292
+ }
293
+ } else {
294
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
295
+ }
296
+ } else if (process.platform === 'linux') {
297
+ if (process.arch === 'x64') {
298
+ if (isMusl()) {
299
+ try {
300
+ return require('./markers.linux-x64-musl.node')
301
+ } catch (e) {
302
+ loadErrors.push(e)
303
+ }
304
+ try {
305
+ const binding = require('@farhnkrnapratma/markers-linux-x64-musl')
306
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-x64-musl/package.json').version
307
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
308
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
309
+ }
310
+ return binding
311
+ } catch (e) {
312
+ loadErrors.push(e)
313
+ }
314
+ } else {
315
+ try {
316
+ return require('./markers.linux-x64-gnu.node')
317
+ } catch (e) {
318
+ loadErrors.push(e)
319
+ }
320
+ try {
321
+ const binding = require('@farhnkrnapratma/markers-linux-x64-gnu')
322
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-x64-gnu/package.json').version
323
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
324
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
325
+ }
326
+ return binding
327
+ } catch (e) {
328
+ loadErrors.push(e)
329
+ }
330
+ }
331
+ } else if (process.arch === 'arm64') {
332
+ if (isMusl()) {
333
+ try {
334
+ return require('./markers.linux-arm64-musl.node')
335
+ } catch (e) {
336
+ loadErrors.push(e)
337
+ }
338
+ try {
339
+ const binding = require('@farhnkrnapratma/markers-linux-arm64-musl')
340
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-arm64-musl/package.json').version
341
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
342
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
343
+ }
344
+ return binding
345
+ } catch (e) {
346
+ loadErrors.push(e)
347
+ }
348
+ } else {
349
+ try {
350
+ return require('./markers.linux-arm64-gnu.node')
351
+ } catch (e) {
352
+ loadErrors.push(e)
353
+ }
354
+ try {
355
+ const binding = require('@farhnkrnapratma/markers-linux-arm64-gnu')
356
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-arm64-gnu/package.json').version
357
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
358
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
359
+ }
360
+ return binding
361
+ } catch (e) {
362
+ loadErrors.push(e)
363
+ }
364
+ }
365
+ } else if (process.arch === 'arm') {
366
+ if (isMusl()) {
367
+ try {
368
+ return require('./markers.linux-arm-musleabihf.node')
369
+ } catch (e) {
370
+ loadErrors.push(e)
371
+ }
372
+ try {
373
+ const binding = require('@farhnkrnapratma/markers-linux-arm-musleabihf')
374
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-arm-musleabihf/package.json').version
375
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
376
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
377
+ }
378
+ return binding
379
+ } catch (e) {
380
+ loadErrors.push(e)
381
+ }
382
+ } else {
383
+ try {
384
+ return require('./markers.linux-arm-gnueabihf.node')
385
+ } catch (e) {
386
+ loadErrors.push(e)
387
+ }
388
+ try {
389
+ const binding = require('@farhnkrnapratma/markers-linux-arm-gnueabihf')
390
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-arm-gnueabihf/package.json').version
391
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
392
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
393
+ }
394
+ return binding
395
+ } catch (e) {
396
+ loadErrors.push(e)
397
+ }
398
+ }
399
+ } else if (process.arch === 'loong64') {
400
+ if (isMusl()) {
401
+ try {
402
+ return require('./markers.linux-loong64-musl.node')
403
+ } catch (e) {
404
+ loadErrors.push(e)
405
+ }
406
+ try {
407
+ const binding = require('@farhnkrnapratma/markers-linux-loong64-musl')
408
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-loong64-musl/package.json').version
409
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
410
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
411
+ }
412
+ return binding
413
+ } catch (e) {
414
+ loadErrors.push(e)
415
+ }
416
+ } else {
417
+ try {
418
+ return require('./markers.linux-loong64-gnu.node')
419
+ } catch (e) {
420
+ loadErrors.push(e)
421
+ }
422
+ try {
423
+ const binding = require('@farhnkrnapratma/markers-linux-loong64-gnu')
424
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-loong64-gnu/package.json').version
425
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
426
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
427
+ }
428
+ return binding
429
+ } catch (e) {
430
+ loadErrors.push(e)
431
+ }
432
+ }
433
+ } else if (process.arch === 'riscv64') {
434
+ if (isMusl()) {
435
+ try {
436
+ return require('./markers.linux-riscv64-musl.node')
437
+ } catch (e) {
438
+ loadErrors.push(e)
439
+ }
440
+ try {
441
+ const binding = require('@farhnkrnapratma/markers-linux-riscv64-musl')
442
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-riscv64-musl/package.json').version
443
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
445
+ }
446
+ return binding
447
+ } catch (e) {
448
+ loadErrors.push(e)
449
+ }
450
+ } else {
451
+ try {
452
+ return require('./markers.linux-riscv64-gnu.node')
453
+ } catch (e) {
454
+ loadErrors.push(e)
455
+ }
456
+ try {
457
+ const binding = require('@farhnkrnapratma/markers-linux-riscv64-gnu')
458
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-riscv64-gnu/package.json').version
459
+ if (bindingPackageVersion !== '1.0.0-alpha1' && 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 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
+ }
462
+ return binding
463
+ } catch (e) {
464
+ loadErrors.push(e)
465
+ }
466
+ }
467
+ } else if (process.arch === 'ppc64') {
468
+ try {
469
+ return require('./markers.linux-ppc64-gnu.node')
470
+ } catch (e) {
471
+ loadErrors.push(e)
472
+ }
473
+ try {
474
+ const binding = require('@farhnkrnapratma/markers-linux-ppc64-gnu')
475
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-ppc64-gnu/package.json').version
476
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
477
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
478
+ }
479
+ return binding
480
+ } catch (e) {
481
+ loadErrors.push(e)
482
+ }
483
+ } else if (process.arch === 's390x') {
484
+ try {
485
+ return require('./markers.linux-s390x-gnu.node')
486
+ } catch (e) {
487
+ loadErrors.push(e)
488
+ }
489
+ try {
490
+ const binding = require('@farhnkrnapratma/markers-linux-s390x-gnu')
491
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-linux-s390x-gnu/package.json').version
492
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
493
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
494
+ }
495
+ return binding
496
+ } catch (e) {
497
+ loadErrors.push(e)
498
+ }
499
+ } else {
500
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
501
+ }
502
+ } else if (process.platform === 'openharmony') {
503
+ if (process.arch === 'arm64') {
504
+ try {
505
+ return require('./markers.openharmony-arm64.node')
506
+ } catch (e) {
507
+ loadErrors.push(e)
508
+ }
509
+ try {
510
+ const binding = require('@farhnkrnapratma/markers-openharmony-arm64')
511
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-openharmony-arm64/package.json').version
512
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
513
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
514
+ }
515
+ return binding
516
+ } catch (e) {
517
+ loadErrors.push(e)
518
+ }
519
+ } else if (process.arch === 'x64') {
520
+ try {
521
+ return require('./markers.openharmony-x64.node')
522
+ } catch (e) {
523
+ loadErrors.push(e)
524
+ }
525
+ try {
526
+ const binding = require('@farhnkrnapratma/markers-openharmony-x64')
527
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-openharmony-x64/package.json').version
528
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
529
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
530
+ }
531
+ return binding
532
+ } catch (e) {
533
+ loadErrors.push(e)
534
+ }
535
+ } else if (process.arch === 'arm') {
536
+ try {
537
+ return require('./markers.openharmony-arm.node')
538
+ } catch (e) {
539
+ loadErrors.push(e)
540
+ }
541
+ try {
542
+ const binding = require('@farhnkrnapratma/markers-openharmony-arm')
543
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-openharmony-arm/package.json').version
544
+ if (bindingPackageVersion !== '1.0.0-alpha1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
545
+ throw new Error(`Native binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
546
+ }
547
+ return binding
548
+ } catch (e) {
549
+ loadErrors.push(e)
550
+ }
551
+ } else {
552
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
553
+ }
554
+ } else {
555
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
556
+ }
557
+ }
558
+
559
+ function createLoadErrorChain(errors) {
560
+ return errors.reduce((previous, current) => {
561
+ let message
562
+ try {
563
+ message =
564
+ current && typeof current.message === 'string'
565
+ ? current.message
566
+ : String(current)
567
+ } catch {
568
+ message = 'Unknown error'
569
+ }
570
+ const error = new Error(message)
571
+ error.cause = previous
572
+ return error
573
+ }, null)
574
+ }
575
+
576
+ // NAPI_RS_FORCE_WASI is a tri-state flag:
577
+ // unset / any other value → native binding preferred, WASI is only a fallback
578
+ // 'true' → prefer WASI, but retain native as a lazy fallback
579
+ // 'error' → require WASI without initializing a native fallback
580
+ // Treating any non-empty string as truthy (the historical behavior) meant
581
+ // NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
582
+ // the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
583
+ //
584
+ // NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
585
+ // WASI loading. It never crosses into another flavor or falls back to native.
586
+ const __napiWasiFlavors = ['wasm32-wasi']
587
+ const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
588
+ const __napiWasiFlavorRequested =
589
+ typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
590
+ if (
591
+ __napiWasiFlavorRequested &&
592
+ __napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
593
+ ) {
594
+ throw new Error(
595
+ 'Unsupported WASI flavor "' +
596
+ __napiWasiFlavor +
597
+ '". Available flavors: ' +
598
+ __napiWasiFlavors.join(', '),
599
+ )
600
+ }
601
+ const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
602
+ const forceWasi =
603
+ process.env.NAPI_RS_FORCE_WASI === 'true' ||
604
+ forceWasiError ||
605
+ __napiWasiFlavorRequested
606
+
607
+ if (!forceWasi) {
608
+ nativeBinding = requireNative()
609
+ __napiRequiredNativeBinding = nativeBinding
610
+ }
611
+
612
+ if (!nativeBinding || forceWasi) {
613
+ let wasiBinding = null
614
+ let wasiBindingLoaded = false
615
+ const wasiBindingErrors = []
616
+ const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
617
+ try {
618
+ require.resolve(specifier)
619
+ } catch (resolveError) {
620
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
621
+ throw resolveError
622
+ }
623
+ if (isPackage) {
624
+ try {
625
+ require.resolve(specifier + '/package.json')
626
+ } catch (packageError) {
627
+ if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
628
+ return resolveError
629
+ }
630
+ // An exports restriction proves the package exists even when its
631
+ // package.json is not public. Preserve the root resolution failure.
632
+ throw resolveError
633
+ }
634
+ // The package exists but its main/export target is broken.
635
+ throw resolveError
636
+ }
637
+ return resolveError
638
+ }
639
+ if (localArtifacts) {
640
+ let artifactError = null
641
+ for (let i = 0; i < localArtifacts.length; i++) {
642
+ try {
643
+ require.resolve(localArtifacts[i])
644
+ return null
645
+ } catch (resolveError) {
646
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
647
+ throw resolveError
648
+ }
649
+ artifactError = resolveError
650
+ }
651
+ }
652
+ return artifactError
653
+ }
654
+ return null
655
+ }
656
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
657
+ let candidateError = null
658
+ let candidateFailed = false
659
+ try {
660
+ candidateError = __napiWasiResolveCandidate('./markers.wasi.cjs', false, ['./markers.wasm32-wasi.debug.wasm', './markers.wasm32-wasi.wasm'])
661
+ candidateFailed = candidateError !== null
662
+ if (!candidateFailed) {
663
+ wasiBinding = require('./markers.wasi.cjs')
664
+ nativeBinding = wasiBinding
665
+ __napiLoadedBindingTarget = 'wasm32-wasi'
666
+ wasiBindingLoaded = true
667
+ }
668
+ } catch (err) {
669
+ candidateError = err
670
+ candidateFailed = true
671
+ }
672
+ if (candidateFailed) {
673
+ wasiBindingErrors.push(candidateError)
674
+ loadErrors.push(candidateError)
675
+ }
676
+ }
677
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
678
+ let candidateError = null
679
+ let candidateFailed = false
680
+ try {
681
+ candidateError = __napiWasiResolveCandidate('@farhnkrnapratma/markers-wasm32-wasi', true, undefined)
682
+ candidateFailed = candidateError !== null
683
+ if (!candidateFailed) {
684
+ if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
685
+ const bindingPackageVersion = require('@farhnkrnapratma/markers-wasm32-wasi/package.json').version
686
+ if (bindingPackageVersion !== '1.0.0-alpha1') {
687
+ throw new Error(`WASI binding package version mismatch, expected 1.0.0-alpha1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
688
+ }
689
+ }
690
+ wasiBinding = require('@farhnkrnapratma/markers-wasm32-wasi')
691
+ nativeBinding = wasiBinding
692
+ __napiLoadedBindingTarget = 'wasm32-wasi'
693
+ wasiBindingLoaded = true
694
+ }
695
+ } catch (err) {
696
+ candidateError = err
697
+ candidateFailed = true
698
+ }
699
+ if (candidateFailed) {
700
+ wasiBindingErrors.push(candidateError)
701
+ loadErrors.push(candidateError)
702
+ }
703
+ }
704
+ if (
705
+ !wasiBindingLoaded &&
706
+ forceWasi &&
707
+ !forceWasiError &&
708
+ !__napiWasiFlavorRequested
709
+ ) {
710
+ nativeBinding = requireNative()
711
+ __napiRequiredNativeBinding = nativeBinding
712
+ }
713
+ if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
714
+ const error = new Error(
715
+ __napiWasiFlavorRequested
716
+ ? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
717
+ : 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
718
+ )
719
+ error.cause = createLoadErrorChain(wasiBindingErrors)
720
+ throw error
721
+ }
722
+ }
723
+
724
+ if (!nativeBinding) {
725
+ if (loadErrors.length > 0) {
726
+ const error = new Error(
727
+ `Cannot find native binding. ` +
728
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
729
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
730
+ )
731
+ // assign instead of the `new Error(message, { cause })` options form,
732
+ // which Node < 16.9 silently ignores
733
+ error.cause = createLoadErrorChain(loadErrors)
734
+ throw error
735
+ }
736
+ throw new Error(`Failed to load native binding`)
737
+ }
738
+
739
+ // A package can patch its own fallback in front of the load-failure check
740
+ // above, e.g. a WebContainer download through `napi-postinstall/fallback`.
741
+ // That fallback swaps `nativeBinding` for a generated WASI loader, which has
742
+ // already stamped its own flavor, while the target above still says 'native'.
743
+ // Take that flavor over, or the CommonJS stamp throws a conflict and the ESM
744
+ // export reports the wrong artifact. Three limits keep the conflict check:
745
+ // - only a binding this loader did not load itself, so a native addon whose
746
+ // `#[napi(module_exports)]` hook claims the name is still rejected;
747
+ // - only an own data property, read through its descriptor, so no addon
748
+ // getter runs here, and it must read back the same, as the stamp reads it;
749
+ // - only a flavor in `__napiWasiFlavors`, the ones this loader's own WASI
750
+ // chain can report ('wasm32-wasi' for a package without a WASI target).
751
+ // This is metadata and never fails a load: a throwing Proxy trap keeps 'native'.
752
+ if (
753
+ __napiLoadedBindingTarget === 'native' &&
754
+ nativeBinding !== __napiRequiredNativeBinding
755
+ ) {
756
+ try {
757
+ const __napiBindingTargetDescriptor = Object.getOwnPropertyDescriptor(
758
+ nativeBinding,
759
+ '__napiBindingTarget',
760
+ )
761
+ if (
762
+ __napiBindingTargetDescriptor &&
763
+ __napiWasiFlavors.indexOf(__napiBindingTargetDescriptor.value) !== -1 &&
764
+ nativeBinding.__napiBindingTarget === __napiBindingTargetDescriptor.value
765
+ ) {
766
+ __napiLoadedBindingTarget = __napiBindingTargetDescriptor.value
767
+ }
768
+ } catch {
769
+ // keep 'native'
770
+ }
771
+ }
772
+
773
+ function __napiStampBindingTarget(exportsObject, target) {
774
+ if (
775
+ Object.prototype.hasOwnProperty.call(exportsObject, '__napiBindingTarget')
776
+ ) {
777
+ if (exportsObject.__napiBindingTarget === target) {
778
+ // Already ours: the root entry aliases the object it loaded, so a WASI
779
+ // fallback candidate — or a `NAPI_RS_NATIVE_LIBRARY_PATH` override that
780
+ // is a generated loader — arrives already stamped with this same value.
781
+ return target
782
+ }
783
+ const error = new Error(
784
+ '`__napiBindingTarget` is reserved by the generated binding loader, but the loaded binding already exports it. Rename the export, e.g. #[napi(js_name = "...")].',
785
+ )
786
+ error.code = 'ERR_NAPI_BINDING_TARGET_CONFLICT'
787
+ throw error
788
+ }
789
+ if (!Object.isExtensible(exportsObject)) {
790
+ // A `#[napi(module_exports)]` hook may seal or freeze this object
791
+ // (`Object::seal` / `Object::freeze`). Reporting the artifact is metadata,
792
+ // never a reason to fail an otherwise successful load, so the stamp is
793
+ // skipped. What a consumer still sees then follows the entry point: the
794
+ // browser and deferred loaders declare `__napiBindingTarget` at module
795
+ // level and go on reporting it, while the CommonJS entries hand back this
796
+ // very object as `module.exports`, so there the value is absent.
797
+ return target
798
+ }
799
+ try {
800
+ // [[Define]], not [[Set]]: an ordinary assignment walks the prototype
801
+ // chain, so an inherited accessor could swallow the value or throw and
802
+ // fail an otherwise successful load. The descriptor is what a successful
803
+ // assignment would have produced.
804
+ Object.defineProperty(exportsObject, '__napiBindingTarget', {
805
+ configurable: true,
806
+ enumerable: true,
807
+ value: target,
808
+ writable: true,
809
+ })
810
+ } catch {
811
+ // Same rule as the non-extensible skip above: reporting the artifact is
812
+ // metadata, never a reason to fail an otherwise successful load. An exotic
813
+ // object (a Proxy whose defineProperty trap refuses) is skipped, not
814
+ // thrown over.
815
+ }
816
+ // The CommonJS loaders assign this return value so `cjs-module-lexer` — and
817
+ // therefore Node's CJS -> ESM named export detection — can see
818
+ // `__napiBindingTarget` statically.
819
+ return target
820
+ }
821
+ // Stamp before the alias, not after. The guard only reads `nativeBinding`
822
+ // (`hasOwnProperty` plus a comparison), which is safe against any addon
823
+ // accessor; an assignment is not, because a `#[napi(module_exports)]` hook can
824
+ // expose a getter reporting this very value and a setter that throws. So the
825
+ // assignment lands on the loader's own `module.exports`, still the original
826
+ // object here, and the alias below replaces it.
827
+ //
828
+ // The assignment is what keeps the marker a statically visible CommonJS export:
829
+ // `cjs-module-lexer` is Node's CJS -> ESM named export detection, it cannot see
830
+ // a bare call, and the later `module.exports = nativeBinding` does not undo the
831
+ // detection. The assignment itself always succeeds — its target is this
832
+ // loader's own, still extensible `module.exports` — and the alias below then
833
+ // discards the value it wrote. What a consumer reads is whatever the guard put
834
+ // on `nativeBinding`, so on a frozen binding, where the guard skips, the
835
+ // linked import resolves to `undefined`.
836
+ module.exports.__napiBindingTarget = __napiStampBindingTarget(nativeBinding, __napiLoadedBindingTarget)
837
+ module.exports = nativeBinding
838
+ module.exports.convert = nativeBinding.convert
839
+ module.exports.convertAsync = nativeBinding.convertAsync
package/package.json CHANGED
@@ -1,6 +1,85 @@
1
1
  {
2
2
  "name": "@farhnkrnapratma/markers",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0-alpha1",
4
+ "description": "High-performance HTML to Markdown converter with full GFM support",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/farhnkrnapratma/markers"
10
+ },
11
+ "homepage": "https://github.com/farhnkrnapratma/markers#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/farhnkrnapratma/markers/issues"
14
+ },
15
+ "license": "MIT OR Apache-2.0",
16
+ "keywords": [
17
+ "html",
18
+ "markdown",
19
+ "converter",
20
+ "html-to-markdown",
21
+ "gfm",
22
+ "napi-rs",
23
+ "rust"
24
+ ],
25
+ "files": [
26
+ "index.js",
27
+ "index.d.ts",
28
+ "README.md",
29
+ "LICENSE-MIT",
30
+ "LICENSE-APACHE"
31
+ ],
32
+ "napi": {
33
+ "binaryName": "markers",
34
+ "targets": [
35
+ "x86_64-unknown-linux-gnu",
36
+ "x86_64-pc-windows-msvc",
37
+ "x86_64-apple-darwin",
38
+ "x86_64-unknown-linux-musl",
39
+ "aarch64-unknown-linux-gnu",
40
+ "aarch64-unknown-linux-musl",
41
+ "aarch64-apple-darwin",
42
+ "aarch64-pc-windows-msvc"
43
+ ]
44
+ },
45
+ "engines": {
46
+ "node": ">= 14"
47
+ },
48
+ "scripts": {
49
+ "artifacts": "napi artifacts",
50
+ "build": "napi build --platform --release --features napi",
51
+ "build:debug": "napi build --platform --features napi",
52
+ "prepublishOnly": "napi pre-publish -t npm --no-gh-release",
53
+ "test": "ava",
54
+ "universal": "napi universalize",
55
+ "version": "napi version",
56
+ "prepare": "bash .githooks/install.sh"
57
+ },
58
+ "devDependencies": {
59
+ "@commitlint/cli": "^21.2.4",
60
+ "@commitlint/config-conventional": "^21.2.4",
61
+ "@napi-rs/cli": "^3.10.12",
62
+ "ava": "^8.3.0"
63
+ },
64
+ "ava": {
65
+ "timeout": "3m"
66
+ },
67
+ "optionalDependencies": {
68
+ "@farhnkrnapratma/markers-darwin-arm64": "1.0.0-alpha1",
69
+ "@farhnkrnapratma/markers-darwin-x64": "1.0.0-alpha1",
70
+ "@farhnkrnapratma/markers-linux-arm64-gnu": "1.0.0-alpha1",
71
+ "@farhnkrnapratma/markers-linux-arm64-musl": "1.0.0-alpha1",
72
+ "@farhnkrnapratma/markers-linux-x64-gnu": "1.0.0-alpha1",
73
+ "@farhnkrnapratma/markers-linux-x64-musl": "1.0.0-alpha1",
74
+ "@farhnkrnapratma/markers-win32-arm64-msvc": "1.0.0-alpha1",
75
+ "@farhnkrnapratma/markers-win32-x64-msvc": "1.0.0-alpha1"
76
+ },
77
+ "packageManager": "bun@1.4.4",
78
+ "publishConfig": {
79
+ "access": "public"
80
+ },
81
+ "overrides": {
82
+ "glob": "^14.0.2",
83
+ "minimatch": "^11.0.1"
84
+ }
85
+ }