-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Do not overwrite already optimized (same size) files #1308
Comments
Hi @ofrias Instead of running repeatedly manually please use |
The problem can be reproduced even if you run svgo using multipass (which is what we do). This is not a workaround. |
Did you check the latest version? I landed a fix in https://github.com/svg/svgo/releases/tag/v2.0.1 |
I am trying, but I get this error:
I have already installed commander using npm ( |
Run only |
Thanks. I have tried with version 2.0.2 and all the files in the zip included in the original report, except from 1 (gq.svg) exhibit the same problem. Every time you run |
I'm not sure it's possible without reading of existing file. Reading may be quite expensive operation. |
Would it be possible then to generate the ids sequence always starting by the same number? Not doing this is what causes the file differences. |
Could you clarify which ids are you talking about? |
For example this file contains this tag:
The problem is that every time you run svgo on this file the id changes to a different value, first to |
Do you specify any config? |
No, just |
Just to clarify, are the repeated runs on the same source or are you checking in the output into git and running against that in future runs? I wasn't able to reproduce the mentioned |
The repeated runs are not on the same source. We run svgo against the output of previous runs. We have an images folder with svgs, on version control, and when we add new images we run svgo on the full folder to be sure that all images are optimized. |
@ofrias I figured as much :) So the issue of the I've only run against single SVGs personally, but perhaps the plugin is not resetting the counter it increments for generating IDs when it processes multiple SVG (although multipass on the same SVG made no difference for me either). |
Here you have the full test sequence with this file. In this case after 3 executions the file ends up being exactly the same as the original one. It looks like it goes through a never ending cycle.
|
I downloaded the zip, extracted the SVG into a temporary folder (downloads directory on my system, not Turned out that it was running my After taking care of that unexpected surprise of config crawling, I was getting deterministic results. Is it possible that there is some config file being read in accidentally for you as well? Perhaps try running your reproduction from another system or at least another directory higher up so that no config searching by SVGO is contributing to reproduction issues? If that isn't the problem, it would be difficult to pin-point the issue if no one can reproduce it. I suppose the next step would be running SVGO within a docker container as a way to isolate to a more common environment. |
In my case there is no svgo.config.js file up the tree. Has svgo dependencies on other npm packages? If this is the case, could you please share the versions of these other packages in your system? I am running it on Ubuntu 20.04, don't know if this can make any difference.
|
Are you familiar with Docker? It's pretty straight-forward to install, your distro should have a package for it. With Docker installed run the following command via CLI from the directory with the original
You should be able to reproduce that same output this way. It runs SVGO from within a containerized OS (Official NodeJS installed on Alpine Linux in this case), similar to a Virtual Machine if that helps. With the That might help you isolate the problem from your system as something doesn't seem right on it?
Are you running this within a project directory? Did you try in an isolated location instead? The Docker test above should help verify that your system environment is affecting the results for some reason.
I'm doubtful of that causing a problem, but it may not be invalid (eg Alpine Linux sometimes has compatibility issues). One could verify this just by taking the I am running Manjaro Linux myself. |
I have reproduced your same resutls with Docker, so there is no issue in this particular Docker setup. But I am running a standard Ubuntu 20.04, without any special configuration, and I have this issue. I am speculating, but maybe there is a variable not initialized, or something similar, that exhibits this behavior on Ubuntu 20.04 and not in the Docker setup. |
By the way, I can reproduce the same issue without using --multipass, so it is not related to this flag. |
Forgot to answer that we are not running the test on a project directory (tried with /tmp/ for example) We have even executed it on 2 different systems (both with Ubuntu 20.04), with the same results. |
Then the issue is specific to your system if the Docker image cannot reproduce it, you need to identify what is different. Did you try with an One workaround in the meantime would perhaps be to run SVGO through a Docker container when you need to. You can write a simple Dockerfile that extends a base image to provide SVGO by default, then instead of running a container with the command |
I think that the issue is affecting all Ubuntu 20.04 users, not just my system. As I told you we have reproduced it in 2 different PCs, and by 2 different people. We are already using a workaround, which is basically do not committing the files that we know have this issue. |
As I suggested, verifying via Ubuntu Docker image was probably sufficient. You're likely running the NodeJS package from Ubuntu? As 20.04 is a LTS release, it stayed with the 2018 release of NodeJS 10.x.x (with updates), Alternatively you can use the same version manager I use on my system (separate from the system package that I only have installed for the system to use with system packages, not for development). I use Here's a CLI snippet to test via a Docker image of Ubuntu 20.04. You can easily reproduce your issue by using # Start a docker image based off of Ubuntu 20.04
$ docker run --rm -it --volume "$PWD/Volaris.svg:/svg/Volaris.svg" --workdir "/svg" ubuntu:20.04
# Multi-line copy/paste command, installs 'asdf' version manager with nodejs version of our choosing, updates PATH env var explicitly to avoid reloading shell, then installs svgo
$ apt update && apt install --yes curl git gnupg \
&& git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.0 \
&& echo ". $HOME/.asdf/asdf.sh" >> .bashrc \
&& export PATH="/root/.asdf/shims:/root/.asdf/bin:/usr/local/sbin:~/.asdf/installs/nodejs/15.14.0/.npm/bin/:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
&& asdf plugin add nodejs \
&& asdf install nodejs 15.14.0 && asdf global nodejs 15.14.0 \
&& npm install -g svgo
# Run you command sequence here as copy/paste or individual commands
$ cut -c116-121 Volaris.svg \
&& svgo Volaris.svg \
&& cut -c116-121 Volaris.svg You can change the NodeJS version by replacing the version number with whatever suites, no need to install
So while the 2.0 release in Feb 2021 mentions needing |
OK, thanks for your help. Then I understand that this is a bug of svgo on NodeJS 10.x.x. In my system:
If this is the case we prefer to stick to the versions provided by the OS as much as possible, so for the moment we will continue using the workaround until Ubuntu upgrades to a newer version of NodeJS. |
I don't follow Ubuntu much, but I would expect it updated to newer 10.x.x versions at the very least... You could get newer releases by using Ubuntu 20.10 or 21.04 from this month release. The next Ubuntu LTS to replace 20.04 will be one more year away at 22.04,that's quite a while a way. NodeJS is already at 15.x.x, 3 years of improvements. You also have the option of using the official Snap release. But using Docker is perfectly valid too as shown above, there are official Docker images from NodeJS on DockerHub (debian and alpine based), you can still be conservative with an LTS release of NodeJS if you like. There's also leveraging free CI services online like Github Actions. Configure a yaml file to tell Github to use Ubuntu 20.04 or newer with or without docker image to run nodejs (Github maintains a version they keep up to date for their Ubuntu images ensuring stability and security). Great for automated builds like this with SVGO whenever pushing to master or merging a PR. |
Not sure why, but indeed I can still reproduce the issue with Node.js v10.19.0 with the latest version of SVGO. However, since that's no longer a supported version, I'll just close the issue. ^-^' Thanks for debugging this meanwhile, and sorry it took so long to review this. |
Hello.
When I run svgo repeatedly over the same SVG file it is always altered, even if the resultant file size is the same. This seems to happen because the internal IDs are modified.
I attach several files which exhibit this problem.
mutant svgs.zip
This issue creates a problem when the files are in version control systems, or when their hash is used for something (for example for browser caching).
Thanks!
The text was updated successfully, but these errors were encountered: