Skip to content
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

Append version to dist URL to force re-download #20

Merged
merged 3 commits into from
Sep 12, 2020

Conversation

mcaskill
Copy link
Contributor

@mcaskill mcaskill commented Sep 6, 2020

Checklist:

  • I've read the Contributing page.
  • I've created an issue and referenced it here.
  • My code is tested.
  • My code follows the WordPress code style.
  • My code has proper inline documentation.

Description

Currently, this Composer plugin reuses the same cache key regardless of the specified package version because the package's dist.url does not change between version bumps.

"version": "5.9.0",
"dist": {
    "type": "zip",
    "url": "https://www.advancedcustomfields.com"
}

Based on Composer's documentation for packages that do not support Composer (and this snippet from the source code) the dist.url is expected to reflect the version:

"version": "5.9.0",
"dist": {
    "type": "zip",
    "url": "https://github.com/AdvancedCustomFields/acf/archive/5.9.0.zip"
}

This means if you were to change the dist.url (any random URI) along with a version bump, you'd see that Composer would use a new cache key with that new version.

Since the real archive files for these premium WordPress plugins are hidden behind complex URLs, API response keys, and often expire, this Composer plugin needs to assign some kind of unique stand-in for the dist.url to serve as a unique cache key for each version.

How has this been tested?

I've tested this on a client project that uses Advanced Custom Fields Pro, Gravity Forms, and Polylang Pro.

Types of changes

This pull request introduces a change that when a download URL is resolved, the package's unique name (name + normlized version) is appended to the internal dist.url (as a hashed URI fragment) in order to generate a new cache key to trigger the download of the package update.

Similar to ffraenz/private-composer-installer.

Resolves #7, #18

mcaskill added a commit to mcaskill/composer-wp-pro-plugins that referenced this pull request Sep 7, 2020
This allows Composer to cache the updated version under a new hash.

Resolves junaidbhura#7, junaidbhura#18
Instead of appending the package's pretty version to the initial dist URL, we are appending a SHA1 hash of the package's unique name (`<name>-<version>`).

This will prevent duplicate cache keys between a plugin and its add-ons that may share the same version.

Removed:
- Variable `$package_version` since usage is limited to `switch` statement.
- Placeholder `%version%` since its an unused concept and confusing with usage of unique name instead of only the version.
@junaidbhura junaidbhura merged commit 4389421 into junaidbhura:master Sep 12, 2020
@mcaskill mcaskill deleted the bugfix/dist-url branch September 28, 2020 18:17
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.

ZIP archives in cache always use the same filename
2 participants