From bb590b8928b26e9cc750f5887270c1fe138ba0f9 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sun, 2 Oct 2022 00:17:16 +0300 Subject: [PATCH] Drop extendDefaultPlugins --- lib/svgo-node.js | 7 +---- lib/svgo.js | 8 +----- lib/svgo/config.js | 36 -------------------------- test/config/_index.test.js | 53 +------------------------------------- 4 files changed, 3 insertions(+), 101 deletions(-) diff --git a/lib/svgo-node.js b/lib/svgo-node.js index 04087d52..47e5cf7d 100644 --- a/lib/svgo-node.js +++ b/lib/svgo-node.js @@ -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) => { diff --git a/lib/svgo.js b/lib/svgo.js index a2e1017d..0e958613 100644 --- a/lib/svgo.js +++ b/lib/svgo.js @@ -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 = {}; diff --git a/lib/svgo/config.js b/lib/svgo/config.js index 12301b65..08bbd186 100644 --- a/lib/svgo/config.js +++ b/lib/svgo/config.js @@ -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') { diff --git a/test/config/_index.test.js b/test/config/_index.test.js index 1028153b..e5a4af5a 100644 --- a/test/config/_index.test.js +++ b/test/config/_index.test.js @@ -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) {