chore: upgrade to NAPI-RS 3.0 stable (#142)

* chore: upgrade to NAPI-RS 3.0 stable

* upgrade debian

* edition

* napi cross

* napi cross

* Install nasm

* cross aarch64

* image version

* save

* update lock

* process.arch

* lockfile

* move artifacts

* set node version

* ubuntu

* wasm artifacts name

* cflags

* upgrade NAPI
This commit is contained in:
LongYinan 2025-07-24 22:02:44 +08:00 committed by GitHub
parent 2b42e4063c
commit 6b9fc30b86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 1025 additions and 1044 deletions

View File

@ -72,17 +72,12 @@ jobs:
target: i686-pc-windows-msvc
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: >-
set -e &&
apt-get update &&
apt-get install meson -y &&
rm /usr/lib/llvm-18/lib/libc++.so &&
export LDFLAGS="-L/usr/lib/llvm-18/lib -L/usr/x86_64-unknown-linux-gnu/lib/gcc/x86_64-unknown-linux-gnu/4.8.5" &&
export CFLAGS="-fuse-ld=lld -B/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5 --sysroot=/usr/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/sysroot" &&
export CXXFLAGS="-stdlib=libc++ -fuse-ld=lld -B/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5 --sysroot=/usr/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/sysroot -L/usr/lib/llvm-15/lib" &&
yarn workspace @napi-rs/image build --features with_simd --target x86_64-unknown-linux-gnu &&
chmod -R 777 target
build: |
CC=clang
CXX=clang++
TARGET_CC=clang
TARGET_CXX=clang++
yarn workspace @napi-rs/image build --features with_simd --target x86_64-unknown-linux-gnu --use-napi-cross
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
docker: ghcr.io/brooooooklyn/canvas/musl-builder:lts
@ -113,16 +108,10 @@ jobs:
yarn workspace @napi-rs/image build --target aarch64-apple-darwin --features with_simd
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
build: >-
set -e &&
rm /usr/aarch64-unknown-linux-gnu/lib/llvm-18/lib/libunwind.so &&
rm /usr/aarch64-unknown-linux-gnu/lib/llvm-18/lib/libc++.so &&
export LDFLAGS="-L/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5" &&
export CFLAGS="-fuse-ld=lld -mcrc -B/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5 --sysroot=/usr/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot" &&
export CXXFLAGS="-fuse-ld=lld -mcrc -B/usr/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/4.8.5 --sysroot=/usr/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot -L/usr/aarch64-unknown-linux-gnu/lib/llvm-18/lib -stdlib=libc++" &&
yarn workspace @napi-rs/image build --features with_simd --target aarch64-unknown-linux-gnu &&
chmod -R 777 target
build: |
export TARGET_CC=clang
export TARGET_CXX=clang++
yarn workspace @napi-rs/image build --features with_simd --target aarch64-unknown-linux-gnu --use-napi-cross
- host: ubuntu-latest
target: aarch64-linux-android
build: |
@ -141,17 +130,21 @@ jobs:
unset RUSTFLAGS &&
unset CC &&
unset CXX &&
rustup target add aarch64-unknown-linux-musl &&
rustup update &&
apk add --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing --no-cache aom-dev perl meson &&
yarn workspace @napi-rs/image build --target aarch64-unknown-linux-musl --features with_simd &&
chmod -R 777 target
- host: macos-latest
- host: ubuntu-latest
target: wasm32-wasip1-threads
setup: |
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-arm64-macos.tar.gz
tar -xvf wasi-sdk-25.0-arm64-macos.tar.gz
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz
tar -xvf wasi-sdk-25.0-x86_64-linux.tar.gz
build: |
export WASI_SDK_PATH="$(pwd)/wasi-sdk-25.0-arm64-macos"
export WASI_SDK_PATH="$(pwd)/wasi-sdk-25.0-x86_64-linux"
export CMAKE_BUILD_PARALLEL_LEVEL=2
export TARGET_CXXFLAGS="--target=wasm32-wasi-threads --sysroot=$(pwd)/wasi-sdk-25.0-x86_64-linux/share/wasi-sysroot -pthread -mllvm -wasm-enable-sjlj -lsetjmp"
export TARGET_CFLAGS="$TARGET_CXXFLAGS"
yarn workspace @napi-rs/image build --target wasm32-wasip1-threads
name: stable - ${{ matrix.settings.target }} - node@22
@ -167,7 +160,6 @@ jobs:
cache: yarn
- name: Setup nasm
uses: ilammy/setup-nasm@v1
if: matrix.settings.target == 'x86_64-pc-windows-msvc' || matrix.settings.target == 'x86_64-apple-darwin' || matrix.settings.target == 'i686-pc-windows-msvc'
- name: Install cargo-xwin
uses: taiki-e/install-action@v2
if: matrix.settings.target == 'i686-pc-windows-msvc' || matrix.settings.target == 'aarch64-pc-windows-msvc'
@ -223,8 +215,8 @@ jobs:
with:
name: bindings-${{ matrix.settings.target }}
path: |
packages/*/*.node
packages/*/*.wasm
packages/binding/*.node
packages/binding/image.wasm32-wasi.wasm
if-no-files-found: error
@ -232,19 +224,19 @@ jobs:
name: Build armv7-unknown-linux-gnueabihf
runs-on: ubuntu-latest
container:
image: debian:buster
image: debian:bullseye
steps:
- name: Setup tools
run: |
apt-get update
apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libatomic1-armhf-cross git build-essential cmake ninja-build wget curl gnupg
echo "deb http://apt.llvm.org/buster/ llvm-toolchain-buster-18 main" >> /etc/apt/sources.list
echo "deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-18 main" >> /etc/apt/sources.list
echo "deb http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-19 main" >> /etc/apt/sources.list
echo "deb-src http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-19 main" >> /etc/apt/sources.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
apt-get update
apt-get install -y clang-18
ln -s /usr/bin/clang-18 /usr/bin/clang
ln -s /usr/bin/clang++-18 /usr/bin/clang++
apt-get install -y clang-19
ln -s /usr/bin/clang-19 /usr/bin/clang
ln -s /usr/bin/clang++-19 /usr/bin/clang++
- uses: actions/checkout@v4
with:
submodules: true
@ -286,7 +278,7 @@ jobs:
- uses: actions/checkout@v4
- name: Build
id: build
uses: cross-platform-actions/action@v0.28.0
uses: cross-platform-actions/action@v0.29.0
env:
DEBUG: 'napi:*'
RUSTUP_HOME: /home/runner/rustup
@ -466,7 +458,8 @@ jobs:
matrix:
node:
- '20'
runs-on: ubuntu-latest
- '22'
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- name: Download artifacts
@ -484,11 +477,6 @@ jobs:
- name: List packages
run: ls -R packages
shell: bash
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- name: Setup and run tests
uses: addnab/docker-run-action@v3
with:
@ -536,23 +524,22 @@ jobs:
run: yarn test
test-wasi-on-nodejs:
name: Test wasi on Node.js
runs-on: macos-latest
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-wasm32-wasip1-threads
path: artifacts
path: packages/binding
- name: Install dependencies
run: yarn install --immutable --mode=skip-build
- name: Create npm dirs
run: yarn workspace @napi-rs/image napi create-npm-dirs
- name: Move artifacts
run: yarn artifacts
shell: bash
- name: List packages
run: ls -R packages
shell: bash

View File

@ -12,19 +12,19 @@
"website"
],
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.92",
"@napi-rs/cli": "^3.0.4",
"@taplo/cli": "^0.7.0",
"@types/node": "^24.0.4",
"@types/node": "^24.1.0",
"@types/sharp": "^0.32.0",
"ava": "^6.4.0",
"ava": "^6.4.1",
"blurhash": "^2.0.5",
"chalk": "^5.4.1",
"electron": "^37.0.0",
"lerna": "^8.2.2",
"electron": "^37.2.4",
"lerna": "^8.2.3",
"npm-run-all2": "^8.0.4",
"prettier": "^3.6.1",
"prettier": "^3.6.2",
"rxjs": "^7.8.2",
"sharp": "^0.34.2",
"sharp": "^0.34.3",
"typescript": "^5.8.3"
},
"scripts": {

View File

@ -1,5 +1,5 @@
[package]
edition = "2021"
edition = "2024"
name = "napi_rs_image"
version = "0.0.0"
@ -16,15 +16,15 @@ oxipng_libdeflater = ["oxipng/zopfli", "oxipng/parallel"]
with_simd = ["mozjpeg-sys/nasm_simd_parallel_build"]
[dependencies]
fast_image_resize = "5"
fast_image_resize = { version = "5", features = ["image"] }
image = { version = "0.25", default-features = false, features = ["jpeg", "ico", "png", "pnm", "tga", "tiff", "bmp", "webp", "hdr", "dds"] }
imagequant = "4.0.0"
jpeg-decoder = "0.3"
libavif = { version = "0.14", default-features = false, features = ["codec-aom"] }
libc = "0.2"
lodepng = "3"
napi = { version = "3.0.0-beta", default-features = false, features = ["napi3"] }
napi-derive = { version = "3.0.0-beta", default-features = false, features = ["type-def"] }
napi = { version = "3.0.0", default-features = false, features = ["napi3"] }
napi-derive = { version = "3.0.0", default-features = false, features = ["type-def"] }
num-complex = "0.4"
num_cpus = "1"
once_cell = "1"

View File

@ -6,6 +6,7 @@ import {
} from '@napi-rs/wasm-runtime'
const __wasi = new __WASI({
version: 'preview1',
})
@ -13,6 +14,7 @@ const __wasi = new __WASI({
const __wasmUrl = new URL('./image.wasm32-wasi.wasm', import.meta.url).href
const __emnapiContext = __emnapiGetDefaultContext()
const __sharedMemory = new WebAssembly.Memory({
initial: 4000,
maximum: 65536,

View File

@ -82,7 +82,7 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
s.toString().includes("kHandle")
);
if (kPublicPort) {
if (kHandle) {
worker[kHandle].ref = () => {};
}

View File

@ -82,7 +82,6 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm') {
try {
return require('./image.android-arm-eabi.node')
@ -94,7 +93,6 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
}
@ -110,7 +108,6 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'ia32') {
try {
return require('./image.win32-ia32-msvc.node')
@ -122,7 +119,6 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm64') {
try {
return require('./image.win32-arm64-msvc.node')
@ -134,22 +130,20 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
}
} else if (process.platform === 'darwin') {
try {
return require('./image.darwin-universal.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-darwin-universal')
} catch (e) {
loadErrors.push(e)
}
return require('./image.darwin-universal.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-darwin-universal')
} catch (e) {
loadErrors.push(e)
}
if (process.arch === 'x64') {
try {
return require('./image.darwin-x64.node')
@ -161,7 +155,6 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm64') {
try {
return require('./image.darwin-arm64.node')
@ -173,7 +166,6 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
}
@ -189,7 +181,6 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm64') {
try {
return require('./image.freebsd-arm64.node')
@ -201,7 +192,6 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
}
@ -209,106 +199,98 @@ function requireNative() {
if (process.arch === 'x64') {
if (isMusl()) {
try {
return require('./image.linux-x64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-x64-musl')
} catch (e) {
loadErrors.push(e)
}
return require('./image.linux-x64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-x64-musl')
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./image.linux-x64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-x64-gnu')
} catch (e) {
loadErrors.push(e)
}
return require('./image.linux-x64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-x64-gnu')
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'arm64') {
if (isMusl()) {
try {
return require('./image.linux-arm64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-arm64-musl')
} catch (e) {
loadErrors.push(e)
}
return require('./image.linux-arm64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-arm64-musl')
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./image.linux-arm64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-arm64-gnu')
} catch (e) {
loadErrors.push(e)
}
return require('./image.linux-arm64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-arm64-gnu')
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'arm') {
if (isMusl()) {
try {
return require('./image.linux-arm-musleabihf.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-arm-musleabihf')
} catch (e) {
loadErrors.push(e)
}
return require('./image.linux-arm-musleabihf.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-arm-musleabihf')
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./image.linux-arm-gnueabihf.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-arm-gnueabihf')
} catch (e) {
loadErrors.push(e)
}
return require('./image.linux-arm-gnueabihf.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-arm-gnueabihf')
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'riscv64') {
if (isMusl()) {
try {
return require('./image.linux-riscv64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-riscv64-musl')
} catch (e) {
loadErrors.push(e)
}
return require('./image.linux-riscv64-musl.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-riscv64-musl')
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./image.linux-riscv64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-riscv64-gnu')
} catch (e) {
loadErrors.push(e)
}
return require('./image.linux-riscv64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-riscv64-gnu')
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'ppc64') {
try {
@ -321,7 +303,6 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 's390x') {
try {
return require('./image.linux-s390x-gnu.node')
@ -333,10 +314,46 @@ function requireNative() {
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
}
} else if (process.platform === 'openharmony') {
if (process.arch === 'arm64') {
try {
return require('./image.linux-arm64-ohos.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-arm64-ohos')
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'x64') {
try {
return require('./image.linux-x64-ohos.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-x64-ohos')
} catch (e) {
loadErrors.push(e)
}
} else if (process.arch === 'arm') {
try {
return require('./image.linux-arm-ohos.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@napi-rs/image-linux-arm-ohos')
} catch (e) {
loadErrors.push(e)
}
} else {
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
}
} else {
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
}

View File

@ -72,7 +72,7 @@
},
"repository": "git@github.com:Brooooooklyn/Image.git",
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.92",
"@napi-rs/wasm-runtime": "^0.2.11"
"@napi-rs/cli": "^3.0.4",
"@napi-rs/wasm-runtime": "^1.0.1"
}
}

View File

@ -66,7 +66,7 @@ unsafe fn moz_jpeg_compress(
usize,
mozjpeg_sys::jpeg_decompress_struct,
mozjpeg_sys::jpeg_compress_struct,
)> {
)> { unsafe {
std::panic::catch_unwind(|| {
let mut de_c_info: mozjpeg_sys::jpeg_decompress_struct = std::mem::zeroed();
let mut err_handler = create_error_handler();
@ -110,15 +110,15 @@ unsafe fn moz_jpeg_compress(
format!("Compress JPEG failed {err:?}"),
)
})
}
}}
unsafe fn create_error_handler() -> mozjpeg_sys::jpeg_error_mgr {
unsafe fn create_error_handler() -> mozjpeg_sys::jpeg_error_mgr { unsafe {
let mut err: mozjpeg_sys::jpeg_error_mgr = std::mem::zeroed();
mozjpeg_sys::jpeg_std_error(&mut err);
err.error_exit = Some(unwind_error_exit);
err.emit_message = Some(silence_message);
err
}
}}
unsafe extern "C-unwind" fn unwind_error_exit(cinfo: &mut mozjpeg_sys::jpeg_common_struct) {
let message = unsafe {

View File

@ -4,19 +4,19 @@ use std::sync::Arc;
use image::imageops::overlay;
use image::{
imageops::FilterType, ColorType, DynamicImage, ImageBuffer, ImageEncoder, ImageFormat, RgbaImage,
ColorType, DynamicImage, ImageBuffer, ImageEncoder, ImageFormat, RgbaImage, imageops::FilterType,
};
use libavif::AvifData;
use napi::bindgen_prelude::*;
use napi_derive::napi;
use resvg::{
tiny_skia,
usvg::{self, fontdb::Database, Options},
usvg::{self, Options, fontdb::Database},
};
use crate::{
avif::{encode_avif_inner, AvifConfig},
fast_resize::{fast_resize, FastResizeOptions, ResizeFit},
avif::{AvifConfig, encode_avif_inner},
fast_resize::{FastResizeOptions, ResizeFit, fast_resize},
png::PngEncodeOptions,
};
@ -205,6 +205,7 @@ impl ThreadsafeDynamicImage {
}
}
#[allow(clippy::mut_from_ref)]
pub(crate) fn get(&self, with_exif: bool) -> Result<&mut ImageMetaData> {
let image = Box::leak(unsafe { Box::from_raw(self.image) });
let mut exif = HashMap::new();
@ -784,8 +785,8 @@ impl Transformer {
#[napi]
pub fn metadata_sync(&mut self, env: Env, with_exif: Option<bool>) -> Result<Metadata> {
let mut task = MetadataTask {
dynamic_image: self.dynamic_image.clone(),
with_exif: with_exif.unwrap_or(false),
dynamic_image: self.dynamic_image.clone(),
with_exif: with_exif.unwrap_or(false),
};
let output = task.compute()?;
task.resolve(env, output)

View File

@ -7,7 +7,7 @@ pub(crate) unsafe fn lossless_encode_webp_inner(
width: u32,
height: u32,
color_type: &image::ColorType,
) -> Result<(*mut u8, usize)> {
) -> Result<(*mut u8, usize)> { unsafe {
let mut out_buf = std::ptr::null_mut();
let len = match color_type {
ColorType::Rgb8 => {
@ -38,7 +38,7 @@ pub(crate) unsafe fn lossless_encode_webp_inner(
}
};
Ok((out_buf, len))
}
}}
#[inline]
pub(crate) unsafe fn encode_webp_inner(
@ -47,7 +47,7 @@ pub(crate) unsafe fn encode_webp_inner(
width: u32,
height: u32,
color_type: &image::ColorType,
) -> Result<(*mut u8, usize)> {
) -> Result<(*mut u8, usize)> { unsafe {
let mut out_buf = std::ptr::null_mut();
let len = match input {
DynamicImage::ImageRgb8(input) => {
@ -104,4 +104,4 @@ pub(crate) unsafe fn encode_webp_inner(
}
};
Ok((out_buf, len))
}
}}

View File

@ -1,7 +1,7 @@
import { execSync } from 'child_process'
import { join } from 'path'
import { promises as fs } from 'fs'
import { fileURLToPath } from 'url'
import { execSync } from 'node:child_process'
import { join } from 'node:path'
import { promises as fs } from 'node:fs'
import { fileURLToPath } from 'node:url'
import chalk from 'chalk'
import fetch from 'node-fetch'
@ -13,12 +13,13 @@ await fs.writeFile('public/img/example.mjs', await fs.readFile('../example.mjs')
await fs.writeFile('public/img/sharp.mjs', await fs.readFile('../sharp.mjs'))
if (process.env.VERCEL) {
const gnuBinary = await fetch(`https://unpkg.com/@napi-rs/image-linux-x64-gnu`, {
const arch = process.arch
const gnuBinary = await fetch(`https://unpkg.com/@napi-rs/image-linux-${arch}-gnu`, {
redirect: 'follow',
follow: 10,
}).then((res) => res.arrayBuffer())
console.info(chalk.greenBright(`Installed @napi-rs/image.linux-x64-gnu, size: ${gnuBinary.byteLength}`))
await fs.writeFile(join(__dirname, '../../../packages/binding/image.linux-x64-gnu.node'), Buffer.from(gnuBinary))
console.info(chalk.greenBright(`Installed @napi-rs/image.linux-${arch}-gnu, size: ${gnuBinary.byteLength}`))
await fs.writeFile(join(__dirname, `../../../packages/binding/image.linux-${arch}-gnu.node`), Buffer.from(gnuBinary))
}
execSync('node example.mjs', {

View File

@ -4,15 +4,15 @@
"version": "0.0.0",
"type": "module",
"dependencies": {
"@napi-rs/canvas": "^0.1.72",
"@napi-rs/image": "^1.9.2",
"@napi-rs/canvas": "^0.1.74",
"@napi-rs/image": "^1.11.0",
"chalk": "^5.4.1",
"next": "^15.3.4",
"next": "^15.4.3",
"nextra": "^3",
"nextra-theme-docs": "^3",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"sharp": "^0.34.2"
"sharp": "^0.34.3"
},
"scripts": {
"build": "node generate-img.js && node changelog.js && next build",

1685
yarn.lock

File diff suppressed because it is too large Load Diff