Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add alias of removeScriptElement to removeScripts #2033

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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