Skip to content

Commit

Permalink
fix: do not ignoring webpack config loading errors
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Jul 3, 2024
1 parent 28bbb72 commit 285980e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 7 additions & 4 deletions actions/build.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../lib/configuration/defaults';
import { FileSystemReader } from '../lib/readers';
import { ERROR_PREFIX } from '../lib/ui';
import { isModuleAvailable } from '../lib/utils/is-module-available';
import { AbstractAction } from './abstract.action';
import webpack = require('webpack');

Expand Down Expand Up @@ -261,13 +262,15 @@ export class BuildAction extends AbstractAction {
webpackRef: typeof webpack,
) => webpack.Configuration {
const pathToWebpackFile = join(process.cwd(), webpackPath);
const isWebpackFileAvailable = isModuleAvailable(pathToWebpackFile);
if (!isWebpackFileAvailable && webpackPath === defaultPath) {
return ({}) => ({});
}

try {
return require(pathToWebpackFile);
} catch (err) {
if (webpackPath !== defaultPath) {
throw err;
}
return ({}) => ({});
throw err;
}
}
}
8 changes: 8 additions & 0 deletions lib/utils/is-module-available.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function isModuleAvailable(path: string): boolean {
try {
require.resolve(path);
return true;
} catch {
return false;
}
}

0 comments on commit 285980e

Please sign in to comment.