Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7360a9a
bundler: create the HTML import manifest on the plugin and in-memory …
robobun Aug 14, 2026
70b34c6
bundler: resolve in-memory imports through the same path as files on …
robobun Aug 14, 2026
70af9ef
bundler: register the manifest module at each call site instead of in…
robobun Aug 14, 2026
361a1c4
bundler: shorten the HTML import helper docs
robobun Aug 14, 2026
aa0a705
bundler: leave the import record's kind alone when binding it to a ma…
robobun Aug 14, 2026
cfd54fa
bundler: resolve a relative `files` key against the cwd in FileMap::put
robobun Oct 23, 2026
1821799
bundler: cut the `files` change down to the key rule
robobun Oct 24, 2026
da2faca
docs: say what two spellings of one `files` key do
robobun Oct 24, 2026
151e309
Merge branch 'main' into farm/30313fcf/html-import-plugin-resolve
robobun Oct 24, 2026
d332760
bundler: copy the jsx options of an in-memory import only for a new m…
robobun Oct 24, 2026
278bf63
test: run the server bundle of an in-memory HTML import
robobun Oct 24, 2026
fe96dce
bundler: keep only the `files` route of the HTML import manifest fix
robobun Oct 25, 2026
e8ee882
bundler: move the resolve result once per import record
robobun Oct 25, 2026
3e5ddbb
test: accept the Windows form of a manifest `input` for a `files` key
robobun Oct 25, 2026
615748e
test: run the two Bun.serve cases of an in-memory page concurrently
robobun Oct 25, 2026
c84ec3a
bundler: send a `files` hit through the shared steps of `resolve_impo…
robobun Oct 25, 2026
978a5e9
bundler: keep the path from the root for a `[dir]` directory that is …
robobun Oct 25, 2026
47a5a20
bundler: limit the `files` key rule to builds that have a `./` or `..…
robobun Oct 25, 2026
d3663aa
test: pin the Windows form of a manifest `input` for a `files` key
robobun Oct 25, 2026
2cf6121
bundler: take the `files` change of #38605 as it is now
robobun Oct 25, 2026
1e7729a
docs: name the absolute path of a `files` file in the default root rule
robobun Oct 25, 2026
370b4ee
Merge the branch of #38605 (farm/30313fcf/html-import-plugin-resolve)…
robobun Oct 25, 2026
3ed147a
bundler: name the output of a `./` key by its path from the cwd
robobun Oct 25, 2026
26de674
test: keep the name of the test for an absolute key as it is on main
robobun Oct 25, 2026
c71a44a
bundler: send an absolute entry point of a `./` key to the disk resolver
robobun Oct 25, 2026
e90d269
bundler: keep builds with no `./` key as they are on main
robobun Oct 25, 2026
4331347
bundler: add `file_map` to the field list of `LinkerContext::load` on…
robobun Oct 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/bundler/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ A map of file paths to their contents for in-memory bundling: bundle virtual fil

You can provide file contents as a `string`, `Blob`, `TypedArray`, or `ArrayBuffer`.

A key that starts with `./` or `../` names the file at that path from the current working directory of the `Bun.build()` call. In a key, `\` is the same as `/`: `.\a.ts` and `./a.ts` are one key, and the last one wins. If two keys name one file in different ways (`./a.ts` and `./lib/../a.ts`) and have different contents, `Bun.build()` throws a `TypeError`. Bun uses an absolute key as written, so write it the way `path.resolve()` returns it.

#### Bundle entirely from memory

You can bundle code without any files on disk by providing all sources in `files`:
Expand All @@ -251,7 +253,7 @@ const output = await result.outputs[0].text();
console.log(output);
```

When all entrypoints are in the `files` map, Bun uses the current working directory as the root.
When every entrypoint is written exactly like a key of `files`, Bun uses the current working directory as the root.

#### Override files on disk

