@phron/image 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +79 -0
- package/dist/index.js +51 -0
- package/dist/native.d.ts +2 -0
- package/dist/native.js +8 -0
- package/dist/next.d.ts +35 -0
- package/dist/next.js +48 -0
- package/dist/options.d.ts +22 -0
- package/dist/options.js +25 -0
- package/native.cjs +852 -0
- package/native.d.cts +81 -0
- package/package.json +96 -4
- package/phron-image.wasm32-wasip1.wasm +0 -0
- package/phron-image.wasm32-wasip1.wasm.d.mts +6 -0
- package/phron-image.wasm32-wasip1.workerd.d.mts +2 -0
- package/phron-image.wasm32-wasip1.workerd.mjs +2 -0
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export type { Gravity, ResizeType } from "./options.js";
|
|
2
|
+
export { options } from "./options.js";
|
|
3
|
+
/** Where a browser URL points: pass `baseUrl` (a custom domain) or `label`, never both. */
|
|
4
|
+
export interface Target {
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/** Source label: `https://<label>.phronusercontent.com`. */
|
|
7
|
+
label?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface SignUrlParams extends Target {
|
|
10
|
+
/** Hex signing key, as shown once in the console. Server-side only. */
|
|
11
|
+
key: string;
|
|
12
|
+
/** Hex salt, as shown once in the console. Server-side only. */
|
|
13
|
+
salt: string;
|
|
14
|
+
/** Processing options, for example `[options.width(800), options.quality(80)]`. */
|
|
15
|
+
options?: readonly string[];
|
|
16
|
+
/** Source path, not yet encoded. */
|
|
17
|
+
path: string;
|
|
18
|
+
/** Output format, written as `@<format>`. */
|
|
19
|
+
format?: string;
|
|
20
|
+
/** Unix seconds. Adds an `exp:<n>` option, which is part of the signed path. */
|
|
21
|
+
expiresAt?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Build a signed browser URL: `<base>/<signature>/<options>/plain/<path>[@<format>]`.
|
|
25
|
+
* The signing is done by the Rust core. Server-side only: `key` and `salt` must never reach a
|
|
26
|
+
* browser. Throws if an input is invalid.
|
|
27
|
+
*/
|
|
28
|
+
export declare function signUrl(params: SignUrlParams): string;
|
|
29
|
+
export interface PublicUrlParams extends Target {
|
|
30
|
+
/** Preset name. */
|
|
31
|
+
preset: string;
|
|
32
|
+
/** One of the source's public widths. */
|
|
33
|
+
width?: number;
|
|
34
|
+
path: string;
|
|
35
|
+
format?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build an unsigned browser URL for a source whose access is "public":
|
|
39
|
+
* `<base>/_/pr:<preset>[/w:<width>]/plain/<path>[@<format>]`. No secret involved.
|
|
40
|
+
*/
|
|
41
|
+
export declare function publicUrl(params: PublicUrlParams): string;
|
|
42
|
+
export interface ApiUrlParams {
|
|
43
|
+
label: string;
|
|
44
|
+
/** Override the API host (default `https://api.phron.net`). */
|
|
45
|
+
apiBaseUrl?: string;
|
|
46
|
+
options?: readonly string[];
|
|
47
|
+
path: string;
|
|
48
|
+
format?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build an API URL: `https://api.phron.net/v1/image/<label>/_/<options>/plain/<path>`.
|
|
52
|
+
* Send it with an `Authorization: Bearer <API key>` header. Not signed.
|
|
53
|
+
*/
|
|
54
|
+
export declare function apiUrl(params: ApiUrlParams): string;
|
|
55
|
+
export interface InfoUrlParams {
|
|
56
|
+
label: string;
|
|
57
|
+
apiBaseUrl?: string;
|
|
58
|
+
/** Info options, for example `["size:1", "format:1"]`. */
|
|
59
|
+
options?: readonly string[];
|
|
60
|
+
path: string;
|
|
61
|
+
}
|
|
62
|
+
/** Build an info URL: `https://api.phron.net/v1/image/<label>/info/<info options>/plain/<path>`. */
|
|
63
|
+
export declare function infoUrl(params: InfoUrlParams): string;
|
|
64
|
+
/**
|
|
65
|
+
* Percent-encode a source path: each segment is encoded, slashes are kept, a leading slash is
|
|
66
|
+
* dropped. `@` is encoded too, because an unescaped `@` starts the output format.
|
|
67
|
+
*/
|
|
68
|
+
export declare function encodePath(path: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Round an expiry up to a bucket boundary: `now + ttl`, rounded UP to a multiple of
|
|
71
|
+
* `bucketSeconds`. The result is a unix time in seconds.
|
|
72
|
+
*
|
|
73
|
+
* A URL that carries the same `exp` on every render stays byte-identical, so the browser's
|
|
74
|
+
* cache (which may keep a result for up to a day) keeps working. An `exp` of "now plus one
|
|
75
|
+
* hour" changes every second and defeats it.
|
|
76
|
+
*/
|
|
77
|
+
export declare function roundedExpiry(ttlSeconds: number, bucketSeconds?: number, nowMs?: number): number;
|
|
78
|
+
/** Build a `srcset` value: `<url> <width>w, ...`, one URL per width. */
|
|
79
|
+
export declare function srcset(builder: (width: number) => string, widths: readonly number[]): string;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { native } from "./native.js";
|
|
2
|
+
export { options } from "./options.js";
|
|
3
|
+
const list = (options) => options ? [...options] : undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Build a signed browser URL: `<base>/<signature>/<options>/plain/<path>[@<format>]`.
|
|
6
|
+
* The signing is done by the Rust core. Server-side only: `key` and `salt` must never reach a
|
|
7
|
+
* browser. Throws if an input is invalid.
|
|
8
|
+
*/
|
|
9
|
+
export function signUrl(params) {
|
|
10
|
+
return native.signUrl({ ...params, options: list(params.options) });
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Build an unsigned browser URL for a source whose access is "public":
|
|
14
|
+
* `<base>/_/pr:<preset>[/w:<width>]/plain/<path>[@<format>]`. No secret involved.
|
|
15
|
+
*/
|
|
16
|
+
export function publicUrl(params) {
|
|
17
|
+
return native.publicUrl(params);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Build an API URL: `https://api.phron.net/v1/image/<label>/_/<options>/plain/<path>`.
|
|
21
|
+
* Send it with an `Authorization: Bearer <API key>` header. Not signed.
|
|
22
|
+
*/
|
|
23
|
+
export function apiUrl(params) {
|
|
24
|
+
return native.apiUrl({ ...params, options: list(params.options) });
|
|
25
|
+
}
|
|
26
|
+
/** Build an info URL: `https://api.phron.net/v1/image/<label>/info/<info options>/plain/<path>`. */
|
|
27
|
+
export function infoUrl(params) {
|
|
28
|
+
return native.infoUrl({ ...params, options: list(params.options) });
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Percent-encode a source path: each segment is encoded, slashes are kept, a leading slash is
|
|
32
|
+
* dropped. `@` is encoded too, because an unescaped `@` starts the output format.
|
|
33
|
+
*/
|
|
34
|
+
export function encodePath(path) {
|
|
35
|
+
return native.encodePath(path);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Round an expiry up to a bucket boundary: `now + ttl`, rounded UP to a multiple of
|
|
39
|
+
* `bucketSeconds`. The result is a unix time in seconds.
|
|
40
|
+
*
|
|
41
|
+
* A URL that carries the same `exp` on every render stays byte-identical, so the browser's
|
|
42
|
+
* cache (which may keep a result for up to a day) keeps working. An `exp` of "now plus one
|
|
43
|
+
* hour" changes every second and defeats it.
|
|
44
|
+
*/
|
|
45
|
+
export function roundedExpiry(ttlSeconds, bucketSeconds = 3600, nowMs = Date.now()) {
|
|
46
|
+
return native.roundedExpiry(nowMs / 1000, ttlSeconds, bucketSeconds);
|
|
47
|
+
}
|
|
48
|
+
/** Build a `srcset` value: `<url> <width>w, ...`, one URL per width. */
|
|
49
|
+
export function srcset(builder, widths) {
|
|
50
|
+
return widths.map((w) => `${builder(w)} ${w}w`).join(", ");
|
|
51
|
+
}
|
package/dist/native.d.ts
ADDED
package/dist/native.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The napi-rs addon, loaded through the generated `native.cjs` (it picks the platform package,
|
|
3
|
+
* `@phron/image-<platform>`, or a local `.node` file in development). The addon is generated at
|
|
4
|
+
* build time and is not in version control.
|
|
5
|
+
*/
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
export const native = require("../native.cjs");
|
package/dist/next.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `next/image` loader for public sources. It runs in the browser, where the native addon cannot
|
|
3
|
+
* load, so it builds the unsigned public URL itself instead of calling the Rust core. This is
|
|
4
|
+
* the one URL builder written outside the core: the `public` cases of `conformance/vectors.json`
|
|
5
|
+
* pin it to the core's output (tests/conformance.test.ts). Retire it when a WebAssembly build of
|
|
6
|
+
* the core can serve browsers (docs/adr/0001-rust-core-multi-language.md).
|
|
7
|
+
*/
|
|
8
|
+
export interface NextImageLoaderProps {
|
|
9
|
+
src: string;
|
|
10
|
+
width: number;
|
|
11
|
+
quality?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface PublicLoaderParams {
|
|
14
|
+
/** A custom domain, for example `https://img.example.com`. Pass this or `label`. */
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
/** Source label: `https://<label>.phronusercontent.com`. */
|
|
17
|
+
label?: string;
|
|
18
|
+
/** Preset name. */
|
|
19
|
+
preset: string;
|
|
20
|
+
format?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A `next/image` custom loader for a source whose access is "public". It builds unsigned
|
|
24
|
+
* URLs, so it holds no secret and is safe in client code.
|
|
25
|
+
*
|
|
26
|
+
* Next.js asks for the widths in `images.deviceSizes` and `images.imageSizes`; set those to
|
|
27
|
+
* the source's list of public widths.
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* "use client";
|
|
31
|
+
* import { publicLoader } from "@phron/image/next";
|
|
32
|
+
* export default publicLoader({ label: "my-source", preset: "card" });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function publicLoader(params: PublicLoaderParams): ({ src, width }: NextImageLoaderProps) => string;
|
package/dist/next.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `next/image` loader for public sources. It runs in the browser, where the native addon cannot
|
|
3
|
+
* load, so it builds the unsigned public URL itself instead of calling the Rust core. This is
|
|
4
|
+
* the one URL builder written outside the core: the `public` cases of `conformance/vectors.json`
|
|
5
|
+
* pin it to the core's output (tests/conformance.test.ts). Retire it when a WebAssembly build of
|
|
6
|
+
* the core can serve browsers (docs/adr/0001-rust-core-multi-language.md).
|
|
7
|
+
*/
|
|
8
|
+
const LABEL = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i;
|
|
9
|
+
const encodePath = (path) => path
|
|
10
|
+
.replace(/^\/+/, "")
|
|
11
|
+
.split("/")
|
|
12
|
+
.map((segment) => encodeURIComponent(segment))
|
|
13
|
+
.join("/");
|
|
14
|
+
function baseOf({ baseUrl, label }) {
|
|
15
|
+
if (baseUrl !== undefined && label !== undefined)
|
|
16
|
+
throw new TypeError("pass either baseUrl or label, not both");
|
|
17
|
+
if (baseUrl !== undefined)
|
|
18
|
+
return baseUrl.replace(/\/+$/, "");
|
|
19
|
+
if (label === undefined)
|
|
20
|
+
throw new TypeError("baseUrl or label is required");
|
|
21
|
+
if (!LABEL.test(label))
|
|
22
|
+
throw new TypeError(`invalid source label: ${JSON.stringify(label)}`);
|
|
23
|
+
return `https://${label}.phronusercontent.com`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A `next/image` custom loader for a source whose access is "public". It builds unsigned
|
|
27
|
+
* URLs, so it holds no secret and is safe in client code.
|
|
28
|
+
*
|
|
29
|
+
* Next.js asks for the widths in `images.deviceSizes` and `images.imageSizes`; set those to
|
|
30
|
+
* the source's list of public widths.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* "use client";
|
|
34
|
+
* import { publicLoader } from "@phron/image/next";
|
|
35
|
+
* export default publicLoader({ label: "my-source", preset: "card" });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function publicLoader(params) {
|
|
39
|
+
const base = baseOf(params);
|
|
40
|
+
const suffix = params.format ? `@${encodeURIComponent(params.format)}` : "";
|
|
41
|
+
// `quality` is ignored on purpose: a preset fixes the quality, and an unsigned URL accepts
|
|
42
|
+
// only a preset and a width.
|
|
43
|
+
return ({ src, width }) => {
|
|
44
|
+
if (!Number.isInteger(width) || width <= 0)
|
|
45
|
+
throw new TypeError("width must be a positive integer");
|
|
46
|
+
return `${base}/_/pr:${encodeURIComponent(params.preset)}/w:${width}/plain/${encodePath(src)}${suffix}`;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type ResizeType = "fit" | "fill" | "fill-down" | "force" | "auto";
|
|
2
|
+
export type Gravity = "no" | "so" | "ea" | "we" | "noea" | "nowe" | "soea" | "sowe" | "ce" | "sm";
|
|
3
|
+
export declare const options: {
|
|
4
|
+
/** `rs:<type>:<width>:<height>` */
|
|
5
|
+
readonly resize: (type: ResizeType, width: number, height: number) => string;
|
|
6
|
+
/** `w:<width>` */
|
|
7
|
+
readonly width: (width: number) => string;
|
|
8
|
+
/** `h:<height>` */
|
|
9
|
+
readonly height: (height: number) => string;
|
|
10
|
+
/** `q:<quality>` (1 to 100). */
|
|
11
|
+
readonly quality: (quality: number) => string;
|
|
12
|
+
/** `f:<format>`. A URL can also carry the format as an `@<format>` suffix. */
|
|
13
|
+
readonly format: (format: string) => string;
|
|
14
|
+
/** `g:<gravity>[:<x offset>:<y offset>]` */
|
|
15
|
+
readonly gravity: (gravity: Gravity, xOffset?: number, yOffset?: number) => string;
|
|
16
|
+
/** `pr:<preset>` */
|
|
17
|
+
readonly preset: (name: string) => string;
|
|
18
|
+
/** `exp:<unix seconds>` */
|
|
19
|
+
readonly expires: (unixSeconds: number) => string;
|
|
20
|
+
/** Escape hatch: an option written exactly as it should appear in the URL. */
|
|
21
|
+
readonly raw: (option: string) => string;
|
|
22
|
+
};
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed helpers for the common processing options. Each returns the option as a string, so
|
|
3
|
+
* they mix freely with raw strings in an `options` array. The rules live in the Rust core.
|
|
4
|
+
*/
|
|
5
|
+
import { native } from "./native.js";
|
|
6
|
+
export const options = {
|
|
7
|
+
/** `rs:<type>:<width>:<height>` */
|
|
8
|
+
resize: (type, width, height) => native.optionResize(type, width, height),
|
|
9
|
+
/** `w:<width>` */
|
|
10
|
+
width: (width) => native.optionWidth(width),
|
|
11
|
+
/** `h:<height>` */
|
|
12
|
+
height: (height) => native.optionHeight(height),
|
|
13
|
+
/** `q:<quality>` (1 to 100). */
|
|
14
|
+
quality: (quality) => native.optionQuality(quality),
|
|
15
|
+
/** `f:<format>`. A URL can also carry the format as an `@<format>` suffix. */
|
|
16
|
+
format: (format) => native.optionFormat(format),
|
|
17
|
+
/** `g:<gravity>[:<x offset>:<y offset>]` */
|
|
18
|
+
gravity: (gravity, xOffset, yOffset) => native.optionGravity(gravity, xOffset, yOffset),
|
|
19
|
+
/** `pr:<preset>` */
|
|
20
|
+
preset: (name) => native.optionPreset(name),
|
|
21
|
+
/** `exp:<unix seconds>` */
|
|
22
|
+
expires: (unixSeconds) => native.optionExpires(unixSeconds),
|
|
23
|
+
/** Escape hatch: an option written exactly as it should appear in the URL. */
|
|
24
|
+
raw: (option) => native.optionRaw(option),
|
|
25
|
+
};
|
package/native.cjs
ADDED
|
@@ -0,0 +1,852 @@
|
|
|
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('./phron-image.android-arm64.node')
|
|
91
|
+
} catch (e) {
|
|
92
|
+
loadErrors.push(e)
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const binding = require('@phron/image-android-arm64')
|
|
96
|
+
const bindingPackageVersion = require('@phron/image-android-arm64/package.json').version
|
|
97
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.android-arm-eabi.node')
|
|
107
|
+
} catch (e) {
|
|
108
|
+
loadErrors.push(e)
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const binding = require('@phron/image-android-arm-eabi')
|
|
112
|
+
const bindingPackageVersion = require('@phron/image-android-arm-eabi/package.json').version
|
|
113
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.win32-x64-gnu.node')
|
|
128
|
+
} catch (e) {
|
|
129
|
+
loadErrors.push(e)
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const binding = require('@phron/image-win32-x64-gnu')
|
|
133
|
+
const bindingPackageVersion = require('@phron/image-win32-x64-gnu/package.json').version
|
|
134
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.win32-x64-msvc.node')
|
|
144
|
+
} catch (e) {
|
|
145
|
+
loadErrors.push(e)
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const binding = require('@phron/image-win32-x64-msvc')
|
|
149
|
+
const bindingPackageVersion = require('@phron/image-win32-x64-msvc/package.json').version
|
|
150
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.win32-ia32-msvc.node')
|
|
161
|
+
} catch (e) {
|
|
162
|
+
loadErrors.push(e)
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
const binding = require('@phron/image-win32-ia32-msvc')
|
|
166
|
+
const bindingPackageVersion = require('@phron/image-win32-ia32-msvc/package.json').version
|
|
167
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.win32-arm64-msvc.node')
|
|
177
|
+
} catch (e) {
|
|
178
|
+
loadErrors.push(e)
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
const binding = require('@phron/image-win32-arm64-msvc')
|
|
182
|
+
const bindingPackageVersion = require('@phron/image-win32-arm64-msvc/package.json').version
|
|
183
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.darwin-universal.node')
|
|
196
|
+
} catch (e) {
|
|
197
|
+
loadErrors.push(e)
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
const binding = require('@phron/image-darwin-universal')
|
|
201
|
+
const bindingPackageVersion = require('@phron/image-darwin-universal/package.json').version
|
|
202
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.darwin-x64.node')
|
|
212
|
+
} catch (e) {
|
|
213
|
+
loadErrors.push(e)
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
const binding = require('@phron/image-darwin-x64')
|
|
217
|
+
const bindingPackageVersion = require('@phron/image-darwin-x64/package.json').version
|
|
218
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.darwin-arm64.node')
|
|
228
|
+
} catch (e) {
|
|
229
|
+
loadErrors.push(e)
|
|
230
|
+
}
|
|
231
|
+
try {
|
|
232
|
+
const binding = require('@phron/image-darwin-arm64')
|
|
233
|
+
const bindingPackageVersion = require('@phron/image-darwin-arm64/package.json').version
|
|
234
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.freebsd-x64.node')
|
|
248
|
+
} catch (e) {
|
|
249
|
+
loadErrors.push(e)
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
const binding = require('@phron/image-freebsd-x64')
|
|
253
|
+
const bindingPackageVersion = require('@phron/image-freebsd-x64/package.json').version
|
|
254
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.freebsd-arm64.node')
|
|
264
|
+
} catch (e) {
|
|
265
|
+
loadErrors.push(e)
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
const binding = require('@phron/image-freebsd-arm64')
|
|
269
|
+
const bindingPackageVersion = require('@phron/image-freebsd-arm64/package.json').version
|
|
270
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.freebsd-ppc64.node')
|
|
280
|
+
} catch (e) {
|
|
281
|
+
loadErrors.push(e)
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
const binding = require('@phron/image-freebsd-ppc64')
|
|
285
|
+
const bindingPackageVersion = require('@phron/image-freebsd-ppc64/package.json').version
|
|
286
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.linux-x64-musl.node')
|
|
301
|
+
} catch (e) {
|
|
302
|
+
loadErrors.push(e)
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
const binding = require('@phron/image-linux-x64-musl')
|
|
306
|
+
const bindingPackageVersion = require('@phron/image-linux-x64-musl/package.json').version
|
|
307
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.linux-x64-gnu.node')
|
|
317
|
+
} catch (e) {
|
|
318
|
+
loadErrors.push(e)
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
const binding = require('@phron/image-linux-x64-gnu')
|
|
322
|
+
const bindingPackageVersion = require('@phron/image-linux-x64-gnu/package.json').version
|
|
323
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.linux-arm64-musl.node')
|
|
335
|
+
} catch (e) {
|
|
336
|
+
loadErrors.push(e)
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
const binding = require('@phron/image-linux-arm64-musl')
|
|
340
|
+
const bindingPackageVersion = require('@phron/image-linux-arm64-musl/package.json').version
|
|
341
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.linux-arm64-gnu.node')
|
|
351
|
+
} catch (e) {
|
|
352
|
+
loadErrors.push(e)
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
const binding = require('@phron/image-linux-arm64-gnu')
|
|
356
|
+
const bindingPackageVersion = require('@phron/image-linux-arm64-gnu/package.json').version
|
|
357
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.linux-arm-musleabihf.node')
|
|
369
|
+
} catch (e) {
|
|
370
|
+
loadErrors.push(e)
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
const binding = require('@phron/image-linux-arm-musleabihf')
|
|
374
|
+
const bindingPackageVersion = require('@phron/image-linux-arm-musleabihf/package.json').version
|
|
375
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.linux-arm-gnueabihf.node')
|
|
385
|
+
} catch (e) {
|
|
386
|
+
loadErrors.push(e)
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
const binding = require('@phron/image-linux-arm-gnueabihf')
|
|
390
|
+
const bindingPackageVersion = require('@phron/image-linux-arm-gnueabihf/package.json').version
|
|
391
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.linux-loong64-musl.node')
|
|
403
|
+
} catch (e) {
|
|
404
|
+
loadErrors.push(e)
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
const binding = require('@phron/image-linux-loong64-musl')
|
|
408
|
+
const bindingPackageVersion = require('@phron/image-linux-loong64-musl/package.json').version
|
|
409
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.linux-loong64-gnu.node')
|
|
419
|
+
} catch (e) {
|
|
420
|
+
loadErrors.push(e)
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
const binding = require('@phron/image-linux-loong64-gnu')
|
|
424
|
+
const bindingPackageVersion = require('@phron/image-linux-loong64-gnu/package.json').version
|
|
425
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.linux-riscv64-musl.node')
|
|
437
|
+
} catch (e) {
|
|
438
|
+
loadErrors.push(e)
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
const binding = require('@phron/image-linux-riscv64-musl')
|
|
442
|
+
const bindingPackageVersion = require('@phron/image-linux-riscv64-musl/package.json').version
|
|
443
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.linux-riscv64-gnu.node')
|
|
453
|
+
} catch (e) {
|
|
454
|
+
loadErrors.push(e)
|
|
455
|
+
}
|
|
456
|
+
try {
|
|
457
|
+
const binding = require('@phron/image-linux-riscv64-gnu')
|
|
458
|
+
const bindingPackageVersion = require('@phron/image-linux-riscv64-gnu/package.json').version
|
|
459
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 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('./phron-image.linux-ppc64-gnu.node')
|
|
470
|
+
} catch (e) {
|
|
471
|
+
loadErrors.push(e)
|
|
472
|
+
}
|
|
473
|
+
try {
|
|
474
|
+
const binding = require('@phron/image-linux-ppc64-gnu')
|
|
475
|
+
const bindingPackageVersion = require('@phron/image-linux-ppc64-gnu/package.json').version
|
|
476
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.linux-s390x-gnu.node')
|
|
486
|
+
} catch (e) {
|
|
487
|
+
loadErrors.push(e)
|
|
488
|
+
}
|
|
489
|
+
try {
|
|
490
|
+
const binding = require('@phron/image-linux-s390x-gnu')
|
|
491
|
+
const bindingPackageVersion = require('@phron/image-linux-s390x-gnu/package.json').version
|
|
492
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.openharmony-arm64.node')
|
|
506
|
+
} catch (e) {
|
|
507
|
+
loadErrors.push(e)
|
|
508
|
+
}
|
|
509
|
+
try {
|
|
510
|
+
const binding = require('@phron/image-openharmony-arm64')
|
|
511
|
+
const bindingPackageVersion = require('@phron/image-openharmony-arm64/package.json').version
|
|
512
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.openharmony-x64.node')
|
|
522
|
+
} catch (e) {
|
|
523
|
+
loadErrors.push(e)
|
|
524
|
+
}
|
|
525
|
+
try {
|
|
526
|
+
const binding = require('@phron/image-openharmony-x64')
|
|
527
|
+
const bindingPackageVersion = require('@phron/image-openharmony-x64/package.json').version
|
|
528
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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('./phron-image.openharmony-arm.node')
|
|
538
|
+
} catch (e) {
|
|
539
|
+
loadErrors.push(e)
|
|
540
|
+
}
|
|
541
|
+
try {
|
|
542
|
+
const binding = require('@phron/image-openharmony-arm')
|
|
543
|
+
const bindingPackageVersion = require('@phron/image-openharmony-arm/package.json').version
|
|
544
|
+
if (bindingPackageVersion !== '0.1.0' && 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 0.1.0 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-wasip1']
|
|
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-wasip1')) {
|
|
657
|
+
let candidateError = null
|
|
658
|
+
let candidateFailed = false
|
|
659
|
+
try {
|
|
660
|
+
candidateError = __napiWasiResolveCandidate('./phron-image.wasip1.cjs', false, ['./phron-image.wasm32-wasip1.debug.wasm', './phron-image.wasm32-wasip1.wasm'])
|
|
661
|
+
candidateFailed = candidateError !== null
|
|
662
|
+
if (!candidateFailed) {
|
|
663
|
+
wasiBinding = require('./phron-image.wasip1.cjs')
|
|
664
|
+
nativeBinding = wasiBinding
|
|
665
|
+
__napiLoadedBindingTarget = 'wasm32-wasip1'
|
|
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-wasip1')) {
|
|
678
|
+
let candidateError = null
|
|
679
|
+
let candidateFailed = false
|
|
680
|
+
try {
|
|
681
|
+
candidateError = __napiWasiResolveCandidate('@phron/image-wasm32-wasip1', 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('@phron/image-wasm32-wasip1/package.json').version
|
|
686
|
+
if (bindingPackageVersion !== '0.1.0') {
|
|
687
|
+
throw new Error(`WASI binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
wasiBinding = require('@phron/image-wasm32-wasip1')
|
|
691
|
+
nativeBinding = wasiBinding
|
|
692
|
+
__napiLoadedBindingTarget = 'wasm32-wasip1'
|
|
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.apiUrl = nativeBinding.apiUrl
|
|
839
|
+
module.exports.encodePath = nativeBinding.encodePath
|
|
840
|
+
module.exports.infoUrl = nativeBinding.infoUrl
|
|
841
|
+
module.exports.optionExpires = nativeBinding.optionExpires
|
|
842
|
+
module.exports.optionFormat = nativeBinding.optionFormat
|
|
843
|
+
module.exports.optionGravity = nativeBinding.optionGravity
|
|
844
|
+
module.exports.optionHeight = nativeBinding.optionHeight
|
|
845
|
+
module.exports.optionPreset = nativeBinding.optionPreset
|
|
846
|
+
module.exports.optionQuality = nativeBinding.optionQuality
|
|
847
|
+
module.exports.optionRaw = nativeBinding.optionRaw
|
|
848
|
+
module.exports.optionResize = nativeBinding.optionResize
|
|
849
|
+
module.exports.optionWidth = nativeBinding.optionWidth
|
|
850
|
+
module.exports.publicUrl = nativeBinding.publicUrl
|
|
851
|
+
module.exports.roundedExpiry = nativeBinding.roundedExpiry
|
|
852
|
+
module.exports.signUrl = nativeBinding.signUrl
|
package/native.d.cts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
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 ApiInput {
|
|
13
|
+
label: string
|
|
14
|
+
apiBaseUrl?: string
|
|
15
|
+
options?: Array<string>
|
|
16
|
+
path: string
|
|
17
|
+
format?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Build an API URL (`/v1/image/<label>/_/...`), sent with a bearer API key. */
|
|
21
|
+
export declare function apiUrl(input: ApiInput): string
|
|
22
|
+
|
|
23
|
+
/** Percent-encode a source path the way the URL builders do. */
|
|
24
|
+
export declare function encodePath(path: string): string
|
|
25
|
+
|
|
26
|
+
export interface InfoInput {
|
|
27
|
+
label: string
|
|
28
|
+
apiBaseUrl?: string
|
|
29
|
+
options?: Array<string>
|
|
30
|
+
path: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Build an info URL (`/v1/image/<label>/info/...`). */
|
|
34
|
+
export declare function infoUrl(input: InfoInput): string
|
|
35
|
+
|
|
36
|
+
export declare function optionExpires(unixSeconds: number): string
|
|
37
|
+
|
|
38
|
+
export declare function optionFormat(format: string): string
|
|
39
|
+
|
|
40
|
+
export declare function optionGravity(gravity: string, xOffset?: number | undefined | null, yOffset?: number | undefined | null): string
|
|
41
|
+
|
|
42
|
+
export declare function optionHeight(height: number): string
|
|
43
|
+
|
|
44
|
+
export declare function optionPreset(name: string): string
|
|
45
|
+
|
|
46
|
+
export declare function optionQuality(quality: number): string
|
|
47
|
+
|
|
48
|
+
export declare function optionRaw(option: string): string
|
|
49
|
+
|
|
50
|
+
export declare function optionResize(kind: string, width: number, height: number): string
|
|
51
|
+
|
|
52
|
+
export declare function optionWidth(width: number): string
|
|
53
|
+
|
|
54
|
+
export interface PublicInput {
|
|
55
|
+
baseUrl?: string
|
|
56
|
+
label?: string
|
|
57
|
+
preset: string
|
|
58
|
+
width?: number
|
|
59
|
+
path: string
|
|
60
|
+
format?: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Build an unsigned browser URL for a source whose access is public. */
|
|
64
|
+
export declare function publicUrl(input: PublicInput): string
|
|
65
|
+
|
|
66
|
+
/** `now + ttl`, rounded up to a multiple of `bucketSeconds`, in unix seconds. */
|
|
67
|
+
export declare function roundedExpiry(nowSeconds: number, ttlSeconds: number, bucketSeconds: number): number
|
|
68
|
+
|
|
69
|
+
export interface SignInput {
|
|
70
|
+
baseUrl?: string
|
|
71
|
+
label?: string
|
|
72
|
+
key: string
|
|
73
|
+
salt: string
|
|
74
|
+
options?: Array<string>
|
|
75
|
+
path: string
|
|
76
|
+
format?: string
|
|
77
|
+
expiresAt?: number
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Build a signed browser URL. Server-side only: `key` and `salt` must never reach a browser. */
|
|
81
|
+
export declare function signUrl(input: SignInput): string
|
package/package.json
CHANGED
|
@@ -1,6 +1,98 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phron/image",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Build and sign Phron Image URLs. A Rust core, bound through napi-rs: native on Linux x64, WebAssembly everywhere else.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"phron",
|
|
7
|
+
"image",
|
|
8
|
+
"signed-url",
|
|
9
|
+
"hmac",
|
|
10
|
+
"nextjs",
|
|
11
|
+
"napi"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/phron-net/image.git",
|
|
19
|
+
"directory": "bindings/node"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/phron-net/image#readme",
|
|
22
|
+
"bugs": "https://github.com/phron-net/image/issues",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./next": {
|
|
31
|
+
"types": "./dist/next.d.ts",
|
|
32
|
+
"default": "./dist/next.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json",
|
|
35
|
+
"./workerd": {
|
|
36
|
+
"types": "./phron-image.wasm32-wasip1.workerd.d.mts",
|
|
37
|
+
"default": "./phron-image.wasm32-wasip1.workerd.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./wasm": {
|
|
40
|
+
"types": "./phron-image.wasm32-wasip1.wasm.d.mts",
|
|
41
|
+
"default": "./phron-image.wasm32-wasip1.wasm"
|
|
42
|
+
},
|
|
43
|
+
"./wasm.wasm": {
|
|
44
|
+
"types": "./phron-image.wasm32-wasip1.wasm.d.mts",
|
|
45
|
+
"default": "./phron-image.wasm32-wasip1.wasm"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist",
|
|
50
|
+
"native.cjs",
|
|
51
|
+
"native.d.cts",
|
|
52
|
+
"phron-image.wasm32-wasip1.workerd.mjs",
|
|
53
|
+
"phron-image.wasm32-wasip1.workerd.d.mts",
|
|
54
|
+
"phron-image.wasm32-wasip1.wasm",
|
|
55
|
+
"phron-image.wasm32-wasip1.wasm.d.mts"
|
|
56
|
+
],
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=20"
|
|
59
|
+
},
|
|
60
|
+
"napi": {
|
|
61
|
+
"binaryName": "phron-image",
|
|
62
|
+
"targets": [
|
|
63
|
+
"x86_64-unknown-linux-gnu",
|
|
64
|
+
"wasm32-wasip1"
|
|
65
|
+
],
|
|
66
|
+
"wasm": {
|
|
67
|
+
"cpu": false
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public",
|
|
72
|
+
"provenance": true
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"build:native": "napi build --platform --release --js native.cjs --dts native.d.cts",
|
|
76
|
+
"build:native:debug": "napi build --platform --js native.cjs --dts native.d.cts",
|
|
77
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
78
|
+
"typecheck": "tsc --noEmit",
|
|
79
|
+
"test": "vitest run",
|
|
80
|
+
"prepublishOnly": "napi prepublish -t npm --no-gh-release"
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@emnapi/core": "^2.0.0-beta.3",
|
|
84
|
+
"@emnapi/runtime": "^2.0.0-beta.3",
|
|
85
|
+
"@napi-rs/cli": "^3.10.12",
|
|
86
|
+
"@napi-rs/wasm-runtime": "^1.2.7",
|
|
87
|
+
"@types/node": "^22.0.0",
|
|
88
|
+
"emnapi": "^2.0.0-beta.3",
|
|
89
|
+
"esbuild": "^0.28.2",
|
|
90
|
+
"miniflare": "^4.20260730.0",
|
|
91
|
+
"typescript": "^7.0.2",
|
|
92
|
+
"vitest": "^5.1.0"
|
|
93
|
+
},
|
|
94
|
+
"optionalDependencies": {
|
|
95
|
+
"@phron/image-linux-x64-gnu": "0.1.0",
|
|
96
|
+
"@phron/image-wasm32-wasip1": "0.1.0"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// napi-rs-wasi-root-facade:{"version":1,"flavorPackage":"@phron/image-wasm32-wasip1","wasmSha256":"4fa16c1d538f9aa277c99401ddd7ab20d5c9e46b3bd3d0993ba8f50c84b94a72"}
|
|
2
|
+
/* auto-generated by NAPI-RS */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
|
|
5
|
+
declare const wasmModule: WebAssembly.Module
|
|
6
|
+
export default wasmModule
|
package/README.md
DELETED