Skip to content

Commit

Permalink
chore(deps)!: upgrade svgo to v3 (#1440)
Browse files Browse the repository at this point in the history
* chore(deps)!: upgrade svgo to v3

BREAKING CHANGE: increase the minimum supported node version to v14.

* fix(package): allow node 14, 16 and 18

Co-authored-by: Ludovico Fischer <43557+ludofischer@users.noreply.github.com>

* fix(test): update svgo output

* chore(frameworks): update css

* fix(svgo): update to revert skipping library check

* chore(deps): update svgo to v3.0.2

---------

Co-authored-by: Ludovico Fischer <43557+ludofischer@users.noreply.github.com>
Co-authored-by: Ludovico Fischer <livrerie@gmail.com>
  • Loading branch information
3 people committed Mar 14, 2023
1 parent 39a2040 commit 4e272f8
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 58 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-eggs-worry.md
@@ -0,0 +1,5 @@
---
'postcss-svgo': major
---

Upgrade dependency svgo to v3 and increase the minimum supported node version to v14.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cssnano/test/fixtures.js
Expand Up @@ -350,7 +350,7 @@ test(
`.box {
background-image: url('data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20%3F%3E%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20width%3D%22100%25%22%20height%3D%22100%25%22%20viewBox%3D%220%200%201%201%22%20preserveAspectRatio%3D%22none%22%3E%3ClinearGradient%20id%3D%22gradient%22%20gradientUnits%3D%22userSpaceOnUse%22%20x1%3D%220%25%22%20y1%3D%220%25%22%20x2%3D%22100%25%22%20y2%3D%220%25%22%3E%3Cstop%20offset%3D%220%25%22%20stop-color%3D%22%23414042%22%2F%3E%3Cstop%20offset%3D%22100%25%22%20stop-color%3D%22%23ffffff%22%20stop-opacity%3D%220%22%2F%3E%3C%2FlinearGradient%3E%3Crect%20x%3D%220%22%20y%3D%220%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22url(%23gradient)%22%20%2F%3E%3C%2Fsvg%3E');
}`,
`.box{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1' preserveAspectRatio='none'%3E%3ClinearGradient id='a' gradientUnits='userSpaceOnUse' x1='0%25' y1='0%25' x2='100%25' y2='0%25'%3E%3Cstop offset='0%25' stop-color='%23414042'/%3E%3Cstop offset='100%25' stop-color='%23fff' stop-opacity='0'/%3E%3C/linearGradient%3E%3Cpath fill='url(%23a)' d='M0 0h1v1H0z'/%3E%3C/svg%3E")}`
`.box{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 1 1'%3E%3ClinearGradient id='a' x1='0%25' x2='100%25' y1='0%25' y2='0%25' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0%25' stop-color='%23414042'/%3E%3Cstop offset='100%25' stop-color='%23fff' stop-opacity='0'/%3E%3C/linearGradient%3E%3Cpath fill='url(%23a)' d='M0 0h1v1H0z'/%3E%3C/svg%3E")}`
)
);

Expand Down
5 changes: 2 additions & 3 deletions packages/postcss-svgo/package.json
Expand Up @@ -28,16 +28,15 @@
"repository": "cssnano/cssnano",
"dependencies": {
"postcss-value-parser": "^4.2.0",
"svgo": "^2.7.0"
"svgo": "^3.0.2"
},
"bugs": {
"url": "https://github.com/cssnano/cssnano/issues"
},
"engines": {
"node": "^10 || ^12 || >=14.0"
"node": "^14 || ^16 || >= 18"
},
"devDependencies": {
"@types/svgo": "^2.6.2",
"postcss": "^8.2.15"
},
"peerDependencies": {
Expand Down
7 changes: 2 additions & 5 deletions packages/postcss-svgo/src/index.js
Expand Up @@ -43,12 +43,9 @@ function minifySVG(input, opts) {
svg = svg.replace(escapedQuotes, '$1="$2"');

const result = optimize(svg, opts);
if (result.error) {
throw new Error(result.error);
}

return {
result: /** @type {import('svgo').OptimizedSvg}*/ (result).data,
result: /** @type {import('svgo').Output}*/ (result).data,
isUriEncoded,
};
}
Expand Down Expand Up @@ -117,7 +114,7 @@ function minify(decl, opts, postcssResult) {

decl.value = minified.toString();
}
/** @typedef {{encode?: boolean, plugins?: object[]} & import('svgo').OptimizeOptions} Options */
/** @typedef {{encode?: boolean, plugins?: object[]} & import('svgo').Config} Options */
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} opts
Expand Down
8 changes: 4 additions & 4 deletions packages/postcss-svgo/test/index.js
Expand Up @@ -128,7 +128,7 @@ test(
'should not throw when decoding a svg',
processCSS(
"h1{-webkit-mask-box-image: url(\"data:image/svg+xml;charset=utf-8,<svg height='35' viewBox='0 0 96 70' width='48' xmlns='http://www.w3.org/2000/svg'><path d='m84 35c1 7-5 37-42 35-37 2-43-28-42-35-1-7 5-37 42-35 37-2 43 28 42 35z'/></svg>\") 50% 56% 46% 42%;}",
'h1{-webkit-mask-box-image: url(\'data:image/svg+xml;charset=utf-8,<svg height="35" viewBox="0 0 96 70" width="48" xmlns="http://www.w3.org/2000/svg"><path d="M84 35c1 7-5 37-42 35C5 72-1 42 0 35-1 28 5-2 42 0c37-2 43 28 42 35z"/></svg>\') 50% 56% 46% 42%;}'
'h1{-webkit-mask-box-image: url(\'data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="35" viewBox="0 0 96 70"><path d="M84 35c1 7-5 37-42 35C5 72-1 42 0 35-1 28 5-2 42 0c37-2 43 28 42 35z"/></svg>\') 50% 56% 46% 42%;}'
)
);

