Skip to content

Commit 19c7395

Browse files
committed
Make configFiles always be an array
1 parent 77ec1fd commit 19c7395

1 file changed

Lines changed: 31 additions & 32 deletions

File tree

bin/convert-argv.js

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
77

88
module.exports = function(optimist, argv, convertOptions) {
99

10-
var options = {};
10+
var options = [];
1111

1212
// Help
1313
if(argv.help) {
@@ -35,7 +35,7 @@ module.exports = function(optimist, argv, convertOptions) {
3535
}
3636

3737
var configFileLoaded = false;
38-
var configFile = {};
38+
var configFiles = [];
3939
var extensions = Object.keys(interpret.extensions).sort(function(a, b) {
4040
return a === '.js' ? -1 : b === '.js' ? 1 : a.length - b.length;
4141
});
@@ -57,36 +57,36 @@ module.exports = function(optimist, argv, convertOptions) {
5757
var tmpExt = extensions[i];
5858
if(configPath.indexOf(tmpExt, configPath.length - tmpExt.length) > -1) {
5959
return tmpExt;
60-
break;
6160
}
6261
}
6362
return path.extname(configPath);
6463
}
65-
if(Array.isArray(argv.config)) {
66-
configFile = argv.config.map(function(configArg) {
67-
var resolvedPath = path.resolve(configArg);
68-
var extension = getConfigExtension(resolvedPath);
69-
return {
70-
path: resolvedPath,
71-
ext: extension
72-
};
73-
});
74-
} else {
75-
configFile.path = path.resolve(argv.config);
76-
configFile.ext = getConfigExtension(configFile.path);
64+
65+
function mapConfigArg(configArg) {
66+
var resolvedPath = path.resolve(configArg);
67+
var extension = getConfigExtension(resolvedPath);
68+
return {
69+
path: resolvedPath,
70+
ext: extension
71+
};
7772
}
73+
74+
var configArgList = Array.isArray(argv.config) ? argv.config : [argv.config];
75+
configFiles = configArgList.map(mapConfigArg);
7876
} else {
7977
for(i = 0; i < defaultConfigFiles.length; i++) {
8078
var webpackConfig = defaultConfigFiles[i].path;
8179
if(fs.existsSync(webpackConfig)) {
82-
configFile.ext = defaultConfigFiles[i].ext;
83-
configFile.path = webpackConfig;
80+
configFiles.push({
81+
path: webpackConfig,
82+
ext: defaultConfigFiles[i].ext
83+
});
8484
break;
8585
}
8686
}
8787
}
8888

89-
if(configFile) {
89+
if(configFiles.length > 0) {
9090
function registerCompiler(moduleDescriptor) {
9191
if(moduleDescriptor) {
9292
if(typeof moduleDescriptor === "string") {
@@ -118,21 +118,20 @@ module.exports = function(optimist, argv, convertOptions) {
118118
return options;
119119
}
120120

121-
if(Array.isArray(configFile)) {
122-
options = [];
123-
configFile.forEach(function(file) {
124-
registerCompiler(interpret.extensions[file.ext]);
125-
options.push(requireConfig(file.path));
126-
});
127-
configFileLoaded = true;
128-
} else {
129-
registerCompiler(interpret.extensions[configFile.ext]);
130-
options = requireConfig(configFile.path);
131-
configFileLoaded = true;
132-
}
121+
configFiles.forEach(function(file) {
122+
registerCompiler(interpret.extensions[file.ext]);
123+
options.push(requireConfig(file.path));
124+
});
125+
configFileLoaded = true;
133126
}
134127

135-
return processConfiguredOptions(options);
128+
if(!configFileLoaded) {
129+
return processConfiguredOptions({});
130+
} else if(options.length === 1) {
131+
return processConfiguredOptions(options[0]);
132+
} else {
133+
return processConfiguredOptions(options);
134+
}
136135

137136
function processConfiguredOptions(options) {
138137
if(options === null || typeof options !== "object") {
@@ -566,7 +565,7 @@ module.exports = function(optimist, argv, convertOptions) {
566565
}
567566

568567
if(!options.entry) {
569-
if(configFile.path) {
568+
if(configFileLoaded) {
570569
console.error("Configuration file found but no entry configured.");
571570
} else {
572571
console.error("No configuration file found and no entry configured via CLI option.");

0 commit comments

Comments
 (0)