Skip to content

Commit

Permalink
Tweaks the regex
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysm committed Nov 26, 2023
1 parent bbd2e95 commit b87ab34
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Actions/FixJsImportPaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
2 changes: 1 addition & 1 deletion tests/FixJsImportPathsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Check failure on line 35 in tests/FixJsImportPathsTest.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.45.* - prefer-lowest - windows-latest

Failed asserting that 'import 'bootstrap'\r\n

Check failure on line 35 in tests/FixJsImportPathsTest.php

View workflow job for this annotation

GitHub Actions / P8.1 - L9.45.* - prefer-stable - windows-latest

Failed asserting that 'import 'bootstrap'\r\n

Check failure on line 35 in tests/FixJsImportPathsTest.php

View workflow job for this annotation

GitHub Actions / P8.1 - L10.* - prefer-lowest - windows-latest

Failed asserting that 'import 'bootstrap'\r\n

Check failure on line 35 in tests/FixJsImportPathsTest.php

View workflow job for this annotation

GitHub Actions / P8.1 - L10.* - prefer-stable - windows-latest

Failed asserting that 'import 'bootstrap'\r\n
$this->assertMatchesRegularExpression('#import axios from ["\']axios["\']#', File::get($this->tmpFolder.DIRECTORY_SEPARATOR.'bootstrap.js'));

// Libs folders...
Expand Down
1 change: 1 addition & 0 deletions tests/stubs/fixing-paths/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import './bootstrap'
import './libs'

0 comments on commit b87ab34

Please sign in to comment.