From d91aea4ad3ec099adfc842a84481be3c444878d5 Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Tue, 11 Jun 2024 22:39:24 +0100 Subject: [PATCH] fix: add alias of removeScriptElement to removeScripts --- lib/svgo.js | 29 ++++++++++++++++++++++++----- lib/version.js | 2 +- package.json | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/svgo.js b/lib/svgo.js index ba2385288..f63eed345 100644 --- a/lib/svgo.js +++ b/lib/svgo.js @@ -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.`); } @@ -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.`); } diff --git a/lib/version.js b/lib/version.js index 0207178e2..141e8d9be 100644 --- a/lib/version.js +++ b/lib/version.js @@ -1,2 +1,2 @@ /** Version of SVGO. */ -export const VERSION = '4.0.0-rc.0'; +export const VERSION = '4.0.0-rc.1'; diff --git a/package.json b/package.json index 4092c056f..c4b90806a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "packageManager": "yarn@3.8.2", "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",