From e984ffddd5d53466a042036045897fcff057d273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojtek=20Sza=C5=82kiewicz?= Date: Thu, 25 Apr 2024 13:35:27 +0200 Subject: [PATCH 1/3] feat: add path normalization for windows --- src/FileEnumerator.php | 5 +++-- src/Helpers/Path.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/Helpers/Path.php diff --git a/src/FileEnumerator.php b/src/FileEnumerator.php index d46e846..f1fa64d 100644 --- a/src/FileEnumerator.php +++ b/src/FileEnumerator.php @@ -9,6 +9,7 @@ use BrianHenryIE\Strauss\Composer\ComposerPackage; use BrianHenryIE\Strauss\Composer\Extra\StraussConfig; +use BrianHenryIE\Strauss\Helpers\Path; use League\Flysystem\Filesystem; use League\Flysystem\Local\LocalFilesystemAdapter; use RecursiveDirectoryIterator; @@ -125,7 +126,7 @@ public function compileFileList(): DiscoveredFiles $this->addFile($dependency, $namespaceRelativePath, $type); } elseif (is_dir($sourceAbsolutePath)) { // trailingslashit(). (to remove duplicates). - $sourcePath = rtrim($sourceAbsolutePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; + $sourcePath = Path::normalize($sourceAbsolutePath); // $this->findFilesInDirectory() $finder = new Finder(); @@ -139,7 +140,7 @@ public function compileFileList(): DiscoveredFiles continue; } - $namespaceRelativePath = rtrim($namespaceRelativePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; + $namespaceRelativePath = Path::normalize($namespaceRelativePath); $this->addFile( $dependency, diff --git a/src/Helpers/Path.php b/src/Helpers/Path.php new file mode 100644 index 0000000..5edfd04 --- /dev/null +++ b/src/Helpers/Path.php @@ -0,0 +1,11 @@ + Date: Thu, 25 Apr 2024 13:35:56 +0200 Subject: [PATCH 2/3] feat: add else block for package relative path --- src/Composer/ComposerPackage.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Composer/ComposerPackage.php b/src/Composer/ComposerPackage.php index 972eb05..135b6fc 100644 --- a/src/Composer/ComposerPackage.php +++ b/src/Composer/ComposerPackage.php @@ -7,6 +7,7 @@ namespace BrianHenryIE\Strauss\Composer; +use BrianHenryIE\Strauss\Helpers\Path; use Composer\Composer; use Composer\Factory; use Composer\IO\NullIO; @@ -128,6 +129,8 @@ public function __construct(Composer $composer, array $overrideAutoload = null) } elseif (1 === preg_match('/.*\/([^\/]*\/[^\/]*)\/composer.json/', $composerJsonFileAbsolute, $output_array)) { // Not every package gets installed to a folder matching its name (crewlabs/unsplash). $this->relativePath = $output_array[1]; + } else { + $this->relativePath = Path::normalize($this->packageName); } if (!is_null($overrideAutoload)) { From c6754a3138862452803d9df24ef4084c543b9ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojtek=20Sza=C5=82kiewicz?= Date: Thu, 25 Apr 2024 14:31:21 +0200 Subject: [PATCH 3/3] fix: package path regexes --- src/Composer/ComposerPackage.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Composer/ComposerPackage.php b/src/Composer/ComposerPackage.php index 135b6fc..74d2139 100644 --- a/src/Composer/ComposerPackage.php +++ b/src/Composer/ComposerPackage.php @@ -7,7 +7,6 @@ namespace BrianHenryIE\Strauss\Composer; -use BrianHenryIE\Strauss\Helpers\Path; use Composer\Composer; use Composer\Factory; use Composer\IO\NullIO; @@ -124,13 +123,11 @@ public function __construct(Composer $composer, array $overrideAutoload = null) $this->relativePath = $this->packageName; $this->packageAbsolutePath = realpath($vendorDirectory . DIRECTORY_SEPARATOR . $this->packageName) . DIRECTORY_SEPARATOR; // If the package is symlinked, the path will be outside the working directory. - } elseif (0 !== strpos($absolutePath, getcwd()) && 1 === preg_match('/.*\/([^\/]*\/[^\/]*)\/[^\/]*/', $vendorDirectory, $output_array)) { + } elseif (0 !== strpos($absolutePath, getcwd()) && 1 === preg_match('/.*[\/\\\\]([^\/\\\\]*[\/\\\\][^\/\\\\]*)[\/\\\\][^\/\\\\]*/', $vendorDirectory, $output_array)) { $this->relativePath = $output_array[1]; - } elseif (1 === preg_match('/.*\/([^\/]*\/[^\/]*)\/composer.json/', $composerJsonFileAbsolute, $output_array)) { - // Not every package gets installed to a folder matching its name (crewlabs/unsplash). + } elseif (1 === preg_match('/.*[\/\\\\]([^\/\\\\]+[\/\\\\][^\/\\\\]+)[\/\\\\]composer.json/', $composerJsonFileAbsolute, $output_array)) { + // Not every package gets installed to a folder matching its name (crewlabs/unsplash). $this->relativePath = $output_array[1]; - } else { - $this->relativePath = Path::normalize($this->packageName); } if (!is_null($overrideAutoload)) {