Skip to content

Commit

Permalink
[Breaking] update svgo to v2; drop node < v10.13
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 17, 2021
1 parent c7ae6fd commit 90eeedd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Expand Up @@ -2,10 +2,11 @@ language: node_js
os:
- linux
node_js:
- "15"
- "14"
- "12"
- "10"
- "9"
- "8"
- "6"
- "10.13"
before_install:
- 'nvm install-latest-npm'
script:
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -50,6 +50,9 @@
"@babel/parser": "^7.0.0",
"lodash.isplainobject": "^4.0.6",
"resolve": "^1.20.0",
"svgo": "^0.7.2"
"svgo": "^2.0.0"
},
"engines": {
"node": ">=10.13"
}
}
2 changes: 1 addition & 1 deletion src/escapeBraces.js
Expand Up @@ -7,5 +7,5 @@ export default function escapeBraces(raw) {
// <style> .class1 {} .class2{}</style>
// to
// <style> .class1 {`{`}{`}`} .class2{`{`}{`}`}</style>
return raw.replace(/(\{|\})/g, '{`$1`}');
return { ...raw, data: raw.data.replace(/(\{|\})/g, '{`$1`}') };
}
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -75,7 +75,7 @@ export default declare(({

const escapeSvgSource = escapeBraces(optimizedSource);

const parsedSvgAst = parse(escapeSvgSource, {
const parsedSvgAst = parse(escapeSvgSource.data, {
sourceType: 'module',
plugins: ['jsx'],
});
Expand Down
15 changes: 2 additions & 13 deletions src/optimize.js
@@ -1,7 +1,7 @@
// validates svgo opts
// to contain minimal set of plugins that will strip some stuff
// for the babylon JSX parser to work
import Svgo from 'svgo';
import * as SVGO from 'svgo';
import isPlainObject from 'lodash.isplainobject';

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

export default function optimize(content, opts = {}) {
validateAndFix(opts);
const svgo = new Svgo(opts);

// Svgo isn't _really_ async, so let's do it this way:
let returnValue;
svgo.optimize(content, (response) => {
if (response.error) {
returnValue = response.error;
} else {
returnValue = response.data;
}
});

return returnValue;
return SVGO.optimize(content, opts);
}

0 comments on commit 90eeedd

Please sign in to comment.