Best way to install private/paid plugins with Composer?

Most of what you want is covered by this example in the official Composer docs: https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md

Your ideal workflow is a little different but I’m not sure it’s all needed. As long as you have your own Satis repository running which defines your private repositories/packages, the only people who will be able to download them are those with the proper SSH keys.

3 Likes

I Needed a slightly different setup to get my repo to be installed via composer; hopefully this will help someone who may be stuck:

My project’s "repositories" key in the composer.json file has:

    {
      "type": "vcs",
      "url": "https://bitbucket.org/accountname/reponame.git"
}

in "require" i have:

"accountname/reponame":"dev-master"

And in my repo composer.json file I needed to change "dist" into "source" or else it would not work:

{
    "name": "accountname/reponame",
    "version": "master",
    "source": {
        "url": "https://bitbucket.org/accountname/reponame.git",
        "type": "git"
    }
}

finally, while doing the update:

composer update -v --prefer-source
5 Likes

I’m trying to include a MU-Plugin thats hosted on my private bitbucket.

I’ve added the following to my projects composer.json

{
    "type": "vcs",
    "url": "git@bitbucket.org:kjprince/disable-year-month-uploads.git"
    }, 

In the require section I’ve added this:

"kjprince/disable-year-month-uploads": "dev-master"

When I do composer update it fails and shows the following error:

[LogicException]
  Downloader "Composer\Downloader\GitDownloader" is a source type downloader and can not be used to dow
  nload dist

I updated my composer.json to use source instead of dist and I get the error below:

Skipped branch master, Package kjprince/disable-year-month-uploads's source key should be specified as {"type": ..., "url": ..., "reference": ...},
{"url":"git@bitbucket.org:kjprince\/disable-year-month-uploads.git","type":"git"} given.

My plugin contains the following composer.json

{
    "name": "kjprince/disable-year-month-uploads",
    "version": "master",
    "type": "wordpress-muplugin",
    "source": {
        "url": "git@bitbucket.org:kjprince/disable-year-month-uploads.git",
        "type": "git"
    }
}

Anyone know what’s going on here?

Does the kjprince/disable-year-month-uploads repo contain a composer.json? If not, you need to specify more information like this:

{
      "type": "package",
      "package": {
        "name": "kjprince/disable-year-month-uploads",
        "version": "master",
        "type": "wordpress-plugin",
        "source": {
          "type": "vcs",
          "url": "git@bitbucket.org:kjprince/disable-year-month-uploads.git"
        },
        "require" : {
          "composer/installers": "v1.0.16"
        }
      }
    }
1 Like

Hi all, I have a question regarding Satis, composer and private plugins.

I have a plugin called x-shortcodes from vendor themeco, I’ve put the entire code of the plugin in our private git repo: ssh://git@code.ttss.ch:2222/diffusion/SATIS/satis.git

The plugin PHP code is in the themeco/x-shortcodes/ folder inside the git repo.

Inside satis.json I’ve put:

{
    "name": "TTSS",
    "homepage": "http://satis.ttss.ch",
    "repositories": [
        { "type": "vcs", "url": "ssh://git@code.ttss.ch:2222/diffusion/SATIS/satis.git" },
        {
                "type": "package",
                "package": {
                        "name": "themeco/x-shortcodes",
                        "version": "2.3.3",
                        "source": {
                                "url": "ssh://git@code.ttss.ch:2222/diffusion/SATIS/satis.git:/themeco/x-shortcodes/",
                                "type": "git",
                                "reference": "origin/master"
                        },
                        "autoload": {
                            "psr-4": { "themeco\\x-shortcodes\\": "themeco/x-shortcodes/" }
                            }
                }
        }
    ],
    "require-all": true
}

when I execute composer update x-shortcodes get’s installed fine (fetches it from git as it should do) but places everything in the folder vendor/themeco/x-shortcodes/themeco/ which is wrong, I neet to specify which folder to get from git, he actually pulls all the git root.

To make things short I would place all my private plugins into one repo, under <vendor>/<plugin-name> and serve them that way. Suggestions? Thanks.

think I resolved it using zip files:

{
  "name": "TTSS",
  "homepage": "http://satis.ttss.ch",

  "repositories": [
    {
      "type": "package",
      "package": {
        "name": "themeco/x-shortcodes",
        "description": "Includes all shortcode functionality for X",
        "keywords": ["themeco","x-shortcodes"],
        "license": "LGPL-3.0+",
        "authors": [
          {
            "name":"Themeco",
            "homepage":"http://theme.co"
          }
        ],
        "version": "2.3.3",
        "dist": {
          "url": "http://satis.ttss.ch/files/x-shortcodes.zip",
          "type": "zip"
        },
        "type": "wordpress-plugin",
        "require": {
            "php": ">=5.3.2",
            "composer/installers": "*"
        }
      }
    }
  ],
  "require-all": true
}
1 Like

