@vellora/native 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/LICENSE-DejaVu.txt +187 -0
- package/README.md +32 -0
- package/THIRD-PARTY-NOTICES.md +6172 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/package.json +76 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** The only platforms this phase ships prebuilds for. */
|
|
2
|
+
export declare const SUPPORTED_PLATFORMS: readonly ["macOS arm64 (darwin-arm64)", "macOS x64 (darwin-x64)", "linux x64 glibc (linux-x64-gnu)", "linux arm64 glibc (linux-arm64-gnu)"];
|
|
3
|
+
/**
|
|
4
|
+
* Host-tag → prebuild package map. Pre-enumerates the full intended matrix so adding a target later
|
|
5
|
+
* is purely additive (publish the package, flip its value from `null`): no loader-shape or consumer
|
|
6
|
+
* change. Published in the launch matrix: `darwin-arm64`, `darwin-x64`, `linux-x64-gnu`,
|
|
7
|
+
* `linux-arm64-gnu`. Reserved (no published package yet): `linux-x64-musl`, `linux-arm64-musl`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const RESOLUTION_TABLE: Readonly<Record<string, string | null>>;
|
|
10
|
+
/**
|
|
11
|
+
* Render options forwarded to `vellora-core`. Producer is fixed to `vellora`; only the document
|
|
12
|
+
* title and a deterministic creation date `[year, month, day]` (never wall-clock) are caller-supplied.
|
|
13
|
+
*/
|
|
14
|
+
export interface RenderOpts {
|
|
15
|
+
title?: string;
|
|
16
|
+
creationDate?: [number, number, number];
|
|
17
|
+
}
|
|
18
|
+
/** Surface of the native addon: the smoke export plus the async `render` binding. */
|
|
19
|
+
export interface VelloraAddon {
|
|
20
|
+
coreName(): string;
|
|
21
|
+
render(html: Uint8Array, opts?: RenderOpts): Promise<Uint8Array>;
|
|
22
|
+
/** Test-only: forces a worker-thread panic to verify panic-to-rejection. Not a public API. */
|
|
23
|
+
__forcePanicForTest?(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/** napi-rs platform tag, e.g. `darwin-arm64`, `linux-x64-gnu`, `linux-arm64-musl`. */
|
|
26
|
+
export declare function platformTag(platform?: string, arch?: string): string;
|
|
27
|
+
/** Build the actionable error thrown when no compatible addon exists for the host. */
|
|
28
|
+
export declare function unsupportedPlatformError(platform: string, arch: string, tag?: string): Error;
|
|
29
|
+
/** Resolve and cache the host addon. Throws an actionable error on an unsupported platform. */
|
|
30
|
+
export declare function addon(): VelloraAddon;
|
|
31
|
+
/** Smoke export: proves the addon loads and is callable in-process. */
|
|
32
|
+
export declare function coreName(): string;
|
|
33
|
+
/**
|
|
34
|
+
* Render document HTML *content* bytes to a PDF on the libuv threadpool, off the Node main thread.
|
|
35
|
+
* `html` is always content (never a file path); the returned `Uint8Array` is JS-owned and starts
|
|
36
|
+
* with `%PDF-`. Rejects with an `Error` carrying the `vellora-core` diagnostic — for a located
|
|
37
|
+
* diagnostic the error also exposes `{ feature, line, col, hint }` as machine-readable properties.
|
|
38
|
+
*/
|
|
39
|
+
export declare function render(html: Uint8Array, opts?: RenderOpts): Promise<Uint8Array>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vellora/native — platform loader.
|
|
3
|
+
*
|
|
4
|
+
* Resolves the correct prebuilt napi-rs `.node` addon for the host (a locally built addon in dev,
|
|
5
|
+
* or a per-platform `optionalDependencies` package once published), and throws a clear, actionable
|
|
6
|
+
* error when no compatible addon is found. Re-exports the addon's async, thread-safe `render`
|
|
7
|
+
* function (libuv-threadpool, per-call isolated) unchanged.
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
10
|
+
import { createRequire } from "node:module";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
// Both `src/` (vitest) and `dist/` (built) live one level under the package root, where the
|
|
15
|
+
// locally built `.node` is emitted, so `..` resolves to the package dir in both cases.
|
|
16
|
+
const PKG_DIR = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
17
|
+
/** The only platforms this phase ships prebuilds for. */
|
|
18
|
+
export const SUPPORTED_PLATFORMS = [
|
|
19
|
+
"macOS arm64 (darwin-arm64)",
|
|
20
|
+
"macOS x64 (darwin-x64)",
|
|
21
|
+
"linux x64 glibc (linux-x64-gnu)",
|
|
22
|
+
"linux arm64 glibc (linux-arm64-gnu)",
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Host-tag → prebuild package map. Pre-enumerates the full intended matrix so adding a target later
|
|
26
|
+
* is purely additive (publish the package, flip its value from `null`): no loader-shape or consumer
|
|
27
|
+
* change. Published in the launch matrix: `darwin-arm64`, `darwin-x64`, `linux-x64-gnu`,
|
|
28
|
+
* `linux-arm64-gnu`. Reserved (no published package yet): `linux-x64-musl`, `linux-arm64-musl`.
|
|
29
|
+
*/
|
|
30
|
+
export const RESOLUTION_TABLE = {
|
|
31
|
+
"darwin-arm64": "@vellora/native-darwin-arm64",
|
|
32
|
+
"darwin-x64": "@vellora/native-darwin-x64",
|
|
33
|
+
"linux-x64-gnu": "@vellora/native-linux-x64-gnu",
|
|
34
|
+
"linux-arm64-gnu": "@vellora/native-linux-arm64-gnu",
|
|
35
|
+
// Reserved for a later phase: no published package yet (musl needs a native-musl build host).
|
|
36
|
+
"linux-x64-musl": null,
|
|
37
|
+
"linux-arm64-musl": null,
|
|
38
|
+
};
|
|
39
|
+
function isMusl() {
|
|
40
|
+
try {
|
|
41
|
+
const report = process.report?.getReport();
|
|
42
|
+
return !report?.header?.glibcVersionRuntime;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** napi-rs platform tag, e.g. `darwin-arm64`, `linux-x64-gnu`, `linux-arm64-musl`. */
|
|
49
|
+
export function platformTag(platform = process.platform, arch = process.arch) {
|
|
50
|
+
if (platform === "linux") {
|
|
51
|
+
return `linux-${arch}-${isMusl() ? "musl" : "gnu"}`;
|
|
52
|
+
}
|
|
53
|
+
return `${platform}-${arch}`;
|
|
54
|
+
}
|
|
55
|
+
/** Build the actionable error thrown when no compatible addon exists for the host. */
|
|
56
|
+
export function unsupportedPlatformError(platform, arch, tag = platformTag(platform, arch)) {
|
|
57
|
+
const windowsNote = platform === "win32"
|
|
58
|
+
? "\nWindows is not supported yet — prebuilt Windows binaries are a planned fast-follow."
|
|
59
|
+
: "";
|
|
60
|
+
return new Error(`@vellora/native: no compatible prebuilt addon for ${platform}-${arch} (resolved tag "${tag}").
|
|
61
|
+
Supported platforms: ${SUPPORTED_PLATFORMS.join(", ")}.${windowsNote}
|
|
62
|
+
To build locally, install the Rust toolchain and run \`npm run build\` at the repo root (which runs \`napi build\` for the vellora-napi crate).`);
|
|
63
|
+
}
|
|
64
|
+
function loadAddon() {
|
|
65
|
+
const tag = platformTag();
|
|
66
|
+
// 1) Dev: a locally built `.node` next to the package takes precedence.
|
|
67
|
+
const localPath = join(PKG_DIR, `vellora.${tag}.node`);
|
|
68
|
+
if (existsSync(localPath)) {
|
|
69
|
+
return require(localPath);
|
|
70
|
+
}
|
|
71
|
+
// 2) Published: resolve the matching prebuild package via the resolution table. Only the
|
|
72
|
+
// host-matching entry is required; a missing sibling optional package must not break the load.
|
|
73
|
+
const pkg = RESOLUTION_TABLE[tag];
|
|
74
|
+
if (pkg) {
|
|
75
|
+
try {
|
|
76
|
+
return require(pkg);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// The optional prebuild package is absent on this host; fall through to the actionable error.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
throw unsupportedPlatformError(process.platform, process.arch, tag);
|
|
83
|
+
}
|
|
84
|
+
let cached;
|
|
85
|
+
/** Resolve and cache the host addon. Throws an actionable error on an unsupported platform. */
|
|
86
|
+
export function addon() {
|
|
87
|
+
if (!cached) {
|
|
88
|
+
cached = loadAddon();
|
|
89
|
+
}
|
|
90
|
+
return cached;
|
|
91
|
+
}
|
|
92
|
+
/** Smoke export: proves the addon loads and is callable in-process. */
|
|
93
|
+
export function coreName() {
|
|
94
|
+
return addon().coreName();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Render document HTML *content* bytes to a PDF on the libuv threadpool, off the Node main thread.
|
|
98
|
+
* `html` is always content (never a file path); the returned `Uint8Array` is JS-owned and starts
|
|
99
|
+
* with `%PDF-`. Rejects with an `Error` carrying the `vellora-core` diagnostic — for a located
|
|
100
|
+
* diagnostic the error also exposes `{ feature, line, col, hint }` as machine-readable properties.
|
|
101
|
+
*/
|
|
102
|
+
export function render(html, opts) {
|
|
103
|
+
return addon().render(html, opts);
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,4FAA4F;AAC5F,uFAAuF;AACvF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAEpE,yDAAyD;AACzD,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,4BAA4B;IAC5B,wBAAwB;IACxB,iCAAiC;IACjC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,GAAG,WAAW,EAAE,CAAC;IAC1B,wEAAwE;IACxE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC;IACvD,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1B,OAAO,OAAO,CAAC,SAAS,CAAiB,CAAC;IAC5C,CAAC;IACD,yFAAyF;IACzF,+FAA+F;IAC/F,MAAM,GAAG,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,GAAG,EAAE,CAAC;QACR,IAAI,CAAC;YACH,OAAO,OAAO,CAAC,GAAG,CAAiB,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,8FAA8F;QAChG,CAAC;IACH,CAAC;IACD,MAAM,wBAAwB,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACtE,CAAC;AAED,IAAI,MAAgC,CAAC;AAErC,+FAA+F;AAC/F,MAAM,UAAU,KAAK;IACnB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,SAAS,EAAE,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,QAAQ;IACtB,OAAO,KAAK,EAAE,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,IAAgB,EAAE,IAAiB;IACxD,OAAO,KAAK,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vellora/native",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "Prebuilt napi-rs addon loader for vellora — alpha.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"html-to-pdf",
|
|
7
|
+
"pdf",
|
|
8
|
+
"pdf-generation",
|
|
9
|
+
"invoice",
|
|
10
|
+
"boleto",
|
|
11
|
+
"receipt",
|
|
12
|
+
"pdfa",
|
|
13
|
+
"pdfua",
|
|
14
|
+
"tagged-pdf",
|
|
15
|
+
"no-puppeteer",
|
|
16
|
+
"no-chromium",
|
|
17
|
+
"serverless",
|
|
18
|
+
"wkhtmltopdf-alternative",
|
|
19
|
+
"napi-rs",
|
|
20
|
+
"nodejs"
|
|
21
|
+
],
|
|
22
|
+
"homepage": "https://github.com/diomalta/vellora#readme",
|
|
23
|
+
"bugs": "https://github.com/diomalta/vellora/issues",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/diomalta/vellora.git",
|
|
27
|
+
"directory": "packages/native"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"author": "Diego Malta <diohmalta@gmail.com>",
|
|
31
|
+
"type": "module",
|
|
32
|
+
"main": "dist/index.js",
|
|
33
|
+
"types": "dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"README.md",
|
|
47
|
+
"LICENSE",
|
|
48
|
+
"THIRD-PARTY-NOTICES.md",
|
|
49
|
+
"LICENSE-DejaVu.txt"
|
|
50
|
+
],
|
|
51
|
+
"napi": {
|
|
52
|
+
"binaryName": "vellora",
|
|
53
|
+
"targets": [
|
|
54
|
+
"aarch64-apple-darwin",
|
|
55
|
+
"x86_64-apple-darwin",
|
|
56
|
+
"x86_64-unknown-linux-gnu",
|
|
57
|
+
"aarch64-unknown-linux-gnu",
|
|
58
|
+
"x86_64-unknown-linux-musl"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build:addon": "napi build --release --platform --manifest-path ../../crates/vellora-napi/Cargo.toml --output-dir . --no-js",
|
|
63
|
+
"build": "tsc"
|
|
64
|
+
},
|
|
65
|
+
"optionalDependencies": {
|
|
66
|
+
"@vellora/native-darwin-arm64": "0.1.0-alpha.0",
|
|
67
|
+
"@vellora/native-darwin-x64": "0.1.0-alpha.0",
|
|
68
|
+
"@vellora/native-linux-x64-gnu": "0.1.0-alpha.0",
|
|
69
|
+
"@vellora/native-linux-arm64-gnu": "0.1.0-alpha.0",
|
|
70
|
+
"@vellora/native-linux-x64-musl": "0.1.0-alpha.0"
|
|
71
|
+
},
|
|
72
|
+
"publishConfig": {
|
|
73
|
+
"access": "public",
|
|
74
|
+
"provenance": true
|
|
75
|
+
}
|
|
76
|
+
}
|