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 77a8bc3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
18 changes: 9 additions & 9 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 @@ -190,10 +191,8 @@ export class BuildAction extends AbstractAction {
getWebpackConfigPath(configuration, commandOptions, appName) ??
defaultWebpackConfigFilename;

const webpackConfigFactoryOrConfig = this.getWebpackConfigFactoryByPath(
webpackPath,
defaultWebpackConfigFilename,
);
const webpackConfigFactoryOrConfig =
this.getWebpackConfigFactoryByPath(webpackPath);
return webpackCompiler.run(
configuration,
pathToTsconfig,
Expand Down Expand Up @@ -255,19 +254,20 @@ export class BuildAction extends AbstractAction {

private getWebpackConfigFactoryByPath(
webpackPath: string,
defaultPath: string,
): (
config: webpack.Configuration,
webpackRef: typeof webpack,
) => webpack.Configuration {
const pathToWebpackFile = join(process.cwd(), webpackPath);
const isWebpackFileAvailable = isModuleAvailable(pathToWebpackFile);
if (!isWebpackFileAvailable) {
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 (e) {
return false;
}
}

0 comments on commit 77a8bc3

Please sign in to comment.