Skip to content

Commit 55a9170

Browse files
committed
fix: update napi-rs(2.10.13) to resolve Electron 21+ create Buffer issues
1 parent d7a5d41 commit 55a9170

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ resvg = { version = "0.25.0", default-features = false, features = [
3636
] }
3737

3838
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
39-
napi = { version = "2.10.0", features = ["serde-json", "async"] }
40-
napi-derive = "2.9.1"
39+
napi = { version = "2.10.13", features = ["serde-json", "async"] }
40+
napi-derive = "2.10.0"
4141
resvg = { version = "0.25.0", default-features = false, features = [
4242
"filter",
4343
"dump-svg",

__test__/index.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { Resvg, renderAsync } from '../index'
1010
import { jimpToRgbaPixels } from './helper'
1111

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

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

516516
test('should throw (SVG string is empty)', (t) => {

__test__/wasm.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ test.before(async () => {
1616
})
1717

1818
test('Use href to load a JPG image without alpha', async (t) => {
19-
const imgUrl = 'http://tva2.sinaimg.cn/crop.0.0.250.250.80/534b48acjw8ehw72edguyj206y06yq32.jpg'
19+
const imgUrl = 'https://himg.bdimg.com/sys/portrait/hotitem/wildkid/46'
2020
const svg = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
21-
<image href="${imgUrl}" width="80" height="80"/>
21+
<image href="${imgUrl}" width="300" height="300"/>
2222
</svg>`
2323
const resvg = new Resvg(svg)
2424
const resolved = await Promise.all(

js-binding.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ function isMusl() {
1111
// For Node 10
1212
if (!process.report || typeof process.report.getReport !== 'function') {
1313
try {
14-
return readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
14+
const lddPath = require('child_process').execSync('which ldd').toString().trim();
15+
return readFileSync(lddPath, 'utf8').includes('musl')
1516
} catch (e) {
1617
return true
1718
}
@@ -101,6 +102,15 @@ switch (platform) {
101102
}
102103
break
103104
case 'darwin':
105+
localFileExisted = existsSync(join(__dirname, 'resvgjs.darwin-universal.node'))
106+
try {
107+
if (localFileExisted) {
108+
nativeBinding = require('./resvgjs.darwin-universal.node')
109+
} else {
110+
nativeBinding = require('@resvg/resvg-js-darwin-universal')
111+
}
112+
break
113+
} catch {}
104114
switch (arch) {
105115
case 'x64':
106116
localFileExisted = existsSync(join(__dirname, 'resvgjs.darwin-x64.node'))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
},
7575
"devDependencies": {
7676
"@napi-rs/canvas": "^0.1.25",
77-
"@napi-rs/cli": "^2.13.2",
77+
"@napi-rs/cli": "^2.14.5",
7878
"@swc-node/register": "^1.5.1",
7979
"@types/node": "^18.0.0",
8080
"@types/sharp": "^0.31.0",

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,12 @@ __metadata:
344344
languageName: node
345345
linkType: hard
346346

347-
"@napi-rs/cli@npm:^2.13.2":
348-
version: 2.13.2
349-
resolution: "@napi-rs/cli@npm:2.13.2"
347+
"@napi-rs/cli@npm:^2.14.5":
348+
version: 2.14.5
349+
resolution: "@napi-rs/cli@npm:2.14.5"
350350
bin:
351351
napi: scripts/index.js
352-
checksum: cf9b4d48031ff2981ceaac92afe3b17bc9e2af4e97ae414d469638280cb377f43bf60bd45ce974a756fc7ae7b33ba82c9fc26d0057cce5a028b3537a06824a58
352+
checksum: 2b6b16f90fbf49d0200792fb5a9c41da5e287eb666759182fb9c80e4ce05abe4a40002d129096ec2c47a53b5969619bdf9092b424f18bd605dcda2ebaff98eee
353353
languageName: node
354354
linkType: hard
355355

@@ -405,7 +405,7 @@ __metadata:
405405
resolution: "@resvg/resvg-js@workspace:."
406406
dependencies:
407407
"@napi-rs/canvas": ^0.1.25
408-
"@napi-rs/cli": ^2.13.2
408+
"@napi-rs/cli": ^2.14.5
409409
"@swc-node/register": ^1.5.1
410410
"@types/node": ^18.0.0
411411
"@types/sharp": ^0.31.0

0 commit comments

Comments
 (0)