Skip to content

Fix: Empty build.excludes or build.includes array breaks the build #3786

@swashbuck

Description

@swashbuck

Subject of the issue

Setting build.excludes or build.includes to an empty array [] in config.json causes unexpected build failures. An empty array should be equivalent to not specifying the property at all, but instead it silently breaks plugin filtering.

Your environment

  • Affects all framework versions with the current generateConfigData and isPathIncluded implementation

Steps to reproduce

  1. Set "build": { "excludes": [] } in config.json
  2. Run grunt build or rub

Expected behaviour

An empty excludes array excludes nothing. An empty includes array has no filtering effect. Both should behave identically to not specifying the property.

Actual behaviour

  • excludes: [] - The generateExcludedRegExp function joins an empty array, producing new RegExp('', 'i') which matches every file path. All plugins are excluded, causing downstream errors like Cannot read properties of undefined (reading 'applyDefaults').
  • includes: [] - Similarly produces a malformed regex with a trailing | alternative that matches everything.

Root cause

In helpers.js generateConfigData(), empty arrays pass the truthiness check and get propagated into grunt config:

if (buildConfig.includes) data.includes = ...  // [] is truthy
if (buildConfig.excludes) data.excludes = ...  // [] is truthy

Proposed fix

Add .length checks so empty arrays are treated identically to undefined:

if (buildConfig.includes?.length) ...
if (buildConfig.excludes?.length) ...
if (buildConfig.productionExcludes?.length) ...

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

Needs Reviewing

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions