Skip to content

Commit

Permalink
fix(cli): when the user enters the same command (#10474)
Browse files Browse the repository at this point in the history
  • Loading branch information
yucccc committed Oct 17, 2022
1 parent 7f45eb5 commit 2326f4a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/vite/src/node/cli.ts
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

0 comments on commit 2326f4a

Please sign in to comment.