Skip to content

Commit 7e890a9

Browse files
authored
Merge pull request #591 from gregberge/upgrade-deps
Upgrade to SVGO v2
2 parents 3a2f5e3 + ae47269 commit 7e890a9

File tree

22 files changed

+853
-2129
lines changed

22 files changed

+853
-2129
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
plugins: [
3+
{
4+
name: 'preset-default',
5+
params: {
6+
overrides: {
7+
removeTitle: false,
8+
},
9+
},
10+
},
11+
]
12+
}

__fixtures__/withSvgoYml/.svgo.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

__fixtures__/withSvgoYml/.svgo.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/cli/src/__snapshots__/index.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ __fixtures__/numeric/2.file.svg -> __fixtures_build__/whole/numeric/2file.js
545545
__fixtures__/numeric/file.svg -> __fixtures_build__/whole/numeric/file.js
546546
__fixtures__/simple/file.svg -> __fixtures_build__/whole/simple/file.js
547547
__fixtures__/withprettierrc/file.svg -> __fixtures_build__/whole/withprettierrc/file.js
548-
__fixtures__/withsvgoyml/file.svg -> __fixtures_build__/whole/withsvgoyml/file.js
548+
__fixtures__/withsvgoconfig/file.svg -> __fixtures_build__/whole/withsvgoconfig/file.js
549549
__fixtures__/withsvgrrc/file.svg -> __fixtures_build__/whole/withsvgrrc/file.js"
550550
`;
551551
@@ -564,7 +564,7 @@ __fixtures__/numeric/2.file.svg -> __fixtures_build__/whole/numeric/2file.tsx
564564
__fixtures__/numeric/file.svg -> __fixtures_build__/whole/numeric/file.tsx
565565
__fixtures__/simple/file.svg -> __fixtures_build__/whole/simple/file.tsx
566566
__fixtures__/withprettierrc/file.svg -> __fixtures_build__/whole/withprettierrc/file.tsx
567-
__fixtures__/withsvgoyml/file.svg -> __fixtures_build__/whole/withsvgoyml/file.tsx
567+
__fixtures__/withsvgoconfig/file.svg -> __fixtures_build__/whole/withsvgoconfig/file.tsx
568568
__fixtures__/withsvgrrc/file.svg -> __fixtures_build__/whole/withsvgrrc/file.tsx"
569569
`;
570570

packages/cli/src/index.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@ function parseObjectList(arg, accumulation = {}) {
2828
return args.reduce((acc, arg) => parseObject(arg, acc), accumulation)
2929
}
3030

