Skip to content

Add .gitattributes to exclude dev files from Composer package #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2020
Merged

Add .gitattributes to exclude dev files from Composer package #13

merged 1 commit into from
Feb 20, 2020

Conversation

Krinkle
Copy link
Contributor

@Krinkle Krinkle commented Feb 15, 2020

This omits unnececary files from the deployed package. Especially when auditing packages for production deployment, or when versioning the vendor/ directory, this helps reduce noise.

This package is currently being considered for bundling with https://github.com/Wikipedia/mediawiki (vendor). The extraneous files from Net_URL2 stood out in a local build as most other packages seem to exclude these kinds of files.

@ktomk
Copy link
Contributor

ktomk commented Feb 20, 2020

@Krinkle Looks very fine on first glance.

By the type of change I get somewhat the impression that this is not only for this specific package. So could you add a bit of context to this PR why each directory has been chosen? Especially if this is about Net_URL2 only or is more in the general structure of Pear package projects?

@ktomk ktomk merged commit 457e5ef into pear:master Feb 20, 2020
@Krinkle Krinkle deleted the composer-ignore branch February 20, 2020 13:32
@Krinkle
Copy link
Contributor Author

Krinkle commented Mar 13, 2020

@ktomk Indeed, this is not specific to the Net_URL2 package, and not even specific to Pear projects.

Most dependencies that Wikipedia uses via Composer seem to make their exports relatively minimal and are at least loosely aware of how Packagist exports it from Git.

For Pear projects, I suspect this has not been taken to account simply because it isn't (historically) the main way these projects are distributed. So even if it was considered, it will have likely been expressed somewhere other than in .gitattributes.

