Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer installs jQuery components in wrong directory

I'm trying to install jQuery components via Composer in CakePHP app, the composer.json:

{
    "name": "affiliate",
    "require": {
        "cakephp/cakephp": "2.5.*",
        "cakephp/debug_kit": "2.2.*@dev",
        "cakedc/utils": "dev-develop",
        "cakedc/search": "dev-develop",
        "friendsofcake/crud": "3.*",
        "components/jquery": "2.*"
    },
    "config": {
        "vendor-dir": "Vendor/"
    }
}

And it installs some files in app/Vendor/components/jquery, but also it creates and installs some files in APP's root - app/components/jquery. I would like to have all in Vendor one, how can I fix that?

like image 815
redd Avatar asked Sep 05 '14 12:09

redd


1 Answers

The components/jquery package uses component-installer, which can read from your composer.json a specified component-dir setting which is where you want to put the downloaded components - e.g. in your web/assets folder:

{
    "require": {
        "components/jquery": "*"
    },
    "config": {
        "component-dir": "web/assets"
    }
}

To read more about this check out the docs here.

You can then add those downloaded component files in web/assets to your .gitignore so that you're not adding files which are loaded in by the package manager.

If you're not a fan of this approach, then one other option is that you can add your own package repository to your composer.json like this:

{
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "jquery/jquery",
                "version": "2.1.1",
                "dist": {
                    "url": "http://code.jquery.com/jquery-2.1.1.js",
                    "type": "file"
                }
            }
        }
    ],
    "require": {
        "jquery/jquery": "2.1.1"
    }
}

With this approach, composer will download the JS file to vendor/jquery/jquery/jquery-2.1.1.js - you can then add a symlink to this from your www root directory.

like image 86
madebydavid Avatar answered Oct 02 '22 21:10

madebydavid