Yeah, Composer won’t pull from a subdirectory within a Git repo. In fact it’s not even possible using git clone. See http://stackoverflow.com/questions/600079/is-there-any-way-to-clone-a-git-repositorys-sub-directory-only

1 Like

Perfect, thanks @swalkinshaw everything works this way, now I’ll just protect the package repo with some basic auth and it should be fine.

For WPML users: http://wpml.org/forums/topic/composer-support/#post-419855

1 Like

I think this is the best way.

2 Likes

After a quick search I was unable to find any references to managing plugins with composer from https://github.com/wp-premium

Soo, I felt like this thread would be a good place to bring it up…

So, I got the following to work with no issue:

{
        "type": "package",
        "package": {
            "name": "wp-premium/gravityforms",
            "type": "wordpress-plugin",
            "version": "1.9.17.5",
            "dist": {
                "url": "https://github.com/wp-premium/gravityforms/archive/master.zip",
                "type": "zip"
            }
        }
}

and then simply ran $ composer require "wp-premium/gravityforms"

While the above worked, is it the correct approach? or should i be doing something different? (note: i’d really rather not maintain a multitude of private repos, but would if its the correct approach)

note: i also tried the same format above but with “git” as the type and changing the url to:

git@github.com:wp-premium/gravityforms.git

…along with some other variations but had no luck with any

Thanks in advance!

2 Likes

There’s a new project by the creator of Composer called Toran Proxy.
This might solve most of the issues here.

https://toranproxy.com/

2 Likes

@wdeer that’s awesome.

Any idea who maintains the wp-premium repo?

@vdrnn that looks really cool too.

But correct me if I’m wrong guys– with toranproxy you’d need to manually update the proxy repo every time the plugin updates, and with wp-premium the repo owner updates it?

If that’s the idea of wp-premium does, that seems incredibly useful. But then you’ll probably still need to update the .json manually (to update version #s)? Or is there an automated process for this?

Edit: -“gist” +“idea”, gist is probably a bad word to use now that it’s a proper noun. :slightly_smiling:

1 Like

Yep, you would

Composer packages work off Git tags, so you could just tag each release as the version number.

1 Like

@kalenjohnson very true! That’s awesome.

Which leads me to my next point:

@wdeer, your problem with using the remote git repo is that your .json syntax is wrong. Try something like this:

{
      "type": "vcs",
      "url": "git@github.com:wp-premium/gravityforms.git"
    },

@kalenjohnson, that ^^ should work right?

zip is probably faster, but yeah using Git is better IMO as you just need to update the version number rather than the file URL each time.

With a .zip can you do it like this?

{
  "type": "vcs",
  "url": "git@github.com:wp-premium/gravityforms.zip"
},

Or do you have to do it like this?

{
        "type": "package",
        "package": {
            "name": "wp-premium/gravityforms",
            "type": "wordpress-plugin",
            "version": "1.9.17.5",
            "dist": {
                "url": "https://github.com/wp-premium/gravityforms/archive/master.zip",
                "type": "zip"
            }
        }
}
1 Like

For a long time I added

{
    "type": "git",
    "url": "git@bitbucket.org:your-name/advanced-custom-fields-pro.git"
   },

etc, etc, and just tagged my commits with the new version number.

Now I use Toran Proxy because you can set it up with a cron and it will mirror all your git repos and also packagist too if you want at whatever rate you decide to set the cron job for. So you really only need to push new versions to your private repos and Toran automatically stays in sync.

If you want a super ez way to do zip files check out
https://getcomposer.org/doc/05-repositories.md#artifact

2 Likes

Hi there, if you are fed up of writing / modifying composer.json for your premium or own packages, release-belt from Rarst is a nice solution.

  1. Serve release-belt through a web server of your choice (can be the php embedded one)
  2. Drop your plugins and themes zips in release/wordpress-{plugin,theme}/company/
  3. that’s all

Relase-belt will create a composer.json automatically.

I’m just starting using it on a server on the wild with basic http auth and it works great.

4 Likes

I’m running into problems with this approach when deploying, as I’m not sure how to pass the --prefer-source flag to the deploy script.

Ideally, I’d like to avoid using the --prefer-source flag, but on composer update and deploy, I get the error message:

[LogicException] Downloader “Composer\Downloader\GitDownloader” is a source type downloader
and can not be used to download dist

And I really don’t understand what’s going on and how to get around it (how do you set the private plugin to be “source” rather than “dist”?).

Bedrock composer.json repository code:

    {
      "type": "vcs",
      "url": "git@bitbucket.org:growdigital/advanced-custom-fields-pro.git"
    }

Plugin composer.json:

{
  "name": "growdigital/advanced-custom-fields-pro",
  "type": "wordpress-plugin",
  "source": {
    "type": "git",
    "url": "git!@bitbucket.org:growdigital/advanced-custom-fields-pro.git"
  }
}

And it feels like I’ve tried every variation inbetween!!