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

feat: expose builtin plugins #2027

Merged
merged 1 commit into from
Jun 9, 2024
Merged

Conversation

SethFalco
Copy link
Member

Exposes a new property called builtinPlugins. This is intended to cover use cases where clients imported/required the list of available plugins or the default preset.

If you import/require the array of built-in plugins, or a single plugin during runtime, this is now a top-level exported member instead:

// builtin.mjs - get an array of all built-in plugins
- import { builtin } from 'svgo/lib/builtin';
+ import { builtinPlugins } from 'svgo'

// plugin.mjs - get a single plugin
- import presetDefault from 'svgo/plugins/preset-default';
+ import { builtinPlugins } from 'svgo';
+ const prefixDefault = builtinPlugins.find(plugin => plugin.name === 'preset-default');

// plugin-map.mjs - get all plugins as a map using the plugin name as a key
import { builtinPlugins } from 'svgo';
const pluginMap = builtinPlugins.reduce((acc, val) => acc.set(val.name, val), new Map());
const prefixDefault = pluginMap.get('preset-default');

This also introduces the proposal from:

Plugins may now export two more properties, isPreset and plugins, both only defined for presets such as preset-default. This is aimed at client developers rather than end-users, and allows them to check if a plugin is a preset and get the plugins in a preset in the order they they are invoked.

@SethFalco SethFalco merged commit 0c13740 into svg:main Jun 9, 2024
10 checks passed
@SethFalco SethFalco deleted the feat/expose-builtin branch June 9, 2024 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant