-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix(cli): when the user enters the same command #10474
Conversation
This seems to be crossing the work for #10428. I think we should combine them similar to #10428 (comment). cc @btea |
packages/vite/src/node/cli.ts
Outdated
? normalizeOptionsConfig[key](value) | ||
: value[value.length - 1] | ||
} | ||
} |
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.
The logic here may be extracted and then applied to other options as well.
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.
OK, I'll try to modify it.
packages/vite/src/node/cli.ts
Outdated
@@ -28,6 +28,27 @@ interface GlobalCLIOptions { | |||
force?: boolean | |||
} | |||
|
|||
const normalizeOptionsConfig: Record<string, (v: any[]) => any> = { | |||
port: (v) => { | |||
return v.find((p) => typeof p === 'number' || typeof p === 'string') || 5173 |
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.
Maybe findLast
should be used here? Because if the other options are arrays, the last value you select.
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.
ok
I think the "use last duplicated value" logic in this PR is good, but code pattern wise I quite prefer #10428 😬 We need to normalize/sanitize the options for the related commands, and |
Now the logic has become pure, and no longer try to preset that the value of the last option does not meet the specification. Find the next valid value forward and don't know if it meets your expectations. |
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.
Description
When the user enters multiple identical options or incorrect option type, it can handle it correctly. fix: #10424
yarn vite --port --port="123" --host --host
Additional context
Fixed to: take the last array, and if you need to customize the output, you can correctly process the returned format.
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).