API / Minn\Runtime / ScriptPack

ScriptPack final class

Minn\Runtime\ScriptPack · public/minn/src/Minn/Runtime/ScriptPack.php · 146 lines

The site-supplied script pack: the `wp-*` JavaScript packages the engine does not reimplement, which a few plugins' front ends need (WooCommerce's block cart and checkout are the reason it exists).

These packages are GPL, so the engine never ships them: the SITE installs them into its own `wp-content`, the way it installs a language pack, and the engine registers the handles only when they are actually there. A site owner adding GPL files to a site that already runs GPL plugins is not the engine distributing GPL; nothing under `minn/` changes.

The engine's own MIT packages under `minn/assets/wp` always win: the pack fills the gaps around them, it does not replace them.

Constants and properties

constRELATIVE_DIR = 'minn-packages/wp-scripts'

Under the site's wp-content, so backups and migrations carry it.

constMANIFEST = 'script-loader-packages.php'
privateVENDOR = array ( 'lodash' => array ( ), 'moment' => array ( ), 'react' => array ( ), 'react-dom' => array ( 0 => 'react', ), 'react-jsx-runtime' => array ( 0 => 'react', ), 'regenerator-runtime' => array ( ), 'wp-polyfill' => array ( ), 'wp-polyfill-dom-rect' => array ( ), 'wp-polyfill-element-closest' => array ( ), 'wp-polyfill-fetch' => array ( ), 'wp-polyfill-formdata' => array ( ), 'wp-polyfill-inert' => array ( ), 'wp-polyfill-node-contains' => array ( ), 'wp-polyfill-object-fit' => array ( ), 'wp-polyfill-url' => array ( ), )

The vendor handles WordPress registers outside the packages manifest (captured from the reference). `moment` matters as much as `react`: one unregistered handle anywhere in a dependency tree drops every script above it, which is how a missing moment silently cost the whole WooCommerce cart bundle.

Public

staticdir(string $contentDir): string#

Where the script pack lives under wp-content.

staticinstalled(string $contentDir): bool#

Whether the script pack is on disk.

statichandles(string $contentDir): array#

Every handle the pack can register: the packages manifest keyed by `name.js` becomes `wp-name`, plus the three vendor handles. A handle whose file is missing from the pack is skipped rather than registered against a 404.

@return array<string, array{file: string, deps: list<string>, ver: string}>
staticinstallFromTree(string $contentDir, string $tree): array#

Copies the packages out of a WordPress tree (or an unpacked core download) into the site's pack directory. Only the built JavaScript and the manifest are taken, and only from the paths they live at, so a wrong source folder copies nothing rather than something odd.

@return array{files: int, dir: string}
staticremove(string $contentDir): bool#

Removes the pack; the engine's own packages keep working without it.

Internals 1

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatestamp(string $file): string#