Skip to content

bun-types: declare MatchedRoute.scriptSrc - #39278

Open
robobun wants to merge 1 commit into
mainfrom
farm/372b2e72/fsrouter-scriptsrc-types
Open

bun-types: declare MatchedRoute.scriptSrc#39278
robobun wants to merge 1 commit into
mainfrom
farm/372b2e72/fsrouter-scriptsrc-types

Conversation

@robobun

@robobun robobun commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

Problem

Fix

  • Declare readonly scriptSrc: string on MatchedRoute, marked @deprecated in favor of src, in the same shape as WebSocket.URL (bun.d.ts:4656).
  • Declaring rather than removing: the getter is installed on the prototype and reachable by users, and the declarations are meant to mirror what the runtime installs. The proto table keeps it for old bun-framework-next versions, so the declaration points at src instead of presenting it as a second supported name.
  • Test: test/integration/bun-types/fixture/fsrouter.ts reads src and scriptSrc. Every type-checking case in test/integration/bun-types/bun-types.test.ts (with and without lib.dom, no lib, tsgo) checks that fixture, which is what .github/workflows/bun-types.yml runs on a release bun.

Background

  • src/**/*.classes.ts files are the input to src/codegen/generate-classes.ts; each proto entry becomes a property of the generated prototype, so the MatchedRoute proto table is the list of members the runtime installs.
  • packages/bun-types is the published @types/bun surface. It is written by hand, not generated from the class tables, which is how a member can exist at runtime without being declared (or the reverse, as with assetPrefix).
  • test/integration/bun-types/bun-types.test.ts packs bun-types and type-checks fixture/*.ts against it through the TypeScript language service in-process; those cases are skipped under debug builds because driving that API in a debug build is very slow.
Earlier revision

The first push also refactored the Bun.mmap block in bun-types.test.ts into a shared tsc() helper and added a Bun.FileSystemRouter case that spawned tsc over a three-line program, so that a debug-build run of the file exercised the declaration. That hunk conflicted with #39270 (which deletes the block it refactored and lints the file down to one spawn site) and duplicated the fixture assertions, so it was dropped. The declaration is unchanged from that revision; the fixture lines moved up two lines so the file also merges cleanly with #39282.

@robobun
robobun requested a review from alii as a code owner August 16, 2026 03:07
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 9 minutes

Limit details: You’ve used all 5 included reviews currently available under your plan.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: db737100-4169-4290-ab6a-d785f27b9f33

📥 Commits

Reviewing files that changed from the base of the PR and between aec33f5 and 2a48b0e.

📒 Files selected for processing (2)
  • packages/bun-types/bun.d.ts
  • test/integration/bun-types/fixture/fsrouter.ts

Comment @coderabbitai help to get the list of available commands.

@robobun

robobun commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 12:48 AM PT - Aug 16th, 2026

@robobun, your commit 2a48b0e3a795f5685f426e6a0e1d9cdf8959f791 passed in Build #99275! 🎉


🧪   To try this PR locally:

bunx bun-pr 39278

That installs a local version of the PR into your bun-39278 executable, so you can run:

bun-39278 --bun

@robobun

robobun commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator Author

Status: ready for review. Current revision (2a48b0e) is the declaration plus two fixture lines; the bun-types.test.ts hunk from the first push was dropped so this merges cleanly with #39270 and #39282 (details in the description).

Reproduced on bun 1.4.0: router.match("/").scriptSrc is a string at runtime (MatchedRoute proto table in filesystem_router.classes.ts), while type-checking the same read against bun-types fails with TS2339: Property 'scriptSrc' does not exist on type 'MatchedRoute'. Without the bun.d.ts hunk, 9 of the 15 cases in test/integration/bun-types/bun-types.test.ts fail with that error on a release bun; with it, 15 of 15 pass.

The assetPrefix half of the same survey (declared, but no getter at runtime) is #33433; the origin/query return types are #39282.

@claude claude 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.

LGTM — declares a runtime property that already exists, marked deprecated in favor of src.

What was reviewed:

  • Confirmed scriptSrc is a real getter on the MatchedRoute prototype (filesystem_router.classes.ts:86), backed by the same getScriptSrc as src and sharing its cache slot.
  • The tsc() helper refactor preserves the existing Bun.mmap test's checked program and assertion semantics (three .toBe → one .toEqual on the same values).
  • Fixture additions match neighboring expectType lines; no changes to unrelated members.
Extended reasoning...

Overview

Adds readonly scriptSrc: string (with @deprecated JSDoc pointing at src) to the MatchedRoute interface in packages/bun-types/bun.d.ts. The runtime already installs this getter on the prototype (src/runtime/api/filesystem_router.classes.ts:86-93), backed by the same getScriptSrc implementation as src and kept for old bun-framework-next compatibility. The test file extracts the existing tsc-spawn logic into a shared tsc() helper and adds a new case for MatchedRoute.scriptSrc; the fixture file gains two expectType<string> lines.

Security risks

None. This is a .d.ts type declaration change plus test-only code — no runtime behavior is affected.

Level of scrutiny

Low. Type declarations only; the runtime property already exists and is verified by cross-referencing the .classes.ts proto table. The test refactor is a straightforward extraction: the Bun.mmap case's checked source string is byte-identical, and the assertion changed from three separate expect().toBe() calls to one .toEqual({stdout: "", stderr: "", exitCode: 0}) — semantically equivalent, and arguably a better failure message since all three fields are shown at once.

Other factors

  • The @deprecated annotation follows the same shape as WebSocket.URL elsewhere in the file, and correctly steers users to src rather than presenting scriptSrc as a supported second name.
  • The PR description explicitly scopes out the pre-existing origin/query type inaccuracies and the assetPrefix runtime gap (handled by #33433), which is the right call for a focused change.
  • Tests cover both the release-build fixture path (all typeTest cases now exercise scriptSrc via fsrouter.ts) and the debug-build spawned-tsc path, satisfying the "test fails without the fix" requirement per the PR description's before/after counts.

Bun.FileSystemRouter's MatchedRoute prototype installs scriptSrc as a
second name for src (filesystem_router.classes.ts), but the MatchedRoute
interface in bun.d.ts did not declare it, so reading it failed to
type-check. Declare it as a deprecated alias of src, and read both names
in the fsrouter fixture that bun-types.test.ts type-checks.
@robobun
robobun force-pushed the farm/372b2e72/fsrouter-scriptsrc-types branch from 6146e64 to 2a48b0e Compare August 16, 2026 07:17

@claude claude 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.

LGTM — one-line type declaration matching the runtime MatchedRoute proto table, plus fixture coverage. The inline nit is description-accuracy only and doesn't block.

Extended reasoning...

Overview

This PR adds readonly scriptSrc: string (marked @deprecated in favor of src) to the MatchedRoute interface in packages/bun-types/bun.d.ts, and adds two expectType<string> reads for src and scriptSrc to the existing test/integration/bun-types/fixture/fsrouter.ts fixture. Total: 5 lines of declaration + 3 lines of fixture.

I verified the runtime claim against src/runtime/api/filesystem_router.classes.ts:86-93: the MatchedRoute proto table installs both scriptSrc and src getters, both backed by getScriptSrc and sharing the scriptSrc cache slot, with a comment noting scriptSrc is kept for compatibility with old bun-framework-next versions. The declaration accurately mirrors what the runtime installs, and marking it @deprecated pointing at src is the right call given the proto-table comment.

Security risks

None. This is a pure .d.ts type-declaration change plus a type-check fixture; no compiled code is touched.

Level of scrutiny

Low. Per CLAUDE.md, edits to packages/bun-types/**/*.d.ts don't touch compiled code and are covered by the bun-types.test.ts type-check harness. The change is mechanical (declare a member that exists at runtime), follows the exact shape of an existing precedent (WebSocket.URL deprecated alias), and CI passed (Build #99051).

Other factors

The bug-hunting system flagged one nit: the PR description claims a bun-types.test.ts change (a Bun.FileSystemRouter case with a shared tsc-spawning helper) that isn't in the diff — only bun.d.ts and the fixture were committed. This is description-accuracy only; the shipped fixture coverage is sufficient under CLAUDE.md's explicit bun-types exception, and the fixture is exercised by every type-check case in bun-types.test.ts on release builds. The nit doesn't affect the correctness of what shipped.

Comment thread test/integration/bun-types/fixture/fsrouter.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant