niklan / composer-directories
Composer plugin that automatically creates directories defined in your composer.json.
Package info
github.com/Niklan/composer-directories
Type:composer-plugin
pkg:composer/niklan/composer-directories
Requires
- php: >=8.2
- composer-plugin-api: ^2.0
Requires (Dev)
- composer/composer: ^2.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- slevomat/coding-standard: *
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2026-03-05 08:40:26 UTC
README
A Composer plugin that automatically creates directories and symlinks defined in your composer.json during install and update commands. Directories are always created before symlinks.
Installation
composer require niklan/composer-directories
Usage
Add configuration to the extra section of your composer.json:
{
"extra": {
"ensure-directories": [
"web/sites/simpletest/browser_output",
"var/log",
"var/files/public",
{"path": "var/files/private", "permissions": "0700"}
],
"symlinks": {
"var/files/public": "web/sites/default/files"
}
}
}
Both features work independently -- you can use directories, symlinks, or both.
Directories
- String entries use the default permission
0775(drwxrwxr-x), matching the Drupal default. - Object entries accept a
pathand an optionalpermissionsstring in octal format. - All paths are relative to the project root (where
composer.jsonis located).
Symlinks
- Keys are targets, values are link paths. Both are relative to the project root.
- If a symlink already exists and points to the correct target, it is left as-is. If it points elsewhere, it is replaced.
- If a non-symlink file/directory exists at the link path, it is skipped with a warning.
- On Windows, directory junctions are used instead of symlinks (no admin rights needed).
Verbose output
Run composer install -v to see skipped directories and symlinks that already exist:
> post-install-cmd: Niklan\ComposerDirectories\DirectoriesPlugin->onPostCommand
Directory exists: var/files/private
Directory exists: var/files/private/translations
Directory exists: var/files/public
Directory exists: var/files/temporary
Directory exists: var/log
Symlink exists: web/sites/default/files
Security
Paths that resolve outside the project root (e.g., ../../../etc) are rejected with a warning. This applies to both directories and symlinks (target and link).
Development
Requirements
- PHP 8.2+
- Composer 2.x
Setup
composer install
Linting
# Run all linters composer lint # Run individually composer phpcs # PHP CodeSniffer (PSR-12 + Slevomat) composer phpstan # PHPStan (level 10)
Auto-fix code style
composer phpcbf
Testing
composer phpunit
Run everything
composer test
License
MIT