Skip to content

fix: accept readonly arrays for build candidates and Scanner sources - #20708

Merged
RobinMalfait merged 1 commit into
tailwindlabs:mainfrom
Sudhakar7J:fix/readonly-build-candidates
Nov 17, 2026
Merged

RobinMalfait merged 1 commit into
tailwindlabs:mainfrom
Sudhakar7J:fix/readonly-build-candidates

Conversation

@Sudhakar7J

Copy link
Copy Markdown
Contributor

Summary

Fixes #20706.

build() only iterates its candidates, and Scanner only reads its sources, but their public types required mutable arrays. Code holding either as a readonly array had to copy it into a mutable one first.

  • packages/tailwindcss/src/index.ts: build() now takes readonly string[] in both compile() and compileAst().
  • crates/node/src/lib.rs: ScannerOptions.sources is generated as ReadonlyArray<SourceEntry> via #[napi(ts_type = ...)].
  • Added type-level regression tests for both public types.
  • Added a changelog entry.

Mutable arrays remain assignable to readonly arrays, so this is backwards compatible.

Test plan

  • pnpm exec vitest run packages/tailwindcss/src/index.test.ts — 268 passed.
  • tsc -p packages/tailwindcss/tsconfig.check.json --noEmit — clean (package-scoped check).
  • rustfmt --check --edition 2021 crates/node/src/lib.rs — clean.
  • node ./scripts/changelog.mjs check — clean.
  • Built @tailwindcss/oxide and confirmed the generated crates/node/index.d.ts now declares sources?: ReadonlyArray<SourceEntry>.
  • The new type-level tests assign readonly arrays to both APIs, so they fail to type-check against the previous mutable signatures and pass with this change.

Notes

The #[napi(ts_type = ...)] attribute only changes the generated TypeScript declaration; the Rust field remains Option<Vec<SourceEntry>>, so there is no runtime change.

@Sudhakar7J
Sudhakar7J requested a review from a team as a code owner November 12, 2026 05:17
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This PR appears safe to merge.

Reviews (8) · Last reviewed commit: "fix: accept readonly arrays for build ca..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c219e3e3-6610-412a-80da-9d4d4004a3c5
Commits

Reviewing files that changed from the base of the PR and between f4a706f and 8a911d7.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The build() methods now accept readonly candidate arrays, and ScannerOptions.sources is annotated to accept a readonly array. The added type tests cover both inputs. The changelog records the update.

Severity of issue fixed: Medium

Merge Risk: Minimal · previous review f4a70

