From 6b95c53e48a2622f4f2b6fdfa6c2c26dc30bbba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 26 Mar 2024 21:40:24 +0000 Subject: feat(add): always produce multiline config file (#23077) This commit changes `deno add` to always produce a multiline config file. In v1.41.3: ``` $ mkdir foo $ cd foo $ deno add @std/assert Created deno.json configuration file. Add @std/assert - jsr:@std/assert@^0.220.0 $ cat deno.json { "imports": { "@std/assert": "jsr:@std/assert@^0.220.0" } } ``` Now: ``` $ mkdir foo $ cd foo $ deno add @std/assert Created deno.json configuration file. Add @std/assert - jsr:@std/assert@^0.220.0 $ cat deno.json { "imports": { "@std/assert": "jsr:@std/assert@^0.220.0" } } ``` --- cli/tools/registry/pm.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'cli/tools') diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index 8a0a53c9a..a69a474e7 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -268,7 +268,15 @@ fn update_config_file_content( let insert_position = obj.range.end - 1; text_changes.push(TextChange { range: insert_position..insert_position, - new_text: format!("\"imports\": {{ {} }}", generated_imports), + // NOTE(bartlomieju): adding `\n` here to force the formatter to always + // produce a config file that is multline, like so: + // ``` + // { + // "imports": { + // "": ":@" + // } + // } + new_text: format!("\"imports\": {{\n {} }}", generated_imports), }) } // we verified the shape of `imports` above -- cgit v1.2.3