From af5f4f7a98b7caebb115d3ab13fa583b88ecbf17 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 1 Feb 2021 13:23:48 +0530 Subject: [PATCH] chore(init): remove --force flag --- INIT.md | 6 -- .../src/utils/modify-config-helper.ts | 3 +- packages/generators/src/utils/scaffold.ts | 6 +- packages/init/README.md | 6 -- packages/init/src/index.ts | 7 +-- test/init/force/init-force.test.js | 60 ------------------- 6 files changed, 3 insertions(+), 85 deletions(-) delete mode 100644 test/init/force/init-force.test.js diff --git a/INIT.md b/INIT.md index fed6af945fd..94769b34572 100644 --- a/INIT.md +++ b/INIT.md @@ -81,12 +81,6 @@ webpack-cli init webpack-cli init --auto ``` -**To force config generation** - -```bash -webpack-cli init --force -``` - **To scaffold in a specified path** ```bash diff --git a/packages/generators/src/utils/modify-config-helper.ts b/packages/generators/src/utils/modify-config-helper.ts index 09f9d23f8b4..8dede3af614 100644 --- a/packages/generators/src/utils/modify-config-helper.ts +++ b/packages/generators/src/utils/modify-config-helper.ts @@ -39,7 +39,6 @@ export function modifyHelperUtil( configFile: string = DEFAULT_WEBPACK_CONFIG_FILENAME, packages?: string[], autoSetDefaults = false, - generateConfig = false, generationPath = '.', ): void { const configPath: string | null = null; @@ -135,7 +134,7 @@ export function modifyHelperUtil( ) as TransformConfig; // scaffold webpack config file from using .yo-rc.json - return runTransform(transformConfig, 'init', generateConfig, generationPath); + return runTransform(transformConfig, 'init', generationPath); } catch (error) { logger.error(error); process.exitCode = 2; diff --git a/packages/generators/src/utils/scaffold.ts b/packages/generators/src/utils/scaffold.ts index f7fed7cc34d..ec38c2278bd 100644 --- a/packages/generators/src/utils/scaffold.ts +++ b/packages/generators/src/utils/scaffold.ts @@ -39,13 +39,9 @@ function mapOptionsToTransform(config: Config): string[] { * and writes the file */ -export function runTransform(transformConfig: TransformConfig, action: string, generateConfig: boolean, generationPath: string): void { +export function runTransform(transformConfig: TransformConfig, action: string, generationPath: string): void { // webpackOptions.name sent to nameTransform if match const webpackConfig = Object.keys(transformConfig).filter((p: string): boolean => { - if (p == 'usingDefaults') { - return generateConfig; - } - return p !== 'configFile' && p !== 'configPath'; }); const initActionNotDefined = action && action !== 'init'; diff --git a/packages/init/README.md b/packages/init/README.md index fc6ea999a16..a1e392533cb 100644 --- a/packages/init/README.md +++ b/packages/init/README.md @@ -28,12 +28,6 @@ npx webpack-cli init npx webpack-cli init --auto ``` -**To force config generation** - -```bash -npx webpack-cli init --force -``` - **To scaffold in a specified path** ```bash diff --git a/packages/init/src/index.ts b/packages/init/src/index.ts index 077e673053c..e75210408ce 100644 --- a/packages/init/src/index.ts +++ b/packages/init/src/index.ts @@ -16,11 +16,6 @@ class InitCommand { type: Boolean, description: 'To generate default config', }, - { - name: 'force', - type: Boolean, - description: 'To force config generation', - }, { name: 'generation-path', type: String, @@ -34,7 +29,7 @@ class InitCommand { return; } - modifyHelperUtil(initGenerator, null, null, options.auto, options.force, options.generationPath); + modifyHelperUtil(initGenerator, null, null, options.auto, options.generationPath); }, ); } diff --git a/test/init/force/init-force.test.js b/test/init/force/init-force.test.js deleted file mode 100644 index bbcf9bdd36a..00000000000 --- a/test/init/force/init-force.test.js +++ /dev/null @@ -1,60 +0,0 @@ -'use strict'; - -const { green } = require('colorette'); -const fs = require('fs'); -const { join, resolve } = require('path'); -const rimraf = require('rimraf'); -const { runPromptWithAnswers } = require('../../utils/test-utils'); -const firstPrompt = 'Will your application have multiple bundles?'; - -const ENTER = '\x0D'; -const genPath = join(__dirname, 'test-assets'); - -const successLog = `You can now run ${green('yarn build')} to bundle your application!`; - -describe('init force flag', () => { - beforeAll(() => { - rimraf.sync(genPath); - fs.mkdirSync(genPath); - }); - - it('should scaffold webpack config', async () => { - const { stdout } = await runPromptWithAnswers( - genPath, - ['init', '--force'], - [`N${ENTER}`, ENTER, ENTER, ENTER, ENTER, ENTER, ENTER, ENTER], - ); - - expect(stdout).toBeTruthy(); - expect(stdout).toContain(firstPrompt); - - // Skip test in case installation fails - if (!fs.existsSync(resolve(genPath, './yarn.lock'))) { - return; - } - - // Test regressively files are scaffolded - const files = ['./package.json', './src/index.js', './webpack.config.js']; - - files.forEach((file) => { - expect(fs.existsSync(resolve(genPath, file))).toBeTruthy(); - }); - - const webpackConfig = require(join(genPath, 'webpack.config.js')); - - expect(webpackConfig.modules.rules).toEqual([]); - - // Check package json is correctly configured - const pkgJsonTests = () => { - const pkgJson = require(join(genPath, './package.json')); - expect(pkgJson).toBeTruthy(); - expect(pkgJson['devDependencies']).toBeTruthy(); - expect(pkgJson['devDependencies']['webpack']).toBeTruthy(); - expect(pkgJson['scripts']['build'] == 'webpack').toBeTruthy(); - }; - expect(pkgJsonTests).not.toThrow(); - - // Check we are not logging twice - expect(stdout.split(successLog).length - 1).toBe(1); - }); -});