Add Composer support #32

Closed
Rarst opened this Issue Jun 29, 2013 · 32 comments

Projects

None yet

8 participants

@Rarst
Rarst commented Jun 29, 2013

Supporting Composer simplifies a lot consuming and updating a library ( as previously requested in #24 ) in downstream projects, as opposed to consuming it with Git and using as submodule.

The main challenge is however path logic of Hybrid core that require it to be nested directly inside theme folder (which Composer doesn't support, see composer/composer#1767 ).

Might this be considered for refactoring and moving towards Composer support?

@lkraav
lkraav commented Jun 29, 2013

+1

@Rarst
Rarst commented Jun 29, 2013

Ok, for those interested and not easily scared I had actually tortured Hybrid Core to work as Composer package in current state for my theme: https://bitbucket.org/Rarst/hybrid-wing/commits/03b010f1b45ef9ba381c49e659d3f740a1b34821

@getdave
getdave commented Oct 9, 2013

@Rarst As I understand it all this requires is adding the following contents to a file called composer.json to the root of the repo.

{
    "name": "justintadlock/hybrid-core",
    "authors": [
        {
            "name": "Justin Tadlock",
            "email": "justin@hisdomain.tdl"
        }
    ],
    "type": "wordpress-theme",
    "require": {
        "composer/installers": "~1.0"
    }
}

Note: I'm not sure about what @justintadlock would need to specifiy as the "type". It's not really a theme is it?

I'll defer to your superior knowledge. I would like to add Hybrid as a dependency of my them so thanks for pushing this.

@Rarst
Rarst commented Oct 9, 2013

Not that easy since Hybrid Core is not a theme indeed and in current state needs to be inside a theme to work. Well without subclassing and dirty hacks I did for myself.

@justintadlock
Owner

Composer support is not even on my radar for the moment. It's not that it's something that isn't useful or won't be considered at some point in the future. It's just that for the majority of uses at the moment, it's not important.

From what I understand, the biggest issue in the way is the HYBRID_DIR and HYBRID_URI constants, which are the items that force Hybrid Core to be used as a sub-directory inside of a theme.

There's always been a purpose to having those constants defined, which is to make sure Hybrid Core was run inside a theme. Before opening that up, I wanted the framework to mature enough to be used as something like a plugin, for example. Plus, testing of every Hybrid Core feature to make sure it can run outside of the theme is paramount for a change like this. I believe we're at that point, so it's really all about testing.

Don't expect composer support to be rolled into Hybrid Core any time soon, if ever. However, if there are any other changes to Hybrid Core that need to be done to facilitate adding your own composer support, I'm up for that.

@getdave
getdave commented Oct 11, 2013

@justintadlock Thanks for summarising your thoughts and rationale. I think it's clear that composer support is low down the priority list. Glad to hear you're thinking about it though.

Thanks for all your work on Hybrid. It's really excellent.

@Rarst
Rarst commented Mar 20, 2014

Don't expect composer support to be rolled into Hybrid Core any time soon, if ever.

Why not at current stage? Constants thing had been implemented for upcoming v2 core release. After that there isn't anything required to be changed on the table for Composer support, just actually doing it and seeing how it goes.

I doubt there would be considerable immediate demand/adoption, but just having it in would be very helpful for those with Composer-heavy workflows like me.

@justintadlock
Owner

In all honesty, I'm not familiar with Composer one bit. Because there has been so little demand for it, it's hard for me to make it a priority when I have so many other items that are in need of attention. Basically, it comes down to me learning and fully understanding something entirely new (I'd never add something to the framework that I didn't understand completely). I enjoy learning new things, which is a bit of a prerequisite in this business, but I have more pressing matters at the moment.

Like I said earlier, if there's anything I can do to facilitate someone adding this themselves, I'm up for it. It's just not the time for something like this to be built directly in.

@Rarst
Rarst commented Mar 21, 2014

Well, as above — it pretty much was doable already and with constants it's doable more easily. The reason to actually include it are:

  • convenience (managing of packages for natively composer-enabled project happens by itself, without it someone needs to manage releases by hand and fork or otherwise maintain it)
  • ease of use (it helps to support composer for people to actually use composer, chicken/egg)

What's the worst thing that could happen from just going ahead and adding it really? It doesn't affect existing users one bit since it doesn't require them to switch to using it.

@justintadlock
Owner

It's not about what could happen with adding it, good or bad. It's about me, Justin Tadlock, personally understanding Composer. It's not something I've had time to delve into. Without that understanding, I won't make a decision on whether to add it.

This is simply about a lack of knowledge on my part.

@Rarst
Rarst commented Mar 21, 2014

I get that part (and rather admire it :), just trying to find a practical angle through/over/around it.

As you said yourself — it's not a priority because there isn't demand, well here is me being demand.

@getdave
getdave commented Mar 24, 2014

@justintadlock I second that "demand" and can also confirm with @Rarst that adding Composer support will not effect current users but it will enhance Hybrid Core for those users (like myself) who use Composer.

I totally get it that time is a massive issue here and you're right to focus on more pressing concerns. Nonetheless please consider that adding a composer.json file will not in any way effect the framework at all. I'd understand your hesitancy if we were suggesting adding some new PHP code but given that this is purely an enhancement and will have no knock-on effects I don't see any issue here. However I respect that you are the repo owner and will defer to what you feel comfortable with.

Nonetheless, is there anything @Rarst and I can do to add Composer support on your behalf? Would a pull request help?

Also if you're interesting in getting a basic intro to Composer + WordPress then you could check out my article on Smashing Mag (shameless plug!).

@lkraav
lkraav commented Mar 24, 2014

Maybe if @Rarst made a short screencast of example usage and linked to it in commit message. As @justintadlock said learning enough about the beast to understand it is the issue.

@lkraav
lkraav commented Mar 24, 2014

Lolz that's indeed quite a bit. YET... if a play icon would show the magic that happens after typing "composer update", the barrier might really disappear underground.

@sheabunge

@lkraav Rarst does have a Composer talk on WordPress.tv - not specific to Hybrid Core, but does give a working example.

@justintadlock
Owner

Thanks for the links, everyone. I'll be reviewing them and trying to learn.

@pdewouters

big plus one from me too. Would be great to have composer support. I think the main problem might be for those who currently have it as a submodule in existing projects?

@JamesGeiger

Looks at composer, thinks oh man, web development is already hard enough. Now I gotta learn something else...

Also in my humble opinion, maybe a few people will use it, but not many. Don't get mad at me for saying that. I know you guys are big fans of it :)

@Rarst
Rarst commented May 24, 2014

web development is already hard enough

Yes, it is very hard to keep track of all the libraries and components I use and update them easily and reliably from version to version. If only there was a software that would do it for me... ;)

Also in my humble opinion, maybe a few people will use it, but not many.

Composer is de-facto how anything and everything gets used in larger PHP world now. The only reason for "few people" impression is that WP is being backwards about it.

@JamesGeiger

Maybe I will research it tonight. I can definitely see its benefits, I just have a lot of things to learn already. Also, I am not an expert, so was just giving my humble opinion :)

