Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/guide/structure-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ class FontAwesomeAsset extends AssetBundle
The above example defines an asset bundle for the ["fontawesome" package](https://fontawesome.com/). By specifying
the `only` publishing option, only the `fonts` and `css` subdirectories will be published.

Instead of patterns, you may list the published files and subdirectories explicitly in the `files` publishing option
(available since version 2.0.56). Each listed entry is published with all its contents, so this is the simplest way
to publish only the client side part of a package that also contains server side code:

```php
public $sourcePath = '@vendor/studio-42/elfinder';
public $publishOptions = [
'files' => ['css', 'img', 'js', 'sounds'],
];
```

The `files` option is an alternative to `only` and cannot be combined with `only` and `except`. Other options, like
`beforeCopy` and `afterCopy`, work with it as usual.

> Note: The name of the published directory does not depend on the publishing options. A directory that has already
been published is not updated when you change them, so remove it from the `@webroot/assets` directory (or use
the `forceCopy` option) after such a change.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved


### Bower and NPM Assets installation <span id="bower-npm-assets"></span>

Expand Down Expand Up @@ -532,6 +550,22 @@ With the above configuration, the asset manager will create a symbolic link to t
when it is being published. This is faster than file copying and can also ensure that the published assets are
always up-to-date.

The [[yii\web\AssetBundle::publishOptions|publishing options]] are honoured when the assets are linked:

- If an asset bundle uses the `only`, `except`, `beforeCopy` or `afterCopy` publishing options (also together with
`files`), or [[yii\web\AssetManager::beforeCopy|beforeCopy]] or [[yii\web\AssetManager::afterCopy|afterCopy]] of
the asset manager are set, the directory structure is recreated and each file that passes the filters is linked
separately, so that the excluded files are not accessible from the Web. Changes of the linked files are reflected
immediately, but a file added to the source path later is published only after the published directory is removed,
or on every publishing with [[yii\web\AssetManager::forceCopy|forceCopy]] enabled, which recreates the links.
- If an asset bundle uses only the `files` publishing option, each listed entry is linked as a whole, so files added
to a listed directory are published immediately. Note that files whose name starts with a dot are not skipped
inside a listed directory in this case.
- Otherwise, the whole source path is linked.

> Note: Before version 2.0.56, these publishing options were ignored when `linkAssets` was enabled and the whole
source path was published.


### Cache Busting <span id="cache-busting"></span>

Expand Down
2 changes: 2 additions & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Yii Framework 2 Change Log
2.0.56 under development
------------------------

- Bug #21150: Fix `yii\web\AssetManager` ignoring the `only`, `except`, `beforeCopy` and `afterCopy` publish options when `linkAssets` is enabled, which published files excluded by these options (rob006)
- Enh #21150: Add the `files` publish option to `yii\web\AssetManager::publish()` to publish only the listed files and directories of an asset bundle (rob006)
- Bug #21073: Fix `MultipartFormDataParser` boundary extraction when `Content-Type` has additional parameters (iliaal)
- Bug #21121: Fix `yii\validators\DateValidator` rejecting non-ASCII dates on PHP 8.4.27 and 8.5.12 (eluhr)
- Bug #21020: Fix duplicate `@return` annotation for `yii\db\ActiveRecord::hasOne()` (nazard)
Expand Down
10 changes: 10 additions & 0 deletions framework/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ Upgrade from Yii 2.0.55
Custom storage classes should override `sessionIdExists()` instead and drop that code. The default
implementation accepts every ID, so a class that does neither is not protected by strict mode.

* `yii\web\AssetManager` with `linkAssets` enabled now honours the `only`, `except`, `beforeCopy` and `afterCopy`
publish options (and the `beforeCopy` / `afterCopy` properties of the asset manager). Previously, the whole source
directory of an asset bundle was symlinked and these options were ignored. Now, the directory structure is
recreated and only the files that pass the filters are symlinked, one by one, so a file that was accessible only
because the filters were ignored is not published anymore. A file added to the source directory later is published
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
only after the published directory is removed (or with `forceCopy`, which now recreates the links in this case).
To symlink whole subdirectories, list them in the new `files` publish option instead of `only`.
When using a custom `hashCallback` that keeps the name of the published directory across the upgrade, the existing
symlink is replaced automatically on the next publish.

Upgrade from Yii 2.0.53
-----------------------

Expand Down
7 changes: 7 additions & 0 deletions framework/web/AssetBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ class AssetBundle extends BaseObject
/**
* @var PublishOptions the options to be passed to [[AssetManager::publish()]] when the asset bundle
* is being published. This property is used only when [[sourcePath]] is set.
*
* Note that the name of the published directory does not depend on these options, so an already published
* directory is not updated when they change. The change takes effect after the published directory is removed
* (or with the "forceCopy" option).
*
* @see AssetManager::publish() for the supported options.
* @see AssetManager::linkAssets for how the options are applied when the assets are symlinked.
*/
public $publishOptions = [];

Expand Down
Loading
Loading