Compat: Refactor patch generation scripts
What's the problem this PR addresses?
I was planning to update the built-in TypeScript patch when I encountered some inconveniences working with the built-in patches:
- The patch generations scripts are not cross-platform
- The
typescriptscript uses POSIX paths, andgit diffgenerates patches with quoted Windows paths which the script can't work with - The other scripts are bash scripts
- The
- There is no clear way to use a local clone of
yarnpkg/TypeScriptfor generating patches - Other than the TypeScript patch, the built-in patches are not readily available (requires running a script to dump)
- The patches for each package are generated with different
git diffoptions, which may cause inconsistencies and the generated patch may be affected by the contributor's global git config. - The output of the scripts is not clear on what is happening
How did you fix it?
Reimplemented all 3 patch generation scripts in TypeScript, using @yarnpkg/core and @yarnpkg/fslib utilities to make them cross-platform.
The common parts of the generation procedure are extracted into a shared module, ensuring the patches are generated with the same options and ignoring the contributor's global git config as much as possible. Also, git diff is executed in a way that does not incorporate Windows paths into the patch.
This new patch generator includes documentation on usage and maintenance via JSDoc comments and the README.
In case someone wants to review how the patches are changed during this rewrite, the first 3 commits in this PR provides a step-by-step view:
- The existing patches are dumped into the filesystem to provide the "before" state in the git history
- The scripts are reimplemented in TypeScript, where minor issue with the patches are fixed
- The
fseventspatches have an extraenous/copy/in the source path - The patched
resolvesources are updated in #6694 but the patch was not - There is a patch for
typescriptthat applies to no versions of TypeScript - The differing
git diffoptions are preserved, to minimize the change to the patches in this commit
- The
git diffoptions are unified
Also made the CI process check for consistency of the patches when anything inside packages/plugin-compat/extra changes, not just when the bundled patches themselves change.
On the output, I tried to find a async task runner library to manage that. tasuku seemed promising at first but output that is not managed via it will be moved to above the task list, even after all tasks are complete. In the end, I created a very rudimentary logger for the scripts.
Checklist
- [x] I have read the Contributing Guide.
- [x] I have set the packages that need to be released for my changes to be effective.
- [x] I will check that all automated PR checks pass before the PR gets reviewed.