@mdrs/core 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 +73 -0
- package/LICENSE-MIT +21 -0
- package/README.md +118 -2
- package/index.d.ts +46 -0
- package/index.js +16 -0
- package/index.native.d.ts +39 -0
- package/index.native.js +784 -0
- package/package.json +78 -4
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,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MDRS
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**MDRS (Markdown Rich Syntax)** is a superset of Markdown. It is meant as a drop-in replacement: any CommonMark or GitHub Flavored Markdown document should render the same way. On top of that it adds directives (`:::note`, `:::tabs`, `:::details`, `:::steps`, …), math, diagrams, charts, references and document variables (`:::define` with `${…}` interpolation).
|
|
4
|
+
|
|
5
|
+
MDRS files use the `.mdrs` extension.
|
|
6
|
+
|
|
7
|
+
## Status
|
|
8
|
+
|
|
9
|
+
Alpha (`v1.0.0-alpha1`). The Rust renderer port is in progress. The original TypeScript engine at `idstead/packages/mdrs/core` remains intact and is the behavior reference.
|
|
10
|
+
|
|
11
|
+
The Rust crate supports CommonMark/GFM rendering, sanitization, selected block directives, JSON-backed `:::define` expressions and conditionals, server-side KaTeX math, diagram/chart/embed markers, references, extended task states, icons, and verbatim blocks. It is not a byte-for-byte parity port: asynchronous JavaScript resolver callbacks and browser-side Mermaid/chart execution remain runtime integrations rather than Rust implementations.
|
|
12
|
+
|
|
13
|
+
| Registry | Name |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| crates.io | [`mdrs`](https://crates.io/crates/mdrs) |
|
|
16
|
+
| npm | [`@mdrs/core`](https://www.npmjs.com/package/@mdrs/core) |
|
|
17
|
+
|
|
18
|
+
The `napi` and `wasm` Cargo features expose `renderMarkdown`, `prepareMarkdownPage`, `resolveDefines` and `isMdrsPath`, plus `*WithData` variants that accept a JSON string for definitions, expressions and conditionals. Async JavaScript resolver callbacks are not exposed by the synchronous Rust ABI.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
cargo add mdrs # Rust
|
|
24
|
+
bun add @mdrs/core # JavaScript / TypeScript (or: npm install @mdrs/core)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
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. Math is rendered server-side through `katex-rs`; Mermaid and chart markers are left for browser-side execution.
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
Rust:
|
|
32
|
+
|
|
33
|
+
```rust
|
|
34
|
+
use std::path::Path;
|
|
35
|
+
|
|
36
|
+
assert_eq!(mdrs::FILE_EXTENSION, "mdrs");
|
|
37
|
+
assert!(mdrs::is_mdrs_path(Path::new("docs/intro.mdrs")));
|
|
38
|
+
|
|
39
|
+
let html = mdrs::render_markdown("# Hello\n\nA **rich** document.")?;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
JavaScript / TypeScript:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { FILE_EXTENSION, isMdrsPath, renderMarkdown } from '@mdrs/core';
|
|
46
|
+
|
|
47
|
+
FILE_EXTENSION; // "mdrs"
|
|
48
|
+
isMdrsPath('docs/intro.mdrs'); // true
|
|
49
|
+
renderMarkdown('# Hello\n\nA **rich** document.');
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
To render a `.mdrs` file to HTML, run the bundled example with the path of the file:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
cargo run --example showcase_render -- docs/intro.mdrs > intro.html
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Repository layout
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
src/
|
|
62
|
+
lib.rs public API
|
|
63
|
+
markdown.rs CommonMark / GFM rendering
|
|
64
|
+
containers.rs block directives (:::note, :::tabs, …)
|
|
65
|
+
define.rs :::define variables, expressions, conditionals
|
|
66
|
+
headings.rs heading ids and structure
|
|
67
|
+
sanitize.rs HTML sanitization
|
|
68
|
+
bindings/ Node.js (napi) and WebAssembly (wasm) glue
|
|
69
|
+
examples/ showcase_render: renders a .mdrs file to HTML
|
|
70
|
+
benches/ rendering baseline
|
|
71
|
+
scripts/ binding checks and parity tooling
|
|
72
|
+
index.js JavaScript entry (re-exports the generated native loader)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Development
|
|
76
|
+
|
|
77
|
+
Requirements: Rust (stable) with the `wasm32-unknown-unknown` target, and [Bun](https://bun.sh) (`bun.lock` is the only lockfile).
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
bun install # JS dependencies and git hooks
|
|
81
|
+
cargo test --locked # Rust tests
|
|
82
|
+
cargo check --features napi
|
|
83
|
+
cargo check --target wasm32-unknown-unknown --features wasm
|
|
84
|
+
bun run build:release # Node artifact for this platform
|
|
85
|
+
bun run test:bindings # offline binding checks
|
|
86
|
+
bun run test:native # build:release + test:bindings
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`test:bindings` validates the TypeScript declarations against both binding modules and checks the `napi` and `wasm` Cargo features. It reports, without failing, when the local `napi` or `wasm-pack` packagers are unavailable.
|
|
90
|
+
|
|
91
|
+
Parity and performance checks:
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
bun scripts/showcase-parity.ts # compare the showcase with the TypeScript mirror (needs the idstead checkout)
|
|
95
|
+
cargo bench --locked --offline --bench render
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The parity command reports output hashes, marker counts and the first difference. The Rust output is intentionally not byte-for-byte identical to the mirror yet.
|
|
99
|
+
|
|
100
|
+
Releases are cut with git-flow (`git-flow release start/finish`). Pushing a `v*` tag makes CircleCI build the native binding for every platform and publish `@mdrs/core` to npm; the crate is published with `cargo publish`.
|
|
101
|
+
|
|
102
|
+
## Contributing
|
|
103
|
+
|
|
104
|
+
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).
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
Licensed under either of
|
|
109
|
+
|
|
110
|
+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>)
|
|
111
|
+
- MIT License ([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/licenses/MIT>)
|
|
112
|
+
|
|
113
|
+
at your option.
|
|
114
|
+
|
|
115
|
+
Unless you explicitly state otherwise, any contribution intentionally submitted
|
|
116
|
+
for inclusion in this project by you, as defined in the Apache-2.0 license,
|
|
117
|
+
shall be dual licensed as above, without any additional terms or conditions.
|
|
118
|
+
|
|
119
|
+
Copyright © 2026 Farhan Kurnia Pratama
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** The file extension used by MDRS documents, without the leading dot. */
|
|
2
|
+
export declare const FILE_EXTENSION: 'mdrs';
|
|
3
|
+
|
|
4
|
+
/** Returns `true` when `path` ends in the `.mdrs` extension (case-insensitive). */
|
|
5
|
+
export declare function isMdrsPath(path: string): boolean;
|
|
6
|
+
|
|
7
|
+
export interface RenderOptions {
|
|
8
|
+
internalOrigins?: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface HeadingItem {
|
|
12
|
+
id: string;
|
|
13
|
+
text: string;
|
|
14
|
+
level: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface PreparedMarkdownPage {
|
|
18
|
+
html: string;
|
|
19
|
+
headings: HeadingItem[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export declare function renderMarkdown(
|
|
23
|
+
markdown: string,
|
|
24
|
+
options?: RenderOptions
|
|
25
|
+
): string;
|
|
26
|
+
|
|
27
|
+
export declare function renderMarkdownWithData(
|
|
28
|
+
markdown: string,
|
|
29
|
+
dataJson: string,
|
|
30
|
+
options?: RenderOptions
|
|
31
|
+
): string;
|
|
32
|
+
|
|
33
|
+
export declare function prepareMarkdownPage(
|
|
34
|
+
markdown: string,
|
|
35
|
+
options?: RenderOptions
|
|
36
|
+
): PreparedMarkdownPage;
|
|
37
|
+
|
|
38
|
+
export declare function prepareMarkdownPageWithData(
|
|
39
|
+
markdown: string,
|
|
40
|
+
dataJson: string,
|
|
41
|
+
options?: RenderOptions
|
|
42
|
+
): PreparedMarkdownPage;
|
|
43
|
+
|
|
44
|
+
export declare function resolveDefines(markdown: string): string;
|
|
45
|
+
|
|
46
|
+
export declare function resolveDefinesWithData(markdown: string, dataJson: string): string;
|
package/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const FILE_EXTENSION = 'mdrs';
|
|
2
|
+
|
|
3
|
+
export function isMdrsPath(path) {
|
|
4
|
+
const name = String(path).split(/[\\/]/).pop() ?? '';
|
|
5
|
+
const dot = name.lastIndexOf('.');
|
|
6
|
+
return dot > 0 && name.slice(dot + 1).toLowerCase() === FILE_EXTENSION;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
prepareMarkdownPage,
|
|
11
|
+
prepareMarkdownPageWithData,
|
|
12
|
+
renderMarkdown,
|
|
13
|
+
renderMarkdownWithData,
|
|
14
|
+
resolveDefines,
|
|
15
|
+
resolveDefinesWithData,
|
|
16
|
+
} from './index.native.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
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 BindingHeadingItem {
|
|
13
|
+
id: string
|
|
14
|
+
text: string
|
|
15
|
+
level: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface BindingPreparedMarkdownPage {
|
|
19
|
+
html: string
|
|
20
|
+
headings: Array<BindingHeadingItem>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface BindingRenderOptions {
|
|
24
|
+
internalOrigins?: Array<string>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export declare function isMdrsPath(path: string): boolean
|
|
28
|
+
|
|
29
|
+
export declare function prepareMarkdownPage(markdown: string, options?: BindingRenderOptions | undefined | null): BindingPreparedMarkdownPage
|
|
30
|
+
|
|
31
|
+
export declare function prepareMarkdownPageWithData(markdown: string, dataJson: string, options?: BindingRenderOptions | undefined | null): BindingPreparedMarkdownPage
|
|
32
|
+
|
|
33
|
+
export declare function renderMarkdown(markdown: string, options?: BindingRenderOptions | undefined | null): string
|
|
34
|
+
|
|
35
|
+
export declare function renderMarkdownWithData(markdown: string, dataJson: string, options?: BindingRenderOptions | undefined | null): string
|
|
36
|
+
|
|
37
|
+
export declare function resolveDefines(markdown: string): string
|
|
38
|
+
|
|
39
|
+
export declare function resolveDefinesWithData(markdown: string, dataJson: string): string
|
package/index.native.js
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/* auto-generated by NAPI-RS */
|
|
4
|
+
|
|
5
|
+
import { createRequire } from 'module'
|
|
6
|
+
const require = createRequire(import.meta.url)
|
|
7
|
+
|
|
8
|
+
const { readFileSync } = require('fs')
|
|
9
|
+
let nativeBinding = null
|
|
10
|
+
// Which artifact actually loaded. The WASI fallback chain overwrites it with
|
|
11
|
+
// the flavor it resolved; the late native retry below leaves it alone because
|
|
12
|
+
// it only runs while no WASI candidate has been loaded. The take-over check
|
|
13
|
+
// after the load-failure block can also set it.
|
|
14
|
+
let __napiLoadedBindingTarget = 'native'
|
|
15
|
+
// What this loader's own `requireNative()` calls returned. The check after
|
|
16
|
+
// the load-failure block compares it with `nativeBinding` to tell a binding
|
|
17
|
+
// this loader loaded from one that code outside it put in its place.
|
|
18
|
+
let __napiRequiredNativeBinding = null
|
|
19
|
+
const loadErrors = []
|
|
20
|
+
|
|
21
|
+
const isMusl = () => {
|
|
22
|
+
let musl = false
|
|
23
|
+
if (process.platform === 'linux') {
|
|
24
|
+
musl = isMuslFromFilesystem()
|
|
25
|
+
if (musl === null) {
|
|
26
|
+
musl = isMuslFromReport()
|
|
27
|
+
}
|
|
28
|
+
if (musl === null) {
|
|
29
|
+
musl = isMuslFromChildProcess()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return musl
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
36
|
+
|
|
37
|
+
const isMuslFromFilesystem = () => {
|
|
38
|
+
try {
|
|
39
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
40
|
+
} catch {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const isMuslFromReport = () => {
|
|
46
|
+
let report = null
|
|
47
|
+
if (process.report && typeof process.report.getReport === 'function') {
|
|
48
|
+
process.report.excludeNetwork = true
|
|
49
|
+
report = process.report.getReport()
|
|
50
|
+
}
|
|
51
|
+
if (!report) {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
55
|
+
return false
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
58
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
59
|
+
return true
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const isMuslFromChildProcess = () => {
|
|
66
|
+
try {
|
|
67
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
68
|
+
} catch (e) {
|
|
69
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function requireNative() {
|
|
75
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
76
|
+
try {
|
|
77
|
+
const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
|
|
78
|
+
// The override may be a generated WASI loader, which already reports its
|
|
79
|
+
// own flavor. Adopt it: `module.exports` aliases this object, so claiming
|
|
80
|
+
// 'native' would both misreport the artifact and overwrite the loader's
|
|
81
|
+
// marker through the alias.
|
|
82
|
+
__napiLoadedBindingTarget =
|
|
83
|
+
overrideBinding && typeof overrideBinding.__napiBindingTarget === 'string'
|
|
84
|
+
? overrideBinding.__napiBindingTarget
|
|
85
|
+
: 'native'
|
|
86
|
+
return overrideBinding
|
|
87
|
+
} catch (err) {
|
|
88
|
+
loadErrors.push(err)
|
|
89
|
+
}
|
|
90
|
+
} else if (process.platform === 'android') {
|
|
91
|
+
if (process.arch === 'arm64') {
|
|
92
|
+
try {
|
|
93
|
+
return require('./mdrs.android-arm64.node')
|
|
94
|
+
} catch (e) {
|
|
95
|
+
loadErrors.push(e)
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const binding = require('@mdrs/core-android-arm64')
|
|
99
|
+
const bindingPackageVersion = require('@mdrs/core-android-arm64/package.json').version
|
|
100
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
101
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
102
|
+
}
|
|
103
|
+
return binding
|
|
104
|
+
} catch (e) {
|
|
105
|
+
loadErrors.push(e)
|
|
106
|
+
}
|
|
107
|
+
} else if (process.arch === 'arm') {
|
|
108
|
+
try {
|
|
109
|
+
return require('./mdrs.android-arm-eabi.node')
|
|
110
|
+
} catch (e) {
|
|
111
|
+
loadErrors.push(e)
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const binding = require('@mdrs/core-android-arm-eabi')
|
|
115
|
+
const bindingPackageVersion = require('@mdrs/core-android-arm-eabi/package.json').version
|
|
116
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
117
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
118
|
+
}
|
|
119
|
+
return binding
|
|
120
|
+
} catch (e) {
|
|
121
|
+
loadErrors.push(e)
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
125
|
+
}
|
|
126
|
+
} else if (process.platform === 'win32') {
|
|
127
|
+
if (process.arch === 'x64') {
|
|
128
|
+
if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
|
|
129
|
+
try {
|
|
130
|
+
return require('./mdrs.win32-x64-gnu.node')
|
|
131
|
+
} catch (e) {
|
|
132
|
+
loadErrors.push(e)
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const binding = require('@mdrs/core-win32-x64-gnu')
|
|
136
|
+
const bindingPackageVersion = require('@mdrs/core-win32-x64-gnu/package.json').version
|
|
137
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
138
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
139
|
+
}
|
|
140
|
+
return binding
|
|
141
|
+
} catch (e) {
|
|
142
|
+
loadErrors.push(e)
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
try {
|
|
146
|
+
return require('./mdrs.win32-x64-msvc.node')
|
|
147
|
+
} catch (e) {
|
|
148
|
+
loadErrors.push(e)
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const binding = require('@mdrs/core-win32-x64-msvc')
|
|
152
|
+
const bindingPackageVersion = require('@mdrs/core-win32-x64-msvc/package.json').version
|
|
153
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
154
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
155
|
+
}
|
|
156
|
+
return binding
|
|
157
|
+
} catch (e) {
|
|
158
|
+
loadErrors.push(e)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
} else if (process.arch === 'ia32') {
|
|
162
|
+
try {
|
|
163
|
+
return require('./mdrs.win32-ia32-msvc.node')
|
|
164
|
+
} catch (e) {
|
|
165
|
+
loadErrors.push(e)
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const binding = require('@mdrs/core-win32-ia32-msvc')
|
|
169
|
+
const bindingPackageVersion = require('@mdrs/core-win32-ia32-msvc/package.json').version
|
|
170
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
171
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
172
|
+
}
|
|
173
|
+
return binding
|
|
174
|
+
} catch (e) {
|
|
175
|
+
loadErrors.push(e)
|
|
176
|
+
}
|
|
177
|
+
} else if (process.arch === 'arm64') {
|
|
178
|
+
try {
|
|
179
|
+
return require('./mdrs.win32-arm64-msvc.node')
|
|
180
|
+
} catch (e) {
|
|
181
|
+
loadErrors.push(e)
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const binding = require('@mdrs/core-win32-arm64-msvc')
|
|
185
|
+
const bindingPackageVersion = require('@mdrs/core-win32-arm64-msvc/package.json').version
|
|
186
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
187
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
188
|
+
}
|
|
189
|
+
return binding
|
|
190
|
+
} catch (e) {
|
|
191
|
+
loadErrors.push(e)
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
195
|
+
}
|
|
196
|
+
} else if (process.platform === 'darwin') {
|
|
197
|
+
try {
|
|
198
|
+
return require('./mdrs.darwin-universal.node')
|
|
199
|
+
} catch (e) {
|
|
200
|
+
loadErrors.push(e)
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
const binding = require('@mdrs/core-darwin-universal')
|
|
204
|
+
const bindingPackageVersion = require('@mdrs/core-darwin-universal/package.json').version
|
|
205
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
206
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
207
|
+
}
|
|
208
|
+
return binding
|
|
209
|
+
} catch (e) {
|
|
210
|
+
loadErrors.push(e)
|
|
211
|
+
}
|
|
212
|
+
if (process.arch === 'x64') {
|
|
213
|
+
try {
|
|
214
|
+
return require('./mdrs.darwin-x64.node')
|
|
215
|
+
} catch (e) {
|
|
216
|
+
loadErrors.push(e)
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
const binding = require('@mdrs/core-darwin-x64')
|
|
220
|
+
const bindingPackageVersion = require('@mdrs/core-darwin-x64/package.json').version
|
|
221
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
222
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
223
|
+
}
|
|
224
|
+
return binding
|
|
225
|
+
} catch (e) {
|
|
226
|
+
loadErrors.push(e)
|
|
227
|
+
}
|
|
228
|
+
} else if (process.arch === 'arm64') {
|
|
229
|
+
try {
|
|
230
|
+
return require('./mdrs.darwin-arm64.node')
|
|
231
|
+
} catch (e) {
|
|
232
|
+
loadErrors.push(e)
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const binding = require('@mdrs/core-darwin-arm64')
|
|
236
|
+
const bindingPackageVersion = require('@mdrs/core-darwin-arm64/package.json').version
|
|
237
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
|
+
}
|
|
240
|
+
return binding
|
|
241
|
+
} catch (e) {
|
|
242
|
+
loadErrors.push(e)
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
246
|
+
}
|
|
247
|
+
} else if (process.platform === 'freebsd') {
|
|
248
|
+
if (process.arch === 'x64') {
|
|
249
|
+
try {
|
|
250
|
+
return require('./mdrs.freebsd-x64.node')
|
|
251
|
+
} catch (e) {
|
|
252
|
+
loadErrors.push(e)
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
const binding = require('@mdrs/core-freebsd-x64')
|
|
256
|
+
const bindingPackageVersion = require('@mdrs/core-freebsd-x64/package.json').version
|
|
257
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
258
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
259
|
+
}
|
|
260
|
+
return binding
|
|
261
|
+
} catch (e) {
|
|
262
|
+
loadErrors.push(e)
|
|
263
|
+
}
|
|
264
|
+
} else if (process.arch === 'arm64') {
|
|
265
|
+
try {
|
|
266
|
+
return require('./mdrs.freebsd-arm64.node')
|
|
267
|
+
} catch (e) {
|
|
268
|
+
loadErrors.push(e)
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
const binding = require('@mdrs/core-freebsd-arm64')
|
|
272
|
+
const bindingPackageVersion = require('@mdrs/core-freebsd-arm64/package.json').version
|
|
273
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
274
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
275
|
+
}
|
|
276
|
+
return binding
|
|
277
|
+
} catch (e) {
|
|
278
|
+
loadErrors.push(e)
|
|
279
|
+
}
|
|
280
|
+
} else if (process.arch === 'ppc64') {
|
|
281
|
+
try {
|
|
282
|
+
return require('./mdrs.freebsd-ppc64.node')
|
|
283
|
+
} catch (e) {
|
|
284
|
+
loadErrors.push(e)
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
const binding = require('@mdrs/core-freebsd-ppc64')
|
|
288
|
+
const bindingPackageVersion = require('@mdrs/core-freebsd-ppc64/package.json').version
|
|
289
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
290
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
291
|
+
}
|
|
292
|
+
return binding
|
|
293
|
+
} catch (e) {
|
|
294
|
+
loadErrors.push(e)
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
298
|
+
}
|
|
299
|
+
} else if (process.platform === 'linux') {
|
|
300
|
+
if (process.arch === 'x64') {
|
|
301
|
+
if (isMusl()) {
|
|
302
|
+
try {
|
|
303
|
+
return require('./mdrs.linux-x64-musl.node')
|
|
304
|
+
} catch (e) {
|
|
305
|
+
loadErrors.push(e)
|
|
306
|
+
}
|
|
307
|
+
try {
|
|
308
|
+
const binding = require('@mdrs/core-linux-x64-musl')
|
|
309
|
+
const bindingPackageVersion = require('@mdrs/core-linux-x64-musl/package.json').version
|
|
310
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
311
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
312
|
+
}
|
|
313
|
+
return binding
|
|
314
|
+
} catch (e) {
|
|
315
|
+
loadErrors.push(e)
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
try {
|
|
319
|
+
return require('./mdrs.linux-x64-gnu.node')
|
|
320
|
+
} catch (e) {
|
|
321
|
+
loadErrors.push(e)
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
const binding = require('@mdrs/core-linux-x64-gnu')
|
|
325
|
+
const bindingPackageVersion = require('@mdrs/core-linux-x64-gnu/package.json').version
|
|
326
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
327
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
328
|
+
}
|
|
329
|
+
return binding
|
|
330
|
+
} catch (e) {
|
|
331
|
+
loadErrors.push(e)
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
} else if (process.arch === 'arm64') {
|
|
335
|
+
if (isMusl()) {
|
|
336
|
+
try {
|
|
337
|
+
return require('./mdrs.linux-arm64-musl.node')
|
|
338
|
+
} catch (e) {
|
|
339
|
+
loadErrors.push(e)
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
const binding = require('@mdrs/core-linux-arm64-musl')
|
|
343
|
+
const bindingPackageVersion = require('@mdrs/core-linux-arm64-musl/package.json').version
|
|
344
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
345
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
346
|
+
}
|
|
347
|
+
return binding
|
|
348
|
+
} catch (e) {
|
|
349
|
+
loadErrors.push(e)
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
try {
|
|
353
|
+
return require('./mdrs.linux-arm64-gnu.node')
|
|
354
|
+
} catch (e) {
|
|
355
|
+
loadErrors.push(e)
|
|
356
|
+
}
|
|
357
|
+
try {
|
|
358
|
+
const binding = require('@mdrs/core-linux-arm64-gnu')
|
|
359
|
+
const bindingPackageVersion = require('@mdrs/core-linux-arm64-gnu/package.json').version
|
|
360
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
361
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
362
|
+
}
|
|
363
|
+
return binding
|
|
364
|
+
} catch (e) {
|
|
365
|
+
loadErrors.push(e)
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
} else if (process.arch === 'arm') {
|
|
369
|
+
if (isMusl()) {
|
|
370
|
+
try {
|
|
371
|
+
return require('./mdrs.linux-arm-musleabihf.node')
|
|
372
|
+
} catch (e) {
|
|
373
|
+
loadErrors.push(e)
|
|
374
|
+
}
|
|
375
|
+
try {
|
|
376
|
+
const binding = require('@mdrs/core-linux-arm-musleabihf')
|
|
377
|
+
const bindingPackageVersion = require('@mdrs/core-linux-arm-musleabihf/package.json').version
|
|
378
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
379
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
380
|
+
}
|
|
381
|
+
return binding
|
|
382
|
+
} catch (e) {
|
|
383
|
+
loadErrors.push(e)
|
|
384
|
+
}
|
|
385
|
+
} else {
|
|
386
|
+
try {
|
|
387
|
+
return require('./mdrs.linux-arm-gnueabihf.node')
|
|
388
|
+
} catch (e) {
|
|
389
|
+
loadErrors.push(e)
|
|
390
|
+
}
|
|
391
|
+
try {
|
|
392
|
+
const binding = require('@mdrs/core-linux-arm-gnueabihf')
|
|
393
|
+
const bindingPackageVersion = require('@mdrs/core-linux-arm-gnueabihf/package.json').version
|
|
394
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
395
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
396
|
+
}
|
|
397
|
+
return binding
|
|
398
|
+
} catch (e) {
|
|
399
|
+
loadErrors.push(e)
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
} else if (process.arch === 'loong64') {
|
|
403
|
+
if (isMusl()) {
|
|
404
|
+
try {
|
|
405
|
+
return require('./mdrs.linux-loong64-musl.node')
|
|
406
|
+
} catch (e) {
|
|
407
|
+
loadErrors.push(e)
|
|
408
|
+
}
|
|
409
|
+
try {
|
|
410
|
+
const binding = require('@mdrs/core-linux-loong64-musl')
|
|
411
|
+
const bindingPackageVersion = require('@mdrs/core-linux-loong64-musl/package.json').version
|
|
412
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
413
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
414
|
+
}
|
|
415
|
+
return binding
|
|
416
|
+
} catch (e) {
|
|
417
|
+
loadErrors.push(e)
|
|
418
|
+
}
|
|
419
|
+
} else {
|
|
420
|
+
try {
|
|
421
|
+
return require('./mdrs.linux-loong64-gnu.node')
|
|
422
|
+
} catch (e) {
|
|
423
|
+
loadErrors.push(e)
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
const binding = require('@mdrs/core-linux-loong64-gnu')
|
|
427
|
+
const bindingPackageVersion = require('@mdrs/core-linux-loong64-gnu/package.json').version
|
|
428
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
429
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
430
|
+
}
|
|
431
|
+
return binding
|
|
432
|
+
} catch (e) {
|
|
433
|
+
loadErrors.push(e)
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
} else if (process.arch === 'riscv64') {
|
|
437
|
+
if (isMusl()) {
|
|
438
|
+
try {
|
|
439
|
+
return require('./mdrs.linux-riscv64-musl.node')
|
|
440
|
+
} catch (e) {
|
|
441
|
+
loadErrors.push(e)
|
|
442
|
+
}
|
|
443
|
+
try {
|
|
444
|
+
const binding = require('@mdrs/core-linux-riscv64-musl')
|
|
445
|
+
const bindingPackageVersion = require('@mdrs/core-linux-riscv64-musl/package.json').version
|
|
446
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
447
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
448
|
+
}
|
|
449
|
+
return binding
|
|
450
|
+
} catch (e) {
|
|
451
|
+
loadErrors.push(e)
|
|
452
|
+
}
|
|
453
|
+
} else {
|
|
454
|
+
try {
|
|
455
|
+
return require('./mdrs.linux-riscv64-gnu.node')
|
|
456
|
+
} catch (e) {
|
|
457
|
+
loadErrors.push(e)
|
|
458
|
+
}
|
|
459
|
+
try {
|
|
460
|
+
const binding = require('@mdrs/core-linux-riscv64-gnu')
|
|
461
|
+
const bindingPackageVersion = require('@mdrs/core-linux-riscv64-gnu/package.json').version
|
|
462
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
463
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
464
|
+
}
|
|
465
|
+
return binding
|
|
466
|
+
} catch (e) {
|
|
467
|
+
loadErrors.push(e)
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
} else if (process.arch === 'ppc64') {
|
|
471
|
+
try {
|
|
472
|
+
return require('./mdrs.linux-ppc64-gnu.node')
|
|
473
|
+
} catch (e) {
|
|
474
|
+
loadErrors.push(e)
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
const binding = require('@mdrs/core-linux-ppc64-gnu')
|
|
478
|
+
const bindingPackageVersion = require('@mdrs/core-linux-ppc64-gnu/package.json').version
|
|
479
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
|
+
}
|
|
482
|
+
return binding
|
|
483
|
+
} catch (e) {
|
|
484
|
+
loadErrors.push(e)
|
|
485
|
+
}
|
|
486
|
+
} else if (process.arch === 's390x') {
|
|
487
|
+
try {
|
|
488
|
+
return require('./mdrs.linux-s390x-gnu.node')
|
|
489
|
+
} catch (e) {
|
|
490
|
+
loadErrors.push(e)
|
|
491
|
+
}
|
|
492
|
+
try {
|
|
493
|
+
const binding = require('@mdrs/core-linux-s390x-gnu')
|
|
494
|
+
const bindingPackageVersion = require('@mdrs/core-linux-s390x-gnu/package.json').version
|
|
495
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
|
+
}
|
|
498
|
+
return binding
|
|
499
|
+
} catch (e) {
|
|
500
|
+
loadErrors.push(e)
|
|
501
|
+
}
|
|
502
|
+
} else {
|
|
503
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
504
|
+
}
|
|
505
|
+
} else if (process.platform === 'openharmony') {
|
|
506
|
+
if (process.arch === 'arm64') {
|
|
507
|
+
try {
|
|
508
|
+
return require('./mdrs.openharmony-arm64.node')
|
|
509
|
+
} catch (e) {
|
|
510
|
+
loadErrors.push(e)
|
|
511
|
+
}
|
|
512
|
+
try {
|
|
513
|
+
const binding = require('@mdrs/core-openharmony-arm64')
|
|
514
|
+
const bindingPackageVersion = require('@mdrs/core-openharmony-arm64/package.json').version
|
|
515
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
516
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
517
|
+
}
|
|
518
|
+
return binding
|
|
519
|
+
} catch (e) {
|
|
520
|
+
loadErrors.push(e)
|
|
521
|
+
}
|
|
522
|
+
} else if (process.arch === 'x64') {
|
|
523
|
+
try {
|
|
524
|
+
return require('./mdrs.openharmony-x64.node')
|
|
525
|
+
} catch (e) {
|
|
526
|
+
loadErrors.push(e)
|
|
527
|
+
}
|
|
528
|
+
try {
|
|
529
|
+
const binding = require('@mdrs/core-openharmony-x64')
|
|
530
|
+
const bindingPackageVersion = require('@mdrs/core-openharmony-x64/package.json').version
|
|
531
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
532
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
533
|
+
}
|
|
534
|
+
return binding
|
|
535
|
+
} catch (e) {
|
|
536
|
+
loadErrors.push(e)
|
|
537
|
+
}
|
|
538
|
+
} else if (process.arch === 'arm') {
|
|
539
|
+
try {
|
|
540
|
+
return require('./mdrs.openharmony-arm.node')
|
|
541
|
+
} catch (e) {
|
|
542
|
+
loadErrors.push(e)
|
|
543
|
+
}
|
|
544
|
+
try {
|
|
545
|
+
const binding = require('@mdrs/core-openharmony-arm')
|
|
546
|
+
const bindingPackageVersion = require('@mdrs/core-openharmony-arm/package.json').version
|
|
547
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
548
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
549
|
+
}
|
|
550
|
+
return binding
|
|
551
|
+
} catch (e) {
|
|
552
|
+
loadErrors.push(e)
|
|
553
|
+
}
|
|
554
|
+
} else {
|
|
555
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
556
|
+
}
|
|
557
|
+
} else {
|
|
558
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function createLoadErrorChain(errors) {
|
|
563
|
+
return errors.reduce((previous, current) => {
|
|
564
|
+
let message
|
|
565
|
+
try {
|
|
566
|
+
message =
|
|
567
|
+
current && typeof current.message === 'string'
|
|
568
|
+
? current.message
|
|
569
|
+
: String(current)
|
|
570
|
+
} catch {
|
|
571
|
+
message = 'Unknown error'
|
|
572
|
+
}
|
|
573
|
+
const error = new Error(message)
|
|
574
|
+
error.cause = previous
|
|
575
|
+
return error
|
|
576
|
+
}, null)
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// NAPI_RS_FORCE_WASI is a tri-state flag:
|
|
580
|
+
// unset / any other value → native binding preferred, WASI is only a fallback
|
|
581
|
+
// 'true' → prefer WASI, but retain native as a lazy fallback
|
|
582
|
+
// 'error' → require WASI without initializing a native fallback
|
|
583
|
+
// Treating any non-empty string as truthy (the historical behavior) meant
|
|
584
|
+
// NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
|
|
585
|
+
// the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
|
|
586
|
+
//
|
|
587
|
+
// NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
|
|
588
|
+
// WASI loading. It never crosses into another flavor or falls back to native.
|
|
589
|
+
const __napiWasiFlavors = ['wasm32-wasi']
|
|
590
|
+
const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
|
|
591
|
+
const __napiWasiFlavorRequested =
|
|
592
|
+
typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
|
|
593
|
+
if (
|
|
594
|
+
__napiWasiFlavorRequested &&
|
|
595
|
+
__napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
|
|
596
|
+
) {
|
|
597
|
+
throw new Error(
|
|
598
|
+
'Unsupported WASI flavor "' +
|
|
599
|
+
__napiWasiFlavor +
|
|
600
|
+
'". Available flavors: ' +
|
|
601
|
+
__napiWasiFlavors.join(', '),
|
|
602
|
+
)
|
|
603
|
+
}
|
|
604
|
+
const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
|
|
605
|
+
const forceWasi =
|
|
606
|
+
process.env.NAPI_RS_FORCE_WASI === 'true' ||
|
|
607
|
+
forceWasiError ||
|
|
608
|
+
__napiWasiFlavorRequested
|
|
609
|
+
|
|
610
|
+
if (!forceWasi) {
|
|
611
|
+
nativeBinding = requireNative()
|
|
612
|
+
__napiRequiredNativeBinding = nativeBinding
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (!nativeBinding || forceWasi) {
|
|
616
|
+
let wasiBinding = null
|
|
617
|
+
let wasiBindingLoaded = false
|
|
618
|
+
const wasiBindingErrors = []
|
|
619
|
+
const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
|
|
620
|
+
try {
|
|
621
|
+
require.resolve(specifier)
|
|
622
|
+
} catch (resolveError) {
|
|
623
|
+
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
624
|
+
throw resolveError
|
|
625
|
+
}
|
|
626
|
+
if (isPackage) {
|
|
627
|
+
try {
|
|
628
|
+
require.resolve(specifier + '/package.json')
|
|
629
|
+
} catch (packageError) {
|
|
630
|
+
if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
|
|
631
|
+
return resolveError
|
|
632
|
+
}
|
|
633
|
+
// An exports restriction proves the package exists even when its
|
|
634
|
+
// package.json is not public. Preserve the root resolution failure.
|
|
635
|
+
throw resolveError
|
|
636
|
+
}
|
|
637
|
+
// The package exists but its main/export target is broken.
|
|
638
|
+
throw resolveError
|
|
639
|
+
}
|
|
640
|
+
return resolveError
|
|
641
|
+
}
|
|
642
|
+
if (localArtifacts) {
|
|
643
|
+
let artifactError = null
|
|
644
|
+
for (let i = 0; i < localArtifacts.length; i++) {
|
|
645
|
+
try {
|
|
646
|
+
require.resolve(localArtifacts[i])
|
|
647
|
+
return null
|
|
648
|
+
} catch (resolveError) {
|
|
649
|
+
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
650
|
+
throw resolveError
|
|
651
|
+
}
|
|
652
|
+
artifactError = resolveError
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return artifactError
|
|
656
|
+
}
|
|
657
|
+
return null
|
|
658
|
+
}
|
|
659
|
+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
|
|
660
|
+
let candidateError = null
|
|
661
|
+
let candidateFailed = false
|
|
662
|
+
try {
|
|
663
|
+
candidateError = __napiWasiResolveCandidate('./mdrs.wasi.cjs', false, ['./mdrs.wasm32-wasi.debug.wasm', './mdrs.wasm32-wasi.wasm'])
|
|
664
|
+
candidateFailed = candidateError !== null
|
|
665
|
+
if (!candidateFailed) {
|
|
666
|
+
wasiBinding = require('./mdrs.wasi.cjs')
|
|
667
|
+
nativeBinding = wasiBinding
|
|
668
|
+
__napiLoadedBindingTarget = 'wasm32-wasi'
|
|
669
|
+
wasiBindingLoaded = true
|
|
670
|
+
}
|
|
671
|
+
} catch (err) {
|
|
672
|
+
candidateError = err
|
|
673
|
+
candidateFailed = true
|
|
674
|
+
}
|
|
675
|
+
if (candidateFailed) {
|
|
676
|
+
wasiBindingErrors.push(candidateError)
|
|
677
|
+
loadErrors.push(candidateError)
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
|
|
681
|
+
let candidateError = null
|
|
682
|
+
let candidateFailed = false
|
|
683
|
+
try {
|
|
684
|
+
candidateError = __napiWasiResolveCandidate('@mdrs/core-wasm32-wasi', true, undefined)
|
|
685
|
+
candidateFailed = candidateError !== null
|
|
686
|
+
if (!candidateFailed) {
|
|
687
|
+
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
688
|
+
const bindingPackageVersion = require('@mdrs/core-wasm32-wasi/package.json').version
|
|
689
|
+
if (bindingPackageVersion !== '0.0.0') {
|
|
690
|
+
throw new Error(`WASI binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
wasiBinding = require('@mdrs/core-wasm32-wasi')
|
|
694
|
+
nativeBinding = wasiBinding
|
|
695
|
+
__napiLoadedBindingTarget = 'wasm32-wasi'
|
|
696
|
+
wasiBindingLoaded = true
|
|
697
|
+
}
|
|
698
|
+
} catch (err) {
|
|
699
|
+
candidateError = err
|
|
700
|
+
candidateFailed = true
|
|
701
|
+
}
|
|
702
|
+
if (candidateFailed) {
|
|
703
|
+
wasiBindingErrors.push(candidateError)
|
|
704
|
+
loadErrors.push(candidateError)
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (
|
|
708
|
+
!wasiBindingLoaded &&
|
|
709
|
+
forceWasi &&
|
|
710
|
+
!forceWasiError &&
|
|
711
|
+
!__napiWasiFlavorRequested
|
|
712
|
+
) {
|
|
713
|
+
nativeBinding = requireNative()
|
|
714
|
+
__napiRequiredNativeBinding = nativeBinding
|
|
715
|
+
}
|
|
716
|
+
if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
|
|
717
|
+
const error = new Error(
|
|
718
|
+
__napiWasiFlavorRequested
|
|
719
|
+
? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
|
|
720
|
+
: 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
|
|
721
|
+
)
|
|
722
|
+
error.cause = createLoadErrorChain(wasiBindingErrors)
|
|
723
|
+
throw error
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (!nativeBinding) {
|
|
728
|
+
if (loadErrors.length > 0) {
|
|
729
|
+
const error = new Error(
|
|
730
|
+
`Cannot find native binding. ` +
|
|
731
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
732
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
733
|
+
)
|
|
734
|
+
// assign instead of the `new Error(message, { cause })` options form,
|
|
735
|
+
// which Node < 16.9 silently ignores
|
|
736
|
+
error.cause = createLoadErrorChain(loadErrors)
|
|
737
|
+
throw error
|
|
738
|
+
}
|
|
739
|
+
throw new Error(`Failed to load native binding`)
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// A package can patch its own fallback in front of the load-failure check
|
|
743
|
+
// above, e.g. a WebContainer download through `napi-postinstall/fallback`.
|
|
744
|
+
// That fallback swaps `nativeBinding` for a generated WASI loader, which has
|
|
745
|
+
// already stamped its own flavor, while the target above still says 'native'.
|
|
746
|
+
// Take that flavor over, or the CommonJS stamp throws a conflict and the ESM
|
|
747
|
+
// export reports the wrong artifact. Three limits keep the conflict check:
|
|
748
|
+
// - only a binding this loader did not load itself, so a native addon whose
|
|
749
|
+
// `#[napi(module_exports)]` hook claims the name is still rejected;
|
|
750
|
+
// - only an own data property, read through its descriptor, so no addon
|
|
751
|
+
// getter runs here, and it must read back the same, as the stamp reads it;
|
|
752
|
+
// - only a flavor in `__napiWasiFlavors`, the ones this loader's own WASI
|
|
753
|
+
// chain can report ('wasm32-wasi' for a package without a WASI target).
|
|
754
|
+
// This is metadata and never fails a load: a throwing Proxy trap keeps 'native'.
|
|
755
|
+
if (
|
|
756
|
+
__napiLoadedBindingTarget === 'native' &&
|
|
757
|
+
nativeBinding !== __napiRequiredNativeBinding
|
|
758
|
+
) {
|
|
759
|
+
try {
|
|
760
|
+
const __napiBindingTargetDescriptor = Object.getOwnPropertyDescriptor(
|
|
761
|
+
nativeBinding,
|
|
762
|
+
'__napiBindingTarget',
|
|
763
|
+
)
|
|
764
|
+
if (
|
|
765
|
+
__napiBindingTargetDescriptor &&
|
|
766
|
+
__napiWasiFlavors.indexOf(__napiBindingTargetDescriptor.value) !== -1 &&
|
|
767
|
+
nativeBinding.__napiBindingTarget === __napiBindingTargetDescriptor.value
|
|
768
|
+
) {
|
|
769
|
+
__napiLoadedBindingTarget = __napiBindingTargetDescriptor.value
|
|
770
|
+
}
|
|
771
|
+
} catch {
|
|
772
|
+
// keep 'native'
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
const { isMdrsPath, prepareMarkdownPage, prepareMarkdownPageWithData, renderMarkdown, renderMarkdownWithData, resolveDefines, resolveDefinesWithData } = nativeBinding
|
|
777
|
+
export { isMdrsPath }
|
|
778
|
+
export { prepareMarkdownPage }
|
|
779
|
+
export { prepareMarkdownPageWithData }
|
|
780
|
+
export { renderMarkdown }
|
|
781
|
+
export { renderMarkdownWithData }
|
|
782
|
+
export { resolveDefines }
|
|
783
|
+
export { resolveDefinesWithData }
|
|
784
|
+
export const __napiBindingTarget = __napiLoadedBindingTarget
|
package/package.json
CHANGED
|
@@ -1,6 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdrs/core",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0-alpha1",
|
|
4
|
+
"description": "MDRS (Markdown Rich Syntax): a drop-in superset of Markdown",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"author": "Farhan Kurnia Pratama <farhnkrnapratma@gmail.com>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/farhnkrnapratma/mdrs.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/farhnkrnapratma/mdrs#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/farhnkrnapratma/mdrs/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./index.js",
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"default": "./index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"index.js",
|
|
26
|
+
"index.native.js",
|
|
27
|
+
"index.d.ts",
|
|
28
|
+
"index.native.d.ts",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE-MIT",
|
|
31
|
+
"LICENSE-APACHE"
|
|
32
|
+
],
|
|
33
|
+
"keywords": [
|
|
34
|
+
"markdown",
|
|
35
|
+
"commonmark",
|
|
36
|
+
"gfm",
|
|
37
|
+
"parser",
|
|
38
|
+
"directives",
|
|
39
|
+
"mdrs"
|
|
40
|
+
],
|
|
41
|
+
"sideEffects": false,
|
|
42
|
+
"scripts": {
|
|
43
|
+
"prepare": "bash .githooks/install.sh",
|
|
44
|
+
"build": "napi build --platform --features napi --esm --js index.native.js --dts index.native.d.ts",
|
|
45
|
+
"build:release": "napi build --platform --release --features napi --esm --js index.native.js --dts index.native.d.ts",
|
|
46
|
+
"test:bindings": "bun scripts/test-bindings.mjs",
|
|
47
|
+
"test:native": "bun run build:release && bun run test:bindings"
|
|
48
|
+
},
|
|
49
|
+
"napi": {
|
|
50
|
+
"binaryName": "mdrs",
|
|
51
|
+
"targets": [
|
|
52
|
+
"x86_64-unknown-linux-gnu",
|
|
53
|
+
"aarch64-unknown-linux-gnu",
|
|
54
|
+
"x86_64-unknown-linux-musl",
|
|
55
|
+
"aarch64-unknown-linux-musl",
|
|
56
|
+
"x86_64-apple-darwin",
|
|
57
|
+
"aarch64-apple-darwin",
|
|
58
|
+
"x86_64-pc-windows-msvc",
|
|
59
|
+
"aarch64-pc-windows-msvc"
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@commitlint/cli": "^21.2.4",
|
|
67
|
+
"@commitlint/config-conventional": "^21.2.4",
|
|
68
|
+
"@napi-rs/cli": "^3.10.12"
|
|
69
|
+
},
|
|
70
|
+
"optionalDependencies": {
|
|
71
|
+
"@mdrs/core-linux-x64-gnu": "1.0.0-alpha1",
|
|
72
|
+
"@mdrs/core-linux-arm64-gnu": "1.0.0-alpha1",
|
|
73
|
+
"@mdrs/core-linux-x64-musl": "1.0.0-alpha1",
|
|
74
|
+
"@mdrs/core-linux-arm64-musl": "1.0.0-alpha1",
|
|
75
|
+
"@mdrs/core-darwin-x64": "1.0.0-alpha1",
|
|
76
|
+
"@mdrs/core-darwin-arm64": "1.0.0-alpha1",
|
|
77
|
+
"@mdrs/core-win32-x64-msvc": "1.0.0-alpha1",
|
|
78
|
+
"@mdrs/core-win32-arm64-msvc": "1.0.0-alpha1"
|
|
79
|
+
}
|
|
80
|
+
}
|