From 9c8a228e09d6c9cc7bd21b1773875e3bddee505a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Oct 2022 15:06:39 +0000 Subject: [PATCH 1/3] chore(deps): bump svgo from 2.8.0 to 3.0.0 Bumps [svgo](https://github.com/svg/svgo) from 2.8.0 to 3.0.0. - [Release notes](https://github.com/svg/svgo/releases) - [Changelog](https://github.com/svg/svgo/blob/main/CHANGELOG-old.md) - [Commits](https://github.com/svg/svgo/compare/v2.8.0...v3.0.0) --- updated-dependencies: - dependency-name: svgo dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 90043aa..28e794e 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "html-minifier": "^4.0.0", "micromatch": "^4.0.2", "minify-xml": "^3.2.0", - "svgo": "^2.4.0", + "svgo": "^3.0.0", "terser": "^5.3.0" }, "devDependencies": { From a6e2ea08791a79906bc2f6a3d0b08b9f0745b6df Mon Sep 17 00:00:00 2001 From: MDLeom <43627182+curbengh@users.noreply.github.com> Date: Sun, 6 Nov 2022 02:54:55 +0000 Subject: [PATCH 2/3] fix(svg): svgo@3 now throws error - cleanupIDs -> cleanupIds - https://github.com/svg/svgo/releases/tag/v3.0.0 --- README.md | 2 +- lib/filter.js | 16 ++++++++++------ test/svg.test.js | 14 +++++++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e79ea49..9c274af 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ minify: # Retain comments removeComments: false # Do not remove unused ID attributes - cleanupIDs: false + cleanupIds: false ``` - For more options, see [svgo](https://github.com/svg/svgo). - **globOptions** - See [globbing](#globbing) section. diff --git a/lib/filter.js b/lib/filter.js index dd2d2d5..ecec928 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -152,12 +152,16 @@ function minifySvg () { assetPath.on('data', (chunk) => (assetTxt += chunk)) assetPath.on('end', async () => { if (assetTxt.length) { - const { data, error } = svgOptimize(assetTxt, { ...options, plugins }) - if (data) { - if (verbose) logFn.call(this, assetTxt, data, path, 'svg') - resolve(route.set(path, data)) - } else if (error) { - reject(new Error(`Path: ${path}\n${error}`)) + try { + const { data } = svgOptimize(assetTxt, { ...options, plugins }) + if (data) { + if (verbose) logFn.call(this, assetTxt, data, path, 'svg') + resolve(route.set(path, data)) + } else { + reject(new Error(`Path: ${path}\nEmpty svg input`)) + } + } catch (err) { + reject(new Error(`Path: ${path}\n${err}`)) } } resolve() diff --git a/test/svg.test.js b/test/svg.test.js index 9a4b2ea..83c2866 100644 --- a/test/svg.test.js +++ b/test/svg.test.js @@ -71,7 +71,7 @@ describe('svg', () => { test('option', async () => { const customOpt = { - cleanupIDs: false + cleanupIds: false } hexo.config.minify.svg.plugins = customOpt plugins = [{ @@ -117,10 +117,14 @@ describe('svg', () => { const input = '{}' hexo.route.set(path, input) - const { error } = svgOptimize(input, { plugins }) - - expect(error).toBeDefined() - await expect(s()).rejects.toThrow(`Path: ${path}\n${error}`) + let expected + try { + svgOptimize(input, { plugins }) + } catch (err) { + expected = err + } + expect(expected).toBeDefined() + await expect(s()).rejects.toThrow(`Path: ${path}\n${expected}`) }) test('include - exclude *.min.svg by default', async () => { From a6f434ff8da8eb8bbe6cd10eaaf20854ed3b5f4c Mon Sep 17 00:00:00 2001 From: MDLeom <43627182+curbengh@users.noreply.github.com> Date: Sun, 6 Nov 2022 04:50:36 +0000 Subject: [PATCH 3/3] fix(svg): ignore empty input --- lib/filter.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/filter.js b/lib/filter.js index ecec928..ac09d71 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -154,12 +154,8 @@ function minifySvg () { if (assetTxt.length) { try { const { data } = svgOptimize(assetTxt, { ...options, plugins }) - if (data) { - if (verbose) logFn.call(this, assetTxt, data, path, 'svg') - resolve(route.set(path, data)) - } else { - reject(new Error(`Path: ${path}\nEmpty svg input`)) - } + if (verbose) logFn.call(this, assetTxt, data, path, 'svg') + resolve(route.set(path, data)) } catch (err) { reject(new Error(`Path: ${path}\n${err}`)) }