Simple, fast, isolated way to download+assimilate ZIP/TAR files

Overview

Composer Downloads Plugin

The "Downloads" plugin allows you to download extra files (*.zip or *.tar.gz) and extract them within your package.

This is an updated version of lastcall/composer-extra-files. It adds integration tests, fixes some bugs, and makes a few other improvements. Some of the configuration options have changed, so it has been renamed to prevent it from conflicting in real-world usage.

Example

Suppose you publish a PHP package foo/bar which relies on an external artifact examplelib-0.1.zip. Place this configuration in the composer.json for foo/bar:

{
  "name": "foo/bar",
  "require": {
    "civicrm/composer-downloads-plugin": "~2.1"
  },
  "extra": {
    "downloads": {
      "examplelib": {
        "url": "https://example.com/examplelib-0.1.zip",
        "path": "extern/examplelib",
        "ignore": ["test", "doc", ".*"]
      }
    }
  }
}

When a downstream user of foo/bar runs composer install, it will fetch and extract the zip file, creating vendor/foo/bar/extern/examplelib.

Evaluation

The primary strengths of composer-downloads-plugin are:

  • Simple: It downloads a URL (ZIP/TAR file) and extracts it. It only needs to know two things: what to download (url) and where to put it (path). It runs as pure-PHP without any external dependencies.
  • Fast: The logic does not require scanning, indexing, or mapping any large registries. The download system uses composer's built-in cache.
  • Isolated: As the author of a package foo/bar, you define the content under the vendor/foo/bar folder. When others use foo/bar, there is no need for special instructions, no root-level configuration, no interaction with other packages.

The "Downloads" plugin is only a download mechanism. Use it to assimilate an external resource as part of a composer package.

The "Downloads" plugin is not a dependency management system. There is no logic to scan registries, resolve transitive dependencies, identify version-conflicts, etc among diverse external resources. If you need that functionality, then you may want a bridge to integrate composer with an external dependency management tool. A few good bridges to consider:

Configuration: Properties

The extra.downloads section contains a list of files to download. Each extra-file has a symbolic ID (e.g. examplelib above) and some mix of properties:

  • url: The URL to fetch the content from.

  • path: The releative path where content will be extracted.

  • type: (Optional) Determines how the download is handled

    • archive: The url references a zip or tarball which should be extracted at the given path. (Default for URLs involving *.zip, *.tar.gz, or *.tgz.)
    • file: The url should be downloaded to the given path. (Default for all other URLs.)
    • phar: The url references a PHP executable which should be installed at the given path.
  • ignore: (Optional) A list of a files that should be omited from the extracted folder. (This supports a subset of .gitignore notation.)

  • version: (Optional) A version number for the downloaded artifact. This has no functional impact on the lifecycle of the artifact, but it can affect the console output, and it can be optionally used as a variable when setting url or path.

Values in url and path support the following variables:

  • {$id}: The symbolic identifier of the download. (In the introductory example, it would be examplelib.)
  • {$version}: The displayed/simulated/pretty version number of the package.

Configuration: Defaults

You may set default properties for all downloads. Place them under *, as in:

{
  "extra": {
    "downloads": {
      "*": {
        "path": "bower_components/{$id}",
        "ignore": ["test", "tests", "doc", "docs"]
      },
      "jquery": {
        "url": "https://github.com/jquery/jquery-dist/archive/1.12.4.zip"
      },
      "jquery-ui": {
        "url": "https://github.com/components/jqueryui/archive/1.12.1.zip"
      }
    }
  }
}

This example will:

  • Create bower_components/jquery (based on jQuery 1.12.4), minus any test/doc folders.
  • Create bower_components/jquery-ui (based on jQueryUI 1.12.1), minus any test/doc folders.

Tips

  • In each downloaded folder, this plugin will create a small metadata folder (.composer-downloads) to track the origin of the current code. If you modify the composer.json to use a different URL, then it will re-download the file.

  • Download each extra file to a distinct path. Don't try to download into overlapping paths. (This has not been tested, but I expect downloads are not well-ordered, and you may find that updates require re-downloading.)

  • What should you do if you normally download the extra-file as *.tar.gz but sometimes (for local dev) need to grab bleeding edge content from somewhere else? Simply delete the autodownloaded folder and replace it with your own. composer-downloads-plugin will detect that conflict (by virtue of the absent .composer-downloads) and leave your code in place (until you choose to get rid of it). To switch back, you can simply delete the code and run composer install again.

Known Limitations

If you use downloads in a root-project (or in symlinked dev repo), it will create+update downloads, but it will not remove orphaned items automatically. This could be addressed by doing a file-scan for .composer-downloads (and deleting any orphan folders). Since the edge-case is not particularly common right now, and since a file-scan could be time-consuming, it might make sense as a separate subcommand.

I believe the limitation does not affect downstream consumers of a dependency. In that case, the regular composer install/update/removal mechanics should take care of any nested downloads.

Automated Tests

The tests/ folder includes unit-tests and integration-tests written with PHPUnit. Each integration-test generates a new folder/project with a plausible, representative composer.json file and executes composer install. It checks the output has the expected files.

To run the tests, you will need composer and phpunit in the PATH.

[~/src/composer-downloads-plugin] which composer
/Users/myuser/bin/composer

[~/src/composer-downloads-plugin] which phpunit
/Users/myuser/bin/phpunit

[~/src/composer-downloads-plugin] phpunit
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.

.....                                                               5 / 5 (100%)

