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

fix: context overriden by flags default value. fixes #36 #38

Merged
merged 1 commit into from
Jun 24, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ const WebpackCommandError = require('./WebpackCommandError');

module.exports = {
distill(argv, config, options) {
const cwdContext = { context: process.cwd() };
let result;

if (Array.isArray(config)) {
result = config.map((conf) => merge(conf, options));
result = config.map((conf) => merge(cwdContext, conf, options));
} else {
result = merge(config, options);
result = merge(cwdContext, config, options);
}

if (argv.configName) {
Expand Down
4 changes: 2 additions & 2 deletions lib/flags/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ module.exports = {

if (argv.context) {
result.context = path.resolve(argv.context);
} else {
result.context = process.cwd();
}
// there is no else case for context, as we don't want a default value
// here to override a context value in a config

if (argv.debug) {
const { LoaderOptionsPlugin } = webpack;
Expand Down
11 changes: 11 additions & 0 deletions test/tests/__snapshots__/config.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
exports[`lib/config > distill() #0 1`] = `
Array [
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/common/entry-a.js",
"mode": "development",
},
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/common/entry-b.js",
"mode": "development",
},
Expand All @@ -26,6 +28,7 @@ Object {

exports[`lib/config > distill() plugins #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"plugins": Array [
1,
],
Expand All @@ -34,6 +37,7 @@ Object {

exports[`lib/config > distill() plugins #1 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"plugins": Array [
1,
],
Expand All @@ -42,6 +46,7 @@ Object {

exports[`lib/config > distill() plugins #2 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"plugins": Array [
1,
1,
Expand All @@ -52,13 +57,15 @@ Object {
exports[`lib/config > distill() plugins from config array #0 1`] = `
Array [
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/common/entry-a.js",
"mode": "development",
"plugins": Array [
1,
],
},
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/common/entry-b.js",
"mode": "development",
"plugins": Array [
Expand All @@ -71,13 +78,15 @@ Array [
exports[`lib/config > distill() plugins from config array #1 1`] = `
Array [
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/common/entry-a.js",
"mode": "development",
"plugins": Array [
1,
],
},
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/common/entry-b.js",
"mode": "development",
"plugins": Array [
Expand All @@ -90,13 +99,15 @@ Array [
exports[`lib/config > distill() plugins from config array #2 1`] = `
Array [
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/common/entry-a.js",
"mode": "development",
"plugins": Array [
1,
],
},
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/common/entry-b.js",
"mode": "development",
"plugins": Array [
Expand Down
3 changes: 0 additions & 3 deletions test/tests/__snapshots__/flags.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ 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 {
Expand All @@ -180,7 +179,6 @@ Object {

exports[`lib/flags > should parse compound flags: --run-prod #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"mode": "production",
"output": Object {},
"plugins": Array [
Expand All @@ -207,7 +205,6 @@ Object {

exports[`lib/flags > should parse flags cleanly #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"output": Object {},
}
`;
Expand Down
4 changes: 0 additions & 4 deletions test/tests/__snapshots__/reporters.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`StylishReporter > problems/stylish-problems reporter should apply #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/test/fixtures/reporters/stylish/problems/entry-problems.js",
"mode": "development",
"plugins": Array [
Expand Down Expand Up @@ -46,7 +45,6 @@ webpack v4.6.0

exports[`StylishReporter > stylish reporter should apply #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/test/fixtures/common/entry-a.js",
"mode": "development",
"plugins": Array [
Expand Down Expand Up @@ -75,7 +73,6 @@ webpack v4.6.0
exports[`StylishReporter > stylish-multi reporter should apply #0 1`] = `
Array [
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/test/fixtures/common/entry-a.js",
"mode": "development",
"plugins": Array [
Expand All @@ -85,7 +82,6 @@ Array [
],
},
Object {
"context": "<PROJECT_ROOT>",
"entry": Array [
"<PROJECT_ROOT>/test/fixtures/common/entry-b.js",
"<PROJECT_ROOT>/test/fixtures/common/entry-c.js",
Expand Down
15 changes: 15 additions & 0 deletions test/tests/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { test } = require('../util');
const { distill } = require('../../lib/config');
const { apply } = require('../../lib/flags');

const config = [
{
Expand All @@ -18,6 +19,20 @@ test('lib/config', module, () => {
expect(result).toMatchSnapshot();
});

it(`distill() context`, () => {
const argv = {};
const options = apply({}, {});

let result = distill(argv, { context: 'batman' }, { context: 'superman' });
expect(result.context).toBe('superman');

result = distill(argv, { context: 'batman' }, options);
expect(result.context).toBe('batman');

result = distill(argv, {}, options);
expect(result.context).toBe(process.cwd());
});

it(`distill() plugins`, () => {
let result = distill({}, {}, { plugins: [1] });
expect(result).toMatchSnapshot();
Expand Down
1 change: 0 additions & 1 deletion test/tests/flags/__snapshots__/debug.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Flags > --debug > should apply #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/test/fixtures/common/entry-a.js",
"mode": "development",
"plugins": Array [
Expand Down
1 change: 0 additions & 1 deletion test/tests/flags/__snapshots__/devtool.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Flags > --devtool > should apply #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"devtool": "cheap-source-map",
"entry": "<PROJECT_ROOT>/test/fixtures/common/entry-a.js",
"mode": "development",
Expand Down
1 change: 0 additions & 1 deletion test/tests/flags/__snapshots__/entry.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Flags > --entry > multi should apply #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"entry": Object {
"main": Array [
"./test/fixtures/common/entry-a.js",
Expand Down
3 changes: 0 additions & 3 deletions test/tests/flags/__snapshots__/reporter.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Flags > --reporter > basic reporter should apply #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/test/fixtures/common/entry-a.js",
"mode": "development",
"plugins": Array [
Expand Down Expand Up @@ -32,7 +31,6 @@ exports[`Flags > --reporter > basic reporter should build #1 1`] = `"bf58edd8"`;
exports[`Flags > --reporter > basic-multi reporter should apply #0 1`] = `
Array [
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/test/fixtures/common/entry-a.js",
"mode": "development",
"plugins": Array [
Expand All @@ -43,7 +41,6 @@ Array [
"reporter": "basic",
},
Object {
"context": "<PROJECT_ROOT>",
"entry": Array [
"<PROJECT_ROOT>/test/fixtures/common/entry-b.js",
"<PROJECT_ROOT>/test/fixtures/common/entry-c.js",
Expand Down
2 changes: 0 additions & 2 deletions test/tests/flags/__snapshots__/run-mode.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Flags > --run-dev > should apply #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"devtool": "eval-cheap-module-source-map",
"entry": "<PROJECT_ROOT>/test/fixtures/common/entry-a.js",
"mode": "development",
Expand Down Expand Up @@ -35,7 +34,6 @@ exports[`Flags > --run-dev > should build #1 1`] = `"1f4895c0"`;

exports[`Flags > --run-prod > should apply #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/test/fixtures/common/entry-a.js",
"mode": "development",
"plugins": Array [
Expand Down
1 change: 0 additions & 1 deletion test/tests/flags/__snapshots__/watch.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Flags > --watch > should apply #0 1`] = `
Object {
"context": "<PROJECT_ROOT>",
"entry": "<PROJECT_ROOT>/test/fixtures/common/entry-a.js",
"mode": "development",
"name": "single-flag",
Expand Down