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

Rename patches.lock to patches.lock.json #492

Merged
merged 1 commit into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/api/patches-lock.md → docs/api/patches-lock-json.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: patches.lock
title: patches.lock.json
weight: 40
---

`patches.lock` is the mechanism that Composer Patches now uses to maintain a known-good list of patches to apply to the project. For external projects, the structure of `patches.lock` may also be treated as an API. If you're considering `patches.lock` as a data source for your project, there are a few things that you should keep in mind:
`patches.lock.json` is the mechanism that Composer Patches now uses to maintain a known-good list of patches to apply to the project. For external projects, the structure of `patches.lock.json` may also be treated as an API. If you're considering `patches.lock.json` as a data source for your project, there are a few things that you should keep in mind:

* `patches.lock` should be considered **read-only** for external uses.
* The general structure of `patches.lock` will not change. You can rely on a JSON file structured like so:
* `patches.lock.json` should be considered **read-only** for external uses.
* The general structure of `patches.lock.json` will not change. You can rely on a JSON file structured like so:
```json
{
"_hash": "[the hash]",
Expand Down
2 changes: 1 addition & 1 deletion docs/stork.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ files = [
{ path = "api/capabilities.md", url = "/api/capabilities/", title = "Capabilities" },
{ path = "api/events.md", url = "/api/events/", title = "Events" },
{ path = "api/overview.md", url = "/api/overview/", title = "Overview" },
{ path = "api/patches-lock.md", url = "/api/patches-lock/", title = "patches.lock" },
{ path = "api/patches-lock-json.md", url = "/api/patches-lock-json/", title = "patches.lock.json" },
{ path = "getting-started/installation.md", url = "/getting-started/installation/", title = "Installation" },
{ path = "getting-started/system-requirements.md", url = "/getting-started/system-requirements/", title = "System Requirements" },
{ path = "getting-started/terminology.md", url = "/getting-started/terminology/", title = "Terminology" },
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 50
## `composer patches-relock`
**Alias**: `composer prl`

`patches-relock` causes the plugin to re-discover all available patches and then write them to the `patches.lock` file for your project. This command should be used when changing the list of patches in your project. See the [recommended workflows]({{< relref "recommended-workflows.md" >}}) page for details.
`patches-relock` causes the plugin to re-discover all available patches and then write them to the `patches.lock.json` file for your project. This command should be used when changing the list of patches in your project. See the [recommended workflows]({{< relref "recommended-workflows.md" >}}) page for details.

---

Expand Down
10 changes: 5 additions & 5 deletions docs/usage/defining-patches.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Internally, the plugin uses the expanded format for _all_ patches. Similar to th
}
```

`sha256` can either be specified in your patch definition as above or the sha256 of a patch file will be calculated and written to your `patches.lock` file as part of installation.
`sha256` can either be specified in your patch definition as above or the sha256 of a patch file will be calculated and written to your `patches.lock.json` file as part of installation.

`depth` can be specified on a per-patch basis. If specified, this value overrides any other defaults. If not specified, the first available depth out of the following will be used:

Expand Down Expand Up @@ -106,7 +106,7 @@ As in previous versions of Composer Patches, you can store patch definitions in
}
}
```
This approach works for many teams, but you should consider moving your patch definitions to a separate `patches.json`. Doing so will mean that you don't have to update `composer.lock` every time you change a patch. Because patch data is locked in `patches.lock`, moving the data out of `composer.json` has little downside and can improve your workflow substantially.
This approach works for many teams, but you should consider moving your patch definitions to a separate `patches.json`. Doing so will mean that you don't have to update `composer.lock` every time you change a patch. Because patch data is locked in `patches.lock.json`, moving the data out of `composer.json` has little downside and can improve your workflow substantially.

### Patches file

Expand All @@ -120,8 +120,8 @@ If you're defining patches in `patches.json` (or some other separate patches fil
}
```

## `patches.lock`
## `patches.lock.json`

If `patches.lock` does not exist the first time you run `composer install` with this plugin enabled, one will be created for you. Generally, you shouldn't need to do anything with this file: commit it to your project repository alongside your `composer.json` and `composer.lock`, and commit any changes when you change your patch definitions.
If `patches.lock.json` does not exist the first time you run `composer install` with this plugin enabled, one will be created for you. Generally, you shouldn't need to do anything with this file: commit it to your project repository alongside your `composer.json` and `composer.lock`, and commit any changes when you change your patch definitions.

This file is similar to `composer.lock` in that it includes a `_hash` and the expanded definition for all patches in your project. When `patches.lock` exists, patches will be installed from the locked definitions in this file (_instead_ of using the definitions in `composer.json` or elsewhere).
This file is similar to `composer.lock` in that it includes a `_hash` and the expanded definition for all patches in your project. When `patches.lock.json` exists, patches will be installed from the locked definitions in this file (_instead_ of using the definitions in `composer.json` or elsewhere).
10 changes: 5 additions & 5 deletions docs/usage/recommended-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ weight: 40

## Initial setup

The plugin can safely be [installed]({{< relref "../getting-started/installation.md" >}}) as part of initial project setup, even if you don't have any patches to apply right away. A `patches.lock` will still be written, but it will be empty.
The plugin can safely be [installed]({{< relref "../getting-started/installation.md" >}}) as part of initial project setup, even if you don't have any patches to apply right away. A `patches.lock.json` will still be written, but it will be empty.

## Add a patch to your project

