Skip to content

bun-types: declare bytes() on ShellPromise - #44725

Open
robobun wants to merge 1 commit into
mainfrom
robobun/2f9a6bb7/shell-promise-bytes-type
Open

robobun wants to merge 1 commit into
mainfrom
robobun/2f9a6bb7/shell-promise-bytes-type

Conversation

@robobun

@robobun robobun commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • await $`echo hello`.bytes() works at runtime. TypeScript rejects it: error TS2339: Property 'bytes' does not exist on type 'ShellPromise'.
  • add .bytes() method to various readables #11104 added bytes() to ShellPromise, ShellOutput and ShellError in src/js/builtins/shell.ts. packages/bun-types/shell.d.ts declares it on ShellOutput and ShellError only.

Fix

  • Declare bytes(): Promise<Uint8Array<ArrayBuffer>> on ShellPromise, between arrayBuffer() and blob() as in the runtime class.
  • Add a .bytes() section to docs/runtime/shell.mdx. Each printed output, there and in the JSDoc, comes from a run of the snippet.
  • Verified: test/integration/bun-types/bun-types.test.ts, 22 pass. With the new fixture line and the shell.d.ts of main, 10 of 22 fail with that TS2339. The five tsc checks of lint.yml pass.
  • Self-reviewed: 7 concerns read, 7 addressed. The review output was cut off, so at least one more is open (Notes).

Background

  • $`cmd` returns a ShellPromise. The command starts on await. An output method such as .text() calls .quiet(), starts the command and resolves with stdout.
  • bun-types.test.ts type-checks test/integration/bun-types/fixture/. It pins two expected diagnostics to index.ts:196 and index.ts:322, so the new check is below both.
  • Fix every type error in test/ #44614 cast the one caller, test/js/bun/shell/bunshell-instance.test.ts:99, to any. After this PR the cast is not necessary. This PR keeps it, so that test does not change.
  • No other design exists: only shell.d.ts declares ShellPromise.

Downsides

  • $`cmd`.run() is still a type error. Notes lists it with six other mismatches that this PR does not change.
  • The unpacked bun-types package grows by 711 bytes: 412 in shell.d.ts, 299 in its copy of the docs page. The bun binary does not change.
Notes

