Skip to content

Commit 1f107af

Browse files
committed
feat: upgrade to svgo v2
BREAKING CHANGE: config format of SVGO changes & SVGR does not merge SVGO config.
1 parent 18cd7c8 commit 1f107af

File tree

18 files changed

+196
-390
lines changed

18 files changed

+196
-390
lines changed
File renamed without changes.
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/plugin-svgo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
"dependencies": {
2929
"cosmiconfig": "^7.0.1",
3030
"deepmerge": "^4.2.2",
31-
"svgo": "^1.2.2"
31+
"svgo": "^2.5.0"
3232
}
3333
}

0 commit comments

Comments
 (0)