diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1d3841f6..9bcfc490 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,16 +23,17 @@ jobs: - name: Install dependencies run: composer install --prefer-dist --no-suggest --no-progress - name: Run tests - run: vendor/bin/phpunit --printer mheap\\GithubActionsReporter\\Printer + run: composer run test lint: runs-on: ubuntu-latest name: Lint project files steps: - uses: actions/checkout@v1 - name: Install PHP - uses: shivammathur/setup-php@1.3.7 + uses: shivammathur/setup-php@v2 with: php-version: '7.4' + tools: composer, cs2pr - name: Debugging run: | php --version @@ -40,5 +41,6 @@ jobs: composer --version - name: Install dependencies run: composer install --prefer-dist --no-suggest --no-progress - - name: Run validate - run: composer run lint + + - name: Run PHPCS + run: vendor/bin/phpcs -q -n --report=checkstyle | cs2pr diff --git a/README.md b/README.md index 2b84c283..813edcff 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,6 @@ Mozart requires little configuration. All you need to do is tell it where the bu "packages": [ "pimple/pimple" ], - "exclude_packages": [ - "psr/container" - ], "override_autoload": { "google/apiclient": { "classmap": [ @@ -55,7 +52,6 @@ The following configuration is optional: - `delete_vendor_directories` is a boolean flag to indicate if the packages' vendor directories should be deleted after being processed. _default: true_. - `packages` is an optional array that defines the packages to be processed by Mozart. The array requires the slugs of packages in the same format as provided in your `composer.json`. Mozart will automatically rewrite dependencies of these packages as well. You don't need to add dependencies of these packages to the list. If this field is absent, all packages listed under composer require will be included. -- `exclude_packages` is an optional array that defines the packages to be excluded from the processing performed by Mozart. This is useful if some of the packages in the `packages` array define dependent packages whose namespaces you want to keep unchanged. The array requires the slugs of the packages, as in the case of the `packages` array. - `override_autoload` a dictionary, keyed with the package names, of autoload settings to replace those in the original packages' `composer.json` `autoload` property. After Composer has loaded the packages as defined in your `composer.json` file, you can now run `mozart compose` and Mozart will bundle your packages according to the above configuration. It is recommended to dump the autoloader after Mozart has finished running, in case there are new classes or namespaces generated that aren't included in the autoloader yet. diff --git a/src/Console/Commands/Compose.php b/src/Console/Commands/Compose.php index 592cd456..7bbee156 100644 --- a/src/Console/Commands/Compose.php +++ b/src/Console/Commands/Compose.php @@ -69,14 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $require = array_keys(get_object_vars($composer->require)); } - $packagesByName = $this->findPackages($require); - $excludedPackagesNames = isset($config->excluded_packages) ? $config->excluded_packages : []; - $packagesToMoveByName = array_diff_key($packagesByName, array_flip($excludedPackagesNames)); - $packages = array_values($packagesToMoveByName); - - foreach ($packages as $package) { - $package->dependencies = array_diff_key($package->dependencies, array_flip($excludedPackagesNames)); - } + $packages = $this->findPackages($require); $this->mover = new Mover($workingDir, $config); $this->replacer = new Replacer($workingDir, $config); @@ -180,7 +173,7 @@ private function findPackages($slugs) } $package->dependencies = $this->findPackages($dependencies); - $packages[$package_slug] = $package; + $packages[] = $package; } return $packages; diff --git a/src/Mover.php b/src/Mover.php index 61cc2379..a0f8e2b1 100644 --- a/src/Mover.php +++ b/src/Mover.php @@ -147,9 +147,7 @@ public function movePackage(Package $package) } } - if (!in_array($package->config->name, $this->movedPackages)) { - $this->movedPackages[] = $package->config->name; - } + $this->movedPackages[] = $package->config->name; } if (!isset($this->config->delete_vendor_directories) || $this->config->delete_vendor_directories === true) { @@ -202,25 +200,11 @@ public function moveFile(Package $package, $autoloader, $file, $path = '') protected function deletePackageVendorDirectories() { foreach ($this->movedPackages as $movedPackage) { - $packageDir = 'vendor' . DIRECTORY_SEPARATOR . $movedPackage; - if (!is_dir($packageDir) || is_link($packageDir)) { + $packageDir = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $movedPackage; + if (is_link($packageDir)) { continue; } - $this->filesystem->deleteDir($packageDir); - - //Delete parent directory too if it became empty - //(because that package was the only one from that vendor) - $parentDir = dirname($packageDir); - if ($this->dirIsEmpty($parentDir)) { - $this->filesystem->deleteDir($parentDir); - } } } - - private function dirIsEmpty($dir) - { - $di = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS); - return iterator_count($di) === 0; - } }