Skip to content

Commit 0c38afd

Browse files
committed
refactor: potential undefined access in getwebpackconfigpath
The function accesses `builder.options?.configPath` without verifying `builder.options` exists. While optional chaining prevents a crash, if `builder.options` is undefined, `webpackPath` becomes undefined and is returned — but the caller may expect a valid path. This can lead to runtime errors downstream when the path is used (e.g., in file system operations or webpack CLI invocation). Signed-off-by: Zendy <50132805+zendy199x@users.noreply.github.com>
1 parent 67b8bc7 commit 0c38afd

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

lib/compiler/helpers/get-webpack-config-path.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
```ts
12
import { Input } from '../../../commands';
23
import { Builder, Configuration } from '../../configuration';
34
import { getValueOrDefault } from './get-value-or-default';
@@ -31,9 +32,15 @@ export function getWebpackConfigPath(
3132
appName,
3233
);
3334
34-
webpackPath =
35-
typeof builder === 'object' && builder?.type === 'webpack'
36-
? builder.options?.configPath
37-
: undefined;
38-
return webpackPath;
35+
if (typeof builder === 'object' && builder?.type === 'webpack') {
36+
const webpackConfigPath = builder.options?.configPath;
37+
if (webpackConfigPath) {
38+
return webpackConfigPath;
39+
}
40+
// If builder.type is 'webpack' but no config path is specified, return undefined
41+
// to let webpack use its default behavior
42+
return undefined;
43+
}
44+
return undefined;
3945
}
46+
```

0 commit comments

Comments
 (0)