Skip to content

Commit

Permalink
fix: add alias of removeScriptElement to removeScripts
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed Jun 11, 2024
1 parent 7593b32 commit d91aea4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
29 changes: 24 additions & 5 deletions lib/svgo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,34 @@ import { invokePlugins } from './svgo/plugins.js';
import { encodeSVGDatauri } from './svgo/tools.js';
import { VERSION } from './version.js';

const pluginsMap = {};
/**
* @typedef {import('./svgo.js').BuiltinPluginOrPreset<?, ?>} BuiltinPluginOrPreset
*/

const pluginsMap = new Map();
for (const plugin of builtin) {
pluginsMap[plugin.name] = plugin;
pluginsMap.set(plugin.name, plugin);
}

/**
* @param {string} name
* @returns {BuiltinPluginOrPreset}
*/
function getPlugin(name) {
if (name === 'removeScriptElement') {
console.warn(
'Warning: removeScriptElement has been renamed to removeScripts, please update your SVGO config',
);
return pluginsMap.get('removeScripts');
}

return pluginsMap.get(name);
}

const resolvePluginConfig = (plugin) => {
if (typeof plugin === 'string') {
// resolve builtin plugin specified as string
const builtinPlugin = pluginsMap[plugin];
const builtinPlugin = getPlugin(plugin);
if (builtinPlugin == null) {
throw Error(`Unknown builtin plugin "${plugin}" specified.`);
}
Expand All @@ -25,13 +44,13 @@ const resolvePluginConfig = (plugin) => {
}
if (typeof plugin === 'object' && plugin != null) {
if (plugin.name == null) {
throw Error(`Plugin name should be specified`);
throw Error(`Plugin name must be specified`);
}
// use custom plugin implementation
let fn = plugin.fn;
if (fn == null) {
// resolve builtin plugin implementation
const builtinPlugin = pluginsMap[plugin.name];
const builtinPlugin = getPlugin(plugin.name);
if (builtinPlugin == null) {
throw Error(`Unknown builtin plugin "${plugin.name}" specified.`);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/** Version of SVGO. */
export const VERSION = '4.0.0-rc.0';
export const VERSION = '4.0.0-rc.1';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"packageManager": "[email protected]",
"name": "svgo",
"version": "4.0.0-rc.0",
"version": "4.0.0-rc.1",
"description": "SVGO is a Node.js library and command-line application for optimizing vector images.",
"license": "MIT",
"type": "module",
Expand Down

0 comments on commit d91aea4

Please sign in to comment.