Skip to content

Commit de08bc8

Browse files
Add an upgrade guide for moving from 1.x to 2.x (#62)
* Add a 1.x to 2.x upgrade guide and link it from the README * Update UPGRADE.md --------- Co-authored-by: Joe Tannenbaum <joe.tannenbaum@laravel.com>
1 parent bdffc5c commit de08bc8

2 files changed

Lines changed: 133 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Run any command from any composer package, even if it's not installed in your pr
66

77
cpx is to Composer what npx is to npm.
88

9+
> Note: Upgrading from cpx 1.x? The 1.x series is frozen and no longer supported — see the [upgrade guide](./UPGRADE.md) to move to 2.x.
10+
911
## Installation
1012

1113
Install cpx globally with Composer:

UPGRADE.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Upgrade guide
2+
3+
- [Upgrading to 2.x from 1.x](#upgrading-to-2x-from-1x)
4+
- [Support for 1.x](#support-for-1x)
5+
- [Updating your installation](#updating-your-installation)
6+
- [Cached packages and metadata](#cached-packages-and-metadata)
7+
- [Command changes](#command-changes)
8+
- [Listing installed packages](#listing-installed-packages)
9+
- [Package aliases](#package-aliases)
10+
- [The check, format, and test commands](#the-check-format-and-test-commands)
11+
- [Checking the cpx version](#checking-the-cpx-version)
12+
- [Behavior changes](#behavior-changes)
13+
- [Local binaries are preferred](#local-binaries-are-preferred)
14+
- [Running PHP files](#running-php-files)
15+
- [The composer_require function](#the-composer_require-function)
16+
- [Non-interactive output](#non-interactive-output)
17+
18+
## Upgrading to 2.x from 1.x
19+
20+
cpx 2.x is a full rewrite that ships as a self-contained PHAR, but it keeps the same package name, the same `~/.cpx` cache directory, and the same core usage — `cpx <package-name> <command> [arguments]` works exactly as it did in 1.x. Most upgrades take about five minutes: update the global installation, then review the command and behavior changes below.
21+
22+
For everything new in 2.x — local package directories, gist execution, user-defined aliases, JSON output, and more — see the [README](./README.md).
23+
24+
## Support for 1.x
25+
26+
The 1.x release series is frozen and no longer supported. No further 1.x releases will be published, including bug fixes and security fixes. All development happens on the 2.x series.
27+
28+
## Updating your installation
29+
30+
cpx 2.x requires PHP 8.3 or higher.
31+
32+
To upgrade, require cpx globally again:
33+
34+
```shell
35+
composer global require cpx/cpx:^2.0
36+
```
37+
38+
The `cpx upgrade` command has been removed. To update cpx itself in the future, use Composer directly:
39+
40+
```shell
41+
composer global update cpx/cpx
42+
```
43+
44+
## Cached packages and metadata
45+
46+
No manual migration of the `~/.cpx` directory is required. cpx 2.x reads your existing metadata and upgrades it to the new format automatically, and packages installed without a version constraint are reused as-is.
47+
48+
Packages that were run with a version constraint (such as `friendsofphp/php-cs-fixer:^3.0`) are stored under new directory names in 2.x, so they are installed fresh the first time you run them. You may remove the 1.x copies left behind:
49+
50+
```shell
51+
cpx clean
52+
```
53+
54+
The old directories are reported as orphaned packages and deleted.
55+
56+
## Command changes
57+
58+
### Listing installed packages
59+
60+
`cpx list` now shows every available cpx command, matching standard console behavior. To see the packages you have installed through cpx, use:
61+
62+
```shell
63+
cpx installed
64+
```
65+
66+
### Package aliases
67+
68+
1.x shipped a built-in list of shortcuts for popular packages, so commands like `cpx phpstan` and `cpx laravel` worked out of the box. This list has been removed in 2.x. Instead, you may define your own aliases:
69+
70+
```shell
71+
cpx alias phpstan/phpstan phpstan
72+
cpx alias laravel/installer laravel
73+
```
74+
75+
`cpx aliases` now lists the aliases you have defined instead of the built-in list, and `cpx unalias <name>` removes one.
76+
77+
Inside a project that already installs a tool, no alias is needed — a bare name such as `cpx phpstan` runs the matching binary from your project's `vendor/bin` directory.
78+
79+
### The check, format, and test commands
80+
81+
The `cpx check`, `cpx format`, and `cpx test` commands (and their `analyze`, `analyse`, and `fmt` aliases) have been removed. Run the underlying tool directly instead:
82+
83+
```shell
84+
cpx pint
85+
cpx phpstan
86+
cpx pest
87+
```
88+
89+
Because 2.x prefers binaries already installed in your project, these commands run your project's own pinned version of each tool, which is what the 1.x commands approximated.
90+
91+
### Checking the cpx version
92+
93+
The `cpx version` command and the `-v` shorthand have been removed. Use the standard option instead:
94+
95+
```shell
96+
cpx --version
97+
```
98+
99+
## Behavior changes
100+
101+
### Local binaries are preferred
102+
103+
When you run a package inside a Composer project that already has a matching binary installed, 2.x runs the binary from your project's `vendor/bin` directory instead of installing an isolated copy — the same way npx prefers local binaries. 1.x always used the isolated copy.
104+
105+
To restore the 1.x behavior for a single run, pass `--skip-local` before the package name:
106+
107+
```shell
108+
cpx --skip-local laravel/pint --version
109+
```
110+
111+
### Running PHP files
112+
113+
In 1.x, passing a path to an existing PHP file (such as `cpx script.php`) ran the file. In 2.x, files must be run through `cpx exec` explicitly:
114+
115+
```shell
116+
cpx exec script.php
117+
```
118+
119+
### The `composer_require` function
120+
121+
The `composer_require()` helper available inside `cpx exec` scripts and `cpx tinker` sessions has been renamed to `cpx_require()`:
122+
123+
```php
124+
cpx_require('nesbot/carbon');
125+
126+
echo Carbon\Carbon::now();
127+
```
128+
129+
### Non-interactive output
130+
131+
When cpx detects that it is not running in an interactive terminal — stdin is redirected, `--no-interaction` is passed, or an AI agent is detected — its own management commands (`installed`, `aliases`, `alias`, `unalias`, `clean`, and `update`) respond with a single line of JSON instead of formatted text, and package runs stream only the tool's own output. If you parse cpx output in scripts, update them for the JSON format, or pass `--json` to get the same output from an interactive terminal.

0 commit comments

Comments
 (0)