Skip to content

Commit

Permalink
fix: allow unknown files to use default require as fallback (#1747)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv authored Aug 19, 2020
1 parent 5b49061 commit b071623
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions packages/webpack-cli/lib/groups/ConfigGroup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { existsSync } = require('fs');
const { resolve, sep, dirname, parse } = require('path');
const { resolve, sep, dirname, extname } = require('path');
const webpackMerge = require('webpack-merge');
const { extensions, jsVariants } = require('interpret');
const GroupHelper = require('../utils/GroupHelper');
Expand Down Expand Up @@ -42,25 +42,16 @@ const getDefaultConfigFiles = () => {
};

const getConfigInfoFromFileName = (filename) => {
const fileMetaData = parse(filename);
// .cjs is not available on interpret side, handle it manually for now
if (filename.endsWith('.cjs')) {
return [
{
path: resolve(filename),
ext: '.cjs',
module: null,
},
];
}
return Object.keys(extensions)
.filter((ext) => ext.includes(fileMetaData.ext))
.filter((ext) => fileMetaData.base.substr(fileMetaData.base.length - ext.length) === ext)
.map((ext) => {
const ext = extname(filename);
// since we support only one config for now
const allFiles = [filename];
// return all the file metadata
return allFiles
.map((file) => {
return {
path: resolve(filename),
path: resolve(file),
ext: ext,
module: extensions[ext],
module: extensions[ext] || null,
};
})
.filter((e) => existsSync(e.path));
Expand Down

0 comments on commit b071623

Please sign in to comment.