diff --git a/__fixtures__/withSvgoYml/file.svg b/__fixtures__/withSvgoConfig/file.svg
similarity index 100%
rename from __fixtures__/withSvgoYml/file.svg
rename to __fixtures__/withSvgoConfig/file.svg
diff --git a/__fixtures__/withSvgoConfig/svgo.config.js b/__fixtures__/withSvgoConfig/svgo.config.js
new file mode 100644
index 00000000..af634d9b
--- /dev/null
+++ b/__fixtures__/withSvgoConfig/svgo.config.js
@@ -0,0 +1,12 @@
+module.exports = {
+ plugins: [
+ {
+ name: 'preset-default',
+ params: {
+ overrides: {
+ removeTitle: false,
+ },
+ },
+ },
+ ]
+}
\ No newline at end of file
diff --git a/__fixtures__/withSvgoYml/.svgo.json b/__fixtures__/withSvgoYml/.svgo.json
deleted file mode 100644
index 89ae8c29..00000000
--- a/__fixtures__/withSvgoYml/.svgo.json
+++ /dev/null
@@ -1 +0,0 @@
-{"plugins": [{"removeTitle": false}]}
diff --git a/__fixtures__/withSvgoYml/.svgo.yml b/__fixtures__/withSvgoYml/.svgo.yml
deleted file mode 100644
index bd16d00e..00000000
--- a/__fixtures__/withSvgoYml/.svgo.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-plugins:
- - removeTitle: false
diff --git a/packages/cli/src/__snapshots__/index.test.js.snap b/packages/cli/src/__snapshots__/index.test.js.snap
index c6a57053..484bd62d 100644
--- a/packages/cli/src/__snapshots__/index.test.js.snap
+++ b/packages/cli/src/__snapshots__/index.test.js.snap
@@ -545,7 +545,7 @@ __fixtures__/numeric/2.file.svg -> __fixtures_build__/whole/numeric/2file.js
__fixtures__/numeric/file.svg -> __fixtures_build__/whole/numeric/file.js
__fixtures__/simple/file.svg -> __fixtures_build__/whole/simple/file.js
__fixtures__/withprettierrc/file.svg -> __fixtures_build__/whole/withprettierrc/file.js
-__fixtures__/withsvgoyml/file.svg -> __fixtures_build__/whole/withsvgoyml/file.js
+__fixtures__/withsvgoconfig/file.svg -> __fixtures_build__/whole/withsvgoconfig/file.js
__fixtures__/withsvgrrc/file.svg -> __fixtures_build__/whole/withsvgrrc/file.js"
`;
@@ -564,7 +564,7 @@ __fixtures__/numeric/2.file.svg -> __fixtures_build__/whole/numeric/2file.tsx
__fixtures__/numeric/file.svg -> __fixtures_build__/whole/numeric/file.tsx
__fixtures__/simple/file.svg -> __fixtures_build__/whole/simple/file.tsx
__fixtures__/withprettierrc/file.svg -> __fixtures_build__/whole/withprettierrc/file.tsx
-__fixtures__/withsvgoyml/file.svg -> __fixtures_build__/whole/withsvgoyml/file.tsx
+__fixtures__/withsvgoconfig/file.svg -> __fixtures_build__/whole/withsvgoconfig/file.tsx
__fixtures__/withsvgrrc/file.svg -> __fixtures_build__/whole/withsvgrrc/file.tsx"
`;
diff --git a/packages/cli/src/index.js b/packages/cli/src/index.js
index 42c363c2..32b48aee 100644
--- a/packages/cli/src/index.js
+++ b/packages/cli/src/index.js
@@ -28,22 +28,23 @@ function parseObjectList(arg, accumulation = {}) {
return args.reduce((acc, arg) => parseObject(arg, acc), accumulation)
}
-function isFile(filePath) {
- try {
- const stats = fs.statSync(filePath)
- return stats.isFile()
- } catch (error) {
- return false
- }
-}
-
const parseConfig = (name) => (arg) => {
- const json = isFile(arg) ? fs.readFileSync(arg) : arg
try {
- return JSON.parse(json)
+ if (arg.endsWith('rc')) {
+ const content = fs.readFileSync(arg, 'utf-8')
+ return JSON.parse(content)
+ }
+
+ const ext = path.extname(arg)
+ if (ext === '.js' || ext === '.json') {
+ // eslint-disable-next-line import/no-dynamic-require, global-require
+ return require(path.join(process.cwd(), arg))
+ }
+
+ return JSON.parse(arg)
} catch (error) {
exitError(
- `"${name}" is not valid, please specify a file or use inline JSON.`,
+ `"${name}" is not valid, please specify a valid file or use a inline JSON.`,
)
return null
}
diff --git a/packages/cli/src/index.test.js b/packages/cli/src/index.test.js
index 6c9ba628..e557c327 100644
--- a/packages/cli/src/index.test.js
+++ b/packages/cli/src/index.test.js
@@ -100,14 +100,14 @@ describe('cli', () => {
it('should support --svgo-config as json', async () => {
const result = await cli(
- `--svgo-config '{"plugins": [{"removeTitle": false}]}' __fixtures__/simple/file.svg`,
+ `--svgo-config '{"plugins":[{"name":"preset-default","params":{"overrides":{"removeTitle":false}}}]}' __fixtures__/simple/file.svg`,
)
expect(result).toMatchSnapshot()
}, 10000)
it('should support --svgo-config as file', async () => {
const result = await cli(
- `--svgo-config __fixtures__/withSvgoYml/.svgo.json __fixtures__/simple/file.svg`,
+ `--svgo-config __fixtures__/withSvgoConfig/svgo.config.js __fixtures__/simple/file.svg`,
)
expect(result).toMatchSnapshot()
}, 10000)
diff --git a/packages/core/src/__fixtures__/svgo/.svgo.yml b/packages/core/src/__fixtures__/svgo/.svgo.yml
deleted file mode 100644
index 821113d8..00000000
--- a/packages/core/src/__fixtures__/svgo/.svgo.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-plugins:
- - removeDesc: false
diff --git a/packages/core/src/__fixtures__/svgo/svgo.config.js b/packages/core/src/__fixtures__/svgo/svgo.config.js
new file mode 100644
index 00000000..e414abb0
--- /dev/null
+++ b/packages/core/src/__fixtures__/svgo/svgo.config.js
@@ -0,0 +1,12 @@
+module.exports = {
+ plugins: [
+ {
+ name: 'preset-default',
+ params: {
+ overrides: {
+ removeDesc: false,
+ },
+ },
+ },
+ ]
+}
\ No newline at end of file
diff --git a/packages/core/src/__snapshots__/convert.test.js.snap b/packages/core/src/__snapshots__/convert.test.js.snap
index 0b30523e..2b1ca4c7 100644
--- a/packages/core/src/__snapshots__/convert.test.js.snap
+++ b/packages/core/src/__snapshots__/convert.test.js.snap
@@ -13,7 +13,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -36,7 +36,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -59,7 +59,7 @@ function SvgComponent() {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -88,7 +88,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -111,7 +111,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -135,7 +135,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -159,7 +159,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -183,7 +183,7 @@ function SvgComponent() {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -213,7 +213,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -243,7 +243,7 @@ function SvgComponent(props, svgRef) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -268,7 +268,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -282,7 +282,7 @@ exports[`convert config should support options {"prettier":false} 1`] = `
"import * as React from \\"react\\";
function SvgComponent(props) {
- return ;
+ return ;
}
export default SvgComponent;"
@@ -307,7 +307,7 @@ function SvgComponent(props, svgRef) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -331,7 +331,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -354,7 +354,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -384,7 +384,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -451,7 +451,7 @@ function SvgComponent({ title, titleId, ...props }) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -505,7 +505,7 @@ function SvgComponent(props) {
fillRule=\\"evenodd\\"
strokeLinecap=\\"square\\"
>
-
+
)
@@ -528,10 +528,20 @@ function SvgComponent(props) {
{...props}
>
-
+
@@ -599,9 +617,8 @@ function SvgComponent(props) {
strokeLinecap=\\"square\\"
>
-
+
-
)
@@ -616,12 +633,23 @@ exports[`convert should remove null characters 1`] = `
function SvgComponent(props) {
return (
-