Install package into custom directory Composer - path

Hey I am trying to install a package into a custom 'admin' directory using composer.
Here is my JSON:
{
"name": "frontier/installer",
"description": "The best front end engineer package around",
"require": {
"aheinze/cockpit": "*"
},
"extra":{
"installer-paths":{
"admin": ["aheinze/cockpit"]
}
}
}
Now when I run composer install it all installs but defaults to vendor/aheinze/cockpit I cannot for the life of me figure out why.
Have done my research this should be the right code... any obvious errors?
Cheers.

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.

If you want to use the installer-paths option the package you want to be installed in a different path must require composer/installers.
In your case the aheinze/cockpit package doesn't require composer/installers as you can see in its composer.json at github.
Have a look at the composer documentation for custom paths and you see that it tells you:
Note: You cannot use this to change the path of any package. This is only applicable to packages that require composer/installers and use a custom type that it handles.
This means you are not able to change the install path of this specific package.
Anyway I don't see any necessity to install it into any different directory from the default vendor folder.

If you just need to put all packages under the "admin" directory, the best option is:
{
"config": {
"vendor-dir": "admin"
}
}

You can use the post-autoload-dump script to copy the package after install/dump-autoload:
"scripts": {
"post-autoload-dump": [
"cp -r vendor/aheinze/cockpit admin"
]
},

