Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docs/bundler/esbuild.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ In Bun's CLI, boolean flags like `--minify` take no argument. Flags that take on
| `--packages` | `--packages` | No differences |
| `--platform` | `--target` | Renamed to `--target` for consistency with tsconfig. Does not support `neutral`. |
| `--serve` | n/a | Not applicable |
| `--sourcemap` | `--sourcemap` | Supports `linked` (the default when no value is given), `external`, `inline`, and `none`. Does not support esbuild's `both`. |
| `--sourcemap` | `--sourcemap` | Supports `linked`, `external`, `inline`, and `none`. With no value: `linked` when writing to disk, `inline` when writing to stdout (same as esbuild). `linked` and `external` require `--outdir` or `--outfile`. Does not support esbuild's `both`. |
| `--splitting` | `--splitting` | No differences |
| `--target` | n/a | Not supported. Bun's bundler performs no syntactic down-leveling. |
| `--watch` | `--watch` | No differences |
Expand Down
12 changes: 6 additions & 6 deletions docs/bundler/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,12 @@ Specifies the type of sourcemap to generate.
</Tab>
</Tabs>

| Value | Description |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `"none"` | Default. No sourcemap is generated. |
| `"linked"` | A separate `*.js.map` file is created alongside each `*.js` bundle using a `//# sourceMappingURL` comment to link the two. Requires `--outdir` to be set. You can customize the base URL in this comment with `--public-path`.<br/><br/>`js<br/>// <bundled code here><br/><br/>//# sourceMappingURL=bundle.js.map<br/>` |
| `"external"` | A separate `*.js.map` file is created alongside each `*.js` bundle without inserting a `//# sourceMappingURL` comment.<br/><br/>Generated bundles contain a debug id that can be used to associate a bundle with its corresponding sourcemap. This `debugId` is added as a comment at the bottom of the file.<br/><br/>`js<br/>// <generated bundle code><br/><br/>//# debugId=<DEBUG ID><br/>` |
| `"inline"` | A sourcemap is generated and appended to the end of the generated bundle as a base64 payload.<br/><br/>`js<br/>// <bundled code here><br/><br/>//# sourceMappingURL=data:application/json;base64,<encoded sourcemap here><br/>` |
| Value | Description |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `"none"` | Default. No sourcemap is generated. |
| `"linked"` | A separate `*.js.map` file is created alongside each `*.js` bundle using a `//# sourceMappingURL` comment to link the two. Requires `--outdir` or `--outfile`. You can customize the base URL in this comment with `--public-path`.<br/><br/>`js<br/>// <bundled code here><br/><br/>//# sourceMappingURL=bundle.js.map<br/>` |
| `"external"` | A separate `*.js.map` file is created alongside each `*.js` bundle without inserting a `//# sourceMappingURL` comment. Requires `--outdir` or `--outfile`.<br/><br/>Generated bundles contain a debug id that can be used to associate a bundle with its corresponding sourcemap. This `debugId` is added as a comment at the bottom of the file.<br/><br/>`js<br/>// <generated bundle code><br/><br/>//# debugId=<DEBUG ID><br/>` |
| `"inline"` | A sourcemap is generated and appended to the end of the generated bundle as a base64 payload.<br/><br/>`js<br/>// <bundled code here><br/><br/>//# sourceMappingURL=data:application/json;base64,<encoded sourcemap here><br/>` |

The associated `*.js.map` sourcemap is a JSON file containing an equivalent `debugId` property.

