Skip to content

Commit

Permalink
Switch to relative paths
Browse files Browse the repository at this point in the history
When this package was initially designed it didn't take into account situations where files aren't
moved. But are mounted into a running Docker container for development. By switching to relative
paths both situations, and most logical others are supported.

Resolves: WyriHaximus/reactphp-child-process-messenger#72 (reported by @lucasnetau)
  • Loading branch information
WyriHaximus committed Jul 10, 2021
1 parent 3345df5 commit 7b413e8
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "MIT",
"require": {
"php": "^8 || ^7.4",
"composer-plugin-api": "^2"
"composer-plugin-api": "^2",
"wikimedia/relpath": "^2.1"
},
"require-dev": {
"wyrihaximus/test-utilities": "^3"
Expand Down
51 changes: 49 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/BinAutoloadPathUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Composer\Plugin\PluginInterface;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;
use Wikimedia\RelPath;

use function array_key_exists;
use function dirname;
Expand Down Expand Up @@ -72,7 +73,9 @@ private static function updatePackage(PackageInterface $package, string $vendorD
}

foreach ($package->getExtra()['wyrihaximus']['bin-autoload-path-update'] as $binPath) {
self::updateBinPath(self::getVendorPath($vendorDir, $package) . $binPath, $autoloaderPath);
$vendorPath = self::getVendorPath($vendorDir, $package);
$relativeAutoloaderPath = (string) RelPath::getRelativePath($autoloaderPath, dirname($vendorPath . $binPath));
self::updateBinPath($vendorPath . $binPath, $relativeAutoloaderPath);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/BinAutoloadPathUpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public function update(): void

self::assertFileExists($tmpDir . 'bin/app-name');
self::assertFileExists($tmpDir . 'vendor/wyrihaximus/b/bin/app-b-name');
self::assertSame($tmpDir . 'vendor/autoload.php', file_get_contents($tmpDir . 'bin/app-name'));
self::assertSame($tmpDir . 'vendor/autoload.php', file_get_contents($tmpDir . 'vendor/wyrihaximus/b/bin/app-b-name'));
self::assertSame('../vendor/autoload.php', file_get_contents($tmpDir . 'bin/app-name'));
self::assertSame('../../../autoload.php', file_get_contents($tmpDir . 'vendor/wyrihaximus/b/bin/app-b-name'));
}

/**
Expand Down

0 comments on commit 7b413e8

Please sign in to comment.