mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
feat(cli): use deno fmt for lock and coverage files (#13018)
This commit is contained in:
parent
5c0636888c
commit
b51b0c834b
3 changed files with 12 additions and 4 deletions
|
@ -12,6 +12,8 @@ use std::path::PathBuf;
|
|||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::tools::fmt::format_json;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Lockfile {
|
||||
write: bool,
|
||||
|
@ -42,13 +44,15 @@ impl Lockfile {
|
|||
}
|
||||
let j = json!(&self.map);
|
||||
let s = serde_json::to_string_pretty(&j).unwrap();
|
||||
|
||||
let format_s = format_json(&s, &Default::default()).unwrap_or(s);
|
||||
let mut f = std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(&self.filename)?;
|
||||
use std::io::Write;
|
||||
f.write_all(s.as_bytes())?;
|
||||
f.write_all(format_s.as_bytes())?;
|
||||
debug!("lockfile write {}", self.filename.display());
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use crate::flags::Flags;
|
|||
use crate::fs_util::collect_files;
|
||||
use crate::proc_state::ProcState;
|
||||
use crate::source_maps::SourceMapGetter;
|
||||
use crate::tools::fmt::format_json;
|
||||
|
||||
use deno_ast::swc::common::Span;
|
||||
use deno_ast::MediaType;
|
||||
|
@ -158,8 +159,11 @@ impl CoverageCollector {
|
|||
let filepath = self.dir.join(filename);
|
||||
|
||||
let mut out = BufWriter::new(File::create(filepath)?);
|
||||
serde_json::to_writer_pretty(&mut out, &script_coverage)?;
|
||||
out.write_all(b"\n")?;
|
||||
let coverage = serde_json::to_string(&script_coverage)?;
|
||||
let formated_coverage =
|
||||
format_json(&coverage, &Default::default()).unwrap_or(coverage);
|
||||
|
||||
out.write_all(formated_coverage.as_bytes())?;
|
||||
out.flush()?;
|
||||
}
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ fn format_markdown(
|
|||
/// Formats JSON and JSONC using the rules provided by .deno()
|
||||
/// of configuration builder of <https://github.com/dprint/dprint-plugin-json>.
|
||||
/// See <https://git.io/Jt4ht> for configuration.
|
||||
fn format_json(
|
||||
pub fn format_json(
|
||||
file_text: &str,
|
||||
fmt_options: &FmtOptionsConfig,
|
||||
) -> Result<String, String> {
|
||||
|
|
Loading…
Reference in a new issue