clean-css / clean-css-cli

The command line interface to clean-css CSS optimizer
MIT License
305 stars 17 forks source link

clean-css-cli does not work on Windows properly #3

Closed tssajo closed 7 years ago

tssajo commented 7 years ago

If you are on the Windows platform and the CSS file you are trying to minify is on a different drive letter, e.g.: drive F: instead of the default drive C: and you attempt to run the cleancss command with an absolute path pointing to the input file (as well as an absolute path to the output file) then clean-css-cli is trying to import something from an invalid path, see: 7d2991665c666f8d4940ed49060ac1e6

A directory or file name on Windows cannot contain the colon ( : ) character!

This issue is originally surfaced here: https://github.com/tssajo/Minify/issues/51

This is a regression introduced in clean-css-cli.

clean-css 3.x.x in the same situation worked just fine.

tssajo commented 7 years ago

In addition to the above: It also causes trouble if the path contains spaces. As you can see on the above screenshot, the original directory was "F:\Two Bad Mice..." So both the colon character after F is causing an invalid path and also the space after Two is making the path trimmed early as: "C:\WINDOWS\system32/F:/Two"

IMO the current working directory cannot just be concatenated with the source file's path at will. At least not on Windows.

jakubpawlowicz commented 7 years ago

@tssajo thanks for giving it a try - I'll try it locally on Windows and get back to you.

jakubpawlowicz commented 7 years ago

It's actually an API issue as well. Fix is coming!

jakubpawlowicz commented 7 years ago

I've just released 4.0.4 fixing handling spaces in paths, see ^ issue in API. Could you reinstall clean-css-cli and give it another try? It works fine on Windows 10 and Node 7 for me.

tssajo commented 7 years ago

@jakubpawlowicz I do not know why you closed this when it is definitely still broken! And I cannot even re-open... :( Please re-open this issue! Thanks!

The "spaces in path" issue was a 2nd issue, that one you fixed and that's great.

But the main issue was not with the spaces in path! The main issue occurs when you try to use cleancss on a file which is on a different driveletter than your current working directory.

For example: You are here: C:\Windows\system32 and you issue the following command: cleancss --skip-rebase -o "D:\Two Bad Mice\style.min.css" "D:\Two Bad Mice\style.css"

It still does not work! Please look at the result: cleancss_error

See how you incorrectly concatenate the path of the current working directory with the specified file's path? This is the problem: C:/Windows/system32/D:/Two Bad Mice/style.css Why the concatenation??? The file is NOT under the current working directory, it is under a different driveletter ( under drive D: ) BTW, this concatenated path is invalid on Windows, because a directory path cannot have a colon character in it.

This is the issue I originally reported here. Not handling spaces in paths properly was just an additional issue (maybe I should have reported that as a separate issue).

jakubpawlowicz commented 7 years ago

@tssajo I closed it because I tested the new version locally and it worked fine, see my local output on Node 7 and Win 10.

screen shot 2017-02-06 at 07 28 44

If it's not fixed we can reopen this issue, however, I don't see it happening anymore.

jakubpawlowicz commented 7 years ago

Oh, scratch that. I can see it still happens when rebasing is used via --output flag.

tssajo commented 7 years ago

@jakubpawlowicz Thanks for your answer!

So it was the output ( -o ) flag then. Good to know!

I'll try your updated version of clean-css tomorrow. Thanks, again!

jakubpawlowicz commented 7 years ago

So this should be fixed in 4.0.5. Works fine locally with -o option.

tssajo commented 7 years ago

I can confirm that the issue has been fixed with version 4.0.5

Thank you!

jakubpawlowicz commented 7 years ago

That's great 👍

morais099 commented 6 years ago

Hello @jakubpawlowicz , I'm having problems with clean-css-li version 4.1.11. I use Windows 10 64 bits and my files .css not be minified. You said that the problem was fixed in version 4.0.5, but it continues. The error that occurs is the same one mentioned by tssajo. You can help me?