Improve TYPO3 Development with Composer 2.0

Improve TYPO3 Development with Composer 2.0

Woohoo! TYPO3 (aka PHP) people’s long-awaited Composer 2.0 has been launched with lightning-fast speed. In this blog, I want to highlight major features, TYPO3 meets Composer 2.0, an interesting TYPO3 case study for Composer 2.0, What if your TYPO3 project doesn’t support Composer 2.0, etc. As a TYPO3 Developer, you should be aware of it. Keep reading!

On 24th Oct, Composer 2.0 was officially announced by team Packagist. By inspiring Susi’s Blog (Miss TYPO3), I want to write an all-in-one TYPO3 + Composer 2.0 blog. If you are new to TYPO3 Composer, then I recommend reading one of my popular blog The Best Guide to TYPO3 Composer.

We are living in Composer-Era. Composer is the backbone of modern development in the TYPO3 landscape. It has been so much easier to pull in open-source as well as private TYPO3 extensions (packages) to your TYPO3 project.

I want to dedicate this blog to the Composer team and people who contribute lots to make TYPO3 compatible with Composer. Honestly, the team composer worked hard and released Composer 2.0 of this incredible piece of software. Big hands to those awesome people who give back to the OpenSource community (both Composer and TYPO3).

Composer 2.0 comes with performance improvements, error reporting improvements, and some features that will help check the compatibility PHP version/extensions at runtime. Explore All Features.

Composer 2.0 - Because Speed Matters

A major goal of Composer 2.0 was to improve as lightning super fast, here is the official test-drive by the composer team.

What/Why Composer is needed for TYPO3?

The Composer was a milestone in TYPO3’s history, such as TYPO3 v9. Composer allows us (TYPO3 Developers) to stop duplicating code and start reusing it in an easy and fast way. Today you can find an incredible number of TYPO3 extensions, and with one command, you can install them in your TYPO3 project. I am sure that without Composer, TYPO3 wouldn’t be the same.

What’s wrong with Composer 1.0 (History)

The composer was released more than 8 years ago which is a predecessor of PEAR which is a PHP package manager. The composer has become the de facto package manager for most of the PHP projects including TYPO3.

Composer although have served well, however, there has always been an issue with performance and memory consumption. The Composer version 2 aims to be more performant in terms of memory and faster download time.

When TYPO3 Meets Composer 2.0 (Case-Study)

I tried out Composer 2 and compared it with Composer 1 in a TYPO3 project executing the various tasks which are used on a general TYPO3 project.

Case 1. Create New TYPO3 Project

composer create-project “typo3/cms-base-distribution:^10” YourProjectName --prefer-dist

Case 2. Install New TYPO3 Extension

composer require nitsan/ns-backup

Case 3. Uninstall TYPO3 Extension

composer remove nitsan/ns-backup

Case 4. Install TYPO3 dependencies with composer.lock

composer install

Case 5. Update TYPO3 Core

composer update --with-dependencies

How’s the PHP Compatibility with Composer 2.0

Composer 2.0 still supports PHP 5.3+ but the team Composer is planning to remove support for older versions of PHP in future minor releases because they feel it’s really outdated and makes the code quite hard to maintain in places.

You can expect the Composer to only work on PHP 7.1 or later from Composer 2.2. So, it’s better to upgrade your TYPO3 projects to the latest PHP by that time!

Install & Upgrade Composer 2.0

If you are looking to freshly install Composer 2.0, then check How to install the Composer section.

Are you excited to upgrade your Composer 1 to Composer 2.0? Open your terminal and try the below commands.

// to try the latest RC version (2.x).
composer self-update --preview

// to try the latest dev build (2.x).
composer self-update --snapshot

// to go back to stable releases (1.x for now).
composer self-update --stable

// in CI/scripts, if you want to pin Composer to 1.x until you are ready to migrate, this will ensure you stay on 1.x releases even once a 2.0 stable comes out.
composer self-update --1

