Adds a merge driver that can automatically re-number messages added to
`errors.json` if a merge conflict occurs. Now, it would be easier to
just run `pnpm update-error-codes`, but that's slow and requires
installing deps + building everything, so i'm just manually merging +
renumbering instead.
To avoid disrupting people's workflows (in case this is buggy, or
something), it's currently *not enabled by default*. To enable the merge
driver, run:
```shell
scripts/merge-errors-json/install
```
which will add it to your `.git/config`. Once it's been confirmed to
work well, we can make this command run by default in `postinstall`.
### Testing
Other than the test i added (which doesn't run git), i've tested this
manually with this script that rebases some stacked branches:
<details>
<summary>merge-driver-test.sh</summary>
```bash
#!/usr/bin/env bash
set -eu -o pipefail
cd "$1"
current_branch="$(git branch --show-current)"
(
set -eu -o pipefail
git switch lubieowoce/errors-json-merge-driver
git switch --force-create 'test/errors-json/base'
echo '{
"1": "base message"
}
' > packages/next/errors.json
git commit -am 'base commit'
git switch --force-create 'test/errors-json/one';
echo '{
"1": "base message",
"2": "message from branch one"
}
' > packages/next/errors.json
git commit -am 'commit 1'
git switch 'test/errors-json/base'
git switch --force-create 'test/errors-json/stacked-1'
echo '{
"1": "base message",
"2": "message from stacked 1"
}
' > packages/next/errors.json
git commit -am 'stacked 1'
git switch --force-create 'test/errors-json/stacked-2'
echo '{
"1": "base message",
"2": "message from stacked 1",
"3": "message from stacked 2"
}
' > packages/next/errors.json
git commit -am 'stacked 2'
git rebase 'test/errors-json/one' --update-refs || true
bat packages/next/errors.json
git rebase --abort || true
)
git switch "$current_branch"
```
</details>
The script does a bunch of git operations, so it's easiest to put it
outside of your next.js repo and call `bash merge-driver-test.sh
path/to/next.js`.