@Rarst
Rarst commented May 24, 2014

Ok, I made that gif after all :)

composer

composer create-project rarst/hybrid-wing:dev-master --repository-url=http://rarst.net
@justintadlock
Owner

I'm still following this. I'm reading bits here and there on Composer. Unfortunately, most Composer-related documentation is written by programmers rather than writers who know how to program or programmers who know how to write. :)

@getdave - Your Smashing article was helpful and is actually the best-written tutorial I've seen yet.

Justin's progress thus far: Installed Composer on computer.


Some ways to help this along for those of you interested in Composer support:

  • Explain to Justin, step-by-step, what he would need to do. Pretend no time has passed since I was this guy and my knowledge level remains the same.
  • Provide actual code, files, etc. that needs to be added to Hybrid Core.
@Rarst
Rarst commented May 26, 2014

Steps:

  1. Reading, discussing, and understading composer.json pull requested in #64 Then preferably merging :)
  2. Adding Hybrid Core package to Packagist for easy installation.
  3. Producing example of using Hybrid Core as Composer package, I could probably do fork of Hybrid Base or something to show it.
  4. Considering converting Hybrid Core's dependencies to Composer (all those extensions).
@justintadlock
Owner

Thanks for this. I have a pretty good understanding of the code. Seeing exactly what I needed to add helps.

Reading, discussing, and understading composer.json pull requested in #64 Then preferably merging :)

What is the autoload section for?

Adding Hybrid Core package to Packagist for easy installation.

Is it possible to run the package from my own site? Or, is that something more complex that I need to wait to get into?

