Skip to content

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

Open
@Bhoft

Description

@Bhoft

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions