Skip to content

Exclude tests and development files from Composer dist via .gitattributes - #630

Merged
cviebrock merged 1 commit into
cviebrock:masterfrom
hosni:remove-tests-from-composer-package
Jul 20, 2026
Merged

Exclude tests and development files from Composer dist via .gitattributes#630
cviebrock merged 1 commit into
cviebrock:masterfrom
hosni:remove-tests-from-composer-package

Conversation

@hosni

@hosni hosni commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Add a .gitattributes file so development-only paths are marked with export-ignore. When users install via Composer’s default dist archives, they get a smaller package without the test suite and related tooling/config, while those files remain in the Git repository for development and CI.
Paths excluded from dist exports include:

  • tests/
  • .github/
  • tooling/config (e.g. phpunit.xml, phpstan.dist.neon, .php-cs-fixer.php)
  • contributor/docs that aren’t needed at runtime (CONTRIBUTING.md, TODO.md, etc.)
    This does not change runtime behaviour. Tests are unchanged and still available in the source repo / when installing with --prefer-source.
    No new behavioural tests or README updates are needed for this packaging-only change.

@hosni hosni changed the title Ignore development files and directories to export with composer package Exclude tests and development files from Composer dist via .gitattributes Jul 14, 2026
@cviebrock

Copy link
Copy Markdown
Owner

Thanks @hosni ... interesting!

Is this any different than defining those exclusions in composer.json with an archive.exclude entry?

@hosni

hosni commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

Yes, there is.
archive.exclude only affects archives created with composer archive, whereas export-ignore is honored by git archive, which GitHub uses to generate the source ZIPs that Composer typically downloads as dist packages. So for GitHub-hosted packages, .gitattributes is what actually reduces the size of the package users receive.

@cviebrock

Copy link
Copy Markdown
Owner

Nice. Great addition to the packages ... thanks @hosni !

@cviebrock
cviebrock merged commit 8d0455b into cviebrock:master Jul 20, 2026
6 checks passed
@cviebrock

Copy link
Copy Markdown
Owner

Version 13.0.1 includes this now, and I can confirm from the zip archive it works 😉 .

@hosni

hosni commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@cviebrock Thank you for your great package! 🫶

This is the difference between archive size of 13.0.0 and 13.0.1, exactly 300KB 😄
image

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