Repository navigation
Minify frontend/admin assets as an optional release build - #8
Merged
Merged
Conversation
…requirement Adds bin/build-assets.js (terser + clean-css, no bundler) producing .min.js/.min.css build artifacts for the cookie-notice banner and admin settings assets. The plain files stay the source of truth for contributors (AGENTS.md's "no build step" policy is untouched); `npm run build` is optional locally, and the release workflow (deploy.yml) now runs it before packaging a tagged release, so the minified files ship in production without ever being committed to main. CookieNotice::get_asset_url() / Settings::get_asset_url() enqueue the .min.* file when SCRIPT_DEBUG is off and it exists on disk, mirroring WordPress core's own suffix convention, and fall back to the plain file otherwise — a fresh checkout that never ran the build keeps working exactly as before. Closes #4. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The push token available in this environment lacks the `workflow` scope GitHub requires to update workflow files, so .github/workflows/deploy.yml can't be pushed from here. See the PR description for the exact diff to apply manually (adds a Node/npm setup + `npm run build` step before the 10up SVN deploy step, so tagged releases ship the minified assets). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- Replace the real SCRIPT_DEBUG constant + @runInSeparateProcess in the new PHPUnit tests with a protected is_script_debug() seam on both CookieNotice and Settings, overridden via an anonymous subclass in tests. Process isolation was failing in CI with "Serialization of 'Closure' is not allowed" (WP's global hook state holds closures), and defining SCRIPT_DEBUG for real would have leaked into every other test in the same PHPUnit process. - Add pretest:js/pretest:build-assets npm hooks that install node_modules on demand (skipped if already present) — the CI "Run JS tests" job runs `npm run test:js` with no separate install step, and the workflow file itself can't be touched from this environment (see the open PR's note about the missing `workflow` OAuth scope), so the fix has to live in package.json instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
wp_register_script()/wp_register_style() are no-ops once a handle is already registered — they never overwrite its `src` — so without deregistering 'frontconsent-cookie-notice'/'frontconsent-settings' in tear_down(), whichever `src` the first test in each new file enqueued was "sticking" for every later test in the same PHPUnit process (WP core's own test suite resets many globals between tests, but not $wp_scripts/ $wp_styles). This was failing 4 tests in CI with the wrong (stale) src. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
davidperezgar
approved these changes
Sep 29, 2026
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.
Summary
bin/build-assets.js, a small Node script (no bundler) that usesterser(JS) andclean-css(CSS) to produce.min.js/.min.cssbuild artifacts forassets/cookie-notice/frontconsent-cookie-notice.js/.cssandassets/admin/settings.js/.css.CookieNotice::get_asset_url()andSettings::get_asset_url()enqueue the.min.*file whenSCRIPT_DEBUGis off (undefined or false) and the file exists on disk, mirroring WordPress core's own suffix convention — otherwise they fall back to the plain file.AGENTS.md's "no build step" policy already states (amended with one clarifying sentence about the new optional release step)..min.js/.min.cssare gitignored — they're never committed tomain, never required for local dev, and a fresh checkout that hasn't run the build simply falls back to the plain files (verified by tests).npm run buildas an optional local script, plusnpm run test:build-assets(also covered bynpm run test:js) smoke-testing the minifiers against the real source files: non-empty output, syntactically valid (new vm.Script(...)), and still containing a few behavior-relevant tokens/selectors.tests/Unit/CookieNoticeAssetMinificationTest.php,tests/Unit/SettingsAssetMinificationTest.php) covering: minified file preferred when present andSCRIPT_DEBUGis off, plain file used when the minified file is absent, and plain file forced whenSCRIPT_DEBUGis on even if a minified file exists (run in a separate process so the constant doesn't leak into other tests).Manual follow-up needed:
.github/workflows/deploy.ymlThe push token available to this automation lacks the
workflowOAuth scope GitHub requires to update workflow files, so the actual CI wiring couldn't be pushed on this branch. Please apply this diff by hand (or ask me to redo it with proper scope) before merging, so tagged releases actually ship the minified assets:- name: Build run: composer install -o --no-dev --ignore-platform-reqs + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install npm dependencies + run: npm ci + + - name: Build minified assets + run: npm run build + - name: WordPress Plugin Deploy uses: 10up/action-wordpress-plugin-deploy@stableInsert it right after the existing
- name: Build(composer install) step, before- name: WordPress Plugin Deploy, in.github/workflows/deploy.yml..distignorealready excludesbin/,node_modules/, andpackage.json/package-lock.jsonfrom the SVN package, and does not exclude*.min.*, so the generated files ship correctly once this step runs.Test plan
composer lint— passescomposer phpstan— passes ("No errors")npm run test:js(25 tests, includes newbuild-assets.test.js) — all passnpm run build— verified it produces valid.min.js/.min.css(checked withnode --checkand manual inspection), then removed the artifacts again since they're gitignored dev-only outputcomposer test(PHPUnit) — not run in this sandbox: no MySQL/MariaDB or Docker available to stand up the WordPress test database (bin/install-wp-tests.shrequires it). The new tests follow the existingYoast\WPTestUtils\WPIntegration\TestCasepattern exactly (seetests/Unit/CookieNoticePolicyPageTest.php) and were verified for syntax (php -l) and logic by hand; please runcomposer testin CI/locally to confirm.Closes #4.
🤖 Generated with Claude Code