diff --git a/packages/webpack-cli/__tests__/arg-parser.test.js b/packages/webpack-cli/__tests__/arg-parser.test.js index dca85eb4031..a2712c7edf4 100644 --- a/packages/webpack-cli/__tests__/arg-parser.test.js +++ b/packages/webpack-cli/__tests__/arg-parser.test.js @@ -368,7 +368,7 @@ describe('arg-parser', () => { expect(res.unknownArgs.length).toEqual(0); expect(res.opts.entry).toEqual(['test.js']); expect(res.opts.hot).toBeTruthy(); - expect(res.opts.output).toEqual('./dist/'); + expect(res.opts.outputPath).toEqual('./dist/'); expect(res.opts.stats).toEqual(true); expect(warnMock.mock.calls.length).toEqual(0); }); diff --git a/packages/webpack-cli/__tests__/resolveOutput.test.js b/packages/webpack-cli/__tests__/resolveOutput.test.js index 1031f8d7e8f..3522d5b1068 100644 --- a/packages/webpack-cli/__tests__/resolveOutput.test.js +++ b/packages/webpack-cli/__tests__/resolveOutput.test.js @@ -1,10 +1,11 @@ +const { resolve } = require('path'); const resolveOutput = require('../lib/groups/resolveOutput'); describe('OutputGroup', function () { it('should handle the output option', () => { const result = resolveOutput({ - output: './bundle.js', + outputPath: './bundle', }); - expect(result.options.output.filename).toEqual('bundle.js'); + expect(result.options.output.path).toEqual(resolve('bundle')); }); }); diff --git a/packages/webpack-cli/lib/groups/resolveOutput.js b/packages/webpack-cli/lib/groups/resolveOutput.js index c8fd64aaf35..b658a9e8a55 100644 --- a/packages/webpack-cli/lib/groups/resolveOutput.js +++ b/packages/webpack-cli/lib/groups/resolveOutput.js @@ -5,15 +5,13 @@ const path = require('path'); * @param {args} args - Parsed arguments passed to the CLI */ const resolveOutput = (args) => { - const { output } = args; + const { outputPath } = args; const finalOptions = { options: { output: {} }, outputOptions: {}, }; - if (output) { - const { dir, base, ext } = path.parse(output); - finalOptions.options.output.path = ext.length === 0 ? path.resolve(dir, base) : path.resolve(dir); - if (ext.length > 0) finalOptions.options.output.filename = base; + if (outputPath) { + finalOptions.options.output.path = path.resolve(outputPath); } return finalOptions; }; diff --git a/packages/webpack-cli/lib/utils/cli-flags.js b/packages/webpack-cli/lib/utils/cli-flags.js index 2a274b08b88..fbdfc993534 100644 --- a/packages/webpack-cli/lib/utils/cli-flags.js +++ b/packages/webpack-cli/lib/utils/cli-flags.js @@ -117,8 +117,8 @@ const core = [ description: 'Outputs list of supported flags', }, { - name: 'output', - usage: '--output ', + name: 'output-path', + usage: '--output-path ', alias: 'o', type: String, description: 'Output location of the file generated by webpack e.g. ./dist/', diff --git a/test/config/basic/basic-config.test.js b/test/config/basic/basic-config.test.js index 01feb8afb94..a2d876db072 100644 --- a/test/config/basic/basic-config.test.js +++ b/test/config/basic/basic-config.test.js @@ -1,21 +1,13 @@ 'use strict'; -const { stat } = require('fs'); +const { existsSync } = require('fs'); const { resolve } = require('path'); const { run } = require('../../utils/test-utils'); describe('basic config file', () => { - it('is able to understand and parse a very basic configuration file', (done) => { - const { stdout, stderr } = run( - __dirname, - ['-c', resolve(__dirname, 'webpack.config.js'), '--output', './binary/a.bundle.js'], - false, - ); + it('is able to understand and parse a very basic configuration file', () => { + const { stdout, stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'], false); expect(stderr).toBeFalsy(); - expect(stdout).not.toBe(undefined); - stat(resolve(__dirname, './binary/a.bundle.js'), (err, stats) => { - expect(err).toBe(null); - expect(stats.isFile()).toBe(true); - done(); - }); + expect(stdout).toBeTruthy(); + expect(existsSync(resolve(__dirname, './binary/a.bundle.js'))).toBeTruthy(); }); }); diff --git a/test/defaults/output-defaults.test.js b/test/defaults/output-defaults.test.js index 11079b0f90e..18cd26d8e17 100644 --- a/test/defaults/output-defaults.test.js +++ b/test/defaults/output-defaults.test.js @@ -5,7 +5,7 @@ const { run } = require('../utils/test-utils'); describe('output flag defaults', () => { it('should create default file for a given directory', (done) => { - const { stdout } = run(__dirname, ['--entry', './a.js', '--output', './binary'], false); + const { stdout } = run(__dirname, ['--entry', './a.js', '--output-path', './binary'], false); // Should not print warning about config fallback, as we have production as default expect(stdout).not.toContain('option has not been set, webpack will fallback to'); stat(resolve(__dirname, './binary/main.js'), (err, stats) => { @@ -26,7 +26,7 @@ describe('output flag defaults', () => { }); it('throw error on empty output flag', () => { - const { stderr } = run(__dirname, ['--entry', './a.js', '--output'], false); - expect(stderr).toContain("error: option '-o, --output ' argument missing"); + const { stderr } = run(__dirname, ['--entry', './a.js', '--output-path'], false); + expect(stderr).toContain("error: option '-o, --output-path ' argument missing"); }); }); diff --git a/test/devtool/array/source-map-array.test.js b/test/devtool/array/source-map-array.test.js index 9bedc1e4e8a..3672c8eaba7 100644 --- a/test/devtool/array/source-map-array.test.js +++ b/test/devtool/array/source-map-array.test.js @@ -14,7 +14,7 @@ describe('source-map object', () => { }); }); it('should override entire array on flag', (done) => { - const { stderr } = run(__dirname, ['--devtool', 'source-map', '--output', './binary'], false); + const { stderr } = run(__dirname, ['--devtool', 'source-map', '--output-path', './binary'], false); expect(stderr).toBe(''); readdir(resolve(__dirname, 'binary'), (err, files) => { expect(err).toBe(null); diff --git a/test/devtool/object/source-map-object.test.js b/test/devtool/object/source-map-object.test.js index c537cbd65e1..9418f2eaa2e 100644 --- a/test/devtool/object/source-map-object.test.js +++ b/test/devtool/object/source-map-object.test.js @@ -24,7 +24,7 @@ describe('source-map object', () => { }); it('should override config with source-map', (done) => { - run(__dirname, ['-c', './webpack.eval.config.js', '--devtool', 'source-map', '-o', './binary/dist-amd.js'], false); + run(__dirname, ['-c', './webpack.eval.config.js', '--devtool', 'source-map', '-o', './binary'], false); stat(resolve(__dirname, 'binary/dist-amd.js.map'), (err, stats) => { expect(err).toBe(null); expect(stats.isFile()).toBe(true); diff --git a/test/entry/defaults-index/entry-multi-args.test.js b/test/entry/defaults-index/entry-multi-args.test.js index 270e0f8a94d..6ce53ebc2eb 100644 --- a/test/entry/defaults-index/entry-multi-args.test.js +++ b/test/entry/defaults-index/entry-multi-args.test.js @@ -18,7 +18,7 @@ describe('single entry flag index present', () => { }); it('finds default index file, compiles and overrides with flags successfully', (done) => { - const { stderr } = run(__dirname, ['--output', 'bin/main.js']); + const { stderr } = run(__dirname, ['--output-path', 'bin']); expect(stderr).toBeFalsy(); stat(resolve(__dirname, './bin/main.js'), (err, stats) => { diff --git a/test/node/node.test.js b/test/node/node.test.js index 63114299a8e..d922b3fb61b 100644 --- a/test/node/node.test.js +++ b/test/node/node.test.js @@ -8,7 +8,7 @@ const { run } = require('../utils/test-utils'); // throws different error from what we manually see describe('node flags', () => { it('is able to pass the options flags to node js', async (done) => { - const { stdout, stderr } = await run(__dirname, ['--output', './bin/[name].bundle.js'], false, [ + const { stdout, stderr } = await run(__dirname, ['--output-path', './bin'], false, [ `--require=${resolve(__dirname, 'bootstrap.js')}`, `--require=${resolve(__dirname, 'bootstrap2.js')}`, ]); diff --git a/test/node/webpack.config.js b/test/node/webpack.config.js index b58f8a91f0d..4913dff71b6 100644 --- a/test/node/webpack.config.js +++ b/test/node/webpack.config.js @@ -4,6 +4,6 @@ module.exports = { entry: './a.js', output: { path: resolve(__dirname, 'binary'), - filename: 'a.bundle.js', + filename: '[name].bundle.js', }, }; diff --git a/test/output/named-bundles/output-named-bundles.test.js b/test/output/named-bundles/output-named-bundles.test.js index 612fb8ae105..ecd7970531f 100644 --- a/test/output/named-bundles/output-named-bundles.test.js +++ b/test/output/named-bundles/output-named-bundles.test.js @@ -5,7 +5,7 @@ const { run } = require('../../utils/test-utils'); describe('output flag named bundles', () => { it('should output file given as flag instead of in configuration', () => { - const { stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output', './binary/a.bundle.js'], false); + const { stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'], false); expect(stderr).toBeFalsy(); const stats = statSync(resolve(__dirname, './binary/a.bundle.js')); @@ -13,7 +13,7 @@ describe('output flag named bundles', () => { }); it('should resolve the path to binary/a.bundle.js as ./binary/a.bundle.js', () => { - const { stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output', 'binary/a.bundle.js'], false); + const { stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', 'binary'], false); expect(stderr).toBeFalsy(); const stats = statSync(resolve(__dirname, './binary/a.bundle.js')); @@ -21,11 +21,7 @@ describe('output flag named bundles', () => { }); it('should create multiple bundles with an overriding flag', () => { - const { stderr } = run( - __dirname, - ['-c', resolve(__dirname, 'webpack.single.config.js'), '--output', './bin/[name].bundle.js'], - false, - ); + const { stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.single.config.js'), '--output-path', './bin'], false); expect(stderr).toBeFalsy(); let stats = statSync(resolve(__dirname, './bin/b.bundle.js')); @@ -45,8 +41,8 @@ describe('output flag named bundles', () => { }); it('should output file in bin directory using default webpack config with warning for empty output value', () => { - const { stdout, stderr, exitCode } = run(__dirname, ['--output'], false); - expect(stderr).toEqual("error: option '-o, --output ' argument missing"); + const { stdout, stderr, exitCode } = run(__dirname, ['--output-path'], false); + expect(stderr).toEqual("error: option '-o, --output-path ' argument missing"); expect(exitCode).toEqual(1); expect(stdout).toBeFalsy(); }); diff --git a/test/output/named-bundles/webpack.config.js b/test/output/named-bundles/webpack.config.js index 0029ad8473f..e6d61551f48 100644 --- a/test/output/named-bundles/webpack.config.js +++ b/test/output/named-bundles/webpack.config.js @@ -4,6 +4,6 @@ module.exports = { entry: './a.js', output: { path: resolve(__dirname, 'bin'), - filename: 'bundle.js', + filename: 'a.bundle.js', }, }; diff --git a/test/output/named-bundles/webpack.single.config.js b/test/output/named-bundles/webpack.single.config.js index 112d94387a1..32f35d14cd0 100644 --- a/test/output/named-bundles/webpack.single.config.js +++ b/test/output/named-bundles/webpack.single.config.js @@ -7,6 +7,6 @@ module.exports = { }, output: { path: resolve(__dirname, 'bin'), - filename: 'bundle.js', + filename: '[name].bundle.js', }, }; diff --git a/test/utils/test-utils.js b/test/utils/test-utils.js index 87ae5ecffb8..4cd27900e9f 100644 --- a/test/utils/test-utils.js +++ b/test/utils/test-utils.js @@ -24,7 +24,7 @@ const run = (testCase, args = [], setOutput = true, nodeArgs = [], env) => { const outputPath = path.resolve(testCase, 'bin'); const processExecutor = nodeArgs.length ? execaNode : spawnSync; - const argsWithOutput = setOutput ? args.concat('--output', outputPath) : args; + const argsWithOutput = setOutput ? args.concat('--output-path', outputPath) : args; const result = processExecutor(WEBPACK_PATH, argsWithOutput, { cwd, reject: false, @@ -40,7 +40,7 @@ const runWatch = ({ testCase, args = [], setOutput = true, outputKillStr = 'Time const cwd = path.resolve(testCase); const outputPath = path.resolve(testCase, 'bin'); - const argsWithOutput = setOutput ? args.concat('--output', outputPath) : args; + const argsWithOutput = setOutput ? args.concat('--output-path', outputPath) : args; return new Promise((resolve, reject) => { const watchPromise = execa(WEBPACK_PATH, argsWithOutput, { @@ -76,7 +76,7 @@ const runAndGetWatchProc = (testCase, args = [], setOutput = true, input = '', f const cwd = path.resolve(testCase); const outputPath = path.resolve(testCase, 'bin'); - const argsWithOutput = setOutput ? args.concat('--output', outputPath) : args; + const argsWithOutput = setOutput ? args.concat('--output-path', outputPath) : args; const options = { cwd, diff --git a/test/utils/test-utils.test.js b/test/utils/test-utils.test.js index a7a6f0d6029..0c8ac2ad1e6 100644 --- a/test/utils/test-utils.test.js +++ b/test/utils/test-utils.test.js @@ -38,7 +38,7 @@ describe('run function', () => { // Executes the correct command expect(command).toContain('cli.js'); // Should use apply a default output dir - expect(command).toContain('--output'); + expect(command).toContain('--output-path'); expect(command).toContain('bin'); expect(stdout).toBeTruthy(); expect(stderr).toBeFalsy(); @@ -61,7 +61,7 @@ describe('run function', () => { it('uses default output when output param is false', () => { const { stdout, stderr, command } = run(__dirname, [], false); // execution command contains info command - expect(command).not.toContain('--output'); + expect(command).not.toContain('--output-path'); expect(stdout).toBeTruthy(); expect(stderr).toBeFalsy(); }); @@ -73,7 +73,7 @@ describe('runAndGetWatchProc function', () => { // Executes the correct command expect(command).toContain('cli.js'); // Should use apply a default output dir - expect(command).toContain('--output'); + expect(command).toContain('--output-path'); expect(command).toContain('bin'); expect(stdout).toBeTruthy(); expect(stderr).toBeFalsy(); @@ -96,7 +96,7 @@ describe('runAndGetWatchProc function', () => { it('uses default output when output param is false', async () => { const { stdout, stderr, command } = await runAndGetWatchProc(__dirname, [], false); // execution command contains info command - expect(command).not.toContain('--output'); + expect(command).not.toContain('--output-path'); expect(stdout).toBeTruthy(); expect(stderr).toBeFalsy(); });