Not in this PR

  • ShellPromise.prototype.run() exists at runtime and has no declaration. It starts the command and returns the promise. After run(), text(), json(), lines(), arrayBuffer(), bytes() and blob() reject with Shell is already running. The docs and the types have never shown it (first shell PR: feat: Bun shell #7748). The repo has one caller, test/js/bun/shell/commands/rm.test.ts:273, with a cast. A maintainer must decide if run() is public API, so this PR does not declare it.
  • get stdin(): WritableStream is declared on ShellPromise. The runtime has no stdin.
  • new $.Shell() has the type $. The instance has no braces, escape, Shell, ShellPromise or ShellError.
  • ShellPromise and ShellError have the constructor types of Promise and Error. The runtime constructors take other arguments.
  • ShellError#info and ShellPromise#cwd() with no argument work at runtime and have no declaration.
  • I filed bun-types: the declarations of $ (Bun Shell) do not match the runtime #44724 for this list. A maintainer closed it, because GitHub issues are for problems that a user ran into. This list is now only here.

The cast from #44614

  • Fix every type error in test/ #44614 merged with ($`echo hello` as any).bytes() at bunshell-instance.test.ts:99. It listed "$.ShellPromise has no bytes()" under the gaps it left, and it chose casts so that a fix of the types breaks nothing.
  • This PR does not remove the cast. The removal changes no runtime behavior: bun build --no-bundle --target=bun gives the same 4,776 bytes for the test with and without it. It can go in a later cleanup.
  • Measured for that cleanup, with the cast removed: tsc 7.0.2 in test/ reports js/bun/shell/bunshell-instance.test.ts(99,30): error TS2339: Property 'bytes' does not exist on type 'ShellPromise'. with the shell.d.ts of main, and no error in that file with this branch.
  • test/ also reads the copy of bun-types that bun install --cwd test puts in test/node_modules. For the run with the shell.d.ts of main, that file was in both places.

Docs

  • The docs section is an addition to the type fix. .arrayBuffer() is also not on the page. This PR leaves it off.
  • Three printed outputs on the same page are wrong. This PR does not change them. Line 70 prints <Buffer 48 65 6c 6c 6f 21 0a>, line 71 prints <Buffer >, and line 455 prints Blob (13 bytes). docs, bun-types: correct 20 examples that do not run as printed #44480 corrects examples of this kind and does not touch this page.

Fixture line

  • The line is below index.ts:322 but not at the end of the file. The branch robobun/4462621c/shell-inherit-stdio appends its checks at the end, and git merge-tree reports a conflict for a second append there. This position merges cleanly with that branch.

Probes (bun 1.4.3-canary 367d939, release build. src/js/builtins/shell.ts has the same JavaScript on main.)

  • Own property names of the ShellPromise prototype: arrayBuffer, blob, bytes, constructor, cwd, env, json, lines, nothrow, quiet, run, text, then, throws.
  • bytes() resolves to a plain Uint8Array. Its buffer is an ArrayBuffer. It equals stdout for nine command shapes, which include a builtin, an external command, a pipeline, empty output, and 108 KB of output.

Also run

  • tsc --noEmit -p for scripts/build, scripts, src/js, src and src/runtime/bake: no output.
  • prettier --check on shell.d.ts and shell.mdx.

Self-review

  • The seven concerns pair into four requests: the Fix every type error in test/ #44614 note, a list of what is not in this PR, no change here to the three wrong outputs, and a statement about .arrayBuffer().
  • The review output was cut off before its concerns about the diff itself. It says that one of them needs a change. I could not read it.

no test proof · iteration 0 · no src or test change; test-proof not applicable

@robobun

robobun commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

Status: ready for review.

Reproduction

  1. On main, add this line to test/integration/bun-types/fixture/index.ts, below line 322:
    expectType(Bun.$`echo hello`.bytes()).is<Promise<Uint8Array<ArrayBuffer>>>();
  2. Run bun test test/integration/bun-types/bun-types.test.ts.
  3. 10 of 22 tests fail with error TS2339: Property 'bytes' does not exist on type 'ShellPromise'.

With this branch, 22 pass.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 26 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: oven-sh/bun/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 1df7fd17-ab65-4e2e-8563-d45f332ede18
📥 Commits

Reviewing files that changed from the base of the PR and between ee5e016 and 54481b6.

📒 Files selected for processing: 3
  • docs/runtime/shell.mdx
  • packages/bun-types/shell.d.ts
  • test/integration/bun-types/fixture/index.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: oven-sh/bun/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: 7f894216-3d1a-4e7f-a2bd-0adffe9ea008
📥 Commits

Reviewing files that changed from the base of the PR and between bd599f5 and ee5e016.

📒 Files selected for processing (3)
  • docs/runtime/shell.mdx
  • packages/bun-types/shell.d.ts
  • test/integration/bun-types/fixture/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.

Walkthrough

The ShellPromise type now declares a bytes() method that returns command output as a Uint8Array. The shell documentation includes an example, and the Bun types fixture checks the return type.

Changes

Shell output bytes API

Layer / File(s) Summary
ShellPromise bytes() method
packages/bun-types/shell.d.ts, docs/runtime/shell.mdx, test/integration/bun-types/fixture/index.ts
ShellPromise declares bytes() as returning Promise<Uint8Array<ArrayBuffer>>. The documentation shows reading command output as bytes, and the fixture asserts the method's return type.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to ee5e0

This adds the missing TypeScript declaration and documentation for existing bytes() behavior, with a fixture check for its return type. No actionable merge risk remains.

Pre-merge checks: Passed 4
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely identifies the main change: declaring bytes() on ShellPromise in bun-types.
Description check Passed The description explains the problem, fix, scope, limitations, and verification results. It does not use the template headings exactly, but it contains the required information for what the PR does an…
Full details: Description check

Explanation

The description explains the problem, fix, scope, limitations, and verification results. It does not use the template headings exactly, but it contains the required information for what the PR does and how it was verified.

  • Autopilot · 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

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

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

Code review found no issues

No high-confidence issues detected in this change.

@robobun
robobun force-pushed the robobun/2f9a6bb7/shell-promise-bytes-type branch from ee5e016 to ab53c08 Compare October 16, 2026 07:33
@robobun

robobun commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 8:40 PM PT - Oct 16th, 2026

⏳ @robobun, your commit 54481b6 is still building in Build #127209, but has 1 failures so far (All Failures):

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

Code review found no issues

No high-confidence issues detected in this change.

@robobun
robobun force-pushed the robobun/2f9a6bb7/shell-promise-bytes-type branch from ab53c08 to 0f2322c Compare October 16, 2026 08:09

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline nit, I also checked the new declaration against the runtime in src/js/builtins/shell.ts: bytes() wraps arrayBuffer() in new Uint8Array(x), so Promise<Uint8Array<ArrayBuffer>> matches, and the example byte counts (6 for hello\n, 13 for Hello World!\n) are correct. The fixture assertion sits below both pinned-diagnostic lines (196, 322), so it does not shift them.

Extended reasoning...

The change adds a bytes() declaration to ShellPromise in packages/bun-types/shell.d.ts, a docs section in docs/runtime/shell.mdx, and one type-level fixture assertion; no runtime or security-sensitive code is touched. The declaration mirrors the existing runtime method, and the ruled-out note records that verification. packages/bun-types/ is covered by a CODEOWNER entry, and the inline finding notes a stale as any cast the description claims was removed, so a maintainer look remains appropriate rather than an automated approval.

Comment thread packages/bun-types/shell.d.ts
The runtime has had ShellPromise.prototype.bytes() since #11104. The
types declared bytes() on ShellOutput and ShellError only, so
`await $`cmd`.bytes()` was a TS2339 error.

Declare it, document it beside .blob() in the shell docs, and add a
type check to the bun-types fixture.
@robobun
robobun force-pushed the robobun/2f9a6bb7/shell-promise-bytes-type branch from 0f2322c to 54481b6 Compare October 17, 2026 03:11

This branch has not been deployed

No deployments
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