From afef3601f8eb065c60810c801f9b2a70c7940e38 Mon Sep 17 00:00:00 2001 From: Tony Messias Date: Sat, 3 Feb 2024 19:17:24 -0300 Subject: [PATCH] Store the package name, version, and URL (with CDN) of the vendored files --- src/Commands/PinCommand.php | 2 +- src/Npm.php | 2 +- src/Packager.php | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Commands/PinCommand.php b/src/Commands/PinCommand.php index b23c026..2c9fde0 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".*$#', + '#Importmap::pin\([\'\"]%s[\'\"].*$#', preg_quote($package), ); } diff --git a/src/Npm.php b/src/Npm.php index bea82cc..3de19f1 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\(["\']([^"\']*)["\'].*\)\; \/\/.*@(\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(); diff --git a/src/Packager.php b/src/Packager.php index 08c040f..ea4f1e3 100644 --- a/src/Packager.php +++ b/src/Packager.php @@ -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, ); }