Skip to content

Conversation

@robobun
Copy link
Collaborator

@robobun robobun commented Dec 8, 2025

Summary

  • Expanded documentation for embedding files in single-file executables with with { type: "file" }
  • Added clear explanation of how the import attribute works and path transformation at build time
  • Added examples for reading embedded files with both Bun.file() and Node.js fs APIs
  • Added practical examples: JSON configs, HTTP static assets, templates, binary files (WASM, fonts)
  • Improved Bun.embeddedFiles section with a dynamic asset server example

Test plan

  • Verified all code examples compile and run correctly with bun build --compile
  • Tested Bun.file() reads embedded files correctly
  • Tested node:fs APIs (readFileSync, promises.readFile, stat) work with embedded files
  • Tested Bun.embeddedFiles returns correct blob array
  • Tested --asset-naming flag removes content hashes

🤖 Generated with Claude Code

@robobun
Copy link
Collaborator Author

robobun commented Dec 8, 2025

Updated 4:42 PM PT - Dec 7th, 2025

@autofix-ci[bot], your commit 35f7f64bbf8124dac57d631ccaab769adc5ba447 passed in Build #33003! 🎉


🧪   To try this PR locally:

bunx bun-pr 25408

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

bun-25408 --bun

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Walkthrough

Expanded the "Embed assets & files" documentation in the executables guide with comprehensive step-by-step instructions, detailed explanations of the embedding mechanism, and practical examples including configuration files, static assets, templates, and binary files. Added clarifications about Bun.embeddedFiles and embedded file listing.

Changes

Cohort / File(s) Change Summary
Documentation restructuring
docs/bundler/executables.mdx
Expanded "Embed assets & files" section with step-by-step guide, detailed embedding mechanism explanation, multiple reading methods, practical examples (JSON configs, static assets, templates, binary files, SQLite databases, N-API addons, directories), and Bun.embeddedFiles clarifications

Possibly related PRs

Suggested reviewers

  • alii
  • RiskyMH

Pre-merge checks

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: expanding documentation for single-file executable file embedding, which directly matches the PR's primary objective.
Description check ✅ Passed The PR description provides a detailed summary of changes and a comprehensive test plan, exceeding the basic template requirements with thorough verification details.

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

Add comprehensive documentation for embedding files with `with { type: "file" }`:

- Explain how the import attribute works and path transformation
- Show reading embedded files with Bun.file() (arrayBuffer, text, blob)
- Show reading embedded files with Node.js fs APIs (readFileSync, promises.readFile, stat)
- Add practical examples: JSON configs, HTTP static assets, templates, binary files
- Improve Bun.embeddedFiles section with dynamic asset server example
- Add note about source code exclusion from embeddedFiles

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9c96937 and 35f7f64.

📒 Files selected for processing (1)
  • docs/bundler/executables.mdx (2 hunks)
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/building-bun.mdc:0-0
Timestamp: 2025-11-24T18:34:55.173Z
Learning: Applies to src/**/*.{cpp,zig} : Execute files using `bun bd <file> <...args>`; never use `bun <file>` directly as it will not include your changes
📚 Learning: 2025-11-14T16:07:01.064Z
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24719
File: docs/bundler/executables.mdx:527-560
Timestamp: 2025-11-14T16:07:01.064Z
Learning: In the Bun repository, certain bundler features like compile with code splitting (--compile --splitting) are CLI-only and not supported in the Bun.build() JavaScript API. Tests for CLI-only features use backend: "cli" flag (e.g., test/bundler/bundler_compile_splitting.test.ts). The CompileBuildConfig interface correctly restricts these with splitting?: never;. When documenting CLI-only bundler features, add a note clarifying they're not available via the programmatic API.

Applied to files:

  • docs/bundler/executables.mdx
📚 Learning: 2025-11-24T18:37:11.466Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:11.466Z
Learning: Write JS builtins for Bun's Node.js compatibility and APIs, and run `bun bd` after changes

Applied to files:

  • docs/bundler/executables.mdx
📚 Learning: 2025-11-13T07:23:11.159Z
Learnt from: RiskyMH
Repo: oven-sh/bun PR: 24668
File: docs/quickstart.mdx:181-197
Timestamp: 2025-11-13T07:23:11.159Z
Learning: In Bun.serve's routes configuration, imported HTML files can be assigned directly to routes without wrapping them in a function that returns a Response. For example, `import index from './index.html'` followed by `"/": index` in the routes object is valid Bun syntax for serving HTML content.

Applied to files:

  • docs/bundler/executables.mdx
