From 5f0a06dbb5cd4c0b2a375a3ad861f9fff18f4673 Mon Sep 17 00:00:00 2001 From: Razvan Grigore Date: Thu, 21 Mar 2024 06:12:23 +0200 Subject: [PATCH] Bower is deprecated since 2017, we should use npm instead. https://bower.io/blog/2017/how-to-migrate-away-from-bower/ While at it, let's use minified JS in production. Credits @robregonm --- .github/workflows/ci-node.yml | 2 +- composer.json | 8 +- composer.lock | 124 ++++++++++--------------- framework/composer.json | 19 +++- framework/validators/PunycodeAsset.php | 2 +- framework/web/JqueryAsset.php | 4 +- framework/widgets/MaskedInputAsset.php | 4 +- framework/widgets/PjaxAsset.php | 2 +- tests/js/tests/yii.activeForm.test.js | 2 +- tests/js/tests/yii.captcha.test.js | 2 +- tests/js/tests/yii.gridView.test.js | 2 +- tests/js/tests/yii.test.js | 4 +- tests/js/tests/yii.validation.test.js | 4 +- 13 files changed, 80 insertions(+), 99 deletions(-) diff --git a/.github/workflows/ci-node.yml b/.github/workflows/ci-node.yml index 3f49942b84a..0c317018ec1 100644 --- a/.github/workflows/ci-node.yml +++ b/.github/workflows/ci-node.yml @@ -23,7 +23,7 @@ jobs: run: composer update $DEFAULT_COMPOSER_FLAGS - name: Install JQuery `3.6.*@stable` for tests. - run: composer require "bower-asset/jquery:3.6.*@stable" + run: composer require "npm-asset/jquery:3.6.*@stable" - name: Install node.js. uses: actions/setup-node@v1 diff --git a/composer.json b/composer.json index 37a21f8ce9b..cd2c51e4d5e 100644 --- a/composer.json +++ b/composer.json @@ -75,10 +75,10 @@ "yiisoft/yii2-composer": "~2.0.4", "ezyang/htmlpurifier": "^4.6", "cebe/markdown": "~1.0.0 | ~1.1.0 | ~1.2.0", - "bower-asset/jquery": "3.7.*@stable | 3.6.*@stable | 3.5.*@stable | 3.4.*@stable | 3.3.*@stable | 3.2.*@stable | 3.1.*@stable | 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable", - "bower-asset/inputmask": "^5.0.8 ", - "bower-asset/punycode": "^2.2", - "bower-asset/yii2-pjax": "~2.0.1" + "npm-asset/jquery": "3.7.*@stable | 3.6.*@stable | 3.5.*@stable | 3.4.*@stable | 3.3.*@stable | 3.2.*@stable | 3.1.*@stable | 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable", + "npm-asset/inputmask": "^5.0.8 ", + "npm-asset/punycode": "^2.2", + "npm-asset/yii2-pjax": "~2.0.1" }, "require-dev": { "dms/phpunit-arraysubset-asserts": "^0.5", diff --git a/composer.lock b/composer.lock index e5d5f186df3..fc127bdb754 100644 --- a/composer.lock +++ b/composer.lock @@ -4,83 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7269257cc9e1f2b37d4e30c637bb226b", + "content-hash": "c1ab83d0eb50d7867b2af1a1966534ad", "packages": [ - { - "name": "bower-asset/inputmask", - "version": "5.0.8", - "source": { - "type": "git", - "url": "git@github.com:RobinHerbots/Inputmask.git", - "reference": "e0f39e0c93569c6b494c3a57edef2c59313a6b64" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/e0f39e0c93569c6b494c3a57edef2c59313a6b64", - "reference": "e0f39e0c93569c6b494c3a57edef2c59313a6b64" - }, - "require": { - "bower-asset/jquery": ">=1.7" - }, - "type": "bower-asset", - "license": [ - "http://opensource.org/licenses/mit-license.php" - ] - }, - { - "name": "bower-asset/jquery", - "version": "3.7.1", - "source": { - "type": "git", - "url": "https://github.com/jquery/jquery-dist.git", - "reference": "fde1f76e2799dd877c176abde0ec836553246991" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/jquery/jquery-dist/zipball/fde1f76e2799dd877c176abde0ec836553246991", - "reference": "fde1f76e2799dd877c176abde0ec836553246991" - }, - "type": "bower-asset", - "license": [ - "MIT" - ] - }, - { - "name": "bower-asset/punycode", - "version": "v2.3.1", - "source": { - "type": "git", - "url": "https://github.com/mathiasbynens/punycode.js.git", - "reference": "9e1b2cda98d215d3a73fcbfe93c62e021f4ba768" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mathiasbynens/punycode.js/zipball/9e1b2cda98d215d3a73fcbfe93c62e021f4ba768", - "reference": "9e1b2cda98d215d3a73fcbfe93c62e021f4ba768" - }, - "type": "bower-asset" - }, - { - "name": "bower-asset/yii2-pjax", - "version": "2.0.8", - "source": { - "type": "git", - "url": "git@github.com:yiisoft/jquery-pjax.git", - "reference": "a9298d57da63d14a950f1b94366a864bc62264fb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/a9298d57da63d14a950f1b94366a864bc62264fb", - "reference": "a9298d57da63d14a950f1b94366a864bc62264fb" - }, - "require": { - "bower-asset/jquery": ">=1.8" - }, - "type": "bower-asset", - "license": [ - "MIT" - ] - }, { "name": "cebe/markdown", "version": "1.2.1", @@ -206,6 +131,51 @@ }, "time": "2023-11-17T15:01:25+00:00" }, + { + "name": "npm-asset/inputmask", + "version": "5.0.8", + "dist": { + "type": "tar", + "url": "https://registry.npmjs.org/inputmask/-/inputmask-5.0.8.tgz" + }, + "type": "npm-asset", + "license": [ + "MIT" + ] + }, + { + "name": "npm-asset/jquery", + "version": "3.7.1", + "dist": { + "type": "tar", + "url": "https://registry.npmjs.org/jquery/-/jquery-3.7.1.tgz" + }, + "type": "npm-asset", + "license": [ + "MIT" + ] + }, + { + "name": "npm-asset/punycode", + "version": "2.3.1", + "dist": { + "type": "tar", + "url": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz" + }, + "type": "npm-asset", + "license": [ + "MIT" + ] + }, + { + "name": "npm-asset/yii2-pjax", + "version": "2.0.8", + "dist": { + "type": "tar", + "url": "https://registry.npmjs.org/yii2-pjax/-/yii2-pjax-2.0.8.tgz" + }, + "type": "npm-asset" + }, { "name": "yiisoft/yii2-composer", "version": "2.0.10", @@ -2353,7 +2323,7 @@ "aliases": [], "minimum-stability": "dev", "stability-flags": { - "bower-asset/jquery": 0 + "npm-asset/jquery": 0 }, "prefer-stable": true, "prefer-lowest": false, diff --git a/framework/composer.json b/framework/composer.json index 4934013b667..f507c830414 100644 --- a/framework/composer.json +++ b/framework/composer.json @@ -70,11 +70,17 @@ "yiisoft/yii2-composer": "~2.0.4", "ezyang/htmlpurifier": "^4.6", "cebe/markdown": "~1.0.0 | ~1.1.0 | ~1.2.0", - "bower-asset/jquery": "3.7.*@stable | 3.6.*@stable | 3.5.*@stable | 3.4.*@stable | 3.3.*@stable | 3.2.*@stable | 3.1.*@stable | 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable", - "bower-asset/inputmask": "^5.0.8 ", - "bower-asset/punycode": "^2.2", - "bower-asset/yii2-pjax": "~2.0.1" + "npm-asset/jquery": "3.7.*@stable | 3.6.*@stable | 3.5.*@stable | 3.4.*@stable | 3.3.*@stable | 3.2.*@stable | 3.1.*@stable | 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable", + "npm-asset/inputmask": "^5.0.8 ", + "npm-asset/punycode": "^2.2", + "npm-asset/yii2-pjax": "~2.0.1" }, + "repositories": [ + { + "type": "composer", + "url": "https://asset-packagist.org" + } + ], "autoload": { "psr-4": {"yii\\": ""} }, @@ -85,5 +91,10 @@ "branch-alias": { "dev-master": "2.0.x-dev" } + }, + "config": { + "allow-plugins": { + "yiisoft/yii2-composer": true + } } } diff --git a/framework/validators/PunycodeAsset.php b/framework/validators/PunycodeAsset.php index 781bed204a8..2c7ed84902b 100644 --- a/framework/validators/PunycodeAsset.php +++ b/framework/validators/PunycodeAsset.php @@ -18,7 +18,7 @@ */ class PunycodeAsset extends AssetBundle { - public $sourcePath = '@bower/punycode'; + public $sourcePath = '@npm/punycode'; public $js = [ 'punycode.js', ]; diff --git a/framework/web/JqueryAsset.php b/framework/web/JqueryAsset.php index 399f58481a5..03273df71a4 100644 --- a/framework/web/JqueryAsset.php +++ b/framework/web/JqueryAsset.php @@ -16,8 +16,8 @@ */ class JqueryAsset extends AssetBundle { - public $sourcePath = '@bower/jquery/dist'; + public $sourcePath = '@npm/jquery/dist'; public $js = [ - 'jquery.js', + YII_ENV_DEV ? 'jquery.js' : 'jquery.min.js' ]; } diff --git a/framework/widgets/MaskedInputAsset.php b/framework/widgets/MaskedInputAsset.php index dc7d15ff95c..84ec824c56c 100644 --- a/framework/widgets/MaskedInputAsset.php +++ b/framework/widgets/MaskedInputAsset.php @@ -20,9 +20,9 @@ */ class MaskedInputAsset extends AssetBundle { - public $sourcePath = '@bower/inputmask/dist'; + public $sourcePath = '@npm/inputmask/dist'; public $js = [ - 'jquery.inputmask.js', + YII_ENV_DEV ? 'jquery.inputmask.js' : 'jquery.inputmask.min.js', ]; public $depends = [ 'yii\web\YiiAsset', diff --git a/framework/widgets/PjaxAsset.php b/framework/widgets/PjaxAsset.php index f2940725a4b..6b77ff3ec66 100644 --- a/framework/widgets/PjaxAsset.php +++ b/framework/widgets/PjaxAsset.php @@ -18,7 +18,7 @@ */ class PjaxAsset extends AssetBundle { - public $sourcePath = '@bower/yii2-pjax'; + public $sourcePath = '@npm/yii2-pjax'; public $js = [ 'jquery.pjax.js', ]; diff --git a/tests/js/tests/yii.activeForm.test.js b/tests/js/tests/yii.activeForm.test.js index f79599b0747..363f23e85fb 100644 --- a/tests/js/tests/yii.activeForm.test.js +++ b/tests/js/tests/yii.activeForm.test.js @@ -8,7 +8,7 @@ var vm = require('vm'); describe('yii.activeForm', function () { var yiiActiveFormPath = 'framework/assets/yii.activeForm.js'; var yiiPath = 'framework/assets/yii.js'; - var jQueryPath = 'vendor/bower-asset/jquery/dist/jquery.js'; + var jQueryPath = 'vendor/npm-asset/jquery/dist/jquery.js'; var $; var $activeForm; diff --git a/tests/js/tests/yii.captcha.test.js b/tests/js/tests/yii.captcha.test.js index 9fdd1d1d95f..5d67b5ff228 100644 --- a/tests/js/tests/yii.captcha.test.js +++ b/tests/js/tests/yii.captcha.test.js @@ -8,7 +8,7 @@ var vm = require('vm'); describe('yii.captcha', function () { var yiiCaptchaPath = 'framework/assets/yii.captcha.js'; - var jQueryPath = 'vendor/bower-asset/jquery/dist/jquery.js'; + var jQueryPath = 'vendor/npm-asset/jquery/dist/jquery.js'; var $; var $captcha; var settings = { diff --git a/tests/js/tests/yii.gridView.test.js b/tests/js/tests/yii.gridView.test.js index 85f5b56637e..034986aa0c4 100644 --- a/tests/js/tests/yii.gridView.test.js +++ b/tests/js/tests/yii.gridView.test.js @@ -9,7 +9,7 @@ var vm = require('vm'); describe('yii.gridView', function () { var yiiGridViewPath = 'framework/assets/yii.gridView.js'; var yiiPath = 'framework/assets/yii.js'; - var jQueryPath = 'vendor/bower-asset/jquery/dist/jquery.js'; + var jQueryPath = 'vendor/npm-asset/jquery/dist/jquery.js'; var $; var $gridView; var settings = { diff --git a/tests/js/tests/yii.test.js b/tests/js/tests/yii.test.js index 0164dcf8606..4453479c0c1 100644 --- a/tests/js/tests/yii.test.js +++ b/tests/js/tests/yii.test.js @@ -20,8 +20,8 @@ var StringUtils = { describe('yii', function () { var yiiPath = 'framework/assets/yii.js'; - var jQueryPath = 'vendor/bower-asset/jquery/dist/jquery.js'; - var pjaxPath = 'vendor/bower-asset/yii2-pjax/jquery.pjax.js'; + var jQueryPath = 'vendor/npm-asset/jquery/dist/jquery.js'; + var pjaxPath = 'vendor/npm-asset/yii2-pjax/jquery.pjax.js'; var sandbox; var $; var yii; diff --git a/tests/js/tests/yii.validation.test.js b/tests/js/tests/yii.validation.test.js index 3fa08f45278..35d09aa2abf 100644 --- a/tests/js/tests/yii.validation.test.js +++ b/tests/js/tests/yii.validation.test.js @@ -18,7 +18,7 @@ var StringUtils = { }; var jsdom = require('mocha-jsdom'); -var punycode = require('../../../vendor/bower-asset/punycode/punycode'); +var punycode = require('../../../vendor/npm-asset/punycode/punycode'); var fs = require('fs'); var vm = require('vm'); @@ -76,7 +76,7 @@ describe('yii.validation', function () { } jsdom({ - src: fs.readFileSync('vendor/bower-asset/jquery/dist/jquery.js', 'utf-8') + src: fs.readFileSync('vendor/npm-asset/jquery/dist/jquery.js', 'utf-8') }); before(function () {