fmarcia / uglifycss

Port of YUI CSS Compressor from Java to NodeJS
MIT License
284 stars 37 forks source link

Cannot convert URLs when input is from stdin #55

Closed mdr1384 closed 6 years ago

mdr1384 commented 6 years ago

Searched the issues "convert urls stdin" did not find anything...

This works:

uglifycss --convert-urls y/z/output x/input/a.css > y/z/output/a.min.css

This does not:

sass x/input/a.scss | uglifycss --convert-urls y/z/output > y/z/output/a.min.css

You get a JS error:

TypeError: Cannot read property 'slice' of undefined
    at convertRelativeUrls (/usr/local/lib/node_modules/uglifycss/uglifycss-lib.js:121:44)
    at Object.processString (/usr/local/lib/node_modules/uglifycss/uglifycss-lib.js:448:15)
    at Socket.<anonymous> (/usr/local/lib/node_modules/uglifycss/uglifycss:143:35)
    at emitNone (events.js:110:20)
    at Socket.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1059:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

I suppose it has to do with needing to know the dirname of the source file? Possibly extending the option e.g. --convert-urls-out y/z/output --convert-urls-in x/input would help?

Anyway the workaround (creating a temp file) is not going to work for me since x/input is not writable by the process doing the uglification, and you can't put the temp files in /tmp (or anywhere other than x/input) since that results in incorrect URLs.

fmarcia commented 6 years ago

You're right: without a path from a source file, there's no way to get a new relative path but I don't plan to add a new parameter to deal with this: like you said, the workaround is to create a temporary file. Sorry, it's not possible for you. Any way, I'll manage this situation by displaying an error message.