Skip to content

Commit

Permalink
Merge pull request #693 from lakatostamas/feature/find-config-recursi…
Browse files Browse the repository at this point in the history
…vely

Feature/find config recursively
  • Loading branch information
evenstensberg committed Jan 3, 2019
2 parents 83602d4 + 3ec2e9d commit f9bb82d
Show file tree
Hide file tree
Showing 19 changed files with 938 additions and 427 deletions.
32 changes: 11 additions & 21 deletions bin/convert-argv.js
Expand Up @@ -6,6 +6,7 @@ const prepareOptions = require("./prepareOptions");
const webpackConfigurationSchema = require("./webpackConfigurationSchema.json");
const validateSchema = require("webpack").validateSchema;
const WebpackOptionsValidationError = require("webpack").WebpackOptionsValidationError;
const findup = require("findup-sync");

module.exports = function(...args) {
const argv = args[1] || args[0];
Expand Down Expand Up @@ -43,18 +44,6 @@ module.exports = function(...args) {
const extensions = Object.keys(interpret.extensions).sort(function(a, b) {
return a === ".js" ? -1 : b === ".js" ? 1 : a.length - b.length;
});
const defaultConfigFiles = ["webpack.config", "webpackfile"]
.map(function(filename) {
return extensions.map(function(ext) {
return {
path: path.resolve(filename + ext),
ext: ext
};
});
})
.reduce(function(a, i) {
return a.concat(i);
}, []);

let i;
if (argv.config) {
Expand All @@ -80,15 +69,16 @@ module.exports = function(...args) {
const configArgList = Array.isArray(argv.config) ? argv.config : [argv.config];
configFiles = configArgList.map(mapConfigArg);
} else {
for (i = 0; i < defaultConfigFiles.length; i++) {
const webpackConfig = defaultConfigFiles[i].path;
if (fs.existsSync(webpackConfig)) {
configFiles.push({
path: webpackConfig,
ext: defaultConfigFiles[i].ext
});
break;
}
const defaultConfigFiles = ["webpack.config", "webpackfile"];
const webpackConfigFileRegExp = `(${defaultConfigFiles.join("|")})(${extensions.join("|")})`;
const pathToWebpackConfig = findup(webpackConfigFileRegExp);

if (pathToWebpackConfig) {
const resolvedPath = path.resolve(pathToWebpackConfig);
configFiles.push({
path: resolvedPath,
ext: resolvedPath.split(".").pop(),
});
}
}
if (configFiles.length > 0) {
Expand Down

0 comments on commit f9bb82d

Please sign in to comment.