Story #65106
closedQuestion: composer.json in own extension and requires: How to do it correctly ..?
0%
Description
Hi,
I really would like to know, how to create a correct composer.json for my own extension.
I am quite clear that I have to set the type to "typo3-cms-extension".
The default composer.json mentioned on http://composer.typo3.org is rather lagging.
1.) With 7.x and 6.10 one should also define the class namespace, if I understand this correctly. If it is possible (newer extensions).
2.) How to handle require. This is actually quite important as the ext_emconf.php requires are basically ignored if a composer.json exists.
Except if I create a Package.php file where I enforce the use fo the ext_emconf.php file.
Now, I cannot add typo3-ter/ext as the Vendorname typo3-ter is only for the download of extensions via composer.typo3.org
And the extension would therefore not be found which is actually the correct behaviour as the extension itself will most certainly not have typo3-ter as vendor :)
Now, one possibility would be to add only the extension name in require. But I believe this is not completely correct with the composer.json naming convention but it would work. It might also require a corresponding replace in once own composer.json
I would just like to know if something like this would be the correct way to do it:
{ "name": "AndreasA/composerdemoext", "description": "Just a demo composer.json for a typo3 ext", "type": "typo3-cms-extension", "version": "1.0.0", "replace": { "composerdemoext": "self.version" }, "require": { "typo3/cms-core": "~6.2", "static_info_tables": "~6.0" }
That way in other extensions where I want to require this "compsoerdemoext" extension I could also use "require": {"composerdemoext": "1.0.0" } because of the replace.
And the static_info_tables Extension would also be found because that is the Extension name ithout a composer.json. With a composer.json that extension might require the corresponding replace.
Not sure if self.version is enough in replace but it should be.
Of course, those names are not exactly correct composer names, so I am not sure that is the correct way to create a composer.json.
In the future when does extensions might use composer names, I would be able to keep the file in this way if those extensions also use replace but I then should also be able to change the require part to the name defined in the corresponding composer.json.
e.g. In this example: "require": {"AndreasA/composerdemoext": "1.0.0" }
Updated by Andreas Allacher almost 10 years ago
Also: This should be documented somewhere.
Small correction, forgot the new autoload section:
{ "name": "AndreasA/composerdemoext", "description": "Just a demo composer.json for a typo3 ext", "type": "typo3-cms-extension", "version": "1.0.0", "replace": { "composerdemoext": "self.version" }, "require": { "typo3/cms-core": "~6.2", "static_info_tables": "~6.0" }, "autoload": { "classmap": ["Classes"] }, }
Updated by Andreas Allacher almost 10 years ago
Actually regarding Classloader shouldn't it be actually like this. I just copied the autoload part from the current news extension:
https://git.typo3.org/TYPO3CMS/Extensions/news.git/commitdiff/991de43c29a333adfb7dbcdfeb11d558c5671a97
But I think it should be like this:
{ "name": "AndreasA/composerdemoext", "description": "Just a demo composer.json for a typo3 ext", "type": "typo3-cms-extension", "version": "1.0.0", "replace": { "composerdemoext": "self.version" }, "require": { "typo3/cms-core": "~6.2", "static_info_tables": "~6.0" }, "autoload": { "psr-4": { "AndreasA\\Composerdemoext\\": "Classes/" } }, "autoload-dev": { "psr-4": { "AndreasA\\Composerdemoext\\Tests": "Tests/" } } }
Updated by Andreas Allacher almost 10 years ago
Regards, to last comment classmap makes sense for news because it currently uses Tx_News_* classnames instead of namespaces.
Updated by Wouter Wolters almost 10 years ago
- Status changed from New to Rejected
Hi Andreas,
Good to read your are starting to use composer.
But this is not the place to ask these questions, this is a bug-tracker.
Please move your question to the forum: http://forum.typo3.org
Thanks
Updated by Andreas Allacher almost 10 years ago
True in a way.
However, it also means that there is kind of a lack of documentation regarding this which I think should be fixed.
Anway, I created a forum thread (hopefully the correct forum):
http://forum.typo3.org/index.php?t=msg&th=208621
Btw. is an ext_emconf.php even required still with 6.2.10+. If so what about 7.1+ ?
Updated by Wouter Wolters almost 10 years ago
I'm sure the documentation will be fixed and made better, but we have different focus levels per release for TYPO3 CMS 7.
See the roadmap http://typo3.org/typo3-cms/roadmap/
In TYPO3 CMS 7.3 the focus is also composer intergration.
Updated by Andreas Allacher almost 10 years ago
I actually know the roadmap but with regards to the already new composer ClassLoader (which will also be available in 6.2.10 from what I understand) it makes sense to use correct composer.json already so I wanted to ask.
I am really looking forward to 7 LTS.
I am currently especially interested in 7.3 but I am sure there will be other interesting features.
Updated by Sybille Peters over 5 years ago
Please see the new page https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ExtensionArchitecture/ComposerJson/Index.html in the documentation (look at the page for the respective version you are using by clicking on "Related Link" and then selecting your version).
Additionally, you can ask questions on Stack Overflow (use tag "typo3") or in Slack #typo3-cms. (https://typo3.org/help/)
About questions or suggestions for documentation, you can ask in #typo3-documentation on Slack.
I suggest to close this now.