diff --git a/src/Composer/Config/JsonConfigSource.php b/src/Composer/Config/JsonConfigSource.php index db3d36dc4..596d14f52 100644 --- a/src/Composer/Config/JsonConfigSource.php +++ b/src/Composer/Config/JsonConfigSource.php @@ -162,7 +162,7 @@ class JsonConfigSource implements ConfigSourceInterface public function removeProperty(string $name): void { $this->manipulateJson('removeProperty', static function (&$config, $key): void { - if (strpos($key, 'extra.') === 0 || strpos($key, 'scripts.') === 0) { + if (strpos($key, 'extra.') === 0 || strpos($key, 'scripts.') === 0 || stripos($key, 'autoload.') === 0 || stripos($key, 'autoload-dev.') === 0) { $bits = explode('.', $key); $last = array_pop($bits); $arr = &$config[reset($bits)]; diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index 2e0f70411..c6c5eb555 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -214,6 +214,14 @@ class JsonManipulator return $this->removeSubNode('scripts', substr($name, 8)); } + if (strpos($name, 'autoload.') === 0) { + return $this->removeSubNode('autoload', substr($name, 9)); + } + + if (strpos($name, 'autoload-dev.') === 0) { + return $this->removeSubNode('autoload-dev', substr($name, 13)); + } + return $this->removeMainKey($name); } diff --git a/tests/Composer/Test/Command/ConfigCommandTest.php b/tests/Composer/Test/Command/ConfigCommandTest.php index cf3a55acc..9d08f7cc5 100644 --- a/tests/Composer/Test/Command/ConfigCommandTest.php +++ b/tests/Composer/Test/Command/ConfigCommandTest.php @@ -107,6 +107,16 @@ class ConfigCommandTest extends TestCase ['setting-key' => 'extra.patches.foo/bar', 'setting-value' => ['{"123":"value"}'], '--json' => true, '--merge' => true], ['extra' => ['patches' => ['foo/bar' => [123 => 'value']]]], ]; + yield 'unset autoload' => [ + ['autoload' => ['psr-4' => ['test'], 'classmap' => ['test']]], + ['setting-key' => 'autoload.psr-4', '--unset' => true], + ['autoload' => ['classmap' => ['test']]], + ]; + yield 'unset autoload-dev' => [ + ['autoload-dev' => ['psr-4' => ['test'], 'classmap' => ['test']]], + ['setting-key' => 'autoload-dev.psr-4', '--unset' => true], + ['autoload-dev' => ['classmap' => ['test']]], + ]; } /**