How it works

Asset Packagist provides information about Bower and NPM packages in a similar way to Packagist does it for Composer packages. So when you run composer for your project with enabled Asset Packagist repository composer knows all the available releases of bower-asset and npm-asset packages and knows how to download their files.

First we add Bower and NPM packages to our repository. Script collects package information and prepares JSON file in Packagist format. For example you can look what we have for Bower moment package:

https://asset-packagist.org/p/bower-asset/moment/latest.json

The file contains description of all of the versions of the package in the following format:


    "2.13.0.0": {
      "uid": 1000600,
      "name": "bower-asset/moment",
      "version": "2.13.0.0",
      "type": "bower-asset",
      "dist": {
        "type": "zip",
        "url": "https://api.github.com/repos/moment/moment/zipball/d6651c21c6131fbb5db891b60971357739015688",
        "reference": "d6651c21c6131fbb5db891b60971357739015688"
      },
      "source": {
        "type": "git",
        "url": "https://github.com/moment/moment.git",
        "reference": "d6651c21c6131fbb5db891b60971357739015688"
      }
    },
    

So when you run composer it downloads info about packages provided by Asset Packagist repository, then composer resolves dependencies and finds proper versions of required packages, then it downloads packages files to vendor directory of your project (actually composer doesn't care if these are PHP or JS or whatever files).

All the JSON files are stored and served as static files on Asset Packagist side and composer effectively cashes those files on your side so everything works as quick as possible.

Installing to a custom path

Asset Packagist is NOT a plugin so it can't affect where the package will be installed.
By default bower-asset/bootstrap package will be installed to vendor/bower-asset/bootstrap folder.

But you can achieve installing to custom path with oomphinc/composer-installers-extender plugin like this:


    "require": {
        "oomphinc/composer-installers-extender": "^1.1",
        "bower-asset/bootstrap": "^3.3",
        "npm-asset/jquery": "^2.2"
    },
    "extra": {
        "installer-types": ["bower-asset", "npm-asset"],
        "installer-paths": {
            "public/assets/{$vendor}/{$name}/": ["type:bower-asset", "type:npm-asset"]
        }
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
    ]
    

Yii2

Yii2 expects Bower and NPM packages to be installed to vendor/bower and vendor/npm folders respectively.

So, to use asset-packagist for Yii2 projects it's necessary to reassign Bower and NPM aliases in your application config like this:


    $config = [
        ...
        'aliases' => [
            '@bower' => '@vendor/bower-asset',
            '@npm'   => '@vendor/npm-asset',
        ],
        ...
    ];
    

Migrating from composer-asset-plugin

Moving from composer-asset-plugin is not straightforward when you host several applications on single server. It's known that asset packagist and asset plugin don't work well together when plugin is installed in global scope. So, to not affect other applications by deleting the plugin, you may disable the plugin locally via composer.json config option (you need plugin version ≥ 1.3.0 for this):


    "config": {
        "fxp-asset": {
            "enabled": false
        }
    }
    

Acknowledgements

This project uses Francois Pluchino's composer-asset-plugin to convert Bower and NPM packages to Composer format.

The search is powered by https://libraries.io/.