mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Drop extendDefaultPlugins
This commit is contained in:
@ -4,13 +4,8 @@ const os = require('os');
|
||||
const fs = require('fs');
|
||||
const { pathToFileURL } = require('url');
|
||||
const path = require('path');
|
||||
const {
|
||||
extendDefaultPlugins,
|
||||
optimize: optimizeAgnostic,
|
||||
createContentItem,
|
||||
} = require('./svgo.js');
|
||||
const { optimize: optimizeAgnostic, createContentItem } = require('./svgo.js');
|
||||
|
||||
exports.extendDefaultPlugins = extendDefaultPlugins;
|
||||
exports.createContentItem = createContentItem;
|
||||
|
||||
const importConfig = async (configFile) => {
|
||||
|
@ -1,18 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
defaultPlugins,
|
||||
resolvePluginConfig,
|
||||
extendDefaultPlugins,
|
||||
} = require('./svgo/config.js');
|
||||
const { defaultPlugins, resolvePluginConfig } = require('./svgo/config.js');
|
||||
const { parseSvg } = require('./parser.js');
|
||||
const { stringifySvg } = require('./stringifier.js');
|
||||
const { invokePlugins } = require('./svgo/plugins.js');
|
||||
const JSAPI = require('./svgo/jsAPI.js');
|
||||
const { encodeSVGDatauri } = require('./svgo/tools.js');
|
||||
|
||||
exports.extendDefaultPlugins = extendDefaultPlugins;
|
||||
|
||||
const optimize = (input, config) => {
|
||||
if (config == null) {
|
||||
config = {};
|
||||
|
@ -57,42 +57,6 @@ const pluginsOrder = [
|
||||
const defaultPlugins = pluginsOrder.filter((name) => pluginsMap[name].active);
|
||||
exports.defaultPlugins = defaultPlugins;
|
||||
|
||||
const extendDefaultPlugins = (plugins) => {
|
||||
console.warn(
|
||||
'\n"extendDefaultPlugins" utility is deprecated.\n' +
|
||||
'Use "preset-default" plugin with overrides instead.\n' +
|
||||
'For example:\n' +
|
||||
`{\n` +
|
||||
` name: 'preset-default',\n` +
|
||||
` params: {\n` +
|
||||
` overrides: {\n` +
|
||||
` // customize plugin options\n` +
|
||||
` convertShapeToPath: {\n` +
|
||||
` convertArcs: true\n` +
|
||||
` },\n` +
|
||||
` // disable plugins\n` +
|
||||
` convertPathData: false\n` +
|
||||
` }\n` +
|
||||
` }\n` +
|
||||
`}\n`
|
||||
);
|
||||
const extendedPlugins = pluginsOrder.map((name) => ({
|
||||
name,
|
||||
active: pluginsMap[name].active,
|
||||
}));
|
||||
for (const plugin of plugins) {
|
||||
const resolvedPlugin = resolvePluginConfig(plugin);
|
||||
const index = pluginsOrder.indexOf(resolvedPlugin.name);
|
||||
if (index === -1) {
|
||||
extendedPlugins.push(plugin);
|
||||
} else {
|
||||
extendedPlugins[index] = plugin;
|
||||
}
|
||||
}
|
||||
return extendedPlugins;
|
||||
};
|
||||
exports.extendDefaultPlugins = extendDefaultPlugins;
|
||||
|
||||
const resolvePluginConfig = (plugin) => {
|
||||
let configParams = {};
|
||||
if (typeof plugin === 'string') {
|
||||
|
@ -1,9 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
resolvePluginConfig,
|
||||
extendDefaultPlugins,
|
||||
} = require('../../lib/svgo/config.js');
|
||||
const { resolvePluginConfig } = require('../../lib/svgo/config.js');
|
||||
|
||||
describe('config', function () {
|
||||
describe('extend config with object', function () {
|
||||
@ -123,54 +120,6 @@ describe('config', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('allows to extend default plugins list', () => {
|
||||
const extendedPlugins = extendDefaultPlugins([
|
||||
{
|
||||
name: 'customPlugin',
|
||||
fn: () => {},
|
||||
},
|
||||
{
|
||||
name: 'removeAttrs',
|
||||
params: { atts: ['aria-label'] },
|
||||
},
|
||||
{
|
||||
name: 'cleanupIDs',
|
||||
params: { remove: false },
|
||||
},
|
||||
]);
|
||||
const removeAttrsIndex = extendedPlugins.findIndex(
|
||||
(item) => item.name === 'removeAttrs'
|
||||
);
|
||||
const cleanupIDsIndex = extendedPlugins.findIndex(
|
||||
(item) => item.name === 'cleanupIDs'
|
||||
);
|
||||
it('should preserve internal plugins order', () => {
|
||||
expect(removeAttrsIndex).toEqual(41);
|
||||
expect(cleanupIDsIndex).toEqual(11);
|
||||
});
|
||||
it('should activate inactive by default plugins', () => {
|
||||
const removeAttrsPlugin = resolvePluginConfig(
|
||||
extendedPlugins[removeAttrsIndex]
|
||||
);
|
||||
const cleanupIDsPlugin = resolvePluginConfig(
|
||||
extendedPlugins[cleanupIDsIndex]
|
||||
);
|
||||
expect(removeAttrsPlugin.active).toEqual(true);
|
||||
expect(cleanupIDsPlugin.active).toEqual(true);
|
||||
});
|
||||
it('should leave not extended inactive plugins to be inactive', () => {
|
||||
const inactivePlugin = resolvePluginConfig(
|
||||
extendedPlugins.find((item) => item.name === 'addClassesToSVGElement')
|
||||
);
|
||||
expect(inactivePlugin.active).toEqual(false);
|
||||
});
|
||||
it('should put custom plugins in the end', () => {
|
||||
expect(extendedPlugins[extendedPlugins.length - 1].name).toEqual(
|
||||
'customPlugin'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function getPlugin(name, plugins) {
|
||||
|
Reference in New Issue
Block a user