Skip to content

Commit

Permalink
Merge branch 'next' into feat/json
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Sep 30, 2020
2 parents fc7cb3d + d7559d2 commit 2803c89
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 87 deletions.
14 changes: 0 additions & 14 deletions packages/webpack-cli/__tests__/OutputGroup.test.js

This file was deleted.

10 changes: 10 additions & 0 deletions packages/webpack-cli/__tests__/resolveOutput.test.js
@@ -0,0 +1,10 @@
const resolveOutput = require('../lib/groups/resolveOutput');

describe('OutputGroup', function () {
it('should handle the output option', () => {
const result = resolveOutput({
output: './bundle.js',
});
expect(result.options.output.filename).toEqual('bundle.js');
});
});
54 changes: 0 additions & 54 deletions packages/webpack-cli/lib/groups/OutputGroup.js

This file was deleted.

21 changes: 21 additions & 0 deletions packages/webpack-cli/lib/groups/resolveOutput.js
@@ -0,0 +1,21 @@
const path = require('path');

/**
* Resolves the output flag
* @param {args} args - Parsed arguments passed to the CLI
*/
const resolveOutput = (args) => {
const { output } = 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;
}
return finalOptions;
};

module.exports = resolveOutput;
4 changes: 0 additions & 4 deletions packages/webpack-cli/lib/utils/cli-flags.js
Expand Up @@ -3,13 +3,11 @@ const cli = packageExists('webpack') ? require('webpack').cli : undefined;

const HELP_GROUP = 'help';
const BASIC_GROUP = 'basic';
const OUTPUT_GROUP = 'output';
const ADVANCED_GROUP = 'advanced';

const groups = {
HELP_GROUP,
BASIC_GROUP,
OUTPUT_GROUP,
ADVANCED_GROUP,
};

Expand Down Expand Up @@ -55,7 +53,6 @@ const commands = [
{
name: 'output',
type: String,
group: OUTPUT_GROUP,
description: 'To get the output in specified format ( accept json or markdown )',
},
],
Expand Down Expand Up @@ -123,7 +120,6 @@ const core = [
name: 'output',
usage: '--output <path to output directory>',
alias: 'o',
group: OUTPUT_GROUP,
type: String,
description: 'Output location of the file generated by webpack e.g. ./dist/',
link: 'https://webpack.js.org/concepts/#output',
Expand Down
8 changes: 8 additions & 0 deletions packages/webpack-cli/lib/utils/merge-strategies.js
@@ -0,0 +1,8 @@
const outputStrategy = {
'output.filename': 'prepend',
'output.path': 'prepend',
};

module.exports = {
outputStrategy,
};
11 changes: 3 additions & 8 deletions packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -3,17 +3,18 @@ const GroupHelper = require('./utils/GroupHelper');
const handleConfigResolution = require('./groups/ConfigGroup');
const resolveMode = require('./groups/resolveMode');
const resolveStats = require('./groups/resolveStats');
const resolveOutput = require('./groups/resolveOutput');
const { Compiler } = require('./utils/Compiler');
const { groups, core } = require('./utils/cli-flags');
const webpackMerge = require('webpack-merge');
const { toKebabCase } = require('./utils/helpers');
const argParser = require('./utils/arg-parser');
const { outputStrategy } = require('./utils/merge-strategies');

class WebpackCLI extends GroupHelper {
constructor() {
super();
this.groupMap = new Map();
this.groups = [];
this.args = {};
this.compilation = new Compiler();
this.defaultEntry = 'index';
Expand Down Expand Up @@ -120,12 +121,6 @@ class WebpackCLI extends GroupHelper {
this.helpGroup = new HelpGroup();
break;
}
case groups.OUTPUT_GROUP: {
const OutputGroup = require('./groups/OutputGroup');
this.outputGroup = new OutputGroup(value);
this.groups.push(this.outputGroup);
break;
}
}
}
}
Expand Down Expand Up @@ -243,7 +238,7 @@ class WebpackCLI extends GroupHelper {
.then(() => this._handleDefaultEntry())
.then(() => this._handleConfig(parsedArgs))
.then(() => this._baseResolver(resolveMode, parsedArgs, this.compilerConfiguration))
.then(() => this._handleGroupHelper(this.outputGroup))
.then(() => this._baseResolver(resolveOutput, parsedArgs, {}, outputStrategy))
.then(() => this._handleCoreFlags())
.then(() => this._handleGroupHelper(this.basicGroup))
.then(() => this._handleGroupHelper(this.advancedGroup))
Expand Down
11 changes: 4 additions & 7 deletions test/output/named-bundles/output-named-bundles.test.js
Expand Up @@ -45,12 +45,9 @@ describe('output flag named bundles', () => {
});

it('should output file in bin directory using default webpack config with warning for empty output value', () => {
const { stderr } = run(__dirname, ['--output='], false);
expect(stderr).toContain(
"You provided an empty output value. Falling back to the output value of your webpack config file, or './dist/' if none was provided",
);

const stats = statSync(resolve(__dirname, './bin/bundle.js'));
expect(stats.isFile()).toBe(true);
const { stdout, stderr, exitCode } = run(__dirname, ['--output'], false);
expect(stderr).toEqual("error: option '-o, --output <value>' argument missing");
expect(exitCode).toEqual(1);
expect(stdout).toBeFalsy();
});
});

0 comments on commit 2803c89

Please sign in to comment.