Repository navigation
feat(cli): add wordpress-source command to materialize core source from the archive cache - #2566
Merged
Merged
Conversation
…om the archive cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
wp-codebox wordpress-source [--wp <version-query>] [--json]. It writes WordPress core source files to the host from the same validated archive cache WP Codebox uses to boot Playground.packages/runtime-playground/src/playground-wordpress-source.ts:materializePlaygroundWordPressSource(). Exported from the playground package.packages/cli/src/commands/wordpress-source.ts: the CLI command. Registered in the command router and CLI entry, and documented in the CLI help and the README command list.@php-wasm/stream-compression(already in the lockfile at 3.1.46 through@php-wasm/universal) is now a direct dependency ofruntime-playground, used for zip extraction. The command does not shell out tounzip.Why
Some tools need WordPress core source without a booted site. One example is PHP smoke tests that load
wp-includes/html-api/*. With this command they use the same WordPress that WP Codebox runs. WP Codebox stays the only owner of WordPress release resolution, download and validation, so consumers don't need their own downloader.Contract
--wptakes an exact version (7.1.2) orlatest. If omitted, it defaults to latest. The query goes through the existingresolvePlaygroundWordPressStartupAsset→resolveWordPressReleaseForStartuppath, which ensures a validated${version}.zipinplaygroundWordPressArchiveCacheDirectory(). It uses the existing lock, downloader and validator; there is no second downloader.trunk,nightlyand URL queries are rejected because they don't map to a release archive whose$wp_versioncan be checked.The archive is extracted once to
<archive cache>/source/<version>/wordpress, the directory that containswp-includes/version.php.Extraction is atomic:
<archive cache>/source/.<version>.<pid>.<uuid>.partial.wordpress/).wp-includes/version.phpmust declare$wp_versionequal to the resolved version.<archive cache>/source/<version>.If another caller has already published a tree that verifies, it is reused. A tree that fails verification is moved aside and replaced. The staging directory is always removed.
With
--json, stdout is exactly one line:{"schema":"wp-codebox/wordpress-source/v1","version":"7.1.2","root":"…/source/7.1.2/wordpress","archive":"…/7.1.2.zip","sourceUrl":"https://…"}.Without
--json, stdout is only the root path.Diagnostics go to stderr.
Exit codes:
0on success;1when materialization fails (offline, unknown version, invalid archive, verification mismatch), with a message on stderr and nothing on stdout;2for invalid arguments.Verification
tests/wordpress-source.test.tsruns in the fast lane via smoke discovery. It covers:version.phpverification, including mismatch and missing file.partialdirectoriesfetchstubbedtrunk--jsonemits one line with exactly the 5 keys; plain output is the root path; failures leave stdout empty, write to stderr and exit1; bad flags exit2npm run check: passed, 329 commands. This covers the build, the typecheck (tsc -b) and every fast contract, including the new test.npm run build && node packages/cli/dist/index.js wordpress-source --wp 7.1.2 --jsonexits0and prints{"schema":"wp-codebox/wordpress-source/v1","version":"7.1.2","root":"$HOME/.wordpress-playground/source/7.1.2/wordpress","archive":"$HOME/.wordpress-playground/7.1.2.zip","sourceUrl":"https://wordpress.org/wordpress-7.1.2.zip"}.<root>/wp-includes/html-api/class-wp-html-tag-processor.phpexists, andversion.phpdeclares$wp_version = '7.1.2'.WP_CODEBOX_PLAYGROUND_WORDPRESS_CACHE_DIR=$(mktemp -d)):version.phphave the same SHA-256 hashes as the output ofunzip.--jsonwith no--wpresolved latest to 7.1.3.--wp 0.0.1exited1with stderrHTTP 404 Not Found.--wp trunkexited1with a clear message..partialdirectories were left behind.AI disclosure: written by Claude in OpenCode with Chris Huber; Claude implemented, tested and opened this PR.