From b87ab34c1c12e78d6129aa0da4e55490e69c0da2 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sun, 26 Nov 2023 15:18:49 -0300 Subject: [PATCH] Tweaks the regex --- src/Actions/FixJsImportPaths.php | 2 +- tests/FixJsImportPathsTest.php | 2 +- tests/stubs/fixing-paths/app.js | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Actions/FixJsImportPaths.php b/src/Actions/FixJsImportPaths.php index 8347eb3..7bbec6f 100644 --- a/src/Actions/FixJsImportPaths.php +++ b/src/Actions/FixJsImportPaths.php @@ -47,7 +47,7 @@ private function updatedJsImports(SplFileInfo $file) try { $lines[$index] = preg_replace_callback( - '#import (?:.*["\'])(\..*)(?:[\'"];?.*)#', + '#import.+["\']([\.]+.*)["\']#', function ($matches) use ($file) { $replaced = $this->replaceDotImports($file, $matches[1], $matches[0]); diff --git a/tests/FixJsImportPathsTest.php b/tests/FixJsImportPathsTest.php index 1aa8fb7..d6c2b6d 100644 --- a/tests/FixJsImportPathsTest.php +++ b/tests/FixJsImportPathsTest.php @@ -32,7 +32,7 @@ public function fixes_imports() // Root files... $this->assertTrue(File::exists($this->tmpFolder.DIRECTORY_SEPARATOR.'app.js')); - $this->assertMatchesRegularExpression('#import ["\']bootstrap["\']#', File::get($this->tmpFolder.DIRECTORY_SEPARATOR.'app.js')); + $this->assertMatchesRegularExpression('#import ["\']bootstrap["\']\nimport ["\']libs["\']#', File::get($this->tmpFolder.DIRECTORY_SEPARATOR.'app.js')); $this->assertMatchesRegularExpression('#import axios from ["\']axios["\']#', File::get($this->tmpFolder.DIRECTORY_SEPARATOR.'bootstrap.js')); // Libs folders... diff --git a/tests/stubs/fixing-paths/app.js b/tests/stubs/fixing-paths/app.js index fc4f654..fc82c3f 100644 --- a/tests/stubs/fixing-paths/app.js +++ b/tests/stubs/fixing-paths/app.js @@ -1 +1,2 @@ import './bootstrap' +import './libs'