@svg-rs/svgo 0.0.3

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.
Files changed (5) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +105 -0
  3. package/index.d.ts +16 -0
  4. package/index.js +289 -0
  5. package/package.json +114 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 N-API for Rust
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # `@napi-rs/package-template`
2
+
3
+ ![https://github.com/napi-rs/package-template/actions](https://github.com/napi-rs/package-template/workflows/CI/badge.svg)
4
+
5
+ > Template project for writing node packages with napi-rs.
6
+
7
+ # Usage
8
+
9
+ 1. Click **Use this template**.
10
+ 2. **Clone** your project.
11
+ 3. Run `yarn install` to install dependencies.
12
+ 4. Run `npx napi rename -n [name]` command under the project folder to rename your package.
13
+
14
+ ## Install this test package
15
+
16
+ ```
17
+ yarn add @napi-rs/package-template
18
+ ```
19
+
20
+ ## Support matrix
21
+
22
+ ### Operating Systems
23
+
24
+ | | node14 | node16 | node18 |
25
+ | ---------------- | ------ | ------ | ------ |
26
+ | Windows x64 | ✓ | ✓ | ✓ |
27
+ | Windows x32 | ✓ | ✓ | ✓ |
28
+ | Windows arm64 | ✓ | ✓ | ✓ |
29
+ | macOS x64 | ✓ | ✓ | ✓ |
30
+ | macOS arm64 | ✓ | ✓ | ✓ |
31
+ | Linux x64 gnu | ✓ | ✓ | ✓ |
32
+ | Linux x64 musl | ✓ | ✓ | ✓ |
33
+ | Linux arm gnu | ✓ | ✓ | ✓ |
34
+ | Linux arm64 gnu | ✓ | ✓ | ✓ |
35
+ | Linux arm64 musl | ✓ | ✓ | ✓ |
36
+ | Android arm64 | ✓ | ✓ | ✓ |
37
+ | Android armv7 | ✓ | ✓ | ✓ |
38
+ | FreeBSD x64 | ✓ | ✓ | ✓ |
39
+
40
+ ## Ability
41
+
42
+ ### Build
43
+
44
+ After `yarn build/npm run build` command, you can see `package-template.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs).
45
+
46
+ ### Test
47
+
48
+ With [ava](https://github.com/avajs/ava), run `yarn test/npm run test` to testing native addon. You can also switch to another testing framework if you want.
49
+
50
+ ### CI
51
+
52
+ With GitHub Actions, each commit and pull request will be built and tested automatically in [`node@14`, `node@16`, `@node18`] x [`macOS`, `Linux`, `Windows`] matrix. You will never be afraid of the native addon broken in these platforms.
53
+
54
+ ### Release
55
+
56
+ Release native package is very difficult in old days. Native packages may ask developers who use it to install `build toolchain` like `gcc/llvm`, `node-gyp` or something more.
57
+
58
+ With `GitHub actions`, we can easily prebuild a `binary` for major platforms. And with `N-API`, we should never be afraid of **ABI Compatible**.
59
+
60
+ The other problem is how to deliver prebuild `binary` to users. Downloading it in `postinstall` script is a common way that most packages do it right now. The problem with this solution is it introduced many other packages to download binary that has not been used by `runtime codes`. The other problem is some users may not easily download the binary from `GitHub/CDN` if they are behind a private network (But in most cases, they have a private NPM mirror).
61
+
62
+ In this package, we choose a better way to solve this problem. We release different `npm packages` for different platforms. And add it to `optionalDependencies` before releasing the `Major` package to npm.
63
+
64
+ `NPM` will choose which native package should download from `registry` automatically. You can see [npm](./npm) dir for details. And you can also run `yarn add @napi-rs/package-template` to see how it works.
65
+
66
+ ## Develop requirements
67
+
68
+ - Install the latest `Rust`
69
+ - Install `Node.js@10+` which fully supported `Node-API`
70
+ - Install `yarn@1.x`
71
+
72
+ ## Test in local
73
+
74
+ - yarn
75
+ - yarn build
76
+ - yarn test
77
+
78
+ And you will see:
79
+
80
+ ```bash
81
+ $ ava --verbose
82
+
83
+ ✔ sync function from native code
84
+ ✔ sleep function from native code (201ms)
85
+
86
+
87
+ 2 tests passed
88
+ ✨ Done in 1.12s.
89
+ ```
90
+
91
+ ## Release package
92
+
93
+ Ensure you have set your **NPM_TOKEN** in the `GitHub` project setting.
94
+
95
+ In `Settings -> Secrets`, add **NPM_TOKEN** into it.
96
+
97
+ When you want to release the package:
98
+
99
+ ```
100
+ npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
101
+
102
+ git push
103
+ ```
104
+
105
+ GitHub actions will do the rest job for you.
package/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ export interface RemoveDescOptions {
7
+ /** Remove any `desc` elements, even if they have children. */
8
+ removeAny: boolean
9
+ }
10
+ export interface PluginConfig {
11
+ removeDesc: RemoveDescOptions
12
+ }
13
+ export interface OptimizeOptions {
14
+ plugins: PluginConfig
15
+ }
16
+ export declare function optimize(inputXml: string, options: OptimizeOptions): string
package/index.js ADDED
@@ -0,0 +1,289 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /* prettier-ignore */
4
+
5
+ /* auto-generated by NAPI-RS */
6
+
7
+ const { existsSync, readFileSync } = require('fs')
8
+ const { join } = require('path')
9
+
10
+ const { platform, arch } = process
11
+
12
+ let nativeBinding = null
13
+ let localFileExisted = false
14
+ let loadError = null
15
+
16
+ function isMusl() {
17
+ // For Node 10
18
+ if (!process.report || typeof process.report.getReport !== 'function') {
19
+ try {
20
+ const lddPath = require('child_process').execSync('which ldd').toString().trim()
21
+ return readFileSync(lddPath, 'utf8').includes('musl')
22
+ } catch (e) {
23
+ return true
24
+ }
25
+ } else {
26
+ const { glibcVersionRuntime } = process.report.getReport().header
27
+ return !glibcVersionRuntime
28
+ }
29
+ }
30
+
31
+ switch (platform) {
32
+ case 'android':
33
+ switch (arch) {
34
+ case 'arm64':
35
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.android-arm64.node'))
36
+ try {
37
+ if (localFileExisted) {
38
+ nativeBinding = require('./svgo-rs.android-arm64.node')
39
+ } else {
40
+ nativeBinding = require('@svg-rs/svgo-android-arm64')
41
+ }
42
+ } catch (e) {
43
+ loadError = e
44
+ }
45
+ break
46
+ case 'arm':
47
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.android-arm-eabi.node'))
48
+ try {
49
+ if (localFileExisted) {
50
+ nativeBinding = require('./svgo-rs.android-arm-eabi.node')
51
+ } else {
52
+ nativeBinding = require('@svg-rs/svgo-android-arm-eabi')
53
+ }
54
+ } catch (e) {
55
+ loadError = e
56
+ }
57
+ break
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(join(__dirname, 'svgo-rs.win32-x64-msvc.node'))
66
+ try {
67
+ if (localFileExisted) {
68
+ nativeBinding = require('./svgo-rs.win32-x64-msvc.node')
69
+ } else {
70
+ nativeBinding = require('@svg-rs/svgo-win32-x64-msvc')
71
+ }
72
+ } catch (e) {
73
+ loadError = e
74
+ }
75
+ break
76
+ case 'ia32':
77
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.win32-ia32-msvc.node'))
78
+ try {
79
+ if (localFileExisted) {
80
+ nativeBinding = require('./svgo-rs.win32-ia32-msvc.node')
81
+ } else {
82
+ nativeBinding = require('@svg-rs/svgo-win32-ia32-msvc')
83
+ }
84
+ } catch (e) {
85
+ loadError = e
86
+ }
87
+ break
88
+ case 'arm64':
89
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.win32-arm64-msvc.node'))
90
+ try {
91
+ if (localFileExisted) {
92
+ nativeBinding = require('./svgo-rs.win32-arm64-msvc.node')
93
+ } else {
94
+ nativeBinding = require('@svg-rs/svgo-win32-arm64-msvc')
95
+ }
96
+ } catch (e) {
97
+ loadError = e
98
+ }
99
+ break
100
+ default:
101
+ throw new Error(`Unsupported architecture on Windows: ${arch}`)
102
+ }
103
+ break
104
+ case 'darwin':
105
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.darwin-universal.node'))
106
+ try {
107
+ if (localFileExisted) {
108
+ nativeBinding = require('./svgo-rs.darwin-universal.node')
109
+ } else {
110
+ nativeBinding = require('@svg-rs/svgo-darwin-universal')
111
+ }
112
+ break
113
+ } catch {}
114
+ switch (arch) {
115
+ case 'x64':
116
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.darwin-x64.node'))
117
+ try {
118
+ if (localFileExisted) {
119
+ nativeBinding = require('./svgo-rs.darwin-x64.node')
120
+ } else {
121
+ nativeBinding = require('@svg-rs/svgo-darwin-x64')
122
+ }
123
+ } catch (e) {
124
+ loadError = e
125
+ }
126
+ break
127
+ case 'arm64':
128
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.darwin-arm64.node'))
129
+ try {
130
+ if (localFileExisted) {
131
+ nativeBinding = require('./svgo-rs.darwin-arm64.node')
132
+ } else {
133
+ nativeBinding = require('@svg-rs/svgo-darwin-arm64')
134
+ }
135
+ } catch (e) {
136
+ loadError = e
137
+ }
138
+ break
139
+ default:
140
+ throw new Error(`Unsupported architecture on macOS: ${arch}`)
141
+ }
142
+ break
143
+ case 'freebsd':
144
+ if (arch !== 'x64') {
145
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
146
+ }
147
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.freebsd-x64.node'))
148
+ try {
149
+ if (localFileExisted) {
150
+ nativeBinding = require('./svgo-rs.freebsd-x64.node')
151
+ } else {
152
+ nativeBinding = require('@svg-rs/svgo-freebsd-x64')
153
+ }
154
+ } catch (e) {
155
+ loadError = e
156
+ }
157
+ break
158
+ case 'linux':
159
+ switch (arch) {
160
+ case 'x64':
161
+ if (isMusl()) {
162
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-x64-musl.node'))
163
+ try {
164
+ if (localFileExisted) {
165
+ nativeBinding = require('./svgo-rs.linux-x64-musl.node')
166
+ } else {
167
+ nativeBinding = require('@svg-rs/svgo-linux-x64-musl')
168
+ }
169
+ } catch (e) {
170
+ loadError = e
171
+ }
172
+ } else {
173
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-x64-gnu.node'))
174
+ try {
175
+ if (localFileExisted) {
176
+ nativeBinding = require('./svgo-rs.linux-x64-gnu.node')
177
+ } else {
178
+ nativeBinding = require('@svg-rs/svgo-linux-x64-gnu')
179
+ }
180
+ } catch (e) {
181
+ loadError = e
182
+ }
183
+ }
184
+ break
185
+ case 'arm64':
186
+ if (isMusl()) {
187
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-arm64-musl.node'))
188
+ try {
189
+ if (localFileExisted) {
190
+ nativeBinding = require('./svgo-rs.linux-arm64-musl.node')
191
+ } else {
192
+ nativeBinding = require('@svg-rs/svgo-linux-arm64-musl')
193
+ }
194
+ } catch (e) {
195
+ loadError = e
196
+ }
197
+ } else {
198
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-arm64-gnu.node'))
199
+ try {
200
+ if (localFileExisted) {
201
+ nativeBinding = require('./svgo-rs.linux-arm64-gnu.node')
202
+ } else {
203
+ nativeBinding = require('@svg-rs/svgo-linux-arm64-gnu')
204
+ }
205
+ } catch (e) {
206
+ loadError = e
207
+ }
208
+ }
209
+ break
210
+ case 'arm':
211
+ if (isMusl()) {
212
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-arm-musleabihf.node'))
213
+ try {
214
+ if (localFileExisted) {
215
+ nativeBinding = require('./svgo-rs.linux-arm-musleabihf.node')
216
+ } else {
217
+ nativeBinding = require('@svg-rs/svgo-linux-arm-musleabihf')
218
+ }
219
+ } catch (e) {
220
+ loadError = e
221
+ }
222
+ } else {
223
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-arm-gnueabihf.node'))
224
+ try {
225
+ if (localFileExisted) {
226
+ nativeBinding = require('./svgo-rs.linux-arm-gnueabihf.node')
227
+ } else {
228
+ nativeBinding = require('@svg-rs/svgo-linux-arm-gnueabihf')
229
+ }
230
+ } catch (e) {
231
+ loadError = e
232
+ }
233
+ }
234
+ break
235
+ case 'riscv64':
236
+ if (isMusl()) {
237
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-riscv64-musl.node'))
238
+ try {
239
+ if (localFileExisted) {
240
+ nativeBinding = require('./svgo-rs.linux-riscv64-musl.node')
241
+ } else {
242
+ nativeBinding = require('@svg-rs/svgo-linux-riscv64-musl')
243
+ }
244
+ } catch (e) {
245
+ loadError = e
246
+ }
247
+ } else {
248
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-riscv64-gnu.node'))
249
+ try {
250
+ if (localFileExisted) {
251
+ nativeBinding = require('./svgo-rs.linux-riscv64-gnu.node')
252
+ } else {
253
+ nativeBinding = require('@svg-rs/svgo-linux-riscv64-gnu')
254
+ }
255
+ } catch (e) {
256
+ loadError = e
257
+ }
258
+ }
259
+ break
260
+ case 's390x':
261
+ localFileExisted = existsSync(join(__dirname, 'svgo-rs.linux-s390x-gnu.node'))
262
+ try {
263
+ if (localFileExisted) {
264
+ nativeBinding = require('./svgo-rs.linux-s390x-gnu.node')
265
+ } else {
266
+ nativeBinding = require('@svg-rs/svgo-linux-s390x-gnu')
267
+ }
268
+ } catch (e) {
269
+ loadError = e
270
+ }
271
+ break
272
+ default:
273
+ throw new Error(`Unsupported architecture on Linux: ${arch}`)
274
+ }
275
+ break
276
+ default:
277
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
278
+ }
279
+
280
+ if (!nativeBinding) {
281
+ if (loadError) {
282
+ throw loadError
283
+ }
284
+ throw new Error(`Failed to load native binding`)
285
+ }
286
+
287
+ const { optimize } = nativeBinding
288
+
289
+ module.exports.optimize = optimize
package/package.json ADDED
@@ -0,0 +1,114 @@
1
+ {
2
+ "name": "@svg-rs/svgo",
3
+ "version": "0.0.3",
4
+ "description": "Node.js tool for optimizing SVG files by Rust.",
5
+ "main": "index.js",
6
+ "repository": "https://github.com/oxidized-world/svgo-rs",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "napi-rs",
10
+ "NAPI",
11
+ "N-API",
12
+ "Rust",
13
+ "node-addon",
14
+ "node-addon-api"
15
+ ],
16
+ "files": [
17
+ "index.d.ts",
18
+ "index.js"
19
+ ],
20
+ "napi": {
21
+ "name": "svgo-rs",
22
+ "triples": {
23
+ "defaults": true,
24
+ "additional": [
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
+ ]
36
+ }
37
+ },
38
+ "engines": {
39
+ "node": ">= 10"
40
+ },
41
+ "publishConfig": {
42
+ "registry": "https://registry.npmjs.org/",
43
+ "access": "public"
44
+ },
45
+ "scripts": {
46
+ "artifacts": "napi artifacts",
47
+ "bench": "node --import @swc-node/register/esm-register benchmark/bench.ts",
48
+ "build": "napi build --platform --release",
49
+ "build:debug": "napi build --platform",
50
+ "format": "run-p format:prettier format:rs format:toml",
51
+ "format:prettier": "prettier . -w",
52
+ "format:toml": "taplo format",
53
+ "format:rs": "cargo fmt",
54
+ "lint": "oxlint .",
55
+ "prepublishOnly": "napi prepublish -t npm",
56
+ "test": "vitest run",
57
+ "test:watch": "vitest",
58
+ "version": "napi version",
59
+ "postinstall": "husky"
60
+ },
61
+ "devDependencies": {
62
+ "@napi-rs/cli": "^2.18.4",
63
+ "@swc-node/register": "^1.10.6",
64
+ "@swc/core": "^1.6.13",
65
+ "@taplo/cli": "^0.7.0",
66
+ "chalk": "^5.3.0",
67
+ "husky": "^9.0.11",
68
+ "lint-staged": "^15.2.7",
69
+ "npm-run-all2": "^7.0.0",
70
+ "oxlint": "^0.15.0",
71
+ "prettier": "^3.3.3",
72
+ "svgo": "^3.3.2",
73
+ "tinybench": "^3.0.0",
74
+ "typescript": "^5.5.3",
75
+ "vitest": "^3.0.4"
76
+ },
77
+ "lint-staged": {
78
+ "*.@(js|ts|tsx)": [
79
+ "oxlint --fix"
80
+ ],
81
+ "*.@(js|ts|tsx|yml|yaml|md|json)": [
82
+ "prettier --write"
83
+ ],
84
+ "*.toml": [
85
+ "taplo format"
86
+ ],
87
+ "*.rs": [
88
+ "cargo fmt --"
89
+ ]
90
+ },
91
+ "prettier": {
92
+ "printWidth": 120,
93
+ "semi": false,
94
+ "trailingComma": "all",
95
+ "singleQuote": true,
96
+ "arrowParens": "always"
97
+ },
98
+ "packageManager": "yarn@4.6.0",
99
+ "optionalDependencies": {
100
+ "@svg-rs/svgo-win32-x64-msvc": "0.0.3",
101
+ "@svg-rs/svgo-darwin-x64": "0.0.3",
102
+ "@svg-rs/svgo-linux-x64-gnu": "0.0.3",
103
+ "@svg-rs/svgo-linux-x64-musl": "0.0.3",
104
+ "@svg-rs/svgo-linux-arm64-gnu": "0.0.3",
105
+ "@svg-rs/svgo-win32-ia32-msvc": "0.0.3",
106
+ "@svg-rs/svgo-linux-arm-gnueabihf": "0.0.3",
107
+ "@svg-rs/svgo-darwin-arm64": "0.0.3",
108
+ "@svg-rs/svgo-android-arm64": "0.0.3",
109
+ "@svg-rs/svgo-freebsd-x64": "0.0.3",
110
+ "@svg-rs/svgo-linux-arm64-musl": "0.0.3",
111
+ "@svg-rs/svgo-win32-arm64-msvc": "0.0.3",
112
+ "@svg-rs/svgo-android-arm-eabi": "0.0.3"
113
+ }
114
+ }