This change lets TypeScript callers pass readonly arrays for build candidates and scanner sources, with no runtime change. The only effect is that code mutating ScannerOptions.sources through the type may need a small adjustment. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main changes: readonly arrays for build candidates and for Scanner sources. The changeset makes these type changes in packages/tailwindcss/src/index.ts and crates/node/src/lib.…
Description check Passed The description states the purpose of the change: build() and Scanner only read their inputs, but their public types required mutable arrays. It lists the modified files (index.ts, crates/node/src/lib…
Linked Issues check Passed Issue #20706 has two coding requirements. (1) build(candidates) must accept readonly string[]. The whole-PR summary (merge base to head) shows build changed from string[] to `readonly string[]…
Out of Scope Changes check Passed All changed files in the whole-PR summary relate to #20706. The index.ts changes are the two build signature updates. The lib.rs change is one ts_type annotation on ScannerOptions.sources. T…
Full details: Title check

Explanation

The title names the two main changes: readonly arrays for build candidates and for Scanner sources. The changeset makes these type changes in packages/tailwindcss/src/index.ts and crates/node/src/lib.rs, so the title matches the main change. The 'fix:' prefix is a conventional commit type and the title is 68 characters long.

Full details: Description check

Explanation

The description states the purpose of the change: build() and Scanner only read their inputs, but their public types required mutable arrays. It lists the modified files (index.ts, crates/node/src/lib.rs), the added type-level regression tests, the changelog entry, validation steps, and a backward-compatibility note. It is directly related to the changeset.

Full details: Linked Issues check

Explanation

Issue #20706 has two coding requirements. (1) build(candidates) must accept readonly string[]. The whole-PR summary (merge base to head) shows build changed from string[] to readonly string[] in both compileAst() and compile() in packages/tailwindcss/src/index.ts, with implementation bodies unchanged. (2) ScannerOptions.sources must accept readonly SourceEntry[]. The summary shows #[napi(ts_type = ...)] on pub sources in crates/node/src/lib.rs, which generates ReadonlyArray&lt;SourceEntry&gt; in the declaration. The Rust field and runtime behavior are unchanged. Mutable arrays remain assignable to readonly parameters, as the issue requires. Type-level regression tests in packages/tailwindcss/src/index.test.ts cover both APIs. The head moved since the previous review. The whole-PR summary remains consistent with the earlier conclusion, so it is retained. The incremental diff was not independently read. The author-reported checks were not rerun, and the reproduction project was not inspected.

Full details: Out of Scope Changes check

Explanation

All changed files in the whole-PR summary relate to #20706. The index.ts changes are the two build signature updates. The lib.rs change is one ts_type annotation on ScannerOptions.sources. The test file adds type-level coverage for both APIs. The changelog entry documents the fix. The summary reports no runtime, dependency, or refactoring changes. The changelog and test file were assessed from the summary only. The incremental diff since the previous reviewed heads was not independently read.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0d2fa357-97ec-484c-a9d6-e0585ddddc4d
Commits

Reviewing files that changed from the base of the PR and between e907051 and f4a706f.

Files selected for processing: 1

  • crates/node/src/lib.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Additional comments: 1

crates/node/src/lib.rs-92-92: 1

92-92: Major · Data Integrity & Integration · Heavy lift

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Preserve mutable access through ScannerOptions.

Existing code such as options.sources!.push(entry) no longer type-checks when options has type ScannerOptions. This can break consumer builds even though mutable arrays remain valid constructor inputs. Consider a separate readonly constructor-input type while preserving the existing mutable ScannerOptions contract.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 089e5720-1d70-4774-9ab4-1c445e4a00e0
Commits

Reviewing files that changed from the base of the PR and between b08bf83 and 0303828.

Files selected for processing: 4

  • .changelog/readonly-build-candidates.md
  • crates/node/src/lib.rs
  • packages/tailwindcss/src/index.test.ts
  • packages/tailwindcss/src/index.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@Sudhakar7J

Copy link
Copy Markdown
Contributor Author

Thanks for flagging this — I considered that tradeoff.

ReadonlyArray<SourceEntry> on ScannerOptions.sources allows both mutable and readonly arrays to be passed (which addresses #20706), but it does make options.sources read-only when accessed through the ScannerOptions type (so options.sources.push(...) would no longer type-check). At runtime the underlying value can still be a mutable array, but the declared type becomes stricter.

If you’d prefer to preserve mutable access via ScannerOptions.sources while still accepting readonly inputs, I can adjust this (e.g. by keeping the property mutable in the public type and using a separate/compatible input type for construction, if that fits napi-rs typing here). Happy to update based on maintainer preference.

@RobinMalfait
RobinMalfait self-requested a review November 16, 2026 21:26
@RobinMalfait RobinMalfait self-assigned this Nov 16, 2026
@RobinMalfait
RobinMalfait force-pushed the fix/readonly-build-candidates branch from 0303828 to e907051 Compare November 16, 2026 21:28
@RobinMalfait

Copy link
Copy Markdown
Contributor

I rebased this PR on the latest main and force pushed it.

Sent by an AI assistant on behalf of @RobinMalfait.

@RobinMalfait
RobinMalfait force-pushed the fix/readonly-build-candidates branch from e907051 to f4a706f Compare November 17, 2026 12:00
@RobinMalfait
RobinMalfait enabled auto-merge (squash) November 17, 2026 12:00

@RobinMalfait RobinMalfait left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR! Nice and small change, and the type-level tests make sure that readonly arrays keep working.

Sent by an AI assistant on behalf of @RobinMalfait.

`build()` only iterates its candidates and `Scanner` only reads its
sources, but both public types required mutable arrays. Code that holds
either as a `readonly` array had to copy it first.

- `packages/tailwindcss/src/index.ts`: type `build()` candidates as
  `readonly string[]` for both `compile()` and `compileAst()`.
- `crates/node/src/lib.rs`: emit `ReadonlyArray<SourceEntry>` for
  `ScannerOptions.sources` via `#[napi(ts_type = ...)]`.
- Add type-level regression tests for both public types.

Fixes tailwindlabs#20706
@RobinMalfait
RobinMalfait force-pushed the fix/readonly-build-candidates branch from f4a706f to 8a911d7 Compare November 17, 2026 12:06
@RobinMalfait
RobinMalfait merged commit 938b970 into tailwindlabs:main Nov 17, 2026
12 checks 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.

Scanner's sources and build's candidates refuse a readonly array, though each is only read

2 participants