From 0b2b1191eeeecaa8aef36141a2d8e236aa3bd1b6 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 17 Feb 2021 12:54:45 -0800 Subject: [PATCH 1/3] [Dev Deps] update `@babel/cli`, `@babel/node`, `@babel/preset-react`, `eslint` --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9162282..8817ba2 100644 --- a/package.json +++ b/package.json @@ -30,12 +30,12 @@ }, "homepage": "https://github.com/kesne/babel-plugin-inline-react-svg#readme", "devDependencies": { - "@babel/cli": "^7.12.10", + "@babel/cli": "^7.12.16", "@babel/core": "^7.0.0", - "@babel/node": "^7.12.10", - "@babel/preset-react": "^7.12.10", + "@babel/node": "^7.12.16", + "@babel/preset-react": "^7.12.13", "babel-preset-airbnb": "^3.3.2", - "eslint": "^7.17.0", + "eslint": "^7.20.0", "eslint-config-airbnb": "^18.2.1", "eslint-plugin-import": "^2.22.1", "eslint-plugin-jsx-a11y": "^6.4.1", From c7ae6fdb9de0bb3c9002d3f5af10d97607ab3222 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 17 Feb 2021 12:55:52 -0800 Subject: [PATCH 2/3] [Deps] update `resolve` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8817ba2..921bac4 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "@babel/helper-plugin-utils": "^7.0.0", "@babel/parser": "^7.0.0", "lodash.isplainobject": "^4.0.6", - "resolve": "^1.19.0", + "resolve": "^1.20.0", "svgo": "^0.7.2" } } From 90eeedda0bf1b380de35d5eb57e2443f1e4987f9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 17 Feb 2021 13:38:43 -0800 Subject: [PATCH 3/3] [Breaking] update `svgo` to v2; drop node < v10.13 --- .travis.yml | 7 ++++--- package.json | 5 ++++- src/escapeBraces.js | 2 +- src/index.js | 2 +- src/optimize.js | 15 ++------------- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5ab70bc..3ddc064 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/package.json b/package.json index 921bac4..faad619 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/escapeBraces.js b/src/escapeBraces.js index 4cd0a16..eaa206a 100644 --- a/src/escapeBraces.js +++ b/src/escapeBraces.js @@ -7,5 +7,5 @@ export default function escapeBraces(raw) { // // to // - return raw.replace(/(\{|\})/g, '{`$1`}'); + return { ...raw, data: raw.data.replace(/(\{|\})/g, '{`$1`}') }; } diff --git a/src/index.js b/src/index.js index 044d3fb..c88fc0e 100644 --- a/src/index.js +++ b/src/index.js @@ -75,7 +75,7 @@ export default declare(({ const escapeSvgSource = escapeBraces(optimizedSource); - const parsedSvgAst = parse(escapeSvgSource, { + const parsedSvgAst = parse(escapeSvgSource.data, { sourceType: 'module', plugins: ['jsx'], }); diff --git a/src/optimize.js b/src/optimize.js index db76ae2..d9e56e0 100644 --- a/src/optimize.js +++ b/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']; @@ -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); }