Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

pun install

Install the locked dependencies into vendor/.

pun install
pun install --no-dev --classmap-authoritative
pun install --ignore-platform-req=ext-imagick

pun install installs the versions in composer.lock into vendor/. The result matches composer install, so you can switch between the two tools.

Where the dependencies come from

pun install reads composer.json and composer.lock, not pun.toml. Without a composer.json, it exits 2. pun require creates one.

Without a lock, pun install resolves one first, as pun update does. If composer.json changed after the lock was written, pun install warns that the lock is out of date. Run pun update to refresh it.

What an install does

  1. Pun checks that the lock meets composer.json, as composer install does: every package that require (and require-dev, without --no-dev) names must be in the lock at a version the constraint accepts, or be provided or replaced by a locked package or the root. If one isn’t, Pun prints Composer’s lines (- Required package "…" is not present in the lock file.) and exits 4 without touching vendor/. With config.allow-missing-requirements set to true, Pun prints the lines and installs anyway. This check runs after pre-install-cmd, on every install from a lock, including a no-op install.
  2. Pun checks that the lock can be installed on this PHP, as composer install does: every platform requirement (php, ext-*, lib-*) of the root and of the locked packages, and every conflict between locked packages. If one fails, Pun prints Composer’s problem report and exits 2 without touching vendor/. --ignore-platform-req and --ignore-platform-reqs leave requirements out, and config.platform overrides recorded in the lock apply. REQ+ (for example php+) ignores only the upper bound. Pun remembers a check that passed, in its cache, and doesn’t run it again for the same composer.json, lock, PHP platform, and flags.
  3. Packages already at the locked reference stay. Packages no longer locked are removed.
  4. Other packages download in parallel, or come from Composer’s download cache. Each archive is extracted once into Pun’s package store, and vendor/ gets its files from there (see Package store).
  5. Each archive must match its shasum in the lock, or the install stops.
  6. Path repositories become symlinks.
  7. Pun writes vendor/composer, the autoloader, and vendor/bin.

After an install succeeds, Pun records what it read and what it wrote in its cache (PUN_CACHE_DIR). The next pun install with the same flags skips steps 2 to 7 when nothing on either list changed. The lists cover composer.json, composer.lock, the PHP platform, the files and directories under the root’s autoload paths and path repositories, the git refs the root version comes from, vendor/autoload.php, vendor/composer/, the bin directory, and each package’s directory. The pre-install-cmd, pre-autoload-dump, post-autoload-dump, and post-install-cmd events still run, as on Composer’s no-op install. Pun always runs the full install for a random APCu prefix, a pre-autoload-dump script, or an allowed plugin that runs on PHP.

Pun installs zip and tar archives and path repositories. A package locked with only a VCS source fails.

Credentials come from COMPOSER_AUTH, the project’s auth.json, then Composer’s global auth.json. Pun supports github-oauth, gitlab-token, bearer, and http-basic. COMPOSER_MAX_PARALLEL_HTTP limits parallel downloads (default 48). Pun refuses http:// URLs unless config.secure-http is false.

Package store

Pun keeps every extracted package in a store in its cache (PUN_CACHE_DIR, under store/), keyed by the archive’s URL, reference, and checksum. Installing a package the store already has needs no download and no extraction. Pun only links the package’s files into vendor/. The files and their modes are the ones composer install writes. Pun writes vendor/composer/, vendor/autoload.php, and vendor/bin for each project, and doesn’t link them.

--link-mode (or PUN_LINK_MODE) sets how files reach vendor/:

Mode How Disk Editing a file in vendor/
hardlink (default, as in pnpm) One file for the store and every project. Copies across filesystems. Shared on every filesystem Changes the store and every project that uses the package
clone Copy-on-write clone (Btrfs, XFS, APFS). Copies where the filesystem can’t clone. Shared until written, where cloning works Changes only this project
copy Ordinary copy Not shared Changes only this project

With hardlink, an editor or patch that writes a file in place also changes the store and every other project linked to that file. Pun checks a stored package’s files against the time it stored them before it links them, as pnpm does, and extracts an edited package again, so later installs get Composer’s files. Projects that already link the edited file keep sharing it. If you edit files in vendor/ by hand, use clone (on Btrfs, XFS or APFS) or copy, for example with PUN_LINK_MODE=clone in your shell profile. Tools that write a new file and rename it over the old one don’t change the store.

Pun also caches the classes it finds in a stored package for the class map, so pun install and pun composer dump-autoload rescan only the root’s autoload paths, path repositories, and packages installed from source. A class you add by hand to a package in vendor/ reaches the class map only after that package is installed again. Pun also keeps the last autoloader it generated for each vendor/ directory. When the next dump has the same inputs (the flags, composer.json, every package’s metadata and install path, and the files under the root’s autoload paths and path repositories), Pun writes the kept files instead of generating them again.

Scripts and plugins

Pun runs the root package’s pre-install-cmd, pre-autoload-dump, post-autoload-dump, and post-install-cmd scripts, with vendor/bin first on PATH. A Class::method callback gets an event with getComposer()->getConfig(), getIO(), isDevMode(), and getArguments().

Pun runs the plugins that config.allow-plugins allows. pestphp/pest-plugin and php-http/discovery need no PHP. Other plugins run on the system PHP, and the first one makes Pun download composer.phar 2.11.2 into Composer’s cache. If a plugin throws, the command exits 2.

Plugins don’t get the package events, pre-operations-exec, pre-pool-create, or the download events. Custom installer paths, such as those of composer/installers, and plugin commands aren’t supported.

Options

Option Effect
--no-dev Leave out require-dev packages, and remove them if installed
-o, --optimize-autoloader Add PSR-0 and PSR-4 classes to the class map. Also config.optimize-autoloader.
-a, --classmap-authoritative Load classes from the class map only. Implies -o.
--apcu-autoloader Cache class lookups in APCu. Also config.apcu-autoloader.
--apcu-autoloader-prefix=PREFIX The APCu prefix (default: random). Implies --apcu-autoloader.
--no-autoloader Skip the autoloader and its dump events
--no-scripts Skip the root package’s scripts. Plugins still run.
--no-plugins Skip the Composer plugins
--ignore-platform-req=REQ Leave REQ out of the install-time platform check and platform_check.php. Repeatable. Accepts *; REQ+ ignores only the upper bound.
--ignore-platform-reqs Skip the install-time platform check and write no platform_check.php
--link-mode=MODE hardlink (default), clone, or copy: how files reach vendor/ from the store. Also PUN_LINK_MODE.
-d, --working-dir=DIR Run in DIR

Exit codes

Code When
0 Installed
4 The lock doesn’t meet a requirement of composer.json, and config.allow-missing-requirements isn’t set
2 No composer.json, a lock this PHP can’t install, unresolvable requirements, a failed download, checksum, or script, or another run error

Last updated on

Was this page helpful?