summaryrefslogtreecommitdiff
path: root/cli/tools/bundle.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools/bundle.rs')
-rw-r--r--cli/tools/bundle.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs
index 375a64088..a248c0385 100644
--- a/cli/tools/bundle.rs
+++ b/cli/tools/bundle.rs
@@ -147,12 +147,29 @@ fn bundle_module_graph(
}
}
- deno_emit::bundle_graph(
+ let mut output = deno_emit::bundle_graph(
graph,
deno_emit::BundleOptions {
bundle_type: deno_emit::BundleType::Module,
emit_options: ts_config_result.ts_config.into(),
emit_ignore_directives: true,
},
- )
+ )?;
+
+ // todo(https://github.com/denoland/deno_emit/issues/85): move to deno_emit
+ if let Some(shebang) = shebang_file(graph) {
+ output.code = format!("{}\n{}", shebang, output.code);
+ }
+
+ Ok(output)
+}
+
+fn shebang_file(graph: &deno_graph::ModuleGraph) -> Option<String> {
+ let source = graph.get(&graph.roots[0].0)?.maybe_source.as_ref()?;
+ let first_line = source.lines().next()?;
+ if first_line.starts_with("#!") {
+ Some(first_line.to_string())
+ } else {
+ None
+ }
}