Repository navigation
Generate the Legacy Flags reference from source - #14720
Conversation
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
|
Preview deployment ✅ Deployment complete!
|
yanthomasdev
left a comment
There was a problem hiding this comment.
Good work! Added two suggestions regarding the behavior when no legacy flags are found in the core repo.
| * Options prefixed with `legacy.` are documented on that page instead of the configuration reference. | ||
| */ | ||
| const LEGACY_NAME = 'legacy'; | ||
| const LEGACY_PREFIX = `${LEGACY_NAME}.`; |
There was a problem hiding this comment.
Like you mentioned in the description, I think it's the best approach to add a small warning when no legacy flags are available. It's a small addition so I am going to make suggestions for the change.
| const LEGACY_PREFIX = `${LEGACY_NAME}.`; | |
| const LEGACY_PREFIX = `${LEGACY_NAME}.`; | |
| /** Displayed on the legacy flags page when no `legacy` options are documented. */ | |
| const NO_LEGACY_FLAGS = `Currently no legacy flags are available.\n`; |
| configResult = formatLinks(configResult, 'configuration-reference'); | ||
| legacyResult = formatLinks(legacyIntro + legacyResult, 'legacy-flags'); |
There was a problem hiding this comment.
And maybe we also want to error if no legacy intro is found at all?
| configResult = formatLinks(configResult, 'configuration-reference'); | |
| legacyResult = formatLinks(legacyIntro + legacyResult, 'legacy-flags'); | |
| // Without an intro, the source is likely missing the legacy flags docs entirely, | |
| // so it should fail instead of overwriting the page with an empty one. | |
| if (!legacyIntro) { | |
| throw new Error(`Missing @docs JSDoc comment with a description for @name ${LEGACY_NAME}`); | |
| } | |
| configResult = formatLinks(configResult, 'configuration-reference'); | |
| legacyResult = formatLinks(legacyIntro + (legacyResult || NO_LEGACY_FLAGS), 'legacy-flags'); |
There was a problem hiding this comment.
Yeah, I'm not sure what the best approach is, and I was hoping for some brainstorming. So, thanks for bringing that up!
I think throwing an error for the intro makes sense as a safety net!
But, we probably want "Currently no legacy flags are available." to also appear in the JSDoc directly for people accessing legacy in the editor? So, I'm torn regarding NO_LEGACY_FLAGS. My current approach was to add it to the JSDoc (and document that in AD²). Adding it here might cause it to appear twice. But, it's also something easy to miss when removing legacy flags...
The changes still go through the nightly CI PR, so maybe it's enough to catch something wrong?
There was a problem hiding this comment.
Thanks, @yanthomasdev! I tested a few things locally and I still think the Error is a nice addition. Pushed with e705c8a
I still think "Currently no legacy flags are available." should be in the JSDoc, and we might end with the same sentence twice with NO_LEGACY_FLAGS. So, maybe we should try this and see if it's possible that we're forgetting to update the JSDoc. What do you think?
Co-authored-by: Yan <[email protected]>
Co-authored-by: Yan <[email protected]> Co-authored-by: matthewp <[email protected]>
Description (required)
Extends the existing
docgen.mjsscript to automatically generate thelegacy-flags.mdxfile, in the same way as forconfiguration-reference.mdx. This generates both the page introduction (fromconfig.legacy) and the legacy flags using their respective JSDoc.I think it can be helpful for:
types/public/config.ts(except experimental flags...), and they don't have to wonder if this requires a docs update.I tested the docgen script locally, and this seems to work fine:
$ node ./scripts/docgen.mjs Fetch `src/types/public/config.ts` from withastro/astro#main: 0.004ms Parse types and generate configuration reference: 92.164ms Update configuration-reference.mdx: 0.224ms Update legacy-flags.mdx: 0.041msThe additional time seems reasonable. But, if anyone want to test by themselves; they'll need those changes: withastro/astro#18378
The possible caveat is: we don't have a fallback placeholder when there are no legacy flags. But, looking at when the last one was introduced, we always keep the
legacyobject. So, I think the easy fix is to putCurrently no legacy flags are available.to the JSDoc when this happens, instead of an inline comment.References