Skip to content

Commit

Permalink
Merge pull request #50 from tonysm/tm/fix-previous-version-detection
Browse files Browse the repository at this point in the history
Fix outdated command breaks on previous comment format
  • Loading branch information
tonysm authored Feb 4, 2024
2 parents d4e67ab + 3c1f08c commit 34ecbc3
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Commands/PinCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Npm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Packager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/npm/audit-importmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
use Tonysm\ImportmapLaravel\Facades\Importmap;

Importmap::pin('is-svg', to: 'https://cdn.skypack.dev/[email protected]', 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
2 changes: 1 addition & 1 deletion tests/fixtures/npm/outdated-importmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
use Tonysm\ImportmapLaravel\Facades\Importmap;

Importmap::pin('is-svg', to: 'https://cdn.skypack.dev/[email protected]', 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

0 comments on commit 34ecbc3

Please sign in to comment.