fix(metadata): preserve -- prefix in anchor IDs for CLI flags#758
fix(metadata): preserve -- prefix in anchor IDs for CLI flags#758sujalgoel wants to merge 2 commits intonodejs:mainfrom
Conversation
Two regexes in DOC_API_SLUGS_REPLACEMENTS were stripping -- from the start of slugs, turning --permission into permission and breaking existing links. Fixes nodejs#757
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryLow Risk Overview This updates the Reviewed by Cursor Bugbot for commit a15edca. Bugbot is set up for automated code reviews on this repo. Configure here. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #758 +/- ##
=======================================
Coverage 78.42% 78.43%
=======================================
Files 157 157
Lines 13959 13963 +4
Branches 1152 1152
=======================================
+ Hits 10948 10952 +4
Misses 3006 3006
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
avivkeller
left a comment
There was a problem hiding this comment.
Just make sure existing links aren't broken
| describe('cli flag anchor preservation', () => { | ||
| it('preserves -- prefix for CLI flags', () => { | ||
| assert.strictEqual(slug('--permission', identity), '--permission'); | ||
| }); | ||
|
|
||
| it('preserves -- prefix for multi-word CLI flags', () => { | ||
| assert.strictEqual(slug('--allow-fs-read', identity), '--allow-fs-read'); | ||
| }); | ||
| }); | ||
|
|
Should be fine. The docs never updated their links to match v25's output (the issue even calls this out), so |
|
On this preview page, the heading -C condition, --conditions=condition has the anchor You can use Link Checker to check links and anchors in Web pages or full Web sites. For example, with preview CLI:
|
| { from: /^-(?=[^-])/g, to: '' }, // Remove a single leading hyphen (preserves -- prefix for CLI flags) | ||
| { from: /(?<!^-*)-+$/g, to: '' }, // Remove any trailing hyphens | ||
| { from: /^(?!-+$).*?(--+)/g, to: '-' }, // Replace multiple hyphens | ||
| { from: /^(?!-+$)[^-].*?(--+)/g, to: '-' }, // Replace multiple consecutive hyphens (not at start) |
There was a problem hiding this comment.
This regex looks very odd, unless there is some magic going on, this is replacing all of [^-].*?(--+) with -?
Fixes #757.
In v25, CLI flag headings like
--permissionproduce anchor#permissioninstead of
#--permission, breaking links that worked in v24.Two regexes in
DOC_API_SLUGS_REPLACEMENTScaused this. The leadinghyphen rule (
^-+(?!-*$)) stripped all leading hyphens unconditionally.The consecutive hyphen rule (
^(?!-+$).*?(--+)) also fired on anythingstarting with
--.Changes in
constants.mjs:^-+(?!-*$)->^-(?=[^-]). Strips only a single-not followed by another, so--permissionpasses through.[^-]after the start anchor so the ruleskips
---prefixed slugs.Changes in
slugger.test.mjs:--fooexpectation from'foo'to'--foo'--permissionand--allow-fs-readTest plan
node --run testnode --run lintnode --run format