Skip to content

Commit 421fd60

Browse files
committed
Add an optional "excluded_packages" configuration key.
This is an array of package slugs. Any package included here won't be processed by Mozart: it won't have its namepsaced changed and won't be moved from its original location. Namespace references to these packages won't be changed. This is useful if there are dependent packages whose namespace shouldn't be changed, for examle "psr/container".
1 parent a647ec6 commit 421fd60

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Mozart requires little configuration. All you need to do is tell it where the bu
2727
"packages": [
2828
"pimple/pimple"
2929
],
30+
"exclude_packages": [
31+
"psr/container"
32+
],
3033
"override_autoload": {
3134
"google/apiclient": {
3235
"classmap": [
@@ -52,6 +55,7 @@ The following configuration is optional:
5255

5356
- `delete_vendor_directories` is a boolean flag to indicate if the packages' vendor directories should be deleted after being processed. _default: true_.
5457
- `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.
58+
- `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.
5559
- `override_autoload` a dictionary, keyed with the package names, of autoload settings to replace those in the original packages' `composer.json` `autoload` property.
5660

5761
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.

src/Console/Commands/Compose.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
6969
$require = array_keys(get_object_vars($composer->require));
7070
}
7171

72-
$packages = $this->findPackages($require);
72+
$packagesByName = $this->findPackages($require);
73+
$excludedPackagesNames = isset($config->excluded_packages) ? $config->excluded_packages : [];
74+
$packagesToMoveByName = array_diff_key($packagesByName, array_flip($excludedPackagesNames));
75+
$packages = array_values($packagesToMoveByName);
76+
77+
foreach ($packages as $package) {
78+
$package->dependencies = array_diff_key($package->dependencies, array_flip($excludedPackagesNames));
79+
}
7380

7481
$this->mover = new Mover($workingDir, $config);
7582
$this->replacer = new Replacer($workingDir, $config);
@@ -173,7 +180,7 @@ private function findPackages($slugs)
173180
}
174181

175182
$package->dependencies = $this->findPackages($dependencies);
176-
$packages[] = $package;
183+
$packages[$package_slug] = $package;
177184
}
178185

179186
return $packages;

0 commit comments

Comments
 (0)