diff --git a/src/Commands/PinCommand.php b/src/Commands/PinCommand.php index 2c9fde0..ec30584 100644 --- a/src/Commands/PinCommand.php +++ b/src/Commands/PinCommand.php @@ -84,7 +84,7 @@ private function importPackages(Packager $packager, Collection $imports): void private function pattern(string $package): string { return sprintf( - '#Importmap::pin\([\'\"]%s[\'\"].*$#', + '#.*pin\([\'\"]%s[\'\"].*#', preg_quote($package), ); } diff --git a/src/Npm.php b/src/Npm.php index 3de19f1..92f95e6 100644 --- a/src/Npm.php +++ b/src/Npm.php @@ -95,7 +95,7 @@ private function findPackagesFromCdnMatches(string $content) private function findPackagesFromLocalMatches(string $content) { - preg_match_all('/^Importmap::pin\(.+\)\;\s*\/\/\s*(.+?)@(.+?)\s+.*\r?$/m', $content, $matches); + preg_match_all('/pin\([\'\"](.*?)[\'\"].*\);\s+\/\/\s+.*?@(\d+\.\d+\.\d+.*?)\s/m', $content, $matches); if (count($matches) !== 3) { return collect(); diff --git a/src/Packager.php b/src/Packager.php index d292e54..c05cf23 100644 --- a/src/Packager.php +++ b/src/Packager.php @@ -123,7 +123,7 @@ private function packageFilename(string $package): string private function extractPackageVersionFrom(string $url): string { - preg_match('#(@\d+\.\d+\.\d+)/#', $url, $matches); + preg_match('#(@\d+\.\d+\.\d+.*?)/#', $url, $matches); if (! ($matches[1] ?? false)) { return 'Unknown Version'; diff --git a/tests/fixtures/npm/audit-importmap.php b/tests/fixtures/npm/audit-importmap.php index 0ca7d4d..5485d89 100644 --- a/tests/fixtures/npm/audit-importmap.php +++ b/tests/fixtures/npm/audit-importmap.php @@ -3,4 +3,4 @@ use Tonysm\ImportmapLaravel\Facades\Importmap; Importmap::pin('is-svg', to: 'https://cdn.skypack.dev/is-svg@3.0.0', preload: true); -Importmap::pin('lodash', to: '/js/vendor/lodash.js'); // lodash@4.17.12 +Importmap::pin('lodash', to: '/js/vendor/lodash.js'); // @4.17.12 diff --git a/tests/fixtures/npm/outdated-importmap.php b/tests/fixtures/npm/outdated-importmap.php index 0c207ce..694ba55 100644 --- a/tests/fixtures/npm/outdated-importmap.php +++ b/tests/fixtures/npm/outdated-importmap.php @@ -3,4 +3,4 @@ use Tonysm\ImportmapLaravel\Facades\Importmap; Importmap::pin('is-svg', to: 'https://cdn.skypack.dev/is-svg@3.0.0', preload: true); -Importmap::pin('lodash', to: '/js/vendor/lodash.js'); // lodash@4.0.0 +Importmap::pin('lodash', to: '/js/vendor/lodash.js'); // @4.0.0