-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load svgo version from project (#9969)
- Loading branch information
1 parent
f304cf5
commit f53f450
Showing
10 changed files
with
492 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 8 additions & 6 deletions
14
packages/core/integration-tests/test/integration/svgo-config/svgo.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
const { extendDefaultPlugins } = require('svgo'); | ||
|
||
module.exports = { | ||
plugins: extendDefaultPlugins([ | ||
plugins: [ | ||
{ | ||
name: 'removeComments', | ||
active: false | ||
name: 'preset-default', | ||
params: { | ||
overrides: { | ||
removeComments: false | ||
} | ||
} | ||
} | ||
]) | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// @flow | ||
export function detectSVGOVersion( | ||
config: any, | ||
): {|version: 3|} | {|version: 2, path: string|} { | ||
if (!config) { | ||
return {version: 3}; | ||
} | ||
|
||
// These options were removed in v2. | ||
if (config.full != null || config.svg2js != null) { | ||
return {version: 2, path: config.full != null ? '/full' : '/svg2js'}; | ||
} | ||
|
||
if (Array.isArray(config.plugins)) { | ||
// Custom plugins in v2 had additional (required) fields that don't exist anymore. | ||
let v2Plugin = config.plugins.findIndex( | ||
p => p?.type != null || (p?.fn && p?.params != null), | ||
); | ||
if (v2Plugin !== -1) { | ||
let field = config.plugins[v2Plugin].type != null ? 'type' : 'params'; | ||
return {version: 2, path: `/plugins/${v2Plugin}/${field}`}; | ||
} | ||
|
||
// the cleanupIDs plugin lost the prefix option in v3. | ||
let cleanupIdsIndex = config.plugins.findIndex( | ||
p => p?.name === 'cleanupIDs', | ||
); | ||
let cleanupIDs = | ||
cleanupIdsIndex !== -1 ? config.plugins[cleanupIdsIndex] : null; | ||
if (cleanupIDs?.params?.prefix != null) { | ||
return {version: 2, path: `/plugins/${cleanupIdsIndex}/params/prefix`}; | ||
} | ||
|
||
// Automatically migrate some options from SVGO 2 config files. | ||
config.plugins = config.plugins.filter(p => p?.active !== false); | ||
|
||
for (let i = 0; i < config.plugins.length; i++) { | ||
let p = config.plugins[i]; | ||
if (p === 'cleanupIDs') { | ||
config.plugins[i] = 'cleanupIds'; | ||
} | ||
|
||
if (p?.name === 'cleanupIDs') { | ||
config.plugins[i].name = 'cleanupIds'; | ||
} | ||
} | ||
} | ||
|
||
return {version: 3}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.