Skip to content

Commit

Permalink
Store the package name, version, and URL (with CDN) of the vendored f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
tonysm committed Feb 3, 2024
1 parent 2cb7fbd commit afef360
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 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".*$#',
'#Importmap::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\(["\']([^"\']*)["\'].*\)\; \/\/.*@(\d+\.\d+\.\d+(?:[^\s]*)).*\r?$/m', $content, $matches);
preg_match_all('/^Importmap::pin\(.+\)\;\s*\/\/\s*(.+?)@(.+?)\s+.*\r?$/m', $content, $matches);

if (count($matches) !== 3) {
return collect();
Expand Down
4 changes: 3 additions & 1 deletion src/Packager.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ public function vendoredPinFor(string $package, string $url): string
$version = $this->extractPackageVersionFrom($url);

return sprintf(
'Importmap::pin("%s", to: "%s"); // %s',
'Importmap::pin("%s", to: "%s"); // %s%s downloaded from %s',
$package,
Str::after($this->vendoredPackageName($package), 'resources'),
$package,
$version,
$url,
);
}

Expand Down

0 comments on commit afef360

Please sign in to comment.