@svg-rs/svgo 0.0.4 → 0.0.5
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/README.md +56 -0
- package/README.zh.md +57 -0
- package/index.d.ts +1 -4
- package/index.js +346 -265
- package/package.json +40 -38
package/README.md
CHANGED
|
@@ -35,6 +35,62 @@ const optimizedSvg = optimize(inputSvg)
|
|
|
35
35
|
console.log(optimizedSvg)
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
## Plugins
|
|
39
|
+
|
|
40
|
+
- [] ddAttributesToSVGElement
|
|
41
|
+
- [] addClassesToSVGElement
|
|
42
|
+
- [] cleanupAttrs
|
|
43
|
+
- [] cleanupEnableBackground
|
|
44
|
+
- [] cleanupIds
|
|
45
|
+
- [] cleanupListOfValues
|
|
46
|
+
- [] cleanupNumericValues
|
|
47
|
+
- [] collapseGroups
|
|
48
|
+
- [] convertColors
|
|
49
|
+
- [] convertEllipseToCircle
|
|
50
|
+
- [] convertOneStopGradients
|
|
51
|
+
- [] convertPathData
|
|
52
|
+
- [] convertShapeToPath
|
|
53
|
+
- [] convertStyleToAttrs
|
|
54
|
+
- [] convertTransform
|
|
55
|
+
- [] inlineStyles
|
|
56
|
+
- [] mergePaths
|
|
57
|
+
- [] mergeStyles
|
|
58
|
+
- [] minifyStyles
|
|
59
|
+
- [x] moveElemsAttrsToGroup
|
|
60
|
+
- [] moveGroupAttrsToElems
|
|
61
|
+
- [] prefixIds
|
|
62
|
+
- [] removeAttributesBySelector
|
|
63
|
+
- [] removeAttrs
|
|
64
|
+
- [x] removeComments
|
|
65
|
+
- [] removeDeprecatedAttrs
|
|
66
|
+
- [x] removeDesc
|
|
67
|
+
- [] removeDimensions
|
|
68
|
+
- [x] removeDoctype
|
|
69
|
+
- [x] removeEditorsNSData
|
|
70
|
+
- [] removeElementsByAttr
|
|
71
|
+
- [] removeEmptyAttrs
|
|
72
|
+
- [] removeEmptyContainers
|
|
73
|
+
- [] removeEmptyText
|
|
74
|
+
- [] removeHiddenElems
|
|
75
|
+
- [x] removeMetadata
|
|
76
|
+
- [] removeNonInheritableGroupAttrs
|
|
77
|
+
- [] removeOffCanvasPaths
|
|
78
|
+
- [] removeRasterImages
|
|
79
|
+
- [] removeScripts
|
|
80
|
+
- [] removeStyleElement
|
|
81
|
+
- [x] removeTitle
|
|
82
|
+
- [] removeUnknownsAndDefaults
|
|
83
|
+
- [] removeUnusedNS
|
|
84
|
+
- [] removeUselessDefs
|
|
85
|
+
- [] removeUselessStrokeAndFill
|
|
86
|
+
- [] removeViewBox
|
|
87
|
+
- [] removeXMLNS
|
|
88
|
+
- [x] removeXMLProcInst
|
|
89
|
+
- [] removeXlink
|
|
90
|
+
- [] reusePaths
|
|
91
|
+
- [] sortAttrs
|
|
92
|
+
- [] sortDefsChildren
|
|
93
|
+
|
|
38
94
|
## Benchmarks
|
|
39
95
|
|
|
40
96
|
`svgo-rs` provides significant performance improvements over JavaScript-based SVG optimizers. Run the benchmarks in the `benchmark/` directory to compare:
|
package/README.zh.md
CHANGED
|
@@ -35,6 +35,63 @@ const optimizedSvg = optimize(inputSvg)
|
|
|
35
35
|
console.log(optimizedSvg)
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
|
|
39
|
+
## 插件
|
|
40
|
+
|
|
41
|
+
- [] ddAttributesToSVGElement
|
|
42
|
+
- [] addClassesToSVGElement
|
|
43
|
+
- [] cleanupAttrs
|
|
44
|
+
- [] cleanupEnableBackground
|
|
45
|
+
- [] cleanupIds
|
|
46
|
+
- [] cleanupListOfValues
|
|
47
|
+
- [] cleanupNumericValues
|
|
48
|
+
- [] collapseGroups
|
|
49
|
+
- [] convertColors
|
|
50
|
+
- [] convertEllipseToCircle
|
|
51
|
+
- [] convertOneStopGradients
|
|
52
|
+
- [] convertPathData
|
|
53
|
+
- [] convertShapeToPath
|
|
54
|
+
- [] convertStyleToAttrs
|
|
55
|
+
- [] convertTransform
|
|
56
|
+
- [] inlineStyles
|
|
57
|
+
- [] mergePaths
|
|
58
|
+
- [] mergeStyles
|
|
59
|
+
- [] minifyStyles
|
|
60
|
+
- [x] moveElemsAttrsToGroup
|
|
61
|
+
- [] moveGroupAttrsToElems
|
|
62
|
+
- [] prefixIds
|
|
63
|
+
- [] removeAttributesBySelector
|
|
64
|
+
- [] removeAttrs
|
|
65
|
+
- [x] removeComments
|
|
66
|
+
- [] removeDeprecatedAttrs
|
|
67
|
+
- [x] removeDesc
|
|
68
|
+
- [] removeDimensions
|
|
69
|
+
- [x] removeDoctype
|
|
70
|
+
- [x] removeEditorsNSData
|
|
71
|
+
- [] removeElementsByAttr
|
|
72
|
+
- [] removeEmptyAttrs
|
|
73
|
+
- [] removeEmptyContainers
|
|
74
|
+
- [] removeEmptyText
|
|
75
|
+
- [] removeHiddenElems
|
|
76
|
+
- [x] removeMetadata
|
|
77
|
+
- [] removeNonInheritableGroupAttrs
|
|
78
|
+
- [] removeOffCanvasPaths
|
|
79
|
+
- [] removeRasterImages
|
|
80
|
+
- [] removeScripts
|
|
81
|
+
- [] removeStyleElement
|
|
82
|
+
- [x] removeTitle
|
|
83
|
+
- [] removeUnknownsAndDefaults
|
|
84
|
+
- [] removeUnusedNS
|
|
85
|
+
- [] removeUselessDefs
|
|
86
|
+
- [] removeUselessStrokeAndFill
|
|
87
|
+
- [] removeViewBox
|
|
88
|
+
- [] removeXMLNS
|
|
89
|
+
- [x] removeXMLProcInst
|
|
90
|
+
- [] removeXlink
|
|
91
|
+
- [] reusePaths
|
|
92
|
+
- [] sortAttrs
|
|
93
|
+
- [] sortDefsChildren
|
|
94
|
+
|
|
38
95
|
## 基准测试
|
|
39
96
|
|
|
40
97
|
`svgo-rs` 相较于基于 JavaScript 的 SVG 优化器提供了显著的性能提升。可以在 `benchmark/` 目录中运行基准测试进行比较:
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,315 +1,396 @@
|
|
|
1
|
-
|
|
1
|
+
// prettier-ignore
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
// @ts-nocheck
|
|
5
4
|
/* auto-generated by NAPI-RS */
|
|
6
5
|
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const { platform, arch } = process
|
|
6
|
+
const { createRequire } = require('node:module')
|
|
7
|
+
require = createRequire(__filename)
|
|
11
8
|
|
|
9
|
+
const { readFileSync } = require('node:fs')
|
|
12
10
|
let nativeBinding = null
|
|
13
|
-
|
|
14
|
-
let loadError = null
|
|
11
|
+
const loadErrors = []
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
13
|
+
const isMusl = () => {
|
|
14
|
+
let musl = false
|
|
15
|
+
if (process.platform === 'linux') {
|
|
16
|
+
musl = isMuslFromFilesystem()
|
|
17
|
+
if (musl === null) {
|
|
18
|
+
musl = isMuslFromReport()
|
|
19
|
+
}
|
|
20
|
+
if (musl === null) {
|
|
21
|
+
musl = isMuslFromChildProcess()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return musl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
28
|
+
|
|
29
|
+
const isMuslFromFilesystem = () => {
|
|
30
|
+
try {
|
|
31
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
32
|
+
} catch {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isMuslFromReport = () => {
|
|
38
|
+
let report = null
|
|
39
|
+
if (typeof process.report?.getReport === 'function') {
|
|
40
|
+
process.report.excludeNetwork = true
|
|
41
|
+
report = process.report.getReport()
|
|
42
|
+
}
|
|
43
|
+
if (!report) {
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
50
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
23
51
|
return true
|
|
24
52
|
}
|
|
25
|
-
} else {
|
|
26
|
-
const { glibcVersionRuntime } = process.report.getReport().header
|
|
27
|
-
return !glibcVersionRuntime
|
|
28
53
|
}
|
|
54
|
+
return false
|
|
29
55
|
}
|
|
30
56
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
57
|
+
const isMuslFromChildProcess = () => {
|
|
58
|
+
try {
|
|
59
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function requireNative() {
|
|
67
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
68
|
+
try {
|
|
69
|
+
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
loadErrors.push(err)
|
|
72
|
+
}
|
|
73
|
+
} else if (process.platform === 'android') {
|
|
74
|
+
if (process.arch === 'arm64') {
|
|
75
|
+
try {
|
|
76
|
+
return require('./svgo-rs.android-arm64.node')
|
|
77
|
+
} catch (e) {
|
|
78
|
+
loadErrors.push(e)
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return require('@svg-rs/svgo-android-arm64')
|
|
82
|
+
} catch (e) {
|
|
83
|
+
loadErrors.push(e)
|
|
84
|
+
}
|
|
85
|
+
} else if (process.arch === 'arm') {
|
|
86
|
+
try {
|
|
87
|
+
return require('./svgo-rs.android-arm-eabi.node')
|
|
88
|
+
} catch (e) {
|
|
89
|
+
loadErrors.push(e)
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
return require('@svg-rs/svgo-android-arm-eabi')
|
|
93
|
+
} catch (e) {
|
|
94
|
+
loadErrors.push(e)
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
98
|
+
}
|
|
99
|
+
} else if (process.platform === 'win32') {
|
|
100
|
+
if (process.arch === 'x64') {
|
|
101
|
+
try {
|
|
102
|
+
return require('./svgo-rs.win32-x64-msvc.node')
|
|
103
|
+
} catch (e) {
|
|
104
|
+
loadErrors.push(e)
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
return require('@svg-rs/svgo-win32-x64-msvc')
|
|
108
|
+
} catch (e) {
|
|
109
|
+
loadErrors.push(e)
|
|
110
|
+
}
|
|
111
|
+
} else if (process.arch === 'ia32') {
|
|
112
|
+
try {
|
|
113
|
+
return require('./svgo-rs.win32-ia32-msvc.node')
|
|
114
|
+
} catch (e) {
|
|
115
|
+
loadErrors.push(e)
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return require('@svg-rs/svgo-win32-ia32-msvc')
|
|
119
|
+
} catch (e) {
|
|
120
|
+
loadErrors.push(e)
|
|
121
|
+
}
|
|
122
|
+
} else if (process.arch === 'arm64') {
|
|
123
|
+
try {
|
|
124
|
+
return require('./svgo-rs.win32-arm64-msvc.node')
|
|
125
|
+
} catch (e) {
|
|
126
|
+
loadErrors.push(e)
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
return require('@svg-rs/svgo-win32-arm64-msvc')
|
|
130
|
+
} catch (e) {
|
|
131
|
+
loadErrors.push(e)
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
135
|
+
}
|
|
136
|
+
} else if (process.platform === 'darwin') {
|
|
137
|
+
try {
|
|
138
|
+
return require('./svgo-rs.darwin-universal.node')
|
|
139
|
+
} catch (e) {
|
|
140
|
+
loadErrors.push(e)
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
return require('@svg-rs/svgo-darwin-universal')
|
|
144
|
+
} catch (e) {
|
|
145
|
+
loadErrors.push(e)
|
|
146
|
+
}
|
|
147
|
+
if (process.arch === 'x64') {
|
|
148
|
+
try {
|
|
149
|
+
return require('./svgo-rs.darwin-x64.node')
|
|
150
|
+
} catch (e) {
|
|
151
|
+
loadErrors.push(e)
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
return require('@svg-rs/svgo-darwin-x64')
|
|
155
|
+
} catch (e) {
|
|
156
|
+
loadErrors.push(e)
|
|
157
|
+
}
|
|
158
|
+
} else if (process.arch === 'arm64') {
|
|
159
|
+
try {
|
|
160
|
+
return require('./svgo-rs.darwin-arm64.node')
|
|
161
|
+
} catch (e) {
|
|
162
|
+
loadErrors.push(e)
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
return require('@svg-rs/svgo-darwin-arm64')
|
|
166
|
+
} catch (e) {
|
|
167
|
+
loadErrors.push(e)
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
171
|
+
}
|
|
172
|
+
} else if (process.platform === 'freebsd') {
|
|
173
|
+
if (process.arch === 'x64') {
|
|
174
|
+
try {
|
|
175
|
+
return require('./svgo-rs.freebsd-x64.node')
|
|
176
|
+
} catch (e) {
|
|
177
|
+
loadErrors.push(e)
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
return require('@svg-rs/svgo-freebsd-x64')
|
|
181
|
+
} catch (e) {
|
|
182
|
+
loadErrors.push(e)
|
|
183
|
+
}
|
|
184
|
+
} else if (process.arch === 'arm64') {
|
|
185
|
+
try {
|
|
186
|
+
return require('./svgo-rs.freebsd-arm64.node')
|
|
187
|
+
} catch (e) {
|
|
188
|
+
loadErrors.push(e)
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
return require('@svg-rs/svgo-freebsd-arm64')
|
|
192
|
+
} catch (e) {
|
|
193
|
+
loadErrors.push(e)
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
197
|
+
}
|
|
198
|
+
} else if (process.platform === 'linux') {
|
|
199
|
+
if (process.arch === 'x64') {
|
|
200
|
+
if (isMusl()) {
|
|
36
201
|
try {
|
|
37
|
-
|
|
38
|
-
nativeBinding = require('./svgo-rs.android-arm64.node')
|
|
39
|
-
} else {
|
|
40
|
-
nativeBinding = require('@svg-rs/svgo-android-arm64')
|
|
41
|
-
}
|
|
202
|
+
return require('./svgo-rs.linux-x64-musl.node')
|
|
42
203
|
} catch (e) {
|
|
43
|
-
|
|
204
|
+
loadErrors.push(e)
|
|
44
205
|
}
|
|
45
|
-
break
|
|
46
|
-
case 'arm':
|
|
47
|
-
localFileExisted = existsSync(join(__dirname, 'svgo-rs.android-arm-eabi.node'))
|
|
48
206
|
try {
|
|
49
|
-
|
|
50
|
-
nativeBinding = require('./svgo-rs.android-arm-eabi.node')
|
|
51
|
-
} else {
|
|
52
|
-
nativeBinding = require('@svg-rs/svgo-android-arm-eabi')
|
|
53
|
-
}
|
|
207
|
+
return require('@svg-rs/svgo-linux-x64-musl')
|
|
54
208
|
} catch (e) {
|
|
55
|
-
|
|
209
|
+
loadErrors.push(e)
|
|
56
210
|
}
|
|
57
|
-
|
|
58
|
-
default:
|
|
59
|
-
throw new Error(`Unsupported architecture on Android ${arch}`)
|
|
60
|
-
}
|
|
61
|
-
break
|
|
62
|
-
case 'win32':
|
|
63
|
-
switch (arch) {
|
|
64
|
-
case 'x64':
|
|
65
|
-
localFileExisted = existsSync(
|
|
66
|
-
join(__dirname, 'svgo-rs.win32-x64-msvc.node')
|
|
67
|
-
)
|
|
211
|
+
} else {
|
|
68
212
|
try {
|
|
69
|
-
|
|
70
|
-
nativeBinding = require('./svgo-rs.win32-x64-msvc.node')
|
|
71
|
-
} else {
|
|
72
|
-
nativeBinding = require('@svg-rs/svgo-win32-x64-msvc')
|
|
73
|
-
}
|
|
213
|
+
return require('./svgo-rs.linux-x64-gnu.node')
|
|
74
214
|
} catch (e) {
|
|
75
|
-
|
|
215
|
+
loadErrors.push(e)
|
|
76
216
|
}
|
|
77
|
-
break
|
|
78
|
-
case 'ia32':
|
|
79
|
-
localFileExisted = existsSync(
|
|
80
|
-
join(__dirname, 'svgo-rs.win32-ia32-msvc.node')
|
|
81
|
-
)
|
|
82
217
|
try {
|
|
83
|
-
|
|
84
|
-
nativeBinding = require('./svgo-rs.win32-ia32-msvc.node')
|
|
85
|
-
} else {
|
|
86
|
-
nativeBinding = require('@svg-rs/svgo-win32-ia32-msvc')
|
|
87
|
-
}
|
|
218
|
+
return require('@svg-rs/svgo-linux-x64-gnu')
|
|
88
219
|
} catch (e) {
|
|
89
|
-
|
|
220
|
+
loadErrors.push(e)
|
|
90
221
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
join(__dirname, 'svgo-rs.win32-arm64-msvc.node')
|
|
95
|
-
)
|
|
222
|
+
}
|
|
223
|
+
} else if (process.arch === 'arm64') {
|
|
224
|
+
if (isMusl()) {
|
|
96
225
|
try {
|
|
97
|
-
|
|
98
|
-
nativeBinding = require('./svgo-rs.win32-arm64-msvc.node')
|
|
99
|
-
} else {
|
|
100
|
-
nativeBinding = require('@svg-rs/svgo-win32-arm64-msvc')
|
|
101
|
-
}
|
|
226
|
+
return require('./svgo-rs.linux-arm64-musl.node')
|
|
102
227
|
} catch (e) {
|
|
103
|
-
|
|
228
|
+
loadErrors.push(e)
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
return require('@svg-rs/svgo-linux-arm64-musl')
|
|
232
|
+
} catch (e) {
|
|
233
|
+
loadErrors.push(e)
|
|
104
234
|
}
|
|
105
|
-
break
|
|
106
|
-
default:
|
|
107
|
-
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
|
108
|
-
}
|
|
109
|
-
break
|
|
110
|
-
case 'darwin':
|
|
111
|
-
localFileExisted = existsSync(join(__dirname, 'svgo-rs.darwin-universal.node'))
|
|
112
|
-
try {
|
|
113
|
-
if (localFileExisted) {
|
|
114
|
-
nativeBinding = require('./svgo-rs.darwin-universal.node')
|
|
115
235
|
} else {
|
|
116
|
-
|
|
236
|
+
try {
|
|
237
|
+
return require('./svgo-rs.linux-arm64-gnu.node')
|
|
238
|
+
} catch (e) {
|
|
239
|
+
loadErrors.push(e)
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
return require('@svg-rs/svgo-linux-arm64-gnu')
|
|
243
|
+
} catch (e) {
|
|
244
|
+
loadErrors.push(e)
|
|
245
|
+
}
|
|
117
246
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
switch (arch) {
|
|
121
|
-
case 'x64':
|
|
122
|
-
localFileExisted = existsSync(join(__dirname, 'svgo-rs.darwin-x64.node'))
|
|
247
|
+
} else if (process.arch === 'arm') {
|
|
248
|
+
if (isMusl()) {
|
|
123
249
|
try {
|
|
124
|
-
|
|
125
|
-
nativeBinding = require('./svgo-rs.darwin-x64.node')
|
|
126
|
-
} else {
|
|
127
|
-
nativeBinding = require('@svg-rs/svgo-darwin-x64')
|
|
128
|
-
}
|
|
250
|
+
return require('./svgo-rs.linux-arm-musleabihf.node')
|
|
129
251
|
} catch (e) {
|
|
130
|
-
|
|
252
|
+
loadErrors.push(e)
|
|
131
253
|
}
|
|
132
|
-
break
|
|
133
|
-
case 'arm64':
|
|
134
|
-
localFileExisted = existsSync(
|
|
135
|
-
join(__dirname, 'svgo-rs.darwin-arm64.node')
|
|
136
|
-
)
|
|
137
254
|
try {
|
|
138
|
-
|
|
139
|
-
nativeBinding = require('./svgo-rs.darwin-arm64.node')
|
|
140
|
-
} else {
|
|
141
|
-
nativeBinding = require('@svg-rs/svgo-darwin-arm64')
|
|
142
|
-
}
|
|
255
|
+
return require('@svg-rs/svgo-linux-arm-musleabihf')
|
|
143
256
|
} catch (e) {
|
|
144
|
-
|
|
257
|
+
loadErrors.push(e)
|
|
145
258
|
}
|
|
146
|
-
break
|
|
147
|
-
default:
|
|
148
|
-
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
|
149
|
-
}
|
|
150
|
-
break
|
|
151
|
-
case 'freebsd':
|
|
152
|
-
if (arch !== 'x64') {
|
|
153
|
-
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
|
154
|
-
}
|
|
155
|
-
localFileExisted = existsSync(join(__dirname, 'svgo-rs.freebsd-x64.node'))
|
|
156
|
-
try {
|
|
157
|
-
if (localFileExisted) {
|
|
158
|
-
nativeBinding = require('./svgo-rs.freebsd-x64.node')
|
|
159
259
|
} else {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
break
|
|
166
|
-
case 'linux':
|
|
167
|
-
switch (arch) {
|
|
168
|
-
case 'x64':
|
|
169
|
-
if (isMusl()) {
|
|
170
|
-
localFileExisted = existsSync(
|
|
171
|
-
join(__dirname, 'svgo-rs.linux-x64-musl.node')
|
|
172
|
-
)
|
|
173
|
-
try {
|
|
174
|
-
if (localFileExisted) {
|
|
175
|
-
nativeBinding = require('./svgo-rs.linux-x64-musl.node')
|
|
176
|
-
} else {
|
|
177
|
-
nativeBinding = require('@svg-rs/svgo-linux-x64-musl')
|
|
178
|
-
}
|
|
179
|
-
} catch (e) {
|
|
180
|
-
loadError = e
|
|
181
|
-
}
|
|
182
|
-
} else {
|
|
183
|
-
localFileExisted = existsSync(
|
|
184
|
-
join(__dirname, 'svgo-rs.linux-x64-gnu.node')
|
|
185
|
-
)
|
|
186
|
-
try {
|
|
187
|
-
if (localFileExisted) {
|
|
188
|
-
nativeBinding = require('./svgo-rs.linux-x64-gnu.node')
|
|
189
|
-
} else {
|
|
190
|
-
nativeBinding = require('@svg-rs/svgo-linux-x64-gnu')
|
|
191
|
-
}
|
|
192
|
-
} catch (e) {
|
|
193
|
-
loadError = e
|
|
194
|
-
}
|
|
260
|
+
try {
|
|
261
|
+
return require('./svgo-rs.linux-arm-gnueabihf.node')
|
|
262
|
+
} catch (e) {
|
|
263
|
+
loadErrors.push(e)
|
|
195
264
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
join(__dirname, 'svgo-rs.linux-arm64-musl.node')
|
|
201
|
-
)
|
|
202
|
-
try {
|
|
203
|
-
if (localFileExisted) {
|
|
204
|
-
nativeBinding = require('./svgo-rs.linux-arm64-musl.node')
|
|
205
|
-
} else {
|
|
206
|
-
nativeBinding = require('@svg-rs/svgo-linux-arm64-musl')
|
|
207
|
-
}
|
|
208
|
-
} catch (e) {
|
|
209
|
-
loadError = e
|
|
210
|
-
}
|
|
211
|
-
} else {
|
|
212
|
-
localFileExisted = existsSync(
|
|
213
|
-
join(__dirname, 'svgo-rs.linux-arm64-gnu.node')
|
|
214
|
-
)
|
|
215
|
-
try {
|
|
216
|
-
if (localFileExisted) {
|
|
217
|
-
nativeBinding = require('./svgo-rs.linux-arm64-gnu.node')
|
|
218
|
-
} else {
|
|
219
|
-
nativeBinding = require('@svg-rs/svgo-linux-arm64-gnu')
|
|
220
|
-
}
|
|
221
|
-
} catch (e) {
|
|
222
|
-
loadError = e
|
|
223
|
-
}
|
|
265
|
+
try {
|
|
266
|
+
return require('@svg-rs/svgo-linux-arm-gnueabihf')
|
|
267
|
+
} catch (e) {
|
|
268
|
+
loadErrors.push(e)
|
|
224
269
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (localFileExisted) {
|
|
233
|
-
nativeBinding = require('./svgo-rs.linux-arm-musleabihf.node')
|
|
234
|
-
} else {
|
|
235
|
-
nativeBinding = require('@svg-rs/svgo-linux-arm-musleabihf')
|
|
236
|
-
}
|
|
237
|
-
} catch (e) {
|
|
238
|
-
loadError = e
|
|
239
|
-
}
|
|
240
|
-
} else {
|
|
241
|
-
localFileExisted = existsSync(
|
|
242
|
-
join(__dirname, 'svgo-rs.linux-arm-gnueabihf.node')
|
|
243
|
-
)
|
|
244
|
-
try {
|
|
245
|
-
if (localFileExisted) {
|
|
246
|
-
nativeBinding = require('./svgo-rs.linux-arm-gnueabihf.node')
|
|
247
|
-
} else {
|
|
248
|
-
nativeBinding = require('@svg-rs/svgo-linux-arm-gnueabihf')
|
|
249
|
-
}
|
|
250
|
-
} catch (e) {
|
|
251
|
-
loadError = e
|
|
252
|
-
}
|
|
270
|
+
}
|
|
271
|
+
} else if (process.arch === 'riscv64') {
|
|
272
|
+
if (isMusl()) {
|
|
273
|
+
try {
|
|
274
|
+
return require('./svgo-rs.linux-riscv64-musl.node')
|
|
275
|
+
} catch (e) {
|
|
276
|
+
loadErrors.push(e)
|
|
253
277
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
join(__dirname, 'svgo-rs.linux-riscv64-musl.node')
|
|
259
|
-
)
|
|
260
|
-
try {
|
|
261
|
-
if (localFileExisted) {
|
|
262
|
-
nativeBinding = require('./svgo-rs.linux-riscv64-musl.node')
|
|
263
|
-
} else {
|
|
264
|
-
nativeBinding = require('@svg-rs/svgo-linux-riscv64-musl')
|
|
265
|
-
}
|
|
266
|
-
} catch (e) {
|
|
267
|
-
loadError = e
|
|
268
|
-
}
|
|
269
|
-
} else {
|
|
270
|
-
localFileExisted = existsSync(
|
|
271
|
-
join(__dirname, 'svgo-rs.linux-riscv64-gnu.node')
|
|
272
|
-
)
|
|
273
|
-
try {
|
|
274
|
-
if (localFileExisted) {
|
|
275
|
-
nativeBinding = require('./svgo-rs.linux-riscv64-gnu.node')
|
|
276
|
-
} else {
|
|
277
|
-
nativeBinding = require('@svg-rs/svgo-linux-riscv64-gnu')
|
|
278
|
-
}
|
|
279
|
-
} catch (e) {
|
|
280
|
-
loadError = e
|
|
281
|
-
}
|
|
278
|
+
try {
|
|
279
|
+
return require('@svg-rs/svgo-linux-riscv64-musl')
|
|
280
|
+
} catch (e) {
|
|
281
|
+
loadErrors.push(e)
|
|
282
282
|
}
|
|
283
|
-
|
|
284
|
-
case 's390x':
|
|
285
|
-
localFileExisted = existsSync(
|
|
286
|
-
join(__dirname, 'svgo-rs.linux-s390x-gnu.node')
|
|
287
|
-
)
|
|
283
|
+
} else {
|
|
288
284
|
try {
|
|
289
|
-
|
|
290
|
-
nativeBinding = require('./svgo-rs.linux-s390x-gnu.node')
|
|
291
|
-
} else {
|
|
292
|
-
nativeBinding = require('@svg-rs/svgo-linux-s390x-gnu')
|
|
293
|
-
}
|
|
285
|
+
return require('./svgo-rs.linux-riscv64-gnu.node')
|
|
294
286
|
} catch (e) {
|
|
295
|
-
|
|
287
|
+
loadErrors.push(e)
|
|
296
288
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
289
|
+
try {
|
|
290
|
+
return require('@svg-rs/svgo-linux-riscv64-gnu')
|
|
291
|
+
} catch (e) {
|
|
292
|
+
loadErrors.push(e)
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
} else if (process.arch === 'ppc64') {
|
|
296
|
+
try {
|
|
297
|
+
return require('./svgo-rs.linux-ppc64-gnu.node')
|
|
298
|
+
} catch (e) {
|
|
299
|
+
loadErrors.push(e)
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
return require('@svg-rs/svgo-linux-ppc64-gnu')
|
|
303
|
+
} catch (e) {
|
|
304
|
+
loadErrors.push(e)
|
|
305
|
+
}
|
|
306
|
+
} else if (process.arch === 's390x') {
|
|
307
|
+
try {
|
|
308
|
+
return require('./svgo-rs.linux-s390x-gnu.node')
|
|
309
|
+
} catch (e) {
|
|
310
|
+
loadErrors.push(e)
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
return require('@svg-rs/svgo-linux-s390x-gnu')
|
|
314
|
+
} catch (e) {
|
|
315
|
+
loadErrors.push(e)
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
319
|
+
}
|
|
320
|
+
} else if (process.platform === 'openharmony') {
|
|
321
|
+
if (process.arch === 'arm64') {
|
|
322
|
+
try {
|
|
323
|
+
return require('./svgo-rs.linux-arm64-ohos.node')
|
|
324
|
+
} catch (e) {
|
|
325
|
+
loadErrors.push(e)
|
|
326
|
+
}
|
|
327
|
+
try {
|
|
328
|
+
return require('@svg-rs/svgo-linux-arm64-ohos')
|
|
329
|
+
} catch (e) {
|
|
330
|
+
loadErrors.push(e)
|
|
331
|
+
}
|
|
332
|
+
} else if (process.arch === 'x64') {
|
|
333
|
+
try {
|
|
334
|
+
return require('./svgo-rs.linux-x64-ohos.node')
|
|
335
|
+
} catch (e) {
|
|
336
|
+
loadErrors.push(e)
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
return require('@svg-rs/svgo-linux-x64-ohos')
|
|
340
|
+
} catch (e) {
|
|
341
|
+
loadErrors.push(e)
|
|
342
|
+
}
|
|
343
|
+
} else if (process.arch === 'arm') {
|
|
344
|
+
try {
|
|
345
|
+
return require('./svgo-rs.linux-arm-ohos.node')
|
|
346
|
+
} catch (e) {
|
|
347
|
+
loadErrors.push(e)
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
return require('@svg-rs/svgo-linux-arm-ohos')
|
|
351
|
+
} catch (e) {
|
|
352
|
+
loadErrors.push(e)
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
300
356
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
357
|
+
} else {
|
|
358
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
nativeBinding = requireNative()
|
|
363
|
+
|
|
364
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
365
|
+
try {
|
|
366
|
+
nativeBinding = require('./svgo-rs.wasi.cjs')
|
|
367
|
+
} catch (err) {
|
|
368
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
369
|
+
loadErrors.push(err)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (!nativeBinding) {
|
|
373
|
+
try {
|
|
374
|
+
nativeBinding = require('@svg-rs/svgo-wasm32-wasi')
|
|
375
|
+
} catch (err) {
|
|
376
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
377
|
+
loadErrors.push(err)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
304
381
|
}
|
|
305
382
|
|
|
306
383
|
if (!nativeBinding) {
|
|
307
|
-
if (
|
|
308
|
-
throw
|
|
384
|
+
if (loadErrors.length > 0) {
|
|
385
|
+
throw new Error(
|
|
386
|
+
`Cannot find native binding. ` +
|
|
387
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
388
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
389
|
+
{ cause: loadErrors }
|
|
390
|
+
)
|
|
309
391
|
}
|
|
310
392
|
throw new Error(`Failed to load native binding`)
|
|
311
393
|
}
|
|
312
394
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
module.exports.optimize = optimize
|
|
395
|
+
module.exports = nativeBinding
|
|
396
|
+
module.exports.optimize = nativeBinding.optimize
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svg-rs/svgo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Node.js tool for optimizing SVG files by Rust.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "https://github.com/oxidized-world/svgo-rs",
|
|
@@ -17,22 +17,23 @@
|
|
|
17
17
|
"index.js"
|
|
18
18
|
],
|
|
19
19
|
"napi": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
"binaryName": "svgo-rs",
|
|
21
|
+
"targets": [
|
|
22
|
+
"x86_64-pc-windows-msvc",
|
|
23
|
+
"x86_64-apple-darwin",
|
|
24
|
+
"x86_64-unknown-linux-gnu",
|
|
25
|
+
"x86_64-unknown-linux-musl",
|
|
26
|
+
"aarch64-unknown-linux-gnu",
|
|
27
|
+
"i686-pc-windows-msvc",
|
|
28
|
+
"armv7-unknown-linux-gnueabihf",
|
|
29
|
+
"aarch64-apple-darwin",
|
|
30
|
+
"aarch64-linux-android",
|
|
31
|
+
"x86_64-unknown-freebsd",
|
|
32
|
+
"aarch64-unknown-linux-musl",
|
|
33
|
+
"aarch64-pc-windows-msvc",
|
|
34
|
+
"armv7-linux-androideabi",
|
|
35
|
+
"wasm32-wasip1-threads"
|
|
36
|
+
]
|
|
36
37
|
},
|
|
37
38
|
"engines": {
|
|
38
39
|
"node": ">= 10"
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
},
|
|
44
45
|
"scripts": {
|
|
45
46
|
"artifacts": "napi artifacts",
|
|
46
|
-
"bench": "node --import @
|
|
47
|
+
"bench": "node --import @oxc-node/core/register benchmark/bench.ts",
|
|
47
48
|
"build": "napi build --platform --release",
|
|
48
49
|
"build:debug": "napi build --platform",
|
|
49
50
|
"format": "format:rs && format:toml",
|
|
@@ -54,23 +55,23 @@
|
|
|
54
55
|
"test": "vitest run",
|
|
55
56
|
"test:watch": "vitest",
|
|
56
57
|
"version": "napi version",
|
|
57
|
-
"
|
|
58
|
+
"prepare": "husky"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
61
|
"@biomejs/biome": "^1.9.4",
|
|
61
|
-
"@napi-rs/cli": "^
|
|
62
|
-
"@
|
|
63
|
-
"@swc/core": "^1.11.21",
|
|
62
|
+
"@napi-rs/cli": "^3.0.0",
|
|
63
|
+
"@oxc-node/core": "^0.0.29",
|
|
64
64
|
"@taplo/cli": "^0.7.0",
|
|
65
|
+
"@tybys/wasm-util": "^0.10.0",
|
|
65
66
|
"husky": "^9.1.7",
|
|
66
67
|
"lint-staged": "^15.5.1",
|
|
67
68
|
"svgo": "^3.3.2",
|
|
68
69
|
"tinybench": "^4.0.1",
|
|
69
70
|
"typescript": "^5.8.3",
|
|
70
|
-
"vitest": "^3.
|
|
71
|
+
"vitest": "^3.2.4"
|
|
71
72
|
},
|
|
72
73
|
"lint-staged": {
|
|
73
|
-
"*.@(js|ts|tsx|yml|yaml|
|
|
74
|
+
"*.@(js|ts|tsx|yml|yaml|json)": [
|
|
74
75
|
"biome lint --write"
|
|
75
76
|
],
|
|
76
77
|
"*.toml": [
|
|
@@ -80,20 +81,21 @@
|
|
|
80
81
|
"cargo fmt --"
|
|
81
82
|
]
|
|
82
83
|
},
|
|
83
|
-
"packageManager": "yarn@4.9.
|
|
84
|
+
"packageManager": "yarn@4.9.2",
|
|
84
85
|
"optionalDependencies": {
|
|
85
|
-
"@svg-rs/svgo-win32-x64-msvc": "0.0.
|
|
86
|
-
"@svg-rs/svgo-darwin-x64": "0.0.
|
|
87
|
-
"@svg-rs/svgo-linux-x64-gnu": "0.0.
|
|
88
|
-
"@svg-rs/svgo-linux-x64-musl": "0.0.
|
|
89
|
-
"@svg-rs/svgo-linux-arm64-gnu": "0.0.
|
|
90
|
-
"@svg-rs/svgo-win32-ia32-msvc": "0.0.
|
|
91
|
-
"@svg-rs/svgo-linux-arm-gnueabihf": "0.0.
|
|
92
|
-
"@svg-rs/svgo-darwin-arm64": "0.0.
|
|
93
|
-
"@svg-rs/svgo-android-arm64": "0.0.
|
|
94
|
-
"@svg-rs/svgo-freebsd-x64": "0.0.
|
|
95
|
-
"@svg-rs/svgo-linux-arm64-musl": "0.0.
|
|
96
|
-
"@svg-rs/svgo-win32-arm64-msvc": "0.0.
|
|
97
|
-
"@svg-rs/svgo-android-arm-eabi": "0.0.
|
|
86
|
+
"@svg-rs/svgo-win32-x64-msvc": "0.0.5",
|
|
87
|
+
"@svg-rs/svgo-darwin-x64": "0.0.5",
|
|
88
|
+
"@svg-rs/svgo-linux-x64-gnu": "0.0.5",
|
|
89
|
+
"@svg-rs/svgo-linux-x64-musl": "0.0.5",
|
|
90
|
+
"@svg-rs/svgo-linux-arm64-gnu": "0.0.5",
|
|
91
|
+
"@svg-rs/svgo-win32-ia32-msvc": "0.0.5",
|
|
92
|
+
"@svg-rs/svgo-linux-arm-gnueabihf": "0.0.5",
|
|
93
|
+
"@svg-rs/svgo-darwin-arm64": "0.0.5",
|
|
94
|
+
"@svg-rs/svgo-android-arm64": "0.0.5",
|
|
95
|
+
"@svg-rs/svgo-freebsd-x64": "0.0.5",
|
|
96
|
+
"@svg-rs/svgo-linux-arm64-musl": "0.0.5",
|
|
97
|
+
"@svg-rs/svgo-win32-arm64-msvc": "0.0.5",
|
|
98
|
+
"@svg-rs/svgo-android-arm-eabi": "0.0.5",
|
|
99
|
+
"@svg-rs/svgo-wasm32-wasi": "0.0.5"
|
|
98
100
|
}
|
|
99
101
|
}
|