A script, in Composer's terms, can either be a PHP callback (defined as a
static method) or any command-line executable command. Scripts are useful
for executing a package's custom code or package-specific commands during
the Composer execution process.

Note: Only scripts defined in the root package's composer.json are
executed. If a dependency of the root package specifies its own scripts,
Composer does not execute those additional scripts.

command: occurs before any Composer Command is executed on the CLI. It
provides you with access to the input and output objects of the program.

pre-file-download: occurs before files are downloaded and allows
you to manipulate the RemoteFilesystem object prior to downloading files
based on the URL to be downloaded.

pre-command-run: occurs before a command is executed and allows you to
manipulate the InputInterface object's options and arguments to tweak
a command's behavior.

Note: Composer makes no assumptions about the state of your dependencies
prior to install or update. Therefore, you should not specify scripts
that require Composer-managed dependencies in the pre-update-cmd or
pre-install-cmd event hooks. If you need to execute scripts prior to
install or update please make sure they are self-contained within your
root package.

The root JSON object in composer.json should have a property called
"scripts", which contains pairs of named events and each event's
corresponding scripts. An event's scripts can be defined as either a string
(only for a single script) or an array (for single or multiple scripts.)

For any given event:

Scripts execute in the order defined when their corresponding event is fired.

An array of scripts wired to a single event can contain both PHP callbacks
and command-line executable commands.

Callbacks can only autoload classes from psr-0, psr-4 and classmap
definitions. If a defined callback relies on functions defined outside of a
class, the callback itself is responsible for loading the file containing these
functions.

Note: During a composer install or update process, a variable named
COMPOSER_DEV_MODE will be added to the environment. If the command was run
with the --no-dev flag, this variable will be set to 0, otherwise it will be
set to 1.

If you would like to run the scripts for an event manually, the syntax is:

composer run-script [--dev] [--no-dev] script

For example composer run-script post-install-cmd will run any
post-install-cmd scripts that have been defined.

You can also give additional arguments to the script handler by appending --
followed by the handler arguments. e.g.
composer run-script post-install-cmd -- --check will pass--check along to
the script handler. Those arguments are received as CLI arg by CLI handlers,
and can be retrieved as an array via $event->getArguments() by PHP handlers.

If you add custom scripts that do not fit one of the predefined event name
above, you can either run them with run-script or also run them as native
Composer commands. For example the handler defined below is executable by
simply running composer test:

{
"scripts": {
"test": "phpunit"
}
}

Similar to the run-script command you can give additional arguments to scripts,
e.g. composer test -- --filter <pattern> will pass --filter <pattern> along
to the phpunit script.

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. In this example no matter if the phpunit binary is
actually in vendor/bin/phpunit or bin/phpunit it will be found and executed.

Although Composer is not intended to manage long-running processes and other
such aspects of PHP projects, it can sometimes be handy to disable the process
timeout on custom commands. This timeout defaults to 300 seconds and can be
overridden in a variety of ways depending on the desired effect:

disable it for all commands using the config key process-timeout,

disable it for the current or future invocations of composer using the
environment variable COMPOSER_PROCESS_TIMEOUT,

for a specific invocation using the --timeout flag of the run-script command,

using a static helper for specific scripts.

To disable the timeout for specific scripts with the static helper directly in
composer.json: