diff --git a/packages/webpack/get-config.js b/packages/webpack/get-config.js index c267767d..5a20cd05 100644 --- a/packages/webpack/get-config.js +++ b/packages/webpack/get-config.js @@ -11,7 +11,40 @@ let writeFile = promisify(fs.writeFile) const STATIC = /\.(eot|woff2?|ttf|otf|svg|png|jpe?g|gif|webp|mp4|mp3|ogg|pdf|html|ico|md)$/ +function checkIfFilesExist(limitConfig, check) { + let cwd = limitConfig.cwd || process.cwd() + + let filesToCheck = new Set() + if (check.files) { + if (Array.isArray(check.files)) { + for (let file of check.files) { + filesToCheck.add(file) + } + } else { + filesToCheck.add(check.files) + } + } + if (check.path) { + filesToCheck.add(join(cwd, check.path)) + } + + let filesToIgnore = (check.ignore || []).filter(Boolean).map(file => join(cwd, file)) + filesToCheck = Array.from(filesToCheck).filter(file => !filesToIgnore.includes(file)) + + if (filesToIgnore.length && !filesToCheck.length) { + throw Error(`Could not test '${check.name}' because it includes no file to check`) + } + + for (let file of filesToCheck) { + if (!fs.existsSync(file)) { + throw Error(`Could not test '${check.name}' because file '${file}' is missing`) + } + } +} + module.exports = async function getConfig(limitConfig, check, output) { + checkIfFilesExist(limitConfig, check) + if (check.import) { let loader = '' for (let i in check.import) {