Skip to content

refactor(compiler): potential undefined access in getWebpackConfigPath#3296

Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom
zendy199x:fix/potential-undefined-access-in-getwebpackconfigpath
Apr 7, 2026
Merged

refactor(compiler): potential undefined access in getWebpackConfigPath#3296
kamilmysliwiec merged 1 commit intonestjs:masterfrom
zendy199x:fix/potential-undefined-access-in-getwebpackconfigpath

Conversation

@zendy199x
Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[x] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

The function getWebpackConfigPath 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).

Issue Number: N/A

What is the new behavior?

The function now includes an explicit null/undefined check for builder.options and configPath. If builder.type === 'webpack' but no configPath is specified, a more robust handling (e.g., logging or erroring) is introduced to prevent unexpected undefined paths from propagating.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

  • Contribution type: Code Quality
  • Title: refactor(compiler): potential undefined access in getWebpackConfigPath
  • Files changed: lib/compiler/helpers/get-webpack-config-path.ts
  • Linked issue: N/A
  • Commit message: refactor: potential undefined access in getwebpackconfigpath

Copilot AI review requested due to automatic review settings March 29, 2026 17:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts getWebpackConfigPath to use an explicit builder.type === 'webpack' branch and return early when a webpack config path is found, aiming to avoid propagating unexpected undefined values.

Changes:

  • Refactors getWebpackConfigPath from a ternary assignment to an explicit if/early-return structure.
  • Adds an inline comment describing the intended fallback behavior when no config path is provided.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/compiler/helpers/get-webpack-config-path.ts
Comment thread lib/compiler/helpers/get-webpack-config-path.ts
Comment thread lib/compiler/helpers/get-webpack-config-path.ts
@zendy199x zendy199x force-pushed the fix/potential-undefined-access-in-getwebpackconfigpath branch 2 times, most recently from 0c38afd to e58842b Compare March 29, 2026 18:42
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>
@zendy199x zendy199x force-pushed the fix/potential-undefined-access-in-getwebpackconfigpath branch from e58842b to 5733ca7 Compare March 29, 2026 18:53
@zendy199x
Copy link
Copy Markdown
Contributor Author

The changes look good and address a potential issue where getWebpackConfigPath could return undefined. Here are my thoughts:

  1. Problem Addressed: The refactor properly checks for builder.options and configPath, preventing undefined values that could cause downstream errors.

  2. Code Clarity: Changing from a ternary to

@kamilmysliwiec kamilmysliwiec merged commit 9e38818 into nestjs:master Apr 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants