How to minimize size of composer download? - php

I'm using composer to download two packages like this:
{
"require": {
"propel/propel1": "1.6.9",
"smarty/smarty": "v3.1.14"
}
}
Now for example this smarty package is loading whole svn repository (not only files) and just the .svn folder weights 12MB. It also loads documentation and bunch of other files that can be useful in development, but have no right to be part of the production environment.
My question is - is there a way to install packages only with files that are libraries needed to run the application?

I have seen a fragment in the composer documentation, and for the most current version 3.1.14, this works and downloads the ZIP file blazingly fast:
{
"require": {
"smarty/smarty" : "3.1.14"
},
"repositories": [
{
"type": "package",
"package": {
"name": "smarty/smarty",
"version": "3.1.14",
"dist": {
"url": "http://www.smarty.net/files/Smarty-3.1.14.zip",
"type": "zip"
},
"source": {
"url": "http://smarty-php.googlecode.com/svn/",
"type": "svn",
"reference": "tags/Smarty_3_1_14/distribution/"
}
}
}
]
}
Unfortunately Smarty seems to NOT maintain such info, so you are on your own when updating it, but I think it should enable you to switch from that nasty SVN download to getting the released ZIP file distribution if you adjust the paths a little bit, and probably add --prefer-dist to your composer install call.

Related

Composer Satis Repository seems to be referring to source URL rather than dist URL

I have a Satis server with basic HTTP authentication set up.
The config file looks like this:
{
"name": "MySatisServer",
"homepage": "https:\/\/satis.example.co.uk",
"repositories": [
{
"type": "git",
"url": "git#github.com:Org\/Repo1.git"
},
{
"type": "git",
"url": "git#github.com:Org\/Repo2.git"
},
{
"type": "git",
"url": "git#github.com:Org\/Repo3.git"
},
{
"type": "git",
"url": "git#github.com:Org\/Repo4.git"
}
],
"require-all": true,
"require-dependencies": true,
"require-dev-dependencies": true,
"archive": {
"directory": "dist",
"format": "zip",
"prefix-url": "https://satis.example.co.uk"
}
}
I have run the satis build, which created my dist directory with the packages.json file that looks correct.
I am able to go to https://satis.example.co.uk in my browser and download any version of the repositories that I want as a ZIP and it works fine.
The problem appears when I try to use the repo through composer.
My composer.json file looks something like this:
{
"name": "some/project",
"description": "",
"license": "proprietary",
"authors": [],
"require": {
"org/repo-4": "^1.0"
},
"repositories": [
{
"type": "composer",
"url": "https://satis.example.co.uk"
}
]
}
Since the Satis Server is behind basic HTTP authentication I also have an auth.json file that looks like this:
{
"http-basic": {
"satis.example.co.uk": {
"username": "my-username",
"password": "my-password"
}
}
}
Running a composer install gives me the following output:
- Installing org/repo-4 (1.0.0): Downloading (failed) Failed to download org/repo-4 from dist: The "https://api.github.com/repos/Org/Repo4/zipball/128f63b6a91cf71d5cda8f84861254452ff3a1af" file could not be downloaded (HTTP/1.1 404 Not Found)
Now trying to download from source
- Installing org/repo-4 (1.0.0): Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private repos
Head to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+box359.localdomain+2017-04-18+1416
to retrieve a token. It will be stored in "/home/ubuntu/CashbackEngine/auth.json" for future use by Composer.
Token (hidden):
As you can see from the above, it is completely ignoring the fact that the file it needs to download is located at https://satis.example.co.uk/dist/org/repo-4/repo-4-1.0.0-e1cd03.zip, and is jumping straight to try and fetch from the source at GitHub, which is not the desired result as it is a private GitHub repository.
It looks as if it doesn't even realise that there is a different dist version available.
Is there something wrong with my set up?
Any help is appreciated.
The problem was related to the composer.lock file.
Although the dist URL on Satis was correct, composer wasn't even paying attention to it as the composer lock file had cached the old dist url which was at GitHub.
The solution was to delete the composer.lock file and run composer install. I also ran a composer clearcache beforehand just to make sure.

How to use Composer repositories in required package?

I have two code repositories. They both have composer.json files (see below). The first composer.json file is required by the second composer.json file, with the former stored remotely on bitbucket.
I have run both composer.json files locally: the first file passes and downloads the vendors as I would expect; the second file, which calls the first file, does not and I get this error:
Problem 1
- The requested package timeago/timeago could not be found in any version, there may be a typo in the package name.
Problem 2
- The requested package prettify/prettify could not be found in any version, there may be a typo in the package name.
Now, if I remove all repositories from the first file, and their corresponding entries in requires, then all works as expected and the files are downloaded. So, I think the problem lies with the repositories section in the first file somehow. Any ideas?
Here are my two composer files:
File one:
"repositories": {
"prettify/prettify": {
"type": "package",
"package": {
"name": "prettify",
"version": "dev-master",
"source": {
"url": "http://google-code-prettify.googlecode.com",
"type": "svn",
"reference": "svn/trunk"
}
}
},
"timeago/timeago": {
"type": "package",
"package": {
"name": "timeago",
"version": "dev-master",
"source": {
"url": "https://github.com/rmm5t/jquery-timeago.git",
"type": "git",
"reference": "master"
}
}
},
"require": {
"timeago": "dev-master",
"prettify": "dev-master",
}
}
File two:
"require": {
"vendor/project": "master"
},
If you use private repositories mentioned in the composer.json of a dependency of your main package, you have to repeat them there.
Alternatively you can set up an instance of Satis to create the necessary metadata from all the private repositories you use, and simply link this instead.
Composer will NOT recursively scan repositories for further links to other repositories, because that would lead to infinite scan times and really poor performance, and ultimately to undecidable problems as well, so whatever package you are using has to either only use Packagist as a source, or must mention the source for all packages that should override or add to Packagist.
Having one single Satis instance that acts as a complete map of all your private repositories will really ease the process.

Composer install path for custom package

I've read other questions about this topic and I just can't seem to get this to work. I'm trying to get a download of cforms as a custom package to install into wp-content/plugins/cforms. I've gotten this to work for the other packages that wpackagist supplies, and even some custom plugins developed in-house.
Here's what I have:
{
"name": "mycompany/wordpress-install",
"description": "Themes and plugins for our wordpress install.",
"authors": [
{
"name": "Me",
"email": "example#example.net"
}
],
"require": {
"deliciousdays/cforms": "14.5.2"
},
"repositories": [
{
"type": "package",
"package": {
"name": "deliciousdays/cforms",
"version": "14.5.2",
"dist": {
"url": "http://www.deliciousdays.com/download/cforms-v14.5.zip",
"type": "zip"
}
}
}
],
"extra": {
"installer-paths": {
"wp-content/plugins/cforms": ["deliciousdays/cforms"]
}
}
}
It's downloading cforms fine, but it's still putting it into vendor/deliciousdays/cforms when I want it in (obviously) wp-content/plugins/cforms. What am I doing wrong?
Try using this composer.json, it includes Wordpress (v3.9 as of right now).
It uses fancyguy/webroot-installer to install to certain directories.
This file is meant to be in the root wordpress directory. The extra section shows the "webroot-dir" to be "."; This will install into current directory, (Do not use "/" or "./"), if you would like it to install into a specific directory simply change "." to the name of the directory you'd like to install to.
"extra": {
"webroot-dir": ".",
"webroot-package": "wordpress"
}
So after running this file you should have the normal wordpress structure with cforms placed in the wp-content/plugins directory, to install a theme, you can copy the cforms section and change the type to "wordpress-theme" to have it installed into the themes directory.
I'm by no means an expert with composer, but I was able to get this working correctly.
{
"name": "mycompany/wordpress-install",
"description": "Themes and plugins for our wordpress install.",
"authors": [
{
"name": "Me",
"email": "example#example.net"
}
],
"repositories": [
{
"type": "composer",
"url": "http://wpackagist.org"
},
{
"type": "package",
"package": {
"name": "wordpress",
"type": "webroot",
"version": "3.9",
"dist": {
"type": "zip",
"url": "https://github.com/WordPress/WordPress/archive/3.9.zip"
}
}
},
{
"type": "package",
"package": {
"name": "cforms",
"type": "wordpress-plugin",
"version": "14.5.2",
"dist": {
"url": "http://www.deliciousdays.com/download/cforms-v14.5.zip",
"type": "zip"
}
}
}
],
"require": {
"php": ">=5.3.0",
"composer/installers": "~1.0",
"wordpress": "3.9",
"fancyguy/webroot-installer": "1.0.0",
"wpackagist/wordpress-seo": "*",
"cforms": "14.5.2"
},
"extra": {
"webroot-dir": ".",
"webroot-package": "wordpress"
}
}
Note that using wpackagist, you can view a list of installable plugins/themes at these links:
http://plugins.svn.wordpress.org/
http://themes.svn.wordpress.org/
If you would like to include plugins from the Wordpress Plugin Respository, you can add them in easily. For instance, if you wanted to add the Yoast Wordpress SEO plugin, you would add the following to require (Note that you need to know the slug of the plugin to add it):
"require": {
"php": ">=5.3.0",
"composer/installers": "~1.0",
"wordpress": "3.9",
"fancyguy/webroot-installer": "1.0.0",
"wpackagist/wordpress-seo": "*",
"cforms": "14.5.2"
}
Finally figured it out after trying lots of different things. I think I was missing two things:
In the package declaration I changed it to have the "type": "wordpress-plugin", and then in the requires I had to add "composers/installers": "~1.0" like so (also note that the extra was removed entirely):
{
"name": "mycompany/wordpress-install",
"description": "Themes and plugins for our wordpress install.",
"authors": [
{
"name": "Me",
"email": "example#example.net"
}
],
"require": {
"composer/installers": "~1.0.0",
"deliciousdays/cforms": "14.5.2"
},
"repositories": [
{
"type": "package",
"package": {
"name": "deliciousdays/cforms",
"version": "14.5.2",
"type": "wordpress-plugin",
"dist": {
"url": "http://www.deliciousdays.com/download/cforms-v14.5.zip",
"type": "zip"
}
}
}
]
}
I still have been unable to figure out how to get a custom package to install to a directory of my choosing even with the composer/installers require in there. It just seems to ignore everything until I've added a type to the object, and then it forces it to download into the location defined by that type, based on how composer/installers decided to map it.
But I think this will work for now... If anyone knows how to make it download into, say, "myfolder/something/cforms" I'll accept your answer.
it happens I have got an answer for you, because I ran into the same problem. Clearly, there is a big demand now to custom install packages.
The composer/installers ONLY work on defined frameworks and CMS(s), but doesn't work for normal composer packages.
I have implemented this composer plugin to install packages into user (custom) defined folders you can just include it in your composer.json, follow the example and tell me if you have more questions :)
https://github.com/mnsami/composer-custom-directory-installer
composer-custom-directory-installer
A composer plugin, to install differenty types of composer packages in custom directories outside the default composer default installation path which is in the vendor folder.
This is not another composer-installer library for supporting non-composer package types i.e. application .. etc. This is only to add the flexability of installing composer packages outside the vendor folder. This package only supports composer package types,
https://getcomposer.org/doc/04-schema.md#type
The type of the package. It defaults to library.
Package types are used for custom installation logic. If you have a package that needs some special logic, you can define a custom type. This could be a symfony-bundle, a wordpress-plugin or a typo3-module. These types will all be specific to certain projects, and they will need to provide an installer capable of installing packages of that type.
How to use
Include the composer plugin into your composer.json require section::
"require":{
"php": ">=5.3",
"mnsami/composer-custom-directory-installer": "1.1.*",
"monolog/monolog": "*"
}
In the extra section define the custom directory you want to the package to be installed in::
"extra":{
"installer-paths":{
"./monolog/": ["monolog/monolog"]
}
by adding the installer-paths part, you are telling composer to install the monolog package inside the monolog folder in your root directory.
As an added new feature, we have added more flexibility in defining your download directory same like the composer/installers, in other words you can use variables like {$vendor} and {$name} in your installer-path section:
"extra": {
"installer-paths": {
"./customlibs/{$vendor}/db/{$name}": ["doctrine/orm"]
}
}
the above will manage to install the doctrine/orm package in the root folder of your project, under customlibs.
Note
Composer type: project is not supported in this installer, as packages with type project only make sense to be used with application shells like symfony/framework-standard-edition, to be required by another package.

How to use rackspace php-opencloud with Laravel 4

I'm trying to use the php-opencloud library with Laravel 4 (it's my first time with it, I'm a bit intimidated...)
I have added this to my composer.json, tried a composer update, which downloaded the lib correctly, but what's next? How can I autoload it?
"repositories": {
"php-opencloud": {
"type": "package",
"package": {
"name": "rackspace/php-opencloud",
"version": "1.4.1",
"source": {
"url": "https://github.com/rackspace/php-opencloud.git",
"type": "git",
"reference": "origin/master"
}
}
}
}
Most of the packages you install via Composer make use of autoloading:
Basic Usage: AutoloadingComposer Docs
That is basically just including a single file in your bootstrap and you're ready to go:
require 'vendor/autoload.php';
That is relative to the location where you placed your composer.json file.

How do I define an explicit SVN revision for a Composer repository?

I'm trying to include google-api-php-client library to my project using Composer. Simpliest way is to get library from VCS trunk branch, but I think it's not the best idea in my case. Much better will be point to some stable library state (tag or revision). Whereas there's no tags available, get a particular svn revision is the only option. But I have no idea how to do this.
I tried different package configs with no success, something like this:
{
"repositories":[
{
"type":"package",
"package":{
"name":"project/google-api-php-client",
"version":"0.2.1",
"source":{
"type":"svn",
"url":"http://google-api-php-client.googlecode.com/svn",
"reference":"trunk/?r=515"
}
}
}
]
}
Whether it possible at all to checkout svn revision with composer? Thanks in advance.
Using a package repository when you are defining the version you can specify a revision in the reference. An example from my wordpress composer.json
{
"repositories": [
"type": "package",
"package": {
"name": "wordpress-plugin/wp-minify",
"type": "wordpress-plugin",
"version": "1.2",
"source": {
"type": "svn",
"url": "http://plugins.svn.wordpress.org/wp-minify",
"reference": "trunk#691320"
},
"require": {
"composer/installers": "~1.0"
}
}
]
}
This installs the plugin from the trunk with an explicit revision of 691320.
The version can be set in the require part (that you don't show).
The only SVN options available are:
{
"repositories": [
{
"type": "vcs",
"url": "http://svn.example.org/projectA/",
"trunk-path": "Trunk",
"branches-path": "Branches",
"tags-path": "Tags"
}
]
}
Look's like you want to use a package, but you could also just define this repository and require the appropriate version (can you tag? It's easier).
You could also try to put the revision insive the version parameter but I don't think that will work.
Also, the documentation state that about the "trunk" path:
Since Subversion has no native concept of branches and tags, Composer
assumes by default that code is located in $url/trunk, $url/branches
and $url/tags. If your repository has a different layout you can
change those values.

Categories