Skip to content

Commit

Permalink
Fix Windows path resolution
Browse files Browse the repository at this point in the history
Changed:
- Rename `$relativePath` to `$resolvedPath` in method `filterAutoloads()`
- Method `filterAutoloads()` to normalize the resolved autoload file paths
- Method `parseAutoloads()` to normalize the "vendor-dir" path
- Method `parseExcludedFiles()` to normalize the the excluded file paths

Fixed:
- Closes #2
- Closes #3
- Closes #4
- Closes #5
  • Loading branch information
mcaskill committed Dec 18, 2018
1 parent e9add63 commit 31576de
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/ExcludeFilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Composer\Package\PackageInterface;
use Composer\Plugin\PluginInterface;
use Composer\Script\ScriptEvents;
use Composer\Util\Filesystem;

class ExcludeFilePlugin implements
PluginInterface,
Expand Down Expand Up @@ -76,8 +77,10 @@ public function parseAutoloads()
return;
}

$vendorDir = $composer->getConfig()->get('vendor-dir');
$exclude = $this->parseExcludedFiles($exclude, $vendorDir);
$filesystem = new Filesystem();
$config = $composer->getConfig();
$vendorPath = $filesystem->normalizePath(realpath(realpath($config->get('vendor-dir'))));
$exclude = $this->parseExcludedFiles($exclude, $vendorPath);

$generator = $composer->getAutoloadGenerator();
$packages = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
Expand Down Expand Up @@ -122,7 +125,8 @@ private function filterAutoloads(array $packageMap, PackageInterface $mainPackag
$path = $package->getTargetDir() . '/' . $path;
}

$relativePath = $installPath . '/' . $path;
$resolvedPath = $installPath . '/' . $path;
$resolvedPath = strtr($resolvedPath, '\\', '/');

if (in_array($relativePath, $blacklist)) {
unset($autoload[$type][$key]);
Expand Down Expand Up @@ -164,13 +168,14 @@ private function getExcludedFiles(PackageInterface $package)
* Prepends the vendor directory to each path in "extra.exclude-from-files".
*
* @param string[] $paths Array of paths absolute from the vendor directory.
* @param string $vendorDir The directory for installed dependencies.
* @param string $vendorPath The directory for installed dependencies.
* @return array Retuns the list of excluded files, prepended with the vendor directory.
*/
private function parseExcludedFiles(array $paths, $vendorDir)
private function parseExcludedFiles(array $paths, $vendorPath)
{
foreach ($paths as &$path) {
$path = $vendorDir . '/' . $path;
$path = preg_replace('{/+}', '/', trim(strtr($path, '\\', '/'), '/'));
$path = $vendorPath . '/' . $path;
}

return $paths;
Expand Down

1 comment on commit 31576de

@zorca
Copy link

@zorca zorca commented on 31576de Dec 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please sign in to comment.