diff --git a/src/Configurator/AddLinesConfigurator.php b/src/Configurator/AddLinesConfigurator.php index 8a4bc6d6..20029f11 100644 --- a/src/Configurator/AddLinesConfigurator.php +++ b/src/Configurator/AddLinesConfigurator.php @@ -164,10 +164,14 @@ public function executeUnconfigure(Recipe $recipe, $config): void } } - private function getPatchedContents(string $file, string $value, string $position, ?string $target, bool $warnIfMissing): string + private function getPatchedContents(string $file, string|array $value, string $position, ?string $target, bool $warnIfMissing): string { $fileContents = $this->readFile($file); + if (\is_array($value)) { + $value = implode(\PHP_EOL, $value); + } + if (false !== strpos($fileContents, $value)) { return $fileContents; // already includes value, skip } diff --git a/tests/Configurator/AddLinesConfiguratorTest.php b/tests/Configurator/AddLinesConfiguratorTest.php index b9cb5516..02623fcc 100644 --- a/tests/Configurator/AddLinesConfiguratorTest.php +++ b/tests/Configurator/AddLinesConfiguratorTest.php @@ -562,6 +562,70 @@ public function getUpdateTests() import './stimulus_bootstrap'; import * as Turbo from '@hotwired/turbo'; +console.log(Turbo); +EOF + ], + ]; + + yield 'recipe_changes_with_multiline_string' => [ + ['assets/app.js' => $appJsOriginal], + [ + ['file' => 'assets/app.js', 'position' => 'top', 'content' => "import './bootstrap';"], + ], + [ + ['file' => 'assets/app.js', 'position' => 'top', 'content' => "import './stimulus_bootstrap';\nimport { useIntersection } from 'stimulus-use';"], + ], + ['assets/app.js' => << [ + ['assets/app.js' => $appJsOriginal], + [ + ['file' => 'assets/app.js', 'position' => 'top', 'content' => "import './bootstrap';"], + ], + [ + ['file' => 'assets/app.js', 'position' => 'top', 'content' => [ + "import './stimulus_bootstrap';", + "import { useIntersection } from 'stimulus-use';", + ]], + ], + ['assets/app.js' => << [ + ['assets/app.js' => $appJsOriginal], + [ + ['file' => 'assets/app.js', 'position' => 'top', 'content' => "import './bootstrap';"], + ], + [ + ['file' => 'assets/app.js', 'position' => 'top', 'content' => [ + "import './stimulus_bootstrap';", + "import { useIntersection } from 'stimulus-use';", + '', + " console.log(years['2025'] !== years['0225']);", + ]], + ], + ['assets/app.js' => <<