Skip to content

Don't include vendor folder in transport package - #184

Open
hugopeek wants to merge 1 commit into
theboxer:3.xfrom
hugopeek:dont-package-vendor-folder
Open

hugopeek wants to merge 1 commit into
theboxer:3.xfrom
hugopeek:dont-package-vendor-folder

Conversation

@hugopeek

Copy link
Copy Markdown

This revives the old 'composer' flag from @Jako . If set to true, the vendor folder will be moved temporarily and restored after the transport package is created.

This revives the old 'composer' flag from Jako. If set to true, the vendor folder will be moved temporarily and restored after the transport package is created.
@Jako

Jako commented May 29, 2025 •

Copy link
Copy Markdown
Contributor

In that case, a composer.phar file has to be added in the core/components/<namespace> folder and the following script can be added the gpm.json in the build -> scriptsAfter section:

"build": {
    "scriptsAfter": [
        "script.composer.php"
    ]
}

script.composer.php

<?php
/**
 * Resolve Composer dependencies
 *
 * @package gpm
 * @subpackage build
 *
 * @var array $options
 * @var xPDOTransport $transport
 */

use Composer\Console\HtmlOutputFormatter;
use Composer\Factory;
use Composer\Installer;
use Composer\IO\BufferIO;
use Symfony\Component\Console\Output\StreamOutput;
use xPDO\Transport\xPDOTransport;

$success = true;
if ($transport->xpdo) {
    switch ($options[xPDOTransport::PACKAGE_ACTION]) {
        case xPDOTransport::ACTION_INSTALL:
        case xPDOTransport::ACTION_UPGRADE:
            $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Installing/updating dependencies, this may take some time...');

            $path = MODX_CORE_PATH . "components/{$transport->name}/";

            // Set Composer environment variables
            putenv("COMPOSER={$path}composer.json");
            putenv("COMPOSER_HOME={$path}.composer");
            putenv("COMPOSER_VENDOR_DIR={$path}vendor/");

            // Change the path to the package namespace folder, to prevent autoloading other namespaces
            chdir($path);

            require "phar://{$path}composer.phar/vendor/autoload.php";

            // Run Composer without proc_open/exec
            $io = new BufferIO('', StreamOutput::VERBOSITY_NORMAL, new HtmlOutputFormatter());
            $composer = Factory::create($io);
            $install = Installer::create($io, $composer);
            $install
                ->setPreferDist(true)
                ->setDevMode(false)
                ->setOptimizeAutoloader(true)
                ->setUpdate(false)
                ->setPreferStable(true);

            try {
                $install->run();
            } catch (Exception $e) {
                $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, get_class($e) . ' installing dependencies: ' . $e->getMessage());
                echo get_class($e) . ': ' . $e->getMessage() . "\n";
                $success = false;
            }

            $output = $io->getOutput();
            $output = nl2br(trim($output));
            $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, $output);
            break;
        case xPDOTransport::ACTION_UNINSTALL:
            break;
    }
}
return $success;

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants