简体   繁体   中英

How do I configure my composer package to point to a specific subdirectory of the repository?

I have a Github repository , which I recently submitted to Packagist . The top-level directory of my repository is as follows:

  • build/
  • bootsole/
  • examples/
  • licenses/
  • screenshots/

The bootsole subdirectory is the actual directory containing the classes that are managed/autoloaded by composer.

I tried creating a new project, to test the package. In the new project, my composer.json is as follows:

{
    "require": {
        "php": ">=5.4.0",
        "alexweissman/bootsole": "0.2.0"
    }
}

I run composer install , and it fetches bootsole and its dependency, valitron . However, it places bootsole in vendor/alexweissman/bootsole/ , and what's more, it places the entire repository in that directory - not just the bootsole subdirectory.

Is it possible to configure a package to only include the contents of the subdirectory bootsole (ie, omit build/ , examples/ , etc)?

Update: This question seems to suggest that it isn't possible (though the question is over a year old at this point). It suggests that I tell git to ignore the other directories in the archive, which I'd rather not do for the benefit of developers who don't use composer.

Is there perhaps a way to create a separate branch that contains only the bootsole/ subdirectory, point Composer to that branch, and somehow auto-synchronize Composer's branch with the master branch?

Whatever you run composer install on, or composer require on will generally be put in the vendor directory. Composer essentially owns the vendor directory. There are ways to put these items elsewhere, but it defeats the purpose of composer, which is to help you manage version changes in all your interacting libraries.

However, another option is to run composer create-project . This will essentially clone the project to wherever you tell it, and then load up everything in the require section of the composer.json file. My guess is that you want two projects, one for the initial install of all the directories that you will tell your user to run composer create-project on, and another that will be just the bootsole directory, which you will require in the first project's composer.json file, and which will be put in /vendor/alexweissman/bootsole. You will need to change your code to look for the bootsole directory there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM