From 952a1883b1a18c4fb38e8eb7bbbdb2aefc7942f4 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Sat, 26 Dec 2020 19:27:04 +0300 Subject: [PATCH] fix: the `--progress` option with the `serve` command (#2265) --- packages/serve/__tests__/mergeOptions.test.ts | 34 ------------------- packages/serve/src/index.ts | 2 +- packages/serve/src/mergeOptions.ts | 24 ------------- packages/serve/src/startDevServer.ts | 17 ++++++++-- test/serve/basic/serve-basic.test.js | 16 +++++++++ 5 files changed, 31 insertions(+), 62 deletions(-) delete mode 100644 packages/serve/__tests__/mergeOptions.test.ts delete mode 100644 packages/serve/src/mergeOptions.ts diff --git a/packages/serve/__tests__/mergeOptions.test.ts b/packages/serve/__tests__/mergeOptions.test.ts deleted file mode 100644 index 5b97dacfb87..00000000000 --- a/packages/serve/__tests__/mergeOptions.test.ts +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -import mergeOptions from '../src/mergeOptions'; -import { devServerClientLogging } from '../src/types'; - -describe('mergeOptions', () => { - it('merges CLI and devServer options correctly', () => { - const cliOptions = { - client: { - logging: devServerClientLogging.verbose, - }, - hot: true, - bonjour: true, - }; - const devServerOptions = { - client: { - host: 'localhost', - logging: devServerClientLogging.none, - }, - hot: false, - liveReload: false, - }; - // CLI should take priority - expect(mergeOptions(cliOptions, devServerOptions)).toEqual({ - client: { - host: 'localhost', - logging: 'verbose', - }, - hot: true, - bonjour: true, - liveReload: false, - }); - }); -}); diff --git a/packages/serve/src/index.ts b/packages/serve/src/index.ts index c8fe5dfc1dd..0987e357b90 100644 --- a/packages/serve/src/index.ts +++ b/packages/serve/src/index.ts @@ -51,7 +51,7 @@ class ServeCommand { const processors: Array<(opts: Record) => void> = []; for (const optionName in options) { - if (optionName === 'hot' || optionName === 'progress') { + if (optionName === 'hot') { devServerOptions[optionName] = options[optionName]; webpackOptions[optionName] = options[optionName]; } else { diff --git a/packages/serve/src/mergeOptions.ts b/packages/serve/src/mergeOptions.ts deleted file mode 100644 index 6022dc4ffb8..00000000000 --- a/packages/serve/src/mergeOptions.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { devServerOptionsType } from './types'; - -/** - * - * Merges CLI options and devServer options from config file - * - * @param {Object} cliOptions - devServer CLI args - * @param {Object} devServerOptions - devServer config options - * - * @returns {Object} merged options object - */ -export default function mergeOptions(cliOptions: devServerOptionsType, devServerOptions: devServerOptionsType): devServerOptionsType { - // CLI options should take precedence over devServer options, - // and CLI options should have no default values included - const options = { ...devServerOptions, ...cliOptions }; - - if (devServerOptions.client && cliOptions.client) { - // the user could set some client options in their devServer config, - // then also specify client options on the CLI - options.client = { ...devServerOptions.client, ...cliOptions.client }; - } - - return options; -} diff --git a/packages/serve/src/startDevServer.ts b/packages/serve/src/startDevServer.ts index 51ce17b9e45..08a9478cc76 100644 --- a/packages/serve/src/startDevServer.ts +++ b/packages/serve/src/startDevServer.ts @@ -1,6 +1,4 @@ -import { utils } from 'webpack-cli'; - -import mergeOptions from './mergeOptions'; +import { devServerOptionsType } from './types'; /** * @@ -48,6 +46,19 @@ export default async function startDevServer(compiler, cliOptions, logger): Prom const servers = []; const usedPorts: number[] = []; + const mergeOptions = (cliOptions: devServerOptionsType, devServerOptions: devServerOptionsType): devServerOptionsType => { + // CLI options should take precedence over devServer options, + // and CLI options should have no default values included + const options = { ...devServerOptions, ...cliOptions }; + + if (devServerOptions.client && cliOptions.client) { + // the user could set some client options in their devServer config, + // then also specify client options on the CLI + options.client = { ...devServerOptions.client, ...cliOptions.client }; + } + + return options; + }; for (const devServerOpts of devServerOptions) { const options = mergeOptions(cliOptions, devServerOpts); diff --git a/test/serve/basic/serve-basic.test.js b/test/serve/basic/serve-basic.test.js index 16549148b67..923dea3fff2 100644 --- a/test/serve/basic/serve-basic.test.js +++ b/test/serve/basic/serve-basic.test.js @@ -61,6 +61,22 @@ describe('basic serve usage', () => { expect(stdout).not.toContain('HotModuleReplacementPlugin'); }); + it('should work with the "--progress" option', async () => { + const { stderr, stdout } = await runServe(['--progress'], __dirname); + + expect(stderr).toContain('webpack.Progress'); + expect(stdout).toContain('main.js'); + expect(stdout).not.toContain('HotModuleReplacementPlugin'); + }); + + it('should work with the "--progress" option using the "profile" value', async () => { + const { stderr, stdout } = await runServe(['--progress', 'profile'], __dirname); + + expect(stderr).toContain('webpack.Progress'); + expect(stdout).toContain('main.js'); + expect(stdout).not.toContain('HotModuleReplacementPlugin'); + }); + it('should work with flags', async () => { const { stderr, stdout } = await runServe(['--hot'], __dirname);