Skip to content

Slim packaged artifacts - #42

Merged
samdark merged 1 commit into
masterfrom
chore/slim-packaged-artifacts
Jun 2, 2026
Merged

Slim packaged artifacts#42
samdark merged 1 commit into
masterfrom
chore/slim-packaged-artifacts

Conversation

@samdark

@samdark samdark commented Jun 2, 2026

Copy link
Copy Markdown
Member

Summary

  • Strip PHPDoc from packaged PHP files while preserving runtime-reflected PHPDoc in cebe/markdown
  • Omit non-runtime package inputs such as Composer installed.json, VCS placeholders, and .hhi stubs
  • Move benchmark fixture generation to dev autoload and fix direct Composer dependency declarations

Verification

  • make test tests/Unit/Benchmarks/BenchmarkFixtureTest.php
  • make test tests/Unit/Packaging/ConfigurationPackagingTest.php
  • make composer-dependency-analyser
  • make test
  • make package-phar
  • make php CLI_ARGS='dist/phar/yiipress.phar --help'
  • make php CLI_ARGS='dist/phar/yiipress.phar build --content-dir=docs --output-dir=runtime/phar-docs-output --no-cache'

Packaged PHAR size on this branch: 2,861,304 bytes.

Summary by CodeRabbit

  • New Features

    • PHAR packages now have documentation comments stripped, reducing binary size while preserving runtime functionality
  • Chores

    • Updated build configuration and packaging scripts for macOS, Windows, and Docker environments
    • Expanded automated test coverage for PHAR generation and build artifact validation

Copilot AI review requested due to automatic review settings June 2, 2026 22:33
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@samdark, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 30 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d81f2cf9-b316-4002-be2c-59a6a73f97f8

📥 Commits

Reviewing files that changed from the base of the PR and between 6b5341d and 5a9f07d.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • benchmarks/src/BenchmarkDataGenerator.php
  • build/PharArchiveFilter.php
  • build/PhpDocStripper.php
  • build/package-macos.sh
  • build/package-phar.php
  • build/package-windows.ps1
  • composer.json
  • docker/Dockerfile
  • docs/binaries-phar-docker.md
  • tests/Unit/Benchmarks/BenchmarkFixtureTest.php
  • tests/Unit/Packaging/ConfigurationPackagingTest.php
📝 Walkthrough

Walkthrough

This PR introduces PHPDoc stripping during PHAR packaging to reduce binary artifact size. A new PhpDocStripper utility tokenizes PHP source and removes documentation comments, integrated into the PHAR build pipeline with archive filter refinements. The utility is distributed across all packaging targets (macOS, Windows, Docker), supported by new dependencies and comprehensive test coverage.

Changes

PHPDoc Stripping Feature

Layer / File(s) Summary
PHPDoc Stripper Utility Implementation
build/PhpDocStripper.php
New PhpDocStripper class with shouldStrip(string $path): bool (filters .php files, excludes vendor/cebe/markdown/) and strip(string $code): string (tokenizes PHP source, removes T_DOC_COMMENT tokens, concatenates remaining tokens).
Archive Filtering Refinements
build/PharArchiveFilter.php
shouldExclude() now excludes exact path config/.gitignore and excludes only vendor/composer/installed.json instead of all vendor/composer/ paths. File extension check expanded to exclude .hhi files alongside .md and .rst.
PHAR Packaging Integration
build/package-phar.php
Imports and includes PhpDocStripper. During PHAR file iteration, checks PhpDocStripper::shouldStrip($localPath): if true, reads file, strips PHPDoc via PhpDocStripper::strip(), adds stripped content via addFromString; otherwise uses existing addFile path.
Platform Build Distribution
build/package-macos.sh, build/package-windows.ps1, docker/Dockerfile
PhpDocStripper.php copied into macOS app build/ directory, Windows $appPath/build payload, and Docker phar-builder stage /app/build/ alongside existing packaging helper files.
Build Dependencies and Autoload
composer.json
Adds react/stream to require and evenement/evenement to require-dev. Expands autoload-dev with classmap for build/PharArchiveFilter.php and build/PhpDocStripper.php, and introduces PSR-4 mapping for YiiPress\\Benchmark\\ namespace to benchmarks/src.
Documentation
docs/binaries-phar-docker.md
Documents PHAR builder behavior: runtime-only input filtering, --no-dev dependency installation, PHPDoc stripping to reduce artifact size while preserving runtime reflection, and exclusion of non-runtime helpers and type stubs.
Comprehensive Test Coverage
tests/Unit/Benchmarks/BenchmarkFixtureTest.php, tests/Unit/Packaging/ConfigurationPackagingTest.php
New test testBenchmarkDataGeneratorIsDevAutoloaded verifies benchmark autoload config. New test pharBuilderStripsPhpDocFromPackagedPhpFiles validates PhpDocStripper behavior, Composer dev classmap, and stripping logic. New test platformPackageScriptsUseStrippedPharBuilderSupportFiles verifies Windows/macOS scripts reference stripper and invoke packaging with correct PHAR read-only settings. Updated pharBuilderCopiesOnlyRuntimeInputs to require PhpDocStripper.php copy. Updated pharBuilderExcludesVendorNonRuntimeFiles with additional exclusions including config/.gitignore and vendor/nikic/fast-route/FastRoute.hhi. Removed file-level require_once of PharArchiveFilter.php.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • yiipress/engine#36: Introduces macOS packaging script and build/CI wiring that directly overlaps with the PHPDoc stripper distribution to platform package targets.