Expand Down
4 changes: 2 additions & 2 deletions src/bundler/aot/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn report_unsupported_options(options: &BundleOptions<'_>, log: &mut Log) -> boo
loaders: _, jsx: _, react_compiler: _, react_compiler_filter: _, root_dir: _, preserve_symlinks: _,
tsconfig_override: _, main_fields: _, transform_options: _, external: _, packages: _,
extension_order: _, main_field_extension_order: _, no_macros: _, custom_conditions: _,
entry_naming: _, compile_entry_point_name: _, force_node_env: _,
entry_naming: _, entry_point_file_name: _, force_node_env: _,
emit_decorator_metadata: _, experimental_decorators: _, use_define_for_class_fields: _,
define: _, drop: _, bundler_feature_flags: _, asset_naming: _,
auto_import_jsx: _, allow_runtime: _,
Expand Down Expand Up @@ -628,7 +628,7 @@ pub(crate) fn embedded_entry_point_names(
root_directory: &[u8],
log: &mut Log,
) -> Option<Vec<Vec<u8>>> {
let compile_name = Some(&options.compile_entry_point_name[..]).filter(|name| !name.is_empty());
let compile_name = Some(&options.entry_point_file_name[..]).filter(|name| !name.is_empty());
let mut template = output_name_template(&options.entry_naming);
let names = entry_points
.iter()
Expand Down
2 changes: 1 addition & 1 deletion src/bundler/aot/options/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fn set_framework(options: &mut BundleOptions<'_>) {

fn set_root_and_compile_name(options: &mut BundleOptions<'_>) {
options.root_dir = Box::from(&b"src"[..]);
options.compile_entry_point_name = Box::from(&b"app"[..]);
options.entry_point_file_name = Box::from(&b"app"[..]);
}

#[test]
Expand Down
38 changes: 24 additions & 14 deletions src/bundler/linker_context/computeChunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,17 @@ pub(crate) fn compute_chunks<'a>(
let output_paths = this.graph.entry_points.items_output_path();
// re-borrow after `find_all_imported_parts_in_js_order` released `&mut this`.
let ast_targets = this.graph.ast.items_target();
let mut compile_entry_point_pending =
!bv2.transpiler().options.compile_entry_point_name.is_empty();
let is_executable = this.options.compile_mode.is_executable();
let mut entry_point_file_name_pending =
!bv2.transpiler().options.entry_point_file_name.is_empty();
// The chunks that `--entry-naming` names.
let takes_entry_naming = |chunk: &Chunk| {
chunk.entry_point.is_entry_point()
&& (matches!(chunk.content, chunk::Content::Html)
|| (kinds[chunk.entry_point.source_index() as usize]
== crate::EntryPoint::Kind::UserSpecified
&& !chunk.flags.contains(chunk::Flags::HAS_HTML_CHUNK)))
};
for (chunk_id, chunk) in chunks.iter_mut().enumerate() {
// Assign a unique key to each chunk. This key encodes the index directly so
// we can easily recover it later without needing to look it up in a map. The
Expand Down Expand Up @@ -605,28 +614,29 @@ pub(crate) fn compute_chunks<'a>(
this.unique_key_prefix = chunk.unique_key[..prefix_len].into();
}

// The same file that `StandaloneModuleGraph::to_bytes` embeds as the entry point.
if compile_entry_point_pending
&& this.chunk_output_kind(chunk) == OutputKind::EntryPoint
&& this.chunk_side(chunk) == Side::Server
if entry_point_file_name_pending
&& if is_executable {
// The same file that `StandaloneModuleGraph::to_bytes` embeds as the entry point.
this.chunk_output_kind(chunk) == OutputKind::EntryPoint
&& this.chunk_side(chunk) == Side::Server
} else {
// `--outfile`: a build that writes one file has one such chunk.
takes_entry_naming(chunk)
}
{
compile_entry_point_pending = false;
entry_point_file_name_pending = false;
// The name is a placeholder value, so a `[name]` or `[hash]` in it is never expanded.
chunk.template = PathTemplate {
data: Box::from(&b"./[name]"[..]),
placeholder: Placeholder {
name: bv2.transpiler().options.compile_entry_point_name.clone(),
name: bv2.transpiler().options.entry_point_file_name.clone(),
..Default::default()
},
};
continue;
}

if chunk.entry_point.is_entry_point()
&& (matches!(chunk.content, chunk::Content::Html)
|| (kinds[chunk.entry_point.source_index() as usize]
== crate::EntryPoint::Kind::UserSpecified
&& !chunk.flags.contains(chunk::Flags::HAS_HTML_CHUNK)))
{
if takes_entry_naming(chunk) {
// Use fileWithTarget template if there are HTML imports and user hasn't manually set naming
if has_server_html_imports && bv2.transpiler().options.entry_naming.is_empty() {
chunk.template = PathTemplate::FILE_WITH_TARGET.into();
Expand Down
9 changes: 5 additions & 4 deletions src/bundler/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,8 +1465,8 @@ pub struct BundleOptions<'a> {
pub debugger: bool,

pub compile_mode: CompileMode,
/// `--compile`: the name of the entry point's chunk, `/$bunfs/root/<name>` in the executable.
pub compile_entry_point_name: Box<[u8]>,
/// The file name `--outfile` or `--compile` gives the entry point's chunk, as written: it is not a naming template.
pub entry_point_file_name: Box<[u8]>,
pub metafile: bool,
/// Path to write JSON metafile (for Bun.build API)
pub metafile_json_path: Box<[u8]>,
Expand Down Expand Up @@ -1678,7 +1678,8 @@ impl<'a> BundleOptions<'a> {
code_coverage: self.code_coverage,
debugger: self.debugger,
compile_mode: self.compile_mode,
compile_entry_point_name: self.compile_entry_point_name.clone(),
// Only the parent names output files (`compute_chunks`, `transform_only_dest_path`).
entry_point_file_name: Box::default(),
metafile: self.metafile,
metafile_json_path: self.metafile_json_path.clone(),
metafile_markdown_path: self.metafile_markdown_path.clone(),
Expand Down Expand Up @@ -1934,7 +1935,7 @@ impl<'a> BundleOptions<'a> {
code_coverage: false,
debugger: false,
compile_mode: CompileMode::None,
compile_entry_point_name: Box::default(),
entry_point_file_name: Box::default(),
metafile: false,
metafile_json_path: Box::default(),
metafile_markdown_path: Box::default(),
Expand Down
4 changes: 4 additions & 0 deletions src/bundler/transpiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3028,6 +3028,10 @@ impl<'a> Transpiler<'a> {
loader: options::Loader,
output: &[u8],
) -> Box<[u8]> {
if !self.options.entry_point_file_name.is_empty() {
return self.options.entry_point_file_name.clone();
}

let rel_to_root = bun_paths::resolve_path::relative_platform::<
bun_paths::resolve_path::platform::Auto,
false,
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 @@ -1252,7 +1252,7 @@ impl CompletionStruct for JSBundleCompletionTask {
}
if let Some(compile) = &config.compile {
let executable = executable_path(config, compile);
transpiler.options.compile_entry_point_name =
transpiler.options.entry_point_file_name =
Box::from(executable_entry_point_name(&executable));
}
// `BundleOptions.{banner,footer}` are `Cow<'static, [u8]>`; clone into
Expand Down
11 changes: 9 additions & 2 deletions src/runtime/cli/Arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3170,8 +3170,15 @@ fn parse_build_command_options(

if let Some(setting) = args.option(b"--sourcemap") {
if setting.is_empty() {
// In the future, Bun is going to make this default to .linked
opts.source_map = Some(api::SourceMapMode::Linked);
// Same rule as `Bun.build({ sourcemap: true })`.
let writes_to_disk = ctx.bundler_options.compile
|| !ctx.bundler_options.outdir.is_empty()
|| !ctx.bundler_options.outfile.is_empty();
opts.source_map = Some(if writes_to_disk {
api::SourceMapMode::Linked
} else {
api::SourceMapMode::Inline
});
} else if setting == b"inline" {
opts.source_map = Some(api::SourceMapMode::Inline);
} else if setting == b"none" {
Expand Down
Loading
Loading