1. [Define a patch]({{< relref "defining-patches.md" >}}) in your `composer.json` or your external patches file (either will work by default, but choose the appropriate place based on how your project is configured).
2. Run [`composer patches-relock`]({{< relref "commands.md#composer-patches-relock" >}}) to regenerate `patches.lock` with your new patch.
2. Run [`composer patches-relock`]({{< relref "commands.md#composer-patches-relock" >}}) to regenerate `patches.lock.json` with your new patch.
3. Run [`composer patches-repatch`]({{< relref "commands.md#composer-patches-repatch" >}}) to delete patched dependencies and reinstall them with any defined patches {{< warning title="Running `composer patches-repatch` will delete data" >}}
Ensure that you don't have any unsaved changes in any patched dependencies in your project.
{{< /warning >}}
4. If your patch definition was added to `composer.json`, run `composer update --lock` to update the content hash in `composer.lock`.
5. Commit any related changes to your external patches file (if configured), `composer.json`, `composer.lock`, and `patches.lock`.
5. Commit any related changes to your external patches file (if configured), `composer.json`, `composer.lock`, and `patches.lock.json`.

## Apply patches added to the project by someone else

Expand All @@ -36,12 +36,12 @@ If you're installing the project from scratch:
## Remove a patch

1. Delete the patch definition from your `composer.json` or external patches file.
2. Run [`composer patches-relock`]({{< relref "commands.md#composer-patches-relock" >}}) to regenerate `patches.lock` with your new patch.
2. Run [`composer patches-relock`]({{< relref "commands.md#composer-patches-relock" >}}) to regenerate `patches.lock.json` with your new patch.
3. Manually delete the dependency that you removed a patch from (the location of the dependency will vary by project, but a good starting point is to look in the `vendor/` directory).
4. Run [`composer patches-repatch`]({{< relref "commands.md#composer-patches-repatch" >}}) to delete patched dependencies and reinstall them with any defined patches {{< warning title="Running `composer patches-repatch` will delete data" >}}
Ensure that you don't have any unsaved changes in any patched dependencies in your project.
{{< /warning >}}
5. If your patch definition was removed from `composer.json`, run `composer update --lock` to update the content hash in `composer.lock`.
6. Commit any related changes to your external patches file (if configured), `composer.json`, `composer.lock`, and `patches.lock`.
6. Commit any related changes to your external patches file (if configured), `composer.json`, `composer.lock`, and `patches.lock.json`.


4 changes: 2 additions & 2 deletions src/Command/RelockCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RelockCommand extends PatchesCommandBase
protected function configure(): void
{
$this->setName('patches-relock');
$this->setDescription('Find all patches defined in the project and re-write patches.lock.');
$this->setDescription('Find all patches defined in the project and re-write patches.lock.json.');
$this->setAliases(['prl']);
}

Expand All @@ -27,7 +27,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
unlink($plugin->getLockFile()->getPath());
}
$plugin->createNewPatchesLock();
$output->write(' - <info>patches.lock</info> has been recreated successfully.', true);
$output->write(' - <info>patches.lock.json</info> has been recreated successfully.', true);
return 0;
}
}
2 changes: 1 addition & 1 deletion src/Locker.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(JsonFile $lockFile)
}

/**
* Returns the sha256 hash of the sorted content of the patches.lock file.
* Returns the sha256 hash of the sorted content of the patches.lock.json file.
*
* @param PatchCollection $patchCollection
* The resolved patches for the project.
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function activate(Composer $composer, IOInterface $io): void
$this->patches = array();
$this->installedPatches = array();
$this->lockFile = new JsonFile(
dirname(realpath(\Composer\Factory::getComposerFile())) . '/patches.lock',
dirname(realpath(\Composer\Factory::getComposerFile())) . '/patches.lock.json',
null,
$this->io
);
Expand Down Expand Up @@ -203,7 +203,7 @@ public function loadLockedPatches()
{
$locked = $this->locker->isLocked();
if (!$locked) {
$this->io->write('<warning>patches.lock does not exist. Creating a new patches.lock.</warning>');
$this->io->write('<warning>patches.lock.json does not exist. Creating a new patches.lock.json.</warning>');
$this->createNewPatchesLock();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/_support/Helper/Acceptance.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function _afterSuite()
$composerLockFiles = glob($this->_getFixturesDir() . '/*/composer.lock');
$filesystem->remove($composerLockFiles);

$patchesLockFiles = glob($this->_getFixturesDir() . '/*/patches.lock');
$patchesLockFiles = glob($this->_getFixturesDir() . '/*/patches.lock.json');
$filesystem->remove($patchesLockFiles);

$composerVendorDirs = glob($this->_getFixturesDir() . '/*/vendor');
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/CommandsCept.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
$I->amInPath(codecept_data_dir('fixtures/commands'));
$I->runComposerCommand('install', ['-vvv']);

$I->openFile('patches.lock');
$I->openFile('patches.lock.json');
$I->seeInThisFile('725f2631cb6a92c8c3ffc2e396e89f73b726869131d4c4d2a5903aae6854a260');

$I->runShellCommand('composer patches-relock');
$I->openFile('patches.lock');
$I->openFile('patches.lock.json');
$I->seeInThisFile('725f2631cb6a92c8c3ffc2e396e89f73b726869131d4c4d2a5903aae6854a260');

$I->runShellCommand('composer patches-repatch 2>&1');
Expand Down