Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project vendor/bin to PATH. #26

Merged
merged 1 commit into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ A list of packages to install globally (using `composer global require`). If you

If `true`, and if there are any configured `composer_global_packages`, the `vendor/bin` directory inside `composer_home_path` will be added to the system's default `$PATH` (for all users).

composer_project_path: /path/to/project

Path to a composer project.

composer_add_project_to_path: false

If `true`, and if you have configured a `composer_project_path`, the `vendor/bin` directory inside `composer_project_path` will be added to the system's default `$PATH` (for all users).

composer_github_oauth_token: ''

GitHub OAuth token, used to avoid GitHub API rate limiting errors when building and rebuilding applications using Composer. Follow GitHub's directions to [Create a personal access token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) if you run into these rate limit errors.
Expand Down
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ composer_global_packages: []

composer_add_to_path: true

# Add a project vendor/bin directory to the PATH
composer_add_project_to_path: false
#composer_project_path: /path/to/project/vendor/bin

# GitHub OAuth token (used to help overcome API rate limits).
composer_github_oauth_token: ''
3 changes: 3 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@

- include: global-require.yml
when: composer_global_packages|length > 0

- include: project-bin.yml
when: composer_add_project_to_path
6 changes: 6 additions & 0 deletions tasks/project-bin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Add composer_project_path bin directory to global $PATH.
template:
src: composer-project.sh.j2
dest: /etc/profile.d/composer-project.sh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative, I'd be setting the destination of this PATH variable change to the shell of a user. The user running Composer manager.

Composer being a dependency manager for PHP projects, rather than a global package installer for all users on a system, assumes that it will be run by and for a single user on a system. The Composer global install for example is for adding a package dependency globally to all projects, but not all users. It installs packages globally to the home path of the user executing the Composer manager require command.

For this reason, I'd suggest adding the PATH variable change to the shell for all users on the system is probably not a great idea. I'm happy though to be convinced otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christopher-hopper agree that this would be preferable however this would also require adding user context to this role.

However I've it easier to leverage custom composer commands.

Note: Before executing scripts, Composer's bin-dir is temporarily pushed on top of the PATH environment variable so that binaries of dependencies are easily accessible.

mode: 0644
1 change: 1 addition & 0 deletions templates/composer-project.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export PATH={{ composer_project_path }}/vendor/bin:$PATH