Skip to content

Commit c2103f1

Browse files
committed
Fix autoloading when installed as a package
1 parent 6eaf5a5 commit c2103f1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cpx/cpx",
33
"description": "Run any command from any composer package, even if it's not installed in your project.",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"type": "library",
66
"license": "MIT",
77
"keywords": [

cpx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,21 @@ use Cpx\Commands\AliasesCommand;
1818
use Cpx\Commands\UpgradeCommand;
1919
use Cpx\Commands\VersionCommand;
2020

21-
require_once __DIR__ . '/vendor/autoload.php';
21+
if (isset($GLOBALS['_composer_autoload_path'])) {
22+
require_once $GLOBALS['_composer_autoload_path'];
23+
24+
unset($GLOBALS['_composer_autoload_path']);
25+
} else {
26+
foreach ([__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php'] as $file) {
27+
if (file_exists($file)) {
28+
require_once $file;
29+
30+
break;
31+
}
32+
}
33+
34+
unset($file);
35+
}
2236

2337
function printColor(string $message, string $color = "\033[1;32m"): void
2438
{

0 commit comments

Comments
 (0)