Skip to content

Commit

Permalink
Merge pull request #2627 from micalevisk/fix-issue-2421
Browse files Browse the repository at this point in the history
fix: propagate errors raised when loading the webpack configuration file
  • Loading branch information
kamilmysliwiec authored Jul 5, 2024
2 parents 682e7dd + f48ce24 commit 952da4b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 4 additions & 6 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,10 @@ export class BuildAction extends AbstractAction {
webpackRef: typeof webpack,
) => webpack.Configuration {
const pathToWebpackFile = join(process.cwd(), webpackPath);
try {
return require(pathToWebpackFile);
} catch (err) {
if (webpackPath !== defaultPath) {
throw err;
}
const isWebpackFileAvailable = isModuleAvailable(pathToWebpackFile);
if (!isWebpackFileAvailable && webpackPath === defaultPath) {
return ({}) => ({});
}
return require(pathToWebpackFile);
}
}
7 changes: 5 additions & 2 deletions lib/compiler/assets-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ export class AssetsManager {

const filesToCopy = assets.map<AssetEntry>((item) => {
let includePath = typeof item === 'string' ? item : item.include!;
let excludePath = typeof item !== 'string' && item.exclude ? item.exclude : undefined;
let excludePath =
typeof item !== 'string' && item.exclude ? item.exclude : undefined;

includePath = join(sourceRoot, includePath).replace(/\\/g, '/');
excludePath = excludePath ? join(sourceRoot, excludePath).replace(/\\/g, '/') : undefined;
excludePath = excludePath
? join(sourceRoot, excludePath).replace(/\\/g, '/')
: undefined;

return {
outDir: typeof item !== 'string' ? item.outDir || outDir : outDir,
Expand Down
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 952da4b

Please sign in to comment.