Expand Down
8 changes: 8 additions & 0 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3607,6 +3607,14 @@ declare module "bun" {
* the contents of files that do exist on disk. The keys are file paths (which should
* match how they're imported) and the values are the file contents.
*
* A key that starts with `./` or `../` names the file at that path from
* the current working directory of the `Bun.build()` call. In a key, `\`
* is the same as `/`: `.\a.ts` and `./a.ts` are one key, and the last one
* wins. If two keys name one file in different ways (`./a.ts` and
* `./lib/../a.ts`) and have different contents, `Bun.build()` throws a
* `TypeError`. Bun uses an absolute key as written, so write it the way
* `path.resolve()` returns it.
*
* File contents can be provided as:
* - `string` - The source code as a string
* - `Blob` - A Blob containing the source code
Expand Down
6 changes: 5 additions & 1 deletion src/bundler/LinkerContext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,11 @@ impl<'a> LinkerContext<'a> {
// Note: `Path::assert_pretty_is_valid` lives on the
// resolver-side `Path<'a>`; the logger `Path` has no
// such debug hook yet.
debug_assert!(source.path.text.as_ptr() != source.path.pretty.as_ptr());
// A name in `Bun.build`'s `files` is its own display path.
debug_assert!(
source.path.text.as_ptr() != source.path.pretty.as_ptr()
|| !bun_paths::is_absolute(source.path.text)
);

break 'brk source.path.pretty;
} else {
Expand Down
714 changes: 572 additions & 142 deletions src/bundler/bundle_v2.rs

Large diffs are not rendered by default.

27 changes: 12 additions & 15 deletions src/runtime/api/JSBundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) mod js_bundler {
}

/// A map of file paths to their in-memory contents.
/// LAYERING: the data-only struct (`map: StringHashMap<Box<[u8]>>`) and
/// LAYERING: the struct, `put` and
/// `get`/`contains`/`resolve` live in `bun_bundler::bundle_v2` so the
/// bundler thread can read it without depending on `bun_runtime`. Only
/// the JS-aware `from_js` constructor lives here.
Expand All @@ -55,7 +55,7 @@ pub(crate) mod js_bundler {
/// The bytes are copied: the bundler runs on a separate thread and must not
/// borrow JS heap memory.
fn file_map_from_js(global_this: &JSGlobalObject, files_value: JSValue) -> JsResult<FileMap> {
let mut this = FileMap::default();
let mut this = FileMap::new(bun_resolver::fs::FileSystem::get().top_level_dir());
Comment thread
robobun marked this conversation as resolved.
Resolved
// errdefer this.deinit() — `FileMap` (Box<[u8]> values) drops on `?`.

let Some(files_obj) = files_value.get_object() else {
Expand All @@ -74,7 +74,7 @@ pub(crate) mod js_bundler {
},
)?;

this.map.reserve(files_iter.len);
this.reserve(files_iter.len);

while let Some((prop, property_value)) = files_iter.next()? {
let blob_or_string = match crate::node::BlobOrStringOrBuffer::from_js(
Expand All @@ -90,17 +90,14 @@ pub(crate) mod js_bundler {
let bytes: Box<[u8]> = blob_or_string.slice().into();
drop(blob_or_string);

// Clone the key since we need to own it.
let mut key = prop.to_owned_slice();

// Normalize backslashes to forward slashes for cross-platform consistency.
// Use dangerouslyConvertPathToPosixInPlace which always converts \ to /
// (uses sep_windows constant, not sep which varies by target).
bun_paths::resolve_path::dangerously_convert_path_to_posix_in_place::<u8>(
key.as_mut_slice(),
);

this.map.put_assume_capacity(&key, bytes);
if let Err(conflict) = this.put(prop.to_owned_slice(), bytes) {
return Err(global_this.throw_invalid_arguments(format_args!(
"files: the keys \"{}\" and \"{}\" both name \"{}\" and have different contents",
bstr::BStr::new(&conflict.other),
prop,
bstr::BStr::new(&conflict.path),
)));
}
}

Ok(this)
Expand Down Expand Up @@ -1012,7 +1009,7 @@ pub(crate) mod js_bundler {
let entry_points = this.entry_points.keys();

// Check if all entry points are in the FileMap - if so, use cwd
if !this.files.map.is_empty() {
if !this.files.is_empty() {
let mut all_in_filemap = true;
for ep in entry_points {
if !this.files.contains(ep) {
Comment thread
robobun marked this conversation as resolved.
Resolved
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/api/js_bundle_completion_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ impl CompletionStruct for JSBundleCompletionTask {
}
fn file_map(&mut self) -> Option<NonNull<Bv2FileMap>> {
// `FileMap` and `Bv2FileMap` are the same `bun_bundler` type.
if self.config.files.map.is_empty() {
if self.config.files.is_empty() {
None
} else {
Some(NonNull::from(&mut self.config.files))
Expand Down
Loading
Loading