This is the first Pear dependency that Wikipedia loads via Composer (we've previously loaded one or two by other means), and thus the first time I noticed it.

@ktomk
Copy link
Contributor

ktomk commented Mar 14, 2020

@Krinkle Thanks for your response on the topic. Based on your reply I've taken the opportunity to review the changes. I think they are fine for production code-only distribution especially in context of distributing via composer and prefer-dist with Github repositories.

Would you be so kind and could leave some feedback about how the overall experience is to make use of this library via composer? I ask because from what I remember when the package was ported over to Github some years ago and when adding composer support, IIRC it was needed to add the include-path setting in composer.json. This is normally not that well. But I also see there is classmap autoloading:

    "autoload": {
        "classmap": ["Net/URL2.php"]
    },
    "include-path": [
        "./"
    ],

So I'm interested if this has any implications for your use-case next to the export improvements already done.

@Krinkle
Copy link
Contributor Author

Krinkle commented May 3, 2020

As someone who uses Composer, the presence of include-path here stands out as "odd". I suppose maybe it is here to simplify migration for legacy apps that previously installed the package from from PECL (without a class loader). These users would presumably have placed statements like require_once "Net/URL2.php.php" anywhere in their code, and based on the PHP include_path it would eventually find this directory file and load the class file that way.

In the Composer landscape, I believe it is generally preferred not to rely on internal file paths or run-time directory scanning of this kind, in favour of mapping a namespace to a directory (PSR-4). Alternatively, you can also give it a list of files and directories and let it scan these are install-time and builds its own class-to-file map. The latter is what NET_URL2 currently uses.

This means that during installation, composer finds the URL2.php file, finds that it declares the NET_URL2 class and memorises this for itself (example).

For the majority of existing and for all new users, I would expect include-path therefor to be redundant. But it's up to you whether to continue to support that. If you want to remove it, all you'd have to do is remove include-path and then for end-users they would simply have to remove any stray require or include statements for NET/URL2 from their code. They would not have to put anything in its place, because they are already using Composer and that is already registering Net_URL2 with PHP's autoloader, which means they can reference the class directly in their code without any such require or include statement.

See https://getcomposer.org/doc/04-schema.md#autoload for more information.

Hope that helps!

ktomk added a commit to ktomk/Net_URL2 that referenced this pull request Mar 12, 2025
Resolves: https://pear.php.net/bugs/bug.php?id=29032 "Request #29032: Release with PHP 8.4 support (Sam Reed, 2025-03-07)"
Resolves: pear#20 "MSGH Pear Net_URL2 pear#20: URL2.php remove executable bit (Sam Reed, 2025-02-28)"
Resolves: pear#18 "MSGH Pear Net_URL2 pear#18: Restore Phpunit Tests (Tom Klingenberg, 2025-02-12)"
Resolves: pear#17 "MSGH Pear Net_URL2 pear#17: Fix _encodeData regexp (Andreas Kurth, 2025-02-09)"
Resolves: https://pear.php.net/bugs/bug.php?id=28662 "Request #28662: Minimum supported PHP version? (Sam Reed, 2024-11-25)"
Resolves: pear#15 "MSGH Pear Net_URL2 pear#15: Update CI to GitHub Actions (Sam Reed, 2024-11-25)"
Resolves: pear#14 "MSGH Pear Net_URL2 pear#14: URL2: Fix implicit null declaration (Sam Reed, 2024-11-25)"
Resolves: https://pear.php.net/bugs/bug.php?id=28649 "Bug #28649: PHP 8.4 compatybility bug" (Aleksander Machniak, 2024-08-30)
Resolves: pear#13 "MSGH Pear Net_URL2 pear#13: Add .gitattributes to exclude dev files from Composer package (Timo Tijhof, 2020-02-15)"
ktomk added a commit to ktomk/Net_URL2 that referenced this pull request Mar 12, 2025
Resolves: https://pear.php.net/bugs/bug.php?id=29032 "Request #29032: Release with PHP 8.4 support (Sam Reed, 2025-03-07)"
Resolves: pear#20 "MSGH Pear Net_URL2 pear#20: URL2.php remove executable bit (Sam Reed, 2025-02-28)"
Resolves: pear#18 "MSGH Pear Net_URL2 pear#18: Restore Phpunit Tests (Tom Klingenberg, 2025-02-12)"
Resolves: pear#17 "MSGH Pear Net_URL2 pear#17: Fix _encodeData regexp (Andreas Kurth, 2025-02-09)"
Resolves: https://pear.php.net/bugs/bug.php?id=28662 "Request #28662: Minimum supported PHP version? (Sam Reed, 2024-11-25)"
Resolves: pear#15 "MSGH Pear Net_URL2 pear#15: Update CI to GitHub Actions (Sam Reed, 2024-11-25)"
Resolves: pear#14 "MSGH Pear Net_URL2 pear#14: URL2: Fix implicit null declaration (Sam Reed, 2024-11-25)"
Resolves: https://pear.php.net/bugs/bug.php?id=28649 "Bug #28649: PHP 8.4 compatybility bug" (Aleksander Machniak, 2024-08-30)
Resolves: pear#13 "MSGH Pear Net_URL2 pear#13: Add .gitattributes to exclude dev files from Composer package (Timo Tijhof, 2020-02-15)"
ktomk added a commit to ktomk/Net_URL2 that referenced this pull request Mar 24, 2025
Resolves: https://pear.php.net/bugs/bug.php?id=29032 "Request #29032: Release with PHP 8.4 support (Sam Reed, 2025-03-07)"
Resolves: pear#20 "MSGH Pear Net_URL2 pear#20: URL2.php remove executable bit (Sam Reed, 2025-02-28)"
Resolves: pear#18 "MSGH Pear Net_URL2 pear#18: Restore Phpunit Tests (Tom Klingenberg, 2025-02-12)"
Resolves: pear#17 "MSGH Pear Net_URL2 pear#17: Fix _encodeData regexp (Andreas Kurth, 2025-02-09)"
Resolves: https://pear.php.net/bugs/bug.php?id=28662 "Request #28662: Minimum supported PHP version? (Sam Reed, 2024-11-25)"
Resolves: pear#15 "MSGH Pear Net_URL2 pear#15: Update CI to GitHub Actions (Sam Reed, 2024-11-25)"
Resolves: pear#14 "MSGH Pear Net_URL2 pear#14: URL2: Fix implicit null declaration (Sam Reed, 2024-11-25)"
Resolves: https://pear.php.net/bugs/bug.php?id=28649 "Bug #28649: PHP 8.4 compatybility bug" (Aleksander Machniak, 2024-08-30)
Resolves: pear#13 "MSGH Pear Net_URL2 pear#13: Add .gitattributes to exclude dev files from Composer package (Timo Tijhof, 2020-02-15)"
ktomk added a commit to ktomk/Net_URL2 that referenced this pull request Mar 24, 2025
Resolves: https://pear.php.net/bugs/bug.php?id=29032 "Request #29032: Release with PHP 8.4 support (Sam Reed, 2025-03-07)"
Resolves: pear#20 "MSGH Pear Net_URL2 pear#20: URL2.php remove executable bit (Sam Reed, 2025-02-28)"
Resolves: pear#18 "MSGH Pear Net_URL2 pear#18: Restore Phpunit Tests (Tom Klingenberg, 2025-02-12)"
Resolves: pear#17 "MSGH Pear Net_URL2 pear#17: Fix _encodeData regexp (Andreas Kurth, 2025-02-09)"
Resolves: https://pear.php.net/bugs/bug.php?id=28662 "Request #28662: Minimum supported PHP version? (Sam Reed, 2024-11-25)"
Resolves: pear#15 "MSGH Pear Net_URL2 pear#15: Update CI to GitHub Actions (Sam Reed, 2024-11-25)"
Resolves: pear#14 "MSGH Pear Net_URL2 pear#14: URL2: Fix implicit null declaration (Sam Reed, 2024-11-25)"
Resolves: https://pear.php.net/bugs/bug.php?id=28649 "Bug #28649: PHP 8.4 compatybility bug" (Aleksander Machniak, 2024-08-30)
Resolves: pear#13 "MSGH Pear Net_URL2 pear#13: Add .gitattributes to exclude dev files from Composer package (Timo Tijhof, 2020-02-15)"
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