Skip to content

Commit 561ca87

Browse files
committed
Only add makefile command to scripts if makefile package is present
1 parent e09157d commit 561ca87

File tree

2 files changed

+20
-61
lines changed

2 files changed

+20
-61
lines changed

composer.lock

Lines changed: 1 addition & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Composer/Installer.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,31 @@ public static function findEventListeners(Event $event): void
7676
return;
7777
}
7878

79-
if (array_key_exists('name', $json) && $json['name'] === 'wyrihaximus/test-utilities') {
80-
self::addMakeOnInstallOrUpdate($event->getIO(), $rootPackagePath);
79+
if (! array_key_exists('require-dev', $json)) {
80+
return;
81+
}
8182

83+
if (! is_array($json['require-dev'])) {
8284
return;
8385
}
8486

85-
if (! array_key_exists('require-dev', $json)) {
87+
$hasMakefiles = false;
88+
foreach (array_keys($json['require-dev']) as $package) {
89+
if ($package === 'wyrihaximus/makefiles') {
90+
$hasMakefiles = true;
91+
break;
92+
}
93+
}
94+
95+
if (! $hasMakefiles) {
8696
return;
8797
}
8898

89-
if (! is_array($json['require-dev'])) {
99+
unset($hasMakefiles);
100+
101+
if (array_key_exists('name', $json) && $json['name'] === 'wyrihaximus/test-utilities') {
102+
self::addMakeOnInstallOrUpdate($event->getIO(), $rootPackagePath);
103+
90104
return;
91105
}
92106

@@ -150,7 +164,7 @@ private static function addMakeOnInstallOrUpdate(IOInterface $io, string $rootPa
150164
$replacementComposerJsonString = preg_replace('/^( +?)\\1(?=[^ ])/m', '$1', $replacementComposerJsonString);
151165
if (is_string($replacementComposerJsonString)) {
152166
$io->write('<info>wyrihaximus/test-utilities:</info> Writing new <fg=cyan>composer.json</>');
153-
file_put_contents($rootPackagePath . '/composer.json', $replacementComposerJsonString);
167+
file_put_contents($rootPackagePath . '/composer.json', $replacementComposerJsonString . "\r\n");
154168
}
155169
}
156170
}

0 commit comments

Comments
 (0)