Producing example of using Hybrid Core as Composer package, I could probably do fork of Hybrid Base or something to show it.

Yeah, I'd want to see how that's done.

Considering converting Hybrid Core's dependencies to Composer (all those extensions).

What effect would that have on people downloading all of Hybrid Core? Would they still be able to do a Git Clone or dowload the ZIP from here and get all of the files?

@Rarst
Rarst commented May 26, 2014

What is the autoload section for?

When Composer package is installed (by itself or as dependency for another package) Composer produces vendor/autoload.php file. Simply includeing that file registers PHP autoloader for all packages involved.

So that section explains Composer what it needs to add to autoload for Hybrid Core. It's not much since it handles most of the loading itself.

Is it possible to run the package from my own site? Or, is that something more complex that I need to wait to get into?

Absolutely possible (Composer infrastructure is 100% open), easiest is to use Satis. I can help you out with setup.

It's not hard but my personal opinion (having run my own Satis instance and still having it around) it is best to simply go with Packagist for any and all public packages.

Yeah, I'd want to see how that's done.

Ok, it's on me to do some time soon.

I do have setup already in Hybrid Wing, but it's a little too hacked up and packed full of details that will go away with native Composer support in Hybrid Core so don't bother looking at that. :)

What effect would that have on people downloading all of Hybrid Core? Would they still be able to do a Git Clone or dowload the ZIP from here and get all of the files?

If you decide to convert plugins to dependencies people would need to either create Core project via Composer directly or clone from GitHub and run Composer install command. You can still pack complete "built" downloads, but outside of GitHub.

This one is conversation for another day really, just mentioned it as possible "roadmap" after we have Core and themes workflows done. :)

@andydownunder

What effect would that have on people downloading all of Hybrid Core? Would they still be able to do a Git Clone or dowload the ZIP from here and get all of the files?

If you decide to convert plugins to dependencies people would need to either create Core project via Composer directly or clone from GitHub and run Composer install command. You can still pack complete "built" downloads, but outside of GitHub.

This would be a big problem for me. I do not use Composer in my workflow, but I do pull from the HC git repository all the time. I'm certainly not going to install some big package management software and run commands just to get a complete download of Hybrid Core after doing a git pull. Big -1.

@Rarst
Rarst commented May 26, 2014

I highly doubt Hybrid Core would introduce Composer as hard absolute requirement any time soon. Personally I am not and not going to be pushing for that. :)

Your opinion on how much you want to be using Composer might go through some changes once you get some experience with it. :)

@justintadlock
Owner

As far as I'm concerned, we currently have Composer support. I just need to set up things on Packagist, which requires that the Master branch have the composer.json file. I'll be pushing the 2.0 branch into the Master branch within the next week (that's the plan anyway).

If anyone wants to see how the composer.json file looks or suggest changes, see this file:
https://github.com/justintadlock/hybrid-core/blob/2.0/composer.json

Absolutely possible (Composer infrastructure is 100% open), easiest is to use Satis. I can help you out with setup.

It's not hard but my personal opinion (having run my own Satis instance and still having it around) it is best to simply go with Packagist for any and all public packages.

Thanks. I'll probably go with Packagist for the moment.

If you decide to convert plugins to dependencies people would need to either create Core project via Composer directly or clone from GitHub and run Composer install command. You can still pack complete "built" downloads, but outside of GitHub.

This one is conversation for another day really, just mentioned it as possible "roadmap" after we have Core and themes workflows done. :)

That's what I was thinking would happen. That's definitely a conversation for the future. Right now, I just want the focus to be on allowing those of you who want to use Composer to do so.

This would be a big problem for me. I do not use Composer in my workflow, but I do pull from the HC git repository all the time. I'm certainly not going to install some big package management software and run commands just to get a complete download of Hybrid Core after doing a git pull. Big -1.

Composer will not now and should never be a requirement, which is why I asked the question. Basically, I want to allow folks to use Composer if they wish but not force anyone into it. I'm not personally using Composer, so any type of requirement of it would be out of the question.

@justintadlock
Owner

Here's the Packagist link: https://packagist.org/packages/justintadlock/hybrid-core

I'm closing this one now. Please open new tickets or pull requests for any changes that are required.

I think we can all give @Rarst a pat on the back now, right?

@Rarst
Rarst commented Jul 14, 2014

👍 👍

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