diff options
author | Fenix <zhuzhenfeng1993@hotmail.com> | 2023-01-04 00:19:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 16:19:28 +0000 |
commit | 501472f06ba52d46611bd1ffd8bf4fe9de94425d (patch) | |
tree | da7ed8162becc75d5e848033341f74f610db3ff2 /cli/tools/bundle.rs | |
parent | 7716449d41bef9c41b8de7e16341cbe8b253a6da (diff) |
fix(cli): bundle command support shebang file (#17113)
Diffstat (limited to 'cli/tools/bundle.rs')
-rw-r--r-- | cli/tools/bundle.rs | 21 |
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 + } } |