Skip to content

Commit

Permalink
fix: warn and do not crash on null plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed Sep 27, 2023
1 parent b15da27 commit dfdadc7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/svgo.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,22 @@ const optimize = (input, config) => {
for (let i = 0; i < maxPassCount; i += 1) {
info.multipassCount = i;
const ast = parseSvg(input, config.path);
/** @type {unknown[]|unknown} */
const plugins = config.plugins || ['preset-default'];
if (Array.isArray(plugins) === false) {
if (!Array.isArray(plugins)) {
throw Error(
"Invalid plugins list. Provided 'plugins' in config should be an array."
'malformed config, `plugins` property must be an array.\nSee more info here: https://github.com/svg/svgo#configuration'
);
}
const resolvedPlugins = plugins
.filter((plugin) => plugin != null)
.map(resolvePluginConfig);

if (resolvedPlugins.length < plugins.length) {
console.warn(
'Warning: plugins list includes null or undefined elements, these will be ignored.'
);
}
const resolvedPlugins = plugins.map(resolvePluginConfig);
const globalOverrides = {};
if (config.floatPrecision != null) {
globalOverrides.floatPrecision = config.floatPrecision;
Expand Down

0 comments on commit dfdadc7

Please sign in to comment.