Time: 40.35 seconds, Memory: 10.00MB

OK (5 tests, 7 assertions)

The integration tests can be a bit large/slow. To monitor the tests more closesly, set the DEBUG variable, as in:

[~/src/composer-downloads-plugin] env DEBUG=2 phpunit

Local Dev Harness

What if you want to produce an environment which uses the current plugin code - one where you can quickly re-run composer commands while iterating on code?

You may use any of the integration-tests to initialize a baseline environment:

env USE_TEST_PROJECT=$HOME/src/myprj DEBUG=2 phpunit tests/SniffTest.php
You might also like...
How to use indirect download file with multi-server on PHP

indirect-download-with-multi-server how to use indirect download file with multi-server on PHP Server 1 (main) Create A folder in Server 1 (folder nam

Download this Plugin and you will have Hive MC server in your own!

Your-Own-Hive Version: v1.9.0 Murder Mystery Update Next Update: Survival Games This Plugin has all the essentials with HiveMC! Updates Every Day! Pla

Columnar analytics for PHP - a pure PHP library to read and write simple columnar files in a performant way.

Columnar Analytics (in pure PHP) On GitHub: https://github.com/envoymediagroup/columna About the project What does it do? This library allows you to w

This Kirby V3 Plugin brings snippets and blueprints together in one place. It includes useful tools that completely changing the way you work with Kirby: Fast and well organized.
This Kirby V3 Plugin brings snippets and blueprints together in one place. It includes useful tools that completely changing the way you work with Kirby: Fast and well organized.

Kirby Components Overview Do you love to make awesome projects with Kirby CMS? Do you also find it difficult to switch between snippets and blueprints

MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query and get result in a fastest way
MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query and get result in a fastest way

Mysql Optimizer mysql optimizer also known as MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query

⚡️Lightning-fast linter for .env files. Written in Rust 🦀

⚡️ Lightning-fast linter for .env files. Written in Rust 🦀 Dotenv-linter can check / fix / compare .env files for problems that may cause the applica

Perch Dashboard app for exporting content to (Kirby) text files and Kirby Blueprint files
Perch Dashboard app for exporting content to (Kirby) text files and Kirby Blueprint files

toKirby Perch Dashboard app for exporting content to (Kirby) text files and Kirby Blueprint files. You can easily install and test it in a few steps.

An online system to keep digitized form of employee personal files (staff personal files)

An online system to keep digitized form of employee personal files (staff personal files).

Comments
  • Support Composer 2

    Support Composer 2

      Problem 1
        - civicrm/civicrm-core[5.29.0, ..., 5.31.x-dev] require civicrm/composer-downloads-plugin ^2.0 -> satisfiable by civicrm/composer-downloads-plugin[v2.0.0, v2.1.0, v2.1.1].
        - civicrm/composer-downloads-plugin[v2.0.0, ..., v2.1.1] require composer-plugin-api ^1.1 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
        - Root composer.json requires civicrm/civicrm-core ~5.29 -> satisfiable by civicrm/civicrm-core[5.29.0, ..., 5.31.x-dev].
    
    opened by mglaman 7
Releases(v3.0.0)
Owner
CiviCRM
CiviCRM
Tool for easy selection and export of user files in ZIP format.

Personal data export Idea Tool for easy selection and export of user files in ZIP format. Within a single selector, you choose all user data (much of

Baraja packages 2 Oct 18, 2021
Free ZIP Code API - Free Access to Worldwide Postal Code Data

About Zipcodebase - Free Zip Code API Zipcodebase is a zip code API that was founded in 2019 to solve common issues with postal code data. As we have

SaaS Industries 2 Nov 26, 2022
List of France cities with zip codes, department codes, region codes, districts for former cities, GPS latitude longitude coordinates, and INSEE reference code.

List of France cities with zip codes, department codes, region codes, districts for former cities, GPS latitude longitude coordinates, and INSEE reference code.

Coercive 4 May 25, 2022
Small class to extract + compress .zip, .gz, .rar archives via browser.

The Unzipper The Unzipper extracts .zip and .rar archives or .gz/tar.gz files on webservers. It detects .zip/.rar/.tar.gz/.gz archives and let you cho

Lục Thiên Phong 10 Dec 24, 2022
Download TikTok videos for free. No login or password are required.

Download TikTok videos for free. No login or password are required.

Ibnu syawal 19 Oct 31, 2022
All in one Video Downloader - Download videos from facebook twitter youtube tiktok and 1000+ other sites .. made by Vijay Kumar

VKRdownloader Video Downloader by @TherealVKR Vijay Kumar .... Download Video From YouTube , Facebook , Twitter , Instagram , TikTok , And 1000+ Other

Vijay Kumar 35 Dec 29, 2022
a Telegram bot to fetch download link from pan.baidu.com

baiduwp-bot a Telegram bot to fetch download link from pan.baidu.com What it can do Get a file download link from share link. 从分享链接获取下载地址 How to use G

Yuan_Tuo 23 Dec 3, 2022
A hacky PHP script to download posts, images, videos and framework grading from Parent Zone

ParentZoneDownloader A hacky PHP script to download posts, images, videos and framework grading from Parent Zone Pre-Requisites Tested on PHP 7.4, but

null 2 Sep 6, 2021
Library download currency rate and save in database, It's designed to be extended by any available data source.

Library download currency rate and save in database, It's designed to be extended by any available data source.

Flexmind. Krzysztof Bielecki 2 Oct 6, 2021