-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(cli): normalize the application of default option values #7220
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,9 @@ async function writePluginTranslationFiles({ | |
|
||
export async function writeTranslations( | ||
siteDir: string, | ||
options: WriteTranslationsOptions & ConfigOptions & {locale?: string}, | ||
options: Partial< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not fan of this kind of change 🤷♂️ I'd rather do the opposite and ensure all commands are never partial => handle edge cases and apply defaults at the edge of the system There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related: #4841 We should always assume the existence of those users that don't interact through the CLI. Even if it's technically not documented usage, I don't see why it makes the architecture any different if we apply defaults within There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, that seems reasonable What I don't like is to have long methods receiving partial options, where there's always a risk to end up using the partial option on which default was not properly applied Can we split the methods in 2, something like this? function doWriteTranslations(siteDir: string, options: Options) {
// actual code
}
export function writeTranslations(siteDir: string, options: Partial<Options>) {
return doWriteTranslations(siteDir, applyDefaults(options))
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, makes sense. |
||
WriteTranslationsOptions & ConfigOptions & {locale?: string} | ||
>, | ||
): Promise<void> { | ||
const context = await loadContext({ | ||
siteDir, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where are these default values being applied now?
isn't it convenient that the default value and the doc message mentioning it are co-located?
Why not doing the opposite instead: always apply all default values in this file, ensuring we don't have to handle partial options anywhere else in the system?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These have always been applied internally, before and after. These default values actually only serve the purpose of being confusing & overly defensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I understand this is the only place where
3000
is defined.Otherwise it's the default of the underlying lib, which as you can see, can change over time (vercel/serve#680)
I'd rather keep applying these defaults explicitly so that we don't depend on underlying deps changes.
Also we can use the default options in commander help messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh... you're sure? 😄
docusaurus/packages/docusaurus/src/commands/commandUtils.ts
Line 22 in 3b32a41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah 😅 didn't search in utils