Skip to content

Commit 762e3b9

Browse files
committed
fix: config lookup
1 parent d3fe773 commit 762e3b9

8 files changed

Lines changed: 13 additions & 14 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ coverage
2626
test/js/*
2727
test/**/bin/
2828
test/**/**/bin/
29+
test/config/basic/binary/**
2930
# lerna log
3031
lerna-debug.log
3132

lib/bootstrap.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ async function runCLI(cli, commandIsUsed) {
4949
const oldMapValue = argsMap[arg];
5050
argsMap[arg] = {
5151
value: process.argv[idx],
52-
type: (arg.charAt(0) === '-' && arg.charAt(1) === '-') ? 'dash' : 'cmd',
5352
pos: idx
5453
}
5554
// Swap idx of overriden value
@@ -67,8 +66,10 @@ async function runCLI(cli, commandIsUsed) {
6766
return;
6867
}
6968
process.cliLogger.warn(`duplicate flags found, defaulting to last set value`);
70-
} else {
69+
}
70+
else {
7171
process.cliLogger.error(err);
72+
return;
7273
}
7374
}
7475
}

lib/groups/config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class ConfigGroup extends GroupHelper {
1212
this.configOptions = [];
1313
}
1414
getDefaultConfigFiles() {
15-
const { mode } = this.args;
1615
let DEFAULT_FILES = ['.webpack/webpack.config', '.webpack/webpack.config.dev', '.webpack/webpack.config.prod', '.webpack/webpackfile', 'webpack.config'];
1716

1817
return DEFAULT_FILES.map(filename =>
@@ -83,8 +82,8 @@ class ConfigGroup extends GroupHelper {
8382
}
8483
if (!this.configFiles) {
8584
const tmpConfigFiles = this.defaultConfigFiles
86-
.filter(defaultFile => {
87-
return existsSync(defaultFile.path);
85+
.filter(file => {
86+
return existsSync(file.path);
8887
})
8988
.map(this.mapConfigArg.bind(this));
9089
if (tmpConfigFiles.length) {

lib/utils/zero-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module.exports = function(groupResult, isDevMode) {
22
if (!isDevMode) {
33
const prodConfig = require('./prod-config');
4-
groupResult.options = require('webpack-merge')(groupResult.options, prodConfig);
4+
groupResult.options = require('webpack-merge')(prodConfig, groupResult.options);
55
} else {
66
const devConfig = require('./dev-config');
7-
groupResult.options = require('webpack-merge')(groupResult.options, devConfig);
7+
groupResult.options = require('webpack-merge')(devConfig, groupResult.options);
88
}
99
return groupResult;
1010
};

lib/webpack-cli.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class webpackCLI extends GroupHelper {
100100
groupResult.options = webpackMerge(groupResult.options, e.options);
101101
});
102102
const isDevMode = groupResult.outputOptions['dev'];
103-
return require('./utils/zero-config')(groupResult, isDevMode);
103+
const wrappedConfig = require('./utils/zero-config')(groupResult, isDevMode);
104+
return wrappedConfig;
104105
}
105106

106107
async run(args, yargsOptions) {

test/config/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/config/basic/basic-config.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const { resolve, sep } = require('path');
44
const { run, extractSummary } = require('../../utils/test-utils');
55

66
describe('basic config file', () => {
7-
it.skip('is able to understand and parse a very basic configuration file', done => {
8-
const { stdout, stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]);
9-
expect(stderr).toBe(undefined);
7+
it('is able to understand and parse a very basic configuration file', done => {
8+
const { stdout, stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output', './binary/a.bundle.js']);
9+
expect(stderr).toContain('duplicate flags found, defaulting to last set value');
1010
expect(stdout).not.toBe(undefined);
1111
const summary = extractSummary(stdout);
1212
const outputDir = 'basic/binary';

test/utils/test-utils.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable @typescript-eslint/explicit-function-return-type */
22
'use strict';
3-
/* eslint-disable @typescript-eslint/explicit-function-return-type */
43
const path = require('path');
54
const fs = require('fs');
65
const execa = require('execa');
@@ -26,7 +25,6 @@ function run(testCase, args = []) {
2625
reject: false,
2726
stdio: ENABLE_LOG_COMPILATION ? 'inherit' : 'pipe',
2827
});
29-
3028
return result;
3129
}
3230

0 commit comments

Comments
 (0)