Skip to content

Commit 34ecbc3

Browse files
authored
Merge pull request #50 from tonysm/tm/fix-previous-version-detection
Fix outdated command breaks on previous comment format
2 parents d4e67ab + 3c1f08c commit 34ecbc3

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

src/Commands/PinCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private function importPackages(Packager $packager, Collection $imports): void
8484
private function pattern(string $package): string
8585
{
8686
return sprintf(
87-
'#Importmap::pin\([\'\"]%s[\'\"].*$#',
87+
'#.*pin\([\'\"]%s[\'\"].*#',
8888
preg_quote($package),
8989
);
9090
}

src/Npm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private function findPackagesFromCdnMatches(string $content)
9595

9696
private function findPackagesFromLocalMatches(string $content)
9797
{
98-
preg_match_all('/^Importmap::pin\(.+\)\;\s*\/\/\s*(.+?)@(.+?)\s+.*\r?$/m', $content, $matches);
98+
preg_match_all('/pin\([\'\"](.*?)[\'\"].*\);\s+\/\/\s+.*?@(\d+\.\d+\.\d+.*?)\s/m', $content, $matches);
9999

100100
if (count($matches) !== 3) {
101101
return collect();

src/Packager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private function packageFilename(string $package): string
123123

124124
private function extractPackageVersionFrom(string $url): string
125125
{
126-
preg_match('#(@\d+\.\d+\.\d+)/#', $url, $matches);
126+
preg_match('#(@\d+\.\d+\.\d+.*?)/#', $url, $matches);
127127

128128
if (! ($matches[1] ?? false)) {
129129
return 'Unknown Version';

tests/fixtures/npm/audit-importmap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
use Tonysm\ImportmapLaravel\Facades\Importmap;
44

55
Importmap::pin('is-svg', to: 'https://cdn.skypack.dev/[email protected]', preload: true);
6-
Importmap::pin('lodash', to: '/js/vendor/lodash.js'); // lodash@4.17.12
6+
Importmap::pin('lodash', to: '/js/vendor/lodash.js'); // @4.17.12

tests/fixtures/npm/outdated-importmap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
use Tonysm\ImportmapLaravel\Facades\Importmap;
44

55
Importmap::pin('is-svg', to: 'https://cdn.skypack.dev/[email protected]', preload: true);
6-
Importmap::pin('lodash', to: '/js/vendor/lodash.js'); // lodash@4.0.0
6+
Importmap::pin('lodash', to: '/js/vendor/lodash.js'); // @4.0.0

0 commit comments

Comments
 (0)