Skip to content
This repository has been archived by the owner on Sep 11, 2018. It is now read-only.

fix: define flag documentation, run-dev and run-prod implementation #34

Merged
merged 4 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/flags/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ module.exports = {
},
define: {
type: 'object',
desc: 'Define any free var in the bundle',
desc: `Used to redefine or replace a variable or key in the bundle. Complex
keys should be set in config. {dim e.g. --define.batman robin}`,
},
hot: {
type: 'boolean',
Expand Down
12 changes: 6 additions & 6 deletions lib/flags/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
/* eslint-disable no-param-reassign */
if (argv.runDev) {
argv.debug = true;
argv['output-pathinfo'] = true;
argv.outputPathinfo = true;
if (!argv.devtool) {
argv.devtool = 'eval-cheap-module-source-map';
}
Expand All @@ -29,10 +29,10 @@ module.exports = {
}

if (argv.runProd) {
argv['optimize-minimize'] = true;
argv.define = []
.concat(argv.define || [])
.concat('process.env.NODE_ENV="production"');
argv.optimizeMinimize = true;
argv.define = Object.assign({}, argv.define, {
'process.env.NODE_ENV': 'production',
});
if (!argv.mode) {
argv.mode = 'production';
}
Expand Down Expand Up @@ -126,7 +126,7 @@ Typically used for language-specific require hooks`,
'run-prod': {
alias: 'p',
desc:
'An alias for --optimize-minimize --define process.env.NODE_ENV="production"',
'An alias for --optimize-minimize, which also defines process.env.NODE_ENV="production"',
type: 'boolean',
},
version: {
Expand Down
2 changes: 1 addition & 1 deletion test/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function nameTest(test) {
function match(received) {
const { file } = current;
const snapshotState = new SnapshotState(file, {
updateSnapshot: argv.update ? 'all' : 'new',
updateSnapshot: argv.update || argv.u ? 'all' : 'new',
});
const matcher = toMatchSnapshot.bind({
snapshotState,
Expand Down
52 changes: 52 additions & 0 deletions test/tests/__snapshots__/flags.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,58 @@ exports[`lib/flags > should display help #1 1`] = `
"
`;

exports[`lib/flags > should parse compound flags: --run-dev #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"devtool": "eval-cheap-module-source-map",
"mode": "development",
"output": Object {
"pathinfo": true,
},
"plugins": Array [
LoaderOptionsPlugin {
"options": Object {
"debug": true,
"test": Object {
"test": [Function],
},
},
},
NamedModulesPlugin {
"options": Object {},
},
],
"reporter": "<PROJECT_ROOT>/test/fixtures/common/test-reporter.js",
}
`;

exports[`lib/flags > should parse compound flags: --run-prod #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"mode": "production",
"output": Object {},
"plugins": Array [
LoaderOptionsPlugin {
"options": Object {
"minimize": true,
"test": Object {
"test": [Function],
},
},
},
DefinePlugin {
"definitions": Object {
"process.env.NODE_ENV": "production",
},
},
NamedModulesPlugin {
"options": Object {},
},
],
"reporter": "<PROJECT_ROOT>/test/fixtures/common/test-reporter.js",
}
`;

exports[`lib/flags > should parse flags cleanly #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
Expand Down
12 changes: 12 additions & 0 deletions test/tests/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const { test } = require('../util');
const flags = require('../../lib/flags');
const { validateFlags } = require('../../lib/flags/util');

const config = require('../fixtures/common/webpack.config.js');

test('lib/flags', module, () => {
it(`should display help`, () => {
const result = flags.help();
Expand All @@ -17,6 +19,16 @@ test('lib/flags', module, () => {
const result = flags.apply({}, {});
expect(result).toMatchSnapshot();
});

it('should parse compound flags: --run-dev', () => {
const result = flags.apply({ runDev: true }, config);
expect(result).toMatchSnapshot();
});

it('should parse compound flags: --run-prod', () => {
const result = flags.apply({ runProd: true }, config);
expect(result).toMatchSnapshot();
});
});

test('lib/flags/util', module, () => {
Expand Down