Expand All @@ -154,15 +154,15 @@ test(
'should not fail on "malformed" svgs',
processCSS(
"h1{background-image:url(\"data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg'><line stroke-width='2' stroke='rgb(255,0,0)' x1='0' y1='100%' x2='100%' y2='0'></line></svg>\")}",
'h1{background-image:url(\'data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg"><line stroke-width="2" stroke="red" y1="100%" x2="100%"/></svg>\')}'
'h1{background-image:url(\'data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg"><line x2="100%" y1="100%" stroke="red" stroke-width="2"/></svg>\')}'
)
);

test(
'should encode "malformed" svgs',
processCSS(
"h1{background-image:url(\"data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg'><line stroke-width='2' stroke='rgb(255,0,0)' x1='0' y1='100%' x2='100%' y2='0'></line></svg>\")}",
"h1{background-image:url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cline stroke-width='2' stroke='red' y1='100%25' x2='100%25'/%3E%3C/svg%3E\")}",
"h1{background-image:url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cline x2='100%25' y1='100%25' stroke='red' stroke-width='2'/%3E%3C/svg%3E\")}",
{ encode: true }
)
);
Expand Down Expand Up @@ -276,7 +276,7 @@ test(
'should encode hashes',
processCSS(
`h1{background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="120" height="32" viewBox="0 0 1200 320"> <path d="M137.189 140V17.17h-36.676L73.871 31.832z" fill="rgb(102,51,153)"/></svg>');}`,
`h1{background-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="120" height="32" viewBox="0 0 1200 320"><path d="M137.189 140V17.17h-36.676L73.871 31.832z" fill="%23639"/></svg>');}`
`h1{background-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="120" height="32" viewBox="0 0 1200 320"><path fill="%23639" d="M137.189 140V17.17h-36.676L73.871 31.832z"/></svg>');}`
)
);

Expand Down
4 changes: 2 additions & 2 deletions packages/postcss-svgo/types/index.d.ts
@@ -1,5 +1,5 @@
export = pluginCreator;
/** @typedef {{encode?: boolean, plugins?: object[]} & import('svgo').OptimizeOptions} Options */
/** @typedef {{encode?: boolean, plugins?: object[]} & import('svgo').Config} Options */
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} opts
Expand All @@ -12,6 +12,6 @@ declare namespace pluginCreator {
type Options = {
encode?: boolean;
plugins?: object[];
} & import('svgo').OptimizeOptions;
} & import('svgo').Config;
declare var postcss: true;
import { encode } from "./lib/url";
93 changes: 56 additions & 37 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 comments on commit 4e272f8

@richb-hanover
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this upgrade to svgo@3.0.2 require a bump in the postcss-svgo version (from 5.1.0)? Thanks.

@ludofischer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this upgrade to svgo@3.0.2 require a bump in the postcss-svgo version (from 5.1.0)? Thanks.

It will once it's released, but this code is not available on npm yet.

@richb-hanover
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How soon might that be (that it gets moved to npm)? Thanks.

@ludofischer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How soon might that be (that it gets moved to npm)? Thanks.

A week or so maybe. Why are you interested in the upgrade to svgo 3.0.2 in particular? Is there a speficic feature/bug fix you need?

@richb-hanover
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great news. No particular bug, I'm looking to get rid of the warning about the dependency on stable@0.1.8. Thanks!

Please sign in to comment.