diff --git a/src/Configurator/AddLinesConfigurator.php b/src/Configurator/AddLinesConfigurator.php index 146b28b5..24bb2920 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("\n", $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 43306947..a0a4de58 100644 --- a/tests/Configurator/AddLinesConfiguratorTest.php +++ b/tests/Configurator/AddLinesConfiguratorTest.php @@ -566,6 +566,70 @@ public function getUpdateTests() 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' => <<