From aa1c55b85121b47a4639cf8beb41691f4daf451e Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 3 Oct 2018 14:59:51 +0200 Subject: [PATCH] added asset PackageJsonVersionStrategy --- frontend/custom_version_strategy.rst | 5 +- reference/configuration/framework.rst | 101 +++++++++++++++++++++++++- templating.rst | 5 +- 3 files changed, 105 insertions(+), 6 deletions(-) diff --git a/frontend/custom_version_strategy.rst b/frontend/custom_version_strategy.rst index 746d53d971a..942b37a3f61 100644 --- a/frontend/custom_version_strategy.rst +++ b/frontend/custom_version_strategy.rst @@ -18,8 +18,9 @@ own version strategy. Symfony provides various cache busting implementations via the :ref:`version `, - :ref:`version_format `, and - :ref:`json_manifest_path ` + :ref:`version_format `, + :ref:`json_manifest_path ` and + :ref:`package_json_path ` configuration options. Creating your Own Asset Version Strategy diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index ff6c076c97e..417bbbb5822 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -40,6 +40,7 @@ Configuration * `base_path`_ * `base_urls`_ * `json_manifest_path`_ + * `package_json_path`_ * `packages`_ * `version_format`_ * `version_strategy`_ @@ -1116,6 +1117,7 @@ Each package can configure the following options: * :ref:`version ` * :ref:`version_format ` * :ref:`json_manifest_path ` +* :ref:`package_json_path ` .. _reference-framework-assets-version: .. _ref-framework-assets-version: @@ -1184,7 +1186,8 @@ option. .. note:: - This parameter cannot be set at the same time as ``version_strategy`` or ``json_manifest_path``. + This parameter cannot be set at the same time as + ``version_strategy``, ``json_manifest_path`` or ``package_json_path``. .. tip:: @@ -1317,7 +1320,7 @@ individually for each asset package: .. note:: - This parameter cannot be set at the same time as ``version`` or ``json_manifest_path``. + This parameter cannot be set at the same time as ``version``, ``json_manifest_path`` or ``package_json_path``. .. _reference-assets-json-manifest-path: .. _reference-templating-json-manifest-path: @@ -1415,6 +1418,100 @@ package: If you request an asset that is *not found* in the ``manifest.json`` file, the original - *unmodified* - asset path will be returned. + +package_json_path +.................. + +**type**: ``string`` **default**: ``null`` + +The file path to a ``package.json`` file containing a json with a version number +which is increased by using ``npm version patch --git-tag-version false`` at the +build time of the assets. + +This option can be set globally for all assets and individually for each asset +package: + +.. configuration-block:: + + .. code-block:: yaml + + # config/packages/framework.yaml + framework: + assets: + # this version is applied to every asset (including packages) + package_json_path: "%kernel.project_dir%/package.json" + packages: + foo_package: + # this package uses its own version (the default file is ignored) + package_json_path: "%kernel.project_dir%/assets/different/package.json" + bar_package: + # this package uses the global version (the default file is used) + base_path: '/images' + + .. code-block:: xml + + + + + + + + + + + + + + + + + .. code-block:: php + + // config/packages/framework.php + $container->loadFromExtension('framework', array( + 'assets' => array( + // this version is applied to every asset (including packages) + 'package_json_path' => '%kernel.project_dir%/package.json', + 'packages' => array( + 'foo_package' => array( + // this package uses its own version (the default file is ignored) + 'package_json_path' => '%kernel.project_dir%/assets/different/package.json', + ), + 'bar_package' => array( + // this package uses the global version (the default file is used) + 'base_path' => '/images', + ), + ), + ), + )); + +Example ``package.json`` file: + +.. code-block:: js + + { + "version": "1.2.3", + "scripts": { + "build": "npm run build:assets && npm run version:patch", + "build:assets": "...", + "version:patch": "npm version patch --git-tag-version false" + } + } + +.. note:: + + This parameter cannot be set at the same time as ``version`` or ``version_strategy``. + Additionally, this option cannot be nullified at the package scope if a global package.json + file is specified. + templating ~~~~~~~~~~ diff --git a/templating.rst b/templating.rst index 21df296f0fc..4dff0b4db98 100644 --- a/templating.rst +++ b/templating.rst @@ -660,8 +660,9 @@ being used and generating the correct paths accordingly. The ``asset()`` function supports various cache busting techniques via the :ref:`version `, - :ref:`version_format `, and - :ref:`json_manifest_path ` configuration options. + :ref:`version_format `, + :ref:`json_manifest_path ` and + :ref:`package_json_path ` configuration options. If you need absolute URLs for assets, use the ``absolute_url()`` Twig function as follows: