13

Introduction

This is quite a lengthy question, the question I asked in the title is probably ambiguous and I may change this to something more suitable.

A similar question has already been asked and answered here although I do not think this entirely answers the question.

Synopsis

I am working with a team of developers on a project. We are using a framework (for argument sake - the framework is irrelevant) except one of the requirements is that we use .

These packages are essentially de-coupled from the application and each other, however one package may depend on another package.

These packages have their own repository, and during development of the application have branch aliases set to dev-master.

Problem #1

In order for the application to work with my packages I need to register them with composer.json, which is fine until I have to commit the existing work of my package development to their repository before I can run composer update.

Problem #2

I have committed the initial package architecture and the composer.json. I run composer update which completes and my package is available to the application. Yet, I continue to develop this package at the same time another developer has already committed a different change to this package - i.e. a bug fix.

I need to update another package in order for my work to continue, yet I can't because doing so would throw a warning similar to:

Loading composer repositories with package information
Updating dependencies (including require-dev)         
  - Removing hu/admin (dev-master)
  The package has modified files:
  M composer.json
  M src/...
  Discard changes [y,n,v,?]?

If I respond with y my changes are blown away and lost forever. If I choose n composer is aborted and my project is broken due to a package not being updated parallel to my changes.

Problem #3

Another problem with this way of developing is that if I am working on my package outside of vendor and I commit my changes I can run composer update but my application is broken due to a fatal error. I fix the missing ; or other small syntax error. I commit this change and run composer update - yet I don't want my git history full of little typo fixes and parse error fixes just because I can't work on my package within the application parallel to other development/developers on the application and other packages or this package.

Problem #4

I discovered a package on GuitHub called franzliedke/studio which seems to part-solve my problem. Once a package has been published due to being complete/functional, this then cannot remain inside the vendor/bin directory alas causing the initial problems to rise once more.

Conclusion

I am wondering the best way to work around this or any best practices in order to work on packages with teams of developers without having to commit everything every time before I run composer update.

did have a workbench feature which was pretty cool. But was removed from version 5.0 and so was that bad practice?

Community
  • 1
  • 1
Ash
  • 3,242
  • 2
  • 23
  • 35

1 Answers1

4

That's what we do in huge projects consisting of several little composer components which are developed at the same time:

Develop your application 'in one piece' like described in the other answer your mentioned by just keeping all components separate inside their own namespaces and directory structure.

/Application
-composer.json (Application json)
-/src
--/Component1
----composer.json (Component json)
--/Component2
----composer.json (Component json)
--/ApplicationFeature
----Class1.php
----Class2.php

The whole application is developed in a single git repository which would eliminate most of your aforementioned problems. Then occasionally split the application repo into single component repositories using git subtree. I wrote a little php cli script which splits the project into smaller components and pushes them to the according component repositories. There are a lot of advantages compared to git submodules. The whole commit history of a component is kept and pushed to the component repository. More information on subtrees here In case you are interested please let me know, I am happy to share the script which splits/tags and finally pushes the single components by just defining a directory <-> componentName mapping as a json.

Community
  • 1
  • 1
tworabbits
  • 1,203
  • 12
  • 17
  • Thanks for your response. So initially you are correct that is how I intended to work. Your response to *problem 1* is not accurate but that's my fault for not entirely making my intentions clear (I will update the question). Your response to *problem 2* is how i currently work and as you have mentioned is bad alas why I've asked this question to move away from that bad practice. My problem is mainly working on packages that are core to the application. Essentially instead of using modules I wanted to develop the application in packages using services/providers. Does this help? – Ash May 18 '15 at 14:52
  • Got it, sorry. I tried to present an approach we use in projects similar to yours. Hope that pleases your needs. – tworabbits May 18 '15 at 15:30
  • Perfect! I've accepted the answer. This does seem to be what i'm trying to achieve. – Ash May 19 '15 at 07:59
  • Great. As I said let me know when you are interested in detail about how I actually solved it (splitting an existing project, adding new components, pushing/pulling changes of a single component to its own repo etc.) – tworabbits May 19 '15 at 08:29