Bedrock custom installer path with Composer

Hello! I’m having trouble getting a custom installer path for a specific package with Composer in Bedrock. The package downloads but it goes to the default /vendor directory. Here’s what I got for the repository, require and extra.

"repositories": [
     {
	  "type": "package",
	  "package": {
	    "name": "syamilmj/aqua-resizer",
	    "version": "1.2.1",
	    "type": "theme-include",
	    "dist": {
	      "type": "zip",
	      "url": "https://github.com/syamilmj/Aqua-Resizer/archive/master.zip"
	    },
	    "require" : {
	      "composer/installers": "~1.0"
	    }
	  } 
        }
]
"require": {
   "syamilmj/aqua-resizer": "^1.2"
}
"extra": {
    "installer-paths": {
      "web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
      "web/app/plugins/{$name}/": ["type:wordpress-plugin"],
      "web/app/themes/{$name}/": ["type:wordpress-theme"],
      "web/app/themes/theme-name/{$name}/": ["type:theme-include"]
    },
    "wordpress-install-dir": "web/wp"
  }

Thanks for any help at all in advance!

Simply change your extra to the following:

"extra": {
    "installer-paths": {
      "web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
      "web/app/plugins/{$name}/": ["type:wordpress-plugin", "syamilmj/aqua-resizer"],
      "web/app/themes/{$name}/": ["type:wordpress-theme"],
      "web/app/themes/theme-name/{$name}/": ["type:theme-include"]
    },
    "wordpress-install-dir": "web/wp"
  }

And re-run composer install or composer update

Thank you Nicolo! I tried this but to no avail. Is there a reason why the additional item is on the wordpress-plugin line instead of the new custom install path line (“theme-include”)? I tried moving it to that line as well but it keeps ending up in the root vendor directory.

The extra section instructs composer on where to move the packages once downloaded.
If this you’re downloading is a plugin for WordPress, the correct spot for it would be the plugins folder more than the theme. That’s the reason why I put it into the type:wordpress-plugins section.

Also, it’s important for you to know that even if it ends up being in your vendor folder, composer will autoload it for you. So the class and functions of this library will still be available to you when you’re developing, regardless of it’s position.

I had a look at this library and the guy didn’t properly publish any tag nor package type.
This is the configuration I used to install the plugin in the plugins folder anyway, for your reference:

{
  "name": "roots/bedrock",
  "type": "project",
  "license": "MIT",
  "description": "A modern WordPress stack",
  "homepage": "https://roots.io/bedrock/",
  "authors": [
    {
      "name": "Scott Walkinshaw",
      "email": "scott.walkinshaw@gmail.com",
      "homepage": "https://github.com/swalkinshaw"
    },
    {
      "name": "Ben Word",
      "email": "ben@benword.com",
      "homepage": "https://github.com/retlehs"
    }
  ],
  "keywords": [
    "bedrock","roots","wordpress","stack","composer","vagrant","wp"
  ],
  "support": {
    "issues": "https://github.com/roots/bedrock/issues",
    "forum": "https://discourse.roots.io/category/bedrock"
  },
  "config": {
    "preferred-install": "dist"
  },
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    },
    {
      "type": "package",
      "package": {
        "name": "syamilmj/aqua-resizer",
        "type": "wordpress-plugin",
        "version": "dev-master",
       "source": {
          "type": "git",
          "url": "https://github.com/syamilmj/Aqua-Resizer",
          "reference": "master"
        }
      }
    }
  ],
  "require": {
    "php": ">=5.6",
    "composer/composer": "~1.0.0@dev",
    "composer/installers": "~1.0.25",
    "vlucas/phpdotenv": "^2.0.1",
    "johnpbloch/wordpress": "~4.5",
    "oscarotero/env": "^1.0",
    "wp-cli/wp-cli": "~0.23",
    "roots/soil": "^3.6.2",
    "roots/wp-h5bp-htaccess": "^2.0.1",
    "roots/wp-password-bcrypt": "*",
    "syamilmj/aqua-resizer": "dev-master"
  },
  "extra": {
    "installer-paths": {
      "web/app/mu-plugins/{$name}/": [
        "type:wordpress-muplugin",
        "roots/soil",
        "roots/wp-h5bp-htaccess"
      ],
      "web/app/plugins/{$name}/": [ "type:wordpress-plugin" ],
      "web/app/themes/{$name}/": [ "type:wordpress-theme" ]
    },
    "wordpress-install-dir": "web/wp"
  },
  "require-dev": {
    "squizlabs/php_codesniffer": "^2.5.1"
  },
  "scripts": {
    "test": [
      "vendor/bin/phpcs --ignore=web/wp/,vendor/,web/app/ -n -s ."
    ]
  }
}

1 Like

Thank you again and sorry to disappear there for a bit. The package isn’t a plugin actually. It’s a php script that functions.php needs to include which is why I’m trying to put it in the theme directory. Still unable to get it to work. I updated my package definition and require to what you have and below is what extra looks like as well. Hoping I’m just missin’ somethin’ dumb here.

{
	  "type": "package",
	  "package": {
	    "name": "syamilmj/aqua-resizer",
	    "version": "dev-master",
	    "type": "theme-include",
	    "source": {
	      "type": "git",
	      "url": "https://github.com/syamilmj/Aqua-Resizer",
	      "reference": "master"
	    },
	    "require" : {
	      "composer/installers": "~1.0"
	    }
	  } 
    }
"require": {
    "syamilmj/aqua-resizer": "dev-master"
  }
"extra": {
    "installer-paths": {
      "web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
      "web/app/plugins/{$name}/": ["type:wordpress-plugin"],
      "web/app/themes/{$name}/": ["type:wordpress-theme"],
      "web/app/themes/theme-name/{$name}/": ["type:theme-include"]
    },
    "wordpress-install-dir": "web/wp"
  }

The configuration is correct and should be putting the script in the folder you want.
Have you tried running composer clear-cache && composer update?

Ah, good to know about the cache! Gave that a shot but still to no avail. No worries though. Since it’s just one file and it actually needs to be included in the final theme build I decided to commit it to the repo. Probably safer that way anyway. I really appreciate all of your help @Nicolo_Sacchi!

1 Like