PHPackages                             melchiorkokernoot/composer-pkg-scripts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. melchiorkokernoot/composer-pkg-scripts

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

melchiorkokernoot/composer-pkg-scripts
======================================

Composer plugin that provides a way for packages to expose scripts to the root project

1.0.0(3y ago)23.5k↓40.6%1MITPHPPHP &gt;=7.1

Since Mar 3Pushed 2y agoCompare

[ Source](https://github.com/MelchiorKokernoot/composer-pkg-scripts)[ Packagist](https://packagist.org/packages/melchiorkokernoot/composer-pkg-scripts)[ RSS](/packages/melchiorkokernoot-composer-pkg-scripts/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (1)

Composer package scripts
========================

[](#composer-package-scripts)

Composer plugin that provides a way for packages to expose custom scripts to the root project. These scripts work similarly to the root-only [scripts](https://getcomposer.org/doc/04-schema.md#scripts) option.

[![https://travis-ci.com/kuria/composer-pkg-scripts.svg?branch=master](https://camo.githubusercontent.com/a7d46911b45144d0ba722a2c298a2467c940ffc9d9fee5d393a4faca0d41cee3/68747470733a2f2f7472617669732d63692e636f6d2f6b757269612f636f6d706f7365722d706b672d736372697074732e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/kuria/composer-pkg-scripts)Contents

- [Requirements](#requirements)
- [Terminology](#terminology)
- [Installation](#installation)
- [Defining package scripts](#defining-package-scripts)
    - [Referencing other scripts](#referencing-other-scripts)
    - [Specifying aliases and help](#specifying-aliases-and-help)
    - [Using variables](#using-variables)
- [Running package scripts](#running-package-scripts)
- [Using package scripts in events](#using-package-scripts-in-events)
- [Listing package scripts](#listing-package-scripts)
- [Debugging package scripts and variables](#debugging-package-scripts-and-variables)

[Requirements](#id1)
--------------------

[](#requirements)

- PHP 7.1+
- Composer 1.6+

[Terminology](#id2)
-------------------

[](#terminology)

root packagethe main package (project)root scripta script defined in the root package's [scripts](https://getcomposer.org/doc/04-schema.md#scripts) optionpackage scripta script defined in a package's `extra.package-scripts` option[Installation](#id3)
--------------------

[](#installation)

Specify `kuria/composer-pkg-scripts` as a dependency in your `composer.json`.

This can be done either in the root package or in one of the required packages (perhaps a [metapackage?](https://getcomposer.org/doc/04-schema.md#type)). That depends entirely on your use case.

```
{
    // ...
    "require": {
        "kuria/composer-pkg-scripts": "^1.0"
    }
}
```

[Defining package scripts](#id4)
--------------------------------

[](#defining-package-scripts)

Package scripts can be defined in the *composer.json*'s [extra](https://getcomposer.org/doc/04-schema.md#extra) option.

The syntax is identical to the root-only [scripts](https://getcomposer.org/doc/04-schema.md#scripts) option. See [Composer docs - defining scripts](https://getcomposer.org/doc/articles/scripts.md#defining-scripts).

```
{
    "name": "acme/example",
    // ...
    "extra": {
        "package-scripts": {
            "hello-world": "echo Hello world!",
            "php-version": "php -v"
        }
    }
}
```

The final script names are automatically prefixed by the package name.

The example above will define the following scripts:

- `acme:example:hello-world`
- `acme:example:php-version`

To define shorter aliases, see [Specifying aliases and help](#specifying-aliases-and-help).

Note

Package scripts will **not** override root [scripts](https://getcomposer.org/doc/04-schema.md#scripts) with the same name.

Note

Package scripts defined in the root package will not be loaded. Use [scripts](https://getcomposer.org/doc/04-schema.md#scripts) instead.

### [Referencing other scripts](#id5)

[](#referencing-other-scripts)

In addition to the root [scripts](https://getcomposer.org/doc/04-schema.md#scripts), package scripts may reference other package scripts defined in the same file.

See [Composer docs - referencing scripts](https://getcomposer.org/doc/articles/scripts.md#referencing-scripts).

```
{
    "name": "acme/example",
    // ...
    "extra": {
        "package-scripts": {
            "all": ["@first", "@second", "@third"],
            "first": "echo first",
            "second": "echo second",
            "third": "echo third"
        }
    }
}
```

Package scripts of other packages may be referenced using their full name or alias (if it exists). Using the full name should be preferred.

```
{
    "name": "acme/example",
    // ...
    "extra": {
        "package-scripts": {
            "another-foo": "@acme:another:foo"
        }
    }
}
```

### [Specifying aliases and help](#id6)

[](#specifying-aliases-and-help)

Package script aliases and help can be defined in the *composer.json*'s [extra](https://getcomposer.org/doc/04-schema.md#extra)option.

```
{
    "name": "acme/example",
    // ...
    "extra": {
        "package-scripts": {
            "hello-world": "echo Hello world!",
            "php-version": "php -v"
        },
        "package-scripts-meta": {
            "hello-world": {"aliases": "hello", "help": "An example command"},
            "php-version": {"aliases": ["phpv", "pv"], "help": "Show PHP version"}
        }
    }
}
```

Unlike script names, aliases are not automatically prefixed by the package name.

The example above will define the following scripts:

- `acme:example:hello-world`
- `acme:example:php-version`
- `hello`
- `phpv`
- `pv`

Note

Package script aliases will **not** override root [scripts](https://getcomposer.org/doc/04-schema.md#scripts) or other aliases with the same name.

#### Specifying aliases in the root package

[](#specifying-aliases-in-the-root-package)

If a package doesn't provide suitable aliases, the root package may define them in its [scripts](https://getcomposer.org/doc/04-schema.md#scripts) option.

```
{
    "name": "acme/project",
    // ...
    "scripts": {
        "acme-hello": "@acme:example:hello-world"
    }
}
```

### [Using variables](#id7)

[](#using-variables)

Unlike root [scripts](https://getcomposer.org/doc/04-schema.md#scripts), package scripts may use variable placeholders.

The syntax of the placeholder is:

```
{$variable-name}
```

- variable name can consist of any characters other than "}"
- nonexistent variables resolve to an empty string
- the final value is escaped by `escapeshellarg()`
- array variables will be imploded and separated by spaces, with each value escaped by `escapeshellarg()`

#### Composer configuration

[](#composer-configuration)

All Composer configuration directives are available through variables.

See [Composer docs - config](https://getcomposer.org/doc/06-config.md).

```
{
    "name": "acme/example",
    // ...
    "extra": {
        "package-scripts": {
            "list-vendors": "ls {$vendor-dir}"
        }
    }
}
```

#### Package variables

[](#package-variables)

Packages may define their own variables in the *composer.json*'s [extra](https://getcomposer.org/doc/04-schema.md#extra) option.

```
{
    "name": "acme/example",
    // ...
    "extra": {
        "package-scripts": {
            "hello": "echo {$name}"
        },
        "package-scripts-vars": {
            "name": "Bob"
        }
    }
}
```

These defaults may then be overriden in the root package, if needed:

```
{
    "name": "acme/project",
    // ...
    "extra": {
        "package-scripts-vars": {
            "acme/example": {
                "name": "John"
            }
        }
    }
}
```

##### Referencing other variables

[](#referencing-other-variables)

Package variables may reference [composer configuration directives](https://getcomposer.org/doc/06-config.md)or other package variables belonging to the same package.

```
{
    "name": "acme/example",
    // ...
    "extra": {
        "package-scripts": {
            "hello": "echo Hello {$names}",
            "show-paths": "echo {$paths}"
        },
        "package-scripts-vars": {
            "names": ["Bob", "{$other-names}"],
            "other-names": ["John", "Nick"],
            "paths": ["{$vendor-dir}", "{$bin-dir}"]
        }
    }
}
```

```
composer acme:example:hello
```

```
> echo Hello "Bob" "John" "Nick"
Hello Bob John Nick
```

```
composer acme:example:show-paths
```

```
> echo "/project/vendor" "/project/vendor/bin"
/project/vendor /project/vendor/bin
```

Note

Array variables must be referenced directly, e.g. `"{$array-var}"`, not embedded in the middle of a string.

Nested array variable references are flattened into a simple list, as seen in the examples above.

[Running package scripts](#id8)
-------------------------------

[](#running-package-scripts)

Package scripts can be invoked the same way root [scripts](https://getcomposer.org/doc/04-schema.md#scripts) can:

1. `composer run-script acme:example:hello-world`
2. `composer acme:example:hello-world`

See [Composer docs - running scripts manually](https://getcomposer.org/doc/articles/scripts.md#running-scripts-manually).

[Using package scripts in events](#id9)
---------------------------------------

[](#using-package-scripts-in-events)

Package scripts may be used in event scripts (provided the plugin is loaded at that point).

```
{
    "name": "acme/project",
    // ...
    "scripts": {
        "post-install-cmd": "@acme:example:hello-world"
    }
}
```

[Listing package scripts](#id10)
--------------------------------

[](#listing-package-scripts)

This plugin provides a command called `package-scripts:list`, which lists both active and inactive package scripts and aliases.

```
composer package-scripts:list
```

```
Available package scripts:
  acme:example:hello-world (hello)    An example command
  acme:example:php-version (phpv, pv) Show PHP version
```

Enabling verbose mode will show additonal information:

```
composer package-scripts:list -v
```

```
Available package scripts:
  acme:example:hello-world Run the "hello-world" script from acme/example
   - package: acme/example
   - definition: "echo Hello world!"
   - aliases:
  acme:example:php-version Run the "php-version" script from acme/example
   - package: acme/example
   - definition: "php -v"
   - aliases:
```

You may use the `psl` alias instead of the full command name.

[Debugging package scripts and variables](#id11)
------------------------------------------------

[](#debugging-package-scripts-and-variables)

This plugin provides a command called `package-scripts:dump`, which dumps compiled scripts (including root scripts) or package script variables.

```
composer package-scripts:dump
```

Specifying the `--vars` flag will dump compiled package script variables instead:

```
composer package-scripts:dump --vars
```

You may use the `psd` alias instead of the full command name.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1173d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c6acec44c8f326764aeaa4f283ee2e083223568504a9e5ef4d5fb78d4a922225?d=identicon)[MelchiorKokernoot](/maintainers/MelchiorKokernoot)

---

Top Contributors

[![shira-374](https://avatars.githubusercontent.com/u/1024071?v=4)](https://github.com/shira-374 "shira-374 (16 commits)")[![MelchiorKokernoot](https://avatars.githubusercontent.com/u/23347384?v=4)](https://github.com/MelchiorKokernoot "MelchiorKokernoot (4 commits)")[![etobi](https://avatars.githubusercontent.com/u/152207?v=4)](https://github.com/etobi "etobi (1 commits)")

---

Tags

composerpackagescriptscripts

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/melchiorkokernoot-composer-pkg-scripts/health.svg)

```
[![Health](https://phpackages.com/badges/melchiorkokernoot-composer-pkg-scripts/health.svg)](https://phpackages.com/packages/melchiorkokernoot-composer-pkg-scripts)
```

###  Alternatives

[jean85/pretty-package-versions

A library to get pretty versions strings of installed dependencies

1.3k289.5M63](/packages/jean85-pretty-package-versions)[fxp/composer-asset-plugin

NPM/Bower Dependency Manager for Composer

8894.8M41](/packages/fxp-composer-asset-plugin)[composer/satis

Simple Repository Generator

3.3k1.4M17](/packages/composer-satis)[foxy/foxy

Fast, reliable, and secure NPM/Yarn/pnpm bridge for Composer

177287.5k25](/packages/foxy-foxy)[neronmoon/scriptsdev

Scripts-dev behaviour for Composer

691.5M41](/packages/neronmoon-scriptsdev)[netojose/laravel-bootstrap-4-forms

Bootstrap 4 form builder for Laravel 5

182115.3k](/packages/netojose-laravel-bootstrap-4-forms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
