Skip to content

feat: validate output target in Rsbuild config#5592

Merged
chenjiahan merged 4 commits intomainfrom
target_validation_0714
Jul 14, 2025
Merged

feat: validate output target in Rsbuild config#5592
chenjiahan merged 4 commits intomainfrom
target_validation_0714

Conversation

@chenjiahan
Copy link
Member

@chenjiahan chenjiahan commented Jul 14, 2025

Summary

Validate the output.target in the Rsbuild config to detect configuration errors at an earlier stage.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings July 14, 2025 09:50
@netlify
Copy link

netlify bot commented Jul 14, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 55eb005
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/68750700ae93740008021d96
😎 Deploy Preview https://deploy-preview-5592--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 81 (🟢 up 8 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

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 adds early validation for the output.target setting in Rsbuild configurations and updates E2E scripts to normalize error messages and cover invalid-target scenarios.

  • Refactored environment name checks and introduced per-environment output.target validation in initConfigs.ts.
  • Stripped ANSI control characters from caught build errors in shared E2E scripts.
  • Added a new E2E case for invalid output.target.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/provider/initConfigs.ts Refactor config.environments guard and add output.target validation
e2e/scripts/shared.ts Import and apply stripVTControlCharacters to sanitize error messages
e2e/cases/output/invalid-target/exports-presence/src/index.js Add placeholder entry point for invalid-target test
e2e/cases/output/invalid-target/exports-presence/index.test.ts Add Playwright test for invalid output.target error
Comments suppressed due to low confidence (4)

e2e/cases/output/invalid-target/exports-presence/index.test.ts:4

  • [nitpick] The test name references an "exportsPresence" error but is actually validating an invalid output.target. Rename it to something like should throw for invalid output.target for clarity.
test('should throw error by default (exportsPresence error)', async () => {

e2e/cases/output/invalid-target/exports-presence/index.test.ts:16

  • Consider adding a complementary test case that uses valid targets (web, node, web-worker) to ensure no error is thrown when the value is correct.
  expect(rsbuild.buildError?.message).toContain(

packages/core/src/provider/initConfigs.ts:184

  • If output.target can also be provided at the top level (outside environments), this early return will skip its validation. Consider validating config.output?.target before returning or clearly documenting that root-level targets must go under environments.
  if (!config.environments) {

packages/core/src/provider/initConfigs.ts:199

  • Directly accessing output without checking for its existence may throw if an environment has no output block. Add a guard (e.g. const outputConfig = config.environments[name].output || {};) or use optional chaining.
    const outputConfig = config.environments[name].output;

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Undefined `outputConfig` Causes Target Access Error

The validateRsbuildConfig function attempts to access outputConfig.target without ensuring outputConfig is defined. If config.environments[name].output is missing or undefined, this results in a TypeError "Cannot read property 'target' of undefined".

packages/core/src/provider/initConfigs.ts#L199-L201

const outputConfig = config.environments[name].output;
if (outputConfig.target) {

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@chenjiahan chenjiahan merged commit 04506f3 into main Jul 14, 2025
12 checks passed
@chenjiahan chenjiahan deleted the target_validation_0714 branch July 14, 2025 13:39
@chenjiahan chenjiahan mentioned this pull request Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant