May 25, 2021 Composer
1. Binary supply library and vendor/bin
2. What is a binary supply library?
4. What is the role of defining binary supply libraries in composer.json?
5. What happens when Composer runs to the composer.json file that defines the binary supply library?
7. What about windows .bat and files?
8. Can a binary supply library be installed somewhere other than vendor/bin?
vendor/bin
A Composer resource pack, any command-line script that you want to pass to the user who installed it, should be included
二进制供应库
If a resource pack contains other scripts that are not required by the user, such as build or compile scripts, the code should not be included in the binary repository.
It is defined by adding a bin key to the
bin
composer.json
It is defined as an array of files so that any given item can add multiple binary files.
{
"bin": ["bin/my-script", "bin/my-other-script"]
}
For any
project that
depends on the resource pack, it will direct Composer to install the bin files in the resource pack into
vendor/bin
directory.
This is a convenient way to expose useful scripts, otherwise they will be hidden deep
vendor/
Nothing happens to a binary supply library that is directly defined by a resource pack.
Composer checks all binary files defined in the dependency package.
And set up a soft connection to
vendor/bin
for each dependent binary library.
For example, this is how the binary library of the
my-vendor/project-a
resource pack is installed:
{
"name": "my-vendor/project-a",
"bin": ["bin/project-a-bin"]
}
Executing the composer install command on
composer install
has
bin/project-a-bin
composer.json
Another example is the
my-vendor/project-b
such a require definition:
{
"name": "my-vendor/project-b",
"require": {
"my-vendor/project-a": "*"
}
}
When you execute the composer install command on
composer.json
checks all the dependent packages for project-b and installs their binary
vendor/bin
composer install
In this case, Composer
vendor/bin/project-a-bin
those access paths that
vendor/my-vendor/project-a/bin/project-a-bin
can access.
On a Class Unix platform, this is achieved by creating soft links.
Packages that are fully managed by Composer
do not
need to contain any
.bat
files.
When running in a Windows environment, Composer handles the installation of binary files in a special way:
.bat
automatically
Sometimes a resource pack needs to maintain
.bat
to support the workflow, which can not be included in Composer.
In this case, the resource pack should
not
list them as binary files because Composer does not need to know them.
Of course, there are two ways to specify other optional locations for binary supply libraries:
bin-dir
composer.json
file
COMPOSER_BIN_DIR
Examples of the former are as follows:
{
"config": {
"bin-dir": "scripts"
}
}
Running composer
composer install
composer.json
install installs all binary supply
scripts/
instead of
vendor/bin/