summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2020-05-08 03:39:00 +0900
committerGitHub <noreply@github.com>2020-05-07 14:39:00 -0400
commit93cf3bd5341d5985201ea0905280082d5a3310f9 (patch)
tree1eac1afa8813e00cb47b0051b73c987889b086d2
parent9a8d94842044c5d91ce8ac09ed96c0e184d842b2 (diff)
feat: format deno bundle output (#5139)
-rw-r--r--cli/compilers/ts.rs7
-rw-r--r--cli/fmt.rs7
-rw-r--r--cli/tests/bundle.test.out14
3 files changed, 21 insertions, 7 deletions
diff --git a/cli/compilers/ts.rs b/cli/compilers/ts.rs
index 77297713e..db4313927 100644
--- a/cli/compilers/ts.rs
+++ b/cli/compilers/ts.rs
@@ -7,6 +7,7 @@ use crate::diagnostics::DiagnosticItem;
use crate::disk_cache::DiskCache;
use crate::file_fetcher::SourceFile;
use crate::file_fetcher::SourceFileFetcher;
+use crate::fmt;
use crate::fs as deno_fs;
use crate::global_state::GlobalState;
use crate::msg;
@@ -343,17 +344,19 @@ impl TsCompiler {
return Err(ErrBox::from(bundle_response.diagnostics));
}
+ let output_string = fmt::format_text(&bundle_response.bundle_output)?;
+
if let Some(out_file_) = out_file.as_ref() {
eprintln!("Emitting bundle to {:?}", out_file_);
- let output_bytes = bundle_response.bundle_output.as_bytes();
+ let output_bytes = output_string.as_bytes();
let output_len = output_bytes.len();
deno_fs::write_file(out_file_, output_bytes, 0o666)?;
// TODO(bartlomieju): add "humanFileSize" method
eprintln!("{} bytes emmited.", output_len);
} else {
- println!("{}", bundle_response.bundle_output);
+ println!("{}", output_string);
}
Ok(())
diff --git a/cli/fmt.rs b/cli/fmt.rs
index 74d3d0eea..9b6e5975d 100644
--- a/cli/fmt.rs
+++ b/cli/fmt.rs
@@ -171,6 +171,13 @@ fn format_stdin(check: bool) -> Result<(), ErrBox> {
Ok(())
}
+/// Formats the given source text
+pub fn format_text(source: &str) -> Result<String, ErrBox> {
+ dprint::Formatter::new(get_config())
+ .format_text(&PathBuf::from("_tmp.ts"), &source)
+ .map_err(|e| OpError::other(e).into())
+}
+
fn files_str(len: usize) -> &'static str {
if len == 1 {
"file"
diff --git a/cli/tests/bundle.test.out b/cli/tests/bundle.test.out
index b286dad48..c3e12e8a9 100644
--- a/cli/tests/bundle.test.out
+++ b/cli/tests/bundle.test.out
@@ -6,13 +6,17 @@ let System, __instantiateAsync, __instantiate;
})();
System.register("print_hello", [], function (exports_1, context_1) {
-[WILDCARD]
-});
-System.register("subdir2/mod2", ["print_hello"], function (exports_2, context_2) {
-[WILDCARD]
+ [WILDCARD]
});
+System.register(
+ "subdir2/mod2",
+ ["print_hello"],
+ function (exports_2, context_2) {
+ [WILDCARD]
+ },
+);
System.register("mod1", ["subdir2/mod2"], function (exports_3, context_3) {
-[WILDCARD]
+ [WILDCARD]
});
const __exp = __instantiate("mod1");