From 99739998e701f4825fc75521f99da6a3aa4780a2 Mon Sep 17 00:00:00 2001 From: Krasnoperov Vitaliy Date: Wed, 20 Dec 2017 10:51:12 +0200 Subject: [PATCH 01/17] Fix that travis build --- .travis.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index e55eba6..3325341 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,11 @@ language: php -php: - - '5.3' - - '5.6' - - '7.0' - - '7.1' - - hhvm +matrix: + include: + - php: 5.3 + dist: precise + - php: 5.6 + - php: 7.0 + - php: 7.1 + - php: hhvm script: python tests/tests.py \ No newline at end of file From 69c0e5c6536e83e96bf82d2f82884f97ef95fa93 Mon Sep 17 00:00:00 2001 From: Oscar Reimer Date: Thu, 26 Jul 2018 15:13:46 +0200 Subject: [PATCH 02/17] Fix crash when used in composer.json's with branch alias set --- composer.lock | 324 ++++++++++++++--------------- src/Plugin.php | 9 +- tests/extra-with-branch-alias.json | 37 ++++ tests/tests.py | 5 + 4 files changed, 212 insertions(+), 163 deletions(-) create mode 100644 tests/extra-with-branch-alias.json diff --git a/composer.lock b/composer.lock index 0320979..d6ecbbb 100644 --- a/composer.lock +++ b/composer.lock @@ -9,16 +9,16 @@ "packages-dev": [ { "name": "composer/ca-bundle", - "version": "1.0.7", + "version": "1.1.1", "source": { "type": "git", "url": "https://github.com/composer/ca-bundle.git", - "reference": "b17e6153cb7f33c7e44eb59578dc12eee5dc8e12" + "reference": "d2c0a83b7533d6912e8d516756ebd34f893e9169" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/ca-bundle/zipball/b17e6153cb7f33c7e44eb59578dc12eee5dc8e12", - "reference": "b17e6153cb7f33c7e44eb59578dc12eee5dc8e12", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/d2c0a83b7533d6912e8d516756ebd34f893e9169", + "reference": "d2c0a83b7533d6912e8d516756ebd34f893e9169", "shasum": "" }, "require": { @@ -27,12 +27,9 @@ "php": "^5.3.2 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.5", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5", "psr/log": "^1.0", - "symfony/process": "^2.5 || ^3.0" - }, - "suggest": { - "symfony/process": "This is necessary to reliably check whether openssl_x509_parse is vulnerable on older php versions, but can be ignored on PHP 5.5.6+" + "symfony/process": "^2.5 || ^3.0 || ^4.0" }, "type": "library", "extra": { @@ -64,7 +61,7 @@ "ssl", "tls" ], - "time": "2017-03-06T11:59:08+00:00" + "time": "2018-03-29T19:57:20+00:00" }, { "name": "composer/composer", @@ -72,31 +69,34 @@ "source": { "type": "git", "url": "https://github.com/composer/composer.git", - "reference": "2e9dbb79ef63036090d01b07d005428e05c8a5fc" + "reference": "9bc578e24a32f265f01f46e389edb028a61e9a07" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/composer/zipball/2e9dbb79ef63036090d01b07d005428e05c8a5fc", - "reference": "2e9dbb79ef63036090d01b07d005428e05c8a5fc", + "url": "https://api.github.com/repos/composer/composer/zipball/9bc578e24a32f265f01f46e389edb028a61e9a07", + "reference": "9bc578e24a32f265f01f46e389edb028a61e9a07", "shasum": "" }, "require": { "composer/ca-bundle": "^1.0", "composer/semver": "^1.0", - "composer/spdx-licenses": "^1.0", + "composer/spdx-licenses": "^1.2", + "composer/xdebug-handler": "^1.1", "justinrainbow/json-schema": "^3.0 || ^4.0 || ^5.0", "php": "^5.3.2 || ^7.0", "psr/log": "^1.0", - "seld/cli-prompt": "^1.0", "seld/jsonlint": "^1.4", "seld/phar-utils": "^1.0", - "symfony/console": "^2.7 || ^3.0", - "symfony/filesystem": "^2.7 || ^3.0", - "symfony/finder": "^2.7 || ^3.0", - "symfony/process": "^2.7 || ^3.0" + "symfony/console": "^2.7 || ^3.0 || ^4.0", + "symfony/filesystem": "^2.7 || ^3.0 || ^4.0", + "symfony/finder": "^2.7 || ^3.0 || ^4.0", + "symfony/process": "^2.7 || ^3.0 || ^4.0" + }, + "conflict": { + "symfony/console": "2.8.38" }, "require-dev": { - "phpunit/phpunit": "^4.5 || ^5.0.5", + "phpunit/phpunit": "^4.8.35 || ^5.7", "phpunit/phpunit-mock-objects": "^2.3 || ^3.0" }, "suggest": { @@ -110,7 +110,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.5-dev" + "dev-master": "1.7-dev" } }, "autoload": { @@ -141,7 +141,7 @@ "dependency", "package" ], - "time": "2017-03-11 16:11:59" + "time": "2018-07-26T12:15:32+00:00" }, { "name": "composer/semver", @@ -207,23 +207,23 @@ }, { "name": "composer/spdx-licenses", - "version": "1.1.5", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/composer/spdx-licenses.git", - "reference": "96c6a07b05b716e89a44529d060bc7f5c263cb13" + "reference": "cb17687e9f936acd7e7245ad3890f953770dec1b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/spdx-licenses/zipball/96c6a07b05b716e89a44529d060bc7f5c263cb13", - "reference": "96c6a07b05b716e89a44529d060bc7f5c263cb13", + "url": "https://api.github.com/repos/composer/spdx-licenses/zipball/cb17687e9f936acd7e7245ad3890f953770dec1b", + "reference": "cb17687e9f936acd7e7245ad3890f953770dec1b", "shasum": "" }, "require": { "php": "^5.3.2 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.5 || ^5.0.5", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5", "phpunit/phpunit-mock-objects": "2.3.0 || ^3.0" }, "type": "library", @@ -264,29 +264,73 @@ "spdx", "validator" ], - "time": "2016-09-28T07:17:45+00:00" + "time": "2018-04-30T10:33:04+00:00" + }, + { + "name": "composer/xdebug-handler", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/composer/xdebug-handler.git", + "reference": "c919dc6c62e221fc6406f861ea13433c0aa24f08" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/c919dc6c62e221fc6406f861ea13433c0aa24f08", + "reference": "c919dc6c62e221fc6406f861ea13433c0aa24f08", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0", + "psr/log": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Composer\\XdebugHandler\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "John Stevenson", + "email": "john-stevenson@blueyonder.co.uk" + } + ], + "description": "Restarts a process without xdebug.", + "keywords": [ + "Xdebug", + "performance" + ], + "time": "2018-04-11T15:42:36+00:00" }, { "name": "justinrainbow/json-schema", - "version": "5.1.0", + "version": "5.2.7", "source": { "type": "git", "url": "https://github.com/justinrainbow/json-schema.git", - "reference": "48817e5f95c9d29e11513f12e43cc0223fa5eb6c" + "reference": "8560d4314577199ba51bf2032f02cd1315587c23" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/48817e5f95c9d29e11513f12e43cc0223fa5eb6c", - "reference": "48817e5f95c9d29e11513f12e43cc0223fa5eb6c", + "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/8560d4314577199ba51bf2032f02cd1315587c23", + "reference": "8560d4314577199ba51bf2032f02cd1315587c23", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^2.1", "json-schema/json-schema-test-suite": "1.2.0", - "phpdocumentor/phpdocumentor": "~2", - "phpunit/phpunit": "^4.8.22" + "phpunit/phpunit": "^4.8.35" }, "bin": [ "bin/validate-json" @@ -330,7 +374,7 @@ "json", "schema" ], - "time": "2017-02-22T03:28:16+00:00" + "time": "2018-02-14T22:26:30+00:00" }, { "name": "psr/log", @@ -379,73 +423,25 @@ ], "time": "2016-10-10T12:19:37+00:00" }, - { - "name": "seld/cli-prompt", - "version": "1.0.2", - "source": { - "type": "git", - "url": "https://github.com/Seldaek/cli-prompt.git", - "reference": "8cbe10923cae5bcd7c5a713f6703fc4727c8c1b4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Seldaek/cli-prompt/zipball/8cbe10923cae5bcd7c5a713f6703fc4727c8c1b4", - "reference": "8cbe10923cae5bcd7c5a713f6703fc4727c8c1b4", - "shasum": "" - }, - "require": { - "php": ">=5.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Seld\\CliPrompt\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be" - } - ], - "description": "Allows you to prompt for user input on the command line, and optionally hide the characters they type", - "keywords": [ - "cli", - "console", - "hidden", - "input", - "prompt" - ], - "time": "2016-04-18T09:31:41+00:00" - }, { "name": "seld/jsonlint", - "version": "1.6.0", + "version": "1.7.1", "source": { "type": "git", "url": "https://github.com/Seldaek/jsonlint.git", - "reference": "791f8c594f300d246cdf01c6b3e1e19611e301d8" + "reference": "d15f59a67ff805a44c50ea0516d2341740f81a38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/791f8c594f300d246cdf01c6b3e1e19611e301d8", - "reference": "791f8c594f300d246cdf01c6b3e1e19611e301d8", + "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/d15f59a67ff805a44c50ea0516d2341740f81a38", + "reference": "d15f59a67ff805a44c50ea0516d2341740f81a38", "shasum": "" }, "require": { "php": "^5.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" }, "bin": [ "bin/jsonlint" @@ -474,7 +470,7 @@ "parser", "validator" ], - "time": "2017-03-06T16:42:24+00:00" + "time": "2018-01-24T12:46:19+00:00" }, { "name": "seld/phar-utils", @@ -522,39 +518,44 @@ }, { "name": "symfony/console", - "version": "v3.2.6", + "version": "v4.1.2", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "28fb243a2b5727774ca309ec2d92da240f1af0dd" + "reference": "5c31f6a97c1c240707f6d786e7e59bfacdbc0219" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/28fb243a2b5727774ca309ec2d92da240f1af0dd", - "reference": "28fb243a2b5727774ca309ec2d92da240f1af0dd", + "url": "https://api.github.com/repos/symfony/console/zipball/5c31f6a97c1c240707f6d786e7e59bfacdbc0219", + "reference": "5c31f6a97c1c240707f6d786e7e59bfacdbc0219", "shasum": "" }, "require": { - "php": ">=5.5.9", - "symfony/debug": "~2.8|~3.0", + "php": "^7.1.3", "symfony/polyfill-mbstring": "~1.0" }, + "conflict": { + "symfony/dependency-injection": "<3.4", + "symfony/process": "<3.3" + }, "require-dev": { "psr/log": "~1.0", - "symfony/event-dispatcher": "~2.8|~3.0", - "symfony/filesystem": "~2.8|~3.0", - "symfony/process": "~2.8|~3.0" + "symfony/config": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/lock": "~3.4|~4.0", + "symfony/process": "~3.4|~4.0" }, "suggest": { - "psr/log": "For using the console logger", + "psr/log-implementation": "For using the console logger", "symfony/event-dispatcher": "", - "symfony/filesystem": "", + "symfony/lock": "", "symfony/process": "" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.2-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -581,42 +582,35 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2017-03-06T19:30:27+00:00" + "time": "2018-07-16T14:05:40+00:00" }, { - "name": "symfony/debug", - "version": "v3.2.6", + "name": "symfony/filesystem", + "version": "v4.1.2", "source": { "type": "git", - "url": "https://github.com/symfony/debug.git", - "reference": "b90c9f91ad8ac37d9f114e369042d3226b34dc1a" + "url": "https://github.com/symfony/filesystem.git", + "reference": "562bf7005b55fd80d26b582d28e3e10f2dd5ae9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/b90c9f91ad8ac37d9f114e369042d3226b34dc1a", - "reference": "b90c9f91ad8ac37d9f114e369042d3226b34dc1a", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/562bf7005b55fd80d26b582d28e3e10f2dd5ae9c", + "reference": "562bf7005b55fd80d26b582d28e3e10f2dd5ae9c", "shasum": "" }, "require": { - "php": ">=5.5.9", - "psr/log": "~1.0" - }, - "conflict": { - "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" - }, - "require-dev": { - "symfony/class-loader": "~2.8|~3.0", - "symfony/http-kernel": "~2.8|~3.0" + "php": "^7.1.3", + "symfony/polyfill-ctype": "~1.8" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.2-dev" + "dev-master": "4.1-dev" } }, "autoload": { "psr-4": { - "Symfony\\Component\\Debug\\": "" + "Symfony\\Component\\Filesystem\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -636,36 +630,36 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony Debug Component", + "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2017-02-18T17:28:00+00:00" + "time": "2018-05-30T07:26:09+00:00" }, { - "name": "symfony/filesystem", - "version": "v3.2.6", + "name": "symfony/finder", + "version": "v4.1.2", "source": { "type": "git", - "url": "https://github.com/symfony/filesystem.git", - "reference": "bc0f17bed914df2cceb989972c3b996043c4da4a" + "url": "https://github.com/symfony/finder.git", + "reference": "84714b8417d19e4ba02ea78a41a975b3efaafddb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/bc0f17bed914df2cceb989972c3b996043c4da4a", - "reference": "bc0f17bed914df2cceb989972c3b996043c4da4a", + "url": "https://api.github.com/repos/symfony/finder/zipball/84714b8417d19e4ba02ea78a41a975b3efaafddb", + "reference": "84714b8417d19e4ba02ea78a41a975b3efaafddb", "shasum": "" }, "require": { - "php": ">=5.5.9" + "php": "^7.1.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.2-dev" + "dev-master": "4.1-dev" } }, "autoload": { "psr-4": { - "Symfony\\Component\\Filesystem\\": "" + "Symfony\\Component\\Finder\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -685,39 +679,39 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony Filesystem Component", + "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2017-03-06T19:30:27+00:00" + "time": "2018-06-19T21:38:16+00:00" }, { - "name": "symfony/finder", - "version": "v3.2.6", + "name": "symfony/polyfill-ctype", + "version": "v1.8.0", "source": { "type": "git", - "url": "https://github.com/symfony/finder.git", - "reference": "92d7476d2df60cd851a3e13e078664b1deb8ce10" + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/92d7476d2df60cd851a3e13e078664b1deb8ce10", - "reference": "92d7476d2df60cd851a3e13e078664b1deb8ce10", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae", "shasum": "" }, "require": { - "php": ">=5.5.9" + "php": ">=5.3.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.2-dev" + "dev-master": "1.8-dev" } }, "autoload": { "psr-4": { - "Symfony\\Component\\Finder\\": "" + "Symfony\\Polyfill\\Ctype\\": "" }, - "exclude-from-classmap": [ - "/Tests/" + "files": [ + "bootstrap.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -725,31 +719,37 @@ "MIT" ], "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" } ], - "description": "Symfony Finder Component", + "description": "Symfony polyfill for ctype functions", "homepage": "https://symfony.com", - "time": "2017-02-21T09:12:04+00:00" + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2018-04-30T19:57:29+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.3.0", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4" + "reference": "3296adf6a6454a050679cde90f95350ad604b171" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/e79d363049d1c2128f133a2667e4f4190904f7f4", - "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", + "reference": "3296adf6a6454a050679cde90f95350ad604b171", "shasum": "" }, "require": { @@ -761,7 +761,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "1.8-dev" } }, "autoload": { @@ -795,29 +795,29 @@ "portable", "shim" ], - "time": "2016-11-14T01:06:16+00:00" + "time": "2018-04-26T10:06:28+00:00" }, { "name": "symfony/process", - "version": "v3.2.6", + "version": "v4.1.2", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "68bfa8c83f24c0ac04ea7193bcdcda4519f41892" + "reference": "1d1677391ecf00d1c5b9482d6050c0c27aa3ac3a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/68bfa8c83f24c0ac04ea7193bcdcda4519f41892", - "reference": "68bfa8c83f24c0ac04ea7193bcdcda4519f41892", + "url": "https://api.github.com/repos/symfony/process/zipball/1d1677391ecf00d1c5b9482d6050c0c27aa3ac3a", + "reference": "1d1677391ecf00d1c5b9482d6050c0c27aa3ac3a", "shasum": "" }, "require": { - "php": ">=5.5.9" + "php": "^7.1.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.2-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -844,7 +844,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2017-03-04T12:23:14+00:00" + "time": "2018-05-31T10:17:53+00:00" } ], "aliases": [], diff --git a/src/Plugin.php b/src/Plugin.php index bf241ac..3fb99fb 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -4,6 +4,7 @@ use Composer\Composer; use Composer\IO\IOInterface; +use Composer\Package\AliasPackage; use Composer\Package\CompletePackage; use Composer\Plugin\PluginInterface; @@ -13,6 +14,11 @@ public function activate(Composer $composer, IOInterface $io) { $package = $composer->getPackage(); + // If we have extra.branch-alias, package will be an instanceof RootAliasPackage instead of RootPackage + if ($package instanceof AliasPackage) { + $package = $package->getAliasOf(); + } + if ($package instanceof CompletePackage && in_array('--no-dev', $_SERVER['argv'], true)) { return; } @@ -34,6 +40,7 @@ public function activate(Composer $composer, IOInterface $io) foreach ($devScripts as $event => &$listeners) { $listeners = (array)$listeners; } - $package->setScripts(array_merge_recursive($package->getScripts(), $devScripts)); + + $package->setScripts(array_merge_recursive($package->getScripts(), $devScripts)); } } diff --git a/tests/extra-with-branch-alias.json b/tests/extra-with-branch-alias.json new file mode 100644 index 0000000..980cda6 --- /dev/null +++ b/tests/extra-with-branch-alias.json @@ -0,0 +1,37 @@ +{ + "name": "neronmoon/scriptsdev-test", + "description": "Scripts-dev behaviour for Composer", + "keywords": [ + "dev", + "scripts", + "composer", + "commands", + "commands execution" + ], + "homepage": "https://github.com/neronmoon/scriptsdev", + "type": "project", + "license": "MIT", + "authors": [ + { + "name": "Vitaliy Krasnoperov", + "email": "alistar.neron@gmail.com" + } + ], + "repositories": [ + { + "type": "path", + "url": "" + } + ], + "require": { + "neronmoon/scriptsdev": "*@dev" + }, + "extra": { + "branch-alias": { + "dev-master": "*-dev" + }, + "scripts-dev": { + "post-update-cmd": "echo SCRIPTSDEV RULEZ" + } + } +} \ No newline at end of file diff --git a/tests/tests.py b/tests/tests.py index 06cde99..d64ef84 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -3,6 +3,8 @@ def test(test, args=[], cmd=['composer', 'update', '-v'], clean_dir=True): + print "Testing:", test + working_dir = '/tmp/scriptsdev/' + test if clean_dir: @@ -38,6 +40,9 @@ def check_not(expect_not, actual): check('SCRIPTSDEV RULEZ', test('extra')) check_not('SCRIPTSDEV RULEZ', test('extra', ['--no-dev'])) +check('SCRIPTSDEV RULEZ', test('extra-with-branch-alias')) +check_not('SCRIPTSDEV RULEZ', test('extra-with-branch-alias', ['--no-dev'])) + check('SCRIPTSDEV RULEZ', test('legacy')) check_not('SCRIPTSDEV RULEZ', test('legacy', ['--no-dev'])) From 7c714bd9d681af6ee36bf576e3d17dd50a03d033 Mon Sep 17 00:00:00 2001 From: Oscar Reimer Date: Thu, 26 Jul 2018 15:17:42 +0200 Subject: [PATCH 03/17] Fixed mixed tabs and spaces --- src/Plugin.php | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 3fb99fb..72caf06 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -10,37 +10,39 @@ class Plugin implements PluginInterface { - public function activate(Composer $composer, IOInterface $io) - { - $package = $composer->getPackage(); + public function activate(Composer $composer, IOInterface $io) + { + $package = $composer->getPackage(); - // If we have extra.branch-alias, package will be an instanceof RootAliasPackage instead of RootPackage - if ($package instanceof AliasPackage) { + // If we have extra.branch-alias, package will be an instanceof RootAliasPackage instead of RootPackage + if ($package instanceof AliasPackage) { $package = $package->getAliasOf(); } - if ($package instanceof CompletePackage && in_array('--no-dev', $_SERVER['argv'], true)) { - return; - } + if ($package instanceof CompletePackage && in_array('--no-dev', $_SERVER['argv'], true)) { + return; + } - $devScripts = array(); - $config = json_decode(file_get_contents(getcwd() . '/composer.json'), true); - if (isset($config['scripts-dev']) && is_array($config['scripts-dev'])) { - $io->writeError("You're using deprecated way to define development-only scripts. + $devScripts = array(); + $config = json_decode(file_get_contents(getcwd().'/composer.json'), true); + if (isset($config['scripts-dev']) && is_array($config['scripts-dev'])) { + $io->writeError( + "You're using deprecated way to define development-only scripts. Please, move commands under `scripts-dev` directive into `extra` field. -See README.md for more details."); - $devScripts = array_merge_recursive($devScripts, $config['scripts-dev']); - } +See README.md for more details." + ); + $devScripts = array_merge_recursive($devScripts, $config['scripts-dev']); + } - $extra = $package->getExtra(); - if (isset($extra['scripts-dev']) && is_array($extra['scripts-dev'])) { - $devScripts = array_merge_recursive($devScripts, $extra['scripts-dev']); - } + $extra = $package->getExtra(); + if (isset($extra['scripts-dev']) && is_array($extra['scripts-dev'])) { + $devScripts = array_merge_recursive($devScripts, $extra['scripts-dev']); + } - foreach ($devScripts as $event => &$listeners) { - $listeners = (array)$listeners; - } + foreach ($devScripts as $event => &$listeners) { + $listeners = (array) $listeners; + } $package->setScripts(array_merge_recursive($package->getScripts(), $devScripts)); - } + } } From 9ea6b0e0f5de3cb5baf4a31e4fdb8baa395a2386 Mon Sep 17 00:00:00 2001 From: neronmoon Date: Tue, 4 Sep 2018 15:36:59 +0200 Subject: [PATCH 04/17] Add some tweaks to tests and make composer cmd to run them --- composer.json | 61 +++++++++++++++++++++++++++++--------------------- tests/tests.py | 21 +++++++++-------- 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/composer.json b/composer.json index fc7f75d..7cee118 100644 --- a/composer.json +++ b/composer.json @@ -1,28 +1,37 @@ { - "name": "neronmoon/scriptsdev", - "description": "Scripts-dev behaviour for Composer", - "keywords": ["dev", "scripts", "composer", "commands", "commands execution"], - "homepage": "https://github.com/neronmoon/scriptsdev", - "type": "composer-plugin", - "license": "MIT", - "authors": [ - { - "name": "Vitaliy Krasnoperov", - "email": "alistar.neron@gmail.com" + "name": "neronmoon/scriptsdev", + "description": "Scripts-dev behaviour for Composer", + "keywords": [ + "dev", + "scripts", + "composer", + "commands", + "commands execution" + ], + "homepage": "https://github.com/neronmoon/scriptsdev", + "type": "composer-plugin", + "license": "MIT", + "authors": [ + { + "name": "Vitaliy Krasnoperov", + "email": "alistar.neron@gmail.com" + } + ], + "autoload": { + "psr-4": { + "ScriptsDev\\": "src/" + } + }, + "require": { + "composer-plugin-api": "^1.0" + }, + "require-dev": { + "composer/composer": "~1.0@dev" + }, + "extra": { + "class": "ScriptsDev\\Plugin" + }, + "scripts": { + "test": "python tests/tests.py" } - ], - "autoload": { - "psr-4": { - "ScriptsDev\\": "src/" - } - }, - "require": { - "composer-plugin-api": "^1.0" - }, - "require-dev": { - "composer/composer": "~1.0@dev" - }, - "extra": { - "class": "ScriptsDev\\Plugin" - } -} \ No newline at end of file +} diff --git a/tests/tests.py b/tests/tests.py index d64ef84..c9119f7 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -2,14 +2,13 @@ import os -def test(test, args=[], cmd=['composer', 'update', '-v'], clean_dir=True): - print "Testing:", test +def test(test, args=[], cmd=['composer', 'update', '-v']): + print "Testing:", test, args, cmd, working_dir = '/tmp/scriptsdev/' + test - if clean_dir: - check_call(['rm', '-rf', working_dir]) - check_call(['mkdir', '-p', working_dir]) + check_call(['rm', '-rf', working_dir]) + check_call(['mkdir', '-p', working_dir]) source_composer_json = open('tests/%s.json' % test, 'r').read() source_composer_json = source_composer_json.replace('', os.getcwd()) @@ -22,17 +21,17 @@ def test(test, args=[], cmd=['composer', 'update', '-v'], clean_dir=True): def check(expect, actual): - print "expect: ", expect - print "actual: ", actual if not expect in actual: raise Exception('EXPECTED\n"%s"\nBUT FOUND\n"%s"' % (expect, actual)) + else: + print 'OK' def check_not(expect_not, actual): - print "expect not: ", expect_not - print "actual: ", actual if expect_not in actual: raise Exception('EXPECTED\n"%s"\nBUT FOUND\n"%s"' % (expect_not, actual)) + else: + print 'OK' ############ TESTS HERE ############# @@ -49,5 +48,5 @@ def check_not(expect_not, actual): check('SCRIPTSDEV RULEZ', test('extra-with-custom-script', cmd=['composer', 'run-script', 'test-update'])) check_not('SCRIPTSDEV RULEZ', test('extra-with-custom-script', cmd=['composer', 'run-script', 'test-update-no-dev'])) -check('SCRIPTSDEV RULEZ', test('extra-with-custom-script', cmd=['composer', 'run-script', 'test-install'], clean_dir=False)) -check_not('SCRIPTSDEV RULEZ', test('extra-with-custom-script', cmd=['composer', 'run-script', 'test-install-no-dev'], clean_dir=False)) \ No newline at end of file +check('SCRIPTSDEV RULEZ', test('extra-with-custom-script', cmd=['composer', 'run-script', 'test-install'])) +check_not('SCRIPTSDEV RULEZ', test('extra-with-custom-script', cmd=['composer', 'run-script', 'test-install-no-dev'])) From 4286d2009e9918ce7874a61c43640b1f1eae63d4 Mon Sep 17 00:00:00 2001 From: neronmoon Date: Tue, 4 Sep 2018 15:40:15 +0200 Subject: [PATCH 05/17] Fix readme travis link --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fc83297..9e5532f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# scriptsdev for [Composer](https://github.com/composer/composer) ![Build status](https://travis-ci.org/neronmoon/scriptsdev.svg?branch=master) +# scriptsdev for [Composer](https://github.com/composer/composer) [![Build Status](https://travis-ci.org/neronmoon/scriptsdev.svg?branch=master)](https://travis-ci.org/neronmoon/scriptsdev) It's like require-dev, but for scripts -## Installation +## Installation Just run `composer require neronmoon/scriptsdev --dev` ## Usage @@ -28,4 +28,4 @@ After installing you able to add extra.scripts-dev directive in your `composer.j "post-update-cmd": "php ./someCoolCommand.php" } ... -``` \ No newline at end of file +``` From ec989f1f6c54124fb10b8b95b883766c36cf7682 Mon Sep 17 00:00:00 2001 From: neronmoon Date: Thu, 22 Nov 2018 14:34:08 +0200 Subject: [PATCH 06/17] A bit of refactor and resolve #7 --- src/DevScriptProxyCommand.php | 49 ++++++++++++ src/DevScriptsCommandProvider.php | 60 +++++++++++++++ src/PackageScriptsExtractor.php | 60 +++++++++++++++ src/Plugin.php | 43 +++-------- ...tra-with-custom-script-run-script-dev.json | 28 +++++++ tests/tests.py | 75 +++++++++++++------ 6 files changed, 261 insertions(+), 54 deletions(-) create mode 100644 src/DevScriptProxyCommand.php create mode 100644 src/DevScriptsCommandProvider.php create mode 100644 src/PackageScriptsExtractor.php create mode 100644 tests/extra-with-custom-script-run-script-dev.json diff --git a/src/DevScriptProxyCommand.php b/src/DevScriptProxyCommand.php new file mode 100644 index 0000000..ce3b9d9 --- /dev/null +++ b/src/DevScriptProxyCommand.php @@ -0,0 +1,49 @@ +setName('{name}') + ->setDescription('Run the {name} defined in composer.json.') + ->setDefinition(array( + new InputArgument('script', InputArgument::OPTIONAL, ''), + new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''), + new InputOption('timeout', null, InputOption::VALUE_REQUIRED, + 'Sets script timeout in seconds, or 0 for never.'), + new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'), + new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'), + new InputOption('list', 'l', InputOption::VALUE_NONE, 'List scripts.'), + )); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $args = array( + 'command' => 'run-script', + 'script' => $this->getName(), + 'args' => $input->getArgument('args'), + '--timeout' => $input->getOption('timeout') ?: '0', + '--dev' => $input->getOption('dev'), + '--no-dev' => $input->getOption('no-dev'), + '--list' => $input->getOption('list'), + ); + + var_dump($args); + $command = $this->getApplication()->find('run-script'); + + $arrayInput = new ArrayInput($args); + $command->run($arrayInput, $output); + } +} diff --git a/src/DevScriptsCommandProvider.php b/src/DevScriptsCommandProvider.php new file mode 100644 index 0000000..a241cf4 --- /dev/null +++ b/src/DevScriptsCommandProvider.php @@ -0,0 +1,60 @@ +composer = $args['composer']; + $this->io = $args['io']; + } + + public function getCommands() + { + $package = $this->composer->getPackage(); + $extractor = new PackageScriptsExtractor($this->io); + $devScripts = $extractor->extract($package); + $commands = array(); + foreach ($devScripts as $name => $cmd) { + $commands[] = $this->buildCommand($name); + } + return $commands; + } + + /** + * @param $name + * @return DevScriptProxyCommand + */ + private function buildCommand($name) + { + $command = new DevScriptProxyCommand($name); + $command->setName($this->replaceName($command->getName(), $name)); + $command->setDescription($this->replaceName($command->getDescription(), $name)); + return $command; + } + + private function replaceName($string, $replacement) + { + return str_replace('{name}', $replacement, $string); + } +} diff --git a/src/PackageScriptsExtractor.php b/src/PackageScriptsExtractor.php new file mode 100644 index 0000000..69076eb --- /dev/null +++ b/src/PackageScriptsExtractor.php @@ -0,0 +1,60 @@ +io = $io; + } + + /** + * @param Package $package + * @return array + */ + public function extract(Package $package) + { + // If we have extra.branch-alias, package will be an instanceof RootAliasPackage instead of RootPackage + if ($package instanceof AliasPackage) { + $package = $package->getAliasOf(); + } + + if ($package instanceof CompletePackage && in_array('--no-dev', $_SERVER['argv'], true)) { + return array(); + } + + $devScripts = array(); + $config = json_decode(file_get_contents(getcwd() . '/composer.json'), true); + if (isset($config['scripts-dev']) && is_array($config['scripts-dev'])) { + $this->io->writeError( + "You're using deprecated way to define development-only scripts. +Please, move commands under `scripts-dev` directive into `extra` field. +See README.md for more details." + ); + $devScripts = array_merge_recursive($devScripts, $config['scripts-dev']); + } + + $extra = $package->getExtra(); + if (isset($extra['scripts-dev']) && is_array($extra['scripts-dev'])) { + $devScripts = array_merge_recursive($devScripts, $extra['scripts-dev']); + } + + foreach ($devScripts as $event => &$listeners) { + $listeners = (array)$listeners; + } + + return $devScripts; + } +} diff --git a/src/Plugin.php b/src/Plugin.php index 72caf06..369e50a 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -4,44 +4,25 @@ use Composer\Composer; use Composer\IO\IOInterface; -use Composer\Package\AliasPackage; -use Composer\Package\CompletePackage; +use Composer\Plugin\Capable; use Composer\Plugin\PluginInterface; +use Composer\Plugin\Capability\CommandProvider; -class Plugin implements PluginInterface +class Plugin implements PluginInterface, Capable { + public function getCapabilities() + { + return array( + CommandProvider::class => DevScriptsCommandProvider::class, + ); + } + public function activate(Composer $composer, IOInterface $io) { $package = $composer->getPackage(); - // If we have extra.branch-alias, package will be an instanceof RootAliasPackage instead of RootPackage - if ($package instanceof AliasPackage) { - $package = $package->getAliasOf(); - } - - if ($package instanceof CompletePackage && in_array('--no-dev', $_SERVER['argv'], true)) { - return; - } - - $devScripts = array(); - $config = json_decode(file_get_contents(getcwd().'/composer.json'), true); - if (isset($config['scripts-dev']) && is_array($config['scripts-dev'])) { - $io->writeError( - "You're using deprecated way to define development-only scripts. -Please, move commands under `scripts-dev` directive into `extra` field. -See README.md for more details." - ); - $devScripts = array_merge_recursive($devScripts, $config['scripts-dev']); - } - - $extra = $package->getExtra(); - if (isset($extra['scripts-dev']) && is_array($extra['scripts-dev'])) { - $devScripts = array_merge_recursive($devScripts, $extra['scripts-dev']); - } - - foreach ($devScripts as $event => &$listeners) { - $listeners = (array) $listeners; - } + $extractor = new PackageScriptsExtractor($io); + $devScripts = $extractor->extract($package); $package->setScripts(array_merge_recursive($package->getScripts(), $devScripts)); } diff --git a/tests/extra-with-custom-script-run-script-dev.json b/tests/extra-with-custom-script-run-script-dev.json new file mode 100644 index 0000000..451dd1c --- /dev/null +++ b/tests/extra-with-custom-script-run-script-dev.json @@ -0,0 +1,28 @@ +{ + "name": "neronmoon/scriptsdev-test", + "description": "Scripts-dev behaviour for Composer", + "keywords": ["dev", "scripts", "composer", "commands", "commands execution"], + "homepage": "https://github.com/neronmoon/scriptsdev", + "type": "project", + "license": "MIT", + "authors": [ + { + "name": "Vitaliy Krasnoperov", + "email": "alistar.neron@gmail.com" + } + ], + "repositories": [ + { + "type": "path", + "url": "" + } + ], + "require": { + "neronmoon/scriptsdev": "*@dev" + }, + "extra": { + "scripts-dev": { + "test": "echo SCRIPTSDEV RULEZ" + } + } +} diff --git a/tests/tests.py b/tests/tests.py index c9119f7..237cde1 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,23 +1,32 @@ -from subprocess import check_output, check_call import os +from subprocess import check_output, check_call -def test(test, args=[], cmd=['composer', 'update', '-v']): - print "Testing:", test, args, cmd, +def test(test, cmds): + print "Testing:", test, cmds, working_dir = '/tmp/scriptsdev/' + test check_call(['rm', '-rf', working_dir]) check_call(['mkdir', '-p', working_dir]) - source_composer_json = open('tests/%s.json' % test, 'r').read() - source_composer_json = source_composer_json.replace('', os.getcwd()) + if isinstance(cmds[0], basestring): + cmds = [cmds] - target_composer_json = open(working_dir + '/composer.json', 'w') - target_composer_json.write(source_composer_json) - target_composer_json.close() + output = '' + for cmd in cmds: + source_composer_json = open('tests/%s.json' % test, 'r').read() + source_composer_json = source_composer_json.replace('', os.getcwd()) - return check_output(cmd + args, cwd=working_dir) + target_composer_json = open(working_dir + '/composer.json', 'w') + target_composer_json.write(source_composer_json) + target_composer_json.close() + + try: + output += check_output(cmd, cwd=working_dir) + except Exception, e: + output += str(e.output) + return output def check(expect, actual): @@ -36,17 +45,37 @@ def check_not(expect_not, actual): ############ TESTS HERE ############# -check('SCRIPTSDEV RULEZ', test('extra')) -check_not('SCRIPTSDEV RULEZ', test('extra', ['--no-dev'])) - -check('SCRIPTSDEV RULEZ', test('extra-with-branch-alias')) -check_not('SCRIPTSDEV RULEZ', test('extra-with-branch-alias', ['--no-dev'])) - -check('SCRIPTSDEV RULEZ', test('legacy')) -check_not('SCRIPTSDEV RULEZ', test('legacy', ['--no-dev'])) - -check('SCRIPTSDEV RULEZ', test('extra-with-custom-script', cmd=['composer', 'run-script', 'test-update'])) -check_not('SCRIPTSDEV RULEZ', test('extra-with-custom-script', cmd=['composer', 'run-script', 'test-update-no-dev'])) - -check('SCRIPTSDEV RULEZ', test('extra-with-custom-script', cmd=['composer', 'run-script', 'test-install'])) -check_not('SCRIPTSDEV RULEZ', test('extra-with-custom-script', cmd=['composer', 'run-script', 'test-install-no-dev'])) +check('SCRIPTSDEV RULEZ', test('extra', ['composer', 'update'])) +check_not('SCRIPTSDEV RULEZ', test('extra', ['composer', '--no-dev', 'update'])) + +check('SCRIPTSDEV RULEZ', test('extra-with-branch-alias', ['composer', 'update'])) +check_not('SCRIPTSDEV RULEZ', test('extra-with-branch-alias', ['composer', '--no-dev', 'update'])) + +check('SCRIPTSDEV RULEZ', test('legacy', ['composer', 'update'])) +check_not('SCRIPTSDEV RULEZ', test('legacy', ['composer', '--no-dev', 'update'])) + +check('SCRIPTSDEV RULEZ', test('extra-with-custom-script', ['composer', 'run-script', 'test-update'])) +check_not('SCRIPTSDEV RULEZ', test('extra-with-custom-script', ['composer', 'run-script', 'test-update-no-dev'])) + +check('SCRIPTSDEV RULEZ', test('extra-with-custom-script', ['composer', 'run-script', 'test-install'])) +check_not('SCRIPTSDEV RULEZ', test('extra-with-custom-script', ['composer', 'run-script', 'test-install-no-dev'])) + +check('SCRIPTSDEV RULEZ', test('extra-with-custom-script-run-script-dev', [ + ['composer', 'update'], + ['composer', 'run-script', 'test']])) +check('SCRIPTSDEV RULEZ', test('extra-with-custom-script-run-script-dev', [ + ['composer', 'update'], + ['composer', '--dev', 'run-script', 'test']])) +check_not('SCRIPTSDEV RULEZ', test('extra-with-custom-script-run-script-dev', [ + ['composer', 'update'], + ['composer', '--no-dev', 'run-script', 'test']])) + +check('SCRIPTSDEV RULEZ', test('extra-with-custom-script-run-script-dev', [ + ['composer', 'update'], + ['composer', 'test']])) +check('SCRIPTSDEV RULEZ', test('extra-with-custom-script-run-script-dev', [ + ['composer', 'update'], + ['composer', '--dev', 'test']])) +check_not('SCRIPTSDEV RULEZ', test('extra-with-custom-script-run-script-dev', [ + ['composer', 'update'], + ['composer', '--no-dev', 'test']])) From 08f2279a815acb5c5d50546e4b364bf353b34a25 Mon Sep 17 00:00:00 2001 From: neronmoon Date: Thu, 22 Nov 2018 14:36:04 +0200 Subject: [PATCH 07/17] Add new readme usage --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e5532f..e466f26 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ After installing you able to add extra.scripts-dev directive in your `composer.j "post-install-cmd": [ "npm install --dev" ], - "post-update-cmd": "php ./someCoolCommand.php" + "post-update-cmd": "php ./someCoolCommand.php", + "test": "phpunit" }, } ... From 8a295c763e99438876049fd62377de4516dc3f03 Mon Sep 17 00:00:00 2001 From: neronmoon Date: Thu, 22 Nov 2018 14:48:44 +0200 Subject: [PATCH 08/17] Remove forgotten var_dump, fix readme and deprecation warning. Add more tests --- src/DevScriptProxyCommand.php | 1 - src/PackageScriptsExtractor.php | 13 +++++++++---- tests/legacy-with-run-scripts-dev.json | 26 ++++++++++++++++++++++++++ tests/legacy.json | 2 +- tests/tests.py | 16 +++++++++++++--- 5 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 tests/legacy-with-run-scripts-dev.json diff --git a/src/DevScriptProxyCommand.php b/src/DevScriptProxyCommand.php index ce3b9d9..43f840f 100644 --- a/src/DevScriptProxyCommand.php +++ b/src/DevScriptProxyCommand.php @@ -40,7 +40,6 @@ protected function execute(InputInterface $input, OutputInterface $output) '--list' => $input->getOption('list'), ); - var_dump($args); $command = $this->getApplication()->find('run-script'); $arrayInput = new ArrayInput($args); diff --git a/src/PackageScriptsExtractor.php b/src/PackageScriptsExtractor.php index 69076eb..9a9f09b 100644 --- a/src/PackageScriptsExtractor.php +++ b/src/PackageScriptsExtractor.php @@ -15,6 +15,8 @@ class PackageScriptsExtractor */ private $io; + protected static $warningPrinted = false; + public function __construct(IOInterface $io) { $this->io = $io; @@ -38,11 +40,14 @@ public function extract(Package $package) $devScripts = array(); $config = json_decode(file_get_contents(getcwd() . '/composer.json'), true); if (isset($config['scripts-dev']) && is_array($config['scripts-dev'])) { - $this->io->writeError( - "You're using deprecated way to define development-only scripts. + if (!static::$warningPrinted) { + $this->io->writeError( + "You're using deprecated way to define development-only scripts. Please, move commands under `scripts-dev` directive into `extra` field. -See README.md for more details." - ); +See https://github.com/neronmoon/scriptsdev/blob/master/README.md for more details." + ); + static::$warningPrinted = true; + } $devScripts = array_merge_recursive($devScripts, $config['scripts-dev']); } diff --git a/tests/legacy-with-run-scripts-dev.json b/tests/legacy-with-run-scripts-dev.json new file mode 100644 index 0000000..704b1b8 --- /dev/null +++ b/tests/legacy-with-run-scripts-dev.json @@ -0,0 +1,26 @@ +{ + "name": "neronmoon/scriptsdev-test", + "description": "Scripts-dev behaviour for Composer", + "keywords": ["dev", "scripts", "composer", "commands", "commands execution"], + "homepage": "https://github.com/neronmoon/scriptsdev", + "type": "project", + "license": "MIT", + "authors": [ + { + "name": "Vitaliy Krasnoperov", + "email": "alistar.neron@gmail.com" + } + ], + "repositories": [ + { + "type": "path", + "url": "" + } + ], + "require": { + "neronmoon/scriptsdev": "*@dev" + }, + "scripts-dev": { + "test": "echo SCRIPTSDEV RULEZ" + } +} diff --git a/tests/legacy.json b/tests/legacy.json index 7aacdda..74be368 100644 --- a/tests/legacy.json +++ b/tests/legacy.json @@ -23,4 +23,4 @@ "scripts-dev": { "post-update-cmd": "echo SCRIPTSDEV RULEZ" } -} \ No newline at end of file +} diff --git a/tests/tests.py b/tests/tests.py index 237cde1..70302ce 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -45,15 +45,25 @@ def check_not(expect_not, actual): ############ TESTS HERE ############# +check('SCRIPTSDEV RULEZ', test('legacy', ['composer', 'update'])) +check_not('SCRIPTSDEV RULEZ', test('legacy', ['composer', '--no-dev', 'update'])) + +check('SCRIPTSDEV RULEZ', test('legacy-with-run-scripts-dev', [ + ['composer', 'update'], + ['composer', 'run-script', 'test']])) +check('SCRIPTSDEV RULEZ', test('legacy-with-run-scripts-dev', [ + ['composer', 'update'], + ['composer', '--dev', 'run-script', 'test']])) +check_not('SCRIPTSDEV RULEZ', test('legacy-with-run-scripts-dev', [ + ['composer', 'update'], + ['composer', '--no-dev', 'run-script', 'test']])) + check('SCRIPTSDEV RULEZ', test('extra', ['composer', 'update'])) check_not('SCRIPTSDEV RULEZ', test('extra', ['composer', '--no-dev', 'update'])) check('SCRIPTSDEV RULEZ', test('extra-with-branch-alias', ['composer', 'update'])) check_not('SCRIPTSDEV RULEZ', test('extra-with-branch-alias', ['composer', '--no-dev', 'update'])) -check('SCRIPTSDEV RULEZ', test('legacy', ['composer', 'update'])) -check_not('SCRIPTSDEV RULEZ', test('legacy', ['composer', '--no-dev', 'update'])) - check('SCRIPTSDEV RULEZ', test('extra-with-custom-script', ['composer', 'run-script', 'test-update'])) check_not('SCRIPTSDEV RULEZ', test('extra-with-custom-script', ['composer', 'run-script', 'test-update-no-dev'])) From 794bbd0b3ffa185be7376aea84cbcd690acda7ad Mon Sep 17 00:00:00 2001 From: neronmoon Date: Thu, 22 Nov 2018 14:51:17 +0200 Subject: [PATCH 09/17] Fix PHP 5.3 tests --- src/Plugin.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 369e50a..46603ae 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -6,14 +6,13 @@ use Composer\IO\IOInterface; use Composer\Plugin\Capable; use Composer\Plugin\PluginInterface; -use Composer\Plugin\Capability\CommandProvider; class Plugin implements PluginInterface, Capable { public function getCapabilities() { return array( - CommandProvider::class => DevScriptsCommandProvider::class, + 'Composer\Plugin\Capability\CommandProvider' => 'ScriptsDev\DevScriptsCommandProvider', ); } From 57027a788d2022d33883d5536878e57986ffce3b Mon Sep 17 00:00:00 2001 From: neronmoon Date: Fri, 14 Dec 2018 09:24:55 +0200 Subject: [PATCH 10/17] Add known issue about validation. Close #9 --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index e466f26..c49be2a 100644 --- a/README.md +++ b/README.md @@ -30,3 +30,13 @@ After installing you able to add extra.scripts-dev directive in your `composer.j } ... ``` + +## Known issues + +- Usage of this plugin will cause minor warning of validation process. +`composer validate` command will display something like this. +``` +./composer.json is valid, but with a few warnings +See https://getcomposer.org/doc/04-schema.md for details on the schema +Description for non-existent script "test" found in "scripts-descriptions" +``` From e9a3f559ee6ff209b17535e9553adcf59afe653b Mon Sep 17 00:00:00 2001 From: neronmoon Date: Tue, 26 Feb 2019 15:56:15 +0200 Subject: [PATCH 11/17] Fix #11 --- src/PackageScriptsExtractor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PackageScriptsExtractor.php b/src/PackageScriptsExtractor.php index 9a9f09b..50d8ba0 100644 --- a/src/PackageScriptsExtractor.php +++ b/src/PackageScriptsExtractor.php @@ -6,7 +6,7 @@ use Composer\IO\IOInterface; use Composer\Package\AliasPackage; use Composer\Package\CompletePackage; -use Composer\Package\Package; +use Composer\Package\PackageInterface; class PackageScriptsExtractor { @@ -23,10 +23,10 @@ public function __construct(IOInterface $io) } /** - * @param Package $package + * @param PackageInterface $package * @return array */ - public function extract(Package $package) + public function extract(PackageInterface $package) { // If we have extra.branch-alias, package will be an instanceof RootAliasPackage instead of RootPackage if ($package instanceof AliasPackage) { From aedb5ed8c3edc07b0085caee9b0ef5a9ffae043b Mon Sep 17 00:00:00 2001 From: neronmoon Date: Tue, 26 Feb 2019 16:00:35 +0200 Subject: [PATCH 12/17] Stop supporting hhvm since composer doesn't --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3325341..7c3a860 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,5 @@ matrix: - php: 5.6 - php: 7.0 - php: 7.1 - - php: hhvm -script: python tests/tests.py \ No newline at end of file +script: python tests/tests.py From 546b96749e15783a626ddf05bfe3253c0d328444 Mon Sep 17 00:00:00 2001 From: Sergey Repin Date: Wed, 27 Feb 2019 16:55:44 +0200 Subject: [PATCH 13/17] hotfix extract if not cli instance --- src/PackageScriptsExtractor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PackageScriptsExtractor.php b/src/PackageScriptsExtractor.php index 50d8ba0..3929eab 100644 --- a/src/PackageScriptsExtractor.php +++ b/src/PackageScriptsExtractor.php @@ -33,7 +33,7 @@ public function extract(PackageInterface $package) $package = $package->getAliasOf(); } - if ($package instanceof CompletePackage && in_array('--no-dev', $_SERVER['argv'], true)) { + if ($package instanceof CompletePackage && isset($_SERVER['argv']) && in_array('--no-dev', $_SERVER['argv'], true)) { return array(); } From 4de1afd44c1282029f7be3fe888ce0ae7570c32d Mon Sep 17 00:00:00 2001 From: Fabien Villepinte Date: Tue, 7 Apr 2020 21:20:16 +0200 Subject: [PATCH 14/17] Fix TypeError with recent version of Composer --- src/DevScriptProxyCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DevScriptProxyCommand.php b/src/DevScriptProxyCommand.php index 43f840f..a69668e 100644 --- a/src/DevScriptProxyCommand.php +++ b/src/DevScriptProxyCommand.php @@ -43,6 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $command = $this->getApplication()->find('run-script'); $arrayInput = new ArrayInput($args); - $command->run($arrayInput, $output); + $statusCode = $command->run($arrayInput, $output); + return is_numeric($statusCode) ? (int) $statusCode : 0; } } From 79ff8318273321c828562c7eb47c794bb47d32ee Mon Sep 17 00:00:00 2001 From: Fabien Villepinte Date: Sat, 11 Jul 2020 14:14:23 +0200 Subject: [PATCH 15/17] Add support for Composer 2 --- composer.json | 4 ++-- src/Plugin.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 7cee118..701a36b 100644 --- a/composer.json +++ b/composer.json @@ -23,10 +23,10 @@ } }, "require": { - "composer-plugin-api": "^1.0" + "composer-plugin-api": "^1.0 || ^2.0" }, "require-dev": { - "composer/composer": "~1.0@dev" + "composer/composer": "~1.0@dev || ~2.0@dev" }, "extra": { "class": "ScriptsDev\\Plugin" diff --git a/src/Plugin.php b/src/Plugin.php index 46603ae..8227e82 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -25,4 +25,12 @@ public function activate(Composer $composer, IOInterface $io) $package->setScripts(array_merge_recursive($package->getScripts(), $devScripts)); } + + public function deactivate(Composer $composer, IOInterface $io) + { + } + + public function uninstall(Composer $composer, IOInterface $io) + { + } } From 9e276a030d06f0a5202d627de6673a229efe7149 Mon Sep 17 00:00:00 2001 From: Fabien Villepinte Date: Sat, 11 Jul 2020 14:58:24 +0200 Subject: [PATCH 16/17] Update branch alias test to get a PHP error See #14 --- tests/extra-with-branch-alias.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/extra-with-branch-alias.json b/tests/extra-with-branch-alias.json index 980cda6..2dda890 100644 --- a/tests/extra-with-branch-alias.json +++ b/tests/extra-with-branch-alias.json @@ -26,12 +26,13 @@ "require": { "neronmoon/scriptsdev": "*@dev" }, + "version": "dev-master", "extra": { "branch-alias": { - "dev-master": "*-dev" + "dev-master": "99.0.0-dev" }, "scripts-dev": { "post-update-cmd": "echo SCRIPTSDEV RULEZ" } } -} \ No newline at end of file +} From 6919af4d8768e1ecdca1fd9a2e35e795557903d4 Mon Sep 17 00:00:00 2001 From: Fabien Villepinte Date: Sat, 11 Jul 2020 15:02:48 +0200 Subject: [PATCH 17/17] Fix undefined method error --- src/PackageScriptsExtractor.php | 6 ------ src/Plugin.php | 5 +++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/PackageScriptsExtractor.php b/src/PackageScriptsExtractor.php index 3929eab..1995dbd 100644 --- a/src/PackageScriptsExtractor.php +++ b/src/PackageScriptsExtractor.php @@ -4,7 +4,6 @@ use Composer\IO\IOInterface; -use Composer\Package\AliasPackage; use Composer\Package\CompletePackage; use Composer\Package\PackageInterface; @@ -28,11 +27,6 @@ public function __construct(IOInterface $io) */ public function extract(PackageInterface $package) { - // If we have extra.branch-alias, package will be an instanceof RootAliasPackage instead of RootPackage - if ($package instanceof AliasPackage) { - $package = $package->getAliasOf(); - } - if ($package instanceof CompletePackage && isset($_SERVER['argv']) && in_array('--no-dev', $_SERVER['argv'], true)) { return array(); } diff --git a/src/Plugin.php b/src/Plugin.php index 46603ae..14f3f43 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -4,6 +4,7 @@ use Composer\Composer; use Composer\IO\IOInterface; +use Composer\Package\AliasPackage; use Composer\Plugin\Capable; use Composer\Plugin\PluginInterface; @@ -19,6 +20,10 @@ public function getCapabilities() public function activate(Composer $composer, IOInterface $io) { $package = $composer->getPackage(); + // If we have extra.branch-alias, package will be an instanceof RootAliasPackage instead of RootPackage + if ($package instanceof AliasPackage) { + $package = $package->getAliasOf(); + } $extractor = new PackageScriptsExtractor($io); $devScripts = $extractor->extract($package);