Upgrade to Composer 2.0

// To upgrade, the following command should be executed:
composer self-update --2

Downgrade to Composer 1.0

// Aha, If your TYPO3 project not compatible with Composer 2, you can roll back to Composer 1
composer self-update --1

As a TYPO3 Developer, What care is needed to support Composer 2.0?

As a TYPO3 Developer, you don’t need to pay extra care to support Composer 2.0. It means you don’t need to make any changes to your composer.json.

But, in some cases, you might get the following error.

“You are using Composer 2, which some of your plugins seem to be incompatible with. Make sure you update your plugins or report a plugin-issue to ask them to support Composer 2.”

Then make sure, your all dependent TYPO3 extensions have properly configured and support Composer 2.0 as below.

"require": {
    "composer-plugin-api": "^1.0 || ^2.0"
},

"require-dev": {
    "composer/composer": "1.6.* || 2.0.*",
    "composer/semver": "1.0.* || 2.0.*",
},

In a worst-case scenario, You can continue with composer 1.0 to keep work on your TYPO3 project ;)

What if 3rd party TYPO3 extensions don’t support Composer 2.0?

Good thing is that Composer 2 is providing backward compatibility. The one issue you're most likely to encounter when upgrading to Composer 2 is having Composer TYPO3 extensions that don't support this newer version yet.

The ideal solution would be upgrading those TYPO3 extensions to newer versions (or submitting a feature request to the TYPO3 extension’s developers to support Composer 2). But if that's not feasible you can actually co-install both Composer 1 and Composer 2 by following these steps:

Step 1. Install composer v1 separately

sudo cp `which composer` /usr/local/bin/composer1
sudo composer1 self-update --1

Step 2. Upgrade Composer to v2

sudo composer self-update --2

Step 3. Add composer v2 alias (optional)

sudo ln -s `which composer` /usr/local/bin/composer2

TYPO3 Community Wants You

As a give back to the TYPO3 Community, Please ensure your TYPO3 extensions which are published at TER (TYPO3 Extensions Repository) will support Composer 2.0 :)

Conclusion

Thanks for reading my blog.

I hope you learned and enjoy the journey of TYPO3 & Composer 2.0. Let’s have a quick recap.

  • First of all, You should update your composer with `composer self-update --2` to get lightning-fast speed into your TYPO3 project.
  • Test-drive Composer 2.0 with your new & existing TYPO3 project.
  • As TYPO3 Developer and CLI-users, Read all features available in Composer 2.0
  • In case, If your TYPO3 project causes compatibility issues with Composer 2.0, then either set up both Composer versions or just rollback to Composer 1.0 for a while.
  • Last but not least, Make sure your published TYPO3 extensions are supporting awesome Composer 2.0.

Have a Happy TYPO3 with Composer 2.0!

Post Comment

Your email address will not be published. Required fields are marked *

×

Name is required!

Enter valid name

Valid email is required!

Enter valid email address

Comment is required!

Google Captcha Is Required!

Be the First to Comment
10+ Women of TYPO3 Who Code, Design, and Inspire!

10+ Women of TYPO3 Who Code, Design, and Inspire!

TYPO3 Women & Girls rocks at TYPO3 community! Today, I’m proud to write first-time in the TYPO3 history blog about T3-Womaniya ;)…

7 Best TYPO3 Code Quality, Review & Lint Tools

7 Best TYPO3 Code Quality, Review & Lint Tools

Are you looking for good practices on TYPO3 code quality? Then, you are in the correct place. In this article, You will find…

Get Prepared for TYPO3 v10

Get Prepared for TYPO3 v10 - Before It’s Release

Woohoo! Team T3Terminal is very excited for TYPO3 v10 LTS that is going to be released on 21st April 2020 :)Are you also…

Stay up to date with our recent TYPO3 Blogs, news, & updates