Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: manage third party libs via composer #8240

Draft
wants to merge 10 commits into
base: release-3.0
Choose a base branch
from

Conversation

MissAllSunday
Copy link
Contributor

This is a simple POC for allowing SMF to handle their internal third party libraries via composer.

Some key features to take into consideration for this POC

  • Composer is solely used by SMF, that is, no access to mod authors. Mod authors can still ship their own vendor folder if they provide their respective configuration for it
  • Modifications to Simplemachines/build-tools will have to be made to further remove hardcoded instances of third party libs, happy to do those changes myself if required.
  • SMF release process will need to change to accommodate composer commands.

.scrutinizer.yml Outdated Show resolved Hide resolved
MissAllSunday and others added 2 commits June 17, 2024 13:47
Co-authored-by: John Rayes <live627@gmail.com>
Co-authored-by: John Rayes <live627@gmail.com>
@@ -1523,8 +1523,7 @@ public static function getFileVersions(array &$versionOptions): array
);

$ignore_sources = [
Config::$sourcedir . '/minify/*',
Config::$sourcedir . '/ReCaptcha/*',
Config::$vendordir . '/*',
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm reading the code right, this line can go because ``$vendordiris outside of$sourcedir`, no?

Comment on lines -1681 to +1695
include_once implode(DIRECTORY_SEPARATOR, [Config::$sourcedir, 'minify', 'src', 'Exception.php']);
include_once implode(DIRECTORY_SEPARATOR, [Config::$vendordir, 'minify', 'src', 'Exception.php']);

include_once implode(DIRECTORY_SEPARATOR, [Config::$sourcedir, 'minify', 'src', 'Exceptions', 'BasicException.php']);
include_once implode(DIRECTORY_SEPARATOR, [Config::$vendordir, 'minify', 'src', 'Exceptions', 'BasicException.php']);

include_once implode(DIRECTORY_SEPARATOR, [Config::$sourcedir, 'minify', 'src', 'Exceptions', 'FileImportException.php']);
include_once implode(DIRECTORY_SEPARATOR, [Config::$vendordir, 'minify', 'src', 'Exceptions', 'FileImportException.php']);

include_once implode(DIRECTORY_SEPARATOR, [Config::$sourcedir, 'minify', 'src', 'Exceptions', 'IOException.php']);
include_once implode(DIRECTORY_SEPARATOR, [Config::$vendordir, 'minify', 'src', 'Exceptions', 'IOException.php']);

include_once implode(DIRECTORY_SEPARATOR, [Config::$sourcedir, 'minify', 'src', 'Minify.php']);
include_once implode(DIRECTORY_SEPARATOR, [Config::$vendordir, 'minify', 'src', 'Minify.php']);

include_once implode(DIRECTORY_SEPARATOR, [Config::$sourcedir, 'minify', 'path-converter', 'src', 'Converter.php']);
include_once implode(DIRECTORY_SEPARATOR, [Config::$vendordir, 'minify', 'path-converter', 'src', 'Converter.php']);

include_once implode(DIRECTORY_SEPARATOR, [Config::$sourcedir, 'minify', 'src', 'CSS.php']);
include_once implode(DIRECTORY_SEPARATOR, [Config::$vendordir, 'minify', 'src', 'CSS.php']);

include_once implode(DIRECTORY_SEPARATOR, [Config::$sourcedir, 'minify', 'src', 'JS.php']);
include_once implode(DIRECTORY_SEPARATOR, [Config::$vendordir, 'minify', 'src', 'JS.php']);
Copy link
Contributor

Choose a reason for hiding this comment

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

would it not be better to just include the Composer autoload file here?

@@ -54,7 +54,7 @@
}

// 4. Get some more stuff we need.
require_once $sourcedir . '/Autoloader.php';
require_once '/vendor/autoload.php';
Copy link
Contributor

Choose a reason for hiding this comment

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

why the leading slash? Wouldn't that try to look in the top directory?

Comment on lines +137 to +162
$loader = require SMF\Config::$vendordir . '/autoload.php';
$third_party_mappers = [];

// Ensure $sourcedir is set to something valid.
if (class_exists(Config::class, false) && isset(Config::$sourcedir)) {
$sourcedir = Config::$sourcedir;
}

require_once SMF\Config::$sourcedir . '/Autoloader.php';
if (empty($sourcedir) || !is_dir($sourcedir)) {
$sourcedir = __DIR__;
}

// Do any third-party scripts want in on the fun?
if (!defined('SMF_INSTALLING') && class_exists(Config::class, false)) {
if (!class_exists(IntegrationHook::class, false) && is_file($sourcedir . '/IntegrationHook.php')) {
require_once $sourcedir . '/IntegrationHook.php';
}

if (class_exists(IntegrationHook::class, false)) {
IntegrationHook::call('integrate_autoload', [&$third_party_mappers]);
}
}

foreach ($third_party_mappers as $prefix => $dirname) {
$loader->addPsr4($prefix, $dirname);
}
Copy link
Member

@Sesquipedalian Sesquipedalian Jun 24, 2024

Choose a reason for hiding this comment

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

I'd prefer to see this code moved back into an autoloader class file rather than having it here in index.php.

Part of the reason for moving the existing autoloading code into a separate class was to avoid polluting the global namespace with variables in index.php. (Note: when backward compatibility support is enabled we end up putting references to class variables from SMF's namespace into the global namespace anyway, but the idea is to eliminate that in a future version.)

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.

3 participants