Skip to content
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

Change AssetController to use relative path for conversion with yuicompressor #16088

Open
Bhoft opened this issue Apr 12, 2018 · 2 comments
Open
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug

Comments

@Bhoft
Copy link
Contributor

Bhoft commented Apr 12, 2018

The yuicompressor has the problem that "absolute paths" aren't working on Windows with the "current" version 2.4.8 for the output file (which is already 3 years old and it doesn't look like a newer release would happen anytime soon)

See this issue about this problem:
yui/yuicompressor#78

The Version 2.4.7 works without a problem but has of course issues which were fixed in the 2.4.8 release.
So it would be good that the 2.4.8 version of the yuicompressor would also work on Windows.

A solution "could" be that the -o parameter of the shell exec uses a relative path instead of an absolute.

I tried to set the webroot alias "relative", so instead of
Yii::setAlias('@webroot', __DIR__ . '/web');
to
Yii::setAlias('@webroot', './web');
in the "assets.php" file for assetbundle generation call yii asset assets.php config/assets-dev.php.

The compressed css is then generated but all 'url' inside the css are wrong, so images and fonts aren't correctly included..

If the -o parameter for the yuicompressor would use a relative path instead of an absolute the generated would work also Windows machines.

So instead of
'{to}' => escapeshellarg($outputFile),
use this line
'{to}' => escapeshellarg(substr($outputFile, strlen(Yii::getAlias('@app/')))),

on this line:
https://github.com/yiisoft/yii2/blob/master/framework/console/controllers/AssetController.php#L549

So that the to output path would be
-o "web/assets/css/all-temp.css"
instead of
-o "D:\wamp\www\yii2-app\web/assets/css/all-temp.css"

What steps will reproduce the problem?

create a asset bundle on console with yuicompressor version 2.4.8 on Windows.

What is the expected result?

a compressed css instead of an java exception.

What do you get instead?

java.io.FileNotFoundException: wampwwwyii2-app\web\assets\css\all-temp.css:\wamp\www\yii2-app\web\assets\css\all-temp.css.tmp (The filename, directory name, or volume label syntax is incorrect) at java.io.FileOutputStream.open0(Native Method) at java.io.FileOutputStream.open(Unknown Source)

Additional info

Q A
Yii version 2.0.15.1
PHP version 7.1.4
Operating system Win 7
@samdark samdark added type:bug Bug status:ready for adoption Feel free to implement this issue. labels Apr 13, 2018
@SilverFire
Copy link
Member

Thank you for the reported issue. Would you like to help up to fix this issue by submitting a pull request? We have contributors guide that is a good starting point. If you need any tip – let us know.

@yus-ham
Copy link
Contributor

yus-ham commented Apr 28, 2018

java.io.FileNotFoundException: wampwwwyii2-app\web\assets\css\all-temp... It seem there are missing the DIRECTORY_SEPARATOR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug
Projects
None yet
Development

No branches or pull requests

4 participants