1
0
Fork 0

composer#11852 fix: ability to remove autoload* keys (#11967)

pull/11972/head
Krzysztof Ciszewski 2024-05-08 11:19:05 +02:00 committed by GitHub
parent 2fe3244ddb
commit 4d7476ca30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View File

@ -162,7 +162,7 @@ class JsonConfigSource implements ConfigSourceInterface
public function removeProperty(string $name): void public function removeProperty(string $name): void
{ {
$this->manipulateJson('removeProperty', static function (&$config, $key): 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); $bits = explode('.', $key);
$last = array_pop($bits); $last = array_pop($bits);
$arr = &$config[reset($bits)]; $arr = &$config[reset($bits)];

View File

@ -214,6 +214,14 @@ class JsonManipulator
return $this->removeSubNode('scripts', substr($name, 8)); 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); return $this->removeMainKey($name);
} }

View File

@ -107,6 +107,16 @@ class ConfigCommandTest extends TestCase
['setting-key' => 'extra.patches.foo/bar', 'setting-value' => ['{"123":"value"}'], '--json' => true, '--merge' => true], ['setting-key' => 'extra.patches.foo/bar', 'setting-value' => ['{"123":"value"}'], '--json' => true, '--merge' => true],
['extra' => ['patches' => ['foo/bar' => [123 => 'value']]]], ['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']]],
];
} }
/** /**