Skip to content

Commit

Permalink
Fix autoloading when installed as a package
Browse files Browse the repository at this point in the history
  • Loading branch information
imliam committed Oct 1, 2024
1 parent 6eaf5a5 commit c2103f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cpx/cpx",
"description": "Run any command from any composer package, even if it's not installed in your project.",
"version": "1.0.0",
"version": "1.0.1",
"type": "library",
"license": "MIT",
"keywords": [
Expand Down
16 changes: 15 additions & 1 deletion cpx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,21 @@ use Cpx\Commands\AliasesCommand;
use Cpx\Commands\UpgradeCommand;
use Cpx\Commands\VersionCommand;

require_once __DIR__ . '/vendor/autoload.php';
if (isset($GLOBALS['_composer_autoload_path'])) {
require_once $GLOBALS['_composer_autoload_path'];

unset($GLOBALS['_composer_autoload_path']);
} else {
foreach ([__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php'] as $file) {
if (file_exists($file)) {
require_once $file;

break;
}
}

unset($file);
}

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

0 comments on commit c2103f1

Please sign in to comment.