Poem

🐰 Hops through packages, trimming the fat,
Doc comments vanish—PHAR grows lean and flat,
Reflection lives on, the runtime stays spry,
Smaller binaries soaring through the sky!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Slim packaged artifacts' directly aligns with the PR's primary objective of reducing packaged artifact sizes by stripping PHPDoc and omitting non-runtime files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/slim-packaged-artifacts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces packaged PHAR/static artifact size by stripping non-runtime PHPDoc from packaged PHP files (while preserving reflection-needed docs for cebe/markdown), excluding additional non-runtime vendor/runtime inputs, and moving benchmark fixture generation helpers to dev-only autoload with dependency cleanups.

Changes:

  • Add PhpDocStripper and integrate it into build/package-phar.php so packaged PHP sources have PHPDoc removed (except vendor/cebe/markdown).
  • Tighten packaging filters/scripts to omit additional non-runtime inputs (e.g. vendor/composer/installed.json, .hhi stubs, config/.gitignore) and ensure platform/Docker packaging scripts include the new support file.
  • Move benchmark dataset generator to autoload-dev and adjust Composer dependencies accordingly.

Reviewed changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Unit/Packaging/ConfigurationPackagingTest.php Adds assertions covering PHPDoc stripping behavior, packaging inputs, and Composer autoload expectations.
tests/Unit/Benchmarks/BenchmarkFixtureTest.php Verifies benchmark generator is dev-autoloaded (not part of runtime autoload).
docs/binaries-phar-docker.md Updates documentation to describe stripping and omitted non-runtime inputs.
docker/Dockerfile Ensures PhpDocStripper.php is copied into the PHAR build stage.
composer.lock Updates lockfile to reflect dependency graph changes.
composer.json Adds react/stream, adds evenement/evenement (dev), and configures autoload-dev classmap/PSR-4 for build + benchmark helpers.
build/PhpDocStripper.php Introduces PHPDoc stripping implementation.
build/PharArchiveFilter.php Expands exclusion rules to omit additional non-runtime packaged files.
build/package-windows.ps1 Copies PhpDocStripper.php into Windows packaging workspace.
build/package-phar.php Integrates PhpDocStripper into PHAR assembly process.
build/package-macos.sh Copies PhpDocStripper.php into macOS packaging workspace.
benchmarks/src/BenchmarkDataGenerator.php Adds benchmark fixture dataset generator (intended for dev/test usage).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread build/package-phar.php
@samdark
samdark force-pushed the chore/slim-packaged-artifacts branch from 6b5341d to e1a6bb4 Compare June 2, 2026 22:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
docs/binaries-phar-docker.md (1)

31-31: ⚡ Quick win

Consider breaking up the long sentence for readability.

Line 31 packs multiple concepts (build inputs, dependency installation, PHPDoc stripping rationale, and exclusions) into a single ~500-character sentence. While technically correct, splitting it into 3-4 shorter sentences would improve readability and make each concept easier to scan.