📚 Learning: 2025-10-15T04:01:16.478Z
Learnt from: AmanVarshney01
Repo: oven-sh/bun PR: 23580
File: docs/guides/ecosystem/prisma.md:21-26
Timestamp: 2025-10-15T04:01:16.478Z
Learning: For Prisma with Bun runtime and Rust-free client (engineType "client"), when using local SQLite files (file:// URLs), use either prisma/adapter-better-sqlite3 or the Bun-native synapsenwerkstatt/prisma-bun-sqlite-adapter. The prisma/adapter-libsql adapter is only for remote libSQL/Turso endpoints and will not work with local SQLite file URLs.

Applied to files:

  • docs/bundler/executables.mdx
📚 Learning: 2025-10-19T02:52:37.412Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/tsconfig.json:1-15
Timestamp: 2025-10-19T02:52:37.412Z
Learning: In the Bun repository, packages under packages/ (e.g., bun-otel) can follow a TypeScript-first pattern where package.json exports point directly to .ts files (not compiled .js files). Bun natively runs TypeScript, so consumers import .ts sources directly and receive full type information without needing compiled .d.ts declaration files. For such packages, adding "declaration": true or "outDir" in tsconfig.json is unnecessary and would break the export structure.
<!-- [remove_learning]
ceedde95-980e-4898-a2c6-40ff73913664

Applied to files:

  • docs/bundler/executables.mdx
📚 Learning: 2025-11-24T18:34:55.173Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/building-bun.mdc:0-0
Timestamp: 2025-11-24T18:34:55.173Z
Learning: Applies to src/**/*.{cpp,zig} : Execute files using `bun bd <file> <...args>`; never use `bun <file>` directly as it will not include your changes

Applied to files:

  • docs/bundler/executables.mdx
📚 Learning: 2025-10-19T02:44:46.354Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/context-propagation.test.ts:1-1
Timestamp: 2025-10-19T02:44:46.354Z
Learning: In the Bun repository, standalone packages under packages/ (e.g., bun-vscode, bun-inspector-protocol, bun-plugin-yaml, bun-plugin-svelte, bun-debug-adapter-protocol, bun-otel) co-locate their tests with package source code using *.test.ts files. This follows standard npm/monorepo patterns. The test/ directory hierarchy (test/js/bun/, test/cli/, test/js/node/) is reserved for testing Bun's core runtime APIs and built-in functionality, not standalone packages.

Applied to files:

  • docs/bundler/executables.mdx
📚 Learning: 2025-11-24T18:37:30.259Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: test/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:37:30.259Z
Learning: Applies to test/**/*.test.{ts,js,jsx,tsx,mjs,cjs} : Use `bun:test` with files that end in `*.test.{ts,js,jsx,tsx,mjs,cjs}`

Applied to files:

  • docs/bundler/executables.mdx
📚 Learning: 2025-10-08T13:56:00.875Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 23373
File: src/bun.js/api/BunObject.zig:2514-2521
Timestamp: 2025-10-08T13:56:00.875Z
Learning: For Bun codebase: prefer using `bun.path` utilities (e.g., `bun.path.joinAbsStringBuf`, `bun.path.join`) over `std.fs.path` functions for path operations.

Applied to files:

  • docs/bundler/executables.mdx
📚 Learning: 2025-11-24T18:35:39.205Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/registering-bun-modules.mdc:0-0
Timestamp: 2025-11-24T18:35:39.205Z
Learning: Reference existing modules like Valkey, S3Client, or SQLite as guides when implementing new Bun features

Applied to files:

  • docs/bundler/executables.mdx
🪛 LanguageTool
docs/bundler/executables.mdx

[style] ~570-~570: Try using a synonym here to strengthen your writing.
Context: ...ing embedded files Bun.embeddedFiles gives you access to all embedded files as Blob ...

(GIVE_PROVIDE)

🔇 Additional comments (1)
docs/bundler/executables.mdx (1)

385-620: Excellent expansion of embedding documentation with clear examples and explanations.

The restructured section is well-organized and comprehensive:

  • The "How it works" explanation clearly describes the path transformation mechanism at build time
  • Separate subsections for Bun.file() and Node.js fs APIs address both use cases
  • Practical examples (JSON config, static assets, templates, binary files) are concrete and immediately useful
  • The dynamic asset server example (lines 596–616) effectively demonstrates real-world usage of Bun.embeddedFiles
  • The Note clarifying that source files are excluded from embeddedFiles adds important context for developers concerned about source protection

All code examples follow Bun's documented patterns correctly, including proper import attribute syntax and the correct type signature (ReadonlyArray<Blob>).

### Listing embedded files

To get a list of all embedded files, use `Bun.embeddedFiles`:
`Bun.embeddedFiles` gives you access to all embedded files as `Blob` objects:
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Strengthen the writing with a more precise verb.

The phrase "gives you access to" is slightly redundant. Consider using "provides" for more direct phrasing.

-`Bun.embeddedFiles` gives you access to all embedded files as `Blob` objects:
+`Bun.embeddedFiles` provides access to all embedded files as `Blob` objects:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
`Bun.embeddedFiles` gives you access to all embedded files as `Blob` objects:
`Bun.embeddedFiles` provides access to all embedded files as `Blob` objects:
🧰 Tools
🪛 LanguageTool

[style] ~570-~570: Try using a synonym here to strengthen your writing.
Context: ...ing embedded files Bun.embeddedFiles gives you access to all embedded files as Blob ...

(GIVE_PROVIDE)

🤖 Prompt for AI Agents
In docs/bundler/executables.mdx around line 570, the phrase "gives you access
to" is wordy; replace it with a more precise verb such as "provides" (e.g.,
"Bun.embeddedFiles provides all embedded files as `Blob` objects" or "provides
access to all embedded files as `Blob` objects") to tighten the wording while
preserving the original meaning.

@Jarred-Sumner Jarred-Sumner merged commit 3af0d23 into main Dec 8, 2025
7 checks passed
@Jarred-Sumner Jarred-Sumner deleted the claude/docs-embed-files-expanded branch December 8, 2025 02:43
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.

3 participants