Component-based development with composer

Philippe Gerber

Let's say I want to write a new application.

/workspace/exampleapp/
  .git
  src/
  vendor/
    app/
      component1/
        .git
        src/
        composer.json
      component2/
        .git
        src/
        composer.json
  composer.json

I have three git repositories. They have no remotes. I also have three composer.json files.

/workspace/app/composer.json

{
  "name": "app/app",
  "type": "project",
  "license": "MIT",
  "require": {
    "app/component1": "dev-master",
    "app/component2": "dev-master"
  },
  "autoload": {
    "psr-4": {"app\\": "src/"}
  }
}

/workspace/app/vendor/app/component1/composer.json

{
  "name": "app/component1",
  "type": "library",
  "license": "MIT",
  "autoload": {
    "psr-4": {"app\\": "src/"}
  }
}

/workspace/app/vendor/app/component2/composer.json

{
  "name": "app/component2",
  "type": "library",
  "license": "MIT",
  "autoload": {
    "psr-4": {"app\\": "src/"}
  }
}

If I run composer update in the project root I receive the error The requested package app/component1 could not be found in any version, there may be a typo in the package name.

What do I have to change to make it work? Is there a way without moving the components directories out of the vendor directory or creating remote repositories?

Thank you!

Danack

I think you are suffering from the XY problem - I'm going to pretend that you actually asked "How can I setup a project with Composer with the following requirements?"

  • Be able to work without a remote Git server i.e. be able to commit and push locally.
  • Be able to commit code for the components separately to the commits to the main project.
  • Be able to edit the code in the vendor directories for your repositories, and commit from those directories.

In which case the answer is, setup your directories like this:

/workspace/app/
  composer.json
    src/

/workspace/components/
  component1/
    composer.json
    src/
  component2/
    src/
    composer.json

Setup each of your component's composer file like this:

/workspace/components/component1/composer.json

{
  "name": "app/component1",
  "type": "library",
  "license": "MIT",
  "autoload": {
    "psr-4": {"app\\": "src/"}
  }
}

Tell your the composer.json file for your app to use the components directories as local git repositories.

/workspace/app/composer.json

{
  "name": "app/app",
  "type": "project",
  "license": "MIT",
  "require": {
    "app/component1": "dev-master",
    "app/component2": "dev-master"
  },
  "autoload": {
    "psr-4": {"app\\": "src/"}
  },
  "repositories": [
    {
        "type": "vcs",
        "url": "/workspace/components/component1"
    },
    {
        "type": "vcs",
        "url": "/workspace/components/component2"
    }
  ],
}

When you do the first "composer update" you should run it with the option composer update --prefer-source. That will force composer to do a git clone for the code, rather than downloading just a zip-ball and extracting it.

(Adding --prefer-source may not be required, it seems composer may do clone by default when fetching from a local directory repository).

You will now be able to edit the code for the components in the vendor directory, be able to commit it separately to the app code, as well as be able to push it to 'remote' git repository at /workspace/components/component1/.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Composer specifying 'in development' packages?

From Dev

Symfony and composer component folder

From Dev

Composer - installing local packages in development with dependencies error

From Dev

Composer not creating correct sub folders for Symfony component

From Dev

Programmatically add composer while creating a component

From Dev

composer set a git repository as type component

From Dev

Component and UI suites for iOS development?

From Dev

Component and UI suites for iOS development?

From Dev

Sorting JPanels based on component

From Dev

Scala - console based development workflow

From Dev

How to render component inside a component based on route

From Dev

Composer class not found fatal error - wordpress plugin development

From Dev

How do you properly test a Composer package during development?

From Dev

ZF2 autoloading strategy for development and production with git/composer

From Dev

I can't flag my composer development as stable

From Dev

ember component based on model type

From Dev

thread in script based component not working

From Dev

Component based entity system in scala

From Dev

Create swing component based on property

From Dev

Skip a component based on condition in Talend

From Dev

Skip a component based on condition in Talend

From Dev

render component based on the id of user

From Dev

Render component based of parameter in path

From Dev

How does Symfony manage Component sub-packages with Git and Composer?

From Dev

Feature-based development with Sonatype Nexus OSS

From Dev

Docker based development environment and live environment

From Dev

Feature-based development with Sonatype Nexus OSS

From Dev

composer private package based on gitlab is identified as git submodule

From Dev

Should I create a custom VJing application based on Quartz Composer?

Related Related

  1. 1

    Composer specifying 'in development' packages?

  2. 2

    Symfony and composer component folder

  3. 3

    Composer - installing local packages in development with dependencies error

  4. 4

    Composer not creating correct sub folders for Symfony component

  5. 5

    Programmatically add composer while creating a component

  6. 6

    composer set a git repository as type component

  7. 7

    Component and UI suites for iOS development?

  8. 8

    Component and UI suites for iOS development?

  9. 9

    Sorting JPanels based on component

  10. 10

    Scala - console based development workflow

  11. 11

    How to render component inside a component based on route

  12. 12

    Composer class not found fatal error - wordpress plugin development

  13. 13

    How do you properly test a Composer package during development?

  14. 14

    ZF2 autoloading strategy for development and production with git/composer

  15. 15

    I can't flag my composer development as stable

  16. 16

    ember component based on model type

  17. 17

    thread in script based component not working

  18. 18

    Component based entity system in scala

  19. 19

    Create swing component based on property

  20. 20

    Skip a component based on condition in Talend

  21. 21

    Skip a component based on condition in Talend

  22. 22

    render component based on the id of user

  23. 23

    Render component based of parameter in path

  24. 24

    How does Symfony manage Component sub-packages with Git and Composer?

  25. 25

    Feature-based development with Sonatype Nexus OSS

  26. 26

    Docker based development environment and live environment

  27. 27

    Feature-based development with Sonatype Nexus OSS

  28. 28

    composer private package based on gitlab is identified as git submodule

  29. 29

    Should I create a custom VJing application based on Quartz Composer?

HotTag

Archive