📝 Suggested refactor for clarity
-The PHAR builder copies only runtime inputs into the build stage: `config/`, `public/`, `src/`, `themes/`, `yii`, Composer metadata, and the PHAR build scripts. Dependencies are installed with `--no-dev` inside that stage before the PHAR is assembled. PHPDoc comments are stripped from packaged PHP files to keep the standalone PHAR and embedded static-binary PHAR smaller while preserving runtime comments, code, and dependency PHPDoc that is read through reflection at runtime. Benchmark fixture helpers, Composer's `installed.json`, VCS placeholders, and non-runtime type stubs are omitted because packaged commands do not need them.
+The PHAR builder copies only runtime inputs into the build stage: `config/`, `public/`, `src/`, `themes/`, `yii`, Composer metadata, and the PHAR build scripts. Dependencies are installed with `--no-dev` inside that stage before the PHAR is assembled.
+
+PHPDoc comments are stripped from packaged PHP files to reduce artifact size while preserving runtime comments, code, and dependency PHPDoc that is read through reflection at runtime. Benchmark fixture helpers, Composer's `installed.json`, VCS placeholders, and non-runtime type stubs are omitted because packaged commands do not need them.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/binaries-phar-docker.md` at line 31, Split the long sentence that starts
with "The PHAR builder copies only runtime inputs" into 3–4 shorter sentences:
one stating which inputs are copied (e.g., `config/`, `public/`, `src/`,
`themes/`, `yii`, Composer metadata, PHAR build scripts), a second describing
that dependencies are installed with `--no-dev` inside the build stage before
assembling the PHAR, a third explaining that PHPDoc comments are stripped to
reduce PHAR size while preserving runtime/reflection-read comments and
dependency PHPDoc, and a final short sentence listing omitted items (benchmark
fixtures, Composer's `installed.json`, VCS placeholders, non-runtime type
stubs). Keep wording concise and preserve technical details and rationale.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@docs/binaries-phar-docker.md`:
- Line 31: Split the long sentence that starts with "The PHAR builder copies
only runtime inputs" into 3–4 shorter sentences: one stating which inputs are
copied (e.g., `config/`, `public/`, `src/`, `themes/`, `yii`, Composer metadata,
PHAR build scripts), a second describing that dependencies are installed with
`--no-dev` inside the build stage before assembling the PHAR, a third explaining
that PHPDoc comments are stripped to reduce PHAR size while preserving
runtime/reflection-read comments and dependency PHPDoc, and a final short
sentence listing omitted items (benchmark fixtures, Composer's `installed.json`,
VCS placeholders, non-runtime type stubs). Keep wording concise and preserve
technical details and rationale.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a4f5b7fb-753b-4a1c-9c7e-bda58853625f

📥 Commits

Reviewing files that changed from the base of the PR and between 1dba693 and 6b5341d.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • benchmarks/src/BenchmarkDataGenerator.php
  • build/PharArchiveFilter.php
  • build/PhpDocStripper.php
  • build/package-macos.sh
  • build/package-phar.php
  • build/package-windows.ps1
  • composer.json
  • docker/Dockerfile
  • docs/binaries-phar-docker.md
  • tests/Unit/Benchmarks/BenchmarkFixtureTest.php
  • tests/Unit/Packaging/ConfigurationPackagingTest.php

@samdark

samdark commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

Addressed Copilot discussion r3344866244 in e1a6bb4: package-local paths are normalized to forward slashes before filtering, PHPDoc stripping, and PHAR entry creation. PharArchiveFilter and PhpDocStripper also normalize paths defensively, with Windows-style path coverage in packaging tests.

@samdark
samdark force-pushed the chore/slim-packaged-artifacts branch from e1a6bb4 to 5a9f07d Compare June 2, 2026 22:49
@samdark

samdark commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

Rebased on current master and resolved the composer.lock conflict in 5a9f07d. Also addressed the docs readability nit. Local verification passed: make test, git diff --check, make composer-dependency-analyser, make package-phar, and dist/phar/yiipress.phar --help smoke test. GitHub now reports the PR as mergeable; CI jobs are still pending.

@samdark
samdark merged commit 1e45fa6 into master Jun 2, 2026
7 checks passed
@samdark
samdark deleted the chore/slim-packaged-artifacts branch June 2, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants