Skip to content

Commit 3dd8f55

Browse files
authored
Merge pull request #65 from funbox/improve-config
Remove import of patched SVGO plugin from default config
2 parents 06e32ae + cdeb2fc commit 3dd8f55

File tree

7 files changed

+43
-11
lines changed

7 files changed

+43
-11
lines changed

.optimiztrc.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import removeUnknownsAndDefaults from './svgo/removeUnknownsAndDefaults.cjs';
2-
31
export default {
42
optimize: {
53
jpeg: {
@@ -75,11 +73,7 @@ export default {
7573
We want to remove useless parts of SVG, but to leave `stroke="none"`.
7674
For this purpose we use here a custom version of `removeUnknownsAndDefaults`.
7775
*/
78-
{
79-
name: 'removeUnknownsAndDefaults',
80-
...removeUnknownsAndDefaults,
81-
},
82-
76+
'removeUnknownsAndDefaultsPATCHED',
8377
'cleanupAttrs',
8478
'mergeStyles',
8579
'inlineStyles',

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 5.0.0 (19.05.2023)
4+
5+
Removed `removeOffCanvasPaths` plugin from SVGO config due to known bugs: [svg/svgo#1732](https://github.com/svg/svgo/issues/1732), [svg/svgo#1646](https://github.com/svg/svgo/issues/1646).
6+
7+
Removed import of `removeUnknownsAndDefaults` plugin from the default config to make it easy to redefine the config on the user side.
8+
9+
Check out [migration guide](./MIGRATION.md).
10+
11+
312
## 4.1.1 (27.02.2023)
413

514
Fixed installation and included the configuration file to the package.

MIGRATION.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Migration
22

3+
## 4.1.1 → 5.0.0
4+
5+
First, `removeOffCanvasPaths` SVGO plugin has been removed, so make sure that all your SVG files are optimized correctly by Optimizt v5.
6+
It's possible that you encounter structure changes in the SVGs code, but there should not be any visual changes.
7+
8+
Last, if you were using your own config file and monkey-patched import of `removeUnknownsAndDefaults` plugin, now you should not do it.
9+
Instead use string literal `'removeUnknownsAndDefaultsPATCHED'` in `optimize.svg.plugin` array of the config. Check out the default config to make sure that you're doing everything right.
10+
11+
312
## 3.1.2 → 4.0.0
413

514
Drop Node.js v12 support.

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import convert from './lib/convert.js';
33
import findConfig from './lib/findConfig.js';
44
import { enableVerbose } from './lib/log.js';
55
import optimize from './lib/optimize.js';
6+
import prepareConfig from './lib/prepareConfig.js';
67
import prepareFilePaths from './lib/prepareFilePaths.js';
78
import prepareOutputPath from './lib/prepareOutputPath.js';
89

910
export default async function optimizt({ paths, avif, webp, force, lossless, verbose, output, config }) {
1011
const configFilepath = config ? checkConfigPath(config) : findConfig();
1112
const configData = await import(configFilepath);
13+
const preparedConfig = prepareConfig(configData);
1214

1315
if (verbose) enableVerbose();
1416

@@ -20,14 +22,14 @@ export default async function optimizt({ paths, avif, webp, force, lossless, ver
2022
webp,
2123
force,
2224
output: prepareOutputPath(output),
23-
config: configData.default.convert,
25+
config: preparedConfig.convert,
2426
});
2527
} else {
2628
await optimize({
2729
paths: prepareFilePaths(paths, ['gif', 'jpeg', 'jpg', 'png', 'svg']),
2830
lossless,
2931
output: prepareOutputPath(output),
30-
config: configData.default.optimize,
32+
config: preparedConfig.optimize,
3133
});
3234
}
3335
}

lib/prepareConfig.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import removeUnknownsAndDefaults from '../svgo/removeUnknownsAndDefaults.cjs';
2+
3+
export default function prepareConfig(configData) {
4+
const svgoPlugins = configData.default.optimize?.svg?.plugins;
5+
6+
if (svgoPlugins) {
7+
const indexOfRemoveUnknownsAndDefaults = svgoPlugins.indexOf('removeUnknownsAndDefaultsPATCHED');
8+
9+
if (indexOfRemoveUnknownsAndDefaults !== -1) {
10+
svgoPlugins[indexOfRemoveUnknownsAndDefaults] = {
11+
name: 'removeUnknownsAndDefaults',
12+
...removeUnknownsAndDefaults,
13+
};
14+
}
15+
}
16+
17+
return configData.default;
18+
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@funboxteam/optimizt",
3-
"version": "4.1.1",
3+
"version": "5.0.0",
44
"description": "CLI image optimization tool",
55
"license": "MIT",
66
"author": "Andrey Warkentin (https://github.com/343dev)",

0 commit comments

Comments
 (0)