Skip to content
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

Merged
merged 6 commits into from
Oct 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/vite/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ interface GlobalCLIOptions {
force?: boolean
}

const filterDuplicateOptions = <T extends object>(options: T) => {
for (const [key, value] of Object.entries(options)) {
if (Array.isArray(value)) {
options[key as keyof T] = value[value.length - 1]
}
}
}
/**
* removing global flags before passing as command specific sub-configs
*/
Expand Down Expand Up @@ -76,6 +83,7 @@ cli
`[boolean] force the optimizer to ignore the cache and re-bundle`
)
.action(async (root: string, options: ServerOptions & GlobalCLIOptions) => {
filterDuplicateOptions(options)
// output structure is preserved even after bundling so require()
// is ok here
const { createServer } = await import('./server')
Expand Down Expand Up @@ -164,6 +172,7 @@ cli
)
.option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
.action(async (root: string, options: BuildOptions & GlobalCLIOptions) => {
filterDuplicateOptions(options)
const { build } = await import('./build')
const buildOptions: BuildOptions = cleanOptions(options)

Expand Down Expand Up @@ -196,6 +205,7 @@ cli
)
.action(
async (root: string, options: { force?: boolean } & GlobalCLIOptions) => {
filterDuplicateOptions(options)
const { optimizeDeps } = await import('./optimizer')
try {
const config = await resolveConfig(
Expand Down Expand Up @@ -237,6 +247,7 @@ cli
strictPort?: boolean
} & GlobalCLIOptions
) => {
filterDuplicateOptions(options)
const { preview } = await import('./preview')
try {
const server = await preview({
Expand Down