Skip to content

Commit

Permalink
fix: update napi-rs(2.10.13) to resolve Electron 21+ create Buffer is…
Browse files Browse the repository at this point in the history
…sues
  • Loading branch information
yisibl committed Jan 30, 2023
1 parent d7a5d41 commit 55a9170
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ resvg = { version = "0.25.0", default-features = false, features = [
] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
napi = { version = "2.10.0", features = ["serde-json", "async"] }
napi-derive = "2.9.1"
napi = { version = "2.10.13", features = ["serde-json", "async"] }
napi-derive = "2.10.0"
resvg = { version = "0.25.0", default-features = false, features = [
"filter",
"dump-svg",
Expand Down
6 changes: 3 additions & 3 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { Resvg, renderAsync } from '../index'
import { jimpToRgbaPixels } from './helper'

test('Use href to load a JPG image without alpha', async (t) => {
const imgUrl = 'http://tva2.sinaimg.cn/crop.0.0.250.250.80/534b48acjw8ehw72edguyj206y06yq32.jpg'
const imgUrl = 'https://himg.bdimg.com/sys/portrait/hotitem/wildkid/46'
const svg = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image href="${imgUrl}" width="80" height="80"/>
<image href="${imgUrl}" width="300" height="300"/>
</svg>`
const resvg = new Resvg(svg, {
font: {
Expand Down Expand Up @@ -510,7 +510,7 @@ test('should throw (no input parameters)', (t) => {
)

t.is(error.code, 'InvalidArg')
t.is(error.message, 'Value is not either String or Vec<u8>')
t.is(error.message, 'Value is non of these types `String`, `Vec<u8>`, ')
})

test('should throw (SVG string is empty)', (t) => {
Expand Down
4 changes: 2 additions & 2 deletions __test__/wasm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ test.before(async () => {
})

test('Use href to load a JPG image without alpha', async (t) => {
const imgUrl = 'http://tva2.sinaimg.cn/crop.0.0.250.250.80/534b48acjw8ehw72edguyj206y06yq32.jpg'
const imgUrl = 'https://himg.bdimg.com/sys/portrait/hotitem/wildkid/46'
const svg = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image href="${imgUrl}" width="80" height="80"/>
<image href="${imgUrl}" width="300" height="300"/>
</svg>`
const resvg = new Resvg(svg)
const resolved = await Promise.all(
Expand Down
12 changes: 11 additions & 1 deletion js-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== 'function') {
try {
return readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
const lddPath = require('child_process').execSync('which ldd').toString().trim();
return readFileSync(lddPath, 'utf8').includes('musl')
} catch (e) {
return true
}
Expand Down Expand Up @@ -101,6 +102,15 @@ switch (platform) {
}
break
case 'darwin':
localFileExisted = existsSync(join(__dirname, 'resvgjs.darwin-universal.node'))
try {
if (localFileExisted) {
nativeBinding = require('./resvgjs.darwin-universal.node')
} else {
nativeBinding = require('@resvg/resvg-js-darwin-universal')
}
break
} catch {}
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'resvgjs.darwin-x64.node'))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"devDependencies": {
"@napi-rs/canvas": "^0.1.25",
"@napi-rs/cli": "^2.13.2",
"@napi-rs/cli": "^2.14.5",
"@swc-node/register": "^1.5.1",
"@types/node": "^18.0.0",
"@types/sharp": "^0.31.0",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,12 @@ __metadata:
languageName: node
linkType: hard

"@napi-rs/cli@npm:^2.13.2":
version: 2.13.2
resolution: "@napi-rs/cli@npm:2.13.2"
"@napi-rs/cli@npm:^2.14.5":
version: 2.14.5
resolution: "@napi-rs/cli@npm:2.14.5"
bin:
napi: scripts/index.js
checksum: cf9b4d48031ff2981ceaac92afe3b17bc9e2af4e97ae414d469638280cb377f43bf60bd45ce974a756fc7ae7b33ba82c9fc26d0057cce5a028b3537a06824a58
checksum: 2b6b16f90fbf49d0200792fb5a9c41da5e287eb666759182fb9c80e4ce05abe4a40002d129096ec2c47a53b5969619bdf9092b424f18bd605dcda2ebaff98eee
languageName: node
linkType: hard

Expand Down Expand Up @@ -405,7 +405,7 @@ __metadata:
resolution: "@resvg/resvg-js@workspace:."
dependencies:
"@napi-rs/canvas": ^0.1.25
"@napi-rs/cli": ^2.13.2
"@napi-rs/cli": ^2.14.5
"@swc-node/register": ^1.5.1
"@types/node": ^18.0.0
"@types/sharp": ^0.31.0
Expand Down

1 comment on commit 55a9170

@vercel
Copy link

@vercel vercel bot commented on 55a9170 Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

resvg-js – ./

resvg-js.vercel.app
resvg-js-yisibl.vercel.app
resvg-js-git-main-yisibl.vercel.app

Please sign in to comment.