Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/find config recursively #693

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 19 additions & 17 deletions bin/convert-argv.js
Original file line number Diff line number Diff line change
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");
ematipico marked this conversation as resolved.
Show resolved Hide resolved

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,12 +69,25 @@ 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)) {
const defaultConfigFileNames = ["webpack.config", "webpackfile"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good chance to move "webpack.config" and "webpackfile" inside two constants

.map(function(filename) {
return extensions.map(function(ext) {
return filename.concat(ext);
});
})
.reduce(function(a, i) {
return a.concat(i);
}, []);

for (i = 0; i < defaultConfigFileNames.length; i++) {
Copy link
Member

@hemal7735 hemal7735 Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need some logic change here. Let's see both implementations.

existing-implementation: try to find file from ["webpack.config", "webpackfile"] in cwd.

current-modification:

  1. try to find file webpack.config in up-fashion.
  2. if found then return, if not go to step#3
  3. try to find file webpackfile in up-fashion.
  4. if found then return

Do we see the problem here? Even though webpackfile is there one level above, it would not be discovered, but 2 level up webpack.config would be given chance first.

I would want both files to get a fair chance to be discovered. @evenstensberg @ematipico your thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

top-down priority is the best

Copy link
Member

@hemal7735 hemal7735 Nov 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evenstensberg sorry, I did not get you. Can you give any example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hemal7735 I think you are right. I implemented a solution with (dynamically created) RegExp, but I didn't merge it into this PR. I also added webpackfile related tests. Could you please check it? https://github.com/lakatostamas/webpack-cli/compare/1f2b7e2..727a59a

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah both files should always have the same priority at each path of directory structure.

const webpackConfigName = defaultConfigFileNames[i];
var pathToWebpackConfig = findup(webpackConfigName);

if (pathToWebpackConfig) {
const resolvedPath = path.resolve(pathToWebpackConfig);
configFiles.push({
path: webpackConfig,
ext: defaultConfigFiles[i].ext
path: resolvedPath,
ext: resolvedPath.split(".").pop(),
});
break;
}
Expand Down