Home > Enterprise >  How to use composer just to load the minimum files needed to resolve dependency
How to use composer just to load the minimum files needed to resolve dependency

Time:09-03

I am totaly new to composer !

Example; When using composer like composer require smarty/smarty I get all kinds of directorys installed like

  • vendor\smarty\smarty\lexer

But I only need smarty\libs and this smarty/libs should show up in an existing project direcory at webroot/project/smarty/libs.

In essence , can i specify this so composer just gets me what I need and puts it where I need it?

CodePudding user response:

In essence , can i specify this so composer just gets me what I need and puts it where I need it?

Yes, but it requires additional configuration. What you already have (and what Composer is for):

  1. You identified a Composer package containing a directory of files you have interest in.
  2. You already processed that package with the Composer utility within your project and you have updated your project configuration accordingly.

Now in the default setup, Composer installs in the vendor directory. This directory is not part of your project commonly, therefore the name "vendor", and often excluded.

Now you want to import a directory of files into your project from the (in your project already configured) vendor folder.

This is basically a file-copying operation, consult your systems programming manual for the commands to recursively copy a directory of files (or consult the PHP manual for this).

Then adopt your project install instructions to (re-)create the target directory and copy over the files after the command to (re-)create the vendor folder (perhaps you're using composer install for that).

If you want to do this with Composer - which is possible - add a post-install event script to your project configuration.

Execute your setup instructions.

You then add your changes, review them and commit them to the project history.


Alternatively, you can also not ignore the whole vendor folder, just the part you are not interested in and then create a reference so that the project targets directory is in fact a relative symbolic link to the descendant directory of interest in vendor. This requires your system as well as your software configuration management software to support symbolic links (for example Git does). Composer itself can deal with both ways fine.


And here the take-away: You need the Smarty Composer dependency only at development time, therefore you add it to require-dev - not require.

If that does not give you enough isolation, you create another Composer project configuration and pass its name with the COMPOSER environment parameter. You specify as well a non-standard Composer vendor directory name with that configuration and then do the operations there (this is perhaps the best to try it out in an existing project).

CodePudding user response:

The composer installs all the dependencies mentioned in its composer.json, so here your project needs smarty and the smarty needs other packages to run itself. If you check the composer.json file it has mentioned the required dependency as below.

"require-dev": {
    "phpunit/phpunit": "^8.5 || ^7.5",
    "smarty/smarty-lexer": "^3.1"
}

If you want to skip the dev dependencies use this command

composer install --no-dev

check this answer for more details.

  • Related