-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
latest slash path is been ignored #438
Comments
Yes, this behaviour has changed to reflect the results of the |
Closing now, please reply / re-open if you have doubts or questions! |
Sorry for the delay. /* does not work as well sailor@spock:/tmp$ minify --match '\.(css|html|js|json)$' -sarp 'www/dev/*' -o 'www/hml/'
ERROR: stat www/dev/*: no such file or directory
sailor@spock:/tmp$ ll www/dev/
total 116
drwxrwxr-x 3 sailor sailor 100 Out 4 15:05 ./
drwxrwxr-x 4 sailor sailor 80 Out 4 15:08 ../
-rw-r--r-- 1 sailor sailor 7098 Out 4 15:04 index.html
drwxrwxr-x 2 sailor sailor 80 Out 4 15:05 sub/
-rw-r--r-- 1 sailor sailor 106720 Out 4 15:05 sys.js
sailor@spock:/tmp$ ll www/hml/
total 0
drwxrwxr-x 2 sailor sailor 40 Out 4 15:06 ./
drwxrwxr-x 4 sailor sailor 80 Out 4 15:08 ../
|
What shell are you using? |
sailor@spock:/tmp$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.7 LTS"
sailor@spock:/tmp$ echo $0
-bash
sailor@spock:/tmp$ bash --version
GNU bash, versão 4.3.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
Licença GPLv3+: GNU GPL versão 3 ou posterior <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. |
Sorry, you need to remove the quotes around |
should work |
Nope sailor@spock:/tmp$ ll www/dev/
total 116
drwxrwxr-x 3 sailor sailor 100 Out 4 16:00 ./
drwxrwxr-x 4 sailor sailor 80 Out 4 16:02 ../
-rw-rw-r-- 1 sailor sailor 7098 Out 4 16:01 index.html
drwxrwxr-x 2 sailor sailor 60 Out 4 16:01 sub/
-rw-rw-r-- 1 sailor sailor 106720 Out 4 16:01 sys.js
$ minify --match '\.(css|html|js|json)$' -sarp www/dev/* -o www/hml/
2021-10-04 16:01:43.955863984 -0300 -03 2021-10-04 16:01:20.871933588 -0300 -03
2021-10-04 16:02:16.779764968 -0300 -03 2021-10-04 16:01:43.955863984 -0300 -03
2021-10-04 16:02:16.779764968 -0300 -03 2021-10-04 16:01:36.875885335 -0300 -03
sailor@spock:/tmp$ ll www/hml/
total 0
drwxrwxr-x 4 sailor sailor 80 Out 4 16:02 ./
drwxrwxr-x 4 sailor sailor 80 Out 4 16:02 ../
drwxrwxr-x 2 sailor sailor 80 Out 4 16:02 dev/
drwxrwxr-x 2 sailor sailor 60 Out 4 16:02 sub/ It's working in the sence it is minifying, but it is creating the dev subfolder inside the hml and moving files there and, yet, the sub folder is not going inside dev, it's gooing to the hml root. Edit: I believe the behavior with folders (sub) is the right one, not the behavior of files that is creating a new folder with the same name of the source. |
Yes it's making complete sense! I've pushed out a fix that hopefully works well (there are many edge-cases), please let me know how it goes. |
I've made a little test while struggling to use minify to work in-place both with recurse and with single-files. Behaviour also changes between versions. The only workaround I found to work reliably across versions and use-cases, is to Here's the self-contained test, with results for v2.12.8 (macOS, via the minify Homebrew tap) and v2.12.4 (Debian bookworm): #!/bin/sh
# Test running minify with various input/output directory combinations with
# the intent to minify the input file in place.
# Test both `--recurse` and single-file invocations via the `find` command.
#
# Put this script inside a subdirectory of a new empty directory, e.g.
# <home>/my-test/script/minify-tests.sh
#
# `--output` trailing slash did not make any difference in these tests, though
# I added it to comply with the manual saying '(must have trailing slash)'.
#
# OK : input was minified (=became a one-liner) in-place
# FAIL: input was not minified or the result was saved in a new location
cd "$(dirname "$0")" || exit 1
cat > index.html <<EOF
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="referrer" content="no-referrer">
<link rel="canonical" href="https://example.com/">
<link rel="stylesheet" href="/assets/css/main.css">
<title>my page</title>
<body>
EOF
cat > site.webmanifest <<EOF
{
"name": "",
"icons": [
{ "src": "/assets/icon/touch-icon-192.png", "sizes": "192x192" },
{ "src": "/assets/icon/touch-icon-512.png", "sizes": "512x512" }
],
"background_color": "#ffffff",
"theme_color": "#ffffff",
"display": "standalone"
}
EOF
# Run minify in a absolute directory that is not a subdirectory of the current directory
rm -rf ../a1 ../a2 ../a3 ../a4 ../a5
# v2.12.8 (macOS) v2.12.4 (Debian)
# OK /FAIL OK /OK
input="$(realpath ../a1)"; mkdir -p "${input}"; cp index.html "${input}"; cp site.webmanifest "${input}"
minify "${input}" --recursive --output "${input}/../" --verbose
find "${input}" -name '*.webmanifest' -exec minify --type=json --output ./ --verbose {} \;
# OK /FAIL FAIL/OK
input="$(realpath ../a2)"; mkdir -p "${input}"; cp index.html "${input}"; cp site.webmanifest "${input}"
minify "${input}/" --recursive --output "${input}/" --verbose
find "${input}" -name '*.webmanifest' -exec minify --type=json --output ./ --verbose {} \;
# FAIL/FAIL FAIL/OK
input="$(realpath ../a3)"; mkdir -p "${input}"; cp index.html "${input}"; cp site.webmanifest "${input}"
minify "${input}" --recursive --output "${input}/" --verbose
find "${input}" -name '*.webmanifest' -exec minify --type=json --output ./ --verbose {} \;
# repeat test:
# FAIL/FAIL FAIL/FAIL NOTE: recurses into the output directory ending up with ../a3/a3/a3/index.html
minify "${input}" --recursive --output "${input}/" --verbose
find "${input}" -name '*.webmanifest' -exec minify --type=json --output ./ --verbose {} \;
# FAIL/FAIL FAIL/OK
input="$(realpath ../a4)"; mkdir -p "${input}"; cp index.html "${input}"; cp site.webmanifest "${input}"
minify "${input}" --recursive --output ./ --verbose
find "${input}" -name '*.webmanifest' -exec minify --type=json --output ./ --verbose {} \;
# OK /OK OK /OK
input="$(realpath ../a5)"; mkdir -p "${input}"; cp index.html "${input}"; cp site.webmanifest "${input}"
(
cd "${input}" || exit 1
minify . --recursive --output ./ --verbose
find . -name '*.webmanifest' -exec minify --type=json --output ./ --verbose {} \;
)
# Run minify in a subdirectory of the current directory
rm -rf r1 r2 r3 r4 r5
# OK /OK OK /OK
input='r1'; mkdir -p "${input}"; cp index.html "${input}"; cp site.webmanifest "${input}"
minify "${input}" --recursive --output "${input}/../" --verbose
find "${input}" -name '*.webmanifest' -exec minify --type=json --output ./ --verbose {} \;
# OK /OK FAIL/OK
input='r2'; mkdir -p "${input}"; cp index.html "${input}"; cp site.webmanifest "${input}"
minify "${input}/" --recursive --output "${input}/" --verbose
find "${input}" -name '*.webmanifest' -exec minify --type=json --output ./ --verbose {} \;
# FAIL/OK FAIL/OK
input='r3'; mkdir -p "${input}"; cp index.html "${input}"; cp site.webmanifest "${input}"
minify "${input}" --recursive --output "${input}/" --verbose
find "${input}" -name '*.webmanifest' -exec minify --type=json --output ./ --verbose {} \;
# OK /OK OK /OK
input='r4'; mkdir -p "${input}"; cp index.html "${input}"; cp site.webmanifest "${input}"
minify "${input}" --recursive --output ./ --verbose
find "${input}" -name '*.webmanifest' -exec minify --type=json --output ./ --verbose {} \;
# OK /OK OK /OK
input='r5'; mkdir -p "${input}"; cp index.html "${input}"; cp site.webmanifest "${input}"
(
cd "${input}" || exit 1
minify . --recursive --output ./ --verbose
find . -name '*.webmanifest' -exec minify --type=json --output ./ --verbose {} \;
)
rm -rf index.html site.webmanifest It's possible I've made some mistakes in registering results and even more possible that I had missed the right way to call |
Thank you for the extensive test, I will look into all cases. |
Thank you @tdewolff, much appreciated. Also thanks for making minify! |
I've pushed out a (possible) fix, including tests so this doesn't happen again. Please test for yourself as well, for me all your tests work as expected, including the a3/r3 recursive output. I used to model for equivalent functionality as |
Thank you very much for your updates. I'll make tests after next week. |
I retested with the latest Git version (sorry for the delay!). One improvement is that the target directories are no longer re-created in the current directory with tests a1, a2, a3. With a4 it's still created. On the other hand Also with the latest version, the original temp source file #!/bin/sh
# Posted to https://github.com/tdewolff/minify/issues/438 v2
# Test running minify with various input/output directory combinations with
# the intent to minify the input file in place.
# Test both `--recurse` and single-file invocations via the `find` command.
#
# Put this script inside a subdirectory of a new empty directory, e.g.
# <home>/my-test/script/minify-tests.sh
#
# `--output` trailing slash did not make any difference in these tests, though
# I added it to comply with the manual saying '(must have trailing slash)'.
#
# OK : input was minified (=became a one-liner) in-place
# FAIL: input was not minified or the result was saved in a new location
cd "$(dirname "$0")" || exit 1
initfiles() {
cat > index.html <<EOF
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="referrer" content="no-referrer">
<link rel="canonical" href="https://example.com/">
<link rel="stylesheet" href="/assets/css/main.css">
<title>my page</title>
<body>
EOF
cat > site.webmanifest <<EOF
{
"name": "",
"icons": [
{ "src": "/assets/icon/touch-icon-192.png", "sizes": "192x192" },
{ "src": "/assets/icon/touch-icon-512.png", "sizes": "512x512" }
],
"background_color": "#ffffff",
"theme_color": "#ffffff",
"display": "standalone"
}
EOF
}
minify=~/.go/bin/minify
# Run minify in a absolute directory that is not a subdirectory of the current directory
rm -rf ../a1 ../a2 ../a3 ../a4 ../a5
# v2.12.8 (macOS) v2.12.4 (Debian) dfaa2fcde
# OK /FAIL OK /OK OK /FAIL
input="$(pwd)/../a1"; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output "${input}/../" --verbose
find "${input}" -name '*.webmanifest' -exec "${minify}" --type=json --output ./ --verbose {} \;
# OK /FAIL FAIL/OK OK /FAIL
input="$(pwd)/../a2"; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}/" --recursive --output "${input}/" --verbose
find "${input}" -name '*.webmanifest' -exec "${minify}" --type=json --output ./ --verbose {} \;
# FAIL/FAIL FAIL/OK FAIL/FAIL
input="$(pwd)/../a3"; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output "${input}/" --verbose
find "${input}" -name '*.webmanifest' -exec "${minify}" --type=json --output ./ --verbose {} \;
# repeat test:
# FAIL/FAIL FAIL/FAIL FAIL/FAIL NOTE: recurses into the output directory ending up with ../a3/a3/a3/index.html
"${minify}" "${input}" --recursive --output "${input}/" --verbose
find "${input}" -name '*.webmanifest' -exec "${minify}" --type=json --output ./ --verbose {} \;
# FAIL/FAIL FAIL/OK FAIL/FAIL
input="$(pwd)/../a4"; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output ./ --verbose
find "${input}" -name '*.webmanifest' -exec "${minify}" --type=json --output ./ --verbose {} \;
# OK /OK OK /OK OK /OK
input="$(pwd)/../a5"; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
(
cd "${input}" || exit 1
"${minify}" . --recursive --output ./ --verbose
find . -name '*.webmanifest' -exec "${minify}" --type=json --output ./ --verbose {} \;
)
# Run minify in a subdirectory of the current directory
rm -rf r1 r2 r3 r4 r5
# OK /OK OK /OK OK /FAIL
input='r1'; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output "${input}/../" --verbose
find "${input}" -name '*.webmanifest' -exec "${minify}" --type=json --output ./ --verbose {} \;
# OK /OK FAIL/OK OK /FAIL
input='r2'; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}/" --recursive --output "${input}/" --verbose
find "${input}" -name '*.webmanifest' -exec "${minify}" --type=json --output ./ --verbose {} \;
# FAIL/OK (rec.) FAIL/OK OK /FAIL (rec.)
input='r3'; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output "${input}/" --verbose
find "${input}" -name '*.webmanifest' -exec "${minify}" --type=json --output ./ --verbose {} \;
# OK /OK OK /OK OK /FAIL
input='r4'; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output ./ --verbose
find "${input}" -name '*.webmanifest' -exec "${minify}" --type=json --output ./ --verbose {} \;
# OK /OK OK /OK OK /OK
input='r5'; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
(
cd "${input}" || exit 1
"${minify}" . --recursive --output ./ --verbose
find . -name '*.webmanifest' -exec "${minify}" --type=json --output ./ --verbose {} \;
)
rm -rf index.html site.webmanifest |
Thanks again for the in-depth analysis. What does The a3 recursive test is expected to work like that by the way, this is what happens with
Problem:
Otherwise, I see that the |
Sorry for the confusion! OK/FAIL means that the html input was correctly minified, but the What I'm looking for is a combination that works alike Indeed, the remaining issue is |
Looking into the Some options:
|
This was indeed the reason for the The filename extension is Even though the spec Also thanks for your suggestions! I started testing with This halved the amount of test cases. One remaining issue is that the Debian-supplied older v2.12.4 has Also Updated test script: #!/bin/sh
# Posted to https://github.com/tdewolff/minify/issues/438 v3
# Test running minify with various input/output directory combinations with
# the intent to minify the input file in place.
# Test both `--recurse` and single-file invocations via the `find` command.
#
# Put this script inside a subdirectory of a new empty directory, e.g.
# <home>/my-test/script/minify-tests.sh
#
# `--output` trailing slash did not make any difference in these tests, though
# I added it to comply with the manual saying '(must have trailing slash)'.
#
# OK : input was minified (=became a one-liner) in-place
# FAIL: input was not minified or the result was saved in a new location
cd "$(dirname "$0")" || exit 1
initfiles() {
cat > index.html <<EOF
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="referrer" content="no-referrer">
<link rel="canonical" href="https://example.com/">
<link rel="stylesheet" href="/assets/css/main.css">
<title>my page</title>
<body>
EOF
cat > site.webmanifest <<EOF
{
"name": "",
"icons": [
{ "src": "/assets/icon/touch-icon-192.png", "sizes": "192x192" },
{ "src": "/assets/icon/touch-icon-512.png", "sizes": "512x512" }
],
"background_color": "#ffffff",
"theme_color": "#ffffff",
"display": "standalone"
}
EOF
}
minify=~/.go/bin/minify
# Run minify in a absolute directory that is not a subdirectory of the current directory
rm -rf ../a1 ../a2 ../a3 ../a4 ../a5
# v2.12.8 (macOS) v2.12.4 (Debian) dfaa2fcde/v2.12.8-brew
# OK OK OK
input="$(pwd)/../a1"; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output "${input}/../" --verbose
"${minify}" "${input}" --recursive --match='.*\.webmanifest' --type=json --output "${input}/../" --verbose
# OK FAIL (rec) OK
input="$(pwd)/../a2"; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}/" --recursive --output "${input}/" --verbose
"${minify}" "${input}/" --recursive --match='.*\.webmanifest' --type=json --output "${input}/" --verbose
# FAIL FAIL FAIL
input="$(pwd)/../a3"; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output "${input}/" --verbose
"${minify}" "${input}" --recursive --match='.*\.webmanifest' --type=json --output "${input}/" --verbose
# repeat test:
# FAIL (rec.) FAIL (rec.) FAIL (rec.)
"${minify}" "${input}" --recursive --output "${input}/" --verbose
"${minify}" "${input}" --recursive --match='.*\.webmanifest' --type=json --output "${input}/" --verbose
# FAIL FAIL FAIL
input="$(pwd)/../a4"; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output ./ --verbose
"${minify}" "${input}" --recursive --match='.*\.webmanifest' --type=json --output ./ --verbose
# OK OK OK
input="$(pwd)/../a5"; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
(
cd "${input}" || exit 1
"${minify}" . --recursive --output ./ --verbose
"${minify}" . --recursive --match='.*\.webmanifest' --type=json --output ./ --verbose
)
# Run minify in a subdirectory of the current directory
rm -rf r1 r2 r3 r4 r5
# OK OK OK
input='r1'; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output "${input}/../" --verbose
"${minify}" "${input}" --recursive --match='.*\.webmanifest' --type=json --output "${input}/../" --verbose
# OK FAIL OK
input='r2'; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}/" --recursive --output "${input}/" --verbose
"${minify}" "${input}/" --recursive --match='.*\.webmanifest' --type=json --output "${input}/" --verbose
# FAIL (rec.) FAIL (rec.) FAIL (rec.)
input='r3'; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output "${input}/" --verbose
"${minify}" "${input}" --recursive --match='.*\.webmanifest' --type=json --output "${input}/" --verbose
# OK OK OK
input='r4'; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
"${minify}" "${input}" --recursive --output ./ --verbose
"${minify}" "${input}" --recursive --match='.*\.webmanifest' --type=json --output ./ --verbose
# OK OK OK
input='r5'; mkdir -p "${input}"; initfiles; cp index.html "${input}"; cp site.webmanifest "${input}"
(
cd "${input}" || exit 1
"${minify}" . --recursive --output ./ --verbose
"${minify}" . --recursive --match='.*\.webmanifest' --type=json --output ./ --verbose
)
rm -rf index.html site.webmanifest |
I tend to think an option to do every file operation in place would be At the moment it's almost unpredictable where something will be My use-case is a static website generator where the output is already Something like this would work without any doubts: $ minify . --inplace --recursive [...] (show error if an Perhaps also a Together with recognizing On more minor bit: Docs says that the output directory must end with A v4 of the test script with four new combinations: a6/r6/a7/r7. BTW, for now I settled with a1 and r4. This works with bookworm and |
I can't change the past, so I'm only concerned with getting the latest version bug-free. This issue has helped a lot in making sure the tool works correctly, but previous versions will naturally behave differently. It's not my intention to make all version behave the same, instead I want to make it work as expected. If you really need a solution that works for all versions, it might be better to use common bash tools, such as: The in-place option that you refer to is easily achieved by using the same input and output directories: Adding There really is a difference with Regarding Regarding your new tests, I'm not sure what your confusion is as both work as expected with the latest version. What did you expect?
I've added a commit, what remains is 1) adding more common web file format extensions, 2) support for Thanks for all the time and in-depth analysis!! |
…or index.*, otherwise use regexp as before; the glob pattern will match the final part of the path, see #438
Support for wildcards in |
No worries, me also thanks for your fixes and input, and taking your time to discuss this. I hope it will get better, especially once Debian upgrades minify to a newer version. Then I can move (back) to the clean [ If you ever consider an |
I've added support for the $ minify -r -o out/ --ext.scss=text/css --ext.xjs=js src/ or $ minify -r -o out/ --ext {scss:text/css xjs:js} src/ |
@tdewolff: Looks very cool! Just tested it, and this worked for me for the $ minify -r -o out/ --ext.webmanifest=json src/ Missing your commit ref 39b0c09 above, I just realized that minify now recognizes Thank you so much for these! |
I started to get this problem in newer versions:
(TBH, I still don't undestand this error, but I guess it is related, so, I' m showing it here)
But then, testing, if I remove the link from dev folder, and test it with files and directories only, I found this:
And that is wrong!
I wanted the dev folder content under hml folder and not dev folder under hml folder, because of that I used www/dev/ and not www/dev (notice the slash at the end).
It was working before, but the behavior changed somewhere in the way.
The text was updated successfully, but these errors were encountered: