Skip to content

Commit 90eeedd

Browse files
committed
[Breaking] update svgo to v2; drop node < v10.13
1 parent c7ae6fd commit 90eeedd

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ language: node_js
22
os:
33
- linux
44
node_js:
5+
- "15"
6+
- "14"
7+
- "12"
58
- "10"
6-
- "9"
7-
- "8"
8-
- "6"
9+
- "10.13"
910
before_install:
1011
- 'nvm install-latest-npm'
1112
script:

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
"@babel/parser": "^7.0.0",
5151
"lodash.isplainobject": "^4.0.6",
5252
"resolve": "^1.20.0",
53-
"svgo": "^0.7.2"
53+
"svgo": "^2.0.0"
54+
},
55+
"engines": {
56+
"node": ">=10.13"
5457
}
5558
}

src/escapeBraces.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export default function escapeBraces(raw) {
77
// <style> .class1 {} .class2{}</style>
88
// to
99
// <style> .class1 {`{`}{`}`} .class2{`{`}{`}`}</style>
10-
return raw.replace(/(\{|\})/g, '{`$1`}');
10+
return { ...raw, data: raw.data.replace(/(\{|\})/g, '{`$1`}') };
1111
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default declare(({
7575

7676
const escapeSvgSource = escapeBraces(optimizedSource);
7777

78-
const parsedSvgAst = parse(escapeSvgSource, {
78+
const parsedSvgAst = parse(escapeSvgSource.data, {
7979
sourceType: 'module',
8080
plugins: ['jsx'],
8181
});

src/optimize.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// validates svgo opts
22
// to contain minimal set of plugins that will strip some stuff
33
// for the babylon JSX parser to work
4-
import Svgo from 'svgo';
4+
import * as SVGO from 'svgo';
55
import isPlainObject from 'lodash.isplainobject';
66

77
const essentialPlugins = ['removeDoctype', 'removeComments'];
@@ -54,17 +54,6 @@ function validateAndFix(opts) {
5454

5555
export default function optimize(content, opts = {}) {
5656
validateAndFix(opts);
57-
const svgo = new Svgo(opts);
5857

59-
// Svgo isn't _really_ async, so let's do it this way:
60-
let returnValue;
61-
svgo.optimize(content, (response) => {
62-
if (response.error) {
63-
returnValue = response.error;
64-
} else {
65-
returnValue = response.data;
66-
}
67-
});
68-
69-
return returnValue;
58+
return SVGO.optimize(content, opts);
7059
}

0 commit comments

Comments
 (0)