fix: render a readme's relative links against its own branch - #8411
Merged
Merged
Conversation
`processReadme` turns a raw readme url into the page it is rendered at so
that relative links resolve, and it did that by inserting `blob/` in front
of the literal `master`:
.replace(/master/, "blob/master")
A repository on `main` therefore got no `blob/` at all, and every relative
link in its readme resolved to `github.com/<owner>/<repo>/main/<path>`,
which is not a url GitHub serves. Of the loader and plugin repositories
the site generates pages from, the nine sampled are all on `main` —
including `diagnostics-webpack-plugin`, whose readme links `CHANGELOG.md`
and `./LICENSE`.
The branch is read from the raw url now, whatever it is called, so the
rendered url is built rather than patched. A repository or owner whose
name contains `master` is no longer rewritten by accident either.
The suite pinned the old behaviour: "rewrite relative url" asserted the
`main` url without `blob/` as what it should be. It asserts the link that
resolves now, and a new case covers `master`, `main` and `next` together.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Loader and plugin pages are generated from each package's readme, and
processReadmeresolves the readme's relative links against the page it is rendered at. It built that page url by insertingblob/in front of the literalmaster:A repository on
mainmatches nothing, so noblob/is inserted and every relative link resolves tohttps://github.com/<owner>/<repo>/main/<path>— not a url GitHub serves. Same function, two branches:This is not an edge case: of the repositories the site generates pages from, the nine I sampled are all on
main—less-loader,sass-loader,postcss-loader,stylus-loader,terser-webpack-plugin,minimizer-webpack-plugin,diagnostics-webpack-plugin,babel-loader,svg-chunk-webpack-plugin. A[LICENSE](./LICENSE)link sits at the bottom of nearly every one of those readmes.I found it while checking that
diagnostics-webpack-plugin's page would render correctly after the rename — its readme linksCHANGELOG.mdand./LICENSE, and both came out broken.The branch is read from the raw url now, whatever it is called, so the rendered url is built rather than patched. As a side effect an owner or repository whose name contains
masteris no longer rewritten by accident.Tests
npx jest— 25 suites, 105 tests, all passing.Worth a look in review: the suite pinned the bug.
"rewrite relative url"asserted themainurl withoutblob/as the expected output, so the broken link was encoded as correct. That expectation now names the link that resolves, and a new case coversmaster,mainandnexttogether.lint:prosecould not run here —valeis not installed in this environment — but this diff touches nosrc/contentprose.lint:js,lint:prettier,lint:markdownandlint:spellingall pass.Use of AI
AI was used. It rendered the plugin readme through
processReadmewhile verifying the page after a rename, noticed the rewritten links were wrong, reduced it to themaster/mainpair above, sampled the repositories' default branches to see how far it reached, then wrote the fix and the test and corrected the expectation that had pinned it.🤖 Generated with Claude Code
https://claude.ai/code/session_01GzZci4NQeiqwdrVfd7dGXy
Generated by Claude Code