31-
function isFile(filePath) {
32-
try {
33-
const stats = fs.statSync(filePath)
34-
return stats.isFile()
35-
} catch (error) {
36-
return false
37-
}
38-
}
39-
4031
const parseConfig = (name) => (arg) => {
41-
const json = isFile(arg) ? fs.readFileSync(arg) : arg
4232
try {
43-
return JSON.parse(json)
33+
if (arg.endsWith('rc')) {
34+
const content = fs.readFileSync(arg, 'utf-8')
35+
return JSON.parse(content)
36+
}
37+
38+
const ext = path.extname(arg)
39+
if (ext === '.js' || ext === '.json') {
40+
// eslint-disable-next-line import/no-dynamic-require, global-require
41+
return require(path.join(process.cwd(), arg))
42+
}
43+
44+
return JSON.parse(arg)
4445
} catch (error) {
4546
exitError(
46-
`"${name}" is not valid, please specify a file or use inline JSON.`,
47+
`"${name}" is not valid, please specify a valid file or use a inline JSON.`,
4748
)
4849
return null
4950
}

packages/cli/src/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ describe('cli', () => {
100100

101101
it('should support --svgo-config as json', async () => {
102102
const result = await cli(
103-
`--svgo-config '{"plugins": [{"removeTitle": false}]}' __fixtures__/simple/file.svg`,
103+
`--svgo-config '{"plugins":[{"name":"preset-default","params":{"overrides":{"removeTitle":false}}}]}' __fixtures__/simple/file.svg`,
104104
)
105105
expect(result).toMatchSnapshot()
106106
}, 10000)
107107

108108
it('should support --svgo-config as file', async () => {
109109
const result = await cli(
110-
`--svgo-config __fixtures__/withSvgoYml/.svgo.json __fixtures__/simple/file.svg`,
110+
`--svgo-config __fixtures__/withSvgoConfig/svgo.config.js __fixtures__/simple/file.svg`,
111111
)
112112
expect(result).toMatchSnapshot()
113113
}, 10000)

packages/core/src/__fixtures__/svgo/.svgo.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
plugins: [
3+
{
4+
name: 'preset-default',
5+
params: {
6+
overrides: {
7+
removeDesc: false,
8+
},
9+
},
10+
},
11+
]
12+
}

packages/core/src/__snapshots__/convert.test.js.snap

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function SvgComponent(props) {
1313
fillRule=\\"evenodd\\"
1414
strokeLinecap=\\"square\\"
1515
>
16-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
16+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
1717
</g>
1818
</svg>
1919
)
@@ -36,7 +36,7 @@ function SvgComponent(props) {
3636
fillRule=\\"evenodd\\"
3737
strokeLinecap=\\"square\\"
3838
>
39-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
39+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
4040
</g>
4141
</svg>
4242
)
@@ -59,7 +59,7 @@ function SvgComponent() {
5959
fillRule=\\"evenodd\\"
6060
strokeLinecap=\\"square\\"
6161
>
62-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
62+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
6363
</g>
6464
</svg>
6565
)
@@ -88,7 +88,7 @@ function SvgComponent(props) {
8888
fillRule=\\"evenodd\\"
8989
strokeLinecap=\\"square\\"
9090
>
91-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
91+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
9292
</g>
9393
</svg>
9494
)
@@ -111,7 +111,7 @@ function SvgComponent(props) {
111111
fillRule=\\"evenodd\\"
112112
strokeLinecap=\\"square\\"
113113
>
114-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
114+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
115115
</g>
116116
</svg>
117117
)
@@ -135,7 +135,7 @@ function SvgComponent(props) {
135135
fillRule=\\"evenodd\\"
136136
strokeLinecap=\\"square\\"
137137
>
138-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
138+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
139139
</g>
140140
</svg>
141141
)
@@ -159,7 +159,7 @@ function SvgComponent(props) {
159159
fillRule=\\"evenodd\\"
160160
strokeLinecap=\\"square\\"
161161
>
162-
<Svg.Path d=\\"M51 37L37 51M51 51L37 37\\" />
162+
<Svg.Path d=\\"M51 37 37 51M51 51 37 37\\" />
163163
</Svg.G>
164164
</Svg>
165165
)
@@ -183,7 +183,7 @@ function SvgComponent() {
183183
fillRule=\\"evenodd\\"
184184
strokeLinecap=\\"square\\"
185185
>
186-
<Path d=\\"M51 37L37 51M51 51L37 37\\" />
186+
<Path d=\\"M51 37 37 51M51 51 37 37\\" />
187187
</G>
188188
</Svg>
189189
)
@@ -213,7 +213,7 @@ function SvgComponent(props) {
213213
fillRule=\\"evenodd\\"
214214
strokeLinecap=\\"square\\"
215215
>
216-
<Path d=\\"M51 37L37 51M51 51L37 37\\" />
216+
<Path d=\\"M51 37 37 51M51 51 37 37\\" />
217217
</G>
218218
</Svg>
219219
)
@@ -243,7 +243,7 @@ function SvgComponent(props, svgRef) {
243243
fillRule=\\"evenodd\\"
244244
strokeLinecap=\\"square\\"
245245
>
246-
<Path d=\\"M51 37L37 51M51 51L37 37\\" />
246+
<Path d=\\"M51 37 37 51M51 51 37 37\\" />
247247
</G>
248248
</Svg>
249249
)
@@ -268,7 +268,7 @@ function SvgComponent(props) {
268268
fillRule=\\"evenodd\\"
269269
strokeLinecap=\\"square\\"
270270
>
271-
<Path d=\\"M51 37L37 51M51 51L37 37\\" />
271+
<Path d=\\"M51 37 37 51M51 51 37 37\\" />
272272
</G>
273273
</Svg>
274274
)
@@ -282,7 +282,7 @@ exports[`convert config should support options {"prettier":false} 1`] = `
282282
"import * as React from \\"react\\";
283283
284284
function SvgComponent(props) {
285-
return <svg width={88} height={88} xmlns=\\"http://www.w3.org/2000/svg\\" {...props}><g stroke=\\"#063855\\" strokeWidth={2} fill=\\"none\\" fillRule=\\"evenodd\\" strokeLinecap=\\"square\\"><path d=\\"M51 37L37 51M51 51L37 37\\" /></g></svg>;
285+
return <svg width={88} height={88} xmlns=\\"http://www.w3.org/2000/svg\\" {...props}><g stroke=\\"#063855\\" strokeWidth={2} fill=\\"none\\" fillRule=\\"evenodd\\" strokeLinecap=\\"square\\"><path d=\\"M51 37 37 51M51 51 37 37\\" /></g></svg>;
286286
}
287287
288288
export default SvgComponent;"
@@ -307,7 +307,7 @@ function SvgComponent(props, svgRef) {
307307
fillRule=\\"evenodd\\"
308308
strokeLinecap=\\"square\\"
309309
>
310-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
310+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
311311
</g>
312312
</svg>
313313
)
@@ -331,7 +331,7 @@ function SvgComponent(props) {
331331
fillRule=\\"evenodd\\"
332332
strokeLinecap=\\"square\\"
333333
>
334-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
334+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
335335
</g>
336336
</svg>
337337
)
@@ -354,7 +354,7 @@ function SvgComponent(props) {
354354
fillRule=\\"evenodd\\"
355355
strokeLinecap=\\"square\\"
356356
>
357-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
357+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
358358
</g>
359359
</svg>
360360
)
@@ -384,7 +384,7 @@ function SvgComponent(props) {
384384
fillRule=\\"evenodd\\"
385385
strokeLinecap=\\"square\\"
386386
>
387-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
387+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
388388
</g>
389389
</svg>
390390
)
@@ -451,7 +451,7 @@ function SvgComponent({ title, titleId, ...props }) {
451451
fillRule=\\"evenodd\\"
452452
strokeLinecap=\\"square\\"
453453
>
454-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
454+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
455455
</g>
456456
</svg>
457457
)
@@ -505,7 +505,7 @@ function SvgComponent(props) {
505505
fillRule=\\"evenodd\\"
506506
strokeLinecap=\\"square\\"
507507
>
508-
<path d=\\"M51 37L37 51M51 51L37 37\\" />
508+
<path d=\\"M51 37 37 51M51 51 37 37\\" />
509509
</g>
510510
</svg>
511511
)
@@ -528,18 +528,27 @@ function SvgComponent(props) {
528528
{...props}
529529
>
530530
<g transform=\\"translate(0 -1004.362)\\">
531-
<g id=\\"prefix__a\\" color=\\"#000\\" fill=\\"#a3a3a3\\" strokeWidth={8}>
531+
<g id=\\"prefix__a\\">
532532
<rect
533533
style={{
534+
color: '#000',
535+
fill: '#a3a3a3',
536+
fillOpacity: 1,
537+
fillRule: 'nonzero',
538+
stroke: 'none',
539+
strokeWidth: 8,
534540
marker: 'none',
541+
visibility: 'visible',
542+
display: 'inline',
543+
overflow: 'visible',
544+
enableBackground: 'accumulate',
535545
}}
536546
width={4}
537547
height={4}
538548
x={4}
539549
y={1010.362}
540550
rx={0.2}
541551
ry={0.2}
542-
overflow=\\"visible\\"
543552
/>
544553
<rect
545554
ry={0.2}
@@ -549,9 +558,18 @@ function SvgComponent(props) {
549558
height={4}
550559
width={32}
551560
style={{
561+
color: '#000',
562+
fill: '#a3a3a3',
563+
fillOpacity: 1,
564+
fillRule: 'nonzero',
565+
stroke: 'none',
566+
strokeWidth: 8,
552567
marker: 'none',
568+
visibility: 'visible',
569+
display: 'inline',
570+
overflow: 'visible',
571+
enableBackground: 'accumulate',
553572
}}
554-
overflow=\\"visible\\"
555573
/>
556574
</g>
557575
<use xlinkHref=\\"#prefix__a\\" />
@@ -599,9 +617,8 @@ function SvgComponent(props) {
599617
strokeLinecap=\\"square\\"
600618
>
601619
<g id=\\"prefix__Dismiss\\" stroke=\\"#063855\\" strokeWidth={2}>
602-
<path d=\\"M51 37L37 51M51 51L37 37\\" id=\\"prefix__Shape\\" />
620+
<path d=\\"M51 37 37 51M51 51 37 37\\" id=\\"prefix__Shape\\" />
603621
</g>
604-
<style />
605622
</g>
606623
</svg>
607624
)
@@ -616,12 +633,23 @@ exports[`convert should remove null characters 1`] = `
616633
617634
function SvgComponent(props) {
618635
return (
619-
<svg xmlns=\\"http://www.w3.org/2000/svg\\" width={25} height={25} {...props}>
636+
<svg
637+
xmlns=\\"http://www.w3.org/2000/svg\\"
638+
width={25}
639+
height={25}
640+
style={{
641+
enableBackground: 'new 0 0 25 25',
642+
}}
643+
xmlSpace=\\"preserve\\"
644+
{...props}
645+
>
620646
<path
621647
d=\\"M19.4 24.5H5.6c-2.8 0-5.1-2.3-5.1-5.1V5.6C.5 2.8 2.8.5 5.6.5h13.8c2.8 0 5.1 2.3 5.1 5.1v13.8c0 2.8-2.3 5.1-5.1 5.1z\\"
622-
fill=\\"#fff\\"
623-
stroke=\\"#434a54\\"
624-
strokeMiterlimit={10}
648+
style={{
649+
fill: '#fff',
650+
stroke: '#434a54',
651+
strokeMiterlimit: 10,
652+
}}
625653
/>
626654
</svg>
627655
)
@@ -637,12 +665,18 @@ exports[`convert should remove style tags 1`] = `
637665
function SvgComponent(props) {
638666
return (
639667
<svg width={88} height={88} xmlns=\\"http://www.w3.org/2000/svg\\" {...props}>
640-
<g fill=\\"red\\" fillRule=\\"evenodd\\" strokeLinecap=\\"square\\">
668+
<style />
669+
<g
670+
fill=\\"none\\"
671+
fillRule=\\"evenodd\\"
672+
strokeLinecap=\\"square\\"
673+
style={{
674+
fill: 'red',
675+
}}
676+
>
641677
<g id=\\"prefix__Dismiss\\" stroke=\\"#063855\\" strokeWidth={2}>
642-
<path d=\\"M51 37L37 51\\" id=\\"prefix__Shape\\" />
643-
<path d=\\"M51 51L37 37\\" />
678+
<path d=\\"M51 37 37 51M51 51 37 37\\" id=\\"prefix__Shape\\" />
644679
</g>
645-
<style />
646680
</g>
647681
</svg>
648682
)

0 commit comments

Comments
 (0)