diff --git a/src/Composer/ComposerPackage.php b/src/Composer/ComposerPackage.php index 972eb05..74d2139 100644 --- a/src/Composer/ComposerPackage.php +++ b/src/Composer/ComposerPackage.php @@ -123,10 +123,10 @@ 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]; } diff --git a/src/FileEnumerator.php b/src/FileEnumerator.php index a16611f..50ee49e 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 @@ +