For install multiple packages in the same directory you can follow this structure
1- your path should be like this "modules/patched/{$name}"
2- and an array of any package that you want to move or install that same directory
"extra":{
"installer-paths": {
"modules/patched/{$name}": [
"drupal/signature_field",
"drupal/eck",
"drupal/auto_entitylabel"
]
}
The package or module should be in your require section as well.
"require": {
"composer/installers": "^1.0.24",
"drupal/auto_entitylabel": "2.x-dev",
"drupal/signature_field": "^1.0#RC",
"drupal/eck": "^1.0#alpha",
}

Related

error with composer autoload installing phpspreadsheet

I've never used composer before, so I'm not sure what this error means or what I need to do. But I am trying to use PHPSpreadsheet to be able to convert excel files into php for adding information to a database.
Uncaught Exception: Composer autoloader could not be found. Install
dependencies with composer install and try again.
Can anyone tell me what I need to do to get this system working.
Running cPanel with PHP7 EasyApache4
I do have root access to dedicated server.
Looks like you haven't installed the packages via composer.
You have to create a file named "composer.json" on the root of your project.
it should be something like this:
{
"require": {
"phpmailer/phpmailer":"5.2.22",
"slim/slim":"2.0",
"rain/raintpl":"3.0.0",
},
"autoload": {
"psr-4": {
"ProjectName\\": "vendor\\projectPackage\\php-classes\\src"
}
}
}
After that you should run the command "composer install" on you git bash and it will download your dependencies and create an autoload for you.

What is the "main file" property when doing bower init?

What is the use of property main file when you run bower init? I have been looking and many people says that it currently has no purpose.
Is that true? Bower's documentation doesn't explain it either.
According to the Bower.io documentation
main
Recommended Type: String or Array of String
The primary acting files necessary to use your package. While Bower
does not directly use these files, they are listed with the
commands bower list --json andbower list --paths, so they can be used
by build tools.
Preprocessor files like CoffeeScript should be compiled.Do not include
minified files.Filenames should not be versioned (Bad:
package.1.1.0.js; Good: package.js).
I think it's more for the package management, and build tools like Grunt and Brunch. For example, Bootstrap's bower.json looks like :
{
"name": "bootstrap",
"version": "3.0.3",
"main": [
"./dist/css/bootstrap.css",
"./dist/js/bootstrap.js",
"./dist/fonts/glyphicons-halflings-regular.eot",
"./dist/fonts/glyphicons-halflings-regular.svg",
"./dist/fonts/glyphicons-halflings-regular.ttf",
"./dist/fonts/glyphicons-halflings-regular.woff"
],
"ignore": [
"**/.*",
"_config.yml",
"CNAME",
"composer.json",
"CONTRIBUTING.md",
"docs",
"js/tests"
],
"dependencies": {
"jquery": ">= 1.9.0"
}
}
When I build in Brunch, it pulls these files from my bower_components folder in my public folder.
According to Bower's JSON Specification (https://github.com/bower/spec/blob/master/json.md#main), the "main" property is used to list the files primarily used in the project. The files listed are not actually used by Bower in any way, they are apparently there for the purpose of being used by other build tools.
Here is the official specification:
main
Recommended
Type: String or Array of String
The primary acting files necessary to use your package. While Bower does not directly use these files, they are listed with the commands bower list --json and bower list --paths, so they can be used by build tools.
Preprocessor files like CoffeeScript should be compiled.
Do not include minified files.
Filenames should not be versioned (Bad: package.1.1.0.js; Good: package.js).

"ignore" in Bower's bower.json?

Bower's website describes the ignore key in bower.json:
ignore [array]: An array of paths not needed in production that you want Bower to ignore when installing your package.
Does this mean that it's ignoring paths in installed components, or in your package? Or something else? I was confused by this.
TL;DR:
ignore only works within the scope of packages being installed, ignoring matching patterns.
Somewhat longer answer:
Bower will ignore all files matching the patterns specified in the ignore property of bower.json in installed packages.
So, suppose if you ran bower install someBowerPackage which had following structure:
someBowerPackage
|- css/
|- js/
|- index.html
|- bower.json
with a bower.json file having:
{
...
"ignore": [ "index.html" ]
}
then, index.html file of this someBowerPackage will not be installed within this package.
ignore is related to the files in your package
You can't ignore on behalf of other packages
Dependencies are loaded all or none
ignore values are only applied to packages fetched from a bower install endpoint by that component's bower.json file.
ignore values specified in project-root/bower.json have no effect on packages fetched as that project's components.
The bower.json Spec has been documented in its own github repo since this question was originally asked.
Ignore
Recommended
Type: Array of String
A list of files for Bower to ignore when installing your package.
Note: symbolic links will always be ignored. However bower.json will never be ignored.
The ignore rules follow the same rules specified in the gitignore pattern spec.
Files matching globs or file values in ignore will not be downloaded from an endpoint as part of the package.

Does luarocks management have "./node_modules" equivalent for projects?

In NodeJS/NPM, you can create a package.json and run npm install to install all your dependencies in a folder within your project: ./node_modules. (A project can be an app or another module/package.)
Ruby also has a "bundler" system (using a .bundle file) that keeps track of gems specific to a dir (ie project).
Does LuaRocks have similar conventions? Or is it recommeneded to install everything to /usr or $HOME?
So far I've been able to get similiar functionality, but I have to create a custom LuaRocks config file and specify --tree=my_local_lua_rocks_dir every time I want to install a rock. Granted, I can always create a bash script. The point is that it seems I'm going against a convention.
It is possible to install rocks into a directory under the current directory, using the --tree flag:
luarocks install --tree ./lua_modules lpeg
And then you have to configure your package.path and package.cpath variables in Lua (settable via LUA_PATH and LUA_CPATH environment variables) so it finds the modules installed inside it. There are several ways to do this conveniently: this tutorial explains how to do it, with more examples.
Instead of using Vert, I've decided to just edit the LuaRocks config file:
In /etc/luarocks/config.lua :
rocks_servers = {
[[http://rocks.moonscript.org/]],
[[http://luarocks.org/repositories/rocks]]
}
rocks_trees = {
[[/usr/local]],
[[./my_dir]]
}
./my_dir is relative to the pwd you're in, not to the location of the config file. Of course, change my_dir to whatever you want.
"The order of the rock_trees matters: When installing rocks, LuaRocks tries to pick a location to store the rock starting from the bottom of the list; when loading rocks in runtime, LuaRocks scans from the top of the list." From: http://luarocks.org/en/Config_file_format
Then in your .bashrc:
eval `luarocks path`
export PATH=$PATH:my_dir/bin
However, for certain commands you now have to specify the tree or it will give you a confusing error:
luarocks make --tree=my_dir

Choose bower install directory

This is a follow-up to this question. I'm using bower 0.7.1, and still cannot get the components to be installed anywhere else than in the components folder.
I tried adding the following line to my component.json, as per this PR:
"componentsDirectory": "public/components"
But it will still install in ./components.
I tried to create a .bowerrc file next to component.json:
{
"directory" : "public/components"
}
But I get this error when running bower install:
Error: Unable to parse local .bowerrc file: Unexpected token }
Any idea?
Actually the .bowerrc file does work, this was an issue with my IDE not saving the file properly:
{
"directory" : "public/components"
}
I'm still wondering why componentsDirectory still doesn't work in component.json, though.
While you can happily use Bower to manage the dependencies of your own personal projects, primarily the component.json is a description of your project for other people. If you share a component through the Bower registry the component.json goes with it to describe the dependencies. That is why your own local preferences like where to install components don't belong in there.
Another way to change installation directory temporarily is using --config option in command line:
bower install jquery --config.directory=/path/to/your/components
If you are creating this file in Notepad++, make sure the Encoding is set to "Encode in UTF-8 without BOM" and save as file type "Any".

Resources