Skip to content

Commit

Permalink
Fix symlinked files autoloaders package relative path Fix #78
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHenryIE committed Dec 10, 2023
1 parent 13c6531 commit af1ac75
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/Composer/ComposerPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public function __construct(Composer $composer, array $overrideAutoload = null)
if (file_exists($vendorDirectory . DIRECTORY_SEPARATOR . $this->packageName)) {
$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)) {
$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).
$this->relativePath = $output_array[1];
Expand Down
9 changes: 1 addition & 8 deletions src/FileEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,8 @@ public function compileFileList(): void

foreach ($namespace_relative_paths as $namespace_relative_path) {
if (is_file($packagePath . $namespace_relative_path)) {
// $finder->files()->name($file)->in($source_path);

$sourceAbsoluteFilepath = $packagePath . $namespace_relative_path;

$outputRelativeFilepath = str_replace($prefixToRemove, '', $sourceAbsoluteFilepath);
$outputRelativeFilepath = preg_replace('#[\\\/]+#', DIRECTORY_SEPARATOR, $outputRelativeFilepath);
if (is_null($outputRelativeFilepath)) {
throw new \Exception('Error replacing directory separator in outputRelativeFilepath.');
}
$outputRelativeFilepath = $dependency->getRelativePath() . DIRECTORY_SEPARATOR . $namespace_relative_path;

$file = array(
'dependency' => $dependency,
Expand Down

0 comments on commit af1ac75

Please sign in to comment.